On Wed, 21 Nov 2012 10:03:18 -0800 (PST)
Jean-Pierre Flori <
jpf...@gmail.com> wrote:
> > We let people shoot themselves in the foot if they wish to. This
> > approach seems to be everywhere in Python.
> >
> > Of course :)
>
> My point is rather of questioning the way things are normalized by
> Pynac.
>
> When you get something foolish as I suggested, I guess that Sage says
> the different non-symbolic pieces can not be coerced into a common
> parent, and so pynac does nothing.
>
> In the original problematic case, you have something in Z and other
> things in GF(q), so I guess what you do is to ask Sage to coerce all
> of these somewhere which happens to be GF(q) (or is it Z?) and
> compute the content there (not really clear how this is done either
> if we are working in GF(q)), and then multiply the original thing by
> -1/content (the opposite/inverse is computed in GF(q)) (the
> multiplication by this computed value is done where?).
> In the original example, the problem is that -1 in Z becomes +1 in
> GF(2^k), and the content is 1 and -1/1 is still 1, and then you
> multiply the original -1 (in Z) coefficient by 1 (in ??? Z I guess,
> cause otherwise the result would live in GF(2^k) and be 1 and the
> original problem would not occur!).
Right. The arithmetic is done by Sage, so coercion applies as usual.
The result of -1 in ZZ (the coefficient) divided by 1 in GF(2^8)
(-content) is 1 in GF(2^8).
The problem is, numeric::{div,mul}_dyn() choses to ignore multiplication
by anything which is equal to 1 in ZZ. So this normalization is skipped
altogether.
Here is the normalization code:
http://hg.pynac.org/pynac/src/5f14c0386822d8c7448bae2577f3966d3dd35902/ginac/mul.cpp?at=default#cl-730
Here is mul_dyn and div_dyn:
http://hg.pynac.org/pynac/src/5f14c0386822d8c7448bae2577f3966d3dd35902/ginac/numeric.cpp?at=default#cl-1836
> Or do you only consider the "integer part" of things which is
> mysterious, but let's say you take a representative in 0..p-1 for
> each coeff of the polynomial representation of GF(q) over GF(p), and
> compute the gcd of that, and the gcd of the different gcd's and
> compute its inverse as a similar representative in GF(p), its
> opposite and multiply by the resulting integer, which would lead to
> the original bug.
>
> Or content is just something different and specific to ginac?
>
> I should really look at the code, or stop asking stupid questions :)
These are not stupid questions. Unfortunately normalization is a black
art in itself. The correct thing to do is slightly different for each
algebraic domain. When we are dealing with symbolic expressions, it's
unclear altogether. I don't know how GiNaC handles these things either.
I am starting believe more and more that my initial fix is wrong. We
should change numeric::{div,mul}_dyn instead.
Cheers,
Burcin