Skip to content

Commit 1b539c5

Browse files
committed
handle new dim property for Ideals + few simplification in dimension
1 parent e7a70fa commit 1b539c5

File tree

6 files changed

+17
-13
lines changed

6 files changed

+17
-13
lines changed

src/algorithms/dimension.jl

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ julia> dimension(I)
1818
```
1919
"""
2020
function dimension(I::Ideal{T}) where T <: MPolyRingElem
21-
21+
2222
gb = get(I.gb, 0, groebner_basis(I, complete_reduction = true))
2323
R = parent(first(gb))
24-
res = [trues(ngens(R))]
2524

25+
res = [trues(ngens(R))]
2626
lead_exps = (_drl_lead_exp).(gb)
27-
for lexp in lead_exps
27+
for lexp in lead_exps
2828
to_del = Int[]
2929
new_miss = BitVector[]
30+
nz_exps_inds = findall(!iszero, lexp)
3031
for (i, mis) in enumerate(res)
31-
nz_exps_inds = findall(e -> !iszero(e), lexp)
3232
ind_var_inds = findall(mis)
3333
if issubset(nz_exps_inds, ind_var_inds)
3434
for j in nz_exps_inds
@@ -44,10 +44,7 @@ function dimension(I::Ideal{T}) where T <: MPolyRingElem
4444
unique!(res)
4545
end
4646

47-
length(res) == 0 && return -1
48-
max_length = maximum(mis -> length(findall(mis)), res)
49-
50-
I.dim = max_length
47+
I.dim = isempty(res) ? -1 : maximum(length findall, res)
5148
return I.dim
5249
end
5350

@@ -57,6 +54,6 @@ end
5754

5855
function _drl_lead_exp(p::MPolyRingElem)
5956
exps = collect(Nemo.exponent_vectors(p))
60-
_, i = findmax((u -> _drl_exp_vector(u)).(exps))
57+
_, i = findmax(_drl_exp_vector, exps)
6158
return exps[i]
6259
end

src/algorithms/solvers.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,14 @@ function _core_msolve(
126126
if jl_dim > 0
127127
error("Dimension of ideal is greater than zero, no solutions provided.")
128128
end
129+
I.dim = 0
129130

130131
# get rational parametrization
131132
jl_len = Base.unsafe_wrap(Array, res_len[], jl_ld)
132133
nterms = 0
133134

134135
if jl_dquot == 0
136+
I.dim = -1
135137
C,x = polynomial_ring(QQ,"x")
136138
I.rat_param = RationalParametrization(Symbol[], ZZRingElem[], C(-1), C(-1), PolyRingElem[])
137139
I.real_sols = QQFieldElem[]

src/types.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727

2828
mutable struct Ideal{T <: MPolyRingElem}
2929
gens::Vector{T}
30-
dim::Int
30+
dim::Union{Int, Nothing}
3131
gb::Dict{Int, Vector{T}}
3232
inter_sols::Vector{Vector{Vector{QQFieldElem}}}
3333
real_sols::Vector{Vector{QQFieldElem}}
@@ -37,9 +37,8 @@ mutable struct Ideal{T <: MPolyRingElem}
3737
function Ideal(F::Vector{T}) where {T <: MPolyRingElem}
3838
I = new{T}()
3939
I.gens = F
40-
I.dim = -1
4140
I.gb = Dict()
42-
41+
I.dim = nothing
4342
return I
4443
end
4544
end

test/algorithms/dimension.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
R, (x,y) = polynomial_ring(QQ,["x","y"])
33
I = Ideal([x^2,x*y])
44
@test isone(dimension(I))
5+
@test isone(I.dim)
56

67
R, (x,y,z) = polynomial_ring(GF(101),["x","y","z"])
78
I = Ideal([x+2*y+2*z-1, x^2+2*y^2+2*z^2-x, 2*x*y+2*y*z-y])
89
@test iszero(dimension(I))
10+
@test iszero(I.dim)
911

1012
I = Ideal([R(1)])
1113
@test dimension(I) == -1
14+
@test I.dim == -1
1215
end

test/algorithms/groebner-bases.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
z^4 + 38*z^3 + 95*z^2 + 95*z
1717
]
1818
@test G == H
19-
19+
2020
I = Ideal([x+2*y+2*z-1, x^2+2*y^2+2*z^2-x, 2*x*y+2*y*z-y])
2121
G = groebner_basis(I, eliminate=2, intersect=false)
2222
H = MPolyRingElem[

test/algorithms/solvers.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@test inter_sols == real_solutions(I, interval=true)
2727
@test rat_sols == rational_solutions(I)
2828
@test I.real_sols == real_solutions(I)
29+
@test iszero(I.dim)
2930

3031
C, x = polynomial_ring(QQ, "x")
3132
elim = 128304*x^8 - 93312*x^7 + 15552*x^6 + 3144*x^5 - 1120*x^4 + 36*x^3 + 15*x^2 - x
@@ -55,11 +56,13 @@
5556
I = Ideal([x1^2-x2, x1*x3-x4, x2*x4-12, x4^3-x3^2])
5657
real_solutions(I)
5758
@test I.rat_param.vars == Symbol[]
59+
@test I.dim == -1
5860

5961
I = Ideal([x1^2-x2, x1*x3, x2-12])
6062
@test_throws ErrorException real_solutions(I)
6163
@test_throws ErrorException real_solutions(I, interval=true)
6264
@test_throws ErrorException rational_solutions(I)
65+
@test isnothing(I.dim)
6366

6467
R, (x, y) = polynomial_ring(QQ,["x","y"])
6568
# issue 54

0 commit comments

Comments
 (0)