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 2867 - (download) (annotate)
Tue Feb 10 06:52:58 2015 UTC (4 years, 5 months ago) by cchiw
File size: 2935 byte(s)
moved split around, added norm to typechecker, added sqrt to ein
(*Test to determine if two EIN expressions are equal
* Very trivial approach
*)
structure  EqualEin = struct

    local
    structure E = Ein
    structure P=Printer
    in
    
    (*isIndex: mu list *mu list -> int *)
    fun isIndex([],[])=0
      | isIndex(i::ix,j::jx)=if(i=j) then isIndex(ix, jx) else 1
      | isIndex _ = 1

    (*isEqual:ein_exp*ein_exp->int *)
    fun isEqual(e1,e2)=let
        fun iter([],[])= 0
          | iter(a::ax,b::bx)=(case isEqual(a,b)
                of 0 => iter(ax,bx)
                | _ =>1
                (*end case*))
        in (case (e1,e2)
            of (E.Field(id,ix),E.Field(id2,ix2))        => if(id=id2) then isIndex(ix, ix2) else 1
            | (E.Tensor(id,ix),E.Tensor(id2,ix2))       => if(id=id2) then isIndex(ix, ix2) else 1
            | (E.Const c1,E.Const c2)                   => if (c1=c2) then 0 else 1 
            | (E.Krn(tid,ix,pos),E.Krn (jid,jx,pos2))   => if(tid=jid)
                                                            then isIndex(ix,jx) + isEqual(pos,pos2)
                                                            else 1
            | (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 e1, E.Sqrt e2)                    => isEqual(e1,e2)
            | (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))               => isEqual(a,c)+isEqual(b,d)
            | (E.Conv(fid,alpha,tid,ix),E.Conv(fid2,alpha2,tid2,jx)) =>
                if(fid=fid2) andalso (tid=tid2)
                then isIndex(alpha,alpha2)+ isIndex(ix,jx)
                else 0 
            | (E.Probe(a,b),E.Probe(c,d))               => isEqual(a,c)+isEqual(b,d)
            | (E.Img(id1,ix1,pos1),E.Img (id2,ix2,pos2))=> iter(pos1, pos2) 
            | (E.Sum(c,e1), E.Sum(c2,e2))               => isEqual(e1,e2)
            | (E.Value i, E.Value j)=> isIndex([i],[j])
            
            | _                                          =>1
            (*end case*))
        end 
    (*isEinEqual:EIN*EIN-> bool*)
    fun isEinEqual(e1,e2)=let
        val body1=E.body e1
        val body2=E.body e2
        val n=isEqual(body1,body2)
        in
            if(n=0) then true
            else  false
        end
  end; (* local *)

    end (* local *)

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