Skip to content

Commit

Permalink
rebased code on Nemo
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamed-barakat committed Jan 5, 2025
1 parent d4cb8a0 commit c204aad
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.10'
- '1.11'
- 'nightly'
os:
- ubuntu-latest
Expand Down
6 changes: 3 additions & 3 deletions CITATION.bib
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ @misc{MatricesForHomalg.jl
author = {Mohamed Barakat <mohamed.barakat@uni-siegen.de>, Johanna Knecht <johanna.knecht@student.uni-siegen.de>},
title = {MatricesForHomalg.jl},
url = {https://github.com/homalg-project/MatricesForHomalg.jl},
version = {v0.0.1},
year = {2023},
month = {5}
version = {v0.1.0},
year = {2025},
month = {1}
}
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name = "MatricesForHomalg"
uuid = "29b9b1b6-efa6-450e-8188-a5a2c25df071"
authors = ["Mohamed Barakat <[email protected]>", "Johanna Knecht <[email protected]>"]
version = "0.0.2"
version = "0.1.0"

[deps]
AbstractAlgebra = "c3fe647b-3220-5bb0-a1ea-a7954cac585d"
Nemo = "2edaba10-b0f1-5616-af89-8c11ac63239a"

[compat]
AbstractAlgebra = "^0.30.2, 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.40, 0.41, 0.42, 0.43, 0.44"
julia = "1.9, 1.10"
Nemo = "0.48.0"
julia = "1.9, 1.10, 1.11"

[extras]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# MatricesForHomalg

[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://homalg-project.github.io/MatricesForHomalg.jl/stable/)
### Matrices for the homalg project

<!--[![Stable](https://img.shields.io/badge/docs-stable-blue.svg)](https://homalg-project.github.io/MatricesForHomalg.jl/stable/)-->
[![Dev](https://img.shields.io/badge/docs-dev-blue.svg)](https://homalg-project.github.io/MatricesForHomalg.jl/dev/)
[![Build Status](https://github.com/homalg-project/MatricesForHomalg.jl/actions/workflows/Tests.yml/badge.svg?branch=main)](https://github.com/homalg-project/MatricesForHomalg.jl/actions/workflows/Tests.yml?query=branch%3Amain)
[![Coverage](https://codecov.io/gh/homalg-project/MatricesForHomalg.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/homalg-project/MatricesForHomalg.jl)
Expand Down
112 changes: 56 additions & 56 deletions src/MatricesForHomalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ module MatricesForHomalg

import Base: getindex

import AbstractAlgebra
import AbstractAlgebra: ZZ, QQ, matrix
import Nemo
import Nemo: ZZ, QQ, matrix

export ZZ, QQ

## Constructors of homalg rings

TypeOfRingForHomalg = AbstractAlgebra.NCRing
TypeOfRingForHomalg = Nemo.NCRing

TypeOfFieldForHomalg = AbstractAlgebra.Field
TypeOfFieldForHomalg = Nemo.Field

TypeOfRingElementForHomalg = AbstractAlgebra.NCRingElement
TypeOfRingElementForHomalg = Nemo.NCRingElement

"""
HomalgRingOfIntegers()
Expand All @@ -25,11 +25,11 @@ Returns the ring of (rational) integers.
```jldoctest
julia> ring = HomalgRingOfIntegers()
Integers
Integer ring
```
"""
function HomalgRingOfIntegers()::AbstractAlgebra.Integers{BigInt}
return AbstractAlgebra.ZZ
function HomalgRingOfIntegers()::Nemo.ZZRing
return Nemo.ZZ
end

"""
Expand All @@ -39,11 +39,11 @@ Returns the field of rationals.
```jldoctest
julia> field = HomalgFieldOfRationals()
Rationals
Rational field
```
"""
function HomalgFieldOfRationals()::AbstractAlgebra.Rationals{BigInt}
return AbstractAlgebra.QQ
function HomalgFieldOfRationals()::Nemo.QQField
return Nemo.QQ
end

"""
Expand All @@ -53,31 +53,31 @@ Returns the name of the ring as a string.
```jldoctest
julia> ring = HomalgRingOfIntegers()
Integers
Integer ring
julia> RingName(ring)
"Z"
julia> field = HomalgFieldOfRationals()
Rationals
Rational field
julia> RingName(field)
"Q"
```
"""
function RingName(field_of_rationals::AbstractAlgebra.Rationals{BigInt})::String
function RingName(field_of_rationals::Nemo.QQField)::String
return "Q"
end

function RingName(ring_of_integers::AbstractAlgebra.Integers{BigInt})::String
function RingName(ring_of_integers::Nemo.ZZRing)::String
return "Z"
end

export HomalgRingOfIntegers, HomalgFieldOfRationals, RingName

## Constructors of homalg matrices

TypeOfMatrixForHomalg = AbstractAlgebra.Generic.MatSpaceElem
TypeOfMatrixForHomalg = Nemo.MatrixElem

"""
HomalgMatrix(L, r, c, R)
Expand Down Expand Up @@ -114,7 +114,7 @@ julia> mat = HomalgIdentityMatrix(3, ZZ)
```
"""
function HomalgIdentityMatrix(r, R)::TypeOfMatrixForHomalg
return AbstractAlgebra.identity_matrix(R, r)
return Nemo.identity_matrix(R, r)
end

"""
Expand All @@ -130,7 +130,7 @@ julia> mat = HomalgZeroMatrix(3, 2, ZZ)
```
"""
function HomalgZeroMatrix(r, c, R)::TypeOfMatrixForHomalg
return AbstractAlgebra.zero_matrix(R, r, c)
return Nemo.zero_matrix(R, r, c)
end

"""
Expand Down Expand Up @@ -212,7 +212,7 @@ julia> mat = HomalgDiagonalMatrix(1:5, ZZ)
```
"""
function HomalgDiagonalMatrix(diagonal_entries, R)::TypeOfMatrixForHomalg
return AbstractAlgebra.block_diagonal_matrix(map(a->HomalgMatrix([a],1,1,R), diagonal_entries))
return Nemo.block_diagonal_matrix(map(a->HomalgMatrix([a],1,1,R), diagonal_entries))
end

"""
Expand All @@ -226,18 +226,18 @@ julia> mat = HomalgMatrix([1,2,3,4,5,6], 2, 3, ZZ)
[4 5 6]
julia> QQ * mat
[1//1 2//1 3//1]
[4//1 5//1 6//1]
[1 2 3]
[4 5 6]
julia> qmat = QQ * mat
[1//1 2//1 3//1]
[4//1 5//1 6//1]
[1 2 3]
[4 5 6]
julia> ZZ * qmat == mat
true
```
"""
Base.:*(R, mat) = AbstractAlgebra.change_base_ring(R, mat)
Base.:*(R, mat) = Nemo.change_base_ring(R, mat)

export HomalgMatrix, HomalgIdentityMatrix, HomalgZeroMatrix, HomalgRowVector, HomalgColumnVector, HomalgDiagonalMatrix

Expand All @@ -259,7 +259,7 @@ true
```
"""
function IsOne(mat)::Bool
return AbstractAlgebra.isone(mat)
return NumberRows(mat) == NumberColumns(mat) && Nemo.Nemo.isone(mat) ## the precondition fixes a bug in Nemo 0.48.0
end

"""
Expand All @@ -278,7 +278,7 @@ true
```
"""
function IsZero(mat)::Bool
return AbstractAlgebra.iszero(mat)
return Nemo.iszero(mat)
end

"""
Expand Down Expand Up @@ -314,7 +314,7 @@ true
```
"""
function IsSymmetricMatrix(mat)::Bool
return AbstractAlgebra.is_symmetric(mat)
return Nemo.is_symmetric(mat)
end

export IsOne, IsZero, IsEmptyMatrix, IsSymmetricMatrix
Expand All @@ -332,18 +332,18 @@ julia> mat = HomalgMatrix(1:6, 2, 3, ZZ)
[4 5 6]
julia> HomalgRing(mat)
Integers
Integer ring
julia> mat = HomalgMatrix(1:6, 2, 3, QQ)
[1//1 2//1 3//1]
[4//1 5//1 6//1]
[1 2 3]
[4 5 6]
julia> HomalgRing(mat)
Rationals
Rational field
```
"""
function HomalgRing(mat)
return AbstractAlgebra.base_ring(mat)
return Nemo.base_ring(mat)
end

"""
Expand All @@ -361,7 +361,7 @@ julia> NumberRows(mat)
```
"""
function NumberRows(mat)::Int64
return AbstractAlgebra.nrows(mat)
return Nemo.nrows(mat)
end

"""
Expand All @@ -379,7 +379,7 @@ julia> NumberColumns(mat)
```
"""
function NumberColumns(mat)::Int64
return AbstractAlgebra.ncols(mat)
return Nemo.ncols(mat)
end

"""
Expand Down Expand Up @@ -462,21 +462,21 @@ julia> RowReducedEchelonForm(mat)
([3 0 -3; 0 1 2; 0 0 0], 2)
julia> mat = HomalgMatrix(reverse(1:9), 3, 3, QQ)
[9//1 8//1 7//1]
[6//1 5//1 4//1]
[3//1 2//1 1//1]
[9 8 7]
[6 5 4]
[3 2 1]
julia> RowReducedEchelonForm(mat)
([1 0 -1; 0 1 2; 0 0 0], 2)
"""
function RowReducedEchelonForm(mat::AbstractAlgebra.Generic.MatSpaceElem{BigInt})::Tuple{TypeOfMatrixForHomalg, Int64}
hnf = AbstractAlgebra.hnf(mat)
rank = AbstractAlgebra.rank(hnf)
function RowReducedEchelonForm(mat::Nemo.ZZMatrix)::Tuple{TypeOfMatrixForHomalg, Int64}
hnf = Nemo.hnf(mat)
rank = Nemo.rank(hnf)
return hnf, rank
end

function RowReducedEchelonForm(mat::AbstractAlgebra.Generic.MatSpaceElem{Rational{BigInt}})::Tuple{TypeOfMatrixForHomalg, Int64}
rank, rref = AbstractAlgebra.rref(mat)
function RowReducedEchelonForm(mat::Nemo.QQMatrix)::Tuple{TypeOfMatrixForHomalg, Int64}
rank, rref = Nemo.rref(mat)
return rref, rank
end

Expand All @@ -496,13 +496,13 @@ julia> BasisOfRows(mat)
[0 3 6]
julia> mat = HomalgMatrix(1:9, 3, 3, QQ)
[1//1 2//1 3//1]
[4//1 5//1 6//1]
[7//1 8//1 9//1]
[1 2 3]
[4 5 6]
[7 8 9]
julia> BasisOfRows(mat)
[1//1 0//1 -1//1]
[0//1 1//1 2//1]
[1 0 -1]
[0 1 2]
```
"""
function BasisOfRows(mat)::TypeOfMatrixForHomalg
Expand All @@ -527,14 +527,14 @@ julia> BasisOfColumns(mat)
[1 6]
julia> mat = HomalgMatrix(1:9, 3, 3, QQ)
[1//1 2//1 3//1]
[4//1 5//1 6//1]
[7//1 8//1 9//1]
[1 2 3]
[4 5 6]
[7 8 9]
julia> BasisOfColumns(mat)
[ 1//1 0//1]
[ 0//1 1//1]
[-1//1 2//1]
[ 1 0]
[ 0 1]
[-1 2]
```
"""
function BasisOfColumns(mat)::TypeOfMatrixForHomalg
Expand Down Expand Up @@ -982,7 +982,7 @@ julia> KroneckerMat(mat2, mat1)
```
"""
function KroneckerMat(mat1, mat2)::TypeOfMatrixForHomalg
return AbstractAlgebra.kronecker_product(mat1, mat2)
return Nemo.kronecker_product(mat1, mat2)
end

"""
Expand Down Expand Up @@ -1155,7 +1155,7 @@ function SafeRightDivide(B, A)::TypeOfMatrixForHomalg
end

# function SafeRightDivide(mat2, mat1)::Union{TypeOfMatrixForHomalg}
# return AbstractAlgebra.solve_left(mat1, mat2)
# return Nemo.solve_left(mat1, mat2)
# end

"""
Expand Down Expand Up @@ -1380,7 +1380,7 @@ function SafeLeftDivide(A, B)::TypeOfMatrixForHomalg
end

#= function SafeLeftDivide(A, B)::Union{TypeOfMatrixForHomalg}
return AbstractAlgebra.solve(A, B)
return Nemo.solve(A, B)
end =#

"""
Expand Down

0 comments on commit c204aad

Please sign in to comment.