X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?a=blobdiff_plain;f=ginac%2Fbasic.cpp;h=bad172a983440d27c62f0a6488df64b8a4bcc3fb;hb=63f3e977f92d51ea173382a9b7c4c3b18bda7b8e;hp=01d369716f30870d2bf8e0eeab2441278647e97c;hpb=d5b86dd10dd9cba12175d07af0b6edfc9a215e36;p=ginac.git diff --git a/ginac/basic.cpp b/ginac/basic.cpp index 01d36971..bad172a9 100644 --- a/ginac/basic.cpp +++ b/ginac/basic.cpp @@ -3,7 +3,7 @@ * Implementation of GiNaC's ABC. */ /* - * GiNaC Copyright (C) 1999-2015 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2018 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 @@ -309,7 +309,6 @@ ex basic::map(map_function & f) const } if (copy) { - copy->setflag(status_flags::dynallocated); copy->clearflag(status_flags::hash_calculated | status_flags::expanded); return *copy; } else @@ -374,7 +373,7 @@ ex basic::collect(const ex & s, bool distributed) const pre_coeff = pre_coeff.coeff(li, cexp); key *= pow(li, cexp); } - exmap::iterator ci = cmap.find(key); + auto ci = cmap.find(key); if (ci != cmap.end()) ci->second += pre_coeff; else @@ -384,7 +383,7 @@ ex basic::collect(const ex & s, bool distributed) const exvector resv; for (auto & mi : cmap) resv.push_back((mi.first)*(mi.second)); - return (new add(resv))->setflag(status_flags::dynallocated); + return dynallocate(resv); } else { @@ -411,7 +410,7 @@ ex basic::collect(const ex & s, bool distributed) const } /** Perform automatic non-interruptive term rewriting rules. */ -ex basic::eval(int level) const +ex basic::eval() const { // There is nothing to do for basic objects: return hold(); @@ -419,25 +418,17 @@ ex basic::eval(int level) const /** Function object to be applied by basic::evalf(). */ struct evalf_map_function : public map_function { - int level; - evalf_map_function(int l) : level(l) {} - ex operator()(const ex & e) override { return evalf(e, level); } + ex operator()(const ex & e) override { return evalf(e); } }; /** Evaluate object numerically. */ -ex basic::evalf(int level) const +ex basic::evalf() const { if (nops() == 0) return *this; else { - if (level == 1) - return *this; - else if (level == -max_recursion_level) - throw(std::runtime_error("max recursion level reached")); - else { - evalf_map_function map_evalf(level - 1); - return map(map_evalf); - } + evalf_map_function map_evalf; + return map(map_evalf); } } @@ -594,10 +585,11 @@ bool basic::match(const ex & pattern, exmap& repl_lst) const ex basic::subs_one_level(const exmap & m, unsigned options) const { if (options & subs_options::no_pattern) { - auto it = m.find(*this); + ex thisex = *this; // NB: *this may be deleted here. + auto it = m.find(thisex); if (it != m.end()) return it->second; - return *this; + return thisex; } else { for (auto & it : m) { exmap repl_lst; @@ -625,7 +617,6 @@ ex basic::subs(const exmap & m, unsigned options) const // Something changed, clone the object basic *copy = duplicate(); - copy->setflag(status_flags::dynallocated); copy->clearflag(status_flags::hash_calculated | status_flags::expanded); // Substitute the changed operand @@ -911,9 +902,6 @@ void basic::ensure_if_modifiable() const // global variables ////////// -int max_recursion_level = 1024; - - #ifdef GINAC_COMPARE_STATISTICS compare_statistics_t::~compare_statistics_t() {