GiNaC  1.8.0
expairseq.h
Go to the documentation of this file.
1 
5 /*
6  * GiNaC Copyright (C) 1999-2020 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 
31 namespace GiNaC {
32 
33 typedef std::vector<expair> epvector;
34 typedef epvector::iterator epp;
35 
39 
49 class expairseq : public basic
50 {
52 
53  // other constructors
54 public:
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
61 public:
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;
76 protected:
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
83 protected:
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
104 protected:
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);
108  void construct_from_2_expairseq(const expairseq & s1,
109  const expairseq & s2);
110  void construct_from_expairseq_ex(const expairseq & s,
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 
126 protected:
129 };
130 
136 {
137  public:
138  make_flat_inserter(const epvector &epv, bool b): do_renaming(b)
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
virtual expair split_ex_to_pair(const ex &e) const
void do_print(const print_context &c, unsigned level) const
Interface to GiNaC&#39;s indexed expressions.
A sequence of class expair.
Definition: expairseq.h:49
bool match(const ex &pattern, exmap &repl_lst) const override
Check whether the expression matches a given pattern.
exset syms
Definition: factor.cpp:2434
exvector get_all_dummy_indices_safely(const ex &e)
More reliable version of the form.
Definition: indexed.cpp:1394
virtual ex recombine_pair_to_ex(const expair &p) const
make_flat_inserter(const epvector &epv, bool b)
Definition: expairseq.h:138
void combine_same_terms_sorted_seq()
ex to_rational(exmap &repl) const override
Implementation of ex::to_rational() for expairseqs.
Definition: normal.cpp:2705
bool is_equal(const ex &other) const
Definition: ex.h:345
Definition: add.cpp:38
virtual ex default_overall_coeff() const
epvector expandchildren(unsigned options) const
bool info(unsigned inf) const override
Information about the object.
void do_print_tree(const print_tree &c, unsigned level) const
This class is the ABC (abstract base class) of GiNaC&#39;s class hierarchy.
Definition: basic.h:104
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:684
unsigned return_type() const override
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
ex x
Definition: factor.cpp:1641
ex expand(unsigned options=0) const override
Expand expression, i.e.
ex map(map_function &f) const override
Construct new expression by applying the specified function to all sub-expressions (one level only...
epvector seq
Definition: expairseq.h:127
virtual void printseq(const print_context &c, char delim, unsigned this_precedence, unsigned upper_precedence) const
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
Definition: expairseq.h:62
Class to handle the renaming of dummy indices.
Definition: expairseq.h:135
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
Definition: numeric.h:81
virtual expair combine_ex_with_coeff_to_pair(const ex &e, const ex &c) const
void construct_from_epvector(const epvector &v, bool do_index_renaming=false)
virtual ex thisexpairseq(const epvector &v, const ex &oc, bool do_index_renaming=false) const
virtual expair combine_pair_with_coeff_to_pair(const expair &p, const ex &c) const
unsigned options
Definition: factor.cpp:2480
mvec m
Definition: factor.cpp:771
Definition of expression pairs (building blocks of expairseq).
epvector * conjugateepvector(const epvector &)
Complex conjugate every element of an epvector.
void construct_from_expairseq_ex(const expairseq &s, const ex &e)
void construct_from_2_ex(const ex &lh, const ex &rh)
ex eval() const override
Perform automatic non-interruptive term rewriting rules.
std::vector< ex > exvector
Definition: basic.h:46
std::map< ex, ex, ex_is_less > exmap
Definition: basic.h:50
ex conjugate() const override
epvector::iterator epp
expair-vector pointer
Definition: expairseq.h:34
virtual bool can_make_flat(const expair &p) const
unsigned calchash() const override
Compute the hash value of an object and if it makes sense to store it in the objects status_flags...
Function object for map().
Definition: basic.h:85
size_t n
Definition: factor.cpp:1463
Base class for print_contexts.
Definition: print.h:102
A pair of expressions.
Definition: expair.h:37
ex op(size_t i) const override
Return operand/member at position i.
epvector subschildren(const exmap &m, unsigned options=0) const
virtual bool expair_needs_further_processing(epp it)
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
Definition: archive.h:48
Lightweight wrapper for GiNaC&#39;s symbolic objects.
Definition: ex.h:72
virtual void combine_overall_coeff(const ex &c)
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
ex coeff(const ex &thisex, const ex &s, int n=1)
Definition: ex.h:742
bool is_equal_same_type(const basic &other) const override
Returns true if two objects of same type are equal.
Wrapper template for making GiNaC classes out of STL containers.
Definition: container.h:73
expairseq(const ex &lh, const ex &rh)
#define GINAC_DECLARE_REGISTERED_CLASS(classname, supername)
Macro for inclusion in the declaration of each registered class.
Definition: registrar.h:153
make_flat_inserter(const exvector &v, bool b)
Definition: expairseq.h:146
void make_flat(const exvector &v)
ex handle_factor(const ex &x, const ex &coeff)
Definition: expairseq.h:153
std::vector< expair > epvector
expair-vector
Definition: expairseq.h:33
bool is_canonical() const
void read_archive(const archive_node &n, lst &syms) override
Load (deserialize) the object from an archive node.
size_t c
Definition: factor.cpp:770
size_t nops() const override
Number of operands/members.
void construct_from_exvector(const exvector &v)
void combine_indices(const exvector &dummies_of_factor)
Definition: expairseq.h:173
Context for tree-like output for debugging.
Definition: print.h:146
virtual void printpair(const print_context &c, const expair &p, unsigned upper_precedence) const
void archive(archive_node &n) const override
Save (serialize) the object into archive node.
void construct_from_2_expairseq(const expairseq &s1, const expairseq &s2)
ex to_polynomial(exmap &repl) const override
Implementation of ex::to_polynomial() for expairseqs.
Definition: normal.cpp:2721
epvector evalchildren() const

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