|
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_IDX_H 00024 #define GINAC_IDX_H 00025 00026 #include "ex.h" 00027 #include "numeric.h" 00028 00029 namespace GiNaC { 00030 00035 class idx : public basic 00036 { 00037 GINAC_DECLARE_REGISTERED_CLASS(idx, basic) 00038 00039 // other constructors 00040 public: 00046 explicit idx(const ex & v, const ex & dim); 00047 00048 // functions overriding virtual functions from base classes 00049 public: 00050 bool info(unsigned inf) const; 00051 size_t nops() const; 00052 ex op(size_t i) const; 00053 ex map(map_function & f) const; 00054 ex evalf(int level = 0) const; 00055 ex subs(const exmap & m, unsigned options = 0) const; 00056 void archive(archive_node& n) const; 00057 void read_archive(const archive_node& n, lst& syms); 00058 protected: 00059 ex derivative(const symbol & s) const; 00060 bool match_same_type(const basic & other) const; 00061 unsigned calchash() const; 00062 00063 // new virtual functions in this class 00064 public: 00067 virtual bool is_dummy_pair_same_type(const basic & other) const; 00068 00069 // non-virtual functions in this class 00070 public: 00072 ex get_value() const {return value;} 00073 00075 bool is_numeric() const {return is_exactly_a<numeric>(value);} 00076 00078 bool is_symbolic() const {return !is_exactly_a<numeric>(value);} 00079 00081 ex get_dim() const {return dim;} 00082 00084 bool is_dim_numeric() const {return is_exactly_a<numeric>(dim);} 00085 00087 bool is_dim_symbolic() const {return !is_exactly_a<numeric>(dim);} 00088 00090 ex replace_dim(const ex & new_dim) const; 00091 00094 ex minimal_dim(const idx & other) const; 00095 00096 protected: 00097 void print_index(const print_context & c, unsigned level) const; 00098 void do_print(const print_context & c, unsigned level) const; 00099 void do_print_csrc(const print_csrc & c, unsigned level) const; 00100 void do_print_latex(const print_latex & c, unsigned level) const; 00101 void do_print_tree(const print_tree & c, unsigned level) const; 00102 00103 protected: 00104 ex value; 00105 ex dim; 00106 }; 00107 GINAC_DECLARE_UNARCHIVER(idx); 00108 00109 00112 class varidx : public idx 00113 { 00114 GINAC_DECLARE_REGISTERED_CLASS(varidx, idx) 00115 00116 // other constructors 00117 public: 00124 varidx(const ex & v, const ex & dim, bool covariant = false); 00125 00126 // functions overriding virtual functions from base classes 00127 public: 00128 bool is_dummy_pair_same_type(const basic & other) const; 00129 void archive(archive_node& n) const; 00130 void read_archive(const archive_node& n, lst& syms); 00131 protected: 00132 bool match_same_type(const basic & other) const; 00133 00134 // non-virtual functions in this class 00135 public: 00137 bool is_covariant() const {return covariant;} 00138 00140 bool is_contravariant() const {return !covariant;} 00141 00143 ex toggle_variance() const; 00144 00145 protected: 00146 void do_print(const print_context & c, unsigned level) const; 00147 void do_print_tree(const print_tree & c, unsigned level) const; 00148 00149 // member variables 00150 protected: 00151 bool covariant; 00152 }; 00153 GINAC_DECLARE_UNARCHIVER(varidx); 00154 00155 00161 class spinidx : public varidx 00162 { 00163 GINAC_DECLARE_REGISTERED_CLASS(spinidx, varidx) 00164 00165 // other constructors 00166 public: 00174 spinidx(const ex & v, const ex & dim = 2, bool covariant = false, bool dotted = false); 00175 00176 // functions overriding virtual functions from base classes 00177 public: 00178 bool is_dummy_pair_same_type(const basic & other) const; 00179 // complex conjugation 00180 ex conjugate() const { return toggle_dot(); } 00181 void archive(archive_node& n) const; 00182 void read_archive(const archive_node& n, lst& syms); 00183 protected: 00184 bool match_same_type(const basic & other) const; 00185 00186 // non-virtual functions in this class 00187 public: 00189 bool is_dotted() const {return dotted;} 00190 00192 bool is_undotted() const {return !dotted;} 00193 00196 ex toggle_dot() const; 00197 00200 ex toggle_variance_dot() const; 00201 00202 protected: 00203 void do_print(const print_context & c, unsigned level) const; 00204 void do_print_latex(const print_latex & c, unsigned level) const; 00205 void do_print_tree(const print_tree & c, unsigned level) const; 00206 00207 // member variables 00208 protected: 00209 bool dotted; 00210 }; 00211 GINAC_DECLARE_UNARCHIVER(spinidx); 00212 00213 00214 // utility functions 00215 00217 bool is_dummy_pair(const idx & i1, const idx & i2); 00218 00220 bool is_dummy_pair(const ex & e1, const ex & e2); 00221 00230 void find_free_and_dummy(exvector::const_iterator it, exvector::const_iterator itend, exvector & out_free, exvector & out_dummy); 00231 00239 inline void find_free_and_dummy(const exvector & v, exvector & out_free, exvector & out_dummy) 00240 { 00241 find_free_and_dummy(v.begin(), v.end(), out_free, out_dummy); 00242 } 00243 00248 inline void find_dummy_indices(const exvector & v, exvector & out_dummy) 00249 { 00250 exvector free_indices; 00251 find_free_and_dummy(v.begin(), v.end(), free_indices, out_dummy); 00252 } 00253 00255 inline size_t count_dummy_indices(const exvector & v) 00256 { 00257 exvector free_indices, dummy_indices; 00258 find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices); 00259 return dummy_indices.size(); 00260 } 00261 00263 inline size_t count_free_indices(const exvector & v) 00264 { 00265 exvector free_indices, dummy_indices; 00266 find_free_and_dummy(v.begin(), v.end(), free_indices, dummy_indices); 00267 return free_indices.size(); 00268 } 00269 00273 ex minimal_dim(const ex & dim1, const ex & dim2); 00274 00275 } // namespace GiNaC 00276 00277 #endif // ndef GINAC_IDX_H