Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve triu #1920

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Solve triu #1920

wants to merge 8 commits into from

Conversation

fieker
Copy link
Contributor

@fieker fieker commented Dec 3, 2024

No description provided.

but what do we want?
we have
 solve_triu       for fields            Ax = b
                      rings (this PR)   Ax = b
 solve_triu_left      rings (this PR)   xA = b
All three accept large "b", ie. can solve multiple equations in one.
However, they require "A" to be non-singular square

We also have
 can_solve_left_reduced_triu
which can deal with arbitrary matrices "A" in rref, but can only
deal with single row "b"

solve_triu for fields also has flags for the diagonal being 1

if b and A are square, this is asymptotically not optimal as it will
be a n^3/2 algo

I can add test - if we want this "interface"

Note: for triangular, one cannot transpose to reduce one case to the
      other
Note: in serious use, should also be supplemented by special
      implementations in Nemo/ Flint for nmod and/or ZZ
      and friends
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.28%. Comparing base (7a473f4) to head (89c4f1c).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1920      +/-   ##
==========================================
+ Coverage   88.17%   88.28%   +0.11%     
==========================================
  Files         120      120              
  Lines       30303    30383      +80     
==========================================
+ Hits        26719    26823     +104     
+ Misses       3584     3560      -24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@thofma
Copy link
Member

thofma commented Dec 5, 2024

With this change we end up having both

function _solve_triu(U::MatElem{T}, b::MatElem{T}, unit::Bool = false) where {T <: FieldElement}

and

function _solve_triu(U::MatElem{T}, b::MatElem{T}; side::Symbol = :left) where {T <: RingElement}

which I find a bit confusing.

julia> @which AbstractAlgebra._solve_triu(QQ[1 2; 3 4], QQ[1 2; 3 4])
_solve_triu(U::MatElem{T}, b::MatElem{T}) where T<:FieldElement
     @ AbstractAlgebra ~/bla/AbstractAlgebra.jl/src/Matrix.jl:3454

julia> @which AbstractAlgebra._solve_triu(ZZ[1 2; 3 4], ZZ[1 2; 3 4])
_solve_triu(U::MatElem{T}, b::MatElem{T}; side) where T<:RingElement
     @ AbstractAlgebra ~/bla/AbstractAlgebra.jl/src/Matrix.jl:3505

Maybe we can discuss this quickly tomorrow after the meeting.

@fieker
Copy link
Contributor Author

fieker commented Dec 6, 2024 via email

@thofma
Copy link
Member

thofma commented Dec 7, 2024

I am afraid it get's more complicated than adding units to the new functions, since the existing _solve_triu and the new _solve_triu are incompatible when it comes to the "side":

julia> A = matrix(ZZ, 2, 2, [1, 2, 0, 3]);

julia> AbstractAlgebra._solve_triu(A, matrix(ZZ, 1, 2, [1, 2]))
[1   0]

julia> AbstractAlgebra._solve_triu(QQ.(A), matrix(QQ, 1, 2, [1, 0]))
ERROR: BoundsError: attempt to access 1×2 Matrix{Rational{BigInt}} at index [2, 1]
Stacktrace:
 [1] throw_boundserror(A::Matrix{Rational{BigInt}}, I::Tuple{Int64, Int64})

julia> AbstractAlgebra._solve_triu(QQ.(A), matrix(QQ, 2,  1, [1, 0]))
[1//1]
[0//1]

Can we come up with a new name for the new methods? Then we can consider _solve_triu some relict that we will never touch again. How about _solve_upper_triangular? Or __solve_triue for maximal confusion?

@fieker
Copy link
Contributor Author

fieker commented Dec 8, 2024 via email

@fieker
Copy link
Contributor Author

fieker commented Dec 8, 2024

so, for current applications we need, apart from names,

  • upper triangular left solver over ZZ for Det
  • upper and lower triangular right solver over fields for LU (one with, one without units)

adding the unit support is trivial. The more intersting problem is if one checks, optionally, that the matrix is triangular. In my application it will be, in the LU solver it will not, so adding the assertion would trigger an error.
Currently, for ZZ there are Strassen versions for both right and left and, I think, for the tril! over fields.
Here as well: what do we want? Strassen makes a difference. Also, do we want inplace solvers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants