From d2b639670ee90512df447f2569a2d33365de6c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 15:41:39 +0200 Subject: [PATCH 01/19] Fix `force_coerce` --- src/AbstractAlgebra.jl | 4 ++-- src/Deprecations.jl | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/AbstractAlgebra.jl b/src/AbstractAlgebra.jl index 8c827886dc..2d43c57435 100644 --- a/src/AbstractAlgebra.jl +++ b/src/AbstractAlgebra.jl @@ -106,8 +106,8 @@ include("PrintHelper.jl") # parent(b) == a && return a # return force_coerce(a, b) # -function force_coerce(a, b, throw_error::Type{Val{T}} = Val{true}) where {T} - if throw_error === Val{true} +function force_coerce(a, b, throw_error::Val{T} = Val(true)) where {T} + if throw_error isa Val{true} error("coercion not possible") end return nothing diff --git a/src/Deprecations.jl b/src/Deprecations.jl index aa3046566a..7c73d0c644 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -40,4 +40,5 @@ end # ############################################################################### -#= currently none =# +# deprecated during 0.40.* +@deprecate force_coerce(a, b, throw_error::Type{Val{T}}) where {T} force_coerce(a, b, Val(T)) From 637f63739652e370206b90e4f225bce05ba2ba60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 15:42:12 +0200 Subject: [PATCH 02/19] Fix `force_op` --- src/AbstractAlgebra.jl | 6 +++--- src/Deprecations.jl | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/AbstractAlgebra.jl b/src/AbstractAlgebra.jl index 2d43c57435..30cfd92d98 100644 --- a/src/AbstractAlgebra.jl +++ b/src/AbstractAlgebra.jl @@ -117,15 +117,15 @@ end # a common over structure # designed(?) to be minimally invasive in AA and Nemo, but filled with # content in Hecke/Oscar -function force_op(op::Function, throw_error::Type{Val{T}}, a...) where {T} - if throw_error === Val{true} +function force_op(op::Function, throw_error::Val{T}, a...) where {T} + if throw_error isa Val{true} error("no common overstructure for the arguments found") end return false end function force_op(op::Function, a...) - return force_op(op, Val{true}, a...) + return force_op(op, Val(true), a...) end ############################################################################### diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 7c73d0c644..96ee256e5d 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -42,3 +42,4 @@ end # deprecated during 0.40.* @deprecate force_coerce(a, b, throw_error::Type{Val{T}}) where {T} force_coerce(a, b, Val(T)) +@deprecate force_op(op::Function, throw_error::Type{Val{T}}, a...) where {T} force_op(op, Val(T), a...) From 7e89d3af09136064bf6094e52d6519b521ace547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 15:42:56 +0200 Subject: [PATCH 03/19] Fix `_hnf_minors!` --- src/Deprecations.jl | 1 + src/Matrix.jl | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 96ee256e5d..2da633c1fc 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -43,3 +43,4 @@ end # deprecated during 0.40.* @deprecate force_coerce(a, b, throw_error::Type{Val{T}}) where {T} force_coerce(a, b, Val(T)) @deprecate force_op(op::Function, throw_error::Type{Val{T}}, a...) where {T} force_op(op, Val(T), a...) +@deprecate _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{Val{S}}) where {T <: RingElement, S} _hnf_minors!(H, U, Val(S)) diff --git a/src/Matrix.jl b/src/Matrix.jl index 0eba74ea38..9ce57835ab 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -4462,7 +4462,7 @@ Kannan-Bachem. The input must have full column rank. """ function hnf_minors(A::MatrixElem{T}) where {T <: RingElement} H = deepcopy(A) - _hnf_minors!(H, similar(A, 0, 0), Val{false}) + _hnf_minors!(H, similar(A, 0, 0), Val(false)) return H end @@ -4476,11 +4476,11 @@ have full column rank. function hnf_minors_with_transform(A::MatrixElem{T}) where {T <: RingElement} H = deepcopy(A) U = similar(A, nrows(A), nrows(A)) - _hnf_minors!(H, U, Val{true}) + _hnf_minors!(H, U, Val(true)) return H, U end -function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{Val{S}} = Val{false}) where {T <: RingElement, S} +function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, ::Val{with_transform} = Val(false)) where {T <: RingElement, with_transform} m = nrows(H) n = ncols(H) @@ -4489,9 +4489,7 @@ function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{V R = base_ring(H) - with_trafo = with_transform == Val{true} ? true : false - - if with_trafo + if with_transform for i in 1:m for j in 1:m if j == i @@ -4546,7 +4544,7 @@ function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{V t = mul!(t, q, H[j, j2]) H[k, j2] = add!(H[k, j2], H[k, j2], t) end - if with_trafo + if with_transform for j2 in 1:m t = mul!(t, q, U[j, j2]) U[k, j2] = add!(U[k, j2], U[k, j2], t) @@ -4572,7 +4570,7 @@ function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{V H[k, j2] = reduce!(H[k, j2]) H[j, j2] = reduce!(H[j, j2]) end - if with_trafo + if with_transform for j2 in 1:m b = mul_red!(b, u, U[j, j2], false) t2 = mul_red!(t2, v, U[k, j2], false) @@ -4588,7 +4586,7 @@ function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{V if is_zero_entry(H, k, k) swap_rows!(H, k, l) - if with_trafo + if with_transform swap_rows!(U, k, l) end l = l - 1 @@ -4602,7 +4600,7 @@ function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{V for j in k:n H[k, j] = mul!(H[k, j], H[k, j], u) end - if with_trafo + if with_transform for j in 1:m U[k, j] = mul!(U[k, j], U[k, j], u) end @@ -4620,7 +4618,7 @@ function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{V t = mul!(t, q, H[j, j2]) H[i, j2] = add!(H[i, j2], H[i, j2], t) end - if with_trafo + if with_transform for j2 in 1:m t = mul!(t, q, U[j, j2]) U[i, j2] = add!(U[i, j2], U[i, j2], t) @@ -4658,7 +4656,7 @@ function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{V t = mul!(t, q, H[j, j2]) H[k, j2] = add!(H[k, j2], H[k, j2], t) end - if with_trafo + if with_transform for j2 in 1:m t = mul!(t, q, U[j, j2]) U[k, j2] = add!(U[k, j2], U[k, j2], t) @@ -4681,7 +4679,7 @@ function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{V H[k, j2] = reduce!(H[k, j2]) H[j, j2] = reduce!(H[j, j2]) end - if with_trafo + if with_transform for j2 in 1:m b = mul_red!(b, u, U[j, j2], false) t2 = mul_red!(t2, v, U[k, j2], false) @@ -4705,7 +4703,7 @@ function _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{V t = mul!(t, q, H[j, j2]) H[i, j2] = add!(H[i, j2], H[i, j2], t) end - if with_trafo + if with_transform for j2 in 1:m t = mul!(t, q, U[j, j2]) U[i, j2] = add!(U[i, j2], U[i, j2], t) From abf3bb3ade47e4ccc202c4e98416e4fce212e3aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 15:47:54 +0200 Subject: [PATCH 04/19] Fix `_hnf_kb` --- src/Deprecations.jl | 1 + src/Matrix.jl | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 2da633c1fc..16ded15543 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -44,3 +44,4 @@ end @deprecate force_coerce(a, b, throw_error::Type{Val{T}}) where {T} force_coerce(a, b, Val(T)) @deprecate force_op(op::Function, throw_error::Type{Val{T}}, a...) where {T} force_op(op, Val(T), a...) @deprecate _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{Val{S}}) where {T <: RingElement, S} _hnf_minors!(H, U, Val(S)) +@deprecate _hnf_kb(A, trafo::Type{Val{T}} = Val{false}) where T _hnf_kb(A, Val(T)) diff --git a/src/Matrix.jl b/src/Matrix.jl index 9ce57835ab..b010164996 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -4725,7 +4725,7 @@ Compute the upper right row Hermite normal form of $A$ using a modification of the algorithm of Kannan-Bachem. """ function hnf_kb(A::MatrixElem{T}) where {T <: RingElement} - return _hnf_kb(A, Val{false}) + return _hnf_kb(A, Val(false)) end @doc raw""" @@ -4736,13 +4736,13 @@ matrix $U$ with $UA = H$ using a modification of the algorithm of Kannan-Bachem. """ function hnf_kb_with_transform(A::MatrixElem{T}) where {T <: RingElement} - return _hnf_kb(A, Val{true}) + return _hnf_kb(A, Val(true)) end -function _hnf_kb(A, trafo::Type{Val{T}} = Val{false}) where T +function _hnf_kb(A, ::Val{with_transform} = Val(false)) where {with_transform} H = deepcopy(A) m = nrows(H) - if trafo == Val{true} + if with_transform U = identity_matrix(A, m) hnf_kb!(H, U, true) return H, U From a4cf07157558de7749423524f0af3d4eb5f33858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 15:49:58 +0200 Subject: [PATCH 05/19] Fix `_snf_kb` --- src/Deprecations.jl | 1 + src/Matrix.jl | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 16ded15543..a32bceb606 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -45,3 +45,4 @@ end @deprecate force_op(op::Function, throw_error::Type{Val{T}}, a...) where {T} force_op(op, Val(T), a...) @deprecate _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{Val{S}}) where {T <: RingElement, S} _hnf_minors!(H, U, Val(S)) @deprecate _hnf_kb(A, trafo::Type{Val{T}} = Val{false}) where T _hnf_kb(A, Val(T)) +@deprecate _snf_kb(A::MatrixElem{T}, trafo::Type{Val{V}} = Val{false}) where {V, T <: RingElement} _snf_kb(A, Val(V)) diff --git a/src/Matrix.jl b/src/Matrix.jl index b010164996..1c4f333565 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -5039,18 +5039,18 @@ function is_snf(A::MatrixElem{T}) where T <: RingElement end function snf_kb(A::MatrixElem{T}) where {T <: RingElement} - return _snf_kb(A, Val{false}) + return _snf_kb(A, Val(false)) end function snf_kb_with_transform(A::MatrixElem{T}) where {T <: RingElement} - return _snf_kb(A, Val{true}) + return _snf_kb(A, Val(true)) end -function _snf_kb(A::MatrixElem{T}, trafo::Type{Val{V}} = Val{false}) where {V, T <: RingElement} +function _snf_kb(A::MatrixElem{T}, ::Val{with_transform} = Val(false)) where {T <: RingElement, with_transform} S = deepcopy(A) m = nrows(S) n = ncols(S) - if trafo == Val{true} + if with_transform U = identity_matrix(A, m) K = identity_matrix(A, n) snf_kb!(S, U, K, true) From 0ff15e8eff5836bcd3f4b7510c56ab4bc8720acc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 15:51:51 +0200 Subject: [PATCH 06/19] Fix `_weak_popov` --- src/Deprecations.jl | 1 + src/Matrix.jl | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index a32bceb606..89dcbb89fd 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -46,3 +46,4 @@ end @deprecate _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{Val{S}}) where {T <: RingElement, S} _hnf_minors!(H, U, Val(S)) @deprecate _hnf_kb(A, trafo::Type{Val{T}} = Val{false}) where T _hnf_kb(A, Val(T)) @deprecate _snf_kb(A::MatrixElem{T}, trafo::Type{Val{V}} = Val{false}) where {V, T <: RingElement} _snf_kb(A, Val(V)) +@deprecate _weak_popov(A::MatElem{T}, trafo::Type{Val{S}} = Val{false}) where {T <: PolyRingElem, S} _weak_popov(A, Val(S)) diff --git a/src/Matrix.jl b/src/Matrix.jl index 1c4f333565..85b28fc83a 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -5273,7 +5273,7 @@ end Return the weak Popov form of $A$. """ function weak_popov(A::MatElem{T}) where {T <: PolyRingElem} - return _weak_popov(A, Val{false}) + return _weak_popov(A, Val(false)) end @doc raw""" @@ -5283,14 +5283,14 @@ Compute a tuple $(P, U)$ where $P$ is the weak Popov form of $A$ and $U$ is a transformation matrix so that $P = UA$. """ function weak_popov_with_transform(A::MatElem{T}) where {T <: PolyRingElem} - return _weak_popov(A, Val{true}) + return _weak_popov(A, Val(true)) end -function _weak_popov(A::MatElem{T}, trafo::Type{Val{S}} = Val{false}) where {T <: PolyRingElem, S} +function _weak_popov(A::MatElem{T}, ::Val{with_transform} = Val(false)) where {T <: PolyRingElem, with_transform} P = deepcopy(A) m = nrows(P) W = similar(A, 0, 0) - if trafo == Val{true} + if with_transform U = identity_matrix(A, m) weak_popov!(P, W, U, false, true) return P, U From 332baaf9e99900c01f0bf17a002e8307c56df35c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 15:54:44 +0200 Subject: [PATCH 07/19] Fix `_extended_weak_popov` --- src/Deprecations.jl | 1 + src/Matrix.jl | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 89dcbb89fd..c276bc25ee 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -47,3 +47,4 @@ end @deprecate _hnf_kb(A, trafo::Type{Val{T}} = Val{false}) where T _hnf_kb(A, Val(T)) @deprecate _snf_kb(A::MatrixElem{T}, trafo::Type{Val{V}} = Val{false}) where {V, T <: RingElement} _snf_kb(A, Val(V)) @deprecate _weak_popov(A::MatElem{T}, trafo::Type{Val{S}} = Val{false}) where {T <: PolyRingElem, S} _weak_popov(A, Val(S)) +@deprecate _extended_weak_popov(A::MatElem{T}, V::MatElem{T}, trafo::Type{Val{S}} = Val{false}) where {T <: PolyRingElem, S} _extended_weak_popov(A, V, Val(S)) diff --git a/src/Matrix.jl b/src/Matrix.jl index 85b28fc83a..88facfb629 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -5309,7 +5309,7 @@ on $A$ and a vector $W$ by applying the same transformations on the vector $V$. Return the tuple $(P, W)$. """ function extended_weak_popov(A::MatElem{T}, V::MatElem{T}) where {T <: PolyRingElem} - return _extended_weak_popov(A, V, Val{false}) + return _extended_weak_popov(A, V, Val(false)) end @doc raw""" @@ -5321,15 +5321,15 @@ and a transformation matrix $U$ so that $P = UA$. Return the tuple $(P, W, U)$. """ function extended_weak_popov_with_transform(A::MatElem{T}, V::MatElem{T}) where {T <: PolyRingElem} - return _extended_weak_popov(A, V, Val{true}) + return _extended_weak_popov(A, V, Val(true)) end -function _extended_weak_popov(A::MatElem{T}, V::MatElem{T}, trafo::Type{Val{S}} = Val{false}) where {T <: PolyRingElem, S} +function _extended_weak_popov(A::MatElem{T}, V::MatElem{T}, ::Val{with_transform} = Val(false)) where {T <: PolyRingElem, with_transform} @assert nrows(V) == nrows(A) && ncols(V) == 1 P = deepcopy(A) W = deepcopy(V) m = nrows(P) - if trafo == Val{true} + if with_transform U = identity_matrix(A) weak_popov!(P, W, U, true, true) return P, W, U From 498c7c81245e7f5052fbc418b5334fc18fc01bef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:02:49 +0200 Subject: [PATCH 08/19] Fix `_popov` --- src/Deprecations.jl | 9 +++++---- src/Matrix.jl | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index c276bc25ee..998ec65e7d 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -44,7 +44,8 @@ end @deprecate force_coerce(a, b, throw_error::Type{Val{T}}) where {T} force_coerce(a, b, Val(T)) @deprecate force_op(op::Function, throw_error::Type{Val{T}}, a...) where {T} force_op(op, Val(T), a...) @deprecate _hnf_minors!(H::MatrixElem{T}, U::MatrixElem{T}, with_transform::Type{Val{S}}) where {T <: RingElement, S} _hnf_minors!(H, U, Val(S)) -@deprecate _hnf_kb(A, trafo::Type{Val{T}} = Val{false}) where T _hnf_kb(A, Val(T)) -@deprecate _snf_kb(A::MatrixElem{T}, trafo::Type{Val{V}} = Val{false}) where {V, T <: RingElement} _snf_kb(A, Val(V)) -@deprecate _weak_popov(A::MatElem{T}, trafo::Type{Val{S}} = Val{false}) where {T <: PolyRingElem, S} _weak_popov(A, Val(S)) -@deprecate _extended_weak_popov(A::MatElem{T}, V::MatElem{T}, trafo::Type{Val{S}} = Val{false}) where {T <: PolyRingElem, S} _extended_weak_popov(A, V, Val(S)) +@deprecate _hnf_kb(A, trafo::Type{Val{T}}) where T _hnf_kb(A, Val(T)) +@deprecate _snf_kb(A::MatrixElem{T}, trafo::Type{Val{V}}) where {V, T <: RingElement} _snf_kb(A, Val(V)) +@deprecate _weak_popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _weak_popov(A, Val(S)) +@deprecate _extended_weak_popov(A::MatElem{T}, V::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _extended_weak_popov(A, V, Val(S)) +@deprecate _popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _popov(A, Val(S)) diff --git a/src/Matrix.jl b/src/Matrix.jl index 88facfb629..4fb915aee6 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -5545,7 +5545,7 @@ end Return the Popov form of $A$. """ function popov(A::MatElem{T}) where {T <: PolyRingElem} - return _popov(A, Val{false}) + return _popov(A, Val(false)) end @doc raw""" @@ -5555,13 +5555,13 @@ Compute a tuple $(P, U)$ where $P$ is the Popov form of $A$ and $U$ is a transformation matrix so that $P = UA$. """ function popov_with_transform(A::MatElem{T}) where {T <: PolyRingElem} - return _popov(A, Val{true}) + return _popov(A, Val(true)) end -function _popov(A::MatElem{T}, trafo::Type{Val{S}} = Val{false}) where {T <: PolyRingElem, S} +function _popov(A::MatElem{T}, ::Val{with_transform} = Val(false)) where {T <: PolyRingElem, with_transform} P = deepcopy(A) m = nrows(P) - if trafo == Val{true} + if with_transform U = identity_matrix(A, m) popov!(P, U, true) return P, U From eed3011b4a4b3172d4b804d88914e39d957ed5d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:05:07 +0200 Subject: [PATCH 09/19] Fix `_hnf_via_popov` --- src/Deprecations.jl | 3 ++- src/Matrix.jl | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 998ec65e7d..6d5f6de27e 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -48,4 +48,5 @@ end @deprecate _snf_kb(A::MatrixElem{T}, trafo::Type{Val{V}}) where {V, T <: RingElement} _snf_kb(A, Val(V)) @deprecate _weak_popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _weak_popov(A, Val(S)) @deprecate _extended_weak_popov(A::MatElem{T}, V::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _extended_weak_popov(A, V, Val(S)) -@deprecate _popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _popov(A, Val(S)) +@deprecate _popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _popov(A, Val(S)) +@deprecate _hnf_via_popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _hnf_via_popov(A, Val(S)) diff --git a/src/Matrix.jl b/src/Matrix.jl index 4fb915aee6..b533554bd6 100644 --- a/src/Matrix.jl +++ b/src/Matrix.jl @@ -5686,17 +5686,17 @@ function popov!(P::MatElem{T}, U::MatElem{T}, with_trafo::Bool = false) where {T end function hnf_via_popov(A::MatElem{T}) where {T <: PolyRingElem} - return _hnf_via_popov(A, Val{false}) + return _hnf_via_popov(A, Val(false)) end function hnf_via_popov_with_transform(A::MatElem{T}) where {T <: PolyRingElem} - return _hnf_via_popov(A, Val{true}) + return _hnf_via_popov(A, Val(true)) end -function _hnf_via_popov(A::MatElem{T}, trafo::Type{Val{S}} = Val{false}) where {T <: PolyRingElem, S} +function _hnf_via_popov(A::MatElem{T}, ::Val{with_transform} = Val(false)) where {T <: PolyRingElem, with_transform} H = deepcopy(A) m = nrows(H) - if trafo == Val{true} + if with_transform U = identity_matrix(A, m) hnf_via_popov!(H, U, true) return H, U From 421423054202da19c1cf2b9946dbed9b78bf3311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:13:08 +0200 Subject: [PATCH 10/19] Add some inference tests to matrix functions --- test/generic/MatRing-test.jl | 24 ++++++------- test/generic/Matrix-test.jl | 70 ++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/test/generic/MatRing-test.jl b/test/generic/MatRing-test.jl index 05dadcaa38..ba95c0243c 100644 --- a/test/generic/MatRing-test.jl +++ b/test/generic/MatRing-test.jl @@ -1339,10 +1339,10 @@ if false # see bug 160 A = M(map(R, Any[0 0 0; x^3+1 x^2 0; 0 x^2 x^5])) - H = hnf_minors(A) + H = @inferred hnf_minors(A) @test is_upper_triangular(H) - H, U = hnf_minors_with_transform(A) + H, U = @inferred hnf_minors_with_transform(A) @test is_upper_triangular(H) @test is_unit(det(U)) @test U*A == H @@ -1358,10 +1358,10 @@ if false # see bug 160 B = N(map(S, Any[1 0 a 0; a*y^3 0 3*a^2 0; y^4+a 0 y^2+y 5; y 1 y 2])) - H = hnf_minors(B) + H = @inferred hnf_minors(B) @test is_upper_triangular(H) - H, U = hnf_minors_with_transform(B) + H, U = @inferred hnf_minors_with_transform(B) @test is_upper_triangular(H) @test is_unit(det(U)) @test U*B == H @@ -1375,10 +1375,10 @@ end A = M(map(R, Any[0 0 0; x^3+1 x^2 0; 0 x^2 x^5])) - H = AbstractAlgebra.hnf_kb(A) + H = @inferred AbstractAlgebra.hnf_kb(A) @test is_upper_triangular(H) - H, U = AbstractAlgebra.hnf_kb_with_transform(A) + H, U = @inferred AbstractAlgebra.hnf_kb_with_transform(A) @test is_upper_triangular(H) @test is_unit(det(U)) @test U*A == H @@ -1394,10 +1394,10 @@ end B = N(map(S, Any[1 0 a; a*y^3 0 3*a^2; y^4+a 0 y^2+y])) - H = AbstractAlgebra.hnf_kb(B) + H = @inferred AbstractAlgebra.hnf_kb(B) @test is_upper_triangular(H) - H, U = AbstractAlgebra.hnf_kb_with_transform(B) + H, U = @inferred AbstractAlgebra.hnf_kb_with_transform(B) @test is_upper_triangular(H) @test is_unit(det(U)) @test U*B == H @@ -1480,10 +1480,10 @@ end A = M(map(R, Any[0 0 0; x^3+1 x^2 0; 0 x^2 x^5])) - T = AbstractAlgebra.snf_kb(A) + T = @inferred AbstractAlgebra.snf_kb(A) @test is_snf(T) - T, U, K = AbstractAlgebra.snf_kb_with_transform(A) + T, U, K = @inferred AbstractAlgebra.snf_kb_with_transform(A) @test is_snf(T) @test is_unit(det(U)) @test is_unit(det(K)) @@ -1500,10 +1500,10 @@ end B = N(map(S, Any[1 0 a; a*y^3 0 3*a^2; y^4+a 0 y^2+y])) - T = AbstractAlgebra.snf_kb(B) + T = @inferred AbstractAlgebra.snf_kb(B) @test is_snf(T) - T, U, K = AbstractAlgebra.snf_kb_with_transform(B) + T, U, K = @inferred AbstractAlgebra.snf_kb_with_transform(B) @test is_snf(T) @test is_unit(det(U)) @test is_unit(det(K)) diff --git a/test/generic/Matrix-test.jl b/test/generic/Matrix-test.jl index 81ecda2d73..510a84daa8 100644 --- a/test/generic/Matrix-test.jl +++ b/test/generic/Matrix-test.jl @@ -3584,10 +3584,10 @@ end A = M(map(R, Any[0 0 0; x^3+1 x^2 0; 0 x^2 x^5; x^4+1 x^2 x^5+x^3])) - H = hnf_minors(A) + H = @inferred hnf_minors(A) @test is_hnf(H) - H, U = hnf_minors_with_transform(A) + H, U = @inferred hnf_minors_with_transform(A) @test is_hnf(H) @test is_unit(det(U)) @test U*A == H @@ -3603,10 +3603,10 @@ end B = N(map(S, Any[1 0 a 0; a*y^3 0 3*a^2 0; y^4+a 0 y^2+y 5; y 1 y 2])) - H = hnf_minors(B) + H = @inferred hnf_minors(B) @test is_hnf(H) - H, U = hnf_minors_with_transform(B) + H, U = @inferred hnf_minors_with_transform(B) @test is_hnf(H) @test is_unit(det(U)) @test U*B == H @@ -3615,7 +3615,7 @@ end @testset "Generic.Mat.hnf_kb" begin M = matrix(ZZ, BigInt[4 6 2; 0 0 10; 0 5 3]) - H, U = AbstractAlgebra.hnf_kb_with_transform(M) + H, U = @inferred AbstractAlgebra.hnf_kb_with_transform(M) @test H == matrix(ZZ, BigInt[4 1 9; 0 5 3; 0 0 10]) @test is_unit(det(U)) @@ -3627,10 +3627,10 @@ end A = M(map(R, Any[0 0 0; x^3+1 x^2 0; 0 x^2 x^5; x^4+1 x^2 x^5+x^3])) - H = AbstractAlgebra.hnf_kb(A) + H = @inferred AbstractAlgebra.hnf_kb(A) @test is_hnf(H) - H, U = AbstractAlgebra.hnf_kb_with_transform(A) + H, U = @inferred AbstractAlgebra.hnf_kb_with_transform(A) @test is_hnf(H) @test is_unit(det(U)) @test U*A == H @@ -3646,10 +3646,10 @@ end B = N(map(S, Any[1 0 a 0; a*y^3 0 3*a^2 0; y^4+a 0 y^2+y 5])) - H = AbstractAlgebra.hnf_kb(B) + H = @inferred AbstractAlgebra.hnf_kb(B) @test is_hnf(H) - H, U = AbstractAlgebra.hnf_kb_with_transform(B) + H, U = @inferred AbstractAlgebra.hnf_kb_with_transform(B) @test is_hnf(H) @test is_unit(det(U)) @test U*B == H @@ -3755,10 +3755,10 @@ end A = M(map(R, Any[0 0 0; x^3+1 x^2 0; 0 x^2 x^5; x^4+1 x^2 x^5+x^3])) - T = AbstractAlgebra.snf_kb(A) + T = @inferred AbstractAlgebra.snf_kb(A) @test is_snf(T) - T, U, K = AbstractAlgebra.snf_kb_with_transform(A) + T, U, K = @inferred AbstractAlgebra.snf_kb_with_transform(A) @test is_snf(T) @test is_unit(det(U)) @test is_unit(det(K)) @@ -3775,10 +3775,10 @@ end B = N(map(S, Any[1 0 a 0; a*y^3 0 3*a^2 0; y^4+a 0 y^2+y 5])) - T = AbstractAlgebra.snf_kb(B) + T = @inferred AbstractAlgebra.snf_kb(B) @test is_snf(T) - T, U, K = AbstractAlgebra.snf_kb_with_transform(B) + T, U, K = @inferred AbstractAlgebra.snf_kb_with_transform(B) @test is_snf(T) @test is_unit(det(U)) @test is_unit(det(K)) @@ -3851,10 +3851,10 @@ end A = matrix(R, map(R, Any[1 2 3 x; x 2*x 3*x x^2; x x^2+1 x^3+x^2 x^4+x^2+1])) r = 2 # == rank(A) - P = weak_popov(A) + P = @inferred weak_popov(A) @test is_weak_popov(P, r) - P, U = weak_popov_with_transform(A) + P, U = @inferred weak_popov_with_transform(A) @test is_weak_popov(P, r) @test U*A == P @test is_unit(det(U)) @@ -3866,10 +3866,10 @@ end B = matrix(S, map(S, Any[ 4*y^2+3*y+5 4*y^2+3*y+4 6*y^2+1; 3*y+6 3*y+5 y+3; 6*y^2+4*y+2 6*y^2 2*y^2+y])) s = 2 # == rank(B) - P = weak_popov(B) + P = @inferred weak_popov(B) @test is_weak_popov(P, s) - P, U = weak_popov_with_transform(B) + P, U = @inferred weak_popov_with_transform(B) @test is_weak_popov(P, s) @test U*B == P @test is_unit(det(U)) @@ -3880,10 +3880,10 @@ end M = matrix_space(polynomial_ring(QQ, "x")[1], rand(1:5), rand(1:5)) A = rand(M, -1:5, -5:5) r = rank(A) - P = weak_popov(A) + P = @inferred weak_popov(A) @test is_weak_popov(P, r) - P, U = weak_popov_with_transform(A) + P, U = @inferred weak_popov_with_transform(A) @test is_weak_popov(P, r) @test U*A == P @test is_unit(det(U)) @@ -3896,10 +3896,10 @@ end for i in 1:2 A = rand(M, 1:5) r = rank(A) - P = weak_popov(A) + P = @inferred weak_popov(A) @test is_weak_popov(P, r) - P, U = weak_popov_with_transform(A) + P, U = @inferred weak_popov_with_transform(A) @test is_weak_popov(P, r) @test U*A == P @test is_unit(det(U)) @@ -3912,10 +3912,10 @@ end for i in 1:2 A = rand(M, -1:5, 0:100) r = rank(A) - P = weak_popov(A) + P = @inferred weak_popov(A) @test is_weak_popov(P, r) - P, U = weak_popov_with_transform(A) + P, U = @inferred weak_popov_with_transform(A) @test is_weak_popov(P, r) @test U*A == P @test is_unit(det(U)) @@ -3928,20 +3928,20 @@ end A = matrix(R, map(R, Any[1 2 3 x; x 2*x 3*x x^2; x x^2+1 x^3+x^2 x^4+x^2+1])) r = 2 # == rank(A) - P = popov(A) + P = @inferred popov(A) @test is_popov(P, r) - P, U = popov_with_transform(A) + P, U = @inferred popov_with_transform(A) @test is_popov(P, r) @test U*A == P @test is_unit(det(U)) A = matrix(R, 3, 3, [ x^4, 0, 0, x^3, x^4, x^3, x^3, x^5, x^5 ]) r = 3 # == rank(A) - P = popov(A) + P = @inferred popov(A) @test is_popov(P, r) - P, U = popov_with_transform(A) + P, U = @inferred popov_with_transform(A) @test is_popov(P, r) @test U*A == P @test is_unit(det(U)) @@ -3953,10 +3953,10 @@ end B = matrix(S, map(S, Any[ 4*y^2+3*y+5 4*y^2+3*y+4 6*y^2+1; 3*y+6 3*y+5 y+3; 6*y^2+4*y+2 6*y^2 2*y^2+y])) s = 2 # == rank(B) - P = popov(B) + P = @inferred popov(B) @test is_popov(P, s) - P, U = popov_with_transform(B) + P, U = @inferred popov_with_transform(B) @test is_popov(P, s) @test U*B == P @test is_unit(det(U)) @@ -3967,10 +3967,10 @@ end M = matrix_space(polynomial_ring(QQ, "x")[1], rand(1:5), rand(1:5)) A = rand(M, -1:5, -5:5) r = rank(A) - P = popov(A) + P = @inferred popov(A) @test is_popov(P, r) - P, U = popov_with_transform(A) + P, U = @inferred popov_with_transform(A) @test is_popov(P, r) @test U*A == P @test is_unit(det(U)) @@ -3983,10 +3983,10 @@ end for i in 1:2 A = rand(M, 1:5) r = rank(A) - P = popov(A) + P = @inferred popov(A) @test is_popov(P, r) - P, U = popov_with_transform(A) + P, U = @inferred popov_with_transform(A) @test is_popov(P, r) @test U*A == P @test is_unit(det(U)) @@ -3999,10 +3999,10 @@ end for i in 1:2 A = rand(M, -1:5, 0:100) r = rank(A) - P = popov(A) + P = @inferred popov(A) @test is_popov(P, r) - P, U = popov_with_transform(A) + P, U = @inferred popov_with_transform(A) @test is_popov(P, r) @test U*A == P @test is_unit(det(U)) From 07e94862936b85e1a3703b0418984531ad5e603a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:17:44 +0200 Subject: [PATCH 11/19] Fix `gen` --- src/Deprecations.jl | 1 + src/generic/MPoly.jl | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 6d5f6de27e..cb6001bc0b 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -50,3 +50,4 @@ end @deprecate _extended_weak_popov(A::MatElem{T}, V::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _extended_weak_popov(A, V, Val(S)) @deprecate _popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _popov(A, Val(S)) @deprecate _hnf_via_popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _hnf_via_popov(A, Val(S)) +@deprecate gen(a::MPolyRing{T}, i::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} gen(a, i, Val(ord)) diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index ef798643fd..95d8400f02 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -37,21 +37,21 @@ number_of_variables(a::MPolyRing) = a.num_vars number_of_generators(a::MPolyRing) = a.num_vars -function gen(a::MPolyRing{T}, i::Int, ::Type{Val{:lex}}) where {T <: RingElement} +function gen(a::MPolyRing{T}, i::Int, ::Val{:lex}) where {T <: RingElement} n = nvars(a) @boundscheck 1 <= i <= n || throw(ArgumentError("variable index out of range")) return a([one(base_ring(a))], reshape([UInt(j == n - i + 1) for j = 1:n], n, 1)) end -function gen(a::MPolyRing{T}, i::Int, ::Type{Val{:deglex}}) where {T <: RingElement} +function gen(a::MPolyRing{T}, i::Int, ::Val{:deglex}) where {T <: RingElement} n = nvars(a) @boundscheck 1 <= i <= n || throw(ArgumentError("variable index out of range")) return a([one(base_ring(a))], reshape([[UInt(j == n - i + 1) for j in 1:n]..., UInt(1)], n + 1, 1)) end -function gen(a::MPolyRing{T}, i::Int, ::Type{Val{:degrevlex}}) where {T <: RingElement} +function gen(a::MPolyRing{T}, i::Int, ::Val{:degrevlex}) where {T <: RingElement} n = nvars(a) @boundscheck 1 <= i <= n || throw(ArgumentError("variable index out of range")) return a([one(base_ring(a))], reshape([[UInt(j == i) @@ -66,7 +66,7 @@ ring. """ function gens(a::MPolyRing{T}) where {T <: RingElement} n = a.num_vars - return elem_type(a)[gen(a, i, Val{a.ord})::elem_type(a) for i in 1:n] + return elem_type(a)[gen(a, i, Val(internal_ordering(a))) for i in 1:n] end @doc raw""" @@ -76,7 +76,7 @@ Return the $i$-th generator (variable) of the given polynomial ring. """ function gen(a::MPolyRing{T}, i::Int) where {T <: RingElement} - return gen(a, i, Val{a.ord}) + return gen(a, i, Val(a.ord)) end function vars(p::MPoly{T}) where {T <: RingElement} From 65fefcaa6e2766491e91a586136bc9847d785ee5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:34:11 +0200 Subject: [PATCH 12/19] Fix `exponent_vector` --- src/Deprecations.jl | 1 + src/generic/MPoly.jl | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index cb6001bc0b..6e3b6fadd5 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -51,3 +51,4 @@ end @deprecate _popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _popov(A, Val(S)) @deprecate _hnf_via_popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _hnf_via_popov(A, Val(S)) @deprecate gen(a::MPolyRing{T}, i::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} gen(a, i, Val(ord)) +import .Generic: exponent_vector; @deprecate exponent_vector(a::Generic.MPoly{T}, i::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} exponent_vector(a, i, Val(ord)) diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index 95d8400f02..ca55835c4b 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -125,7 +125,7 @@ end # ############################################################################### -function exponent_vector(a::MPoly{T}, i::Int, ::Type{Val{:lex}}) where T <: RingElement +function exponent_vector(a::MPoly{T}, i::Int, ::Val{:lex}) where T <: RingElement A = a.exps N = size(A, 1) return [Int(A[j, i]) for j in N:-1:1] @@ -135,7 +135,7 @@ function exponent(a::MPoly{T}, i::Int, j::Int, ::Type{Val{:lex}}) where T <: Rin return Int(a.exps[size(a.exps, 1) + 1 - j, i]) end -function exponent_vector(a::MPoly{T}, i::Int, ::Type{Val{:deglex}}) where T <: RingElement +function exponent_vector(a::MPoly{T}, i::Int, ::Val{:deglex}) where T <: RingElement A = a.exps N = size(A, 1) return [Int(A[j, i]) for j in N - 1:-1:1] @@ -145,7 +145,7 @@ function exponent(a::MPoly{T}, i::Int, j::Int, ::Type{Val{:deglex}}) where T <: return Int(a.exps[size(a.exps, 1) - j, i]) end -function exponent_vector(a::MPoly{T}, i::Int, ::Type{Val{:degrevlex}}) where T <: RingElement +function exponent_vector(a::MPoly{T}, i::Int, ::Val{:degrevlex}) where T <: RingElement A = a.exps N = size(A, 1) return [Int(A[j, i]) for j in 1:N - 1] @@ -164,7 +164,7 @@ are given in the order of the variables for the ring, as supplied when the ring was created. """ function exponent_vector(a::MPoly{T}, i::Int) where T <: RingElement - return exponent_vector(a, i, Val{parent(a).ord}) + return exponent_vector(a, i, Val(internal_ordering(parent(a)))) end @doc raw""" From b4083dc0248c1ac02ae7aaf673fbce98e051bcde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:34:21 +0200 Subject: [PATCH 13/19] Fix `exponent` --- src/Deprecations.jl | 1 + src/generic/MPoly.jl | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 6e3b6fadd5..359224ec5e 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -52,3 +52,4 @@ end @deprecate _hnf_via_popov(A::MatElem{T}, trafo::Type{Val{S}}) where {T <: PolyRingElem, S} _hnf_via_popov(A, Val(S)) @deprecate gen(a::MPolyRing{T}, i::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} gen(a, i, Val(ord)) import .Generic: exponent_vector; @deprecate exponent_vector(a::Generic.MPoly{T}, i::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} exponent_vector(a, i, Val(ord)) +import .Generic: exponent; @deprecate exponent(a::Generic.MPoly{T}, i::Int, j::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} exponent(a, i, j, Val(ord)) diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index ca55835c4b..d9d423cb9c 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -131,7 +131,7 @@ function exponent_vector(a::MPoly{T}, i::Int, ::Val{:lex}) where T <: RingElemen return [Int(A[j, i]) for j in N:-1:1] end -function exponent(a::MPoly{T}, i::Int, j::Int, ::Type{Val{:lex}}) where T <: RingElement +function exponent(a::MPoly{T}, i::Int, j::Int, ::Val{:lex}) where T <: RingElement return Int(a.exps[size(a.exps, 1) + 1 - j, i]) end @@ -141,7 +141,7 @@ function exponent_vector(a::MPoly{T}, i::Int, ::Val{:deglex}) where T <: RingEle return [Int(A[j, i]) for j in N - 1:-1:1] end -function exponent(a::MPoly{T}, i::Int, j::Int, ::Type{Val{:deglex}}) where T <: RingElement +function exponent(a::MPoly{T}, i::Int, j::Int, ::Val{:deglex}) where T <: RingElement return Int(a.exps[size(a.exps, 1) - j, i]) end @@ -151,7 +151,7 @@ function exponent_vector(a::MPoly{T}, i::Int, ::Val{:degrevlex}) where T <: Ring return [Int(A[j, i]) for j in 1:N - 1] end -function exponent(a::MPoly{T}, i::Int, j::Int, ::Type{Val{:degrevlex}}) where T <: RingElement +function exponent(a::MPoly{T}, i::Int, j::Int, ::Val{:degrevlex}) where T <: RingElement return Int(a.exps[j, i]) end @@ -175,7 +175,7 @@ Term and variable numbering begins at $1$ and variables are ordered as during the creation of the ring. """ function exponent(a::MPoly{T}, i::Int, j::Int) where T <: RingElement - return exponent(a, i, j, Val{parent(a).ord}) + return exponent(a, i, j, Val(internal_ordering(parent(a)))) end function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}, ::Type{Val{:lex}}) where T <: RingElement From 53f695cfa3aaba54792de5ae106b2040820a8ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:42:57 +0200 Subject: [PATCH 14/19] Fix `set_exponent_vector!` --- src/Deprecations.jl | 1 + src/generic/MPoly.jl | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 359224ec5e..87b6957c9c 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -53,3 +53,4 @@ end @deprecate gen(a::MPolyRing{T}, i::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} gen(a, i, Val(ord)) import .Generic: exponent_vector; @deprecate exponent_vector(a::Generic.MPoly{T}, i::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} exponent_vector(a, i, Val(ord)) import .Generic: exponent; @deprecate exponent(a::Generic.MPoly{T}, i::Int, j::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} exponent(a, i, j, Val(ord)) +import .Generic: set_exponent_vector!; @deprecate set_exponent_vector!(a::Generic.MPoly{T}, i::Int, exps::Vector{Int}, ::Type{Val{ord}}) where {T <: RingElement, ord} set_exponent_vector!(a, i, exps, Val(ord)) diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index d9d423cb9c..70ca9645f6 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -178,7 +178,7 @@ function exponent(a::MPoly{T}, i::Int, j::Int) where T <: RingElement return exponent(a, i, j, Val(internal_ordering(parent(a)))) end -function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}, ::Type{Val{:lex}}) where T <: RingElement +function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}, ::Val{:lex}) where T <: RingElement fit!(a, i) A = a.exps A[:, i] = exps[end:-1:1] @@ -188,7 +188,7 @@ function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}, ::Type{Val return a end -function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}, ::Type{Val{:deglex}}) where T <: RingElement +function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}, ::Val{:deglex}) where T <: RingElement fit!(a, i) A = a.exps A[1:end - 1, i] = exps[end:-1:1] @@ -199,7 +199,7 @@ function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}, ::Type{Val return a end -function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}, ::Type{Val{:degrevlex}}) where T <: RingElement +function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}, ::Val{:degrevlex}) where T <: RingElement fit!(a, i) A = a.exps A[1:end - 1, i] = exps @@ -218,7 +218,7 @@ correspond to the exponents of the variables in the order supplied when the ring was created. The modified polynomial is returned. """ function set_exponent_vector!(a::MPoly{T}, i::Int, exps::Vector{Int}) where T <: RingElement - return set_exponent_vector!(a, i, exps, Val{parent(a).ord}) + return set_exponent_vector!(a, i, exps, Val(internal_ordering(parent(a)))) end @doc raw""" From a3f14f85d91a72f077ffad0c9d1200727aa352a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:46:31 +0200 Subject: [PATCH 15/19] Fix `is_gen` --- src/Deprecations.jl | 1 + src/generic/MPoly.jl | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 87b6957c9c..19bd261208 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -54,3 +54,4 @@ end import .Generic: exponent_vector; @deprecate exponent_vector(a::Generic.MPoly{T}, i::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} exponent_vector(a, i, Val(ord)) import .Generic: exponent; @deprecate exponent(a::Generic.MPoly{T}, i::Int, j::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} exponent(a, i, j, Val(ord)) import .Generic: set_exponent_vector!; @deprecate set_exponent_vector!(a::Generic.MPoly{T}, i::Int, exps::Vector{Int}, ::Type{Val{ord}}) where {T <: RingElement, ord} set_exponent_vector!(a, i, exps, Val(ord)) +import .Generic: is_gen; @deprecate is_gen(x::Generic.MPoly{T}, ::Type{Val{ord}}) where {T <: RingElement, ord} is_gen(x, Val(ord)) diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index 70ca9645f6..aceb32f958 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -596,7 +596,7 @@ function Base.hash(x::MPoly{T}, h::UInt) where {T <: RingElement} return b end -function is_gen(x::MPoly{T}, ::Type{Val{:lex}}) where {T <: RingElement} +function is_gen(x::MPoly{T}, ::Val{:lex}) where {T <: RingElement} exps = x.exps N = size(exps, 1) for k = 1:N @@ -616,12 +616,12 @@ function is_gen(x::MPoly{T}, ::Type{Val{:lex}}) where {T <: RingElement} return false end -function is_gen(x::MPoly{T}, ::Type{Val{:deglex}}) where {T <: RingElement} +function is_gen(x::MPoly{T}, ::Val{:deglex}) where {T <: RingElement} N = size(x.exps, 1) return x.exps[N, 1] == UInt(1) end -function is_gen(x::MPoly{T}, ::Type{Val{:degrevlex}}) where {T <: RingElement} +function is_gen(x::MPoly{T}, ::Val{:degrevlex}) where {T <: RingElement} N = size(x.exps, 1) return x.exps[N, 1] == UInt(1) end @@ -639,7 +639,7 @@ function is_gen(x::MPoly{T}) where {T <: RingElement} if !isone(coeff(x, 1)) return false end - return is_gen(x, Val{parent(x).ord}) + return is_gen(x, Val(internal_ordering(parent(x)))) end @doc raw""" From bf08607ee97138100c604dc480cade5148fb2009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:49:47 +0200 Subject: [PATCH 16/19] Fix `degree` --- src/Deprecations.jl | 1 + src/generic/MPoly.jl | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Deprecations.jl b/src/Deprecations.jl index 19bd261208..2b9ffeec3d 100644 --- a/src/Deprecations.jl +++ b/src/Deprecations.jl @@ -55,3 +55,4 @@ import .Generic: exponent_vector; @deprecate exponent_vector(a::Generic.MPoly{T} import .Generic: exponent; @deprecate exponent(a::Generic.MPoly{T}, i::Int, j::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} exponent(a, i, j, Val(ord)) import .Generic: set_exponent_vector!; @deprecate set_exponent_vector!(a::Generic.MPoly{T}, i::Int, exps::Vector{Int}, ::Type{Val{ord}}) where {T <: RingElement, ord} set_exponent_vector!(a, i, exps, Val(ord)) import .Generic: is_gen; @deprecate is_gen(x::Generic.MPoly{T}, ::Type{Val{ord}}) where {T <: RingElement, ord} is_gen(x, Val(ord)) +import .Generic: degree; @deprecate degree(f::Generic.MPoly{T}, i::Int, ::Type{Val{ord}}) where {T <: RingElement, ord} degree(f, i, Val(ord)) diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index aceb32f958..71f68ac472 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -760,7 +760,7 @@ function max_fields(f::MPoly{T}) where {T <: RingElement} return biggest, b end -function degree(f::MPoly{T}, i::Int, ::Type{Val{:lex}}) where T <: RingElement +function degree(f::MPoly{T}, i::Int, ::Val{:lex}) where T <: RingElement A = f.exps N = size(A, 1) if i == 1 @@ -777,7 +777,7 @@ function degree(f::MPoly{T}, i::Int, ::Type{Val{:lex}}) where T <: RingElement end end -function degree(f::MPoly{T}, i::Int, ::Type{Val{:deglex}}) where T <: RingElement +function degree(f::MPoly{T}, i::Int, ::Val{:deglex}) where T <: RingElement A = f.exps N = size(A, 1) biggest = -1 @@ -790,7 +790,7 @@ function degree(f::MPoly{T}, i::Int, ::Type{Val{:deglex}}) where T <: RingElemen return biggest end -function degree(f::MPoly{T}, i::Int, ::Type{Val{:degrevlex}}) where T <: RingElement +function degree(f::MPoly{T}, i::Int, ::Val{:degrevlex}) where T <: RingElement A = f.exps N = size(A, 1) biggest = -1 @@ -804,7 +804,7 @@ function degree(f::MPoly{T}, i::Int, ::Type{Val{:degrevlex}}) where T <: RingEle end function degree(f::MPoly{T}, i::Int) where T <: RingElement - return degree(f, i, Val{parent(f).ord}) + return degree(f, i, Val(internal_ordering(parent(f)))) end @doc raw""" From 907b92d805b39e3a7e8874ff7db496ed6b17cc8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Wed, 10 Apr 2024 16:54:56 +0200 Subject: [PATCH 17/19] Fix `main_variable_coefficient` --- src/generic/MPoly.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/generic/MPoly.jl b/src/generic/MPoly.jl index 71f68ac472..787b4c08a1 100644 --- a/src/generic/MPoly.jl +++ b/src/generic/MPoly.jl @@ -3670,7 +3670,7 @@ function main_variable_coefficient_lex(a::MPoly{T}, k0::Int, n::Int) where {T <: return parent(a)(Ac, Ae) end -function main_variable_coefficient(a::MPoly{T}, k::Int, n::Int, ::Type{Val{:lex}}) where {T <: RingElement} +function main_variable_coefficient(a::MPoly{T}, k::Int, n::Int, ::Val{:lex}) where {T <: RingElement} return main_variable_coefficient_lex(a, k, n) end @@ -3707,11 +3707,11 @@ function main_variable_coefficient_deglex(a::MPoly{T}, k0::Int, n::Int) where {T return parent(a)(Ac, Ae) end -function main_variable_coefficient(a::MPoly{T}, k::Int, n::Int, ::Type{Val{:deglex}}) where {T <: RingElement} +function main_variable_coefficient(a::MPoly{T}, k::Int, n::Int, ::Val{:deglex}) where {T <: RingElement} return main_variable_coefficient_deglex(a, k, n) end -function main_variable_coefficient(a::MPoly{T}, k::Int, n::Int, ::Type{Val{:degrevlex}}) where {T <: RingElement} +function main_variable_coefficient(a::MPoly{T}, k::Int, n::Int, ::Val{:degrevlex}) where {T <: RingElement} return main_variable_coefficient_deglex(a, k, n) end @@ -3737,10 +3737,10 @@ function main_variable_extract(R::SparsePolyRing, a::MPoly{T}, k::Int) where {T A = main_variable_terms(a2, k) Pe = zeros(UInt, length(A)) Pc = Vector{MPoly{T}}(undef, length(A)) - ord = parent(a).ord + ord = internal_ordering(parent(a)) for i = 1:length(A) Pe[i] = a2.exps[k, A[i]] - Pc[i] = main_variable_coefficient(a2, k, A[i], Val{ord}) + Pc[i] = main_variable_coefficient(a2, k, A[i], Val(ord)) end return R(Pc, Pe) end From 9e82859fef1b02d155865be045973eb3821f872b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 11 Apr 2024 18:00:30 +0200 Subject: [PATCH 18/19] Add transition hack --- src/AbstractAlgebra.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/AbstractAlgebra.jl b/src/AbstractAlgebra.jl index 30cfd92d98..62eb9e6b88 100644 --- a/src/AbstractAlgebra.jl +++ b/src/AbstractAlgebra.jl @@ -125,6 +125,11 @@ function force_op(op::Function, throw_error::Val{T}, a...) where {T} end function force_op(op::Function, a...) + ### TODO: remove in the next breaking release, and fix downstream packages instead + if applicable(force_op, op, Val{true}, a...) && !endswith(functionloc(force_op, (typeof(op), Type{Val{true}}, typeof.(a)...))[1], joinpath("base", "deprecated.jl")) + return force_op(op, Val{true}, a...) + end + ### return force_op(op, Val(true), a...) end From 6b2e0b75b086a6562c9b7a844ab5868316fca5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20G=C3=B6ttgens?= Date: Thu, 11 Apr 2024 18:50:11 +0200 Subject: [PATCH 19/19] Small enhancement --- src/AbstractAlgebra.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/AbstractAlgebra.jl b/src/AbstractAlgebra.jl index 62eb9e6b88..defb6f51b9 100644 --- a/src/AbstractAlgebra.jl +++ b/src/AbstractAlgebra.jl @@ -106,8 +106,8 @@ include("PrintHelper.jl") # parent(b) == a && return a # return force_coerce(a, b) # -function force_coerce(a, b, throw_error::Val{T} = Val(true)) where {T} - if throw_error isa Val{true} +function force_coerce(a, b, ::Val{throw_error} = Val(true)) where {throw_error} + if throw_error error("coercion not possible") end return nothing @@ -117,8 +117,8 @@ end # a common over structure # designed(?) to be minimally invasive in AA and Nemo, but filled with # content in Hecke/Oscar -function force_op(op::Function, throw_error::Val{T}, a...) where {T} - if throw_error isa Val{true} +function force_op(op::Function, ::Val{throw_error}, a...) where {throw_error} + if throw_error error("no common overstructure for the arguments found") end return false