Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Number format with arbitrary precision #44

Closed
ckrause opened this issue Feb 26, 2021 · 6 comments
Closed

Number format with arbitrary precision #44

ckrause opened this issue Feb 26, 2021 · 6 comments

Comments

@ckrause
Copy link
Owner

ckrause commented Feb 26, 2021

We currently use 64-bit signed ints as number format. Many of the sequence terms in the OEIS exceed this size. We should check if there are libraries for big number formats or if it is feasible to implement it ourselves.

@karttu
Copy link
Contributor

karttu commented Mar 2, 2021

There are several, for example GMP (GNU Multiple Precision Arithmetic Library), but I don't know about their current status. Note that with any bignum-implementation comes the added headache of the need to allocate and deallocate lists, possibly largish. (OTOH, with only two 64-bit words we already go up to 340282366920938463463374607431768211456, unsigned). But with well-designed interfaces that kind of change might be mostly transparent (coding-wise), except perhaps in the execution times and memory usage? But I'm not an expert in C++, so I don't know all of its perks.

@ckrause
Copy link
Owner Author

ckrause commented Mar 3, 2021

I don't think we don't need arbitrary precision. I was thinking to use C++ templates with std::arrays. That should be much more efficient, because everything is stored directly on the stack.

@jonmaiga
Copy link

jonmaiga commented Mar 6, 2021

I've had decent success with the trio mpir+mprf+mpreal. If you are aiming for integer only operations mpir might suffice (e.g. mpz_class) or possibly own implementation/other lightweight library.

(Great project btw!)

@neoneye
Copy link
Collaborator

neoneye commented Mar 29, 2021

For evaluating programs with bigger number you can use LODA Lab. However this cannot do mining of new programs.

PROMPT> loda eval A42 -t 19 
1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111,11111111111,111111111111,1111111111111,11111111111111,111111111111111,1111111111111111,11111111111111111,111111111111111111,1111111111111111111

PROMPT> loda-lab eval 42 -t 40
1,11,111,1111,11111,111111,1111111,11111111,111111111,1111111111,11111111111,111111111111,1111111111111,11111111111111,111111111111111,1111111111111111,11111111111111111,111111111111111111,1111111111111111111,11111111111111111111,111111111111111111111,1111111111111111111111,11111111111111111111111,111111111111111111111111,1111111111111111111111111,11111111111111111111111111,111111111111111111111111111,1111111111111111111111111111,11111111111111111111111111111,111111111111111111111111111111,1111111111111111111111111111111,11111111111111111111111111111111,111111111111111111111111111111111,1111111111111111111111111111111111,11111111111111111111111111111111111,111111111111111111111111111111111111,1111111111111111111111111111111111111,11111111111111111111111111111111111111,111111111111111111111111111111111111111,1111111111111111111111111111111111111111

(LODA is indeed a great project!)

@ckrause
Copy link
Owner Author

ckrause commented Aug 1, 2021

I added native support for big numbers in LODA. No external libraries are used. There is an upper limit of the size (configurable at compile time). Currently we support up to 180 decimal digits. Still room for performance improvements:

2021-08-01 16:33:18|INFO |Starting operations benchmark
2021-08-01 16:33:18|INFO |mov: 0.079µs
2021-08-01 16:33:18|INFO |add: 0.159µs
2021-08-01 16:33:18|INFO |sub: 0.279µs
2021-08-01 16:33:18|INFO |trn: 0.392µs
2021-08-01 16:33:18|INFO |mul: 2.369µs
2021-08-01 16:33:18|INFO |div: 15.448µs
2021-08-01 16:33:18|INFO |dif: 19.218µs
2021-08-01 16:33:19|INFO |mod: 19.025µs
2021-08-01 16:33:19|INFO |pow: 89.842µs
2021-08-01 16:33:20|INFO |gcd: 583.418µs
2021-08-01 16:33:20|INFO |bin: 36.602µs
2021-08-01 16:33:20|INFO |cmp: 0.028µs
2021-08-01 16:33:20|INFO |min: 0.128µs
2021-08-01 16:33:20|INFO |max: 0.117µs

@ckrause ckrause closed this as completed Aug 1, 2021
@neoneye
Copy link
Collaborator

neoneye commented Aug 1, 2021

Awesome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants