From c12c8ec3c5cf0c75f061f6c52d04206277bbdcca Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Thu, 28 Jan 2016 22:11:46 +0100 Subject: [PATCH] Remove 'level' argument of evalf(). The 'level' argument was modeled after that of the eval() methods (removed in 6c946d4c). It has never been very useful except for confusing developers. Moreover, I have no indication that it has ever been used. --- doc/tutorial/ginac.texi | 4 ++-- ginac/basic.cpp | 16 ++++------------ ginac/basic.h | 2 +- ginac/constant.cpp | 2 +- ginac/constant.h | 2 +- ginac/ex.h | 6 +++--- ginac/fderivative.cpp | 7 ------- ginac/fderivative.h | 1 - ginac/function.cppy | 9 +++------ ginac/function.hppy | 2 +- ginac/idx.cpp | 2 +- ginac/idx.h | 2 +- ginac/integral.cpp | 20 ++++---------------- ginac/integral.h | 2 +- ginac/matrix.h | 4 ++-- ginac/mul.cpp | 16 ++++------------ ginac/mul.h | 2 +- ginac/numeric.cpp | 4 +--- ginac/numeric.h | 2 +- ginac/power.cpp | 18 +++++------------- ginac/power.h | 2 +- ginac/pseries.cpp | 8 +------- ginac/pseries.h | 2 +- ginac/structure.h | 1 - ginac/symbol.h | 2 +- ginsh/ginsh.1.in | 2 +- ginsh/ginsh_parser.ypp | 11 ++--------- 27 files changed, 44 insertions(+), 107 deletions(-) diff --git a/doc/tutorial/ginac.texi b/doc/tutorial/ginac.texi index 32f0e255..a8c53797 100644 --- a/doc/tutorial/ginac.texi +++ b/doc/tutorial/ginac.texi @@ -4213,7 +4213,7 @@ GiNaC keeps algebraic expressions, numbers and constants in their exact form. To evaluate them using floating-point arithmetic you need to call @example -ex ex::evalf(int level = 0) const; +ex ex::evalf() const; @end example @cindex @code{Digits} @@ -8323,7 +8323,7 @@ might want to provide: @example bool info(unsigned inf) const override; -ex evalf(int level = 0) const override; +ex evalf() const override; ex series(const relational & r, int order, unsigned options = 0) const override; ex derivative(const symbol & s) const override; @end example diff --git a/ginac/basic.cpp b/ginac/basic.cpp index 029a0ab9..6abe4727 100644 --- a/ginac/basic.cpp +++ b/ginac/basic.cpp @@ -418,25 +418,17 @@ ex basic::eval() 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); } } diff --git a/ginac/basic.h b/ginac/basic.h index 6f5cd1d2..9c03d612 100644 --- a/ginac/basic.h +++ b/ginac/basic.h @@ -136,7 +136,7 @@ public: // only const functions please (may break reference counting) // evaluation virtual ex eval() const; - virtual ex evalf(int level = 0) const; + virtual ex evalf() const; virtual ex evalm() const; virtual ex eval_integ() const; protected: diff --git a/ginac/constant.cpp b/ginac/constant.cpp index 743eb602..44acf4cc 100644 --- a/ginac/constant.cpp +++ b/ginac/constant.cpp @@ -148,7 +148,7 @@ bool constant::info(unsigned inf) const return inherited::info(inf); } -ex constant::evalf(int level) const +ex constant::evalf() const { if (ef!=nullptr) { return ef(); diff --git a/ginac/constant.h b/ginac/constant.h index 9720f03f..86f945cd 100644 --- a/ginac/constant.h +++ b/ginac/constant.h @@ -48,7 +48,7 @@ public: // functions overriding virtual functions from base classes public: bool info(unsigned inf) const override; - ex evalf(int level = 0) const override; + ex evalf() const override; bool is_polynomial(const ex & var) const override; ex conjugate() const override; ex real_part() const override; diff --git a/ginac/ex.h b/ginac/ex.h index 1f211826..a6369ef4 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -116,7 +116,7 @@ public: // evaluation ex eval() const { return bp->eval(); } - ex evalf(int level = 0) const { return bp->evalf(level); } + ex evalf() const { return bp->evalf(); } ex evalm() const { return bp->evalm(); } ex eval_ncmul(const exvector & v) const { return bp->eval_ncmul(v); } ex eval_integ() const { return bp->eval_integ(); } @@ -758,8 +758,8 @@ inline ex collect(const ex & thisex, const ex & s, bool distributed = false) inline ex eval(const ex & thisex) { return thisex.eval(); } -inline ex evalf(const ex & thisex, int level = 0) -{ return thisex.evalf(level); } +inline ex evalf(const ex & thisex) +{ return thisex.evalf(); } inline ex evalm(const ex & thisex) { return thisex.evalm(); } diff --git a/ginac/fderivative.cpp b/ginac/fderivative.cpp index 3fcafee5..b8ad07a8 100644 --- a/ginac/fderivative.cpp +++ b/ginac/fderivative.cpp @@ -152,13 +152,6 @@ ex fderivative::eval() const return this->hold(); } -/** Numeric evaluation falls back to evaluation of arguments. - * @see basic::evalf */ -ex fderivative::evalf(int level) const -{ - return basic::evalf(level); -} - /** The series expansion of derivatives falls back to Taylor expansion. * @see basic::series */ ex fderivative::series(const relational & r, int order, unsigned options) const diff --git a/ginac/fderivative.h b/ginac/fderivative.h index 2c0ae886..70f65ec4 100644 --- a/ginac/fderivative.h +++ b/ginac/fderivative.h @@ -61,7 +61,6 @@ public: public: void print(const print_context & c, unsigned level = 0) const override; ex eval() const override; - ex evalf(int level = 0) const override; ex series(const relational & r, int order, unsigned options = 0) const override; ex thiscontainer(const exvector & v) const override; ex thiscontainer(exvector && v) const override; diff --git a/ginac/function.cppy b/ginac/function.cppy index 6f293de9..d9a59dc7 100644 --- a/ginac/function.cppy +++ b/ginac/function.cppy @@ -414,22 +414,19 @@ ex function::eval() const return eval_result; } -ex function::evalf(int level) const +ex function::evalf() const { GINAC_ASSERT(serialhold(); } -ex integral::evalf(int level) const +ex integral::evalf() const { - ex ea; - ex eb; - ex ef; - - if (level==1) { - ea = a; - eb = b; - ef = f; - } else if (level == -max_recursion_level) { - throw(runtime_error("max recursion level reached")); - } else { - ea = a.evalf(level-1); - eb = b.evalf(level-1); - ef = f.evalf(level-1); - } + ex ea = a.evalf(); + ex eb = b.evalf(); + ex ef = f.evalf(); // 12.34 is just an arbitrary number used to check whether a number // results after substituting a number for the integration variable. diff --git a/ginac/integral.h b/ginac/integral.h index 10b290f3..056c4b43 100644 --- a/ginac/integral.h +++ b/ginac/integral.h @@ -42,7 +42,7 @@ public: public: unsigned precedence() const override {return 45;} ex eval() const override; - ex evalf(int level=0) const override; + ex evalf() const override; int degree(const ex & s) const override; int ldegree(const ex & s) const override; ex eval_ncmul(const exvector & v) const override; diff --git a/ginac/matrix.h b/ginac/matrix.h index 5fa9a4cc..e611aa5b 100644 --- a/ginac/matrix.h +++ b/ginac/matrix.h @@ -189,8 +189,8 @@ inline size_t nops(const matrix & m) inline ex expand(const matrix & m, unsigned options = 0) { return m.expand(options); } -inline ex evalf(const matrix & m, int level = 0) -{ return m.evalf(level); } +inline ex evalf(const matrix & m) +{ return m.evalf(); } inline unsigned rows(const matrix & m) { return m.rows(); } diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 9843e616..15dee661 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -574,22 +574,14 @@ ex mul::eval() const return this->hold(); } -ex mul::evalf(int level) const +ex mul::evalf() const { - if (level==1) - return mul(seq, overall_coeff); - - if (level==-max_recursion_level) - throw(std::runtime_error("max recursion level reached")); - epvector s; s.reserve(seq.size()); - --level; - for (auto & it : seq) { - s.push_back(expair(it.rest.evalf(level), it.coeff)); - } - return dynallocate(std::move(s), overall_coeff.evalf(level)); + for (auto & it : seq) + s.push_back(expair(it.rest.evalf(), it.coeff)); + return dynallocate(std::move(s), overall_coeff.evalf()); } void mul::find_real_imag(ex & rp, ex & ip) const diff --git a/ginac/mul.h b/ginac/mul.h index 7cef7488..8db42814 100644 --- a/ginac/mul.h +++ b/ginac/mul.h @@ -56,7 +56,7 @@ public: ex coeff(const ex & s, int n = 1) const override; bool has(const ex & other, unsigned options = 0) const override; ex eval() const override; - ex evalf(int level=0) const override; + ex evalf() const override; ex real_part() const override; ex imag_part() const override; ex evalm() const override; diff --git a/ginac/numeric.cpp b/ginac/numeric.cpp index f7c4cb04..f27fd3ac 100644 --- a/ginac/numeric.cpp +++ b/ginac/numeric.cpp @@ -784,11 +784,9 @@ ex numeric::eval() const * currently set. In case the object already was a floating point number the * precision is trimmed to match the currently set default. * - * @param level ignored, only needed for overriding basic::evalf. * @return an ex-handle to a numeric. */ -ex numeric::evalf(int level) const +ex numeric::evalf() const { - // level can safely be discarded for numeric objects. return numeric(cln::cl_float(1.0, cln::default_float_format) * value); } diff --git a/ginac/numeric.h b/ginac/numeric.h index ea3dcd23..115987ec 100644 --- a/ginac/numeric.h +++ b/ginac/numeric.h @@ -104,7 +104,7 @@ public: ex coeff(const ex & s, int n = 1) const override; bool has(const ex &other, unsigned options = 0) const override; ex eval() const override; - ex evalf(int level = 0) const override; + ex evalf() const override; ex subs(const exmap & m, unsigned options = 0) const override { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const override; ex to_rational(exmap & repl) const override; diff --git a/ginac/power.cpp b/ginac/power.cpp index 4600fc3e..5cddca89 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -562,23 +562,15 @@ ex power::eval() const return this->hold(); } -ex power::evalf(int level) const +ex power::evalf() const { - ex ebasis; + ex ebasis = basis.evalf(); ex eexponent; - if (level==1) { - ebasis = basis; + if (!is_exactly_a(exponent)) + eexponent = exponent.evalf(); + else eexponent = exponent; - } else if (level == -max_recursion_level) { - throw(std::runtime_error("max recursion level reached")); - } else { - ebasis = basis.evalf(level-1); - if (!is_exactly_a(exponent)) - eexponent = exponent.evalf(level-1); - else - eexponent = exponent; - } return dynallocate(ebasis, eexponent); } diff --git a/ginac/power.h b/ginac/power.h index 55acd786..19d153df 100644 --- a/ginac/power.h +++ b/ginac/power.h @@ -60,7 +60,7 @@ public: int ldegree(const ex & s) const override; ex coeff(const ex & s, int n = 1) const override; ex eval() const override; - ex evalf(int level=0) const override; + ex evalf() const override; ex evalm() const override; ex series(const relational & s, int order, unsigned options = 0) const override; ex subs(const exmap & m, unsigned options = 0) const override; diff --git a/ginac/pseries.cpp b/ginac/pseries.cpp index 2d0b7adc..2ea4365f 100644 --- a/ginac/pseries.cpp +++ b/ginac/pseries.cpp @@ -410,14 +410,8 @@ ex pseries::eval() const } /** Evaluate coefficients numerically. */ -ex pseries::evalf(int level) const +ex pseries::evalf() const { - if (level == 1) - return *this; - - if (level == -max_recursion_level) - throw (std::runtime_error("pseries::evalf(): recursion limit exceeded")); - // Construct a new series with evaluated coefficients epvector new_seq; new_seq.reserve(seq.size()); diff --git a/ginac/pseries.h b/ginac/pseries.h index d5f09cf8..e0c9443a 100644 --- a/ginac/pseries.h +++ b/ginac/pseries.h @@ -51,7 +51,7 @@ public: ex coeff(const ex &s, int n = 1) const override; ex collect(const ex &s, bool distributed = false) const override; ex eval() const override; - ex evalf(int level=0) const override; + ex evalf() const override; ex series(const relational & r, int order, unsigned options = 0) const override; ex subs(const exmap & m, unsigned options = 0) const override; ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const override; diff --git a/ginac/structure.h b/ginac/structure.h index 3fccf6b7..49df915c 100644 --- a/ginac/structure.h +++ b/ginac/structure.h @@ -127,7 +127,6 @@ public: public: // evaluation ex eval() const override { return hold(); } - ex evalf(int level = 0) const override { return inherited::evalf(level); } ex evalm() const override { return inherited::evalm(); } protected: ex eval_ncmul(const exvector & v) const override { return hold_ncmul(v); } diff --git a/ginac/symbol.h b/ginac/symbol.h index 03a4f884..b4df05b4 100644 --- a/ginac/symbol.h +++ b/ginac/symbol.h @@ -47,7 +47,7 @@ public: public: bool info(unsigned inf) const override; ex eval() const override { return *this; } // for performance reasons - ex evalf(int level = 0) const override { return *this; } // overwrites basic::evalf() for performance reasons + ex evalf() const override { return *this; } // overwrites basic::evalf() for performance reasons ex series(const relational & s, int order, unsigned options = 0) const override; ex subs(const exmap & m, unsigned options = 0) const override { return subs_one_level(m, options); } // overwrites basic::subs() for performance reasons ex normal(exmap & repl, exmap & rev_lookup, int level = 0) const override; diff --git a/ginsh/ginsh.1.in b/ginsh/ginsh.1.in index 496458b7..b19ca630 100644 --- a/ginsh/ginsh.1.in +++ b/ginsh/ginsh.1.in @@ -278,7 +278,7 @@ detail here. Please refer to the GiNaC documentation. .BI divide( expression ", " expression ) \- exact polynomial division .br -.BI evalf( "expression [" ", " level] ) +.BI evalf( expression ) \- evaluates an expression to a floating point number .br .BI evalm( expression ) diff --git a/ginsh/ginsh_parser.ypp b/ginsh/ginsh_parser.ypp index 4afef742..20243ba7 100644 --- a/ginsh/ginsh_parser.ypp +++ b/ginsh/ginsh_parser.ypp @@ -331,7 +331,7 @@ static ex f_collect_common_factors(const exprseq &e) {return collect_common_fact static ex f_convert_H_to_Li(const exprseq &e) {return convert_H_to_Li(e[0], e[1]);} static ex f_degree(const exprseq &e) {return e[0].degree(e[1]);} static ex f_denom(const exprseq &e) {return e[0].denom();} -static ex f_evalf1(const exprseq &e) {return e[0].evalf();} +static ex f_evalf(const exprseq &e) {return e[0].evalf();} static ex f_evalm(const exprseq &e) {return e[0].evalm();} static ex f_eval_integ(const exprseq &e) {return e[0].eval_integ();} static ex f_expand(const exprseq &e) {return e[0].expand();} @@ -413,12 +413,6 @@ static ex f_divide(const exprseq &e) return fail(); } -static ex f_evalf2(const exprseq &e) -{ - CHECK_ARG(1, numeric, evalf); - return e[0].evalf(ex_to(e[1]).to_int()); -} - static ex f_find(const exprseq &e) { exset found; @@ -611,8 +605,7 @@ static const fcn_init builtin_fcns[] = { {"diff", f_diff2, 2}, {"diff", f_diff3, 3}, {"divide", f_divide, 2}, - {"evalf", f_evalf1, 1}, - {"evalf", f_evalf2, 2}, + {"evalf", f_evalf, 1}, {"evalm", f_evalm, 1}, {"eval_integ", f_eval_integ, 1}, {"expand", f_expand, 1}, -- 2.47.0