Automatic evaluation/simplification
Yes, the FAQ says it is completely automatic. However, is there a way to switch it off? Forgive me for the very imprecise question. The situation is as follows: we have some monster expressions where we need to substitute a few thousands of symbol's occurrences with something else. We did that by implementing our own recursive tree traversal. However, we estimate that more than 80% of the time is spent in attempted simplifications by GiNaC (which we know are deemed to fail). Is there any way to implement this substitution process so as to avoid this big overhead? Thanks in advance Roberto -- Prof. Roberto Bagnara Computer Science Group Department of Mathematics, University of Parma, Italy http://www.cs.unipr.it/~bagnara/ mailto:bagnara@cs.unipr.it
Hi! On Tue, Nov 12, 2002 at 10:34:16PM +0100, Roberto Bagnara wrote:
Yes, the FAQ says it is completely automatic. However, is there a way to switch it off?
Sort of. There's the method basic::hold() which sets status_flags::evaluated in the object, which in turn tells the evaluator to stop. To be effective, however, this must be called before the object is wrapped in an 'ex' (before ex::construct_from_basic() is called). Therefore it works best with functions and other cases where you explicitly call the constructor of a GiNaC object: ex e; symbol x("x"); e = GiNaC::sin(0); cout << e << endl; e = GiNaC::sin(0).hold(); cout << e << endl; e = mul(x, 0).hold(); cout << e << endl; This prints "0", "sin(0)" and "0*x", respectively. In the last case, (x*0).hold() doesn't work (there's no ex::hold()), neither does ex_to<basic>(x*0).hold(), because once the 'basic' becomes an 'ex', it's too late for hold(). Also, this only works for evaluations done in the eval() method. Especially in the case of sums and products, the bulk of the evaluation work (sorting and combining terms) is done by the constructors, and hold() can actually do more harm than good here: e = add(x, -x).hold(); This produces an (invalid) empty 'add' object (which add::eval() would have turned into a numeric zero). The only way to get 'held' objects to re-evaluate is to manually clear the 'evaluated' flag: ex_to<basic>(e).clearflag(status_flags::evaluated); Bye, Christian -- / Coding on PowerPC and proud of it \/ http://www.uni-mainz.de/~bauec002/
participants (2)
-
Christian Bauer
-
Roberto Bagnara