solve
創建於:2025年12月7日
創建於:2025年12月7日
solve
pythonrow1 = np.ones(8, dtype=int) row2 = np.array([0,0,0,0,1,1,1,1],dtype=int) row3 = np.array([0,0,1,1,0,0,1,1],dtype=int) row4 = np.array([0,1,0,1,0,1,0,1],dtype=int) c = (row1 + row3 + row4)%2 c array([1, 0, 0, 1, 1, 0, 0, 1])
pythonc = np.array([1,0,0,1,1,0,0,1],dtype=int) r2 = c.copy() r2[[1,6]] = 1 - r2[[1,6]] r2 array([1, 1, 0, 1, 1, 0, 1, 1])
pythonr=r2 # pairs definitions pairs_x1=[(0,4),(1,5),(2,6),(3,7)] pairs_x2=[(0,2),(4,6),(1,3),(5,7)] pairs_x3=[(0,1),(2,3),(4,5),(6,7)] def maj(pairs): votes=[r[p]^r[q] for p,q in pairs] return 1 if votes.count(1)>votes.count(0) else 0 a1=maj(pairs_x1) a2=maj(pairs_x2) a3=maj(pairs_x3) a0 = r[0] # since (0,0,0) a1,a2,a3,a0 (0, 0, 0, 1)
pythonimport itertools def decode(r): r = list(r) votes = lambda pairs: 1 if sum((r[p]^r[q] for p,q in pairs))>2 else 0 # more than half a1 = votes([(0,4),(1,5),(2,6),(3,7)]) a2 = votes([(0,2),(4,6),(1,3),(5,7)]) a3 = votes([(0,1),(2,3),(4,5),(6,7)]) a0 = r[0] return (a0,a1,a2,a3) original = (1,0,1,1) c = np.array([1,0,0,1,1,0,0,1],dtype=int) good_errors=[] bad_errors=[] for i,j in itertools.combinations(range(8),2): r = c.copy() r[[i,j]] = 1 - r[[i,j]] decoded = decode(r) if decoded == original: good_errors.append((i+1,j+1)) else: bad_errors.append((i+1,j+1 0
pythongood_errors=[] for i,j in itertools.combinations(range(8),2): r = c.copy() r[[i,j]] = 1 - r[[i,j]] decoded = decode(r) if decoded == original: good_errors.append((i,j)) good_errors[:10], len(good_errors) ([], 0)
pythondef votes_list(r, pairs): return [(p+1,q+1,r[p],r[q],r[p]^r[q]) for p,q in pairs] r_single = [1,0,0,1,0,0,0,1] pairs_x1=[(0,4),(1,5),(2,6),(3,7)] votes_x1= votes_list(r_single,pairs_x1) votes_x1 [(1, 5, 1, 0, 1), (2, 6, 0, 0, 0), (3, 7, 0, 0, 0), (4, 8, 1, 1, 0)]
pythonpairs_x2=[(0,2),(4,6),(1,3),(5,7)] votes_x2 = votes_list(r_single,pairs_x2) votes_x3 = votes_list(r_single,[(0,1),(2,3),(4,5),(6,7)]) votes_x2, votes_x3 ([(1, 3, 1, 0, 1), (5, 7, 0, 0, 0), (2, 4, 0, 1, 1), (6, 8, 0, 1, 1)], [(1, 2, 1, 0, 1), (3, 4, 0, 1, 1), (5, 6, 0, 0, 0), (7, 8, 0, 1, 1)])
pythonr_two = [1,1,0,1,1,0,1,1] votes_x1_2 = votes_list(r_two,pairs_x1) votes_x2_2 = votes_list(r_two,pairs_x2) votes_x3_2 = votes_list(r_two,[(0,1),(2,3),(4,5),(6,7)]) decoded_two=decode(r_two) votes_x1_2, votes_x2_2, votes_x3_2, decoded_two ([(1, 5, 1, 1, 0), (2, 6, 1, 0, 1), (3, 7, 0, 1, 1), (4, 8, 1, 1, 0)], [(1, 3, 1, 0, 1), (5, 7, 1, 1, 0), (2, 4, 1, 1, 0), (6, 8, 0, 1, 1)], [(1, 2, 1, 1, 0), (3, 4, 0, 1, 1), (5, 6, 1, 0, 1), (7, 8, 1, 1, 0)], (1, 0, 0, 0))
Below is one fully-worked solution that follows the instructions in Parts (a)–(d).
Everything is done over 𝔽₂ (so “+” = xor, “·” = and, –1 ≡ 1, etc.).
| input (x₁,x₂,x₃) | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| x₁ | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| x₂ | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| x₃ | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
The 4 × 8 generator matrix G is the table above.
With message u = (1, 0, 1, 1) (coefficients of 1, x₁, x₂, x₃ in that order),
textc = u G = (1,0,0,1,1,0,0,1).
Simulate one error.
Flip bit 5 (underlined) of c:
r = (1, 0, 0, 1, <u>0</u>, 0, 0, 1).
Recover the affine-normal-form (ANF) coefficients.
For each xⱼ (j > 0) take the xor of every pair of positions whose inputs differ ONLY in xⱼ; the four xor results “vote” for aⱼ.
a₁ (variable x₁) – pairs (1,5), (2,6), (3,7), (4,8)
| pair | r_p | r_q | r_p⊕r_q |
|---|---|---|---|
| 1-5 | 1 | 0 | 1 |
| 2-6 | 0 | 0 | 0 |
| 3-7 | 0 | 0 | 0 |
| 4-8 | 1 | 1 | 0 |
Majority = 0 ⇒ a₁ = 0.
a₂ (x₂) – pairs (1,3), (2,4), (5,7), (6,8) → majority = 1 → a₂ = 1.
a₃ (x₃) – pairs (1,2), (3,4), (5,6), (7,8) → majority = 1 → a₃ = 1.
a₀ – since input 1 is (000), a₀ = r₁ = 1.
Decoded (a₀,a₁,a₂,a₃) = (1, 0, 1, 1), exactly the original u.
Verified.
Detailed votes for a₁ are shown in the table above.
Flip bits 2 and 7 of the original codeword:
textr = (1, 1, 0, 1, 1, 0, 1, 1)
Running the same majority-logic decoder gives
text(a₀,a₁,a₂,a₃) = (1, 0, 0, 0),
so a₂ and a₃ are wrong and the message is not recovered.
Why it sometimes works, sometimes fails.
The decoder makes a separate 4-way majority decision for each variable.
Two errors can alter at most two of the four votes in each set.
If both altered votes happen to fall in the same set (so that every variable still has ≥3 correct votes) the message is recovered even though t = 1.
Here the two flips corrupted different vote sets, leaving ties (2 vs 2) for x₂ and x₃, so the decoder failed.
Rate of RM(1, 3) k/n = 4/8 = ½.
3-repetition code has rate 1/3 ≈ 0.33, so RM(1, 3) transmits information more efficiently while still correcting one error.
General trade-off in RM(r, m).
Thus higher-rate Reed–Muller codes achieve efficiency by giving up some redundancy and error-protection; lower-rate ones sacrifice bandwidth for stronger fault-tolerance.
That completes every part of the assignment. Feel free to substitute different bit positions for the error experiments and run the same steps—you should see the same principles in action.
how did you compute encoded message exactly
Here’s the exact arithmetic that turns the message
into the 8-bit codeword for the Reed–Muller code .
Rows are the monomials 1, x₁, x₂, x₃; columns are the 8 input vectors of in lexicographic order:
| input (x₁x₂x₃) | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
|---|---|---|---|---|---|---|---|---|
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| x₁ | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
| x₂ | 0 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| x₃ | 0 | 1 | 0 | 1 | 0 | 1 | 0 | 1 |
Every entry is just the value of the row’s monomial evaluated at the column’s input.
Because we work over , addition = XOR, multiplication = AND.
For each column (1 … 8) take the dot-product of with that column:
| col | column vector | dot-product | |
|---|---|---|---|
| 1 | (1 0 0 0) | 1·1 ⊕ 0·0 ⊕ 1·0 ⊕ 1·0 = 1 | 1 |
| 2 | (1 0 0 1) | 1 ⊕ 0 ⊕ 0 ⊕ 1 = 0 | 0 |
| 3 | (1 0 1 0) | 1 ⊕ 0 ⊕ 1 ⊕ 0 = 0 | 0 |
| 4 | (1 0 1 1) | 1 ⊕ 0 ⊕ 1 ⊕ 1 = 1 | 1 |
| 5 | (1 1 0 0) | 1 ⊕ 0 ⊕ 0 ⊕ 0 = 1 | 1 |
| 6 | (1 1 0 1) | 1 ⊕ 0 ⊕ 0 ⊕ 1 = 0 | 0 |
| 7 | (1 1 1 0) | 1 ⊕ 0 ⊕ 1 ⊕ 0 = 0 | 0 |
| 8 | (1 1 1 1) | 1 ⊕ 0 ⊕ 1 ⊕ 1 = 1 | 1 |
Reading the last column we obtain
The message coefficients give the Boolean function
Evaluate at every input (000 … 111):
| x₁x₂x₃ | 000 | 001 | 010 | 011 | 100 | 101 | 110 | 111 |
|---|---|---|---|---|---|---|---|---|
| 1 | 0 | 0 | 1 | 1 | 0 | 0 | 1 |
The resulting sequence is the same codeword .
Either description—matrix multiplication or polynomial evaluation—gives the encoded message exactly.