GiNaC 1.8.7
expairseq.h
Go to the documentation of this file.
1
5/*
6 * GiNaC Copyright (C) 1999-2023 Johannes Gutenberg University Mainz, Germany
7 *
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.
12 *
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.
17 *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef GINAC_EXPAIRSEQ_H
24#define GINAC_EXPAIRSEQ_H
25
26#include "expair.h"
27#include "indexed.h"
28
29#include <vector>
30
31namespace GiNaC {
32
33typedef std::vector<expair> epvector;
34typedef epvector::iterator epp;
35
39
49class expairseq : public basic
50{
52
53 // other constructors
54public:
55 expairseq(const ex & lh, const ex & rh);
56 expairseq(const exvector & v);
57 expairseq(const epvector & v, const ex & oc, bool do_index_renaming = false);
58 expairseq(epvector && vp, const ex & oc, bool do_index_renaming = false);
59
60 // functions overriding virtual functions from base classes
61public:
62 unsigned precedence() const override {return 10;}
63 bool info(unsigned inf) const override;
64 size_t nops() const override;
65 ex op(size_t i) const override;
66 ex map(map_function & f) const override;
67 ex eval() const override;
68 ex to_rational(exmap & repl) const override;
69 ex to_polynomial(exmap & repl) const override;
70 bool match(const ex & pattern, exmap& repl_lst) const override;
71 ex subs(const exmap & m, unsigned options = 0) const override;
72 ex conjugate() const override;
73
74 void archive(archive_node& n) const override;
75 void read_archive(const archive_node& n, lst& syms) override;
76protected:
77 bool is_equal_same_type(const basic & other) const override;
78 unsigned return_type() const override;
79 unsigned calchash() const override;
80 ex expand(unsigned options=0) const override;
81
82 // new virtual functions which can be overridden by derived classes
83protected:
84 virtual ex thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming = false) const;
85 virtual ex thisexpairseq(epvector && vp, const ex & oc, bool do_index_renaming = false) const;
86 virtual void printseq(const print_context & c, char delim,
87 unsigned this_precedence,
88 unsigned upper_precedence) const;
89 virtual void printpair(const print_context & c, const expair & p,
90 unsigned upper_precedence) const;
91 virtual expair split_ex_to_pair(const ex & e) const;
92 virtual expair combine_ex_with_coeff_to_pair(const ex & e,
93 const ex & c) const;
95 const ex & c) const;
96 virtual ex recombine_pair_to_ex(const expair & p) const;
97 virtual bool expair_needs_further_processing(epp it);
98 virtual ex default_overall_coeff() const;
99 virtual void combine_overall_coeff(const ex & c);
100 virtual void combine_overall_coeff(const ex & c1, const ex & c2);
101 virtual bool can_make_flat(const expair & p) const;
102
103 // non-virtual functions in this class
104protected:
105 void do_print(const print_context & c, unsigned level) const;
106 void do_print_tree(const print_tree & c, unsigned level) const;
107 void construct_from_2_ex(const ex & lh, const ex & rh);
109 const expairseq & s2);
111 const ex & e);
112 void construct_from_exvector(const exvector & v);
113 void construct_from_epvector(const epvector & v, bool do_index_renaming = false);
114 void construct_from_epvector(epvector && v, bool do_index_renaming = false);
115 void make_flat(const exvector & v);
116 void make_flat(const epvector & v, bool do_index_renaming = false);
117 void canonicalize();
119 bool is_canonical() const;
120 epvector expandchildren(unsigned options) const;
121 epvector evalchildren() const;
122 epvector subschildren(const exmap & m, unsigned options = 0) const;
123
124// member variables
125
126protected:
129};
130
136{
137 public:
139 {
140 if (!do_renaming)
141 return;
142 for (epvector::const_iterator i=epv.begin(); i!=epv.end(); ++i)
143 if(are_ex_trivially_equal(i->coeff, 1))
144 combine_indices(i->rest.get_free_indices());
145 }
147 {
148 if (!do_renaming)
149 return;
150 for (exvector::const_iterator i=v.begin(); i!=v.end(); ++i)
151 combine_indices(i->get_free_indices());
152 }
153 ex handle_factor(const ex &x, const ex &coeff)
154 {
155 if (!do_renaming)
156 return x;
157 exvector dummies_of_factor;
158 if (is_a<numeric>(coeff) && coeff.is_equal(GiNaC::numeric(1)))
159 dummies_of_factor = get_all_dummy_indices_safely(x);
160 else if (is_a<numeric>(coeff) && coeff.is_equal(GiNaC::numeric(2)))
161 dummies_of_factor = x.get_free_indices();
162 else
163 return x;
164 if (dummies_of_factor.size() == 0)
165 return x;
166 sort(dummies_of_factor.begin(), dummies_of_factor.end(), ex_is_less());
168 dummies_of_factor, x);
169 combine_indices(dummies_of_factor);
170 return new_factor;
171 }
172 private:
173 void combine_indices(const exvector &dummies_of_factor)
174 {
175 exvector new_dummy_indices;
176 set_union(used_indices.begin(), used_indices.end(),
177 dummies_of_factor.begin(), dummies_of_factor.end(),
178 std::back_insert_iterator<exvector>(new_dummy_indices), ex_is_less());
179 used_indices.swap(new_dummy_indices);
180 }
183};
184
185} // namespace GiNaC
186
187#endif // ndef GINAC_EXPAIRSEQ_H
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition: archive.h:49
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Definition: basic.h:105
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
Lightweight wrapper for GiNaC's symbolic objects.
Definition: ex.h:72
bool is_equal(const ex &other) const
Definition: ex.h:345
A pair of expressions.
Definition: expair.h:38
A sequence of class expair.
Definition: expairseq.h:50
ex eval() const override
Perform coefficient-wise automatic term rewriting rules in this class.
Definition: expairseq.cpp:240
epvector subschildren(const exmap &m, unsigned options=0) const
Member-wise substitute in this sequence.
Definition: expairseq.cpp:1084
void combine_same_terms_sorted_seq()
Compact a presorted expairseq by combining all matching expairs to one each.
Definition: expairseq.cpp:924
size_t nops() const override
Number of operands/members.
Definition: expairseq.cpp:202
bool is_equal_same_type(const basic &other) const override
Returns true if two objects of same type are equal.
Definition: expairseq.cpp:419
expairseq(const ex &lh, const ex &rh)
Definition: expairseq.cpp:80
virtual bool expair_needs_further_processing(epp it)
Definition: expairseq.cpp:564
ex conjugate() const override
Definition: expairseq.cpp:274
void construct_from_2_expairseq(const expairseq &s1, const expairseq &s2)
Definition: expairseq.cpp:667
bool match(const ex &pattern, exmap &repl_lst) const override
Check whether the expression matches a given pattern.
Definition: expairseq.cpp:287
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
Definition: expairseq.cpp:377
unsigned return_type() const override
Definition: expairseq.cpp:441
epvector seq
Definition: expairseq.h:127
ex to_polynomial(exmap &repl) const override
Implementation of ex::to_polynomial() for expairseqs.
Definition: normal.cpp:2751
void construct_from_epvector(const epvector &v, bool do_index_renaming=false)
Definition: expairseq.cpp:793
void construct_from_2_ex(const ex &lh, const ex &rh)
Definition: expairseq.cpp:605
virtual ex default_overall_coeff() const
Definition: expairseq.cpp:574
void archive(archive_node &n) const override
Save (serialize) the object into archive node.
Definition: expairseq.cpp:132
virtual void printpair(const print_context &c, const expair &p, unsigned upper_precedence) const
Definition: expairseq.cpp:499
bool is_canonical() const
Check if this expairseq is in sorted (canonical) form.
Definition: expairseq.cpp:972
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
Definition: expairseq.h:62
virtual ex thisexpairseq(const epvector &v, const ex &oc, bool do_index_renaming=false) const
Create an object of this type.
Definition: expairseq.cpp:489
virtual expair combine_pair_with_coeff_to_pair(const expair &p, const ex &c) const
Definition: expairseq.cpp:547
bool info(unsigned inf) const override
Information about the object.
Definition: expairseq.cpp:177
void construct_from_exvector(const exvector &v)
Definition: expairseq.cpp:781
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
Definition: expairseq.cpp:112
virtual expair combine_ex_with_coeff_to_pair(const ex &e, const ex &c) const
Definition: expairseq.cpp:538
void make_flat(const exvector &v)
Combine this expairseq with argument exvector.
Definition: expairseq.cpp:819
virtual void printseq(const print_context &c, char delim, unsigned this_precedence, unsigned upper_precedence) const
Definition: expairseq.cpp:508
virtual bool can_make_flat(const expair &p) const
Definition: expairseq.cpp:595
ex to_rational(exmap &repl) const override
Implementation of ex::to_rational() for expairseqs.
Definition: normal.cpp:2735
ex expand(unsigned options=0) const override
Expand expression, i.e.
Definition: expairseq.cpp:466
void construct_from_expairseq_ex(const expairseq &s, const ex &e)
Definition: expairseq.cpp:720
void do_print(const print_context &c, unsigned level) const
Definition: expairseq.cpp:149
epvector evalchildren() const
Member-wise evaluate the expairs in this sequence.
Definition: expairseq.cpp:1047
ex op(size_t i) const override
Return operand/member at position i.
Definition: expairseq.cpp:210
virtual ex recombine_pair_to_ex(const expair &p) const
Form an ex out of an expair, using the corresponding semantics.
Definition: expairseq.cpp:559
void do_print_tree(const print_tree &c, unsigned level) const
Definition: expairseq.cpp:156
virtual void combine_overall_coeff(const ex &c)
Definition: expairseq.cpp:579
ex map(map_function &f) const override
Construct new expression by applying the specified function to all sub-expressions (one level only,...
Definition: expairseq.cpp:218
epvector expandchildren(unsigned options) const
Member-wise expand the expairs in this sequence.
Definition: expairseq.cpp:1009
void canonicalize()
Brings this expairseq into a sorted (canonical) form.
Definition: expairseq.cpp:915
unsigned calchash() const override
Compute the hash value of an object and if it makes sense to store it in the objects status_flags,...
Definition: expairseq.cpp:446
virtual expair split_ex_to_pair(const ex &e) const
Form an expair from an ex, using the corresponding semantics.
Definition: expairseq.cpp:532
Class to handle the renaming of dummy indices.
Definition: expairseq.h:136
make_flat_inserter(const exvector &v, bool b)
Definition: expairseq.h:146
ex handle_factor(const ex &x, const ex &coeff)
Definition: expairseq.h:153
void combine_indices(const exvector &dummies_of_factor)
Definition: expairseq.h:173
make_flat_inserter(const epvector &epv, bool b)
Definition: expairseq.h:138
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
Definition: numeric.h:82
Base class for print_contexts.
Definition: print.h:103
Context for tree-like output for debugging.
Definition: print.h:147
Definition of expression pairs (building blocks of expairseq).
unsigned options
Definition: factor.cpp:2475
size_t n
Definition: factor.cpp:1432
size_t c
Definition: factor.cpp:757
ex x
Definition: factor.cpp:1610
exset syms
Definition: factor.cpp:2429
mvec m
Definition: factor.cpp:758
Interface to GiNaC's indexed expressions.
Definition: add.cpp:38
std::map< ex, ex, ex_is_less > exmap
Definition: basic.h:50
std::vector< expair > epvector
expair-vector
Definition: expairseq.h:33
epvector * conjugateepvector(const epvector &epv)
Complex conjugate every element of an epvector.
Definition: expairseq.cpp:252
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
Definition: ex.h:699
ex coeff(const ex &thisex, const ex &s, int n=1)
Definition: ex.h:757
epvector::iterator epp
expair-vector pointer
Definition: expairseq.h:34
lst rename_dummy_indices_uniquely(const exvector &va, const exvector &vb)
Similar to above, where va and vb are the same and the return value is a list of two lists for substi...
Definition: indexed.cpp:1460
std::vector< ex > exvector
Definition: basic.h:48
exvector get_all_dummy_indices_safely(const ex &e)
More reliable version of the form.
Definition: indexed.cpp:1394
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition: registrar.h:153
Function object for map().
Definition: basic.h:85

This page is part of the GiNaC developer's reference. It was generated automatically by doxygen. For an introduction, see the tutorial.