NB. If anyone wants to do Clifford Algebra
NB. Part 1. Definitions.
NB. For N orthogonal unit vectors; e.g.
N =: 3
NB. The power set giving all unit vector combinations is:
P =: #: i. 2 ^ N
NB. The exclusive-or verb is
xor =: [EMAIL PROTECTED]
NB. The verb taking bitstrings to signed integers, (0 1 -> 1 _1):
bs =: -@<:@+:
NB. Its inverse verb, (1 _1 -> 0 1), is:
sb =: -:@>:@-
NB. (bs 0 1) = (_1^ 0 1)
NB. The grades (bitcounts) of the combinations are:
K =: +/"1 P
NB. The parities of the combinations are:
NB. (xor/"1 P) = (2|K)
NB. The combination xor table is:
xor"1/~ P
NB. Its integer form is:
H =: #. xor"1/~ P
NB. The sign parity verb in multiplying two combinations is:
swap =: xor/ @ , @ (*&(</~ i.N)) @ (*./)"1
NB. The sign factor table is:
S =: bs swap/~ P
NB. The general bilinear product on multivectors where
NB. ((i xor j) { c) = ((i,j) { u) * (i{ a) * (j { b) <=> c = a (u kai) b
NB. is given by the adverb:
kai =: 1 : '([: +/ H {"1 u * */)"1 1'
NB. (Note. Greek "kai" = "and".)
NB. The Clifford or geometric product (for all-positive metric) is:
g =: S kai
NB. g =: ([: +/ H {"1 S * */)"1 1
NB. This adverb constructs filtering inner products, equal to g where the
NB. component grade (k,l){K meets the condition (k u l):
en =: 1 : 'S * (u/~ K) = H{K'
NB. (Note. Greek "en-" = "in".)
NB. Wedge product as above:
NB. for k-blade A, l-blade B, <A w B>(k+l) = <A>k g <B>l
w =: + en kai
NB. Hestenes inner product as above:
NB. for k-blade A, l-blade B, <A w B>(abs(k-l)) = <A>k g <B>l
d =: ((* *)@-) en kai
NB. Left Contraction:
NB. for k-blade A, l-blade B, <A w B>(k < l)= <A>k g <B>l
cl =: < en kai
NB. The identity matrix of order 2^N is:
I =: =/~ i. 2^N
NB. The rows of the I matrix are just the list of unit components.
NB. Grade involution:
NB. (Note. Written as circumflex or caret superior (^) in Lounesto.)
Scir =: _1^K
cir =: *"1 & Scir
NB. Reversion, or Main involution
NB. (Note. Written as tilde superior (~) in Lounesto, dagger in Hestenes.)
Srev =: +/ I * S
rev =: *"1 & Srev
NB. Clifford conjugate
NB. (Note. Written as bar superior in Lounesto.)
Sbar =: Scir * Srev
bar =: *"1 & Sbar
NB. The multivector norm is:
q =: ({. @ (d rev))"1
NB. The magnitude is:
mag =: %: @ q
NB. The reciprocal is:
div =: rev % q
NB. The normalized or unit-magnitude mutivector is given by:
unit =: % mag
NB. For a blade B, i.e. g product of vectors, (g div) B = one.
NB. Define a Clifford multivector by injecting components of one grade:
inj =: 4 : 'y +/ .* (x = K) # I'
NB. Project out the components of one grade:
proj =: 4 : '(x = K) # y'
NB. Test Series 1.
NB. Specifically for N = 3:
NB. Name the Clifford components:
'one e1 e2 e12 e3 e13 e23 e123' =: <"1 I
NB. Injectors for each grade:
sca =: 0&inj
vec =: 1&inj
bi =: 2&inj
tri=: 3&inj
all1 =: *./ @ ,
associates =: 1 : 'all1 (I u/ I u/ I) = (I u/ I) u/ I'
NB. Test Clifford product associativity:
NB. Test100 =: all1 ((I g/ I) g/ I) = (I g/ (I g/ I))
NB. Test100a =: g associates
NB. Test (a w b) == ( (a g b) - (b g a))/2, for vectors a, b.
NB. Test101 =: all1 (w = [: -: g - g~)"1 /~ 1 proj I
NB. Test (a d b) == ( (a g b) + (b g a))/2, for vectors a, b.
NB. Test102 =: all1 (d = [: -: g + g~)"1 /~ 1 proj I
NB. Test square of vector is a scalar
NB. Test103 =: all1 1 ="1 Q 1 inj =/~ i.3
NB. Test104 =: all1 one ="1 g~ 1 inj =/~ i.3
NB. Test dot commutates on vectors.
NB. Test105 =:. all1 (V d/ V) = (V d~/ V) [ V =. 1 proj I
NB. Test wedge anticommutates on vectors.
NB. Test106 =: all1 (V w/ V) = - (V w~/ V) [ V =. 1 proj I
NB. Test wedge product associativity.
NB. Test107 =: w associates.
NB. Blade reciprocal example:
NB. Test108 =: m =. vector 3 4 0 , 12 _5 0 ,: 0 0 1
NB. Test108 =: all1 one = (d r) g/ m
all1 cir cir I = I
all1 rev rev I = I
all1 bar bar I = I
all1 (cir I) = (bar rev I)
all1 (cir I) = (rev bar I)
all1 (cir g/~ I) = (g/~ cir I)
all1 (rev g/~ I) = (g~/~ rev I)
all1 (bar g/~ I) = (g~/~ bar I)
NB. The conjugate of the product of the reverse is the product of the
conjugates.
NB. all1 (rev g/~ I) = (g~/~ rev I)
NB. Part 2. Quaternions and Rotations.
sin =: 1&o.
cos =: 2&o.
arcsin =: _1&o.
arccos =: _2&o.
pi =: o.
tol =: <.&.(*&1e14)
NB. Extending the complex identities:
NB. exp (i theta) = cos theta + i sin theta,
NB. exp (r + i theta) = e^r * (cos theta + i sin theta)
NB. exp gives the quaternion for rotation in a given bivector plane:
expi =: 3 : '((one * cos mag y) + ((unit y) * sin mag y))'
exp =: 3 : '(^ mag -: (+ rev) y) * expi -: (- rev) y'
NB. Example: the quaternion q90 (= e12) rotates vectors in the e12 plane by
NB. 90 degrees clockwise, while rotating the e3 component to e123:
q90 =: expi (pi%2) * e12
q90 g vec 3 4 5
NB. Example: qe90 treats vectors as q90, but dilates them by (^1) = e = 2.718..
qe90 =: exp one + (pi%2) * e12
qe90 g vec 3 4 5
NB. Example: q45 gives a 45 degree rotation in the e12 plane,
NB. while rotating the e3 component 45 degrees toward e123.
NB. q45 left multiplied twice is the same as q90:
q45 =: expi (pi%4) * e12
q45 g vec 3 4 5
q45 g q45 g vec 3 4 5
NB. The rotor operation (Q g V g (div Q)) gives a rotation in the Q plane,
NB. preserving the components perpendicular to the plane:
rot =: 4 : 'x g y g div x'
q45 rot vec 3 4 5
NB. The square root of a unit quaternion, or angle-halving operation, is:
qhf =: 3 : 'unit one + y'
NB. q45 = qhf e12
NB. The Argand angle of a quaternion is:
arg =: 3 : '_2 o. {. unit y'"1
NB. This is the angle between the quaternion and one. It is the arccos of the
NB. scalar component of the unit, and is less than pi, since
NB. (expi unit * (pi + theta)) = expi (- unit) * theta
NB. For vectors a, b, represent a triangle as:
a =: vec 4 3 1
b =: vec _2 _1 3
c =: - (a + b)
abc =: a , b ,: c
NB. Then the cyclic permutation of abc is
1&|. abc
NB. For the exterior and interior angles at the ab vertex:
NB. (a d b) = (mag a) (mag b) cos extab = - (mag a) (mag b) cos intab
NB. (a w b) = (mag a) (mag b) (unit a w b) sin extab ( = sin intab)
NB. (a g b) = (mag a) (mag b) expi (unit a w b) * extab
((unit b g a) * (mag b) % (mag a)) = (b g div a)
Test201 =: one = tol (a g div c) g (c g div b) g (b g div a)
Test202 =:one = tol g/ ((g div)/ 1&|.) abc
NB. The interior sines are:
%: (q (a w b)) % (*/ q abc) % (q abc)
(mag (a w b)) % (*/ mag abc) % (mag abc)
NB. The sum of the interior angles is pi:
Test203 =: (pi 1) = tol +/ arcsin %: (q (a w b)) % (*/ q abc) % (q abc)
NB. The cosine of intab, at the ab vertex, is:
arccos - ((q c) - (q a) + (q b)) % 2 * (*/mag abc) % (mag c)
NB. The area is:
area =: mag -: a w b
NB. By Heron's formula:
NB. Test204 =: area = %: s * */ s - mag abc [ s =. -: +/ mag abc
NB. By Wildberger's formula is:
NB. Test205 =: area =: %: (% 16) * (*: +/ q abc) - 2 * (+/ *: q abc)
NB. Part 4. Walsh Functions and Hadamard Matrices
NB. Part 5. Multilinear expressions and identities
NB. Part6. Split Representations.
NB. References
NB. New Foundations for Classical Mechanics
NB. Hestenes, David
NB. D. Reidel Publishing Company
NB. 1986
NB. ISBN 90-277-2090-8
NB.
NB. Clifford Algebras and Spinors
NB. Lounesto, Pertti
NB. Cambridge University Press
NB. London Mathematical Society Lecture Note Series, 286
NB. 2001
NB. ISBN 0-521-005515-5
NB.
NB. Geometric algebra: a computational framework for geometric applications.
NB. Dorst, Leo, and Mann, Stephen
NB. 2002
NB. [In two parts:]
NB. http://www.science.uva.nl/ga/files/cga-1.pdf
NB. http://www.science.uva.nl/ga/files/cga-2.pdf
NB.
NB. Honing geometric algebra for its use in the computer sciences pdf, ps.gz
NB. Dorst, Leo
NB. 2001
NB. http://www.science.uva.nl/ga/publications/honing.pdf
NB.
NB. Maths for Programmers. Section 5, Multivector Methods
NB. Ian C. Bell
NB. http://www.iancgbell.clara.net/maths/geoalg.htm
NB.
NB. Pythagoras, Euclid, Archimedes and a new Trigonometry
NB. Wildberger, N.J.
NB. 2006
NB. http://web.maths.unsw.edu.au/~norman/papers/Pythagoras.pdf
NB. Jsoftware Inc. are the authors and developers of the J language.
NB. http://www.jsoftware.com
NB. Posted to the J language programming forum
NB. <[email protected]>
NB. 16/10/2007.
NB. (c) Copyright, Jonathan Burns.
NB. Jonathan Arthur Russell Burns, b. 29/8/1949, Melbourne, Vic., Australia
NB. claims authorship of the text above. Permission is given for free use,
NB. including copying, excerpting and modifying, provided only that the
NB. original authorship is not disputed.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm