67 if (
typeid(*
this) !=
typeid(other)) {
133 const std::vector<print_functor> & pdt =
reg_info->options.get_print_dispatch_table();
137 if (
id >= pdt.size() || !(pdt[
id].is_valid())) {
141 if (parent_pc_info) {
142 pc_info = parent_pc_info;
148 if (parent_reg_info) {
150 pc_info = &c.get_class_info();
159 throw (std::runtime_error(std::string(
"basic::print(): method for ") + class_name() +
"/" + c.class_name() +
" not found"));
164 pdt[id](*
this, c, level);
171 c.
s <<
"[" << class_name() <<
" object]";
177 c.
s << std::string(level,
' ') << class_name() <<
" @" <<
this
178 << std::hex <<
", hash=0x" <<
hashvalue <<
", flags=0x" <<
flags << std::dec;
180 c.
s <<
", nops=" <<
nops();
182 for (
size_t i=0; i<
nops(); ++i)
189 c.
s << class_name() <<
"()";
202 std::cerr << std::endl;
240 throw(std::range_error(std::string(
"basic::op(): ") + class_name() + std::string(
" has no operands")));
247 throw(std::range_error(std::string(
"basic::let_op(): ") + class_name() + std::string(
" has no operands")));
255 throw(std::invalid_argument(std::string(
"non-numeric indices not supported by ") + class_name()));
268 throw(std::invalid_argument(std::string(
"non-numeric indices not supported by ") + class_name()));
283 if (
match(pattern, repl_lst))
285 for (
size_t i=0; i<
nops(); i++)
286 if (
op(i).
has(pattern, options))
300 basic *copy =
nullptr;
301 for (
size_t i=0; i<num; i++) {
302 const ex & o =
op(i);
342 return n==0 ? *this :
_ex0;
359 else if (distributed) {
368 for (
const auto & xi : x) {
371 for (
auto & li : l) {
372 int cexp = pre_coeff.
degree(li);
373 pre_coeff = pre_coeff.
coeff(li, cexp);
374 key *=
pow(li, cexp);
376 auto ci = cmap.find(key);
377 if (ci != cmap.end())
378 ci->second += pre_coeff;
380 cmap.insert(exmap::value_type(key, pre_coeff));
384 for (
auto & mi : cmap)
385 resv.push_back((mi.first)*(mi.second));
392 size_t n = s.
nops() - 1;
409 return x + (*
this - x).
expand();
431 return map(map_evalf);
542 for (
auto & it : repl_lst) {
543 if (it.first.is_equal(pattern))
546 repl_lst[pattern] = *
this;
572 exmap tmp_repl = repl_lst;
574 for (
size_t i=0; i<
nops(); i++)
575 if (!
op(i).
match(pattern.
op(i), tmp_repl))
589 auto it = m.find(thisex);
594 for (
auto & it : m) {
613 for (
size_t i=0; i<num; i++) {
614 const ex & orig_op =
op(i);
615 const ex & subsed_op = orig_op.
subs(m, options);
623 copy->
let_op(i++) = subsed_op;
627 copy->
let_op(i) =
op(i).subs(m, options);
654 return ex(*this).diff(s, nth);
659 ndiff = ndiff.
diff(s);
678 return real_part_function(*this).hold();
683 return imag_part_function(*this).hold();
710 return map(map_derivative);
759 rt.
tinfo = &
typeid(*this);
773 for (
size_t i=0; i<
nops(); i++) {
775 v ^= this->
op(i).gethash();
818#ifdef GINAC_COMPARE_STATISTICS
819 compare_statistics.total_basic_compares++;
821 const unsigned hash_this =
gethash();
822 const unsigned hash_other = other.
gethash();
823 if (hash_this<hash_other)
return -1;
824 if (hash_this>hash_other)
return 1;
825#ifdef GINAC_COMPARE_STATISTICS
826 compare_statistics.compare_same_hashvalue++;
829 const std::type_info& typeid_this =
typeid(*this);
830 const std::type_info& typeid_other =
typeid(other);
831 if (typeid_this == typeid_other) {
842#ifdef GINAC_COMPARE_STATISTICS
843 compare_statistics.compare_same_type++;
853 return (typeid_this.before(typeid_other) ? -1 : 1);
865#ifdef GINAC_COMPARE_STATISTICS
866 compare_statistics.total_basic_is_equals++;
870#ifdef GINAC_COMPARE_STATISTICS
871 compare_statistics.is_equal_same_hashvalue++;
873 if (
typeid(*
this) !=
typeid(other))
876#ifdef GINAC_COMPARE_STATISTICS
877 compare_statistics.is_equal_same_type++;
897 throw(std::runtime_error(
"cannot modify multiply referenced object"));
905#ifdef GINAC_COMPARE_STATISTICS
906compare_statistics_t::~compare_statistics_t()
908 std::clog <<
"ex::compare() called " << total_compares <<
" times" << std::endl;
909 std::clog <<
"nontrivial compares: " << nontrivial_compares <<
" times" << std::endl;
910 std::clog <<
"basic::compare() called " << total_basic_compares <<
" times" << std::endl;
911 std::clog <<
"same hashvalue in compare(): " << compare_same_hashvalue <<
" times" << std::endl;
912 std::clog <<
"compare_same_type() called " << compare_same_type <<
" times" << std::endl;
913 std::clog << std::endl;
914 std::clog <<
"ex::is_equal() called " << total_is_equals <<
" times" << std::endl;
915 std::clog <<
"nontrivial is_equals: " << nontrivial_is_equals <<
" times" << std::endl;
916 std::clog <<
"basic::is_equal() called " << total_basic_is_equals <<
" times" << std::endl;
917 std::clog <<
"same hashvalue in is_equal(): " << is_equal_same_hashvalue <<
" times" << std::endl;
918 std::clog <<
"is_equal_same_type() called " << is_equal_same_type <<
" times" << std::endl;
919 std::clog << std::endl;
920 std::clog <<
"basic::gethash() called " << total_gethash <<
" times" << std::endl;
921 std::clog <<
"used cached hashvalue " << gethash_cached <<
" times" << std::endl;
924compare_statistics_t compare_statistics;
Interface to GiNaC's sums of expressions.
Archiving of GiNaC expressions.
Interface to GiNaC's ABC.
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
void add_string(const std::string &name, const std::string &value)
Add property of type "string" to node.
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
virtual return_type_t return_type_tinfo() const
virtual size_t nops() const
Number of operands/members.
virtual ex eval_integ() const
Evaluate integrals, if result is known.
const basic & clearflag(unsigned f) const
Clear some status_flags.
virtual bool match_same_type(const basic &other) const
Returns true if the attributes of two objects are similar enough for a match.
virtual bool match(const ex &pattern, exmap &repls) const
Check whether the expression matches a given pattern.
virtual void dbgprinttree() const
Little wrapper around printtree to be called within a debugger.
void print_dispatch(const print_context &c, unsigned level) const
Like print(), but dispatch to the specified class.
virtual ex imag_part() const
virtual void archive(archive_node &n) const
Save (serialize) the object into archive node.
virtual ex eval() const
Perform automatic non-interruptive term rewriting rules.
const basic & setflag(unsigned f) const
Set some status_flags.
virtual bool info(unsigned inf) const
Information about the object.
virtual bool contract_with(exvector::iterator self, exvector::iterator other, exvector &v) const
Try to contract two indexed expressions that appear in the same product.
ex diff(const symbol &s, unsigned nth=1) const
Default interface of nth derivative ex::diff(s, n).
virtual ex scalar_mul_indexed(const ex &self, const numeric &other) const
Multiply an indexed expression with a scalar.
unsigned hashvalue
hash value
void ensure_if_modifiable() const
Ensure the object may be modified without hurting others, throws if this is not the case.
virtual bool is_equal_same_type(const basic &other) const
Returns true if two objects of same type are equal.
virtual bool has(const ex &other, unsigned options=0) const
Test for occurrence of a pattern.
virtual ex evalm() const
Evaluate sums, products and integer powers of matrices.
virtual ex eval_indexed(const basic &i) const
Perform automatic symbolic evaluations on indexed expression that contains this object as the base ex...
virtual int degree(const ex &s) const
Return degree of highest power in object s.
virtual ex conjugate() const
virtual unsigned precedence() const
Return relative operator precedence (for parenthezing output).
virtual ex op(size_t i) const
Return operand/member at position i.
unsigned flags
of type status_flags
virtual ex add_indexed(const ex &self, const ex &other) const
Add two indexed expressions.
const basic & operator=(const basic &other)
basic assignment operator: the other object might be of a derived class.
virtual void print(const print_context &c, unsigned level=0) const
Output to stream.
void do_print(const print_context &c, unsigned level) const
Default output to stream.
virtual void read_archive(const archive_node &n, lst &syms)
Load (deserialize) the object from an archive node.
ex subs_one_level(const exmap &m, unsigned options) const
Helper function for subs().
const basic & hold() const
Stop further evaluation.
bool is_equal(const basic &other) const
Test for syntactic equality.
virtual ex collect(const ex &s, bool distributed=false) const
Sort expanded expression in terms of powers of some object(s).
virtual ex subs(const exmap &m, unsigned options=0) const
Substitute a set of objects by arbitrary expressions.
virtual ex real_part() const
virtual int compare_same_type(const basic &other) const
Returns order relation between two objects of same type.
virtual ex & let_op(size_t i)
Return modifiable operand/member at position i.
virtual basic * duplicate() const
Create a clone of this object on the heap.
virtual void dbgprint() const
Little wrapper around print to be called within a debugger.
void do_print_tree(const print_tree &c, unsigned level) const
Tree output to stream.
virtual ex coeff(const ex &s, int n=1) const
Return coefficient of degree n in object s.
virtual unsigned return_type() const
virtual ex eval_ncmul(const exvector &v) const
void do_print_python_repr(const print_python_repr &c, unsigned level) const
Python parsable output to stream.
virtual ex derivative(const symbol &s) const
Default implementation of ex::diff().
virtual int ldegree(const ex &s) const
Return degree of lowest power in object s.
virtual ex expand(unsigned options=0) const
Expand expression, i.e.
int compare(const basic &other) const
Compare objects syntactically to establish canonical ordering.
virtual ex evalf() const
Evaluate object numerically.
virtual ex operator[](const ex &index) const
virtual unsigned calchash() const
Compute the hash value of an object and if it makes sense to store it in the objects status_flags,...
virtual exvector get_free_indices() const
Return a vector containing the free indices of an expression.
virtual bool is_polynomial(const ex &var) const
Check whether this is a polynomial in the given variables.
virtual ex map(map_function &f) const
Construct new expression by applying the specified function to all sub-expressions (one level only,...
class_info * get_parent() const
Get pointer to class_info of parent class (or nullptr).
Lightweight wrapper for GiNaC's symbolic objects.
ex diff(const symbol &s, unsigned nth=1) const
Compute partial derivative of an expression.
ex expand(unsigned options=0) const
Expand an expression.
int degree(const ex &s) const
ex subs(const exmap &m, unsigned options=0) const
ex collect(const ex &s, bool distributed=false) const
ex coeff(const ex &s, int n=1) const
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
This class holds a two-component object, a basis and and exponent representing exponentiation.
Base class for print_contexts.
std::ostream & s
stream to output to
Context for default (ginsh-parsable) output.
Context for python-parsable output.
Context for tree-like output for debugging.
const unsigned delta_indent
size of indentation step
void set_refcount(unsigned int r) noexcept
unsigned int get_refcount() const noexcept
Flags to store information about the state of an object.
@ expanded
.expand(0) has already done its job (other expand() options ignore this flag)
@ evaluated
.eval() has already done its job
@ hash_calculated
.calchash() has already done its job
@ no_pattern
disable pattern matching
Interface to GiNaC's light-weight expression handles.
Interface to GiNaC's initially known functions.
Definition of GiNaC's lst.
ex hold_ncmul(const exvector &v)
const numeric pow(const numeric &x, const numeric &y)
container< std::list > lst
std::map< ex, ex, ex_is_less > exmap
B & dynallocate(Args &&... args)
Constructs a new (class basic or derived) B object on the heap.
class_info< registered_class_options > registered_class_info
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
int compare_pointers(const T *a, const T *b)
Compare two pointers (just to establish some sort of canonical order).
attribute_pure const T & ex_to(const ex &e)
Return a reference to the basic-derived class T object embedded in an expression.
ex diff(const ex &thisex, const symbol &s, unsigned nth=1)
registered_class_info structure< T, CP >::reg_info
print_func< print_context >(&varidx::do_print). print_func< print_latex >(&varidx
bool is_a(const basic &obj)
Check if obj is a T, including base classes.
class_info< print_context_options > print_context_class_info
ex evalf(const ex &thisex)
static unsigned make_hash_seed(const std::type_info &tinfo)
We need a hash function which gives different values for objects of different types.
unsigned rotate_left(unsigned n)
Rotate bits of unsigned value by one bit to the left.
GiNaC::evalm_map_function map_evalm
int to_int(const numeric &x)
ex eval_integ(const ex &thisex)
ex evalm(const ex &thisex)
bool is_exactly_a(const basic &obj)
Check if obj is a T, not including base classes.
std::vector< ex > exvector
GiNaC::eval_integ_map_function map_eval_integ
Interface to GiNaC's non-commutative products of expressions.
Makes the interface to the underlying bignum package available.
Interface to GiNaC's overloaded operators.
Interface to GiNaC's symbolic exponentiation (basis^exponent).
#define GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(classname, supername, options)
Macro for inclusion in the implementation of each registered class.
Interface to relations between expressions.
Function object to be applied by basic::derivative().
derivative_map_function(const symbol &sym)
ex operator()(const ex &e) override
Function object to be applied by basic::eval_integ().
ex operator()(const ex &e) override
Function object to be applied by basic::evalf().
ex operator()(const ex &e) override
Function object to be applied by basic::evalm().
ex operator()(const ex &e) override
Function object to be applied by basic::expand().
expand_map_function(unsigned o)
ex operator()(const ex &e) override
Function object for map().
To distinguish between different kinds of non-commutative objects.
std::type_info const * tinfo
to distinguish between non-commutative objects of different type.
unsigned rl
to distinguish between non-commutative objects of the same type.
Interface to GiNaC's symbolic objects.
Interface to several small and furry utilities needed within GiNaC but not of any interest to the use...
Interface to GiNaC's wildcard objects.