[1]:

using Oscar

$\require{action}$
 -----    -----    -----      -      -----
|     |  |     |  |     |    | |    |     |
|     |  |        |         |   |   |     |
|     |   -----   |        |     |  |-----
|     |        |  |        |-----|  |   |
|     |  |     |  |     |  |     |  |    |
-----    -----    -----   -     -  -     -

...combining (and extending) ANTIC, GAP, Polymake and Singular
Version 0.5.0 ...
... which comes with absolutely no warranty whatsoever
(c) 2019-2020 by The Oscar Development Team


# Rings and ideals in OSCAR¶

## First let’s try things like with Taylor’s presentation: working directly with Singular¶

[45]:

# this is how to write a comment
# field of rational numbers in Singular
K1 = Singular.QQ

[45]:

Rational Field

[46]:

# a finite field in Singular
K2 = Singular.Fp(7)

[46]:

Finite Field of Characteristic 7

[47]:

# a multivariate polynomial ring in Singular
R1,(a,b,c,d) = Singular.PolynomialRing(K1,["a","b","c","d"], ordering=:degrevlex)

[47]:

($\text{Multivariate Polynomial Ring in 4 variables:} [a, b, c, d]\text{ over }$Rational Field, [$a$, $b$, $c$, $d$])
[48]:

typeof(R1) # so R1 is some object with type Singular.PolyRing

[48]:

Singular.PolyRing{Singular.n_Q}

[49]:

R2,(x,y,z) = Singular.PolynomialRing(K2,["x","y","z"], ordering=:degrevlex)

[49]:

($\text{Multivariate Polynomial Ring in 3 variables:} [x, y, z]\text{ over }$Finite Field of Characteristic 7, [$x$, $y$, $z$])
[50]:

# one can do arithmetics as one would expect
f = (a+b+c)^3 - a*b*c
g = a^5+13*b+7*c
h = f^2+g*f; #semicolons suppress output

[51]:

# defining ideals
J = Singular.Ideal(R1,f,h,g^4)

[51]:

Singular Ideal over Singular Polynomial Ring (QQ),(a,b,c,d),(dp(4),C) with generators (a^3+3*a^2*b+3*a*b^2+b^3+3*a^2*c+5*a*b*c+3*b^2*c+3*a*c^2+3*b*c^2+c^3, a^8+3*a^7*b+3*a^6*b^2+a^5*b^3+3*a^7*c+5*a^6*b*c+3*a^5*b^2*c+3*a^6*c^2+3*a^5*b*c^2+a^5*c^3+a^6+6*a^5*b+15*a^4*b^2+20*a^3*b^3+15*a^2*b^4+6*a*b^5+b^6+6*a^5*c+28*a^4*b*c+54*a^3*b^2*c+54*a^2*b^3*c+28*a*b^4*c+6*b^5*c+15*a^4*c^2+54*a^3*b*c^2+79*a^2*b^2*c^2+54*a*b^3*c^2+15*b^4*c^2+20*a^3*c^3+54*a^2*b*c^3+54*a*b^2*c^3+20*b^3*c^3+15*a^2*c^4+28*a*b*c^4+15*b^2*c^4+6*a*c^5+6*b*c^5+c^6+13*a^3*b+39*a^2*b^2+39*a*b^3+13*b^4+7*a^3*c+60*a^2*b*c+86*a*b^2*c+46*b^3*c+21*a^2*c^2+74*a*b*c^2+60*b^2*c^2+21*a*c^3+34*b*c^3+7*c^4, a^20+52*a^15*b+28*a^15*c+1014*a^10*b^2+1092*a^10*b*c+294*a^10*c^2+8788*a^5*b^3+14196*a^5*b^2*c+7644*a^5*b*c^2+1372*a^5*c^3+28561*b^4+61516*b^3*c+49686*b^2*c^2+17836*b*c^3+2401*c^4)

[52]:

# Let's write an ideal over the finite field
p = x^2 - x*y*z
q = x*z^3
I = Singular.Ideal(R2,p,q)

[52]:

Singular Ideal over Singular Polynomial Ring (ZZ/7),(x,y,z),(dp(3),C) with generators (-x*y*z+x^2, x*z^3)

[53]:

# We can call from the library primdec to perform a primary decomposition
##(might get some extra output first time you run it)
P = Singular.LibPrimdec.primdecGTZ(R2,I)

[53]:

2-element Array{Array{Singular.sideal{Singular.spoly{Singular.n_Zp}},1},1}:
[Singular Ideal over Singular Polynomial Ring (ZZ/7),(x,y,z),(dp(3),C) with generators (x), Singular Ideal over Singular Polynomial Ring (ZZ/7),(x,y,z),(dp(3),C) with generators (x)]
[Singular Ideal over Singular Polynomial Ring (ZZ/7),(x,y,z),(dp(3),C) with generators (z^3, -x*y*z+x^2), Singular Ideal over Singular Polynomial Ring (ZZ/7),(x,y,z),(dp(3),C) with generators (z, x)]

[11]:

