Skip to content

Commit

Permalink
adjugate and pgcd fixed - coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
KlausC committed Nov 23, 2023
1 parent 6263d9c commit 329d70c
Show file tree
Hide file tree
Showing 6 changed files with 205 additions and 174 deletions.
2 changes: 1 addition & 1 deletion src/fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ end

function *(x::T, y::T) where T<:Frac
a, b, c, d = x.num, x.den, y.num, y.den
g = pgcd(a, d)
g = pgcd(a, d) # TODO call pgcd for GCD domains which are not Eucidean domains
a /= g
d /= g
g = pgcd(b, c)
Expand Down
25 changes: 21 additions & 4 deletions src/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,16 +402,33 @@ end
"""
adjugate(A::AbstractMatrix{<:Ring})
The adjugate of matrix `A`. Invariant is `det(A) * I == adjugate(A) * A == det(A) * I(n)`.
The adjugate of matrix `A`. Invariant is `adjugate(A) * A == det(A) * I`.
"""
function adjugate(A::AbstractMatrix{P}) where P
function adjugate(A::AbstractMatrix{P}) where P<:Ring
da = det(A)
if isunit(da)
_adjugate(A, da)
else
_adjugate_fallback(A)
end
end
function _adjugate(A::AbstractMatrix{P}, da) where P<:Union{Polynomial,ZZ}
Q = Frac(P)
B = Q.(A)
C = inv(B) .* Q(da)
numerator.(C)
end
function _adjugate(A::AbstractMatrix{P}, da) where P
inv(A) * da
end
function _adjugate_fallback(A::AbstractMatrix{P}) where P
PP = P[]
Q = Frac(PP)
B = Q(monom(PP)) + A
B = Q(monom(PP)) + Q.(A)
d = det(B)
C = inv(B) .* d
D = numerator.(C)
evaluate.(D, 0)
convert.(P, evaluate.(D, 0))
end

"""
Expand Down
Loading

0 comments on commit 329d70c

Please sign in to comment.