Skip to content

Commit

Permalink
Populate Nemo p-adic integer arithmetic
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanuxem committed Feb 4, 2025
1 parent 9e36304 commit c9c0257
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 38 deletions.
10 changes: 5 additions & 5 deletions src/algebra/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -395,14 +395,14 @@ GUESSLIST= SMPEXPR FAMR2 NEWTON UFPS GOPT GUESSF1 GUESSP1\
RECOP STNSR GUESS GUESSEB GUESSINT GUESSF GUESSP GUESSPI GUESSAN

ifdef JULIA_WRAP_SO_TARGET
JULIALIST = INECF INPADICZ JARBPR JCF32 JCF32VEC JCF32MAT JCF32SMA \
JULIALIST = EXPADICZ INECF JARBPR JCF32 JCF32VEC JCF32MAT JCF32SMA \
JCF64 JCF64MAT JCF64MTF JCF64SMA JCF64VEC JCFSF JCFLOAT JCF32LA \
JCF64LA JCRING JDFRAME JDRAW JF32 JF32AF JF32VEC JF32VEC2 JF32MAT \
JF32SMAT JF64 JF64AF JF64MAT JF64MTF JF32SF JF64SF JF32SF2 JF64SF2 \
JF64SMAT JF64VEC JF64VEC2 JFLOAT JFSF JFSF2 JI64 JI64VEC JMATCAT \
JMATRIX JMFLOAT JMTYPE JOBJECT JOBAGG JOBBOOL JOBBINT JOBCF32 JOBCF64 \
JOBDICT JOBDLINK JOBF32 JOBF64 JOBI64 JOBPAIR JOBRING JOBTPLE JOBTYPE \
JPLOT JRING JF32LA JF64LA JSTRU JSYM JUF JTYPE JVECCAT JVECTOR JVECTOR2 \
JF64SMAT JF64VEC JF64VEC2 JFLOAT JFSF JFSF2 JI64 JI64VEC JMATCAT \
JMATRIX JMFLOAT JMTYPE JOBJECT JOBAGG JOBBOOL JOBBINT JOBCF32 JOBCF64 \
JOBDICT JOBDLINK JOBF32 JOBF64 JOBI64 JOBPAIR JOBRING JOBTPLE JOBTYPE \
JPLOT JRING JF32LA JF64LA JSTRU JSYM JUF JTYPE JVECCAT JVECTOR JVECTOR2 \
NACF NACFS NAN NACB NARB NCB NCF NCRING NECF NFF NFR NFRAC NPADICC \
NINT NMLP NMP NPADICZ NPF NRB NRF NRING NTYPE NULP NUP NZMOD
JULIACATLIST = JARBPR JCRING JMATCAT JMFLOAT JMTYPE JOBAGG JOBRING JOBTYPE \
Expand Down
3 changes: 2 additions & 1 deletion src/algebra/exposed.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,8 @@
(|Evalable| . EVALAB)
(|ExpressionSpace| . ES)
(|ExpressionSpace2| . ESC2)
(|ExtendedNMPAdicInteger| . EXPADICZ)
(|ExtendedNMPAdicRational| . EXPADICQ)
(|ExtensibleLinearAggregate| . ELAGG)
(|ExtensionField| . XF)
(|Field| . FIELD)
Expand Down Expand Up @@ -773,7 +775,6 @@
(|InnerNormalBasisFieldFunctions| . INBFF)
(|InnerNumericEigenPackage| . INEP)
(|InnerNumericFloatSolvePackage| . INFSP)
(|InnerPAdicInteger| . IPADICZ)
(|InnerPolySign| . INPSIGN)
(|InnerPolySum| . ISUMP)
(|InnerPrimeField| . IPF)
Expand Down
4 changes: 2 additions & 2 deletions src/algebra/jnball.spad
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ NMComplexBall() == NMAcbField(256)
++ Keywords: arbitrary precision, floating point number, real
++ Description:
++ \spadtype{NMRealField} implements arbitrary precision ball
++ arithmetic using the NM JL package.
++ arithmetic using the Nemo Julia package.
++ Reference: https://nemocas.github.io/NM.jl/stable/
NMRealField() : Exports == Implementation where
PI ==> PositiveInteger
Expand Down Expand Up @@ -890,7 +890,7 @@ NMRealField() : Exports == Implementation where
++ Keywords: arbitrary precision, floating point number, complex
++ Description:
++ \spadtype{NMComplexField} implements arbitrary precision ball
++ arithmetic using the NM JL package.
++ arithmetic using the Nemo Julia package.
++ Reference: https://nemocas.github.io/NM.jl/stable/
NMComplexField() : Exports == Implementation where
JI64 ==> JLInt64
Expand Down
4 changes: 2 additions & 2 deletions src/algebra/jnemo.spad
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ NMIntegerMod(p : PositiveInteger) : Exports == Implementation where
++ Date Created: Feb. 2024
++ Description:
++ This domain allows the manipulation of NM prime field
++ elements using the NM JL package (FLINT based).
++ elements using the Nemo Julia package (FLINT based).
++ https://flintlib.org/
NMPrimeField(p : PositiveInteger) : Exports == Implementation where
PI ==> PositiveInteger
Expand Down Expand Up @@ -644,7 +644,7 @@ NMPrimeField(p : PositiveInteger) : Exports == Implementation where
++ Date Created: Feb. 2024
++ Description:
++ This domain allows the manipulation of NM Galois field
++ of p^n elements using the NM JL package (FLINT based).
++ of p^n elements using the Nemo Julia package (FLINT based).
++ https://flintlib.org/
NMFiniteField(p : PositiveInteger, n: PositiveInteger) : Exports == Implementation where
PI ==> PositiveInteger
Expand Down
71 changes: 46 additions & 25 deletions src/algebra/jnpadic.spad
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
++ Keywords: p-adic, completion
++ Examples:
++ References:
++ Description: This is the catefory of stream-based representations of
++ Description: This is the category representations of
++ the p-adic integers.
NMPadicIntegerCategory(p) : Category == Definition where
p : NMInteger
NINT ==> NMInteger
I ==> Integer
NNI ==> NonNegativeInteger

