[GiNaC-list] comparing ex

Richard B. Kreckel kreckel at ginac.de
Thu Aug 18 23:12:30 CEST 2005


On Thu, 18 Aug 2005, Vera Louise Hauge wrote:
> I want to compare (or test the equality of) two ex objects which contain
> symbols.
> a = a0 + x*a1;
> b = a0 + a1*x;
>
> If the ex objects are evaluated (symbolically), such that
> a-b becomes 0, then the test would be finished.
>
> However, how do I evaluate such a expression as a-b symbolically?
>
> Or are there other ways of comparing two such ex objects?
>
> Any suggestions on how to do this?

I fail to understand: Expressions are canonicalized by eval() if that can
be done within "reasonable" time [0].  Normally, reasonable time means in
order < O(N^2), where N would be the size of the expression (number of
monomials in a polynomial in your example).  In your case, that means that
in GiNaC the two ex objects cannot be expressed the way you wrote them
because they are canonicalized immediately.  You should really try.

More generally, regarding test for zero, I recommend you read about
Richardson's Theorem in [1] or [2].

Regards
   -richy.

[0] <http://www.ginac.de/FAQ.html#evaluation>
[1] <http://mathworld.wolfram.com/RichardsonsTheorem.html>
[2] <http://www.cis.upenn.edu/~wilf/AeqB.html>, page 5.
-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>





More information about the GiNaC-list mailing list