• Main Page
  • Namespaces
  • Classes
  • Files
  • File List

libalgebra-demo/libalgebra/multi_polynomial.h

00001 /* *************************************************************
00002 
00003 Copyright 2010 Terry Lyons, Stephen Buckley, Djalil Chafai, 
00004 Greg Gyurkó and Arend Janssen. 
00005 
00006 Distributed under the terms of the GNU General Public License, 
00007 Version 3. (See accompanying file License.txt)
00008 
00009 ************************************************************* */
00010 
00011 
00012 
00013 
00014 //multi_polynomial.h
00015 
00016 
00017 #ifndef multi_polynomialH_SEEN
00018 #define multi_polynomialH_SEEN
00019 
00021 
00031 template<typename SCA, typename RAT, DEG n_letters, DEG max_degree>
00032 class multi_polynomial : public algebra<free_monomial_basis<SCA, RAT, n_letters, max_degree> >
00033 {
00034 public:
00036         typedef free_monomial_basis<SCA, RAT, n_letters, max_degree> BASIS;
00038         typedef typename BASIS::KEY KEY;
00040         typedef sparse_vector<BASIS> VECT;
00042         typedef algebra<BASIS> ALG;
00044         typedef typename ALG::iterator iterator;
00046         typedef typename ALG::const_iterator const_iterator;
00047 public:
00049         multi_polynomial(void) {}
00051         multi_polynomial(const multi_polynomial& t)
00052                 : ALG(t) {}
00054         multi_polynomial(const ALG& a)
00055                 : ALG(a) {}
00057         multi_polynomial(const VECT& v)
00058                 : ALG(v) {}     
00060         multi_polynomial(LET letter, const SCA& s)
00061                 : ALG(VECT::basis.keyofletter(letter), s) {}
00063         explicit multi_polynomial(const KEY& k)
00064                 : ALG(k) {}
00066         explicit multi_polynomial(const SCA& s)
00067                 : ALG(VECT::basis.empty_key, s) {}
00068 public:
00070   inline __DECLARE_BINARY_OPERATOR(multi_polynomial,*,*=,SCA)
00072   inline __DECLARE_BINARY_OPERATOR(multi_polynomial,/,/=,RAT)
00074   inline __DECLARE_BINARY_OPERATOR(multi_polynomial,*,*=,multi_polynomial)
00076   inline __DECLARE_BINARY_OPERATOR(multi_polynomial,+,+=,multi_polynomial)
00078   inline __DECLARE_BINARY_OPERATOR(multi_polynomial,-,-=,multi_polynomial)
00080   inline __DECLARE_UNARY_OPERATOR(multi_polynomial,-,-,ALG)
00082         inline friend multi_polynomial exp(const multi_polynomial& arg)
00083         {
00084                 // Computes the truncated exponential of arg
00085                 // 1 + arg + arg^2/2! + ... + arg^n/n! where n = max_degree
00086                 static KEY kunit;
00087                 multi_polynomial result(kunit);
00088                 for (DEG i = max_degree; i >= 1; --i)
00089                 {
00090                         result.mul_scal_div(arg, (RAT)i);
00091                         result += (multi_polynomial)kunit;
00092                 }
00093                 return result;
00094         }
00096         inline friend multi_polynomial log(const multi_polynomial& arg)
00097         {
00098                 // Computes the truncated log of arg up to degree max_degree
00099                 // The coef. of the constant term (empty word in the monoid) of arg 
00100                 // is forced to 1.
00101                 // log(arg) = log(1+x) = x - x^2/2 + ... + (-1)^(n+1) x^n/n.
00102                 // max_degree must be > 0
00103                 static KEY kunit;
00104                 multi_polynomial tunit(kunit);
00105                 multi_polynomial x(arg);
00106                 iterator it = x.find(kunit);
00107                 if (it != x.end())
00108                         x.erase(it);
00109                 multi_polynomial result;
00110                 for (DEG i = max_degree; i >= 1; --i)
00111                 {
00112                         if (i % 2 == 0)
00113                                 result.sub_scal_div(tunit, (RAT)i);
00114                         else
00115                                 result.add_scal_div(tunit, (RAT)i);
00116                         result *= x;
00117                 }
00118                 return result;
00119         }
00120 };
00121 
00122 // Include once wrapper
00123 #endif // DJC_COROPA_LIBALGEBRA_TENSORH_SEEN
00124 
00125 //EOF.

Generated on Fri Jan 14 2011 17:50:33 for Rough Differential Equation Solver by  doxygen 1.7.1