Berlekamp–Massey Binary Complexity
Infer the shortest binary feedback recurrence while tracing discrepancies one bit at a time.
By Riano · Published · Updated · Report a correction
Berlekamp–Massey Binary Complexity
The Berlekamp–Massey algorithm synthesizes the shortest linear feedback shift register (LFSR) capable of generating a given finite binary sequence. By iteratively processing the sequence one bit at a time, it dynamically updates the discrepancy and connection polynomial, providing the minimal linear recurrence.
Worked Example
Consider the LFSR sequence prefix of length 4: 1001. We apply the Berlekamp-Massey algorithm over the finite field GF(2).
- Initialize: Sequence
s = [1, 0, 0, 1], Connection polynomialC = [1], Previous polynomialB = [1], Linear complexityL = 0, shiftm = 1. - Step 1 (t=0): Read
s[0] = 1.
Discrepancyd = s[0] = 1.
UpdateC:C_new = C ^ (B shifted by m) = [1] ^ [0, 1] = [1, 1].
Since2L <= t(0 <= 0), updateL = t + 1 - L = 1,B = old_C = [1],m = 1. - Step 2 (t=1): Read
s[1] = 0.
Discrepancyd = s[1] ^ (C[1]*s[0]) = 0 ^ (1*1) = 1.
UpdateC:C_new = [1, 1] ^ ([0, 1] shifted by 1) = [1, 1] ^ [0, 1] = [1, 0].
Here2L <= tis false (2 <= 1 is false). Incrementm = 2. - Step 3 (t=2): Read
s[2] = 0.
Discrepancyd = s[2] ^ (C[1]*s[1]) = 0 ^ (0*0) = 0.
Sinced = 0,Cremains[1, 0]. Incrementm = 3. - Step 4 (t=3): Read
s[3] = 1.
Discrepancyd = s[3] ^ (C[1]*s[2]) = 1 ^ (0*0) = 1.
UpdateC:C_new = [1, 0] ^ ([1] shifted by 3) = [1, 0] ^ [0, 0, 0, 1] = [1, 0, 0, 1].
Since2L <= t(2 <= 3 is true), updateL = 3 + 1 - 1 = 3,B = [1, 0],m = 1.
The final linear complexity is L = 3 with connection coefficients 1, 0, 0, 1.
Interactive Experiment
Trace the discrepancy and connection shifts dynamically:
- Open the interactive module at https://riano.app/module/berlekamp-massey-binary-complexity.
- Select the Sequence control and choose Alternating. Observe the synthesized complexity drop to 2, capturing the simple repeating pattern.
- Change the Prefix length control to examine how the required minimal complexity grows as more bits are revealed. Notice how the visual trace updates the connection polynomial taps whenever a non-zero discrepancy is found.
Model Limitations
This implementation operates exclusively over the finite field GF(2), utilizing XOR arithmetic. It is specifically designed for binary sequences and does not generalize to real numbers or arbitrary finite fields. Furthermore, requesting a prefix length that exceeds the available sequence data (such as asking for length 1 from an empty sequence) constitutes an invalid bound, and the algorithm correctly refuses to compute a result for such undefined states.
References
The Berlekamp-Massey algorithm and its role in determining the minimal linear complexity of shift registers are covered extensively in modern coding theory literature. For foundational material on finite fields and linear feedback shift registers, refer to the Stanford CS250 course materials, which detail sequence generation and error-correcting codes.
Experience it interactively
Adjust parameters, observe in real time, and build deep intuition with Riano’s interactive Berlekamp–Massey Binary Complexity module.
Try Berlekamp–Massey Binary Complexity on Riano →