Geometric algebra: Difference between revisions

→‎{{header|Perl 6}}: rephrasing + minor fix in the verification code
(→‎{{header|Perl 6}}: rephrasing + minor fix in the verification code)
Line 578:
}</lang>
 
And here is the code implementing andfor verifying quaternionsthe solution:
 
<lang perl6>use MultiVector;
use Test;
 
plan 29;
 
sub infix:<cdot>($x, $y) { ($x*$y + $y*$x)/2 }
my @e = map &e, ^5;
 
for ^5 X ^5 -> ($i, $j) {
my $s = $i == $j ?? 1 !! 0;
ok @e[($i]) cdot @e[($j]) == $s, "e$i cdot e$j = $s";
}
sub random {
Line 596 ⟶ 595:
MultiVector.new:
:blades(my Real %{UInt} = $_ => rand.round(.01))
}, (^32).pick(5);
}
 
my ($a, $b, $c) = random() xx 3;
 
ok ($a*$b)*$c == $a*($b*$c), 'associativity';
ok $a*($b + $c) == $a*$b + $a*$c, 'left distributivity';
ok ($a + $b)*$c == $a*$c + $b*$c, 'right distributivity';
my @coeff = (.5 - rand) xx 45;
my $v = [+] @coeff Z* map &e, ^45;
ok ($v**2).narrow ~~ Real, 'contraction';</lang>
{{out}}
1,934

edits