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