66 if (
typeid(*
this) !=
typeid(other)) {
132 const std::vector<print_functor> & pdt =
reg_info->options.get_print_dispatch_table();
136 if (
id >= pdt.size() || !(pdt[
id].is_valid())) {
140 if (parent_pc_info) {
141 pc_info = parent_pc_info;
147 if (parent_reg_info) {
149 pc_info = &c.get_class_info();
158 throw (std::runtime_error(std::string(
"basic::print(): method for ") + class_name() +
"/" + c.class_name() +
" not found"));
163 pdt[id](*
this, c, level);
170 c.
s <<
"[" << class_name() <<
" object]";
176 c.
s << std::string(level,
' ') << class_name() <<
" @" <<
this
177 << std::hex <<
", hash=0x" <<
hashvalue <<
", flags=0x" <<
flags << std::dec;
179 c.
s <<
", nops=" <<
nops();
181 for (
size_t i=0; i<
nops(); ++i)
188 c.
s << class_name() <<
"()";
201 std::cerr << std::endl;
239 throw(std::range_error(std::string(
"basic::op(): ") + class_name() + std::string(
" has no operands")));
246 throw(std::range_error(std::string(
"basic::let_op(): ") + class_name() + std::string(
" has no operands")));
254 throw(std::invalid_argument(std::string(
"non-numeric indices not supported by ") + class_name()));
267 throw(std::invalid_argument(std::string(
"non-numeric indices not supported by ") + class_name()));
282 if (
match(pattern, repl_lst))
284 for (
size_t i=0; i<
nops(); i++)
285 if (
op(i).
has(pattern, options))
299 basic *copy =
nullptr;
300 for (
size_t i=0; i<num; i++) {
301 const ex & o =
op(i);
341 return n==0 ? *this :
_ex0;
358 else if (distributed) {
367 for (
const auto & xi : x) {
370 for (
auto & li : l) {
371 int cexp = pre_coeff.
degree(li);
372 pre_coeff = pre_coeff.
coeff(li, cexp);
373 key *=
pow(li, cexp);
375 auto ci = cmap.find(key);
376 if (ci != cmap.end())
377 ci->second += pre_coeff;
379 cmap.insert(exmap::value_type(key, pre_coeff));
383 for (
auto & mi : cmap)
384 resv.push_back((mi.first)*(mi.second));
391 size_t n = s.
nops() - 1;
408 return x + (*
this - x).
expand();
430 return map(map_evalf);
541 for (
auto & it : repl_lst) {
542 if (it.first.is_equal(pattern))
545 repl_lst[pattern] = *
this;
571 exmap tmp_repl = repl_lst;
573 for (
size_t i=0; i<
nops(); i++)
574 if (!
op(i).
match(pattern.
op(i), tmp_repl))
588 auto it = m.find(thisex);
593 for (
auto & it : m) {
612 for (
size_t i=0; i<num; i++) {
613 const ex & orig_op =
op(i);
614 const ex & subsed_op = orig_op.
subs(m, options);
622 copy->
let_op(i++) = subsed_op;
626 copy->
let_op(i) =
op(i).subs(m, options);
653 return ex(*this).diff(s, nth);
658 ndiff = ndiff.
diff(s);
677 return real_part_function(*this).hold();
682 return imag_part_function(*this).hold();
709 return map(map_derivative);
758 rt.
tinfo = &
typeid(*this);
771 unsigned v = make_hash_seed(
typeid(*
this));
772 for (
size_t i=0; i<
nops(); i++) {
774 v ^= this->
op(i).gethash();
817#ifdef GINAC_COMPARE_STATISTICS
818 compare_statistics.total_basic_compares++;
820 const unsigned hash_this =
gethash();
821 const unsigned hash_other = other.
gethash();
822 if (hash_this<hash_other)
return -1;
823 if (hash_this>hash_other)
return 1;
824#ifdef GINAC_COMPARE_STATISTICS
825 compare_statistics.compare_same_hashvalue++;
828 const std::type_info& typeid_this =
typeid(*this);
829 const std::type_info& typeid_other =
typeid(other);
830 if (typeid_this == typeid_other) {
841#ifdef GINAC_COMPARE_STATISTICS
842 compare_statistics.compare_same_type++;
852 return (typeid_this.before(typeid_other) ? -1 : 1);
864#ifdef GINAC_COMPARE_STATISTICS
865 compare_statistics.total_basic_is_equals++;
869#ifdef GINAC_COMPARE_STATISTICS
870 compare_statistics.is_equal_same_hashvalue++;
872 if (
typeid(*
this) !=
typeid(other))
875#ifdef GINAC_COMPARE_STATISTICS
876 compare_statistics.is_equal_same_type++;
896 throw(std::runtime_error(
"cannot modify multiply referenced object"));
904#ifdef GINAC_COMPARE_STATISTICS
905compare_statistics_t::~compare_statistics_t()
907 std::clog <<
"ex::compare() called " << total_compares <<
" times" << std::endl;
908 std::clog <<
"nontrivial compares: " << nontrivial_compares <<
" times" << std::endl;
909 std::clog <<
"basic::compare() called " << total_basic_compares <<
" times" << std::endl;
910 std::clog <<
"same hashvalue in compare(): " << compare_same_hashvalue <<
" times" << std::endl;
911 std::clog <<
"compare_same_type() called " << compare_same_type <<
" times" << std::endl;
912 std::clog << std::endl;
913 std::clog <<
"ex::is_equal() called " << total_is_equals <<
" times" << std::endl;
914 std::clog <<
"nontrivial is_equals: " << nontrivial_is_equals <<
" times" << std::endl;
915 std::clog <<
"basic::is_equal() called " << total_basic_is_equals <<
" times" << std::endl;
916 std::clog <<
"same hashvalue in is_equal(): " << is_equal_same_hashvalue <<
" times" << std::endl;
917 std::clog <<
"is_equal_same_type() called " << is_equal_same_type <<
" times" << std::endl;
918 std::clog << std::endl;
919 std::clog <<
"basic::gethash() called " << total_gethash <<
" times" << std::endl;
920 std::clog <<
"used cached hashvalue " << gethash_cached <<
" times" << std::endl;
923compare_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)
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.