]> www.ginac.de Git - ginac.git/commitdiff
Remove 'level' argument of evalf().
authorRichard Kreckel <kreckel@ginac.de>
Thu, 28 Jan 2016 21:11:46 +0000 (22:11 +0100)
committerRichard Kreckel <kreckel@ginac.de>
Thu, 28 Jan 2016 21:45:02 +0000 (22:45 +0100)
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.

27 files changed:
doc/tutorial/ginac.texi
ginac/basic.cpp
ginac/basic.h
ginac/constant.cpp
ginac/constant.h
ginac/ex.h
ginac/fderivative.cpp
ginac/fderivative.h
ginac/function.cppy
ginac/function.hppy
ginac/idx.cpp
ginac/idx.h
ginac/integral.cpp
ginac/integral.h
ginac/matrix.h
ginac/mul.cpp
ginac/mul.h
ginac/numeric.cpp
ginac/numeric.h
ginac/power.cpp
ginac/power.h
ginac/pseries.cpp
ginac/pseries.h
ginac/structure.h
ginac/symbol.h
ginsh/ginsh.1.in
ginsh/ginsh_parser.ypp

index 32f0e255ede71d30fbbd5fe96eba241af5f47abc..a8c537971edbfbdf0aceee5ad9c3988c726c7dd3 100644 (file)
@@ -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
index 029a0ab9d8a755558cb3f5c682db5f07c712701f..6abe4727a424a0622fd2569f2956a0f2c6ad65cd 100644 (file)
@@ -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);
        }
 }
 
index 6f5cd1d24f2e29d974284cc51e431780e5b39e6a..9c03d61264b6fcc7d2ece30ce592b2fa2e15bcae 100644 (file)
@@ -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:
index 743eb6029a5b83e382205acb3b4929051c7d33df..44acf4ccb2f1d64d1cbcebc6d7772c04dff4c2a3 100644 (file)
@@ -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();
index 9720f03f9129dd815a9caa325aa0a076fbea7e31..86f945cdfacc89e0b7c113b2312e084130a29a8c 100644 (file)
@@ -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;
index 1f211826aa2c71e3cacad36a273998e1f70019d2..a6369ef4f0c8fccbe9b90985b25b6540f50fd783 100644 (file)
@@ -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(); }
index 3fcafee558953556d8edf924bbc6abeae2b623b4..b8ad07a8ada48b63b4c316445b622805026dc1a8 100644 (file)
@@ -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
index 2c0ae886d9816e11a56abf14ec4af4d0c44457dc..70f65ec4d4bfe3b45efee4e13e2eceb6b1dffc5e 100644 (file)
@@ -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;
index 6f293de9dbadbca8f313a47915ac62dd83c926d1..d9a59dc781cc81de8fa6d75fb4ba8d9227c4381d 100644 (file)
@@ -414,22 +414,19 @@ ex function::eval() const
        return eval_result;
 }
 
-ex function::evalf(int level) const
+ex function::evalf() const
 {
        GINAC_ASSERT(serial<registered_functions().size());
        const function_options &opt = registered_functions()[serial];
 
        // Evaluate children first
        exvector eseq;
-       if (level == 1 || !(opt.evalf_params_first))
+       if (!opt.evalf_params_first)
                eseq = seq;
-       else if (level == -max_recursion_level)
-               throw(std::runtime_error("max recursion level reached"));
        else {
                eseq.reserve(seq.size());
-               --level;
                for (auto & it : seq) {
-                       eseq.push_back(it.evalf(level));
+                       eseq.push_back(it.evalf());
                }
        }
 
index 360079face9960afba984252790c6fd00b8a147b..34ea39c414c2945293453c46b7eb5a9cb58ec08a 100644 (file)
@@ -229,7 +229,7 @@ public:
        unsigned precedence() const override {return 70;}
        ex expand(unsigned options=0) const override;
        ex eval() const override;
-       ex evalf(int level=0) const override;
+       ex evalf() const override;
        ex eval_ncmul(const exvector & v) const override;
        unsigned calchash() const override;
        ex series(const relational & r, int order, unsigned options = 0) const override;
index 8789cc92d97ebeb0bf587d687eb109211ed4f7fb..601c339b9fb745e203073426fb0742bf1164e7c0 100644 (file)
@@ -365,7 +365,7 @@ unsigned idx::calchash() const
 
 /** By default, basic::evalf would evaluate the index value but we don't want
  *  a.1 to become a.(1.0). */
-ex idx::evalf(int level) const
+ex idx::evalf() const
 {
        return *this;
 }
index ac856232f091905f3eca16d58d5bbc7ee761c093..de44973fedc58be3cce881e794662b3b0f99cc5e 100644 (file)
@@ -51,7 +51,7 @@ public:
        size_t nops() const override;
        ex op(size_t i) const override;
        ex map(map_function & f) const override;
-       ex evalf(int level = 0) const override;
+       ex evalf() const override;
        ex subs(const exmap & m, unsigned options = 0) const override;
        void archive(archive_node& n) const override;
        void read_archive(const archive_node& n, lst& syms) override;
index 0f27df6964fd2ed88cb2cb1a5101f2a8734dd190..d2d451b4b4a41258f9941a9be43f8b59c4cb12c6 100644 (file)
@@ -154,23 +154,11 @@ ex integral::eval() const
        return this->hold();
 }
 
