|
GiNaC
1.6.2
|
00001 00005 /* 00006 * GiNaC Copyright (C) 1999-2011 Johannes Gutenberg University Mainz, Germany 00007 * 00008 * This program is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version. 00012 * 00013 * This program is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00021 */ 00022 00023 #ifndef GINAC_INDEXED_H 00024 #define GINAC_INDEXED_H 00025 00026 #include "exprseq.h" 00027 #include "wildcard.h" 00028 00029 #include <map> 00030 00031 namespace GiNaC { 00032 00033 class scalar_products; 00034 class symmetry; 00035 00039 class indexed : public exprseq 00040 { 00041 GINAC_DECLARE_REGISTERED_CLASS(indexed, exprseq) 00042 00043 friend ex simplify_indexed(const ex & e, exvector & free_indices, exvector & dummy_indices, const scalar_products & sp); 00044 friend ex simplify_indexed_product(const ex & e, exvector & free_indices, exvector & dummy_indices, const scalar_products & sp); 00045 friend bool reposition_dummy_indices(ex & e, exvector & variant_dummy_indices, exvector & moved_indices); 00046 00047 // other constructors 00048 public: 00053 indexed(const ex & b); 00054 00060 indexed(const ex & b, const ex & i1); 00061 00068 indexed(const ex & b, const ex & i1, const ex & i2); 00069 00077 indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3); 00078 00087 indexed(const ex & b, const ex & i1, const ex & i2, const ex & i3, const ex & i4); 00088 00097 indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2); 00098 00108 indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3); 00109 00120 indexed(const ex & b, const symmetry & symm, const ex & i1, const ex & i2, const ex & i3, const ex & i4); 00121 00128 indexed(const ex & b, const exvector & iv); 00129 00137 indexed(const ex & b, const symmetry & symm, const exvector & iv); 00138 00139 // internal constructors 00140 indexed(const symmetry & symm, const exprseq & es); 00141 indexed(const symmetry & symm, const exvector & v, bool discardable = false); 00142 indexed(const symmetry & symm, std::auto_ptr<exvector> vp); 00143 00144 // functions overriding virtual functions from base classes 00145 public: 00146 unsigned precedence() const {return 55;} 00147 bool info(unsigned inf) const; 00148 ex eval(int level = 0) const; 00149 ex real_part() const; 00150 ex imag_part() const; 00151 exvector get_free_indices() const; 00152 00154 void archive(archive_node& n) const; 00156 void read_archive(const archive_node& n, lst& syms); 00157 protected: 00158 ex derivative(const symbol & s) const; 00159 ex thiscontainer(const exvector & v) const; 00160 ex thiscontainer(std::auto_ptr<exvector> vp) const; 00161 unsigned return_type() const; 00162 return_type_t return_type_tinfo() const { return op(0).return_type_tinfo(); } 00163 ex expand(unsigned options = 0) const; 00164 00165 // new virtual functions which can be overridden by derived classes 00166 // none 00167 00168 // non-virtual functions in this class 00169 public: 00172 bool all_index_values_are(unsigned inf) const; 00173 00175 exvector get_indices() const; 00176 00178 exvector get_dummy_indices() const; 00179 00183 exvector get_dummy_indices(const indexed & other) const; 00184 00187 bool has_dummy_index_for(const ex & i) const; 00188 00190 ex get_symmetry() const {return symtree;} 00191 00192 protected: 00193 void printindices(const print_context & c, unsigned level) const; 00194 void print_indexed(const print_context & c, const char *openbrace, const char *closebrace, unsigned level) const; 00195 void do_print(const print_context & c, unsigned level) const; 00196 void do_print_latex(const print_latex & c, unsigned level) const; 00197 void do_print_tree(const print_tree & c, unsigned level) const; 00198 void validate() const; 00199 00200 // member variables 00201 protected: 00202 ex symtree; 00203 }; 00204 GINAC_DECLARE_UNARCHIVER(indexed); 00205 00206 00207 class spmapkey { 00208 public: 00209 spmapkey() : dim(wild()) {} 00210 spmapkey(const ex & v1, const ex & v2, const ex & dim = wild()); 00211 00212 bool operator==(const spmapkey &other) const; 00213 bool operator<(const spmapkey &other) const; 00214 00215 void debugprint() const; 00216 00217 protected: 00218 ex v1, v2, dim; 00219 }; 00220 00221 typedef std::map<spmapkey, ex> spmap; 00222 00227 class scalar_products { 00228 public: 00230 void add(const ex & v1, const ex & v2, const ex & sp); 00231 00233 void add(const ex & v1, const ex & v2, const ex & dim, const ex & sp); 00234 00238 void add_vectors(const lst & l, const ex & dim = wild()); 00239 00241 void clear(); 00242 00243 bool is_defined(const ex & v1, const ex & v2, const ex & dim) const; 00244 ex evaluate(const ex & v1, const ex & v2, const ex & dim) const; 00245 void debugprint() const; 00246 00247 protected: 00248 spmap spm; /*< Map from defined scalar product pairs to their values */ 00249 }; 00250 00251 00252 // utility functions 00253 00255 exvector get_all_dummy_indices(const ex & e); 00256 00259 exvector get_all_dummy_indices_safely(const ex & e); 00260 00263 ex rename_dummy_indices_uniquely(exvector & va, const ex & b, bool modify_va = false); 00264 00266 ex rename_dummy_indices_uniquely(const ex & a, const ex & b); 00267 00269 ex rename_dummy_indices_uniquely(const exvector & va, const exvector & vb, const ex & b); 00270 00273 lst rename_dummy_indices_uniquely(const exvector & va, const exvector & vb); 00274 00284 ex expand_dummy_sum(const ex & e, bool subs_idx = false); 00285 00286 } // namespace GiNaC 00287 00288 #endif // ndef GINAC_INDEXED_H