summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/pru.hs53
1 files changed, 51 insertions, 2 deletions
diff --git a/examples/pru.hs b/examples/pru.hs
index 4a5104b..fb33962 100644
--- a/examples/pru.hs
+++ b/examples/pru.hs
@@ -164,7 +164,7 @@ contractionF t1 t2 = contraction t1 n1 t2 n2
164 fn = snd . snd . head . dims 164 fn = snd . snd . head . dims
165 165
166 166
167dual vs = foldl' contractionF (leviCivita n) vs 167dualV vs = foldl' contractionF (leviCivita n) vs
168 where n = fst . head . dims . head $ vs 168 where n = fst . head . dims . head $ vs
169 169
170 170
@@ -175,4 +175,53 @@ dual2 = foldl' contractionF (leviCivita 3) [u,v,w]
175contract1b t (n1,n2) = contract1 t n1 n2 175contract1b t (n1,n2) = contract1 t n1 n2
176 176
177dual1' = prod (foldl' contract1b ((leviCivita 3) <*> (u /\ v)) [("1","p'"),("2'","q''")]) (scalar (recip $ fact 2)) 177dual1' = prod (foldl' contract1b ((leviCivita 3) <*> (u /\ v)) [("1","p'"),("2'","q''")]) (scalar (recip $ fact 2))
178dual2' = prod (foldl' contract1b ((leviCivita 3) <*> (u /\ v /\ w)) [("1","p'"),("2'","q''"),("3'","r''")]) (scalar (recip $ fact 3)) \ No newline at end of file 178dual2' = prod (foldl' contract1b ((leviCivita 3) <*> (u /\ v /\ w)) [("1","p'"),("2'","q''"),("3'","r''")]) (scalar (recip $ fact 3))
179
180
181x1 = vector "p" [0,0,1]
182x2 = vector "q" [2,2,2]
183x3 = vector "r" [-3,-1,-1]
184x4 = vector "s" [12,0,3]
185
186raise (T d v) = T (map raise' d) v
187 where raise' (n,(Covariant,s)) = (n,(Contravariant,s))
188 raise' (n,(Contravariant,s)) = (n,(Covariant,s))
189
190dualMV t = prod (foldl' contract1b (lc <*> t) ds) (scalar (recip $ fromIntegral $ fact (length ds)))
191 where
192 lc = leviCivita n
193 nms1 = map (snd.snd) (dims lc)
194 nms2 = map ((++"'").snd.snd) (dims t)
195 ds = zip nms1 nms2
196 n = fst . head . dims $ t
197
198-- intersection of two lines :-)
199-- > raise $ dualMV $ raise $ dualMV (x1/\x2) /\ dualV [x3,x4]
200--(3'^[3]) [24.0,24.0,12.0]
201
202y1 = vector "p" [0,0,0,1]
203y2 = vector "q" [2,2,0,2]
204y3 = vector "r" [-3,-1,0,-1]
205y4 = vector "s" [12,0,0,3]
206
207-- why not in R^4?
208-- > raise $ dualMV $ raise $ dualMV (y1/\y2) /\ dualV [y3,y4]
209-- scalar 0.0
210-- it seems that the sum of ranks must be greater than n :(
211
212asBase r n = filter (\x-> (x==nub x && x==sort x)) $ sequence $ replicate r [1..n]
213
214partF t i = part t (name,i) where name = snd . snd . head . dims $ t
215
216--partL = foldl' partF
217
218niceAS t = filter ((/=0.0).fst) $ zip vals base
219 where vals = map ((`at` 0).ten.foldl' partF t) (map (map pred) base)
220 base = asBase r n
221 r = length (dims t)
222 n = fst . head . dims $ t
223
224z1 = vector "p" [0,0,0,1]
225z2 = vector "q" [1,0,0,1]
226z3 = vector "r" [0,1,0,1]
227z4 = vector "s" [0,0,1,1]