P-Adic numbers, basic is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Convert two rationals to p-adic numbers and add them up. Rational reconstruction is needed to interpret the result.

p-Adic numbers were introduced around 1900 by Hensel. p-Adic expansions (a series of digits 0 ≤ d < p times p-power weights) are finite-tailed and tend to zero in the direction of higher positive powers of p (to the left in the notation used here). For example, the number 4 (100.0) has smaller 2-adic norm than 1/4 (0.01).

If we convert a natural number, the familiar p-ary expansion is obtained: 10 decimal is 1010 both binary and 2-adic. To convert a rational number a/b we perform long division modulo powers of p. If p is actually prime, this is always possible if first the 'p-part' is removed from b (and the p-adic point moved to the left accordingly). The inverse of b modulo p is then used in the conversion.

Recipe: at each step the most significant digit of the partial remainder (initially a) is zeroed by subtracting a proper multiple of the divisor b. Shift out the zero digit (divide by p) and repeat until the remainder is zero or the precision limit is reached. Note that the 'proper multiplier' is always d = partial remainder * 1/b (mod p). The d's are the successive p-adic digits to find.

p-Adic addition proceeds as usual, with carry from the right to the leftmost term, where it has least magnitude and just drops off. We can work with approximate rationals and obtain exact results. The routine for rational reconstruction demonstrates this: repeatedly add a p-adic to itself (keeping count to determine the denominator), until an integer is reached (the numerator then equals the weighted digit sum). But even p-adic arithmetic fails if the precision is too low. The examples mostly set the shortest prime-exponent combinations that allow valid reconstruction.

Reference.

## FreeBASIC

<lang freebasic> ' *********************************************** 'subject: convert two rationals to p-adic numbers, ' add them up and show the result. 'tested : FreeBasic 1.07.0

'you can change this:

const emx = 64 'exponent maximum

const dmx = 100000 'approximation loop maximum

'better not change '------------------------------------------------ const amx = 1048576 'argument maximum

const Pmax = 32749 'max. prime < 2^15

type ratio

```  as longint a, b
```

end type

type padic declare function r2pa (byref q as ratio, byval sw as integer) as integer 'convert q = a/b to p-adic number, set sw to print declare sub printf (byval sw as integer) 'print expansion, set sw to print rational declare sub crat () 'rational reconstruction

declare sub add (byref a as padic, byref b as padic) 'let self:= a + b declare sub cmpt (byref a as padic) 'let self:= complement_a

declare function dsum () as long 'weighted digit sum

```  as long d(-emx to emx - 1)
as integer v
```

end type

'global variables dim shared as long p1, p = 7 'default prime dim shared as integer k = 11 'precision

1. define min(a, b) iif((a) > (b), b, a)

'------------------------------------------------ 'convert rational a/b to p-adic number function padic.r2pa (byref q as ratio, byval sw as integer) as integer dim as longint a = q.a, b = q.b dim as long r, s, b1 dim i as integer r2pa = 0

```  if b = 0 then return 1
if b < 0 then b = -b: a = -a
if abs(a) > amx or b > amx then return -1
if p < 2 or k < 1 then return 1
```
```  'max. short prime
p = min(p, Pmax)
'max. array length
k = min(k, emx - 1)
```
```  if sw then
'echo numerator, denominator,
print a;"/";str(b);" + ";
'prime and precision
print "O(";str(p);"^";str(k);")"
end if
```
```  'initialize
v = 0
p1 = p - 1
for i = -emx to emx - 1
d(i) = 0: next
```
```  if a = 0 then return 0
```
```  i = 0
'find -exponent of p in b
do until b mod p
b \= p: i -= 1
loop
```
```  s = 0
r = b mod p
'modular inverse for small p
for b1 = 1 to p1
s += r
if s > p1 then s -= p
if s = 1 then exit for
next b1
```
```  if b1 = p then
print "r2pa: impossible inverse mod"
return -1
end if
```
```  v = emx
do
'find exponent of p in a
do until a mod p
a \= p: i += 1
loop
```
```     'valuation
if v = emx then v = i
```
```     'upper bound
if i >= emx then exit do
'check precision
if (i - v) > k then exit do
```
```     'next digit
d(i) = a * b1 mod p
if d(i) < 0 then d(i) += p
```
```     'remainder - digit * divisor
a -= d(i) * b
loop while a
```

