GiNaC  1.6.2
Public Member Functions | Protected Member Functions | Protected Attributes
GiNaC::expairseq Class Reference

A sequence of class expair. More...

#include <expairseq.h>

Inheritance diagram for GiNaC::expairseq:
GiNaC::basic GiNaC::refcounted GiNaC::add GiNaC::mul

List of all members.

Public Member Functions

 expairseq (const ex &lh, const ex &rh)
 expairseq (const exvector &v)
 expairseq (const epvector &v, const ex &oc, bool do_index_renaming=false)
 expairseq (std::auto_ptr< epvector >, const ex &oc, bool do_index_renaming=false)
unsigned precedence () const
 Return relative operator precedence (for parenthezing output).
bool info (unsigned inf) const
 Information about the object.
size_t nops () const
 Number of operands/members.
ex op (size_t i) const
 Return operand/member at position i.
ex map (map_function &f) const
 Construct new expression by applying the specified function to all sub-expressions (one level only, not recursively).
ex eval (int level=0) const
 Perform coefficient-wise automatic term rewriting rules in this class.
ex to_rational (exmap &repl) const
 Implementation of ex::to_rational() for expairseqs.
ex to_polynomial (exmap &repl) const
 Implementation of ex::to_polynomial() for expairseqs.
bool match (const ex &pattern, exmap &repl_lst) const
 Check whether the expression matches a given pattern.
ex subs (const exmap &m, unsigned options=0) const
 Substitute a set of objects by arbitrary expressions.
ex conjugate () const
void archive (archive_node &n) const
 Save (serialize) the object into archive node.
void read_archive (const archive_node &n, lst &syms)
 Load (deserialize) the object from an archive node.

Protected Member Functions

bool is_equal_same_type (const basic &other) const
 Returns true if two objects of same type are equal.
unsigned return_type () const
unsigned calchash () const
 Compute the hash value of an object and if it makes sense to store it in the objects status_flags, do so.
ex expand (unsigned options=0) const
 Expand expression, i.e.
virtual ex thisexpairseq (const epvector &v, const ex &oc, bool do_index_renaming=false) const
 Create an object of this type.
virtual ex thisexpairseq (std::auto_ptr< epvector > vp, const ex &oc, bool do_index_renaming=false) const
virtual void printseq (const print_context &c, char delim, unsigned this_precedence, unsigned upper_precedence) const
virtual void printpair (const print_context &c, const expair &p, unsigned upper_precedence) const
virtual expair split_ex_to_pair (const ex &e) const
 Form an expair from an ex, using the corresponding semantics.
virtual expair combine_ex_with_coeff_to_pair (const ex &e, const ex &c) const
virtual expair combine_pair_with_coeff_to_pair (const expair &p, const ex &c) const
virtual ex recombine_pair_to_ex (const expair &p) const
 Form an ex out of an expair, using the corresponding semantics.
virtual bool expair_needs_further_processing (epp it)
virtual ex default_overall_coeff () const
virtual void combine_overall_coeff (const ex &c)
virtual void combine_overall_coeff (const ex &c1, const ex &c2)
virtual bool can_make_flat (const expair &p) const
void do_print (const print_context &c, unsigned level) const
 Default output to stream.
void do_print_tree (const print_tree &c, unsigned level) const
 Tree output to stream.
void construct_from_2_ex_via_exvector (const ex &lh, const ex &rh)
void construct_from_2_ex (const ex &lh, const ex &rh)
void construct_from_2_expairseq (const expairseq &s1, const expairseq &s2)
void construct_from_expairseq_ex (const expairseq &s, const ex &e)
void construct_from_exvector (const exvector &v)
void construct_from_epvector (const epvector &v, bool do_index_renaming=false)
void make_flat (const exvector &v)
 Combine this expairseq with argument exvector.
void make_flat (const epvector &v, bool do_index_renaming=false)
 Combine this expairseq with argument epvector.
void canonicalize ()
 Brings this expairseq into a sorted (canonical) form.
void combine_same_terms_sorted_seq ()
 Compact a presorted expairseq by combining all matching expairs to one each.
bool is_canonical () const
 Check if this expairseq is in sorted (canonical) form.
std::auto_ptr< epvectorexpandchildren (unsigned options) const
 Member-wise expand the expairs in this sequence.
