diff --git a/Project.toml b/Project.toml index 1a1bbfb..d08c52e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,20 +1,24 @@ name = "SemialgebraicSets" uuid = "8e049039-38e8-557d-ae3a-bc521ccf6204" repo = "https://github.com/JuliaAlgebra/SemialgebraicSets.jl.git" -version = "0.2.3" +version = "0.2.4" [deps] +DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MultivariatePolynomials = "102ac46a-7ee4-5c85-9060-abc95bfdeaa3" +MutableArithmetics = "d8a4904e-b15c-11e9-3269-09a3773c0cb0" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" +TypedPolynomials = "afbbf031-7a57-5f58-a1b9-b774a0fad08d" [compat] -MultivariatePolynomials = "0.3" +MultivariatePolynomials = "0.4.2" julia = "1" [extras] DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" +TypedPolynomials = "afbbf031-7a57-5f58-a1b9-b774a0fad08d" [targets] -test = ["Test", "DynamicPolynomials"] +test = ["Test", "DynamicPolynomials", "TypedPolynomials"] diff --git a/src/SemialgebraicSets.jl b/src/SemialgebraicSets.jl index 23bebf9..1235ea2 100644 --- a/src/SemialgebraicSets.jl +++ b/src/SemialgebraicSets.jl @@ -2,6 +2,9 @@ module SemialgebraicSets using Random +import MutableArithmetics +const MA = MutableArithmetics + using MultivariatePolynomials const MP = MultivariatePolynomials diff --git a/src/basic.jl b/src/basic.jl index 327b65d..8180ea1 100644 --- a/src/basic.jl +++ b/src/basic.jl @@ -10,10 +10,10 @@ end function BasicSemialgebraicSet(V::AlgebraicSet{T, PT, A, S}, p::Vector{PT}) where {T, PT<:APL{T}, A, S<:AbstractAlgebraicSolver} BasicSemialgebraicSet{T, PT, typeof(V)}(V, p) end -function BasicSemialgebraicSet(V::AlgebraicSet{T, PT, A, ST}, p::Vector{PS}) where {T, PT<:APL{T}, S, PS<:APL{S}, A, ST<:AbstractAlgebraicSolver} - U = promote_type(T, S) - PU = promote_type(PT, PS) - BasicSemialgebraicSet(convert(AlgebraicSet{U, PU, A, ST}, V), Vector{PU}(p)) +function BasicSemialgebraicSet(V::AlgebraicSet{T, PT, A, SO, U}, p::Vector{PS}) where {T, PT<:APL{T}, S, PS<:APL{S}, A, SO<:AbstractAlgebraicSolver, U} + ST = promote_type(T, S) + PST = promote_type(PT, PS) + BasicSemialgebraicSet(convert(AlgebraicSet{ST, PST, A, SO, U}, V), Vector{PST}(p)) end #BasicSemialgebraicSet{T, PT<:APL{T}}(V::AlgebraicSet{T, PT}, p::Vector{PT}) = BasicSemialgebraicSet{T, PT}(V, p) function basicsemialgebraicset(V, p) diff --git a/src/groebner.jl b/src/groebner.jl index 4376c51..cb91b07 100644 --- a/src/groebner.jl +++ b/src/groebner.jl @@ -12,7 +12,15 @@ where ``m = \\mathrm{lcm}(\\mathrm{\\mathsc{LM}}(p), \\mathrm{\\mathsc{LM}}(q))` """ function spolynomial(p::APL, q::APL) m = lcm(leadingmonomial(p), leadingmonomial(q)) - MultivariatePolynomials._div(m, leadingterm(p)) * p - MultivariatePolynomials._div(m, leadingterm(q)) * q + ltp = leadingterm(p) + # `MA.operate` ensures that the returned value can be mutated without + # affecting either `a` or `p`. + a = MA.operate(*, MP._div(m, monomial(ltp)), p) + ad = MA.operate!!(/, a, MP.coefficient(ltp)) + ltq = leadingterm(q) + b = MA.operate(*, MP._div(m, monomial(ltq)), q) + bd = MA.operate!!(/, b, MP.coefficient(ltq)) + return MA.operate!!(-, ad, bd) end function reducebasis!(F::AbstractVector{<:APL}; kwargs...)