end function

'------------------------------------------------ 'Horner's rule function padic.dsum () as long dim as integer i, t = min(v, 0) dim as long r, s = 0

```  for i = k - 1 + t to t step -1
r = s: s *= p
if r andalso s \ r - p then
'overflow
s = -1: exit for
end if
s += d(i)
next i
```

return s end function

1. macro pint(cp)
```  for j = k - 1 + v to v step -1
if cp then exit for
next j
fl = ((j - v) shl 1) < k
```
1. endmacro

'rational reconstruction sub padic.crat () dim as integer i, j, fl dim as padic s = this dim as long x, y

```  'denominator count
for i = 1 to dmx
'check for integer
pint(s.d(j))
if fl then fl = 0: exit for
```
```     'check negative integer
pint(p1 - s.d(j))
if fl then exit for
```
```     'repeatedly add self to s
next i
```
```  if fl then s.cmpt(s)
```
```  'numerator: weighted digit sum
x = s.dsum: y = i
```
```  if x < 0 or y > dmx then
print "crat: fail"
```
```  else
'negative powers
for i = v to -1
y *= p: next
```
```     'negative rational
if fl then x = -x
```
```     print x;
if y > 1 then print "/";str(y);
print
end if
```

end sub

'print expansion sub padic.printf (byval sw as integer) dim as integer i, t = min(v, 0)

```  for i = k - 1 + t to t step -1
print d(i);
if i = 0 andalso v < 0 then print ".";
next i
print
```
```  'rational approximation
if sw then crat
```

end sub

'------------------------------------------------ 'carry

1. macro cstep(dt)
```  if c > p1 then
dt = c - p: c = 1
else
dt = c: c = 0
end if
```
1. endmacro

'let self:= a + b sub padic.add (byref a as padic, byref b as padic) dim i as integer, r as padic dim as long q, c = 0 with r

``` .v = min(a.v, b.v)
```
```  for i = .v to k +.v
c += a.d(i) + b.d(i)
cstep(.d(i))
next i
```

end with this = r end sub

'let self:= complement_a sub padic.cmpt (byref a as padic) dim i as integer, r as padic dim as long q, c = 1 with r

``` .v = a.v
```
```  for i = .v to k +.v
c += p1 - a.d(i)
cstep(.d(i))
next i
```

end with this = r end sub

'main '------------------------------------------------ dim as integer sw dim as padic a, b, c dim q as ratio

width 64, 30 cls

'rational reconstruction limits 'are relative to the precision: data 2,1, 2,4 data 1,1

data 4,1, 2,4 data 3,1

data 4,1, 2,5 data 3,1

' 4/9 + O(5^4) data 4,9, 5,4 data 8,9

data -7,5, 7,4 data 99,70

data 26,25, 5,4 data -109,125

data 49,2, 7,6 data -4851,2

data -9,5, 3,8 data 27,7

data 5,19, 2,12 data -101,384

'three 'decadic' pairs data 6,7, 10,7 data -5,7

data 2,7, 10,7 data -3,7

data 34,21, 10,9 data -39034,791

'familiar digits data 11,4, 2,43 data 679001,207

data 11,4, 3,27 data 679001,207

data 11,4, 11,13 data 679001,207

data -22,7, 2,37 data 46071,379

data -22,7, 3,23 data 46071,379

data -22,7, 7,13 data 46071,379

data -101,109, 2,40 data 583376,6649

data -101,109, 61,7 data 583376,6649

data -101,109, 32749,3 data 583376,6649

data 0,0, 0,0

print do

```  read q.a,q.b, p,k
```
```  sw = a.r2pa(q, 1)
if sw = 1 then exit do
a.printf(0)
```
```  read q.a,q.b
```
```  sw or= b.r2pa(q, 1)
if sw = 1 then exit do
if sw then continue do
b.printf(0)
```
```  c.add(a, b)
print "+ ="
c.printf(1)
```
```  print : ?
```

loop

system </lang>

