Skip to content

Commit b640a57

Browse files
authored
Default to exact arithmetic (#28)
* Default to exact arithmetic * Bump minor * Fix
1 parent a3afdd6 commit b640a57

File tree

7 files changed

+35
-34
lines changed

7 files changed

+35
-34
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- version: '1'
1818
os: ubuntu-latest
1919
arch: x64
20-
- version: '1.0'
20+
- version: '1.6'
2121
os: ubuntu-latest
2222
arch: x64
2323
- version: '1'

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SemialgebraicSets"
22
uuid = "8e049039-38e8-557d-ae3a-bc521ccf6204"
33
repo = "https://github.com/JuliaAlgebra/SemialgebraicSets.jl.git"
4-
version = "0.2.5"
4+
version = "0.3.0"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
@@ -12,7 +12,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
1212
[compat]
1313
MultivariatePolynomials = "0.4.2"
1414
MutableArithmetics = "0.3.1, 1"
15-
julia = "1"
15+
julia = "1.6"
1616

1717
[extras]
1818
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"

src/ideal.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ struct EmptyPolynomialIdeal <: AbstractPolynomialIdeal end
66
ideal(p::FullSpace, algo=defaultgröbnerbasisalgorithm(p)) = EmptyPolynomialIdeal()
77
Base.rem(p::AbstractPolynomialLike, I::EmptyPolynomialIdeal) = p
88

9+
promote_for_division(::Type{T}) where {T} = T
10+
promote_for_division(::Type{T}) where {T<:Integer} = Rational{big(T)}
11+
promote_for_division(::Type{Rational{T}}) where {T} = Rational{big(T)}
12+
function promote_for_division(::Type{Complex{T}}) where {T}
13+
return Complex{promote_for_division(T)}
14+
end
15+
916
mutable struct PolynomialIdeal{T, PT<:APL{T}, A<:AbstractGröbnerBasisAlgorithm} <: AbstractPolynomialIdeal
1017
p::Vector{PT}
1118
gröbnerbasis::Bool
@@ -15,7 +22,7 @@ function PolynomialIdeal{T, PT}(p::Vector{PT}, algo::A) where {T, PT<:APL{T}, A<
1522
PolynomialIdeal{T, PT, A}(p, false, algo)
1623
end
1724
function PolynomialIdeal(p::Vector{PT}, algo) where {T, PT<:APL{T}}
18-
S = Base.promote_op(/, T, T)
25+
S = promote_for_division(T)
1926
PolynomialIdeal{S, polynomialtype(PT, S)}(AbstractVector{polynomialtype(PT, S)}(p), algo)
2027
end
2128
function PolynomialIdeal{T, PT}() where {T, PT<:APL{T}}

src/schur.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,18 @@ function clusterordschur(M::AbstractMatrix{<:Real}, ɛ)
1818
# See bug JuliaLang/julia#...
1919
return Matrix{float(eltype(M))}(undef, 0, 0), Vector{Int}[]
2020
else
21-
_clusterordschur(M, ɛ)
21+
return _clusterordschur(M, ɛ)
2222
end
2323
end
24+
function _clusterordschur(M::AbstractMatrix{BigFloat}, ɛ)
25+
Z, clusters = _clusterordschur(Float64.(M), ɛ)
26+
return convert(Matrix{BigFloat}, Z), clusters
27+
end
2428
function _clusterordschur(M::AbstractMatrix{<:Real}, ɛ)
2529
# M = Z * T * Z' and "values" gives the eigenvalues
26-
if VERSION >= v"0.7-"
27-
sf = schur(M)
28-
Z = sf.Z
29-
v = sf.values
30-
else
31-
sf = schurfact(M)
32-
Z = sf[:Z]
33-
v = sf[:values]
34-
end
30+
sf = LinearAlgebra.schur(M)
31+
Z = sf.Z
32+
v = sf.values
3533
# documentation says that the error on the eigenvalues is ɛ * norm(T) / conditionnumber
3634
nT = norm(sf.T)
3735

@@ -101,5 +99,5 @@ function _clusterordschur(M::AbstractMatrix{<:Real}, ɛ)
10199
break
102100
end
103101
end
104-
Z, clusters
102+
return Z, clusters
105103
end

src/variety.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defaultalgebraicsetlibrary(p::Vector{<:APL}, solveroralgo...) = defaultalgebraic
1111
mutable struct AlgebraicSet{T, PT<:APL{T}, A, S<:AbstractAlgebraicSolver, U} <: AbstractAlgebraicSet
1212
I::PolynomialIdeal{T, PT, A}
1313
projective::Bool
14-
elements::Vector{Vector{T}}
14+
elements::Vector{Vector{U}}
1515
elementscomputed::Bool
1616
iszerodimensional::Bool
1717
solver::S

test/macro.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,24 @@ struct DummySolver <: SemialgebraicSets.AbstractAlgebraicSolver end
44
Mod.@polyvar x y
55
@test isa(FullSpace(), FullSpace)
66
V = @set x * y == 1
7-
@test V isa AlgebraicSet
7+
@test V isa AlgebraicSet{Rational{BigInt}}
88
@test_throws ArgumentError addinequality!(V, x*y)
99
@testset "Basic" begin
1010
S = @set x - y == 0 && x^2*y >= 1
1111
addequality!(S, x^2 - y)
1212
addinequality!(S, x + y - 1)
13-
# Algebraic set forces `Float64`
14-
@test S isa BasicSemialgebraicSet{Float64}
13+
# Algebraic set forces `Rational{BigInt}`
14+
@test S isa BasicSemialgebraicSet{Rational{BigInt}}
1515
@test S == basicsemialgebraicset(S.V, S.p)
16-
@test sprint(show, S) == "{ (x, y) | x - y = 0, x^2 - y = 0, x^2*y - 1.0 ≥ 0, x + y - 1.0 ≥ 0 }"
17-
@test sprint(show, MIME"text/plain"(), S) == "Basic semialgebraic Set defined by 2 equalities\n x - y = 0\n x^2 - y = 0\n2 inequalities\n x^2*y - 1.0 ≥ 0\n x + y - 1.0 ≥ 0\n"
18-
@test S.V isa AlgebraicSet{Float64}
16+
@test sprint(show, S) == "{ (x, y) | x - y = 0, x^2 - y = 0, x^2*y - 1//1 ≥ 0, x + y - 1//1 ≥ 0 }"
17+
@test sprint(show, MIME"text/plain"(), S) == "Basic semialgebraic Set defined by 2 equalities\n x - y = 0\n x^2 - y = 0\n2 inequalities\n x^2*y - 1//1 ≥ 0\n x + y - 1//1 ≥ 0\n"
18+
@test S.V isa AlgebraicSet{Rational{BigInt}}
1919
@test sprint(show, S.V) == "{ (x, y) | x - y = 0, x^2 - y = 0 }"
2020
@test sprint(show, MIME"text/plain"(), S.V) == "Algebraic Set defined by 2 equalities\n x - y = 0\n x^2 - y = 0\n"
21-
@test S === MultivariatePolynomials.changecoefficienttype(S, Float64)
22-
@test S.V === MultivariatePolynomials.changecoefficienttype(S.V, Float64)
21+
@test S === MultivariatePolynomials.changecoefficienttype(S, Rational{BigInt})
22+
@test S.V === MultivariatePolynomials.changecoefficienttype(S.V, Rational{BigInt})
2323
@test S.V.I === convert(typeof(S.V.I), S.V.I)
24-
@test BasicSemialgebraicSet{Int, polynomialtype(x, Int)}() isa BasicSemialgebraicSet{Float64, polynomialtype(x, Float64)}
24+
@test BasicSemialgebraicSet{Int, polynomialtype(x, Int)}() isa BasicSemialgebraicSet{Rational{BigInt}, polynomialtype(x, Rational{BigInt})}
2525
@test Int32(2)*x^2*y isa MultivariatePolynomials.AbstractTerm{Int32}
2626
Sf = MultivariatePolynomials.changecoefficienttype(S, Float32)
2727
@test Sf isa BasicSemialgebraicSet{Float32}
@@ -125,8 +125,8 @@ Algebraic Set defined by no equality
125125
@set(x y && x == 1 && 2 + y == x),
126126
@set(2 + y == x && x y && x == 1),
127127
@set(2 + y == x && x y && x == 1)]
128-
@test S isa BasicSemialgebraicSet{Float64}
129-
@test S.V isa AlgebraicSet{Float64}
128+
@test S isa BasicSemialgebraicSet{Rational{BigInt}}
129+
@test S.V isa AlgebraicSet{Rational{BigInt}}
130130
end
131131

132132
solver = DummySolver()
@@ -136,8 +136,8 @@ Algebraic Set defined by no equality
136136
@set(x y && x == 1 && 2 + y == x, solver),
137137
@set(2 + y == x && x y && x == 1, solver),
138138
@set(2 + y == x && x y && x == 1, solver)]
139-
@test S isa BasicSemialgebraicSet{Float64}
140-
@test S.V isa AlgebraicSet{Float64}
139+
@test S isa BasicSemialgebraicSet{Rational{BigInt}}
140+
@test S.V isa AlgebraicSet{Rational{BigInt}}
141141
@test S.V.solver === solver
142142
end
143143
end

test/solve.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ solver = ReorderedSchurMultiplicationMatricesSolver(sqrt(eps(Float64)), Mersenne
5555
Mod.@polyvar x y z
5656
V = @set x == y
5757
@test !iszerodimensional(V)
58-
@static if VERSION >= v"0.7-"
59-
@test_throws ErrorException iterate(V)
60-
else
61-
@test_throws ErrorException start(V)
62-
end
58+
@test_throws ErrorException iterate(V)
6359
@test_throws ErrorException length(V)
6460
V = @set 4x^2 == -5x && 3x^3 == 0 solver
6561
@test V.solver.solver === solver

0 commit comments

Comments
 (0)