Skip to content

Commit 0df397f

Browse files
committed
minor bugfixes
1 parent f723ec8 commit 0df397f

File tree

8 files changed

+23
-9
lines changed

8 files changed

+23
-9
lines changed

src/fraction.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
# class constructors
33
Frac(::Type{R}) where R<:Ring = Frac{R}
4+
Frac(::Type{<:ZZ{R}}) where R<:Integer = QQ{R}
45
Frac(::Type{R}) where R<:Integer = QQ{R}
56

67
# construction
@@ -48,7 +49,7 @@ Frac{T}(a::Base.Rational) where T = Frac{T}(T(a.num), T(a.den), NOCHECK)
4849
Frac{T}(a::Ring) where T = Frac{T}(T(a), one(T), NOCHECK)
4950
Frac(a::T) where T<:Ring = Frac{T}(a)
5051
Frac(a::T) where T<:Integer = Frac{ZZ{T}}(a)
51-
Frac(a::Rational{T}) where T<:Integer = Frac{ZZ{T}}(a)
52+
Frac(a::Rational{T}) where T<:Integer = Frac(ZZ{T})(a)
5253
Frac{T}(a::Integer, b::Integer) where T = Frac(T(a), T(b))
5354
function Frac(a::T, b::T) where T<:UnivariatePolynomial
5455
sh = ord(a) - ord(b)

src/promoteconvert.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,5 @@ end
5050
function (G::Type{<:Ring})(a::Any)
5151
B = basetype(G)
5252
# println("G = $G $(isconcretetype(G)) B = $B $(isconcretetype(B))")
53-
isconcretetype(B) && !(a isa B) ? G(convert(B, a)) : throw(MethodError(G, Ref(a)))
53+
isconcretetype(B) && !(a isa B) ? G(convert(B, a)) : throw(MethodError(G, (a,)))
5454
end

src/rationalcanonical.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,19 @@ Calculate the minimal polynomial `m_A` of a square matrix `A` over a ring.
7676
`m_A` is the minimum degree monic polynomial with `m_A(A) == 0`.
7777
"""
7878
function minimal_polynomial(A::AbstractMatrix{R}) where R<:Ring
79-
_minimal_polynomial(A)[1]
79+
minimal_polynomial(A, category_trait(R))
80+
end
81+
82+
function minimal_polynomial(A::AbstractMatrix{R}, ::Type{<:IntegralDomainTrait}) where R
83+
ma = minimal_polynomial(Frac(R).(A))
84+
UnivariatePolynomial{R}(ma)
8085
end
8186

87+
function minimal_polynomial(A::AbstractMatrix{R}, ::Type{<:FieldTrait}) where R
88+
_minimal_polynomial(A)[1]
89+
end
8290
# Implementation - also return a generating vector of stable space
83-
function _minimal_polynomial(A::AbstractMatrix{R}) where R<:Ring
91+
function _minimal_polynomial(A::AbstractMatrix{R}) where R
8492
n = checksquare(A)
8593
u = zeros(R, n)
8694
v = zeros(R, n)

src/univarpolynom.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ promote_rule(::Type{UnivariatePolynomial{R,X}}, ::Type{S}) where {X,R,S<:Rationa
103103
UnivariatePolynomial{promote_type(R, S),X}
104104

105105
(P::Type{<:UnivariatePolynomial{S}})(a::S) where {S} = P([a])
106+
function (P::Type{<:UnivariatePolynomial{S}})(a::UnivariatePolynomial{T,X}) where {S,T,X}
107+
UnivariatePolynomial{S,X}(a.first, S.(a.coeff), NOCHECK)
108+
end
106109
(P::Type{<:UnivariatePolynomial{S}})(a::T) where {S,T<:RingInt} = P([S(a)])
107110

108111
# convert coefficient vector to polynomial

src/zz.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function ZZ{T}(a::Union{QQ{T},Frac{ZZ{T}}}) where T
2121
a.den != 1 && throw(InexactError(:ZZ, ZZ{T}, a))
2222
ZZ(a.num)
2323
end
24-
ZZ(a::Union{QQ{T},Frac{ZZ{T}}}) where T = ZZ{T}(a)
24+
#ZZ(a::Union{QQ{T},Frac{ZZ{T}}}) where T = ZZ{T}(a)
2525
ZZ{S}(a::Union{QQ{T},Frac{ZZ{T}}}) where {S,T} = ZZ(promote_type(S,T)(a))
2626

2727
# promotion and conversion

test/enumerations.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,9 @@ end
131131
@test iroot(196, 65) == 1
132132
end
133133

134-
@testset "oftype" begin
134+
@testset "ofindex" begin
135135
P = ZZ{BigInt}[:x]
136-
A = oftype(big(10)^1000, P)
136+
A = ofindex(big(10)^1000, P)
137137
@test deg(A) > 1000
138138
end
139139

test/rationalcanonical.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ using Test
44
using CommutativeRings
55
using LinearAlgebra
66

7+
Z = ZZ{BigInt}
78
Q = QQ{BigInt}
89
#! format: off
910
tm = [
@@ -39,6 +40,7 @@ push!(tm, [A A; -A A])
3940
@test rem(characteristic_polynomial(A), ma) == 0
4041
B = CommutativeRings.axspace(A, xa, n)
4142
@test A * B == B * ca
43+
@test minimal_polynomial(Z.(A)) == ma
4244
end
4345

4446
@testset "rational normal form test $i" for (i, A) in enumerate(tm)

test/zzmod.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ end
148148
@test CommutativeRings._unsigned(big"-1") == big"-1"
149149
end
150150

151-
@testset "promotion moduli not supported" begin
151+
@testset "promotion of moduli not supported" begin
152152
a = (ZZ / 12)(5)
153153
b = (ZZ / 21)(3)
154-
@test_throws a + b isa ZZ / 3
154+
@test_throws Exception a + b isa ZZ / 3
155155
end
156156

157157
@testset "generator of ZZmod" begin

0 commit comments

Comments
 (0)