Output:
```
2/1 + O(2^4)
0 0 1 0
1/1 + O(2^4)
0 0 0 1
+ =
0 0 1 1
3

4/1 + O(2^4)
0 1 0 0
3/1 + O(2^4)
0 0 1 1
+ =
0 1 1 1
-2/2

4/1 + O(2^5)
0 0 1 0 0
3/1 + O(2^5)
0 0 0 1 1
+ =
0 0 1 1 1
7

4/9 + O(5^4)
4 2 1 1
8/9 + O(5^4)
3 4 2 2
+ =
3 1 3 3
4/3

-7/5 + O(7^4)
2 5 4 0
99/70 + O(7^4)
0 5 0. 5
+ =
6 2 0. 5
1/70

26/25 + O(5^4)
0 1. 0 1
-109/125 + O(5^4)
4. 0 3 1
+ =
0. 0 4 1
21/125

49/2 + O(7^6)
3 3 3 4 0 0
-4851/2 + O(7^6)
3 2 3 3 0 0
+ =
6 6 0 0 0 0
-2401

-9/5 + O(3^8)
2 1 0 1 2 1 0 0
27/7 + O(3^8)
1 2 0 1 1 0 0 0
+ =
1 0 1 0 0 1 0 0
72/35

5/19 + O(2^12)
0 0 1 0 1 0 0 0 0 1 1 1
-101/384 + O(2^12)
1 0 1 0 1. 0 0 0 1 0 0 1
+ =
1 1 1 0 0. 0 0 0 1 0 0 1
1/7296

6/7 + O(10^7)
7 1 4 2 8 5 8
-5/7 + O(10^7)
5 7 1 4 2 8 5
+ =
2 8 5 7 1 4 3
1/7

2/7 + O(10^7)
5 7 1 4 2 8 6
-3/7 + O(10^7)
1 4 2 8 5 7 1
+ =
7 1 4 2 8 5 7
-1/7

34/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
2 0 1 2 1 2 1 2 2 1 2 1 0 0 2 2 0 1 1 2 1 0 0
+ =
0 1 1 1 1 0 0 0 2 0 1 1 1 1 2 0 2 2 0 0 0 0 2
314159/2653

-22/7 + O(7^13)
6 6 6 6 6 6 6 6 6 6 6 3. 6
46071/379 + O(7^13)
6 4 1 6 6 5 1 2 2 1 3 2 4
+ =
4 1 6 6 5 1 2 2 1 3 2 0. 6
314159/2653

-101/109 + O(2^40)
0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0 0 1 0 0 1 1 1
583376/6649 + O(2^40)
1 0 1 0 0 1 0 1 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0
+ =
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 0 0 0 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1
577215/6649

-101/109 + O(61^7)
33 1 7 16 48 7 50
583376/6649 + O(61^7)
33 1 7 16 49 34. 35
+ =
34 8 24 3 57 23. 35
577215/6649

-101/109 + O(32749^3)
5107 21031 15322
583376/6649 + O(32749^3)
5452 13766 16445
+ =
10560 2048 31767
577215/6649

```

## Wren

Translation of: FreeBASIC
Library: Wren-dynamic
Library: Wren-math

<lang ecmascript>import "/dynamic" for Struct import "/math" for Math

// constants var EMX = 64 // exponent maximum (if indexing starts at -EMX) var DMX = 1e5 // approximation loop maximum var AMX = 1048576 // argument maximum var PMAX = 32749 // prime maximum

// global variables var P1 = 0 var P = 7 // default prime var K = 11 // precision

var Ratio = Struct.create("Ratio", ["a", "b"])