std::auto_ptr< epvectorevalchildren (int level) const
 Member-wise evaluate the expairs in this sequence.
std::auto_ptr< epvectorsubschildren (const exmap &m, unsigned options=0) const
 Member-wise substitute in this sequence.

Protected Attributes

epvector seq
ex overall_coeff

Detailed Description

A sequence of class expair.

This is used for time-critical classes like sums and products of terms since handling a list of coeff and rest is much faster than handling a list of products or powers, respectively. (Not incidentally, Maple does it the same way, maybe others too.) The semantics is (at least) twofold: one for addition and one for multiplication and several methods have to be overridden by derived classes to reflect the change in semantics. However, most functionality turns out to be shared between addition and multiplication, which is the reason why there is this base class.

Definition at line 66 of file expairseq.h.


Constructor & Destructor Documentation

GiNaC::expairseq::expairseq ( const ex lh,
const ex rh 
)

Definition at line 111 of file expairseq.cpp.

References construct_from_2_ex(), GINAC_ASSERT, and is_canonical().

Referenced by eval(), and thisexpairseq().

GiNaC::expairseq::expairseq ( const exvector v)

Definition at line 117 of file expairseq.cpp.

References construct_from_exvector(), GINAC_ASSERT, and is_canonical().

GiNaC::expairseq::expairseq ( const epvector v,
const ex oc,
bool  do_index_renaming = false 
)

Definition at line 123 of file expairseq.cpp.

References construct_from_epvector(), GINAC_ASSERT, and is_canonical().

GiNaC::expairseq::expairseq ( std::auto_ptr< epvector vp,
const ex oc,
bool  do_index_renaming = false 
)

Definition at line 131 of file expairseq.cpp.

References construct_from_epvector(), GINAC_ASSERT, and is_canonical().


Member Function Documentation

unsigned GiNaC::expairseq::precedence ( ) const [inline, virtual]

Return relative operator precedence (for parenthezing output).

Reimplemented from GiNaC::basic.

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 79 of file expairseq.h.

Referenced by do_print(), and printpair().

bool GiNaC::expairseq::info ( unsigned  inf) const [virtual]
size_t GiNaC::expairseq::nops ( ) const [virtual]
ex GiNaC::expairseq::op ( size_t  i) const [virtual]
ex GiNaC::expairseq::map ( map_function f) const [virtual]

Construct new expression by applying the specified function to all sub-expressions (one level only, not recursively).

Reimplemented from GiNaC::basic.

Definition at line 307 of file expairseq.cpp.

References default_overall_coeff(), GiNaC::ex::is_equal(), last, overall_coeff, recombine_pair_to_ex(), seq, split_ex_to_pair(), and thisexpairseq().

ex GiNaC::expairseq::eval ( int  level = 0) const [virtual]

Perform coefficient-wise automatic term rewriting rules in this class.

Reimplemented from GiNaC::basic.

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 332 of file expairseq.cpp.

References GiNaC::status_flags::dynallocated, evalchildren(), GiNaC::status_flags::evaluated, expairseq(), GiNaC::basic::flags, GiNaC::basic::hold(), overall_coeff, and GiNaC::basic::setflag().

ex GiNaC::expairseq::to_rational ( exmap repl) const [virtual]
ex GiNaC::expairseq::to_polynomial ( exmap repl) const [virtual]
bool GiNaC::expairseq::match ( const ex pattern,
exmap repl_lst 
) const [virtual]

Check whether the expression matches a given pattern.

For every wildcard object in the pattern, a pair with the wildcard as a key and matching expression as a value is added to repl_lst.

Reimplemented from GiNaC::basic.

Definition at line 378 of file expairseq.cpp.

References GiNaC::ex::begin(), default_overall_coeff(), GiNaC::ex::is_equal(), nops(), GiNaC::ex::nops(), op(), GiNaC::ex::op(), split_ex_to_pair(), and thisexpairseq().

ex GiNaC::expairseq::subs ( const exmap m,
unsigned  options = 0 
) const [virtual]

Substitute a set of objects by arbitrary expressions.

The ex returned will already be evaluated.

Reimplemented from GiNaC::basic.

Definition at line 452 of file expairseq.cpp.

