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

libalgebra-demo/libalgebra/utils.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 //  utils.h
00015 
00016 
00017 // Include once wrapper
00018 #ifndef DJC_COROPA_LIBALGEBRA_UTILSH_SEEN
00019 #define DJC_COROPA_LIBALGEBRA_UTILSH_SEEN
00020 
00022 template<typename SCA, typename RAT, DEG n_letters, DEG max_degree>
00023 class maps
00024 {
00026         typedef free_tensor_basis<SCA, RAT, n_letters, max_degree> TBASIS;
00028         typedef lie_basis<SCA, RAT, n_letters, max_degree> LBASIS;
00030         typedef typename LBASIS::KEY LKEY;
00032         typedef typename TBASIS::KEY TKEY;
00034         typedef lie<SCA, RAT, n_letters, max_degree> LIE;
00036         typedef free_tensor<SCA, RAT, n_letters, max_degree> TENSOR;
00037 public:
00039         maps(void) {}
00040 public:
00042         inline TENSOR exp(LET l)
00043         {       
00044                 TKEY k; // empty word.
00045                 TENSOR result(k);
00046                 SCA coef(+1);
00047                 DEG i;
00048                 for (i = 1; i <= max_degree; ++i)
00049                 {
00050                         coef /= (RAT)i;
00051                         k.push_back(l);
00052                         result[k] = coef;
00053                 }
00054                 return result;
00055         }
00057         inline TENSOR l2t(const LIE& arg)
00058         {
00059                 TENSOR result;
00060                 typename LIE::const_iterator i;
00061                 for (i = arg.begin(); i != arg.end(); ++i)
00062                         result.add_scal_prod(expand(i->first), i->second);
00063                 return result;
00064         }
00066 
00071         inline LIE t2l(const TENSOR& arg)
00072         {
00073                 LIE result;
00074                 typename TENSOR::const_iterator i;
00075                 for (i = arg.begin(); i != arg.end(); ++i)
00076                         result.add_scal_prod(rbraketing(i->first), i->second);
00077                 typename LIE::iterator j;
00078                 for (j = result.begin(); j != result.end(); ++j)
00079                         j->second /= (RAT)LIE::basis.degree(j->first);          
00080                 return result;
00081         }
00083 
00088         inline const LIE& rbraketing(const TKEY& k)
00089         {
00090                 static boost::recursive_mutex table_access;
00091                 // get exclusive recursive access for the thread 
00092                 boost::lock_guard<boost::recursive_mutex> lock(table_access); 
00093 
00094                 static std::map<TKEY, LIE> lies;
00095                 typename std::map<TKEY, LIE>::iterator it;
00096                 it = lies.find(k);
00097                 if (it == lies.end())
00098                         return lies[k] = _rbraketing(k);
00099                 else
00100                         return it->second;
00101         }
00103 
00108         inline const TENSOR& expand(const LKEY& k)      
00109         {
00110                 static boost::recursive_mutex table_access;
00111                 // get exclusive recursive access for the thread 
00112                 boost::lock_guard<boost::recursive_mutex> lock(table_access); 
00113 
00114                 static std::map<LKEY, TENSOR> table;
00115                 typename std::map<LKEY, TENSOR>::iterator it;
00116                 it = table.find(k);
00117                 if (it == table.end())
00118                         return table[k] = _expand(k);
00119                 else
00120                         return it->second;
00121         }
00122 private:
00124         TENSOR _expand(const LKEY& k)   
00125         {
00126                 if (LIE::basis.letter(k))
00127                         return (TENSOR)TENSOR::basis.keyofletter(LIE::basis.getletter(k));
00128                 return commutator(expand(LIE::basis.lparent(k)),
00129                         expand(LIE::basis.rparent(k)));
00130         }
00132         LIE _rbraketing(const TKEY& k)
00133         {
00134                 if (TENSOR::basis.letter(k))
00135                         return (LIE)LIE::basis.keyofletter(TENSOR::basis.getletter(k));
00136                 return rbraketing(TENSOR::basis.lparent(k))
00137                         * rbraketing(TENSOR::basis.rparent(k));
00138         }
00139 };
00140 
00142 template<typename SCA, typename RAT, DEG n_letters, DEG max_degree>
00143 class cbh
00144 {
00146         typedef free_tensor_basis<SCA, RAT, n_letters, max_degree> TBASIS;
00148         typedef lie_basis<SCA, RAT, n_letters, max_degree> LBASIS;
00150         typedef typename LBASIS::KEY LKEY;
00152         typedef typename TBASIS::KEY TKEY;
00154         typedef lie<SCA, RAT, n_letters, max_degree> LIE;
00156         typedef free_tensor<SCA, RAT, n_letters, max_degree> TENSOR;
00158         typedef maps<SCA, RAT, n_letters, max_degree> MAPS;
00159 public:
00161         mutable MAPS maps;//TJL added mutable
00163         TENSOR empty_tensor;
00165         LIE empty_lie;
00166 public:
00168         cbh(void) {}
00169 public:
00171         inline LIE basic(const std::vector<LET>& s) const
00172         {
00173                 TENSOR tmp(maps.exp(s[0]));
00174                 typename std::string::size_type i;              
00175                 for (i = 1; i < s.size(); ++i)
00176                         tmp *= maps.exp(s[i]);
00177                 return maps.t2l(log(tmp));
00178         }
00180         inline LIE full(const std::vector<LIE*>& lies) const
00181         {
00182                 typename std::vector<LIE*>::size_type i;
00183                 TENSOR tmp(exp(maps.l2t(*lies[0])));
00184                 for (i = 1; i < lies.size(); ++i)
00185                         tmp *= exp(maps.l2t(*lies[i]));
00186                 return maps.t2l(log(tmp));
00187         }
00188 };
00189 
00190 
00191 // Include once wrapper
00192 #endif // DJC_COROPA_LIBALGEBRA_UTILSH_SEEN
00193 
00194 //EOF.

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