(*Test to determine if two EIN expressions are equal * Very trivial approach *) structure EqualEin = struct local structure E = Ein structure P=Printer in val testing = 0 fun testp e=(case testing of 1 => (print(String.concat e);1) | _ => 1 (*end case*)) fun boolToString t=(case t of true => "true" | _ => "false" (*end case*)) (*isEqual:ein_exp*ein_exp->int *) fun isBodyEq(b1,b2)=let (* val _ = testp ["\n equal is body",P.printbody b1,"==",P.printbody b2]*) (*isIndex: mu list *mu list -> int *) fun isIndex([],[])=true | isIndex((E.V i)::ix,(E.V j)::jx)= if(i=j) then isIndex(ix, jx) else false | isIndex((E.C( i,flagi))::ix,(E.C (j,flagj))::jx)= if(i=j) andalso (flagi=flagj) then isIndex(ix, jx) else false | isIndex _ = false fun isKx([],[])=true | isKx((E.V i,_)::ix,(E.V j,_)::jx)= if(i=j) then isKx(ix, jx) else false | isKx((E.C (i,true),_)::ix,(E.C (j,true),_)::jx)= if(i=j) then isKx(ix, jx) else false | isKx((E.C (i,false),_)::ix,(E.C (j,false),_)::jx)= if(i=j) then isKx(ix, jx) else false | isKx _ = false fun isSx([],[])=true | isSx((i,_,_)::ix,(j,_,_)::jx)=if(i=j) then isSx(ix, jx) else false | isSx _ = false fun isEqual(e1,e2)=let fun iter([],[])= true | iter(a::ax,b::bx)=(case isEqual(a,b) of true => iter(ax,bx) | false => false (*end case*)) | iter _ =false fun checkop1(e1,e2)=(case (e1,e2) of (E.Sqrt,E.Sqrt) => true | (E.Neg, E.Neg ) => true | (E.Exp, E.Exp ) => true | (E.Cosine , E.Cosine ) => true | (E.ArcCosine, E.ArcCosine ) => true | (E.Sine , E.Sine ) => true | (E.ArcSine , E.ArcSine ) => true | (E.Tangent , E.Tangent ) => true | (E.ArcTangent , E.ArcTangent) => true | _ => false (*end case*)) fun checkop2(e1,e2)=(case (e1,e2) of (E.Div,E.Div) => true | (E.Sub, E.Sub ) => true | _ => false (*end case*)) fun checkopn(e1,e2)=(case (e1,e2) of (E.Add,E.Add) => true | (E.Prod,E.Prod) => true | _ => false (*end case*)) fun base(b1,b2)= (case (b1, b2) of (E.Const c1,E.Const c2) => (c1=c2) (*end case*)) fun greek(g1, g2) =(case (g1,g2) of (E.Delta(ix,jx), E.Delta(ix2,jx2)) => isIndex([ix, jx],[ix2, jx2]) | (E.Epsilon(i,j,k),E.Epsilon(i2,j2,k2)) => isIndex([E.V i,E.V j,E.V k], [E.V i2, E.V j2, E.V k2]) | (E.Eps2(i,j),E.Eps2(i2,j2)) => isIndex([E.V i,E.V j], [E.V i2, E.V j2]) | _ => false (*end case*)) in (case (e1,e2) of (E.B b1,E.B b2)=> base(b1, b2) | (E.Tensor(id,ix),E.Tensor(id2,ix2)) => (id=id2) andalso isIndex(ix, ix2) | (E.G g1, E.G g2) => greek(g1,g2) | (E.Field(id,ix),E.Field(id2,ix2)) => (id=id2) andalso isIndex(ix, ix2) | (E.Lift e1, E.Lift e2) => isEqual(e1,e2) | (E.Conv(fid,alpha,tid,ix),E.Conv(fid2,alpha2,tid2,jx)) => (fid=fid2) andalso (tid=tid2) andalso isIndex(alpha,alpha2) andalso isIndex(ix,jx) | (E.Partial ix, E.Partial jx) => isIndex(ix,jx) | (E.Apply(a,b),E.Apply(c,d)) => iter([a,b],[c,d]) | (E.Probe(a,b),E.Probe(c,d)) => iter([a,b],[c,d]) | (E.Value i, E.Value j) => isIndex([E.V i],[E.V j]) | (E.Img(id1,ix1,pos1),E.Img (id2,ix2,pos2))=> (id1=id2) andalso iter(pos1, pos2) andalso isIndex(ix1, ix2) | (E.Krn(tid,ix,pos),E.Krn (jid,jx,pos2)) => (tid=jid) andalso isKx(ix,jx) andalso isEqual(pos,pos2) | (E.Sum(c,e1), E.Sum(c2,e2)) => isSx(c,c2) andalso isEqual(e1,e2) | (E.Op1(op1,e1), E.Op1(op2,e2))=> checkop1(op1,op2) andalso isEqual(e1,e2) | (E.Op2(op1,e1,e2), E.Op2(op2,e3,e4))=> checkop2(op1,op2) andalso isEqual(e1,e3) andalso isEqual(e2,e4) | (E.Opn(op1,e1), E.Opn(op2,e2))=> checkopn(op1,op2) andalso iter(e1,e2) | (E.BuildPos(e1,e2),E.BuildPos(e3,e4)) => (e1=e3) andalso isEqual(e2,e4) | (E.EvalKrn del1, E.EvalKrn del2) => (del1=del2) | (E.Holder n1, E.Holder n2) => (n1=n2) | _ => false (*end case*)) end in isEqual(b1,b2) end (*isEinEqual:EIN*EIN-> bool*) fun isEinEqual(e1,e2)=let val b=if(((Ein.index e1)=(Ein.index e2)) andalso ((Ein.params e1)=(Ein.params e2))) then let val body1=E.body e1 val body2=E.body e2 val t= isBodyEq(body1,body2) in t end else false in b end end; (* local *) end (* local *)
Click to toggle
does not end with </html> tag
does not end with </body> tag
The output has ended thus: t end else false in b end end; (* local *) end (* local *)