Classical local-return models and whole-domain definitions
DefinitionAPFG3ModelsFull simplex affine automorphisms; entire3x2fixed-marginal fibre, event/contrast models, C4 classical comparison tables, stationary stochastic control and full-domain argmin.
import Mathlib.Analysis.Convex.StdSimplex
import Mathlib.LinearAlgebra.Matrix.PosDef
import Mathlib.LinearAlgebra.Matrix.Determinant.Basic
import Mathlib.Analysis.SpecialFunctions.Sqrt
import Mathlib.GroupTheory.QuotientGroup.Basic
import Mathlib.GroupTheory.GroupAction.Basic
import Mathlib.LinearAlgebra.Matrix.Notation
set_option autoImplicit false
noncomputable section
namespace APFG3
open scoped BigOperators
abbrev Vec (n : ℕ) := Fin n → ℝ
abbrev Mat (n : ℕ) := Matrix (Fin n) (Fin n) ℝ
def simplex (n : ℕ) : Set (Vec n) := {z | (∀ i, 0 ≤ z i) ∧ ∑ i, z i = 1}
def vertex (n : ℕ) (j : Fin n) : Vec n := fun i => if i = j then 1 else 0
def permute {n : ℕ} (π : Equiv.Perm (Fin n)) (z : Vec n) : Vec n := z ∘ π.symm
def mix {n : ℕ} (t : ℝ) (x y : Vec n) : Vec n := fun i => t*x i+(1-t)*y i
structure SimplexAut (n : ℕ) where
forward : Vec n → Vec n
backward : Vec n → Vec n
forward_mem : ∀ z ∈ simplex n, forward z ∈ simplex n
backward_mem : ∀ z ∈ simplex n, backward z ∈ simplex n
left_inverse : ∀ z ∈ simplex n, backward (forward z) = z
right_inverse : ∀ z ∈ simplex n, forward (backward z) = z
forward_affine : ∀ x ∈ simplex n, ∀ y ∈ simplex n, ∀ t ∈ Set.Icc (0:ℝ) 1,
forward (mix t x y) = mix t (forward x) (forward y)
backward_affine : ∀ x ∈ simplex n, ∀ y ∈ simplex n, ∀ t ∈ Set.Icc (0:ℝ) 1,
backward (mix t x y) = mix t (backward x) (backward y)
abbrev Table := Matrix (Fin 3) (Fin 2) ℝ
def table (z : Vec 3) : Table := fun a b => if b = 0 then z a / 3 else (1-z a)/3
def wholeFibre : Set Table := {p | (∀ a b, 0 ≤ p a b) ∧
(∀ a, ∑ b, p a b = 1/3) ∧
(∑ a, p a 0 = 1/3) ∧ (∑ a, p a 1 = 2/3)}
def tablePerm (π : Equiv.Perm (Fin 3)) (p : Table) : Table := fun a b => p (π.symm a) b
def event (i : Fin 3) (p : Table) : ℝ := p i 0
def score (x y : Vec 3) : ℝ := (∑ i, x i * y i)/3
def contrast (w : Vec 2) : Vec 3 := ![w 0+w 1, w 0-w 1, -2*w 0]
def S : Mat 2 := !![1,0;0,-1]
def E : Mat 2 := !![-1/2,1/2;3/2,1/2]
def T : Mat 2 := E*S
def B : Mat 2 := !![2,0;0,2/3]
def J : Mat 2 := (Real.sqrt 3)⁻¹ • ((2:ℝ) • T + 1)
def halfTurn (z : Vec 3) : Vec 3 := fun i => 2/3-z i
def centre : Vec 3 := ![1/3,1/3,1/3]
def contrastCoordinates (z : Vec 3) : Vec 2 := ![-(z 2-1/3)/2,(z 0-z 1)/2]
def centredJ (z : Vec 3) : Vec 3 := centre + contrast (J.mulVec (contrastCoordinates z))
def quadratic {n : ℕ} (m : Mat n) (v : Vec n) : ℝ := ∑ i, v i * (m.mulVec v) i
def c4Value (a b : ℝ) (d : Fin 4) : ℝ := if d=0 then 1 else if d=2 then b else a
def c4Matrix (a b : ℝ) : Mat 4 := fun i j => c4Value a b (i-j)
def c4Prep (h : Fin 4) : Matrix (Fin 4) (Fin 4) ℝ := fun a b => if a-b=h then 1/4 else 0
def c4Move (g : Fin 4) (p : Matrix (Fin 4) (Fin 4) ℝ) := fun a b => p (a-g) b
def threshold (d : Fin 4) : ℕ := if d=0 then 4 else if d=2 then 1 else 3
def c4Observed (h j : Fin 4) : ℝ := (∑ b : Fin 4, ∑ c : Fin 4,
if c.val < threshold ((b+h)-b-j) then (1:ℝ) else 0)/16
def alternating : Vec 4 := ![1,-1,1,-1]
def properPositive (m : Mat 4) : Prop := ∀ k : ℕ, 0<k → k<4 →
∀ e : Fin k ↪ Fin 4, (m.submatrix e e).PosDef
abbrev Pair4 := Fin 4 × Fin 4
def diagonalState (h : Fin 4) : Matrix Pair4 Pair4 ℝ :=
Matrix.diagonal (fun x => c4Prep h x.1 x.2)
def diagonalEffect (a b : ℝ) (j : Fin 4) : Matrix Pair4 Pair4 ℝ :=
Matrix.diagonal (fun x => c4Value a b (x.1-x.2-j))
def stationaryP : Vec 2 := ![9/25,16/25]
def stationaryT : Mat 2 := fun i j => ((if i=j then 1 else 0)+stationaryP i)/2
def stationaryInverse : Mat 2 := fun i j => 2*(if i=j then 1 else 0)-stationaryP i
def correlatedP : Mat 2 := Matrix.diagonal stationaryP
def stochastic {n : ℕ} (m : Mat n) : Prop := (∀ i j, 0 ≤ m i j) ∧ ∀ j, ∑ i, m i j = 1
def argmin {D : Type*} (κ : D → ℝ) : Set D := {x | ∀ y, κ x ≤ κ y}
end APFG3
Read-back
What the Lean code literally says, in plain math · Exact runtime model identifier unavailable; independent reviewer RV-spine (01a082f2-417c-79c1-9069-c35844067fde).
Defines finite real simplex and vertices/permutations/convex mixtures. SimplexAut consists of forward/backward functions inverse and affine on the simplex only; no constraint outside it. Defines the complete nonnegative3x2 fixed-marginal table fibre and its parameter table, native event evaluations, score dot/3, contrast basis, concrete S,E,T,B,J and centered extensions. Defines C4 preparations/local shifts/seed observations/circulant matrices, all proper nonempty principal submatrix positivity, diagonal state/effect data, a2-state stationary stochastic example and whole-domain argmin. No target conclusion assumed. Independent code-first reading by RV-spine. Earlier written-source exposure and required personal paper/code consultation disclosed; this is not fully blind. Open theorem proofs remain sorry. Source-equivalence scope is governed by SOURCE_EQUIVALENCE_REVIEW.json, including G3-04 limits.