Definition ==> Join(EuclideanDomain, CharacteristicZero) with
--digits : % -> ST I
-- ++ \spad{digits(x)} returns a stream of p-adic digits of x.
Expand Down Expand Up @@ -43,7 +42,7 @@ NMPadicIntegerCategory(p) : Category == Definition where
-- ++ \spad{root(f, a)} returns a root of the polynomial \spad{f}.
-- ++ Argument \spad{a} must be a root of \spad{f} \spad{(mod p)}.

)abbrev domain INPADICZ InnerNMPadicInteger
)abbrev domain EXPADICZ ExtendedNMPadicInteger
++ Author: Vanuxem Grégory
++ Date Created: 1 February 2025
++ Basic Operations:
Expand All @@ -56,7 +55,7 @@ NMPadicIntegerCategory(p) : Category == Definition where
++ References:
++ Description:
++ This domain implements Zp, the p-adic completion of the integers.
InnerNMPadicInteger(p : NMInteger, prec : JLInt64) : Exports == Implementation where
ExtendedNMPadicInteger(p : NMInteger, prec : JLInt64) : Exports == Implementation where
--unBalanced? : Boolean
I ==> Integer
NNI ==> NonNegativeInteger
Expand All @@ -67,15 +66,30 @@ InnerNMPadicInteger(p : NMInteger, prec : JLInt64) : Exports == Implementation w
JI64 ==> JLInt64
Exports ==> Join(NMCommutativeRing, NMPadicIntegerCategory(p)) with
"+" : (NINT, %) -> %
++ a + x is the addition of a NemoInteger and a p-adic Integer.
++ a + x is the addition of a Julia Nemo Integer
++ and a p-adic Integer.
"+" : (%, I) -> %
++ x + a is the addition of a p-adic integer and an Integer.
++ x + a is the addition of a p-adic integer
++ and an Integer.
"+" : (%, NINT) -> %
++ x is the addition of a p-adic integer and a Nemo integer.
++ x is the addition of a p-adic integer
++ and a Julia Nemo integer.
"+" : (I, %) -> %
++ a + x is the addition of an Integer and a p-adic integer.
++ For example:
++ \example{p := 1 + 2*7 + 4*7^2 + O(7,3)$NPADICZ(7)}
"+" : (%, NFINT) -> %
++ x is the addition of a p-adic integer
++ and a Julia Nemo Fraction integer.
"+" : (NFINT, %) -> %
++ x is the addition of Julia Nemo Fraction integer
++ and a p-adic integer
"*" : (%, NFINT) -> %
++ x is the multiplication of a p-adic integer
++ and a Julia Nemo Fraction integer.
"*" : (NFINT, %) -> %
++ x is the multiplication of Julia Nemo Fraction integer
++ and a p-adic integer
"*" : (NINT, %) -> %
++ a * x is the multiplication of a NemoInteger and a p-adic integer.
"*" : (I, %) -> %
Expand Down Expand Up @@ -109,8 +123,10 @@ InnerNMPadicInteger(p : NMInteger, prec : JLInt64) : Exports == Implementation w
++ padic(x) returns x as the p-adic completion of the NM Integer.
jpadic : NMFraction NMInteger -> %
++ padic(x) returns x as the p-adic completion of the NM Integer.
O : (NMInteger, NMInteger) -> %
++
O : (NMInteger, JLInt64) -> %
++ 0() creates the default Big-oh from domain parameters.
O : () -> %
++ 0() returns the default Big-oh from domain parameters.
prime : () -> NMInteger
++
precision : % -> Integer
Expand All @@ -132,12 +148,13 @@ InnerNMPadicInteger(p : NMInteger, prec : JLInt64) : Exports == Implementation w
Rep := SExpression

