Karim Belabas on Sun, 01 Aug 2010 19:47:45 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Real zero in libpari


* Bill Allombert [2010-07-26 15:14]:
> On Mon, Jul 26, 2010 at 02:35:04PM +0200, Jeroen Demeyer wrote:
> > Hello pari-users,
> > 
> > I have a technical question about the t_REAL type.  The documentation
> > says that real zero is characterized by having the sign equal to zero.
> > My question is: does a real zero NEED to have lg == 2 in order to be a
> > valid GEN?
> 
> Currently, yes. This is necessary because z[2] must be normalized, and so
> cannot be 0. Thus the only possibility is that z[2] does not exist i.e. lg=2.

A real 0 is allowed to have an arbitrary length, otherwise functions
like affsr() make no sense --  as currently implemented, documented, and
used (look for affsr(0,.) in the PARI sources.

In fact, it is not documented that z[2] must be normalized (and this is
likely to change as it serves no real benefit and make t_INT and t_REAL
mantissas incompatible). The documentation only says that for z != 0,
the mantissa is stored in z[2]....z[lg(z)-1]
(and that the latter words are ignored if signe(z) = 0).

>> I am asking because the following program gives an error:
>> #include <pari/pari.h>
>> int main()
>> {
>>     pari_init(1000000, 500000);
>> 
>>     GEN x = cgetr(3);  /* Normally, lg would be 2 */
>>     setsigne(x, 0);
>>     setexpo(x, -63);
>>     dbgGEN(x, -1);
>> 
>>     /* The following line gives:
>>   ***   overflow in expo().
>>   ***   Error in the PARI system. End of program. */
>>     gexp(x, 100);
>> }
> 
> It seems that mpexp explicitly make the assumption that lg(x)=2 iff signe(x)=0.
> This assumption is correct at this point.

This is a bug in mpexp(). The assumption is useless (getting rid of it
can be done with no loss of efficiency), and not even correct.

Fixed in svn.

> Another frequent similar assumption is done for polynomials with t_INT
> coefficients: lg(x)=2 iff signe(x)=0. Note that this is not true for
> general polynomials (with inexact 0 as coefficients).

In that case, it is documented that the leading term of a t_POL is not
allowed to be an exact rational 0. Hence lg(x) = 2 iff signe(x) = 0
for a t_POL in Z[X].

Cheers,

    K.B.
--
Karim Belabas, IMB (UMR 5251)  Tel: (+33) (0)5 40 00 26 17
Universite Bordeaux 1          Fax: (+33) (0)5 40 00 69 50
351, cours de la Liberation    http://www.math.u-bordeaux1.fr/~belabas/
F-33405 Talence (France)       http://pari.math.u-bordeaux1.fr/  [PARI/GP]
`