Singular.ngens(I)

[11]:

$2$
[12]:

GI = Singular.std(I)

[12]:

Singular Ideal over Singular Polynomial Ring (ZZ/7),(x,y,z),(dp(3),C) with generators (x*y*z-x^2, x*z^3, x^2*z^2, x^3*z, x^4)

[13]:

Singular.ngens(GI)

[13]:

$5$
[14]:

Singular.iszerodim(I)

[14]:

false
[15]:

Singular.dimension(GI)

[15]:

$2$
[16]:

J = Singular.Ideal(R2,x^2*y+x-y+z,y^5-12,z*y^4-x^3+1)

[16]:

Singular Ideal over Singular Polynomial Ring (ZZ/7),(x,y,z),(dp(3),C) with generators (x^2*y+x-y+z, y^5+2, y^4*z-x^3+1)

[17]:

G = Singular.fglm(J,:lex)

[17]:

Singular Ideal over Singular Polynomial Ring (ZZ/7),(x,y,z),(dp(3),C) with generators (x^2-x*y+x*z+y-2*z, y^2*z-x*z^2-y*z^2-z^3+2*x*y-3*y^2-3*x*z+y*z+2*z^2+y-2*z, x*y*z-x*y+x*z+z^2+x-2*y+3*z, x*y^2-x*y-y^2+x*z+2*y*z+z^2+2*x-3*y-3*z, x*z^3+3*y*z^3+2*z^4-2*y^3+3*x*z^2+2*y*z^2+2*z^3+3*x*y-2*y^2+2*x*z-y*z-3*z^2-x+2*y-2*z-1, y^4-3*y*z^3+3*z^4-y^3-3*x*z^2+z^3+2*x*y+2*y^2+2*x*z+y*z+2*z^2+2*x+y-z-2, z^5+y*z^3+z^4-2*y^3+3*x*z^2-y*z^2-z^3-2*x*y+y*z-z^2-3*x+y+3*z+3, y*z^4+3*z^4-3*y^3+x*z^2+2*y*z^2-3*z^3+x*y-3*y^2+3*x*z-3*y*z-3*z^2+2*x-y-z)

[18]:

Singular.iszerodim(G)

[18]:

true
[19]:

Singular.vdim(G)

[19]:

$15$

## Using Oscar: So how is this implemented in Oscar?¶

[54]:

# The syntax looks similar. You do not need Singular.<function> because these
# are functions in OSCAR
T, (x,y,z) = PolynomialRing(QQ, ["x","y","z"])
p = x^2-x*y*z

[54]:

$x^{2} - xyz$
[55]:

typeof(T) #Now instead of Singular.PolynomialRing, this is an object of type FmpqMPolyRing

[55]:

FmpqMPolyRing

[56]:

I = ideal([p,x*z^3]) # square brackets [] around generators
# caveat: at present, ideals cannot be defined in the univariate polynomial ring (type issue)

[56]:

$\text{ideal generated by: }x^{2} - xyz, xz^{3}$
[57]:

typeof(I) #and an ideal is an Oscar.MPolyIdeal

[57]:

Oscar.MPolyIdeal{fmpq_mpoly}

[58]:

#Let's look a bit deeper into what I is.
#Firstly, I has fieldnames of  gens, gb, and dim
fieldnames(Oscar.MPolyIdeal)

[58]:

(:gens, :gb, :dim)
[59]:

I.gb
#Look. There's an error when trying to ask for its groebner basis,
#because this hasn't been computed yet
#If you ask for its dimension, you get -1, indicating that it has not been computed yet.

UndefRefError: access to undefined reference

Stacktrace:
[1] getproperty(::Oscar.MPolyIdeal{fmpq_mpoly}, ::Symbol) at ./Base.jl:33
[2] top-level scope at In[59]:1
[3] include_string(::Function, ::Module, ::String, ::String) at ./loading.jl:1091

[26]:

groebner_basis(I)

[26]:

[$-x^{2} + xyz$, $xz^{3}$, $x^{2}z^{2}$, $x^{3}z$, $x^{4}$]
[27]:

I.gb #The groebner basis is of type "BiPolyArray"

[27]:

Oscar.BiPolyArray{fmpq_mpoly}(fmpq_mpoly[-x^2 + x*y*z, x*z^3, x^2*z^2, x^3*z, x^4], Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (x*y*z-x^2, x*z^3, x^2*z^2, x^3*z, x^4), Multivariate Polynomial Ring in x, y, z over Rational Field, Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C))

[28]:

typeof(I.gens) # so is I.gens

[28]:

Oscar.BiPolyArray{fmpq_mpoly}

[29]:

# BiPolyArrays collect the generators and the ring of an ideal in Oscar and Singular.
# O = Oscar generators
# S = Singular generators
# Ox = Oscar ring
# Sx = Singular ring
# Ideally, you'd like to only keep track of the Oscar info, but it makes sense to actually
# keep the singular info too since we will secretly be calling singular to perform
# computations
fieldnames(typeof(I.gens))

[29]:

