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

SCM Repository

[diderot] View of /branches/charisee/src/compiler/ein/operators.sml
ViewVC logotype

View of /branches/charisee/src/compiler/ein/operators.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2383 - (download) (annotate)
Thu Jun 13 01:57:34 2013 UTC (8 years, 1 month ago) by cchiw
File size: 5375 byte(s)
added ein
(* examples.sml
 *
 * COPYRIGHT (c) 2012 The Diderot Project (http://diderot-language.cs.uchicago.edu)
 * All rights reserved.
 *)

structure Operators = struct

    local
    structure G = GenericEin
    structure E = Ein
    structure S = Specialize
    structure R = Rewrite
    in
 
 (***************************Generic Operators *********************************)
 
 
 val addScalars= G.EIN{
    params = [G.TEN, G.TEN],
    index = [],
    body = G.Add[G.Tensor(0, []),G.Tensor(1, [])]
 }
 

 
 
(* Adding tensors : < X{\alpha} + Y_{\alpha}>_{\alpha} *)
val addTensor = G.EIN{
     params = [G.TEN, G.TEN],
     index = [G.MX],
     body = G.Add[
        G.Tensor(0, [0]),
        G.Tensor(1, [0])
     ]
     }

(* Adding Fields : < F{\alpha} + G_{\alpha}>_{\alpha} *)
val addField = G.EIN{
    params = [G.FLD,G.FLD], (*changed from tensor to field*)
    index = [G.MX],
    body = G.Add[G.Field(0, [0]),G.Field(1, [0])]
    }
    
val addTenField = G.EIN{
    params = [G.TEN,G.FLD], 
    index = [G.MX],
    body = G.Add[G.Tensor(0, []),G.Field(1, [0])]
    }
    
   
val subScalars = G.EIN{
    params = [G.TEN, G.TEN],
    index = [],
    body = G.Sub(G.Tensor(0, []), G.Tensor(1, []))
    }
    
    
(* Subtracting tensors *)
val subTensor = G.EIN{
     params = [G.TEN, G.TEN],
     index = [G.MX],
     body = G.Sub(G.Tensor(0, [0]), G.Tensor(1, [0]))
     }
     

(* Subtracting Fields *)
val subField = G.EIN{
         params = [G.FLD, G.FLD],
         index = [G.MX],
         body = G.Sub(G.Field(0, [0]), G.Field(1, [0]))
        }

val subTenField = G.EIN{
    params = [G.TEN,G.FLD],
    index = [G.MX],
    body = G.Sub(G.Tensor(0, []),G.Field(1, [0]))
    }
    
    
(* scalar times a scalar product: <s1 * s2> *)
val scalarxscalar = G.EIN{
        params = [G.TEN, G.TEN],    
        index = [],
        body = G.Prod[G.Tensor(0, []),  G.Tensor(1, []) ]
    }

    
(* scalar times tensor product: <s * T_{\alpha}>_{\alpha} *)
val scaleTensor = G.EIN{
        params = [G.TEN, G.TEN],    (* s and T *)
        index = [G.MX],           (* \alpha *)
        body = G.Prod[ G.Tensor(0, []),  G.Tensor(1, [0])  ]
        }
    
val scaleField = G.EIN{
    params = [G.TEN, G.FLD],    (* s and T *)
    index = [G.MX],           (* \alpha *)
    body = G.Prod[ G.Tensor(0, []),  G.Field(1, [0])  ]
    }
    
    

val conv = G.EIN{
    params = [],
    index = [G.MX],
    body= G.Conv("V",[],  "h", 0)
    }

val conv1d = G.EIN{
    params = [],
    index = [],
    body= G.Conv("V",[(3,2)],  "h", 0)
    }
    
    
(* Probe: <F(x)>_{\alpha}   *)
val probe = G.EIN{
             params = [G.FLD],
             index= [G.MX],
             body= G.Probe(G.Field(0, [0]), 1) (* F_{\alpha}  Tensor1 is position*)
        }

    
(*< d F /  d_i>_i *)
val Grad=G.EIN{
    params = [G.FLD],
    index = [G.IX],
    body = G.Apply( G.Partial([0]),G.Field(0,[]))
    }
    

(*  <d F_i /d_i> *)
val Divergence= G.EIN{
    params = [G.FLD],
    index = [G.SX],
    body = G.Sum(1,G.Apply( G.Partial([0]),G.Field(0,[0])))
    }
    




val divOuterProduct=G.EIN{
    params = [G.TEN],
    index = [G.MX,G.IX],
    body = G.Apply( G.Partial([0]),G.Tensor(5,[1]))
    }
    
        

        
 
(* generic inner product: <T_{\alpha i} * T'_{i \beta}>_{\alpha \beta} *)
val innerProduct = G.EIN{
        params = [G.TEN, G.TEN],              (* T and T' *)
        index = [G.MX, G.MX, G.SX],   (* \alpha \beta, i *)
        body = G.Sum(1, G.Prod[
            G.Tensor(0, [0,2]),   (* T_{\alpha i} *)
            G.Tensor(1, [2,1])    (* T'_{i \beta} *)
          ])
      }



(*  <T_{\alpha i j} * T'{i j \beta }>_\alpha \beta       *)
val doubleDot= G.EIN{
        params = [G.TEN,G.TEN],
        index = [G.MX, G.MX, G.SX, G.SX],
        body = G.Sum(2,G.Prod[
           G.Tensor(0, [0,2,3]),
           G.Tensor(1,[2,3,1])
         ])
      }

    
(* Trace: <M_{i, i}>  This one Sx represents both i's*)
    val trace = G.EIN{
    params = [G.TEN],         (* M *)
    index = [G.SX],           (* i *)
    body = G.Sum(1,G.Tensor(0, [0,0]))
    }
    

    
(* Identiy: <\delta_{i j}>_{i j}  *)
    val identity = G.EIN{
    params = [],
    index = [G.IX,G.IX],(*[G.IX,G.IX],  *)       (*MX-i then MX-j*)
    body = G.Delta(0, 1)
    }

(*OuterProduct can between vectors and Tensors
    A_i T_jk=> P_ijk
    T_ij A_k=>P_ijk
    Vector Examples : <T_i * T_j>_ij*)
val outerProduct = G.EIN{
        params = [G.TEN, G.TEN],
        index= [G.MX, G.MX],
        body= G.Prod[
        G.Tensor(0, [0]), (* T_i *)
        G.Tensor(1, [1]) (* T_j  *)
    ]}

    

    
(***************************Ein Terms*********************************)        
(*crossProduct is on 3D vectors *)
val crossProductE = E.EIN{
    params = [E.TEN, E.TEN],
    index= [E.IX(3),E.SX(3), E.SX(3)],
    body=(* E.Sum(2,*) E.Prod[ E.Epsilon(0, 1, 2), E.Tensor(0, [1]),  E.Tensor(1, [2]) ]
    }
 (*Need to examine curl here
val Curl2d=E.EIN{
    params = [E.FLD],
    index = [E.IX, E.SX, E.SX],
    body = E.Sum(2,E.Apply( E.Partial([1]), E.Prod[E.Epsilon(0, 1, 2), E.Field(5,[2])]))
    }
    
val Curl3d=E.EIN{
    params = [E.TEN],
    index = [E.IX, E.SX, E.SX],
    body = E.Sum(2,E.Apply( E.Partial([1]), E.Prod[E.Epsilon(0, 1, 2), E.Field(5,[2])]))
    }
*)
(***************************************************************)

  end; (* local *)

    end (* local *)

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