Skip to content

Commit

Permalink
Significantly polishing PR QuantumSavory#244, Adding more details fro…
Browse files Browse the repository at this point in the history
…m literature
  • Loading branch information
Fe-r-oz committed May 18, 2024
1 parent 44f618a commit 635f43c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 23 deletions.
38 changes: 29 additions & 9 deletions src/ecc/codes/classical/reedmuller.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
"""The family of Reed-Muller codes, as discovered by Muller in his 1954 paper [muller1954application](@cite) and Reed who proposed the first efficient decoding algorithm [reed1954class](@cite).
Let `m` be a positive integer and `r` a nonnegative integer with `r ≤ m`. These linear codes, denoted as `RM(r, m)`, have order `r` (where `0 ≤ r ≤ m`) and codeword length `n` of `2ᵐ`.
Two special cases exist:
1. `RM(0, m)`: This is the `0ᵗʰ`-order `RM` code, similar to the binary repetition code with length `2ᵐ`. It's characterized by a single basis vector containing all ones.
2. `RM(m, m)`: This is the `mᵗʰ`-order `RM` code. It encompasses the entire field `F(2ᵐ)`, representing all possible binary strings of length `2ᵐ`.
You might be interested in consulting [raaphorst2003reed](@cite), [abbe2020reed](@cite), and [djordjevic2021quantum](@cite) as well.
The ECC Zoo has an [entry for this family](https://errorcorrectionzoo.org/c/reed_muller)
The ECC Zoo has an [entry for this family](https://errorcorrectionzoo.org/c/reed_muller).
"""

abstract type ClassicalCode end
Expand All @@ -12,27 +18,41 @@ struct ReedMuller <: ClassicalCode
m::Int

function ReedMuller(r, m)
if r < 0 || m < 1 || m >= 11
throw(ArgumentError("Invalid parameters: r must be non-negative and m must be positive and < 11 in order to obtain a valid code and to remain tractable"))
if r < 0 || r > m || m < 1 || m >= 11
throw(ArgumentError("Invalid parameters: r must be non-negative and r ≤ m. Additionally, m must be positive and < 11 in order to obtain a valid code and to remain tractable"))
end
new(r, m)
end
end

function variables_xi(m, i)
return repeat([fill(1, 2^(m - i - 1)); fill(0, 2^(m - i - 1))], outer = 2^i)
function _variablesₓᵢ_rm(m, i)
return repeat([fill(1, 2 ^ (m - i - 1)); fill(0, 2 ^ (m - i - 1))], outer = 2 ^ i)
end

function vmult(vecs...)
function _vmult_rm(vecs...)
return [reduce(*, a, init=1) for a in zip(vecs...)]
end

"""
This function generates the parity-check matrix, `H`, for Reed-Muller `(RM(r, m))` error-correcting codes.
`parity_checks(ReedMuller(r, m))`:
- `m`: Positive integer representing the message length.
- `r`: Nonnegative integer less than or equal to `m`, specifying the code's order.
"""
function parity_checks(c::ReedMuller)
r=c.r
m=c.m
xi = [variables_xi(m, i) for i in 0:m - 1]
row_matrices = [reduce(vmult, [xi[i + 1] for i in S], init = ones(Int, 2^m)) for s in 0:r for S in combinations(0:m - 1, s)]
xᵢ = [_variablesₓᵢ_rm(m, i) for i in 0:m - 1]
row_matrices = [reduce(_vmult_rm, [xᵢ[i + 1] for i in S], init = ones(Int, 2 ^ m)) for s in 0:r for S in combinations(0:m - 1, s)]
rows = length(row_matrices)
cols = length(row_matrices[1])
H = reshape(vcat(row_matrices...), cols, rows)'
end
H = Matrix{Bool}(H)
return H
end

code_n(c::ReedMuller) = 2 ^ c.m
code_k(c::ReedMuller) = sum(binomial.(c.m, 0:c.r))
distance(c::ReedMuller) = 2 ^ (c.m - c.r)
rate(c::ReedMuller) = code_k(c::ReedMuller) / code_n(c::ReedMuller)
28 changes: 14 additions & 14 deletions test/test_ecc_reedmuller.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
using Test
using Nemo
using Combinatorics
using LinearAlgebra
using QuantumClifford
using QuantumClifford.ECC
using QuantumClifford.ECC: AbstractECC, ReedMuller

function binomial_coeff_sum(r, m)
total = 0
for i in 0:r
total += length(combinations(1:m, i))
function designed_distance(matrix, m, r)
for row in eachrow(matrix)
count = sum(row)
if count >= 2 ^ (m - r)
return true
end
end
return total
return false
end

@testset "Test RM(r, m) Matrix Rank" begin
for m in 2:5
for r in 0:m - 1
for m in 3:10
for r in 0:m
H = parity_checks(ReedMuller(r, m))
mat = Nemo.matrix(Nemo.GF(2), H)
computed_rank = LinearAlgebra.rank(mat)
expected_rank = binomial_coeff_sum(r, m)
expected_rank = sum(binomial.(m, 0:r))
@test computed_rank == expected_rank
@test designed_distance(H, m, r) == true
end
end
end

@testset "Testing common examples of RM(r,m) codes [raaphorst2003reed](@cite), [djordjevic2021quantum](@cite), [abbe2020reed](@cite)" begin

#RM(0,3)

# Testing common examples of RM(r,m) codes [raaphorst2003reed](@cite), [djordjevic2021quantum](@cite), [abbe2020reed](@cite).
# RM(0,3)
@test parity_checks(ReedMuller(0,3)) == [1 1 1 1 1 1 1 1]

#RM(1,3)
Expand Down

0 comments on commit 635f43c

Please sign in to comment.