References GiNaC::subs_options::algebraic, GiNaC::subs_options::no_index_renaming, overall_coeff, GiNaC::basic::subs_one_level(), subschildren(), and thisexpairseq().

ex GiNaC::expairseq::conjugate ( ) const [virtual]

Reimplemented from GiNaC::basic.

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 366 of file expairseq.cpp.

References GiNaC::are_ex_trivially_equal(), GiNaC::ex::conjugate(), GiNaC::conjugateepvector(), overall_coeff, seq, thisexpairseq(), and x.

void GiNaC::expairseq::archive ( archive_node n) const [virtual]

Save (serialize) the object into archive node.

Archive the object.

Losely speaking, this method turns an expression into a byte stream (which can be saved and restored later on, or sent via network, etc.)

Reimplemented from GiNaC::basic.

Definition at line 166 of file expairseq.cpp.

References GiNaC::archive_node::add_ex(), overall_coeff, and seq.

void GiNaC::expairseq::read_archive ( const archive_node n,
lst syms 
) [virtual]

Load (deserialize) the object from an archive node.

Construct object from archive_node.

Note:
This method is essentially a constructor. However, constructors can't be virtual. So, if unarchiving routines are implemented as constructors one would need to define such a constructor in every class, even if all it does is simply calling constructor of a superclass.

Reimplemented from GiNaC::basic.

Definition at line 144 of file expairseq.cpp.

References canonicalize(), GiNaC::basic::coeff(), GiNaC::archive_node::find_ex(), GiNaC::archive_node::find_ex_by_loc(), GiNaC::archive_node::find_first(), GiNaC::archive_node::find_last(), GINAC_ASSERT, is_canonical(), last, overall_coeff, and seq.

bool GiNaC::expairseq::is_equal_same_type ( const basic other) const [protected, virtual]

Returns true if two objects of same type are equal.

Normally needs not be reimplemented as long as it wasn't overwritten by some parent class, since it just calls compare_same_type(). The reason why this function exists is that sometimes it is easier to determine equality than an order relation and then it can be overridden.

Reimplemented from GiNaC::basic.

Definition at line 531 of file expairseq.cpp.

References GINAC_ASSERT, GiNaC::ex::is_equal(), overall_coeff, GiNaC::basic::print(), and seq.

unsigned GiNaC::expairseq::return_type ( ) const [protected, virtual]

Reimplemented from GiNaC::basic.

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 595 of file expairseq.cpp.

References GiNaC::return_types::noncommutative_composite.

unsigned GiNaC::expairseq::calchash ( ) const [protected, virtual]

Compute the hash value of an object and if it makes sense to store it in the objects status_flags, do so.

The method inherited from class basic computes a hash value based on the type and hash values of possible members. For this reason it is well suited for container classes but atomic classes should override this implementation because otherwise they would all end up with the same hashvalue.

Reimplemented from GiNaC::basic.

Definition at line 600 of file expairseq.cpp.

References GiNaC::status_flags::evaluated, GiNaC::basic::flags, GiNaC::ex::gethash(), GiNaC::status_flags::hash_calculated, GiNaC::basic::hashvalue, GiNaC::make_hash_seed(), overall_coeff, GiNaC::rotate_left(), seq, and GiNaC::basic::setflag().

ex GiNaC::expairseq::expand ( unsigned  options = 0) const [protected, virtual]

Expand expression, i.e.

multiply it out and return the result as a new expression.

Reimplemented from GiNaC::basic.

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 626 of file expairseq.cpp.

References expandchildren(), GiNaC::status_flags::expanded, overall_coeff, GiNaC::basic::setflag(), and thisexpairseq().

ex GiNaC::expairseq::thisexpairseq ( const epvector v,
const ex oc,
bool  do_index_renaming = false 
) const [protected, virtual]

Create an object of this type.

This method works similar to a constructor. It is useful because expairseq has (at least) two possible different semantics but we want to inherit methods thus avoiding code duplication. Sometimes a method in expairseq has to create a new one of the same semantics, which cannot be done by a ctor because the name (add, mul,...) is unknown on the expaiseq level. In order for this trick to work a derived class must of course override this definition.

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 651 of file expairseq.cpp.

References expairseq().

Referenced by conjugate(), expand(), map(), match(), subs(), to_polynomial(), and to_rational().

