John Cremona on Thu, 10 Dec 2015 15:45:48 +0100


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

Re: Regarding digits function


On 10 December 2015 at 14:21, Karim Belabas
<Karim.Belabas@math.u-bordeaux.fr> wrote:
> * John Cremona [2015-12-10 11:26]:
>> On 10 December 2015 at 10:13, Bill Allombert
>> <Bill.Allombert@math.u-bordeaux.fr> wrote:
>> > On Thu, Dec 10, 2015 at 02:35:33PM +0530, chandra sekaran wrote:
>> >> Hi,
>> >>
>> >> digits(0) is giving  empty vector.  It should give [0].
>> >> Am i correct or wrong?
>> >
>> > No, this is expected: this is consistent with binary(0).
>> > The idea is to remove all leading zeros.
>>
>> That is certainly the mathematically pure answer, but in Real Life we
>> strip leading 0s except for 0 itself, since we do not like empty
>> strings representing integers.
>
> Yes, our convention is that 0 has no digits.
>
> I just checked that both Maple (convert) and Mathematica (IntegerDigits)
> adopt another one; e.g. convert(0,base,2) yields [0].

It took a while to track down but Magma agrees with pari:

> Intseq(10,2);
[ 0, 1, 0, 1 ]
> Intseq(0,2);
[]
> Intseq(0,2,5);
[ 0, 0, 0, 0, 0 ]

where the second arguement is the base, and the third (optional)
causes padding with leading 0s, so one could recover the Maple
behaviour by having that as 1.  Compare

> [Intseq(n,2): n in [0..3]];
[
    [],
    [ 1 ],
    [ 0, 1 ],
    [ 1, 1 ]
]

with

> [Intseq(n,2,1): n in [0..3]];
[
    [ 0 ],
    [ 1 ],
    [ 0, 1 ],
    [ 1, 1 ]
]

So it would be possible for pari's digits() function to also have a
3rd padding parameter.  But it hardly a high priority!

>
>> Perhaps the documentation could point this out?
>
> Done in 'master'.
>

Great!

John

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