-- Set up the field
INPADICZP := concat(["INPADICZ", string(p), "p",string(prec)])
jlEvalString(concat([INPADICZP, "=padic_field(", getind(p), ", precision=", string(prec),")"]))
jlNMRing() == INPADICZP
INPADICZPP := concat(INPADICZP,"(")
jlObject() == jlEvalString(concat(["string(", INPADICZP,")"]))
O(p : NINT, e : NINT) == jlref(concat(["O(",INPADICZP,",", string(p),"^",string(e),")"]))
EXPADICZP := concat(["EXPADICZ", string(p), "p",string(prec)])
jlEvalString(concat([EXPADICZP, "=padic_field(", getind(p), ", precision=", string(prec),")"]))
jlNMRing() == EXPADICZP
EXPADICZPP := concat(EXPADICZP,"(")
jlObject() == jlEvalString(concat(["string(", EXPADICZP,")"]))
O(p, e) == jlref(concat(["O(",EXPADICZP,",", string(p),"^",string(e),")"]))
O() == jlref(concat(["O(",EXPADICZP,",", string(p),"^",string(prec),")"]))

unit?(a) == junbfunc("is_unit", a)
one?(a) == junbfunc("isone", a)
Expand Down Expand Up @@ -201,8 +218,8 @@ InnerNMPadicInteger(p : NMInteger, prec : JLInt64) : Exports == Implementation w
-- st := rst st
-- error "order: series has more than 1000 leading zero coefs"

