Skip to content

Commit

Permalink
setting up for review: fixing Griesmer bound as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Fe-r-oz committed May 16, 2024
1 parent ba0c056 commit a756520
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
10 changes: 7 additions & 3 deletions src/ecc/ECC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,16 @@ end

"""The [Griesmer bound](https://en.wikipedia.org/wiki/Griesmer_bound) on the length of linear binary codes of dimension k and minimum distance d."""
function Griesmer_bound(c)
n = 0
n = code_n(c)
k = code_k(c)
d = distance(c)
sum_val = 0
sum_val = sum(d / 2 ^ i for i in 0:k - 1)
return n >= sum_val
if isinf(d)
return false # If d is infinite, Griesmer bound cannot be applied.

Check warning on line 127 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L121-L127

Added lines #L121 - L127 were not covered by tests
else
sum_val = sum(isinf(d / 2 ^ i) ? d : ceil(Int, d / 2 ^ i) for i in 0:k - 1) # apply ceiling function to d / 2 ^ i.
return n >= sum_val

Check warning on line 130 in src/ecc/ECC.jl

View check run for this annotation

Codecov / codecov/patch

src/ecc/ECC.jl#L129-L130

Added lines #L129 - L130 were not covered by tests
end
end

"""Parity matrix of a code, given as a stabilizer tableau."""
Expand Down
7 changes: 2 additions & 5 deletions src/ecc/codes/classical/hamming.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
"""
The family of `[[2ʳ - 1, 2ʳ - 1 - r, 3]]` Hamming binary codes were discovered by Richard W. Hamming in his 1950 paper [hamming1950error](@cite) as a way of automatically correcting errors introduced by punched card readers. In his original paper, Hamming elaborated his general idea, but specifically focused on the Hamming(7, 4) code which adds three parity bits to four bits of data.
Let `n = 2ʳ - 1`, with `r ≥ 2`. Then the `r × (2ʳ - 1)` matrix `H` whose columns, in order, are the numbers `1, 2, . . . , 2ʳ - 1` written as binary numerals, is the parity check matrix of an `[n = 2ʳ − 1, k = n − r]` binary code [huffman2010fundamentals](@cite).
Any rearrangement of columns of Hᵣ gives an equivalent code. The code is denoted by either `Hᵣ` or `H(2, r)`. The minimum distance of the code is 3.
Let `n = 2ʳ - 1`, with `r ≥ 2`. Then the `r × (2ʳ - 1)` matrix `H` whose columns, in order, are the numbers `1, 2, . . . , 2ʳ - 1` written as binary numerals, is the parity check matrix of an `[n = 2ʳ − 1, k = n − r]` binary code [huffman2010fundamentals](@cite). Any rearrangement of columns of Hᵣ gives an equivalent code. The code is denoted by either `Hᵣ` or `H(2, r)`. The minimum Hamming distance of these code is 3.
The ECC Zoo has an [entry for this family](https://errorcorrectionzoo.org/c/hamming).
"""

abstract type ClassicalCode end
Expand All @@ -16,7 +13,7 @@ struct Hamming <: ClassicalCode

function Hamming(r)
if r <= 2
throw(ArgumentError("Invalid parameters: `r` must be >= 2 to obtain a valid code."))
throw(ArgumentError("Invalid parameters: `r` must be 2 to obtain a valid code."))
end
new(r)
end
Expand Down
1 change: 0 additions & 1 deletion test/test_ecc_hamming.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ end
@test computed_rank == n - k
@test Hamming_bound(Hamming(r)) == true
@test Gilbert_Varshamov_bound(Hamming(r)) == true
@test Griesmer_bound(Hamming(r)) == false
end
# Example taken from [huffman2010fundamentals](@cite).
@test parity_checks(Hamming(3)) == [0 0 0 1 1 1 1;
Expand Down

0 comments on commit a756520

Please sign in to comment.