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) ||
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) ||
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) {
346 #endif // def DO_GINAC_ASSERT 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())
ex expand(unsigned options=0) const override
Expand expression, i.e.
Non-commutative product of expressions.
return_type_t return_type_tinfo() const override
void do_print_python_repr(const print_python_repr &c, unsigned level) const
ex coeff(const ex &s, int n=1) const
A sequence of class expair.
int degree(const ex &s) const override
Return degree of highest power in object s.
bool is_polynomial(const ex &var) const override
Check whether this is a polynomial in the given variables.
ex conjugate() const override
void do_print_latex(const print_latex &c, unsigned level) const
ex thisexpairseq(const epvector &v, const ex &oc, bool do_index_renaming=false) const override
const basic & hold() const
Stop further evaluation.
Interface to GiNaC's clifford algebra (Dirac gamma) objects.
bool is_equal(const ex &other) const
const basic & setflag(unsigned f) const
Set some status_flags.
ex denom(const ex &thisex)
unsigned precedence() const override
Return relative operator precedence (for parenthezing output).
epvector expandchildren(unsigned options) const
void print_add(const print_context &c, const char *openbrace, const char *closebrace, const char *mul_sym, unsigned level) const
Archiving of GiNaC expressions.
Interface to GiNaC's sums of expressions.
void do_print_tree(const print_tree &c, unsigned level) const
This class is the ABC (abstract base class) of GiNaC's class hierarchy.
Context for python-parsable output.
bool are_ex_trivially_equal(const ex &e1, const ex &e2)
Compare two objects of class quickly without doing a deep tree traversal.
ex coeff(const ex &s, int n=1) const override
Return coefficient of degree n in object s.
Interface to GiNaC's products of expressions.
ex evalm() const override
Evaluate sums, products and integer powers of matrices.
ex derivative(const symbol &s) const override
Implementation of ex::diff() for a sum.
matrix add(const matrix &other) const
Sum of matrices.
unsigned return_type() const override
bool info(unsigned inf) const override
Information about the object.
bool info(unsigned inf) const
ex imag_part() const override
Interface to several small and furry utilities needed within GiNaC but not of any interest to the use...
ex numer(const ex &thisex)
expair combine_ex_with_coeff_to_pair(const ex &e, const ex &c) const override
Definition of optimizing macros.
void do_print_csrc(const print_csrc &c, unsigned level) const
This class is a wrapper around CLN-numbers within the GiNaC class hierarchy.
Context for latex-parsable output.
print_func< print_context >(&varidx::do_print). print_func< print_latex >(&varidx
void construct_from_epvector(const epvector &v, bool do_index_renaming=false)
ex eval() const override
Perform automatic term rewriting rules in this class.
#define GINAC_ASSERT(X)
Assertion macro for checking invariances.
expair combine_pair_with_coeff_to_pair(const expair &p, const ex &c) const override
void construct_from_2_ex(const ex &lh, const ex &rh)
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
To distinguish between different kinds of non-commutative objects.
Interface to symbolic matrices.
std::vector< ex > exvector
Interface to GiNaC's overloaded operators.
Base class for print_contexts.
expair split_ex_to_pair(const ex &e) const override
ex real_part() const override
ex op(size_t i) const override
Return operand/member at position i.
ex coeff(const ex &s, int n=1) const override
Return coefficient of degree n in object s.
void do_print(const print_context &c, unsigned level) const
add(const ex &lh, const ex &rh)
const basic & clearflag(unsigned f) const
Clear some status_flags.
ex coeff
second member of pair, must be numeric
void print(const print_context &c, unsigned level=0) const
Print expression to stream.
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...
Lightweight wrapper for GiNaC's symbolic objects.
ex eval_ncmul(const exvector &v) const override
Interface to GiNaC's non-commutative products of expressions.
ex recombine_pair_to_ex(const expair &p) const override
.calchash() has already done its job
ex dirac_ONE(unsigned char rl)
Create a Clifford unity object.
virtual int compare_same_type(const basic &other) const
Returns order relation between two objects of same type.
.expand(0) has already done its job (other expand() options ignore this flag)
Base context for C source output.
std::vector< expair > epvector
expair-vector
int ldegree(const ex &s) const override
Return degree of lowest power in object s.
bool is_canonical() const
ex rest
first member of pair, an arbitrary expression
size_t nops() const override
Number of operands/members.
void construct_from_exvector(const exvector &v)
.eval() has already done its job
unsigned flags
of type status_flags
GINAC_BIND_UNARCHIVER(add)
epvector evalchildren() const