Share
Embed
Raku Next Steps: Hyperbolic
(Part 3)
Raku’s hyper-operators: a simple syntax granting us safe parallel processing, like Prometheus sneaking a flame from the heavens.
Shorten @B = map { $_ * 5 }, @A; to @B = @A »*» 5; boost performance!
Come learn how to cook with all your cores, with the fire that cannot burn down your house.
Bruce Gray
June 27, 2026
Transcript
63 slides
-
Raku Next Steps: Hyperbolic ( Starting to think in Raku
) { with »+« and »~» and «-« and maybe even «ς» } [ Part 3 of a "Intermediate Raku" class ] The Perl and Raku Conference 2026-06-27 -
3 • https://glot.io/new/raku for online coding • Mac: brew install
rakudo-star • Windows/Linux: https://rakudo.org/downloads • Docker: • REPL on any system: • docker run --rm -it rakudo-star • Script on Mac or Unix: • docker run --rm -v "$(pwd):/script" rakudo-star raku /script/a.raku • Script on Windows: • docker run --rm -v "%cd%:/script" rakudo-star raku /script/a.raku Run online, or install locally -
Hyper-operators op« »op «op« »op» «op» »op« op<< >>op <<op<<
>>op>> <<op>> >>op<< -
Hyper-operators op« »op «op« »op» «op» »op« op<< >>op <<op<<
>>op>> <<op>> >>op<< -
Hyper-operators op« »op «op« »op» «op» »op« op<< >>op <<op<<
>>op>> <<op>> >>op<< -
my $c = $a + $b; my @z = @x
»+« @y; 9 -
my @m = (4,0,0,0,2), (3,3,3,2,2), (1,4,1,0,4), (3,0,1,2,2), (2,3,3,2,1), ; my
@n = (4,4,2,1,3), (2,2,3,2,2), (2,2,1,2,0), (4,4,1,1,3), (3,4,0,0,4), ; @o = @m »+« @n; .say for @o; # (8 4 2 1 5) # (5 5 6 4 4) # (3 6 2 2 4) # (7 4 2 3 5) # (5 7 3 2 5) 10 -
my @m = (4,0,0,0,2), (3,3,3,2,2), (1,4,1,0,4), (3,0,1,2,2), (2,3,3,2,1), ; my
@n = (4,4,2,1,3), (2,2,3,2,2), (2,2,1,2,0), (4,4,1,1,3), (3,4,0,0,4), ; @o = @m »+« @n; .say for @o; # (8 4 2 1 5) # (5 5 6 4 4) # (3 6 2 2 4) # (7 4 2 3 5) # (5 7 3 2 5) 11 -
my @a = 8, 10, 12, 14; my @b =
2 xx +@a; 13 -
my @a = 8, 10, 12, 14; my @b =
2 xx +@a; my @c = @a »+« @b; 14 -
my @a = 8, 10, 12, 14; my @b =
2 xx +@a; my @c = @a »+« @b; # = @a Z+ @b; 15 -
die if +@A !== +@B; my @C = @A Z+
@B; # vs my @C = @A »+« @B; 16 -
my @a = 8, 10, 12, 14; my @b =
2 xx +@a; # Pretty kludgy my @c = @a »+« @b; 17 -
my @a = 8, 10, 12, 14; my @b =
2 xx +@a; # Pretty kludgy my @c = @a »+« @b; 18 -
my @a = 8, 10, 12, 14; my @b =
2 xx +@a; # Pretty kludgy my @c = @a »+« @b; 19 -
my @a = 8, 10, 12, 14; my @b =
2 xx +@a; # Pretty kludgy my @c = @a »+» 2; 20 -
my @a = 8, 10, 12, 14; my @b =
2 xx +@a; # Pretty kludgy my @c = @a »+» 2; # = @a X+ 2; 21 -
my @a = 8, 10, 12, 14; my @b =
2 xx +@a; # Pretty kludgy my @c = @a »+» 2; # = @a X+ 2; 22 -
https://en.wikipedia.org/wiki/ ISBN#ISBN-13_check_digit_calculation x₁ + 3x₂ + x₃ + 3x₄ +
x₅ + 3x₆ + x₇ + 3x₈ + x₉ + 3x₁₀ + x₁₁ + 3x₁₂ + x₁₃ ≡ 0 (mod 10) ; (@digits »*» (1,3) ).sum 23 -
https://en.wikipedia.org/wiki/ ISBN#ISBN-13_check_digit_calculation x₁ + 3x₂ + x₃ + 3x₄ +
x₅ + 3x₆ + x₇ + 3x₈ + x₉ + 3x₁₀ + x₁₁ + 3x₁₂ + x₁₃ ≡ 0 (mod 10) (@digits Z* <1 3 1 3 1 3 1 3 1 3 1 3>).sum ; 24 -
https://en.wikipedia.org/wiki/ ISBN#ISBN-13_check_digit_calculation x₁ + 3x₂ + x₃ + 3x₄ +
x₅ + 3x₆ + x₇ + 3x₈ + x₉ + 3x₁₀ + x₁₁ + 3x₁₂ + x₁₃ ≡ 0 (mod 10) (@digits Z* <1 3 1 3 1 3 1 3 1 3 1 3 1>).sum 25 -
https://en.wikipedia.org/wiki/ ISBN#ISBN-13_check_digit_calculation x₁ + 3x₂ + x₃ + 3x₄ +
x₅ + 3x₆ + x₇ + 3x₈ + x₉ + 3x₁₀ + x₁₁ + 3x₁₂ + x₁₃ ≡ 0 (mod 10) (@digits Z* <1 3 1 3 1 3 1 3 1 3 1 3 1>).sum (@digits Z* |( (1,3) xx * ) ).sum 26 -
https://en.wikipedia.org/wiki/ ISBN#ISBN-13_check_digit_calculation x₁ + 3x₂ + x₃ + 3x₄ +
x₅ + 3x₆ + x₇ + 3x₈ + x₉ + 3x₁₀ + x₁₁ + 3x₁₂ + x₁₃ ≡ 0 (mod 10) (@digits Z* <1 3 1 3 1 3 1 3 1 3 1 3 1>).sum (@digits Z* |( (1,3) xx * ) ).sum (@digits »*» (1,3) ).sum 27 -
https://en.wikipedia.org/wiki/ ISBN#ISBN-13_check_digit_calculation x₁ + 3x₂ + x₃ + 3x₄ +
x₅ + 3x₆ + x₇ + 3x₈ + x₉ + 3x₁₀ + x₁₁ + 3x₁₂ + x₁₃ ≡ 0 (mod 10) [+] @digits Z* <1 3 1 3 1 3 1 3 1 3 1 3 1> ; [+] @digits Z* ( |(1,3) xx * ) [+] @digits »*» (1,3) 28 -
Powers and Factorials 7⁴ == 7 * 7 * 7
* 7 7! == 1 * 2 * 3 * 4 * 5 * 6 * 7 33 -
Powers and Factorials 52! == 52 × 51 × 50
× 49 × 48 × 47 × 46 × 45 × 44 × 43 × 42 × 41 × 40 × 39 × 38 × 37 × 36 × 35 × 34 × 33 × 32 × 31 × 30 × 29 × 28 × 27 × 26 × 25 × 24 × 23 × 22 × 21 × 20 × 19 × 18 × 17 × 16 × 15 × 14 × 13 × 12 × 11 × 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1 == 80_658_175_170_943_878_571_660_636_856_403_766_975_289_505_440_8 83_277_824_000_000_000_000 ~~ 2 ** 225 39 -
Powers and Factorials 52! / 50! == 52 * 51
* 50 * 49 * 48 ... 3 * 2 * 1 -------------------------------------- 50 * 49 * 48 ... 3 * 2 * 1 40 -
Powers and Factorials 52! / 50! == 52 * 51
* 50 * 49 * 48 ... 3 * 2 * 1 -------------------------------------- 50 * 49 * 48 ... 3 * 2 * 1 41 -
Powers and Factorials 52! / 50! == 52 * 51
* 50 * 49 * 48 ... 3 * 2 * 1 -------------------------------------- 50 * 49 * 48 ... 3 * 2 * 1 == 52 * 51 42 -
Rising and Falling Powers 7⁴ == 7 * 7 *
7 * 7 7⁴ == 7 * 8 * 9 * 10 == 5040 45 -
Rising and Falling Powers 7⁴ == 7 * 7 *
7 * 7 7⁴ == 7 * 8 * 9 * 10 == 5040 7⁴ == 7 * 6 * 5 * 4 == 840 46 -
Rising and Falling Factorials sub rise (\n,\k) { [*] n
..^ (n + k) } sub fall (\n,\k) { [*] (n - k) ^.. n } say rise(7,4); # 7⁴ == 7 * 8 * 9 * 10 == 5040 say fall(7,4); # 7⁴ == 7 * 6 * 5 * 4 == 840 49 -
Rising and Falling Factorials sub rise (\n,\k) { [*] ^k
+ n } sub fall (\n,\k) { [*] ^(-k) + n } say rise(7,4); # 7⁴ == 7 * 8 * 9 * 10 == 5040 say fall(7,4); # 7⁴ == 7 * 6 * 5 * 4 == 840 50 -
Rising and Falling Factorials sub infix:<**^> ($x, $pow) { [*]
$x «+« ^$pow } sub infix:<**v> ($x, $pow) { [*] $x «-« ^$pow } [*] 7 «-« ^$pow [*] 7 «-« ^4 [*] 7 «-« 0..3 [*] 7-0,7-1,7-2,7-3 [*] 7, 6, 5, 4 7 * 6 * 5 * 4 say 7 **^ 4; # 5040 say 7 **v 4; # 840 51 -
Rising and Falling Factorials sub infix:<**^> ($x, $pow) { [*]
$x «+« ^$pow } sub infix:<**v> ($x, $pow) { [*] $x «-« ^$pow } say (5,7,11) »**^» 4; say 7 «**v« (3,5,7); 52 -
Rising and Falling Factorials sub infix:<**^> ($x, $pow) { [*]
$x «+« ^$pow } sub infix:<**v> ($x, $pow) { [*] $x «-« ^$pow } say (5,7,11) »**^» 4; say 7 «**v« (3,5,7); (1680 5040 24024) ( 210 2520 5040) 53 -
https://rosettacode.org/wiki/Chebyshev_coef fi cients#Raku sub chebft ( Code $func, Real \a,
Real \b, Int \n ) { my \bma = ½ * (b - a); my \bpa = ½ * (b + a); my @pi-n = ( ^n »+» ½ ) »*» (π/n); my @f = ( @pi-n».cos »*» bma »+» bpa )».&$func; my @sums = map { [+] @f »*« (@pi-n »*» $_)».cos }, ^n; return @sums »*» (2/n); } say chebft(&cos, 0, 1, 10).fmt: '%+13.7e'; 55 -
https://rosettacode.org/wiki/Chebyshev_coef fi cients#C #include <stdio.h> #include <string.h> #include <math.h> #ifndef
M_PI #define M_PI 3.14159265358979323846 #endif double test_func(double x) { //return sin(cos(x)) * exp(-(x - 5)*(x - 5)/10); return cos(x); } // map x from range [min, max] to [min_to, max_to] double map(double x, double min_x, double max_x, double min_to, double max_to) { return (x - min_x)/(max_x - min_x)*(max_to - min_to) + min_to; } void cheb_coef(double (*func)(double), int n, double min, double max, double *coef) { memset(coef, 0, sizeof(double) * n); for (int i = 0; i < n; i++) { double f = func(map(cos(M_PI*(i + .5f)/n), -1, 1, min, max))*2/n; for (int j = 0; j < n; j++) coef[j] += f*cos(M_PI*j*(i + .5f)/n); } } // f(x) = sum_{k=0}^{n - 1} c_k T_k(x) - c_0/2 // Note that n >= 2 is assumed; probably should check for that, however silly it is. double cheb_approx(double x, int n, double min, double max, double *coef) { double a = 1, b = map(x, min, max, -1, 1), c; double res = coef[0]/2 + coef[1]*b; x = 2*b; for (int i = 2; i < n; a = b, b = c, i++) // T_{n+1} = 2x T_n - T_{n-1} res += coef[i]*(c = x*b - a); return res; } int main(void) { #define N 10 double c[N], min = 0, max = 1; cheb_coef(test_func, N, min, max, c); printf("Coefficients:"); for (int i = 0; i < N; i++) printf(" %lg", c[i]); puts("\n\nApproximation:\n x func(x) approx diff"); for (int i = 0; i <= 20; i++) { double x = map(i, 0, 20, min, max); double f = test_func(x); double approx = cheb_approx(x, N, min, max, c); printf("% 10.8lf % 10.8lf % 10.8lf % 4.1le\n", x, f, approx, approx - f); } return 0; } 56 -
Which when? 58 Hyper Variant Op Examples Can shorten Can
lengthen Method >>.method @a».uc @a>>.chars Post fi x, Postcircum fi x >>op @a»³ @a»++ @a>>[5] Pre fi x op<< +«@a ~«@a ?<<@a Inward (Zip) >>op<< @a »+« @b No No Right (Scale) >>op>> @a »/» 10 * * Left (Scale) <<op<< 1 «/« (1..100) * * Outward <<op>> CENSORED No (List) Yes (Hash intersection) Yes (List) No (Hash intersection) -
Which when? 59 Code Depth Associative action Dup structure Magic
Size Adjustments Sequential / Concurrent map 1 Whole item Seq No Sequential nodemap 1 Value only Yes (but itemizes?) No Sequential duckmap ???XXX Value only Yes No Sequential deepmap Max Value only Yes No Sequential hyper-ops .nodal ?? 1 !! Max Value only Yes Yes (In fi x and not Inward) Concurrent -
Copyright Information: Images • Camelia • © 2009 by Larry
Wall http://github.com/perl6/mu/raw/master/misc/camelia.txt • Periodic Table of the Operators • © 2004, 2009 by Mark Lentczner https://www.ozonehouse.com/mark/periodic/ -
LICENSE • © 2026 Bruce Gray <[email protected]> This work is
openly licensed under CC BY 4.0. https://creativecommons.org/licenses/by/4.0/