Geometric algebra: Difference between revisions
Content deleted Content added
→{{header|javascript}}: update |
→{{header|Perl 6}}: rephrasing + minor fix in the verification code |
||
Line 578:
}</lang>
And here is the code
<lang perl6>use MultiVector;
use Test;
plan 29;
sub infix:<cdot>($x, $y) { ($x*$y + $y*$x)/2 }
for ^5 X ^5 -> ($i, $j) {
my $s = $i == $j ?? 1 !! 0;
ok
}
sub random {
Line 596 ⟶ 595:
MultiVector.new:
:blades(my Real %{UInt} = $_ => rand.round(.01))
},
}
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
my $v = [+] @coeff Z* map &e, ^
ok ($v**2).narrow ~~ Real, 'contraction';</lang>
{{out}}
|