Hi all,
I found very curious not to find any example of Hensel's lifting in p-adics on various SAGE pages (maybe because I am too much newbie in maths,Sage,ask,.. ??).
I had same experience than others about the "solve()" : discovering than it's not an all purpose solver...
Here is my example for Hensel lifting in p-adics. One hidden difficulty was about 'Symbolic Expression' : very difficult to cast one integer p-adic to constant Expression :-)...explaining why code has various "I want to stay inside Integer scope!" parts.
# Sample for 7-adics: search quadratic root of 2
# We define ring of p-adics here...but only for printing end result
# because Hensel lemma algorithm is NOT Taylor tangent approximation algorithm
w = Integer(7) ; q = 5 ; R = Zp(w,q) ; print 'Working in ring ',R
# Define function, symbolic expression over integer
f(x) = x^2 - 2 ; print 'f : ',f
# Compute derivate functions
F0 = f.diff(0) ; F1 = f.diff(1)
# Set one integer local solution of f(x) = 0
r0 = Integer(3) ; f0r0 = F0(x=r0) ; f1r0 = F1(x=r0)
print 'Is ',r0,' one local solution ? ', (Mod(f0r0,w) == 0) and (Mod(f1r0,w) != 0)
# Get one new local solution from older one at each step of loop
rk = r0 ; wk = Integer(1)
for k in range(q-1):
print ; print '********** Step ',k,'***********' ; print
# Compute k-th power of w
wk = w * wk
# Compute value of F0 and F1 for rk
f0rk = Integer(F0(x=rk)) ; print 'F0(rk) = ', f0rk
f1rk = Integer(F1(x=rk)) ; print 'F1(rk) = ', f1rk
# Most important part:
# - f0rk / wk is "Integer" division, removing the w^k factor
# - negative (-), multiply and inverse_mod operation in ring R
t = Integer(f0rk / wk) * inverse_mod(-f1rk,w) ; print t
rk = rk + Integer(t*wk) ; print rk
# Print result
print ; print 'Result in ring R, f(',R(rk),') = ',R(f(rk))
Hope I formatted these right - let me know...
thanks - yes - where can I learn that strange hieroglyphics you all use for this stuff so you and @ppurka don't have to keep on correcting my mess please? :)
Use the toolbar and the live preview you get, before posting. You will see the hieroglyphics :) Use the "10101" like icon to post code. It ensures that the code is properly formatted and typeset in fixed/monospaced font and is syntax highlighted.