/-- **Uniqueness**: two binary representations without leading zeros that have the same value are
the same list. The last digit is forced (it is the remainder on division by `2`); remove it, and
the rest represent the same smaller number — so by induction they agree too. -/
theorem binary_unique : ∀ l₁ l₂ : List Nat, AllBits l₁ → AllBits l₂ →
NoLeadingZero l₁ → NoLeadingZero l₂ → fromBinary l₁ = fromBinary l₂ → l₁ = l₂
| [], [], _, _, _, _, _ => rfl
| [], e :: es, _, _, _, h₂, hv => absurd hv.symm (value_ne_zero e es h₂)
| d :: ds, [], _, _, h₁, _, hv => absurd hv (value_ne_zero d ds h₁)
| d :: ds, e :: es, ⟨hd, hds⟩, ⟨he, hes⟩, h₁, h₂, hv => by
have hv' : d + 2 * fromBinary ds = e + 2 * fromBinary es := hv
have hde : d = e := by omega
have hrest : fromBinary ds = fromBinary es := by omega
have hlead₁ : NoLeadingZero ds := by
cases ds with
| nil => trivial
| cons _ _ => exact h₁
have hlead₂ : NoLeadingZero es := by
cases es with
| nil => trivial
| cons _ _ => exact h₂
rw [hde, binary_unique ds es hds hes hlead₁ hlead₂ hrest]