Exponentiation with infix operators in (or operating on) the base: Difference between revisions
Exponentiation with infix operators in (or operating on) the base (view source)
Revision as of 19:52, 23 February 2023
, 1 year ago→{{header|Raku}}: re-write without EVAL, works in recent releases of Raku
Langurmonkey (talk | contribs) (added langur language example) |
SqrtNegInf (talk | contribs) (→{{header|Raku}}: re-write without EVAL, works in recent releases of Raku) |
||
Line 768:
sub infix:<∧> is looser(&infix:<->) { $^a ** $^b }
for
('Default
'(1 + -$x)**$p', {(1 + -$^a)**$^b}, '1 + -($x**$p)', {1 + -($^a**$^b)}),
'(1 + -$x)↑$p ', {(1 + -$^a)↑$^b}, '1 + -($x↑$p) ', {1 + -($^a↑$^b)}),
'(1 + -$x)∧$p ', {(1 + -$^a)∧$^b}, '1 + -($x∧$p) ', {1 + -($^a∧$^b)})
-> $case {
▲ "\nEven moreso: custom looser infix exponentiation is looser (lower) precedence than infix subtraction.",
my ($title, @operations) = $case<>;
▲ ('1 + -$x∧$p ', '1 + (-$x)∧$p ', '1 + (-($x)∧$p) ', '(1 + -$x)∧$p ', '1 + -($x∧$p) ')
for -5, 5 X 2, 3 -> ($x, $p) {
printf "x = %2d p = %d", $x, $p;
for @operations -> $
}
}</syntaxhighlight>
Line 799 ⟶ 802:
x = 5 p = 3 │ 1 + -$x↑$p = -124 │ 1 + (-$x)↑$p = -124 │ 1 + (-($x)↑$p) = -124 │ (1 + -$x)↑$p = -64 │ 1 + -($x↑$p) = -124
Even
x = -5 p = 2 │ 1 + -$x∧$p = 36 │ 1 + (-$x)∧$p = 36 │ 1 + (-($x)∧$p) = 26 │ (1 + -$x)∧$p = 36 │ 1 + -($x∧$p) = -24
x = -5 p = 3 │ 1 + -$x∧$p = 216 │ 1 + (-$x)∧$p = 216 │ 1 + (-($x)∧$p) = 126 │ (1 + -$x)∧$p = 216 │ 1 + -($x∧$p) = 126
|