UniqueDecodability : Prop ≡
∀w ∈ L . ∃! decomposition : List[Codeword] .
w = concatenate(decomposition) ∧
∀c ∈ decomposition . c ∈ Codewords(E)
where
L : Set[BinaryString] // Language of all concatenations
concatenate : List[String] → String
MinimalEffectiveConstraint : Prop ≡
∀E : BinaryEncodingSystem .
UniqueDecodable(E) ∧ NonDegenerate(E) →
∃f ∈ ForbiddenPatterns(E) . |f| = 2
Proof by cases:
Case |f| = 1:
Forbid "0" → only "1" → H = 0
Forbid "1" → only "0" → H = 0
Contradicts entropy increase
Case |f| ≥ 3:
All strings of length < 3 are valid
{1, 11, 111, ...} all valid
But 1 is prefix of 11
Not prefix-free → not uniquely decodable
Therefore |f| = 2 is necessary ∎
Proof of Minimality:
Assume only constraints of length k > 2
Then ∀s . |s| < k → s is valid codeword
In particular: 1, 11, ..., 1^{k-1} all valid
But 1 is prefix of 11
String "11" can be decoded as:
- [1, 1]
- [11]
Contradiction with unique decodability
Therefore need constraint with length ≤ 2
Combined with length-1 analysis: must be length 2 ∎
def verify_prefix_ambiguity(codewords):
# 检查前缀冲突
for c1 in codewords:
for c2 in codewords:
if c1 != c2:
if c1.startswith(c2) or c2.startswith(c1):
return True, (c1, c2)
return False, None
def verify_minimal_constraint_length(encoding_system):
# 验证长度2是最小有效约束
constraints = encoding_system.get_constraints()
if all(len(c) > 2 for c in constraints):
# 应该找到前缀冲突
return find_prefix_conflicts(encoding_system)
if any(len(c) == 1 for c in constraints):
# 应该是退化系统
return check_degeneration(encoding_system)
# 长度2约束应该有效
return check_effectiveness(encoding_system)