Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Raku Next Steps: Hyperbolic

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

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.

Avatar for Bruce Gray

Bruce Gray

June 27, 2026

More Decks by Bruce Gray

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. 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
  4. 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
  5. my @a = 8, 10, 12, 14; my @b =

    2 xx +@a; my @c = @a »+« @b; 14
  6. my @a = 8, 10, 12, 14; my @b =

    2 xx +@a; my @c = @a »+« @b; # = @a Z+ @b; 15
  7. die if +@A !== +@B; my @C = @A Z+

    @B; # vs my @C = @A »+« @B; 16
  8. my @a = 8, 10, 12, 14; my @b =

    2 xx +@a; # Pretty kludgy my @c = @a »+« @b; 17
  9. my @a = 8, 10, 12, 14; my @b =

    2 xx +@a; # Pretty kludgy my @c = @a »+« @b; 18
  10. my @a = 8, 10, 12, 14; my @b =

    2 xx +@a; # Pretty kludgy my @c = @a »+« @b; 19
  11. my @a = 8, 10, 12, 14; my @b =

    2 xx +@a; # Pretty kludgy my @c = @a »+» 2; 20
  12. my @a = 8, 10, 12, 14; my @b =

    2 xx +@a; # Pretty kludgy my @c = @a »+» 2; # = @a X+ 2; 21
  13. my @a = 8, 10, 12, 14; my @b =

    2 xx +@a; # Pretty kludgy my @c = @a »+» 2; # = @a X+ 2; 22
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. Powers and Factorials 7⁴ == 7 * 7 * 7

    * 7 7! == 1 * 2 * 3 * 4 * 5 * 6 * 7 33
  21. 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
  22. Powers and Factorials 52! / 50! == 52 * 51

    * 50 * 49 * 48 ... 3 * 2 * 1 -------------------------------------- 50 * 49 * 48 ... 3 * 2 * 1 40
  23. Powers and Factorials 52! / 50! == 52 * 51

    * 50 * 49 * 48 ... 3 * 2 * 1 -------------------------------------- 50 * 49 * 48 ... 3 * 2 * 1 41
  24. Powers and Factorials 52! / 50! == 52 * 51

    * 50 * 49 * 48 ... 3 * 2 * 1 -------------------------------------- 50 * 49 * 48 ... 3 * 2 * 1 == 52 * 51 42
  25. Rising and Falling Powers 7⁴ == 7 * 7 *

    7 * 7 7⁴ == 7 * 8 * 9 * 10 == 5040 45
  26. Rising and Falling Powers 7⁴ == 7 * 7 *

    7 * 7 7⁴ == 7 * 8 * 9 * 10 == 5040 7⁴ == 7 * 6 * 5 * 4 == 840 46
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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
  33. 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
  34. 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)
  35. 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
  36. 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/
  37. LICENSE • © 2026 Bruce Gray <[email protected]>
 This work is

    openly licensed under CC BY 4.0.
 https://creativecommons.org/licenses/by/4.0/