compute regulator with more precision
I want to compute the regulator of a real quadratic field Q(sqrt d) to high precision, accurately enough to compute the fundamental unit. The default breaks at d = 331 where fundamental unit needs more than 53 bits (the precision of doubles). The documentation says that Pari computes to a higher precision than SageMath. Also somewhere it says that if you get a good enough approximation to the regulator, it's trivial to refine it to high accuracy. It refers to "the tutorial" without a link; I read the Pari-GP tutorials on algebraic number theory without finding any explanation of that remark. So actually there are two questions here: point me to an explanation of refining the computation of the regulator, and secondly, fix the following code so that it doesn't print "oops" when d = 331. Sorry, I don't know how to get the code to display with newlines and tabs correct. It looks right when I edit the post.
gp.set_real_precision(256) # doesn't seem to do anything
def check_unit(N):
for d in range(10,N):
if not is_squarefree(d):
continue
K.<a> = QuadraticField(d)
G = K.unit_group()
[x,y] = G.gen(1).value()
x = abs(x)
R = K.regulator(None)
twox = round(exp(R))
x2 = twox/2
y2 = round(twox/sqrt(d))/2
print(d,x,x2,y,y2,exp(R)/2)
if x != x2 or y != y2:
print("oops!")
return
if norm_is_negative(x,d):
print("norm is negative")
A shorter "minimal non-working example":
sage: d = 2352721672669
sage: K.<a> = QuadraticField(d)
sage: gp.default("realprecision",256)
0
sage: R = K.regulator()
followed by many error messages.
Later: well, precision 512 seems to work. So I guess it's just that 256 isn't enough!
to change real precision in gp run
gp.default("realprecision",256)
Use the
101010
button to insert the text of your code ; alternatively, select your code and use Ctrl-K : in both case, your code willbe isolated by newlines and indented with four spaces, which is interpreted as "respect newlines and indentation".HTH,
Also asked at