From: Richard Kreckel Date: Thu, 2 Mar 2000 23:51:33 +0000 (+0000) Subject: - Changed behaviour of .evalf() to not evalf any exponents. X-Git-Tag: release_0-5-4~14 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=ebc7c9b1ef9b051ec35a954ff2e6d2da18ab37e4 - Changed behaviour of .evalf() to not evalf any exponents. --- diff --git a/NEWS b/NEWS index 601e5754..008b05e8 100644 --- a/NEWS +++ b/NEWS @@ -1,12 +1,13 @@ This file records noteworthy changes. -0.5.4 (?? 2000) +0.5.4 (?x?y?z? March 2000) * Algorithms in class matrix (determinant and solve) were replaced by less brain-dead ones and should now have much better performance. * Checks were reorganized and split up into three parts: - a) exams (small tests with predefined input) - b) checks (lenghty consistency checks) - c) timings (for crude benchmarking) + a) exams (small regression tests with predefined input) + b) checks (lenghty coherence checks with random input) + c) timings (for coherence and crude benchmarking) +* Behaviour of .evalf() was changed: it doesn't .evalf() any exponents. 0.5.3 (23 February 2000) * A more flexible scheme for registering functions was implemented, diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp index 7da18758..d791abf2 100644 --- a/ginac/expairseq.cpp +++ b/ginac/expairseq.cpp @@ -261,8 +261,8 @@ void expairseq::printtree(ostream & os, unsigned indent) const unsigned count[MAXCOUNT+1]; for (int i=0; i0) { @@ -283,12 +283,12 @@ void expairseq::printtree(ostream & os, unsigned indent) const ++count[MAXCOUNT]; } } - unsigned fact=1; - double cum_prob=0; - double lambda=(1.0*seq.size())/hashtabsize; + unsigned fact = 1; + double cum_prob = 0; + double lambda = (1.0*seq.size())/hashtabsize; for (int k=0; k0) fact *= k; - double prob=pow(lambda,k)/fact*exp(-lambda); + double prob = pow(lambda,k)/fact*exp(-lambda); cum_prob += prob; os << string(indent+delta_indent,' ') << "bins with " << k << " entries: " << int(1000.0*count[k]/hashtabsize)/10.0 << "% (expected: " @@ -352,12 +352,12 @@ ex expairseq::eval(int level) const ex expairseq::evalf(int level) const { - return thisexpairseq(evalfchildren(level),overall_coeff); + return thisexpairseq(evalfchildren(level),overall_coeff.evalf(level-1)); } ex expairseq::normal(lst &sym_lst, lst &repl_lst, int level) const { - ex n=thisexpairseq(normalchildren(level),overall_coeff); + ex n = thisexpairseq(normalchildren(level),overall_coeff); return n.bp->basic::normal(sym_lst,repl_lst,level); } @@ -383,7 +383,7 @@ ex expairseq::derivative(const symbol & s) const int expairseq::compare_same_type(const basic & other) const { GINAC_ASSERT(is_of_type(other, expairseq)); - const expairseq & o=static_cast(const_cast(other)); + const expairseq & o = static_cast(const_cast(other)); int cmpval; @@ -393,7 +393,7 @@ int expairseq::compare_same_type(const basic & other) const } // compare overall_coeff - cmpval=overall_coeff.compare(o.overall_coeff); + cmpval = overall_coeff.compare(o.overall_coeff); if (cmpval!=0) return cmpval; //if (seq.size()==0) return 0; // empty expairseq's are equal @@ -402,13 +402,13 @@ int expairseq::compare_same_type(const basic & other) const GINAC_ASSERT(hashtabsize==o.hashtabsize); if (hashtabsize==0) { #endif // def EXPAIRSEQ_USE_HASHTAB - epvector::const_iterator cit1=seq.begin(); - epvector::const_iterator cit2=o.seq.begin(); - epvector::const_iterator last1=seq.end(); - epvector::const_iterator last2=o.seq.end(); + epvector::const_iterator cit1 = seq.begin(); + epvector::const_iterator cit2 = o.seq.begin(); + epvector::const_iterator last1 = seq.end(); + epvector::const_iterator last2 = o.seq.end(); for (; (cit1!=last1)&&(cit2!=last2); ++cit1, ++cit2) { - cmpval=(*cit1).compare(*cit2); + cmpval = (*cit1).compare(*cit2); if (cmpval!=0) return cmpval; } @@ -1516,8 +1516,8 @@ bool expairseq::is_canonical() const if (hashtabsize>0) return 1; // not canoncalized #endif // def EXPAIRSEQ_USE_HASHTAB - epvector::const_iterator it=seq.begin(); - epvector::const_iterator it_last=it; + epvector::const_iterator it = seq.begin(); + epvector::const_iterator it_last = it; for (++it; it!=seq.end(); it_last=it, ++it) { if (!((*it_last).is_less(*it)||(*it_last).is_equal(*it))) { if (!is_ex_exactly_of_type((*it_last).rest,numeric)|| @@ -1556,7 +1556,7 @@ epvector * expairseq::expandchildren(unsigned options) const s->reserve(seq.size()); // copy parts of seq which are known not to have changed - epvector::const_iterator cit2=seq.begin(); + epvector::const_iterator cit2 = seq.begin(); while (cit2!=cit) { s->push_back(*cit2); ++cit2; @@ -1600,7 +1600,7 @@ epvector * expairseq::evalchildren(int level) const if (!are_ex_trivially_equal((*cit).rest,evaled_ex)) { // something changed, copy seq, eval and return it - epvector *s=new epvector; + epvector *s = new epvector; s->reserve(seq.size()); // copy parts of seq which are known not to have changed @@ -1629,34 +1629,34 @@ epvector * expairseq::evalchildren(int level) const epvector expairseq::evalfchildren(int level) const { - epvector s; - s.reserve(seq.size()); - - if (level==1) { + if (level==1) return seq; - } - if (level == -max_recursion_level) { + + if (level==-max_recursion_level) throw(std::runtime_error("max recursion level reached")); - } + + epvector s; + s.reserve(seq.size()); + --level; for (epvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) { s.push_back(combine_ex_with_coeff_to_pair((*it).rest.evalf(level), - (*it).coeff)); + (*it).coeff.evalf(level))); } return s; } epvector expairseq::normalchildren(int level) const { + if (level==1) + return seq; + + if (level == -max_recursion_level) + throw(std::runtime_error("max recursion level reached")); + epvector s; s.reserve(seq.size()); - if (level==1) { - return seq; - } - if (level == -max_recursion_level) { - throw(std::runtime_error("max recursion level reached")); - } --level; for (epvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) { s.push_back(combine_ex_with_coeff_to_pair((*it).rest.normal(level), diff --git a/ginac/mul.cpp b/ginac/mul.cpp index 054b2131..976db46e 100644 --- a/ginac/mul.cpp +++ b/ginac/mul.cpp @@ -424,6 +424,25 @@ ex mul::eval(int level) const return this->hold(); } +ex mul::evalf(int level) 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 (epvector::const_iterator it=seq.begin(); it!=seq.end(); ++it) { + s.push_back(combine_ex_with_coeff_to_pair((*it).rest.evalf(level), + (*it).coeff)); + } + return mul(s,overall_coeff.evalf(level)); +} + exvector mul::get_indices(void) const { // return union of indices of factors diff --git a/ginac/mul.h b/ginac/mul.h index 1a017417..01b0b349 100644 --- a/ginac/mul.h +++ b/ginac/mul.h @@ -71,6 +71,7 @@ public: int ldegree(const symbol & s) const; ex coeff(const symbol & s, int n=1) const; ex eval(int level=0) const; + ex evalf(int level=0) const; ex series(const symbol & s, const ex & point, int order) const; ex normal(lst &sym_lst, lst &repl_lst, int level=0) const; numeric integer_content(void) const; diff --git a/ginac/power.cpp b/ginac/power.cpp index 10542b6c..8cb62238 100644 --- a/ginac/power.cpp +++ b/ginac/power.cpp @@ -479,13 +479,16 @@ ex power::evalf(int level) const ex eexponent; if (level==1) { - ebasis=basis; - eexponent=exponent; + ebasis = basis; + eexponent = exponent; } else if (level == -max_recursion_level) { throw(std::runtime_error("max recursion level reached")); } else { - ebasis=basis.evalf(level-1); - eexponent=exponent.evalf(level-1); + ebasis = basis.evalf(level-1); + if (!is_ex_exactly_of_type(eexponent,numeric)) + eexponent = exponent.evalf(level-1); + else + eexponent = exponent; } return power(ebasis,eexponent);