AFTD Auto-Formalizing Theoretical Domains

CodingTheory.Johnson.inner_pmOne_pmOne

theoremverifiedimported Lean

Inner product of two ±1 embeddings. For any two binary words $x, y$ of length $n$, let $\phi(x), \phi(y) \in \mathbb{R}^n$ be their $\pm 1$ embeddings, whose $i$-th coordinates are $-1$ when the corresponding bit is true and $+1$ otherwise. Then their Euclidean inner product is \[ \langle \phi(x),\, \phi(y)\rangle \;=\; n - 2\,d(x,y), \] where $d(x,y)$ is the Hamming distance, the number of coordinates on which $x$ and $y$ differ.

Statement

set_option autoImplicit true in
set_option relaxedAutoImplicit true in
open scoped BigOperators RealInnerProductSpace in
open Finset in
lemma CodingTheory.Johnson.inner_pmOne_pmOne {n : ℕ} (x y : BitVec n) :
    ⟪pmOne x, pmOne y⟫_[ℝ] = (n : ℝ) - 2 * (hdist x y : ℝ)
Source
TCSlib, `CodingTheory.Johnson.inner_pmOne_pmOne`
Lean proof
By Allan Li, Frederick Dehmel, Hydroxyi (from the file's git history), from github.com/Shilun-Allan-Li/tcslib at c8a02591b1e5 (Apache-2.0). Compiled here against leanprover/lean4:v4.33.1, Mathlib v4.33.1; written for leanprover/lean4:v4.25.0.
Verified
07 Oct 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 4
  • CodingTheory.Johnson.BitVecThe type of binary words of length $n$, namely functions $\mathrm{Fin}\,n \to \mathrm{Bool}$.
  • CodingTheory.Johnson.pmOneThe map sending a binary word $x$ to the real vector in $\mathbb{R}^n$ whose $i$-th coordinate is $-1$ if $x_i = \texttt{true}$ and $+1$…
  • CodingTheory.Johnson.coord_mul_pmOneCoordinatewise product of $\pm 1$ embeddings. Let $x, y$ be binary words of length $n$, and encode each as a $\pm 1$ vector in $\bbr^n$ by…
  • CodingTheory.Johnson.hdistFor binary words $x,y$ of length $n$, the Hamming distance is the number of coordinates on which they differ:…
Used by 1

Lean source view module on GitHub

set_option autoImplicit true inset_option relaxedAutoImplicit true inopen scoped BigOperators RealInnerProductSpace inopen Finset inlemma CodingTheory.Johnson.inner_pmOne_pmOne {n : ℕ} (x y : BitVec n) :    ⟪pmOne x, pmOne y⟫_[ℝ] = (n : ℝ) - 2 * (hdist x y : ℝ) := by  have h_pmOne : ∀ i, (pmOne x i) * (pmOne y i) = if x i = y i then 1 else -1 := by    exact fun i => coord_mul_pmOne x y i;  have h_hdist : (CodingTheory.Johnson.hdist x y : ℝ) = ∑ i, (if x i ≠ y i then 1 else 0) := by    simp +decide [ Finset.sum_ite ];    exact congr_arg Finset.card ( Finset.filter_congr fun _ _ => by aesop );  simp_all +decide [ RCLike.wInner ];  simp_all +decide [ mul_comm, Finset.sum_ite ];  rw [ Finset.filter_not, Finset.card_sdiff ] ; norm_num ; ring_nf;  rw [ Nat.cast_sub ( le_trans ( Finset.card_le_univ _ ) ( by norm_num ) ) ] ; ring
See it in the graphDiscuss this resultChallenge it