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

/export/development/ViennaMath/viennamath/runtime/integral.hpp

Go to the documentation of this file.
00001 #ifndef VIENNAMATH_RUNTIME_INTEGRAL_HPP
00002 #define VIENNAMATH_RUNTIME_INTEGRAL_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 
00021 #include <string>
00022 #include <vector>
00023 #include <math.h>
00024 #include <iostream>
00025 #include <sstream>
00026 #include "viennamath/forwards.h"
00027 #include "viennamath/exception.hpp"
00028 
00033 namespace viennamath
00034 {
00035   
00036   //
00037   // Part 1: Concrete intervals
00038   //
00039   
00041   template <typename InterfaceType>
00042   class op_rt_integral
00043   {
00044       typedef typename InterfaceType::numeric_type    NumericT;
00045     
00046     public:
00047       typedef InterfaceType         interface_type;
00048 
00049       op_rt_integral() : integration_variable_(0) {}
00050 
00056       op_rt_integral(viennamath::rt_interval<InterfaceType> const & interv,
00057                      viennamath::rt_variable<InterfaceType> const & var) : interval_(interv),
00058                                                                            integration_variable_(var) {}
00059 
00065       template <id_type id>
00066       op_rt_integral(viennamath::rt_interval<InterfaceType> const & interv,
00067                      viennamath::ct_variable<id> const & var) : interval_(interv),
00068                                                                 integration_variable_(id) {}
00069 
00071       std::string str() const
00072       {
00073         std::stringstream ss;
00074         
00075         ss << "rt_integral[" << interval_ << ", " << integration_variable_ << "]";
00076         return ss.str();
00077       }
00078       
00080       NumericT apply(NumericT value) const
00081       {
00082         //std::cout << "TODO: Call integration here!" << std::endl;
00083         throw analytic_integration_not_supported_exception();
00084         return value;
00085       }
00086       
00088       bool can_simplify() const { return false; }
00089       
00090       viennamath::rt_interval<InterfaceType> const & interval() const { return interval_; }
00091       viennamath::rt_variable<InterfaceType> const & variable() const { return integration_variable_; }
00092       
00093     private:
00094       viennamath::rt_interval<InterfaceType> interval_;
00095       viennamath::rt_variable<InterfaceType> integration_variable_;
00096   };
00097   
00098   
00099   
00100   //
00101   // Convenience functions with rt_interval:
00102   //
00104   template <typename InterfaceType>
00105   rt_expr<InterfaceType> integral(rt_interval<InterfaceType> const & interv,
00106                                   rt_expr<InterfaceType> const & integrand,
00107                                   rt_variable<InterfaceType> const & var)
00108   {
00109     typedef op_rt_integral<InterfaceType>    OperatorT;
00110     OperatorT op(interv, var);
00111     
00112     return rt_expr<InterfaceType>(new rt_unary_expr<InterfaceType>(integrand.get()->clone(),
00113                                                                    new op_unary<OperatorT, InterfaceType>(op))
00114                                  );
00115   }
00116 
00118   template <typename InterfaceType, id_type id>
00119   rt_expr<InterfaceType> integral(rt_interval<InterfaceType> const & interv,
00120                                   rt_expr<InterfaceType> const & integrand,
00121                                   ct_variable<id> const & var)
00122   {
00123     typedef op_rt_integral<InterfaceType>    OperatorT;
00124     OperatorT op(interv, rt_variable<InterfaceType>(id));
00125     
00126     return rt_expr<InterfaceType>(new rt_unary_expr<InterfaceType>(integrand.get()->clone(),
00127                                                                    new op_unary<OperatorT, InterfaceType>(op))
00128                                  );
00129   }
00130 
00132   template <typename InterfaceType, id_type id>
00133   rt_expr<InterfaceType> integral(rt_interval<InterfaceType> const & interv,
00134                                   rt_binary_expr<InterfaceType> const & integrand,
00135                                   ct_variable<id> const & var)
00136   {
00137     typedef op_rt_integral<InterfaceType>    OperatorT;
00138     OperatorT op(interv, rt_variable<InterfaceType>(id));
00139     
00140     return rt_expr<InterfaceType>(new rt_unary_expr<InterfaceType>(integrand.clone(),
00141                                                                    new op_unary<OperatorT, InterfaceType>(op))
00142                                  );
00143   }
00144   
00145   
00146   //
00147   // Part 2: Symbolic integrals
00148   //
00149   
00151   template <typename InterfaceType>
00152   class op_rt_symbolic_integral
00153   {
00154       typedef typename InterfaceType::numeric_type    NumericT;
00155     
00156     public:
00157       typedef InterfaceType         interface_type;
00158 
00159       op_rt_symbolic_integral() {}
00160 
00161       op_rt_symbolic_integral(viennamath::rt_symbolic_interval<InterfaceType> const & interv) : interval_(interv) {}
00162       
00164       std::string str() const
00165       {
00166         std::stringstream ss;
00167         
00168         ss << "symbolic_integral[" << interval_ << "]";
00169         return ss.str();
00170       }
00171       
00173       NumericT apply(NumericT value) const
00174       {
00175         //std::cout << "TODO: Call integration here!" << std::endl;
00176         throw symbolic_integral_evaluation_not_possible_exception();
00177         return value;
00178       }
00179       
00181       bool can_simplify() const { return false; }
00182       
00184       viennamath::rt_symbolic_interval<InterfaceType> const & interval() const { return interval_; }
00185       
00186     private:
00187       viennamath::rt_symbolic_interval<InterfaceType> interval_;
00188   };
00189   
00190   
00191   //
00192   // Convenience functions with symbolic integrals
00193   //
00195   template <typename InterfaceType>
00196   rt_expr<InterfaceType> integral(rt_symbolic_interval<InterfaceType> const & interv,
00197                                   rt_expr<InterfaceType> const & integrand)
00198   {
00199     typedef op_rt_symbolic_integral<InterfaceType>    OperatorT;
00200     
00201     return rt_expr<InterfaceType>(new rt_unary_expr<InterfaceType>(integrand.get()->clone(),
00202                                                                    new op_unary<OperatorT, InterfaceType>(OperatorT(interv)))
00203                                  );
00204   }
00205 
00207   template <typename InterfaceType>
00208   rt_expr<InterfaceType> integral(rt_symbolic_interval<InterfaceType> const & interv,
00209                                   rt_binary_expr<InterfaceType> const & integrand)
00210   {
00211     typedef op_rt_symbolic_integral<InterfaceType>    OperatorT;
00212     
00213     return rt_expr<InterfaceType>(new rt_unary_expr<InterfaceType>(integrand.clone(),
00214                                                                    new op_unary<OperatorT, InterfaceType>(OperatorT(interv)))
00215                                  );
00216   }
00217 
00219   template <typename InterfaceType>
00220   rt_expr<InterfaceType> integral(rt_symbolic_interval<InterfaceType> const & interv,
00221                                   rt_unary_expr<InterfaceType> const & integrand)
00222   {
00223     typedef op_rt_symbolic_integral<InterfaceType>    OperatorT;
00224     
00225     return rt_expr<InterfaceType>(new rt_unary_expr<InterfaceType>(integrand.clone(),
00226                                                                    new op_unary<OperatorT, InterfaceType>(OperatorT(interv)))
00227                                  );
00228   }
00229 
00231   template <typename InterfaceType, typename T>
00232   rt_expr<InterfaceType> integral(rt_symbolic_interval<InterfaceType> const & interv,
00233                                   rt_constant<T, InterfaceType> const & integrand)
00234   {
00235     typedef op_rt_symbolic_integral<InterfaceType>    OperatorT;
00236     
00237     return rt_expr<InterfaceType>(new rt_unary_expr<InterfaceType>(integrand.clone(),
00238                                                                    new op_unary<OperatorT, InterfaceType>(OperatorT(interv)))
00239                                  );
00240   }
00241 
00243   template <typename InterfaceType>
00244   rt_expr<InterfaceType> integral(rt_symbolic_interval<InterfaceType> const & interv,
00245                                   rt_variable<InterfaceType> const & integrand)
00246   {
00247     typedef op_rt_symbolic_integral<InterfaceType>    OperatorT;
00248     
00249     return rt_expr<InterfaceType>(new rt_unary_expr<InterfaceType>(integrand.clone(),
00250                                                                    new op_unary<OperatorT, InterfaceType>(OperatorT(interv)))
00251                                  );
00252   }
00253 
00255   template <typename InterfaceType>
00256   rt_expr<InterfaceType> integral(rt_symbolic_interval<InterfaceType> const & interv,
00257                                   rt_function_symbol<InterfaceType> const & integrand)
00258   {
00259     typedef op_rt_symbolic_integral<InterfaceType>    OperatorT;
00260     
00261     return rt_expr<InterfaceType>(new rt_unary_expr<InterfaceType>(integrand.clone(),
00262                                                                    new op_unary<OperatorT, InterfaceType>(OperatorT(interv)))
00263                                  );
00264   }
00265 
00266 }
00267 
00268 #endif
00269 

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