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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/high-to-mid/handleEin.sml
ViewVC logotype

View of /branches/charisee/src/compiler/high-to-mid/handleEin.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2923 - (download) (annotate)
Tue Mar 3 15:33:44 2015 UTC (4 years, 4 months ago) by cchiw
File size: 3734 byte(s)
move summation around
(* Expands probe ein
 *
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure handleEin = struct

    local
   
    structure E = Ein
    structure DstIL = MidIL
    structure DstOp = MidOps
    structure P=Printer
    structure T=TransformEin
    structure MidToS=MidToString
    structure DstV = DstIL.Var
    in

    val testing=0
    fun setEin(params,index,body)=Ein.EIN{params=params, index=index, body=body}
    fun assignEinApp(y,params,index,body,args)= (y,DstIL.EINAPP(setEin(params,index,body),args))
    fun assignEinApp(y,params,index,body,args)= (y,DstIL.EINAPP(setEin(params,index,body),args))
      fun iTos i =Int.toString i 
    fun testp n=(case testing
        of 0=> 1
        | _ =>(print(String.concat n);1)
        (*end case*))
    val einappzero=DstIL.EINAPP(setEin([],[],E.Const 0),[])
    fun setEinZero y=  (y,einappzero)

    (* isZero:ein_exp->int
    *  Checks to see if the entire body is 0. If so returns 1.
    *)
    fun isZero e=let
        val _=testp["\n Started Zero",P.printbody e]
        fun iterList []= 1
            | iterList(e1::list)=(case (isZero e1)
            of 0=>0
            | _ => iterList list
            (*end case*))
        fun iterProdList []= 0
        | iterProdList [e1]=isZero e1
        | iterProdList(e1::list)=(case (isZero e1)
            of 1=>1
            | _ => iterList list
            (*end case*))
        val z=(case e
            of E.Tensor _         => 0 
            | E.Add e             => iterList e
            | E.Sub(e1,e2)         => iterList [e1,e2]
            | E.Div(e1,e2)         => iterProdList [e1,e2]
            | E.Sum(_ ,e)          => isZero e
            | E.Prod e             => iterProdList e
            | E.Neg e              => isZero e
            | E.Probe(E.Conv _,_)  => 0
            | E.Sqrt e             => isZero e 
            | E.Const 0            => 1
            | E.Field _            => 1
            | E.Partial _          => 1
            | E.Apply _            => 1
            | E.Lift _             => 1
            | E.Conv _             => 1
            | E.PowInt(e ,_)            => isZero e
            | E.PowReal(e,_)             => isZero e
            | _                    => 0
            (*end case*))
        val _=testp["\n Is it Zero",P.printbody e,"--", iTos z]
        in
            z
        end

    fun z e=String.concat["\n\n Found: ",P.printbody e,"=> 0\n"]
    fun sweep e= (case e
        of E.Tensor _           => e
        | E.Add es             => E.Add(List.map sweep es)
        | E.Sub(e1,e2)         => E.Sub(sweep e1,sweep e2)
        | E.Div(e1,e2)         => E.Div(sweep e1,sweep e2)
        | E.Sum(c ,e)          => E.Sum(c, sweep e)
        | E.Prod es             => E.Prod(List.map sweep es)
        | E.Neg e              => E.Neg(sweep e)
        | E.Probe(E.Conv _,_)  => e
        | E.Sqrt e             => E.Sqrt(sweep e)
        | E.Const _            => e
        | E.ConstR _           => e
        | E.Delta _               => e
        | E.Epsilon _             => e
        | E.Eps2 _                => e
        | E.Field _            => (z e;E.Const 0)
        | E.Partial _          => (z e;E.Const 0)
        | E.Apply _            => (z e;E.Const 0)
        | E.Lift _             => (z e;E.Const 0)
        | E.Conv _             => (z e;E.Const 0)
        | E.PowInt(e ,n)       => E.PowInt(sweep e ,n)
        | E.PowReal(e,n)       => E.PowReal(sweep e ,n)
        | E.Probe _            =>
raise Fail (String.concat["\n Incorrect probe, substition was not made. Is the Field in an if statement? :",P.printbody e])
    (*end case*))
  end; (* local *)

end (* local *)

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