```   // uninitialized
construct new() {
_v = 0
_d = List.filled(2 * EMX, 0) // add EMX to index to be consistent wih FB
}
```
```   // properties
v { _v }
v=(o) { _v = o }
d { _d }
```
```   // (re)initialize 'this' from Ratio, set 'sw' to print
r2pa(q, sw) {
var a = q.a
var b = q.b
if (b == 0) return 1
if (b < 0) {
b = -b
a = -a
}
if (a.abs > AMX || b > AMX) return -1
if (P < 2 || K < 1) return 1
P = Math.min(P, PMAX)  // maximum short prime
K = Math.min(K, EMX-1) // maximum array length
if (sw != 0) {
System.write("%(a)/%(b) + ")  // numerator, denominator
System.print("0(%(P)^%(K))")   // prime, precision
}
```
```       // (re)initialize
_v = 0
P1 = P - 1
_d = List.filled(2 * EMX, 0)
if (a == 0) return 0
var i = 0
// find -exponent of P in b
while (b%P == 0) {
b = (b/P).truncate
i = i - 1
}
var s = 0
var r = b % P
```
```       // modular inverse for small P
var b1 = 1
while (b1 <= P1) {
s = s + r
if (s > P1) s = s - P
if (s == 1) break
b1 = b1 + 1
}
if (b1 == P) {
System.print("r2pa: impossible inverse mod")
return -1
}
_v = EMX
while (true) {
// find exponent of P in a
while (a%P == 0) {
a = (a/P).truncate
i = i + 1
}
```
```           // valuation
if (_v == EMX) _v = i
```
```           // upper bound
if (i >= EMX) break
```
```           // check precision
if ((i - _v) > K) break
```
```           // next digit
_d[i+EMX] = a * b1 % P
if (_d[i+EMX] < 0) _d[i+EMX] = _d[i+EMX] + P
```
```           // remainder - digit * divisor
a = a - _d[i+EMX]*b
if (a == 0) break
}
return 0
}
```
```   // Horner's rule
dsum() {
var t = Math.min(_v, 0)
var s = 0
for (i in K - 1 + t..t) {
var r = s
s = s * P
if (r != 0 && ((s/r).truncate - P) != 0) {
// overflow
s = -1
break
}
s = s + _d[i+EMX]
}
return s
}
```
```   // rational reconstruction
crat() {
var fl = false
var s = this
var j = 0
var i = 1
```
```       // denominator count
while (i <= DMX) {
// check for integer
j = K - 1 + _v
while (j >= _v) {
if (s.d[j+EMX] != 0) break
j = j - 1
}
fl = ((j - _v) * 2) < K
if (fl) {
fl = false
break
}
```
```           // check negative integer
j = K - 1 + _v
while (j >= _v) {
if (P1 - s.d[j+EMX] != 0) break
j = j - 1
}
fl = ((j - _v) * 2) < K
if (fl) break
```
```           // repeatedly add self to s
s = s + this
i = i + 1
}
if (fl) s = s.cmpt
```
```       // numerator: weighted digit sum
var x = s.dsum()
var y = i
if (x < 0 || y > DMX) {
System.print("crat: fail")
} else {
// negative powers
i = _v
while (i <= -1) {
y = y * P
i = i + 1
}
```
```           // negative rational
if (fl) x = -x
System.write(x)
if (y > 1) System.write("/%(y)")
System.print()
}
}
```
```   // print expansion
printf(sw) {
var t = Math.min(_v, 0)
for (i in K - 1 + t..t) {
System.write(_d[i + EMX])
if (i == 0 && _v < 0) System.write(".")
System.write(" ")
}
System.print()
// rational approximation
if (sw != 0) crat()
}
```
```   // add b to 'this'
+(b) {
var c = 0
r.v = Math.min(_v, b.v)
for (i in r.v..K + r.v) {
c = c + _d[i+EMX] + b.d[i+EMX]
if (c > P1) {
r.d[i+EMX] = c - P
c = 1
} else {
r.d[i+EMX] = c
c = 0
}
}
return r
}
```
```   // complement
cmpt {
var c = 1
r.v = _v
for (i in _v..K + _v) {
c = c + P1 - _d[i+EMX]
if (c > P1) {
r.d[i+EMX] = c - P
c = 1
} else {
r.d[i+EMX] = c
c = 0
}
}
return r
}
```

}

var data = [

```   /* rational reconstruction limits are relative to the precision */
[2, 1, 2, 4, 1, 1],
[4, 1, 2, 4, 3, 1],
[4, 1, 2, 5, 3, 1],
[4, 9, 5, 4, 8, 9],
[-7, 5, 7, 4, 99, 70],
[26, 25, 5, 4, -109, 125],
[49, 2, 7, 6, -4851, 2],
[-9, 5, 3, 8, 27, 7],
[5, 19, 2, 12, -101, 384],
[6, 7, 10, 7, -5, 7],
[2, 7, 10, 7, -3, 7],
[34, 21, 10, 9, -39034, 791],
/*familiar digits*/
[11, 4, 2, 43, 679001, 207],
[11, 4, 3, 27, 679001, 207],
[11, 4, 11, 13, 679001, 207],
[-22, 7, 2, 37, 46071, 379],
[-22, 7, 3, 23, 46071, 379],
[-22, 7, 7, 13, 46071, 379],
[-101, 109, 2, 40, 583376, 6649],
[-101, 109, 61, 7, 583376, 6649],
[-101, 109, 32749, 3, 583376, 6649]
```

]

