Skip to content

Commit

Permalink
Add preliminary Julia algebraic numbers support
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanuxem committed Mar 27, 2024
1 parent ba1a1fc commit 42fc743
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/algebra/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ GUESSLIST= SMPEXPR FAMR2 NEWTON UFPS GOPT GUESSF1 GUESSP1\
ifdef JULIA_WRAP_SO_TARGET
JULIALIST = JTYPE JRING JVECCAT JMATCAT JUF JSTR JSYM JF64 JCF64 JF64VEC JF64MAT JCF64VEC \
JCF64MAT JF64SMAT JCF64SMA JF64MTF JCF64MTF JF64SF JF64SF2 JDRAW JRLA JCLA \
JPLOT JI64 JI64VEC JINT JFINT JFLOAT JMP JZMOD JGF JFPRB JFPCB JRF JCF JUP
JPLOT JI64 JI64VEC JINT JFINT JFLOAT JAN JMP JZMOD JGF JFPRB JFPCB JRF JCF JUP
JULIACATLIST = JTYPE JRING JVECCAT JMATCAT
JULIACATDOMS = JRING
endif
Expand Down
1 change: 1 addition & 0 deletions src/algebra/exposed.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,7 @@
(|InnerEvalable&| . IEVALAB-)
(|IntegerNumberSystem&| . INS-)
(|IntegralDomain&| . INTDOM-)
(|JuliaAlgebraicNumber| . JAN)
(|JuliaMultivariatePolynomial&| . JMP-)
(|KeyedDictionary&| . KDAGG-)
(|LazyStreamAggregate&| . LZSTAGG-)
Expand Down
86 changes: 84 additions & 2 deletions src/algebra/jnemo.spad
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,7 @@ JuliaFloat() : Exports == Implementation where
import from JuliaFractionInteger

jlInitialize(true)



Rep := SExpression

getind(a) ==> concat(["getindex(", "refs,_"", jlrefId a, "_")"])
Expand Down Expand Up @@ -381,6 +380,89 @@ JuliaFloat() : Exports == Implementation where
jfloat(s : String) : % == jlref(concat(["BigFloat(_"", s,"_")"]))
jfloat(i : Integer) : % == jlref(concat(["BigFloat(_"", string(i),"_")"]))

)abbrev domain JAN JuliaAlgebraicNumber
++ Domain for Julia algebraic number
++ Author: G. Vanuxem
++ Date Created: March. 2023
++ Description:
++ This domain allows the manipulation of Julia algebraic numbers
++ using the Nemo package for Julia (Calcium based).
++ https://fredrikj.net/calcium/
JuliaAlgebraicNumber() : Exports == Implementation where
JI64 ==> JuliaInt64
parsei ==> parse_integer$ScanningUtilities
Exports ==> Join(JuliaRing, OrderedSet, EuclideanDomain) with
"*" : (%, Integer) -> %
coerce : JI64 -> %
coerce : % -> JI64
coerce : % -> Integer
coerce : % -> Expression Integer
coerce : % -> AlgebraicNumber
jint : Integer -> %
Implementation ==> add
import from JuliaUtilityFunctions
import from String

jlInitialize(true)

Rep := SExpression

getind(a) ==> concat(["getindex(", "refs,_"", jlId a, "_")"])
ibinop(op,a,b) ==> jlref(concat([getind(a), op, getind(b)]))
iunfunc(func,a) ==> jlref(concat([func, "(", getind(a),")"]))
ibinfunc(func,a,b) ==>
jlref(concat([func, "(", getind(a), ",", getind(b),")"]))
ibinbop(op,a,b) ==>
jl_bool_eval_string(concat([getind(a), op, getind(b)]))$Lisp


0 == jlref("zero(QQBar)")
1 == jlref("one(QQBar)")

x = y == ibinbop("==",x,y)
x ~= y == ibinbop("!=",x,y)
x < y == ibinbop("<",x,y)
x > y == ibinbop(">",x,y)
x >= y == ibinbop(">=",x,y)
x <= y == ibinbop("<=",x,y)

-- TODO: add boolean unary operator macro?
zero? x ==
jl_bool_eval_string(concat(["iszero(", getind(x),")"]))$Lisp
one? x ==
jl_bool_eval_string(concat(["isone(", getind(x),")"]))$Lisp

x + y == ibinop("+", x, y)
x - y == ibinop("-", x, y)
- x == iunfunc("-", x)
x : % * y : % == ibinop("*", x, y)
x : Integer * y : % == coerce(x) * y
x * y : Integer == jlref(concat([getind(x), "*", getind(coerce(y))]))
x : Integer * y : % == jlref(concat([getind(coerce(x)), "*", getind(y)]))

x ^ y : NonNegativeInteger ==
ibinop("^", x, coerce(y pretend Integer))
x ^ y : PositiveInteger ==
ibinop("^", x, coerce(y pretend Integer))

-- x quo y == ibinop("div", x, y)
x quo y == ibinop("÷", x, y)
x rem y == ibinop("%", x, y)
gcd(a,b) == ibinfunc("gcd",a,b)
lcm(a,b) == ibinfunc("lcm",a,b)

string(x) : String == jlValue(x)

convert(x) : String == jlValue(x)
--coerce(jsi : %): JI64 ==
-- coerce(coerce(x)@Integer)
coerce(i : Integer) ==
jlref(concat(["QQBar(",string(i),")"]))
coerce(i : %) : OutputForm == jlValue(i) pretend OutputForm
coerce(x : %) : Integer == parsei(jlValue x)
coerce(x : %) : Expression(Integer) ==
coerce(parsei(jlValue x))$Expression(Integer)
jan(i : Integer) : % == jlref(concat(["QQBar(", string(i),")"]))

)abbrev domain JZMOD JuliaIntegerMod
++ Experimental domain for Galois Fields
Expand Down

0 comments on commit 42fc743

Please sign in to comment.