(:O, :S, :Ox, :Sx)
[30]:

println(I.gens.O) # print and begin new line
println(I.gens.S)
println(I.gens.Ox)
println(I.gens.Sx)

fmpq_mpoly[x^2 - x*y*z, x*z^3]
Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (-x*y*z+x^2, x*z^3)
Multivariate Polynomial Ring in x, y, z over Rational Field
Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C)

[31]:

dim(I)

[31]:

$2$
[32]:

# What if we wanted to do a primary decomp?
# Well, this is not yet a function in Oscar, but  it is in Singular (as we've seen)
# and our Oscar ideals have all the singular info in them!

[33]:

#In Singular. In the LibPrimdec library. Use the function primdecGTZ. on the Singular ring,
#  and the singular generators as arguments.
P = Singular.LibPrimdec.primdecGTZ(I.gens.Sx,I.gens.S)

[33]:

2-element Array{Array{Singular.sideal{Singular.spoly{Singular.n_Q}},1},1}:
[Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (x), Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (x)]
[Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (z^3, -x*y*z+x^2), Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (z, x)]

[34]:

# Caveat: at present, ideals in a univariate polynomial ring are not encoded
U,v = PolynomialRing(QQ,"v")
println(typeof(U)) # U has type FmpqPolyRing
println(typeof(v)) # the variable v has type fmpq_poly
println(typeof(T)) # T has type FmpqMPolyring
println(typeof(x)) # x has type fmpq_mpoly
println(typeof(I)) # ideal eats elements of type fmpq_mpoly only

FmpqPolyRing
fmpq_poly
FmpqMPolyRing
fmpq_mpoly
Oscar.MPolyIdeal{fmpq_mpoly}

[35]:

# Writing functions is easy!

[36]:

function PrimaryDecomposition(I::Oscar.MPolyIdeal)
# This is a function called PrimaryDecomposition, which takes I as an input. and
# I should be an Oscar.MPolyIdeal
P=Singular.LibPrimdec.primdecGTZ(I.gens.Sx,I.gens.S)
return(P)
end


[36]:

PrimaryDecomposition (generic function with 1 method)

[37]:

# Now we've written a simpler function for primary decomposition
PrimaryDecomposition(I)

[37]:

2-element Array{Array{Singular.sideal{Singular.spoly{Singular.n_Q}},1},1}:
[Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (x), Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (x)]
[Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (z^3, -x*y*z+x^2), Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (z, x)]


## Let’s take one such primary component¶

[38]:

J = ideal([x])
groebner_basis(J)
dim(J)

[38]:

$2$
[39]:

Singular.quotient(I.gens.S,J.gens.S)

[39]:

Singular Ideal over Singular Polynomial Ring (QQ),(x,y,z),(dp(3),C) with generators (y*z-x, z^3, x*z^2, x^2*z, x^3)


## What else has been written for Oscar ideals?¶

[40]:

methodswith(Oscar.MPolyIdeal) # this is how to find out!

[40]:

[PrimaryDecomposition(I::Oscar.MPolyIdeal) in Main at In[36]:1, base_ring(I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:530, dim(I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:515, gen(I::Oscar.MPolyIdeal, i::Int64) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:442, gens(I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:438, image(h::Oscar.MPolyHom_alg, I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:698, ngens(I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:428, preimage(h::Oscar.MPolyHom_alg, I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:702, quo(R::MPolyRing, I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:1162, *(I::Oscar.MPolyIdeal, J::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:398, +(I::Oscar.MPolyIdeal, J::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:404, -(I::Oscar.MPolyIdeal, J::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:409, ==(I::Oscar.MPolyIdeal, J::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:411, ^(I::Oscar.MPolyIdeal, j::Int64) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:417, eliminate(I::Oscar.MPolyIdeal, l::Array{var"#s73",1} where var"#s73"<:MPolyElem) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:714, eliminate(I::Oscar.MPolyIdeal, l::AbstractArray{Int64,1}) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:728, free_resolution(I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Modules/FreeModules-graded.jl:1085, groebner_basis(I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:534, groebner_basis(I::Oscar.MPolyIdeal, ord::Symbol) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:539, in(f::MPolyElem, I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:524, intersect(I::Oscar.MPolyIdeal, J::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:422, show(io::IO, ::Union{MIME{Symbol("text/latex")}, MIME{Symbol("text/html")}}, I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:333, show(io::IO, I::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:318, (::Colon)(I::Oscar.MPolyIdeal, J::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:452, issubset(I::Oscar.MPolyIdeal, J::Oscar.MPolyIdeal) in Oscar at /home/taylor/.julia/packages/Oscar/YX0cd/src/Rings/mpoly.jl:432]
[41]:

E = eliminate(I,[y]) # you can eliminate

[41]:

$\text{ideal generated by: }xz^{3}, x^{2}z^{2}, x^{3}z, x^{4}$
[42]:

intersect(E,I) == E # you can intersect and perform ideal equality tests

[42]:

true
[43]:

I:ideal([z]) # colon indicates saturation right now!

[43]:

$\text{ideal generated by: }x$