share/tensor/itensor.lisp: make X and D shared lexical variables for the functions...
[maxima.git] / share / tensor / lckdt.mac
blob234078e067b283961941738ab2d5c27bd9aaf6a1
1 /* Copyright (C) 2003 Valerij Pipin <pip@iszf.irk.ru>
2  *
3  * This program is free software; you can redistribute it and/or
4  * modify it under the terms of the GNU General Public License as
5  * published by the Free Software Foundation; either version 2 of
6  * the License, or (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be
9  * useful, but WITHOUT ANY WARRANTY; without even the implied
10  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  * PURPOSE.  See the GNU General Public License for more details.
12  *
13  * Commentary:
14  * Simplification of expressions containing the Levi-Civita symbol.
17 lc2kdt(exp):=block([i1,tem],
18         tem:0,
19         if nterms(exp)=1 then _lc2kdt0(exp)
20         else
21         (
22                 for i1 thru nterms(exp) do
23                         tem:tem+_lc2kdt0(part(exp,i1)),
24                 tem
25         )
28 lc2kdt(exp):=block(
29   [exp:expand(exp),n:nterms(exp)],
30   sum(_lc2kdt0(if n>1 then part(exp,i%) else exp),i%,1,n)
34 _lc2kdt0(exp):=block([temp1:1,temp2:1,temp,i1],
35         if part(exp,0)="-" then for i1 thru length(part(num(exp),1)) do
36         (
37                 temp:part(num(exp),1,i1),
38                 if tenpr(temp) and verbify(name(temp))=levi_civita then
39                 (
40                         temp1:_lcprod(temp1,temp),
41                         temp2:temp2*temp
42                 )
43         )
44         else for i1 thru length(num(exp)) do
45         (
46                 temp:part(num(exp),i1),
47                 if tenpr(temp) and verbify(name(temp))=levi_civita then
48                 (
49                         temp1:_lcprod(temp1,temp),
50                         temp2:temp2*temp
51                 )
52         ),
53         temp1*ratsimp(exp/temp2)
54 );*/
56 _lc2kdt0(exp):=block(
57   [res:1,fre:1,fac],
58   if op(exp)="-" then return(-_lc2kdt0(part(exp,1))),
59   if op(num(exp))#"*" then return(exp),
60   for i thru length(num(exp)) do
61   (
62     fac:part(num(exp),i),
63     if tenpr(fac) and verbify(name(fac))=levi_civita then
64       res:_lcprod(res,fac)
65     else fre:fre*fac
66   ),
67   ratsimp(res*fre)/denom(exp)
70 /*_lcprod(lc1,lc2):=block([temp1,tempk,ln11,lf,l1,l2,l11,l22,lku,lkl],
71         if numberp(lc1) or symbolp(lc1) then lc1*lc2
72         else if tenpr(lc2) then /* so name(LC1)=LC */
73         (
74                 if verbify(name(lc2))=levi_civita and tenpr(lc1) then
75                 (               /* again test if LC1 is a single */
76                         l1:covi(lc1),
77                         l11:conti(lc1),
78                         l2:covi(lc2),
79                         l22:conti(lc2),
80                         lkl:append(l1,l2),
81                         lku:append(l11,l22),
82                         if lkl=[] then
83                         (
84                                 lf:length(l11),
85                                 ln11:makelist(idummy(),i,1,lf),
86                                 (
87                                         tempk:1,
88                                         for i thru lf do
89                                                 tempk:tempk*kdelta([],[ln11[i],l11[i]])
90                                 ),
91                                 kdelta(ln11,l22)*tempk
92                         )
93                         else if lku=[] then
94                         (
95                                 lf:length(l1),
96                                 ln11:makelist(idummy(),i,1,lf),
97                                 (
98                                         tempk:1,
99                                         for i thru lf do
100                                                 tempk:tempk*kdelta([l1[i],ln11[i]],[])
101                                 ),
102                                 kdelta(l2,ln11)*tempk
103                         )
104                         else kdelta(lkl,lku)
105                 )
106                 else lc1*lc2
107         )
108         else
109         (
110                 if numberp(lc2) or symbolp(lc2) then lc2*lc1
111                 else
112                 (
113                         temp1:_extlc(lc1,lc2),
114                         _lcprod(lc1,temp1)*(lc2/temp1)
115                 )
116         )
117 );*/
119 _lcprod(lc1,lc2):=block([temp1,ln11,lf,l1,l2,l11,l22,lku,lkl],
120         if numberp(lc1) or symbolp(lc1) then lc1*lc2
121         else if tenpr(lc2) then /* so name(LC1)=LC */
122         (
123                 if verbify(name(lc2))=levi_civita and tenpr(lc1) then
124                 (               /* again test if LC1 is a single */
125                         l1:covi(lc1),
126                         l11:conti(lc1),
127                         l2:covi(lc2),
128                         l22:conti(lc2),
129                         lkl:append(l1,l2),
130                         lku:append(l11,l22),
131                         if lkl=[] then
132                         (
133                                 lf:length(l11),
134                                 ln11:makelist(idummy(),i,1,lf),
135                                 kdelta(ln11,l22)*prod(ev(imetric)([-ln11[i%],-l11[i%]],[]),i%,1,lf)
136                         )
137                         else if lku=[] then
138                         (
139                                 lf:length(l1),
140                                 ln11:makelist(idummy(),i,1,lf),
141                                 kdelta(l2,ln11)*prod(ev(imetric)([l1[i%],ln11[i%]],[]),i%,1,lf)
142                         )
143                         else kdelta(lkl,lku)
144                 )
145                 else lc1*lc2
146         )
147         else
148         (
149                 if numberp(lc2) or symbolp(lc2) then lc2*lc1
150                 else
151                 (
152                         temp1:_extlc(lc1,lc2),
153                         _lcprod(lc1,temp1)*(lc2/temp1)
154                 )
155         )
159 _extlc(lc1,lc2):=block([temp],
160         if covi(lc1)#[] then
161         (
162                 temp:part(num(lc2),1,1),
163                 if tenpr(temp) and verbify(name(temp))=levi_civita and conti(temp)#[] then temp
164                 else 1.
165         )
166         else
167         (
168                 temp:part(num(lc2),1,1),
169                 if tenpr(temp) and verbify(name(temp))=verbify(name(lc1)) and covi(temp)#[] then temp
170                 else 1.
171         )