diff --git a/src/ecc/ECC.jl b/src/ecc/ECC.jl index 5b647a1f1..aa17f0084 100644 --- a/src/ecc/ECC.jl +++ b/src/ecc/ECC.jl @@ -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. + 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 + end end """Parity matrix of a code, given as a stabilizer tableau.""" diff --git a/src/ecc/codes/classical/hamming.jl b/src/ecc/codes/classical/hamming.jl index 31de63354..b12dcef71 100644 --- a/src/ecc/codes/classical/hamming.jl +++ b/src/ecc/codes/classical/hamming.jl @@ -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 @@ -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 diff --git a/test/test_ecc_hamming.jl b/test/test_ecc_hamming.jl index 8c4c0a56c..d48ff8c43 100644 --- a/test/test_ecc_hamming.jl +++ b/test/test_ecc_hamming.jl @@ -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;