var sw = 0 var a = Padic.new() var b = Padic.new()

for (d in data) {

```   var q = Ratio.new(d[0], d[1])
P = d[2]
K = d[3]
sw = a.r2pa(q, 1)
if (sw == 1) break
a.printf(0)
q.a = d[4]
q.b = d[5]
sw = sw | b.r2pa(q, 1)
if (sw == 1) break
if (sw == 0) {
b.printf(0)
var c = a + b
System.print("+ =")
c.printf(1)
}
System.print()
```

}</lang>

Output:
```2/1 + 0(2^4)
0 0 1 0
1/1 + 0(2^4)
0 0 0 1
+ =
0 0 1 1
3

4/1 + 0(2^4)
0 1 0 0
3/1 + 0(2^4)
0 0 1 1
+ =
0 1 1 1
-2/2

4/1 + 0(2^5)
0 0 1 0 0
3/1 + 0(2^5)
0 0 0 1 1
+ =
0 0 1 1 1
7

4/9 + 0(5^4)
4 2 1 1
8/9 + 0(5^4)
3 4 2 2
+ =
3 1 3 3
4/3

-7/5 + 0(7^4)
2 5 4 0
99/70 + 0(7^4)
0 5 0. 5
+ =
6 2 0. 5
1/70

26/25 + 0(5^4)
0 1. 0 1
-109/125 + 0(5^4)
4. 0 3 1
+ =
0. 0 4 1
21/125

49/2 + 0(7^6)
3 3 3 4 0 0
-4851/2 + 0(7^6)
3 2 3 3 0 0
+ =
6 6 0 0 0 0
-2401

-9/5 + 0(3^8)
2 1 0 1 2 1 0 0
27/7 + 0(3^8)
1 2 0 1 1 0 0 0
+ =
1 0 1 0 0 1 0 0
72/35

5/19 + 0(2^12)
0 0 1 0 1 0 0 0 0 1 1 1
-101/384 + 0(2^12)
1 0 1 0 1. 0 0 0 1 0 0 1
+ =
1 1 1 0 0. 0 0 0 1 0 0 1
1/7296

6/7 + 0(10^7)
7 1 4 2 8 5 8
-5/7 + 0(10^7)
5 7 1 4 2 8 5
+ =
2 8 5 7 1 4 3
1/7

2/7 + 0(10^7)
5 7 1 4 2 8 6
-3/7 + 0(10^7)
1 4 2 8 5 7 1
+ =
7 1 4 2 8 5 7
-1/7

34/21 + 0(10^9)
9 5 2 3 8 0 9 5 4
-39034/791 + 0(10^9)
1 3 9 0 6 4 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 0
+ =
0 1 1 1 1 0 0 0 2 0 1 1 1 1 2 0 2 2 0 0 0 0 2
314159/2653

-22/7 + 0(7^13)
6 6 6 6 6 6 6 6 6 6 6 3. 6
46071/379 + 0(7^13)
6 4 1 6 6 5 1 2 2 1 3 2 4
+ =
4 1 6 6 5 1 2 2 1 3 2 0. 6
314159/2653

-101/109 + 0(2^40)
0 1 1 1 1 1 1 0 1 1 0 1 0 0 1 1 0 1 1 0 0 0 0 0 0 1 0 0 1 0 1 1 0 0 1 0 0 1 1 1
583376/6649 + 0(2^40)
1 0 1 0 0 1 0 1 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0
+ =
0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 1 1 0 1 1 0 0 0 1 1 0 0 1 1 1 0 0 0 1 1 1 0 1 1 1
577215/6649

-101/109 + 0(61^7)
33 1 7 16 48 7 50
583376/6649 + 0(61^7)
33 1 7 16 49 34. 35
+ =
34 8 24 3 57 23. 35
577215/6649

-101/109 + 0(32749^3)
5107 21031 15322
583376/6649 + 0(32749^3)
5452 13766 16445
+ =
10560 2048 31767
577215/6649
```