-
Notifications
You must be signed in to change notification settings - Fork 275
Description
Two problems with the current padic type that I've discussed with @r-mb at the workshop:
- It uses a fixed-point notion of precision, but in some applications floating-point precision is better (see https://xavier.caruso.ovh/papers/publis/course-padic.pdf for a nice overview of various precision models).
- It doesn't do error tracking.
- It's based on somewhat naive
fmpzarithmetic, not taking advantage of all our nice code for modular arithmetic with precomputed inverses etc.
I think it would be best to add a family of new p-adic implementations, using the generics system so that there is just one interface. I have in mind at least the following:
Floating-point arithmetic: elements have the form
padic_float_nmod
padic_float_mpn
padic_float_fmpz
These would respectively use nmod, mpn_mod and fmpz_mod arithmetic. Unlike the current padic type, precision would be stored in the context object rather than in the elements, so an element would just be a tuple man, exp (with exp of type slong).
Then for ball arithmetic: elements have the form
padic_ball_nmod
padic_ball_mpn
padic_ball_fmpz
A ball would be a tuple man, exp, err (with err an slong).
Question: should we have both floating-point and fixed-point p-adics, and both approximate and ball versions of each one?
Here is a very minimal draft of a padic_float_nmod implementation that allows multiplying two numbers:
https://gist.github.com/fredrik-johansson/fc2b52fae116218ae37ca3567fdd503c
It does a simple multiplication 4x faster than padic_mul so this kind of specialization clearly looks worth it from a performance point of view (I expect even greater speedups in some other cases).