74 inherited::read_archive(
n, sym_lst);
75 n.find_ex(
"basis",
basis, sym_lst);
81 inherited::archive(
n);
96 c.s << openbrace <<
'(';
103 c.s <<
')' << closebrace;
146 }
else if (
exp == 2) {
150 }
else if (
exp & 1) {
182 (is_a<symbol>(
basis) || is_a<constant>(
basis))) {
216 c.s << class_name() <<
'(';
259 return inherited::info(inf);
276 const ex &mapped_basis = f(
basis);
281 return dynallocate<power>(mapped_basis, mapped_exponent);
306 return ex_to<numeric>(
exponent).to_int();
310 throw(std::runtime_error(
"power::degree(): undefined degree because of non-integer exponent"));
321 return ex_to<numeric>(
exponent).to_int();
325 throw(std::runtime_error(
"power::ldegree(): undefined degree because of non-integer exponent"));
344 int int_exp = ex_to<numeric>(
exponent).to_int();
378 const numeric *num_basis =
nullptr;
379 const numeric *num_exponent =
nullptr;
381 if (is_exactly_a<numeric>(
basis)) {
382 num_basis = &ex_to<numeric>(
basis);
384 if (is_exactly_a<numeric>(
exponent)) {
385 num_exponent = &ex_to<numeric>(
exponent);
391 throw (std::domain_error(
"power::eval(): pow(0,0) is undefined"));
402 if ((num_exponent->
real()).is_zero())
403 throw (std::domain_error(
"power::eval(): pow(0,I) is undefined"));
404 else if ((num_exponent->
real()).is_negative())
405 throw (
pole_error(
"power::eval(): division by zero",1));
415 if (is_exactly_a<function>(
basis))
422 if ( num_exponent ) {
427 const bool basis_is_crational = num_basis->
is_crational();
428 const bool exponent_is_crational = num_exponent->
is_crational();
429 if (!basis_is_crational || !exponent_is_crational) {
431 return dynallocate<numeric>(num_basis->
power(*num_exponent));
441 if (basis_is_crational && exponent_is_crational
448 if (
r.is_negative()) {
479 if (is_exactly_a<power>(
basis)) {
480 const power & sub_power = ex_to<power>(
basis);
481 const ex & sub_basis = sub_power.
basis;
483 if (is_exactly_a<numeric>(sub_exponent)) {
484 const numeric & num_sub_exponent = ex_to<numeric>(sub_exponent);
488 return dynallocate<power>(sub_basis, num_sub_exponent.
mul(*num_exponent));
502 ex_to<numeric>(ex_to<add>(
basis).seq.begin()->coeff).
div(icont);
504 const bool canonicalizable = lead_coeff.
is_integer();
506 if (canonicalizable && (! unit_normal))
509 if (canonicalizable && (icont != *
_num1_p)) {
510 const add& addref = ex_to<add>(
basis);
511 add & addp = dynallocate<add>(addref);
514 for (
auto & i : addp.
seq)
515 i.
coeff = ex_to<numeric>(i.coeff).div_dyn(icont);
519 return dynallocate<mul>(dynallocate<power>(addp, *num_exponent),
c);
521 return dynallocate<power>(addp, *num_exponent);
527 if (is_exactly_a<mul>(
basis)) {
529 const mul & mulref = ex_to<mul>(
basis);
534 mul & mulp = dynallocate<mul>(mulref);
537 return dynallocate<mul>(dynallocate<power>(mulp,
exponent),
538 dynallocate<power>(num_coeff, *num_exponent));
542 mul & mulp = dynallocate<mul>(mulref);
545 return dynallocate<mul>(dynallocate<power>(mulp,
exponent),
546 dynallocate<power>(
abs(num_coeff), *num_exponent));
556 !is_a<matrix>(
basis)) {
569 if (!is_exactly_a<numeric>(
exponent))
574 return dynallocate<power>(ebasis, eexponent);
581 if (is_a<matrix>(ebasis)) {
582 if (is_exactly_a<numeric>(eexponent)) {
583 return dynallocate<matrix>(ex_to<matrix>(ebasis).
pow(eexponent));
586 return dynallocate<power>(ebasis, eexponent);
593 if (!is_a<power>(other))
600 ex_to<numeric>(
exponent) > ex_to<numeric>(other.
op(1)) &&
605 ex_to<numeric>(
exponent) < ex_to<numeric>(other.
op(1)) &&
621 return dynallocate<power>(subsed_basis, subsed_exponent);
626 for (
auto & it :
m) {
627 int nummatches = std::numeric_limits<int>::max();
629 if (
tryfactsubs(*
this, it.first, nummatches, repls)) {
632 ex result = (*this) *
pow(anum/aden, nummatches);
633 return (ex_to<basic>(result)).subs_one_level(
m,
options);
642 return inherited::eval_ncmul(v);
654 return dynallocate<power>(
basis, newexponent);
661 return dynallocate<power>(newbasis,
exponent);
663 return conjugate_function(*this).hold();
680 long N = ex_to<numeric>(
c).to_long();
683 long NN = N > 0 ? N : -N;
686 for (
long n = 0;
n <= NN;
n += 2) {
716 long N = ex_to<numeric>(
c).to_long();
719 long p = N > 0 ? 1 : 3;
720 long NN = N > 0 ? N : -N;
723 for (
long n = 1;
n <= NN;
n += 2) {
748 return dynallocate<mul>(std::move(newseq),
exponent);
758 const power &o =
static_cast<const power &
>(other);
791 prodseq.reserve(
m.seq.size() + 1);
792 powseq.reserve(
m.seq.size() + 1);
796 for (
auto & cit :
m.seq) {
797 ex e=
m.recombine_pair_to_ex(cit);
804 powseq.push_back(cit);
820 if (prodseq.size() > 0) {
821 ex newbasis = dynallocate<mul>(std::move(powseq),
coeff);
823 return dynallocate<mul>(std::move(prodseq)) *
pow(newbasis,
exponent);
832 if (is_exactly_a<add>(expanded_exponent)) {
833 const add &a = ex_to<add>(expanded_exponent);
835 distrseq.reserve(a.
seq.size() + 1);
836 for (
auto & cit : a.
seq) {
843 long int_exponent = num_exponent.
to_int();
844 if (int_exponent > 0 && is_exactly_a<add>(expanded_basis))
845 distrseq.push_back(
expand_add(ex_to<add>(expanded_basis), int_exponent,
options));
852 ex r = dynallocate<mul>(distrseq);
856 if (!is_exactly_a<numeric>(expanded_exponent) ||
857 !ex_to<numeric>(expanded_exponent).
is_integer()) {
866 const numeric & num_exponent = ex_to<numeric>(expanded_exponent);
867 long int_exponent = num_exponent.
to_long();
870 if (int_exponent > 0 && is_exactly_a<add>(expanded_basis))
874 if (is_exactly_a<mul>(expanded_basis))
963 result.reserve(result_size);
968 for (
int k = 1;
k <=
n; ++
k) {
973 binomial_coefficient = 1;
986 const std::vector<unsigned>& partition = partitions.
get();
988 const unsigned msize = std::count_if(partition.begin(), partition.end(), [](
int i) { return i > 0; });
994 const std::vector<unsigned>&
exponent = compositions.
get();
996 monomial.reserve(msize);
998 for (
unsigned i = 0; i <
exponent.size(); ++i) {
999 const ex &
r = a.
seq[i].rest;
1002 !is_exactly_a<numeric>(ex_to<power>(
r).
exponent) ||
1004 !is_exactly_a<add>(ex_to<power>(
r).
basis) ||
1005 !is_exactly_a<mul>(ex_to<power>(
r).
basis) ||
1006 !is_exactly_a<power>(ex_to<power>(
r).
basis));
1008 const numeric &
c = ex_to<numeric>(a.
seq[i].coeff);
1023 }
while (compositions.
next());
1024 }
while (partitions.
next());
1041 size_t result_size = (a.
nops() * (a.
nops()+1)) / 2;
1046 result.reserve(result_size);
1052 for (
auto cit0=a.
seq.begin(); cit0!=
last; ++cit0) {
1053 const ex &
r = cit0->rest;
1058 !is_exactly_a<numeric>(ex_to<power>(
r).
exponent) ||
1060 !is_exactly_a<add>(ex_to<power>(
r).
basis) ||
1061 !is_exactly_a<mul>(ex_to<power>(
r).
basis) ||
1062 !is_exactly_a<power>(ex_to<power>(
r).
basis));
1064 if (
c.is_equal(
_ex1)) {
1065 if (is_exactly_a<mul>(
r)) {
1069 result.emplace_back(
expair(dynallocate<power>(
r,
_ex2),
1073 if (is_exactly_a<mul>(
r)) {
1075 ex_to<numeric>(
c).power_dyn(*
_num2_p)));
1077 result.emplace_back(
expair(dynallocate<power>(
r,
_ex2),
1078 ex_to<numeric>(
c).power_dyn(*
_num2_p)));
1082 for (
auto cit1=cit0+1; cit1!=
last; ++cit1) {
1083 const ex & r1 = cit1->rest;
1092 for (
auto & i : a.
seq)
1126 for (
int i=1; i <
n.to_int(); i++)
1132 distrseq.reserve(
m.seq.size());
1133 bool need_reexpand =
false;
1135 for (
auto & cit :
m.seq) {
1136 expair p =
m.combine_pair_with_coeff_to_pair(cit,
n);
1137 if (from_expand && is_exactly_a<add>(cit.rest) && ex_to<numeric>(p.
coeff).is_pos_integer()) {
1140 need_reexpand =
true;
1142 distrseq.push_back(p);
1145 const mul & result = dynallocate<mul>(std::move(distrseq), ex_to<numeric>(
m.overall_coeff).power_dyn(
n));
Interface to GiNaC's sums of expressions.
Archiving of GiNaC expressions.
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
ex recombine_pair_to_ex(const expair &p) const override
Form an ex out of an expair, using the corresponding semantics.
expair combine_pair_with_coeff_to_pair(const expair &p, const ex &c) const override
This class stores all properties needed to record/retrieve the state of one object of class basic (or...
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
const basic & clearflag(unsigned f) const
Clear some status_flags.
const basic & setflag(unsigned f) const
Set some status_flags.
virtual bool has(const ex &other, unsigned options=0) const
Test for occurrence of a pattern.
unsigned flags
of type status_flags
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 int compare_same_type(const basic &other) const
Returns order relation between two objects of same type.
virtual ex expand(unsigned options=0) const
Expand expression, i.e.
Generate all compositions of a partition of an integer n, starting with the compositions which has no...
const std::vector< unsigned > & get() const
Wrapper template for making GiNaC classes out of STL containers.
Lightweight wrapper for GiNaC's symbolic objects.
numeric integer_content() const
Compute the integer content (= GCD of all numeric coefficients) of an expanded polynomial.
bool match(const ex &pattern) const
Check whether expression matches a specified pattern.
bool is_polynomial(const ex &vars) const
Check whether expression is a polynomial.
ex diff(const symbol &s, unsigned nth=1) const
Compute partial derivative of an expression.
ex expand(unsigned options=0) const
Expand an expression.
bool is_equal(const ex &other) const
int degree(const ex &s) const
bool has(const ex &pattern, unsigned options=0) const
unsigned return_type() const
return_type_t return_type_tinfo() const
ex subs(const exmap &m, unsigned options=0) const
bool info(unsigned inf) const
int compare(const ex &other) const
void print(const print_context &c, unsigned level=0) const
Print expression to stream.
int ldegree(const ex &s) const
ex coeff(const ex &s, int n=1) const
ex coeff
second member of pair, must be numeric
size_t nops() const override
Number of operands/members.
@ expand_rename_idx
used internally by mul::expand()
@ algebraic
enable algebraic matching
Non-commutative product of expressions.
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
bool is_pos_integer() const
True if object is an exact integer greater than zero.
const numeric & mul_dyn(const numeric &other) const
Numerical multiplication method.
bool is_crational() const
True if object is an exact rational number, may even be complex (denominator may be unity).
bool is_rational() const
True if object is an exact rational number, may even be complex (denominator may be unity).
const numeric real() const
Real part of a number.
long to_long() const
Converts numeric types to machine's long.
int compare(const numeric &other) const
This method establishes a canonical order on all numbers.
bool is_positive() const
True if object is not complex and greater than zero.
bool is_real() const
True if object is a real integer, rational or float (but not complex).
const numeric numer() const
Numerator.
bool is_integer() const
True if object is a non-complex integer.
const numeric power(const numeric &other) const
Numerical exponentiation.
const numeric denom() const
Denominator.
const numeric mul(const numeric &other) const
Numerical multiplication method.
bool is_equal(const numeric &other) const
int to_int() const
Converts numeric types to machine's int.
const numeric inverse() const
Inverse of a number.
bool is_zero() const
True if object is zero.
const numeric div(const numeric &other) const
Numerical division method.
Generate all bounded combinatorial partitions of an integer n with exactly m parts (including zero pa...
const std::vector< unsigned > & get() const
Exception class thrown when a singularity is encountered.
This class holds a two-component object, a basis and and exponent representing exponentiation.
static ex expand_mul(const mul &m, const numeric &n, unsigned options, bool from_expand=false)
Expand factors of m in m^n where m is a mul and n is an integer.
void do_print_dflt(const print_dflt &c, unsigned level) const
void do_print_csrc(const print_csrc &c, unsigned level) const
static ex expand_add(const add &a, long n, unsigned options)
expand a^n where a is an add and n is a positive integer.
int degree(const ex &s) const override
Return degree of highest power in object s.
void read_archive(const archive_node &n, lst &syms) override
Read (a.k.a.
ex subs(const exmap &m, unsigned options=0) const override
Substitute a set of objects by arbitrary expressions.
int ldegree(const ex &s) const override
Return degree of lowest power in object s.
static ex expand_add_2(const add &a, unsigned options)
Special case of power::expand_add.
ex real_part() const override
void archive(archive_node &n) const override
Save (a.k.a.
ex derivative(const symbol &s) const override
Implementation of ex::diff() for a power.
ex map(map_function &f) const override
Construct new expression by applying the specified function to all sub-expressions (one level only,...
ex eval() const override
Perform automatic term rewriting rules in this class.
void do_print_python(const print_python &c, unsigned level) const
void print_power(const print_context &c, const char *powersymbol, const char *openbrace, const char *closebrace, unsigned level) const
void do_print_python_repr(const print_python_repr &c, unsigned level) const
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
ex op(size_t i) const override
Return operand/member at position i.
power(const ex &lh, const ex &rh)
void do_print_latex(const print_latex &c, unsigned level) const
ex conjugate() const override
ex coeff(const ex &s, int n=1) const override
Return coefficient of degree n in object s.
bool has(const ex &other, unsigned options=0) const override
Test for occurrence of a pattern.
ex evalm() const override
Evaluate sums, products and integer powers of matrices.
return_type_t return_type_tinfo() const override
size_t nops() const override
Number of operands/members.
ex expand(unsigned options=0) const override
Expand expression, i.e.
bool info(unsigned inf) const override
Information about the object.
ex eval_ncmul(const exvector &v) const override
void do_print_csrc_cl_N(const print_csrc_cl_N &c, unsigned level) const
unsigned return_type() const override
ex imag_part() const override
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
ex evalf() const override
Evaluate object numerically.
Base class for print_contexts.
Context for C source output using CLN numbers.
Base context for C source output.
Context for default (ginsh-parsable) output.
Context for latex-parsable output.
Context for python-parsable output.
Context for python pretty-print output.
@ 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
@ algebraic
enable algebraic substitutions
Definition of optimizing macros.
Interface to GiNaC's constant types and some special constants.
Interface to sequences of expression pairs.
Interface to GiNaC's indexed expressions.
Interface to GiNaC's initially known functions.
Definition of GiNaC's lst.
Interface to symbolic matrices.
Interface to GiNaC's products of expressions.
const numeric pow(const numeric &x, const numeric &y)
std::map< ex, ex, ex_is_less > exmap
std::vector< expair > epvector
expair-vector
const numeric abs(const numeric &x)
Absolute value.
bool is_negative(const numeric &x)
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
const numeric binomial(const numeric &n, const numeric &k)
The Binomial coefficients.
print_func< print_dflt >(&diracone::do_print). print_func< print_latex >(&diracone
const numeric exp(const numeric &x)
Exponential function.
const numeric cos(const numeric &x)
Numeric cosine (trigonometric function).
const numeric iquo(const numeric &a, const numeric &b)
Numeric integer quotient.
bool is_pos_integer(const numeric &x)
const numeric log(const numeric &x)
Natural logarithm.
const numeric sin(const numeric &x)
Numeric sine (trigonometric function).
ex numer(const ex &thisex)
ex factor(const ex &poly, unsigned options)
Interface function to the outside world.
bool is_integer(const numeric &x)
static void print_sym_pow(const print_context &c, const symbol &x, int exp)
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...
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT_T(lst, basic, print_func< print_context >(&lst::do_print). print_func< print_tree >(&lst::do_print_tree)) template<> bool lst GINAC_BIND_UNARCHIVER(lst)
Specialization of container::info() for lst.
bool tryfactsubs(const ex &origfactor, const ex &patternfactor, int &nummatches, exmap &repls)
std::vector< ex > exvector
exvector get_all_dummy_indices(const ex &e)
Returns all dummy indices from the exvector.
const numeric multinomial_coefficient(const std::vector< unsigned > &p)
Compute the multinomial coefficient n!/(p1!*p2!*...*pk!) where n = p1+p2+...+pk, i....
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 for map().
To distinguish between different kinds of non-commutative objects.
Interface to GiNaC's symbolic objects.
Interface to several small and furry utilities needed within GiNaC but not of any interest to the use...