DeRhamComputation/auxilliaries/hensel.sage

31 lines
1.1 KiB
Python
Raw Normal View History

2022-11-18 15:00:34 +01:00
def naive_hensel(fct, F, start = 1, prec=10):
'''given field F and polynomial fct over F((t)), find root of this polynomial in F((t)), using Hensel method with first value equal to start.'''
Rt.<t> = LaurentSeriesRing(F, default_prec=prec)
RtQ = FractionField(Rt)
RptW.<W> = PolynomialRing(RtQ)
RptWQ = FractionField(RptW)
fct = RptWQ(fct)
fct = RptW(numerator(fct))
#return(fct)
#while fct not in RptW:
# print(fct)
# fct *= W
2024-06-10 19:55:49 +02:00
alpha = (fct.derivative())(W = RtQ(start))
2022-11-18 15:00:34 +01:00
w0 = Rt(start)
i = 1
while(i < prec):
w0 = w0 - fct(W = w0)/alpha + O(t^(prec))
i += 1
return w0
def nth_root2(fct, n, prec=10):
'''Given power series in F((t)), find its n-th root up to precision prec.'''
F= parent(fct).base_ring()
Rt.<t> = LaurentSeriesRing(F, default_prec=prec)
RW.<W> = PolynomialRing(Rt)
v = fct.valuation()
fct1 = Rt(fct*t^(-v))
a0 = fct1[0]
if v%n != 0:
raise ValueError('The valuation of the power series is not divisible by n.')
return t^(v//n)*naive_hensel(W^n - fct1, F, start = a0.nth_root(n), prec=prec)