[GiNaC-list] normalization ambiguity
Richard B. Kreckel
kreckel at ginac.de
Wed Oct 5 22:31:18 CEST 2005
Hi Jonathan!
On Wed, 5 Oct 2005, Jonathan Brandmeyer wrote:
> On Mon, 2005-10-03 at 14:34 -0400, Jonathan Brandmeyer wrote:
> > I recently discovered that expressions like pow(x - y, 2) can normalize
> > to pow(y - x, 2) if y compares less than x (according to the ex_is_less
> > comparator).
Yes. Using your wonderful PyGiNaC frontend:
rbk at wallace:~/projects/manydigits/src/warmup$ ./pyginac
Python 2.3.5 (#2, Aug 30 2005, 15:50:26)
[GCC 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ginac import *
>>> x = symbol("x")
>>> y = symbol("y")
>>> print normal((pow(x, 2) - pow(y, 2)) / pow(x-y, 3))
(y+x)*(-y+x)**(-2)
>>>
rbk at wallace:~/projects/manydigits/src/warmup$ ./pyginac
Python 2.3.5 (#2, Aug 30 2005, 15:50:26)
[GCC 4.0.2 20050821 (prerelease) (Debian 4.0.1-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ginac import *
>>> a = symbol("a")
>>> x = symbol("x")
>>> y = symbol("y")
>>> print normal((pow(x, 2) - pow(y, 2)) / pow(x-y, 3))
(y-x)**(-2)*(y+x)
>>>
Try it a couple of times. You should observe that the output is
completely deterministic. The only differens is the seemingly unrelated
symbol a: it changes the serial number of the symbols x and y and, hence,
also affects canonical ordering.
In your test suite: maybe you should not check e against d, but instead
normal(e-d) against 0, or normal(e/d) against 1?
> At this point all I can say is "sometimes", since it has been observed
> to occur even when x compares greater than y.
>
> > Is this behavior deliberate? A particular test in the
> > test suite (check/exam_normalization.cpp) normally only passes when
> > pow(x - y, 2).normal() == pow(x-y, 2).
Also, please see the comment of the function randomify_symbol_serials
ginac/check/times.cpp for an idea how a deterministic program can
presumably by non-deterministic: does the number of symbols generated
before that test change in your test?
Regards
-richy.
--
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>
More information about the GiNaC-list
mailing list