0 == jlref(concat ["zero(", INPADICZP, ")"])
1 == jlref(concat ["one(", INPADICZP, ")"])
0 == jlref(concat ["zero(", EXPADICZP, ")"])
1 == jlref(concat ["one(", EXPADICZP, ")"])
a : NINT + pa : % == jbinfunc("+",a,pa)
a : Integer + pa : % == jbinfunc("+",jnint(a),pa)
a : NINT * pa : % == jbinfunc("*",a,pa)
Expand All @@ -211,24 +228,28 @@ InnerNMPadicInteger(p : NMInteger, prec : JLInt64) : Exports == Implementation w
pa : % + a : I == jbinfunc("+", pa, jnint a)
pa : % * a : NINT == jbinfunc("*", pa, a)
pa : % * a : I == jbinfunc("*", pa, jnint a)
coerce(i : Integer) == junfunc(INPADICZPP, string(i))
coerce(i : NMInteger) == junfunc(INPADICZP, i)
coerce(fi : NMFraction(NMInteger)) == junfunc(INPADICZP, fi)
jpadic(x) == jlref(concat([INPADICZPP, string(x),")"]))
jpadic(fi : NMFraction(NMInteger)) == junfunc(INPADICZP, fi)
pa : % * a : NFINT == jbinfunc("*", pa, a)
a : NFINT * pa: % == jbinfunc("*", a, pa)
pa : % + a : NFINT == jbinfunc("+", pa, a)
a : NFINT + pa: % == jbinfunc("+", a, pa)
coerce(i : Integer) == junfunc(EXPADICZPP, string(i))
coerce(i : NMInteger) == junfunc(EXPADICZP, i)
coerce(fi : NMFraction(NMInteger)) == junfunc(EXPADICZP, fi)
jpadic(x) == jlref(concat([EXPADICZPP, string(x),")"]))
jpadic(fi : NMFraction(NMInteger)) == junfunc(EXPADICZP, fi)
coerce(x) : OUT == string(x) pretend OUT

)abbrev domain NPADICZ NMPadicInteger
++ Author: Grégory Vanuxem
++ Date Created: 3 February 2025
++ Basic Operations:
++ Related Domains: InnerNMPadicInteger
++ Related Domains: ExtendedNMPadicInteger
++ Also See: NMPadicIntegerCategory
++ AMS Classifications:
++ Keywords: p-adic, completion
++ Examples:
++ References:
++ Description:
++ Stream-based implementation of Zp: p-adic numbers are represented as
++ Implementation of Zp: p-adic numbers are represented as
++ sum(i = 0.., a[i] * p^i), where the a[i] lie in 0, 1, ..., (p - 1).
NMPadicInteger(p : NMInteger) == InnerNMPadicInteger(p, 30::JLInt64)
NMPadicInteger(p : NMInteger) == ExtendedNMPadicInteger(p, 64::JLInt64)
9 changes: 6 additions & 3 deletions src/algebra/jutils.spad
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ JLStringUtilities() : Exports == Implementation where
++ jlLatex(str) returns the String corresponding to a JL
++ LaTeX expression, that is, "styled_"str_"" if your JL support it.
++ (StyledStrings official package). Convenience function.
jlString : String -> String
++ jlString(str) costructs an escaped string usable by the Julie parser.
jlRegexMatch? : (String, String) -> Boolean
++ jlRegexMatch(s, regex) checks if the regular expression matches in s.
++ jlRegexMatch?(s, regex) checks if the regular expression matches in s.
jlRegexMatch : (String, String) -> String
++ jlRegexMatch(s, regex) returns the matched regular expression in s.
jlRegexMatch : (String, String, PI) -> String
Expand Down Expand Up @@ -199,6 +201,7 @@ JLStringUtilities() : Exports == Implementation where
jlMessageStyled(mess, color) ==
jlEvalString(concat ["printstyled(" "_"\n ", mess,
"\n_";color=", string(color), ")"])
jlString(str) == concat(["_"", str, "_""])
jlMessageStyled(mess) ==
jl_eval_string(concat(["println(styled_"\n ",mess,"_")"]))$Lisp

Expand Down Expand Up @@ -302,7 +305,7 @@ JLObjDynamicLinker() : Exports == Implementation where
++ Returned value is assumed to be a C type ctype
++ (or any JL supported types). For example:
++ \example{libm:= jlDlOpen "libopenlibm"}
++ \example{squareRoot:= jlDlSym(libm,jsym(sqrt))}
++ \example{squareRoot:= jlDlSym(libm,jsym(sqrt)}
++ \example{jlDlCApply(squareRoot, "Cdouble" jobject("2."), "Cdouble")}
++ \example{sinus:=jlDlSym(libm,jsym(sin))}
++ \example{jlDlCApply(sinus,"Float64"), jobject("2."), "Float64")}
Expand All @@ -327,7 +330,7 @@ JLObjDynamicLinker() : Exports == Implementation where
++ For example with GSL:
++ \example{gsl:= jlDlOpen "libgsl"}
++ \example{hypot3:= jlDlSym(gsl,jsym(gsl_hypot3))}
++ \example{jlDlCApply(hypot3,jobject("2."),jobject("7."),jobjet("9.0"))}
++ \example{jlDlCApply(hypot3,jobject("2."),jobject("7."),jobject("9.0"))}
jlDlCApply : (%, STR, JOBJ, STR, JOBJ, STR, JOBJ, STR) -> JOBJ
++ jlDlCApply(func, ctype, x, xctype, y, xctype, z, ztype) applies the
++ function pointer func to x given its JL C type (xctype) or its
Expand Down

0 comments on commit c9c0257

Please sign in to comment.