SCM Repository
Annotation of /branches/charisee/src/compiler/ein/equal.sml
Parent Directory
|
Revision Log
Revision 2584 - (view) (download)
1 : | cchiw | 2463 | (*Test transform function*) |
2 : | cchiw | 2553 | structure EqualEin = struct |
3 : | cchiw | 2463 | |
4 : | local | ||
5 : | structure E = Ein | ||
6 : | cchiw | 2553 | structure P=Printer |
7 : | cchiw | 2463 | in |
8 : | |||
9 : | |||
10 : | fun isIndex([],[])=0 | ||
11 : | cchiw | 2576 | | isIndex(i::ix,j::jx)=if(i=j) then isIndex(ix, jx) else (print "Index-false";1) |
12 : | | isIndex _ = 1 | ||
13 : | cchiw | 2463 | |
14 : | fun isEqual(e1,e2)=(case (e1,e2) | ||
15 : | of (E.Field(id,ix),E.Field(id2,ix2))=> if(id=id2) then isIndex(ix, ix2) else 1 | ||
16 : | cchiw | 2553 | | (E.Tensor(id,ix),E.Tensor(id2,ix2))=>(print "Tensor";if(id=id2) then isIndex(ix, ix2) else (print"Tensor-False";1)) |
17 : | cchiw | 2463 | | (E.Const c1,E.Const c2) => |
18 : | if(c1>c2) then 1 | ||
19 : | else if (c2>c1) then 1 | ||
20 : | else 0 | ||
21 : | cchiw | 2496 | | (E.Krn(tid,ix,pos),E.Krn (jid,jx,pos2))=> |
22 : | if(tid=jid) then isIndex(ix,jx)+ isEqual(pos,pos2) | ||
23 : | else 1 | ||
24 : | cchiw | 2463 | | (E.Delta(ix,jx), E.Delta(ix2,jx2))=>isIndex([ix, jx],[ix2, jx2]) |
25 : | cchiw | 2553 | | (E.Epsilon(i,j,k),E.Epsilon(i2,j2,k2))=>(print "EPs-"; |
26 : | isIndex([i,j,k], [i2, j2, k2])) | ||
27 : | cchiw | 2463 | | (E.Neg e1, E.Neg e2)=> isEqual(e1,e2) |
28 : | cchiw | 2496 | | (E.Add es, E.Add es2)=>let |
29 : | cchiw | 2463 | fun filter([],[])=0 |
30 : | | filter(a::ax,b::bx)=let | ||
31 : | val v=isEqual(a,b) | ||
32 : | in if(v>0) then 1 | ||
33 : | else filter(ax,bx) | ||
34 : | end | ||
35 : | in filter(es, es2) | ||
36 : | end | ||
37 : | |||
38 : | | (E.Sub(a,b),E.Sub(c,d))=> isEqual(a,c)+isEqual(b,d) | ||
39 : | | (E.Prod es, E.Prod es2)=>let | ||
40 : | cchiw | 2553 | fun filter([],[])=(print "Prod-true";0) |
41 : | cchiw | 2463 | | filter(a::ax,b::bx)=let |
42 : | val v=isEqual(a,b) | ||
43 : | cchiw | 2553 | in if(v>0) then (print "Prod-FALSE-";1) |
44 : | cchiw | 2463 | else filter(ax,bx) |
45 : | end | ||
46 : | in filter(es, es2) end | ||
47 : | | (E.Div(a,b), E.Div(c,d))=>isEqual(a,c)+isEqual(b,d) | ||
48 : | | (E.Partial ix, E.Partial jx)=>isIndex(ix,jx) | ||
49 : | | (E.Apply(a,b),E.Apply(c,d))=> isEqual(a,c)+isEqual(b,d) | ||
50 : | cchiw | 2496 | | (E.Conv(fid,alpha,tid,ix),E.Conv(fid2,alpha2,tid2,jx))=> |
51 : | if(fid=fid2) andalso (tid=tid2) then | ||
52 : | isIndex(alpha,alpha2)+ isIndex(ix,jx) | ||
53 : | else 0 | ||
54 : | cchiw | 2463 | | (E.Probe(a,b),E.Probe(c,d))=> isEqual(a,c)+isEqual(b,d) |
55 : | cchiw | 2496 | | (E.Img(id1,ix1,pos1),E.Img (id2,ix2,pos2))=>let |
56 : | cchiw | 2463 | fun filter([],[])=0 |
57 : | | filter(a::ax,b::bx)=let | ||
58 : | val v=isEqual(a,b) | ||
59 : | in if(v>0) then 1 | ||
60 : | else filter(ax,bx) | ||
61 : | end | ||
62 : | cchiw | 2496 | in filter(pos1, pos2) end |
63 : | cchiw | 2553 | | (E.Sum(c,e1), E.Sum(c2,e2))=> let val gg=isEqual(e1,e2) |
64 : | val ii= (case gg of 0=> print "sum true" |_=> print "Sum-not true") | ||
65 : | cchiw | 2558 | in gg end |
66 : | | (E.Value i, E.Value j)=> isIndex([i],[j]) | ||
67 : | (*| _ =>(print "else";1)*) | ||
68 : | cchiw | 2463 | |
69 : | (*end case*)) | ||
70 : | |||
71 : | |||
72 : | cchiw | 2553 | fun isEinEqual(e1,e2)=let |
73 : | val E.EIN{params, index, body}=e1 | ||
74 : | cchiw | 2584 | (* val pp=print(String.concat["\n IN-EQUAL",P.printerE(e1), P.printerE(e2)])*) |
75 : | cchiw | 2553 | val body1=body |
76 : | val E.EIN{params, index, body}=e2 | ||
77 : | val n=isEqual(body1,body) | ||
78 : | in | ||
79 : | cchiw | 2584 | if(n=0) then (true) |
80 : | else (false) | ||
81 : | cchiw | 2553 | end |
82 : | cchiw | 2463 | end; (* local *) |
83 : | |||
84 : | end (* local *) |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |