118 c.s << openbrace <<
'(';
130 for (
auto & it :
seq) {
131 coeff = ex_to<numeric>(it.coeff);
133 if (
coeff.csgn() == -1)
c.s <<
'-';
else c.s <<
'+';
135 if (
coeff.csgn() == -1)
c.s <<
'-';
140 if (
coeff.is_rational()) {
141 if (
coeff.is_negative())
146 if (
coeff.csgn() == -1)
157 c.s <<
')' << closebrace;
176 char separator =
' ';
177 for (
auto & it :
seq) {
180 if (it.coeff.is_equal(
_ex_1) ||
181 ex_to<numeric>(it.coeff).numer().is_equal(*
_num_1_p))
184 if (it.coeff.is_equal(
_ex1) || it.coeff.is_equal(
_ex_1)) {
186 }
else if (ex_to<numeric>(it.coeff).numer().is_equal(*
_num1_p) ||
187 ex_to<numeric>(it.coeff).numer().is_equal(*
_num_1_p))
191 ex_to<numeric>(it.coeff).denom().print(
c,
precedence());
214 c.s << class_name() <<
'(';
216 for (
size_t i=1; i<
nops(); ++i) {
242 for (
auto & i :
seq) {
251 return inherited::info(inf);
256 for (
auto & i :
seq) {
257 if (!i.rest.is_polynomial(var)) {
266 int deg = std::numeric_limits<int>::min();
271 for (
auto & i :
seq) {
272 int cur_deg = i.rest.degree(s);
281 int deg = std::numeric_limits<int>::max();
286 for (
auto & i :
seq) {
287 int cur_deg = i.rest.ldegree(s);
299 bool do_clifford = (rl != -1);
300 bool nonscalar =
false;
303 for (
auto & i :
seq) {
310 coeffseq_cliff.push_back(
expair(restcoeff, i.
coeff));
318 return dynallocate<add>(nonscalar ? std::move(coeffseq_cliff) : std::move(coeffseq),
342#ifdef DO_GINAC_ASSERT
343 for (
auto & i :
seq) {
348 size_t seq_size =
seq.size();
356 throw (std::logic_error(
"add::eval(): sum of non-commutative objects has non-zero numeric term"));
367 s.reserve(
seq.size());
369 bool all_matrices =
true;
370 bool first_term =
true;
373 for (
auto & it :
seq) {
376 if (is_a<matrix>(
m)) {
378 sum = ex_to<matrix>(
m);
381 sum = sum.
add(ex_to<matrix>(
m));
383 all_matrices =
false;
394 std::unique_ptr<exvector> v(
nullptr);
395 for (
size_t i=0; i<
nops(); ++i) {
406 for (
size_t j=0; j<i; ++j)
408 v->push_back(ccterm);
411 return add(std::move(*v));
419 v.reserve(
seq.size());
420 for (
auto & it :
seq)
436 v.reserve(
seq.size());
437 for (
auto & it :
seq)
453 return inherited::eval_ncmul(v);
455 return seq.begin()->rest.eval_ncmul(v);
465 s.reserve(
seq.size());
470 for (
auto & it :
seq)
471 s.push_back(
expair(it.rest.diff(y), it.coeff));
473 return dynallocate<add>(std::move(s));
478 return inherited::compare_same_type(other);
486 return seq.begin()->rest.return_type();
492 return make_return_type_t<add>();
494 return seq.begin()->rest.return_type_tinfo();
500 return dynallocate<add>(v, oc);
506 return dynallocate<add>(std::move(vp), oc);
511 if (is_exactly_a<mul>(e)) {
512 const mul &mulref(ex_to<mul>(e));
516 mul & mulcopy = dynallocate<mul>(mulref);
519 return expair(mulcopy, numfactor);
528 if (is_exactly_a<mul>(e)) {
529 const mul &mulref(ex_to<mul>(e));
533 mul & mulcopy = dynallocate<mul>(mulref);
536 if (
c.is_equal(
_ex1))
537 return expair(mulcopy, numfactor);
539 return expair(mulcopy, ex_to<numeric>(numfactor).mul_dyn(ex_to<numeric>(
c)));
540 }
else if (is_exactly_a<numeric>(e)) {
541 if (
c.is_equal(
_ex1))
545 return expair(ex_to<numeric>(e).mul_dyn(ex_to<numeric>(
c)),
_ex1);
556 if (is_exactly_a<numeric>(p.
rest)) {
569 return dynallocate<mul>(p.
rest, p.
coeff);
575 if (expanded.empty())
Interface to GiNaC's sums of expressions.
Archiving of GiNaC expressions.
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
add(const ex &lh, const ex &rh)
unsigned return_type() const override
ex derivative(const symbol &s) const override
Implementation of ex::diff() for a sum.
ex coeff(const ex &s, int n=1) const override
Return coefficient of degree n in object s.
void print_add(const print_context &c, const char *openbrace, const char *closebrace, const char *mul_sym, unsigned level) const
ex eval() const override
Perform automatic term rewriting rules in this class.
void do_print(const print_context &c, unsigned level) const
ex real_part() const override
int degree(const ex &s) const override
Return degree of highest power in object s.
void do_print_python_repr(const print_python_repr &c, unsigned level) const
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
bool info(unsigned inf) const override
Information about the object.
int ldegree(const ex &s) const override
Return degree of lowest power in object s.
ex eval_ncmul(const exvector &v) const override
ex thisexpairseq(const epvector &v, const ex &oc, bool do_index_renaming=false) const override
Create an object of this type.
void do_print_latex(const print_latex &c, unsigned level) const
ex conjugate() const override
ex expand(unsigned options=0) const override
Expand expression, i.e.
expair combine_ex_with_coeff_to_pair(const ex &e, const ex &c) const override
ex evalm() const override
Evaluate sums, products and integer powers of matrices.
return_type_t return_type_tinfo() const override
expair split_ex_to_pair(const ex &e) const override
Form an expair from an ex, using the corresponding semantics.
ex imag_part() const override
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
void do_print_csrc(const print_csrc &c, unsigned level) const
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
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.
unsigned flags
of type status_flags
virtual void print(const print_context &c, unsigned level=0) const
Output to stream.
const basic & hold() const
Stop further evaluation.
virtual int compare_same_type(const basic &other) const
Returns order relation between two objects of same type.
Lightweight wrapper for GiNaC's symbolic objects.
bool is_equal(const ex &other) const
bool info(unsigned inf) const
void print(const print_context &c, unsigned level=0) const
Print expression to stream.
ex coeff(const ex &s, int n=1) const
ex rest
first member of pair, an arbitrary expression
ex coeff
second member of pair, must be numeric
A sequence of class expair.
size_t nops() const override
Number of operands/members.
void construct_from_epvector(const epvector &v, bool do_index_renaming=false)
void construct_from_2_ex(const ex &lh, const ex &rh)
bool is_canonical() const
Check if this expairseq is in sorted (canonical) form.
void construct_from_exvector(const exvector &v)
epvector evalchildren() const
Member-wise evaluate the expairs in this sequence.
ex op(size_t i) const override
Return operand/member at position i.
void do_print_tree(const print_tree &c, unsigned level) const
epvector expandchildren(unsigned options) const
Member-wise expand the expairs in this sequence.
matrix add(const matrix &other) const
Sum of matrices.
Non-commutative product of expressions.
ex coeff(const ex &s, int n=1) const override
Return coefficient of degree n in object s.
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
Base class for print_contexts.
Base context for C source output.
Context for latex-parsable output.
Context for python-parsable 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
Interface to GiNaC's clifford algebra (Dirac gamma) objects.
Definition of optimizing macros.
Interface to symbolic matrices.
Interface to GiNaC's products of expressions.
int clifford_max_label(const ex &e, bool ignore_ONE)
Returns the maximal representation label of a clifford object if e contains at least one,...
std::vector< expair > epvector
expair-vector
ex dirac_ONE(unsigned char rl)
Create a Clifford unity object.
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
print_func< print_context >(&varidx::do_print). print_func< print_latex >(&varidx
GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(add, expairseq, print_func< print_context >(&add::do_print). print_func< print_latex >(&add::do_print_latex). print_func< print_csrc >(&add::do_print_csrc). print_func< print_tree >(&add::do_print_tree). print_func< print_python_repr >(&add::do_print_python_repr)) add
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.
std::vector< ex > exvector
Interface to GiNaC's non-commutative products of expressions.
Interface to GiNaC's overloaded operators.
To distinguish between different kinds of non-commutative objects.
Interface to several small and furry utilities needed within GiNaC but not of any interest to the use...