Skip to content

Commit 2dd8d58

Browse files
authored
Final bugfixes for v0.1.0 (#34)
Fixes missing branch when setting k for complete graph special cases. Also sorts the input tuple S (closes #33).
1 parent 662ea42 commit 2dd8d58

File tree

4 files changed

+42
-10
lines changed

4 files changed

+42
-10
lines changed

src/core.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ end
2121
function s_bandwidth(L::AbstractMatrix{<:Integer}, S::Tuple{Vararg{Integer}})
2222
_assert_matrix_is_undirected_laplacian(L)
2323

24+
S = _sort_tuple(S)
2425
spec = laplacian_s_spectra(L, S)
2526

2627
if !spec.s_diagonalizable
@@ -39,12 +40,12 @@ function s_bandwidth(L::AbstractMatrix{<:Integer}, S::Tuple{Vararg{Integer}})
3940

4041
# Using results from Johnston and Plosker (2025, pp. 319–323)
4142
if classify_laplacian(L) isa CompleteGraphLaplacian
42-
if S == (-1, 0, 1)
43-
if 2 < n <= 20 && n % 4 != 0 # Proven subcase of Conjecture 2 applies
44-
k = 2
45-
end
46-
elseif n % 4 == 2 # And, of course, `S = (-1, 1)`; here Theorem 1 applies
43+
if S == (-1, 0, 1) && 2 < n <= 20 && n % 4 != 0 # Subcase of Conjecture 2
44+
k = 2
45+
elseif S == (-1, 1) && n % 4 == 2 # Theorem 1
4746
k = n - 1
47+
else # Back to the general case
48+
k = 1
4849
end
4950
else
5051
k = 1
@@ -91,6 +92,7 @@ function has_s_bandwidth_at_most_k(
9192
)
9293
_assert_matrix_is_undirected_laplacian(L)
9394

95+
S = _sort_tuple(S)
9496
spec = laplacian_s_spectra(L, S)
9597
L_copy = copy(spec.matrix)
9698

@@ -107,11 +109,9 @@ function has_s_bandwidth_at_most_k(
107109

108110
# Using results from Johnston and Plosker (2025, pp. 319–323)
109111
if classify_laplacian(L_copy) isa CompleteGraphLaplacian
110-
if S == (-1, 0, 1)
111-
if k == 1 && 2 < n <= 20 && n % 4 != 0 # Proven subcase of Conjecture 2 applies
112-
return SBandRecognitionResult(L_copy, S, nothing, k, false)
113-
end
114-
elseif n % 4 == 2 # And, of course, `S = (-1, 1)`; here Theorem 1 applies
112+
if S == (-1, 0, 1) && k == 1 && 2 < n <= 20 && n % 4 != 0 # Subcase of Conjecture 2
113+
return SBandRecognitionResult(L_copy, S, nothing, k, false)
114+
elseif S == (-1, 1) && n % 4 == 2 # Theorem 1
115115
if k < n - 1
116116
res = SBandRecognitionResult(L_copy, S, nothing, k, false)
117117
else
@@ -177,6 +177,7 @@ end
177177
function is_s_diagonalizable(L::AbstractMatrix{<:Integer}, S::Tuple{Vararg{Integer}})
178178
_assert_matrix_is_undirected_laplacian(L)
179179

180+
S = _sort_tuple(S)
180181
spec = laplacian_s_spectra(L, S)
181182
L_copy = copy(spec.matrix)
182183

src/eigenvector_generation.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ function pot_kernel_s_eigvecs(n::Integer, S::Tuple{Vararg{Integer}})
2626
throw(DomainError(n, "Laplacian order must be non-negative"))
2727
end
2828

29+
S = _sort_tuple(S)
30+
2931
if S == (-1, 0, 1)
3032
gen = _pot_kernel_01neg_eigvecs(n)
3133
elseif S == (-1, 1)
@@ -59,6 +61,8 @@ function pot_nonkernel_s_eigvecs(n::Integer, S::Tuple{Vararg{Integer}})
5961
throw(DomainError(n, "Laplacian order must be non-negative"))
6062
end
6163

64+
S = _sort_tuple(S)
65+
6266
if S == (-1, 0, 1)
6367
gen = _pot_nonkernel_01neg_eigvecs(n)
6468
elseif S == (-1, 1)

src/laplacian_s_spectra.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
function laplacian_s_spectra(L::AbstractMatrix{<:Integer}, S::Tuple{Vararg{Integer}})
1313
_assert_matrix_is_undirected_laplacian(L)
1414

15+
S = _sort_tuple(S)
16+
1517
if S == (-1, 0, 1)
1618
spec = _laplacian_01neg_spectra(L)
1719
elseif S == (-1, 1)
@@ -409,6 +411,7 @@ function _classified_laplacian_s_spectra(
409411
CL::ArbitraryGraphLaplacian, S::Tuple{Vararg{Integer}}
410412
)
411413
L = CL.matrix
414+
S = _sort_tuple(S)
412415
res = check_spectrum_integrality(L)
413416

414417
if !res.spectrum_integral

src/utils.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,30 @@
44
# http://opensource.org/licenses/MIT>. This file may not be copied, modified, or
55
# distributed except according to those terms.
66

7+
"""
8+
_sort_tuple(S::T) where {T<:Tuple{Vararg{Integer}}} -> T
9+
10+
Return a sorted version of the input tuple.
11+
12+
# Arguments
13+
- `S::T<:Tuple{Vararg{Integer}}`: the tuple to sort.
14+
15+
# Returns
16+
- `::T`: a sorted version of `S`.
17+
18+
# Examples
19+
```jldoctest
20+
julia> S = (-1, 1, 0)
21+
(-1, 1, 0)
22+
23+
julia> SDiagonalizability._sort_tuple(S)
24+
(-1, 0, 1)
25+
```
26+
"""
27+
function _sort_tuple(S::Tuple{Vararg{Integer}})
28+
return Tuple(sort(collect(S)))
29+
end
30+
731
"""
832
_extract_independent_cols(A) -> Matrix{Int}
933

0 commit comments

Comments
 (0)