Math 2325
Project 6 (Chapter 8) - p-adic Numbers

Helmut Knaust, Department of Mathematical Sciences, UTEP, El Paso TX 79968
hknaust@utep.edu
04/27/2017.

Computing p-adic  Cauchy Sequences and Expansions

The following command computes m terms of the “canonical” p-adic Cauchy sequence of the rational number x . The number p must be prime, the default for m is 20. 
Note: The commands will only work if |x(Subscript[|, p ])≤ 1.

PadicCauchy[x_,p_,m_:20]:=If[PrimeQ[p]&&Not[Mod[Denominator[x],p]==0],Table[Solve[x==k,k,Modulus->p^n][[1,1,2]],{n,1,m}],Print["p is not a prime number, or the p-adic norm of ",x," is greater than 1." ]]

PadicCauchy[371,5,10]

PadicCauchy[1/10,11]

PadicCauchy[1/10,3]

PadicCauchy[-1,17]

The next command computes the first m terms of the p - adic expansion of the rational number x The number p must be prime (and less than 11). The default for m is 20. 
Note: The commands will only work if |x(Subscript[|, p ])≤ 1.

PadicExp[x_,p_,m_:20]:=Module[{cs,padic},If[PrimeQ[p]&&p<11&&Not[Mod[Denominator[x],p]==0],cs=Table[Solve[x==k,k,Modulus->p^n][[1,1,2]],{n,1,m}];padic=Prepend[Drop[(RotateLeft[cs]-cs)/Table[p^n,{n,1,m}],-1],First[cs]];Apply[Print,Join[{p,"-adic:   "},Insert[padic,".",2]]],Print["p is not a prime number less than 11, or the p-adic norm of ",x," is greater than 1." ]]]

PadicExp[-2,5]

PadicExp[278,5]

The next command computes the first m terms of the p - adic expansion of the rational number x The number p can be larger than 7, but must be prime. The default for m is 20. 
Note: The commands will only work if |x(Subscript[|, p ])≤ 1.

PadicExp2[x_,p_,m_:20]:=Module[{list=PadicCauchy[x,p,m]},
list=list-Prepend[Rest[RotateRight[list]],0];
Apply[Print,Insert[Flatten[Table[{list[[k]]/p^(k-1)," "},{k,1,Length[list]}]],".",2]]]

PadicExp2[1/10,563]

Computing p - adic Square Roots

The next command computes d terms of the “canonical” p-adic Cauchy sequences of the square roots of rational number q (if those square roots exist). The number p must be prime, the default for d is 5.

PadicSqrtCauchy[q_,p_,d_:5]:=Module[{s},s=Solve[x^2==q,Modulus->p^d];If[s=={},Print["There is no ",p,"-adic number whose square is ",q,"."],Print[PadicCauchy[x/.s[[1]],p,d]];Print[PadicCauchy[x/.s[[2]],p,d]]]]

PadicSqrtCauchy[17,19]

PadicSqrtCauchy[-1,13]

PadicSqrtCauchy[-1,17,20]

PadicSqrtCauchy[-1,7,3]

The last command computes the first d terms of the p-adic expansions of the square roots of q (if those square roots exist). The default for d is 5. p must be prime and less than 11.

PadicSqrtExp[q_,p_,d_:5]:=Module[{s},s=Solve[x^2==q,Modulus->p^d];If[s=={},Print["There is no ",p,"-adic number whose square is ",q,"."],PadicExp[x/.s[[1]],p,d];PadicExp[x/.s[[2]],p,d]]]

PadicSqrtExp[2,7]

PadicSqrtExp[-1,5,15]