/-
  YangBaxter.lean — Layer 2d  (HONEST REWRITE 2026-07-03)

  The prior version proved `yang_baxter_holds` by `rfl` over two alpha-equivalent
  sums (bound variable r ↔ s): the statement was literally X = X.  Even the
  *intended* claim (R = B⊗B satisfies the YBE) is vacuous — on V⊗V⊗V,
  R₁₂·R₁₃·R₂₃ = B²⊗B²⊗B² = R₂₃·R₁₃·R₁₂ for ANY B, because single-site operators
  on distinct strands commute.

  An exact search over ℚ (scratchpad/ybe_sidon.py, ybe_verify.py) further showed
  the Sidon block B = σI + τX admits NO invertible, non-triangular (entangling)
  constant R-matrix: on the B⊗B-commutant every invertible YBE solution is
  diagonal, the permutation P, or triangular.  So "Yang-Baxter integrability of
  the Sidon braid" is not a real theorem — the only YBE structure it carries is
  the trivial permutation.

  This file therefore states the HONEST content: the symmetric-group braid
  relation (the Sₙ image of Bₙ, Artin 1947), realised as a concrete 8×8
  permutation-matrix identity on the 3-strand space, with a NEGATIVE CONTROL
  proving the statement is falsifiable (a non-permutation gate breaks it).
  Matrices verified independently in scratchpad/emit_braid_matrices.py.
-/
import Mathlib.LinearAlgebra.Matrix.Notation
import Mathlib.Tactic

open Matrix

namespace SilverSight.PIST.YangBaxter

/-- SWAP of strands (1,2) on the 3-strand computational space (2³ = 8-dim),
    as a permutation matrix.  Equals SWAP ⊗ I₂. -/
abbrev sL : Matrix (Fin 8) (Fin 8) ℤ :=
  !![1,0,0,0,0,0,0,0; 0,1,0,0,0,0,0,0; 0,0,0,0,1,0,0,0; 0,0,0,0,0,1,0,0;
     0,0,1,0,0,0,0,0; 0,0,0,1,0,0,0,0; 0,0,0,0,0,0,1,0; 0,0,0,0,0,0,0,1]

/-- SWAP of strands (2,3).  Equals I₂ ⊗ SWAP. -/
abbrev sR : Matrix (Fin 8) (Fin 8) ℤ :=
  !![1,0,0,0,0,0,0,0; 0,0,1,0,0,0,0,0; 0,1,0,0,0,0,0,0; 0,0,0,1,0,0,0,0;
     0,0,0,0,1,0,0,0; 0,0,0,0,0,0,1,0; 0,0,0,0,0,1,0,0; 0,0,0,0,0,0,0,1]

/-- **Honest braid relation** (Sₙ image of B₃): the adjacent-strand swaps satisfy
    σ₁σ₂σ₁ = σ₂σ₁σ₂; both sides realise the (1 3) transposition.  This is the
    TRIVIAL (permutation) solution of the Yang-Baxter equation — the only YBE
    structure the Sidon braid actually carries (see header). -/
theorem braid_relation_S8 : sL * sR * sL = sR * sL * sR := by decide

/-- Negative control gate 1 (a non-permutation shear on strands 1,2). -/
abbrev sBadL : Matrix (Fin 8) (Fin 8) ℤ :=
  !![1,0,1,0,0,0,0,0; 0,1,0,1,0,0,0,0; 0,0,1,0,0,0,0,0; 0,0,0,1,0,0,0,0;
     0,0,0,0,1,0,0,0; 0,0,0,0,0,1,0,0; 0,0,0,0,0,0,1,0; 0,0,0,0,0,0,0,1]

/-- Negative control gate 2 (the same shear on strands 2,3). -/
abbrev sBadR : Matrix (Fin 8) (Fin 8) ℤ :=
  !![1,1,0,0,0,0,0,0; 0,1,0,0,0,0,0,0; 0,0,1,0,0,0,0,0; 0,0,0,1,0,0,0,0;
     0,0,0,0,1,1,0,0; 0,0,0,0,0,1,0,0; 0,0,0,0,0,0,1,0; 0,0,0,0,0,0,0,1]

/-- **Negative control** (anti-smuggle): the braid relation is FALSIFIABLE.
    A non-permutation gate on the same strands BREAKS the relation, so
    `braid_relation_S8` is not vacuous.  Verified in emit_braid_matrices.py. -/
theorem braid_relation_falsifiable :
    sBadL * sBadR * sBadL ≠ sBadR * sBadL * sBadR := by decide

end SilverSight.PIST.YangBaxter