-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.
index 10b290f365ceaaa6871392a8cb7e9f29795610d2..056c4b438bb90a33209303fc193106ec6664bcfa 100644 (file)
@@ -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;
index 5fa9a4cc64358e48d2a58e22a42b49d3d6e4f239..e611aa5b022e30b3a93d48a27042fbb694303033 100644 (file)
@@ -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(); }
index 9843e616dfa4c369d9b59fa313b330da23986fa2..15dee661c735f831789bb5e1df634621634f009c 100644 (file)
@@ -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<mul>(std::move(s), overall_coeff.evalf(level));
+       for (auto & it : seq)
+               s.push_back(expair(it.rest.evalf(), it.coeff));
+       return dynallocate<mul>(std::move(s), overall_coeff.evalf());
 }
 
 void mul::find_real_imag(ex & rp, ex & ip) const
index 7cef748838db8e4a8c715a731a31d97d9ff81309..8db4281451145068bd1e5f208975adff3004dc9d 100644 (file)
@@ -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;
index f7c4cb04aa8cc96b3fb6b653664c48e6bf675c94..f27fd3aca60d7d1b090a59aa6562e3bb2bc33620 100644 (file)
@@ -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);
 }
 
index ea3dcd23a78ffb626670f3a493dcb28ac704bb4d..115987eccef56e5a2dd00528d68521a1e1eb6810 100644 (file)
@@ -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;
index 4600fc3e0211267d600056a79a4e0b2ae2988346..5cddca8995bd475c6b6f56f5a7c8d5670280fa6a 100644 (file)
@@ -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<numeric>(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<numeric>(exponent))
-                       eexponent = exponent.evalf(level-1);
-               else
-                       eexponent = exponent;
-       }
 
        return dynallocate<power>(ebasis, eexponent);
 }
index 55acd7862d96a523ff30f71e8d9395154b73521f..19d153df9f769c05801b22f6011bcb69625998fd 100644 (file)
@@ -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;
index 2d0b7adc24ccbd95ef531ea1ce637466941fdaa5..2ea4365f57324d868b6e956e9e6d940b92c52fa6 100644 (file)
@@ -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());
index d5f09cf8d12efb077a0660492437e9fa11b9dae7..e0c9443a0468a38439d9e9d49282c690c71a4d92 100644 (file)
@@ -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;
index 3fccf6b7d938cc1584ae68a66779213bfc7e370f..49df915c90ffdd5605499a5fb2d4753df4633774 100644 (file)
@@ -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); }
index 03a4f884eea8af229b706635f99231a529ba855b..b4df05b49d0fd30fa820dbba10fe4063259ff1e0 100644 (file)
@@ -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;
index 496458b7188b6f75bbb3c2e37d23930b877ffc83..b19ca6301547211347d6ad24b5ae2c6f4676350d 100644 (file)
@@ -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 )
index 4afef74260ddc7255d4b5a54866c821dcc254349..20243ba75ebf63a166a84695e4cd9b86a637e396 100644 (file)
@@ -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<numeric>(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},