Skip to content

Navigation Menu

Sign in
Sign up

feat(padic): add p-adic numbers - #845

Draft
cbmarini wants to merge 2 commits into
form-dev:master from
cbmarini:padic-pr
Draft

feat(padic): add p-adic numbers #845
cbmarini wants to merge 2 commits into
form-dev:master from
cbmarini:padic-pr

Conversation

@cbmarini

@cbmarini cbmarini commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

This PR implements p-adic numbers in Form, using Flint as the backend. The structure follows the floating point system quite closely. Example program:

 * #StartPadic <prime>,<precision>
 #StartPadic 7,10
 Local F = 101/13;
 ToPadic;
 Print;
 .end

Which prints


 F =
 (4 + 6*7^2 + 4*7^3 + 2*7^4 + 5*7^5 + 3*7^6 + 1*7^8 + 2*7^9);

This is the 7-adic series representation of 101/13 up to O(7^10).

There are two other statements

  1. PadicToRat; which converts p-adic numbers back to rationals. It may be worth discussing whether the existing ToRat statement from the floating-point system can be reused here, since floating-point and p-adic modes cannot be active at the same time.
  2. FromPadic f; which replaces the internal (protected) padic_ function by f, exposing the underlying data:
 #$prime = 7;
 #StartPadic `$prime',10
 CFunction f;
 Symbol u,v,N;
 Local F = 101/13;
 ToPadic;
 FromPadic f;
 Print;
 .sort
 F =
 f(0,10,86915469);

The (Flint) data of the padic number can be meaningfully processed further. For example

 
 Transform f decode(12,3):base=`$prime';
 Print;
 .end
 F =
 f(0,10,4,0,6,4,2,5,3,0,1,2);

This computes the coefficients shown in the first example.

Remaining items on the to-do list:

  • Update the manual.
  • Add regression/coverage tests.
  • Transform decode currently doesn't allow for large bases/primes. This may need to be fixed, or alternatively the FromPadic statement could be extended to support this directly, for example FromPadic f, series;.
  • Should the prime number be stored in the internal padic_ function as well?

This can be discussed further at the Form workshop.

This is a squashed commit of https://github.com/cbmarini/form/tree/padic

coveralls commented Jun 12, 2026
edited
Loading

Copy link
Copy Markdown

Coverage Status

coverage: 63.094% (+0.3%) from 62.841% — cbmarini:padic-pr into form-dev:master

cbmarini force-pushed the padic-pr branch 3 times, most recently from 5dc8a6f to 31a1ee7 Compare June 17, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /