-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
275 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
""" | ||
A construction of the Reed-Muller class of codes using the recursive definition. | ||
The Plotkin `(u, u + v)` construction defines a recursive relation between generator matrices of Reed-Muller `(RM)` codes [abbe2020reed](@cite). To derive the generator matrix `G(m, r)` for `RM(r, m)`, the generator matrices of lower-order codes are utilized: | ||
- `G(r - 1, m - 1)`: Generator matrix of `RM(r - 1, m - 1)` | ||
- `G(r, m - 1)`: Generator matrix of `RM(r, m - 1)` | ||
The generator matrix `G(m, r)` of `RM(m, r)` is formulated as follows in matrix notation: | ||
```math | ||
G(m, r) = \begin{bmatrix} | ||
G(r, m - 1) & G(r, m - 1) \\ | ||
0 & G(r - 1, m - 1) | ||
\end{bmatrix} | ||
``` | ||
Here, the matrix 0 denotes an all-zero matrix with dimensions matching `G(r - 1, m - 1)`. This recursive approach facilitates the construction of higher-order Reed-Muller codes based on the generator matrices of lower-order codes. | ||
In addition, the dimension of `RM(m - r - 1, m)` equals the dimension of the dual of `RM(r, m)`. Thus, `RM(m - r - 1, m) = RM(r, m)^⊥` shows that the [dual code](https://en.wikipedia.org/wiki/Dual_code) of `RM(r, m)` is `RM(m − r − 1, m)`, indicating the parity check matrix of `RM(r, m)` is the generator matrix for `RM(m - r - 1, m)`. | ||
See also: `ReedMuller` | ||
""" | ||
struct RecursiveReedMuller <: ClassicalCode | ||
r::Int | ||
m::Int | ||
|
||
function RecursiveReedMuller(r, m) | ||
if r < 0 || r > m | ||
throw(ArgumentError("Invalid parameters: r must be non-negative and r ≤ m in order to valid code.")) | ||
end | ||
new(r, m) | ||
end | ||
end | ||
|
||
function _recursiveReedMuller(r::Int, m::Int) | ||
if r == 1 && m == 1 | ||
return Matrix{Int}([1 1; 0 1]) | ||
elseif r == m | ||
return Matrix{Int}(I, 2^m, 2^m) | ||
elseif r == 0 | ||
return Matrix{Int}(ones(1, 2^m)) | ||
else | ||
Gᵣₘ₋₁ = _recursiveReedMuller(r, m - 1) | ||
Gᵣ₋₁ₘ₋₁ = _recursiveReedMuller(r - 1, m - 1) | ||
return vcat(hcat(Gᵣₘ₋₁, Gᵣₘ₋₁), hcat(zeros(Int, size(Gᵣ₋₁ₘ₋₁)...), Gᵣ₋₁ₘ₋₁)) | ||
end | ||
end | ||
|
||
function generator(c::RecursiveReedMuller) | ||
return _recursiveReedMuller(c.r, c.m) | ||
end | ||
|
||
function parity_checks(c::RecursiveReedMuller) | ||
H = generator(RecursiveReedMuller(c.m - c.r - 1, c.m)) | ||
return H | ||
end | ||
|
||
code_n(c::RecursiveReedMuller) = 2 ^ c.m | ||
|
||
code_k(c::RecursiveReedMuller) = sum(binomial.(c.m, 0:c.r)) | ||
|
||
distance(c::RecursiveReedMuller) = 2 ^ (c.m - c.r) | ||
|
||
rate(c::RecursiveReedMuller) = code_k(c::RecursiveReedMuller) / code_n(c::RecursiveReedMuller) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,60 @@ | ||
"""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 of generator(RM(r, m)) exist: | ||
1. `generator(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. `generator(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 dimension of `RM(m - r - 1, m)` equals the dimension of the dual of `RM(r, m)`. Thus, `RM(m - r - 1, m) = RM(r, m)^⊥` shows that the [dual code](https://en.wikipedia.org/wiki/Dual_code) of `RM(r, m)` is `RM(m − r − 1, m)`, indicating the parity check matrix of `RM(r, m)` is the generator matrix for `RM(m - r - 1, m)`. | ||
abstract type ClassicalCode end | ||
The ECC Zoo has an [entry for this family](https://errorcorrectionzoo.org/c/reed_muller). | ||
See also: `RecursiveReedMuller` | ||
""" | ||
struct ReedMuller <: ClassicalCode | ||
r::Int | ||
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 | ||
throw(ArgumentError("Invalid parameters: r must be non-negative and r ≤ m in order to valid code.")) | ||
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 | ||
|
||
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)] | ||
function generator(c::ReedMuller) | ||
r = c.r | ||
m = c.m | ||
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 | ||
G = reshape(vcat(row_matrices...), cols, rows)' | ||
G = Matrix{Bool}(G) | ||
return G | ||
end | ||
|
||
function parity_checks(c::ReedMuller) | ||
H = generator(ReedMuller(c.m - c.r - 1, c.m)) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.