Anonymous user
P-Adic square roots: Difference between revisions
max. p-adic precision with standard data types
(→{{header|Wren}}: Updated in line with changes to FB example.) |
(max. p-adic precision with standard data types) |
||
Line 47:
const emx =
'exponent maximum
const amx =
'tentative argument maximum
'------------------------------------------------
const Mxd = cdbl(2)^53 - 1
'max. float64 integer
const Pmax = 32749
'max. prime < 2^15
Line 93 ⟶ 96:
function padic.sqrt (byref g as ratio, byval sw as integer) as integer
dim as longint a = g.a, b = g.b
dim as longint
dim as long f1, r, s, t
dim i as integer, f as double
sqrt = 0
Line 152 ⟶ 155:
'find root for small p
for r = 1 to p1
if
next r
Line 181 ⟶ 184:
'evaluate f(x)
#macro evalf(x)
f = b * x * cdbl(x
'overflow
if f
q = clngint(f)
#endmacro
Line 229 ⟶ 233:
function padic.crat (byval sw as integer) as ratio
dim as integer i, j, t = min(v, 0)
dim
dim as long q, x, y
dim as
dim r as ratio
'weighted digit sum
s = 0: pk = 1
for i = t to k - 1 + v
if pk \
'overflow
pk =
end if
s += d(i) *
next i
Line 249 ⟶ 254:
dim as longint m(1) = {pk, s}
dim as longint n(1) = {0, 1}
h = cdbl(s) * s + 1
i = 0: j = 1
▲ s = s * s + 1 ' norm(v)^2
'Lagrange's algorithm
do
f = m(i) *
f += n(i) *
'Euclidean step
Line 262 ⟶ 268:
n(i) -= q * n(j)
h += cdbl(n(i)) * n(i)
'compare norms
if
'interchange vectors
swap i, j
Line 375 ⟶ 382:
data 10496,497, 2,19
data
data
data -1,1, 5,8
Line 383 ⟶ 390:
data 2,1, 7,8
data
data
data
data
data
data -255,256, 257,3
Line 423 ⟶ 430:
loop
end
</lang>
{{out|Examples}}
<pre>
Line 478 ⟶ 486:
lift:
sqrt +/-
...
...
sqrt^2
-577215/664901
lift:
sqrt +/-
...
...
sqrt^2
1 2 1 2
15403/26685
Line 538 ⟶ 546:
lift:
sqrt +/-
... 3 2 6 5 3 1 2 4 1 4. 1
... 3 4 0 1 3 5 4 2 5 2. 6
sqrt^2
3 3 1 1 3 3 4 4 5. 1 1
11696/621467
lift:
sqrt +/-
...
...
sqrt^2
-27764/11521
lift:
sqrt +/-
... 4 2 5 0 4 5 0 1 2 2 1
... 2 4 1 6 2 1 6 5 4 4 6
sqrt^2
3 2 6 5 3 1 2 4 1 4 1
-27584/12953
lift:
sqrt +/-
...
...
sqrt^2
1 4 1 4 2 1 3 5 6 2 3
-166420/135131
lift:
sqrt +/-
...
...
sqrt^2
14142/135623
|