3 * Implementation of GiNaC's index carrying objects. */
6 * GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 #ifndef NO_NAMESPACE_GINAC
32 #endif // ndef NO_NAMESPACE_GINAC
34 GINAC_IMPLEMENT_REGISTERED_CLASS(indexed, exprseq)
37 // default constructor, destructor, copy constructor assignment operator and helpers
44 debugmsg("indexed default constructor",LOGLEVEL_CONSTRUCT);
45 tinfo_key=TINFO_indexed;
50 void indexed::copy(const indexed & other)
52 inherited::copy(other);
55 void indexed::destroy(bool call_parent)
58 inherited::destroy(call_parent);
68 /** Construct indexed object with one index. The index must be of class idx
72 * @return newly constructed indexed object */
73 indexed::indexed(const ex & i1) : inherited(i1)
75 debugmsg("indexed constructor from ex",LOGLEVEL_CONSTRUCT);
76 tinfo_key=TINFO_indexed;
77 GINAC_ASSERT(all_of_type_idx());
80 /** Construct indexed object with two indices. The indices must be of class
83 * @param i1 First index
84 * @param i2 Second index
85 * @return newly constructed indexed object */
86 indexed::indexed(const ex & i1, const ex & i2) : inherited(i1,i2)
88 debugmsg("indexed constructor from ex,ex",LOGLEVEL_CONSTRUCT);
89 tinfo_key=TINFO_indexed;
90 GINAC_ASSERT(all_of_type_idx());
93 /** Construct indexed object with three indices. The indices must be of class
96 * @param i1 First index
97 * @param i2 Second index
98 * @param i3 Third index
99 * @return newly constructed indexed object */
100 indexed::indexed(const ex & i1, const ex & i2, const ex & i3)
101 : inherited(i1,i2,i3)
103 debugmsg("indexed constructor from ex,ex,ex",LOGLEVEL_CONSTRUCT);
104 tinfo_key=TINFO_indexed;
105 GINAC_ASSERT(all_of_type_idx());
108 /** Construct indexed object with four indices. The indices must be of class
111 * @param i1 First index
112 * @param i2 Second index
113 * @param i3 Third index
114 * @param i4 Fourth index
115 * @return newly constructed indexed object */
116 indexed::indexed(const ex & i1, const ex & i2, const ex & i3, const ex & i4)
117 : inherited(i1,i2,i3,i4)
119 debugmsg("indexed constructor from ex,ex,ex,ex",LOGLEVEL_CONSTRUCT);
120 tinfo_key=TINFO_indexed;
121 GINAC_ASSERT(all_of_type_idx());
124 /** Construct indexed object with a specified vector of indices. The indices
125 * must be of class idx or a subclass.
127 * @param iv Vector of indices
128 * @return newly constructed indexed object */
129 indexed::indexed(const exvector & iv) : inherited(iv)
131 debugmsg("indexed constructor from exvector",LOGLEVEL_CONSTRUCT);
132 tinfo_key=TINFO_indexed;
133 GINAC_ASSERT(all_of_type_idx());
136 indexed::indexed(exvector * ivp) : inherited(ivp)
138 debugmsg("indexed constructor from exvector *",LOGLEVEL_CONSTRUCT);
139 tinfo_key=TINFO_indexed;
140 GINAC_ASSERT(all_of_type_idx());
147 /** Construct object from archive_node. */
148 indexed::indexed(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
150 debugmsg("indexed constructor from archive_node", LOGLEVEL_CONSTRUCT);
151 tinfo_key = TINFO_indexed;
154 /** Unarchive the object. */
155 ex indexed::unarchive(const archive_node &n, const lst &sym_lst)
157 return (new indexed(n, sym_lst))->setflag(status_flags::dynallocated);
160 /** Archive the object. */
161 void indexed::archive(archive_node &n) const
163 inherited::archive(n);
167 // functions overriding virtual functions from bases classes
172 basic * indexed::duplicate() const
174 debugmsg("indexed duplicate",LOGLEVEL_DUPLICATE);
175 return new indexed(*this);
178 void indexed::printraw(std::ostream & os) const
180 debugmsg("indexed printraw",LOGLEVEL_PRINT);
181 os << "indexed(indices=";
183 os << ",hash=" << hashvalue << ",flags=" << flags << ")";
186 void indexed::printtree(std::ostream & os, unsigned indent) const
188 debugmsg("indexed printtree",LOGLEVEL_PRINT);
189 os << std::string(indent,' ') << "indexed: " << seq.size() << " indices";
190 os << ",hash=" << hashvalue << ",flags=" << flags << std::endl;
191 printtreeindices(os,indent);
194 void indexed::print(std::ostream & os, unsigned upper_precedence) const
196 debugmsg("indexed print",LOGLEVEL_PRINT);
197 os << "UNNAMEDINDEX";
201 void indexed::printcsrc(std::ostream & os, unsigned type,
202 unsigned upper_precedence) const
204 debugmsg("indexed print csrc",LOGLEVEL_PRINT);
205 print(os,upper_precedence);
208 bool indexed::info(unsigned inf) const
210 if (inf==info_flags::indexed) return true;
211 if (inf==info_flags::has_indices) return seq.size()!=0;
212 return inherited::info(inf);
217 /** Implementation of ex::diff() for an indexed object. It always returns 0.
219 ex indexed::derivative(const symbol & s) const
224 int indexed::compare_same_type(const basic & other) const
226 GINAC_ASSERT(is_of_type(other,indexed));
227 return inherited::compare_same_type(other);
230 bool indexed::is_equal_same_type(const basic & other) const
232 GINAC_ASSERT(is_of_type(other,indexed));
233 return inherited::is_equal_same_type(other);
236 unsigned indexed::return_type(void) const
238 return return_types::noncommutative;
241 unsigned indexed::return_type_tinfo(void) const
246 ex indexed::thisexprseq(const exvector & v) const
251 ex indexed::thisexprseq(exvector * vp) const
257 // virtual functions which can be overridden by derived classes
263 // non-virtual functions in this class
268 void indexed::printrawindices(std::ostream & os) const
271 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
278 void indexed::printtreeindices(std::ostream & os, unsigned indent) const
281 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
282 os << std::string(indent+delta_indent,' ');
289 void indexed::printindices(std::ostream & os) const
295 exvector::const_iterator last=seq.end()-1;
296 exvector::const_iterator cit=seq.begin();
297 for (; cit!=last; ++cit) {
308 /** Check whether all indices are of class idx or a subclass. This function
309 * is used internally to make sure that all constructed indexed objects
310 * really carry indices and not some other classes. */
311 bool indexed::all_of_type_idx(void) const
313 for (exvector::const_iterator cit=seq.begin(); cit!=seq.end(); ++cit) {
314 if (!is_ex_of_type(*cit,idx)) return false;
319 #ifndef NO_NAMESPACE_GINAC
321 #endif // ndef NO_NAMESPACE_GINAC