ex GiNaC::expairseq::thisexpairseq ( std::auto_ptr< epvector vp,
const ex oc,
bool  do_index_renaming = false 
) const [protected, virtual]

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 656 of file expairseq.cpp.

References expairseq().

void GiNaC::expairseq::printseq ( const print_context c,
char  delim,
unsigned  this_precedence,
unsigned  upper_precedence 
) const [protected, virtual]
void GiNaC::expairseq::printpair ( const print_context c,
const expair p,
unsigned  upper_precedence 
) const [protected, virtual]
expair GiNaC::expairseq::split_ex_to_pair ( const ex e) const [protected, virtual]

Form an expair from an ex, using the corresponding semantics.

See also:
expairseq::recombine_pair_to_ex()

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 694 of file expairseq.cpp.

References GiNaC::_ex1.

Referenced by construct_from_2_ex(), construct_from_expairseq_ex(), make_flat(), map(), match(), subschildren(), to_polynomial(), and to_rational().

expair GiNaC::expairseq::combine_ex_with_coeff_to_pair ( const ex e,
const ex c 
) const [protected, virtual]

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 700 of file expairseq.cpp.

References GINAC_ASSERT.

Referenced by evalchildren(), expandchildren(), subschildren(), to_polynomial(), and to_rational().

expair GiNaC::expairseq::combine_pair_with_coeff_to_pair ( const expair p,
const ex c 
) const [protected, virtual]

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 709 of file expairseq.cpp.

References GiNaC::expair::coeff, GINAC_ASSERT, and GiNaC::expair::rest.

ex GiNaC::expairseq::recombine_pair_to_ex ( const expair p) const [protected, virtual]

Form an ex out of an expair, using the corresponding semantics.

See also:
expairseq::split_ex_to_pair()

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 721 of file expairseq.cpp.

References GiNaC::expair::coeff, and GiNaC::expair::rest.

Referenced by map(), op(), subschildren(), to_polynomial(), and to_rational().

bool GiNaC::expairseq::expair_needs_further_processing ( epp  it) [protected, virtual]
ex GiNaC::expairseq::default_overall_coeff ( ) const [protected, virtual]

Reimplemented in GiNaC::mul.

Definition at line 734 of file expairseq.cpp.

References GiNaC::_ex0.

Referenced by do_print_tree(), map(), match(), nops(), op(), printseq(), to_polynomial(), and to_rational().

void GiNaC::expairseq::combine_overall_coeff ( const ex c) [protected, virtual]

Reimplemented in GiNaC::mul.

Definition at line 739 of file expairseq.cpp.

References GINAC_ASSERT, and overall_coeff.

Referenced by construct_from_2_ex(), construct_from_2_expairseq(), construct_from_expairseq_ex(), and make_flat().

void GiNaC::expairseq::combine_overall_coeff ( const ex c1,
const ex c2 
) [protected, virtual]

Reimplemented in GiNaC::mul.

Definition at line 746 of file expairseq.cpp.

References GINAC_ASSERT, and overall_coeff.

bool GiNaC::expairseq::can_make_flat ( const expair p) const [protected, virtual]

Reimplemented in GiNaC::mul.

Definition at line 755 of file expairseq.cpp.

Referenced by make_flat().

void GiNaC::expairseq::do_print ( const print_context c,
unsigned  level 
) const [protected]

Default output to stream.

Reimplemented from GiNaC::basic.

Reimplemented in GiNaC::mul, and GiNaC::add.

Definition at line 185 of file expairseq.cpp.

References precedence(), printseq(), and GiNaC::print_context::s.

void GiNaC::expairseq::do_print_tree ( const print_tree c,
unsigned  level 
) const [protected]
void GiNaC::expairseq::construct_from_2_ex_via_exvector ( const ex lh,
const ex rh 
) [protected]

Definition at line 765 of file expairseq.cpp.

References construct_from_exvector(), GINAC_ASSERT, and seq.

Referenced by construct_from_2_ex().

void GiNaC::expairseq::construct_from_2_ex ( const ex lh,
const ex rh 
) [protected]
void GiNaC::expairseq::construct_from_2_expairseq ( const expairseq s1,
const expairseq s2 
) [protected]
void GiNaC::expairseq::construct_from_expairseq_ex ( const expairseq s,
const ex e 
) [protected]
void GiNaC::expairseq::construct_from_exvector ( const exvector v) [protected]
void GiNaC::expairseq::construct_from_epvector ( const epvector v,
bool  do_index_renaming = false 
) [protected]
void GiNaC::expairseq::make_flat ( const exvector v) [protected]

