Skip to content

Commit 91f6257

Browse files
Merge pull request #75 from kamalsaleh/corner-cases
Fix corner cases in the singular extension
2 parents 444c6cf + 39a31ca commit 91f6257

2 files changed

Lines changed: 41 additions & 4 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "MatricesForHomalg"
22
uuid = "29b9b1b6-efa6-450e-8188-a5a2c25df071"
3-
version = "0.1.10"
3+
version = "0.1.11"
44
authors = ["Mohamed Barakat <mohamed.barakat@uni-siegen.de>", "Johanna Knecht <johanna.knecht@student.uni-siegen.de>"]
55

66
[deps]

ext/MatricesForHomalgSingularExt.jl

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,12 @@ julia> HomalgIdentityMatrix(2, R)
345345
```
346346
"""
347347
function MatricesForHomalg.HomalgIdentityMatrix(r, R::Singular.PolyRing)
348-
return Singular.identity_matrix(R, Int(r))
348+
n = Int(r)
349+
# Singular.identity_matrix segfaults for n=0; return a zero matrix instead
350+
if n == 0
351+
return Singular.zero_matrix(R, 0, 0)
352+
end
353+
return Singular.identity_matrix(R, n)
349354
end
350355

351356
## RandomMatrix for Singular rings
@@ -1042,6 +1047,14 @@ julia> SafeLeftDivide(A, B)
10421047
```
10431048
"""
10441049
function MatricesForHomalg.SafeLeftDivide(A::Singular.smatrix, B::Singular.smatrix)
1050+
R = Singular.base_ring(A)
1051+
# Singular.lift misbehaves for rank-0 modules (0-row A or 0-column B).
1052+
# If A has 0 rows: system A*X=B has 0 equations → trivial solution X=0
1053+
# If B has 0 cols: system A*X=B with B empty → solution X must also be empty
1054+
# In both cases X has shape ncols(A) × ncols(B).
1055+
if Singular.nrows(A) == 0 || Singular.ncols(B) == 0
1056+
return Singular.zero_matrix(R, Singular.ncols(A), Singular.ncols(B))
1057+
end
10451058
M_A = Singular.Module(A)
10461059
M_B = Singular.Module(B)
10471060
T, rest = Singular.lift(M_A, M_B)
@@ -1299,10 +1312,14 @@ true
12991312
```
13001313
"""
13011314
function MatricesForHomalg.ReducedSyzygiesOfColumns(A::Singular.smatrix)
1315+
R = Singular.base_ring(A)
1316+
# Singular.syz is buggy for rank-0 modules; handle the trivial case explicitly
1317+
if Singular.ncols(A) == 0
1318+
return Singular.zero_matrix(R, Singular.ncols(A), 0)
1319+
end
13021320
M = Singular.Module(A)
13031321
S = Singular.syz(M)
13041322
if Singular.iszero(S)
1305-
R = Singular.base_ring(A)
13061323
return Singular.zero_matrix(R, Singular.ncols(A), 0)
13071324
end
13081325
G = Singular.std(S; complete_reduction=true)
@@ -1352,11 +1369,15 @@ julia> ReducedSyzygiesOfColumns(A, N)
13521369
```
13531370
"""
13541371
function MatricesForHomalg.ReducedSyzygiesOfColumns(A::Singular.smatrix, N::Singular.smatrix)
1372+
R = Singular.base_ring(A)
1373+
# Singular.modulo is buggy for rank-0 modules; handle the trivial case explicitly
1374+
if Singular.ncols(A) == 0
1375+
return Singular.zero_matrix(R, Singular.ncols(A), 0)
1376+
end
13551377
M_A = Singular.Module(A)
13561378
M_N = Singular.Module(N)
13571379
S = Singular.modulo(M_A, M_N)
13581380
if Singular.iszero(S)
1359-
R = Singular.base_ring(A)
13601381
return Singular.zero_matrix(R, Singular.ncols(A), 0)
13611382
end
13621383
G = Singular.std(S; complete_reduction=true)
@@ -1386,4 +1407,20 @@ function MatricesForHomalg.ReducedSyzygiesOfRows(A::Singular.smatrix, N::Singula
13861407
return Singular.transpose(MatricesForHomalg.ReducedSyzygiesOfColumns(Singular.transpose(A), Singular.transpose(N)))
13871408
end
13881409

1410+
## Ring membership for Singular polynomial rings
1411+
#
1412+
# In GAP, `r in Ring` checks if r is an element of Ring. Julia's generic `in`
1413+
# tries to iterate over the collection, which fails for Singular.PolyRing.
1414+
# We define explicit Base.in methods to match GAP semantics.
1415+
1416+
# A Singular polynomial belongs to R if it comes from that same ring
1417+
function Base.in(x::Singular.spoly{T}, R::Singular.PolyRing{T}) where T
1418+
Singular.base_ring(x) === R
1419+
end
1420+
1421+
# Integers and rationals can always be coerced into any polynomial ring
1422+
function Base.in(x::Union{Integer, Rational, AbstractFloat}, R::Singular.PolyRing)
1423+
true
1424+
end
1425+
13891426
end # module

0 commit comments

Comments
 (0)