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 2558 - (download) (annotate)
Mon Mar 3 22:55:30 2014 UTC (5 years, 5 months ago) by cchiw
File size: 2801 byte(s)
Added to Eqfn
(*Test transform function*)
structure  EqualEin = struct

    local
    structure E = Ein
    structure P=Printer
    in


fun isIndex([],[])=0
| isIndex(i::ix,j::jx)=if(i=j) then isIndex(ix, jx) else (print "Index-false";1)

fun isEqual(e1,e2)=(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))=>(print "Tensor";if(id=id2) then isIndex(ix, ix2) else (print"Tensor-False";1))
    | (E.Const c1,E.Const c2) =>
            if(c1>c2) then 1
            else if (c2>c1) then 1
            else 0
    | (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))=>(print "EPs-";
        isIndex([i,j,k], [i2, j2, k2]))
    | (E.Neg e1, E.Neg e2)=> isEqual(e1,e2)
    | (E.Add es, E.Add es2)=>let
        fun filter([],[])=0
         | filter(a::ax,b::bx)=let
            val v=isEqual(a,b)
            in if(v>0) then 1
                else filter(ax,bx)
            end
        in filter(es, es2)
        end

    | (E.Sub(a,b),E.Sub(c,d))=> isEqual(a,c)+isEqual(b,d)
    | (E.Prod es, E.Prod es2)=>let
fun filter([],[])=(print "Prod-true";0)
            | filter(a::ax,b::bx)=let
            val v=isEqual(a,b)
            in if(v>0) then (print "Prod-FALSE-";1)
                else filter(ax,bx)
            end
        in filter(es, es2) end 
    | (E.Div(a,b), E.Div(c,d))=>isEqual(a,c)+isEqual(b,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))=>let
            fun filter([],[])=0
            | filter(a::ax,b::bx)=let
            val v=isEqual(a,b)
            in if(v>0) then 1
                else filter(ax,bx)
            end
        in filter(pos1, pos2) end
    | (E.Sum(c,e1), E.Sum(c2,e2))=> let val gg=isEqual(e1,e2)
        val ii= (case gg of 0=> print "sum true" |_=> print "Sum-not true")
        in gg end
    | (E.Value i, E.Value j)=> isIndex([i],[j])
  (*| _ =>(print "else";1)*)

(*end case*))


fun isEinEqual(e1,e2)=let
        val E.EIN{params, index, body}=e1
         val pp=print(String.concat["\n IN-EQUAL",P.printerE(e1), P.printerE(e2)])
        val body1=body
        val E.EIN{params, index, body}=e2
        val n=isEqual(body1,body)
        in
if(n=0) then (print "TRUE";true)
else (print "FALSE";false)
        end
  end; (* local *)

    end (* local *)

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