Addressing single digits of big integers

View: New views
3 Messages — Rating Filter:   Alert me  

Addressing single digits of big integers

by Rafael Anschau :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is it possible to address single digits in big integers, without the high costs of export import ? Something like a pointer to the digit ?

Thanks.

Rafael


_______________________________________________
gmp-discuss mailing list
gmp-discuss@...
http://swox.com/mailman/listinfo/gmp-discuss

Parent Message unknown Re: Addressing single digits of big integers

by Décio Luiz Gazzoni Filho :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


----- Original Message -----
From: "Rafael Anschau" <rafael.anschau@...>
To: gmp-discuss@...
Subject: Addressing single digits of big integers
Date: Thu, 24 Jul 2008 16:48:03 -0300

> Is it possible to address single digits in big integers,
> without the high costs of export import ? Something like a
> pointer to the digit ?

If by digit you mean a base-10 digit, sorry, it's gonna be
fairly costly. Most large integer packages represent values
internally in a power-of-two base, so you can't directly get
base-10 digits, only base-2^k digits. To get base-10 digits
you'll have to incur the cost of changing representation by
exporting, or doing a calculation like x/10^k mod 10, and
both the division and the modulo are costly for large
values.

If you routinely need to work with the base-10
representation of your large integers, and it's a bottleneck
of your code (profile it somewhere to be sure, otherwise you
may lose performance by following this advice), try a
different library which works with a power-of-10 base
representation. I can't name any, but I know that most of
the various Pi-calculator programs out there use base-10
extensively to avoid a costly change of representation at
the end.

Décio
_______________________________________________
gmp-discuss mailing list
gmp-discuss@...
http://swox.com/mailman/listinfo/gmp-discuss

Re: Addressing single digits of big integers

by Paul Zimmermann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

       Rafael,

> Date: Thu, 24 Jul 2008 16:48:03 -0300
> From: "Rafael Anschau" <rafael.anschau@...>
>
> Is it possible to address single digits in big integers, without the high
> costs of export import ? Something like a pointer to the digit ?
>
> Thanks.
>
> Rafael

from a theoretical point of view, as far as I know, the complexity of computing
a single digit (say the middle one) in a base that is not commensurable to the
internal base (for example in base 10 when numbers are represented in radix 2)
is the same as converting the whole number, i.e., O(n log n).

Now if you mean digits in base say 16 or 256, that are commensurable to 2, you
can access them directly using the mpn layer.

Paul Zimmermann
_______________________________________________
gmp-discuss mailing list
gmp-discuss@...
http://swox.com/mailman/listinfo/gmp-discuss
LightInTheBox - Buy quality products at wholesale price!