Combine this expairseq with argument exvector.

It cares for associativity as well as for special handling of numerics.

Definition at line 1026 of file expairseq.cpp.

References GiNaC::_ex1, combine_overall_coeff(), GiNaC::make_flat_inserter::handle_factor(), GiNaC::info_flags::has_indices, overall_coeff, seq, and split_ex_to_pair().

Referenced by construct_from_epvector(), and construct_from_exvector().

void GiNaC::expairseq::make_flat ( const epvector v,
bool  do_index_renaming = false 
) [protected]

Combine this expairseq with argument epvector.

It cares for associativity as well as for special handling of numerics.

Definition at line 1078 of file expairseq.cpp.

References GiNaC::_ex1, GiNaC::are_ex_trivially_equal(), can_make_flat(), GiNaC::ex::coeff(), combine_overall_coeff(), GiNaC::make_flat_inserter::handle_factor(), GiNaC::info_flags::has_indices, overall_coeff, and seq.

void GiNaC::expairseq::canonicalize ( ) [protected]

Brings this expairseq into a sorted (canonical) form.

Definition at line 1139 of file expairseq.cpp.

References seq.

Referenced by construct_from_epvector(), construct_from_exvector(), and read_archive().

void GiNaC::expairseq::combine_same_terms_sorted_seq ( ) [protected]

Compact a presorted expairseq by combining all matching expairs to one each.

On an add object, this is responsible for 2*x+3*x+y -> 5*x+y, for instance.

Definition at line 1148 of file expairseq.cpp.

References construct_from_epvector(), expair_needs_further_processing(), last, and seq.

Referenced by construct_from_epvector(), and construct_from_exvector().

bool GiNaC::expairseq::is_canonical ( ) const [protected]

Check if this expairseq is in sorted (canonical) form.

Useful mainly for debugging or in assertions since being sorted is an invariance.

Definition at line 1505 of file expairseq.cpp.

References printpair(), and seq.

Referenced by GiNaC::add::add(), expairseq(), GiNaC::mul::mul(), and read_archive().

std::auto_ptr< epvector > GiNaC::expairseq::expandchildren ( unsigned  options) const [protected]

Member-wise expand the expairs in this sequence.

See also:
expairseq::expand()
Returns:
pointer to epvector containing expanded pairs or zero pointer, if no members were changed.

Reimplemented in GiNaC::mul.

Definition at line 1547 of file expairseq.cpp.

References GiNaC::are_ex_trivially_equal(), GiNaC::ex::coeff(), combine_ex_with_coeff_to_pair(), GiNaC::ex::expand(), and seq.

Referenced by GiNaC::add::expand(), and expand().

std::auto_ptr< epvector > GiNaC::expairseq::evalchildren ( int  level) const [protected]

Member-wise evaluate the expairs in this sequence.

See also:
expairseq::eval()
Returns:
pointer to epvector containing evaluated pairs or zero pointer, if no members were changed.

Definition at line 1591 of file expairseq.cpp.

References GiNaC::are_ex_trivially_equal(), GiNaC::ex::coeff(), combine_ex_with_coeff_to_pair(), GiNaC::ex::eval(), GiNaC::max_recursion_level, and seq.

Referenced by GiNaC::add::eval(), and eval().

std::auto_ptr< epvector > GiNaC::expairseq::subschildren ( const exmap m,
unsigned  options = 0 
) const [protected]

Member-wise substitute in this sequence.

See also:
expairseq::subs()
Returns:
pointer to epvector containing pairs after application of subs, or NULL pointer if no members were changed.

Definition at line 1645 of file expairseq.cpp.

References GiNaC::are_ex_trivially_equal(), GiNaC::ex::coeff(), combine_ex_with_coeff_to_pair(), GiNaC::subs_options::pattern_is_not_product, GiNaC::subs_options::pattern_is_product, recombine_pair_to_ex(), seq, split_ex_to_pair(), and GiNaC::ex::subs().

Referenced by subs().


Member Data Documentation


The documentation for this class was generated from the following files:

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