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 3092 - (download) (annotate)
Tue Mar 17 20:02:38 2015 UTC (4 years, 5 months ago) by cchiw
File size: 5675 byte(s)
change det 3x3
(*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 isEqual2(e1,e2)=let
        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 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))               => 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)+ isIndex(ix1, ix2)
            | (E.Sum(c,e1), E.Sum(c2,e2))               => isEqual(e1,e2)
            | (E.Value i, E.Value j)=> isIndex([i],[j])
(*          | (E.PowInt (e1,n1), E.PowInt (e2,n2))      => if(n1=n2) then isEqual(e1,e2) else 1
            | (E.PowReal(e1,n1), E.PowReal (e2,n2))     =>  1
*)

            | _                                         =>1
            (*end case*))
        end
        in isEqual(e1,e2)
        end
    (*isEinEqual:EIN*EIN-> bool*)
    fun isEinEqual(e1,e2)=let


        val body1=E.body e1
        val body2=E.body e2

        val n=isEqual2(body1,body2)
   
        in
            if(n=0) then true
            else  false 
        end


    (*isEqual:ein_exp*ein_exp->int *)
    fun isEqual3(e1,e2,args)=let
    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))        =>let
        val a=List.nth(args,id)
           val b=List.nth(args,id2)
            val _ =print"bunndy"
        in if(id=id2)
            then isIndex(ix, ix2)
            else  (*)if (a=b) then 0 else *)1
        end 
    | (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 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))               => isEqual(a,c)+isEqual(b,d)
    | (E.Conv(fid,alpha,tid,ix),E.Conv(fid2,alpha2,tid2,jx)) =>let
            val a=List.nth(args,tid)
            val b=List.nth(args,tid2)
            in    if(fid=fid2) andalso (tid=tid2)
            then isIndex(alpha,alpha2)+ isIndex(ix,jx)
            else 0 end 
    | (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])
    (*          | (E.PowInt (e1,n1), E.PowInt (e2,n2))      => if(n1=n2) then isEqual(e1,e2) else 1
    | (E.PowReal(e1,n1), E.PowReal (e2,n2))     =>  1
    *)

    | _                                         =>1
    (*end case*))
    end
    in isEqual(e1,e2)
    end
 

end; (* local *)

    end (* local *)

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