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 2605 - (download) (annotate)
Wed Apr 30 01:46:09 2014 UTC (7 years, 3 months ago) by cchiw
File size: 3051 byte(s)
code cleanup
(*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 1
    | isIndex _ = 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))       => 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.Lift e1, E.Lift e2)                    => isEqual(e1,e2)
    | (E.Neg e1, E.Neg e2)                      => isEqual(e1,e2)
    | (E.Add es, E.Add es2)                     => let
        fun filter X =(case X
            of ([],[])=> 0
            |(a::ax,b::bx)=>let
                val v=isEqual(a,b)
                in if(v>0) then 1
                    else filter(ax,bx)
                end
            | _ => 1
            (*end case*))
        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 X=(case X
            of ([],[])=> 0
            | (a::ax,b::bx)=>let
                val v=isEqual(a,b)
                in if(v>0) then 1
                    else filter(ax,bx)
                end
            |  _ => 1
            (*end case*))
        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 X=(case X
            of ([],[])=>0
            | (a::ax,b::bx)=> let
                val v=isEqual(a,b)
                in if(v>0) then 1
                else filter(ax,bx)
                end
            |  _ => 1
            (*end case*))
        in filter(pos1, pos2) end
    | (E.Sum(c,e1), E.Sum(c2,e2))               => isEqual(e1,e2)
    | (E.Value i, E.Value j)=> isIndex([i],[j])
    | _                                          =>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), " with ",P.printerE(e2)])*)
    val body1=body
    val E.EIN{params, index, body}=e2
    val n=isEqual(body1,body)
    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