Skip to content

Commit ecaa476

Browse files
authored
use SolveCtx in inv (#2177)
* use SolveCtx in inv * better Trait for Rational{BigInt} * special case for MatRing * .. in the correct module * .. sorting name spaces * fix the F2Matrix stuff for tests
1 parent 6a52300 commit ecaa476

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

src/Matrix.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3715,7 +3715,7 @@ end
37153715

37163716
function Base.inv(M::MatrixElem{T}) where {T <: FieldElement}
37173717
is_square(M) || throw(DomainError(M, "Can not invert non-square Matrix"))
3718-
flag, A = _can_solve_with_solution_lu(M, identity_matrix(M))
3718+
flag, A = can_solve_with_solution(M, identity_matrix(M))
37193719
!flag && error("Singular matrix in inv")
37203720
return A
37213721
end

src/Solve.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ using AbstractAlgebra.PrettyPrinting: @show_name
66
using AbstractAlgebra.PrettyPrinting: Dedent
77
using AbstractAlgebra.PrettyPrinting: Indent
88
using AbstractAlgebra.PrettyPrinting: pretty
9+
import AbstractAlgebra: can_solve_with_solution
910
using AbstractAlgebra: _can_solve_with_solution_fflu
1011
using AbstractAlgebra: _can_solve_with_solution_interpolation
1112
using AbstractAlgebra: _solve_fflu_precomp
@@ -20,7 +21,6 @@ export solve
2021
export solve_init
2122
export solve_context_type
2223
export can_solve
23-
export can_solve_with_solution
2424
export can_solve_with_solution_and_kernel
2525

2626
################################################################################
@@ -97,6 +97,7 @@ function matrix_normal_form_type(R::Ring)
9797
end
9898

9999
matrix_normal_form_type(::Field) = RREFTrait()
100+
matrix_normal_form_type(::Matrix{Rational{BigInt}}) = FFLUTrait()
100101

101102
# The fflu approach is the fastest over a fraction field (see benchmarks on PR 661)
102103
matrix_normal_form_type(::FracField) = FFLUTrait()

src/fundamental_interface.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,5 @@ function _number_of_direct_product_factors end
458458
Return the homomorphism from the domain `D` into the codomain `C` defined by the data.
459459
"""
460460
function hom end
461+
462+
function can_solve_with_solution end

src/generic/MatRing.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ function _can_solve_with_solution_lu(M::MatRingElem{T}, B::MatRingElem{T}) where
5555
return flag, SA
5656
end
5757

58+
function AbstractAlgebra.can_solve_with_solution(M::MatRingElem{T}, B::MatRingElem{T}) where {T <: RingElement}
59+
check_parent(M, B)
60+
R = base_ring(M)
61+
MS = MatSpaceElem{T}(R, M.entries) # convert to ordinary matrix
62+
BS = MatSpaceElem{T}(R, B.entries)
63+
flag, S = can_solve_with_solution(MS, BS)
64+
SA = MatRingElem{T}(R, S.entries)
65+
return flag, SA
66+
end
67+
5868
function _can_solve_with_solution_fflu(M::MatRingElem{T}, B::MatRingElem{T}) where {T <: RingElement}
5969
check_parent(M, B)
6070
R = base_ring(M)

test/generic/Matrix-test.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,10 @@ struct F2Elem <: AbstractAlgebra.FieldElem
4747
end
4848

4949
(::F2)(x::F2Elem) = x
50+
(::F2)(x::Integer) = F2Elem(x % Bool)
5051
Base.:-(x::F2Elem) = x
5152
Base.:+(x::F2Elem, y::F2Elem) = F2Elem(x.x y.x)
53+
Base.:-(x::F2Elem, y::F2Elem) = F2Elem(x.x y.x)
5254
Base.inv(x::F2Elem) = x.x ? x : throw(DivideError())
5355
Base.:*(x::F2Elem, y::F2Elem) = F2Elem(x.x * y.x)
5456

@@ -60,6 +62,7 @@ AbstractAlgebra.elem_type(::Type{F2}) = F2Elem
6062
AbstractAlgebra.parent(x::F2Elem) = F2()
6163
AbstractAlgebra.mul!(x::F2Elem, y::F2Elem, z::F2Elem) = y * z
6264
AbstractAlgebra.add!(x::F2Elem, y::F2Elem) = x + y
65+
AbstractAlgebra.sub!(x::F2Elem, y::F2Elem) = x + y
6366
AbstractAlgebra.divexact(x::F2Elem, y::F2Elem) = y.x ? x : throw(DivideError())
6467

6568
Random.rand(rng::AbstractRNG, sp::Random.SamplerTrivial{F2}) = F2Elem(rand(rng, Bool))

0 commit comments

Comments
 (0)