Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /branches/charisee/src/compiler/ein/equal.sml
ViewVC logotype

View of /branches/charisee/src/compiler/ein/equal.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3174 - (download) (annotate)
Mon Mar 30 11:46:58 2015 UTC (3 years, 11 months ago) by cchiw
File size: 3926 byte(s)
hack
(*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(e1,e2)=let

        (*isIndex: mu list *mu list -> int *)
        fun isIndex([],[])=true
          | isIndex(i::ix,j::jx)=if(i=j) then isIndex(ix, jx) else false
          | isIndex _ = 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
        in (case (e1,e2)
            of (E.Field(id,ix),E.Field(id2,ix2))        => (id=id2) andalso isIndex(ix, ix2)
            | (E.Tensor(id,ix),E.Tensor(id2,ix2))       => (id=id2) andalso isIndex(ix, ix2) 
            | (E.Const c1,E.Const c2)                   => (c1=c2) 
            | (E.Krn(tid,ix,pos),E.Krn (jid,jx,pos2))   =>
                    (tid=jid) andalso isIndex(ix,jx) andalso isEqual(pos,pos2)
            | (E.Delta(ix,jx), E.Delta(ix2,jx2))        => isIndex([ix, jx],[ix2, jx2])
            | (E.Epsilon(i,j,k),E.Epsilon(i2,j2,k2))    => isIndex([i,j,k], [i2, j2, k2])
            | (E.Eps2(i,j),E.Eps2(i2,j2))               => isIndex([i,j], [i2, j2])
            | (E.Lift e1, E.Lift e2)                    => isEqual(e1,e2)
            | (E.Sqrt c1, E.Sqrt c2)                    => isEqual(c1,c2)
            | (E.Neg e1, E.Neg e2)                      => isEqual(e1,e2)
            | (E.Add es, E.Add es2)                     => iter(es, es2)
            | (E.Sub(a,b),E.Sub(c,d))                   => iter([a,b], [c,d])
            | (E.Prod es, E.Prod es2)                   => iter(es, es2)
            | (E.Div(a,b), E.Div(c,d))                  => iter([a,b], [c,d])
            | (E.Partial ix, E.Partial jx)              => isIndex(ix,jx)
            | (E.Apply(a,b),E.Apply(c,d))               => iter([a,b],[c,d])  
            | (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.Probe(a,b),E.Probe(c,d))               => iter([a,b],[c,d])
            | (E.Img(id1,ix1,pos1),E.Img (id2,ix2,pos2))=>
                  (id1=id2) andalso  iter(pos1, pos2) andalso  isIndex(ix1, ix2)
            | (E.Sum(c,e1), E.Sum(c2,e2))               => isSx(c,c2) andalso isEqual(e1,e2)
            | (E.Value i, E.Value j)                    => isIndex([i],[j])
            | (E.Cosine e1 , E.Cosine e2)               => isEqual(e1,e2)
            | (E.ArcCosine e1, E.ArcCosine e2)          => isEqual(e1,e2)
            | (E.Sine e1 , E.Sine e2)                   => isEqual(e1,e2)
            | (E.ArcSine e1 , E.ArcSine e2)             => isEqual(e1,e2)
            | _                                         => false
            (*end case*))
        end
        in isEqual(e1,e2)
        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
        val _ =testp["\n** In ein equal: ",boolToString b,": " ,P.printbody (E.body e1),"\n\t=?=", P.printbody(E.body e2)]
        in b end



end; (* local *)

    end (* local *)

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0