Geometric algebra: Difference between revisions

(rewriting. Back to verifying axioms.)
Line 386:
 
=={{header|javascript}}==
<lang javascript>var CGAGA = function () {
// parts of this comes from https://github.com/weshoke/versor.js/
function e(n) {
var result = [];
Line 393 ⟶ 392:
return result;
}
function cdot(a, b) { return CGA.mul([0.5], CGA.add(CGA.mul(a, b), CGA.mul(b, a))) }
function neg(x) { return multiplymul([-1], x) }
function bitCount(i) {
// Note that unsigned shifting (>>>) is not required.
Line 424 ⟶ 423:
return result;
}
function multiplymul(a, b)
{
var result = [];
Line 450 ⟶ 449:
neg : neg,
add : add,
mul : multiplymul
};
}();</lang>
Line 456 ⟶ 455:
And then, from the console:
 
<lang javascript>var e = CGAGA.e, cdot = GA.cdot;
function cdot(a, b) { return CGA.mul([0.5], CGA.add(CGA.mul(a, b), CGA.mul(b, a))) }
for (var ji = 0; ji < 45; ji++) {
 
for (var ij = 0; ij < 45; ij++) {
for (var j = 0; j < 4; j++) {
if (i < j) {
if (cdot(e(i), e(j))[0]) { console.log("unexpected non-nul scalar product"); }
Line 469 ⟶ 467:
}
 
function randomVector() {
var v = e(0);
var result = [];
v = CGA.add(v, CGA.mul([-1], e(1)));
v for (var i = 0; i < 5; i++) { result = CGAGA.add(v result, CGAGA.mul([2Math.random()], e(2i))); }
return result;
v = CGA.add(v, CGA.mul([3], e(3)));
}
v = CGA.add(v, CGA.mul([-2], e(4)));
function randomMultiVector() {
var result = [];
for (var i = 0; i < 32; i++) { result[i] = Math.random(); }
return result;
}
 
var a = randomMultiVector(), b = randomMultiVector(), c = randomMultiVector();
console.log(CGA.mul(v, v)); // [19, 3: 0, 5: 0, 6: 0, 9: 0, 10: 0, 12: 0, 17: 0, 18: 0, 20: 0, 24: 0]
var vx = erandomVector(0);
 
// (ab)c == a(bc)
var i = CGA.mul(e(0), e(1));
var j = CGAconsole.log(GA.mul(eGA.mul(1a, b), e(2c));
var k = CGAconsole.log(GA.mul(e(0)a, eGA.mul(2b, c)));
 
// a(b + c) == ab + ac
console.log(CGA.mul(i, i)); // [-1]
console.log(CGAGA.mul(ja, jGA.add(b, c))); // [-1]
console.log(CGAGA.add(GA.mul(ka,b), kGA.mul(a, c))); // [-1]
 
console.log(CGA.mul(CGA.mul(i, j), k)); // [-1]
// (a + b)c == ac + bc
var I = CGAconsole.log(GA.mul(eGA.add(1a, b), e(2c));
console.log(GA.add(GA.mul(a,c), GA.mul(b, c)));
var J = CGA.mul(e(2), e(3));
 
var K = CGA.mul(e(1), e(3));
// x² is real
console.log(CGAGA.mul(Ix, Ix)); <// [-1]lang>
{{out}}
console.log(CGA.mul(J, J)); // [-1]
<pre>[-7.834854130554672, -10.179405417124476, 5.696414143584243, -1.4014556169803851, 12.334288331422336, 11.690738709598888, -0.4279888274147221, 6.226618790084965, -10.904144874917206, -5.46919448234424, -5.647472225071031, -2.9801969751721744, -8.284532508545746, -3.3280413654836494, -2.2182526412098493, 0.4191036292473347, 3.0485450100607103, -0.20619687045226742, 2.1369938048939527, 3.730913391951158, 10.929856967963905, 8.301187183717643, -4.874133827873075, 0.7918650606624789, -8.520661635525103, -7.732342981599732, -6.494750491582618, -2.458749173402162, 3.573788336699224, 2.784339193089742, -1.6479372032388944, -0.35120747879544256]
console.log(CGA.mul(K, K)); // [-1]
[-7.83485413055467, -10.179405417124475, 5.696414143584248, -1.4014556169803827, 12.334288331422337, 11.690738709598893, -0.4279888274147213, 6.226618790084964, -10.90414487491721, -5.46919448234424, -5.647472225071032, -2.9801969751721726, -8.284532508545746, -3.3280413654836507, -2.218252641209847, 0.41910362924733874, 3.048545010060707, -0.20619687045226748, 2.136993804893955, 3.7309133919511575, 10.929856967963904, 8.301187183717648, -4.8741338278730755, 0.7918650606624811, -8.520661635525107, -7.732342981599734, -6.494750491582625, -2.45874917340216, 3.5737883366992262, 2.7843391930897443, -1.6479372032388935, -0.351207478795442]
console.log(CGA.mul(CGA.mul(I, J), K)); // [-1]</lang>
[-4.5157935996060425, -3.9762419076273514, -2.653425845411889, -1.2899302330562412, 6.161562884801266, 3.664812215240675, -0.4471521091019873, 2.39303455739218, -1.6486347268701103, 1.156714478904937, 4.5859158357958965, 6.879356425817299, 1.3341425863947358, 5.641350122882839, 6.378155334673649, 6.466962714879142, -3.645688408496504, -1.9659188980662032, 1.3062519818876646, 1.7973392350972788, 2.4770203476100843, 1.258017836002405, 1.3794942194985413, 3.993871627961031, -3.3620439843097127, -0.4228490927003264, 0.27245046364398495, 3.813642689561589, 2.6785051915908604, 5.409359105713415, 2.9578168177883555, 4.425426168284635]
[-4.515793599606042, -3.976241907627351, -2.653425845411889, -1.2899302330562417, 6.161562884801263, 3.664812215240676, -0.44715210910198766, 2.393034557392179, -1.6486347268701103, 1.156714478904937, 4.585915835795897, 6.8793564258172974, 1.3341425863947352, 5.641350122882839, 6.378155334673649, 6.466962714879143, -3.645688408496502, -1.9659188980662032, 1.3062519818876661, 1.7973392350972783, 2.4770203476100843, 1.258017836002407, 1.379494219498544, 3.99387162796103, -3.3620439843097127, -0.42284909270032545, 0.2724504636439853, 3.8136426895615894, 2.67850519159086, 5.409359105713415, 2.9578168177883555, 4.425426168284636]
[-5.8903316026132755, -6.619647679486295, -1.8140191326116537, -2.519531799741982, 6.604158362571294, 6.352401943423508, 0.9412086471616096, 3.719341486246096, -2.209111542028446, 1.9980997124233557, 5.717878641652222, 7.351597777237362, -2.9037939632499974, 1.497897713658653, 6.811544238648882, 5.861907187665564, -3.2638975880372363, -2.2659714695119115, 1.227221599808634, 0.8343365341022846, 2.72461491531054, 2.728833585944902, 2.226404227376565, 3.888097816250177, 0.35867175462798684, 2.3965356477571302, -1.7151608532791172, 1.403673323043394, -2.1441532262277607, 2.5435142440445646, 2.00110597707534, 1.9825972651495558]
[-5.8903316026132755, -6.6196476794862935, -1.8140191326116533, -2.5195317997419817, 6.604158362571292, 6.352401943423505, 0.9412086471616091, 3.719341486246094, -2.209111542028446, 1.9980997124233555, 5.71787864165222, 7.351597777237364, -2.9037939632499974, 1.4978977136586529, 6.81154423864888, 5.861907187665565, -3.263897588037235, -2.2659714695119124, 1.2272215998086353, 0.8343365341022843, 2.72461491531054, 2.7288335859449018, 2.226404227376565, 3.8880978162501783, 0.3586717546279864, 2.396535647757131, -1.715160853279117, 1.4036733230433938, -2.1441532262277603, 2.543514244044564, 2.0011059770753405, 1.9825972651495565]
console[3.log(CGA.mul(v, v)); // [19193752260485546, 3: 0, 5: 0, 6: 0, 9: 0, 10: 0, 12: 0, 17: 0, 18: 0, 20: 0, 24: 0]</pre>
 
=={{header|Perl 6}}==
1,934

edits