• Main Page
  • Namespaces
  • Data Structures
  • Files
  • File List

/export/development/ViennaMath/viennamath/compiletime/unary_op_tags.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAMATH_COMPILETIME_UNARY_OP_TAGS_HPP
00002 #define VIENNAMATH_COMPILETIME_UNARY_OP_TAGS_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2012, Institute for Microelectronics,
00006                        Institute for Analysis and Scientific Computing,
00007                        TU Wien.
00008                              -----------------
00009                ViennaMath - Symbolic and Numerical Math in C++
00010                              -----------------
00011 
00012    Author:     Karl Rupp                          rupp@iue.tuwien.ac.at
00013 
00014    License:    MIT (X11), see file LICENSE in the ViennaMath base directory
00015 ======================================================================= */
00016 
00017 
00018 
00019 
00020 #include <string>
00021 #include <vector>
00022 #include <math.h>
00023 #include "viennamath/forwards.h"
00024 
00029 namespace viennamath
00030 {
00031   //
00032   // identity
00033   //
00038   template <typename NumericT>
00039   struct op_id
00040   {
00041     static std::string str() { return "id"; }
00042     NumericT apply(NumericT value) const { return value; }
00043     bool can_simplify() const { return true; }
00044   };
00045 
00046   //
00047   // exponential
00048   //
00053   template <typename NumericT>
00054   struct op_exp
00055   {
00056     static std::string str() { return "exp"; }
00057     NumericT apply(NumericT value) const { return ::exp(value); }
00058     bool can_simplify() const { return true; }
00059   };
00060 
00061   //
00062   // sinus
00063   //
00068   template <typename NumericT>
00069   struct op_sin
00070   {
00071     static std::string str() { return "sin"; }
00072     NumericT apply(NumericT value) const { return ::sin(value); }
00073     bool can_simplify() const { return true; }
00074   };
00075   
00076   //
00077   // cosinus
00078   //
00083   template <typename NumericT>
00084   struct op_cos
00085   {
00086     static std::string str() { return "cos"; }
00087     NumericT apply(NumericT value) const { return ::cos(value); }
00088     bool can_simplify() const { return true; }
00089   };
00090   
00091 
00092   //
00093   // tangens
00094   //
00099   template <typename NumericT>
00100   struct op_tan
00101   {
00102     static std::string str() { return "tan"; }
00103     NumericT apply(NumericT value) const { return ::tan(value); }
00104     bool can_simplify() const { return true; }
00105   };
00106   
00107   //
00108   // absolute value
00109   //
00114   template <typename NumericT>
00115   struct op_fabs
00116   {
00117     static std::string str() { return "fabs"; }
00118     NumericT apply(NumericT value) const { return ::fabs(value); }
00119     bool can_simplify() const { return true; }
00120   };
00121 
00122   //
00123   // square root
00124   //
00129   template <typename NumericT>
00130   struct op_sqrt
00131   {
00132     static std::string str() { return "sqrt"; }
00133     NumericT apply(NumericT value) const { return ::sqrt(value); }
00134     bool can_simplify() const { return true; }
00135   };
00136 
00137   
00138   //
00139   // natural logarithm (aka ln())
00140   //
00145   template <typename NumericT>
00146   struct op_log //natural logarithm
00147   {
00148     static std::string str() { return "log"; }
00149     NumericT apply(NumericT value) const { return ::log(value); }
00150     bool can_simplify() const { return true; }
00151   };
00152   
00153   //
00154   // logarithm, base 10
00155   //
00160   template <typename NumericT>
00161   struct op_log10
00162   {
00163     static std::string str() { return "log10"; }
00164     NumericT apply(NumericT value) const { return ::log10(value); }
00165     bool can_simplify() const { return true; }
00166   };
00167   
00169 
00170   //
00171   // gradient:
00172   //
00177   template <typename NumericT>
00178   struct op_gradient
00179   {
00180     static std::string str() { return "grad"; }
00181     
00182     NumericT apply(NumericT value) const
00183     {
00184       throw "Cannot evaluate formal gradient. Use transformations first.";
00185       return 0;
00186     }
00187     bool can_simplify() const { return true; }
00188   };
00189   
00190   
00191   //
00192   // divergence
00193   //
00198   template <typename NumericT>
00199   struct op_divergence
00200   {
00201     static std::string str() { return "div"; }
00202     
00203     NumericT apply(NumericT value) const
00204     {
00205       throw "Cannot evaluate formal divergence. Use transformations first.";
00206       return 0;
00207     }
00208     bool can_simplify() const { return true; }
00209   };
00210 
00211   
00212   //
00213   // symbolic partial derivative with respect to variable<id>:
00214   //
00219   template <typename NumericT>
00220   class op_partial_deriv
00221   {
00222     public:
00223       op_partial_deriv() : id_(0) {}
00224       op_partial_deriv(id_type i) : id_(i) {}
00225       
00226       std::string str() const
00227       {
00228         std::stringstream ss;
00229         ss << "partial_deriv<" << id_ << ">";
00230         return ss.str();
00231       }
00232       
00233       NumericT apply(NumericT value) const
00234       {
00235         throw "Cannot evaluate formal partial derivative. Use transformations first.";
00236         return 0;
00237       }
00238       
00239       bool can_simplify() const { return false; }
00240       
00241       id_type id() const { return id_; }
00242       
00243     private:
00244       id_type id_;
00245   };
00246 
00247   //needed for comparison of unary expressions:
00249   template <typename T>
00250   bool unary_op_equal(op_partial_deriv<T> const & lhs, op_partial_deriv<T> const & rhs) { return lhs.id() == rhs.id(); }
00251   
00252   
00253   
00254   //
00255   // integral:
00256   //
00262   template <typename IntervalType, id_type integration_variable>
00263   class op_ct_integral
00264   {
00265       typedef typename IntervalType::numeric_type    NumericT;
00266     
00267     public:
00268       typedef IntervalType         interval_type;
00269       
00270       static std::string str() { return "symb_int"; }
00271       
00272       NumericT apply(NumericT value) const
00273       {
00274         throw "Cannot evaluate symbolic_integration. Use transformations first.";
00275         return value;
00276       }
00277 
00278       bool can_simplify() const { return false; }
00279 
00280     private:
00281       //IntervalType const & interval;
00282       
00283   };
00284   
00285 }
00286 
00287 #endif
00288 

Generated on Wed Feb 29 2012 21:50:43 for ViennaMath by  doxygen 1.7.1