-
Notifications
You must be signed in to change notification settings - Fork 0
/
clifford.spad.pamphlet
1667 lines (1470 loc) · 65.1 KB
/
clifford.spad.pamphlet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass{article}
\usepackage{axiom}
\usepackage{amssymb}
% \input{diagrams.tex}
\begin{document}
\title{\$SPAD/src/algebra clifford.spad}
\author{Martin J Baker, Stephen M. Watt}
\maketitle
\begin{abstract}
\end{abstract}
\eject
\tableofcontents
\eject
\section{domain QFORM QuadraticForm}
<<domain QFORM QuadraticForm>>=
)abbrev domain QFORM QuadraticForm
++ Author: Stephen M. Watt
++ Date Created: August 1988
++ Date Last Updated: May 17, 1991
++ Basic Operations: quadraticForm, elt
++ Related Domains: Matrix, SquareMatrix
++ Also See:
++ AMS Classifications:
++ Keywords: quadratic form
++ Examples:
++ References:
++
++ Description:
++ This domain provides modest support for quadratic forms.
QuadraticForm(n, K): T == Impl where
n: PositiveInteger
K: Field
SM ==> SquareMatrix
V ==> DirectProduct
T ==> AbelianGroup with
quadraticForm: SM(n, K) -> %
++ quadraticForm(m) creates a quadratic form from a symmetric,
++ square matrix m.
matrix: % -> SM(n, K)
++ matrix(qf) creates a square matrix from the quadratic form qf.
elt: (%, V(n, K)) -> K
++ elt(qf,v) evaluates the quadratic form qf on the vector v,
++ producing a scalar.
if SM(n, K) has ConvertibleTo InputForm then ConvertibleTo InputForm
Impl ==> SM(n,K) add
Rep := SM(n,K)
quadraticForm m ==
not symmetric? m =>
error "quadraticForm requires a symmetric matrix"
m::%
matrix q == q pretend SM(n,K)
elt(q,v) == dot(v, (matrix q * v))
if SM(n, K) has ConvertibleTo InputForm then
convert(q:%):InputForm ==
-- without package call we get infinite recursion
mif := (convert(matrix q)$(SM(n, K)))@InputForm
qf := convert(convert('quadraticForm)@SExpression)@InputForm
convert([qf, mif])$InputForm
@
\section{domain CLIF CliffordAlgebra\cite{7,12}}
When using this algebra for geometry and physics we want to be able to mix
the Clifford product with the Grassmann (exterior or wedge) product and
inner products in the same equation.
For example we may want to create a geometric object using meet and join
then transform using conjugation.
In physics we need to combine these products by analogy with the way that
vector algebra combines scalar, dot and cross products. When modeling solid
bodies (isometries) we want to model either 'projective space' or 'conformal
space'.
We also want these to work with a basis from non-diagonal quadratic form
(such as bases which square to +ve and -ve and then rotated).
\subsection{Why So Many Product Types?}
Why So Many Product Types?
The exterior and inner products can be introduced in different ways, one
way is to look at the exterior product as the product which generates the
structure:
<e1, e2...en | ei/\ei=0, ei/\ej= -ej/\ei>
and the interior product defines the metric structure.
Or we can look at exterior and inner products as duals:
\begin{list}{}
topic concept dual concept
product exterior inner
geometric interpretation intersection of spaces meet
union of spaces join
element grade=m grade = n-m
\end{list}
Or we can look at the exterior and inner products as components of the
Clifford product.
When we are dealing with pure vectors in orthogonal bases these concepts
all coincide, however when we move to higher grades or use metrics with a
non-diagonal quadratic form, the inner product types start to diverge and
we end up with the regressive inner product, the contraction inner products,
and so on.
\subsection{instantiate an instance of CliffordAlgebra}
We first need to instantiate an instance of CliffordAlgebra, the constructor
takes 3 parameters:
\begin{list}{}
parameter type meaning
1st PositiveInteger dimension of the underling algebra (module over)
2nd Type type over which this is defined
3rd SquareMatrix of dimension defined by 1st parameter bilinear form
\end{list}
In the following example we will define a 3 dimensional Euclidean space so
the bilinear form is the identity matrix:
(1) -> Eu := CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(1) CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
Type: Domain
\subsection{Entering Multivectors}
Entering Multivectors
We can then create some elements in the algebra (I will call the general
element in this algebra a 'multivector' to be consistent with most of the
literature). First we can create some basis vectors using e(PI):
(2) -> e1:Eu := e(1)
(2) e
1
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(3) -> e2:Eu := e(2)
(3) e
2
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
There are many options for creating higher grade basis,
* by multiplying basis vectors,
* or by using ee(List PI) to specify the higher order term in one go
with a list of its indices (exterior product of indicies)
* or from a binary map of the indicies
* or using the monomial function (Clifford product of indicies)
* or using the pseudoscalar.
(4) -> e12:Eu := e(1) /\ e(2)
(4) e e
1 2
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(5) -> e12:Eu := ee[1,2]
(5) e e
1 2
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(6) -> e12:Eu := eFromBinaryMap(3)
(6) e e
1 2
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(7) -> e12:Eu := monomial(1,[1,2])
(7) e e
1 2
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(8) -> p:Eu := ePseudoscalar()
(8) e e e
1 2 3
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
We can create vectors from a linear sum of its bases and similarly we can
create a bivector from a sum of bases with grade 2:
(9) -> v:Eu := 2*e(1) + 3*e(2) + 4*e(3)
(9) 2e + 3e + 4e
1 2 3
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(10) -> m:Eu := 2*ee[1,2] + 3*ee[1,3] + 4*ee[2,3]
(10) 2e e + 3e e + 4e e
1 2 1 3 2 3
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
If we want a more complicated multivector, then it may be easier to specify
it in one, by using the multivector function. Note that the indices are
specified in binary order,
that is multivector[scalar,e1,e2,e12,e3,e13,e23,e123...] so we only need
specify the multipliers for these:
(11) -> m:Eu := multivector[0,0,0,2,0,3,4,0]
(11) 2e e + 3e e + 4e e
1 2 1 3 2 3
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
\subsection{Algebraic Operations}
Algebraic Operations
We can then do some operations such as:
\begin{list}{}
operator meaning
/\ exterior
\/ regression
* Clifford
lc left contraction
rc right contraction
\end{list}
examples:
(12) -> e1 /\ e2
(12) e e
1 2
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(13) -> e1 /\ e1
(13) 0
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(14) -> e1 \/ e2
(14) 0
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(15) -> e1 \/ e1
(15) 0
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(16) -> lc(e1,e2)
(16) 0
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(17) -> lc(e1,e1)
(17) 1
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(18) -> rc(e1,e2)
(18) 0
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(19) -> rc(e1,e1)
(19) 1
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
\subsection{Functions}
Functions
Here are some functions available for the algebra :
\begin{list}{}
coefficient(%,List NNI) extracts the scalar coefficient of a given basis which is specified by a list of indices.
~(%) Clifford dual
gradeInvolution(%) invert (multiply by -1) vector and modify other grades accordingly
reverse(%) reverse order of basis vectors in each blade
conj(%) equivalent to applying both gradeInvolution and reverse
grade(%) returns an integer representing the maximum grade of the non-zero blades in this multivector. 0 for scalar, 1 for vector and so on.
\end{list}
examples:
(20) -> c:Eu := coefficient(p,[1,2])
(20) 0
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(21) -> c:Eu := coefficient(p,[1,2,3])
(21) 1
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(22) -> ~e12
(22) - 1
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(23) -> gradeInvolution(e12)
(23) e e
1 2
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(24) -> gradeInvolution(p)
(24) - e e e
1 2 3
Type: CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]])
(25) -> grade(p)
(25) 3
Type: PositiveInteger
\subsection{Tables}
Tables
We can produce tables (Cayley table) of the built-in operations, unary and
binary functions by using 'toTable'. The result is a matrix showing all
combinations of the basis for each operand:
(26) -> toTable(lc)$Eu
+1 e e e e e e e e e e e e +
| 1 2 1 2 3 1 3 2 3 1 2 3|
| |
|0 1 0 e 0 e 0 e e |
| 2 3 2 3 |
| |
|0 0 1 - e 0 0 e - e e |
| 1 3 1 3|
| |
|0 0 0 - 1 0 0 0 - e |
(26) | 3 |
| |
|0 0 0 0 1 - e - e e e |
| 1 2 1 2 |
| |
|0 0 0 0 0 - 1 0 e |
| 2 |
| |
|0 0 0 0 0 0 - 1 - e |
| 1 |
| |
+0 0 0 0 0 0 0 - 1 +
Type: Matrix(CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]]))
(27) -> toTable(*)$Eu
+ 1 e e e e e e e e e e e e +
| 1 2 1 2 3 1 3 2 3 1 2 3|
| |
| e 1 e e e e e e e e e e e |
| 1 1 2 2 1 3 3 1 2 3 2 3 |
| |
| e - e e 1 - e e e - e e e e - e e |
| 2 1 2 1 2 3 1 2 3 3 1 3|
| |
| e e - e e - 1 e e e - e e e e - e |
| 1 2 2 1 1 2 3 2 3 1 3 3 |
(27) | |
| e - e e - e e e e e 1 - e - e e e |
| 3 1 3 2 3 1 2 3 1 2 1 2 |
| |
| e e - e - e e e e e e - 1 - e e e |
| 1 3 3 1 2 3 2 3 1 1 2 2 |
| |
| e e e e e - e - e e e e e - 1 - e |
| 2 3 1 2 3 3 1 3 2 1 2 1 |
| |
|e e e e e - e e - e e e e - e - 1 |
+ 1 2 3 2 3 1 3 3 1 2 2 1 +
Type: Matrix(CliffordAlgebra(3,Fraction(Integer),[[1,0,0],[0,1,0],[0,0,1]]))
\subsection{Debugging}
Debugging
There are some commands to help with debugging:
setMode("orthogonal",false)
The "orthogonal" flag is set to true if the non-diagonal terms in the matrix
are zero. This allows a more optimised Clifford multiplication for this
case. The above setMode command would turn that optimisation off forcing all
multiplications to be done by the more general algorithm. This allows the
output of the two algorithms to be compared.
setMode("debug",true)
This "debug" flag causes the internal working of the algorithms to be
displayed during calculations.
<<domain CLIF CliffordAlgebra>>=
)abbrev domain CLIF CliffordAlgebra
++ Author: Martin Baker (adapted from a version by Stephen M. Watt)
++ Date Created: August 1988
++ Date Last Updated: Feb 2010
++ Basic Operations: wholeRadix, fractRadix, wholeRagits, fractRagits
++ Related Domains: QuadraticForm, Quaternion, Complex
++ Also See:
++ AMS Classifications:
++ Keywords: clifford algebra, grassmann algebra, spin algebra
++ Examples:
++ References:
++
++ Description:
++ CliffordAlgebra(n, K, bLin) defines a module of dimension \spad{2^n}
++ over K, given a bilinear form bLin on \spad{K^n}.
++
++ Examples of Clifford Algebras are: gaussians, quaternions, exterior
++ algebras and spin algebras.
CliffordAlgebra(n, K, bLin): T == Impl where
n: PositiveInteger
K: Field
bLin: SquareMatrix(n, K)
PI ==> PositiveInteger
NNI==> NonNegativeInteger
SINT==> SingleInteger
T ==> Join(Ring, Algebra(K)) with
e: PI -> %
++ e(n) produces phi(e_i) where e_i is i-th basis
++ vector in K^n and phi is canonical embedding of
++ K^n into Clifford algebra.
ee: List PI -> %
++ to allow entries like: ee[1,2]
multivector: List K -> %
++ to allow entries like: 1+2*e1+3*e2+4*e1e2 = multivector[1,2,3,4]
coerce: % -> List(K)
++ coerce to multivector
coerce: List(K) -> %
++ coerce from multivector (same as multivector function above)
eFromBinaryMap: NNI -> %
++ eFromBinaryMap(n) sets the appropriate Grassmann basis, for
++ example:
++ eFromBinaryMap(0) = 1 (scalar)
++ eFromBinaryMap(1) = e1
++ eFromBinaryMap(2) = e2
++ eFromBinaryMap(3) = e1/\e2
ePseudoscalar: () -> %
++ unit pseudoscalar
grade: (%) -> NNI
++ return the max grade of multivector, for example
++ 1 is grade 0
++ e1 is grade 1
++ e1/\e2 is grade 2 and so on
monomial: (K, List PI) -> %
++ monomial(c,[i1,i2,...,iN]) produces the value given by
++ \spad{c*e(i1)*e(i2)*...*e(iN)}.
coefficient: (%, List PI) -> K
++ coefficient(x,[i1,i2,...,iN]) extracts the coefficient of
++ \spad{e(i1)*e(i2)*...*e(iN)} in x.
recip: % -> Union(%, "failed")
++ recip(x) computes the multiplicative inverse of x or "failed"
++ if x is not invertible.
toTable: ((%, %) -> %) -> Matrix %
++ displays multiplication table for binary operation which
++ is represented as a function with two parameters.
++ row number represents first operand in binary order
++ column number represents second operand in binary order
++ could have returned type 'List List %' but matrix displays
++ better
toTable: ((%) -> %) -> Matrix %
++ displays table of unary function such as inverse, reverse,
++ complement, or dual basis
++ could have returned type 'List List %' but matrix displays
++ better
_/_\: (%, %) -> %
++ Implement exterior grassmann product operator
++ need to check precidence when used as an infix operator
_\_/: (%, %) -> %
++ Implement regressive inner,meet product operator
++ need to check precidence when used as an infix operator
lc: (%, %) -> %
++ left contraction inner product
rc: (%, %) -> %
++ right contraction inner product
_~: (%) -> %
++ reverse, complement,canonical dual basis
gradeInvolution: (%) -> %
++ x = ((-1)^grade(x))*x
reverse: (%) -> %
++ implements reverse for a single term by using:
++ grade: 0 1 2 3...
++ multi: 1 1 -1 -1...
conj: (%) -> %
++ implements Clifford conjugate for a multivector by involution
++ and reverse of each term seperately using:
++ grade: 0 1 2 3...
++ multi: 1 -1 -1 1...
setMode: (String,Boolean) -> Boolean
++ allows override of parameters such as orthogonal
++ used for debugging
Impl ==> add
Qeelist:Vector K := diagonal(bLin)::Vector K
++ contains the diagonal terms of bLin (what the base vectors
++ square to)
orthogonal:Boolean := diagonal?(bLin)
++ true if bininear form is diagonal (non diagonal terms are zero)
debug:Boolean := false
++ if set to true displays working when calculating results
dim := 2^n
++ the total dimension of all the grades from scalar up to
++ pseudoscalar
Rep := PrimitiveArray K
++ array of Field which can hold the multivector values
New ==> new(dim, 0$K)$Rep
x, y, z: %
c: K
m: Integer
characteristic() == characteristic()$K
dimension(): CardinalNumber == dim::CardinalNumber
x = y ==
for i in 0..dim-1 repeat
if x.i ~= y.i then return false
true
x + y == (z := New; for i in 0..dim-1 repeat z.i := x.i + y.i; z)
x - y == (z := New; for i in 0..dim-1 repeat z.i := x.i - y.i; z)
- x == (z := New; for i in 0..dim-1 repeat z.i := - x.i; z)
m * x == (z := New; for i in 0..dim-1 repeat z.i := m*x.i; z)
c * x == (z := New; for i in 0..dim-1 repeat z.i := c*x.i; z)
-- we want module over non-commutative
-- but no available signatures for:
--x * m == (z := New; for i in 0..dim-1 repeat z.i := x*m.i; z)
--x * c == (z := New; for i in 0..dim-1 repeat z.i := x*c.i; z)
0 == New
1 == (z := New; z.0 := 1; z)
coerce(m): % == (z := New; z.0 := m::K; z)
coerce(c): % == (z := New; z.0 := c; z)
-- output single term to string
-- this produces a simple one line string unlike coerceMonom
-- no formatting such as subscript is done
-- this is intended mainly for debug purposes
toStringTerm(c: K, b: SINT): String ==
mult:String := (mathObject2String$Lisp c)@String
b = 0 => mult
c = 0 => "0"
if c=1 then mult := "e"
if c= -1 then mult := "-e"
if c~=1 and c~= -1 then mult := concat(mult,"e")
for i in 0..n-1 repeat
if bit?(b,i) then mult := concat(mult,string(i+1)$String)
mult
-- output multivector to string
-- this produces a simple one line string unlike coerce(x): Ex
-- no formatting such as subscript is done
-- this is intended mainly for debug purposes
toString(m:%): String ==
res:String := ""
for im in 0..dim-1 repeat
if m.im ~= 0 then
s:String := (mathObject2String$Lisp m.im)@String
neg:Boolean := false
if #s > 0 then neg := (s.1 = char "-")
if res ~= "" and not neg then
res := concat[res,"+",toStringTerm(m.im,im::SINT)]
if res = "" or neg then
res := concat(res,toStringTerm(m.im,im::SINT))
if res = "" then res:="0"
res
-- e(n) produces the appropriate unit element.
-- iz z
-- e(1) = 1 e1
-- e(2) = 2 e2
-- e(3) = 4 e3
e b ==
b::NNI > n => error "No such basis element"
iz := 2^((b-1)::NNI)
z := New; z.iz := 1; z
-- to allow entries like e[1,2]
ee(l) ==
lst:List % := [e i for i in l]
reduce(_/_\, lst , 1)
-- to allow entries like: 1+2*e1+3*e2+4*e1e2 = multivector[1,2,3,4]
multivector(mv:List K) ==
(z := New; for i in 0..dim-1 repeat z.i := mv(i+1); z)
-- convert multivector (list of multipliers of bases)
-- to a \spadtype{CliffordAlgebra} representation
coerce(mv:List(K)): % ==
(z := New; for i in 0..dim-1 repeat z.i := mv(i+1); z)
-- convert \spadtype{CliffordAlgebra} representation to a
-- multivector (list of multipliers of bases).
coerce(rp:%): List(K) == [rp.i for i in 0..dim-1]
-- eFromBinaryMap(n) sets the appropriate unit elements, for
-- example,
-- eFromBinaryMap(0) = 1 (scalar)
-- eFromBinaryMap(1) = e1
-- eFromBinaryMap(2) = e2
-- eFromBinaryMap(3) = e1/\e2
eFromBinaryMap b ==
b >= dim => error "Too big"
z := New; z.b := 1; z
-- unit pseudoscalar
ePseudoscalar() ==
p := New
i := (dim-1)::NNI
p.i := 1
p
-- displays multiplication table for binary operation which
-- is represented as a function with two parameters.
-- row number represents first operand in binary order
-- column number represents second operand in binary order
-- could have returned type 'List List %' but matrix displays better
toTable(fn:(%, %) -> %) ==
l: List % := [eFromBinaryMap(i) for i in 0..dim-1]
matrix [[fn(k,j) for j in l] for k in l]
-- displays table of unary function such as inverse, reverse,
-- complement, or dual basis
-- could have returned type 'List List %' but matrix displays better
toTable(fn:(%) -> %) ==
l: List % := [eFromBinaryMap(i) for i in 0..dim-1]
matrix [[j for j in l],[fn(k) for k in l]]
-- return the grade of the term, for example
-- 1 is grade 0
-- e1 is grade 1
-- e1^e2 is grade 2 and so on
gradeTerm(b:SINT): NNI ==
grade:NNI := 0
for i in 0..n-1 repeat
if bit?(b,i) then grade := grade + 1
grade
-- return the max grade of multivector, for example
-- 1 is grade 0
-- e1 is grade 1
-- e1/\e2 + e1 is grade 2 and so on
grade(x:%): NNI ==
gr:NNI := 0
for ix in 0..dim-1 repeat
if x.ix ~= 0 then
gr := max(gr,gradeTerm(ix::SINT))
gr
-- implements gradeInvolution for a single term by using:
-- x = ((-1)^grade(x))*x
gradeInvolutionTerm(mult: K,type1:SINT): % ==
resul:% := New; resul.type1:=mult
g:NNI := gradeTerm(type1)
sign:Integer := if odd?(g) then -1 else 1
resul := sign*resul
resul
-- implements gradeInvolution for a multivector by involution
-- of each term seperately using:
-- x = ((-1)^grade(x))*x
gradeInvolution(x:%): % ==
z := New
for ix in 0..dim-1 repeat
if x.ix ~= 0 then z := z + gradeInvolutionTerm(x.ix,ix::SINT)
z
-- implements reverse for a single term by using:
-- grade: 0 1 2 3...
-- multi: 1 1 -1 -1...
reverseTerm(mult: K,type1:SINT): % ==
resul:% := New; resul.type1:=mult
g := gradeTerm(type1)::SINT
sign:Integer := if odd?(shift(g,-1)) then -1 else 1
resul := sign*resul
resul
-- implements reversal for a multivector by reverse
-- of each term seperately using:
-- grade: 0 1 2 3...
-- multi: 1 1 -1 -1...
reverse(x:%): % ==
z := New
for ix in 0..dim-1 repeat
if x.ix ~= 0 then z := z + reverseTerm(x.ix,ix::SINT)
z
-- implements Clifford conjugation for a single term by using:
-- grade: 0 1 2 3...
-- multi: 1 -1 -1 1...
conjTerm(mult: K,type1:SINT): % ==
resul:% := New; resul.type1:=mult
g := gradeTerm(type1)::SINT
sign:Integer := if odd?(shift(g+1,-1)) then -1 else 1
resul := sign*resul
resul
-- implements Clifford conjugate for a multivector by involution
-- and reverse of each term seperately using:
-- grade: 0 1 2 3...
-- multi: 1 -1 -1 1...
conj(x:%): % ==
z := New
for ix in 0..dim-1 repeat
if x.ix ~= 0 then z := z + conjTerm(x.ix,ix::SINT)
z
-- allows override of parameters such as orthogonal
-- used for debugging
setMode(s:String,val:Boolean): Boolean ==
if s = "orthogonal" then (orthogonal := val; return true)
if s = "debug" then (debug := val; return true)
false
-- return the base vector number from binary, for example
-- binary for e1 is 001 which returns 1
-- binary for e2 is 010 which returns 2 and so on
baseVect(b:SINT): NNI ==
for i in 0..n-1 repeat
if bit?(b,i) then return i+1
0
-- return a term from bilinear product
bilinear(b1:SINT,b2:SINT): K ==
bv1 := baseVect(b1)
bv2 := baseVect(b2)
if bv1 = 0$NNI then return 0
if bv2 = 0$NNI then return 0
bLin(bv1,bv2)
-- for a given term, return the base furthest on the left, for
-- example e1^e2^e3 would return e1
leftMostBase(b:SINT): SINT ==
mask:SINT := 1
for i in 0..n-1 repeat
if And(mask,b) ~= 0 then return mask
mask := shift(mask,1)::SINT
0
-- for a given term, return the base furthest on the right, for
-- example e1^e2^e3 would return e3
rightMostBase(b:SINT): SINT ==
mask:SINT := shift(1,(n-1)::SINT)$SINT
for i in 0..n-1 repeat
if And(mask,b) ~= 0 then return mask
mask := shift(mask,-1)::SINT
0
-- Implement exterior grassmann product on individual term in a
-- multivector.
exteriorProdTerm(op1mult: K, op1type:SINT,_
op2mult: K, op2type:SINT): % ==
resul:% := New
-- if common terms return without adding
And(op1type,op2type) ~= 0 => resul
c := op1mult * op2mult
bz := Or(op1type,op2type)-- combine terms from both operands
for i in 0..n-1 | bit?(op1type,i) repeat
-- Apply rule ei*ej = -ej*ei for i ~= j
k := 0
for j in i+1..n-1 | bit?(op1type, j) repeat k := k+1
for j in 0..i-1 | bit?(bz, j) repeat k := k+1
if odd? k then c := -c
resul.bz := resul.bz + c
resul
-- Implement regressive inner,meet product on individual term in a
-- multivector.
regressiveProdTerm(op1mult: K, op1type:SINT,_
op2mult: K, op2type:SINT): % ==
op1 := New; op1.op1type := 1$K
op2 := New; op2.op2type := 1$K
res := _/_\(op2*ePseudoscalar(),_
op1*ePseudoscalar())*ePseudoscalar()
res := (op1mult * op2mult)*res
res
-- Implement exterior grassmann product
_/_\(x:%,y:%): % ==
z := New
for ix in 0..dim-1 repeat
if x.ix ~= 0 then for iy in 0..dim-1 repeat
if y.iy ~= 0 then
z := z + exteriorProdTerm(x.ix,ix::SINT,y.iy,iy::SINT)
z
-- Implement regressive inner,meet product operator
_\_/(x:%,y:%): % ==
z := New
for ix in 0..dim-1 repeat
if x.ix ~= 0 then for iy in 0..dim-1 repeat
if y.iy ~= 0 then
z := z + regressiveProdTerm(x.ix,ix::SINT,y.iy,iy::SINT)
z
-- Implement left contraction on individual term in a
-- multivector.
lcProdTerm(op1mult: K, op1type:SINT, op2mult: K, op2type:SINT): % ==
resul:% := New
grade1 := gradeTerm(op1type) -- grade of first operand
grade2 := gradeTerm(op2type) -- grade of second operand
if grade1 = 0 then
-- 1st operand is scalar so return scalar product
resul.op2type := resul.op2type + op1mult*op2mult
return resul
grade2 = 0 => resul -- 2nd operand is scalar so return 0
if grade1 = 1 and grade2 = 1 then -- vect _| vect = bilinear
-- add scalar term
resul.(0$NNI) := resul.(0$NNI) +_
op1mult * op2mult * bilinear(op1type,op2type)
return resul
if grade1 = 1 then
-- 1st operand is vector so
-- apply: x_|(u^v)=(x_|u)^v - u^(x_|v)
uType:SINT := leftMostBase(op2type) -- highest ^factor
vType:SINT := xor(op2type,uType) -- remaining ^factors
inner2:% := New; inner2.vType := 1$K
left:% := _/_\(lcProdTerm(op1mult, op1type,op2mult, uType),_
inner2)
inner4:% := New; inner4.uType := 1$K
resul := resul + left + _/_\(inner4,_
lcProdTerm(-op1mult, op1type,op2mult, vType))
return resul
-- if none of the above is true then apply:
-- (u/\v) _| w = u _| (v _| w)
uType:SINT := leftMostBase(op1type) -- highest ^factor
vType:SINT := xor(op1type,uType) -- remaining ^factors
inner2:% := New
inner2.uType := 1$K
resul := resul+lc(inner2,lcProdTerm(op1mult,vType,op2mult,op2type))
resul
-- Implement right contraction on individual term in a
-- multivector.
rcProdTerm(op1mult: K, op1type:SINT, op2mult: K, op2type:SINT): % ==
resul:% := New
grade1 := gradeTerm(op1type) -- grade of first operand
grade2 := gradeTerm(op2type) -- grade of second operand
if grade2 = 0 then
-- 2nd operand is scalar so return scalar product
resul.op1type := resul.op1type + op1mult*op2mult
return resul
grade1 = 0 => resul -- 1st operand is scalar so return 0
if grade1 = 1 and grade2 = 1 then -- vect |_ vect = bilinear
resul.(0$NNI) := resul.(0$NNI) +_
op1mult * op2mult * bilinear(op1type,op2type)
-- add scalar term
return resul
if grade2 = 1 then
-- 2nd operand is vector so apply: (v^u)|_x=v^(u|_x) - (v|_x)^u
uType:SINT := rightMostBase(op1type) -- lowest ^factor
vType:SINT := xor(op1type,uType) -- remaining ^factors
inner2:% := New; inner2.vType := 1$K
right:% := _/_\(inner2,rcProdTerm(op1mult, uType,_
op2mult,op2type))
inner4:% := New; inner4.uType := 1$K
resul := resul + _/_\(rcProdTerm(op1mult, vType,_
-op2mult, op2type),inner4) + right
if debug then
s1 := concat[toStringTerm(op1mult,op1type),"L",_
toStringTerm(op2mult,op2type)]
s2 := concat["= ",toStringTerm(op1mult, vType),"L",_
toStringTerm(-op2mult, op2type)]
s3 := concat["/\",toString(inner4),"+",toString(right)]
s4 := concat("=",toString(resul))
sayTeX$Lisp concat ["rcProdTerm: ",s1,s2,s3,s4]
return resul
-- if none of the above is true then apply:
-- w |_ (v/\u) = (w |_ v) |_ u
uType:SINT := rightMostBase(op2type) -- lowest ^factor
vType:SINT := xor(op2type,uType) -- remaining ^factors
inner2:% := New
inner2.uType := 1$K
resul := resul+ rc(rcProdTerm(op1mult,op1type,op2mult,vType),_
inner2)
if debug then
s1 := concat[toStringTerm(op1mult,op1type),"L",_
toStringTerm(op2mult,op2type)]
s2 := concat["= (",toStringTerm(op1mult,op1type),"L",_
toStringTerm(op2mult,vType)]
s3 := concat(") L",toString(inner2))
s4 := concat("=",toString(resul))
sayTeX$Lisp concat ["rcProdTerm: ",s1,s2,s3,s4]
resul
-- Implement left contraction inner product
lc(x:%,y:%): % ==
z := New
for ix in 0..dim-1 repeat
if x.ix ~= 0 then for iy in 0..dim-1 repeat
if y.iy ~= 0 then
z := z + lcProdTerm(x.ix,ix::SINT,y.iy,iy::SINT)
z
-- Implement right contraction inner product
rc(x:%,y:%): % ==
z := New
for ix in 0..dim-1 repeat
if x.ix ~= 0 then for iy in 0..dim-1 repeat
if y.iy ~= 0 then
z := z + rcProdTerm(x.ix,ix::SINT,y.iy,iy::SINT)
z
-- Implement Clifford multiplication on individual term in a
-- multivector.
cliffordProdTerm(op1mult: K, op1type:SINT,_
op2mult: K, op2type:SINT): % ==
resul:% := New
grade1 := gradeTerm(op1type) -- grade of first operand
grade2 := gradeTerm(op2type) -- grade of second operand
if grade1 = 0 then
-- 1st operand is scalar so return scalar product
resul.op2type := resul.op2type + op1mult*op2mult
return resul
if grade2 = 0 then
-- 2nd operand is scalar so return scalar product
resul.op1type := resul.op1type + op1mult*op2mult
return resul
if grade1 = 1 and grade2 = 1 then
-- vect * vect = bilinear + x/\y
resul.(0$NNI) := resul.(0$NNI) + _
op1mult * op2mult * bilinear(op1type,op2type)
-- add scalar term
resul := resul + exteriorProdTerm(op1mult,op1type,_
op2mult,op2type)
-- add exterior term
return resul
if grade1 = 1 then -- 1st operand is vector so apply:
-- x*(u/\v) = x /\ u /\ v + x _| (u/\v)
-- = x/\u/\v + (x_|u)/\v + gradeinvolution(u) /\ (x _| v)
uType:SINT := leftMostBase(op2type) -- highest ^factor
vType:SINT := xor(op2type,uType) -- remaining ^factors
xt:% := New; xt.op1type := 1$K
ut:% := New; ut.uType := 1$K
vt:% := New; vt.vType := 1$K
resul := _/_\(xt,exteriorProdTerm(1$K,uType,1$K,vType))_
+ _/_\(lcProdTerm(1$K,op1type,1$K,uType),vt)_
+ _/_\(gradeInvolutionTerm(1$K,uType),_
lcProdTerm(1$K,op1type,1$K,vType))
-- gradeinvolution(u) /\ (x _| v)
resul := (op1mult*op2mult)*resul -- apply 'scalar' multipliers
return resul
if grade2 = 1 then -- 2nd operand is vector so apply:
-- (v/\u)*x = v /\ u /\ x + rc(v/\u,x)
-- = v/\u/\x + v/\rc(u,x) + rc(u, x)/\ gradeinvolution(v)
uType:SINT := rightMostBase(op1type) -- lowest ^factor
vType:SINT := xor(op1type,uType) -- remaining ^factors
xt:% := New; xt.op2type := 1$K
ut:% := New; ut.uType := 1$K
vt:% := New; vt.vType := 1$K
resul := _/_\(exteriorProdTerm(1$K,vType,1$K,uType),xt)_
+ _/_\(vt,rcProdTerm(1$K,uType,1$K,op2type))_
+ _/_\(rcProdTerm(1$K,vType,1$K,op2type),_
gradeInvolutionTerm(1$K,uType))
-- (v |_ x)/\ gradeinvolution(u)
resul := (op1mult*op2mult)*resul -- apply 'scalar' multipliers
return resul
-- if none of the above is true then apply:
-- (u /\ x) * v = u * (x _| v + x /\v) - (u |_ x) * v
xType:SINT := rightMostBase(op1type) -- highest ^factor
uType:SINT := xor(op1type,xType) -- remaining ^factors
ut:% := New; ut.uType := 1$K
vt:% := New; vt.op2type := 1$K
-- factor1 := x * v = x _| v + x /\v
-- factor1:% := cliffordProdTerm(1$K,xType,1$K,op2type)
factor1:% := lcProdTerm(1$K,xType,1$K,op2type)_
+ exteriorProdTerm(1$K,xType,1$K,op2type)
-- factor2 := u |_ x
factor2:% := rcProdTerm(1$K,uType,1$K,xType)
resul := ut * factor1 - factor2 * vt
if debug then
s1 := concat[toStringTerm(op1mult,op1type),"*",_
toStringTerm(op2mult,op2type)]
s2 := concat["=",toString(ut),"*",toString(factor1)]
s3 := concat["-",toString(factor2),"*",toString(vt)]
s4 := concat["=",toString(resul)]
sayTeX$Lisp concat ["cliffordProdTerm: ",s1,s2,s3,s4]
resul := (op1mult*op2mult)*resul -- apply 'scalar' multipliers
resul
-- Implement Clifford multiplication for orthogonal bases
-- on individual term in a multivector.
-- If the bilinear form is diagonal then this may be
-- more efficient than cliffordProdTerm as it does not
-- require recursion.
-- The ei*ej products could instead be precomputed in
-- a (2^n)^2 multiplication table although only
-- practical for low dimension size.
cliffordDiagonalTerm(op1mult: K, op1type:SINT,_
op2mult: K, op2type:SINT): % ==
c := op1mult * op2mult
bz := op2type
for i in 0..n-1 | bit?(op1type,i) repeat
-- Apply rule ei*ej = -ej*ei for i ~= j
k := 0
for j in i+1..n-1 | bit?(op1type, j) repeat k := k+1
for j in 0..i-1 | bit?(bz, j) repeat k := k+1
if odd? k then c := -c
-- Apply rule ei^2 = Q(ei)
if bit?(bz,i) then
c := c * Qeelist.(i+1)
bz:= bz - (2^i)::SINT
else
bz:= bz + (2^i)::SINT
result := New; result.bz := c
result
-- Clifford product
-- if orthogonal then this operation will use faster algorithm
x * y ==
z := New
if orthogonal then
for ix in 0..dim-1 repeat
if x.ix ~= 0 then for iy in 0..dim-1 repeat