Ralf Hemmecke wrote:
>
> First the problem.
>
> Z ==> Integer
> SI ==> SingleInteger
> p:=prevPrime((max()$SI)::Z)$IntegerPrimesPackage(Z)
> F ==> PrimeField p
> FZ ==> SUP F
> f: FZ := monomial(1, 2)$FZ - 2
> factor(f)
>
> If running this in a session one ends up with a nasty
>
> (6) -> f: FZ := monomial(1, 2)$FZ - 2
> Compiling function G387 with type Integer -> Boolean
> Compiling function G389 with type NonNegativeInteger -> Boolean
>
> 2
> (6) ? + 4611686018427387845
> Type:
> SparseUnivariatePolynomial(PrimeField(4611686018427387847))
> (7) -> factor(f)
>
> >> System error:
> The value
> 4684986446884335550
> is not of type
> FIXNUM
>
>
> That's probably not a very big surprise when looking at the special
> implementation of a finite field for a prime that is just a bit smaller
> than the maximum size of a SingleInteger.
>
> However, of course, that shouldn't happen.
>
> I first thought that the multiplication in PrimeField is problematic,
> but no, it works fine. The problem is addmod $ SingleInteger.
> See session below.
>
> The documentation for addmod of SingleInteger is inherited from
> IntegerNumberSystem.
>
> addmod: (%, %, %) -> %
> addmod(a, b, p), 0<=a, b<p>1, means a+b mod p.
>
> Well, one might probably expect that there are problems if the domain
> has only the size of a lisp fixnum. But that's certainly implementation
> dependent. And seemingly mulmod works just fine for these border cases.
>
> Although, I would somehow like that the ++ docstring for addmod $
> SingleInteger would mention the restriction that not only a<p, b<p, but
> also a+b<=max(), I can live with the implicit restriction, that a
> programmer has to take care in the SingleInteger case.
>
> However, there is a real bug that results from this restriction and that
> is in IntegerMod(p)
>
> It says
>
> if p <= convert(max()$SingleInteger)@Integer then
> Rep := SingleInteger
> q := p::SingleInteger
> ...
> else
> Rep := Integer
> ...
>
> Of course it should rather say:
>
> if p <= convert(shift(max()$SingleInteger, -1))@Integer then
>
> Bugfix is attached.
> Can I commit?
Yes, thanks. One can probably slightly improve addmod, but
there are good reasons to use primes significantly smaller
than max()$SingleInteger.
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/fricas-devel/E1ifgyv-0007lq-K9%40hera.math.uni.wroc.pl.