115 c.s << openbrace <<
'(';
127 for (
auto & it :
seq) {
128 coeff = ex_to<numeric>(it.coeff);
130 if (
coeff.csgn() == -1)
c.s <<
'-';
else c.s <<
'+';
132 if (
coeff.csgn() == -1)
c.s <<
'-';
137 if (
coeff.is_rational()) {
138 if (
coeff.is_negative())
143 if (
coeff.csgn() == -1)
154 c.s <<
')' << closebrace;
173 char separator =
' ';
174 for (
auto & it :
seq) {
177 if (it.coeff.is_equal(
_ex_1) ||
178 ex_to<numeric>(it.coeff).numer().is_equal(*
_num_1_p))
181 if (it.coeff.is_equal(
_ex1) || it.coeff.is_equal(
_ex_1)) {
183 }
else if (ex_to<numeric>(it.coeff).numer().is_equal(*
_num1_p) ||
184 ex_to<numeric>(it.coeff).numer().is_equal(*
_num_1_p))
188 ex_to<numeric>(it.coeff).denom().print(
c,
precedence());
211 c.s << class_name() <<
'(';
213 for (
size_t i=1; i<
nops(); ++i) {
239 for (
auto & i :
seq) {
248 return inherited::info(inf);
253 for (
auto & i :
seq) {
254 if (!i.rest.is_polynomial(var)) {
263 int deg = std::numeric_limits<int>::min();
268 for (
auto & i :
seq) {
269 int cur_deg = i.rest.degree(s);
278 int deg = std::numeric_limits<int>::max();
283 for (
auto & i :
seq) {
284 int cur_deg = i.rest.ldegree(s);
296 bool do_clifford = (rl != -1);
297 bool nonscalar =
false;
300 for (
auto & i :
seq) {
307 coeffseq_cliff.push_back(
expair(restcoeff, i.
coeff));
315 return dynallocate<add>(nonscalar ? std::move(coeffseq_cliff) : std::move(coeffseq),
339#ifdef DO_GINAC_ASSERT
340 for (
auto & i :
seq) {
345 size_t seq_size =
seq.size();
353 throw (std::logic_error(
"add::eval(): sum of non-commutative objects has non-zero numeric term"));
364 s.reserve(
seq.size());
366 bool all_matrices =
true;
367 bool first_term =
true;
370 for (
auto & it :
seq) {
373 if (is_a<matrix>(
m)) {
375 sum = ex_to<matrix>(
m);
378 sum = sum.
add(ex_to<matrix>(
m));
380 all_matrices =
false;
391 std::unique_ptr<exvector> v(
nullptr);
392 for (
size_t i=0; i<
nops(); ++i) {
403 for (
size_t j=0; j<i; ++j)
405 v->push_back(ccterm);
408 return add(std::move(*v));
416 v.reserve(
seq.size());
417 for (
auto & it :
seq)
433 v.reserve(
seq.size());
434 for (
auto & it :
seq)
450 return inherited::eval_ncmul(v);
452 return seq.begin()->rest.eval_ncmul(v);
462 s.reserve(
seq.size());
467 for (
auto & it :
seq)
468 s.push_back(
expair(it.rest.diff(y), it.coeff));
470 return dynallocate<add>(std::move(s));
475 return inherited::compare_same_type(other);
483 return seq.begin()->rest.return_type();
489 return make_return_type_t<add>();
491 return seq.begin()->rest.return_type_tinfo();
497 return dynallocate<add>(v, oc);
503 return dynallocate<add>(std::move(vp), oc);
508 if (is_exactly_a<mul>(e)) {
509 const mul &mulref(ex_to<mul>(e));
513 mul & mulcopy = dynallocate<mul>(mulref);
516 return expair(mulcopy, numfactor);
525 if (is_exactly_a<mul>(e)) {
526 const mul &mulref(ex_to<mul>(e));
530 mul & mulcopy = dynallocate<mul>(mulref);
533 if (
c.is_equal(
_ex1))
534 return expair(mulcopy, numfactor);
536 return expair(mulcopy, ex_to<numeric>(numfactor).mul_dyn(ex_to<numeric>(
c)));
537 }
else if (is_exactly_a<numeric>(e)) {
538 if (
c.is_equal(
_ex1))
542 return expair(ex_to<numeric>(e).mul_dyn(ex_to<numeric>(
c)),
_ex1);
553 if (is_exactly_a<numeric>(p.
rest)) {
566 return dynallocate<mul>(p.
rest, p.
coeff);
572 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.
void do_print_tree(const print_tree &c, unsigned level) const
Tree output to stream.
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.
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_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.
#define GINAC_IMPLEMENT_REGISTERED_CLASS_OPT(classname, supername, options)
Macro for inclusion in the implementation of each registered class.
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...