116 c.s << openbrace <<
'(';
128 for (
auto & it :
seq) {
129 coeff = ex_to<numeric>(it.coeff);
131 if (
coeff.csgn() == -1)
c.s <<
'-';
else c.s <<
'+';
133 if (
coeff.csgn() == -1)
c.s <<
'-';
138 if (
coeff.is_rational()) {
139 if (
coeff.is_negative())
144 if (
coeff.csgn() == -1)
155 c.s <<
')' << closebrace;
174 char separator =
' ';
175 for (
auto & it :
seq) {
178 if (it.coeff.is_equal(
_ex_1) ||
179 ex_to<numeric>(it.coeff).numer().is_equal(*
_num_1_p))
182 if (it.coeff.is_equal(
_ex1) || it.coeff.is_equal(
_ex_1)) {
184 }
else if (ex_to<numeric>(it.coeff).numer().is_equal(*
_num1_p) ||
185 ex_to<numeric>(it.coeff).numer().is_equal(*
_num_1_p))
189 ex_to<numeric>(it.coeff).denom().print(
c,
precedence());
212 c.s << class_name() <<
'(';
214 for (
size_t i=1; i<
nops(); ++i) {
240 for (
auto & i :
seq) {
249 return inherited::info(inf);
254 for (
auto & i :
seq) {
255 if (!i.rest.is_polynomial(var)) {
264 int deg = std::numeric_limits<int>::min();
269 for (
auto & i :
seq) {
270 int cur_deg = i.rest.degree(s);
279 int deg = std::numeric_limits<int>::max();
284 for (
auto & i :
seq) {
285 int cur_deg = i.rest.ldegree(s);
297 bool do_clifford = (rl != -1);
298 bool nonscalar =
false;
301 for (
auto & i :
seq) {
308 coeffseq_cliff.push_back(
expair(restcoeff, i.
coeff));
316 return dynallocate<add>(nonscalar ? std::move(coeffseq_cliff) : std::move(coeffseq),
340#ifdef DO_GINAC_ASSERT
341 for (
auto & i :
seq) {
346 size_t seq_size =
seq.size();
354 throw (std::logic_error(
"add::eval(): sum of non-commutative objects has non-zero numeric term"));
365 s.reserve(
seq.size());
367 bool all_matrices =
true;
368 bool first_term =
true;
371 for (
auto & it :
seq) {
374 if (is_a<matrix>(
m)) {
376 sum = ex_to<matrix>(
m);
379 sum = sum.
add(ex_to<matrix>(
m));
381 all_matrices =
false;
392 std::unique_ptr<exvector> v(
nullptr);
393 for (
size_t i=0; i<
nops(); ++i) {
404 for (
size_t j=0; j<i; ++j)
406 v->push_back(ccterm);
409 return add(std::move(*v));
417 v.reserve(
seq.size());
418 for (
auto & it :
seq)
434 v.reserve(
seq.size());
435 for (
auto & it :
seq)
451 return inherited::eval_ncmul(v);
453 return seq.begin()->rest.eval_ncmul(v);
463 s.reserve(
seq.size());
468 for (
auto & it :
seq)
469 s.push_back(
expair(it.rest.diff(y), it.coeff));
471 return dynallocate<add>(std::move(s));
476 return inherited::compare_same_type(other);
484 return seq.begin()->rest.return_type();
490 return make_return_type_t<add>();
492 return seq.begin()->rest.return_type_tinfo();
498 return dynallocate<add>(v, oc);
504 return dynallocate<add>(std::move(vp), oc);
509 if (is_exactly_a<mul>(e)) {
510 const mul &mulref(ex_to<mul>(e));
514 mul & mulcopy = dynallocate<mul>(mulref);
517 return expair(mulcopy, numfactor);
526 if (is_exactly_a<mul>(e)) {
527 const mul &mulref(ex_to<mul>(e));
531 mul & mulcopy = dynallocate<mul>(mulref);
534 if (
c.is_equal(
_ex1))
535 return expair(mulcopy, numfactor);
537 return expair(mulcopy, ex_to<numeric>(numfactor).mul_dyn(ex_to<numeric>(
c)));
538 }
else if (is_exactly_a<numeric>(e)) {
539 if (
c.is_equal(
_ex1))
543 return expair(ex_to<numeric>(e).mul_dyn(ex_to<numeric>(
c)),
_ex1);
554 if (is_exactly_a<numeric>(p.
rest)) {
567 return dynallocate<mul>(p.
rest, p.
coeff);
573 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...