X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fncmul.cpp;h=103e7d6d7f2a13734aebc38e7156a973f2ec1c0b;hb=c018acc8ddca143ba6a202ad095b192205708bc4;hp=9ad55c57c80c427379afa83f9af6ab7f44e13653;hpb=8f283de519668b70b2e675a7055c7f1bf7ba197c;p=ginac.git diff --git a/ginac/ncmul.cpp b/ginac/ncmul.cpp index 9ad55c57..103e7d6d 100644 --- a/ginac/ncmul.cpp +++ b/ginac/ncmul.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's non-commutative products of expressions. */ /* - * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2016 Johannes Gutenberg University Mainz, Germany * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -146,8 +146,7 @@ ex ncmul::expand(unsigned options) const // If there are no sums, we are done if (number_of_adds == 0) { if (!v.empty()) - return (new ncmul(std::move(v)))-> - setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0)); + return dynallocate(std::move(v)).setflag(options == 0 ? status_flags::expanded : 0); else return *this; } @@ -179,8 +178,7 @@ ex ncmul::expand(unsigned options) const term[positions_of_adds[i]] = rename_dummy_indices_uniquely(va, expanded_seq[positions_of_adds[i]].op(k[i]), true); } - distrseq.push_back((new ncmul(std::move(term)))-> - setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0))); + distrseq.push_back(dynallocate(std::move(term)).setflag(options == 0 ? status_flags::expanded : 0)); // increment k[] int l = number_of_adds-1; @@ -192,8 +190,7 @@ ex ncmul::expand(unsigned options) const break; } - return (new add(distrseq))-> - setflag(status_flags::dynallocated | (options == 0 ? status_flags::expanded : 0)); + return dynallocate(distrseq).setflag(options == 0 ? status_flags::expanded : 0); } int ncmul::degree(const ex & s) const @@ -233,7 +230,7 @@ ex ncmul::coeff(const ex & s, int n) const // if a non-zero power of s is found, the resulting product will be 0 for (auto & it : seq) coeffseq.push_back(it.coeff(s,n)); - return (new ncmul(std::move(coeffseq)))->setflag(status_flags::dynallocated); + return dynallocate(std::move(coeffseq)); } bool coeff_found = false; @@ -248,7 +245,7 @@ ex ncmul::coeff(const ex & s, int n) const } if (coeff_found) - return (new ncmul(std::move(coeffseq)))->setflag(status_flags::dynallocated); + return dynallocate(std::move(coeffseq)); return _ex0; } @@ -288,9 +285,8 @@ typedef std::vector exvectorvector; * - ncmul(...,c1,...,c2,...) -> *(c1,c2,ncmul(...)) (pull out commutative elements) * - ncmul(x1,y1,x2,y2) -> *(ncmul(x1,x2),ncmul(y1,y2)) (collect elements of same type) * - ncmul(x1,x2,x3,...) -> x::eval_ncmul(x1,x2,x3,...) - * - * @param level cut-off in recursive evaluation */ -ex ncmul::eval(int level) const + */ +ex ncmul::eval() const { // The following additional rule would be nice, but produces a recursion, // which must be trapped by introducing a flag that the sub-ncmuls() @@ -299,22 +295,20 @@ ex ncmul::eval(int level) const // ncmul(ncmul(x1,x2,...),X,ncmul(y1,y2,...) // (X noncommutative_composite) - if ((level==1) && (flags & status_flags::evaluated)) { + if (flags & status_flags::evaluated) { return *this; } - exvector evaledseq=evalchildren(level); - // ncmul(...,*(x1,x2),...,ncmul(x3,x4),...) -> // ncmul(...,x1,x2,...,x3,x4,...) (associativity) size_t factors = 0; - for (auto & it : evaledseq) + for (auto & it : seq) factors += count_factors(it); exvector assocseq; assocseq.reserve(factors); - make_flat_inserter mf(evaledseq, true); - for (auto & it : evaledseq) { + make_flat_inserter mf(seq, true); + for (auto & it : seq) { ex factor = mf.handle_factor(it, 1); append_factors(assocseq, factor); } @@ -364,8 +358,8 @@ ex ncmul::eval(int level) const else noncommutativeseq.push_back(assocseq[i]); } - commutativeseq.push_back((new ncmul(std::move(noncommutativeseq)))->setflag(status_flags::dynallocated)); - return (new mul(std::move(commutativeseq)))->setflag(status_flags::dynallocated); + commutativeseq.push_back(dynallocate(std::move(noncommutativeseq))); + return dynallocate(std::move(commutativeseq)); } // ncmul(x1,y1,x2,y2) -> *(ncmul(x1,x2),ncmul(y1,y2)) @@ -419,13 +413,12 @@ ex ncmul::eval(int level) const exvector splitseq; splitseq.reserve(evv_num); for (i=0; isetflag(status_flags::dynallocated)); + splitseq.push_back(dynallocate(evv[i])); - return (new mul(splitseq))->setflag(status_flags::dynallocated); + return dynallocate(splitseq); } - return (new ncmul(assocseq))->setflag(status_flags::dynallocated | - status_flags::evaluated); + return dynallocate(assocseq).setflag(status_flags::evaluated); } ex ncmul::evalm() const @@ -451,17 +444,17 @@ ex ncmul::evalm() const } no_matrix: - return (new ncmul(std::move(s)))->setflag(status_flags::dynallocated); + return dynallocate(std::move(s)); } ex ncmul::thiscontainer(const exvector & v) const { - return (new ncmul(v))->setflag(status_flags::dynallocated); + return dynallocate(v); } ex ncmul::thiscontainer(exvector && v) const { - return (new ncmul(std::move(v)))->setflag(status_flags::dynallocated); + return dynallocate(std::move(v)); } ex ncmul::conjugate() const @@ -480,7 +473,7 @@ ex ncmul::conjugate() const --i; ev.push_back(i->conjugate()); } - return (new ncmul(std::move(ev)))->setflag(status_flags::dynallocated).eval(); + return dynallocate(std::move(ev)); } ex ncmul::real_part() const @@ -509,10 +502,10 @@ ex ncmul::derivative(const symbol & s) const for (size_t i=0; isetflag(status_flags::dynallocated)); + addseq.push_back(dynallocate(ncmulseq)); e.swap(ncmulseq[i]); } - return (new add(addseq))->setflag(status_flags::dynallocated); + return dynallocate(addseq); } int ncmul::compare_same_type(const basic & other) const @@ -528,7 +521,7 @@ unsigned ncmul::return_type() const bool all_commutative = true; exvector::const_iterator noncommutative_element; // point to first found nc element - exvector::const_iterator i = seq.begin(), end = seq.end(); + auto i = seq.begin(), end = seq.end(); while (i != end) { unsigned rt = i->return_type(); if (rt == return_types::noncommutative_composite) @@ -615,7 +608,7 @@ const exvector & ncmul::get_factors() const ex reeval_ncmul(const exvector & v) { - return (new ncmul(v))->setflag(status_flags::dynallocated); + return dynallocate(v); } ex hold_ncmul(const exvector & v) @@ -625,8 +618,7 @@ ex hold_ncmul(const exvector & v) else if (v.size() == 1) return v[0]; else - return (new ncmul(v))->setflag(status_flags::dynallocated | - status_flags::evaluated); + return dynallocate(v).setflag(status_flags::evaluated); } GINAC_BIND_UNARCHIVER(ncmul);