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 2428 - (download) (annotate)
Wed Sep 18 18:04:04 2013 UTC (7 years, 2 months ago) by cchiw
File size: 7674 byte(s)
 
(* 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 P = Printer
    in
 
 (***************************Generic Operators *********************************)
 
 

val tensorOp= G.EIN{
    params = [G.TEN],
    index = [G.MX],
    body = G.Tensor(0, G.V[0])
 }
 
val FieldOp= G.EIN{
    params = [G.FLD],
    index = [G.MX, G.MX],
    body =G.Field(0, G.V[0],G.V[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, G.V[0]),
        G.Tensor(1, G.V[0])
     ]
}
    
    (* Subtracting tensors *)
val subTensor = G.EIN{
    params = [G.TEN, G.TEN],
    index = [G.MX],
    body = G.Sub(G.Tensor(0, G.V[0]), G.Tensor(1, G.V[0]))
}
    
    
        
    (* Identiy: <\delta_{i j}>_{i j}  *)
val identity = G.EIN{
        params = [],
        index = [G.IX,G.IX],       (*MX-i then MX-j*)
        body = G.Delta[(G.V[0], G.V[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, G.V[0,0]))
}
        
        
        (* 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.V[]),  G.Tensor(1, G.V[0])  ]
}
        
val divideTensor = G.EIN{
        params = [G.TEN,G.TEN],
        index = [G.MX],
        body = G.Div(G.Tensor(0, G.V[0]), G.Tensor(1, G.V[]))
}
    
        (* 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, G.V[0,2]),   (* T_{\alpha i} *)
            G.Tensor(1, G.V[2,1])    (* T'_{i \beta} *)
            ])
 }
            
            
            
            (*  <T_{\alpha i j} * B{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, G.V[0,2,3]),
            G.Tensor(1,G.V[2,3,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.IX, G.IX],
                body= G.Prod[
                G.Tensor(0, G.V[0]), (* T_i *)
                G.Tensor(1, G.V[1]) (* T_j  *)
                ]
}
                
val transpose = G.EIN{
                params = [G.TEN],
                index= [G.IX,G.IX],
                body= G.Tensor(0, G.V[1,0])
}
                
 (*************************Tensor and Fields********************************)
            val addTenField = G.EIN{
            params = [G.TEN,G.FLD],
            index = [],
            body = G.Add[G.Tensor(0, G.V[]),G.Field(1, G.V[],G.V[])]
            }
                
                val subTenField = G.EIN{
                params = [G.TEN,G.FLD],
                index = [],
                body = G.Sub(G.Tensor(0, G.V[]),G.Field(1, G.V[],G.V[]))
                }
                
                
 (************************* Fields ******************************)
    
    (* 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, G.V[0],G.V[]),G.Field(1, G.V[0],G.V[])]
        }
  
        
(* Subtracting Fields *)
val subField = G.EIN{
         params = [G.FLD, G.FLD],
         index = [G.MX],
         body = G.Sub(G.Field(0, G.V[0],G.V[]), G.Field(1, G.V[0],G.V[]))
        }



    

    
val scaleField = G.EIN{
    params = [G.TEN, G.FLD],    (* s and T *)
    index = [G.MX],           (* \alpha *)
    body = G.Prod[ G.Tensor(0, G.V[]),  G.Field(1,G.V[0],G.V[])  ]
    }
    
    
        
        
        val divideField = G.EIN{
        params = [G.FLD],
        index = [G.MX],
        body = G.Div(G.Field(0, G.V[0],G.V[]), G.Tensor(1, G.V[]))
        }
    

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

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





    (* Curl 2d- [0, 2, 2]*)
    (* Curl 3d- [3,3,3]*)
        
val Curl=G.EIN{
        params = [G.FLD],
        index = [G.IX, G.SX, G.SX],
        body = G.Sum(2,G.Apply( G.Partial(G.V[1]), G.Prod[G.Epsilon(0, 1, 2), G.Field(0,G.V[2],G.V[])]))
        }

    

    (*FLD here is bounded to image field, and dimension of h*)
val conv = G.EIN{
    params = [G.FLD],
    index = [G.IX],
    body= G.Conv(G.Field(0,G.V[0],G.V[]),[])
    (*G.Conv(G.Kernel(0,[0]),[])
      body= G.Conv("V",[],  "h", 0)*)
    }
 
    
val conv2 = E.EIN{
    params = [E.FLD([3])],
    index = [E.IX(3)],
    body= E.Conv(E.Field(0,E.V[0],E.V[]),[])
}


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

(***************************Specialized Terms*********************************)
(*crossProduct is on 3D vectors *)
val crossProductE = E.EIN{
    params = [E.TEN, E.TEN],
    index= [E.IX(3),E.SX(0,3), E.SX(0,3)],
    body=E.Prod[ E.Epsilon(0, 1, 2), E.Tensor(0, E.V[1]),  E.Tensor(1, E.V[2]) ]
    }
        
val expanded= E.EIN{
        params = [E.FLD([3]), E.TEN, E.TEN],
        index= [E.IX(3),E.SX(1-1,1), E.SX(1-1,1)],
        body= E.Sum(2,
            E.Prod[
                E.Probe(E.Field(0,E.V[0],E.V[]), E.Pair[ E.Add[E.Tensor(2,E.C[0]), E.Value(1)], E.Add[E.Tensor(2,E.C[1]), E.Value(2)]]),
                E.Probe(E.Kernel([]), E.Sub(E.Tensor(1,E.C[0]), E.Value(1))),
                E.Probe(E.Kernel([]), E.Sub(E.Tensor(1,E.C[1]), E.Value(2)))
            ])
    }
        


(*(F_y/dx - F_x/dy )k*)
        
 val Curl2d=E.EIN{
        params = [E.FLD([2])],
        index = [E.IX(0), E.IX(0),E.IX(0)],
        body = E.Sub(
        E.Apply(E.Partial(E.C[0]), E.Field(0,E.C[1],E.V[])), E.Apply(E.Partial(E.C[1]), E.Field(0,E.C[0], E.V[]))
        )
    }
val r=    List.map P.printerE [conv2,expanded,Curl2d]
     
        




(***************************Deleted Terms*********************************)
        (*
val Curl3d=E.EIN{
        params = [E.TEN],
        index = [E.IX(3), (E.SX(3)), E.SX(3)],
        body = E.Sum(2,E.Apply( E.Partial([1]), E.Prod[E.Epsilon(0, 1, 2), E.Field(0,[2],[])]))
    }
        
        
        
        val divOuterProduct=G.EIN{
        params = [G.TEN],
        index = [G.MX,G.IX],
        body = G.Apply( G.Partial([0]),G.Tensor(0,G.V[1]))
        }
        
        
        
        
        
  *)
        (*2d Curld, i-0 j-2 k-2*)
        (*3d curl each bouned to 3*)
   
        
    
        
(***************************************************************)

  end; (* local *)

    end (* local *)

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