-
Notifications
You must be signed in to change notification settings - Fork 0
/
grgtrans.sl
1789 lines (1586 loc) · 61 KB
/
grgtrans.sl
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
%==========================================================================%
% GRGtrans.sl Formula Translator %
%==========================================================================%
% GRG 3.2 Standard Lisp Source Code (C) 1988-96 Vadim V. Zhytnikov %
%==========================================================================%
% This file is distributed without any warranty. You may modify it but you %
% are not allowed to remove author's name and/or distribute modified file. %
%==========================================================================%
%---------- General GRG Translator ---------------------------------------
% Translation with (ERROR ...) interruption ...
(de translate1!> (lst)
(cond (lst (unievaluate!> (unitra!> lst)))
(t nil)))
% Translation with !!ER!! return ...
(de translate!> (lst)
(prog nil
(cond((null lst)(return nil)))
(setq ![lsrs!] nil)
(setq lst
(errorset!> (list2 'unitra!> (list2 'quote lst))
![erst1!] ![erst2!]))
(cond((atom lst)(prog2(setq ![er!] lst)(return !!er!!))))
(setq lst
(errorset!> (list2 'unievaluate!> (list 'quote(car lst)))
![erst1!] ![erst2!]))
(cond((atom lst)(prog2(setq ![er!] lst)(return !!er!!))))
(return(car lst)) ))
% Translate for equations with !!ER!! return ...
(de translateeq!> (lst)
(prog nil
(cond((null lst)(return nil)))
(setq ![lsrs!] nil)
(setq lst
(errorset!> (list2 'unitraeq!> (list2 'quote lst))
![erst1!] ![erst2!]))
(cond((atom lst)(prog2(setq ![er!] lst)(return !!er!!))))
(setq lst
(errorset!> (list2 'unievaluateeq!> (list 'quote(car lst)))
![erst1!] ![erst2!]))
(cond((atom lst)(prog2(setq ![er!] lst)(return !!er!!))))
(return(car lst)) ))
% Pre-Translation with !!ER!! return ...
(de pretrans!> (lst)
(prog nil
(cond ((null lst) (return nil)))
(setq ![lsrs!] nil)
(setq lst
(errorset!> (list2 'unitra!> (list2 'quote lst))
![erst1!] ![erst2!]))
(cond((atom lst)(prog2(setq ![er!] lst)(return !!er!!))))
(return(car lst)) ))
% Pre-Translation for equations with !!ER!! return ...
(de pretranseq!> (lst)
(prog nil
(cond((null lst)(return nil)))
(setq ![lsrs!] nil)
(setq lst
(errorset!> (list2 'unitraeq!> (list2 'quote lst))
![erst1!] ![erst2!]))
(cond((atom lst)(prog2(setq ![er!] lst)(return !!er!!))))
(return(car lst)) ))
% Pre-Translation with !!ER!! return with external vars ...
(de pretransext!> (lst)
(prog nil
(cond ((null lst) (return nil)))
(setq ![lsrs!] nil)
(setq lst
(errorset!> (list2 'unitraext!> (list2 'quote lst))
![erst1!] ![erst2!]))
(cond((atom lst)(prog2(setq ![er!] lst)(return !!er!!))))
(return(car lst)) ))
% Final translation with !!ER!! return ...
(de fintrans!> (lst)
(prog nil
(setq lst
(errorset!> (list2 'unievaluate!> (list 'quote lst))
![erst1!] ![erst2!]))
(cond((atom lst)(prog2(setq ![er!] lst)(return !!er!!))))
(return(car lst)) ))
% Evaluation with simplification ...
(de unievaluate!> (lst)
(prog2 (setq lst(unieval!> lst))
(cond((null lst) lst)
((zerop(car lst))(cona!> 0 (cdr lst)))
(t(conf!>(car lst)(cdr lst))))))
% Evaluation with simplification for equations ...
(de unievaluateeq!> (lst)
(prog (wl wr)
(setq wl (unievaluate!>(car lst)))
(setq wr (unievaluate!>(cdr lst)))
(cond((and(null wl)(null wr)) (return nil))
((and wl wr (not(eqn(car wl)(car wr))))(err!> 2209)))
(return
(cond((and wl wr)(cons(car wl)(list 'equal (cdr wl) (cdr wr))))
(wl (cons(car wl)(list 'equal (cdr wl) nil)))
(wr (cons(car wr)(list 'equal nil (cdr wr)))) ))))
% Evaluation ...
(de unieval!> (lst)
(cond((atom lst) lst)
((or(numberp(car lst))(pairp(car lst))(null(car lst))) lst)
((flagp (car lst) '!+specexec) (apply (car lst) (cdr lst)))
(t(apply (car lst) (mapcar (cdr lst) (function unieval!>))))))
% Final value predicate ...
(de concrp!> (w)
(cond((or(null w)(numberp(car w))) t) (t nil)))
% Final valies list predicate ...
(de concrpl!> (lst)
(cond((null lst) t)
((or(null(car lst))(numberp(caar lst))) (concrpl!>(cdr lst)))
(t nil)))
% Pre-Translation with ERR interrupt ...
(de unitra!> (lst)
(einstsum!> (unitra0!>(expandsym!> lst)) ![extvar!]))
% Pre-Translation with ERR and external variables ...
(de unitraext!> (lst)
(cond (![extvar!] (unitra!> lst))
(t (prog (w we)
(setq w (einstsum!> (unitra0!>(expandsym!> lst)) nil))
(setq we (freevar!> w nil))
(setq ![extvara!] (reverse we))
(return w)))))
% Pre-Translation with ERR interrupt for equations ...
(de unitraeq!> (lst)
(cond((or (null(setq lst (seek1!> lst '!=)))
(null(cdr lst)) (null(car lst)) )
(err!> 2208))
(t(cons(unitra!>(reverse(car lst)))(unitra!>(cdr lst))))))
%---------- Einstein Summation -------------------------------------------
% This is main function ...
(de einstsum!> (lst we)
(cond((atom lst) lst)
((numberp(car lst)) lst)
((null(freevar!> lst we)) lst) % no any free variables
% Spacial treatment for Sum and Prod since summation
% variables should not be treated as free variables ...
((memq (car lst) '(sumexec!> prodexec!>))
(list3(car lst)(cadr lst)(einstsum!>(caddr lst)
(consmem!>(caaadr lst)we))))
% Product of two expressions A*B. We make summation if
% there is the same free variables in both A and B ...
((flagp(car lst) '!+multop2)(prog (w1 w2 w)
(setq w1 (freevar!> (cadr lst) we))
(setq w2 (freevar!> (caddr lst) we))
(setq w (intersecl!> w1 w2))
(cond((and(null w1)(null w2))(return lst)) % no any free vars
((null w)(return(list3 % empty intersection => no summation
(car lst)
(einstsum!>(cadr lst)we)
(einstsum!>(caddr lst)we))))
(t(return(mkeinsum!> w lst we)))))) % make new sum
% This is function f(A). We make summation if only
% some free variable appear in A at least twice ...
((eq(car lst) 'funapply!>)(prog (w)
(setq w (freevar1!> (caddr lst) we))
(setq w (errsingl!> w nil))
(cond ((null w) (return lst))
(t (return(mkeinsum0!> w lst))))))
% This is sum of terms. Just apply EINSTSUM> to each
% term independently ...
((eq(car lst) 'plus!>)
(list2 (car lst) (einstsum1!> (cadr lst) we)))
% Others ...
(t(cons (car lst) (einstsum1!> (cdr lst) we)))))
% Just apply EINSTSUM> to the each element of list ...
(de einstsum1!> (lst we)
(cond((null lst) nil)
(t(cons (einstsum!> (car lst) we)
(einstsum1!> (cdr lst) we)))))
% Make Summation for Function ...
(de mkeinsum0!> (w lst)
(cond((null(cdr w))
(list3 'sumexec!> (ncons w) lst))
(t(list3 'sumexec!> (ncons(ncons(car w)))
(mkeinsum0!> (cdr w) lst)))))
% Make Summation for product ...
(de mkeinsum!> (w lst we)
(cond((null(cdr w))
(list3 'sumexec!> (ncons w)
(list3 (car lst)
(einstsum!>(cadr lst)(consmem!>(car w)we))
(einstsum!>(caddr lst)(consmem!>(car w)we)))))
(t(list3 'sumexec!> (ncons(ncons(car w)))
(mkeinsum!> (cdr w) lst (consmem!> (car w) we))))))
% Collects all DUMMYVAR!> variables in expr LST ...
% WE - list of vars already excluded from consideration
% Takes into account special forms like Sum, Prod ...
(de freevar!> (lst we)
(cond((atom lst) nil)
((numberp(car lst)) nil)
((eq(car lst) 'dummyvar!>)
(cond((not(memq(cadr lst)we))(cdr lst))))
((memq (car lst) '(sumexec!> prodexec!>))
(freevar!> (caddr lst) (consmem!>(caaadr lst)we)))
(t(appmem!>(freevar!> (car lst) we)
(freevar!> (cdr lst) we)))))
% Like FREEVAR> but repeated vars can be collected twice ...
(de freevar1!> (lst we)
(cond((atom lst) nil)
((numberp(car lst)) nil)
((eq(car lst) 'dummyvar!>)
(cond((not(memq(cadr lst)we))(cdr lst))))
((memq (car lst) '(sumexec!> prodexec!>))
(freevar1!> (caddr lst) (consmem!>(caaadr lst)we)))
(t(append(freevar1!> (car lst) we)
(freevar1!> (cdr lst) we)))))
% Produces Error if some var in the list present only once ...
%(de errsingl!> (w wr)
% (cond ((null w) wr)
% ((memq (car w) wr) (errsingl!> (cdr w) wr))
% ((memq (car w) (cdr w)) (errsingl!> (cdr w) (cons (car w) wr)))
% (t (prog2 (doub!>(car w)) (err!> 2018)))))
% This version just removes single var from the list ...
(de errsingl!> (w wr)
(cond ((null w) wr)
((memq (car w) wr) (errsingl!> (cdr w) wr))
((memq (car w) (cdr w)) (errsingl!> (cdr w) (cons (car w) wr)))
(t (errsingl!> (cdr w) wr))))
% Intersections of two lists ...
(de intersecl!> (w1 w2)
(cond((or(null w1)(null w2)) nil)
(t(proc (w)
(while!> w1
(cond((memq (car w1) w2)(setq w(cons(car w1)w))))
(setq w1(cdr w1)))
(return w)))))
%------- Main Operations Translation -------------------------------------
% Main sum/difference translation with [,] ...
(de unitra0!> (lst)
(cond ((atom lst) (atomtr!> lst)) % atom
((and(pairp lst)(null(cdr lst)))(unitra0!>(car lst))) % next level
(t(proc (w)
(cond((memq '![ lst)(setq lst(vbrctr!> lst)))) % [ , ] ?
(cond((not(memq(car lst) '(!+ !-))) % + - translation
(setq lst(cons '!+ lst))))
(setq w(mems!> '(!+ !-) (reverse lst) nil))
(cond((eq w !!er!!) (err!> 2017)))
(setq w(listra!>(reversip w)))
(return(cond((null(cdr w))(car w))
((concrpl!> w) (plus!> w))
(t(list2 'plus!> w))))))))
% List of Expressions translation with ~~ treatment ...
(de listra!> (lst)
(proc (w)
(while!> lst
(cond
((eq(caaar lst) '!~!~)
(cond((null w) (err!> 2110))
((eq(cdar lst) '!+)
(setq w(cons(list2 're2!>(car w))(cdr w))))
(t(setq w(cons(list2 'im2i!>(car w))(cdr w))))))
((eq(cdar lst) '!+)(setq w(cons(termtr!>(caar lst))w)))
(t(setq w(cons(list2 'minus!> (termtr!>(caar lst)))w))))
(setq lst(cdr lst)))
(return w)))
% Atom translation ...
(de atomtr!> (w)
(cond ((zerop w) nil) % zero
((stringp w)(prog2(doubs!> w) (err!> 2019)))
((or(numberp w)(flagp w '!+grgvar))(cons 0 w))% number or variable
((get w '!=subind) (prog2 % tensorial index
(setq w (get w '!=subind))
(cond((zerop w) nil)
(t(cons 0 w)))))
(t(prog (wn wi wd wss wb) % data component
(setq wss w)
(setq w (explode2 w))
(setq wb (selid!> w nil)) % w - id wb - indices
(setq wn (incomiv!> w))
(cond
((flagp wn '!+macros3) % it is macro 3 scalar
(cond (wb (doub!> wss) (err!> 2018))
(t (require!> (get wn '!=ndl))
(return (getsac!> wn nil)))))
((flagp wn '!+macros2) % it is macro 2 component
(cond ((null wb) (doub!> wss) (err!> 2018))
(t (return
(funtr!> (list (incom!> w)
(addcomm!> wb wss)) nil)))))
((not(flagp wn '!+ivar)) % it is not an object
(cond ((eq wss '!~!~) (err!> 2110))
(t (return(list2 'dummyvar!> wss))))))
(cond((and(null wb)(get wn '!=idxl))
(return(list2 'dummyvar!> wss))))
(setq wi(mapcar wb 'digorerr!>)) % indixes list
(cond((memq !!er!! wi)
(return(list2 'dummyvar!> wss))))
(cond((eq(goodidxl!> wi (get wn '!=idxl)) !!er!!)
(return(list2 'dummyvar!> wss))))
(require1!> wn)
(cond((and ![umod!] (memq wn '(!#!b !#!e)))
(return(cons (cond((eq wn '!#!b) 1)(t -1))
(mkdx!> (car wi))))))
(return(getsac!> wn wi)) % extracting value
))))
(de addcomm!> (w wss)
(cond ((null (cdr w)) (ncons(addcomm1!> (car w) wss)))
(t (cons (addcomm1!> (car w) wss)
(cons '!, (addcomm!> (cdr w) wss))))))
(de addcomm1!> (w wss)
(cond ((digit w) (compress(ncons w)))
(t (doub!> wss) (err!> 2018))))
% * | /\ _| translation ...
(de termtr!> (lst)
(prog (w wss wo)
(cond((null lst) (err!> 2016)))
(setq w(seek!> lst '( !* !/!\ !_!| !| !. )))
(cond((null w) (return(quotr!> lst))))
(setq wo (get (cadr w) '!=op2))
(setq wss (termtr1!> (cddr w)))
(setq w (quotr!>(reverse (car w))))
(return (cond((and(concrp!> w)(concrp!> wss))
(apply wo (list2 w wss)))
(t (list wo w wss))))))
(de termtr1!> (lst)
(prog (wa wb wo)
(cond((null lst) (err!> 2016)))
(setq wa(seek!> lst '( !* !/!\ !_!| !| !. )))
(cond((null wa) (return(quotr!> lst))))
(setq wo (get (cadr wa) '!=op2))
(setq wb (termtr1!> (cddr wa)))
(setq wa (quotr!>(reverse(car wa))))
(return (cond((and(concrp!> wa)(concrp!> wb))
(apply wo (list2 wa wb)))
(t (list wo wa wb))))))
% / translation ...
(de quotr!> (lst)
(cond((null lst) (err!> 2016))
((not(memq '!/ lst))(exptr!> lst))
(t(prog (w)
(setq w(memlist!> '!/ lst))
(cond((eq w !!er!!) (err!> 2016)))
(setq w (mapcar w 'exptr!>))
(return(quotmk!>(car w)(cdr w)))))))
(de quotmk!> (lst1 lst2)
(cond((null lst2) lst1)
((and(concrp!> lst1)(concrp!>(car lst2)))
(quotmk!> (quoti!> lst1 (car lst2))
(cdr lst2)))
(t(quotmk!> (list 'quoti!> lst1 (car lst2))
(cdr lst2)))))
% ** or ^ translation ...
(de exptr!> (lst)
(prog (w wb)
(cond((null lst) (err!> 2016)))
(setq w(seek!> lst '(!*!* !^) ))
(cond((null w)(return(kertr!> lst))))
(setq wb (exptr!> (cddr w)))
(setq w (kertr!>(reverse(car w))))
(return (cond((and(concrp!> w)(concrp!> wb))
(exp!> w wb))
(t(list 'exp!> w wb))))))
% d # ~ translation ...
(de kertr!> (lst)
(cond((null lst) (err!> 2015))
((pairp(car lst))(cond((cdr lst) (err!> 2014))
(t(unitra0!>(car lst)))))
((not(cdr lst)) (atomtr!>(car lst)))
((get(car lst) '!=sysfun)
(prog (w)
(setq w (get (car lst) '!=sysfun))
(setq lst (kertr!> (cdr lst)))
(return (cond((concrp!> lst) (apply w (ncons lst)))
(t (list2 w lst))))))
(t(funtr!> lst t))))
% [ , ] translation
(de vbrctr!> (lst)
(prog (wa wd w)
(setq lst(seek1!> lst '![ ))
(cond((null(cdr lst)) (err!> 2001)))
(setq wa(car lst)) (setq lst(cdr lst))
(setq lst(seek1!> lst '!] ))
(cond((or(null lst)(null(car lst))) (err!> 2001)))
(setq wd(cdr lst)) (setq lst(car lst))
(setq w(seek1!> lst '!, ))
(cond((or(null w)(null(car w))(null(cdr w))(memq '!, (cdr w)))
(err!> 2001)))
(return(app!> wa (cons 'vbrc!> (cons(reverse lst) wd))))))
% Function translation ...
(de funtr!> (lst bool) % bool=t - einstein summation rule is allowed
(cond((or(null lst)(atom lst)(not(eqn(length lst)2))
(not(idp(car lst))))
(err!> 2021))
((atom(cadr lst))(err!> 2021))
((get (car lst) '!=spectr) % Sum Prod LHS RHS SUB Lim ...
(apply (get (car lst) '!=spectr) (cdr lst)))
(t(prog (w wt wm wx)
(cond((not(or
(eq(car lst) 'vbrc!>)
(flagp (car lst) '!+fun)
(redgood!> (car lst))
(setq wt(get(car lst) '!=macros))
(gettype!> (setq wt (incomiv!>(explode(car lst)))) )))
(prog2(doub!>(car lst)) (err!> 2022))))
(setq w(cond(wt wt)(t (car lst)))) % wt=t - internal variable
(setq lst(cadr lst)) % parameters list
(setq lst(memlist!> '!, lst))
(cond((eq lst !!er!!) (err!> 2020)))
(cond((and wt (get wt '!=idxl))(prog2 % if internal var =>
(setq wm (mapcar lst 'selmani!>)) % indices manipul.
(cond((setq wx(orl!> wm))
(setq lst (mapcar lst 'delmani!>)))))))
(setq lst (mapcar lst (function unitra0!>)))
(return(cond((concrpl!> lst)
(funapply!> w lst wm))
(t(list 'funapply!> w lst wm))))))))
%---------- Indices Manipulations ----------------------------------------
% Selects indices manipulation prefixes ...
(de selmani!> (w)
(cond ((eq (setq w (car w)) '!') 1)
((eq w '!.) 2)
((eq w '!^) 3)
((eq w '!_) 4)
(t nil)))
% Delets iddices manipulation prefixes from expression ...
(de delmani!> (w)
(cond ((flagp (car w) '!+indexman)
(cond ((null(cdr w)) (err!> 2020))
(t (cdr w))))
(t w)))
% Indices manipulations translation ...
(de manitr!> (wf wm) % wf - int.var., wm - manip. types list
(cond ((null(orl!> wm)) nil)
((null(orl!>(setq wm (manitr1!> wm (get wf '!=idxl))))) nil)
(t wm)))
% Manipulation for one index. Prepares action ...
(de manitr1!> (wm wi) % wm - manip.types list, wi - idxl
(cond ((null wm) nil)
(t (cons (manitr2!> (car wm) (car wi))
(manitr1!> (cdr wm) (cdr wi)) ))))
(de manitr2!> (wm wi)
(cond
((null wm) nil)
((enump!> wi) nil)
((eqn wm 1) % ' cvalificator - up
(cond
((and (spinp!> wi) (not(upperp!> wi)))
(require!> '(!#!G)) (ncons(cdr wi))) % .s -> 's
((holpd!> wi) % .g -> 't
(require!> '(!#!G!I !#!D)) 9)
((tetrpd!> wi) % .t -> 't
(require!> '(!#!G!I)) 1)
((holpu!> wi) % 'g -> 't
(require!> '(!#!T)) 5)
(t nil)))
((eqn wm 2) % . cvalificator - down
(cond
((and (spinp!> wi) (upperp!> wi))
(require!> '(!#!G)) (ncons(minus(cdr wi)))) % 's -> .s
((holpu!> wi) % 'g -> .t
(require!> '(!#!G !#!T)) 10)
((tetrpu!> wi) % 't -> .t
(require!> '(!#!G)) 2)
((holpd!> wi) % .g -> .t
(require!> '(!#!D)) 6)
(t nil)))
((eqn wm 3) % ^ cvalificator - g up
(cond
((spinp!> wi) (err!> 9913))
((holpd!> wi) % .g -> 'g
(require!> '(!#!G!I !#!D)) 3)
((tetrpd!> wi) % .t -> 'g
(require!> '(!#!G!I !#!D)) 11)
((tetrpu!> wi) % 't -> 'g
(require!> '(!#!D)) 7)
(t nil)))
((eqn wm 4) % _ cvalificator - g down
(cond
((spinp!> wi) (err!> 9913))
((holpu!> wi) % 'g -> .g
(require!> '(!#!G !#!T)) 4)
((tetrpu!> wi) % 't -> .g
(require!> '(!#!G !#!T)) 12)
((tetrpd!> wi) % .t -> .g
(require!> '(!#!T)) 8)
(t nil)))
))
% Qualified GET data component with ind. manipulations ...
(de getmc!> (w wi wa wm)
(cond ((zerop(gettype!> w))
(cona1!> 0 (getm!> w wi wa wm)))
(t (conf1!> (gettype!> w) (getm!> w wi wa wm)))))
% GET dat component with ind. manipulation ...
(de getm!> (w wi wa wm) % w - int.var. wa - ind.list wm - manipul.
(cond ((null wa) (getsa!> w (reverse wi))) (t
(proc (wc wg wl we wr wo wx)
(setq wl wa) (setq wo wi)
(while!> wm
(cond((null(car wm)) (setq wi(cons(car wl)wi)))
((singlmanp!>(car wm)) (prog2 % the `diagonal' manipulation
(setq wi (cons (rasin!> (car wl) (car wm)) wi))
(setq wc (cons (rasco!> (car wl) (car wm)) wc)) ))
(t(progn (setq we t)
(setq wx t)
(setq wr (getm1!> w wi wl wm)) )))
(exitif wx)
(setq wl (cdr wl))
(setq wm (cdr wm)) )
(cond((null wc)(return(cond(we wr)
(t(getsa!> w(cond
(wo(append(reverse wo)wa))
(t wa)))))))
((null(setq wc(mktimes!> wc))) (return nil))
((zerop(gettype!> w))
(return (mktimes!>(list wc (cond(we wr)
(t(getsa!> w(reverse wi))))))))
(t(return (fndfpr!> wc (cond(we wr)
(t(getsa!> w(reverse wi))))))))
))))
(de getm1!> (w wi wa wm)
(proc (wc wr wt)
(fordim!> m do (prog2
(setq wc (rasco2!> (car wa) m (car wm)))
(cond(wc(prog2
(setq wt(getm!> w (cons m wi) (cdr wa) (cdr wm)))
(cond(wt
(setq wr (cons
(cond((zerop(gettype!> w))
(mktimes!>(list2 wc wt)))
(t(fndfpr!> wc wt))) wr)))))))))
(cond(wr
(cond((zerop(gettype!> w))(return(cons 'plus wr)))
(t(return(dfsum!> wr))))))))
% `Diagonal' manipulation predicate. So in this case we
% do not need make a sum for rasing or lowering of the index ...
(de singlmanp!> (wt) % wt - manipulation type
(cond ((pairp wt) t) % spinorial
((eqn wt 1) (imotop!>)) % m^ab .t -> 't GI
((eqn wt 2) (motop!>)) % m_ab 't -> .t G
((eqn wt 3) (and (imotop!>) (ifdiagp!>))) % g^ab .g -> 'g GI D
((eqn wt 4) (and (motop!>) (fdiagp!>))) % g_ab 'g -> .g G T
((eqn wt 5) (fdiagp!>)) % h^a_m 'g -> 't T
((eqn wt 6) (ifdiagp!>)) % h_a^m .g -> .t D
((eqn wt 7) (ifdiagp!>)) % h^m_a 't -> 'g D
((eqn wt 8) (fdiagp!>)) % h_m^a .t -> .g T
((eqn wt 9) (and (imotop!>) (ifdiagp!>))) % h^am .g -> 't GI D
((eqn wt 10) (and (motop!>) (fdiagp!>))) % h_am 'g -> .t G T
((eqn wt 11) (and (imotop!>) (ifdiagp!>))) % h^ma .t -> 'g GI D
((eqn wt 12) (and (motop!>) (fdiagp!>))) % h_ma 't -> .g G T
(t nil)))
% Index one-to-one map for `diagonl' manipulation ...
(de rasin!> (w wt) % w - index, wt - manipulation type
(cond ((pairp wt) (difference (abs!>(car wt)) w)) % spinorial
((and (imnullp!>) (member wt '(1 3 9 11))) % null inv metric
(rasinst!> w))
((and (mnullp!>) (member wt '(2 4 10 12))) % null metric
(rasinst!> w))
(t w))) % any other
% null indices ...
(de rasinst!> (w)
(cond ((eqn w 0) 1)
((eqn w 1) 0)
((eqn w 2) 3)
((eqn w 3) 2)))
% Multiplier for `diagonal' manipulation ...
(de rasco!> (w wt) % w - index, wt - manipulation type
(cond ((pairp wt) % Spinorial
(cond
((lessp (car wt) 0) (expt -1 w)) % 's -> .s
(t (expt -1 (difference (car wt) w))))) % .s -> 's
((and (mnullp!>) (member wt '(2 4 10 12))) % Null Metric
(cond
((eqn wt 2) (rascost!> w)) % m_ab 't -> .t
((eqn wt 4) (gmetr!> w (rasinst!> w))) % g_mn 'g -> .g
((eqn wt 10) (hlam!> w (rasinst!> w))) % h_am 'g -> .t
((eqn wt 12) (hlam!> (rasinst!> w) w)))) % h_ma 't -> .g
((and (imnullp!>) (member wt '(1 3 9 11))) % Null Inv Metric
(cond
((eqn wt 1) (rascost!> w)) % m^ab .t -> 't
((eqn wt 3) (gimetr!> w (rasinst!> w))) % g^mn .g -> 'g
((eqn wt 9) (huam!> w (rasinst!> w))) % h^am .g -> 't
((eqn wt 11) (huam!> (rasinst!> w) w)))) % h^ma .t -> 'g
(t (rasco2!> w w wt)))) % Any Other
% Null metric ...
(de rascost!> (w)
(cond ((pmmm!>) (cond ((lessp w 2) 1) (t -1)) ) % +---
(t (cond ((lessp w 2) -1) (t 1)) ))) % -+++
% Gives the coefficient for non-daigonal index manipulation ...
(de rasco2!> (wa wm wt) % wm - summation index
(cond ((eqn wt 1) (getimetr!> wa wm)) % m^ab .t -> 't GI
((eqn wt 2) (getmetr!> wa wm)) % m_ab 't -> .t G
((eqn wt 3) (gimetr!> wa wm)) % g^ab .g -> 'g GI D
((eqn wt 4) (gmetr!> wa wm)) % g_ab 'g -> .g G T
((eqn wt 5) (ham!> wa wm)) % h^a_m 'g -> 't T
((eqn wt 6) (hiam!> wa wm)) % h_a^m .g -> .t D
((eqn wt 7) (hiam!> wm wa)) % h^m_a 't -> 'g D
((eqn wt 8) (ham!> wm wa)) % h_m^a .t -> .g T
((eqn wt 9) (huam!> wa wm)) % h^am .g -> 't GI D
((eqn wt 10) (hlam!> wa wm)) % h_am 'g -> .t G T
((eqn wt 11) (huam!> wm wa)) % h^ma .t -> 'g GI D
((eqn wt 12) (hlam!> wm wa)) % h_ma 't -> .g G T
))
%---------- Cvalified simplification -------------------------------------
(de cona!> (w lst)
(cond ((or(null lst)(null(setq lst(zn!>(eval!> lst)))))nil)
(t(cons 0 lst))))
(de conf!> (w lst)
(cond ((or(null lst)(null(setq lst(evalform!> lst))))nil)
(t(cons w lst))))
(de cona1!> (w lst)
(cond ((null lst) nil)
(t (cons 0 lst))))
(de conf1!> (w lst)
(cond ((null lst) nil)
(t (cons w lst))))
%------- Evaluation Functions --------------------------------------------
% Function evaluator ...
(de funapply!> (wf lst wm) % wf - function id or internal data var
(prog (w wi wt) % lst - paramaters, wm - index manipulation
(setq lst (mapcar lst (function unieval!>)))
(cond((eq wf 'vbrc!>) (return(apply 'vbrc!> lst))) % [ , ]
((flagp wf '!+macros)(return(apply wf (ncons lst)))) % macro tensor
((setq wt (gettype!> wf)) (progn % data component
% we need this data ...
(cond ((flagp wf '!+macros2)
(require!> (get wf '!=ndl)))
(t (require1!> wf)))
(setq wi (get wf '!=idxl))
% translating indices ...
(setq lst (mapcar lst (function indextr!>)))
(cond
((eq (goodidxl!> lst wi) !!er!!)
(cond
% index out of range ...
((eqn ![er!] 21022) (err!> ![er!]))
((eqn ![er!] 21023) (err!> ![er!]))
% wrong number of indices ...
(t (return(tryexp!> wf lst wm))))))
% special case: b e in basis mode ...
(cond ((and ![umod!] (memq wf '(!#!b !#!e)))
(return (cons
(cond ((eq wf '!#!b) 1) (t -1))
(mkdx!> (car lst))))))
(cond
((setq wm (manitr!> wf wm)) % ind. manipul.
(return (getmc!> wf nil lst wm)))
(t (return (getsac!> wf lst))))
)))
% and this is really function ...
(setq wt (mapcar lst 'auxfun2!>))
(cond ((memq !!er!! wt) (return(trydistr!> wf lst))))
(return (cons 0 (cons wf wt)))))
(de auxfun2!> (w)
(cond ((null w) 0)
((not(zerop(car w))) !!er!!)
(t (cdr w))))
% Function can be applied distributively to form
% or vector on one and only one argument ...
(de trydistr!> (wf lst)
(proc (wa wb w we wt wr)
(while!> lst
(setq w (car lst))
(cond ((null w) (setq w 0))
((not(zerop(car w))) (go lab))
(t (setq w (cdr w))))
(setq wa (cons w wa))
(setq lst (cdr lst)))
lab
(setq wt (caar lst)) % type
(setq we (cdar lst)) % form or vector expression
(setq lst (cdr lst))
(setq wb (mapcar lst 'auxfun2!>))
(cond ((memq !!er!! wb) (err!> 2023)))
(while!> we
(setq wr (cons (cons (cons wf (app!> wa (cons (caar we) wb)))
(cdar we))
wr))
(setq we (cdr we)))
(return(cons wt (reversip wr)))))
% Trying expand summed indices ...
% wf - int.var., wl - list of indices, wm - list of manipulations
(de tryexp!> (wf wl wm)
(cond ((sp!>) (err!> ![er!])) (t
(proc (wi wll wmm wm1 wl1 wd wss)
(setq wi (get wf '!=idxl)) % idxl
(cond ((null wm) (setq wm (mknlist!> nil (length wi)))))
(while!> wi
(cond
((null wl) (err!> ![er!])) % wrong number of indices
% Summed spinor index ...
((and (spinp!>(car wi)) (greaterp (dimid!>(car wi)) 1))
(setq wd (dimid!>(car wi)))
(while!> (geq wd 1)
(cond ((null wl) (err!> ![er!]))
(t (setq wl1 (cons (car wl) wl1))
(setq wm1 (cons (car wm) wm1))
(setq wl (cdr wl))
(setq wm (cdr wm))))
(setq wd (sub1 wd)))
(setq wll (cons (reverse wl1) wll))
(setq wmm (cons (reverse wm1) wmm))
(setq wl1 nil) (setq wm1 nil))
% Tetrad index ...
((tetrp!>(car wi))
(setq wd 2)
(while!> (geq wd 1)
(cond ((null wl) (err!> ![er!]))
(t (setq wl1 (cons (car wl) wl1))
(setq wm1 (cons (car wm) wm1))
(setq wl (cdr wl))
(setq wm (cdr wm))))
(setq wd (sub1 wd)))
(setq wll (cons (reverse wl1) wll))
(setq wmm (cons (reverse wm1) wmm))
(setq wl1 nil) (setq wm1 nil))
(t
(setq wll (cons (car wl) wll))
(setq wmm (cons (manitr2!> (car wm) (car wi)) wmm))
(setq wl (cdr wl))
(setq wm (cdr wm))))
(setq wi (cdr wi)))
(cond ((or wm wl) (err!> ![er!]))) % wrong number of indices
(setq wi (reverse(get wf '!=idxl)))
(setq wss (signchange!> wll wmm wi))
(setq wm (indexchange!> wll wmm wi))
(setq wl (car wm))
(setq wm (cdr wm))
(return
(cond (wss (minus!>(getmc!> wf nil wl wm)))
(t (getmc!> wf nil wl wm))))
))))
(de signchange!> (wll wmm wi)
(proc (wss)
(while!> wll
(cond
((and (pairp (car wll)) (signchange1!> (car wll) (car wmm) (car wi)))
(setq wss (not wss)) ))
(setq wll (cdr wll))
(setq wmm (cdr wmm))
(setq wi (cdr wi)))
(return wss)))
(de signchange1!> (wl wm wi)
(proc (wss wl1 wm1)
(while!> wl
(setq wm1 (car wm))
(setq wl1 (car wl))
(cond ((or (lessp wl1 0) (greaterp wl1 1)) (err!> 21022))
((or (eqn wm1 3) (eqn wm1 4)) (err!> 9913)))
(cond
((and (eqn wm1 1) (not(upperp!> wi)) (eqn wl1 0)) % index up
(setq wss (not wss)))
((and (eqn wm1 2) (upperp!> wi) (eqn wl1 1)) % index down
(setq wss (not wss))))
(setq wl (cdr wl))
(setq wm (cdr wm)))
(cond ((and (tetrpd!> wi) (not(pmmm!>))) (setq wss (not wss))))
(return wss)))
(de indexchange!> (wl wm wi)
(proc (wll wmm)
(while!> wl
(cond
((pairp(car wl))
(setq wmm (cons nil wmm))
(setq wll (cons (idxchg1!> (car wl) (car wm) (car wi)) wll)))
(t (setq wll (cons (car wl) wll))
(setq wmm (cons (car wm) wmm))))
(setq wl (cdr wl))
(setq wm (cdr wm))
(setq wi (cdr wi)))
(return (cons wll wmm))))
(de idxchg1!> (wl wm wi)
(cond ((spinp!> wi) (idxchg2!> wl wm))
((not(member wl '((0 0)(0 1)(1 0)(1 1)))) !!er!!)
(t (setq wl (list2 (idch1!> (car wl) (car wm))
(idch1!> (cadr wl) (cadr wm))))
(cond ((equal wl '(0 0)) 1)
((equal wl '(1 1)) 0)
((equal wl '(0 1)) 3)
((equal wl '(1 0)) 2) ))))
(de idch1!> (wl wm)
(cond ((and wm (eqn wl 0)) 1)
((and wm (eqn wl 1)) 0)
(t wl)))
(de idxchg2!> (wl wm)
(cond ((null wl) 0)
((car wm) (plus2 (cond ((zerop(car wl)) 1) (t 0))
(idxchg2!> (cdr wl) (cdr wm))))
(t (plus2 (car wl) (idxchg2!> (cdr wl) (cdr wm)))) ))
% Index for data component translation ...
(de indextr!> (w)
(cond((null w) 0)
((not(zerop(car w))) (err!> 20231))
((or(not(numberp(setq w(nz!>(eval!>(cdr w))))))
(lessp w 0)) (err!> 2102))
(t w)))
% Dummy variable evaluation ...
(de dummyvar!> (w)
(cond ((get w '!=subind) (prog2 (setq w (get w '!=subind))
(cond((zerop w) nil)
(t(cons 0 w)))))
(t(prog2(doub!> w) (err!> 2018)))))
% _| execution
(de inpr!> (lst1 lst2)
(cond ((or(null lst1)(null lst2)) nil)
((not(eqn(car lst1) -1)) (err!> 2002))
((eqn(car lst2) -1) (err!> 2003))
((eqn(car lst2) 0) (err!> 2003))
((eqn(car lst2) 1)
(cona1!> 0 (vform1!>(cdr lst1)(cdr lst2))))
(t(conf1!> (sub1(car lst2))
(vform!>(cdr lst1)(cdr lst2))))))
% | execution
(de vef!> (lst1 lst2)
(cond ((or(null lst1)(null lst2)) nil)
((not(eqn(car lst1) -1)) (err!> 20021))
((not(zerop(car lst2))) (err!> 20031))
(t (cona1!> 0 (vfun!>(cdr lst1)(cdr lst2))))))
% . execution
(de vpr!> (lst1 lst2)
(cond ((or (null lst1) (null lst2)) nil)
((and (eqn (car lst1) -1) (eqn (car lst2) -1))
(require!> '( !#!T !#!G ))
(cona1!> 0 (vprod!> (cdr lst1) (cdr lst2))) )
((and (eqn (car lst1) 1) (eqn (car lst2) 1))
(require!> '( !#!D !#!G!I ))
(cona1!> 0 (fprod!> (cdr lst1) (cdr lst2))) )
((and (eqn (car lst1) -1) (eqn (car lst2) 1))
(cona1!> 0 (vform1!> (cdr lst1) (cdr lst2))) )
((and (eqn (car lst1) 1) (eqn (car lst2) -1))
(cona1!> 0 (vform1!> (cdr lst2) (cdr lst1))) )
(t (err!> 2030))))
% d execution
(de dx!> (lst)
(cond ((null lst) nil)
((minusp(car lst)) (err!> 2004))
((and(eqn(car lst)0)(idp(cdr lst))(get(cdr lst) '!=cord))
(cons 1 (cond(![umod!](getel1!> ![xf!] (get (cdr lst) '!=cord)))
(t (mkdx!>(get (cdr lst) '!=cord))))))
((eqn(car lst) 0) (conf1!> 1(dfun!>(cdr lst))))
(t(conf1!> (add1(car lst))
(dex!>(cdr lst))))))
% @ X execution
(de bvec!> (lst)
(cond ((null lst) nil)
((not(zerop(car lst))) (err!> 2013))
((and(idp(cdr lst))(get (cdr lst) '!=cord))
(cons -1 (cond (![umod!]
(getel1!> ![xv!] (get(cdr lst) '!=cord)))
(t (mkdx!>(get (cdr lst) '!=cord))))))
(t(err!> 2013))))
% # execution
(de dualis!> (lst)
(cond ((null lst) nil)
((eqn (car lst) -1) (err!> 2007))
((eqn (car lst) 0) (prog2
(require!> '(!#!V!O!L))
(conf1!> ![dim!] (dual0!>(cdr lst)))))
((eqn (car lst) ![dim!]) (prog2
(require!> '(!#!V!O!L))
(cona1!> 0 (duald!>(cdr lst)))))
(t (prog2
(require!> '(!#!T !#!G !#!V!O!L))
(conf1!> (difference ![dim!] (car lst)) (dual!>(cdr lst)))))))
% / execution
(de quoti!> (lst1 lst2)
(cond ((null lst2) (err!> 2009))
((null lst1) nil)
((not(zerop(car lst2))) (err!> 2011))
((zerop(car lst1))
(cona1!> 0 (list 'quotient (cdr lst1) (cdr lst2))))
(t(conf1!> (car lst1)
(fndfpr!> (list 'quotient 1 (cdr lst2))
(cdr lst1))))))
% + execution
(de plus2!> (lst1 lst2)
(cond((null(setq lst1(unieval!> lst1))) (unieval!> lst2))
((null(setq lst2(unieval!> lst2))) lst1)
((not(eqn(car lst1)(car lst2))) (err!> 2012))
((zerop(car lst1)) (cona1!> 0 (list 'plus(cdr lst1)(cdr lst2))))
(t(conf1!>(car lst1)(dfsum!>(list2(cdr lst1)(cdr lst2)))))))
% + execution
(de plus!> (lst)
(prog (w wt wa)
(foreach!> x in lst do
(cond((setq wa(unieval!> x))(progn
(cond((null wt)(setq wt(car wa))))
(cond((not(eqn wt(car wa))) (err!> 2012)))
(setq w(cons(cdr wa)w))))))
(return(cond((null w) nil)
((zerop wt)(cona1!> 0 (cons 'plus w)))
(t(conf1!> wt (dfsum!> w)))))))
% * execution
(de times2!> (lst1 lst2)
(cond ((or(null lst1)(null lst2)) nil)
((and(zerop(car lst1))(zerop(car lst2)))
(cona1!> 0 (list 'times (cdr lst1)(cdr lst2))))
((and(zerop(car lst1))(not(zerop(car lst2))))
(conf1!> (car lst2)(fndfpr!> (cdr lst1)(cdr lst2))))
((and(zerop(car lst2))(not(zerop(car lst1))))
(conf1!> (car lst1)(fndfpr!> (cdr lst2)(cdr lst1))))
(t (err!> 2010))))
(de times22!> (lst1 lst2)
(cond ((or(null lst1)(null lst2)) nil)
((or(null(setq lst1 (unieval!> lst1)))
(null(setq lst2 (unieval!> lst2)))) nil)
((and(zerop(car lst1))(zerop(car lst2)))
(cona1!> 0 (list 'times (cdr lst1)(cdr lst2))))
((and(zerop(car lst1))(not(zerop(car lst2))))
(conf1!> (car lst2)(fndfpr!> (cdr lst1)(cdr lst2))))
((and(zerop(car lst2))(not(zerop(car lst1))))
(conf1!> (car lst1)(fndfpr!> (cdr lst2)(cdr lst1))))
(t (err!> 2010))))
% - execution
(de minus!> (lst)
(cond ((null lst) nil)
((zerop(car lst)) (cons 0 (chsign!> nil (cdr lst))))
(t(cons (car lst)(chsign!> t (cdr lst))))))
% ~ execution
(de co!> (lst)