What is the largest Positive number supported by Simple Components and PragmArc?

Hi;

I’m running into a problem while trying to write an Ada solution for the Rosetta Code task " Primorial numbers"

which basically are factorials of primes.

I can only calculate to the Primorial (615) afterwhich overflow occurs.

raised STORAGE_ERROR : Ada.Numerics.Big_Numbers.Big_Integers.Bignums.Normalize: big integer limit exceeded

So, before investing any significant effort in trying to port my GNAT BigNum attempt to PragmArc or SImple Components, I’d like to know what the largest Positive Integer both of them can generate prior to stack overflow or insufficient memory.

I do not recall that such limits are documented, but if they are, I apologize for wasting your time.

A follow-on question is: Is there a better way to generate Primorials than by doing so via brute-force?

The task requirements request the length of the Primorial digit string all the way up to to one million!

Seems like these other languages must be “cheating” some how :slight_smile:

Retired Build Engineer

You don’t actually have to find the 1_000_000th primorial, you just have to find its length. I have to confess that offhand I don’t know a way to do that, but the other solutions will almost certainly have implemented it.

Messing around with it a bit: 2x3=6; that is, one-digit times one-digit is one-digit, but then you multiply by 5 and get 30 (two digits), by 7 and get 210 (three digits), by 11 and get 2310 (four digits), by 13 and get 30_030 (five digits), by 17 and get 510_510 (six digits), by 19 and get 9_699_690 (seven digits), and so forth.

The increase seems to be linear (add a digit each time), but I’m pretty sure that before long you’ll get a change of 2 digits instead of a change of 1 digit, and things may get more interesting after that.

Since you can compute up to Primorial (615), do you see a pattern there?

(This sort of thing happens a lot in Advent of Code problems, by the way.)

The implementation in Simple Components is limited by the size of the heap, and, theoretically, by the integer index. That is 64-bit digit ** Integer’Last = (approximately) = 2 ** 64 ** (2 ** 31) = 2 ** (2 ** 37)

For the PragmAda Reusable Components, the answer is a function of the available heap memory (in bits), System.Max_Binary_Modulus, and Integer’Last. Given

type T is mod System.Max_Binary_Modulus;

then the maximum value is

min (2 ** Heap, 2 ** (Integer’Last * T’Size / 2) )

Typically, only the latter term can be calculated. For a 64-bit target and recent compilers, I find

Compiler Integer’Last T’Size
GNAT 2 ** 31 - 1 128
ObjectAda 2 ** 31 - 1 64