Pith. sign in

IndisputableMonolith.Gravity.PhysicalSixTetCubicDirichletInstance

IndisputableMonolith/Gravity/PhysicalSixTetCubicDirichletInstance.lean · 13231 lines · 597 declarations

show as:
view math explainer →

open module explainer GitHub source

Explainer status: pending

   1import IndisputableMonolith.Geometry.PeriodicFreudenthalTorus
   2import IndisputableMonolith.Geometry.ReggeActionNonlinearCorrespondence
   3import IndisputableMonolith.Gravity.FreudenthalLengthChainEndpointCert
   4import IndisputableMonolith.Gravity.ReggeCubicLatticeLimit
   5
   6/-!
   7# Physical Six-Tet Cubic Dirichlet Instance
   8
   9This module connects the encoded periodic Freudenthal torus scaffold to the
  10`PhysicalSixTetCubicDirichletModel` target.
  11
  12It does not assert the physical Dirichlet equality for free.  Instead it
  13packages the exact theorem obligations needed to instantiate the physical
  14model on a periodic Freudenthal torus.
  15-/
  16
  17namespace IndisputableMonolith
  18namespace Gravity
  19namespace PhysicalSixTetCubicDirichletInstance
  20
  21open Geometry.ReggeTriangulation3D
  22open Geometry.ReggeHessian3D
  23open Geometry.Triangulation3DConsistency
  24open Geometry.ReggeActionConcrete
  25open Geometry.ReggeActionSmoothness
  26open Geometry.ReggeActionFirstVariation
  27open Geometry.ReggeActionSecondVariation
  28open Geometry.ReggeActionNonlinearHessianProof
  29open Geometry.ReggeActionNonlinearCorrespondence
  30open Geometry.ReggeActionCubicTaylorBound
  31open Geometry.PeriodicFreudenthalTorus
  32open Geometry.ReggeRigorousFoundation
  33open Geometry.SchlaefliTetrahedronProof
  34open Geometry.SchlaefliTetrahedron
  35open ReggeCubicLatticeLimit
  36
  37noncomputable section
  38
  39def CanonicalHessianIsDirichlet
  40    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
  41    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) : Prop :=
  42  ∀ ξ : VertexPotential P.K,
  43    hessianQuadratic (canonicalReggeHessian P.K P.hK) ξ =
  44      canonicalDirichletEnergy P.K P.hK ξ
  45
  46theorem canonicalHessianIsDirichlet_of_encodedPeriodicFreudenthal
  47    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
  48    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) :
  49    CanonicalHessianIsDirichlet P :=
  50  fun ξ => canonicalReggeHessian_quadratic_eq_dirichlet P.K P.hK ξ
  51
  52/-- Physical finite-difference Dirichlet operator placeholder, separated from
  53the abstract canonical graph Dirichlet energy.  A later proof should replace
  54this with the actual six-tet cubic stencil expression. -/
  55abbrev PhysicalFiniteDifferenceDirichletAction
  56    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
  57    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) :=
  58  VertexPotential P.K → ℝ
  59
  60/-- The exact remaining physical identification target: the canonical
  61Dirichlet energy from incidence weights equals the concrete six-tet
  62finite-difference Dirichlet action. -/
  63def PhysicalFiniteDifferenceDirichletTarget
  64    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
  65    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz)
  66    (D : PhysicalFiniteDifferenceDirichletAction P) : Prop :=
  67  ∀ ξ : VertexPotential P.K, canonicalDirichletEnergy P.K P.hK ξ = D ξ
  68
  69/-- Concrete edge-stencil candidate for the physical six-tet finite-difference
  70Dirichlet action: sum over the encoded global periodic edges, weighted by the
  71flat global edge length.  This is distinct from the abstract canonical
  72vertex-pair Dirichlet energy and is the next physical identification target. -/
  73def periodicEdgeStencilDirichletAction
  74    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
  75    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) :
  76    PhysicalFiniteDifferenceDirichletAction P :=
  77  canonicalEdgeStencilDirichletEnergy P.K P.hK
  78
  79/-- The three axis displacement classes inside the seven positive Freudenthal
  80edge classes. -/
  81def periodicAxisDisp (d : Fin 3) : Fin 7 :=
  82  ⟨d.1, by omega⟩
  83
  84/-- Corrected rational axis stencil exposed by the Session 202 mixed-target
  85audit.  The mixed hinge-deficit quadratic cancels the local square-root factors
  86and matches twice the axis-edge stencil, not the full
  87`sqrt(periodicDispSqEdge)` seven-class edge stencil. -/
  88def canonicalPeriodicMixedAxisStencilAction
  89    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
  90    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
  91    PhysicalFiniteDifferenceDirichletAction
  92      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) :=
  93  fun ξ =>
  94    ∑ base : Vertex Nx Ny Nz, ∑ d : Fin 3,
  95      let edge : PeriodicEdge Nx Ny Nz := { base := base, disp := periodicAxisDisp d }
  96      2 *
  97        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
  98          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
  99
 100def PeriodicEdgeStencilDirichletTarget
 101    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 102    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) : Prop :=
 103  PhysicalFiniteDifferenceDirichletTarget P
 104    (periodicEdgeStencilDirichletAction P)
 105
 106theorem periodicEdgeStencilDirichletAction_nonneg
 107    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 108    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz)
 109    (ξ : VertexPotential P.K) :
 110    0 ≤ periodicEdgeStencilDirichletAction P ξ := by
 111  exact canonicalEdgeStencilDirichletEnergy_nonneg P.K P.hK ξ
 112
 113theorem periodicEdgeStencilTarget_of_noSelfLoop
 114    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 115    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz)
 116    (hNoLoop : NoSelfLoopEdges P.K) :
 117    PeriodicEdgeStencilDirichletTarget P :=
 118  canonicalDirichletEqualsEdgeStencil_of_sumComm_and_reindex P.K P.hK
 119    (canonicalEdgeStencilSumComm P.K P.hK)
 120    (canonicalEdgePairWeightReindex_of_noSelfLoop P.K P.hK hNoLoop)
 121
 122theorem canonicalPeriodicNoSelfLoopEdges
 123    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 124    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
 125    NoSelfLoopEdges (canonicalPeriodicTriangulation Nx Ny Nz) := by
 126  intro e h
 127  have hverts :
 128      (edgeFinEquiv Nx Ny Nz e).endpoints.1 =
 129        (edgeFinEquiv Nx Ny Nz e).endpoints.2 := by
 130    unfold canonicalPeriodicTriangulation canonicalEdgeVerts at h
 131    exact (vertexFinEquiv Nx Ny Nz).symm.injective h
 132  exact PeriodicEdge.endpoints_ne hx hy hz (edgeFinEquiv Nx Ny Nz e) hverts
 133
 134theorem canonicalPeriodicEdgeStencilTarget
 135    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 136    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
 137    PeriodicEdgeStencilDirichletTarget
 138      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) :=
 139  periodicEdgeStencilTarget_of_noSelfLoop
 140    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz)
 141    (canonicalPeriodicNoSelfLoopEdges Nx Ny Nz hx hy hz)
 142
 143theorem canonicalPeriodicJQuadraticTerm_eq_edgeStencil
 144    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 145    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 146    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
 147    canonicalJQuadraticTerm
 148        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 149        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 150        ξ =
 151      (1 / 2) * periodicEdgeStencilDirichletAction
 152        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) ξ := by
 153  rw [canonicalJQuadraticTerm_eq_dirichlet]
 154  rw [canonicalPeriodicEdgeStencilTarget Nx Ny Nz hx hy hz ξ]
 155
 156/-- The concrete local nonlinear Regge/J-cost correspondence on the canonical
 157periodic Freudenthal torus, with the quadratic term written as the real
 158edge-stencil Dirichlet operator. -/
 159def CanonicalPeriodicEdgeStencilLocalCorrespondence
 160    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 161    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
 162  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
 163  ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
 164    ∀ ξ : VertexPotential P.K, ‖ξ‖ < r →
 165      ‖reggeAction P.K P.hK ξ -
 166          reggeAction P.K P.hK (zeroPotential P.K) -
 167          (1 / 2) * periodicEdgeStencilDirichletAction P ξ‖ ≤
 168        C * ‖ξ‖ ^ (3 : ℕ)
 169
 170/-- Concrete periodic Freudenthal form of the strongest true replacement:
 171the full nonlinear Regge action is its flat value plus one half of the periodic
 172edge-stencil/J quadratic energy, up to a controlled cubic remainder. -/
 173def CanonicalPeriodicStrongestTrueReplacement
 174    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 175    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
 176  CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz
 177
 178theorem canonicalPeriodicStrongestTrueReplacement_iff_edgeStencilLocalCorrespondence
 179    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 180    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
 181    CanonicalPeriodicStrongestTrueReplacement Nx Ny Nz hx hy hz ↔
 182      CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
 183  Iff.rfl
 184
 185theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_taylor
 186    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 187    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 188    (hTaylor :
 189      NonlinearReggeCubicTaylorTheorem
 190        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 191        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK) :
 192    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz := by
 193  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
 194  have hLocal := nonlinearRegge_localCorrespondence_of_taylorTheorem P.K P.hK hTaylor
 195  rcases hLocal with ⟨r, C, hr, hC, hineq⟩
 196  refine ⟨r, C, hr, hC, ?_⟩
 197  intro ξ hξ
 198  have hJ := canonicalPeriodicJQuadraticTerm_eq_edgeStencil Nx Ny Nz hx hy hz ξ
 199  simpa [CanonicalPeriodicEdgeStencilLocalCorrespondence, P, hJ]
 200    using hineq ξ hξ
 201
 202/-- Periodic Freudenthal local correspondence from the now-closed line-Taylor
 203cascade.  The remaining caller data are the flat configuration and the standard
 204remainder first/second variation jets; the cubic Taylor estimate itself is no
 205longer a separate input. -/
 206theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_flat_and_remainderJets
 207    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 208    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 209    (hFlat :
 210      FlatConfiguration
 211        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 212        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 213    (hFirst :
 214      ReggeActionRemainderFirstVariationInput
 215        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 216        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 217        (canonicalReggeHessian
 218          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 219          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK))
 220    (hSecond :
 221      ReggeActionRemainderSecondVariationInput
 222        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 223        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK) :
 224    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz := by
 225  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
 226  exact canonicalPeriodicEdgeStencilLocalCorrespondence_of_taylor Nx Ny Nz hx hy hz
 227    (nonlinearReggeCubicTaylorTheorem_of_flat_and_remainderJets
 228      P.K P.hK hFlat hFirst hSecond)
 229
 230/-- Periodic Freudenthal local correspondence from flatness, the remainder
 231first variation, and the nonlinear directional Hessian theorem.  The Hessian
 232theorem supplies the remainder second-variation jet; the closed line-Taylor
 233cascade then supplies the cubic remainder bound. -/
 234theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_flat_first_and_directionalHessian
 235    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 236    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 237    (hFlat :
 238      FlatConfiguration
 239        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 240        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 241    (hFirst :
 242      ReggeActionRemainderFirstVariationInput
 243        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 244        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 245        (canonicalReggeHessian
 246          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 247          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK))
 248    (hHessian :
 249      NonlinearReggeDirectionalHessianTheorem
 250        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 251        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK) :
 252    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz := by
 253  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
 254  exact canonicalPeriodicEdgeStencilLocalCorrespondence_of_flat_and_remainderJets
 255    Nx Ny Nz hx hy hz hFlat hFirst
 256    (reggeActionRemainderSecondVariationInput_of_flat_directionalHessian
 257      P.K P.hK hFlat hHessian)
 258
 259theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_eventuallyZero_edgeStencil_and_taylor
 260    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 261    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 262    (hFlat :
 263      FlatConfiguration
 264        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 265        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 266    (D : DeficitAngleDirectionalDerivativePackage
 267      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 268      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 269    (hZero :
 270      WeightedDeficitDerivativeEventuallyZeroTarget
 271        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 272        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 273        hFlat)
 274    (hMixed :
 275      MixedHingeDeficitEdgeStencilTarget
 276        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 277        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 278        D)
 279    (hTaylor :
 280      NonlinearReggeCubicTaylorTheorem
 281        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 282        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK) :
 283    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz := by
 284  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
 285  have hLocal :=
 286    nonlinearRegge_localCorrespondence_of_eventuallyZero_edgeStencil_and_taylor
 287      P.K P.hK hFlat D hZero hMixed
 288      (canonicalPeriodicEdgeStencilTarget Nx Ny Nz hx hy hz) hTaylor
 289  rcases hLocal with ⟨r, C, hr, hC, hineq⟩
 290  refine ⟨r, C, hr, hC, ?_⟩
 291  intro ξ hξ
 292  have hJ := canonicalPeriodicJQuadraticTerm_eq_edgeStencil Nx Ny Nz hx hy hz ξ
 293  simpa [CanonicalPeriodicEdgeStencilLocalCorrespondence, P, hJ]
 294    using hineq ξ hξ
 295
 296theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_localHessianTaylorInputs
 297    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 298    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 299    (hFlat :
 300      FlatConfiguration
 301        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 302        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 303    (hInputs :
 304      NonlinearReggeLocalHessianTaylorInputs
 305        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 306        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 307        hFlat) :
 308    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz := by
 309  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
 310  have hLocal :=
 311    nonlinearRegge_localCorrespondence_of_localHessianTaylorInputs
 312      P.K P.hK hFlat hInputs
 313  rcases hLocal with ⟨r, C, hr, hC, hineq⟩
 314  refine ⟨r, C, hr, hC, ?_⟩
 315  intro ξ hξ
 316  have hJ := canonicalPeriodicJQuadraticTerm_eq_edgeStencil Nx Ny Nz hx hy hz ξ
 317  simpa [CanonicalPeriodicEdgeStencilLocalCorrespondence, P, hJ]
 318    using hineq ξ hξ
 319
 320theorem canonicalPeriodicStrongestTrueReplacement_of_localHessianTaylorInputs
 321    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 322    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 323    (hFlat :
 324      FlatConfiguration
 325        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 326        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 327    (hInputs :
 328      NonlinearReggeLocalHessianTaylorInputs
 329        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 330        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 331        hFlat) :
 332    CanonicalPeriodicStrongestTrueReplacement Nx Ny Nz hx hy hz :=
 333  canonicalPeriodicEdgeStencilLocalCorrespondence_of_localHessianTaylorInputs
 334    Nx Ny Nz hx hy hz hFlat hInputs
 335
 336/-- The theorem data needed to identify the encoded periodic Freudenthal torus
 337with the physical cubic Dirichlet model. -/
 338structure PeriodicFreudenthalDirichletCertificate
 339    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 340    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) where
 341  latticeSpacing : ℝ
 342  spacing_pos : 0 < latticeSpacing
 343  continuumAction : VertexPotential P.K → ℝ
 344  errorConstant : ℝ
 345  errorConstant_nonneg : 0 ≤ errorConstant
 346  sixTetCubicDecomposition : Prop
 347  canonicalHessian_is_dirichlet : Prop
 348  physicalFiniteDifferenceAction : PhysicalFiniteDifferenceDirichletAction P
 349  physicalFiniteDifference_identification :
 350    PhysicalFiniteDifferenceDirichletTarget P physicalFiniteDifferenceAction
 351  finiteDifferenceEstimate :
 352    ∀ ξ : VertexPotential P.K,
 353      |reggeActionSecondOrder P.K P.hK (canonicalReggeHessian P.K P.hK) ξ -
 354        continuumAction ξ| ≤ errorConstant * latticeSpacing ^ (2 : ℕ)
 355
 356def regularModel_of_periodicFreudenthalCertificate
 357    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 358    {P : EncodedPeriodicFreudenthalTorus Nx Ny Nz}
 359    (C : PeriodicFreudenthalDirichletCertificate P) :
 360    RegularCubicLatticeModel P.K P.hK where
 361  latticeSpacing := C.latticeSpacing
 362  spacing_pos := C.spacing_pos
 363  continuumAction := C.continuumAction
 364  errorConstant := C.errorConstant
 365  errorConstant_nonneg := C.errorConstant_nonneg
 366  secondOrder_action_error := C.finiteDifferenceEstimate
 367
 368def physicalSixTetModel_of_periodicFreudenthalCertificate
 369    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 370    {P : EncodedPeriodicFreudenthalTorus Nx Ny Nz}
 371    (C : PeriodicFreudenthalDirichletCertificate P) :
 372    PhysicalSixTetCubicDirichletModel P.K P.hK where
 373  regularModel := regularModel_of_periodicFreudenthalCertificate C
 374  sixTetCubicDecomposition := C.sixTetCubicDecomposition
 375  canonicalHessian_is_dirichlet := C.canonicalHessian_is_dirichlet
 376  finiteDifferenceEstimate := C.finiteDifferenceEstimate
 377
 378def cubicLimitInput_of_periodicFreudenthalCertificate
 379    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 380    {P : EncodedPeriodicFreudenthalTorus Nx Ny Nz}
 381    (C : PeriodicFreudenthalDirichletCertificate P) :
 382    ReggeCubicLatticeLimitInput P.K P.hK :=
 383  cubicLatticeLimitInput_of_physicalSixTetModel P.K P.hK
 384    (physicalSixTetModel_of_periodicFreudenthalCertificate C)
 385
 386theorem periodicFreudenthalCertificate_cubicLimit
 387    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 388    {P : EncodedPeriodicFreudenthalTorus Nx Ny Nz}
 389    (C : PeriodicFreudenthalDirichletCertificate P) :
 390    ReggeSecondOrderCubicLatticeLimit P.K P.hK
 391      (regularModel_of_periodicFreudenthalCertificate C) :=
 392  C.finiteDifferenceEstimate
 393
 394/-- Refinement-family convergence at the physical periodic-Freudenthal
 395certificate layer.  This connects the six-tet/edge-stencil certificate path to
 396the abstract cubic-lattice convergence wrapper: once the certified
 397`C a^2` envelope tends to zero, the second-order Regge action converges
 398pointwise to the supplied continuum action. -/
 399theorem periodicFreudenthalCertificate_error_vanishes_along_family
 400    {α : Type*} {l : Filter α}
 401    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 402    {P : EncodedPeriodicFreudenthalTorus Nx Ny Nz}
 403    (C : α → PeriodicFreudenthalDirichletCertificate P)
 404    (hEnvelope :
 405      Filter.Tendsto
 406        (fun t : α => (C t).errorConstant * (C t).latticeSpacing ^ (2 : ℕ))
 407        l (nhds 0))
 408    (ξ : VertexPotential P.K) :
 409    Filter.Tendsto
 410      (fun t : α =>
 411        |reggeActionSecondOrder P.K P.hK (canonicalReggeHessian P.K P.hK) ξ -
 412          (C t).continuumAction ξ|)
 413      l (nhds 0) := by
 414  exact
 415    reggeSecondOrderCubicLatticeLimit_error_vanishes_along_models
 416      P.K P.hK
 417      (fun t : α => regularModel_of_periodicFreudenthalCertificate (C t))
 418      (fun t => periodicFreudenthalCertificate_cubicLimit (C t))
 419      hEnvelope ξ
 420
 421/-- Usable refinement criterion for Track 1.B: if the certificate error
 422constants are uniformly bounded and the lattice spacing tends to zero, then the
 423physical periodic-Freudenthal certificate family converges pointwise. -/
 424theorem periodicFreudenthalCertificate_error_vanishes_of_bounded_error_and_spacing
 425    {α : Type*} {l : Filter α}
 426    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 427    {P : EncodedPeriodicFreudenthalTorus Nx Ny Nz}
 428    (C : α → PeriodicFreudenthalDirichletCertificate P)
 429    (B : ℝ)
 430    (hBound : ∀ t : α, (C t).errorConstant ≤ B)
 431    (hSpacing : Filter.Tendsto (fun t : α => (C t).latticeSpacing) l (nhds 0))
 432    (ξ : VertexPotential P.K) :
 433    Filter.Tendsto
 434      (fun t : α =>
 435        |reggeActionSecondOrder P.K P.hK (canonicalReggeHessian P.K P.hK) ξ -
 436          (C t).continuumAction ξ|)
 437      l (nhds 0) := by
 438  have hEnvelope :
 439      Filter.Tendsto
 440        (fun t : α => (C t).errorConstant * (C t).latticeSpacing ^ (2 : ℕ))
 441        l (nhds 0) := by
 442    apply squeeze_zero
 443    · intro t
 444      exact mul_nonneg (C t).errorConstant_nonneg (sq_nonneg (C t).latticeSpacing)
 445    · intro t
 446      exact mul_le_mul_of_nonneg_right (hBound t) (sq_nonneg (C t).latticeSpacing)
 447    · have hcont : Continuous (fun a : ℝ => B * a ^ (2 : ℕ)) := by
 448        continuity
 449      have ht := hcont.tendsto (0 : ℝ)
 450      simpa using ht.comp hSpacing
 451  exact periodicFreudenthalCertificate_error_vanishes_along_family C hEnvelope ξ
 452
 453/-- A refinement-indexed family of physical periodic-Freudenthal certificates
 454with exactly the hypotheses needed for pointwise second-order convergence. -/
 455structure PeriodicFreudenthalRefinementFamily
 456    {α : Type*} (l : Filter α)
 457    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 458    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) where
 459  cert : α → PeriodicFreudenthalDirichletCertificate P
 460  errorBound : ℝ
 461  error_bound : ∀ t : α, (cert t).errorConstant ≤ errorBound
 462  spacing_tendsto_zero :
 463    Filter.Tendsto (fun t : α => (cert t).latticeSpacing) l (nhds 0)
 464
 465theorem PeriodicFreudenthalRefinementFamily.pointwise_converges
 466    {α : Type*} {l : Filter α}
 467    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 468    {P : EncodedPeriodicFreudenthalTorus Nx Ny Nz}
 469    (F : PeriodicFreudenthalRefinementFamily l P)
 470    (ξ : VertexPotential P.K) :
 471    Filter.Tendsto
 472      (fun t : α =>
 473        |reggeActionSecondOrder P.K P.hK (canonicalReggeHessian P.K P.hK) ξ -
 474          (F.cert t).continuumAction ξ|)
 475      l (nhds 0) :=
 476  periodicFreudenthalCertificate_error_vanishes_of_bounded_error_and_spacing
 477    F.cert F.errorBound F.error_bound F.spacing_tendsto_zero ξ
 478
 479/-- Transfer from a spacing-dependent continuum comparison action to a fixed
 480continuum action.  Once the certificate family proves
 481`S_Regge(a) - S_cont(a) → 0`, it is enough to prove
 482`S_cont(a) → S_continuum` to get `S_Regge(a) → S_continuum`. -/
 483theorem PeriodicFreudenthalRefinementFamily.pointwise_converges_to_fixed_limit
 484    {α : Type*} {l : Filter α}
 485    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 486    {P : EncodedPeriodicFreudenthalTorus Nx Ny Nz}
 487    (F : PeriodicFreudenthalRefinementFamily l P)
 488    (limitAction : VertexPotential P.K → ℝ)
 489    (ξ : VertexPotential P.K)
 490    (hContinuum :
 491      Filter.Tendsto (fun t : α => (F.cert t).continuumAction ξ)
 492        l (nhds (limitAction ξ))) :
 493    Filter.Tendsto
 494      (fun _t : α =>
 495        reggeActionSecondOrder P.K P.hK (canonicalReggeHessian P.K P.hK) ξ)
 496      l (nhds (limitAction ξ)) := by
 497  apply tendsto_iff_dist_tendsto_zero.mpr
 498  have hRegge := F.pointwise_converges ξ
 499  have hContinuumAbs :
 500      Filter.Tendsto
 501        (fun t : α => |(F.cert t).continuumAction ξ - limitAction ξ|)
 502        l (nhds 0) := by
 503    have hdist := tendsto_iff_dist_tendsto_zero.mp hContinuum
 504    simpa [Real.dist_eq] using hdist
 505  have hsum := hRegge.add hContinuumAbs
 506  apply squeeze_zero
 507  · intro t
 508    exact dist_nonneg
 509  · intro t
 510    let R := reggeActionSecondOrder P.K P.hK (canonicalReggeHessian P.K P.hK) ξ
 511    let C := (F.cert t).continuumAction ξ
 512    let L := limitAction ξ
 513    calc
 514      dist R L = |R - L| := by
 515        simp [Real.dist_eq]
 516      _ = |(R - C) + (C - L)| := by
 517        congr 1
 518        ring
 519      _ ≤ |R - C| + |C - L| := abs_add_le _ _
 520  · simpa [Real.dist_eq] using hsum
 521
 522/-- Exact-comparison sanity certificate for an encoded periodic Freudenthal
 523torus.  The continuum action is chosen to be the canonical second-order Regge
 524action itself, so the error bound is zero.  This does not replace the physical
 525finite-difference Dirichlet identification; it proves the certificate pathway
 526is inhabited for every encoded periodic torus. -/
 527def exactPeriodicFreudenthalComparisonCertificate
 528    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 529    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) :
 530    PeriodicFreudenthalDirichletCertificate P where
 531  latticeSpacing := 1
 532  spacing_pos := by norm_num
 533  continuumAction := reggeActionSecondOrder P.K P.hK (canonicalReggeHessian P.K P.hK)
 534  errorConstant := 0
 535  errorConstant_nonneg := le_rfl
 536  sixTetCubicDecomposition := True
 537  canonicalHessian_is_dirichlet := CanonicalHessianIsDirichlet P
 538  physicalFiniteDifferenceAction := canonicalDirichletEnergy P.K P.hK
 539  physicalFiniteDifference_identification := by
 540    intro ξ
 541    rfl
 542  finiteDifferenceEstimate := by
 543    intro ξ
 544    simp
 545
 546/-- Exact-comparison certificate with an arbitrary positive lattice spacing.
 547This is the spacing-varying version needed for refinement-indexed families. -/
 548def exactPeriodicFreudenthalComparisonCertificateAtSpacing
 549    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 550    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz)
 551    (a : ℝ) (ha : 0 < a) :
 552    PeriodicFreudenthalDirichletCertificate P where
 553  latticeSpacing := a
 554  spacing_pos := ha
 555  continuumAction := reggeActionSecondOrder P.K P.hK (canonicalReggeHessian P.K P.hK)
 556  errorConstant := 0
 557  errorConstant_nonneg := le_rfl
 558  sixTetCubicDecomposition := True
 559  canonicalHessian_is_dirichlet := CanonicalHessianIsDirichlet P
 560  physicalFiniteDifferenceAction := canonicalDirichletEnergy P.K P.hK
 561  physicalFiniteDifference_identification := by
 562    intro ξ
 563    rfl
 564  finiteDifferenceEstimate := by
 565    intro ξ
 566    simp
 567
 568/-- The spacing-varying exact comparison certificates converge along any
 569refinement schedule whose lattice spacing tends to zero.  This theorem is a
 570certificate-path sanity check, not the physical continuum normalization. -/
 571theorem exactPeriodicFreudenthalComparisonCertificateAtSpacing_converges
 572    {α : Type*} {l : Filter α}
 573    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
 574    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz)
 575    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
 576    (hSpacing : Filter.Tendsto a l (nhds 0))
 577    (ξ : VertexPotential P.K) :
 578    Filter.Tendsto
 579      (fun t : α =>
 580        |reggeActionSecondOrder P.K P.hK (canonicalReggeHessian P.K P.hK) ξ -
 581          (exactPeriodicFreudenthalComparisonCertificateAtSpacing P (a t) (ha t)).continuumAction ξ|)
 582      l (nhds 0) := by
 583  exact
 584    periodicFreudenthalCertificate_error_vanishes_of_bounded_error_and_spacing
 585      (fun t : α => exactPeriodicFreudenthalComparisonCertificateAtSpacing P (a t) (ha t))
 586      0
 587      (by
 588        intro t
 589        simp [exactPeriodicFreudenthalComparisonCertificateAtSpacing])
 590      (by
 591        simpa [exactPeriodicFreudenthalComparisonCertificateAtSpacing] using hSpacing)
 592      ξ
 593
 594/-- Canonical periodic certificate using the actual periodic edge-stencil
 595Dirichlet action as the finite-difference operator.  The continuum comparison
 596is still the exact second-order Regge comparison, so this closes the operator
 597identification without claiming the separate continuum-normalization estimate. -/
 598def canonicalPeriodicEdgeStencilComparisonCertificate
 599    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 600    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
 601    PeriodicFreudenthalDirichletCertificate
 602      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) where
 603  latticeSpacing := 1
 604  spacing_pos := by norm_num
 605  continuumAction :=
 606    reggeActionSecondOrder
 607      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 608      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 609      (canonicalReggeHessian
 610        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 611        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 612  errorConstant := 0
 613  errorConstant_nonneg := le_rfl
 614  sixTetCubicDecomposition := True
 615  canonicalHessian_is_dirichlet :=
 616    CanonicalHessianIsDirichlet
 617      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz)
 618  physicalFiniteDifferenceAction :=
 619    periodicEdgeStencilDirichletAction
 620      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz)
 621  physicalFiniteDifference_identification :=
 622    canonicalPeriodicEdgeStencilTarget Nx Ny Nz hx hy hz
 623  finiteDifferenceEstimate := by
 624    intro ξ
 625    simp
 626
 627/-- Canonical periodic edge-stencil certificate with arbitrary positive lattice
 628spacing.  This is the spacing-varying canonical periodic family used by the
 629refinement criterion. -/
 630def canonicalPeriodicEdgeStencilComparisonCertificateAtSpacing
 631    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 632    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 633    (a : ℝ) (ha : 0 < a) :
 634    PeriodicFreudenthalDirichletCertificate
 635      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) where
 636  latticeSpacing := a
 637  spacing_pos := ha
 638  continuumAction :=
 639    reggeActionSecondOrder
 640      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 641      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 642      (canonicalReggeHessian
 643        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 644        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 645  errorConstant := 0
 646  errorConstant_nonneg := le_rfl
 647  sixTetCubicDecomposition := True
 648  canonicalHessian_is_dirichlet :=
 649    CanonicalHessianIsDirichlet
 650      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz)
 651  physicalFiniteDifferenceAction :=
 652    periodicEdgeStencilDirichletAction
 653      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz)
 654  physicalFiniteDifference_identification :=
 655    canonicalPeriodicEdgeStencilTarget Nx Ny Nz hx hy hz
 656  finiteDifferenceEstimate := by
 657    intro ξ
 658    simp
 659
 660/-- Canonical periodic edge-stencil certificate with a supplied physical
 661continuum comparison action and a supplied `C a^2` estimate.  This is the
 662non-exact certificate constructor needed for the real Track 1.B continuum
 663normalization step. -/
 664def canonicalPeriodicEdgeStencilContinuumCertificateAtSpacing
 665    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 666    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 667    (a : ℝ) (ha : 0 < a)
 668    (continuumAction :
 669      VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K → ℝ)
 670    (errorConstant : ℝ) (hErrorNonneg : 0 ≤ errorConstant)
 671    (hEstimate :
 672      ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
 673        |reggeActionSecondOrder
 674            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 675            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 676            (canonicalReggeHessian
 677              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 678              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 679            ξ - continuumAction ξ| ≤ errorConstant * a ^ (2 : ℕ)) :
 680    PeriodicFreudenthalDirichletCertificate
 681      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) where
 682  latticeSpacing := a
 683  spacing_pos := ha
 684  continuumAction := continuumAction
 685  errorConstant := errorConstant
 686  errorConstant_nonneg := hErrorNonneg
 687  sixTetCubicDecomposition := True
 688  canonicalHessian_is_dirichlet :=
 689    CanonicalHessianIsDirichlet
 690      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz)
 691  physicalFiniteDifferenceAction :=
 692    periodicEdgeStencilDirichletAction
 693      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz)
 694  physicalFiniteDifference_identification :=
 695    canonicalPeriodicEdgeStencilTarget Nx Ny Nz hx hy hz
 696  finiteDifferenceEstimate := hEstimate
 697
 698/-- Spacing-refinement convergence for the canonical periodic edge-stencil
 699certificate family.  This is the first actual spacing-varying periodic
 700Freudenthal certificate path into the Track 1.B second-order convergence
 701wrapper. -/
 702theorem canonicalPeriodicEdgeStencilComparisonCertificateAtSpacing_converges
 703    {α : Type*} {l : Filter α}
 704    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 705    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 706    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
 707    (hSpacing : Filter.Tendsto a l (nhds 0))
 708    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
 709    Filter.Tendsto
 710      (fun t : α =>
 711        |reggeActionSecondOrder
 712            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 713            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 714            (canonicalReggeHessian
 715              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 716              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 717            ξ -
 718          (canonicalPeriodicEdgeStencilComparisonCertificateAtSpacing Nx Ny Nz hx hy hz
 719            (a t) (ha t)).continuumAction ξ|)
 720      l (nhds 0) := by
 721  exact
 722    periodicFreudenthalCertificate_error_vanishes_of_bounded_error_and_spacing
 723      (fun t : α =>
 724        canonicalPeriodicEdgeStencilComparisonCertificateAtSpacing Nx Ny Nz hx hy hz (a t) (ha t))
 725      0
 726      (by
 727        intro t
 728        simp [canonicalPeriodicEdgeStencilComparisonCertificateAtSpacing])
 729      (by
 730        simpa [canonicalPeriodicEdgeStencilComparisonCertificateAtSpacing] using hSpacing)
 731      ξ
 732
 733def canonicalPeriodicEdgeStencilRefinementFamily
 734    {α : Type*} {l : Filter α}
 735    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 736    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 737    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
 738    (hSpacing : Filter.Tendsto a l (nhds 0)) :
 739    PeriodicFreudenthalRefinementFamily l
 740      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) where
 741  cert := fun t =>
 742    canonicalPeriodicEdgeStencilComparisonCertificateAtSpacing Nx Ny Nz hx hy hz
 743      (a t) (ha t)
 744  errorBound := 0
 745  error_bound := by
 746    intro t
 747    simp [canonicalPeriodicEdgeStencilComparisonCertificateAtSpacing]
 748  spacing_tendsto_zero := by
 749    simpa [canonicalPeriodicEdgeStencilComparisonCertificateAtSpacing] using hSpacing
 750
 751theorem canonicalPeriodicEdgeStencilRefinementFamily_pointwise_converges
 752    {α : Type*} {l : Filter α}
 753    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 754    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 755    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
 756    (hSpacing : Filter.Tendsto a l (nhds 0))
 757    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
 758    Filter.Tendsto
 759      (fun t : α =>
 760        |reggeActionSecondOrder
 761            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 762            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 763            (canonicalReggeHessian
 764              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 765              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 766            ξ -
 767          ((canonicalPeriodicEdgeStencilRefinementFamily Nx Ny Nz hx hy hz a ha hSpacing).cert t).continuumAction ξ|)
 768      l (nhds 0) :=
 769  (canonicalPeriodicEdgeStencilRefinementFamily Nx Ny Nz hx hy hz a ha hSpacing).pointwise_converges ξ
 770
 771/-- Refinement-family constructor for the true physical continuum comparison
 772path: each spacing gets a canonical periodic edge-stencil certificate with a
 773supplied continuum action and a supplied `C a^2` estimate.  Uniform boundedness
 774of the supplied constants is the only analytic hypothesis needed by the
 775abstract convergence wrapper. -/
 776def canonicalPeriodicEdgeStencilContinuumRefinementFamily
 777    {α : Type*} {l : Filter α}
 778    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 779    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 780    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
 781    (hSpacing : Filter.Tendsto a l (nhds 0))
 782    (continuumAction :
 783      α →
 784        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K → ℝ)
 785    (errorConstant : α → ℝ)
 786    (hErrorNonneg : ∀ t : α, 0 ≤ errorConstant t)
 787    (B : ℝ) (hBound : ∀ t : α, errorConstant t ≤ B)
 788    (hEstimate :
 789      ∀ t : α,
 790        ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
 791          |reggeActionSecondOrder
 792              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 793              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 794              (canonicalReggeHessian
 795                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 796                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 797              ξ - continuumAction t ξ| ≤ errorConstant t * a t ^ (2 : ℕ)) :
 798    PeriodicFreudenthalRefinementFamily l
 799      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) where
 800  cert := fun t =>
 801    canonicalPeriodicEdgeStencilContinuumCertificateAtSpacing
 802      Nx Ny Nz hx hy hz (a t) (ha t) (continuumAction t)
 803      (errorConstant t) (hErrorNonneg t) (hEstimate t)
 804  errorBound := B
 805  error_bound := by
 806    intro t
 807    simpa [canonicalPeriodicEdgeStencilContinuumCertificateAtSpacing] using hBound t
 808  spacing_tendsto_zero := by
 809    simpa [canonicalPeriodicEdgeStencilContinuumCertificateAtSpacing] using hSpacing
 810
 811theorem canonicalPeriodicEdgeStencilContinuumRefinementFamily_pointwise_converges
 812    {α : Type*} {l : Filter α}
 813    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 814    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 815    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
 816    (hSpacing : Filter.Tendsto a l (nhds 0))
 817    (continuumAction :
 818      α →
 819        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K → ℝ)
 820    (errorConstant : α → ℝ)
 821    (hErrorNonneg : ∀ t : α, 0 ≤ errorConstant t)
 822    (B : ℝ) (hBound : ∀ t : α, errorConstant t ≤ B)
 823    (hEstimate :
 824      ∀ t : α,
 825        ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
 826          |reggeActionSecondOrder
 827              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 828              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 829              (canonicalReggeHessian
 830                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 831                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 832              ξ - continuumAction t ξ| ≤ errorConstant t * a t ^ (2 : ℕ))
 833    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
 834    Filter.Tendsto
 835      (fun t : α =>
 836        |reggeActionSecondOrder
 837            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 838            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 839            (canonicalReggeHessian
 840              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 841              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 842            ξ -
 843          ((canonicalPeriodicEdgeStencilContinuumRefinementFamily
 844            Nx Ny Nz hx hy hz a ha hSpacing continuumAction errorConstant
 845            hErrorNonneg B hBound hEstimate).cert t).continuumAction ξ|)
 846      l (nhds 0) :=
 847  (canonicalPeriodicEdgeStencilContinuumRefinementFamily
 848    Nx Ny Nz hx hy hz a ha hSpacing continuumAction errorConstant
 849    hErrorNonneg B hBound hEstimate).pointwise_converges ξ
 850
 851theorem canonicalPeriodicEdgeStencilContinuumRefinementFamily_converges_to_fixed_limit
 852    {α : Type*} {l : Filter α}
 853    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 854    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 855    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
 856    (hSpacing : Filter.Tendsto a l (nhds 0))
 857    (continuumAction :
 858      α →
 859        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K → ℝ)
 860    (errorConstant : α → ℝ)
 861    (hErrorNonneg : ∀ t : α, 0 ≤ errorConstant t)
 862    (B : ℝ) (hBound : ∀ t : α, errorConstant t ≤ B)
 863    (hEstimate :
 864      ∀ t : α,
 865        ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
 866          |reggeActionSecondOrder
 867              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 868              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 869              (canonicalReggeHessian
 870                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 871                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 872              ξ - continuumAction t ξ| ≤ errorConstant t * a t ^ (2 : ℕ))
 873    (limitAction :
 874      VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K → ℝ)
 875    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
 876    (hContinuum :
 877      Filter.Tendsto (fun t : α => continuumAction t ξ) l (nhds (limitAction ξ))) :
 878    Filter.Tendsto
 879      (fun _t : α =>
 880        reggeActionSecondOrder
 881          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 882          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 883          (canonicalReggeHessian
 884            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 885            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 886          ξ)
 887      l (nhds (limitAction ξ)) := by
 888  let F :=
 889    canonicalPeriodicEdgeStencilContinuumRefinementFamily
 890      Nx Ny Nz hx hy hz a ha hSpacing continuumAction errorConstant
 891      hErrorNonneg B hBound hEstimate
 892  exact F.pointwise_converges_to_fixed_limit limitAction ξ (by
 893    simpa [F, canonicalPeriodicEdgeStencilContinuumRefinementFamily] using hContinuum)
 894
 895/-- Data package for the remaining fixed-continuum comparison step in Track
 8961.B.  To instantiate this with Einstein-Hilbert, future work must provide the
 897fixed continuum action, spacing-dependent comparison actions, `C a^2`
 898estimates, bounded constants, and convergence of the spacing-dependent actions
 899to the fixed one. -/
 900structure CanonicalPeriodicFixedContinuumComparisonData
 901    {α : Type*} (l : Filter α)
 902    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 903    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
 904  spacing : α → ℝ
 905  spacing_pos : ∀ t : α, 0 < spacing t
 906  spacing_tendsto_zero : Filter.Tendsto spacing l (nhds 0)
 907  continuumAction :
 908    α →
 909      VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K → ℝ
 910  errorConstant : α → ℝ
 911  error_nonneg : ∀ t : α, 0 ≤ errorConstant t
 912  errorBound : ℝ
 913  error_bound : ∀ t : α, errorConstant t ≤ errorBound
 914  estimate :
 915    ∀ t : α,
 916      ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
 917        |reggeActionSecondOrder
 918            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 919            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 920            (canonicalReggeHessian
 921              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 922              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 923            ξ - continuumAction t ξ| ≤ errorConstant t * spacing t ^ (2 : ℕ)
 924  limitAction :
 925    VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K → ℝ
 926  continuum_tendsto :
 927    ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
 928      Filter.Tendsto (fun t : α => continuumAction t ξ) l (nhds (limitAction ξ))
 929
 930def CanonicalPeriodicFixedContinuumComparisonData.toRefinementFamily
 931    {α : Type*} {l : Filter α}
 932    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 933    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 934    (D : CanonicalPeriodicFixedContinuumComparisonData l Nx Ny Nz hx hy hz) :
 935    PeriodicFreudenthalRefinementFamily l
 936      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) :=
 937  canonicalPeriodicEdgeStencilContinuumRefinementFamily
 938    Nx Ny Nz hx hy hz D.spacing D.spacing_pos D.spacing_tendsto_zero
 939    D.continuumAction D.errorConstant D.error_nonneg D.errorBound
 940    D.error_bound D.estimate
 941
 942theorem CanonicalPeriodicFixedContinuumComparisonData.pointwise_regge_tendsto_limit
 943    {α : Type*} {l : Filter α}
 944    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 945    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 946    (D : CanonicalPeriodicFixedContinuumComparisonData l Nx Ny Nz hx hy hz)
 947    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
 948    Filter.Tendsto
 949      (fun _t : α =>
 950        reggeActionSecondOrder
 951          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 952          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 953          (canonicalReggeHessian
 954            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 955            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 956          ξ)
 957      l (nhds (D.limitAction ξ)) :=
 958  canonicalPeriodicEdgeStencilContinuumRefinementFamily_converges_to_fixed_limit
 959    Nx Ny Nz hx hy hz D.spacing D.spacing_pos D.spacing_tendsto_zero
 960    D.continuumAction D.errorConstant D.error_nonneg D.errorBound
 961    D.error_bound D.estimate D.limitAction ξ (D.continuum_tendsto ξ)
 962
 963/-- Finite-probe aggregate version of the fixed-continuum comparison theorem.
 964This is the finite-dimensional precursor to the later pointwise-to-integral
 965lift in Track 1.B. -/
 966theorem CanonicalPeriodicFixedContinuumComparisonData.finite_probe_regge_tendsto_limit
 967    {α : Type*} {l : Filter α}
 968    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
 969    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
 970    (D : CanonicalPeriodicFixedContinuumComparisonData l Nx Ny Nz hx hy hz)
 971    {n : ℕ}
 972    (probe :
 973      Fin n →
 974        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
 975    Filter.Tendsto
 976      (fun _t : α =>
 977        ∑ i : Fin n,
 978          reggeActionSecondOrder
 979            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 980            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 981            (canonicalReggeHessian
 982              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 983              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 984            (probe i))
 985      l (nhds (∑ i : Fin n, D.limitAction (probe i))) := by
 986  classical
 987  simpa using
 988    (tendsto_finset_sum (Finset.univ : Finset (Fin n))
 989      (f := fun i (_t : α) =>
 990        reggeActionSecondOrder
 991          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 992          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
 993          (canonicalReggeHessian
 994            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
 995            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
 996          (probe i))
 997      (a := fun i => D.limitAction (probe i))
 998      (by
 999        intro i _hi
1000        exact
1001          CanonicalPeriodicFixedContinuumComparisonData.pointwise_regge_tendsto_limit
1002            Nx Ny Nz hx hy hz D (probe i)))
1003
1004/-- Weighted finite-probe aggregate convergence.  This is the Riemann-sum
1005shape needed for later integral approximations: finite probes with fixed
1006weights converge to the weighted fixed-continuum sum. -/
1007theorem CanonicalPeriodicFixedContinuumComparisonData.weighted_finite_probe_regge_tendsto_limit
1008    {α : Type*} {l : Filter α}
1009    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1010    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1011    (D : CanonicalPeriodicFixedContinuumComparisonData l Nx Ny Nz hx hy hz)
1012    {n : ℕ}
1013    (weight : Fin n → ℝ)
1014    (probe :
1015      Fin n →
1016        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1017    Filter.Tendsto
1018      (fun _t : α =>
1019        ∑ i : Fin n,
1020          weight i *
1021            reggeActionSecondOrder
1022              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1023              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1024              (canonicalReggeHessian
1025                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1026                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1027              (probe i))
1028      l (nhds (∑ i : Fin n, weight i * D.limitAction (probe i))) := by
1029  classical
1030  simpa using
1031    (tendsto_finset_sum (Finset.univ : Finset (Fin n))
1032      (f := fun i (_t : α) =>
1033        weight i *
1034          reggeActionSecondOrder
1035            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1036            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1037            (canonicalReggeHessian
1038              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1039              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1040            (probe i))
1041      (a := fun i => weight i * D.limitAction (probe i))
1042      (by
1043        intro i _hi
1044        exact
1045          (tendsto_const_nhds.mul
1046            (CanonicalPeriodicFixedContinuumComparisonData.pointwise_regge_tendsto_limit
1047              Nx Ny Nz hx hy hz D (probe i)))))
1048
1049/-- Variable-weight finite-probe aggregate convergence.  This is the mesh
1050quadrature shape: if the finite probe weights vary with the refinement
1051parameter but converge to fixed limiting weights, then the weighted Regge
1052aggregate converges to the weighted fixed-continuum aggregate. -/
1053theorem CanonicalPeriodicFixedContinuumComparisonData.variable_weighted_finite_probe_regge_tendsto_limit
1054    {α : Type*} {l : Filter α}
1055    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1056    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1057    (D : CanonicalPeriodicFixedContinuumComparisonData l Nx Ny Nz hx hy hz)
1058    {n : ℕ}
1059    (weight : α → Fin n → ℝ)
1060    (limitWeight : Fin n → ℝ)
1061    (hWeight :
1062      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
1063    (probe :
1064      Fin n →
1065        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1066    Filter.Tendsto
1067      (fun t : α =>
1068        ∑ i : Fin n,
1069          weight t i *
1070            reggeActionSecondOrder
1071              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1072              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1073              (canonicalReggeHessian
1074                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1075                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1076              (probe i))
1077      l (nhds (∑ i : Fin n, limitWeight i * D.limitAction (probe i))) := by
1078  classical
1079  simpa using
1080    (tendsto_finset_sum (Finset.univ : Finset (Fin n))
1081      (f := fun i (t : α) =>
1082        weight t i *
1083          reggeActionSecondOrder
1084            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1085            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1086            (canonicalReggeHessian
1087              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1088              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1089            (probe i))
1090      (a := fun i => limitWeight i * D.limitAction (probe i))
1091      (by
1092        intro i _hi
1093        exact
1094          (hWeight i).mul
1095            (CanonicalPeriodicFixedContinuumComparisonData.pointwise_regge_tendsto_limit
1096              Nx Ny Nz hx hy hz D (probe i))))
1097
1098/-- Fixed-weight finite-probe residual convergence.  This is the zero-error
1099form of the weighted aggregate theorem: the discrete weighted Regge sum minus
1100the fixed-continuum weighted sum vanishes along the refinement filter. -/
1101theorem CanonicalPeriodicFixedContinuumComparisonData.weighted_finite_probe_regge_residual_tendsto_zero
1102    {α : Type*} {l : Filter α}
1103    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1104    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1105    (D : CanonicalPeriodicFixedContinuumComparisonData l Nx Ny Nz hx hy hz)
1106    {n : ℕ}
1107    (weight : Fin n → ℝ)
1108    (probe :
1109      Fin n →
1110        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1111    Filter.Tendsto
1112      (fun _t : α =>
1113        (∑ i : Fin n,
1114          weight i *
1115            reggeActionSecondOrder
1116              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1117              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1118              (canonicalReggeHessian
1119                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1120                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1121              (probe i)) -
1122          ∑ i : Fin n, weight i * D.limitAction (probe i))
1123      l (nhds 0) := by
1124  classical
1125  have hConv :=
1126    CanonicalPeriodicFixedContinuumComparisonData.weighted_finite_probe_regge_tendsto_limit
1127      Nx Ny Nz hx hy hz D weight probe
1128  let limitSum : ℝ := ∑ i : Fin n, weight i * D.limitAction (probe i)
1129  have hConst : Filter.Tendsto (fun _t : α => limitSum) l (nhds limitSum) :=
1130    tendsto_const_nhds
1131  simpa [limitSum] using (hConv.sub hConst)
1132
1133/-- Variable-weight finite-probe residual convergence.  This is the
1134Riemann-sum residual form needed for the later integral argument: if the
1135mesh-dependent weights converge, then the difference between the variable
1136weighted Regge aggregate and the limiting weighted continuum aggregate tends
1137to zero. -/
1138theorem CanonicalPeriodicFixedContinuumComparisonData.variable_weighted_finite_probe_regge_residual_tendsto_zero
1139    {α : Type*} {l : Filter α}
1140    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1141    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1142    (D : CanonicalPeriodicFixedContinuumComparisonData l Nx Ny Nz hx hy hz)
1143    {n : ℕ}
1144    (weight : α → Fin n → ℝ)
1145    (limitWeight : Fin n → ℝ)
1146    (hWeight :
1147      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
1148    (probe :
1149      Fin n →
1150        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1151    Filter.Tendsto
1152      (fun t : α =>
1153        (∑ i : Fin n,
1154          weight t i *
1155            reggeActionSecondOrder
1156              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1157              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1158              (canonicalReggeHessian
1159                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1160                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1161              (probe i)) -
1162          ∑ i : Fin n, limitWeight i * D.limitAction (probe i))
1163      l (nhds 0) := by
1164  classical
1165  have hConv :=
1166    CanonicalPeriodicFixedContinuumComparisonData.variable_weighted_finite_probe_regge_tendsto_limit
1167      Nx Ny Nz hx hy hz D weight limitWeight hWeight probe
1168  let limitSum : ℝ := ∑ i : Fin n, limitWeight i * D.limitAction (probe i)
1169  have hConst : Filter.Tendsto (fun _t : α => limitSum) l (nhds limitSum) :=
1170    tendsto_const_nhds
1171  simpa [limitSum] using (hConv.sub hConst)
1172
1173/-- Candidate fixed physical Dirichlet/EH continuum action for the canonical
1174periodic Freudenthal comparison.  The type is intentionally just the action
1175functional on vertex potentials; the analytic burden is carried by the
1176comparison-data structures below. -/
1177abbrev CanonicalPeriodicFixedPhysicalContinuumAction
1178    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1179    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :=
1180  VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K → ℝ
1181
1182/-- Fixed-action specialization of the Track 1.B comparison data.  This is the
1183interface for the physical Dirichlet/EH step when the continuum action is
1184already fixed and only the spacing-dependent `C a^2` estimates remain to be
1185proved. -/
1186structure CanonicalPeriodicFixedPhysicalActionComparisonData
1187    {α : Type*} (l : Filter α)
1188    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1189    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
1190  spacing : α → ℝ
1191  spacing_pos : ∀ t : α, 0 < spacing t
1192  spacing_tendsto_zero : Filter.Tendsto spacing l (nhds 0)
1193  fixedAction : CanonicalPeriodicFixedPhysicalContinuumAction Nx Ny Nz hx hy hz
1194  errorConstant : α → ℝ
1195  error_nonneg : ∀ t : α, 0 ≤ errorConstant t
1196  errorBound : ℝ
1197  error_bound : ∀ t : α, errorConstant t ≤ errorBound
1198  estimate :
1199    ∀ t : α,
1200      ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
1201        |reggeActionSecondOrder
1202            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1203            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1204            (canonicalReggeHessian
1205              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1206              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1207            ξ - fixedAction ξ| ≤ errorConstant t * spacing t ^ (2 : ℕ)
1208
1209def CanonicalPeriodicFixedPhysicalActionComparisonData.toFixedContinuumComparisonData
1210    {α : Type*} {l : Filter α}
1211    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1212    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1213    (D : CanonicalPeriodicFixedPhysicalActionComparisonData l Nx Ny Nz hx hy hz) :
1214    CanonicalPeriodicFixedContinuumComparisonData l Nx Ny Nz hx hy hz where
1215  spacing := D.spacing
1216  spacing_pos := D.spacing_pos
1217  spacing_tendsto_zero := D.spacing_tendsto_zero
1218  continuumAction := fun _t => D.fixedAction
1219  errorConstant := D.errorConstant
1220  error_nonneg := D.error_nonneg
1221  errorBound := D.errorBound
1222  error_bound := D.error_bound
1223  estimate := D.estimate
1224  limitAction := D.fixedAction
1225  continuum_tendsto := by
1226    intro ξ
1227    exact tendsto_const_nhds
1228
1229/-- Pointwise convergence to a fixed physical Dirichlet/EH action, once the
1230fixed-action `C a^2` estimates are supplied. -/
1231theorem CanonicalPeriodicFixedPhysicalActionComparisonData.pointwise_regge_tendsto_fixed_action
1232    {α : Type*} {l : Filter α}
1233    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1234    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1235    (D : CanonicalPeriodicFixedPhysicalActionComparisonData l Nx Ny Nz hx hy hz)
1236    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1237    Filter.Tendsto
1238      (fun _t : α =>
1239        reggeActionSecondOrder
1240          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1241          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1242          (canonicalReggeHessian
1243            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1244            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1245          ξ)
1246      l (nhds (D.fixedAction ξ)) :=
1247  CanonicalPeriodicFixedContinuumComparisonData.pointwise_regge_tendsto_limit
1248    Nx Ny Nz hx hy hz
1249    (D.toFixedContinuumComparisonData Nx Ny Nz hx hy hz) ξ
1250
1251/-- Fixed-weight finite-probe residual convergence specialized to a fixed
1252physical Dirichlet/EH action. -/
1253theorem CanonicalPeriodicFixedPhysicalActionComparisonData.weighted_finite_probe_residual_tendsto_zero
1254    {α : Type*} {l : Filter α}
1255    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1256    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1257    (D : CanonicalPeriodicFixedPhysicalActionComparisonData l Nx Ny Nz hx hy hz)
1258    {n : ℕ}
1259    (weight : Fin n → ℝ)
1260    (probe :
1261      Fin n →
1262        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1263    Filter.Tendsto
1264      (fun _t : α =>
1265        (∑ i : Fin n,
1266          weight i *
1267            reggeActionSecondOrder
1268              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1269              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1270              (canonicalReggeHessian
1271                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1272                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1273              (probe i)) -
1274          ∑ i : Fin n, weight i * D.fixedAction (probe i))
1275      l (nhds 0) :=
1276  CanonicalPeriodicFixedContinuumComparisonData.weighted_finite_probe_regge_residual_tendsto_zero
1277    Nx Ny Nz hx hy hz
1278    (D.toFixedContinuumComparisonData Nx Ny Nz hx hy hz)
1279    weight probe
1280
1281/-- Variable-weight finite-probe residual convergence specialized to a fixed
1282physical Dirichlet/EH action.  This is the direct Riemann-sum hook for the
1283fixed-action comparison path. -/
1284theorem CanonicalPeriodicFixedPhysicalActionComparisonData.variable_weighted_finite_probe_residual_tendsto_zero
1285    {α : Type*} {l : Filter α}
1286    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1287    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1288    (D : CanonicalPeriodicFixedPhysicalActionComparisonData l Nx Ny Nz hx hy hz)
1289    {n : ℕ}
1290    (weight : α → Fin n → ℝ)
1291    (limitWeight : Fin n → ℝ)
1292    (hWeight :
1293      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
1294    (probe :
1295      Fin n →
1296        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1297    Filter.Tendsto
1298      (fun t : α =>
1299        (∑ i : Fin n,
1300          weight t i *
1301            reggeActionSecondOrder
1302              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1303              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1304              (canonicalReggeHessian
1305                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1306                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1307              (probe i)) -
1308          ∑ i : Fin n, limitWeight i * D.fixedAction (probe i))
1309      l (nhds 0) :=
1310  CanonicalPeriodicFixedContinuumComparisonData.variable_weighted_finite_probe_regge_residual_tendsto_zero
1311    Nx Ny Nz hx hy hz
1312    (D.toFixedContinuumComparisonData Nx Ny Nz hx hy hz)
1313    weight limitWeight hWeight probe
1314
1315/-- The canonical fixed Dirichlet continuum action on the periodic Freudenthal
1316torus: flat Regge value plus one half of the concrete periodic edge-stencil
1317Dirichlet energy.  This is still the quadratic/Dirichlet continuum action, not
1318the full nonlinear Einstein-Hilbert theorem. -/
1319def canonicalPeriodicFixedDirichletContinuumAction
1320    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1321    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
1322    CanonicalPeriodicFixedPhysicalContinuumAction Nx Ny Nz hx hy hz :=
1323  fun ξ =>
1324    reggeAction
1325        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1326        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1327        (zeroPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) +
1328      (1 / 2) *
1329        periodicEdgeStencilDirichletAction
1330          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) ξ
1331
1332/-- The canonical second-order Regge action is exactly the fixed periodic
1333Dirichlet continuum action.  This closes the fixed Dirichlet action instance
1334of the comparison wrapper with zero error; it does not close the full
1335nonlinear EH convergence theorem. -/
1336theorem canonicalPeriodicFixedDirichletContinuumAction_eq_reggeSecondOrder
1337    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1338    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1339    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1340    canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz ξ =
1341      reggeActionSecondOrder
1342        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1343        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1344        (canonicalReggeHessian
1345          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1346          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1347        ξ := by
1348  unfold canonicalPeriodicFixedDirichletContinuumAction reggeActionSecondOrder
1349  rw [← canonicalPeriodicEdgeStencilTarget Nx Ny Nz hx hy hz ξ]
1350  rw [← canonicalReggeHessian_quadratic_eq_dirichlet
1351    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1352    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1353    ξ]
1354
1355/-- Zero-error fixed-action comparison data for the canonical periodic
1356Dirichlet action along any positive spacing schedule tending to zero. -/
1357def canonicalPeriodicFixedDirichletActionComparisonData
1358    {α : Type*} {l : Filter α}
1359    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1360    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1361    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
1362    (hSpacing : Filter.Tendsto a l (nhds 0)) :
1363    CanonicalPeriodicFixedPhysicalActionComparisonData l Nx Ny Nz hx hy hz where
1364  spacing := a
1365  spacing_pos := ha
1366  spacing_tendsto_zero := hSpacing
1367  fixedAction := canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz
1368  errorConstant := fun _t => 0
1369  error_nonneg := by
1370    intro t
1371    exact le_rfl
1372  errorBound := 0
1373  error_bound := by
1374    intro t
1375    exact le_rfl
1376  estimate := by
1377    intro t ξ
1378    rw [canonicalPeriodicFixedDirichletContinuumAction_eq_reggeSecondOrder]
1379    simp
1380
1381/-- Pointwise convergence for the canonical fixed Dirichlet action instance.
1382The convergence is immediate because this fixed action is exactly the
1383second-order Regge action; the theorem packages that exact instance for the
1384same interface used by the later EH comparison. -/
1385theorem canonicalPeriodicFixedDirichletAction_pointwise_tendsto
1386    {α : Type*} {l : Filter α}
1387    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1388    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1389    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
1390    (hSpacing : Filter.Tendsto a l (nhds 0))
1391    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1392    Filter.Tendsto
1393      (fun _t : α =>
1394        reggeActionSecondOrder
1395          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1396          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1397          (canonicalReggeHessian
1398            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1399            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1400          ξ)
1401      l (nhds (canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz ξ)) :=
1402  CanonicalPeriodicFixedPhysicalActionComparisonData.pointwise_regge_tendsto_fixed_action
1403    Nx Ny Nz hx hy hz
1404    (canonicalPeriodicFixedDirichletActionComparisonData Nx Ny Nz hx hy hz a ha hSpacing)
1405    ξ
1406
1407/-- Fixed-weight finite-probe residual convergence for the exact fixed
1408Dirichlet action instance. -/
1409theorem canonicalPeriodicFixedDirichletAction_weighted_finite_probe_residual_tendsto_zero
1410    {α : Type*} {l : Filter α}
1411    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1412    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1413    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
1414    (hSpacing : Filter.Tendsto a l (nhds 0))
1415    {n : ℕ}
1416    (weight : Fin n → ℝ)
1417    (probe :
1418      Fin n →
1419        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1420    Filter.Tendsto
1421      (fun _t : α =>
1422        (∑ i : Fin n,
1423          weight i *
1424            reggeActionSecondOrder
1425              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1426              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1427              (canonicalReggeHessian
1428                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1429                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1430              (probe i)) -
1431          ∑ i : Fin n,
1432            weight i *
1433              canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz (probe i))
1434      l (nhds 0) :=
1435  CanonicalPeriodicFixedPhysicalActionComparisonData.weighted_finite_probe_residual_tendsto_zero
1436    Nx Ny Nz hx hy hz
1437    (canonicalPeriodicFixedDirichletActionComparisonData Nx Ny Nz hx hy hz a ha hSpacing)
1438    weight probe
1439
1440/-- Variable-weight finite-probe residual convergence for the exact fixed
1441Dirichlet action instance. -/
1442theorem canonicalPeriodicFixedDirichletAction_variable_weighted_finite_probe_residual_tendsto_zero
1443    {α : Type*} {l : Filter α}
1444    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1445    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1446    (a : α → ℝ) (ha : ∀ t : α, 0 < a t)
1447    (hSpacing : Filter.Tendsto a l (nhds 0))
1448    {n : ℕ}
1449    (weight : α → Fin n → ℝ)
1450    (limitWeight : Fin n → ℝ)
1451    (hWeight :
1452      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
1453    (probe :
1454      Fin n →
1455        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
1456    Filter.Tendsto
1457      (fun t : α =>
1458        (∑ i : Fin n,
1459          weight t i *
1460            reggeActionSecondOrder
1461              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1462              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1463              (canonicalReggeHessian
1464                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1465                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1466              (probe i)) -
1467          ∑ i : Fin n,
1468            limitWeight i *
1469              canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz (probe i))
1470      l (nhds 0) :=
1471  CanonicalPeriodicFixedPhysicalActionComparisonData.variable_weighted_finite_probe_residual_tendsto_zero
1472    Nx Ny Nz hx hy hz
1473    (canonicalPeriodicFixedDirichletActionComparisonData Nx Ny Nz hx hy hz a ha hSpacing)
1474    weight limitWeight hWeight probe
1475
1476/-- The local nonlinear Regge correspondence, rewritten against the fixed
1477Dirichlet action from the Track 1.B fixed-action pipeline. -/
1478theorem canonicalPeriodicNonlinearResidual_bound_to_fixedDirichlet
1479    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1480    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1481    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1482    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1483      ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
1484        ‖ξ‖ < r →
1485          ‖reggeAction
1486              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1487              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1488              ξ -
1489            canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz ξ‖ ≤
1490            C * ‖ξ‖ ^ (3 : ℕ) := by
1491  rcases hLocal with ⟨r, C, hr, hC, hineq⟩
1492  refine ⟨r, C, hr, hC, ?_⟩
1493  intro ξ hξ
1494  have hResidual :
1495      reggeAction
1496          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1497          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1498          ξ -
1499        canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz ξ =
1500        reggeAction
1501            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1502            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1503            ξ -
1504          reggeAction
1505            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1506            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1507            (zeroPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) -
1508          (1 / 2) *
1509            periodicEdgeStencilDirichletAction
1510              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz) ξ := by
1511    unfold canonicalPeriodicFixedDirichletContinuumAction
1512    ring
1513  rw [hResidual]
1514  exact hineq ξ hξ
1515
1516/-- If a family of perturbations stays inside the local chart and its norm
1517tends to zero, then the full nonlinear Regge action converges to the fixed
1518Dirichlet quadratic action along that family.  This is a local nonlinear
1519residual statement, not the full EH continuum theorem. -/
1520theorem canonicalPeriodicNonlinearResidual_tendsto_zero_to_fixedDirichlet
1521    {α : Type*} {l : Filter α}
1522    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1523    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1524    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1525    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1526      ∀ ξ : α →
1527          VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
1528        (∀ t : α, ‖ξ t‖ < r) →
1529          Filter.Tendsto (fun t : α => ‖ξ t‖) l (nhds 0) →
1530            Filter.Tendsto
1531              (fun t : α =>
1532                ‖reggeAction
1533                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1534                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1535                    (ξ t) -
1536                  canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz (ξ t)‖)
1537              l (nhds 0) := by
1538  rcases canonicalPeriodicNonlinearResidual_bound_to_fixedDirichlet
1539      Nx Ny Nz hx hy hz hLocal with
1540    ⟨r, C, hr, hC, hBound⟩
1541  refine ⟨r, C, hr, hC, ?_⟩
1542  intro ξ hSmall hNorm
1543  have hEnvelope :
1544      Filter.Tendsto (fun t : α => C * ‖ξ t‖ ^ (3 : ℕ)) l (nhds 0) := by
1545    have hcont : Continuous (fun x : ℝ => C * x ^ (3 : ℕ)) := by
1546      continuity
1547    have ht := hcont.tendsto (0 : ℝ)
1548    simpa using ht.comp hNorm
1549  apply squeeze_zero
1550  · intro t
1551    exact norm_nonneg _
1552  · intro t
1553    exact hBound (ξ t) (hSmall t)
1554  · exact hEnvelope
1555
1556/-- Eventual-local-chart version of the nonlinear residual theorem.  The
1557perturbation family only has to be inside the local chart eventually along the
1558filter, which is the form needed for refinement limits. -/
1559theorem canonicalPeriodicNonlinearResidual_tendsto_zero_eventually_to_fixedDirichlet
1560    {α : Type*} {l : Filter α}
1561    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1562    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1563    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1564    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1565      ∀ ξ : α →
1566          VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
1567        (∀ᶠ t : α in l, ‖ξ t‖ < r) →
1568          Filter.Tendsto (fun t : α => ‖ξ t‖) l (nhds 0) →
1569            Filter.Tendsto
1570              (fun t : α =>
1571                ‖reggeAction
1572                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1573                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1574                    (ξ t) -
1575                  canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz (ξ t)‖)
1576              l (nhds 0) := by
1577  rcases canonicalPeriodicNonlinearResidual_bound_to_fixedDirichlet
1578      Nx Ny Nz hx hy hz hLocal with
1579    ⟨r, C, hr, hC, hBound⟩
1580  refine ⟨r, C, hr, hC, ?_⟩
1581  intro ξ hSmallEventually hNorm
1582  have hEnvelope :
1583      Filter.Tendsto (fun t : α => C * ‖ξ t‖ ^ (3 : ℕ)) l (nhds 0) := by
1584    have hcont : Continuous (fun x : ℝ => C * x ^ (3 : ℕ)) := by
1585      continuity
1586    have ht := hcont.tendsto (0 : ℝ)
1587    simpa using ht.comp hNorm
1588  have hNonneg :
1589      ∀ᶠ t : α in l,
1590        0 ≤
1591          ‖reggeAction
1592              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1593              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1594              (ξ t) -
1595            canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz (ξ t)‖ :=
1596    Filter.Eventually.of_forall (fun t => norm_nonneg _)
1597  have hUpper :
1598      ∀ᶠ t : α in l,
1599        ‖reggeAction
1600            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1601            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1602            (ξ t) -
1603          canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz (ξ t)‖ ≤
1604          C * ‖ξ t‖ ^ (3 : ℕ) :=
1605    hSmallEventually.mono (fun t ht => hBound (ξ t) ht)
1606  exact squeeze_zero' hNonneg hUpper hEnvelope
1607
1608/-- Scalar-amplitude specialization of the eventual-local nonlinear residual
1609theorem.  If a fixed perturbation direction is scaled by an amplitude tending
1610to zero, then the full nonlinear Regge residual against the fixed Dirichlet
1611quadratic action tends to zero. -/
1612theorem canonicalPeriodicNonlinearResidual_tendsto_zero_scaled_to_fixedDirichlet
1613    {α : Type*} {l : Filter α}
1614    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1615    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1616    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1617    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1618      ∀ (amp : α → ℝ)
1619        (probe :
1620          VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K),
1621        Filter.Tendsto amp l (nhds 0) →
1622          Filter.Tendsto
1623            (fun t : α =>
1624              ‖reggeAction
1625                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1626                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1627                  (amp t • probe) -
1628                canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz
1629                  (amp t • probe)‖)
1630            l (nhds 0) := by
1631  rcases canonicalPeriodicNonlinearResidual_tendsto_zero_eventually_to_fixedDirichlet
1632      Nx Ny Nz hx hy hz hLocal with
1633    ⟨r, C, hr, hC, hResidual⟩
1634  refine ⟨r, C, hr, hC, ?_⟩
1635  intro amp probe hAmp
1636  let ξ : α →
1637      VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K :=
1638    fun t => amp t • probe
1639  have hNorm : Filter.Tendsto (fun t : α => ‖ξ t‖) l (nhds 0) := by
1640    have hAmpNorm : Filter.Tendsto (fun t : α => ‖amp t‖) l (nhds (0 : ℝ)) := by
1641      simpa using hAmp.norm
1642    have hMul :
1643        Filter.Tendsto (fun t : α => ‖amp t‖ * ‖probe‖) l
1644          (nhds ((0 : ℝ) * ‖probe‖)) :=
1645      hAmpNorm.mul tendsto_const_nhds
1646    simpa [ξ, norm_smul] using hMul
1647  have hSmallEventually : ∀ᶠ t : α in l, ‖ξ t‖ < r := by
1648    have hDist := (Metric.tendsto_nhds.mp hNorm) r hr
1649    exact hDist.mono (fun t ht => by
1650      simpa [Real.dist_eq, abs_of_nonneg (norm_nonneg (ξ t))] using ht)
1651  simpa [ξ] using hResidual ξ hSmallEventually hNorm
1652
1653/-- Spacing-amplitude specialization of the local nonlinear residual theorem.
1654If the scalar amplitude is the lattice spacing schedule itself and the spacing
1655tends to zero, then the nonlinear residual against the fixed Dirichlet action
1656tends to zero for every fixed perturbation direction. -/
1657theorem canonicalPeriodicNonlinearResidual_tendsto_zero_spacing_scaled_to_fixedDirichlet
1658    {α : Type*} {l : Filter α}
1659    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1660    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1661    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1662    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1663      ∀ (spacing : α → ℝ)
1664        (probe :
1665          VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K),
1666        Filter.Tendsto spacing l (nhds 0) →
1667          Filter.Tendsto
1668            (fun t : α =>
1669              ‖reggeAction
1670                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1671                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1672                  (spacing t • probe) -
1673                canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz
1674                  (spacing t • probe)‖)
1675            l (nhds 0) := by
1676  rcases canonicalPeriodicNonlinearResidual_tendsto_zero_scaled_to_fixedDirichlet
1677      Nx Ny Nz hx hy hz hLocal with
1678    ⟨r, C, hr, hC, hScaled⟩
1679  refine ⟨r, C, hr, hC, ?_⟩
1680  intro spacing probe hSpacing
1681  exact hScaled spacing probe hSpacing
1682
1683/-- Finite weighted aggregate of spacing-scaled nonlinear residuals.  This
1684packages the local nonlinear residual control in the finite Riemann-sum shape
1685needed before adding mesh-dependent weights. -/
1686theorem canonicalPeriodicNonlinearResidual_weighted_finite_probe_spacing_scaled_tendsto_zero
1687    {α : Type*} {l : Filter α}
1688    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1689    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1690    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1691    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1692      ∀ {n : ℕ}
1693        (spacing : α → ℝ)
1694        (probe :
1695          Fin n →
1696            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
1697        (weight : Fin n → ℝ),
1698        Filter.Tendsto spacing l (nhds 0) →
1699          Filter.Tendsto
1700            (fun t : α =>
1701              ∑ i : Fin n,
1702                weight i *
1703                  (reggeAction
1704                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1705                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1706                    (spacing t • probe i) -
1707                  canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz
1708                    (spacing t • probe i)))
1709            l (nhds 0) := by
1710  classical
1711  rcases canonicalPeriodicNonlinearResidual_tendsto_zero_spacing_scaled_to_fixedDirichlet
1712      Nx Ny Nz hx hy hz hLocal with
1713    ⟨r, C, hr, hC, hScaled⟩
1714  refine ⟨r, C, hr, hC, ?_⟩
1715  intro n spacing probe weight hSpacing
1716  simpa using
1717    (tendsto_finset_sum (Finset.univ : Finset (Fin n))
1718      (f := fun i (t : α) =>
1719        weight i *
1720          (reggeAction
1721            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1722            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1723            (spacing t • probe i) -
1724          canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz
1725            (spacing t • probe i)))
1726      (a := fun _i => 0)
1727      (by
1728        intro i _hi
1729        have hNorm := hScaled spacing (probe i) hSpacing
1730        have hScalar :
1731            Filter.Tendsto
1732              (fun t : α =>
1733                reggeAction
1734                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1735                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1736                  (spacing t • probe i) -
1737                canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz
1738                  (spacing t • probe i))
1739              l (nhds 0) := by
1740          apply tendsto_iff_dist_tendsto_zero.mpr
1741          simpa [Real.dist_eq] using hNorm
1742        simpa using hScalar.const_mul (weight i)))
1743
1744/-- Variable-weight finite aggregate of spacing-scaled nonlinear residuals.
1745This is the mesh-quadrature version of the local nonlinear residual control:
1746if each finite weight converges to a fixed limiting weight, the weighted
1747nonlinear residual still tends to zero. -/
1748theorem canonicalPeriodicNonlinearResidual_variable_weighted_finite_probe_spacing_scaled_tendsto_zero
1749    {α : Type*} {l : Filter α}
1750    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1751    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1752    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1753    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1754      ∀ {n : ℕ}
1755        (spacing : α → ℝ)
1756        (probe :
1757          Fin n →
1758            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
1759        (weight : α → Fin n → ℝ)
1760        (limitWeight : Fin n → ℝ),
1761        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
1762          Filter.Tendsto spacing l (nhds 0) →
1763            Filter.Tendsto
1764              (fun t : α =>
1765                ∑ i : Fin n,
1766                  weight t i *
1767                    (reggeAction
1768                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1769                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1770                      (spacing t • probe i) -
1771                    canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz
1772                      (spacing t • probe i)))
1773              l (nhds 0) := by
1774  classical
1775  rcases canonicalPeriodicNonlinearResidual_tendsto_zero_spacing_scaled_to_fixedDirichlet
1776      Nx Ny Nz hx hy hz hLocal with
1777    ⟨r, C, hr, hC, hScaled⟩
1778  refine ⟨r, C, hr, hC, ?_⟩
1779  intro n spacing probe weight limitWeight hWeight hSpacing
1780  simpa using
1781    (tendsto_finset_sum (Finset.univ : Finset (Fin n))
1782      (f := fun i (t : α) =>
1783        weight t i *
1784          (reggeAction
1785            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1786            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1787            (spacing t • probe i) -
1788          canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz
1789            (spacing t • probe i)))
1790      (a := fun _i => 0)
1791      (by
1792        intro i _hi
1793        have hNorm := hScaled spacing (probe i) hSpacing
1794        have hScalar :
1795            Filter.Tendsto
1796              (fun t : α =>
1797                reggeAction
1798                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1799                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1800                  (spacing t • probe i) -
1801                canonicalPeriodicFixedDirichletContinuumAction Nx Ny Nz hx hy hz
1802                  (spacing t • probe i))
1803              l (nhds 0) := by
1804          apply tendsto_iff_dist_tendsto_zero.mpr
1805          simpa [Real.dist_eq] using hNorm
1806        simpa using (hWeight i).mul hScalar))
1807
1808/-- Variable-weight finite aggregate of the full nonlinear Regge residual
1809against the canonical second-order Regge action, for spacing-scaled probes.
1810This is the same local nonlinear residual as the fixed-Dirichlet theorem, with
1811the fixed Dirichlet action rewritten by its exact second-order Regge
1812identification. -/
1813theorem canonicalPeriodicNonlinearResidual_variable_weighted_finite_probe_spacing_scaled_to_secondOrder_tendsto_zero
1814    {α : Type*} {l : Filter α}
1815    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1816    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1817    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1818    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1819      ∀ {n : ℕ}
1820        (spacing : α → ℝ)
1821        (probe :
1822          Fin n →
1823            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
1824        (weight : α → Fin n → ℝ)
1825        (limitWeight : Fin n → ℝ),
1826        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
1827          Filter.Tendsto spacing l (nhds 0) →
1828            Filter.Tendsto
1829              (fun t : α =>
1830                ∑ i : Fin n,
1831                  weight t i *
1832                    (reggeAction
1833                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1834                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1835                      (spacing t • probe i) -
1836                    reggeActionSecondOrder
1837                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1838                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1839                      (canonicalReggeHessian
1840                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1841                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1842                      (spacing t • probe i)))
1843              l (nhds 0) := by
1844  rcases canonicalPeriodicNonlinearResidual_variable_weighted_finite_probe_spacing_scaled_tendsto_zero
1845      Nx Ny Nz hx hy hz hLocal with
1846    ⟨r, C, hr, hC, hDirichlet⟩
1847  refine ⟨r, C, hr, hC, ?_⟩
1848  intro n spacing probe weight limitWeight hWeight hSpacing
1849  simpa [canonicalPeriodicFixedDirichletContinuumAction_eq_reggeSecondOrder]
1850    using hDirichlet spacing probe weight limitWeight hWeight hSpacing
1851
1852/-- Aggregate-difference form of the variable-weight nonlinear residual against
1853the canonical second-order Regge action.  This is the form needed for the next
1854finite Riemann-sum composition step: the full nonlinear weighted aggregate and
1855the second-order weighted aggregate differ by a term tending to zero. -/
1856theorem canonicalPeriodicNonlinearAggregate_variable_weighted_finite_probe_spacing_scaled_to_secondOrder_residual_tendsto_zero
1857    {α : Type*} {l : Filter α}
1858    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1859    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1860    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1861    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1862      ∀ {n : ℕ}
1863        (spacing : α → ℝ)
1864        (probe :
1865          Fin n →
1866            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
1867        (weight : α → Fin n → ℝ)
1868        (limitWeight : Fin n → ℝ),
1869        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
1870          Filter.Tendsto spacing l (nhds 0) →
1871            Filter.Tendsto
1872              (fun t : α =>
1873                (∑ i : Fin n,
1874                  weight t i *
1875                    reggeAction
1876                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1877                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1878                      (spacing t • probe i)) -
1879                  ∑ i : Fin n,
1880                    weight t i *
1881                      reggeActionSecondOrder
1882                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1883                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1884                        (canonicalReggeHessian
1885                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1886                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1887                        (spacing t • probe i))
1888              l (nhds 0) := by
1889  rcases canonicalPeriodicNonlinearResidual_variable_weighted_finite_probe_spacing_scaled_to_secondOrder_tendsto_zero
1890      Nx Ny Nz hx hy hz hLocal with
1891    ⟨r, C, hr, hC, hResidual⟩
1892  refine ⟨r, C, hr, hC, ?_⟩
1893  intro n spacing probe weight limitWeight hWeight hSpacing
1894  simpa [Finset.sum_sub_distrib, mul_sub] using
1895    hResidual spacing probe weight limitWeight hWeight hSpacing
1896
1897/-- Scaled finite nonlinear residual against the canonical second-order Regge
1898action.  The cubic local remainder makes the residual divided by
1899`||spacing(t)||^2` tend to zero for spacing-scaled probes.  This is the first
1900nontrivial scaled interface after the unscaled aggregate-vanishing lemmas. -/
1901theorem canonicalPeriodicNonlinearResidual_variable_weighted_finite_probe_spacing_scaled_to_secondOrder_div_spacing_norm_sq_tendsto_zero
1902    {α : Type*} {l : Filter α}
1903    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
1904    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
1905    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
1906    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
1907      ∀ {n : ℕ}
1908        (spacing : α → ℝ)
1909        (probe :
1910          Fin n →
1911            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
1912        (weight : α → Fin n → ℝ)
1913        (limitWeight : Fin n → ℝ),
1914        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
1915          Filter.Tendsto spacing l (nhds 0) →
1916            (∀ᶠ t : α in l, spacing t ≠ 0) →
1917              Filter.Tendsto
1918                (fun t : α =>
1919                  ∑ i : Fin n,
1920                    weight t i *
1921                      ((reggeAction
1922                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1923                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1924                          (spacing t • probe i) -
1925                        reggeActionSecondOrder
1926                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1927                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1928                          (canonicalReggeHessian
1929                            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1930                            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1931                          (spacing t • probe i)) /
1932                        ‖spacing t‖ ^ (2 : ℕ)))
1933                l (nhds 0) := by
1934  classical
1935  rcases canonicalPeriodicNonlinearResidual_bound_to_fixedDirichlet
1936      Nx Ny Nz hx hy hz hLocal with
1937    ⟨r, C, hr, hC, hBound⟩
1938  refine ⟨r, C, hr, hC, ?_⟩
1939  intro n spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
1940  simpa using
1941    (tendsto_finset_sum (Finset.univ : Finset (Fin n))
1942      (f := fun i (t : α) =>
1943        weight t i *
1944          ((reggeAction
1945              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1946              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1947              (spacing t • probe i) -
1948            reggeActionSecondOrder
1949              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1950              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1951              (canonicalReggeHessian
1952                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1953                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1954              (spacing t • probe i)) /
1955            ‖spacing t‖ ^ (2 : ℕ)))
1956      (a := fun _i => 0)
1957      (by
1958        intro i _hi
1959        have hScaledNorm :
1960            Filter.Tendsto
1961              (fun t : α => ‖spacing t • probe i‖) l (nhds 0) := by
1962          have hSpacingNorm :
1963              Filter.Tendsto (fun t : α => ‖spacing t‖) l (nhds (0 : ℝ)) := by
1964            simpa using hSpacing.norm
1965          have hMul :
1966              Filter.Tendsto (fun t : α => ‖spacing t‖ * ‖probe i‖) l
1967                (nhds ((0 : ℝ) * ‖probe i‖)) :=
1968            hSpacingNorm.mul tendsto_const_nhds
1969          simpa [norm_smul] using hMul
1970        have hSmallEventually : ∀ᶠ t : α in l, ‖spacing t • probe i‖ < r := by
1971          have hDist := (Metric.tendsto_nhds.mp hScaledNorm) r hr
1972          exact hDist.mono (fun t ht => by
1973            simpa [Real.dist_eq, abs_of_nonneg (norm_nonneg (spacing t • probe i))] using ht)
1974        have hEnvelope :
1975            Filter.Tendsto
1976              (fun t : α => (C * ‖probe i‖ ^ (3 : ℕ)) * ‖spacing t‖)
1977              l (nhds 0) := by
1978          have hSpacingNorm :
1979              Filter.Tendsto (fun t : α => ‖spacing t‖) l (nhds (0 : ℝ)) := by
1980            simpa using hSpacing.norm
1981          simpa using (hSpacingNorm.const_mul (C * ‖probe i‖ ^ (3 : ℕ)))
1982        have hAbsTendsto :
1983            Filter.Tendsto
1984              (fun t : α =>
1985                |(reggeAction
1986                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1987                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1988                      (spacing t • probe i) -
1989                    reggeActionSecondOrder
1990                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1991                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
1992                      (canonicalReggeHessian
1993                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
1994                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
1995                      (spacing t • probe i)) /
1996                    ‖spacing t‖ ^ (2 : ℕ)|)
1997              l (nhds 0) := by
1998          have hNonneg :
1999              ∀ᶠ t : α in l,
2000                0 ≤
2001                  |(reggeAction
2002                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2003                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2004                        (spacing t • probe i) -
2005                      reggeActionSecondOrder
2006                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2007                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2008                        (canonicalReggeHessian
2009                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2010                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
2011                        (spacing t • probe i)) /
2012                      ‖spacing t‖ ^ (2 : ℕ)| :=
2013            Filter.Eventually.of_forall (fun t => abs_nonneg _)
2014          have hUpper :
2015              ∀ᶠ t : α in l,
2016                |(reggeAction
2017                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2018                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2019                      (spacing t • probe i) -
2020                    reggeActionSecondOrder
2021                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2022                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2023                      (canonicalReggeHessian
2024                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2025                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
2026                      (spacing t • probe i)) /
2027                    ‖spacing t‖ ^ (2 : ℕ)| ≤
2028                  (C * ‖probe i‖ ^ (3 : ℕ)) * ‖spacing t‖ :=
2029            (hSmallEventually.and hSpacing_ne).mono (fun t ht => by
2030              rcases ht with ⟨hsmall, hne⟩
2031              let residual : ℝ :=
2032                reggeAction
2033                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2034                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2035                    (spacing t • probe i) -
2036                  reggeActionSecondOrder
2037                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2038                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2039                    (canonicalReggeHessian
2040                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2041                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
2042                    (spacing t • probe i)
2043              have hb :
2044                  ‖residual‖ ≤ C * ‖spacing t • probe i‖ ^ (3 : ℕ) := by
2045                simpa [residual, canonicalPeriodicFixedDirichletContinuumAction_eq_reggeSecondOrder]
2046                  using hBound (spacing t • probe i) hsmall
2047              have hbAbs :
2048                  |residual| ≤ C * (‖spacing t‖ * ‖probe i‖) ^ (3 : ℕ) := by
2049                simpa [Real.norm_eq_abs, norm_smul] using hb
2050              have hnorm_ne : ‖spacing t‖ ≠ 0 := by
2051                intro hnorm
2052                exact hne (norm_eq_zero.mp hnorm)
2053              have hdenpos : 0 < ‖spacing t‖ ^ (2 : ℕ) :=
2054                sq_pos_of_ne_zero hnorm_ne
2055              calc
2056                |residual / ‖spacing t‖ ^ (2 : ℕ)|
2057                    = |residual| / ‖spacing t‖ ^ (2 : ℕ) := by
2058                      rw [abs_div, abs_of_pos hdenpos]
2059                _ ≤ (C * (‖spacing t‖ * ‖probe i‖) ^ (3 : ℕ)) /
2060                    ‖spacing t‖ ^ (2 : ℕ) := by
2061                      exact div_le_div_of_nonneg_right hbAbs hdenpos.le
2062                _ = (C * ‖probe i‖ ^ (3 : ℕ)) * ‖spacing t‖ := by
2063                      field_simp [hnorm_ne])
2064          exact squeeze_zero' hNonneg hUpper hEnvelope
2065        have hScalar :
2066            Filter.Tendsto
2067              (fun t : α =>
2068                (reggeAction
2069                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2070                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2071                    (spacing t • probe i) -
2072                  reggeActionSecondOrder
2073                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2074                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2075                    (canonicalReggeHessian
2076                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2077                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
2078                    (spacing t • probe i)) /
2079                  ‖spacing t‖ ^ (2 : ℕ))
2080              l (nhds 0) := by
2081          apply tendsto_iff_dist_tendsto_zero.mpr
2082          simpa only [Real.dist_eq, sub_zero] using hAbsTendsto
2083        simpa using (hWeight i).mul hScalar))
2084
2085/-- Finite mesh-weighted scaled second-order aggregate convergence from
2086pointwise scaled second-order limits.  This is the finite Riemann-sum interface
2087for the quadratic layer: once each probe has a supplied continuum-normalized
2088limit after division by `||spacing(t)||^2`, convergent mesh weights give the
2089corresponding weighted finite aggregate limit. -/
2090theorem canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto
2091    {α : Type*} {l : Filter α}
2092    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
2093    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
2094    {n : ℕ}
2095    (spacing : α → ℝ)
2096    (probe :
2097      Fin n →
2098        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
2099    (weight : α → Fin n → ℝ)
2100    (limitWeight : Fin n → ℝ)
2101    (secondOrderLimit : Fin n → ℝ)
2102    (hWeight :
2103      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
2104    (hSecondOrder :
2105      ∀ i : Fin n,
2106        Filter.Tendsto
2107          (fun t : α =>
2108            reggeActionSecondOrder
2109              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2110              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2111              (canonicalReggeHessian
2112                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2113                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
2114              (spacing t • probe i) /
2115              ‖spacing t‖ ^ (2 : ℕ))
2116          l (nhds (secondOrderLimit i))) :
2117    Filter.Tendsto
2118      (fun t : α =>
2119        ∑ i : Fin n,
2120          weight t i *
2121            (reggeActionSecondOrder
2122              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2123              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2124              (canonicalReggeHessian
2125                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2126                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
2127              (spacing t • probe i) /
2128              ‖spacing t‖ ^ (2 : ℕ)))
2129      l (nhds (∑ i : Fin n, limitWeight i * secondOrderLimit i)) := by
2130  classical
2131  simpa using
2132    (tendsto_finset_sum (Finset.univ : Finset (Fin n))
2133      (f := fun i (t : α) =>
2134        weight t i *
2135          (reggeActionSecondOrder
2136            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2137            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
2138            (canonicalReggeHessian
2139              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
2140              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
2141            (spacing t • probe i) /
2142            ‖spacing t‖ ^ (2 : ℕ)))
2143      (a := fun i => limitWeight i * secondOrderLimit i)
2144      (by
2145        intro i _hi
2146        exact (hWeight i).mul (hSecondOrder i)))
2147
2148/-- Flat-deficit zero target for the Regge flat background.  This is the exact
2149geometric input needed to normalize the flat Regge action to zero; the
2150remaining periodic-Freudenthal task is to prove this target from the canonical
2151flat geometry. -/
2152def FlatDeficitZeroTarget (K : Triangulation3D) : Prop :=
2153  ∀ e : Fin K.nE, deficitAngle K (zeroPotential K) e = 0
2154
2155/-- Equivalent angle-sum form of flat zero deficit: the incident local
2156dihedral-angle contributions around each global edge sum to `2π`. -/
2157def FlatDeficitAngleSumTarget (K : Triangulation3D) : Prop :=
2158  ∀ e : Fin K.nE,
2159    (∑ τ : Fin K.nT, localDeficitAngleContribution K (zeroPotential K) e τ) =
2160      2 * Real.pi
2161
2162/-- The incident-angle-sum target implies zero deficit by unfolding the Regge
2163deficit angle. -/
2164theorem flatDeficitZeroTarget_of_angleSum
2165    (K : Triangulation3D)
2166    (hSum : FlatDeficitAngleSumTarget K) :
2167    FlatDeficitZeroTarget K := by
2168  intro e
2169  unfold deficitAngle
2170  rw [hSum e]
2171  ring
2172
2173/-- `FlatConfiguration` already contains the flat-deficit-zero field.  This
2174bridge lets the scaled finite-limit machinery consume the standard
2175flat-configuration package directly. -/
2176theorem FlatDeficitZeroTarget.of_flatConfiguration
2177    (K : Triangulation3D) (hK : IncidenceConsistent K)
2178    (hFlat : FlatConfiguration K hK) :
2179    FlatDeficitZeroTarget K :=
2180  hFlat.flat_deficit_zero
2181
2182/-- The `FlatDeficitZeroTarget` is definitionally the same condition as the
2183global zero-deficit input used by the smoothness/flat-configuration layer. -/
2184theorem flatDeficitZeroTarget_iff_globalZeroDeficitAtFlat
2185    (K : Triangulation3D) :
2186    FlatDeficitZeroTarget K ↔ GlobalZeroDeficitAtFlat K := by
2187  rfl
2188
2189/-- Angle-sum form of the global zero-deficit input used by the smoothness
2190package. -/
2191theorem globalZeroDeficitAtFlat_of_angleSum
2192    (K : Triangulation3D)
2193    (hSum : FlatDeficitAngleSumTarget K) :
2194    GlobalZeroDeficitAtFlat K :=
2195  (flatDeficitZeroTarget_iff_globalZeroDeficitAtFlat K).1
2196    (flatDeficitZeroTarget_of_angleSum K hSum)
2197
2198/-- Local Freudenthal dihedral angle for one tetrahedral edge slot, evaluated
2199on the canonical one-cube Freudenthal squared-edge tuple. -/
2200def freudenthalLocalDihedralAngle (f : Fin 6) : ℝ :=
2201  Geometry.DihedralDerivatives.dihedralAngle3Sq
2202    Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges f
2203
2204/-- Contribution of one periodic cell/tetrahedron pair to the angle sum around
2205a typed periodic edge. -/
2206def canonicalPeriodicTypedEdgeAngleContribution
2207    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2208    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2209    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) : ℝ :=
2210  match canonicalEdgeSlot? edge cellTet.1 cellTet.2 with
2211  | some f => freudenthalLocalDihedralAngle f
2212  | none => 0
2213
2214/-- Typed-edge version of the canonical periodic Freudenthal zero-deficit
2215angle-sum target.  This removes the anonymous finite edge encoder from the
2216next proof: it remains only to classify the incident cell/tetrahedron slots of
2217each typed periodic edge and evaluate their Freudenthal angles. -/
2218def CanonicalPeriodicTypedEdgeAngleSumTarget
2219    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] : Prop :=
2220  ∀ edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz,
2221    (∑ τ : Fin (Fintype.card (Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz)),
2222      canonicalPeriodicTypedEdgeAngleContribution edge (tetFinEquiv Nx Ny Nz τ)) =
2223      2 * Real.pi
2224
2225/-- Direct typed-cell/tetrahedron version of the canonical periodic
2226Freudenthal angle-sum target.  This removes the `Fin` tetrahedron encoder from
2227the remaining incidence proof: the next step can classify the finite set of
2228typed pairs `(cell, localTet)` directly. -/
2229def CanonicalPeriodicDirectTypedEdgeAngleSumTarget
2230    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] : Prop :=
2231  ∀ edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz,
2232    (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
2233      canonicalPeriodicTypedEdgeAngleContribution edge cellTet) =
2234      2 * Real.pi
2235
2236/-- A typed periodic cell/tetrahedron pair is incident to a typed periodic edge
2237when the computable local edge-slot lookup finds a local slot. -/
2238def canonicalPeriodicTypedEdgeIncident
2239    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2240    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2241    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) : Prop :=
2242  (canonicalEdgeSlot? edge cellTet.1 cellTet.2).isSome = true
2243
2244instance canonicalPeriodicTypedEdgeIncident_decidable
2245    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2246    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2247    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) :
2248    Decidable (canonicalPeriodicTypedEdgeIncident edge cellTet) := by
2249  unfold canonicalPeriodicTypedEdgeIncident
2250  infer_instance
2251
2252/-- Witness form of typed edge incidence: a concrete local Freudenthal edge slot
2253`f` is found by `canonicalEdgeSlot?`.  This is the form needed for the finite
2254incident-star classification. -/
2255def canonicalPeriodicTypedEdgeIncidentSlotWitness
2256    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2257    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2258    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) : Prop :=
2259  ∃ f : Fin 6, canonicalEdgeSlot? edge cellTet.1 cellTet.2 = some f
2260
2261instance canonicalPeriodicTypedEdgeIncidentSlotWitness_decidable
2262    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2263    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2264    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) :
2265    Decidable (canonicalPeriodicTypedEdgeIncidentSlotWitness edge cellTet) := by
2266  unfold canonicalPeriodicTypedEdgeIncidentSlotWitness
2267  infer_instance
2268
2269/-- The boolean `isSome` incident predicate is exactly the existence of a local
2270Freudenthal edge-slot witness. -/
2271theorem canonicalPeriodicTypedEdgeIncident_iff_slotWitness
2272    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2273    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2274    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) :
2275    canonicalPeriodicTypedEdgeIncident edge cellTet ↔
2276      canonicalPeriodicTypedEdgeIncidentSlotWitness edge cellTet := by
2277  unfold canonicalPeriodicTypedEdgeIncident canonicalPeriodicTypedEdgeIncidentSlotWitness
2278  exact Option.isSome_iff_exists
2279
2280/-- A concrete local-slot witness identifies the typed periodic edge as the
2281translated Freudenthal local edge for that cell and tetrahedron. -/
2282theorem canonicalPeriodicTypedEdge_eq_localEdgeOf_of_slotWitness
2283    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2284    {edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz}
2285    {cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz}
2286    {f : Fin 6}
2287    (hSlot : canonicalEdgeSlot? edge cellTet.1 cellTet.2 = some f) :
2288    edge = localEdgeOf cellTet.1 cellTet.2 f :=
2289  canonicalEdgeSlot_eq_some_implies hSlot
2290
2291/-- Once the local edge slot is known, the typed edge angle contribution is the
2292corresponding Freudenthal local dihedral angle. -/
2293theorem canonicalPeriodicTypedEdgeAngleContribution_eq_of_slot
2294    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2295    {edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz}
2296    {cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz}
2297    {f : Fin 6}
2298    (hSlot : canonicalEdgeSlot? edge cellTet.1 cellTet.2 = some f) :
2299    canonicalPeriodicTypedEdgeAngleContribution edge cellTet =
2300      freudenthalLocalDihedralAngle f := by
2301  simp [canonicalPeriodicTypedEdgeAngleContribution, hSlot]
2302
2303/-- Geometric witness form of typed edge incidence: the typed periodic edge is
2304exactly the translated local Freudenthal edge of a typed cell/tetrahedron pair. -/
2305def canonicalPeriodicTypedEdgeLocalEdgeOfWitness
2306    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2307    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2308    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) : Prop :=
2309  ∃ f : Fin 6, edge = localEdgeOf cellTet.1 cellTet.2 f
2310
2311instance canonicalPeriodicTypedEdgeLocalEdgeOfWitness_decidable
2312    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2313    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2314    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) :
2315    Decidable (canonicalPeriodicTypedEdgeLocalEdgeOfWitness edge cellTet) := by
2316  unfold canonicalPeriodicTypedEdgeLocalEdgeOfWitness
2317  infer_instance
2318
2319/-- The slot-witness and geometric `localEdgeOf` witness forms of typed
2320incidence are equivalent. -/
2321theorem canonicalPeriodicTypedEdgeIncidentSlotWitness_iff_localEdgeOf
2322    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2323    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2324    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) :
2325    canonicalPeriodicTypedEdgeIncidentSlotWitness edge cellTet ↔
2326      canonicalPeriodicTypedEdgeLocalEdgeOfWitness edge cellTet := by
2327  constructor
2328  · intro h
2329    rcases h with ⟨f, hSlot⟩
2330    exact ⟨f, canonicalEdgeSlot_eq_some_implies hSlot⟩
2331  · intro h
2332    rcases h with ⟨f, hEdge⟩
2333    refine ⟨f, ?_⟩
2334    exact canonicalEdgeSlot_eq_some_of_noDup
2335      (fun f g hg => canonicalPeriodicLocalEdgeNoDup Nx Ny Nz cellTet.1 cellTet.2 f g hg)
2336      hEdge
2337
2338/-- A geometric `localEdgeOf` witness identifies the Freudenthal local angle
2339contributing to the typed periodic edge. -/
2340theorem canonicalPeriodicTypedEdgeAngleContribution_eq_of_localEdgeOf
2341    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2342    {edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz}
2343    {cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz}
2344    {f : Fin 6}
2345    (hEdge : edge = localEdgeOf cellTet.1 cellTet.2 f) :
2346    canonicalPeriodicTypedEdgeAngleContribution edge cellTet =
2347      freudenthalLocalDihedralAngle f := by
2348  have hSlot : canonicalEdgeSlot? edge cellTet.1 cellTet.2 = some f :=
2349    canonicalEdgeSlot_eq_some_of_noDup
2350      (fun f g hg => canonicalPeriodicLocalEdgeNoDup Nx Ny Nz cellTet.1 cellTet.2 f g hg)
2351      hEdge
2352  exact canonicalPeriodicTypedEdgeAngleContribution_eq_of_slot hSlot
2353
2354/-- A geometric `localEdgeOf` witness pins the typed periodic edge to the
2355positive displacement class of the underlying Freudenthal local edge slot. -/
2356theorem canonicalPeriodicTypedEdge_disp_eq_of_localEdgeOf
2357    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2358    {edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz}
2359    {cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz}
2360    {f : Fin 6}
2361    (hEdge : edge = localEdgeOf cellTet.1 cellTet.2 f) :
2362    edge.disp = Geometry.PeriodicFreudenthalTorus.cubeEdgeDisp
2363      (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f) := by
2364  rw [hEdge]
2365  simp [localEdgeOf]
2366
2367/-- A geometric `localEdgeOf` witness also pins the typed periodic edge's base
2368vertex to the translated base vertex of the underlying Freudenthal local edge. -/
2369theorem canonicalPeriodicTypedEdge_base_eq_of_localEdgeOf
2370    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2371    {edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz}
2372    {cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz}
2373    {f : Fin 6}
2374    (hEdge : edge = localEdgeOf cellTet.1 cellTet.2 f) :
2375    edge.base = Geometry.PeriodicFreudenthalTorus.addVertexBits cellTet.1
2376      (Geometry.PeriodicFreudenthalTorus.cubeEdgeBase
2377        (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) := by
2378  rw [hEdge]
2379  simp [localEdgeOf]
2380
2381/-- Equality with a translated local Freudenthal edge is exactly the pair of
2382typed periodic edge equations for base vertex and positive displacement. -/
2383theorem canonicalPeriodicTypedEdge_eq_localEdgeOf_iff_base_and_disp
2384    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2385    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2386    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz)
2387    (f : Fin 6) :
2388    edge = localEdgeOf cellTet.1 cellTet.2 f ↔
2389      edge.base = addVertexBits cellTet.1
2390        (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) ∧
2391      edge.disp = cubeEdgeDisp
2392        (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f) := by
2393  constructor
2394  · intro hEdge
2395    exact ⟨canonicalPeriodicTypedEdge_base_eq_of_localEdgeOf hEdge,
2396      canonicalPeriodicTypedEdge_disp_eq_of_localEdgeOf hEdge⟩
2397  · intro h
2398    cases edge
2399    simp [localEdgeOf] at h ⊢
2400    exact h
2401
2402/-- Each typed cell/tetrahedron contribution can be written as an explicit sum
2403over the six local Freudenthal edge slots, guarded by the geometric equality
2404`edge = localEdgeOf cell tet f`. -/
2405theorem canonicalPeriodicTypedEdgeAngleContribution_eq_sum_localSlots
2406    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2407    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2408    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) :
2409    canonicalPeriodicTypedEdgeAngleContribution edge cellTet =
2410      ∑ f : Fin 6,
2411        if edge = localEdgeOf cellTet.1 cellTet.2 f then
2412          freudenthalLocalDihedralAngle f else 0 := by
2413  classical
2414  cases hslot : canonicalEdgeSlot? edge cellTet.1 cellTet.2 with
2415  | none =>
2416      rw [Finset.sum_eq_zero]
2417      · simp [canonicalPeriodicTypedEdgeAngleContribution, hslot]
2418      · intro f _
2419        have hne : edge ≠ localEdgeOf cellTet.1 cellTet.2 f := by
2420          intro hEdge
2421          have hsome : canonicalEdgeSlot? edge cellTet.1 cellTet.2 = some f :=
2422            canonicalEdgeSlot_eq_some_of_noDup
2423              (fun f g hg =>
2424                canonicalPeriodicLocalEdgeNoDup Nx Ny Nz cellTet.1 cellTet.2 f g hg)
2425              hEdge
2426          rw [hslot] at hsome
2427          contradiction
2428        simp [hne]
2429  | some f =>
2430      have hEdge : edge = localEdgeOf cellTet.1 cellTet.2 f :=
2431        canonicalEdgeSlot_eq_some_implies hslot
2432      have hSlotLocal :
2433          canonicalEdgeSlot? (localEdgeOf cellTet.1 cellTet.2 f) cellTet.1 cellTet.2 =
2434            some f :=
2435        canonicalEdgeSlot_eq_some_of_noDup
2436          (fun f g hg =>
2437            canonicalPeriodicLocalEdgeNoDup Nx Ny Nz cellTet.1 cellTet.2 f g hg)
2438          rfl
2439      rw [Finset.sum_eq_single f]
2440      · simp [canonicalPeriodicTypedEdgeAngleContribution, hEdge, hSlotLocal]
2441      · intro g _ hg
2442        have hne : edge ≠ localEdgeOf cellTet.1 cellTet.2 g := by
2443          intro hEdgeG
2444          have hfg : f = g :=
2445            canonicalPeriodicLocalEdgeNoDup Nx Ny Nz cellTet.1 cellTet.2 f g
2446              (by rw [← hEdge, ← hEdgeG])
2447          exact hg hfg.symm
2448        simp [hne]
2449      · intro hf
2450        exact (hf (Finset.mem_univ f)).elim
2451
2452/-- In the local-slot expansion, slots whose displacement class differs from
2453the typed edge's displacement class contribute zero and may be deleted. -/
2454theorem canonicalPeriodicLocalSlotSum_eq_dispFiltered
2455    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2456    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2457    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) :
2458    (∑ f : Fin 6,
2459        if edge = localEdgeOf cellTet.1 cellTet.2 f then
2460          freudenthalLocalDihedralAngle f else 0) =
2461      ∑ f ∈ (Finset.univ.filter
2462        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
2463          (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
2464        if edge = localEdgeOf cellTet.1 cellTet.2 f then
2465          freudenthalLocalDihedralAngle f else 0 := by
2466  classical
2467  rw [Finset.sum_filter]
2468  refine Finset.sum_congr rfl ?_
2469  intro f _
2470  by_cases hDisp :
2471      edge.disp = cubeEdgeDisp
2472        (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)
2473  · simp [hDisp]
2474  · have hne : edge ≠ localEdgeOf cellTet.1 cellTet.2 f := by
2475      intro hEdge
2476      exact hDisp (canonicalPeriodicTypedEdge_disp_eq_of_localEdgeOf hEdge)
2477    simp [hDisp, hne]
2478
2479/-- After filtering by displacement class, the remaining full edge equality
2480guard is equivalent to the base-vertex offset equation. -/
2481theorem canonicalPeriodicDispFilteredLocalSlotSum_eq_baseFiltered
2482    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2483    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
2484    (cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz) :
2485    (∑ f ∈ (Finset.univ.filter
2486        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
2487          (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
2488        if edge = localEdgeOf cellTet.1 cellTet.2 f then
2489          freudenthalLocalDihedralAngle f else 0) =
2490      ∑ f ∈ (Finset.univ.filter
2491        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
2492          (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
2493        if edge.base = addVertexBits cellTet.1
2494          (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) then
2495          freudenthalLocalDihedralAngle f else 0 := by
2496  classical
2497  refine Finset.sum_congr rfl ?_
2498  intro f hf
2499  have hDisp :
2500      edge.disp = cubeEdgeDisp
2501        (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f) :=
2502    (Finset.mem_filter.mp hf).2
2503  have hiff : (edge = localEdgeOf cellTet.1 cellTet.2 f) ↔
2504      edge.base = addVertexBits cellTet.1
2505        (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) := by
2506    constructor
2507    · intro hEdge
2508      exact canonicalPeriodicTypedEdge_base_eq_of_localEdgeOf hEdge
2509    · intro hBase
2510      exact (canonicalPeriodicTypedEdge_eq_localEdgeOf_iff_base_and_disp edge cellTet f).2
2511        ⟨hBase, hDisp⟩
2512  have hLocalBase :
2513      (localEdgeOf cellTet.1 cellTet.2 f).base =
2514        addVertexBits cellTet.1
2515          (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) := by
2516    simp [localEdgeOf]
2517  by_cases hBase :
2518      edge.base = addVertexBits cellTet.1
2519        (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))
2520  · have hEq : edge = localEdgeOf cellTet.1 cellTet.2 f := hiff.2 hBase
2521    simp [hEq, hLocalBase]
2522  · have hEq : edge ≠ localEdgeOf cellTet.1 cellTet.2 f := by
2523      intro hEdge
2524      exact hBase (hiff.1 hEdge)
2525    simp [hBase, hEq]
2526
2527/-- Incident-filter version of the direct typed-cell/tetrahedron angle-sum
2528target.  All nonincident typed pairs have zero contribution, so the remaining
2529geometric proof can focus only on the finite incident star of each edge. -/
2530def CanonicalPeriodicIncidentFilteredEdgeAngleSumTarget
2531    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] : Prop :=
2532  ∀ edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz,
2533    (∑ cellTet ∈
2534      (Finset.univ.filter
2535        (fun cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz =>
2536          canonicalPeriodicTypedEdgeIncident edge cellTet)),
2537      canonicalPeriodicTypedEdgeAngleContribution edge cellTet) =
2538      2 * Real.pi
2539
2540/-- `localEdgeOf`-filtered version of the incident angle-sum target.  This is
2541the purely geometric finite-star form: the remaining proof classifies exactly
2542which translated local Freudenthal edges equal a given typed periodic edge. -/
2543def CanonicalPeriodicLocalEdgeOfFilteredEdgeAngleSumTarget
2544    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] : Prop :=
2545  ∀ edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz,
2546    (∑ cellTet ∈
2547      (Finset.univ.filter
2548        (fun cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz =>
2549          canonicalPeriodicTypedEdgeLocalEdgeOfWitness edge cellTet)),
2550      canonicalPeriodicTypedEdgeAngleContribution edge cellTet) =
2551      2 * Real.pi
2552
2553/-- Triple-sum version of the canonical periodic Freudenthal angle-sum target:
2554sum directly over typed cells, local tetrahedra, and local edge slots, with
2555nonmatching triples contributing zero. -/
2556def CanonicalPeriodicLocalSlotTripleAngleSumTarget
2557    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] : Prop :=
2558  ∀ edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz,
2559    (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
2560      ∑ f : Fin 6,
2561        if edge = localEdgeOf cellTet.1 cellTet.2 f then
2562          freudenthalLocalDihedralAngle f else 0) =
2563      2 * Real.pi
2564
2565/-- Displacement-filtered triple-sum target: for each typed periodic edge,
2566only local Freudenthal slots with the same positive displacement class are
2567enumerated. -/
2568def CanonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget
2569    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] : Prop :=
2570  ∀ edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz,
2571    (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
2572      ∑ f ∈ (Finset.univ.filter
2573        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
2574          (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
2575        if edge = localEdgeOf cellTet.1 cellTet.2 f then
2576          freudenthalLocalDihedralAngle f else 0) =
2577      2 * Real.pi
2578
2579/-- Base-and-displacement filtered triple-sum target: displacement matching is
2580handled by the finite local-slot filter, and incidence is reduced to the
2581periodic base-vertex offset equation. -/
2582def CanonicalPeriodicBaseDispFilteredLocalSlotTripleAngleSumTarget
2583    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] : Prop :=
2584  ∀ edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz,
2585    (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
2586      ∑ f ∈ (Finset.univ.filter
2587        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
2588          (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
2589        if edge.base = addVertexBits cellTet.1
2590          (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) then
2591          freudenthalLocalDihedralAngle f else 0) =
2592      2 * Real.pi
2593
2594/-- Local Freudenthal `(tet, edge-slot)` pairs.  This is the finite table left
2595after the periodic-cell base-offset equation has been isolated. -/
2596abbrev FreudenthalLocalPair := Fin 6 × Fin 6
2597
2598/-- Positive displacement class of a local Freudenthal `(tet, edge-slot)` pair. -/
2599def freudenthalLocalPairDisp (pair : FreudenthalLocalPair) : Fin 7 :=
2600  cubeEdgeDisp (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2)
2601
2602/-- The seven displacement-class fiber sizes in the one-cube Freudenthal local
2603edge-slot table.  Classes `0,1,2,6` have six local representatives; classes
2604`3,4,5` have four. -/
2605def freudenthalLocalDispMultiplicity : Fin 7 → ℕ
2606  | 0 => 6
2607  | 1 => 6
2608  | 2 => 6
2609  | 3 => 4
2610  | 4 => 4
2611  | 5 => 4
2612  | 6 => 6
2613
2614/-- Explicit local Freudenthal `(tet, edge-slot)` fiber for each positive
2615displacement class. -/
2616def freudenthalLocalPairDispFiber : Fin 7 → Finset FreudenthalLocalPair
2617  | 0 => {((0 : Fin 6), (0 : Fin 6)), ((1 : Fin 6), (0 : Fin 6)),
2618    ((2 : Fin 6), (3 : Fin 6)), ((3 : Fin 6), (5 : Fin 6)),
2619    ((4 : Fin 6), (3 : Fin 6)), ((5 : Fin 6), (5 : Fin 6))}
2620  | 1 => {((0 : Fin 6), (3 : Fin 6)), ((1 : Fin 6), (5 : Fin 6)),
2621    ((2 : Fin 6), (0 : Fin 6)), ((3 : Fin 6), (0 : Fin 6)),
2622    ((4 : Fin 6), (5 : Fin 6)), ((5 : Fin 6), (3 : Fin 6))}
2623  | 2 => {((0 : Fin 6), (5 : Fin 6)), ((1 : Fin 6), (3 : Fin 6)),
2624    ((2 : Fin 6), (5 : Fin 6)), ((3 : Fin 6), (3 : Fin 6)),
2625    ((4 : Fin 6), (0 : Fin 6)), ((5 : Fin 6), (0 : Fin 6))}
2626  | 3 => {((0 : Fin 6), (1 : Fin 6)), ((2 : Fin 6), (1 : Fin 6)),
2627    ((4 : Fin 6), (4 : Fin 6)), ((5 : Fin 6), (4 : Fin 6))}
2628  | 4 => {((1 : Fin 6), (1 : Fin 6)), ((2 : Fin 6), (4 : Fin 6)),
2629    ((3 : Fin 6), (4 : Fin 6)), ((4 : Fin 6), (1 : Fin 6))}
2630  | 5 => {((0 : Fin 6), (4 : Fin 6)), ((1 : Fin 6), (4 : Fin 6)),
2631    ((3 : Fin 6), (1 : Fin 6)), ((5 : Fin 6), (1 : Fin 6))}
2632  | 6 => {((0 : Fin 6), (2 : Fin 6)), ((1 : Fin 6), (2 : Fin 6)),
2633    ((2 : Fin 6), (2 : Fin 6)), ((3 : Fin 6), (2 : Fin 6)),
2634    ((4 : Fin 6), (2 : Fin 6)), ((5 : Fin 6), (2 : Fin 6))}
2635
2636/-- The explicit local displacement fiber table agrees with the computable
2637`freudenthalLocalPairDisp` filter. -/
2638theorem freudenthalLocalPairDispFiber_eq_filter (d : Fin 7) :
2639    freudenthalLocalPairDispFiber d =
2640      ((Finset.univ : Finset FreudenthalLocalPair).filter
2641        (fun pair => freudenthalLocalPairDisp pair = d)) := by
2642  fin_cases d <;> native_decide
2643
2644/-- Freudenthal local angle attached to a local `(tet, edge-slot)` pair. -/
2645def freudenthalLocalPairAngle (pair : FreudenthalLocalPair) : ℝ :=
2646  freudenthalLocalDihedralAngle pair.2
2647
2648/-- Symbolic local-angle sum template for each positive displacement class.
2649The first three axis classes receive two copies each of slots `0`, `3`, and
2650`5`; the face-diagonal classes receive two copies each of slots `1` and `4`;
2651the body-diagonal class receives six copies of slot `2`. -/
2652def freudenthalLocalDispAngleSumTemplate : Fin 7 → ℝ
2653  | 0 => 2 * freudenthalLocalDihedralAngle 0 +
2654    2 * freudenthalLocalDihedralAngle 3 +
2655    2 * freudenthalLocalDihedralAngle 5
2656  | 1 => 2 * freudenthalLocalDihedralAngle 0 +
2657    2 * freudenthalLocalDihedralAngle 3 +
2658    2 * freudenthalLocalDihedralAngle 5
2659  | 2 => 2 * freudenthalLocalDihedralAngle 0 +
2660    2 * freudenthalLocalDihedralAngle 3 +
2661    2 * freudenthalLocalDihedralAngle 5
2662  | 3 => 2 * freudenthalLocalDihedralAngle 1 +
2663    2 * freudenthalLocalDihedralAngle 4
2664  | 4 => 2 * freudenthalLocalDihedralAngle 1 +
2665    2 * freudenthalLocalDihedralAngle 4
2666  | 5 => 2 * freudenthalLocalDihedralAngle 1 +
2667    2 * freudenthalLocalDihedralAngle 4
2668  | 6 => 6 * freudenthalLocalDihedralAngle 2
2669
2670/-- Exact symbolic local-angle sum over the explicit local-pair displacement
2671fiber. -/
2672theorem freudenthalLocalPairDispFiber_angle_sum (d : Fin 7) :
2673    (∑ pair ∈ freudenthalLocalPairDispFiber d, freudenthalLocalPairAngle pair) =
2674      freudenthalLocalDispAngleSumTemplate d := by
2675  fin_cases d <;>
2676    simp [freudenthalLocalPairDispFiber, freudenthalLocalPairAngle,
2677      freudenthalLocalDispAngleSumTemplate]
2678  all_goals ring_nf
2679
2680/-- Exact symbolic local-angle sum over the computable local-pair displacement
2681filter. -/
2682theorem freudenthalLocalPairDisp_filter_angle_sum (d : Fin 7) :
2683    (∑ pair ∈ ((Finset.univ : Finset FreudenthalLocalPair).filter
2684      (fun pair => freudenthalLocalPairDisp pair = d)),
2685      freudenthalLocalPairAngle pair) =
2686      freudenthalLocalDispAngleSumTemplate d := by
2687  rw [← freudenthalLocalPairDispFiber_eq_filter d]
2688  exact freudenthalLocalPairDispFiber_angle_sum d
2689
2690/-- Closed-form Schläfli coefficient for a local `(tet, slot)` pair and local
2691edge-slot direction `k`. -/
2692def freudenthalLocalPairClosedFormSchlaefliCoeff (pair : FreudenthalLocalPair) (k : Fin 6) : ℝ :=
2693  dihedralClosedDerivLength Geometry.FreudenthalCubeTriangulation.freudenthalTet pair.2 k
2694
2695/-- Closed-form Schläfli coefficient as the evaluated rationalized summand. -/
2696theorem freudenthalLocalPairClosedFormSchlaefliCoeff_eq_snorm
2697    (pair : FreudenthalLocalPair) (k : Fin 6) :
2698    freudenthalLocalPairClosedFormSchlaefliCoeff pair k =
2699      schlaefliPolySummandNorm Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges pair.2 k *
2700        Real.sqrt (Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges k) /
2701          (2 * Real.sqrt (Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges pair.2)) := by
2702  dsimp [freudenthalLocalPairClosedFormSchlaefliCoeff]
2703  exact FreudenthalLengthChainEndpointCert.freudenthalDihedralClosedDerivLength_snorm pair.2 k
2704
2705/-- Closed-form Schläfli coefficient from the finite lookup table. -/
2706theorem freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table
2707    (pair : FreudenthalLocalPair) (k : Fin 6) :
2708    freudenthalLocalPairClosedFormSchlaefliCoeff pair k =
2709      FreudenthalLengthChainEndpointCert.freudenthalSchlaefliPolySummandNormTable pair.2 k *
2710        Real.sqrt (Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges k) /
2711          (2 * Real.sqrt (Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges pair.2)) := by
2712  rw [freudenthalLocalPairClosedFormSchlaefliCoeff_eq_snorm,
2713    FreudenthalLengthChainEndpointCert.freudenthalSchlaefliPolySummandNorm_eq_table]
2714
2715/-- Symbolic local length-chain summand for one Freudenthal local pair. -/
2716def freudenthalLocalPairLengthChainSummand (pair : FreudenthalLocalPair) (edgeLengthDir : Fin 6 → ℝ) : ℝ :=
2717  ∑ k : Fin 6, freudenthalLocalPairClosedFormSchlaefliCoeff pair k * edgeLengthDir k
2718
2719theorem freudenthalLocalPairLengthChainSummand_eq_coeffDot
2720    (pair : FreudenthalLocalPair) (edgeLengthDir : Fin 6 → ℝ) :
2721    freudenthalLocalPairLengthChainSummand pair edgeLengthDir =
2722      ∑ k : Fin 6, freudenthalLocalPairClosedFormSchlaefliCoeff pair k * edgeLengthDir k := by
2723  rfl
2724
2725/-- Symbolic local length-chain sum template for each positive displacement
2726class.  The caller supplies one conformal edge-length directional derivative
2727per local edge slot; specialization to the explicit periodic fiber uses
2728`freudenthalExplicitFiberDispLengthChainSumTemplate`. -/
2729def freudenthalLocalDispLengthChainSumTemplate (d : Fin 7) (edgeLengthDir : Fin 6 → ℝ) : ℝ :=
2730  ∑ pair ∈ freudenthalLocalPairDispFiber d, freudenthalLocalPairLengthChainSummand pair edgeLengthDir
2731
2732/-- Exact symbolic local length-chain sum over the explicit local-pair
2733displacement fiber. -/
2734theorem freudenthalLocalPairDispFiber_lengthChain_sum (d : Fin 7) (edgeLengthDir : Fin 6 → ℝ) :
2735    (∑ pair ∈ freudenthalLocalPairDispFiber d, freudenthalLocalPairLengthChainSummand pair edgeLengthDir) =
2736      freudenthalLocalDispLengthChainSumTemplate d edgeLengthDir := by
2737  rfl
2738
2739/-- Exact symbolic local length-chain sum over the computable local-pair
2740displacement filter. -/
2741theorem freudenthalLocalPairDisp_filter_lengthChain_sum (d : Fin 7) (edgeLengthDir : Fin 6 → ℝ) :
2742    (∑ pair ∈ ((Finset.univ : Finset FreudenthalLocalPair).filter
2743        (fun pair => freudenthalLocalPairDisp pair = d)),
2744      freudenthalLocalPairLengthChainSummand pair edgeLengthDir) =
2745      freudenthalLocalDispLengthChainSumTemplate d edgeLengthDir := by
2746  rw [← freudenthalLocalPairDispFiber_eq_filter d]
2747  exact freudenthalLocalPairDispFiber_lengthChain_sum d edgeLengthDir
2748
2749/-- The base/displacement-filtered periodic cell/tet/slot sum collapses to the
2750one-cube local-pair displacement fiber sum.  For each matching local pair,
2751`sum_ite_eq_of_addVertexBits` supplies the unique periodic cell solving the
2752base-offset equation. -/
2753theorem canonicalPeriodicBaseDispFilteredLocalSlotTripleSum_eq_localPairDisp_filter_angle_sum
2754    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2755    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
2756    (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
2757      ∑ f ∈ (Finset.univ.filter
2758        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
2759          (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
2760        if edge.base = addVertexBits cellTet.1
2761          (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) then
2762          freudenthalLocalDihedralAngle f else 0) =
2763      (∑ pair ∈ ((Finset.univ : Finset FreudenthalLocalPair).filter
2764        (fun pair => freudenthalLocalPairDisp pair = edge.disp)),
2765        freudenthalLocalPairAngle pair) := by
2766  classical
2767  unfold Geometry.PeriodicFreudenthalTorus.PeriodicTet
2768  rw [← Finset.univ_product_univ, Finset.sum_product]
2769  rw [Finset.sum_comm]
2770  trans (∑ tet : Fin 6,
2771      ∑ f ∈ (Finset.univ.filter
2772        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
2773          (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
2774        freudenthalLocalDihedralAngle f)
2775  · refine Finset.sum_congr rfl ?_
2776    intro tet _
2777    rw [Finset.sum_comm (s := (Finset.univ : Finset (Vertex Nx Ny Nz)))
2778      (t := (Finset.univ.filter
2779        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
2780          (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))))]
2781    refine Finset.sum_congr rfl ?_
2782    intro f _
2783    exact sum_ite_eq_of_addVertexBits
2784      (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
2785      edge.base (freudenthalLocalDihedralAngle f)
2786  · unfold FreudenthalLocalPair freudenthalLocalPairDisp freudenthalLocalPairAngle
2787    rw [← Finset.univ_product_univ]
2788    rw [Finset.sum_filter]
2789    rw [Finset.sum_product]
2790    simp [Finset.sum_filter, eq_comm]
2791
2792/-- The base/displacement-filtered periodic cell/tet/slot sum is exactly the
2793symbolic Freudenthal local angle template for the typed edge's displacement
2794class.  The only remaining zero-deficit work is therefore the three explicit
2795template identities to `2π`. -/
2796theorem canonicalPeriodicBaseDispFilteredLocalSlotTripleSum_eq_angleTemplate
2797    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
2798    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
2799    (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
2800      ∑ f ∈ (Finset.univ.filter
2801        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
2802          (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
2803        if edge.base = addVertexBits cellTet.1
2804          (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) then
2805          freudenthalLocalDihedralAngle f else 0) =
2806      freudenthalLocalDispAngleSumTemplate edge.disp := by
2807  rw [canonicalPeriodicBaseDispFilteredLocalSlotTripleSum_eq_localPairDisp_filter_angle_sum edge]
2808  exact freudenthalLocalPairDisp_filter_angle_sum edge.disp
2809
2810/-- The final local Freudenthal angle identities needed after the periodic
2811cell-count collapse.  This is now the whole `2π` content of the
2812base/displacement-filtered zero-deficit target. -/
2813def FreudenthalLocalDispAngleTemplateTarget : Prop :=
2814  ∀ d : Fin 7, freudenthalLocalDispAngleSumTemplate d = 2 * Real.pi
2815
2816/-- The three distinct local Freudenthal angle identities underlying the seven
2817positive displacement classes.  Axis classes share the first identity,
2818face-diagonal classes share the second, and the body-diagonal class is the
2819third. -/
2820def FreudenthalLocalThreeAngleIdentityTarget : Prop :=
2821  (2 * freudenthalLocalDihedralAngle 0 +
2822      2 * freudenthalLocalDihedralAngle 3 +
2823      2 * freudenthalLocalDihedralAngle 5 = 2 * Real.pi) ∧
2824    (2 * freudenthalLocalDihedralAngle 1 +
2825      2 * freudenthalLocalDihedralAngle 4 = 2 * Real.pi) ∧
2826    (6 * freudenthalLocalDihedralAngle 2 = 2 * Real.pi)
2827
2828/-- Arithmetic simplification used by the Freudenthal cofactor-cosine values:
2829`sqrt 32 = 4 * sqrt 2`, hence `4 / sqrt 32 = sqrt 2 / 2`. -/
2830private theorem four_div_sqrt_thirty_two_eq_sqrt_two_div_two :
2831    (4 : ℝ) / Real.sqrt 32 = Real.sqrt 2 / 2 := by
2832  rw [show (32 : ℝ) = 16 * 2 by norm_num]
2833  rw [Real.sqrt_mul (by norm_num : (0 : ℝ) ≤ 16)]
2834  have hsqrt16 : Real.sqrt (16 : ℝ) = 4 := by
2835    rw [show (16 : ℝ) = 4 ^ 2 by norm_num]
2836    exact Real.sqrt_sq (by norm_num : (0 : ℝ) ≤ 4)
2837  rw [hsqrt16]
2838  have hsqrt2_ne : Real.sqrt (2 : ℝ) ≠ 0 := by
2839    exact ne_of_gt (Real.sqrt_pos.2 (by norm_num : (0 : ℝ) < 2))
2840  field_simp [hsqrt2_ne]
2841  rw [Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2)]
2842
2843/-- Exact cofactor-cosine values of the canonical Freudenthal tetrahedron's six
2844local dihedral angles. -/
2845theorem freudenthalLocalDihedralCos_eq (f : Fin 6) :
2846    Geometry.DihedralCayleyMenger.dihedralCos3Sq
2847      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges f =
2848      match f with
2849      | 0 => Real.sqrt 2 / 2
2850      | 1 => 0
2851      | 2 => (1 / 2 : ℝ)
2852      | 3 => 0
2853      | 4 => 0
2854      | 5 => Real.sqrt 2 / 2 := by
2855  fin_cases f
2856  all_goals
2857    rw [Geometry.CofactorDerivatives.dihedralCos3Sq_eq_poly]
2858    unfold Geometry.CofactorDerivatives.dihedralCos3SqPoly
2859      Geometry.CofactorDerivatives.dihedralCofactorNumeratorPoly
2860      Geometry.CofactorDerivatives.dihedralDenom3Poly
2861    simp [Geometry.DihedralCayleyMenger.oppositeCMVertices]
2862    unfold Geometry.CofactorPolynomial.cmCofactor3Poly
2863      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges
2864    norm_num
2865  · exact four_div_sqrt_thirty_two_eq_sqrt_two_div_two
2866  · exact four_div_sqrt_thirty_two_eq_sqrt_two_div_two
2867
2868/-- Exact local dihedral angle values of the canonical Freudenthal tetrahedron:
2869`π/4`, `π/2`, `π/3`, `π/2`, `π/2`, `π/4`. -/
2870theorem freudenthalLocalDihedralAngle_eq (f : Fin 6) :
2871    freudenthalLocalDihedralAngle f =
2872      match f with
2873      | 0 => Real.pi / 4
2874      | 1 => Real.pi / 2
2875      | 2 => Real.pi / 3
2876      | 3 => Real.pi / 2
2877      | 4 => Real.pi / 2
2878      | 5 => Real.pi / 4 := by
2879  fin_cases f
2880  · unfold freudenthalLocalDihedralAngle Geometry.DihedralDerivatives.dihedralAngle3Sq
2881    rw [freudenthalLocalDihedralCos_eq]
2882    rw [← Real.cos_pi_div_four]
2883    exact Real.arccos_cos (by positivity) (by linarith [Real.pi_pos])
2884  · unfold freudenthalLocalDihedralAngle Geometry.DihedralDerivatives.dihedralAngle3Sq
2885    rw [freudenthalLocalDihedralCos_eq]
2886    exact Real.arccos_zero
2887  · unfold freudenthalLocalDihedralAngle Geometry.DihedralDerivatives.dihedralAngle3Sq
2888    rw [freudenthalLocalDihedralCos_eq]
2889    rw [← Real.cos_pi_div_three]
2890    exact Real.arccos_cos (by positivity) (by linarith [Real.pi_pos])
2891  · unfold freudenthalLocalDihedralAngle Geometry.DihedralDerivatives.dihedralAngle3Sq
2892    rw [freudenthalLocalDihedralCos_eq]
2893    exact Real.arccos_zero
2894  · unfold freudenthalLocalDihedralAngle Geometry.DihedralDerivatives.dihedralAngle3Sq
2895    rw [freudenthalLocalDihedralCos_eq]
2896    exact Real.arccos_zero
2897  · unfold freudenthalLocalDihedralAngle Geometry.DihedralDerivatives.dihedralAngle3Sq
2898    rw [freudenthalLocalDihedralCos_eq]
2899    rw [← Real.cos_pi_div_four]
2900    exact Real.arccos_cos (by positivity) (by linarith [Real.pi_pos])
2901
2902/-- The three local Freudenthal angle identities close exactly. -/
2903theorem freudenthalLocalThreeAngleIdentityTarget :
2904    FreudenthalLocalThreeAngleIdentityTarget := by
2905  unfold FreudenthalLocalThreeAngleIdentityTarget
2906  have h0 := freudenthalLocalDihedralAngle_eq 0
2907  have h1 := freudenthalLocalDihedralAngle_eq 1
2908  have h2 := freudenthalLocalDihedralAngle_eq 2
2909  have h3 := freudenthalLocalDihedralAngle_eq 3
2910  have h4 := freudenthalLocalDihedralAngle_eq 4
2911  have h5 := freudenthalLocalDihedralAngle_eq 5
2912  constructor
2913  · rw [h0, h3, h5]
2914    ring
2915  constructor
2916  · rw [h1, h4]
2917    ring
2918  · rw [h2]
2919    ring
2920
2921/-- The seven displacement-class angle-template identities reduce to the three
2922distinct Freudenthal local angle identities. -/
2923theorem freudenthalLocalDispAngleTemplateTarget_of_threeAngleIdentities
2924    (h : FreudenthalLocalThreeAngleIdentityTarget) :
2925    FreudenthalLocalDispAngleTemplateTarget := by
2926  intro d
2927  rcases h with ⟨hAxis, hFace, hBody⟩
2928  fin_cases d <;> simp [freudenthalLocalDispAngleSumTemplate, hAxis, hFace, hBody]
2929
2930/-- The seven displacement-class angle-template identities for the canonical
2931Freudenthal tetrahedron. -/
2932theorem freudenthalLocalDispAngleTemplateTarget :
2933    FreudenthalLocalDispAngleTemplateTarget :=
2934  freudenthalLocalDispAngleTemplateTarget_of_threeAngleIdentities
2935    freudenthalLocalThreeAngleIdentityTarget
2936
2937/-- Closed-form length-chain slot weight for one local Freudenthal pair:
2938`∂θ_e/∂L_k · √L_k` at the canonical Freudenthal tetrahedron. -/
2939noncomputable def freudenthalLocalPairClosedFormSlotWeight
2940    (pair : FreudenthalLocalPair) (k : Fin 6) : ℝ :=
2941  dihedralClosedDerivLength Geometry.FreudenthalCubeTriangulation.freudenthalTet pair.2 k *
2942    Real.sqrt (Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges k)
2943
2944/-- Per-displacement-class endpoint-template form of the explicit-fiber mixed
2945target: after the encoded closed-form fiber sum is identified with a function
2946`F d ξ₀ ξ₁` of the two endpoint potentials only, it must satisfy
2947`√s_d · (ξ₀+ξ₁)/2 · (-F d ξ₀ ξ₁) = √s_d · (ξ₀-ξ₁)²`. -/
2948def FreudenthalLocalDispLengthChainEndpointTemplateTarget
2949    (d : Fin 7) (F : ℝ → ℝ → ℝ) : Prop :=
2950  ∀ ξ₀ ξ₁ : ℝ,
2951    Real.sqrt (periodicDispSqEdge d) * (ξ₀ + ξ₁) / 2 * (-F ξ₀ ξ₁) =
2952      Real.sqrt (periodicDispSqEdge d) * (ξ₀ - ξ₁) ^ (2 : ℕ)
2953
2954/-- The three distinct local Freudenthal length-chain endpoint identities
2955underlying the seven positive displacement classes. -/
2956def FreudenthalLocalThreeLengthChainEndpointTemplateTarget
2957    (F : Fin 7 → ℝ → ℝ → ℝ) : Prop :=
2958  FreudenthalLocalDispLengthChainEndpointTemplateTarget 0 (F 0) ∧
2959    FreudenthalLocalDispLengthChainEndpointTemplateTarget 3 (F 3) ∧
2960    FreudenthalLocalDispLengthChainEndpointTemplateTarget 6 (F 6)
2961
2962/-- The base/displacement-filtered periodic zero-deficit target follows from
2963the seven local displacement-class angle-template identities. -/
2964theorem canonicalPeriodicBaseDispFilteredLocalSlotTripleAngleSumTarget_of_localDispAngleTemplates
2965    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
2966    (hAngle : FreudenthalLocalDispAngleTemplateTarget) :
2967    CanonicalPeriodicBaseDispFilteredLocalSlotTripleAngleSumTarget Nx Ny Nz := by
2968  intro edge
2969  rw [canonicalPeriodicBaseDispFilteredLocalSlotTripleSum_eq_angleTemplate edge]
2970  exact hAngle edge.disp
2971
2972/-- The base/displacement-filtered periodic zero-deficit target holds for the
2973canonical Freudenthal local angles. -/
2974theorem canonicalPeriodicBaseDispFilteredLocalSlotTripleAngleSumTarget_holds
2975    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] :
2976    CanonicalPeriodicBaseDispFilteredLocalSlotTripleAngleSumTarget Nx Ny Nz :=
2977  canonicalPeriodicBaseDispFilteredLocalSlotTripleAngleSumTarget_of_localDispAngleTemplates
2978    Nx Ny Nz freudenthalLocalDispAngleTemplateTarget
2979
2980/-- Exact finite multiplicity table for the local Freudenthal edge slots by
2981positive displacement class. -/
2982theorem freudenthalLocalPairDisp_fiber_card (d : Fin 7) :
2983    ((Finset.univ : Finset FreudenthalLocalPair).filter
2984      (fun pair => freudenthalLocalPairDisp pair = d)).card =
2985      freudenthalLocalDispMultiplicity d := by
2986  fin_cases d <;> native_decide
2987
2988/-- Every positive displacement class occurs among the local Freudenthal
2989edge slots. -/
2990theorem freudenthalLocalDispMultiplicity_pos (d : Fin 7) :
2991    0 < freudenthalLocalDispMultiplicity d := by
2992  fin_cases d <;> native_decide
2993
2994/-- The seven local displacement-class multiplicities account for all
2995`6 × 6 = 36` local Freudenthal `(tet, edge-slot)` pairs. -/
2996theorem freudenthalLocalDispMultiplicity_sum :
2997    (∑ d : Fin 7, freudenthalLocalDispMultiplicity d) =
2998      Fintype.card FreudenthalLocalPair := by
2999  native_decide
3000
3001/-- Slot-witness-filter version of the incident angle-sum target.  This names
3002the form in which every incident summand carries an explicit local edge slot
3003`f`. -/
3004def CanonicalPeriodicSlotWitnessFilteredEdgeAngleSumTarget
3005    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] : Prop :=
3006  ∀ edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz,
3007    (∑ cellTet ∈
3008      (Finset.univ.filter
3009        (fun cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz =>
3010          canonicalPeriodicTypedEdgeIncidentSlotWitness edge cellTet)),
3011      canonicalPeriodicTypedEdgeAngleContribution edge cellTet) =
3012      2 * Real.pi
3013
3014/-- The slot-witness filtered angle-sum target implies the `isSome` incident
3015filtered target. -/
3016theorem canonicalPeriodicIncidentFilteredEdgeAngleSumTarget_of_slotWitnessFiltered
3017    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3018    (hSlot :
3019      CanonicalPeriodicSlotWitnessFilteredEdgeAngleSumTarget Nx Ny Nz) :
3020    CanonicalPeriodicIncidentFilteredEdgeAngleSumTarget Nx Ny Nz := by
3021  intro edge
3022  have hFilter :
3023      (Finset.univ.filter
3024        (fun cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz =>
3025          canonicalPeriodicTypedEdgeIncident edge cellTet)) =
3026      (Finset.univ.filter
3027        (fun cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz =>
3028          canonicalPeriodicTypedEdgeIncidentSlotWitness edge cellTet)) := by
3029    ext cellTet
3030    simp [canonicalPeriodicTypedEdgeIncident_iff_slotWitness edge cellTet]
3031  rw [hFilter]
3032  exact hSlot edge
3033
3034/-- The geometric `localEdgeOf` filtered target implies the slot-witness
3035filtered target. -/
3036theorem canonicalPeriodicSlotWitnessFilteredEdgeAngleSumTarget_of_localEdgeOfFiltered
3037    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3038    (hLocal :
3039      CanonicalPeriodicLocalEdgeOfFilteredEdgeAngleSumTarget Nx Ny Nz) :
3040    CanonicalPeriodicSlotWitnessFilteredEdgeAngleSumTarget Nx Ny Nz := by
3041  intro edge
3042  have hFilter :
3043      (Finset.univ.filter
3044        (fun cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz =>
3045          canonicalPeriodicTypedEdgeIncidentSlotWitness edge cellTet)) =
3046      (Finset.univ.filter
3047        (fun cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz =>
3048          canonicalPeriodicTypedEdgeLocalEdgeOfWitness edge cellTet)) := by
3049    ext cellTet
3050    simp [canonicalPeriodicTypedEdgeIncidentSlotWitness_iff_localEdgeOf edge cellTet]
3051  rw [hFilter]
3052  exact hLocal edge
3053
3054/-- The explicit triple-sum target implies the direct typed cell/tetrahedron
3055angle-sum target. -/
3056theorem canonicalPeriodicDirectTypedEdgeAngleSumTarget_of_localSlotTriple
3057    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3058    (hTriple : CanonicalPeriodicLocalSlotTripleAngleSumTarget Nx Ny Nz) :
3059    CanonicalPeriodicDirectTypedEdgeAngleSumTarget Nx Ny Nz := by
3060  intro edge
3061  calc
3062    (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3063        canonicalPeriodicTypedEdgeAngleContribution edge cellTet)
3064        =
3065      ∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3066        ∑ f : Fin 6,
3067          if edge = localEdgeOf cellTet.1 cellTet.2 f then
3068            freudenthalLocalDihedralAngle f else 0 := by
3069        refine Finset.sum_congr rfl ?_
3070        intro cellTet _
3071        exact canonicalPeriodicTypedEdgeAngleContribution_eq_sum_localSlots edge cellTet
3072    _ = 2 * Real.pi := hTriple edge
3073
3074/-- The displacement-filtered triple-sum target implies the raw local-slot
3075triple-sum target because displacement-mismatched slots cannot equal the typed
3076edge. -/
3077theorem canonicalPeriodicLocalSlotTripleAngleSumTarget_of_dispFiltered
3078    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3079    (hDisp :
3080      CanonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget Nx Ny Nz) :
3081    CanonicalPeriodicLocalSlotTripleAngleSumTarget Nx Ny Nz := by
3082  intro edge
3083  calc
3084    (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3085      ∑ f : Fin 6,
3086        if edge = localEdgeOf cellTet.1 cellTet.2 f then
3087          freudenthalLocalDihedralAngle f else 0) =
3088      (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3089        ∑ f ∈ (Finset.univ.filter
3090          (fun f : Fin 6 => edge.disp = cubeEdgeDisp
3091            (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
3092          if edge = localEdgeOf cellTet.1 cellTet.2 f then
3093            freudenthalLocalDihedralAngle f else 0) := by
3094        refine Finset.sum_congr rfl ?_
3095        intro cellTet _
3096        exact canonicalPeriodicLocalSlotSum_eq_dispFiltered edge cellTet
3097    _ = 2 * Real.pi := hDisp edge
3098
3099/-- The base-and-displacement filtered target implies the displacement-filtered
3100target because, within a displacement class, full edge equality is equivalent
3101to the base-offset equation. -/
3102theorem canonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget_of_baseDispFiltered
3103    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3104    (hBase :
3105      CanonicalPeriodicBaseDispFilteredLocalSlotTripleAngleSumTarget Nx Ny Nz) :
3106    CanonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget Nx Ny Nz := by
3107  intro edge
3108  calc
3109    (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3110      ∑ f ∈ (Finset.univ.filter
3111        (fun f : Fin 6 => edge.disp = cubeEdgeDisp
3112          (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
3113        if edge = localEdgeOf cellTet.1 cellTet.2 f then
3114          freudenthalLocalDihedralAngle f else 0) =
3115      (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3116        ∑ f ∈ (Finset.univ.filter
3117          (fun f : Fin 6 => edge.disp = cubeEdgeDisp
3118            (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
3119          if edge.base = addVertexBits cellTet.1
3120            (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) then
3121            freudenthalLocalDihedralAngle f else 0) := by
3122        refine Finset.sum_congr rfl ?_
3123        intro cellTet _
3124        exact canonicalPeriodicDispFilteredLocalSlotSum_eq_baseFiltered edge cellTet
3125    _ = 2 * Real.pi := hBase edge
3126
3127/-- The incident-filter angle-sum target implies the direct typed target because
3128nonincident typed cell/tetrahedron pairs contribute zero. -/
3129theorem canonicalPeriodicDirectTypedEdgeAngleSumTarget_of_incidentFiltered
3130    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3131    (hIncident : CanonicalPeriodicIncidentFilteredEdgeAngleSumTarget Nx Ny Nz) :
3132    CanonicalPeriodicDirectTypedEdgeAngleSumTarget Nx Ny Nz := by
3133  intro edge
3134  have hAllToFilter :
3135      (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3136        canonicalPeriodicTypedEdgeAngleContribution edge cellTet) =
3137      ∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3138        if canonicalPeriodicTypedEdgeIncident edge cellTet then
3139          canonicalPeriodicTypedEdgeAngleContribution edge cellTet else 0 := by
3140    refine Finset.sum_congr rfl ?_
3141    intro cellTet _
3142    by_cases hInc : canonicalPeriodicTypedEdgeIncident edge cellTet
3143    · simp [hInc]
3144    · have hnone : canonicalEdgeSlot? edge cellTet.1 cellTet.2 = none := by
3145        unfold canonicalPeriodicTypedEdgeIncident at hInc
3146        cases hslot : canonicalEdgeSlot? edge cellTet.1 cellTet.2 with
3147        | none => rfl
3148        | some f => simp [hslot] at hInc
3149      simp [canonicalPeriodicTypedEdgeAngleContribution, hnone, hInc]
3150  have hFilter :
3151      (∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3152        if canonicalPeriodicTypedEdgeIncident edge cellTet then
3153          canonicalPeriodicTypedEdgeAngleContribution edge cellTet else 0) =
3154      ∑ cellTet ∈
3155        (Finset.univ.filter
3156          (fun cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz =>
3157            canonicalPeriodicTypedEdgeIncident edge cellTet)),
3158        canonicalPeriodicTypedEdgeAngleContribution edge cellTet := by
3159    rw [Finset.sum_filter]
3160  rw [hAllToFilter, hFilter]
3161  exact hIncident edge
3162
3163/-- The direct typed-cell/tetrahedron angle-sum target implies the typed-edge
3164target with the canonical tetrahedron finite-index encoder. -/
3165theorem canonicalPeriodicTypedEdgeAngleSumTarget_of_directTyped
3166    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3167    (hDirect : CanonicalPeriodicDirectTypedEdgeAngleSumTarget Nx Ny Nz) :
3168    CanonicalPeriodicTypedEdgeAngleSumTarget Nx Ny Nz := by
3169  intro edge
3170  have hReindex :
3171      (∑ τ : Fin (Fintype.card (Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz)),
3172        canonicalPeriodicTypedEdgeAngleContribution edge (tetFinEquiv Nx Ny Nz τ)) =
3173        ∑ cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz,
3174          canonicalPeriodicTypedEdgeAngleContribution edge cellTet :=
3175    Fintype.sum_equiv (tetFinEquiv Nx Ny Nz)
3176      (fun τ : Fin (Fintype.card (Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz)) =>
3177        canonicalPeriodicTypedEdgeAngleContribution edge (tetFinEquiv Nx Ny Nz τ))
3178      (fun cellTet : Geometry.PeriodicFreudenthalTorus.PeriodicTet Nx Ny Nz =>
3179        canonicalPeriodicTypedEdgeAngleContribution edge cellTet)
3180      (fun _τ => rfl)
3181  rw [hReindex]
3182  exact hDirect edge
3183
3184/-- The displacement-filtered local-slot triple target holds for the canonical
3185Freudenthal local angles. -/
3186theorem canonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget_holds
3187    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] :
3188    CanonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget Nx Ny Nz :=
3189  canonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget_of_baseDispFiltered
3190    Nx Ny Nz
3191    (canonicalPeriodicBaseDispFilteredLocalSlotTripleAngleSumTarget_holds
3192      Nx Ny Nz)
3193
3194/-- The raw local-slot triple target holds for the canonical Freudenthal local
3195angles. -/
3196theorem canonicalPeriodicLocalSlotTripleAngleSumTarget_holds
3197    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] :
3198    CanonicalPeriodicLocalSlotTripleAngleSumTarget Nx Ny Nz :=
3199  canonicalPeriodicLocalSlotTripleAngleSumTarget_of_dispFiltered
3200    Nx Ny Nz
3201    (canonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget_holds
3202      Nx Ny Nz)
3203
3204/-- The direct typed edge angle-sum target holds for the canonical Freudenthal
3205local angles. -/
3206theorem canonicalPeriodicDirectTypedEdgeAngleSumTarget_holds
3207    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] :
3208    CanonicalPeriodicDirectTypedEdgeAngleSumTarget Nx Ny Nz :=
3209  canonicalPeriodicDirectTypedEdgeAngleSumTarget_of_localSlotTriple
3210    Nx Ny Nz
3211    (canonicalPeriodicLocalSlotTripleAngleSumTarget_holds Nx Ny Nz)
3212
3213/-- The typed-edge angle-sum target holds for the canonical Freudenthal local
3214angles. -/
3215theorem canonicalPeriodicTypedEdgeAngleSumTarget_holds
3216    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz] :
3217    CanonicalPeriodicTypedEdgeAngleSumTarget Nx Ny Nz :=
3218  canonicalPeriodicTypedEdgeAngleSumTarget_of_directTyped
3219    Nx Ny Nz
3220    (canonicalPeriodicDirectTypedEdgeAngleSumTarget_holds Nx Ny Nz)
3221
3222/-- Canonical periodic Freudenthal zero-deficit target, sharpened to the exact
3223incident local edge slots.  The remaining geometric task is to prove this sum:
3224for every encoded periodic edge, the Freudenthal dihedral angles contributed by
3225all incident tetrahedra add to `2π`. -/
3226def CanonicalPeriodicZeroDeficitAngleSumTarget
3227    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3228    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3229  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3230  ∀ e : Fin P.K.nE,
3231    (∑ τ : Fin P.K.nT,
3232      match P.K.edgeInTet e τ with
3233      | some f => freudenthalLocalDihedralAngle f
3234      | none => 0) =
3235      2 * Real.pi
3236
3237/-- The typed-edge angle-sum target implies the canonical encoded
3238finite-index target. -/
3239theorem canonicalPeriodicZeroDeficitAngleSumTarget_of_typedEdgeAngleSum
3240    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3241    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3242    (hTyped : CanonicalPeriodicTypedEdgeAngleSumTarget Nx Ny Nz) :
3243    CanonicalPeriodicZeroDeficitAngleSumTarget Nx Ny Nz hx hy hz := by
3244  intro e
3245  have h := hTyped (edgeFinEquiv Nx Ny Nz e)
3246  simpa [CanonicalPeriodicTypedEdgeAngleSumTarget,
3247    canonicalPeriodicTypedEdgeAngleContribution,
3248    CanonicalPeriodicZeroDeficitAngleSumTarget,
3249    canonicalEncodedPeriodicFreudenthalTorus,
3250    canonicalEncodedPeriodicFreudenthalTorus_of_endpoint,
3251    canonicalEncodedPeriodicFreudenthalTorus_of_incidence,
3252    canonicalPeriodicTriangulation,
3253    canonicalEdgeInTet] using h
3254
3255/-- The canonical encoded zero-deficit angle-sum target holds for the
3256periodic Freudenthal torus. -/
3257theorem canonicalPeriodicZeroDeficitAngleSumTarget_holds
3258    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3259    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
3260    CanonicalPeriodicZeroDeficitAngleSumTarget Nx Ny Nz hx hy hz :=
3261  canonicalPeriodicZeroDeficitAngleSumTarget_of_typedEdgeAngleSum
3262    Nx Ny Nz hx hy hz
3263    (canonicalPeriodicTypedEdgeAngleSumTarget_holds Nx Ny Nz)
3264
3265/-- The canonical incident-angle-sum target is exactly the flat
3266`localDeficitAngleContribution` sum after evaluating the conformal chart at the
3267zero potential. -/
3268theorem canonicalPeriodicFlatDeficitAngleSumTarget_of_incidentAngleSum
3269    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3270    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3271    (hSum : CanonicalPeriodicZeroDeficitAngleSumTarget Nx Ny Nz hx hy hz) :
3272    FlatDeficitAngleSumTarget
3273      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K := by
3274  intro e
3275  have h := hSum e
3276  simpa [CanonicalPeriodicZeroDeficitAngleSumTarget,
3277    FlatDeficitAngleSumTarget,
3278    localDeficitAngleContribution,
3279    tetDihedralAngleUnderConformal,
3280    conformalTetSqEdges_zero,
3281    canonicalEncodedPeriodicFreudenthalTorus,
3282    canonicalEncodedPeriodicFreudenthalTorus_of_endpoint,
3283    canonicalEncodedPeriodicFreudenthalTorus_of_incidence,
3284    canonicalPeriodicTriangulation] using h
3285
3286/-- Canonical periodic Freudenthal flat-deficit zero, reduced to the exact
3287incident Freudenthal dihedral-angle sum. -/
3288theorem canonicalPeriodicFlatDeficitZeroTarget_of_incidentAngleSum
3289    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3290    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3291    (hSum : CanonicalPeriodicZeroDeficitAngleSumTarget Nx Ny Nz hx hy hz) :
3292    FlatDeficitZeroTarget
3293      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K :=
3294  flatDeficitZeroTarget_of_angleSum
3295    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3296    (canonicalPeriodicFlatDeficitAngleSumTarget_of_incidentAngleSum
3297      Nx Ny Nz hx hy hz hSum)
3298
3299/-- The global zero-deficit input for the canonical periodic Freudenthal torus,
3300reduced to the exact incident Freudenthal dihedral-angle sum. -/
3301theorem canonicalPeriodicGlobalZeroDeficitAtFlat_of_incidentAngleSum
3302    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3303    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3304    (hSum : CanonicalPeriodicZeroDeficitAngleSumTarget Nx Ny Nz hx hy hz) :
3305    GlobalZeroDeficitAtFlat
3306      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K :=
3307  globalZeroDeficitAtFlat_of_angleSum
3308    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3309    (canonicalPeriodicFlatDeficitAngleSumTarget_of_incidentAngleSum
3310      Nx Ny Nz hx hy hz hSum)
3311
3312/-- Canonical periodic Freudenthal flat-deficit zero. -/
3313theorem canonicalPeriodicFlatDeficitZeroTarget
3314    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3315    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
3316    FlatDeficitZeroTarget
3317      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K :=
3318  canonicalPeriodicFlatDeficitZeroTarget_of_incidentAngleSum
3319    Nx Ny Nz hx hy hz
3320    (canonicalPeriodicZeroDeficitAngleSumTarget_holds Nx Ny Nz hx hy hz)
3321
3322/-- Canonical periodic Freudenthal global zero-deficit at the flat
3323configuration. -/
3324theorem canonicalPeriodicGlobalZeroDeficitAtFlat
3325    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3326    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
3327    GlobalZeroDeficitAtFlat
3328      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K :=
3329  canonicalPeriodicGlobalZeroDeficitAtFlat_of_incidentAngleSum
3330    Nx Ny Nz hx hy hz
3331    (canonicalPeriodicZeroDeficitAngleSumTarget_holds Nx Ny Nz hx hy hz)
3332
3333/-- If every flat deficit angle vanishes, then the Regge action at the flat
3334potential is zero.  This is the finite-sum reduction behind the flat-action
3335zero input used by the scaled quadratic normalization layer. -/
3336theorem reggeAction_zeroPotential_eq_zero_of_flatDeficit
3337    (K : Triangulation3D) (hK : IncidenceConsistent K)
3338    (hDeficit : FlatDeficitZeroTarget K) :
3339    reggeAction K hK (zeroPotential K) = 0 := by
3340  unfold reggeAction
3341  apply Finset.sum_eq_zero
3342  intro e _he
3343  rw [hDeficit e, mul_zero]
3344
3345/-- Canonical periodic-Freudenthal flat-action normalization, reduced exactly to
3346flat deficit zero on the encoded periodic torus. -/
3347theorem canonicalPeriodicReggeAction_zeroPotential_eq_zero_of_flatDeficit
3348    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3349    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3350    (hDeficit :
3351      FlatDeficitZeroTarget
3352        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
3353    reggeAction
3354        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3355        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3356        (zeroPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) = 0 :=
3357  reggeAction_zeroPotential_eq_zero_of_flatDeficit
3358    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3359    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3360    hDeficit
3361
3362/-- Flat-action normalization from the standard flat-configuration package. -/
3363theorem reggeAction_zeroPotential_eq_zero_of_flatConfiguration
3364    (K : Triangulation3D) (hK : IncidenceConsistent K)
3365    (hFlat : FlatConfiguration K hK) :
3366    reggeAction K hK (zeroPotential K) = 0 :=
3367  reggeAction_zeroPotential_eq_zero_of_flatDeficit K hK
3368    (FlatDeficitZeroTarget.of_flatConfiguration K hK hFlat)
3369
3370/-- Canonical periodic-Freudenthal flat-action normalization from the standard
3371flat-configuration package. -/
3372theorem canonicalPeriodicReggeAction_zeroPotential_eq_zero_of_flatConfiguration
3373    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3374    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3375    (hFlat :
3376      FlatConfiguration
3377        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3378        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK) :
3379    reggeAction
3380        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3381        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3382        (zeroPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) = 0 :=
3383  canonicalPeriodicReggeAction_zeroPotential_eq_zero_of_flatDeficit
3384    Nx Ny Nz hx hy hz
3385    (FlatDeficitZeroTarget.of_flatConfiguration
3386      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3387      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3388      hFlat)
3389
3390/-- The exact remaining data needed to build the canonical periodic
3391`FlatConfiguration`: a local analytic chart for the encoded Freudenthal torus
3392and global zero-deficit at the flat potential.  Smoothness is not included
3393because it is already constructed from the local chart by
3394`reggeActionContDiffFromLocalChart_of_localChart`. -/
3395structure CanonicalPeriodicFlatConfigurationInputs
3396    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3397    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
3398  localChart :
3399    LocalAnalyticFlatChart
3400      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3401  global_zero_deficit :
3402    GlobalZeroDeficitAtFlat
3403      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3404
3405/-- The local analytic chart for the canonical periodic Freudenthal torus
3406reduces to a single realized nondegenerate copy of the one-cube Freudenthal
3407tetrahedron, since every encoded periodic tetrahedron is the same local
3408Freudenthal tetrahedron. -/
3409def canonicalPeriodicLocalAnalyticFlatChart_of_realizedFreudenthalTet
3410    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3411    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3412    (T : Geometry.AffineIndepInterior.RealizedNonDegenerateTet)
3413    (hT : T.tet = Geometry.FreudenthalCubeTriangulation.freudenthalTet) :
3414    LocalAnalyticFlatChart
3415      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K where
3416  realizedTet := fun _τ => T
3417  realizes_tet := by
3418    intro τ
3419    rw [hT]
3420    rfl
3421
3422/-- Build the realized nondegenerate Freudenthal tetrahedron package from a
3423concrete Euclidean realization whose six squared edges match the one-cube
3424Freudenthal edge tuple. -/
3425def realizedFreudenthalTet_of_sqEdgeOfPoints
3426    (R : Geometry.TetrahedronRealization.RealizedTet)
3427    (hSq :
3428      Geometry.TetrahedronRealization.sqEdgeOfPoints R =
3429        Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges) :
3430    Geometry.AffineIndepInterior.RealizedNonDegenerateTet where
3431  tet := Geometry.FreudenthalCubeTriangulation.freudenthalTet
3432  realization := R
3433  realizes := by
3434    rw [hSq]
3435    rfl
3436
3437/-- Explicit Euclidean coordinates for the one-cube Freudenthal tetrahedron
3438with vertices `(0,0,0)`, `(1,0,0)`, `(1,1,0)`, and `(1,1,1)`.  In the
3439tetrahedral edge order this gives squared lengths `(1,2,3,1,2,1)`. -/
3440def freudenthalRealizationPoints : Fin 4 → EuclideanSpace ℝ (Fin 3)
3441  | 0 => 0
3442  | 1 => EuclideanSpace.single 0 (1 : ℝ)
3443  | 2 => EuclideanSpace.single 0 (1 : ℝ) + EuclideanSpace.single 1 (1 : ℝ)
3444  | 3 =>
3445      EuclideanSpace.single 0 (1 : ℝ) + EuclideanSpace.single 1 (1 : ℝ) +
3446        EuclideanSpace.single 2 (1 : ℝ)
3447
3448/-- Reindex the three nonzero vertices of the Freudenthal tetrahedron by
3449`Fin 3`, sending `0,1,2` to vertices `1,2,3`. -/
3450private def freudenthalNonzeroVertexEquiv : Fin 3 ≃ {j : Fin 4 // j ≠ 0} where
3451  toFun i := ⟨i.succ, Fin.succ_ne_zero i⟩
3452  invFun j := j.1.pred j.2
3453  left_inv i := Fin.pred_succ i
3454  right_inv j := Subtype.ext (Fin.succ_pred j.1 j.2)
3455
3456/-- The explicit one-cube Freudenthal tetrahedron coordinates are affinely
3457independent.  After reindexing the nonzero vertices, the coordinate matrix is
3458upper triangular with diagonal entries `1`. -/
3459theorem freudenthalRealizationPoints_affineIndependent :
3460    AffineIndependent ℝ freudenthalRealizationPoints := by
3461  rw [affineIndependent_iff_linearIndependent_vsub ℝ freudenthalRealizationPoints (0 : Fin 4)]
3462  apply (linearIndependent_equiv freudenthalNonzeroVertexEquiv).mp
3463  rw [Fintype.linearIndependent_iff]
3464  intro g hg i
3465  have hcoord := congrArg (EuclideanSpace.equiv (𝕜 := ℝ) (ι := Fin 3)) hg
3466  simp [freudenthalNonzeroVertexEquiv, freudenthalRealizationPoints, Fin.sum_univ_three] at hcoord
3467  have h2 := congrFun hcoord (2 : Fin 3)
3468  have h1 := congrFun hcoord (1 : Fin 3)
3469  have h0 := congrFun hcoord (0 : Fin 3)
3470  fin_cases i <;> simp at h0 h1 h2 ⊢ <;> linarith
3471
3472/-- The explicit Freudenthal coordinates as a `RealizedTet`, once affine
3473independence of the four points is supplied. -/
3474def freudenthalRealizedTet_of_affineIndependent
3475    (hAffine : AffineIndependent ℝ freudenthalRealizationPoints) :
3476    Geometry.TetrahedronRealization.RealizedTet where
3477  p := freudenthalRealizationPoints
3478  nondegenerate := hAffine
3479
3480/-- The explicit coordinate realization has the Freudenthal squared-edge tuple.
3481This leaves only affine independence as the local geometric proof needed to
3482build a `RealizedTet`. -/
3483theorem freudenthalRealizedTet_of_affineIndependent_sqEdgeOfPoints
3484    (hAffine : AffineIndependent ℝ freudenthalRealizationPoints) :
3485    Geometry.TetrahedronRealization.sqEdgeOfPoints
3486        (freudenthalRealizedTet_of_affineIndependent hAffine) =
3487      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges := by
3488  funext e
3489  fin_cases e <;>
3490    simp [freudenthalRealizedTet_of_affineIndependent, freudenthalRealizationPoints,
3491      Geometry.TetrahedronRealization.sqEdgeOfPoints,
3492      Geometry.TetrahedronRealization.vertexSqDist,
3493      Geometry.TetrahedronRealization.edgeVector,
3494      Geometry.TetrahedronRealization.edgeVertices3,
3495      Geometry.ReggeRigorousFoundation.edgeVertices,
3496      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges,
3497      EuclideanSpace.norm_sq_eq, Fin.sum_univ_three] <;>
3498    norm_num
3499
3500/-- The explicit Freudenthal coordinate tetrahedron, with affine independence
3501proved from the triangular coordinate matrix. -/
3502def freudenthalRealizedTet : Geometry.TetrahedronRealization.RealizedTet :=
3503  freudenthalRealizedTet_of_affineIndependent freudenthalRealizationPoints_affineIndependent
3504
3505/-- The fully explicit coordinate realization has the Freudenthal squared-edge
3506tuple, with no remaining affine-independence hypothesis. -/
3507theorem freudenthalRealizedTet_sqEdgeOfPoints :
3508    Geometry.TetrahedronRealization.sqEdgeOfPoints freudenthalRealizedTet =
3509      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges :=
3510  freudenthalRealizedTet_of_affineIndependent_sqEdgeOfPoints
3511    freudenthalRealizationPoints_affineIndependent
3512
3513/-- Package the two geometric inputs for canonical periodic flatness after the
3514local analytic chart has been reduced to one realized Freudenthal tetrahedron.
3515The remaining global input is the zero-deficit angle sum around each encoded
3516periodic edge. -/
3517def canonicalPeriodicFlatConfigurationInputs_of_realizedFreudenthalTet_zeroDeficit
3518    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3519    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3520    (T : Geometry.AffineIndepInterior.RealizedNonDegenerateTet)
3521    (hT : T.tet = Geometry.FreudenthalCubeTriangulation.freudenthalTet)
3522    (hZero :
3523      GlobalZeroDeficitAtFlat
3524        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
3525    CanonicalPeriodicFlatConfigurationInputs Nx Ny Nz hx hy hz where
3526  localChart :=
3527    canonicalPeriodicLocalAnalyticFlatChart_of_realizedFreudenthalTet
3528      Nx Ny Nz hx hy hz T hT
3529  global_zero_deficit := hZero
3530
3531/-- Construct the canonical periodic flat configuration from its two geometric
3532inputs. -/
3533def CanonicalPeriodicFlatConfigurationInputs.toFlatConfiguration
3534    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
3535    {hx : 2 < Nx} {hy : 2 < Ny} {hz : 2 < Nz}
3536    (I : CanonicalPeriodicFlatConfigurationInputs Nx Ny Nz hx hy hz) :
3537    FlatConfiguration
3538      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3539      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK :=
3540  flatConfiguration_of_localChart_zeroDeficit
3541    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3542    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3543    I.localChart
3544    I.global_zero_deficit
3545    (reggeActionContDiffFromLocalChart_of_localChart
3546      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3547      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3548      I.localChart)
3549
3550/-- Direct canonical periodic flat configuration from one realized Freudenthal
3551tetrahedron plus global zero-deficit. -/
3552def canonicalPeriodicFlatConfiguration_of_realizedFreudenthalTet_zeroDeficit
3553    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3554    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3555    (T : Geometry.AffineIndepInterior.RealizedNonDegenerateTet)
3556    (hT : T.tet = Geometry.FreudenthalCubeTriangulation.freudenthalTet)
3557    (hZero :
3558      GlobalZeroDeficitAtFlat
3559        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
3560    FlatConfiguration
3561      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3562      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK :=
3563  (canonicalPeriodicFlatConfigurationInputs_of_realizedFreudenthalTet_zeroDeficit
3564    Nx Ny Nz hx hy hz T hT hZero).toFlatConfiguration
3565
3566/-- Canonical periodic flat-configuration inputs with both geometric sides
3567discharged: the local chart comes from the explicit Freudenthal coordinate
3568tetrahedron and global zero deficit comes from the certified periodic
3569angle-sum chain. -/
3570def canonicalPeriodicFlatConfigurationInputs
3571    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3572    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
3573    CanonicalPeriodicFlatConfigurationInputs Nx Ny Nz hx hy hz :=
3574  canonicalPeriodicFlatConfigurationInputs_of_realizedFreudenthalTet_zeroDeficit
3575    Nx Ny Nz hx hy hz
3576    (realizedFreudenthalTet_of_sqEdgeOfPoints
3577      freudenthalRealizedTet freudenthalRealizedTet_sqEdgeOfPoints)
3578    rfl
3579    (canonicalPeriodicGlobalZeroDeficitAtFlat Nx Ny Nz hx hy hz)
3580
3581/-- Canonical periodic Freudenthal flat configuration, with no remaining local
3582chart or global zero-deficit input. -/
3583def canonicalPeriodicFlatConfiguration
3584    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3585    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
3586    FlatConfiguration
3587      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3588      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK :=
3589  (canonicalPeriodicFlatConfigurationInputs Nx Ny Nz hx hy hz).toFlatConfiguration
3590
3591/-- Periodic edge-stencil local correspondence from the canonical flat
3592configuration plus the two standard remainder jets. -/
3593theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalFlat_and_remainderJets
3594    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3595    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3596    (hFirst :
3597      ReggeActionRemainderFirstVariationInput
3598        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3599        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3600        (canonicalReggeHessian
3601          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3602          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK))
3603    (hSecond :
3604      ReggeActionRemainderSecondVariationInput
3605        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3606        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK) :
3607    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
3608  canonicalPeriodicEdgeStencilLocalCorrespondence_of_flat_and_remainderJets
3609    Nx Ny Nz hx hy hz
3610    (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
3611    hFirst hSecond
3612
3613/-- Periodic edge-stencil local correspondence from canonical flatness, the
3614remainder first-variation jet, and the nonlinear directional Hessian theorem. -/
3615theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalFlat_first_and_directionalHessian
3616    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3617    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3618    (hFirst :
3619      ReggeActionRemainderFirstVariationInput
3620        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3621        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3622        (canonicalReggeHessian
3623          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3624          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK))
3625    (hHessian :
3626      NonlinearReggeDirectionalHessianTheorem
3627        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3628        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK) :
3629    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
3630  canonicalPeriodicEdgeStencilLocalCorrespondence_of_flat_first_and_directionalHessian
3631    Nx Ny Nz hx hy hz
3632    (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
3633    hFirst hHessian
3634
3635/-- Periodic edge-stencil local correspondence from the standard first-variation
3636package and the nonlinear directional Hessian theorem.  The separate remainder
3637first-variation jet is derived from the full first-variation input by
3638`reggeActionRemainderFirstVariationInput_of_firstVariation`. -/
3639theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalFlat_firstVariationInput_and_directionalHessian
3640    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3641    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3642    (hFirst :
3643      ReggeActionFirstVariationInput
3644        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3645        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3646        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
3647    (hHessian :
3648      NonlinearReggeDirectionalHessianTheorem
3649        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3650        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK) :
3651    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz := by
3652  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3653  exact canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalFlat_first_and_directionalHessian
3654    Nx Ny Nz hx hy hz
3655    (reggeActionRemainderFirstVariationInput_of_firstVariation
3656      P.K P.hK
3657      (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
3658      (canonicalReggeHessian P.K P.hK)
3659      hFirst)
3660    hHessian
3661
3662/-- Periodic edge-stencil local correspondence from the standard first-variation
3663package plus the two lower-level geometric Hessian inputs.  This replaces the
3664nonlinear directional Hessian theorem by the already-proved reduction through
3665weighted deficit-derivative eventual zero and mixed hinge-deficit edge-stencil
3666equality. -/
3667theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalFlat_firstVariationInput_eventuallyZero_and_edgeStencil
3668    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3669    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3670    (hFirst :
3671      ReggeActionFirstVariationInput
3672        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3673        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3674        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
3675    (D : DeficitAngleDirectionalDerivativePackage
3676      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3677      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
3678    (hZero :
3679      WeightedDeficitDerivativeEventuallyZeroTarget
3680        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3681        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3682        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
3683    (hMixed :
3684      MixedHingeDeficitEdgeStencilTarget
3685        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3686        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3687        D) :
3688    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz := by
3689  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3690  exact
3691    canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalFlat_firstVariationInput_and_directionalHessian
3692      Nx Ny Nz hx hy hz hFirst
3693      (nonlinearDirectionalHessian_of_eventuallyZero_and_edgeStencil
3694        P.K P.hK
3695        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
3696        D hZero hMixed
3697        (canonicalPeriodicEdgeStencilTarget Nx Ny Nz hx hy hz))
3698
3699/-- Standard Regge first variation for the canonical periodic Freudenthal torus.
3700The input is discharged by the encoded periodic edge-slot partition. -/
3701def canonicalPeriodicFirstVariationInput
3702    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3703    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
3704    ReggeActionFirstVariationInput
3705      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3706      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3707      (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz) :=
3708  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3709  reggeActionFirstVariationInput_of_edgeSlotPartition P.K P.hK
3710    (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
3711    (edgeSlotPartition_of_encodedPeriodicFreudenthalTorus P)
3712
3713/-- Periodic edge-stencil local correspondence from only the two remaining
3714geometric Hessian-side inputs.  Canonical flatness, first variation, edge-stencil
3715Dirichlet equality, and the Taylor/remainder first-variation bridges are all
3716supplied by preceding theorems. -/
3717theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_eventuallyZero_and_edgeStencilTargets
3718    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3719    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3720    (D : DeficitAngleDirectionalDerivativePackage
3721      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3722      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
3723    (hZero :
3724      WeightedDeficitDerivativeEventuallyZeroTarget
3725        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3726        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3727        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
3728    (hMixed :
3729      MixedHingeDeficitEdgeStencilTarget
3730        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3731        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
3732        D) :
3733    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
3734  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalFlat_firstVariationInput_eventuallyZero_and_edgeStencil
3735    Nx Ny Nz hx hy hz
3736    (canonicalPeriodicFirstVariationInput Nx Ny Nz hx hy hz)
3737    D hZero hMixed
3738
3739/-- Canonical local angle chain-rule package for the periodic Freudenthal torus. -/
3740def canonicalPeriodicLocalAngleLengthChainRulePackage
3741    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3742    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
3743    LocalAngleLengthChainRulePackage
3744      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3745      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK :=
3746  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3747  localAngleLengthChainRulePackage_of_sqEdge P.K P.hK
3748    (localAngleSqEdgeChainRulePackage_of_flat P.K P.hK
3749      (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
3750
3751/-- Canonical local dihedral-angle derivative package for the periodic
3752Freudenthal torus. -/
3753def canonicalPeriodicLocalDihedralDerivativePackage
3754    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3755    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
3756    LocalDihedralDirectionalDerivativePackage
3757      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K :=
3758  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3759  localDihedralDirectionalDerivativePackage_of_lengthChain P.K P.hK
3760    (canonicalPeriodicLocalAngleLengthChainRulePackage Nx Ny Nz hx hy hz)
3761
3762/-- Canonical deficit-derivative package for the periodic Freudenthal torus.
3763It is built from the flat local angle chain rule and the encoded periodic
3764edge-slot partition, so the deficit package is no longer arbitrary in the
3765canonical Track 1.B branch. -/
3766def canonicalPeriodicDeficitDerivativePackage
3767    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3768    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
3769    DeficitAngleDirectionalDerivativePackage
3770      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3771      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK :=
3772  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3773  let L := canonicalPeriodicLocalAngleLengthChainRulePackage Nx Ny Nz hx hy hz
3774  let A := canonicalPeriodicLocalDihedralDerivativePackage Nx Ny Nz hx hy hz
3775  deficitPackage_of_conformalSchlaefliCancellation P.K P.hK A
3776    (conformalSchlaefliCancellation_of_lengthChain_of_bookkeeping P.K P.hK L
3777      (conformalSchlaefliIncidenceBookkeeping_of_edgeSlotBookkeeping P.K P.hK A
3778        (edgeSlotBookkeeping_of_encodedPeriodicFreudenthalTorus P)))
3779
3780theorem canonicalPeriodicDeficitDerivativePackage_deficitDeriv
3781    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3782    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
3783    (ξ :
3784      VertexPotential
3785        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
3786    (e : Fin (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K.nE) :
3787    (canonicalPeriodicDeficitDerivativePackage Nx Ny Nz hx hy hz).deficitDeriv ξ e =
3788      deficitDirectionalDerivFromLocalAngles
3789        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
3790        (canonicalPeriodicLocalDihedralDerivativePackage Nx Ny Nz hx hy hz)
3791        ξ e := by
3792  rfl
3793
3794/-- Local-angle finite-sum form of the canonical mixed hinge-deficit target. -/
3795def CanonicalPeriodicMixedHingeDeficitLocalAngleTarget
3796    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3797    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3798  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3799  ∀ ξ : VertexPotential P.K,
3800    (∑ e : Fin P.K.nE,
3801      hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3802        deficitDirectionalDerivFromLocalAngles P.K
3803          (canonicalPeriodicLocalDihedralDerivativePackage Nx Ny Nz hx hy hz) ξ e) =
3804      canonicalEdgeStencilDirichletEnergy P.K P.hK ξ
3805
3806/-- Length-chain finite-sum form of the canonical mixed hinge-deficit target.
3807This unfolds the canonical local dihedral derivative package to the explicit
3808`localAngleLengthChainDeriv` sum over incident tetrahedron slots. -/
3809def CanonicalPeriodicMixedHingeDeficitLengthChainTarget
3810    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3811    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3812  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3813  ∀ ξ : VertexPotential P.K,
3814    (∑ e : Fin P.K.nE,
3815      hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3816        (-∑ τ : Fin P.K.nT,
3817          match P.K.edgeInTet e τ with
3818          | none => 0
3819          | some f => localAngleLengthChainDeriv P.K P.hK ξ τ f)) =
3820      canonicalEdgeStencilDirichletEnergy P.K P.hK ξ
3821
3822/-- Corrected Session 202 mixed hinge-deficit target.  The exact finite audit
3823shows the mixed length-chain quadratic matches the rational axis stencil, not
3824the full seven-class square-root edge stencil used by the older target above. -/
3825def CanonicalPeriodicMixedHingeDeficitAxisStencilTarget
3826    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3827    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3828  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3829  ∀ ξ : VertexPotential P.K,
3830    (∑ e : Fin P.K.nE,
3831      hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3832        (-∑ τ : Fin P.K.nT,
3833          match P.K.edgeInTet e τ with
3834          | none => 0
3835          | some f => localAngleLengthChainDeriv P.K P.hK ξ τ f)) =
3836      canonicalPeriodicMixedAxisStencilAction Nx Ny Nz hx hy hz ξ
3837
3838/-- Fully expanded finite-sum form of the canonical mixed hinge-deficit target.
3839This exposes the local Schläfli derivative coefficients and the conformal
3840local edge-length directional derivatives. -/
3841def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTarget
3842    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3843    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3844  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3845  ∀ ξ : VertexPotential P.K,
3846    (∑ e : Fin P.K.nE,
3847      hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3848        (-∑ τ : Fin P.K.nT,
3849          match P.K.edgeInTet e τ with
3850          | none => 0
3851          | some f =>
3852              ∑ k : Fin 6,
3853                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
3854                  localEdgeLengthDirectionalDeriv P.K ξ τ k)) =
3855      canonicalEdgeStencilDirichletEnergy P.K P.hK ξ
3856
3857/-- Per-edge form of the expanded mixed hinge-deficit target.  This is the
3858finite local identity that remains before summing over global edges. -/
3859def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainPerEdgeTarget
3860    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3861    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3862  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3863  ∀ (ξ : VertexPotential P.K) (e : Fin P.K.nE),
3864    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3865        (-∑ τ : Fin P.K.nT,
3866          match P.K.edgeInTet e τ with
3867          | none => 0
3868          | some f =>
3869              ∑ k : Fin 6,
3870                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
3871                  localEdgeLengthDirectionalDeriv P.K ξ τ k) =
3872      Real.sqrt (P.hK.globalSqEdge e) *
3873        (ξ (P.K.edgeVerts e).1 - ξ (P.K.edgeVerts e).2) ^ (2 : ℕ)
3874
3875/-- Typed periodic-edge form of the expanded per-edge mixed target.  This
3876removes the anonymous `Fin nE` edge index from the remaining local identity. -/
3877def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEdgeTarget
3878    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3879    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3880  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3881  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
3882    let e := P.edgeEquiv.symm edge
3883    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3884        (-∑ τ : Fin P.K.nT,
3885          match P.K.edgeInTet e τ with
3886          | none => 0
3887          | some f =>
3888              ∑ k : Fin 6,
3889                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
3890                  localEdgeLengthDirectionalDeriv P.K ξ τ k) =
3891      Real.sqrt (P.hK.globalSqEdge e) *
3892        (ξ (P.K.edgeVerts e).1 - ξ (P.K.edgeVerts e).2) ^ (2 : ℕ)
3893
3894/-- Typed endpoint form of the expanded mixed target.  The right-hand side is
3895now written directly from the typed periodic edge displacement and endpoints. -/
3896def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget
3897    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3898    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3899  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3900  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
3901    let e := P.edgeEquiv.symm edge
3902    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3903        (-∑ τ : Fin P.K.nT,
3904          match P.K.edgeInTet e τ with
3905          | none => 0
3906          | some f =>
3907              ∑ k : Fin 6,
3908                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
3909                  localEdgeLengthDirectionalDeriv P.K ξ τ k) =
3910      Real.sqrt (periodicDispSqEdge edge.disp) *
3911        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
3912          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
3913
3914/-- Typed slot-guarded form of the expanded mixed target.  This replaces
3915`edgeInTet` by an explicit six-slot guarded sum using the typed equation
3916`edge = localEdgeOf cell tet f`. -/
3917def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedSlotTarget
3918    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3919    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3920  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3921  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
3922    let e := P.edgeEquiv.symm edge
3923    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3924        (-∑ τ : Fin P.K.nT,
3925          ∑ f : Fin 6,
3926            if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
3927              ∑ k : Fin 6,
3928                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
3929                  localEdgeLengthDirectionalDeriv P.K ξ τ k
3930            else 0) =
3931      Real.sqrt (periodicDispSqEdge edge.disp) *
3932        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
3933          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
3934
3935/-- Displacement-filtered form of the typed slot-guarded mixed target.  Local
3936slots whose positive displacement differs from the typed edge cannot contribute. -/
3937def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainDispFilteredTarget
3938    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3939    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3940  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3941  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
3942    let e := P.edgeEquiv.symm edge
3943    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3944        (-∑ τ : Fin P.K.nT,
3945          ∑ f ∈ (Finset.univ.filter
3946            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
3947              (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f))),
3948            if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
3949              ∑ k : Fin 6,
3950                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
3951                  localEdgeLengthDirectionalDeriv P.K ξ τ k
3952            else 0) =
3953      Real.sqrt (periodicDispSqEdge edge.disp) *
3954        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
3955          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
3956
3957/-- Base-and-displacement-filtered form of the expanded mixed target.  After
3958the displacement filter, the remaining edge-equality guard is equivalent to a
3959periodic base-offset equation. -/
3960def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispFilteredTarget
3961    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3962    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3963  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3964  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
3965    let e := P.edgeEquiv.symm edge
3966    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3967        (-∑ τ : Fin P.K.nT,
3968          ∑ f ∈ (Finset.univ.filter
3969            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
3970              (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f))),
3971            if edge.base = addVertexBits (P.tetEquiv τ).1
3972                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f)) then
3973              ∑ k : Fin 6,
3974                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
3975                  localEdgeLengthDirectionalDeriv P.K ξ τ k
3976            else 0) =
3977      Real.sqrt (periodicDispSqEdge edge.disp) *
3978        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
3979          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
3980
3981/-- Typed-cell/tetrahedron form of the base-and-displacement-filtered mixed
3982target.  This removes the anonymous `Fin nT` tetrahedron index. -/
3983def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispTypedTetTarget
3984    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
3985    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
3986  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
3987  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
3988    let e := P.edgeEquiv.symm edge
3989    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
3990        (-∑ cellTet : PeriodicTet Nx Ny Nz,
3991          ∑ f ∈ (Finset.univ.filter
3992            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
3993              (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
3994            if edge.base = addVertexBits cellTet.1
3995                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) then
3996              ∑ k : Fin 6,
3997                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
3998                  (P.tetEquiv.symm cellTet)).dihedralDeriv f k *
3999                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm cellTet) k
4000            else 0) =
4001      Real.sqrt (periodicDispSqEdge edge.disp) *
4002        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
4003          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
4004
4005/-- Product-split version of the typed-tetrahedron mixed target.  The sum over
4006`PeriodicTet = Vertex × Fin 6` is written as an explicit cell sum followed by a
4007local-tetrahedron sum. -/
4008def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispCellTetTarget
4009    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4010    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
4011  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4012  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
4013    let e := P.edgeEquiv.symm edge
4014    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
4015        (-∑ cell : Vertex Nx Ny Nz,
4016          ∑ tet : Fin 6,
4017            ∑ f ∈ (Finset.univ.filter
4018              (fun f : Fin 6 => edge.disp = cubeEdgeDisp
4019                (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
4020              if edge.base = addVertexBits cell
4021                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f)) then
4022                ∑ k : Fin 6,
4023                  ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
4024                    (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
4025                    localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k
4026              else 0) =
4027      Real.sqrt (periodicDispSqEdge edge.disp) *
4028        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
4029          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
4030
4031/-- The unique periodic cell whose translated local base vertex equals a target
4032base vertex. -/
4033noncomputable def periodicMatchingBaseCell
4034    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4035    (a : Fin 8) (target : Vertex Nx Ny Nz) : Vertex Nx Ny Nz :=
4036  Classical.choose (existsUnique_addVertexBits_eq a target)
4037
4038theorem periodicMatchingBaseCell_spec
4039    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4040    (a : Fin 8) (target : Vertex Nx Ny Nz) :
4041    target = addVertexBits (periodicMatchingBaseCell a target) a :=
4042  (Classical.choose_spec (existsUnique_addVertexBits_eq a target)).1
4043
4044theorem periodicMatchingBaseCell_unique
4045    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4046    (a : Fin 8) (target : Vertex Nx Ny Nz)
4047    {cell : Vertex Nx Ny Nz}
4048    (h : target = addVertexBits cell a) :
4049    cell = periodicMatchingBaseCell a target :=
4050  (Classical.choose_spec (existsUnique_addVertexBits_eq a target)).2 cell h
4051
4052/-- Collapse a finite sum over periodic cells guarded by a base-offset equation
4053to the unique matching cell. -/
4054theorem sum_ite_eq_of_addVertexBits_apply
4055    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4056    (a : Fin 8) (target : Vertex Nx Ny Nz)
4057    (F : Vertex Nx Ny Nz → ℝ) :
4058    (∑ cell : Vertex Nx Ny Nz,
4059      if target = addVertexBits cell a then F cell else 0) =
4060      F (periodicMatchingBaseCell a target) := by
4061  classical
4062  rw [Finset.sum_eq_single (periodicMatchingBaseCell a target)]
4063  · rw [if_pos (periodicMatchingBaseCell_spec a target)]
4064  · intro cell _ hne
4065    have hnot : target ≠ addVertexBits cell a := by
4066      intro h
4067      exact hne (periodicMatchingBaseCell_unique a target h)
4068    simp [hnot]
4069  · intro hnot
4070    exact (hnot (Finset.mem_univ _)).elim
4071
4072/-- Local-pair form of the base/displacement-filtered mixed target.  The
4073periodic cell sum has been collapsed to the unique cell solving the base-offset
4074equation for each local pair. -/
4075def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairTarget
4076    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4077    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
4078  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4079  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
4080    let e := P.edgeEquiv.symm edge
4081    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
4082        (-∑ tet : Fin 6,
4083          ∑ f ∈ (Finset.univ.filter
4084            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
4085              (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
4086              let cell :=
4087                periodicMatchingBaseCell
4088                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
4089                  edge.base
4090              ∑ k : Fin 6,
4091                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
4092                  (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
4093                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k) =
4094      Real.sqrt (periodicDispSqEdge edge.disp) *
4095        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
4096          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
4097
4098/-- Single-filtered-local-pair form of the mixed target.  This is the same
4099local-pair content as `CanonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairTarget`,
4100but written over the explicit displacement fiber of `FreudenthalLocalPair`. -/
4101def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairFiberTarget
4102    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4103    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
4104  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4105  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
4106    let e := P.edgeEquiv.symm edge
4107    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
4108        (-∑ pair ∈ ((Finset.univ : Finset FreudenthalLocalPair).filter
4109          (fun pair => freudenthalLocalPairDisp pair = edge.disp)),
4110              let cell :=
4111                periodicMatchingBaseCell
4112                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
4113                  edge.base
4114              ∑ k : Fin 6,
4115                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
4116                  (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
4117                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k) =
4118      Real.sqrt (periodicDispSqEdge edge.disp) *
4119        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
4120          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
4121
4122/-- Explicit table-fiber form of the mixed target, using the precomputed
4123`freudenthalLocalPairDispFiber` table for the typed edge's displacement. -/
4124def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
4125    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4126    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
4127  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4128  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
4129    let e := P.edgeEquiv.symm edge
4130    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
4131        (-∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4132              let cell :=
4133                periodicMatchingBaseCell
4134                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
4135                  edge.base
4136              ∑ k : Fin 6,
4137                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
4138                  (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
4139                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k) =
4140      Real.sqrt (periodicDispSqEdge edge.disp) *
4141        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
4142          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
4143
4144theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairFiberTarget_of_explicitFiber
4145    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4146    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4147    (hExplicit :
4148      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
4149        Nx Ny Nz hx hy hz) :
4150    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairFiberTarget
4151      Nx Ny Nz hx hy hz := by
4152  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4153  intro ξ edge
4154  rw [← freudenthalLocalPairDispFiber_eq_filter edge.disp]
4155  exact hExplicit ξ edge
4156
4157/-- At canonical periodic flatness every encoded tetrahedron carries the
4158one-cube Freudenthal squared-edge tuple. -/
4159theorem canonicalPeriodicFlat_tet_sqEdge_eq_freudenthal
4160    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4161    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4162    (cell : Vertex Nx Ny Nz) (tet : Fin 6) (k : Fin 6) :
4163    ((canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K.tet
4164        ((canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).tetEquiv.symm (cell, tet))).sqEdge k =
4165      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges k := by
4166  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4167  change (P.K.tet (P.tetEquiv.symm (cell, tet))).sqEdge k = _
4168  let τ := P.tetEquiv.symm (cell, tet)
4169  let hChart := (canonicalPeriodicFlatConfigurationInputs Nx Ny Nz hx hy hz).localChart
4170  have ht := hChart.realizes_tet τ
4171  rw [← ht]
4172  have hconst : (hChart.realizedTet τ).tet =
4173      Geometry.FreudenthalCubeTriangulation.freudenthalTet := by
4174    simp [hChart, canonicalPeriodicFlatConfigurationInputs,
4175      canonicalPeriodicFlatConfigurationInputs_of_realizedFreudenthalTet_zeroDeficit,
4176      canonicalPeriodicLocalAnalyticFlatChart_of_realizedFreudenthalTet,
4177      realizedFreudenthalTet_of_sqEdgeOfPoints, freudenthalRealizedTet]
4178  rw [hconst]
4179  simp only [Geometry.FreudenthalCubeTriangulation.freudenthalTet]
4180
4181/-- The unique periodic cell selected by the explicit Freudenthal fiber entry
4182for a typed periodic edge and local `(tet, slot)` pair. -/
4183noncomputable def freudenthalExplicitFiberPairSelectedCell
4184    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4185    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4186    (pair : FreudenthalLocalPair) : Vertex Nx Ny Nz :=
4187  periodicMatchingBaseCell
4188    (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
4189    edge.base
4190
4191theorem freudenthalExplicitFiberPairSelectedCell_base_eq
4192    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4193    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4194    (pair : FreudenthalLocalPair) :
4195    edge.base = addVertexBits (freudenthalExplicitFiberPairSelectedCell edge pair)
4196      (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2)) :=
4197  periodicMatchingBaseCell_spec
4198    (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
4199    edge.base
4200
4201theorem periodicEdge_eq_of_base_disp
4202    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4203    {e1 e2 : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz}
4204    (hbase : e1.base = e2.base) (hdisp : e1.disp = e2.disp) : e1 = e2 := by
4205  cases e1
4206  cases e2
4207  rw [PeriodicEdge.mk.injEq]
4208  exact ⟨hbase, hdisp⟩
4209
4210theorem freudenthalExplicitFiber_localEdgeOf_eq_edge
4211    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4212    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4213    (pair : FreudenthalLocalPair)
4214    (hdisp : freudenthalLocalPairDisp pair = edge.disp) :
4215    localEdgeOf (freudenthalExplicitFiberPairSelectedCell edge pair) pair.1 pair.2 = edge := by
4216  apply periodicEdge_eq_of_base_disp
4217  · dsimp [localEdgeOf, freudenthalExplicitFiberPairSelectedCell]
4218    exact (periodicMatchingBaseCell_spec
4219      (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
4220      edge.base).symm
4221  · dsimp [localEdgeOf, freudenthalLocalPairDisp]
4222    exact hdisp
4223
4224theorem freudenthalExplicitFiber_addVertexBits_tetVerts_edgeSlot_eq_edgeEndpoints
4225    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4226    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4227    (pair : FreudenthalLocalPair)
4228    (hdisp : freudenthalLocalPairDisp pair = edge.disp) :
4229    let cell := freudenthalExplicitFiberPairSelectedCell edge pair
4230    let tv := edgeVertices pair.2
4231    (addVertexBits cell (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1 tv.1) =
4232        edge.endpoints.1 ∧
4233      addVertexBits cell (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1 tv.2) =
4234        edge.endpoints.2) ∨
4235      (addVertexBits cell (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1 tv.1) =
4236          edge.endpoints.2 ∧
4237        addVertexBits cell (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1 tv.2) =
4238          edge.endpoints.1) := by
4239  have hL := freudenthalExplicitFiber_localEdgeOf_eq_edge edge pair hdisp
4240  have hmatch :=
4241    localEdgeOf_endpoints_match_tetVerts (Nx := Nx) (Ny := Ny) (Nz := Nz)
4242      (freudenthalExplicitFiberPairSelectedCell edge pair) pair.1 pair.2
4243  dsimp only at hmatch ⊢
4244  rw [hL] at hmatch
4245  exact hmatch
4246
4247/-- Expanded Schläfli/length-chain summand for one explicit-fiber local pair. -/
4248noncomputable def freudenthalExplicitFiberPairExpandedSummand
4249    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4250    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4251    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4252    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4253    (pair : FreudenthalLocalPair) : ℝ :=
4254  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4255  let cell := freudenthalExplicitFiberPairSelectedCell edge pair
4256  let τ := P.tetEquiv.symm (cell, pair.1)
4257  ∑ k : Fin 6,
4258    ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv pair.2 k *
4259      localEdgeLengthDirectionalDeriv P.K ξ τ k
4260
4261/-- The expanded explicit-fiber summand is exactly the local angle-length
4262chain derivative at the selected encoded tetrahedron and slot. -/
4263theorem freudenthalExplicitFiberPairExpandedSummand_eq_angleChain
4264    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4265    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4266    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4267    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4268    (pair : FreudenthalLocalPair) :
4269    freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair =
4270      localAngleLengthChainDeriv
4271        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
4272        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
4273        ξ
4274        ((canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).tetEquiv.symm
4275          (freudenthalExplicitFiberPairSelectedCell edge pair, pair.1))
4276        pair.2 := by
4277  rfl
4278
4279/-- Flat Freudenthal local edge-length directional derivative on an encoded
4280periodic tetrahedron, with the squared-edge factor unfolded to
4281`freudenthalTetSqEdges`. -/
4282noncomputable def freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv
4283    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4284    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4285    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4286    (cell : Vertex Nx Ny Nz) (tet : Fin 6) (k : Fin 6) : ℝ :=
4287  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4288  let τ := P.tetEquiv.symm (cell, tet)
4289  let uv := Geometry.ReggeRigorousFoundation.edgeVertices k
4290  Real.sqrt (Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges k) *
4291    ((ξ (P.K.tetVerts τ uv.1) + ξ (P.K.tetVerts τ uv.2)) / 2)
4292
4293theorem freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv_eq
4294    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4295    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4296    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4297    (cell : Vertex Nx Ny Nz) (tet : Fin 6) (k : Fin 6) :
4298    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4299    localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k =
4300      freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv
4301        hx hy hz ξ cell tet k := by
4302  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4303  show localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k =
4304    freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz ξ cell tet k
4305  simp only [localEdgeLengthDirectionalDeriv,
4306    freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv]
4307  rw [canonicalPeriodicFlat_tet_sqEdge_eq_freudenthal Nx Ny Nz hx hy hz cell tet k]
4308
4309/-- At canonical periodic flatness every encoded tetrahedron uses the closed-form
4310Freudenthal Schläfli edge-length derivative table. -/
4311theorem canonicalPeriodicFlat_tet_dihedralDeriv_eq_freudenthalClosed
4312    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4313    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4314    (cell : Vertex Nx Ny Nz) (tet : Fin 6) (f k : Fin 6) :
4315    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4316    let τ := P.tetEquiv.symm (cell, tet)
4317    ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k =
4318      dihedralClosedDerivLength Geometry.FreudenthalCubeTriangulation.freudenthalTet f k := by
4319  dsimp [triangulationSchlaefliData_of_incidence, tetraSchlaefliDerivativeData_closedForm,
4320    tetraSchlaefliDerivativeData_of_equation, canonicalEncodedPeriodicFreudenthalTorus,
4321    canonicalEncodedPeriodicFreudenthalTorus_of_endpoint,
4322    canonicalEncodedPeriodicFreudenthalTorus_of_incidence, canonicalPeriodicTriangulation]
4323
4324/-- Closed-form Schläfli/length-chain summand for one local Freudenthal pair,
4325with caller-supplied conformal edge-length directional derivatives. -/
4326noncomputable def freudenthalLocalPairClosedFormExpandedSummand
4327    (pair : FreudenthalLocalPair) (edgeLengthDir : Fin 6 → ℝ) : ℝ :=
4328  ∑ k : Fin 6,
4329    dihedralClosedDerivLength Geometry.FreudenthalCubeTriangulation.freudenthalTet pair.2 k *
4330      edgeLengthDir k
4331
4332theorem freudenthalLocalPairClosedFormExpandedSummand_eq_lengthChainSummand
4333    (pair : FreudenthalLocalPair) (edgeLengthDir : Fin 6 → ℝ) :
4334    freudenthalLocalPairClosedFormExpandedSummand pair edgeLengthDir =
4335      freudenthalLocalPairLengthChainSummand pair edgeLengthDir := by
4336  rfl
4337
4338theorem freudenthalLocalPairClosedFormExpandedSummand_add
4339    (pair : FreudenthalLocalPair) (f g : Fin 6 → ℝ) :
4340    freudenthalLocalPairClosedFormExpandedSummand pair (f + g) =
4341      freudenthalLocalPairClosedFormExpandedSummand pair f +
4342        freudenthalLocalPairClosedFormExpandedSummand pair g := by
4343  unfold freudenthalLocalPairClosedFormExpandedSummand
4344  rw [← Finset.sum_add_distrib]
4345  refine Finset.sum_congr rfl ?_
4346  intro k _
4347  simp only [Pi.add_apply, mul_add]
4348
4349/-- Closed-form explicit-fiber expanded summand for one local pair. -/
4350noncomputable def freudenthalExplicitFiberPairClosedFormExpandedSummand
4351    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4352    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4353    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4354    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4355    (pair : FreudenthalLocalPair) : ℝ :=
4356  let cell := freudenthalExplicitFiberPairSelectedCell edge pair
4357  freudenthalLocalPairClosedFormExpandedSummand pair fun k =>
4358    freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz ξ cell pair.1 k
4359
4360/-- Flat-unfolded expanded summand for one explicit-fiber local pair. -/
4361noncomputable def freudenthalExplicitFiberPairFlatExpandedSummand
4362    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4363    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4364    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4365    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4366    (pair : FreudenthalLocalPair) : ℝ :=
4367  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4368  let cell := freudenthalExplicitFiberPairSelectedCell edge pair
4369  let τ := P.tetEquiv.symm (cell, pair.1)
4370  ∑ k : Fin 6,
4371    ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv pair.2 k *
4372      freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz ξ cell pair.1 k
4373
4374theorem freudenthalExplicitFiberPairFlatExpandedSummand_eq_expanded
4375    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4376    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4377    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4378    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4379    (pair : FreudenthalLocalPair) :
4380    freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair =
4381      freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair := by
4382  unfold freudenthalExplicitFiberPairFlatExpandedSummand
4383    freudenthalExplicitFiberPairExpandedSummand
4384  refine Finset.sum_congr rfl ?_
4385  intro k _
4386  rw [freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv_eq hx hy hz ξ
4387    (freudenthalExplicitFiberPairSelectedCell edge pair) pair.1 k]
4388
4389theorem freudenthalExplicitFiberPairClosedFormExpandedSummand_eq_flat
4390    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4391    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4392    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4393    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4394    (pair : FreudenthalLocalPair) :
4395    freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz ξ edge pair =
4396      freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair := by
4397  unfold freudenthalExplicitFiberPairClosedFormExpandedSummand
4398    freudenthalExplicitFiberPairFlatExpandedSummand
4399    freudenthalLocalPairClosedFormExpandedSummand
4400  let cell := freudenthalExplicitFiberPairSelectedCell edge pair
4401  refine Finset.sum_congr rfl ?_
4402  intro k _
4403  change
4404    dihedralClosedDerivLength Geometry.FreudenthalCubeTriangulation.freudenthalTet pair.2 k *
4405        freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz ξ cell pair.1 k =
4406      ((triangulationSchlaefliData_of_incidence
4407            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
4408            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK).tetData
4409          ((canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).tetEquiv.symm (cell, pair.1))).dihedralDeriv
4410        pair.2 k *
4411      freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz ξ cell pair.1 k
4412  rw [← canonicalPeriodicFlat_tet_dihedralDeriv_eq_freudenthalClosed hx hy hz cell pair.1 pair.2 k]
4413
4414/-- The explicit-fiber table inner slot sum (Schläfli × local edge-length deriv)
4415matches the flat-unfolded per-pair summand at the selected matching cell. -/
4416theorem freudenthalExplicitFiberTablePairInnerSum_eq_flatExpandedSummand
4417    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4418    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4419    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4420    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4421    (pair : FreudenthalLocalPair) :
4422    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4423    let cell := freudenthalExplicitFiberPairSelectedCell edge pair
4424    (∑ k : Fin 6,
4425        ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
4426            (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
4427          localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k) =
4428      freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair := by
4429  dsimp [freudenthalExplicitFiberPairFlatExpandedSummand]
4430  refine Finset.sum_congr rfl ?_
4431  intro k _
4432  rw [freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv_eq hx hy hz ξ
4433    (freudenthalExplicitFiberPairSelectedCell edge pair) pair.1 k]
4434
4435/-- The explicit-fiber table inner sum matches the expanded summand at the
4436selected matching cell. -/
4437theorem freudenthalExplicitFiberPairExplicitInnerSum_eq_expandedSummand
4438    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4439    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4440    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4441    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4442    (pair : FreudenthalLocalPair) :
4443    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4444    let cell := freudenthalExplicitFiberPairSelectedCell edge pair
4445    (∑ k : Fin 6,
4446        ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
4447            (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
4448          localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k) =
4449      freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair := by
4450  rfl
4451
4452theorem freudenthalExplicitFiberDispTableSum_eq_expandedSummandSum
4453    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4454    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4455    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4456    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
4457    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4458    (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4459        let cell :=
4460          periodicMatchingBaseCell
4461            (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
4462            edge.base
4463        ∑ k : Fin 6,
4464          ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
4465              (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
4466            localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k) =
4467      ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4468        freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair := by
4469  refine Finset.sum_congr rfl ?_
4470  intro pair _
4471  dsimp [freudenthalExplicitFiberPairSelectedCell]
4472  exact freudenthalExplicitFiberPairExplicitInnerSum_eq_expandedSummand hx hy hz ξ edge pair
4473
4474/-- Corrected explicit-fiber global form of the mixed hinge-deficit target.
4475Unlike the old per-edge endpoint target, this keeps the global sum over typed
4476periodic edges and compares it to the rational axis stencil found by the finite
4477audit. -/
4478def CanonicalPeriodicMixedHingeDeficitExplicitFiberAxisStencilTarget
4479    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4480    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
4481  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4482  ∀ ξ : VertexPotential P.K,
4483    (∑ edge : PeriodicEdge Nx Ny Nz,
4484      let e := P.edgeEquiv.symm edge
4485      hingeMeasureDirectionalDeriv P.K P.hK ξ e *
4486        (-∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4487          freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair)) =
4488      canonicalPeriodicMixedAxisStencilAction Nx Ny Nz hx hy hz ξ
4489
4490theorem periodicMatchingBaseCell_eq_of_addVertexBits
4491    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4492    (a : Fin 8)
4493    (target cell : Geometry.PeriodicFreudenthalTorus.Vertex Nx Ny Nz)
4494    (h : target = Geometry.PeriodicFreudenthalTorus.addVertexBits cell a) :
4495    cell = periodicMatchingBaseCell a target :=
4496  periodicMatchingBaseCell_unique a target h
4497
4498theorem canonicalPeriodicTypedEdge_eq_localEdgeOf_of_base_and_disp
4499    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4500    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4501    (cell : Geometry.PeriodicFreudenthalTorus.Vertex Nx Ny Nz) (tet : Fin 6) (f : Fin 6)
4502    (hbase :
4503      edge.base = Geometry.PeriodicFreudenthalTorus.addVertexBits cell
4504        (Geometry.PeriodicFreudenthalTorus.cubeEdgeBase
4505          (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f)))
4506    (hdisp :
4507      edge.disp = Geometry.PeriodicFreudenthalTorus.cubeEdgeDisp
4508        (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f)) :
4509    edge = localEdgeOf cell tet f := by
4510  exact (canonicalPeriodicTypedEdge_eq_localEdgeOf_iff_base_and_disp edge (cell, tet) f).2
4511    ⟨hbase, hdisp⟩
4512
4513/-- Angle-chain form of the explicit-fiber mixed target. -/
4514def CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberAngleChainTarget
4515    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4516    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
4517  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4518  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
4519    let e := P.edgeEquiv.symm edge
4520    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
4521        (-∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4522          localAngleLengthChainDeriv P.K P.hK ξ
4523            (P.tetEquiv.symm (freudenthalExplicitFiberPairSelectedCell edge pair, pair.1))
4524            pair.2) =
4525      Real.sqrt (periodicDispSqEdge edge.disp) *
4526        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
4527          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
4528
4529theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget_of_angleChain
4530    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4531    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4532    (hAngleChain :
4533      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberAngleChainTarget
4534        Nx Ny Nz hx hy hz) :
4535    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
4536      Nx Ny Nz hx hy hz := by
4537  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4538  intro ξ edge
4539  have hsum :
4540      (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4541          freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
4542        ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4543          localAngleLengthChainDeriv P.K P.hK ξ
4544            (P.tetEquiv.symm (freudenthalExplicitFiberPairSelectedCell edge pair, pair.1))
4545            pair.2 := by
4546    refine Finset.sum_congr rfl ?_
4547    intro pair _
4548    exact freudenthalExplicitFiberPairExpandedSummand_eq_angleChain hx hy hz ξ edge pair
4549  simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget,
4550    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberAngleChainTarget,
4551    freudenthalExplicitFiberPairExpandedSummand, hsum, P] using hAngleChain ξ edge
4552
4553theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberAngleChainTarget_of_explicit
4554    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4555    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4556    (hExplicit :
4557      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
4558        Nx Ny Nz hx hy hz) :
4559    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberAngleChainTarget
4560      Nx Ny Nz hx hy hz := by
4561  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4562  intro ξ edge
4563  have hsum :
4564      (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4565          localAngleLengthChainDeriv P.K P.hK ξ
4566            (P.tetEquiv.symm (freudenthalExplicitFiberPairSelectedCell edge pair, pair.1))
4567            pair.2) =
4568        ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4569          freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair := by
4570    refine Finset.sum_congr rfl ?_
4571    intro pair _
4572    exact (freudenthalExplicitFiberPairExpandedSummand_eq_angleChain hx hy hz ξ edge pair).symm
4573  simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget,
4574    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberAngleChainTarget,
4575    freudenthalExplicitFiberPairExpandedSummand, hsum, P] using hExplicit ξ edge
4576
4577/-- Flat-unfolded explicit-fiber mixed target: the fiber sum uses
4578`freudenthalExplicitFiberPairFlatExpandedSummand` entry by entry. -/
4579def CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget
4580    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4581    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
4582  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4583  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
4584    let e := P.edgeEquiv.symm edge
4585    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
4586        (-∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4587          freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair) =
4588      Real.sqrt (periodicDispSqEdge edge.disp) *
4589        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
4590          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
4591
4592/-- Closed-form explicit-fiber mixed target: the fiber sum uses
4593`freudenthalExplicitFiberPairClosedFormExpandedSummand` entry by entry. -/
4594def CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget
4595    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
4596    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
4597  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4598  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
4599    let e := P.edgeEquiv.symm edge
4600    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
4601        (-∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4602          freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz ξ edge pair) =
4603      Real.sqrt (periodicDispSqEdge edge.disp) *
4604        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
4605          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
4606
4607theorem edgeFinEquiv_symm_apply
4608    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4609    (edge : PeriodicEdge Nx Ny Nz) :
4610    edgeFinEquiv Nx Ny Nz ((edgeFinEquiv Nx Ny Nz).symm edge) = edge := by
4611  simp
4612
4613/-- Global squared edge length for an encoded periodic edge is the typed
4614displacement class table entry. -/
4615theorem canonicalEncodedPeriodic_globalSqEdge_eq_periodicDispSqEdge
4616    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4617    {hx : 2 < Nx} {hy : 2 < Ny} {hz : 2 < Nz}
4618    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
4619    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4620    P.hK.globalSqEdge (P.edgeEquiv.symm edge) = periodicDispSqEdge edge.disp := by
4621  dsimp [canonicalEncodedPeriodicFreudenthalTorus,
4622    canonicalEncodedPeriodicFreudenthalTorus_of_endpoint,
4623    canonicalEncodedPeriodicFreudenthalTorus_of_incidence,
4624    canonicalPeriodicTriangulation, canonicalPeriodicEdgeEquiv,
4625    canonicalGlobalSqEdge, canonicalPeriodicIncidenceConsistent_of_endpoint,
4626    canonicalPeriodicIncidenceConsistent]
4627  rw [edgeFinEquiv_symm_apply edge]
4628
4629/-- Encoded edge vertex indices are the typed periodic edge endpoints. -/
4630theorem canonicalEncodedPeriodic_edgeVerts_eq_periodic_endpoints
4631    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4632    {hx : 2 < Nx} {hy : 2 < Ny} {hz : 2 < Nz}
4633    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
4634    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4635    P.K.edgeVerts (P.edgeEquiv.symm edge) =
4636      ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1,
4637        (vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2) := by
4638  dsimp [canonicalEncodedPeriodicFreudenthalTorus,
4639    canonicalEncodedPeriodicFreudenthalTorus_of_endpoint,
4640    canonicalEncodedPeriodicFreudenthalTorus_of_incidence,
4641    canonicalPeriodicTriangulation, canonicalPeriodicEdgeEquiv,
4642    canonicalEdgeVerts]
4643  rw [edgeFinEquiv_symm_apply edge]
4644
4645/-- Hinge-length directional derivative in typed periodic coordinates. -/
4646theorem hingeMeasureDirectionalDeriv_canonicalEncodedPeriodic_edge
4647    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4648    {hx : 2 < Nx} {hy : 2 < Ny} {hz : 2 < Nz}
4649    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4650    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
4651    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4652    hingeMeasureDirectionalDeriv P.K P.hK ξ (P.edgeEquiv.symm edge) =
4653      Real.sqrt (periodicDispSqEdge edge.disp) *
4654        (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) +
4655          ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) / 2 := by
4656  dsimp [hingeMeasureDirectionalDeriv]
4657  rw [canonicalEncodedPeriodic_globalSqEdge_eq_periodicDispSqEdge edge,
4658    canonicalEncodedPeriodic_edgeVerts_eq_periodic_endpoints edge]
4659  ring
4660
4661/-- Closed-form fiber sum for one positive displacement class. -/
4662noncomputable def freudenthalExplicitFiberClosedFormFiberSum
4663    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4664    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4665    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4666    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4667    (d : Fin 7) : ℝ :=
4668  ∑ pair ∈ freudenthalLocalPairDispFiber d,
4669    freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz ξ edge pair
4670
4671theorem freudenthalExplicitFiberClosedFormFiberSum_eq_disp_fiber
4672    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4673    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4674    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4675    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
4676    freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge edge.disp =
4677      ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4678        freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz ξ edge pair := by
4679  rfl
4680
4681theorem freudenthalExplicitFiberFlatDispFiberSum_eq_closedFormFiberSum
4682    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4683    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4684    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4685    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
4686    (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4687        freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair) =
4688      freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge edge.disp := by
4689  rw [freudenthalExplicitFiberClosedFormFiberSum_eq_disp_fiber]
4690  refine Finset.sum_congr rfl ?_
4691  intro pair _
4692  exact (freudenthalExplicitFiberPairClosedFormExpandedSummand_eq_flat hx hy hz ξ edge pair).symm
4693
4694theorem freudenthalExplicitFiberExpandedDispFiberSum_eq_closedFormFiberSum
4695    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4696    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4697    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4698    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
4699    (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
4700        freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
4701      freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge edge.disp :=
4702  Eq.trans
4703    (Finset.sum_congr rfl fun pair _ =>
4704      (freudenthalExplicitFiberPairFlatExpandedSummand_eq_expanded hx hy hz ξ edge pair).symm)
4705    (freudenthalExplicitFiberFlatDispFiberSum_eq_closedFormFiberSum hx hy hz ξ edge)
4706
4707theorem freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv_add
4708    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4709    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4710    (ξ η : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4711    (cell : Vertex Nx Ny Nz) (tet : Fin 6) (k : Fin 6) :
4712    freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz (ξ + η) cell tet k =
4713      freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz ξ cell tet k +
4714        freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz η cell tet k := by
4715  simp only [freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv, Pi.add_apply]
4716  ring
4717
4718theorem freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv_smul
4719    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4720    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4721    (c : ℝ)
4722    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4723    (cell : Vertex Nx Ny Nz) (tet : Fin 6) (k : Fin 6) :
4724    freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz (c • ξ) cell tet k =
4725      c * freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz ξ cell tet k := by
4726  simp only [freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv, Pi.smul_apply, smul_eq_mul]
4727  ring
4728
4729theorem freudenthalExplicitFiberPairFlatExpandedSummand_smul
4730    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4731    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4732    (c : ℝ)
4733    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4734    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4735    (pair : FreudenthalLocalPair) :
4736    freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz (c • ξ) edge pair =
4737      c * freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair := by
4738  unfold freudenthalExplicitFiberPairFlatExpandedSummand
4739  rw [Finset.mul_sum]
4740  refine Finset.sum_congr rfl ?_
4741  intro k _
4742  rw [freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv_smul hx hy hz c ξ
4743    (freudenthalExplicitFiberPairSelectedCell edge pair) pair.1 k]
4744  ring
4745
4746theorem freudenthalExplicitFiberPairClosedFormExpandedSummand_smul
4747    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4748    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4749    (c : ℝ)
4750    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4751    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4752    (pair : FreudenthalLocalPair) :
4753    freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz (c • ξ) edge pair =
4754      c * freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz ξ edge pair := by
4755  rw [freudenthalExplicitFiberPairClosedFormExpandedSummand_eq_flat hx hy hz (c • ξ) edge pair,
4756    freudenthalExplicitFiberPairClosedFormExpandedSummand_eq_flat hx hy hz ξ edge pair]
4757  exact freudenthalExplicitFiberPairFlatExpandedSummand_smul hx hy hz c ξ edge pair
4758
4759theorem freudenthalExplicitFiberClosedFormFiberSum_smul_basis
4760    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4761    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4762    (c : ℝ)
4763    (i : Fin (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K.nV)
4764    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) (d : Fin 7) :
4765    freudenthalExplicitFiberClosedFormFiberSum hx hy hz
4766        (c • Pi.single (M := fun _ : Fin _ => ℝ) i (1 : ℝ)) edge d =
4767      c * freudenthalExplicitFiberClosedFormFiberSum hx hy hz
4768        (Pi.single (M := fun _ : Fin _ => ℝ) i (1 : ℝ)) edge d := by
4769  unfold freudenthalExplicitFiberClosedFormFiberSum
4770  rw [Finset.mul_sum]
4771  refine Finset.sum_congr rfl ?_
4772  intro pair _
4773  exact freudenthalExplicitFiberPairClosedFormExpandedSummand_smul hx hy hz c _ edge pair
4774
4775theorem freudenthalExplicitFiberPairFlatExpandedSummand_add
4776    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4777    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4778    (ξ η : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4779    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4780    (pair : FreudenthalLocalPair) :
4781    freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz (ξ + η) edge pair =
4782      freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair +
4783        freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz η edge pair := by
4784  unfold freudenthalExplicitFiberPairFlatExpandedSummand
4785  rw [← Finset.sum_add_distrib]
4786  refine Finset.sum_congr rfl ?_
4787  intro k _
4788  simp only [freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv_add hx hy hz ξ η
4789    (freudenthalExplicitFiberPairSelectedCell edge pair) pair.1 k, mul_add]
4790
4791theorem freudenthalExplicitFiberPairClosedFormExpandedSummand_add
4792    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4793    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4794    (ξ η : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4795    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4796    (pair : FreudenthalLocalPair) :
4797    freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz (ξ + η) edge pair =
4798      freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz ξ edge pair +
4799        freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz η edge pair := by
4800  rw [freudenthalExplicitFiberPairClosedFormExpandedSummand_eq_flat hx hy hz (ξ + η) edge pair,
4801    freudenthalExplicitFiberPairClosedFormExpandedSummand_eq_flat hx hy hz ξ edge pair,
4802    freudenthalExplicitFiberPairClosedFormExpandedSummand_eq_flat hx hy hz η edge pair]
4803  exact freudenthalExplicitFiberPairFlatExpandedSummand_add hx hy hz ξ η edge pair
4804
4805theorem freudenthalExplicitFiberClosedFormFiberSum_add
4806    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4807    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4808    (ξ η : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4809    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) (d : Fin 7) :
4810    freudenthalExplicitFiberClosedFormFiberSum hx hy hz (ξ + η) edge d =
4811      freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge d +
4812        freudenthalExplicitFiberClosedFormFiberSum hx hy hz η edge d := by
4813  unfold freudenthalExplicitFiberClosedFormFiberSum
4814  rw [← Finset.sum_add_distrib]
4815  refine Finset.sum_congr rfl ?_
4816  intro pair _
4817  exact freudenthalExplicitFiberPairClosedFormExpandedSummand_add hx hy hz ξ η edge pair
4818
4819theorem finRealLinearFunctional_map_finset_sum
4820    {ι : Type*} [DecidableEq ι] (f : (ι → ℝ) → ℝ)
4821    (hf_add : ∀ ξ η, f (ξ + η) = f ξ + f η)
4822    (hf_smul_basis :
4823      ∀ (c : ℝ) (i : ι),
4824        f (c • Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ)) =
4825          c * f (Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ)))
4826    {s : Finset ι} (g : ι → ℝ) :
4827    f (∑ i ∈ s, g i • Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ)) =
4828      ∑ i ∈ s, g i * f (Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ)) := by
4829  have hf0 : f 0 = 0 := by
4830    have h := hf_add 0 0
4831    simp at h
4832    linarith
4833  induction s using Finset.induction with
4834  | empty =>
4835      simp only [Finset.sum_empty]
4836      exact hf0
4837  | @insert a s ha ih =>
4838      rw [Finset.sum_insert ha, hf_add, ih, hf_smul_basis]
4839      simp [Finset.sum_insert ha]
4840
4841/-- A finite-dimensional `ℝ`-linear functional on coordinate potentials is determined
4842by its values on coordinate basis vectors. -/
4843theorem finRealLinearFunctional_eq_sum_coord
4844    {ι : Type*} [Fintype ι] [DecidableEq ι] (f : (ι → ℝ) → ℝ)
4845    (hf_add : ∀ ξ η, f (ξ + η) = f ξ + f η)
4846    (hf_smul_basis :
4847      ∀ (c : ℝ) (i : ι),
4848        f (c • Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ)) =
4849          c * f (Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ)))
4850    (ξ : ι → ℝ) :
4851    f ξ = ∑ i : ι, ξ i * f (Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ)) := by
4852  have hv :
4853      (∑ i : ι, Pi.single (M := fun _ : ι => ℝ) i (ξ i)) = ξ :=
4854    Finset.univ_sum_single ξ
4855  have hsingle :
4856      ∀ i : ι,
4857        Pi.single (M := fun _ : ι => ℝ) i (ξ i) =
4858          ξ i • Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ) := by
4859    intro i
4860    funext j
4861    by_cases hij : j = i
4862    · subst hij
4863      simp [Pi.single_eq_same]
4864    · simp [hij]
4865  have hv_smul :
4866      (∑ i : ι, Pi.single (M := fun _ : ι => ℝ) i (ξ i)) =
4867        ∑ i : ι, ξ i • Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ) :=
4868    Finset.sum_congr rfl fun i _ => hsingle i
4869  calc
4870    f ξ = f (∑ i : ι, Pi.single (M := fun _ : ι => ℝ) i (ξ i)) := by rw [hv]
4871    _ = f (∑ i : ι, ξ i • Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ)) := by
4872      rw [hv_smul]
4873    _ = ∑ i : ι, ξ i * f (Pi.single (M := fun _ : ι => ℝ) i (1 : ℝ)) := by
4874      have hmap :=
4875        finRealLinearFunctional_map_finset_sum f hf_add hf_smul_basis (s := Finset.univ) (g := ξ)
4876      simpa using hmap
4877
4878/-- Coordinate-basis coefficient of the explicit-fiber closed-form sum at one
4879displacement class. -/
4880noncomputable def freudenthalExplicitFiberClosedFormVertexCoeff
4881    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4882    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4883    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) (d : Fin 7)
4884    (i : Fin (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K.nV) : ℝ :=
4885  freudenthalExplicitFiberClosedFormFiberSum hx hy hz
4886    (Pi.single (M := fun _ : Fin _ => ℝ) i (1 : ℝ)) edge d
4887
4888theorem freudenthalExplicitFiberClosedFormFiberSum_eq_sum_vertexCoeffs
4889    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4890    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4891    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4892    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) (d : Fin 7) :
4893    freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge d =
4894      ∑ i : Fin (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K.nV,
4895        ξ i * freudenthalExplicitFiberClosedFormVertexCoeff hx hy hz edge d i :=
4896  finRealLinearFunctional_eq_sum_coord
4897    (f := fun η => freudenthalExplicitFiberClosedFormFiberSum hx hy hz η edge d)
4898    (hf_add := fun η₁ η₂ =>
4899      freudenthalExplicitFiberClosedFormFiberSum_add hx hy hz η₁ η₂ edge d)
4900    (hf_smul_basis := fun c i =>
4901      freudenthalExplicitFiberClosedFormFiberSum_smul_basis hx hy hz c i edge d)
4902    ξ
4903
4904theorem freudenthalExplicitFiberClosedFormFiberSum_smul
4905    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4906    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4907    (c : ℝ)
4908    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4909    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) (d : Fin 7) :
4910    freudenthalExplicitFiberClosedFormFiberSum hx hy hz (c • ξ) edge d =
4911      c * freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge d := by
4912  rw [freudenthalExplicitFiberClosedFormFiberSum_eq_sum_vertexCoeffs hx hy hz (c • ξ) edge d,
4913    freudenthalExplicitFiberClosedFormFiberSum_eq_sum_vertexCoeffs hx hy hz ξ edge d]
4914  simp only [Pi.smul_apply, Finset.mul_sum]
4915  refine Finset.sum_congr rfl ?_
4916  intro i _
4917  rw [freudenthalExplicitFiberClosedFormVertexCoeff, smul_eq_mul, mul_assoc]
4918
4919/-- Explicit-fiber length-chain sum in closed template form: each fiber entry
4920uses the flat edge-length directional derivative at its selected periodic cell. -/
4921noncomputable def freudenthalExplicitFiberDispLengthChainSumTemplate
4922    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4923    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4924    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4925    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4926    (d : Fin 7) : ℝ :=
4927  ∑ pair ∈ freudenthalLocalPairDispFiber d,
4928    freudenthalLocalPairLengthChainSummand pair fun k =>
4929      freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv hx hy hz ξ
4930        (freudenthalExplicitFiberPairSelectedCell edge pair) pair.1 k
4931
4932theorem freudenthalExplicitFiberClosedFormFiberSum_eq_disp_lengthChainTemplate
4933    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4934    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4935    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
4936    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
4937    freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge edge.disp =
4938      freudenthalExplicitFiberDispLengthChainSumTemplate hx hy hz ξ edge edge.disp := by
4939  unfold freudenthalExplicitFiberClosedFormFiberSum
4940    freudenthalExplicitFiberDispLengthChainSumTemplate
4941  refine Finset.sum_congr rfl ?_
4942  intro pair _
4943  unfold freudenthalExplicitFiberPairClosedFormExpandedSummand
4944  rw [freudenthalLocalPairClosedFormExpandedSummand_eq_lengthChainSummand]
4945
4946/-- Encoded tetrahedron vertices are `addVertexBits cell` applied to local cube vertices. -/
4947theorem freudenthalExplicitFiber_canonicalTetVerts_eq
4948    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4949    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4950    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4951    (pair : FreudenthalLocalPair) (v : Fin 4) :
4952    let cell := freudenthalExplicitFiberPairSelectedCell edge pair
4953    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K.tetVerts
4954        ((canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).tetEquiv.symm (cell, pair.1)) v =
4955      (vertexFinEquiv Nx Ny Nz).symm
4956        (addVertexBits cell (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1 v)) := by
4957  exact canonicalEncodedPeriodic_tetVerts_addVertexBits Nx Ny Nz hx hy hz
4958    (freudenthalExplicitFiberPairSelectedCell edge pair) pair.1 v
4959
4960/-- The slot-`pair.2` vertices of the selected encoded tetrahedron coincide with the typed
4961periodic edge endpoints up to orientation. -/
4962theorem freudenthalExplicitFiber_tetVerts_edgeSlot_eq_edgeEndpoints
4963    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
4964    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
4965    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
4966    (pair : FreudenthalLocalPair)
4967    (hdisp : freudenthalLocalPairDisp pair = edge.disp) :
4968    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
4969    let cell := freudenthalExplicitFiberPairSelectedCell edge pair
4970    let tv := Geometry.ReggeRigorousFoundation.edgeVertices pair.2
4971    (P.K.tetVerts (P.tetEquiv.symm (cell, pair.1)) tv.1 =
4972        (vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1 ∧
4973      P.K.tetVerts (P.tetEquiv.symm (cell, pair.1)) tv.2 =
4974        (vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2) ∨
4975      (P.K.tetVerts (P.tetEquiv.symm (cell, pair.1)) tv.1 =
4976          (vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2 ∧
4977        P.K.tetVerts (P.tetEquiv.symm (cell, pair.1)) tv.2 =
4978          (vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) := by
4979  dsimp only
4980  let tv := Geometry.ReggeRigorousFoundation.edgeVertices pair.2
4981  rcases freudenthalExplicitFiber_addVertexBits_tetVerts_edgeSlot_eq_edgeEndpoints edge pair hdisp with
4982    hdir | hrev
4983  · left
4984    constructor
4985    · rw [freudenthalExplicitFiber_canonicalTetVerts_eq hx hy hz edge pair tv.1]
4986      exact congrArg _ hdir.1
4987    · rw [freudenthalExplicitFiber_canonicalTetVerts_eq hx hy hz edge pair tv.2]
4988      exact congrArg _ hdir.2
4989  · right
4990    constructor
4991    · rw [freudenthalExplicitFiber_canonicalTetVerts_eq hx hy hz edge pair tv.1]
4992      exact congrArg _ hrev.1
4993    · rw [freudenthalExplicitFiber_canonicalTetVerts_eq hx hy hz edge pair tv.2]
4994      exact congrArg _ hrev.2
4995
4996/-- Per positive-displacement-class closed-form explicit-fiber mixed target.
4997
4998The endpoint-only packaging (`∃ F : ℝ → ℝ → ℝ` with fiber sum `= F ξ₀ ξ₁`) is
4999blocked for d ∈ {0,3} by the proved vertex expansion together with the finite audit
5000in `scripts/freudenthal_explicit_fiber_endpoint_analysis.py` (interior coefficients
5001do not vanish; at (ξ₀,ξ₁)=(1,1) the fiber sum is −4 while the template forces
5002`F(1,1)=0`; see
5003`FreudenthalLocalDispLengthChainEndpointTemplateTarget_F_eq_zero_at_one_one`).
5004The load-bearing replacement is the global mixed target
5005`CanonicalPeriodicMixedHingeDeficitLengthChainTarget` (sum over edges), not this
5006pointwise endpoint-quadratic ansatz with `fiberSum = F(ξ₀,ξ₁)`. -/
5007def CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget
5008    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5009    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7) : Prop :=
5010  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
5011  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
5012    edge.disp = d →
5013      Real.sqrt (periodicDispSqEdge d) *
5014          (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) +
5015            ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) / 2 *
5016          (-freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge d) =
5017        Real.sqrt (periodicDispSqEdge d) *
5018          (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
5019            ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ)
5020
5021/-- The closed-form explicit-fiber sum for one displacement class depends only
5022on the two endpoint potentials of the typed periodic edge.
5023
5024This is the load-bearing combinatorial step for the bilinear endpoint template:
5025the length-chain sum is `ℝ`-linear in `VertexPotential` (see
5026`freudenthalExplicitFiberClosedFormFiberSum_add`), so endpoint dependence is
5027equivalent to vanishing coefficients on all non-endpoint torus vertices in that
5028linear expansion.  A finite coefficient audit (see
5029`scripts/freudenthal_explicit_fiber_endpoint_analysis.py`) shows nonzero
5030non-endpoint coefficients for axis and face-diagonal classes; the remaining
5031work is a Lean certificate of those cancellations or a revised target. -/
5032def FreudenthalExplicitFiberEndpointDependenceTarget
5033    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5034    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7) : Prop :=
5035  ∃ F : ℝ → ℝ → ℝ,
5036    ∀ (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
5037      (edge : PeriodicEdge Nx Ny Nz),
5038      edge.disp = d →
5039        freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge d =
5040          F (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1))
5041            (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2))
5042
5043/-- Per-edge vertex-coefficient expansion of the explicit-fiber closed-form sum:
5044`fiberSum ξ = ∑_v c_{edge}(v) · ξ(v)`.  This is the honest linear form before any
5045endpoint-only ansatz; a finite audit lives in
5046`scripts/freudenthal_explicit_fiber_endpoint_analysis.py`. -/
5047def FreudenthalExplicitFiberVertexCoefficientExpansionTarget
5048    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5049    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7) : Prop :=
5050  ∀ (edge : PeriodicEdge Nx Ny Nz),
5051    edge.disp = d →
5052      ∃ coeffs : Fin (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K.nV → ℝ,
5053        ∀ (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K),
5054          freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge d =
5055            ∑ i : Fin (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K.nV,
5056              coeffs i * ξ i
5057
5058theorem FreudenthalExplicitFiberVertexCoefficientExpansionTarget_holds
5059    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5060    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7) :
5061    FreudenthalExplicitFiberVertexCoefficientExpansionTarget Nx Ny Nz hx hy hz d := by
5062  intro edge hdisp
5063  refine
5064    ⟨fun i => freudenthalExplicitFiberClosedFormVertexCoeff hx hy hz edge d i, ?_⟩
5065  intro ξ
5066  rw [freudenthalExplicitFiberClosedFormFiberSum_eq_sum_vertexCoeffs hx hy hz ξ edge d]
5067  simp [mul_comm]
5068
5069/-- Uniform affine endpoint coefficients on a displacement class imply
5070`FreudenthalExplicitFiberEndpointDependenceTarget` with
5071`F ξ₀ ξ₁ = c₀ ξ₀ + c₁ ξ₁`.  The global `F` is sharp: auxiliary-vertex zeros per edge are
5072not enough unless `(c₀,c₁)` are constant across all edges of class `d`. -/
5073theorem FreudenthalExplicitFiberEndpointDependenceTarget_of_uniformAffineCoeffs
5074    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5075    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7) (c₀ c₁ : ℝ)
5076    (hSum :
5077      ∀ (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
5078        (edge : PeriodicEdge Nx Ny Nz),
5079        edge.disp = d →
5080          freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge d =
5081            c₀ * ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) +
5082              c₁ * ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) :
5083    FreudenthalExplicitFiberEndpointDependenceTarget Nx Ny Nz hx hy hz d := by
5084  refine ⟨fun ξ₀ ξ₁ => c₀ * ξ₀ + c₁ * ξ₁, ?_⟩
5085  intro ξ edge hdisp
5086  simpa [hdisp] using hSum ξ edge hdisp
5087
5088/-- Per-displacement-class packaged target: endpoint dependence of the fiber sum plus the
5089local endpoint-template polynomial identity.
5090
5091**Status:** blocked for the explicit closed-form fiber sum when `F(ξ₀,ξ₁)` is
5092identified with the fiber sum on endpoint-only potentials: the template forces
5093`F(1,1)=0` while the finite audit reports a nonzero diagonal fiber sum for
5094classes `0` and `3` (see
5095`FreudenthalLocalDispLengthChainEndpointTemplateTarget_F_eq_zero_at_one_one`).
5096Discharge via interior-vertex cancellation or abandon the
5097`fiberSum = F(ξ₀,ξ₁)` identification. -/
5098def FreudenthalExplicitFiberBilinearEndpointTemplateTarget
5099    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5100    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7) : Prop :=
5101  ∃ F : ℝ → ℝ → ℝ,
5102    FreudenthalLocalDispLengthChainEndpointTemplateTarget d F ∧
5103      ∀ (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
5104        (edge : PeriodicEdge Nx Ny Nz),
5105        edge.disp = d →
5106          freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge d =
5107            F (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1))
5108              (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2))
5109
5110theorem periodicDispSqEdge_pos (d : Fin 7) : 0 < periodicDispSqEdge d := by
5111  fin_cases d <;> simp [periodicDispSqEdge]
5112
5113theorem periodicDispSqEdge_sqrt_ne_zero (d : Fin 7) :
5114    Real.sqrt (periodicDispSqEdge d) ≠ 0 :=
5115  ne_of_gt (Real.sqrt_pos.mpr (periodicDispSqEdge_pos d))
5116
5117/-- Any function `F` satisfying the length-chain endpoint template must vanish on
5118the diagonal `(ξ₀,ξ₁) = (1,1)`. -/
5119theorem FreudenthalLocalDispLengthChainEndpointTemplateTarget_F_eq_zero_at_one_one
5120    (d : Fin 7) (F : ℝ → ℝ → ℝ)
5121    (hF : FreudenthalLocalDispLengthChainEndpointTemplateTarget d F) :
5122    F 1 1 = 0 := by
5123  have hEq := hF 1 1
5124  have hs := periodicDispSqEdge_sqrt_ne_zero d
5125  have hCancel :
5126      Real.sqrt (periodicDispSqEdge d) * (1 + 1) / 2 * (-F 1 1) =
5127        Real.sqrt (periodicDispSqEdge d) * (1 - 1) ^ (2 : ℕ) := hEq
5128  simp at hCancel
5129  have hFactor : Real.sqrt (periodicDispSqEdge d) * (-F 1 1) = 0 := by
5130    simpa using hCancel
5131  rcases mul_eq_zero.mp hFactor with hsZero | hF0
5132  · exact absurd hsZero hs
5133  · simpa using neg_eq_zero.mp hF0
5134
5135/-- The template forces `F(1,0) = -2`. -/
5136theorem FreudenthalLocalDispLengthChainEndpointTemplateTarget_F_eq_neg_two_at_one_zero
5137    (d : Fin 7) (F : ℝ → ℝ → ℝ)
5138    (hF : FreudenthalLocalDispLengthChainEndpointTemplateTarget d F) :
5139    F 1 0 = -2 := by
5140  have hEq := hF 1 0
5141  have hs := periodicDispSqEdge_sqrt_ne_zero d
5142  have hCancel :
5143      Real.sqrt (periodicDispSqEdge d) * (1 + 0) / 2 * (-F 1 0) =
5144        Real.sqrt (periodicDispSqEdge d) * (1 - 0) ^ (2 : ℕ) := hEq
5145  rw [pow_two] at hCancel
5146  have hFactor :
5147      Real.sqrt (periodicDispSqEdge d) / 2 * (-F 1 0) = Real.sqrt (periodicDispSqEdge d) := by
5148    simpa using hCancel
5149  have hTwo : Real.sqrt (periodicDispSqEdge d) * (-F 1 0) = 2 * Real.sqrt (periodicDispSqEdge d) := by
5150    linarith
5151  have hRearr :
5152      Real.sqrt (periodicDispSqEdge d) * (-F 1 0) =
5153        Real.sqrt (periodicDispSqEdge d) * (2 : ℝ) := by
5154    rw [hTwo, mul_comm (2 : ℝ) (Real.sqrt (periodicDispSqEdge d))]
5155  have hNeg : -F 1 0 = 2 := mul_left_cancel₀ hs hRearr
5156  linarith
5157
5158/-! ### Axis class-0 explicit-fiber obstruction (`Nx = Ny = Nz = 5`)
5159
5160Finite audit at base `(1,0,0)` (`scripts/freudenthal_explicit_fiber_endpoint_analysis.py`):
5161endpoint-unit closed-form fiber sum is `-4` while the length-chain endpoint template forces
5162`F(1,1) = 0`.  The audit sum below is proved by `norm_num`; the global torus identification
5163is the named target `FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget`. -/
5164
5165namespace AxisDisp0EndpointUnitWitness5
5166
5167abbrev WitnessNx := (5 : ℕ)
5168abbrev WitnessNy := (5 : ℕ)
5169abbrev WitnessNz := (5 : ℕ)
5170
5171instance witnessNeNx : NeZero WitnessNx := ⟨by decide⟩
5172instance witnessNeNy : NeZero WitnessNy := ⟨by decide⟩
5173instance witnessNeNz : NeZero WitnessNz := ⟨by decide⟩
5174
5175def witnessHx : 2 < WitnessNx := by decide
5176def witnessHy : 2 < WitnessNy := by decide
5177def witnessHz : 2 < WitnessNz := by decide
5178
5179def axisWitnessEdge : PeriodicEdge WitnessNx WitnessNy WitnessNz :=
5180  { base := (1, 0, 0), disp := 0 }
5181
5182def axisWitnessEndpoint0 : Vertex WitnessNx WitnessNy WitnessNz := (1, 0, 0)
5183def axisWitnessEndpoint1 : Vertex WitnessNx WitnessNy WitnessNz := (2, 0, 0)
5184
5185theorem axisWitness_edge_endpoints :
5186    axisWitnessEdge.endpoints = (axisWitnessEndpoint0, axisWitnessEndpoint1) := by
5187  native_decide
5188
5189/-- Audit-mirrored per-pair contributions for axis class `0` at endpoint-unit data
5190(base `(1,0,0)`, `N = 5`).  Matches `scripts/freudenthal_explicit_fiber_endpoint_analysis.py`. -/
5191def freudenthalAxisDisp0EndpointUnitAuditSum : ℝ :=
5192  (-1 / 2 : ℝ) + (-1 / 2) + (-1) + (-1 / 2) + (-1) + (-1 / 2)
5193
5194theorem freudenthalAxisDisp0EndpointUnitAuditSum_eq_neg_four :
5195    freudenthalAxisDisp0EndpointUnitAuditSum = (-4 : ℝ) := by
5196  unfold freudenthalAxisDisp0EndpointUnitAuditSum
5197  norm_num
5198
5199open Geometry.FreudenthalCubeTriangulation
5200
5201/-- Explicit matching cell per local pair for the axis witness edge (audit table). -/
5202def axisWitnessCell (pair : FreudenthalLocalPair) : Vertex WitnessNx WitnessNy WitnessNz :=
5203  match pair.1, pair.2 with
5204  | 0, 0 => (1, 0, 0)
5205  | 1, 0 => (1, 0, 0)
5206  | 2, 3 => (1, 4, 0)
5207  | 3, 5 => (1, 4, 4)
5208  | 4, 3 => (1, 0, 4)
5209  | 5, 5 => (1, 4, 4)
5210  | _, _ => (0, 0, 0)
5211
5212theorem axisWitnessCell_base_offset (pair : FreudenthalLocalPair)
5213    (hp : pair ∈ freudenthalLocalPairDispFiber 0) :
5214    axisWitnessEdge.base = addVertexBits (axisWitnessCell pair)
5215      (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2)) := by
5216  have hmem :
5217      pair = (0, 0) ∨ pair = (1, 0) ∨ pair = (2, 3) ∨ pair = (3, 5) ∨ pair = (4, 3) ∨
5218        pair = (5, 5) := by
5219    simpa [freudenthalLocalPairDispFiber] using hp
5220  rcases hmem with rfl | rfl | rfl | rfl | rfl | rfl <;> native_decide
5221
5222theorem axisWitness_selectedCell_eq (pair : FreudenthalLocalPair)
5223    (hp : pair ∈ freudenthalLocalPairDispFiber 0) :
5224    freudenthalExplicitFiberPairSelectedCell axisWitnessEdge pair = axisWitnessCell pair := by
5225  dsimp [freudenthalExplicitFiberPairSelectedCell]
5226  symm
5227  exact periodicMatchingBaseCell_unique _ _ (axisWitnessCell_base_offset pair hp)
5228
5229def axisWitnessEndpointUnitPotential :
5230    VertexPotential
5231      (canonicalEncodedPeriodicFreudenthalTorus WitnessNx WitnessNy WitnessNz witnessHx witnessHy
5232        witnessHz).K :=
5233  fun i =>
5234    if i = (vertexFinEquiv WitnessNx WitnessNy WitnessNz).symm axisWitnessEndpoint0 ∨
5235        i = (vertexFinEquiv WitnessNx WitnessNy WitnessNz).symm axisWitnessEndpoint1 then
5236      1
5237    else 0
5238
5239theorem axisWitnessEndpointUnitPotential_apply (v : Vertex WitnessNx WitnessNy WitnessNz) :
5240    axisWitnessEndpointUnitPotential ((vertexFinEquiv WitnessNx WitnessNy WitnessNz).symm v) =
5241      if v = axisWitnessEndpoint0 ∨ v = axisWitnessEndpoint1 then 1 else 0 := by
5242  dsimp [axisWitnessEndpointUnitPotential]
5243  simp_rw [(vertexFinEquiv WitnessNx WitnessNy WitnessNz).symm.injective.eq_iff]
5244
5245def axisWitnessEndpointXi (v : Vertex WitnessNx WitnessNy WitnessNz) : ℝ :=
5246  if v = axisWitnessEndpoint0 ∨ v = axisWitnessEndpoint1 then 1 else 0
5247
5248theorem axisWitnessEndpointUnitPotential_apply_eq_xi (v : Vertex WitnessNx WitnessNy WitnessNz) :
5249    axisWitnessEndpointUnitPotential ((vertexFinEquiv WitnessNx WitnessNy WitnessNz).symm v) =
5250      axisWitnessEndpointXi v := by
5251  rw [axisWitnessEndpointUnitPotential_apply]
5252  rfl
5253
5254def axisWitnessFlatEdgeLengthDir (pair : FreudenthalLocalPair) (k : Fin 6) : ℝ :=
5255  let cell := axisWitnessCell pair
5256  let uv := Geometry.ReggeRigorousFoundation.edgeVertices k
5257  let v0 := addVertexBits cell (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1 uv.1)
5258  let v1 := addVertexBits cell (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1 uv.2)
5259  Real.sqrt (Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges k) *
5260    (axisWitnessEndpointXi v0 + axisWitnessEndpointXi v1) / 2
5261
5262def axisWitnessPairSummand (pair : FreudenthalLocalPair) : ℝ :=
5263  ∑ k : Fin 6,
5264    freudenthalLocalPairClosedFormSchlaefliCoeff pair k * axisWitnessFlatEdgeLengthDir pair k
5265
5266private lemma axisWitness_tetVertPotential_eq_xi (pair : FreudenthalLocalPair) (u : Fin 4) :
5267    axisWitnessEndpointUnitPotential
5268        ((canonicalEncodedPeriodicFreudenthalTorus WitnessNx WitnessNy WitnessNz witnessHx witnessHy
5269            witnessHz).K.tetVerts
5270          ((canonicalEncodedPeriodicFreudenthalTorus WitnessNx WitnessNy WitnessNz witnessHx witnessHy
5271              witnessHz).tetEquiv.symm (axisWitnessCell pair, pair.1)) u) =
5272      axisWitnessEndpointXi
5273        (addVertexBits (axisWitnessCell pair)
5274          (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1 u)) := by
5275  rw [canonicalEncodedPeriodic_tetVerts_addVertexBits, axisWitnessEndpointUnitPotential_apply_eq_xi]
5276
5277private lemma axisWitness_flatEdgeLengthDir_eq_explicit (pair : FreudenthalLocalPair) (k : Fin 6) :
5278    freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv witnessHx witnessHy witnessHz
5279        axisWitnessEndpointUnitPotential (axisWitnessCell pair) pair.1 k =
5280      axisWitnessFlatEdgeLengthDir pair k := by
5281  dsimp [freudenthalExplicitFiberFlatLocalEdgeLengthDirectionalDeriv, axisWitnessFlatEdgeLengthDir]
5282  simp only [Geometry.ReggeRigorousFoundation.edgeVertices]
5283  rw [axisWitness_tetVertPotential_eq_xi pair, axisWitness_tetVertPotential_eq_xi pair]
5284  ring_nf
5285
5286private theorem axisWitness_explicitPairSummand_eq_local (pair : FreudenthalLocalPair)
5287    (hp : pair ∈ freudenthalLocalPairDispFiber 0) :
5288    freudenthalExplicitFiberPairClosedFormExpandedSummand witnessHx witnessHy witnessHz
5289        axisWitnessEndpointUnitPotential axisWitnessEdge pair =
5290      axisWitnessPairSummand pair := by
5291  dsimp [freudenthalExplicitFiberPairClosedFormExpandedSummand, axisWitnessPairSummand,
5292    freudenthalLocalPairClosedFormExpandedSummand]
5293  rw [axisWitness_selectedCell_eq pair hp]
5294  refine Finset.sum_congr rfl ?_
5295  intro k _
5296  dsimp [freudenthalLocalPairClosedFormSchlaefliCoeff]
5297  rw [axisWitness_flatEdgeLengthDir_eq_explicit pair k]
5298
5299def axisWitnessDisp0LocalFiberSum : ℝ :=
5300  ∑ pair ∈ freudenthalLocalPairDispFiber 0, axisWitnessPairSummand pair
5301
5302/-- Local combinatorial fiber sum matches the finite audit table. -/
5303def FreudenthalAxisDisp0LocalFiberSumEqAuditTarget : Prop :=
5304  axisWitnessDisp0LocalFiberSum = freudenthalAxisDisp0EndpointUnitAuditSum
5305
5306/-- Per-pair audit values for class-0 axis witness (Python
5307`scripts/freudenthal_explicit_fiber_endpoint_analysis.py`).  Discharge of
5308`FreudenthalAxisDisp0LocalFiberSumEqAuditTarget` is via six
5309`Finset.sum_eq_single` + `norm_num` certificates; generator:
5310`scripts/generate_axis_disp0_summand_proofs.py`. -/
5311def axisWitnessPairSummandAudit (pair : FreudenthalLocalPair) : ℝ :=
5312  match pair with
5313  | (0, 0) => -1 / 2
5314  | (1, 0) => -1 / 2
5315  | (2, 3) => -1
5316  | (3, 5) => -1 / 2
5317  | (4, 3) => -1
5318  | (5, 5) => -1 / 2
5319  | _ => 0
5320
5321def FreudenthalAxisDisp0PairSummandEqAuditTarget (pair : FreudenthalLocalPair)
5322    (_hp : pair ∈ freudenthalLocalPairDispFiber 0) : Prop :=
5323  axisWitnessPairSummand pair = axisWitnessPairSummandAudit pair
5324
5325def FreudenthalAxisDisp0AllPairSummandsEqAuditTarget : Prop :=
5326  ∀ pair (hp : pair ∈ freudenthalLocalPairDispFiber 0),
5327    FreudenthalAxisDisp0PairSummandEqAuditTarget pair hp
5328
5329open FreudenthalLengthChainEndpointCert
5330
5331set_option maxHeartbeats 2000000 in
5332
5333private lemma axisWitness_neg_sqrt_half_product :
5334    (-Real.sqrt 2 / 2) * (Real.sqrt 2 / 2) = -1 / 2 := by
5335  have hsq : Real.sqrt 2 ^ 2 = 2 := Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2)
5336  have hne : Real.sqrt 2 ≠ 0 := ne_of_gt (Real.sqrt_pos.2 (by norm_num : (0 : ℝ) < 2))
5337  field_simp [hne]
5338  nlinarith [hsq]
5339
5340private lemma axisWitnessSchlaefli_zero_iff (pair : FreudenthalLocalPair) (k : Fin 6)
5341    (hk : freudenthalSchlaefliPolySummandNormTable pair.2 k = 0) :
5342    freudenthalLocalPairClosedFormSchlaefliCoeff pair k = 0 := by
5343  rw [freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table, hk]
5344  simp
5345
5346private lemma axisWitnessFlatEdgeLengthDir_zero_of_xi_zero
5347    (pair : FreudenthalLocalPair) (k : Fin 6)
5348    (hv0 : axisWitnessEndpointXi (addVertexBits (axisWitnessCell pair)
5349      (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1
5350        (Geometry.ReggeRigorousFoundation.edgeVertices k).1)) = 0)
5351    (hv1 : axisWitnessEndpointXi (addVertexBits (axisWitnessCell pair)
5352      (Geometry.FreudenthalCubeTriangulation.tetVerts pair.1
5353        (Geometry.ReggeRigorousFoundation.edgeVertices k).2)) = 0) :
5354    axisWitnessFlatEdgeLengthDir pair k = 0 := by
5355  dsimp [axisWitnessFlatEdgeLengthDir]
5356  simp [hv0, hv1]
5357
5358private lemma axisWitnessPairSummand_00 :
5359    axisWitnessPairSummand (0, 0) = (-1 / 2 : ℝ) := by
5360  dsimp [axisWitnessPairSummand]
5361  rw [Finset.sum_eq_single (4 : Fin 6)]
5362  · dsimp [axisWitnessFlatEdgeLengthDir]
5363    simp only [Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5364      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5365      Geometry.ReggeRigorousFoundation.edgeVertices,
5366      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5367      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5368      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5369    field_simp
5370    ring_nf
5371    norm_num [Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2), Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 1)]
5372  · intro b _ hb
5373    fin_cases b
5374    all_goals
5375      dsimp [axisWitnessFlatEdgeLengthDir]
5376      first
5377      | exact (hb rfl).elim
5378      | simp only [
5379          Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5380          addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5381          Geometry.ReggeRigorousFoundation.edgeVertices,
5382          freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5383          freudenthalSchlaefliPolySummandNormTable, Real.sqrt_eq_rpow, axisWitnessEndpoint0,
5384          axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5385        norm_num
5386  · intro hmem
5387    exact (hmem (Finset.mem_univ _)).elim
5388
5389private lemma axisWitnessPairSummand_10 :
5390    axisWitnessPairSummand (1, 0) = (-1 / 2 : ℝ) := by
5391  dsimp [axisWitnessPairSummand]
5392  rw [Finset.sum_eq_single (4 : Fin 6)]
5393  · dsimp [axisWitnessFlatEdgeLengthDir]
5394    simp only [Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5395      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5396      Geometry.ReggeRigorousFoundation.edgeVertices,
5397      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5398      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5399      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5400    field_simp
5401    ring_nf
5402    norm_num [Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2), Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 1)]
5403  · intro b _ hb
5404    fin_cases b
5405    all_goals
5406      dsimp [axisWitnessFlatEdgeLengthDir]
5407      first
5408      | exact (hb rfl).elim
5409      | simp only [
5410          Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5411          addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5412          Geometry.ReggeRigorousFoundation.edgeVertices,
5413          freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5414          freudenthalSchlaefliPolySummandNormTable, Real.sqrt_eq_rpow, axisWitnessEndpoint0,
5415          axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5416        norm_num
5417  · intro hmem
5418    exact (hmem (Finset.mem_univ _)).elim
5419
5420private lemma axisWitnessPairSummand_35 :
5421    axisWitnessPairSummand (3, 5) = (-1 / 2 : ℝ) := by
5422  dsimp [axisWitnessPairSummand]
5423  rw [Finset.sum_eq_single (1 : Fin 6)]
5424  · dsimp [axisWitnessFlatEdgeLengthDir]
5425    simp only [Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5426      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5427      Geometry.ReggeRigorousFoundation.edgeVertices,
5428      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5429      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5430      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5431    field_simp
5432    ring_nf
5433    norm_num [Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2), Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 1)]
5434  · intro b _ hb
5435    fin_cases b
5436    all_goals
5437      dsimp [axisWitnessFlatEdgeLengthDir]
5438      first
5439      | exact (hb rfl).elim
5440      | simp only [
5441          Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5442          addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5443          Geometry.ReggeRigorousFoundation.edgeVertices,
5444          freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5445          freudenthalSchlaefliPolySummandNormTable, Real.sqrt_eq_rpow, axisWitnessEndpoint0,
5446          axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5447        norm_num
5448  · intro hmem
5449    exact (hmem (Finset.mem_univ _)).elim
5450
5451private lemma axisWitnessPairSummand_55 :
5452    axisWitnessPairSummand (5, 5) = (-1 / 2 : ℝ) := by
5453  dsimp [axisWitnessPairSummand]
5454  rw [Finset.sum_eq_single (1 : Fin 6)]
5455  · dsimp [axisWitnessFlatEdgeLengthDir]
5456    simp only [Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5457      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5458      Geometry.ReggeRigorousFoundation.edgeVertices,
5459      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5460      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5461      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5462    field_simp
5463    ring_nf
5464    norm_num [Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2), Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 1)]
5465  · intro b _ hb
5466    fin_cases b
5467    all_goals
5468      dsimp [axisWitnessFlatEdgeLengthDir]
5469      first
5470      | exact (hb rfl).elim
5471      | simp only [
5472          Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5473          addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5474          Geometry.ReggeRigorousFoundation.edgeVertices,
5475          freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5476          freudenthalSchlaefliPolySummandNormTable, Real.sqrt_eq_rpow, axisWitnessEndpoint0,
5477          axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5478        norm_num
5479  · intro hmem
5480    exact (hmem (Finset.mem_univ _)).elim
5481
5482private lemma axisWitnessPairSummand_23_inactive (k : Fin 6)
5483    (hk : k ≠ 1 ∧ k ≠ 3 ∧ k ≠ 4) :
5484    freudenthalLocalPairClosedFormSchlaefliCoeff (2, 3) k *
5485        axisWitnessFlatEdgeLengthDir (2, 3) k = 0 := by
5486  fin_cases k
5487  · dsimp [axisWitnessFlatEdgeLengthDir]
5488    simp only [
5489      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5490      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5491      Geometry.ReggeRigorousFoundation.edgeVertices,
5492      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5493      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5494      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5495    norm_num
5496  · exact (hk.1 rfl).elim
5497  · dsimp [axisWitnessFlatEdgeLengthDir]
5498    simp only [
5499      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5500      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5501      Geometry.ReggeRigorousFoundation.edgeVertices,
5502      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5503      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5504      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5505    norm_num
5506  · exact (hk.2.1 rfl).elim
5507  · exact (hk.2.2 rfl).elim
5508  · dsimp [axisWitnessFlatEdgeLengthDir]
5509    simp only [
5510      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5511      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5512      Geometry.ReggeRigorousFoundation.edgeVertices,
5513      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5514      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5515      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5516    norm_num
5517
5518private lemma axisWitnessFin6_ne_of_not_mem_134 (k : Fin 6)
5519    (hk : k ∉ ({1, 3, 4} : Finset (Fin 6))) : k ≠ 1 ∧ k ≠ 3 ∧ k ≠ 4 := by
5520  fin_cases k <;> simp [Finset.mem_insert, Finset.mem_singleton] at hk ⊢
5521
5522private lemma axisWitnessPairSummand_23 :
5523    axisWitnessPairSummand (2, 3) = (-1 : ℝ) := by
5524  dsimp [axisWitnessPairSummand]
5525  have hsum :
5526      ∑ k : Fin 6, freudenthalLocalPairClosedFormSchlaefliCoeff (2, 3) k *
5527          axisWitnessFlatEdgeLengthDir (2, 3) k =
5528        freudenthalLocalPairClosedFormSchlaefliCoeff (2, 3) 1 *
5529            axisWitnessFlatEdgeLengthDir (2, 3) 1 +
5530          freudenthalLocalPairClosedFormSchlaefliCoeff (2, 3) 3 *
5531            axisWitnessFlatEdgeLengthDir (2, 3) 3 +
5532          freudenthalLocalPairClosedFormSchlaefliCoeff (2, 3) 4 *
5533            axisWitnessFlatEdgeLengthDir (2, 3) 4 := by
5534    rw [← Finset.sum_subset (Finset.subset_univ ({1, 3, 4} : Finset (Fin 6)))
5535      fun k _ hk =>
5536        axisWitnessPairSummand_23_inactive k (axisWitnessFin6_ne_of_not_mem_134 k hk)]
5537    rw [show ({1, 3, 4} : Finset (Fin 6)) = insert 1 (insert 3 {4}) from by decide]
5538    simp [Finset.sum_insert, Finset.sum_singleton]
5539    ring_nf
5540  rw [hsum]
5541  dsimp [axisWitnessFlatEdgeLengthDir]
5542  simp only [
5543    Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5544    addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5545    Geometry.ReggeRigorousFoundation.edgeVertices,
5546    freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5547    freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5548    axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5549  field_simp
5550  ring_nf
5551  norm_num [Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2), Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 1),
5552    Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 3)]
5553
5554private lemma axisWitnessPairSummand_43_inactive (k : Fin 6)
5555    (hk : k ≠ 1 ∧ k ≠ 3 ∧ k ≠ 4) :
5556    freudenthalLocalPairClosedFormSchlaefliCoeff (4, 3) k *
5557        axisWitnessFlatEdgeLengthDir (4, 3) k = 0 := by
5558  fin_cases k
5559  · dsimp [axisWitnessFlatEdgeLengthDir]
5560    simp only [
5561      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5562      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5563      Geometry.ReggeRigorousFoundation.edgeVertices,
5564      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5565      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5566      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5567    norm_num
5568  · exact (hk.1 rfl).elim
5569  · dsimp [axisWitnessFlatEdgeLengthDir]
5570    simp only [
5571      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5572      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5573      Geometry.ReggeRigorousFoundation.edgeVertices,
5574      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5575      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5576      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5577    norm_num
5578  · exact (hk.2.1 rfl).elim
5579  · exact (hk.2.2 rfl).elim
5580  · dsimp [axisWitnessFlatEdgeLengthDir]
5581    simp only [
5582      Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5583      addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5584      Geometry.ReggeRigorousFoundation.edgeVertices,
5585      freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5586      freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5587      axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5588    norm_num
5589
5590private lemma axisWitnessPairSummand_43 :
5591    axisWitnessPairSummand (4, 3) = (-1 : ℝ) := by
5592  dsimp [axisWitnessPairSummand]
5593  have hsum :
5594      ∑ k : Fin 6, freudenthalLocalPairClosedFormSchlaefliCoeff (4, 3) k *
5595          axisWitnessFlatEdgeLengthDir (4, 3) k =
5596        freudenthalLocalPairClosedFormSchlaefliCoeff (4, 3) 1 *
5597            axisWitnessFlatEdgeLengthDir (4, 3) 1 +
5598          freudenthalLocalPairClosedFormSchlaefliCoeff (4, 3) 3 *
5599            axisWitnessFlatEdgeLengthDir (4, 3) 3 +
5600          freudenthalLocalPairClosedFormSchlaefliCoeff (4, 3) 4 *
5601            axisWitnessFlatEdgeLengthDir (4, 3) 4 := by
5602    rw [← Finset.sum_subset (Finset.subset_univ ({1, 3, 4} : Finset (Fin 6)))
5603      fun k _ hk =>
5604        axisWitnessPairSummand_43_inactive k (axisWitnessFin6_ne_of_not_mem_134 k hk)]
5605    rw [show ({1, 3, 4} : Finset (Fin 6)) = insert 1 (insert 3 {4}) from by decide]
5606    simp [Finset.sum_insert, Finset.sum_singleton]
5607    ring_nf
5608  rw [hsum]
5609  dsimp [axisWitnessFlatEdgeLengthDir]
5610  simp only [
5611    Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges, addVertexBits, addBits,
5612    addBit, bit, vertexBits, Geometry.FreudenthalCubeTriangulation.tetVerts,
5613    Geometry.ReggeRigorousFoundation.edgeVertices,
5614    freudenthalLocalPairClosedFormSchlaefliCoeff_eq_table,
5615    freudenthalSchlaefliPolySummandNormTable, axisWitnessEndpoint0,
5616    axisWitnessEndpoint1, axisWitnessEndpointXi, axisWitnessCell, Fin.ext_iff, Prod.mk.injEq]
5617  field_simp
5618  ring_nf
5619  norm_num [Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 2), Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 1),
5620    Real.sq_sqrt (by norm_num : (0 : ℝ) ≤ 3)]
5621
5622theorem FreudenthalAxisDisp0AllPairSummandsEqAuditTarget_holds :
5623    FreudenthalAxisDisp0AllPairSummandsEqAuditTarget := by
5624  intro pair hp
5625  dsimp [FreudenthalAxisDisp0PairSummandEqAuditTarget, axisWitnessPairSummandAudit]
5626  have hp' :
5627      pair = (0, 0) ∨ pair = (1, 0) ∨ pair = (2, 3) ∨ pair = (3, 5) ∨ pair = (4, 3) ∨
5628        pair = (5, 5) := by
5629    simpa [freudenthalLocalPairDispFiber] using hp
5630  rcases hp' with rfl | rfl | rfl | rfl | rfl | rfl
5631  · exact axisWitnessPairSummand_00
5632  · exact axisWitnessPairSummand_10
5633  · exact axisWitnessPairSummand_23
5634  · exact axisWitnessPairSummand_35
5635  · exact axisWitnessPairSummand_43
5636  · exact axisWitnessPairSummand_55
5637
5638theorem FreudenthalAxisDisp0LocalFiberSumEqAuditTarget_holds :
5639    FreudenthalAxisDisp0LocalFiberSumEqAuditTarget := by
5640  dsimp [FreudenthalAxisDisp0LocalFiberSumEqAuditTarget, axisWitnessDisp0LocalFiberSum]
5641  have hfiber :
5642      ∑ pair ∈ freudenthalLocalPairDispFiber 0, axisWitnessPairSummand pair =
5643        axisWitnessPairSummand (0, 0) + axisWitnessPairSummand (1, 0) +
5644          axisWitnessPairSummand (2, 3) + axisWitnessPairSummand (3, 5) +
5645          axisWitnessPairSummand (4, 3) + axisWitnessPairSummand (5, 5) := by
5646    simp [freudenthalLocalPairDispFiber, Finset.sum_insert, Finset.sum_singleton]
5647    ring_nf
5648  rw [hfiber, axisWitnessPairSummand_00, axisWitnessPairSummand_10, axisWitnessPairSummand_23,
5649    axisWitnessPairSummand_35, axisWitnessPairSummand_43, axisWitnessPairSummand_55,
5650    freudenthalAxisDisp0EndpointUnitAuditSum]
5651
5652/-- Per-pair identification: explicit-fiber closed-form summand equals the local
5653flat length-chain audit summand on the axis witness at endpoint-unit data. -/
5654def FreudenthalAxisDisp0PairExplicitSummandEqLocalTarget
5655    (pair : FreudenthalLocalPair) (_hp : pair ∈ freudenthalLocalPairDispFiber 0) : Prop :=
5656  freudenthalExplicitFiberPairClosedFormExpandedSummand witnessHx witnessHy witnessHz
5657      axisWitnessEndpointUnitPotential axisWitnessEdge pair =
5658    axisWitnessPairSummand pair
5659
5660def FreudenthalAxisDisp0AllPairExplicitSummandsEqLocalTarget : Prop :=
5661  ∀ pair (hp : pair ∈ freudenthalLocalPairDispFiber 0),
5662    FreudenthalAxisDisp0PairExplicitSummandEqLocalTarget pair hp
5663
5664theorem FreudenthalAxisDisp0AllPairExplicitSummandsEqLocalTarget_holds :
5665    FreudenthalAxisDisp0AllPairExplicitSummandsEqLocalTarget := by
5666  intro pair hp
5667  dsimp [FreudenthalAxisDisp0PairExplicitSummandEqLocalTarget]
5668  exact axisWitness_explicitPairSummand_eq_local pair hp
5669
5670/-- Global closed-form fiber sum at the endpoint-unit potential on the axis witness edge. -/
5671def FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget : Prop :=
5672  freudenthalExplicitFiberClosedFormFiberSum witnessHx witnessHy witnessHz
5673      axisWitnessEndpointUnitPotential axisWitnessEdge 0 =
5674    (-4 : ℝ)
5675
5676/-- Bridge: global explicit-fiber sum equals the local audit sum on the axis witness. -/
5677def FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget : Prop :=
5678  freudenthalExplicitFiberClosedFormFiberSum witnessHx witnessHy witnessHz
5679      axisWitnessEndpointUnitPotential axisWitnessEdge 0 =
5680    axisWitnessDisp0LocalFiberSum
5681
5682theorem FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget_of_all_pair_explicit
5683    (hAll : FreudenthalAxisDisp0AllPairExplicitSummandsEqLocalTarget) :
5684    FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget := by
5685  dsimp [FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget, axisWitnessDisp0LocalFiberSum, axisWitnessEdge]
5686  refine Eq.trans
5687    (freudenthalExplicitFiberClosedFormFiberSum_eq_disp_fiber witnessHx witnessHy witnessHz
5688      axisWitnessEndpointUnitPotential axisWitnessEdge) ?_
5689  refine Finset.sum_congr rfl ?_
5690  intro pair hp
5691  exact hAll pair hp
5692
5693theorem FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget_holds :
5694    FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget :=
5695  FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget_of_all_pair_explicit
5696    FreudenthalAxisDisp0AllPairExplicitSummandsEqLocalTarget_holds
5697
5698theorem FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_of_local_and_audit
5699    (hLocal : FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget)
5700    (hAudit : FreudenthalAxisDisp0LocalFiberSumEqAuditTarget) :
5701    FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget := by
5702  dsimp [FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget,
5703    FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget, FreudenthalAxisDisp0LocalFiberSumEqAuditTarget]
5704  rw [hLocal, hAudit, freudenthalAxisDisp0EndpointUnitAuditSum_eq_neg_four]
5705
5706theorem FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_of_local
5707    (hLocal : FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget) :
5708    FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget :=
5709  FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_of_local_and_audit hLocal
5710    FreudenthalAxisDisp0LocalFiberSumEqAuditTarget_holds
5711
5712theorem FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_of_all_pair_explicit
5713    (hAll : FreudenthalAxisDisp0AllPairExplicitSummandsEqLocalTarget) :
5714    FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget :=
5715  FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_of_local
5716    (FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget_of_all_pair_explicit hAll)
5717
5718theorem FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_holds :
5719    FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget :=
5720  FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_of_local
5721    FreudenthalAxisDisp0GlobalFiberSumEqLocalTarget_holds
5722
5723/-- Bilinear endpoint template is inconsistent with a certified endpoint-unit fiber sum `-4`. -/
5724theorem FreudenthalExplicitFiberBilinearEndpointTemplateTarget_false_of_endpointUnitSum_neg_four
5725    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
5726    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
5727    (edge : PeriodicEdge Nx Ny Nz)
5728    (hdisp : edge.disp = 0)
5729    (endpoint0 endpoint1 : Vertex Nx Ny Nz)
5730    (hend : edge.endpoints = (endpoint0, endpoint1))
5731    (hSum :
5732      freudenthalExplicitFiberClosedFormFiberSum hx hy hz
5733          (fun i =>
5734            if i = (vertexFinEquiv Nx Ny Nz).symm endpoint0 ∨
5735                i = (vertexFinEquiv Nx Ny Nz).symm endpoint1 then
5736              1
5737            else 0)
5738          edge 0 =
5739        (-4 : ℝ))
5740    (hBilinear :
5741      FreudenthalExplicitFiberBilinearEndpointTemplateTarget Nx Ny Nz hx hy hz 0) :
5742    False := by
5743  rcases hBilinear with ⟨F, hTemplate, hFiber⟩
5744  have hF11 :=
5745    FreudenthalLocalDispLengthChainEndpointTemplateTarget_F_eq_zero_at_one_one 0 F hTemplate
5746  let ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K :=
5747    fun i =>
5748      if i = (vertexFinEquiv Nx Ny Nz).symm endpoint0 ∨
5749          i = (vertexFinEquiv Nx Ny Nz).symm endpoint1 then
5750        1
5751      else 0
5752  have hsum := hFiber ξ edge hdisp
5753  have hξ0 : ξ ((vertexFinEquiv Nx Ny Nz).symm endpoint0) = 1 := by
5754    dsimp only [ξ]
5755    rw [if_pos (Or.inl rfl)]
5756  have hξ1 : ξ ((vertexFinEquiv Nx Ny Nz).symm endpoint1) = 1 := by
5757    dsimp only [ξ]
5758    rw [if_pos (Or.inr rfl)]
5759  have hend1 : edge.endpoints.1 = endpoint0 := by simp [hend]
5760  have hend2 : edge.endpoints.2 = endpoint1 := by simp [hend]
5761  have hsum' :
5762      freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge 0 =
5763        F (ξ ((vertexFinEquiv Nx Ny Nz).symm endpoint0))
5764          (ξ ((vertexFinEquiv Nx Ny Nz).symm endpoint1)) := by
5765    simpa [hend1, hend2] using hsum
5766  rw [hξ0, hξ1, hF11] at hsum'
5767  linarith
5768
5769theorem FreudenthalExplicitFiberBilinearEndpointTemplateTarget_false_at_disp0_of_globalWitness
5770    (hGlobal : FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget)
5771    (hBilinear :
5772      FreudenthalExplicitFiberBilinearEndpointTemplateTarget WitnessNx WitnessNy WitnessNz
5773        witnessHx witnessHy witnessHz 0) :
5774    False :=
5775  FreudenthalExplicitFiberBilinearEndpointTemplateTarget_false_of_endpointUnitSum_neg_four
5776    witnessHx witnessHy witnessHz axisWitnessEdge (by rfl) axisWitnessEndpoint0 axisWitnessEndpoint1
5777    axisWitness_edge_endpoints
5778    (by simpa [FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget] using hGlobal) hBilinear
5779
5780theorem FreudenthalExplicitFiberBilinearEndpointTemplateTarget_false_at_disp0 :
5781    FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget →
5782      FreudenthalExplicitFiberBilinearEndpointTemplateTarget WitnessNx WitnessNy WitnessNz
5783        witnessHx witnessHy witnessHz 0 → False :=
5784  FreudenthalExplicitFiberBilinearEndpointTemplateTarget_false_at_disp0_of_globalWitness
5785
5786theorem FreudenthalExplicitFiberBilinearEndpointTemplateTarget_false_at_disp0_unconditional :
5787    FreudenthalExplicitFiberBilinearEndpointTemplateTarget WitnessNx WitnessNy WitnessNz
5788        witnessHx witnessHy witnessHz 0 → False :=
5789  FreudenthalExplicitFiberBilinearEndpointTemplateTarget_false_at_disp0
5790    FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_holds
5791
5792/-- The per-disp explicit-fiber mixed identity fails at axis class `0` on the
5793endpoint-unit counterexample: fiber sum `-4` forces LHS `4` while RHS is `0`. -/
5794theorem FreudenthalAxisDisp0ExplicitFiberClosedFormPerDispTarget_zero_false :
5795    ¬ CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget
5796      WitnessNx WitnessNy WitnessNz witnessHx witnessHy witnessHz 0 := by
5797  intro h
5798  have hc := h axisWitnessEndpointUnitPotential axisWitnessEdge rfl
5799  have hsum := FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_holds
5800  rw [axisWitness_edge_endpoints, hsum,
5801    axisWitnessEndpointUnitPotential_apply_eq_xi axisWitnessEndpoint0,
5802    axisWitnessEndpointUnitPotential_apply_eq_xi axisWitnessEndpoint1] at hc
5803  have hξ0 : axisWitnessEndpointXi axisWitnessEndpoint0 = 1 := by
5804    simp [axisWitnessEndpointXi, axisWitnessEndpoint0]
5805  have hξ1 : axisWitnessEndpointXi axisWitnessEndpoint1 = 1 := by
5806    simp [axisWitnessEndpointXi, axisWitnessEndpoint1, axisWitnessEndpoint0]
5807  rw [hξ0, hξ1] at hc
5808  have hs := periodicDispSqEdge_sqrt_ne_zero (0 : Fin 7)
5809  have hFourMul :
5810      Real.sqrt (periodicDispSqEdge 0) * (4 : ℝ) = 0 := by
5811    calc
5812      Real.sqrt (periodicDispSqEdge 0) * (4 : ℝ) =
5813          Real.sqrt (periodicDispSqEdge 0) * (1 + 1) / 2 * (-(-4 : ℝ)) := by ring
5814      _ = Real.sqrt (periodicDispSqEdge 0) * (1 - 1) ^ (2 : ℕ) := hc
5815      _ = 0 := by norm_num
5816  rw [mul_eq_zero] at hFourMul
5817  rcases hFourMul with hsZero | hFourZero
5818  · exact False.elim (hs hsZero)
5819  · norm_num at hFourZero
5820
5821theorem FreudenthalAxisDisp0ExplicitFiberFlatUnfoldedTarget_false :
5822    ¬ CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget
5823      WitnessNx WitnessNy WitnessNz witnessHx witnessHy witnessHz := by
5824  intro h
5825  have hc := h axisWitnessEndpointUnitPotential axisWitnessEdge
5826  have hsum := FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget_holds
5827  have hflatSum :
5828      (∑ pair ∈ freudenthalLocalPairDispFiber axisWitnessEdge.disp,
5829          freudenthalExplicitFiberPairFlatExpandedSummand witnessHx witnessHy witnessHz
5830            axisWitnessEndpointUnitPotential axisWitnessEdge pair) =
5831        (-4 : ℝ) := by
5832    rw [freudenthalExplicitFiberFlatDispFiberSum_eq_closedFormFiberSum]
5833    dsimp [FreudenthalAxisDisp0GlobalEndpointUnitFiberSumTarget] at hsum
5834    exact hsum
5835  dsimp [CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget] at hc
5836  rw [hingeMeasureDirectionalDeriv_canonicalEncodedPeriodic_edge,
5837    axisWitness_edge_endpoints,
5838    axisWitnessEndpointUnitPotential_apply_eq_xi axisWitnessEndpoint0,
5839    axisWitnessEndpointUnitPotential_apply_eq_xi axisWitnessEndpoint1,
5840    hflatSum] at hc
5841  have hs := periodicDispSqEdge_sqrt_ne_zero (0 : Fin 7)
5842  have hFourMul : Real.sqrt (periodicDispSqEdge 0) * (4 : ℝ) = 0 := by
5843    calc
5844      Real.sqrt (periodicDispSqEdge 0) * (4 : ℝ) =
5845          Real.sqrt (periodicDispSqEdge 0) * (1 + 1) / 2 * (-(-4 : ℝ)) := by ring
5846      _ = Real.sqrt (periodicDispSqEdge 0) * (1 - 1) ^ (2 : ℕ) := hc
5847      _ = 0 := by norm_num
5848  rw [mul_eq_zero] at hFourMul
5849  rcases hFourMul with hsZero | hFourZero
5850  · exact False.elim (hs hsZero)
5851  · norm_num at hFourZero
5852
5853end AxisDisp0EndpointUnitWitness5
5854
5855theorem FreudenthalExplicitFiberEndpointDependenceTarget_of_bilinearEndpoint
5856    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5857    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7)
5858    (hBilinear : FreudenthalExplicitFiberBilinearEndpointTemplateTarget Nx Ny Nz hx hy hz d) :
5859    FreudenthalExplicitFiberEndpointDependenceTarget Nx Ny Nz hx hy hz d := by
5860  rcases hBilinear with ⟨F, _, hFiber⟩
5861  exact ⟨F, hFiber⟩
5862
5863/-- Alias for the per-displacement explicit-fiber bilinear target (bilinear form). -/
5864def CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispBilinearTarget
5865    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5866    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7) : Prop :=
5867  CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget
5868    Nx Ny Nz hx hy hz d
5869
5870/-- The three distinct explicit-fiber bilinear identities (axis, face-diagonal,
5871body-diagonal). -/
5872def CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormThreeBilinearTarget
5873    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5874    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
5875  CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispBilinearTarget
5876      Nx Ny Nz hx hy hz 0 ∧
5877    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispBilinearTarget
5878      Nx Ny Nz hx hy hz 3 ∧
5879    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispBilinearTarget
5880      Nx Ny Nz hx hy hz 6
5881
5882theorem CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget_of_endpointTemplate
5883    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5884    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7)
5885    (F : ℝ → ℝ → ℝ)
5886    (hFiberSum :
5887      ∀ (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
5888        (edge : PeriodicEdge Nx Ny Nz),
5889        edge.disp = d →
5890          freudenthalExplicitFiberClosedFormFiberSum hx hy hz ξ edge d =
5891            F (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1))
5892              (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)))
5893    (hTemplate : FreudenthalLocalDispLengthChainEndpointTemplateTarget d F) :
5894    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget
5895      Nx Ny Nz hx hy hz d := by
5896  intro ξ edge hdisp
5897  have hsum := hFiberSum ξ edge hdisp
5898  have htemp := hTemplate
5899    (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1))
5900    (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2))
5901  simpa [CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget,
5902    hingeMeasureDirectionalDeriv_canonicalEncodedPeriodic_edge, hdisp, hsum] using htemp
5903
5904theorem CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget_of_bilinearEndpoint
5905    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5906    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7)
5907    (hBilinear : FreudenthalExplicitFiberBilinearEndpointTemplateTarget Nx Ny Nz hx hy hz d) :
5908    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget
5909      Nx Ny Nz hx hy hz d := by
5910  rcases hBilinear with ⟨F, hTemplate, hFiber⟩
5911  exact CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget_of_endpointTemplate
5912    Nx Ny Nz hx hy hz d F hFiber hTemplate
5913
5914/-- All seven displacement classes satisfy the explicit-fiber bilinear identity. -/
5915def CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormAllBilinearTarget
5916    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5917    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
5918  ∀ d : Fin 7,
5919    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispBilinearTarget
5920      Nx Ny Nz hx hy hz d
5921
5922theorem FreudenthalAxisDisp0ExplicitFiberClosedFormAllBilinearTarget_false :
5923    ¬ CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormAllBilinearTarget
5924      AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
5925      AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
5926      AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz :=
5927  fun h =>
5928    AxisDisp0EndpointUnitWitness5.FreudenthalAxisDisp0ExplicitFiberClosedFormPerDispTarget_zero_false
5929      (h 0)
5930
5931theorem canonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget_of_allBilinear
5932    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5933    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
5934    (hAll :
5935      CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormAllBilinearTarget
5936        Nx Ny Nz hx hy hz) :
5937    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget
5938      Nx Ny Nz hx hy hz := by
5939  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
5940  intro ξ edge
5941  have hdisp := hAll edge.disp ξ edge rfl
5942  simpa [CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget,
5943    hingeMeasureDirectionalDeriv_canonicalEncodedPeriodic_edge,
5944    freudenthalExplicitFiberClosedFormFiberSum_eq_disp_fiber, P] using hdisp
5945
5946theorem canonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget_of_perDisp
5947    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5948    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
5949    (hPerDisp :
5950      ∀ d : Fin 7,
5951        CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget
5952          Nx Ny Nz hx hy hz d) :
5953    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget
5954      Nx Ny Nz hx hy hz := by
5955  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
5956  intro ξ edge
5957  have hdisp := hPerDisp edge.disp ξ edge rfl
5958  simpa [CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget,
5959    hingeMeasureDirectionalDeriv_canonicalEncodedPeriodic_edge,
5960    freudenthalExplicitFiberClosedFormFiberSum_eq_disp_fiber, P] using hdisp
5961
5962theorem canonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget_of_closedForm
5963    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5964    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
5965    (d : Fin 7)
5966    (hClosedForm :
5967      CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget
5968        Nx Ny Nz hx hy hz) :
5969    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget
5970      Nx Ny Nz hx hy hz d := by
5971  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
5972  intro ξ edge hdisp
5973  have hfull := hClosedForm ξ edge
5974  simpa [CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget,
5975    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget,
5976    hingeMeasureDirectionalDeriv_canonicalEncodedPeriodic_edge,
5977    freudenthalExplicitFiberClosedFormFiberSum_eq_disp_fiber, hdisp, P] using hfull
5978
5979theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget_of_flatUnfolded
5980    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
5981    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
5982    (hFlatUnfolded :
5983      CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget
5984        Nx Ny Nz hx hy hz) :
5985    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
5986      Nx Ny Nz hx hy hz := by
5987  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
5988  intro ξ edge
5989  have hsum :
5990      (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
5991          freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair) =
5992        ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
5993          freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair := by
5994    refine Finset.sum_congr rfl ?_
5995    intro pair _
5996    exact freudenthalExplicitFiberPairFlatExpandedSummand_eq_expanded hx hy hz ξ edge pair
5997  simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget,
5998    CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget, hsum, P] using
5999    hFlatUnfolded ξ edge
6000
6001theorem canonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget_of_expandedLengthChainExplicitFiber
6002    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6003    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6004    (hExplicit :
6005      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
6006        Nx Ny Nz hx hy hz) :
6007    CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget
6008      Nx Ny Nz hx hy hz := by
6009  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6010  intro ξ edge
6011  have hsum :
6012      (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
6013          freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
6014        ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
6015          freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair := by
6016    refine Finset.sum_congr rfl ?_
6017    intro pair _
6018    exact (freudenthalExplicitFiberPairFlatExpandedSummand_eq_expanded hx hy hz ξ edge pair).symm
6019  simpa [CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget,
6020    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget, hsum, P] using
6021    hExplicit ξ edge
6022
6023theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget_iff_flatUnfolded
6024    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6025    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
6026    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
6027      Nx Ny Nz hx hy hz ↔
6028      CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget
6029        Nx Ny Nz hx hy hz :=
6030  ⟨canonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget_of_flatUnfolded
6031      Nx Ny Nz hx hy hz,
6032    canonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget_of_expandedLengthChainExplicitFiber
6033      Nx Ny Nz hx hy hz⟩
6034
6035theorem FreudenthalAxisDisp0ExplicitFiberExpandedLengthChainExplicitFiberTarget_false :
6036    ¬ CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
6037      AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
6038      AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
6039      AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz :=
6040  fun h =>
6041    AxisDisp0EndpointUnitWitness5.FreudenthalAxisDisp0ExplicitFiberFlatUnfoldedTarget_false
6042      (canonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget_of_expandedLengthChainExplicitFiber
6043        AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
6044        AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
6045        AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz h)
6046
6047theorem canonicalPeriodicEdgeStencilLocalCorrespondence_not_of_closedFormPerDisp_at_axisWitness
6048    (hPerDisp :
6049      ∀ d : Fin 7,
6050        CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget
6051          AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
6052          AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
6053          AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz d) :
6054    False :=
6055  AxisDisp0EndpointUnitWitness5.FreudenthalAxisDisp0ExplicitFiberClosedFormPerDispTarget_zero_false
6056    (hPerDisp 0)
6057
6058/-- Canonical periodic Track 1.B second-order Schläfli stationarity, packaged at
6059the flat configuration already discharged for the encoded Freudenthal torus. -/
6060def CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget
6061    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6062    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6063  WeightedDeficitDerivativeStationaryTarget
6064    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6065    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6066    (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
6067
6068def CanonicalPeriodicSecondSchlaefliAlongLineTarget
6069    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6070    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6071  SecondSchlaefliAlongLineTarget
6072    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6073    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6074    (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
6075
6076/-- Typed-periodic-edge form of the second-order Schläfli target.  This is the
6077same stationarity identity as `CanonicalPeriodicSecondSchlaefliAlongLineTarget`,
6078but reindexed from anonymous encoded edge indices to `PeriodicEdge` records.
6079Track `1B-SCH` should use this form for finite-table stationarity work. -/
6080def CanonicalPeriodicSecondSchlaefliTypedEdgeTarget
6081    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6082    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6083  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6084  ∀ ξ : VertexPotential P.K,
6085    (∑ edge : PeriodicEdge Nx Ny Nz,
6086      let e := P.edgeEquiv.symm edge
6087      (hingeLineDeriv P.K P.hK ξ e 0 * deficitLineDeriv P.K ξ e 0 +
6088        hingeMeasureUnderConformal P.K P.hK
6089          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ 0) e *
6090          deficitLineSecondDeriv P.K ξ e 0)) = 0
6091
6092def canonicalPeriodicSecondSchlaefliTypedEdgeSummand
6093    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6094    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6095    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
6096    (edge : PeriodicEdge Nx Ny Nz) : ℝ :=
6097  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6098  let e := P.edgeEquiv.symm edge
6099  hingeLineDeriv P.K P.hK ξ e 0 * deficitLineDeriv P.K ξ e 0 +
6100    hingeMeasureUnderConformal P.K P.hK
6101      (Geometry.ReggeActionSecondVariation.linePotential P.K ξ 0) e *
6102      deficitLineSecondDeriv P.K ξ e 0
6103
6104/-- Fixed-displacement-class form of the typed second-order Schläfli target. -/
6105def CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
6106    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6107    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) (d : Fin 7) : Prop :=
6108  ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
6109    (∑ edge ∈ ((Finset.univ : Finset (PeriodicEdge Nx Ny Nz)).filter
6110        (fun edge => edge.disp = d)),
6111      canonicalPeriodicSecondSchlaefliTypedEdgeSummand Nx Ny Nz hx hy hz ξ edge) = 0
6112
6113/-- Per-displacement form of the typed second-order Schläfli target.  This is
6114the `1B-SCH` finite cancellation table: each of the seven periodic displacement
6115classes contributes zero separately. -/
6116def CanonicalPeriodicSecondSchlaefliTypedEdgePerDispTarget
6117    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6118    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6119  ∀ (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
6120    (d : Fin 7),
6121    (∑ edge ∈ ((Finset.univ : Finset (PeriodicEdge Nx Ny Nz)).filter
6122        (fun edge => edge.disp = d)),
6123      canonicalPeriodicSecondSchlaefliTypedEdgeSummand Nx Ny Nz hx hy hz ξ edge) = 0
6124
6125theorem canonicalPeriodicSecondSchlaefliTypedEdgeTarget_of_perDisp
6126    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6127    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6128    (hDisp : CanonicalPeriodicSecondSchlaefliTypedEdgePerDispTarget Nx Ny Nz hx hy hz) :
6129    CanonicalPeriodicSecondSchlaefliTypedEdgeTarget Nx Ny Nz hx hy hz := by
6130  classical
6131  intro ξ
6132  let f : PeriodicEdge Nx Ny Nz → ℝ :=
6133    canonicalPeriodicSecondSchlaefliTypedEdgeSummand Nx Ny Nz hx hy hz ξ
6134  have hpartition :
6135      (∑ d : Fin 7,
6136        ∑ edge ∈ ((Finset.univ : Finset (PeriodicEdge Nx Ny Nz)).filter
6137          (fun edge => edge.disp = d)), f edge) =
6138        ∑ edge : PeriodicEdge Nx Ny Nz, f edge := by
6139    simpa [f] using
6140      (Finset.sum_fiberwise
6141        (s := (Finset.univ : Finset (PeriodicEdge Nx Ny Nz)))
6142        (g := fun edge : PeriodicEdge Nx Ny Nz => edge.disp)
6143        (f := f))
6144  have hzero :
6145      (∑ d : Fin 7,
6146        ∑ edge ∈ ((Finset.univ : Finset (PeriodicEdge Nx Ny Nz)).filter
6147          (fun edge => edge.disp = d)), f edge) = 0 := by
6148    simp [f, hDisp ξ]
6149  change (∑ edge : PeriodicEdge Nx Ny Nz, f edge) = 0
6150  rw [← hpartition]
6151  exact hzero
6152
6153theorem canonicalPeriodicSecondSchlaefliAlongLineTarget_iff_typedEdge
6154    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6155    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
6156    CanonicalPeriodicSecondSchlaefliAlongLineTarget Nx Ny Nz hx hy hz ↔
6157      CanonicalPeriodicSecondSchlaefliTypedEdgeTarget Nx Ny Nz hx hy hz := by
6158  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6159  constructor
6160  · intro hSch ξ
6161    let F : Fin P.K.nE → ℝ := fun e =>
6162      hingeLineDeriv P.K P.hK ξ e 0 * deficitLineDeriv P.K ξ e 0 +
6163        hingeMeasureUnderConformal P.K P.hK
6164          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ 0) e *
6165          deficitLineSecondDeriv P.K ξ e 0
6166    have hreindex :
6167        (∑ edge : PeriodicEdge Nx Ny Nz, F (P.edgeEquiv.symm edge)) =
6168          ∑ e : Fin P.K.nE, F e := by
6169      simpa [F] using (Equiv.sum_comp P.edgeEquiv.symm F)
6170    rw [hreindex]
6171    simpa [CanonicalPeriodicSecondSchlaefliAlongLineTarget,
6172      SecondSchlaefliAlongLineTarget, P, F] using hSch ξ
6173  · intro hTyped ξ
6174    let F : Fin P.K.nE → ℝ := fun e =>
6175      hingeLineDeriv P.K P.hK ξ e 0 * deficitLineDeriv P.K ξ e 0 +
6176        hingeMeasureUnderConformal P.K P.hK
6177          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ 0) e *
6178          deficitLineSecondDeriv P.K ξ e 0
6179    have hreindex :
6180        (∑ edge : PeriodicEdge Nx Ny Nz, F (P.edgeEquiv.symm edge)) =
6181          ∑ e : Fin P.K.nE, F e := by
6182      simpa [F] using (Equiv.sum_comp P.edgeEquiv.symm F)
6183    have h0 : (∑ edge : PeriodicEdge Nx Ny Nz, F (P.edgeEquiv.symm edge)) = 0 := by
6184      simpa [CanonicalPeriodicSecondSchlaefliTypedEdgeTarget, P, F] using hTyped ξ
6185    have h0e : (∑ e : Fin P.K.nE, F e) = 0 := hreindex.symm.trans h0
6186    simpa [CanonicalPeriodicSecondSchlaefliAlongLineTarget,
6187      SecondSchlaefliAlongLineTarget, P, F] using h0e
6188
6189theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_iff_secondSchlaefli
6190    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6191    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
6192    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget Nx Ny Nz hx hy hz ↔
6193      CanonicalPeriodicSecondSchlaefliAlongLineTarget Nx Ny Nz hx hy hz := by
6194  dsimp [CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget,
6195    CanonicalPeriodicSecondSchlaefliAlongLineTarget]
6196  exact
6197    weightedDeficitDerivativeStationaryTarget_iff_secondSchlaefliAlongLine
6198      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6199      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6200      (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
6201
6202theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_iff_typedEdge
6203    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6204    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
6205    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget Nx Ny Nz hx hy hz ↔
6206      CanonicalPeriodicSecondSchlaefliTypedEdgeTarget Nx Ny Nz hx hy hz := by
6207  exact
6208    (canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_iff_secondSchlaefli
6209      Nx Ny Nz hx hy hz).trans
6210      (canonicalPeriodicSecondSchlaefliAlongLineTarget_iff_typedEdge
6211        Nx Ny Nz hx hy hz)
6212
6213/-- Stronger punctured-neighbourhood Schläfli form at the canonical periodic flat
6214configuration.  Implies `CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget`. -/
6215def CanonicalPeriodicWeightedDeficitDerivativeEventuallyZeroTarget
6216    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6217    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6218  WeightedDeficitDerivativeEventuallyZeroTarget
6219    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6220    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6221    (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
6222
6223theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_of_eventuallyZero
6224    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6225    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6226    (hZero :
6227      CanonicalPeriodicWeightedDeficitDerivativeEventuallyZeroTarget Nx Ny Nz hx hy hz) :
6228    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget Nx Ny Nz hx hy hz := by
6229  dsimp [CanonicalPeriodicWeightedDeficitDerivativeEventuallyZeroTarget,
6230    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget] at hZero ⊢
6231  exact
6232    weightedDeficitDerivativeStationary_of_eventuallyZero
6233      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6234      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6235      (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz) hZero
6236
6237theorem canonicalPeriodicSecondSchlaefliAlongLineTarget_of_eventuallyZero
6238    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6239    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6240    (hZero :
6241      CanonicalPeriodicWeightedDeficitDerivativeEventuallyZeroTarget Nx Ny Nz hx hy hz) :
6242    CanonicalPeriodicSecondSchlaefliAlongLineTarget Nx Ny Nz hx hy hz :=
6243  (canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_iff_secondSchlaefli Nx Ny Nz hx hy
6244      hz).1
6245    (canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_of_eventuallyZero Nx Ny Nz hx hy
6246      hz hZero)
6247
6248/-- The conformal Schläfli identity along the full conformal line on the
6249canonical periodic Freudenthal torus.  This says `V(t) = 0` for ALL `t`,
6250where `V(t) = ∑_e h(t•ξ, e) * deficitLineDeriv(ξ, e, t)`.
6251
6252Proving this single geometric hypothesis (a consequence of the classical
6253Schläfli differential identity `∑_{e∈τ} ℓ_e dθ_{e,τ} = 0` applied at every
6254parameter `t` and summed over all tetrahedra) directly closes the full
6255`CanonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5` without any
6256per-displacement-class decomposition. -/
6257def CanonicalPeriodicConformalSchlaefliAlongLineTarget
6258    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6259    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6260  ConformalSchlaefliAlongLineTarget
6261    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6262    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6263
6264/-- Canonical periodic local non-flat Schläfli target along conformal lines. -/
6265def CanonicalPeriodicLocalConformalSchlaefliAlongLineTarget
6266    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6267    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6268  LocalConformalSchlaefliAlongLineTarget
6269    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6270
6271/-- Canonical periodic non-flat expansion/reindexing target for
6272`∑_e h_e δ'_e` along conformal lines. -/
6273def CanonicalPeriodicConformalSchlaefliAlongLineExpansionTarget
6274    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6275    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6276  ConformalSchlaefliAlongLineExpansionTarget
6277    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6278    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6279
6280/-- Canonical periodic local near-flat non-flat Schläfli target along conformal
6281lines.  This is the domain-correct version needed for the Hessian proof. -/
6282def CanonicalPeriodicLocalConformalSchlaefliNearZeroTarget
6283    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6284    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6285  LocalConformalSchlaefliNearZeroTarget
6286    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6287
6288/-- Canonical periodic near-flat expansion/reindexing target for
6289`∑_e h_e δ'_e` along conformal lines. -/
6290def CanonicalPeriodicConformalSchlaefliNearZeroExpansionTarget
6291    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6292    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6293  ConformalSchlaefliNearZeroExpansionTarget
6294    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6295    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6296
6297/-- Canonical periodic non-flat local angle chain rule, in squared-edge
6298coordinates and localized near the flat point. -/
6299def CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget
6300    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6301    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6302  LocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget
6303    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6304
6305/-- Canonical periodic closed-form local Schläfli zero at the deformed
6306squared-edge tuple, localized near the flat point. -/
6307def CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTarget
6308    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6309    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6310  LocalConformalSchlaefliClosedFormZeroNearZeroTarget
6311    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6312
6313/-- The near-flat expansion plus local Schläfli target directly closes the
6314canonical stationarity target. -/
6315theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_of_nearZeroSchlaefli
6316    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6317    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6318    (hExpand :
6319      CanonicalPeriodicConformalSchlaefliNearZeroExpansionTarget Nx Ny Nz hx hy hz)
6320    (hLocal :
6321      CanonicalPeriodicLocalConformalSchlaefliNearZeroTarget Nx Ny Nz hx hy hz) :
6322    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget Nx Ny Nz hx hy hz := by
6323  dsimp [CanonicalPeriodicConformalSchlaefliNearZeroExpansionTarget,
6324    CanonicalPeriodicLocalConformalSchlaefliNearZeroTarget,
6325    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget] at hExpand hLocal ⊢
6326  exact
6327    weightedDeficitDerivativeStationary_of_nearZeroExpansion_and_local
6328      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6329      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6330      (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
6331      hExpand hLocal
6332
6333/-- The canonical along-line Schläfli target follows from the two localized
6334non-flat targets: local tetrahedral Schläfli at every line parameter plus the
6335global expansion/reindexing of `∑ h δ'` into those local sums. -/
6336theorem canonicalPeriodicConformalSchlaefliAlongLineTarget_of_expansion_and_local
6337    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6338    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6339    (hExpand :
6340      CanonicalPeriodicConformalSchlaefliAlongLineExpansionTarget Nx Ny Nz hx hy hz)
6341    (hLocal :
6342      CanonicalPeriodicLocalConformalSchlaefliAlongLineTarget Nx Ny Nz hx hy hz) :
6343    CanonicalPeriodicConformalSchlaefliAlongLineTarget Nx Ny Nz hx hy hz := by
6344  dsimp [CanonicalPeriodicConformalSchlaefliAlongLineTarget,
6345    CanonicalPeriodicConformalSchlaefliAlongLineExpansionTarget,
6346    CanonicalPeriodicLocalConformalSchlaefliAlongLineTarget] at hExpand hLocal ⊢
6347  exact
6348    conformalSchlaefliAlongLine_of_expansion_and_local
6349      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6350      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6351      hExpand hLocal
6352
6353theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_of_conformalSchlaefli
6354    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6355    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6356    (hSchlaefli :
6357      CanonicalPeriodicConformalSchlaefliAlongLineTarget Nx Ny Nz hx hy hz) :
6358    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget Nx Ny Nz hx hy hz := by
6359  dsimp [CanonicalPeriodicConformalSchlaefliAlongLineTarget,
6360    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget] at hSchlaefli ⊢
6361  exact
6362    weightedDeficitDerivativeStationary_of_conformalSchlaefliAlongLine
6363      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6364      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
6365      (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz) hSchlaefli
6366
6367/-- At `N=5`: the conformal Schläfli identity along the line closes the full
6368stationarity target, bypassing all per-displacement-class machinery. -/
6369abbrev CanonicalPeriodicConformalSchlaefliAlongLineTargetAtN5 : Prop :=
6370  CanonicalPeriodicConformalSchlaefliAlongLineTarget
6371    5 5 5 (by decide) (by decide) (by decide)
6372
6373abbrev CanonicalPeriodicLocalConformalSchlaefliNearZeroTargetAtN5 : Prop :=
6374  CanonicalPeriodicLocalConformalSchlaefliNearZeroTarget
6375    5 5 5 (by decide) (by decide) (by decide)
6376
6377abbrev CanonicalPeriodicConformalSchlaefliNearZeroExpansionTargetAtN5 : Prop :=
6378  CanonicalPeriodicConformalSchlaefliNearZeroExpansionTarget
6379    5 5 5 (by decide) (by decide) (by decide)
6380
6381abbrev CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTargetAtN5 : Prop :=
6382  CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget
6383    5 5 5 (by decide) (by decide) (by decide)
6384
6385abbrev CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTargetAtN5 : Prop :=
6386  CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTarget
6387    5 5 5 (by decide) (by decide) (by decide)
6388
6389theorem canonicalPeriodicLocalConformalSchlaefliNearZeroTarget_of_sqEdgeChainRule_and_closedFormZero
6390    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6391    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6392    (hChain :
6393      CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget
6394        Nx Ny Nz hx hy hz)
6395    (hZero :
6396      CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTarget
6397        Nx Ny Nz hx hy hz) :
6398    CanonicalPeriodicLocalConformalSchlaefliNearZeroTarget Nx Ny Nz hx hy hz := by
6399  dsimp [CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget,
6400    CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTarget,
6401    CanonicalPeriodicLocalConformalSchlaefliNearZeroTarget] at hChain hZero ⊢
6402  exact
6403    localConformalSchlaefliNearZero_of_sqEdgeChainRule_and_closedFormZero
6404      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6405      hChain hZero
6406
6407theorem canonicalPeriodicLocalConformalSchlaefliNearZeroTargetAtN5_of_sqEdgeChainRule_and_closedFormZero
6408    (hChain :
6409      CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTargetAtN5)
6410    (hZero :
6411      CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTargetAtN5) :
6412    CanonicalPeriodicLocalConformalSchlaefliNearZeroTargetAtN5 :=
6413  canonicalPeriodicLocalConformalSchlaefliNearZeroTarget_of_sqEdgeChainRule_and_closedFormZero
6414    5 5 5 (by decide) (by decide) (by decide) hChain hZero
6415
6416/-- The near-flat global Schläfli expansion/reindexing target is closed for the
6417canonical periodic Freudenthal torus.  The proof differentiates the finite
6418deficit-angle sum near zero and uses the encoded edge-slot partition to reindex
6419global edge incidences into local tetrahedral edge slots. -/
6420theorem canonicalPeriodicConformalSchlaefliNearZeroExpansionTarget
6421    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6422    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
6423    CanonicalPeriodicConformalSchlaefliNearZeroExpansionTarget Nx Ny Nz hx hy hz := by
6424  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6425  dsimp [CanonicalPeriodicConformalSchlaefliNearZeroExpansionTarget]
6426  exact
6427    conformalSchlaefliNearZeroExpansion_of_angleDiff_and_partition
6428      P.K P.hK
6429      (edgeSlotPartition_of_encodedPeriodicFreudenthalTorus P)
6430      (localDihedralAngleLineDifferentiabilityNearZero_of_flatConfiguration
6431        P.K P.hK
6432        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
6433
6434theorem canonicalPeriodicConformalSchlaefliNearZeroExpansionTargetAtN5 :
6435    CanonicalPeriodicConformalSchlaefliNearZeroExpansionTargetAtN5 :=
6436  canonicalPeriodicConformalSchlaefliNearZeroExpansionTarget
6437    5 5 5 (by decide) (by decide) (by decide)
6438
6439/-- The non-flat squared-edge chain rule half of the local conformal Schläfli
6440identity is closed for every canonical periodic Freudenthal torus, localized
6441near the flat point. -/
6442theorem canonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget
6443    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6444    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
6445    CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget
6446      Nx Ny Nz hx hy hz := by
6447  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6448  dsimp [CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget]
6449  exact
6450    localConformalSchlaefliAngleSqEdgeChainRuleNearZero_of_flatConfiguration
6451      P.K P.hK
6452      (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
6453
6454theorem canonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTargetAtN5 :
6455    CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTargetAtN5 :=
6456  canonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget
6457    5 5 5 (by decide) (by decide) (by decide)
6458
6459/-- The closed-form algebraic Schläfli-zero half of the local conformal
6460identity is closed for every canonical periodic Freudenthal torus. -/
6461theorem canonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTarget
6462    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6463    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
6464    CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTarget
6465      Nx Ny Nz hx hy hz := by
6466  dsimp [CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTarget]
6467  exact
6468    localConformalSchlaefliClosedFormZeroNearZero
6469      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
6470
6471theorem canonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTargetAtN5 :
6472    CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTargetAtN5 :=
6473  canonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTarget
6474    5 5 5 (by decide) (by decide) (by decide)
6475
6476theorem canonicalPeriodicLocalConformalSchlaefliNearZeroTarget
6477    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6478    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
6479    CanonicalPeriodicLocalConformalSchlaefliNearZeroTarget Nx Ny Nz hx hy hz :=
6480  canonicalPeriodicLocalConformalSchlaefliNearZeroTarget_of_sqEdgeChainRule_and_closedFormZero
6481    Nx Ny Nz hx hy hz
6482    (canonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTarget
6483      Nx Ny Nz hx hy hz)
6484    (canonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTarget
6485      Nx Ny Nz hx hy hz)
6486
6487theorem canonicalPeriodicLocalConformalSchlaefliNearZeroTargetAtN5 :
6488    CanonicalPeriodicLocalConformalSchlaefliNearZeroTargetAtN5 :=
6489  canonicalPeriodicLocalConformalSchlaefliNearZeroTarget
6490    5 5 5 (by decide) (by decide) (by decide)
6491
6492theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_nearZeroSchlaefli
6493    (hExpand : CanonicalPeriodicConformalSchlaefliNearZeroExpansionTargetAtN5)
6494    (hLocal : CanonicalPeriodicLocalConformalSchlaefliNearZeroTargetAtN5) :
6495    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget
6496      5 5 5 (by decide) (by decide) (by decide) :=
6497  canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_of_nearZeroSchlaefli
6498    5 5 5 (by decide) (by decide) (by decide) hExpand hLocal
6499
6500theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_sqEdgeChainRule_and_closedFormZero
6501    (hChain :
6502      CanonicalPeriodicLocalConformalSchlaefliAngleSqEdgeChainRuleNearZeroTargetAtN5)
6503    (hZero :
6504      CanonicalPeriodicLocalConformalSchlaefliClosedFormZeroNearZeroTargetAtN5) :
6505    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget
6506      5 5 5 (by decide) (by decide) (by decide) :=
6507  canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_nearZeroSchlaefli
6508    canonicalPeriodicConformalSchlaefliNearZeroExpansionTargetAtN5
6509    (canonicalPeriodicLocalConformalSchlaefliNearZeroTargetAtN5_of_sqEdgeChainRule_and_closedFormZero
6510      hChain hZero)
6511
6512theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_from_nearZeroSchlaefli :
6513    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget
6514      5 5 5 (by decide) (by decide) (by decide) :=
6515  canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_nearZeroSchlaefli
6516    canonicalPeriodicConformalSchlaefliNearZeroExpansionTargetAtN5
6517    canonicalPeriodicLocalConformalSchlaefliNearZeroTargetAtN5
6518
6519abbrev CanonicalPeriodicLocalConformalSchlaefliAlongLineTargetAtN5 : Prop :=
6520  CanonicalPeriodicLocalConformalSchlaefliAlongLineTarget
6521    5 5 5 (by decide) (by decide) (by decide)
6522
6523abbrev CanonicalPeriodicConformalSchlaefliAlongLineExpansionTargetAtN5 : Prop :=
6524  CanonicalPeriodicConformalSchlaefliAlongLineExpansionTarget
6525    5 5 5 (by decide) (by decide) (by decide)
6526
6527theorem CanonicalPeriodicConformalSchlaefliAlongLineTargetAtN5_of_expansion_and_local
6528    (hExpand : CanonicalPeriodicConformalSchlaefliAlongLineExpansionTargetAtN5)
6529    (hLocal : CanonicalPeriodicLocalConformalSchlaefliAlongLineTargetAtN5) :
6530    CanonicalPeriodicConformalSchlaefliAlongLineTargetAtN5 :=
6531  canonicalPeriodicConformalSchlaefliAlongLineTarget_of_expansion_and_local
6532    5 5 5 (by decide) (by decide) (by decide) hExpand hLocal
6533
6534theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_conformalSchlaefli
6535    (h : CanonicalPeriodicConformalSchlaefliAlongLineTargetAtN5) :
6536    CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget
6537      5 5 5 (by decide) (by decide) (by decide) :=
6538  canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_of_conformalSchlaefli
6539    5 5 5 (by decide) (by decide) (by decide) h
6540
6541/-- The two remaining load-bearing Track 1.B inputs at `(Nx,Ny,Nz)` before
6542`CanonicalPeriodicEdgeStencilLocalCorrespondence`. -/
6543def CanonicalPeriodicTrack1BClosureTarget
6544    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6545    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
6546  CanonicalPeriodicSecondSchlaefliAlongLineTarget Nx Ny Nz hx hy hz ∧
6547    CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz
6548
6549structure CanonicalPeriodicTrack1BOpenInputs
6550    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6551    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
6552  secondSchlaefli : CanonicalPeriodicSecondSchlaefliAlongLineTarget Nx Ny Nz hx hy hz
6553  lengthChain : CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz
6554
6555/-- Track 1.B open inputs with the Schläfli side in the typed periodic-edge
6556form used by lane `1B-SCH`. -/
6557structure CanonicalPeriodicTrack1BTypedEdgeOpenInputs
6558    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6559    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
6560  typedSecondSchlaefli : CanonicalPeriodicSecondSchlaefliTypedEdgeTarget Nx Ny Nz hx hy hz
6561  lengthChain : CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz
6562
6563def CanonicalPeriodicTrack1BOpenInputs.ofTypedEdge
6564    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
6565    {hx : 2 < Nx} {hy : 2 < Ny} {hz : 2 < Nz}
6566    (h : CanonicalPeriodicTrack1BTypedEdgeOpenInputs Nx Ny Nz hx hy hz) :
6567    CanonicalPeriodicTrack1BOpenInputs Nx Ny Nz hx hy hz where
6568  secondSchlaefli :=
6569    (canonicalPeriodicSecondSchlaefliAlongLineTarget_iff_typedEdge Nx Ny Nz hx hy hz).2
6570      h.typedSecondSchlaefli
6571  lengthChain := h.lengthChain
6572
6573structure CanonicalPeriodicTrack1BEventuallyZeroInputs
6574    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6575    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
6576  eventuallyZero : CanonicalPeriodicWeightedDeficitDerivativeEventuallyZeroTarget Nx Ny Nz hx hy hz
6577  lengthChain : CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz
6578
6579theorem canonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget_of_closedForm
6580    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6581    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6582    (hClosedForm :
6583      CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget
6584        Nx Ny Nz hx hy hz) :
6585    CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget
6586      Nx Ny Nz hx hy hz := by
6587  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6588  intro ξ edge
6589  have hsum :
6590      (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
6591          freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz ξ edge pair) =
6592        ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
6593          freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair := by
6594    refine Finset.sum_congr rfl ?_
6595    intro pair _
6596    exact freudenthalExplicitFiberPairClosedFormExpandedSummand_eq_flat hx hy hz ξ edge pair
6597  simpa [CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget,
6598    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget, hsum, P] using
6599    hClosedForm ξ edge
6600
6601theorem FreudenthalAxisDisp0ExplicitFiberClosedFormTarget_false :
6602    ¬ CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget
6603      AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
6604      AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
6605      AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz :=
6606  fun h =>
6607    AxisDisp0EndpointUnitWitness5.FreudenthalAxisDisp0ExplicitFiberFlatUnfoldedTarget_false
6608      (canonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget_of_closedForm
6609        AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
6610        AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
6611        AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz h)
6612
6613theorem canonicalPeriodicEdgeStencilLocalCorrespondence_not_of_explicitFiberClosedFormTarget_at_N5
6614    (hClosed :
6615      CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget
6616        AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
6617        AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
6618        AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz) :
6619    False :=
6620  FreudenthalAxisDisp0ExplicitFiberClosedFormTarget_false hClosed
6621
6622theorem canonicalPeriodicEdgeStencilLocalCorrespondence_not_of_explicitFiberFlatUnfoldedTarget_at_N5
6623    (hFlat :
6624      CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget
6625        AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
6626        AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
6627        AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz) :
6628    False :=
6629  AxisDisp0EndpointUnitWitness5.FreudenthalAxisDisp0ExplicitFiberFlatUnfoldedTarget_false hFlat
6630
6631theorem canonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget_of_flatUnfolded
6632    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6633    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6634    (hFlatUnfolded :
6635      CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget
6636        Nx Ny Nz hx hy hz) :
6637    CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget
6638      Nx Ny Nz hx hy hz := by
6639  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6640  intro ξ edge
6641  have hsum :
6642      (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
6643          freudenthalExplicitFiberPairFlatExpandedSummand hx hy hz ξ edge pair) =
6644        ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
6645          freudenthalExplicitFiberPairClosedFormExpandedSummand hx hy hz ξ edge pair := by
6646    refine Finset.sum_congr rfl ?_
6647    intro pair _
6648    exact (freudenthalExplicitFiberPairClosedFormExpandedSummand_eq_flat hx hy hz ξ edge pair).symm
6649  simpa [CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget,
6650    CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget, hsum, P] using
6651    hFlatUnfolded ξ edge
6652
6653theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairTarget_of_fiber
6654    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6655    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6656    (hFiber :
6657      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairFiberTarget
6658        Nx Ny Nz hx hy hz) :
6659    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairTarget
6660      Nx Ny Nz hx hy hz := by
6661  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6662  intro ξ edge
6663  have hsum :
6664      (∑ tet : Fin 6,
6665          ∑ f ∈ (Finset.univ.filter
6666            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6667              (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
6668              let cell :=
6669                periodicMatchingBaseCell
6670                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
6671                  edge.base
6672              ∑ k : Fin 6,
6673                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
6674                  (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
6675                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k) =
6676        ∑ pair ∈ ((Finset.univ : Finset FreudenthalLocalPair).filter
6677          (fun pair => freudenthalLocalPairDisp pair = edge.disp)),
6678              let cell :=
6679                periodicMatchingBaseCell
6680                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
6681                  edge.base
6682              ∑ k : Fin 6,
6683                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
6684                  (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
6685                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k := by
6686    unfold FreudenthalLocalPair freudenthalLocalPairDisp
6687    rw [← Finset.univ_product_univ]
6688    rw [Finset.sum_filter]
6689    rw [Finset.sum_product]
6690    simp [Finset.sum_filter, eq_comm]
6691  rw [hsum]
6692  exact hFiber ξ edge
6693
6694theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispCellTetTarget_of_localPair
6695    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6696    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6697    (hLocalPair :
6698      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairTarget
6699        Nx Ny Nz hx hy hz) :
6700    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispCellTetTarget
6701      Nx Ny Nz hx hy hz := by
6702  classical
6703  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6704  intro ξ edge
6705  have hcollapse :
6706      (∑ cell : Vertex Nx Ny Nz,
6707          ∑ tet : Fin 6,
6708            ∑ f ∈ (Finset.univ.filter
6709              (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6710                (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
6711              if edge.base = addVertexBits cell
6712                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f)) then
6713                ∑ k : Fin 6,
6714                  ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
6715                    (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
6716                    localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k
6717              else 0) =
6718        ∑ tet : Fin 6,
6719          ∑ f ∈ (Finset.univ.filter
6720            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6721              (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
6722              let cell :=
6723                periodicMatchingBaseCell
6724                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
6725                  edge.base
6726              ∑ k : Fin 6,
6727                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
6728                  (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
6729                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k := by
6730    rw [Finset.sum_comm]
6731    refine Finset.sum_congr rfl ?_
6732    intro tet _
6733    rw [Finset.sum_comm]
6734    refine Finset.sum_congr rfl ?_
6735    intro f _hf
6736    exact sum_ite_eq_of_addVertexBits_apply
6737      (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
6738      edge.base
6739      (fun cell : Vertex Nx Ny Nz =>
6740        ∑ k : Fin 6,
6741          ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
6742            (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
6743            localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k)
6744  rw [hcollapse]
6745  exact hLocalPair ξ edge
6746
6747theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispTypedTetTarget_of_cellTet
6748    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6749    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6750    (hCellTet :
6751      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispCellTetTarget
6752        Nx Ny Nz hx hy hz) :
6753    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispTypedTetTarget
6754      Nx Ny Nz hx hy hz := by
6755  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6756  intro ξ edge
6757  have hsplit :
6758      (∑ cellTet : PeriodicTet Nx Ny Nz,
6759          ∑ f ∈ (Finset.univ.filter
6760            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6761              (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
6762            if edge.base = addVertexBits cellTet.1
6763                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) then
6764              ∑ k : Fin 6,
6765                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
6766                  (P.tetEquiv.symm cellTet)).dihedralDeriv f k *
6767                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm cellTet) k
6768            else 0) =
6769        ∑ cell : Vertex Nx Ny Nz,
6770          ∑ tet : Fin 6,
6771            ∑ f ∈ (Finset.univ.filter
6772              (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6773                (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
6774              if edge.base = addVertexBits cell
6775                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f)) then
6776                ∑ k : Fin 6,
6777                  ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
6778                    (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
6779                    localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k
6780              else 0 := by
6781    unfold PeriodicTet
6782    rw [← Finset.univ_product_univ, Finset.sum_product]
6783  rw [hsplit]
6784  exact hCellTet ξ edge
6785
6786theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispFilteredTarget_of_typedTet
6787    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6788    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6789    (hTyped :
6790      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispTypedTetTarget
6791        Nx Ny Nz hx hy hz) :
6792    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispFilteredTarget
6793      Nx Ny Nz hx hy hz := by
6794  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6795  intro ξ edge
6796  let e := P.edgeEquiv.symm edge
6797  have hsum :
6798      (∑ cellTet : PeriodicTet Nx Ny Nz,
6799          ∑ f ∈ (Finset.univ.filter
6800            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6801              (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f))),
6802            if edge.base = addVertexBits cellTet.1
6803                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf cellTet.2 f)) then
6804              ∑ k : Fin 6,
6805                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
6806                  (P.tetEquiv.symm cellTet)).dihedralDeriv f k *
6807                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm cellTet) k
6808            else 0) =
6809        (∑ τ : Fin P.K.nT,
6810          ∑ f ∈ (Finset.univ.filter
6811            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6812              (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f))),
6813            if edge.base = addVertexBits (P.tetEquiv τ).1
6814                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f)) then
6815              ∑ k : Fin 6,
6816                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
6817                  localEdgeLengthDirectionalDeriv P.K ξ τ k
6818            else 0) := by
6819    simpa using
6820      (Equiv.sum_comp P.tetEquiv.symm
6821        (fun τ : Fin P.K.nT =>
6822          ∑ f ∈ (Finset.univ.filter
6823            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6824              (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f))),
6825            if edge.base = addVertexBits (P.tetEquiv τ).1
6826                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f)) then
6827              ∑ k : Fin 6,
6828                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
6829                  localEdgeLengthDirectionalDeriv P.K ξ τ k
6830            else 0))
6831  rw [← hsum]
6832  exact hTyped ξ edge
6833
6834theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainDispFilteredTarget_of_baseDisp
6835    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6836    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6837    (hBase :
6838      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispFilteredTarget
6839        Nx Ny Nz hx hy hz) :
6840    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainDispFilteredTarget
6841      Nx Ny Nz hx hy hz := by
6842  classical
6843  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6844  intro ξ edge
6845  let e := P.edgeEquiv.symm edge
6846  have hbase :
6847      ∀ τ : Fin P.K.nT,
6848        (∑ f ∈ (Finset.univ.filter
6849          (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6850            (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f))),
6851          if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
6852            ∑ k : Fin 6,
6853              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
6854                localEdgeLengthDirectionalDeriv P.K ξ τ k
6855          else 0) =
6856        ∑ f ∈ (Finset.univ.filter
6857          (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6858            (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f))),
6859          if edge.base = addVertexBits (P.tetEquiv τ).1
6860              (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f)) then
6861            ∑ k : Fin 6,
6862              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
6863                localEdgeLengthDirectionalDeriv P.K ξ τ k
6864          else 0 := by
6865    intro τ
6866    refine Finset.sum_congr rfl ?_
6867    intro f hf
6868    have hDisp :
6869        edge.disp = cubeEdgeDisp
6870          (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f) :=
6871      (Finset.mem_filter.mp hf).2
6872    have hiff : (edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f) ↔
6873        edge.base = addVertexBits (P.tetEquiv τ).1
6874          (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f)) := by
6875      constructor
6876      · intro hEdge
6877        exact canonicalPeriodicTypedEdge_base_eq_of_localEdgeOf hEdge
6878      · intro hBaseEq
6879        exact (canonicalPeriodicTypedEdge_eq_localEdgeOf_iff_base_and_disp edge
6880          (P.tetEquiv τ) f).2 ⟨hBaseEq, hDisp⟩
6881    by_cases hBaseEq :
6882        edge.base = addVertexBits (P.tetEquiv τ).1
6883          (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f))
6884    · have hEq : edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f := hiff.2 hBaseEq
6885      have hLocalBase :
6886          (localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f).base =
6887            addVertexBits (P.tetEquiv τ).1
6888              (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f)) := by
6889        simp [localEdgeOf]
6890      simp [hEq, hLocalBase]
6891    · have hEq : edge ≠ localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f := by
6892        intro hEdge
6893        exact hBaseEq (hiff.1 hEdge)
6894      simp [hEq, hBaseEq]
6895  simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainDispFilteredTarget,
6896    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispFilteredTarget,
6897    hbase, P, e] using hBase ξ edge
6898
6899theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedSlotTarget_of_dispFiltered
6900    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6901    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6902    (hDisp :
6903      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainDispFilteredTarget
6904        Nx Ny Nz hx hy hz) :
6905    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedSlotTarget
6906      Nx Ny Nz hx hy hz := by
6907  classical
6908  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6909  intro ξ edge
6910  let e := P.edgeEquiv.symm edge
6911  have hfilter :
6912      ∀ τ : Fin P.K.nT,
6913        (∑ f : Fin 6,
6914          if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
6915            ∑ k : Fin 6,
6916              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
6917                localEdgeLengthDirectionalDeriv P.K ξ τ k
6918          else 0) =
6919        ∑ f ∈ (Finset.univ.filter
6920          (fun f : Fin 6 => edge.disp = cubeEdgeDisp
6921            (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f))),
6922          if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
6923            ∑ k : Fin 6,
6924              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
6925                localEdgeLengthDirectionalDeriv P.K ξ τ k
6926          else 0 := by
6927    intro τ
6928    rw [Finset.sum_filter]
6929    refine Finset.sum_congr rfl ?_
6930    intro f _hf
6931    by_cases hMatch :
6932        edge.disp = cubeEdgeDisp
6933          (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv τ).2 f)
6934    · simp [hMatch]
6935    · have hne : edge ≠ localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f := by
6936        intro hEdge
6937        exact hMatch (canonicalPeriodicTypedEdge_disp_eq_of_localEdgeOf hEdge)
6938      simp [hMatch, hne]
6939  simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedSlotTarget,
6940    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainDispFilteredTarget,
6941    hfilter, P, e] using hDisp ξ edge
6942
6943theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget_of_typedSlot
6944    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
6945    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
6946    (hSlot :
6947      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedSlotTarget
6948        Nx Ny Nz hx hy hz) :
6949    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget
6950      Nx Ny Nz hx hy hz := by
6951  classical
6952  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
6953  intro ξ edge
6954  let e : Fin P.K.nE := P.edgeEquiv.symm edge
6955  have heq : P.edgeEquiv e = edge := by
6956    simp [e]
6957  have hslot_sum :
6958      ∀ τ : Fin P.K.nT,
6959        (match P.K.edgeInTet e τ with
6960          | none => 0
6961          | some f =>
6962              ∑ k : Fin 6,
6963                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
6964                  localEdgeLengthDirectionalDeriv P.K ξ τ k) =
6965        ∑ f : Fin 6,
6966          if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
6967            ∑ k : Fin 6,
6968              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
6969                localEdgeLengthDirectionalDeriv P.K ξ τ k
6970          else 0 := by
6971    intro τ
6972    cases hInc : P.K.edgeInTet e τ with
6973    | none =>
6974        change (0 : ℝ) =
6975          ∑ f : Fin 6,
6976            if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
6977              ∑ k : Fin 6,
6978                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
6979                  localEdgeLengthDirectionalDeriv P.K ξ τ k
6980            else 0
6981        symm
6982        apply Finset.sum_eq_zero
6983        intro f _hf
6984        have hne : edge ≠ localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f := by
6985          intro hEdge
6986          have hSome : P.K.edgeInTet e τ = some f := by
6987            exact (P.edgeInTet_iff e τ f).2 (by simpa [heq] using hEdge)
6988          rw [hInc] at hSome
6989          contradiction
6990        simp [hne]
6991    | some f0 =>
6992        rw [Finset.sum_eq_single f0]
6993        · have hEdge : edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f0 := by
6994            have h := (P.edgeInTet_iff e τ f0).1 hInc
6995            simpa [heq] using h
6996          simp [hEdge]
6997        · intro f _hf hf_ne
6998          have hne : edge ≠ localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f := by
6999            intro hEdge
7000            have hSome : P.K.edgeInTet e τ = some f := by
7001              exact (P.edgeInTet_iff e τ f).2 (by simpa [heq] using hEdge)
7002            rw [hInc] at hSome
7003            exact hf_ne (Option.some.inj hSome.symm)
7004          simp [hne]
7005        · intro hnot
7006          exact (hnot (Finset.mem_univ f0)).elim
7007  simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget,
7008    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedSlotTarget,
7009    hslot_sum, P, e] using hSlot ξ edge
7010
7011theorem canonicalPeriodicTypedEdge_perTet_edgeInTetExpanded_eq_slotGuarded
7012    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
7013    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7014    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
7015    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz)
7016    (τ : Fin (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K.nT) :
7017    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7018    let e := P.edgeEquiv.symm edge
7019    (match P.K.edgeInTet e τ with
7020      | none => 0
7021      | some f =>
7022          ∑ k : Fin 6,
7023            ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7024              localEdgeLengthDirectionalDeriv P.K ξ τ k) =
7025      ∑ f : Fin 6,
7026        if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7027          ∑ k : Fin 6,
7028            ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7029              localEdgeLengthDirectionalDeriv P.K ξ τ k
7030        else 0 := by
7031  classical
7032  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7033  let e := P.edgeEquiv.symm edge
7034  have heq : P.edgeEquiv e = edge := by simp [e]
7035  show
7036      (match P.K.edgeInTet e τ with
7037        | none => 0
7038        | some f =>
7039            ∑ k : Fin 6,
7040              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7041                localEdgeLengthDirectionalDeriv P.K ξ τ k) =
7042        ∑ f : Fin 6,
7043          if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7044            ∑ k : Fin 6,
7045              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7046                localEdgeLengthDirectionalDeriv P.K ξ τ k
7047          else 0
7048  cases hInc : P.K.edgeInTet e τ with
7049  | none =>
7050      change (0 : ℝ) =
7051        ∑ f : Fin 6,
7052          if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7053            ∑ k : Fin 6,
7054              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7055                localEdgeLengthDirectionalDeriv P.K ξ τ k
7056          else 0
7057      symm
7058      apply Finset.sum_eq_zero
7059      intro f _hf
7060      have hne : edge ≠ localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f := by
7061        intro hEdge
7062        have hSome : P.K.edgeInTet e τ = some f := by
7063          exact (P.edgeInTet_iff e τ f).2 (by simpa [heq] using hEdge)
7064        rw [hInc] at hSome
7065        contradiction
7066      simp [hne]
7067  | some f0 =>
7068      rw [Finset.sum_eq_single f0]
7069      · have hEdge : edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f0 := by
7070          have h := (P.edgeInTet_iff e τ f0).1 hInc
7071          simpa [heq] using h
7072        simp [hEdge]
7073      · intro f _hf hf_ne
7074        have hne : edge ≠ localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f := by
7075          intro hEdge
7076          have hSome : P.K.edgeInTet e τ = some f := by
7077            exact (P.edgeInTet_iff e τ f).2 (by simpa [heq] using hEdge)
7078          rw [hInc] at hSome
7079          exact hf_ne (Option.some.inj hSome.symm)
7080        simp [hne]
7081      · intro hnot
7082        exact (hnot (Finset.mem_univ f0)).elim
7083
7084theorem canonicalPeriodicTypedEdge_edgeInTetExpandedInnerSum_eq_slotGuardedInnerSum
7085    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
7086    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7087    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
7088    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
7089    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7090    let e := P.edgeEquiv.symm edge
7091    (∑ τ : Fin P.K.nT,
7092        match P.K.edgeInTet e τ with
7093        | none => 0
7094        | some f =>
7095            ∑ k : Fin 6,
7096              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7097                localEdgeLengthDirectionalDeriv P.K ξ τ k) =
7098      ∑ τ : Fin P.K.nT,
7099        ∑ f : Fin 6,
7100          if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7101            ∑ k : Fin 6,
7102              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7103                localEdgeLengthDirectionalDeriv P.K ξ τ k
7104          else 0 := by
7105  classical
7106  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7107  let e := P.edgeEquiv.symm edge
7108  refine Finset.sum_congr rfl ?_
7109  intro τ _
7110  exact canonicalPeriodicTypedEdge_perTet_edgeInTetExpanded_eq_slotGuarded hx hy hz ξ edge τ
7111
7112theorem freudenthalExplicitFiberDispTableExpandedSum_eq_localPairExpandedInnerSum
7113    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
7114    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7115    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
7116    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
7117    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7118    (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7119        freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
7120      ∑ tet : Fin 6,
7121        ∑ f ∈ (Finset.univ.filter
7122          (fun f : Fin 6 => edge.disp = cubeEdgeDisp
7123            (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
7124          let cell :=
7125            periodicMatchingBaseCell
7126              (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
7127              edge.base
7128          ∑ k : Fin 6,
7129            ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7130                (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
7131              localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k := by
7132  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7133  have hsum :
7134      (∑ tet : Fin 6,
7135          ∑ f ∈ (Finset.univ.filter
7136            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
7137              (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
7138              let cell :=
7139                periodicMatchingBaseCell
7140                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
7141                  edge.base
7142              ∑ k : Fin 6,
7143                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7144                  (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
7145                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k) =
7146        ∑ pair ∈ ((Finset.univ : Finset FreudenthalLocalPair).filter
7147          (fun pair => freudenthalLocalPairDisp pair = edge.disp)),
7148              let cell :=
7149                periodicMatchingBaseCell
7150                  (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
7151                  edge.base
7152              ∑ k : Fin 6,
7153                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7154                  (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
7155                  localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k := by
7156    unfold FreudenthalLocalPair freudenthalLocalPairDisp
7157    rw [← Finset.univ_product_univ]
7158    rw [Finset.sum_filter]
7159    rw [Finset.sum_product]
7160    simp [Finset.sum_filter, eq_comm]
7161  calc
7162    (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7163        freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
7164        ∑ pair ∈ ((Finset.univ : Finset FreudenthalLocalPair).filter
7165          (fun pair => freudenthalLocalPairDisp pair = edge.disp)),
7166          let cell :=
7167            periodicMatchingBaseCell
7168              (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
7169              edge.base
7170          ∑ k : Fin 6,
7171            ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7172                (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
7173              localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k :=
7174      by
7175        rw [freudenthalLocalPairDispFiber_eq_filter edge.disp]
7176        refine Finset.sum_congr rfl ?_
7177        intro pair _
7178        dsimp [freudenthalExplicitFiberPairExpandedSummand, freudenthalExplicitFiberPairSelectedCell]
7179    _ =
7180        ∑ tet : Fin 6,
7181          ∑ f ∈ (Finset.univ.filter
7182            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
7183              (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
7184            let cell :=
7185              periodicMatchingBaseCell
7186                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
7187                edge.base
7188            ∑ k : Fin 6,
7189              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7190                  (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
7191                localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k :=
7192      hsum.symm
7193
7194theorem canonicalPeriodicTypedEdge_localPairExpandedInnerSum_eq_slotGuardedInnerSum
7195    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
7196    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7197    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
7198    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
7199    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7200    (∑ tet : Fin 6,
7201        ∑ f ∈ (Finset.univ.filter
7202          (fun f : Fin 6 => edge.disp = cubeEdgeDisp
7203            (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
7204          let cell :=
7205            periodicMatchingBaseCell
7206              (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
7207              edge.base
7208          ∑ k : Fin 6,
7209            ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7210                (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
7211              localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k) =
7212      ∑ τ : Fin P.K.nT,
7213        ∑ f : Fin 6,
7214          if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7215            ∑ k : Fin 6,
7216              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7217                localEdgeLengthDirectionalDeriv P.K ξ τ k
7218          else 0 := by
7219  classical
7220  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7221  let pairInnerSum (pair : Fin 6 × Fin 6) : ℝ :=
7222    let cell := freudenthalExplicitFiberPairSelectedCell edge pair
7223    ∑ k : Fin 6,
7224      ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7225          (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
7226        localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k
7227  let slotInnerSum (p : Fin P.K.nT × Fin 6) : ℝ :=
7228    ∑ k : Fin 6,
7229      ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData p.1).dihedralDeriv p.2 k *
7230        localEdgeLengthDirectionalDeriv P.K ξ p.1 k
7231  let sPair :=
7232    (Finset.univ : Finset (Fin 6 × Fin 6)).filter
7233      (fun pair => edge.disp = cubeEdgeDisp
7234        (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
7235  let sSlot :=
7236    (Finset.univ : Finset (Fin P.K.nT × Fin 6)).filter
7237      (fun p => edge = localEdgeOf (P.tetEquiv p.1).1 (P.tetEquiv p.1).2 p.2)
7238  have hsum_pair :
7239      (∑ tet : Fin 6,
7240          ∑ f ∈ (Finset.univ.filter
7241            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
7242              (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
7243            let cell :=
7244              periodicMatchingBaseCell
7245                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
7246                edge.base
7247            ∑ k : Fin 6,
7248              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7249                  (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
7250                localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k) =
7251        ∑ pair ∈ ((Finset.univ : Finset FreudenthalLocalPair).filter
7252          (fun pair => freudenthalLocalPairDisp pair = edge.disp)),
7253          pairInnerSum pair := by
7254    unfold FreudenthalLocalPair freudenthalLocalPairDisp
7255    rw [← Finset.univ_product_univ]
7256    rw [Finset.sum_filter]
7257    rw [Finset.sum_product]
7258    simp [Finset.sum_filter, eq_comm, pairInnerSum, freudenthalExplicitFiberPairSelectedCell]
7259  have hsPair_eq :
7260      sPair =
7261        (Finset.univ.filter
7262          (fun pair : Fin 6 × Fin 6 => freudenthalLocalPairDisp pair = edge.disp)) := by
7263    ext pair
7264    simp [sPair, freudenthalLocalPairDisp, eq_comm]
7265  have hlocal :
7266      (∑ tet : Fin 6,
7267          ∑ f ∈ (Finset.univ.filter
7268            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
7269              (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
7270            let cell :=
7271              periodicMatchingBaseCell
7272                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
7273                edge.base
7274            ∑ k : Fin 6,
7275              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7276                  (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
7277                localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k) =
7278        sPair.sum pairInnerSum := by
7279    rw [hsPair_eq, hsum_pair]
7280  have hsum_slot :
7281      (∑ τ : Fin P.K.nT,
7282          ∑ f : Fin 6,
7283            if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7284              ∑ k : Fin 6,
7285                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7286                  localEdgeLengthDirectionalDeriv P.K ξ τ k
7287            else 0) =
7288        ∑ p ∈ sSlot, slotInnerSum p := by
7289    symm
7290    dsimp [sSlot]
7291    rw [Finset.sum_filter]
7292    rw [← Finset.univ_product_univ]
7293    rw [Finset.sum_product]
7294  have hslot :
7295      (∑ τ : Fin P.K.nT,
7296          ∑ f : Fin 6,
7297            if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7298              ∑ k : Fin 6,
7299                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7300                  localEdgeLengthDirectionalDeriv P.K ξ τ k
7301            else 0) =
7302        sSlot.sum slotInnerSum := hsum_slot
7303  have hbij : sPair.sum pairInnerSum = sSlot.sum slotInnerSum := by
7304    apply Finset.sum_bij'
7305      (fun pair _ =>
7306        (P.tetEquiv.symm
7307          (freudenthalExplicitFiberPairSelectedCell edge pair, pair.1), pair.2))
7308      (fun p _ => ((P.tetEquiv p.1).2, p.2))
7309    · intro pair hp
7310      simp only [sSlot, Finset.mem_filter, Finset.mem_univ, true_and]
7311      simp only [sPair, Finset.mem_filter, Finset.mem_univ, true_and] at hp
7312      have hEdge :=
7313        canonicalPeriodicTypedEdge_eq_localEdgeOf_of_base_and_disp edge
7314          (freudenthalExplicitFiberPairSelectedCell edge pair) pair.1 pair.2
7315          (freudenthalExplicitFiberPairSelectedCell_base_eq edge pair) hp
7316      rw [P.tetEquiv.apply_symm_apply (freudenthalExplicitFiberPairSelectedCell edge pair, pair.1)]
7317      exact hEdge
7318    · intro p hp
7319      simp only [sSlot, Finset.mem_filter, Finset.mem_univ, true_and] at hp
7320      simp only [sPair, Finset.mem_filter, Finset.mem_univ, true_and]
7321      exact
7322        canonicalPeriodicTypedEdge_disp_eq_of_localEdgeOf (Nx := Nx) (Ny := Ny) (Nz := Nz)
7323          (edge := edge) (cellTet := P.tetEquiv p.1) (f := p.2) hp
7324    · intro pair _hp
7325      apply Prod.ext
7326      · exact congrArg Prod.snd
7327          (P.tetEquiv.apply_symm_apply (freudenthalExplicitFiberPairSelectedCell edge pair, pair.1))
7328      · rfl
7329    · intro p hp
7330      apply Prod.ext
7331      · simp only [sSlot, Finset.mem_filter, Finset.mem_univ, true_and] at hp
7332        have hbase := canonicalPeriodicTypedEdge_base_eq_of_localEdgeOf hp
7333        have hcell :
7334            (P.tetEquiv p.1).1 =
7335              freudenthalExplicitFiberPairSelectedCell edge ((P.tetEquiv p.1).2, p.2) :=
7336          periodicMatchingBaseCell_eq_of_addVertexBits
7337            (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf (P.tetEquiv p.1).2 p.2))
7338            edge.base (P.tetEquiv p.1).1 hbase
7339        have harg :
7340            (freudenthalExplicitFiberPairSelectedCell edge ((P.tetEquiv p.1).2, p.2),
7341                (P.tetEquiv p.1).2) =
7342              P.tetEquiv p.1 := by
7343          apply Prod.ext
7344          · exact hcell.symm
7345          · rfl
7346        rw [harg]
7347        exact P.tetEquiv.symm_apply_apply p.1
7348      · rfl
7349    · intro pair _hp
7350      simp [freudenthalExplicitFiberPairSelectedCell]
7351  calc
7352    (∑ tet : Fin 6,
7353        ∑ f ∈ (Finset.univ.filter
7354          (fun f : Fin 6 => edge.disp = cubeEdgeDisp
7355            (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
7356          let cell :=
7357            periodicMatchingBaseCell
7358              (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
7359              edge.base
7360          ∑ k : Fin 6,
7361            ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7362                (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
7363              localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k) =
7364        sPair.sum pairInnerSum := hlocal
7365    _ = sSlot.sum slotInnerSum := hbij
7366    _ =
7367        ∑ τ : Fin P.K.nT,
7368          ∑ f : Fin 6,
7369            if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7370              ∑ k : Fin 6,
7371                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7372                  localEdgeLengthDirectionalDeriv P.K ξ τ k
7373            else 0 := hslot.symm
7374
7375theorem freudenthalExplicitFiberDispTableExpandedSum_eq_typedEdgeInTetExpandedIncidentSum
7376    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
7377    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7378    (ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
7379    (edge : Geometry.PeriodicFreudenthalTorus.PeriodicEdge Nx Ny Nz) :
7380    let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7381    let e := P.edgeEquiv.symm edge
7382    (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7383        freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
7384      ∑ τ : Fin P.K.nT,
7385        match P.K.edgeInTet e τ with
7386        | none => 0
7387        | some f =>
7388            ∑ k : Fin 6,
7389              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7390                localEdgeLengthDirectionalDeriv P.K ξ τ k := by
7391  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7392  let e := P.edgeEquiv.symm edge
7393  calc
7394    (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7395        freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
7396        ∑ tet : Fin 6,
7397          ∑ f ∈ (Finset.univ.filter
7398            (fun f : Fin 6 => edge.disp = cubeEdgeDisp
7399              (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))),
7400            let cell :=
7401              periodicMatchingBaseCell
7402                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf tet f))
7403                edge.base
7404            ∑ k : Fin 6,
7405              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7406                  (P.tetEquiv.symm (cell, tet))).dihedralDeriv f k *
7407                localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, tet)) k :=
7408      freudenthalExplicitFiberDispTableExpandedSum_eq_localPairExpandedInnerSum hx hy hz ξ edge
7409    _ =
7410        ∑ τ : Fin P.K.nT,
7411          ∑ f : Fin 6,
7412            if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7413              ∑ k : Fin 6,
7414                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7415                  localEdgeLengthDirectionalDeriv P.K ξ τ k
7416            else 0 :=
7417      canonicalPeriodicTypedEdge_localPairExpandedInnerSum_eq_slotGuardedInnerSum hx hy hz ξ edge
7418    _ =
7419        ∑ τ : Fin P.K.nT,
7420          match P.K.edgeInTet e τ with
7421          | none => 0
7422          | some f =>
7423              ∑ k : Fin 6,
7424                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7425                  localEdgeLengthDirectionalDeriv P.K ξ τ k := by
7426      refine Finset.sum_congr rfl ?_
7427      intro τ _
7428      show
7429          (∑ f : Fin 6,
7430              if edge = localEdgeOf (P.tetEquiv τ).1 (P.tetEquiv τ).2 f then
7431                ∑ k : Fin 6,
7432                  ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7433                    localEdgeLengthDirectionalDeriv P.K ξ τ k
7434              else 0) =
7435            match P.K.edgeInTet e τ with
7436            | none => 0
7437            | some f =>
7438                ∑ k : Fin 6,
7439                  ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7440                    localEdgeLengthDirectionalDeriv P.K ξ τ k
7441      exact (canonicalPeriodicTypedEdge_perTet_edgeInTetExpanded_eq_slotGuarded hx hy hz ξ edge τ).symm
7442
7443theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget_of_explicitFiber
7444    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7445    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7446    (hExplicit :
7447      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
7448        Nx Ny Nz hx hy hz) :
7449    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget
7450      Nx Ny Nz hx hy hz := by
7451  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7452  intro ξ edge
7453  let e := P.edgeEquiv.symm edge
7454  have hinner :
7455      (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7456          let cell :=
7457            periodicMatchingBaseCell
7458              (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
7459              edge.base
7460          ∑ k : Fin 6,
7461            ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7462                (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
7463              localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k) =
7464        ∑ τ : Fin P.K.nT,
7465          match P.K.edgeInTet e τ with
7466          | none => 0
7467          | some f =>
7468              ∑ k : Fin 6,
7469                ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7470                  localEdgeLengthDirectionalDeriv P.K ξ τ k := by
7471    have htable :
7472        (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7473            freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
7474          ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7475            let cell :=
7476              periodicMatchingBaseCell
7477                (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
7478                edge.base
7479            ∑ k : Fin 6,
7480              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7481                  (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
7482                localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k := by
7483      refine Finset.sum_congr rfl ?_
7484      intro pair _
7485      dsimp [freudenthalExplicitFiberPairExpandedSummand, freudenthalExplicitFiberPairSelectedCell]
7486    rw [← htable]
7487    exact freudenthalExplicitFiberDispTableExpandedSum_eq_typedEdgeInTetExpandedIncidentSum hx hy hz ξ edge
7488  simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget,
7489    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget, hinner, P, e] using
7490    hExplicit ξ edge
7491
7492theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget_of_typedEndpoint
7493    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7494    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7495    (hTyped :
7496      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget
7497        Nx Ny Nz hx hy hz) :
7498    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
7499      Nx Ny Nz hx hy hz := by
7500  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7501  intro ξ edge
7502  let e := P.edgeEquiv.symm edge
7503  have hinner :=
7504    freudenthalExplicitFiberDispTableExpandedSum_eq_typedEdgeInTetExpandedIncidentSum hx hy hz ξ edge
7505  have htable :
7506      (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7507          freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
7508        ∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7509          let cell :=
7510            periodicMatchingBaseCell
7511              (cubeEdgeBase (Geometry.FreudenthalCubeTriangulation.localEdgeOf pair.1 pair.2))
7512              edge.base
7513          ∑ k : Fin 6,
7514            ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData
7515                (P.tetEquiv.symm (cell, pair.1))).dihedralDeriv pair.2 k *
7516              localEdgeLengthDirectionalDeriv P.K ξ (P.tetEquiv.symm (cell, pair.1)) k := by
7517    refine Finset.sum_congr rfl ?_
7518    intro pair _
7519    dsimp [freudenthalExplicitFiberPairExpandedSummand, freudenthalExplicitFiberPairSelectedCell]
7520  have hfiberInner := htable.trans hinner
7521  have hnegInner := congr_arg Neg.neg hfiberInner
7522  have htyped' :
7523      hingeMeasureDirectionalDeriv P.K P.hK ξ e *
7524          (-∑ τ : Fin P.K.nT,
7525            match P.K.edgeInTet e τ with
7526            | none => 0
7527            | some f =>
7528                ∑ k : Fin 6,
7529                  ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7530                    localEdgeLengthDirectionalDeriv P.K ξ τ k) =
7531        Real.sqrt (periodicDispSqEdge edge.disp) *
7532          (ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.1) -
7533            ξ ((vertexFinEquiv Nx Ny Nz).symm edge.endpoints.2)) ^ (2 : ℕ) := by
7534    simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget, P, e] using
7535      hTyped ξ edge
7536  rw [← hnegInner] at htyped'
7537  simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget, P, e] using htyped'
7538
7539theorem FreudenthalAxisDisp0ExpandedLengthChainTypedEndpointTarget_false :
7540    ¬ CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget
7541      AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
7542      AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
7543      AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz := by
7544  intro hTyped
7545  exact FreudenthalAxisDisp0ExplicitFiberExpandedLengthChainExplicitFiberTarget_false
7546    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget_of_typedEndpoint
7547      AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
7548      AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
7549      AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz hTyped)
7550
7551theorem canonicalPeriodicEdgeStencilLocalCorrespondence_not_of_typedEndpoint_at_N5
7552    (hTyped :
7553      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget
7554        AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
7555        AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
7556        AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz) :
7557    False :=
7558  FreudenthalAxisDisp0ExpandedLengthChainTypedEndpointTarget_false hTyped
7559
7560/-- Generic finite reindexing target for the Track 1.B flat Freudenthal lane:
7561the explicit displacement-fiber table sum is the encoded `edgeInTet` incident
7562sum for every typed periodic edge. -/
7563def CanonicalPeriodicTrack1BFiniteReindexingTarget
7564    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7565    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) : Prop :=
7566  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7567  ∀ (ξ : VertexPotential P.K) (edge : PeriodicEdge Nx Ny Nz),
7568    let e := P.edgeEquiv.symm edge
7569    (∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7570        freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) =
7571      ∑ τ : Fin P.K.nT,
7572        match P.K.edgeInTet e τ with
7573        | none => 0
7574        | some f =>
7575            ∑ k : Fin 6,
7576              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7577                localEdgeLengthDirectionalDeriv P.K ξ τ k
7578
7579theorem canonicalPeriodicTrack1BFiniteReindexingTarget_holds
7580    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7581    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
7582    CanonicalPeriodicTrack1BFiniteReindexingTarget Nx Ny Nz hx hy hz := by
7583  intro ξ edge
7584  exact freudenthalExplicitFiberDispTableExpandedSum_eq_typedEdgeInTetExpandedIncidentSum
7585    hx hy hz ξ edge
7586
7587/-- The corrected mixed axis-stencil target follows from the global
7588explicit-fiber axis-stencil identity.  This is the safe replacement for the
7589false typed-endpoint route: it keeps the typed-edge sum global, then uses the
7590proved finite reindexing theorem to return to the canonical `edgeInTet` form. -/
7591theorem canonicalPeriodicMixedHingeDeficitAxisStencilTarget_of_explicitFiberAxis
7592    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7593    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7594    (hExplicit :
7595      CanonicalPeriodicMixedHingeDeficitExplicitFiberAxisStencilTarget
7596        Nx Ny Nz hx hy hz) :
7597    CanonicalPeriodicMixedHingeDeficitAxisStencilTarget Nx Ny Nz hx hy hz := by
7598  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7599  intro ξ
7600  let F : Fin P.K.nE → ℝ := fun e =>
7601    hingeMeasureDirectionalDeriv P.K P.hK ξ e *
7602      (-∑ τ : Fin P.K.nT,
7603        match P.K.edgeInTet e τ with
7604        | none => 0
7605        | some f =>
7606            ∑ k : Fin 6,
7607              ((triangulationSchlaefliData_of_incidence P.K P.hK).tetData τ).dihedralDeriv f k *
7608                localEdgeLengthDirectionalDeriv P.K ξ τ k)
7609  have hreindex :
7610      (∑ edge : PeriodicEdge Nx Ny Nz, F (P.edgeEquiv.symm edge)) =
7611        ∑ e : Fin P.K.nE, F e := by
7612    simpa [F] using (Equiv.sum_comp P.edgeEquiv.symm F)
7613  change (∑ e : Fin P.K.nE, F e) =
7614    canonicalPeriodicMixedAxisStencilAction Nx Ny Nz hx hy hz ξ
7615  rw [← hreindex]
7616  have hsum :
7617      (∑ edge : PeriodicEdge Nx Ny Nz, F (P.edgeEquiv.symm edge)) =
7618        ∑ edge : PeriodicEdge Nx Ny Nz,
7619          let e := P.edgeEquiv.symm edge
7620          hingeMeasureDirectionalDeriv P.K P.hK ξ e *
7621            (-∑ pair ∈ freudenthalLocalPairDispFiber edge.disp,
7622              freudenthalExplicitFiberPairExpandedSummand hx hy hz ξ edge pair) := by
7623    refine Finset.sum_congr rfl ?_
7624    intro edge _
7625    have hinner :=
7626      freudenthalExplicitFiberDispTableExpandedSum_eq_typedEdgeInTetExpandedIncidentSum
7627        hx hy hz ξ edge
7628    dsimp [F]
7629    rw [← hinner]
7630  rw [hsum]
7631  simpa [CanonicalPeriodicMixedHingeDeficitExplicitFiberAxisStencilTarget, P] using hExplicit ξ
7632
7633/-- N=5 finite-lane obstruction target: the typed-endpoint mixed target is
7634false on the certified axis disp-0 endpoint-unit witness. -/
7635def CanonicalPeriodicTrack1BFiniteN5TypedEndpointObstructionTarget : Prop :=
7636  ¬ CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget
7637      AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
7638      AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
7639      AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz
7640
7641theorem canonicalPeriodicTrack1BFiniteN5TypedEndpointObstructionTarget_holds :
7642    CanonicalPeriodicTrack1BFiniteN5TypedEndpointObstructionTarget :=
7643  FreudenthalAxisDisp0ExpandedLengthChainTypedEndpointTarget_false
7644
7645/-- Track 1.B finite-lane closure certificate.  This does not close Track 1.B:
7646it records that the flat finite Freudenthal reindexing and N=5 typed-endpoint
7647obstruction have closed, leaving stationarity to the `1B-SCH` lane. -/
7648structure CanonicalPeriodicTrack1BFiniteLaneCert : Prop where
7649  reindexing :
7650    CanonicalPeriodicTrack1BFiniteReindexingTarget
7651      AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
7652      AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
7653      AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz
7654  typedEndpointObstruction :
7655    CanonicalPeriodicTrack1BFiniteN5TypedEndpointObstructionTarget
7656
7657theorem canonicalPeriodicTrack1BFiniteLaneCert :
7658    CanonicalPeriodicTrack1BFiniteLaneCert :=
7659  ⟨canonicalPeriodicTrack1BFiniteReindexingTarget_holds
7660      AxisDisp0EndpointUnitWitness5.WitnessNx AxisDisp0EndpointUnitWitness5.WitnessNy
7661      AxisDisp0EndpointUnitWitness5.WitnessNz AxisDisp0EndpointUnitWitness5.witnessHx
7662      AxisDisp0EndpointUnitWitness5.witnessHy AxisDisp0EndpointUnitWitness5.witnessHz,
7663    canonicalPeriodicTrack1BFiniteN5TypedEndpointObstructionTarget_holds⟩
7664
7665theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEdgeTarget_of_typedEndpoint
7666    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7667    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7668    (hEndpoint :
7669      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget
7670        Nx Ny Nz hx hy hz) :
7671    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEdgeTarget
7672      Nx Ny Nz hx hy hz := by
7673  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7674  intro ξ edge
7675  have hSq :
7676      (canonicalPeriodicIncidenceConsistent_of_endpoint Nx Ny Nz
7677          (canonicalPeriodicEndpointIncidence Nx Ny Nz)).globalSqEdge
7678        ((edgeFinEquiv Nx Ny Nz).symm edge) =
7679        periodicDispSqEdge edge.disp := by
7680    change
7681      periodicDispSqEdge
7682          ((edgeFinEquiv Nx Ny Nz) ((edgeFinEquiv Nx Ny Nz).symm edge)).disp =
7683        periodicDispSqEdge edge.disp
7684    rw [(edgeFinEquiv Nx Ny Nz).apply_symm_apply edge]
7685  simpa [CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEdgeTarget,
7686    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget,
7687    canonicalEncodedPeriodicFreudenthalTorus,
7688      canonicalEncodedPeriodicFreudenthalTorus_of_endpoint,
7689      canonicalEncodedPeriodicFreudenthalTorus_of_incidence,
7690    canonicalPeriodicEdgeEquiv, canonicalPeriodicTriangulation, canonicalGlobalSqEdge,
7691    canonicalEdgeVerts, hSq, P] using hEndpoint ξ edge
7692
7693theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainPerEdgeTarget_of_typed
7694    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7695    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7696    (hTyped :
7697      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEdgeTarget
7698        Nx Ny Nz hx hy hz) :
7699    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainPerEdgeTarget
7700      Nx Ny Nz hx hy hz := by
7701  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7702  intro ξ e
7703  simpa [P] using hTyped ξ (P.edgeEquiv e)
7704
7705theorem canonicalPeriodicMixedHingeDeficitExpandedLengthChainTarget_of_perEdge
7706    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7707    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7708    (hEdge :
7709      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainPerEdgeTarget
7710        Nx Ny Nz hx hy hz) :
7711    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTarget Nx Ny Nz hx hy hz := by
7712  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7713  intro ξ
7714  simpa [canonicalEdgeStencilDirichletEnergy, P] using
7715    Finset.sum_congr rfl (fun e _ => hEdge ξ e)
7716
7717theorem canonicalPeriodicMixedHingeDeficitLengthChainTarget_of_expanded
7718    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7719    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7720    (hExpanded :
7721      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTarget Nx Ny Nz hx hy hz) :
7722    CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz := by
7723  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7724  intro ξ
7725  simpa [CanonicalPeriodicMixedHingeDeficitLengthChainTarget,
7726    CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTarget,
7727    localAngleLengthChainDeriv, P] using hExpanded ξ
7728
7729theorem canonicalPeriodicMixedHingeDeficitLocalAngleTarget_of_lengthChainTarget
7730    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7731    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7732    (hLength :
7733      CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz) :
7734    CanonicalPeriodicMixedHingeDeficitLocalAngleTarget Nx Ny Nz hx hy hz := by
7735  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7736  intro ξ
7737  simpa [CanonicalPeriodicMixedHingeDeficitLocalAngleTarget,
7738    CanonicalPeriodicMixedHingeDeficitLengthChainTarget,
7739    deficitDirectionalDerivFromLocalAngles,
7740    canonicalPeriodicLocalDihedralDerivativePackage, P] using hLength ξ
7741
7742theorem canonicalPeriodicMixedHingeDeficitLengthChainTarget_of_localAngleTarget
7743    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7744    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7745    (hLocal :
7746      CanonicalPeriodicMixedHingeDeficitLocalAngleTarget Nx Ny Nz hx hy hz) :
7747    CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz := by
7748  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7749  intro ξ
7750  simpa [CanonicalPeriodicMixedHingeDeficitLengthChainTarget,
7751    CanonicalPeriodicMixedHingeDeficitLocalAngleTarget,
7752    deficitDirectionalDerivFromLocalAngles,
7753    canonicalPeriodicLocalDihedralDerivativePackage, P] using hLocal ξ
7754
7755theorem canonicalPeriodicMixedHingeDeficitLengthChainTarget_iff_localAngleTarget
7756    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7757    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
7758    CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz ↔
7759      CanonicalPeriodicMixedHingeDeficitLocalAngleTarget Nx Ny Nz hx hy hz :=
7760  ⟨canonicalPeriodicMixedHingeDeficitLocalAngleTarget_of_lengthChainTarget Nx Ny Nz hx hy hz,
7761    canonicalPeriodicMixedHingeDeficitLengthChainTarget_of_localAngleTarget Nx Ny Nz hx hy hz⟩
7762
7763theorem canonicalPeriodicMixedHingeDeficitEdgeStencilTarget_of_localAngleTarget
7764    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7765    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7766    (hLocal :
7767      CanonicalPeriodicMixedHingeDeficitLocalAngleTarget Nx Ny Nz hx hy hz) :
7768    MixedHingeDeficitEdgeStencilTarget
7769      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7770      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7771      (canonicalPeriodicDeficitDerivativePackage Nx Ny Nz hx hy hz) := by
7772  let P := canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz
7773  intro ξ
7774  simpa [P, canonicalPeriodicDeficitDerivativePackage_deficitDeriv]
7775    using hLocal ξ
7776
7777/-- Canonical local-correspondence endpoint with the deficit package fixed to
7778the periodic Freudenthal one.  The only remaining inputs are now concrete
7779statements about that canonical deficit package: near-flat weighted
7780deficit-derivative vanishing and mixed hinge-deficit equality with the concrete
7781edge-stencil Dirichlet energy. -/
7782theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTargets
7783    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7784    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7785    (hZero :
7786      WeightedDeficitDerivativeEventuallyZeroTarget
7787        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7788        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7789        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7790    (hMixed :
7791      MixedHingeDeficitEdgeStencilTarget
7792        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7793        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7794        (canonicalPeriodicDeficitDerivativePackage Nx Ny Nz hx hy hz)) :
7795    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7796  canonicalPeriodicEdgeStencilLocalCorrespondence_of_eventuallyZero_and_edgeStencilTargets
7797    Nx Ny Nz hx hy hz
7798    (canonicalPeriodicDeficitDerivativePackage Nx Ny Nz hx hy hz)
7799    hZero hMixed
7800
7801/-- Canonical local-correspondence endpoint with the mixed target expressed as a
7802finite local-angle identity. -/
7803theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitLocalAngleTargets
7804    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7805    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7806    (hZero :
7807      WeightedDeficitDerivativeEventuallyZeroTarget
7808        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7809        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7810        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7811    (hMixedLocal :
7812      CanonicalPeriodicMixedHingeDeficitLocalAngleTarget Nx Ny Nz hx hy hz) :
7813    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7814  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTargets
7815    Nx Ny Nz hx hy hz hZero
7816    (canonicalPeriodicMixedHingeDeficitEdgeStencilTarget_of_localAngleTarget
7817      Nx Ny Nz hx hy hz hMixedLocal)
7818
7819/-- Canonical local-correspondence endpoint with the mixed target expressed as
7820the explicit length-chain finite-sum identity. -/
7821theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitLengthChainTargets
7822    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7823    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7824    (hZero :
7825      WeightedDeficitDerivativeEventuallyZeroTarget
7826        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7827        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7828        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7829    (hMixedLength :
7830      CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz) :
7831    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7832  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitLocalAngleTargets
7833    Nx Ny Nz hx hy hz hZero
7834    (canonicalPeriodicMixedHingeDeficitLocalAngleTarget_of_lengthChainTarget
7835      Nx Ny Nz hx hy hz hMixedLength)
7836
7837/-- Canonical local-correspondence endpoint with the mixed target expressed as
7838the fully expanded length-chain finite-sum identity. -/
7839theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExpandedLengthChainTargets
7840    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7841    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7842    (hZero :
7843      WeightedDeficitDerivativeEventuallyZeroTarget
7844        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7845        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7846        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7847    (hMixedExpanded :
7848      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTarget Nx Ny Nz hx hy hz) :
7849    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7850  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitLengthChainTargets
7851    Nx Ny Nz hx hy hz hZero
7852    (canonicalPeriodicMixedHingeDeficitLengthChainTarget_of_expanded
7853      Nx Ny Nz hx hy hz hMixedExpanded)
7854
7855/-- Canonical local-correspondence endpoint with the mixed target reduced to a
7856per-edge expanded finite identity. -/
7857theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitPerEdgeTargets
7858    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7859    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7860    (hZero :
7861      WeightedDeficitDerivativeEventuallyZeroTarget
7862        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7863        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7864        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7865    (hMixedPerEdge :
7866      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainPerEdgeTarget
7867        Nx Ny Nz hx hy hz) :
7868    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7869  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExpandedLengthChainTargets
7870    Nx Ny Nz hx hy hz hZero
7871    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainTarget_of_perEdge
7872      Nx Ny Nz hx hy hz hMixedPerEdge)
7873
7874/-- Canonical local-correspondence endpoint with the mixed target reduced to a
7875typed periodic-edge finite identity. -/
7876theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTypedEdgeTargets
7877    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7878    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7879    (hZero :
7880      WeightedDeficitDerivativeEventuallyZeroTarget
7881        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7882        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7883        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7884    (hMixedTyped :
7885      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEdgeTarget
7886        Nx Ny Nz hx hy hz) :
7887    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7888  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitPerEdgeTargets
7889    Nx Ny Nz hx hy hz hZero
7890    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainPerEdgeTarget_of_typed
7891      Nx Ny Nz hx hy hz hMixedTyped)
7892
7893/-- Canonical local-correspondence endpoint with the mixed target written in
7894typed endpoint/displacement form. -/
7895theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTypedEndpointTargets
7896    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7897    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7898    (hZero :
7899      WeightedDeficitDerivativeEventuallyZeroTarget
7900        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7901        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7902        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7903    (hMixedEndpoint :
7904      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget
7905        Nx Ny Nz hx hy hz) :
7906    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7907  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTypedEdgeTargets
7908    Nx Ny Nz hx hy hz hZero
7909    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEdgeTarget_of_typedEndpoint
7910      Nx Ny Nz hx hy hz hMixedEndpoint)
7911
7912/-- Canonical local-correspondence endpoint with the mixed target written in
7913typed slot-guarded form. -/
7914theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTypedSlotTargets
7915    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7916    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7917    (hZero :
7918      WeightedDeficitDerivativeEventuallyZeroTarget
7919        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7920        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7921        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7922    (hMixedSlot :
7923      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedSlotTarget
7924        Nx Ny Nz hx hy hz) :
7925    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7926  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTypedEndpointTargets
7927    Nx Ny Nz hx hy hz hZero
7928    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget_of_typedSlot
7929      Nx Ny Nz hx hy hz hMixedSlot)
7930
7931/-- Canonical local-correspondence endpoint with the mixed target in
7932displacement-filtered typed-slot form. -/
7933theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitDispFilteredTargets
7934    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7935    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7936    (hZero :
7937      WeightedDeficitDerivativeEventuallyZeroTarget
7938        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7939        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7940        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7941    (hMixedDisp :
7942      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainDispFilteredTarget
7943        Nx Ny Nz hx hy hz) :
7944    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7945  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTypedSlotTargets
7946    Nx Ny Nz hx hy hz hZero
7947    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedSlotTarget_of_dispFiltered
7948      Nx Ny Nz hx hy hz hMixedDisp)
7949
7950/-- Canonical local-correspondence endpoint with the mixed target in
7951base-and-displacement-filtered form. -/
7952theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitBaseDispTargets
7953    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7954    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7955    (hZero :
7956      WeightedDeficitDerivativeEventuallyZeroTarget
7957        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7958        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7959        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7960    (hMixedBase :
7961      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispFilteredTarget
7962        Nx Ny Nz hx hy hz) :
7963    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7964  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitDispFilteredTargets
7965    Nx Ny Nz hx hy hz hZero
7966    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainDispFilteredTarget_of_baseDisp
7967      Nx Ny Nz hx hy hz hMixedBase)
7968
7969/-- Canonical local-correspondence endpoint with the mixed target in typed
7970cell/tetrahedron form. -/
7971theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTypedTetTargets
7972    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7973    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7974    (hZero :
7975      WeightedDeficitDerivativeEventuallyZeroTarget
7976        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7977        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7978        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7979    (hMixedTypedTet :
7980      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispTypedTetTarget
7981        Nx Ny Nz hx hy hz) :
7982    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
7983  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitBaseDispTargets
7984    Nx Ny Nz hx hy hz hZero
7985    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispFilteredTarget_of_typedTet
7986      Nx Ny Nz hx hy hz hMixedTypedTet)
7987
7988/-- Canonical local-correspondence endpoint with the mixed target in explicit
7989cell/local-tetrahedron product form. -/
7990theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitCellTetTargets
7991    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
7992    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
7993    (hZero :
7994      WeightedDeficitDerivativeEventuallyZeroTarget
7995        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
7996        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
7997        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
7998    (hMixedCellTet :
7999      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispCellTetTarget
8000        Nx Ny Nz hx hy hz) :
8001    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
8002  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitTypedTetTargets
8003    Nx Ny Nz hx hy hz hZero
8004    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispTypedTetTarget_of_cellTet
8005      Nx Ny Nz hx hy hz hMixedCellTet)
8006
8007/-- Canonical local-correspondence endpoint using the weaker weighted-stationary
8008Schläfli input rather than the stronger eventual-zero input. -/
8009theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_stationary_and_cellTetTargets
8010    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8011    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
8012    (hStat :
8013      WeightedDeficitDerivativeStationaryTarget
8014        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
8015        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
8016        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
8017    (hMixedCellTet :
8018      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispCellTetTarget
8019        Nx Ny Nz hx hy hz) :
8020    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz := by
8021  exact
8022    canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalFlat_firstVariationInput_and_directionalHessian
8023      Nx Ny Nz hx hy hz
8024      (canonicalPeriodicFirstVariationInput Nx Ny Nz hx hy hz)
8025      (nonlinearDirectionalHessian_of_weightedStationary_and_edgeStencil
8026        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
8027        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
8028        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
8029        (canonicalPeriodicDeficitDerivativePackage Nx Ny Nz hx hy hz)
8030        hStat
8031        (canonicalPeriodicMixedHingeDeficitEdgeStencilTarget_of_localAngleTarget
8032          Nx Ny Nz hx hy hz
8033          (canonicalPeriodicMixedHingeDeficitLocalAngleTarget_of_lengthChainTarget
8034            Nx Ny Nz hx hy hz
8035            (canonicalPeriodicMixedHingeDeficitLengthChainTarget_of_expanded
8036              Nx Ny Nz hx hy hz
8037              (canonicalPeriodicMixedHingeDeficitExpandedLengthChainTarget_of_perEdge
8038                Nx Ny Nz hx hy hz
8039                (canonicalPeriodicMixedHingeDeficitExpandedLengthChainPerEdgeTarget_of_typed
8040                  Nx Ny Nz hx hy hz
8041                  (canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEdgeTarget_of_typedEndpoint
8042                    Nx Ny Nz hx hy hz
8043                    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedEndpointTarget_of_typedSlot
8044                      Nx Ny Nz hx hy hz
8045                      (canonicalPeriodicMixedHingeDeficitExpandedLengthChainTypedSlotTarget_of_dispFiltered
8046                        Nx Ny Nz hx hy hz
8047                        (canonicalPeriodicMixedHingeDeficitExpandedLengthChainDispFilteredTarget_of_baseDisp
8048                          Nx Ny Nz hx hy hz
8049                          (canonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispFilteredTarget_of_typedTet
8050                            Nx Ny Nz hx hy hz
8051                            (canonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispTypedTetTarget_of_cellTet
8052                              Nx Ny Nz hx hy hz hMixedCellTet)))))))))))
8053        (canonicalPeriodicEdgeStencilTarget Nx Ny Nz hx hy hz))
8054
8055/-- Shortest honest Track 1.B local-correspondence endpoint: second-order Schläfli
8056stationarity plus the global length-chain mixed identity, without routing through
8057per-edge endpoint-quadratic or explicit-fiber packaging. -/
8058theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_stationary_and_lengthChainTargets
8059    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8060    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
8061    (hStat :
8062      CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget Nx Ny Nz hx hy hz)
8063    (hLength :
8064      CanonicalPeriodicMixedHingeDeficitLengthChainTarget Nx Ny Nz hx hy hz) :
8065    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz := by
8066  dsimp [CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget] at hStat
8067  exact
8068    canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalFlat_firstVariationInput_and_directionalHessian
8069      Nx Ny Nz hx hy hz
8070      (canonicalPeriodicFirstVariationInput Nx Ny Nz hx hy hz)
8071      (nonlinearDirectionalHessian_of_weightedStationary_and_edgeStencil
8072        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
8073        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
8074        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz)
8075        (canonicalPeriodicDeficitDerivativePackage Nx Ny Nz hx hy hz)
8076        hStat
8077        (canonicalPeriodicMixedHingeDeficitEdgeStencilTarget_of_localAngleTarget
8078          Nx Ny Nz hx hy hz
8079          (canonicalPeriodicMixedHingeDeficitLocalAngleTarget_of_lengthChainTarget
8080            Nx Ny Nz hx hy hz hLength))
8081        (canonicalPeriodicEdgeStencilTarget Nx Ny Nz hx hy hz))
8082
8083theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_track1BOpenInputs
8084    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8085    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
8086    (h : CanonicalPeriodicTrack1BOpenInputs Nx Ny Nz hx hy hz) :
8087    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
8088  canonicalPeriodicEdgeStencilLocalCorrespondence_of_stationary_and_lengthChainTargets
8089    Nx Ny Nz hx hy hz
8090    ((canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_iff_secondSchlaefli Nx Ny Nz hx hy
8091        hz).2 h.secondSchlaefli)
8092    h.lengthChain
8093
8094theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_track1BTypedEdgeOpenInputs
8095    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8096    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
8097    (h : CanonicalPeriodicTrack1BTypedEdgeOpenInputs Nx Ny Nz hx hy hz) :
8098    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
8099  canonicalPeriodicEdgeStencilLocalCorrespondence_of_track1BOpenInputs
8100    Nx Ny Nz hx hy hz
8101    { secondSchlaefli :=
8102        (canonicalPeriodicSecondSchlaefliAlongLineTarget_iff_typedEdge Nx Ny Nz hx hy hz).2
8103          h.typedSecondSchlaefli
8104      lengthChain := h.lengthChain }
8105
8106theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_track1BEventuallyZeroInputs
8107    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8108    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
8109    (h : CanonicalPeriodicTrack1BEventuallyZeroInputs Nx Ny Nz hx hy hz) :
8110    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
8111  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitLengthChainTargets
8112    Nx Ny Nz hx hy hz h.eventuallyZero h.lengthChain
8113
8114theorem canonicalPeriodicTrack1BClosureTarget_iff_openInputs
8115    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8116    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
8117    CanonicalPeriodicTrack1BClosureTarget Nx Ny Nz hx hy hz ↔
8118      Nonempty (CanonicalPeriodicTrack1BOpenInputs Nx Ny Nz hx hy hz) := by
8119  constructor
8120  · intro h
8121    exact ⟨{ secondSchlaefli := h.1, lengthChain := h.2 }⟩
8122  · intro h
8123    rcases h with ⟨hOpen⟩
8124    exact ⟨hOpen.secondSchlaefli, hOpen.lengthChain⟩
8125
8126/-- Track 1.B closure target at the canonical `(Nx,Ny,Nz) = (5,5,5)` certificate scale. -/
8127abbrev CanonicalPeriodicTrack1BClosureTargetAtN5 : Prop :=
8128  CanonicalPeriodicTrack1BClosureTarget 5 5 5 (by decide) (by decide) (by decide)
8129
8130/-- The `1B-SCH` target at the canonical `(Nx,Ny,Nz) = (5,5,5)` certificate scale,
8131in the typed periodic-edge form used for the finite stationarity calculation. -/
8132abbrev CanonicalPeriodicSecondSchlaefliTypedEdgeTargetAtN5 : Prop :=
8133  CanonicalPeriodicSecondSchlaefliTypedEdgeTarget 5 5 5 (by decide) (by decide) (by decide)
8134
8135/-- Seven-displacement-class version of the `1B-SCH` stationarity target at
8136the canonical `N=5` certificate scale. -/
8137abbrev CanonicalPeriodicSecondSchlaefliTypedEdgePerDispTargetAtN5 : Prop :=
8138  CanonicalPeriodicSecondSchlaefliTypedEdgePerDispTarget 5 5 5 (by decide) (by decide) (by decide)
8139
8140/-- Seven named `N=5` displacement-class obligations for `1B-SCH`.  These are
8141the parallelizable leaves under `CanonicalPeriodicSecondSchlaefliTypedEdgePerDispTargetAtN5`. -/
8142structure CanonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5 : Prop where
8143  disp0 : CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8144    5 5 5 (by decide) (by decide) (by decide) (0 : Fin 7)
8145  disp1 : CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8146    5 5 5 (by decide) (by decide) (by decide) (1 : Fin 7)
8147  disp2 : CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8148    5 5 5 (by decide) (by decide) (by decide) (2 : Fin 7)
8149  disp3 : CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8150    5 5 5 (by decide) (by decide) (by decide) (3 : Fin 7)
8151  disp4 : CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8152    5 5 5 (by decide) (by decide) (by decide) (4 : Fin 7)
8153  disp5 : CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8154    5 5 5 (by decide) (by decide) (by decide) (5 : Fin 7)
8155  disp6 : CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8156    5 5 5 (by decide) (by decide) (by decide) (6 : Fin 7)
8157
8158theorem canonicalPeriodicSecondSchlaefliTypedEdgePerDispTargetAtN5_of_sevenDisp
8159    (h : CanonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5) :
8160    CanonicalPeriodicSecondSchlaefliTypedEdgePerDispTargetAtN5 := by
8161  intro ξ d
8162  fin_cases d
8163  · exact h.disp0 ξ
8164  · exact h.disp1 ξ
8165  · exact h.disp2 ξ
8166  · exact h.disp3 ξ
8167  · exact h.disp4 ξ
8168  · exact h.disp5 ξ
8169  · exact h.disp6 ξ
8170
8171theorem canonicalPeriodicSecondSchlaefliTypedEdgeTargetAtN5_of_perDisp
8172    (hDisp : CanonicalPeriodicSecondSchlaefliTypedEdgePerDispTargetAtN5) :
8173    CanonicalPeriodicSecondSchlaefliTypedEdgeTargetAtN5 :=
8174  canonicalPeriodicSecondSchlaefliTypedEdgeTarget_of_perDisp
8175    5 5 5 (by decide) (by decide) (by decide) hDisp
8176
8177theorem canonicalPeriodicSecondSchlaefliTypedEdgeTargetAtN5_of_sevenDisp
8178    (h : CanonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5) :
8179    CanonicalPeriodicSecondSchlaefliTypedEdgeTargetAtN5 :=
8180  canonicalPeriodicSecondSchlaefliTypedEdgeTargetAtN5_of_perDisp
8181    (canonicalPeriodicSecondSchlaefliTypedEdgePerDispTargetAtN5_of_sevenDisp h)
8182
8183/-- The `N=5` typed-edge Schläfli target, re-expressed as the weighted-deficit
8184stationarity target consumed by the nonlinear Hessian route. -/
8185abbrev CanonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5 : Prop :=
8186  CanonicalPeriodicWeightedDeficitDerivativeStationaryTarget
8187    5 5 5 (by decide) (by decide) (by decide)
8188
8189/-- The mixed hinge-deficit length-chain target at the canonical `N=5`
8190certificate scale.  Session 202 finite audits show that this edge-stencil
8191surface is wrong-weighted as stated; keep the abbreviation for existing
8192packaging theorems while the corrected mixed/Hessian target is named. -/
8193abbrev CanonicalPeriodicMixedHingeDeficitLengthChainTargetAtN5 : Prop :=
8194  CanonicalPeriodicMixedHingeDeficitLengthChainTarget
8195    5 5 5 (by decide) (by decide) (by decide)
8196
8197/-- Scalar obstruction exposed by the Session 202 exact finite audit.
8198
8199The single-vertex `N=5` audit gives mixed LHS `12`, while the current
8200edge-stencil RHS gives `6 + 6sqrt(2) + 2sqrt(3)`.  This theorem records that
8201those audited scalar values cannot be equal; the next finite-lane task is to
8202promote the audit evaluator itself to a Lean counterexample or corrected
8203quadratic target. -/
8204theorem canonicalPeriodicMixedLengthSingleVertexAudit_scalar_mismatch :
8205    (12 : ℝ) ≠ 6 + 6 * Real.sqrt 2 + 2 * Real.sqrt 3 := by
8206  intro h
8207  have h2 : (1 : ℝ) < Real.sqrt 2 := by
8208    norm_num [Real.lt_sqrt]
8209  have h3 : (0 : ℝ) < Real.sqrt 3 := by
8210    positivity
8211  nlinarith
8212
8213/-- Corrected mixed hinge-deficit target at the canonical `N=5` certificate
8214scale. -/
8215abbrev CanonicalPeriodicMixedHingeDeficitAxisStencilTargetAtN5 : Prop :=
8216  CanonicalPeriodicMixedHingeDeficitAxisStencilTarget
8217    5 5 5 (by decide) (by decide) (by decide)
8218
8219/-- Global explicit-fiber coefficient-table target whose closure proves the
8220corrected mixed axis-stencil target at `N=5`. -/
8221abbrev CanonicalPeriodicMixedHingeDeficitExplicitFiberAxisStencilTargetAtN5 : Prop :=
8222  CanonicalPeriodicMixedHingeDeficitExplicitFiberAxisStencilTarget
8223    5 5 5 (by decide) (by decide) (by decide)
8224
8225/-- `N=5` packaging theorem for the corrected mixed axis-stencil target. -/
8226theorem canonicalPeriodicMixedHingeDeficitAxisStencilTargetAtN5_of_explicitFiberAxis
8227    (hExplicit :
8228      CanonicalPeriodicMixedHingeDeficitExplicitFiberAxisStencilTargetAtN5) :
8229    CanonicalPeriodicMixedHingeDeficitAxisStencilTargetAtN5 :=
8230  canonicalPeriodicMixedHingeDeficitAxisStencilTarget_of_explicitFiberAxis
8231    5 5 5 (by decide) (by decide) (by decide) hExplicit
8232
8233/-- The Track 1.B local Regge/J-cost correspondence target at the canonical
8234`N=5` certificate scale. -/
8235abbrev CanonicalPeriodicEdgeStencilLocalCorrespondenceAtN5 : Prop :=
8236  CanonicalPeriodicEdgeStencilLocalCorrespondence
8237    5 5 5 (by decide) (by decide) (by decide)
8238
8239theorem canonicalPeriodicEdgeStencilLocalCorrespondenceAtN5_of_mixedLengthChain
8240    (hLength : CanonicalPeriodicMixedHingeDeficitLengthChainTargetAtN5) :
8241    CanonicalPeriodicEdgeStencilLocalCorrespondenceAtN5 :=
8242  canonicalPeriodicEdgeStencilLocalCorrespondence_of_stationary_and_lengthChainTargets
8243    5 5 5 (by decide) (by decide) (by decide)
8244    canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_from_nearZeroSchlaefli
8245    hLength
8246
8247/-- Seven displacement-class Schläfli leaves imply the canonical `N=5`
8248weighted-deficit stationarity target.  This is the direct `1B-SCH` handoff into
8249the Track 1.B local-correspondence/Hessian machinery. -/
8250theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_sevenDisp
8251    (h : CanonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5) :
8252    CanonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5 :=
8253  (canonicalPeriodicWeightedDeficitDerivativeStationaryTarget_iff_typedEdge
8254    5 5 5 (by decide) (by decide) (by decide)).2
8255    (canonicalPeriodicSecondSchlaefliTypedEdgeTargetAtN5_of_sevenDisp h)
8256
8257/-- The `disp = 0` filtered typed-edge sum is exactly the unfiltered base-vertex
8258sum over axis-x periodic edges.  This is the reindexing step needed before the
8259finite stationarity table can be reduced to a periodic base-vertex identity. -/
8260theorem canonicalPeriodicSecondSchlaefliTypedEdgeDisp0_sum_eq_base_sum
8261    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8262    (f : PeriodicEdge Nx Ny Nz → ℝ) :
8263    (∑ edge ∈ ((Finset.univ : Finset (PeriodicEdge Nx Ny Nz)).filter
8264        (fun edge => edge.disp = (0 : Fin 7))), f edge) =
8265      ∑ base : Vertex Nx Ny Nz, f ({ base := base, disp := (0 : Fin 7) } :
8266        PeriodicEdge Nx Ny Nz) := by
8267  classical
8268  refine Finset.sum_bij
8269    (fun edge hedge => edge.base)
8270    ?mem ?inj ?surj ?eq
8271  · intro edge hedge
8272    exact Finset.mem_univ edge.base
8273  · intro edge₁ hedge₁ edge₂ hedge₂ hbase
8274    have hdisp₁ : edge₁.disp = (0 : Fin 7) := (Finset.mem_filter.mp hedge₁).2
8275    have hdisp₂ : edge₂.disp = (0 : Fin 7) := (Finset.mem_filter.mp hedge₂).2
8276    cases edge₁ with
8277    | mk base₁ disp₁ =>
8278      cases edge₂ with
8279      | mk base₂ disp₂ =>
8280        dsimp at hbase hdisp₁ hdisp₂ ⊢
8281        cases hbase
8282        cases hdisp₁
8283        cases hdisp₂
8284        rfl
8285  · intro base _hbase
8286    refine ⟨({ base := base, disp := (0 : Fin 7) } :
8287      PeriodicEdge Nx Ny Nz), ?_, ?_⟩
8288    · simp
8289    · rfl
8290  · intro edge hedge
8291    have hdisp : edge.disp = (0 : Fin 7) := (Finset.mem_filter.mp hedge).2
8292    cases edge with
8293    | mk base disp =>
8294        dsimp at hdisp ⊢
8295        cases hdisp
8296        rfl
8297
8298/-- Base-vertex form of the canonical `N=5`, `disp0` Schläfli stationarity
8299leaf.  The remaining work is now the finite periodic axis-edge cancellation
8300over the 125 base vertices, with no filtered `PeriodicEdge` bookkeeping. -/
8301def CanonicalPeriodicSecondSchlaefliTypedEdgeDisp0BaseVertexTargetAtN5 : Prop :=
8302  ∀ ξ : VertexPotential
8303      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K,
8304    (∑ base : Vertex 5 5 5,
8305      canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8306        5 5 5 (by decide) (by decide) (by decide) ξ
8307        ({ base := base, disp := (0 : Fin 7) } : PeriodicEdge 5 5 5)) = 0
8308
8309/-- The partial weighted deficit-derivative sum over the canonical `disp0`
8310axis-edge class at `N=5`.  Its derivative at zero is exactly the base-vertex
8311second-Schläfli target above. -/
8312noncomputable def canonicalPeriodicDisp0WeightedDeficitDerivativeBaseSumAtN5
8313    (ξ : VertexPotential
8314      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K)
8315    (t : ℝ) : ℝ :=
8316  let P := canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)
8317  ∑ base : Vertex 5 5 5,
8318    let edge : PeriodicEdge 5 5 5 := { base := base, disp := (0 : Fin 7) }
8319    let e := P.edgeEquiv.symm edge
8320    hingeMeasureUnderConformal P.K P.hK
8321      (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8322      deficitLineDeriv P.K ξ e t
8323
8324/-- Stationarity of the partial `disp0` weighted deficit-derivative sum.  This
8325is now the precise remaining analytic/combinatorial content for the `disp0`
8326leaf. -/
8327def CanonicalPeriodicDisp0WeightedDeficitDerivativeBaseStationaryTargetAtN5 : Prop :=
8328  ∀ ξ : VertexPotential
8329      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K,
8330    HasDerivAt (canonicalPeriodicDisp0WeightedDeficitDerivativeBaseSumAtN5 ξ) 0 0
8331
8332set_option maxHeartbeats 10000000
8333
8334/-- The derivative of the partial `disp0` weighted deficit-derivative sum is
8335the base-vertex second-Schläfli summand. -/
8336theorem canonicalPeriodicDisp0WeightedDeficitDerivativeBaseSumAtN5_hasDerivAt
8337    (ξ : VertexPotential
8338      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K) :
8339    HasDerivAt
8340      (canonicalPeriodicDisp0WeightedDeficitDerivativeBaseSumAtN5 ξ)
8341      (∑ base : Vertex 5 5 5,
8342        canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8343          5 5 5 (by decide) (by decide) (by decide) ξ
8344          ({ base := base, disp := (0 : Fin 7) } : PeriodicEdge 5 5 5)) 0 := by
8345  let P := canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)
8346  have hSecond :=
8347    hingeDeficitSecondLineDifferentiabilityAtZero_of_flatConfiguration P.K P.hK
8348      (canonicalPeriodicFlatConfiguration 5 5 5 (by decide) (by decide) (by decide))
8349  have hBase : ∀ base : Vertex 5 5 5,
8350      HasDerivAt
8351        (fun t : ℝ =>
8352          let edge : PeriodicEdge 5 5 5 := { base := base, disp := (0 : Fin 7) }
8353          let e := P.edgeEquiv.symm edge
8354          hingeMeasureUnderConformal P.K P.hK
8355            (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8356            deficitLineDeriv P.K ξ e t)
8357        (canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8358          5 5 5 (by decide) (by decide) (by decide) ξ
8359          ({ base := base, disp := (0 : Fin 7) } : PeriodicEdge 5 5 5)) 0 := by
8360    intro base
8361    let edge : PeriodicEdge 5 5 5 := { base := base, disp := (0 : Fin 7) }
8362    let e := P.edgeEquiv.symm edge
8363    have hHinge0 : DifferentiableAt ℝ
8364        (fun t : ℝ => hingeMeasureUnderConformal P.K P.hK
8365          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e) 0 :=
8366      (hingeLine_contDiffAt_zero P.K P.hK ξ e).differentiableAt (by simp)
8367    have hHingeLine : HasDerivAt
8368        (fun t : ℝ => hingeMeasureUnderConformal P.K P.hK
8369          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e)
8370        (hingeLineDeriv P.K P.hK ξ e 0) 0 := by
8371      simpa [hingeLineDeriv] using hHinge0.hasDerivAt
8372    have hDefDeriv : HasDerivAt (fun t : ℝ => deficitLineDeriv P.K ξ e t)
8373        (deficitLineSecondDeriv P.K ξ e 0) 0 := by
8374      simpa [deficitLineSecondDeriv] using (hSecond ξ e).2.hasDerivAt
8375    change HasDerivAt
8376      (fun t : ℝ =>
8377        hingeMeasureUnderConformal P.K P.hK
8378          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8379          deficitLineDeriv P.K ξ e t)
8380      (hingeLineDeriv P.K P.hK ξ e 0 * deficitLineDeriv P.K ξ e 0 +
8381        hingeMeasureUnderConformal P.K P.hK
8382          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ 0) e *
8383          deficitLineSecondDeriv P.K ξ e 0) 0
8384    convert hDefDeriv.mul hHingeLine using 1
8385    · ext t
8386      simp only [Pi.mul_apply]
8387      ring
8388    · ring_nf
8389  have hsum := HasDerivAt.sum
8390    (u := Finset.univ)
8391    (A := fun base t =>
8392      let edge : PeriodicEdge 5 5 5 := { base := base, disp := (0 : Fin 7) }
8393      let e := P.edgeEquiv.symm edge
8394      hingeMeasureUnderConformal P.K P.hK
8395        (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8396        deficitLineDeriv P.K ξ e t)
8397    (A' := fun base =>
8398      canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8399        5 5 5 (by decide) (by decide) (by decide) ξ
8400        ({ base := base, disp := (0 : Fin 7) } : PeriodicEdge 5 5 5))
8401    (x := 0)
8402    (fun base _ => hBase base)
8403  change HasDerivAt
8404    (fun t : ℝ =>
8405      ∑ base : Vertex 5 5 5,
8406        (let edge : PeriodicEdge 5 5 5 := { base := base, disp := (0 : Fin 7) }
8407         let e := P.edgeEquiv.symm edge
8408         hingeMeasureUnderConformal P.K P.hK
8409          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8410          deficitLineDeriv P.K ξ e t))
8411    (∑ base : Vertex 5 5 5,
8412      canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8413        5 5 5 (by decide) (by decide) (by decide) ξ
8414        ({ base := base, disp := (0 : Fin 7) } : PeriodicEdge 5 5 5)) 0
8415  rw [show
8416      (fun t : ℝ =>
8417        ∑ base : Vertex 5 5 5,
8418          (let edge : PeriodicEdge 5 5 5 := { base := base, disp := (0 : Fin 7) }
8419           let e := P.edgeEquiv.symm edge
8420           hingeMeasureUnderConformal P.K P.hK
8421            (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8422            deficitLineDeriv P.K ξ e t)) =
8423      (∑ base : Vertex 5 5 5,
8424        fun t : ℝ =>
8425          (let edge : PeriodicEdge 5 5 5 := { base := base, disp := (0 : Fin 7) }
8426           let e := P.edgeEquiv.symm edge
8427           hingeMeasureUnderConformal P.K P.hK
8428            (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8429            deficitLineDeriv P.K ξ e t)) by
8430    funext t
8431    simp only [Finset.sum_apply]]
8432  exact hsum
8433
8434set_option maxRecDepth 100000
8435
8436/-- Stationarity of the partial `disp0` weighted deficit-derivative sum closes
8437the base-vertex `disp0` second-Schläfli target. -/
8438theorem CanonicalPeriodicSecondSchlaefliTypedEdgeDisp0BaseVertexTargetAtN5_of_stationary
8439    (hStat : CanonicalPeriodicDisp0WeightedDeficitDerivativeBaseStationaryTargetAtN5) :
8440    CanonicalPeriodicSecondSchlaefliTypedEdgeDisp0BaseVertexTargetAtN5 := by
8441  intro ξ
8442  have hcalc := canonicalPeriodicDisp0WeightedDeficitDerivativeBaseSumAtN5_hasDerivAt ξ
8443  have hzero := hcalc.unique (hStat ξ)
8444  exact hzero
8445
8446/-- The base-vertex axis-edge cancellation implies the actual `disp0` leaf in
8447`CanonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5`. -/
8448theorem canonicalPeriodicSecondSchlaefliTypedEdgeDisp0TargetAtN5_of_baseVertexTarget
8449    (h : CanonicalPeriodicSecondSchlaefliTypedEdgeDisp0BaseVertexTargetAtN5) :
8450    CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8451      5 5 5 (by decide) (by decide) (by decide) (0 : Fin 7) := by
8452  intro ξ
8453  rw [canonicalPeriodicSecondSchlaefliTypedEdgeDisp0_sum_eq_base_sum]
8454  exact h ξ
8455
8456/-! ### Parametric `disp d` reductions for all seven displacement classes
8457
8458The disp0 chain (Sessions 191/194/195) reduces the axis displacement leaf to
8459a single stationarity claim.  This block generalizes that chain to any
8460`d : Fin 7`, exposing one uniform proof template for all seven leaves of
8461`CanonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5`.  Each
8462remaining open content is now a single `HasDerivAt _ _ 0` stationarity claim
8463for the partial weighted deficit-derivative sum over the corresponding
8464displacement class. -/
8465
8466/-- Generic version of the `disp = 0` filtered typed-edge sum identity: for
8467any `d : Fin 7`, the filtered typed-edge sum is the unfiltered base-vertex
8468sum over the corresponding axis-edge class. -/
8469theorem canonicalPeriodicSecondSchlaefliTypedEdgeDisp_sum_eq_base_sum
8470    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8471    (d : Fin 7)
8472    (f : PeriodicEdge Nx Ny Nz → ℝ) :
8473    (∑ edge ∈ ((Finset.univ : Finset (PeriodicEdge Nx Ny Nz)).filter
8474        (fun edge => edge.disp = d)), f edge) =
8475      ∑ base : Vertex Nx Ny Nz, f ({ base := base, disp := d } :
8476        PeriodicEdge Nx Ny Nz) := by
8477  classical
8478  refine Finset.sum_bij
8479    (fun edge _ => edge.base)
8480    ?mem ?inj ?surj ?eq
8481  · intro edge _hedge
8482    exact Finset.mem_univ edge.base
8483  · intro edge₁ hedge₁ edge₂ hedge₂ hbase
8484    have hdisp₁ : edge₁.disp = d := (Finset.mem_filter.mp hedge₁).2
8485    have hdisp₂ : edge₂.disp = d := (Finset.mem_filter.mp hedge₂).2
8486    cases edge₁ with
8487    | mk base₁ disp₁ =>
8488      cases edge₂ with
8489      | mk base₂ disp₂ =>
8490        dsimp at hbase hdisp₁ hdisp₂ ⊢
8491        cases hbase
8492        cases hdisp₁
8493        cases hdisp₂
8494        rfl
8495  · intro base _hbase
8496    refine ⟨({ base := base, disp := d } :
8497      PeriodicEdge Nx Ny Nz), ?_, ?_⟩
8498    · simp
8499    · rfl
8500  · intro edge hedge
8501    have hdisp : edge.disp = d := (Finset.mem_filter.mp hedge).2
8502    cases edge with
8503    | mk base disp =>
8504        dsimp at hdisp ⊢
8505        cases hdisp
8506        rfl
8507
8508/-- Generic base-vertex form of the canonical `N=5` displacement-class
8509Schläfli stationarity leaf. -/
8510def CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5
8511    (d : Fin 7) : Prop :=
8512  ∀ ξ : VertexPotential
8513      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K,
8514    (∑ base : Vertex 5 5 5,
8515      canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8516        5 5 5 (by decide) (by decide) (by decide) ξ
8517        ({ base := base, disp := d } : PeriodicEdge 5 5 5)) = 0
8518
8519/-- Generic base-vertex target implies the matching `DispTarget` at `N=5`. -/
8520theorem canonicalPeriodicSecondSchlaefliTypedEdgeDispTargetAtN5_of_baseVertexTarget
8521    (d : Fin 7)
8522    (h : CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5 d) :
8523    CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8524      5 5 5 (by decide) (by decide) (by decide) d := by
8525  intro ξ
8526  rw [canonicalPeriodicSecondSchlaefliTypedEdgeDisp_sum_eq_base_sum]
8527  exact h ξ
8528
8529/-- The partial weighted deficit-derivative sum over the canonical
8530displacement class `d` at `N=5`.  Its derivative at zero is the matching
8531base-vertex second-Schläfli summand. -/
8532noncomputable def canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5
8533    (d : Fin 7)
8534    (ξ : VertexPotential
8535      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K)
8536    (t : ℝ) : ℝ :=
8537  let P := canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)
8538  ∑ base : Vertex 5 5 5,
8539    let edge : PeriodicEdge 5 5 5 := { base := base, disp := d }
8540    let e := P.edgeEquiv.symm edge
8541    hingeMeasureUnderConformal P.K P.hK
8542      (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8543      deficitLineDeriv P.K ξ e t
8544
8545/-- Stationarity of the partial `disp d` weighted deficit-derivative sum.
8546This is the precise remaining analytic/combinatorial content for each
8547displacement leaf. -/
8548def CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5
8549    (d : Fin 7) : Prop :=
8550  ∀ ξ : VertexPotential
8551      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K,
8552    HasDerivAt (canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5 d ξ) 0 0
8553
8554set_option maxHeartbeats 10000000 in
8555/-- The derivative of the partial `disp d` weighted deficit-derivative sum is
8556the matching base-vertex second-Schläfli summand. -/
8557theorem canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5_hasDerivAt
8558    (d : Fin 7)
8559    (ξ : VertexPotential
8560      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K) :
8561    HasDerivAt
8562      (canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5 d ξ)
8563      (∑ base : Vertex 5 5 5,
8564        canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8565          5 5 5 (by decide) (by decide) (by decide) ξ
8566          ({ base := base, disp := d } : PeriodicEdge 5 5 5)) 0 := by
8567  let P := canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)
8568  have hSecond :=
8569    hingeDeficitSecondLineDifferentiabilityAtZero_of_flatConfiguration P.K P.hK
8570      (canonicalPeriodicFlatConfiguration 5 5 5 (by decide) (by decide) (by decide))
8571  have hBase : ∀ base : Vertex 5 5 5,
8572      HasDerivAt
8573        (fun t : ℝ =>
8574          let edge : PeriodicEdge 5 5 5 := { base := base, disp := d }
8575          let e := P.edgeEquiv.symm edge
8576          hingeMeasureUnderConformal P.K P.hK
8577            (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8578            deficitLineDeriv P.K ξ e t)
8579        (canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8580          5 5 5 (by decide) (by decide) (by decide) ξ
8581          ({ base := base, disp := d } : PeriodicEdge 5 5 5)) 0 := by
8582    intro base
8583    let edge : PeriodicEdge 5 5 5 := { base := base, disp := d }
8584    let e := P.edgeEquiv.symm edge
8585    have hHinge0 : DifferentiableAt ℝ
8586        (fun t : ℝ => hingeMeasureUnderConformal P.K P.hK
8587          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e) 0 :=
8588      (hingeLine_contDiffAt_zero P.K P.hK ξ e).differentiableAt (by simp)
8589    have hHingeLine : HasDerivAt
8590        (fun t : ℝ => hingeMeasureUnderConformal P.K P.hK
8591          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e)
8592        (hingeLineDeriv P.K P.hK ξ e 0) 0 := by
8593      simpa [hingeLineDeriv] using hHinge0.hasDerivAt
8594    have hDefDeriv : HasDerivAt (fun t : ℝ => deficitLineDeriv P.K ξ e t)
8595        (deficitLineSecondDeriv P.K ξ e 0) 0 := by
8596      simpa [deficitLineSecondDeriv] using (hSecond ξ e).2.hasDerivAt
8597    change HasDerivAt
8598      (fun t : ℝ =>
8599        hingeMeasureUnderConformal P.K P.hK
8600          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8601          deficitLineDeriv P.K ξ e t)
8602      (hingeLineDeriv P.K P.hK ξ e 0 * deficitLineDeriv P.K ξ e 0 +
8603        hingeMeasureUnderConformal P.K P.hK
8604          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ 0) e *
8605          deficitLineSecondDeriv P.K ξ e 0) 0
8606    convert hDefDeriv.mul hHingeLine using 1
8607    · ext t
8608      simp only [Pi.mul_apply]
8609      ring
8610    · ring_nf
8611  have hsum := HasDerivAt.sum
8612    (u := Finset.univ)
8613    (A := fun base t =>
8614      let edge : PeriodicEdge 5 5 5 := { base := base, disp := d }
8615      let e := P.edgeEquiv.symm edge
8616      hingeMeasureUnderConformal P.K P.hK
8617        (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8618        deficitLineDeriv P.K ξ e t)
8619    (A' := fun base =>
8620      canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8621        5 5 5 (by decide) (by decide) (by decide) ξ
8622        ({ base := base, disp := d } : PeriodicEdge 5 5 5))
8623    (x := 0)
8624    (fun base _ => hBase base)
8625  change HasDerivAt
8626    (fun t : ℝ =>
8627      ∑ base : Vertex 5 5 5,
8628        (let edge : PeriodicEdge 5 5 5 := { base := base, disp := d }
8629         let e := P.edgeEquiv.symm edge
8630         hingeMeasureUnderConformal P.K P.hK
8631          (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8632          deficitLineDeriv P.K ξ e t))
8633    (∑ base : Vertex 5 5 5,
8634      canonicalPeriodicSecondSchlaefliTypedEdgeSummand
8635        5 5 5 (by decide) (by decide) (by decide) ξ
8636        ({ base := base, disp := d } : PeriodicEdge 5 5 5)) 0
8637  rw [show
8638      (fun t : ℝ =>
8639        ∑ base : Vertex 5 5 5,
8640          (let edge : PeriodicEdge 5 5 5 := { base := base, disp := d }
8641           let e := P.edgeEquiv.symm edge
8642           hingeMeasureUnderConformal P.K P.hK
8643            (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8644            deficitLineDeriv P.K ξ e t)) =
8645      (∑ base : Vertex 5 5 5,
8646        fun t : ℝ =>
8647          (let edge : PeriodicEdge 5 5 5 := { base := base, disp := d }
8648           let e := P.edgeEquiv.symm edge
8649           hingeMeasureUnderConformal P.K P.hK
8650            (Geometry.ReggeActionSecondVariation.linePotential P.K ξ t) e *
8651            deficitLineDeriv P.K ξ e t)) by
8652    funext t
8653    simp only [Finset.sum_apply]]
8654  exact hsum
8655
8656/-- Stationarity of the partial `disp d` weighted deficit-derivative sum
8657closes the matching base-vertex `disp` second-Schläfli target. -/
8658theorem CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5_of_stationary
8659    (d : Fin 7)
8660    (hStat : CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8661    CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5 d := by
8662  intro ξ
8663  have hcalc := canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5_hasDerivAt d ξ
8664  have hzero := hcalc.unique (hStat ξ)
8665  exact hzero
8666
8667/-- The seven `disp d` stationarity claims, one for each displacement class.
8668This is the parametric bundle that supersedes the disp0-only stationarity
8669target.  Each field is a single `HasDerivAt _ _ 0` claim for the partial
8670weighted deficit-derivative sum over the corresponding displacement class. -/
8671structure CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5 : Prop where
8672  disp0 : CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (0 : Fin 7)
8673  disp1 : CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (1 : Fin 7)
8674  disp2 : CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (2 : Fin 7)
8675  disp3 : CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (3 : Fin 7)
8676  disp4 : CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (4 : Fin 7)
8677  disp5 : CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (5 : Fin 7)
8678  disp6 : CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (6 : Fin 7)
8679
8680/-- A single quantified displacement-stationarity proof supplies the seven
8681named stationarity leaves.  This is the preferred next proof interface: prove
8682`∀ d : Fin 7, CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d`,
8683then this theorem packages the seven fields without repeated bookkeeping. -/
8684theorem canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall
8685    (h : ∀ d : Fin 7,
8686      CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8687    CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5 where
8688  disp0 := h (0 : Fin 7)
8689  disp1 := h (1 : Fin 7)
8690  disp2 := h (2 : Fin 7)
8691  disp3 := h (3 : Fin 7)
8692  disp4 := h (4 : Fin 7)
8693  disp5 := h (5 : Fin 7)
8694  disp6 := h (6 : Fin 7)
8695
8696/-- Session 558 projection: the uniform displacement-stationarity proof supplies
8697the `disp0` stationarity leaf. -/
8698theorem canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall_disp0
8699    (h : ∀ d : Fin 7,
8700      CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8701    CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (0 : Fin 7) :=
8702  (canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall h).disp0
8703
8704/-- Session 558 projection: the uniform displacement-stationarity proof supplies
8705the `disp1` stationarity leaf. -/
8706theorem canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall_disp1
8707    (h : ∀ d : Fin 7,
8708      CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8709    CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (1 : Fin 7) :=
8710  (canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall h).disp1
8711
8712/-- Session 558 projection: the uniform displacement-stationarity proof supplies
8713the `disp2` stationarity leaf. -/
8714theorem canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall_disp2
8715    (h : ∀ d : Fin 7,
8716      CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8717    CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (2 : Fin 7) :=
8718  (canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall h).disp2
8719
8720/-- Session 558 projection: the uniform displacement-stationarity proof supplies
8721the `disp3` stationarity leaf. -/
8722theorem canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall_disp3
8723    (h : ∀ d : Fin 7,
8724      CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8725    CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (3 : Fin 7) :=
8726  (canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall h).disp3
8727
8728/-- Session 558 projection: the uniform displacement-stationarity proof supplies
8729the `disp4` stationarity leaf. -/
8730theorem canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall_disp4
8731    (h : ∀ d : Fin 7,
8732      CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8733    CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (4 : Fin 7) :=
8734  (canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall h).disp4
8735
8736/-- Session 558 projection: the uniform displacement-stationarity proof supplies
8737the `disp5` stationarity leaf. -/
8738theorem canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall_disp5
8739    (h : ∀ d : Fin 7,
8740      CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8741    CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (5 : Fin 7) :=
8742  (canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall h).disp5
8743
8744/-- Session 558 projection: the uniform displacement-stationarity proof supplies
8745the `disp6` stationarity leaf. -/
8746theorem canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall_disp6
8747    (h : ∀ d : Fin 7,
8748      CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8749    CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 (6 : Fin 7) :=
8750  (canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall h).disp6
8751
8752/-- Session 558 audit count for the seven uniform-stationarity packaging
8753projections: `disp0` through `disp6`. -/
8754def canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5ForallProjectionCount :
8755    ℕ := 7
8756
8757theorem canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5ForallProjectionCount_eq_seven :
8758    canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5ForallProjectionCount = 7 := rfl
8759
8760/-- The seven displacement-class stationarity claims imply the seven
8761displacement-class typed-edge Schläfli leaves consumed by
8762`canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_sevenDisp`. -/
8763theorem canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity
8764    (h : CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5) :
8765    CanonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5 where
8766  disp0 :=
8767    canonicalPeriodicSecondSchlaefliTypedEdgeDispTargetAtN5_of_baseVertexTarget (0 : Fin 7)
8768      (CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5_of_stationary
8769        (0 : Fin 7) h.disp0)
8770  disp1 :=
8771    canonicalPeriodicSecondSchlaefliTypedEdgeDispTargetAtN5_of_baseVertexTarget (1 : Fin 7)
8772      (CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5_of_stationary
8773        (1 : Fin 7) h.disp1)
8774  disp2 :=
8775    canonicalPeriodicSecondSchlaefliTypedEdgeDispTargetAtN5_of_baseVertexTarget (2 : Fin 7)
8776      (CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5_of_stationary
8777        (2 : Fin 7) h.disp2)
8778  disp3 :=
8779    canonicalPeriodicSecondSchlaefliTypedEdgeDispTargetAtN5_of_baseVertexTarget (3 : Fin 7)
8780      (CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5_of_stationary
8781        (3 : Fin 7) h.disp3)
8782  disp4 :=
8783    canonicalPeriodicSecondSchlaefliTypedEdgeDispTargetAtN5_of_baseVertexTarget (4 : Fin 7)
8784      (CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5_of_stationary
8785        (4 : Fin 7) h.disp4)
8786  disp5 :=
8787    canonicalPeriodicSecondSchlaefliTypedEdgeDispTargetAtN5_of_baseVertexTarget (5 : Fin 7)
8788      (CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5_of_stationary
8789        (5 : Fin 7) h.disp5)
8790  disp6 :=
8791    canonicalPeriodicSecondSchlaefliTypedEdgeDispTargetAtN5_of_baseVertexTarget (6 : Fin 7)
8792      (CanonicalPeriodicSecondSchlaefliTypedEdgeDispBaseVertexTargetAtN5_of_stationary
8793        (6 : Fin 7) h.disp6)
8794
8795/-- Session 559 projection: seven stationarity leaves supply the `disp0`
8796typed-edge Schläfli leaf. -/
8797theorem canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity_disp0
8798    (h : CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5) :
8799    CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8800      5 5 5 (by decide) (by decide) (by decide) (0 : Fin 7) :=
8801  (canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity h).disp0
8802
8803/-- Session 559 projection: seven stationarity leaves supply the `disp1`
8804typed-edge Schläfli leaf. -/
8805theorem canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity_disp1
8806    (h : CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5) :
8807    CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8808      5 5 5 (by decide) (by decide) (by decide) (1 : Fin 7) :=
8809  (canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity h).disp1
8810
8811/-- Session 559 projection: seven stationarity leaves supply the `disp2`
8812typed-edge Schläfli leaf. -/
8813theorem canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity_disp2
8814    (h : CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5) :
8815    CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8816      5 5 5 (by decide) (by decide) (by decide) (2 : Fin 7) :=
8817  (canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity h).disp2
8818
8819/-- Session 559 projection: seven stationarity leaves supply the `disp3`
8820typed-edge Schläfli leaf. -/
8821theorem canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity_disp3
8822    (h : CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5) :
8823    CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8824      5 5 5 (by decide) (by decide) (by decide) (3 : Fin 7) :=
8825  (canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity h).disp3
8826
8827/-- Session 559 projection: seven stationarity leaves supply the `disp4`
8828typed-edge Schläfli leaf. -/
8829theorem canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity_disp4
8830    (h : CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5) :
8831    CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8832      5 5 5 (by decide) (by decide) (by decide) (4 : Fin 7) :=
8833  (canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity h).disp4
8834
8835/-- Session 559 projection: seven stationarity leaves supply the `disp5`
8836typed-edge Schläfli leaf. -/
8837theorem canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity_disp5
8838    (h : CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5) :
8839    CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8840      5 5 5 (by decide) (by decide) (by decide) (5 : Fin 7) :=
8841  (canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity h).disp5
8842
8843/-- Session 559 projection: seven stationarity leaves supply the `disp6`
8844typed-edge Schläfli leaf. -/
8845theorem canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity_disp6
8846    (h : CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5) :
8847    CanonicalPeriodicSecondSchlaefliTypedEdgeDispTarget
8848      5 5 5 (by decide) (by decide) (by decide) (6 : Fin 7) :=
8849  (canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity h).disp6
8850
8851/-- Session 559 audit count for the seven stationarity-to-Schläfli leaf
8852projections: `disp0` through `disp6`. -/
8853def canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5SevenStationarityProjectionCount :
8854    ℕ := 7
8855
8856theorem canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5SevenStationarityProjectionCount_eq_seven :
8857    canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5SevenStationarityProjectionCount = 7 := rfl
8858
8859/-- The seven parametric stationarity claims chain directly to the
8860canonical `N=5` weighted-deficit stationarity target consumed by
8861`CanonicalPeriodicEdgeStencilLocalCorrespondence`.  This is the parametric
8862endpoint of the entire `1B-SCH` reduction: the remaining open content is
8863exactly the seven `HasDerivAt _ _ 0` stationarity claims. -/
8864theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_sevenStationarity
8865    (h : CanonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5) :
8866    CanonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5 :=
8867  canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_sevenDisp
8868    (canonicalPeriodicSecondSchlaefliTypedEdgeSevenDispTargetsAtN5_of_sevenStationarity h)
8869
8870/-- Session 561 endpoint: a uniform proof of all seven displacement-class
8871stationarity claims closes the canonical `N=5` weighted-deficit stationarity
8872target directly. -/
8873theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_forallDispStationarity
8874    (h : ∀ d : Fin 7,
8875      CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d) :
8876    CanonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5 :=
8877  canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_sevenStationarity
8878    (canonicalPeriodicDispWeightedDeficitDerivativeSevenBaseStationaryTargetsAtN5_of_forall h)
8879
8880/-- Session 561 audit count for the direct uniform-stationarity endpoint. -/
8881def canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5ForallDispEndpointCount :
8882    ℕ := 1
8883
8884theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5ForallDispEndpointCount_eq_one :
8885    canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5ForallDispEndpointCount = 1 := rfl
8886
8887/-- Session 567 target: the sum over all seven displacement-class partial
8888weighted deficit-derivative sums is stationary at the flat point. -/
8889def CanonicalPeriodicDispWeightedDeficitDerivativeBaseSumTotalStationaryTargetAtN5 : Prop :=
8890  ∀ ξ : VertexPotential
8891      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K,
8892    HasDerivAt
8893      (fun t : ℝ =>
8894        ∑ d : Fin 7, canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5 d ξ t)
8895      0 0
8896
8897/-- Session 567 target: all seven displacement-class partial weighted
8898deficit-derivative sums are the same one-variable function.  This is the finite
8899translation/cube-symmetry content needed after the total stationarity claim. -/
8900def CanonicalPeriodicDispWeightedDeficitDerivativeBaseSumDispSymmetryTargetAtN5 : Prop :=
8901  ∀ (d : Fin 7)
8902    (ξ : VertexPotential
8903      (canonicalEncodedPeriodicFreudenthalTorus 5 5 5 (by decide) (by decide) (by decide)).K),
8904    (fun t : ℝ => canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5 d ξ t) =
8905      (fun t : ℝ =>
8906        canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5 (0 : Fin 7) ξ t)
8907
8908/-- Session 567 reduction: total stationarity plus displacement-class symmetry
8909closes the uniform seven-displacement stationarity target. -/
8910theorem canonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5_of_totalStationary_and_dispSymmetry
8911    (hTotal : CanonicalPeriodicDispWeightedDeficitDerivativeBaseSumTotalStationaryTargetAtN5)
8912    (hSym : CanonicalPeriodicDispWeightedDeficitDerivativeBaseSumDispSymmetryTargetAtN5) :
8913    ∀ d : Fin 7, CanonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5 d := by
8914  intro d ξ
8915  let f0 : ℝ → ℝ :=
8916    fun t => canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5 (0 : Fin 7) ξ t
8917  have hsum_eq :
8918      (fun t : ℝ =>
8919        ∑ e : Fin 7, canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5 e ξ t) =
8920        (fun t : ℝ => (7 : ℝ) * f0 t) := by
8921    funext t
8922    calc
8923      (∑ e : Fin 7, canonicalPeriodicDispWeightedDeficitDerivativeBaseSumAtN5 e ξ t) =
8924          ∑ _e : Fin 7, f0 t := by
8925            apply Finset.sum_congr rfl
8926            intro e _he
8927            exact congrFun (hSym e ξ) t
8928      _ = (7 : ℝ) * f0 t := by
8929            simp [f0]
8930  have hscaled : HasDerivAt (fun t : ℝ => (7 : ℝ) * f0 t) 0 0 := by
8931    simpa [hsum_eq] using hTotal ξ
8932  have h0 : HasDerivAt f0 0 0 := by
8933    have hdiv := hscaled.const_mul ((7 : ℝ)⁻¹)
8934    simpa [f0, mul_assoc] using hdiv
8935  convert h0 using 1
8936  funext t
8937  simpa [f0] using congrFun (hSym d ξ) t
8938
8939/-- Session 567 audit count for the total-plus-symmetry stationarity reduction:
8940total stationarity, displacement symmetry, and the reduction theorem. -/
8941def canonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTotalSymmetryReductionCount :
8942    ℕ := 3
8943
8944theorem canonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTotalSymmetryReductionCount_eq_three :
8945    canonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTotalSymmetryReductionCount = 3 := rfl
8946
8947/-- Session 571 direct endpoint: total stationarity plus displacement-class
8948symmetry closes the canonical `N=5` weighted-deficit stationarity target without
8949requiring callers to route through the uniform `∀ d` statement manually. -/
8950theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_totalStationary_and_dispSymmetry
8951    (hTotal : CanonicalPeriodicDispWeightedDeficitDerivativeBaseSumTotalStationaryTargetAtN5)
8952    (hSym : CanonicalPeriodicDispWeightedDeficitDerivativeBaseSumDispSymmetryTargetAtN5) :
8953    CanonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5 :=
8954  canonicalPeriodicWeightedDeficitDerivativeStationaryTargetAtN5_of_forallDispStationarity
8955    (canonicalPeriodicDispWeightedDeficitDerivativeBaseStationaryTargetAtN5_of_totalStationary_and_dispSymmetry
8956      hTotal hSym)
8957
8958/-- Session 571 audit count for the direct total-plus-symmetry stationarity endpoint. -/
8959def canonicalPeriodicWeightedDeficitDerivativeStationaryTotalSymmetryEndpointCount :
8960    ℕ := 1
8961
8962theorem canonicalPeriodicWeightedDeficitDerivativeStationaryTotalSymmetryEndpointCount_eq_one :
8963    canonicalPeriodicWeightedDeficitDerivativeStationaryTotalSymmetryEndpointCount = 1 := rfl
8964
8965/-- Track 1.B typed-edge open-input package at the canonical `N=5` certificate scale. -/
8966abbrev CanonicalPeriodicTrack1BTypedEdgeOpenInputsAtN5 : Prop :=
8967  Nonempty (CanonicalPeriodicTrack1BTypedEdgeOpenInputs 5 5 5 (by decide) (by decide) (by decide))
8968
8969/-- Canonical local-correspondence endpoint with the mixed target reduced to
8970the local-pair displacement-filtered form. -/
8971theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitLocalPairTargets
8972    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8973    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
8974    (hStat :
8975      WeightedDeficitDerivativeStationaryTarget
8976        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
8977        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
8978        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
8979    (hMixedLocalPair :
8980      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairTarget
8981        Nx Ny Nz hx hy hz) :
8982    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
8983  canonicalPeriodicEdgeStencilLocalCorrespondence_of_stationary_and_cellTetTargets
8984    Nx Ny Nz hx hy hz hStat
8985    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainBaseDispCellTetTarget_of_localPair
8986      Nx Ny Nz hx hy hz hMixedLocalPair)
8987
8988/-- Canonical local-correspondence endpoint with the mixed target in explicit
8989local-pair displacement-fiber form. -/
8990theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitLocalPairFiberTargets
8991    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
8992    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
8993    (hStat :
8994      WeightedDeficitDerivativeStationaryTarget
8995        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
8996        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
8997        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
8998    (hMixedFiber :
8999      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairFiberTarget
9000        Nx Ny Nz hx hy hz) :
9001    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
9002  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitLocalPairTargets
9003    Nx Ny Nz hx hy hz hStat
9004    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairTarget_of_fiber
9005      Nx Ny Nz hx hy hz hMixedFiber)
9006
9007/-- Canonical local-correspondence endpoint with the mixed target over the
9008explicit precomputed Freudenthal local-pair displacement fiber. -/
9009theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExplicitFiberTargets
9010    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9011    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9012    (hStat :
9013      WeightedDeficitDerivativeStationaryTarget
9014        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9015        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9016        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
9017    (hMixedExplicit :
9018      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget
9019        Nx Ny Nz hx hy hz) :
9020    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
9021  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitLocalPairFiberTargets
9022    Nx Ny Nz hx hy hz hStat
9023    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainLocalPairFiberTarget_of_explicitFiber
9024      Nx Ny Nz hx hy hz hMixedExplicit)
9025
9026theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExplicitFiberFlatUnfoldedTargets
9027    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9028    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9029    (hStat :
9030      WeightedDeficitDerivativeStationaryTarget
9031        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9032        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9033        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
9034    (hMixedFlatUnfolded :
9035      CanonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget
9036        Nx Ny Nz hx hy hz) :
9037    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
9038  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExplicitFiberTargets
9039    Nx Ny Nz hx hy hz hStat
9040    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget_of_flatUnfolded
9041      Nx Ny Nz hx hy hz hMixedFlatUnfolded)
9042
9043theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExplicitFiberClosedFormTargets
9044    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9045    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9046    (hStat :
9047      WeightedDeficitDerivativeStationaryTarget
9048        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9049        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9050        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
9051    (hMixedClosedForm :
9052      CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget
9053        Nx Ny Nz hx hy hz) :
9054    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
9055  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExplicitFiberFlatUnfoldedTargets
9056    Nx Ny Nz hx hy hz hStat
9057    (canonicalPeriodicMixedHingeDeficitExplicitFiberFlatUnfoldedTarget_of_closedForm
9058      Nx Ny Nz hx hy hz hMixedClosedForm)
9059
9060theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExplicitFiberClosedFormPerDispTargets
9061    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9062    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9063    (hStat :
9064      WeightedDeficitDerivativeStationaryTarget
9065        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9066        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9067        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
9068    (hPerDisp :
9069      ∀ d : Fin 7,
9070        CanonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormPerDispTarget
9071          Nx Ny Nz hx hy hz d) :
9072    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
9073  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExplicitFiberClosedFormTargets
9074    Nx Ny Nz hx hy hz hStat
9075    (canonicalPeriodicMixedHingeDeficitExplicitFiberClosedFormTarget_of_perDisp
9076      Nx Ny Nz hx hy hz hPerDisp)
9077
9078theorem canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExplicitFiberAngleChainTargets
9079    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9080    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9081    (hStat :
9082      WeightedDeficitDerivativeStationaryTarget
9083        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9084        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9085        (canonicalPeriodicFlatConfiguration Nx Ny Nz hx hy hz))
9086    (hMixedAngleChain :
9087      CanonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberAngleChainTarget
9088        Nx Ny Nz hx hy hz) :
9089    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz :=
9090  canonicalPeriodicEdgeStencilLocalCorrespondence_of_canonicalDeficitExplicitFiberTargets
9091    Nx Ny Nz hx hy hz hStat
9092    (canonicalPeriodicMixedHingeDeficitExpandedLengthChainExplicitFiberTarget_of_angleChain
9093      Nx Ny Nz hx hy hz hMixedAngleChain)
9094
9095/-- The input bundle exposes the flat-deficit target needed by the previous
9096normalization bridge. -/
9097theorem CanonicalPeriodicFlatConfigurationInputs.flatDeficitZeroTarget
9098    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
9099    {hx : 2 < Nx} {hy : 2 < Ny} {hz : 2 < Nz}
9100    (I : CanonicalPeriodicFlatConfigurationInputs Nx Ny Nz hx hy hz) :
9101    FlatDeficitZeroTarget
9102      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K :=
9103  (flatDeficitZeroTarget_iff_globalZeroDeficitAtFlat
9104    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K).2
9105    I.global_zero_deficit
9106
9107/-- Canonical periodic flat-action normalization from the two-input flat
9108configuration bundle. -/
9109theorem canonicalPeriodicReggeAction_zeroPotential_eq_zero_of_flatConfigurationInputs
9110    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9111    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9112    (I : CanonicalPeriodicFlatConfigurationInputs Nx Ny Nz hx hy hz) :
9113    reggeAction
9114        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9115        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9116        (zeroPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) = 0 :=
9117  canonicalPeriodicReggeAction_zeroPotential_eq_zero_of_flatConfiguration
9118    Nx Ny Nz hx hy hz I.toFlatConfiguration
9119
9120/-- Exact quadratic normalization for the second-order Regge action.  If the
9121flat action is normalized to zero, then the spacing-scaled second-order action
9122on `a • ξ`, divided by `||a||^2`, is exactly the quadratic form
9123`(1 / 2) * H(ξ, ξ)` for every nonzero spacing `a`. -/
9124theorem reggeActionSecondOrder_spacing_scaled_div_norm_sq_eq_quadratic_of_flat_zero
9125    (K : Triangulation3D) (hK : IncidenceConsistent K)
9126    (H : Fin K.nV → Fin K.nV → ℝ)
9127    (hFlat : reggeAction K hK (zeroPotential K) = 0)
9128    (a : ℝ) (ha : a ≠ 0) (ξ : VertexPotential K) :
9129    reggeActionSecondOrder K hK H (a • ξ) / ‖a‖ ^ (2 : ℕ) =
9130      (1 / 2) * hessianQuadratic H ξ := by
9131  have hquad : hessianQuadratic H (a • ξ) =
9132      a ^ (2 : ℕ) * hessianQuadratic H ξ := by
9133    rw [← Geometry.ReggeActionCubicTaylorBound.linePotential_eq_smul K ξ a]
9134    exact Geometry.ReggeActionSecondVariation.hessianQuadratic_linePotential K H ξ a
9135  have hnorm_sq : ‖a‖ ^ (2 : ℕ) = a ^ (2 : ℕ) := by
9136    rw [Real.norm_eq_abs, sq_abs]
9137  unfold reggeActionSecondOrder
9138  rw [hFlat, hquad, hnorm_sq]
9139  field_simp [ha]
9140  ring
9141
9142/-- Filter form of the exact quadratic normalization.  The conclusion is an
9143eventual equality to a constant, so no continuity or rate hypothesis is needed;
9144the only filter hypothesis is eventual nonzero spacing. -/
9145theorem reggeActionSecondOrder_spacing_scaled_div_norm_sq_tendsto_quadratic_of_flat_zero
9146    {α : Type*} {l : Filter α}
9147    (K : Triangulation3D) (hK : IncidenceConsistent K)
9148    (H : Fin K.nV → Fin K.nV → ℝ)
9149    (hFlat : reggeAction K hK (zeroPotential K) = 0)
9150    (spacing : α → ℝ)
9151    (ξ : VertexPotential K)
9152    (hSpacing_ne : ∀ᶠ t : α in l, spacing t ≠ 0) :
9153    Filter.Tendsto
9154      (fun t : α =>
9155        reggeActionSecondOrder K hK H (spacing t • ξ) /
9156          ‖spacing t‖ ^ (2 : ℕ))
9157      l (nhds ((1 / 2) * hessianQuadratic H ξ)) := by
9158  have hEq :
9159      (fun t : α =>
9160        reggeActionSecondOrder K hK H (spacing t • ξ) /
9161          ‖spacing t‖ ^ (2 : ℕ)) =ᶠ[l]
9162        (fun _t : α => (1 / 2) * hessianQuadratic H ξ) :=
9163    hSpacing_ne.mono (fun t ht =>
9164      reggeActionSecondOrder_spacing_scaled_div_norm_sq_eq_quadratic_of_flat_zero
9165        K hK H hFlat (spacing t) ht ξ)
9166  exact tendsto_const_nhds.congr' hEq.symm
9167
9168/-- Canonical finite mesh-weighted second-order aggregate after exact quadratic
9169normalization.  This is the supplied pointwise normalization of session 32
9170instantiated by quadratic homogeneity and flat-action zero-normalization. -/
9171theorem canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_quadratic_of_flat_zero
9172    {α : Type*} {l : Filter α}
9173    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9174    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9175    (hFlat :
9176      reggeAction
9177        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9178        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9179        (zeroPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) = 0)
9180    {n : ℕ}
9181    (spacing : α → ℝ)
9182    (probe :
9183      Fin n →
9184        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9185    (weight : α → Fin n → ℝ)
9186    (limitWeight : Fin n → ℝ)
9187    (hWeight :
9188      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
9189    (hSpacing_ne : ∀ᶠ t : α in l, spacing t ≠ 0) :
9190    Filter.Tendsto
9191      (fun t : α =>
9192        ∑ i : Fin n,
9193          weight t i *
9194            (reggeActionSecondOrder
9195              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9196              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9197              (canonicalReggeHessian
9198                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9199                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9200              (spacing t • probe i) /
9201              ‖spacing t‖ ^ (2 : ℕ)))
9202      l
9203      (nhds
9204        (∑ i : Fin n,
9205          limitWeight i *
9206            ((1 / 2) *
9207              hessianQuadratic
9208                (canonicalReggeHessian
9209                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9210                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9211                (probe i)))) :=
9212  canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto
9213    Nx Ny Nz hx hy hz spacing probe weight limitWeight
9214    (fun i : Fin n =>
9215      (1 / 2) *
9216        hessianQuadratic
9217          (canonicalReggeHessian
9218            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9219            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9220          (probe i))
9221    hWeight
9222    (fun i =>
9223      reggeActionSecondOrder_spacing_scaled_div_norm_sq_tendsto_quadratic_of_flat_zero
9224        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9225        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9226        (canonicalReggeHessian
9227          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9228          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9229        hFlat spacing (probe i) hSpacing_ne)
9230
9231/-- Dirichlet-energy form of the canonical finite mesh-weighted second-order
9232aggregate after exact quadratic normalization.  This rewrites the raw Hessian
9233limit using the already-proved canonical Regge Hessian / Dirichlet identity. -/
9234theorem canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flat_zero
9235    {α : Type*} {l : Filter α}
9236    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9237    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9238    (hFlat :
9239      reggeAction
9240        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9241        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9242        (zeroPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) = 0)
9243    {n : ℕ}
9244    (spacing : α → ℝ)
9245    (probe :
9246      Fin n →
9247        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9248    (weight : α → Fin n → ℝ)
9249    (limitWeight : Fin n → ℝ)
9250    (hWeight :
9251      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
9252    (hSpacing_ne : ∀ᶠ t : α in l, spacing t ≠ 0) :
9253    Filter.Tendsto
9254      (fun t : α =>
9255        ∑ i : Fin n,
9256          weight t i *
9257            (reggeActionSecondOrder
9258              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9259              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9260              (canonicalReggeHessian
9261                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9262                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9263              (spacing t • probe i) /
9264              ‖spacing t‖ ^ (2 : ℕ)))
9265      l
9266      (nhds
9267        (∑ i : Fin n,
9268          limitWeight i *
9269            ((1 / 2) *
9270              canonicalDirichletEnergy
9271                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9272                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9273                (probe i)))) := by
9274  simpa [canonicalReggeHessian_quadratic_eq_dirichlet] using
9275    canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_quadratic_of_flat_zero
9276      Nx Ny Nz hx hy hz hFlat spacing probe weight limitWeight hWeight hSpacing_ne
9277
9278/-- Dirichlet-energy finite second-order aggregate from the sharper geometric
9279input: flat deficits vanish at the canonical periodic background. -/
9280theorem canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatDeficit
9281    {α : Type*} {l : Filter α}
9282    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9283    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9284    (hDeficit :
9285      FlatDeficitZeroTarget
9286        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9287    {n : ℕ}
9288    (spacing : α → ℝ)
9289    (probe :
9290      Fin n →
9291        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9292    (weight : α → Fin n → ℝ)
9293    (limitWeight : Fin n → ℝ)
9294    (hWeight :
9295      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
9296    (hSpacing_ne : ∀ᶠ t : α in l, spacing t ≠ 0) :
9297    Filter.Tendsto
9298      (fun t : α =>
9299        ∑ i : Fin n,
9300          weight t i *
9301            (reggeActionSecondOrder
9302              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9303              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9304              (canonicalReggeHessian
9305                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9306                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9307              (spacing t • probe i) /
9308              ‖spacing t‖ ^ (2 : ℕ)))
9309      l
9310      (nhds
9311        (∑ i : Fin n,
9312          limitWeight i *
9313            ((1 / 2) *
9314              canonicalDirichletEnergy
9315                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9316                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9317                (probe i)))) :=
9318  canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flat_zero
9319    Nx Ny Nz hx hy hz
9320    (canonicalPeriodicReggeAction_zeroPotential_eq_zero_of_flatDeficit
9321      Nx Ny Nz hx hy hz hDeficit)
9322    spacing probe weight limitWeight hWeight hSpacing_ne
9323
9324/-- Dirichlet-energy finite second-order aggregate from the standard
9325flat-configuration package. -/
9326theorem canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatConfiguration
9327    {α : Type*} {l : Filter α}
9328    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9329    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9330    (hFlat :
9331      FlatConfiguration
9332        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9333        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9334    {n : ℕ}
9335    (spacing : α → ℝ)
9336    (probe :
9337      Fin n →
9338        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9339    (weight : α → Fin n → ℝ)
9340    (limitWeight : Fin n → ℝ)
9341    (hWeight :
9342      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
9343    (hSpacing_ne : ∀ᶠ t : α in l, spacing t ≠ 0) :
9344    Filter.Tendsto
9345      (fun t : α =>
9346        ∑ i : Fin n,
9347          weight t i *
9348            (reggeActionSecondOrder
9349              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9350              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9351              (canonicalReggeHessian
9352                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9353                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9354              (spacing t • probe i) /
9355              ‖spacing t‖ ^ (2 : ℕ)))
9356      l
9357      (nhds
9358        (∑ i : Fin n,
9359          limitWeight i *
9360            ((1 / 2) *
9361              canonicalDirichletEnergy
9362                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9363                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9364                (probe i)))) :=
9365  canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatDeficit
9366    Nx Ny Nz hx hy hz
9367    (FlatDeficitZeroTarget.of_flatConfiguration
9368      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9369      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9370      hFlat)
9371    spacing probe weight limitWeight hWeight hSpacing_ne
9372
9373/-- Dirichlet-energy finite second-order aggregate from the canonical
9374two-input flat-configuration bundle. -/
9375theorem canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatConfigurationInputs
9376    {α : Type*} {l : Filter α}
9377    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9378    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9379    (I : CanonicalPeriodicFlatConfigurationInputs Nx Ny Nz hx hy hz)
9380    {n : ℕ}
9381    (spacing : α → ℝ)
9382    (probe :
9383      Fin n →
9384        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9385    (weight : α → Fin n → ℝ)
9386    (limitWeight : Fin n → ℝ)
9387    (hWeight :
9388      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
9389    (hSpacing_ne : ∀ᶠ t : α in l, spacing t ≠ 0) :
9390    Filter.Tendsto
9391      (fun t : α =>
9392        ∑ i : Fin n,
9393          weight t i *
9394            (reggeActionSecondOrder
9395              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9396              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9397              (canonicalReggeHessian
9398                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9399                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9400              (spacing t • probe i) /
9401              ‖spacing t‖ ^ (2 : ℕ)))
9402      l
9403      (nhds
9404        (∑ i : Fin n,
9405          limitWeight i *
9406            ((1 / 2) *
9407              canonicalDirichletEnergy
9408                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9409                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9410                (probe i)))) :=
9411  canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatConfiguration
9412    Nx Ny Nz hx hy hz I.toFlatConfiguration
9413    spacing probe weight limitWeight hWeight hSpacing_ne
9414
9415/-- Composition interface for the scaled full nonlinear Regge aggregate.  Once a
9416finite mesh-weighted second-order aggregate, scaled by `||spacing(t)||^2`, has a
9417supplied limit, the full nonlinear Regge aggregate has the same limit because
9418the scaled nonlinear residual vanishes. -/
9419theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_of_secondOrder
9420    {α : Type*} {l : Filter α}
9421    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9422    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9423    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
9424    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9425      ∀ {n : ℕ}
9426        (spacing : α → ℝ)
9427        (probe :
9428          Fin n →
9429            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9430        (weight : α → Fin n → ℝ)
9431        (limitWeight : Fin n → ℝ)
9432        (limit : ℝ),
9433        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9434          Filter.Tendsto spacing l (nhds 0) →
9435            (∀ᶠ t : α in l, spacing t ≠ 0) →
9436              Filter.Tendsto
9437                (fun t : α =>
9438                  ∑ i : Fin n,
9439                    weight t i *
9440                      (reggeActionSecondOrder
9441                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9442                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9443                        (canonicalReggeHessian
9444                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9445                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9446                        (spacing t • probe i) /
9447                        ‖spacing t‖ ^ (2 : ℕ)))
9448                l (nhds limit) →
9449                Filter.Tendsto
9450                  (fun t : α =>
9451                    ∑ i : Fin n,
9452                      weight t i *
9453                        (reggeAction
9454                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9455                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9456                          (spacing t • probe i) /
9457                          ‖spacing t‖ ^ (2 : ℕ)))
9458                  l (nhds limit) := by
9459  rcases canonicalPeriodicNonlinearResidual_variable_weighted_finite_probe_spacing_scaled_to_secondOrder_div_spacing_norm_sq_tendsto_zero
9460      Nx Ny Nz hx hy hz hLocal with
9461    ⟨r, C, hr, hC, hScaledResidual⟩
9462  refine ⟨r, C, hr, hC, ?_⟩
9463  intro n spacing probe weight limitWeight limit hWeight hSpacing hSpacing_ne hSecondOrder
9464  have hResidual :=
9465    hScaledResidual spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
9466  have hCombined := hSecondOrder.add hResidual
9467  have hCombinedLimit :
9468      Filter.Tendsto
9469        (fun t : α =>
9470          (∑ i : Fin n,
9471            weight t i *
9472              (reggeActionSecondOrder
9473                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9474                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9475                (canonicalReggeHessian
9476                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9477                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9478                (spacing t • probe i) /
9479                ‖spacing t‖ ^ (2 : ℕ))) +
9480            ∑ i : Fin n,
9481              weight t i *
9482                ((reggeAction
9483                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9484                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9485                    (spacing t • probe i) -
9486                  reggeActionSecondOrder
9487                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9488                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9489                    (canonicalReggeHessian
9490                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9491                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9492                    (spacing t • probe i)) /
9493                  ‖spacing t‖ ^ (2 : ℕ)))
9494        l (nhds limit) := by
9495    simpa using hCombined
9496  convert hCombinedLimit using 1
9497  funext t
9498  rw [← Finset.sum_add_distrib]
9499  apply Finset.sum_congr rfl
9500  intro i _hi
9501  ring
9502
9503/-- Full nonlinear Regge finite aggregate convergence from pointwise scaled
9504second-order limits.  This composes the quadratic finite Riemann-sum interface
9505with the scaled nonlinear residual bridge; the only continuum-normalization
9506input is the explicit pointwise limit of each scaled second-order probe. -/
9507theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_of_pointwise_secondOrder
9508    {α : Type*} {l : Filter α}
9509    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9510    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9511    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
9512    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9513      ∀ {n : ℕ}
9514        (spacing : α → ℝ)
9515        (probe :
9516          Fin n →
9517            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9518        (weight : α → Fin n → ℝ)
9519        (limitWeight : Fin n → ℝ)
9520        (secondOrderLimit : Fin n → ℝ),
9521        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9522          Filter.Tendsto spacing l (nhds 0) →
9523            (∀ᶠ t : α in l, spacing t ≠ 0) →
9524              (∀ i : Fin n,
9525                Filter.Tendsto
9526                  (fun t : α =>
9527                    reggeActionSecondOrder
9528                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9529                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9530                      (canonicalReggeHessian
9531                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9532                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9533                      (spacing t • probe i) /
9534                      ‖spacing t‖ ^ (2 : ℕ))
9535                  l (nhds (secondOrderLimit i))) →
9536                Filter.Tendsto
9537                  (fun t : α =>
9538                    ∑ i : Fin n,
9539                      weight t i *
9540                        (reggeAction
9541                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9542                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9543                          (spacing t • probe i) /
9544                          ‖spacing t‖ ^ (2 : ℕ)))
9545                  l (nhds (∑ i : Fin n, limitWeight i * secondOrderLimit i)) := by
9546  rcases canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_of_secondOrder
9547      Nx Ny Nz hx hy hz hLocal with
9548    ⟨r, C, hr, hC, hTransfer⟩
9549  refine ⟨r, C, hr, hC, ?_⟩
9550  intro n spacing probe weight limitWeight secondOrderLimit hWeight hSpacing hSpacing_ne hSecondOrder
9551  have hSecondOrderAggregate :
9552      Filter.Tendsto
9553        (fun t : α =>
9554          ∑ i : Fin n,
9555            weight t i *
9556              (reggeActionSecondOrder
9557                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9558                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9559                (canonicalReggeHessian
9560                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9561                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9562                (spacing t • probe i) /
9563                ‖spacing t‖ ^ (2 : ℕ)))
9564        l (nhds (∑ i : Fin n, limitWeight i * secondOrderLimit i)) :=
9565    canonicalPeriodicSecondOrder_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto
9566      Nx Ny Nz hx hy hz spacing probe weight limitWeight secondOrderLimit hWeight hSecondOrder
9567  exact
9568    hTransfer spacing probe weight limitWeight
9569      (∑ i : Fin n, limitWeight i * secondOrderLimit i)
9570      hWeight hSpacing hSpacing_ne hSecondOrderAggregate
9571
9572/-- Full nonlinear Regge finite aggregate after exact quadratic normalization.
9573This is the first closed nonzero scaled finite limit: under flat-action
9574zero-normalization, the finite full-Regge aggregate has the same scaled limit as
9575the canonical quadratic form.  This remains finite and local; it does not yet
9576identify the quadratic form with the global EH integrand or pass to an
9577integral. -/
9578theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_quadratic_of_flat_zero
9579    {α : Type*} {l : Filter α}
9580    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9581    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9582    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
9583    (hFlat :
9584      reggeAction
9585        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9586        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9587        (zeroPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) = 0) :
9588    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9589      ∀ {n : ℕ}
9590        (spacing : α → ℝ)
9591        (probe :
9592          Fin n →
9593            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9594        (weight : α → Fin n → ℝ)
9595        (limitWeight : Fin n → ℝ),
9596        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9597          Filter.Tendsto spacing l (nhds 0) →
9598            (∀ᶠ t : α in l, spacing t ≠ 0) →
9599              Filter.Tendsto
9600                (fun t : α =>
9601                  ∑ i : Fin n,
9602                    weight t i *
9603                      (reggeAction
9604                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9605                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9606                        (spacing t • probe i) /
9607                        ‖spacing t‖ ^ (2 : ℕ)))
9608                l
9609                (nhds
9610                  (∑ i : Fin n,
9611                    limitWeight i *
9612                      ((1 / 2) *
9613                        hessianQuadratic
9614                          (canonicalReggeHessian
9615                            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9616                            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9617                          (probe i)))) := by
9618  rcases canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_of_pointwise_secondOrder
9619      Nx Ny Nz hx hy hz hLocal with
9620    ⟨r, C, hr, hC, hFull⟩
9621  refine ⟨r, C, hr, hC, ?_⟩
9622  intro n spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
9623  exact
9624    hFull spacing probe weight limitWeight
9625      (fun i : Fin n =>
9626        (1 / 2) *
9627          hessianQuadratic
9628            (canonicalReggeHessian
9629              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9630              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9631            (probe i))
9632      hWeight hSpacing hSpacing_ne
9633      (fun i =>
9634        reggeActionSecondOrder_spacing_scaled_div_norm_sq_tendsto_quadratic_of_flat_zero
9635          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9636          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9637          (canonicalReggeHessian
9638            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9639            (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
9640          hFlat spacing (probe i) hSpacing_ne)
9641
9642/-- Dirichlet-energy form of the full nonlinear Regge finite aggregate after
9643exact quadratic normalization.  The full-Regge scaled aggregate has the finite
9644Dirichlet limit under the same local residual and flat-action-zero hypotheses. -/
9645theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flat_zero
9646    {α : Type*} {l : Filter α}
9647    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9648    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9649    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
9650    (hFlat :
9651      reggeAction
9652        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9653        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9654        (zeroPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) = 0) :
9655    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9656      ∀ {n : ℕ}
9657        (spacing : α → ℝ)
9658        (probe :
9659          Fin n →
9660            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9661        (weight : α → Fin n → ℝ)
9662        (limitWeight : Fin n → ℝ),
9663        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9664          Filter.Tendsto spacing l (nhds 0) →
9665            (∀ᶠ t : α in l, spacing t ≠ 0) →
9666              Filter.Tendsto
9667                (fun t : α =>
9668                  ∑ i : Fin n,
9669                    weight t i *
9670                      (reggeAction
9671                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9672                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9673                        (spacing t • probe i) /
9674                        ‖spacing t‖ ^ (2 : ℕ)))
9675                l
9676                (nhds
9677                  (∑ i : Fin n,
9678                    limitWeight i *
9679                      ((1 / 2) *
9680                        canonicalDirichletEnergy
9681                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9682                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9683                          (probe i)))) := by
9684  rcases canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_quadratic_of_flat_zero
9685      Nx Ny Nz hx hy hz hLocal hFlat with
9686    ⟨r, C, hr, hC, hFull⟩
9687  refine ⟨r, C, hr, hC, ?_⟩
9688  intro n spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
9689  simpa [canonicalReggeHessian_quadratic_eq_dirichlet] using
9690    hFull spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
9691
9692/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
9693sharper geometric input: flat deficits vanish at the canonical periodic
9694background. -/
9695theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatDeficit
9696    {α : Type*} {l : Filter α}
9697    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9698    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9699    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
9700    (hDeficit :
9701      FlatDeficitZeroTarget
9702        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
9703    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9704      ∀ {n : ℕ}
9705        (spacing : α → ℝ)
9706        (probe :
9707          Fin n →
9708            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9709        (weight : α → Fin n → ℝ)
9710        (limitWeight : Fin n → ℝ),
9711        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9712          Filter.Tendsto spacing l (nhds 0) →
9713            (∀ᶠ t : α in l, spacing t ≠ 0) →
9714              Filter.Tendsto
9715                (fun t : α =>
9716                  ∑ i : Fin n,
9717                    weight t i *
9718                      (reggeAction
9719                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9720                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9721                        (spacing t • probe i) /
9722                        ‖spacing t‖ ^ (2 : ℕ)))
9723                l
9724                (nhds
9725                  (∑ i : Fin n,
9726                    limitWeight i *
9727                      ((1 / 2) *
9728                        canonicalDirichletEnergy
9729                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9730                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9731                          (probe i)))) :=
9732  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flat_zero
9733    Nx Ny Nz hx hy hz hLocal
9734    (canonicalPeriodicReggeAction_zeroPotential_eq_zero_of_flatDeficit
9735      Nx Ny Nz hx hy hz hDeficit)
9736
9737/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
9738standard flat-configuration package. -/
9739theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatConfiguration
9740    {α : Type*} {l : Filter α}
9741    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9742    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9743    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
9744    (hFlat :
9745      FlatConfiguration
9746        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9747        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK) :
9748    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9749      ∀ {n : ℕ}
9750        (spacing : α → ℝ)
9751        (probe :
9752          Fin n →
9753            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9754        (weight : α → Fin n → ℝ)
9755        (limitWeight : Fin n → ℝ),
9756        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9757          Filter.Tendsto spacing l (nhds 0) →
9758            (∀ᶠ t : α in l, spacing t ≠ 0) →
9759              Filter.Tendsto
9760                (fun t : α =>
9761                  ∑ i : Fin n,
9762                    weight t i *
9763                      (reggeAction
9764                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9765                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9766                        (spacing t • probe i) /
9767                        ‖spacing t‖ ^ (2 : ℕ)))
9768                l
9769                (nhds
9770                  (∑ i : Fin n,
9771                    limitWeight i *
9772                      ((1 / 2) *
9773                        canonicalDirichletEnergy
9774                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9775                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9776                          (probe i)))) :=
9777  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatDeficit
9778    Nx Ny Nz hx hy hz hLocal
9779    (FlatDeficitZeroTarget.of_flatConfiguration
9780      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9781      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9782      hFlat)
9783
9784/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
9785canonical two-input flat-configuration bundle. -/
9786theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatConfigurationInputs
9787    {α : Type*} {l : Filter α}
9788    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9789    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9790    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
9791    (I : CanonicalPeriodicFlatConfigurationInputs Nx Ny Nz hx hy hz) :
9792    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9793      ∀ {n : ℕ}
9794        (spacing : α → ℝ)
9795        (probe :
9796          Fin n →
9797            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9798        (weight : α → Fin n → ℝ)
9799        (limitWeight : Fin n → ℝ),
9800        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9801          Filter.Tendsto spacing l (nhds 0) →
9802            (∀ᶠ t : α in l, spacing t ≠ 0) →
9803              Filter.Tendsto
9804                (fun t : α =>
9805                  ∑ i : Fin n,
9806                    weight t i *
9807                      (reggeAction
9808                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9809                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9810                        (spacing t • probe i) /
9811                        ‖spacing t‖ ^ (2 : ℕ)))
9812                l
9813                (nhds
9814                  (∑ i : Fin n,
9815                    limitWeight i *
9816                      ((1 / 2) *
9817                        canonicalDirichletEnergy
9818                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9819                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9820                          (probe i)))) :=
9821  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatConfiguration
9822    Nx Ny Nz hx hy hz hLocal I.toFlatConfiguration
9823
9824/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from one
9825realized Freudenthal tetrahedron plus the remaining global zero-deficit input. -/
9826theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_realizedFreudenthalTet_zeroDeficit
9827    {α : Type*} {l : Filter α}
9828    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9829    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9830    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
9831    (T : Geometry.AffineIndepInterior.RealizedNonDegenerateTet)
9832    (hT : T.tet = Geometry.FreudenthalCubeTriangulation.freudenthalTet)
9833    (hZero :
9834      GlobalZeroDeficitAtFlat
9835        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
9836    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9837      ∀ {n : ℕ}
9838        (spacing : α → ℝ)
9839        (probe :
9840          Fin n →
9841            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9842        (weight : α → Fin n → ℝ)
9843        (limitWeight : Fin n → ℝ),
9844        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9845          Filter.Tendsto spacing l (nhds 0) →
9846            (∀ᶠ t : α in l, spacing t ≠ 0) →
9847              Filter.Tendsto
9848                (fun t : α =>
9849                  ∑ i : Fin n,
9850                    weight t i *
9851                      (reggeAction
9852                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9853                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9854                        (spacing t • probe i) /
9855                        ‖spacing t‖ ^ (2 : ℕ)))
9856                l
9857                (nhds
9858                  (∑ i : Fin n,
9859                    limitWeight i *
9860                      ((1 / 2) *
9861                        canonicalDirichletEnergy
9862                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9863                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9864                          (probe i)))) :=
9865  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_flatConfigurationInputs
9866    Nx Ny Nz hx hy hz hLocal
9867    (canonicalPeriodicFlatConfigurationInputs_of_realizedFreudenthalTet_zeroDeficit
9868      Nx Ny Nz hx hy hz T hT hZero)
9869
9870/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from a
9871concrete Euclidean realization of the one-cube Freudenthal tetrahedron plus the
9872remaining global zero-deficit input. -/
9873theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_realizedTet_sqEdge_zeroDeficit
9874    {α : Type*} {l : Filter α}
9875    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9876    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9877    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
9878    (R : Geometry.TetrahedronRealization.RealizedTet)
9879    (hSq :
9880      Geometry.TetrahedronRealization.sqEdgeOfPoints R =
9881        Geometry.FreudenthalCubeTriangulation.freudenthalTetSqEdges)
9882    (hZero :
9883      GlobalZeroDeficitAtFlat
9884        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
9885    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9886      ∀ {n : ℕ}
9887        (spacing : α → ℝ)
9888        (probe :
9889          Fin n →
9890            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9891        (weight : α → Fin n → ℝ)
9892        (limitWeight : Fin n → ℝ),
9893        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9894          Filter.Tendsto spacing l (nhds 0) →
9895            (∀ᶠ t : α in l, spacing t ≠ 0) →
9896              Filter.Tendsto
9897                (fun t : α =>
9898                  ∑ i : Fin n,
9899                    weight t i *
9900                      (reggeAction
9901                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9902                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9903                        (spacing t • probe i) /
9904                        ‖spacing t‖ ^ (2 : ℕ)))
9905                l
9906                (nhds
9907                  (∑ i : Fin n,
9908                    limitWeight i *
9909                      ((1 / 2) *
9910                        canonicalDirichletEnergy
9911                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9912                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9913                          (probe i)))) :=
9914  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_realizedFreudenthalTet_zeroDeficit
9915    Nx Ny Nz hx hy hz hLocal
9916    (realizedFreudenthalTet_of_sqEdgeOfPoints R hSq)
9917    rfl
9918    hZero
9919
9920/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
9921explicit Freudenthal coordinate realization, assuming affine independence of
9922those four points and the remaining global zero-deficit input. -/
9923theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealizationAffine_zeroDeficit
9924    {α : Type*} {l : Filter α}
9925    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9926    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9927    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
9928    (hAffine : AffineIndependent ℝ freudenthalRealizationPoints)
9929    (hZero :
9930      GlobalZeroDeficitAtFlat
9931        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
9932    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9933      ∀ {n : ℕ}
9934        (spacing : α → ℝ)
9935        (probe :
9936          Fin n →
9937            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9938        (weight : α → Fin n → ℝ)
9939        (limitWeight : Fin n → ℝ),
9940        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9941          Filter.Tendsto spacing l (nhds 0) →
9942            (∀ᶠ t : α in l, spacing t ≠ 0) →
9943              Filter.Tendsto
9944                (fun t : α =>
9945                  ∑ i : Fin n,
9946                    weight t i *
9947                      (reggeAction
9948                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9949                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9950                        (spacing t • probe i) /
9951                        ‖spacing t‖ ^ (2 : ℕ)))
9952                l
9953                (nhds
9954                  (∑ i : Fin n,
9955                    limitWeight i *
9956                      ((1 / 2) *
9957                        canonicalDirichletEnergy
9958                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9959                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9960                          (probe i)))) :=
9961  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_realizedTet_sqEdge_zeroDeficit
9962    Nx Ny Nz hx hy hz hLocal
9963    (freudenthalRealizedTet_of_affineIndependent hAffine)
9964    (freudenthalRealizedTet_of_affineIndependent_sqEdgeOfPoints hAffine)
9965    hZero
9966
9967/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
9968explicit Freudenthal coordinate realization.  The local chart side is now
9969fully discharged; the remaining geometric input is global zero deficit. -/
9970theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_zeroDeficit
9971    {α : Type*} {l : Filter α}
9972    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
9973    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
9974    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
9975    (hZero :
9976      GlobalZeroDeficitAtFlat
9977        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
9978    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
9979      ∀ {n : ℕ}
9980        (spacing : α → ℝ)
9981        (probe :
9982          Fin n →
9983            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
9984        (weight : α → Fin n → ℝ)
9985        (limitWeight : Fin n → ℝ),
9986        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
9987          Filter.Tendsto spacing l (nhds 0) →
9988            (∀ᶠ t : α in l, spacing t ≠ 0) →
9989              Filter.Tendsto
9990                (fun t : α =>
9991                  ∑ i : Fin n,
9992                    weight t i *
9993                      (reggeAction
9994                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
9995                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
9996                        (spacing t • probe i) /
9997                        ‖spacing t‖ ^ (2 : ℕ)))
9998                l
9999                (nhds
10000                  (∑ i : Fin n,
10001                    limitWeight i *
10002                      ((1 / 2) *
10003                        canonicalDirichletEnergy
10004                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10005                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10006                          (probe i)))) :=
10007  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealizationAffine_zeroDeficit
10008    Nx Ny Nz hx hy hz hLocal
10009    freudenthalRealizationPoints_affineIndependent
10010    hZero
10011
10012/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
10013explicit Freudenthal coordinate realization, with both the local realized-chart
10014input and canonical global zero-deficit discharged.  This is the strongest
10015current finite scaled Track 1.B theorem before the remaining EH-integrand and
10016finite-to-integral layers. -/
10017theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization
10018    {α : Type*} {l : Filter α}
10019    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10020    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10021    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
10022    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
10023      ∀ {n : ℕ}
10024        (spacing : α → ℝ)
10025        (probe :
10026          Fin n →
10027            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10028        (weight : α → Fin n → ℝ)
10029        (limitWeight : Fin n → ℝ),
10030        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
10031          Filter.Tendsto spacing l (nhds 0) →
10032            (∀ᶠ t : α in l, spacing t ≠ 0) →
10033              Filter.Tendsto
10034                (fun t : α =>
10035                  ∑ i : Fin n,
10036                    weight t i *
10037                      (reggeAction
10038                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10039                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10040                        (spacing t • probe i) /
10041                        ‖spacing t‖ ^ (2 : ℕ)))
10042                l
10043                (nhds
10044                  (∑ i : Fin n,
10045                    limitWeight i *
10046                      ((1 / 2) *
10047                        canonicalDirichletEnergy
10048                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10049                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10050                          (probe i)))) :=
10051  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_zeroDeficit
10052    Nx Ny Nz hx hy hz hLocal
10053    (canonicalPeriodicGlobalZeroDeficitAtFlat Nx Ny Nz hx hy hz)
10054
10055/-- A finite physical/EH limit action on vertex-potential probes for the
10056canonical periodic Freudenthal torus.  This is the finite-probe target that the
10057later integral theorem will replace by an actual manifold integral. -/
10058abbrev CanonicalPeriodicFinitePhysicalLimitAction
10059    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10060    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :=
10061  VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K → ℝ
10062
10063/-- The finite physical/EH limit action agrees with the currently proved
10064canonical finite Dirichlet limit.  Instantiating this target with the true EH
10065integrand approximation is the next Track 1.B mathematical task. -/
10066def CanonicalPeriodicFiniteDirichletPhysicalLimitTarget
10067    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10068    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10069    (A : CanonicalPeriodicFinitePhysicalLimitAction Nx Ny Nz hx hy hz) : Prop :=
10070  ∀ ξ : VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K,
10071    A ξ =
10072      (1 / 2) *
10073        canonicalDirichletEnergy
10074          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10075          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10076          ξ
10077
10078/-- Normalized full nonlinear Regge finite aggregates converge to any supplied
10079finite physical/EH limit action that has been identified with the canonical
10080finite Dirichlet limit.  This separates the already closed Regge-to-Dirichlet
10081finite theorem from the still-open EH-integrand identification. -/
10082theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_physicalLimit_of_finiteDirichletTarget
10083    {α : Type*} {l : Filter α}
10084    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10085    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10086    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
10087    (A : CanonicalPeriodicFinitePhysicalLimitAction Nx Ny Nz hx hy hz)
10088    (hA : CanonicalPeriodicFiniteDirichletPhysicalLimitTarget Nx Ny Nz hx hy hz A) :
10089    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
10090      ∀ {n : ℕ}
10091        (spacing : α → ℝ)
10092        (probe :
10093          Fin n →
10094            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10095        (weight : α → Fin n → ℝ)
10096        (limitWeight : Fin n → ℝ),
10097        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
10098          Filter.Tendsto spacing l (nhds 0) →
10099            (∀ᶠ t : α in l, spacing t ≠ 0) →
10100              Filter.Tendsto
10101                (fun t : α =>
10102                  ∑ i : Fin n,
10103                    weight t i *
10104                      (reggeAction
10105                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10106                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10107                        (spacing t • probe i) /
10108                        ‖spacing t‖ ^ (2 : ℕ)))
10109                l
10110                (nhds (∑ i : Fin n, limitWeight i * A (probe i))) := by
10111  rcases
10112    canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization
10113      Nx Ny Nz hx hy hz hLocal with
10114    ⟨r, C, hr, hC, hFull⟩
10115  refine ⟨r, C, hr, hC, ?_⟩
10116  intro n spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
10117  have hTarget :
10118      (∑ i : Fin n,
10119        limitWeight i *
10120          ((1 / 2) *
10121            canonicalDirichletEnergy
10122              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10123              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10124              (probe i))) =
10125        ∑ i : Fin n, limitWeight i * A (probe i) := by
10126    refine Finset.sum_congr rfl ?_
10127    intro i _
10128    rw [hA (probe i)]
10129  rw [← hTarget]
10130  exact hFull spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
10131
10132/-- Residual form of the finite physical/EH limit interface: once the supplied
10133finite physical limit action is identified with the canonical finite Dirichlet
10134limit, the normalized full-Regge aggregate minus the finite physical aggregate
10135tends to zero. -/
10136theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_physicalLimit_residual_tendsto_zero_of_finiteDirichletTarget
10137    {α : Type*} {l : Filter α}
10138    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10139    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10140    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
10141    (A : CanonicalPeriodicFinitePhysicalLimitAction Nx Ny Nz hx hy hz)
10142    (hA : CanonicalPeriodicFiniteDirichletPhysicalLimitTarget Nx Ny Nz hx hy hz A) :
10143    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
10144      ∀ {n : ℕ}
10145        (spacing : α → ℝ)
10146        (probe :
10147          Fin n →
10148            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10149        (weight : α → Fin n → ℝ)
10150        (limitWeight : Fin n → ℝ),
10151        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
10152          Filter.Tendsto spacing l (nhds 0) →
10153            (∀ᶠ t : α in l, spacing t ≠ 0) →
10154              Filter.Tendsto
10155                (fun t : α =>
10156                  (∑ i : Fin n,
10157                    weight t i *
10158                      (reggeAction
10159                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10160                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10161                        (spacing t • probe i) /
10162                        ‖spacing t‖ ^ (2 : ℕ))) -
10163                    ∑ i : Fin n, limitWeight i * A (probe i))
10164                l (nhds 0) := by
10165  rcases
10166    canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_physicalLimit_of_finiteDirichletTarget
10167      Nx Ny Nz hx hy hz hLocal A hA with
10168    ⟨r, C, hr, hC, hFull⟩
10169  refine ⟨r, C, hr, hC, ?_⟩
10170  intro n spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
10171  let target : ℝ := ∑ i : Fin n, limitWeight i * A (probe i)
10172  have hConst : Filter.Tendsto (fun _t : α => target) l (nhds target) :=
10173    tendsto_const_nhds
10174  simpa [target] using
10175    (hFull spacing probe weight limitWeight hWeight hSpacing hSpacing_ne).sub hConst
10176
10177/-- The canonical finite EH/Dirichlet limit action currently available at the
10178periodic Freudenthal finite-probe level.  It is the already proved finite
10179Dirichlet integrand approximation; the remaining Track 1.B work is to lift
10180this finite action to a genuine manifold integral. -/
10181def CanonicalPeriodicFiniteEHDirichletLimitAction
10182    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10183    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
10184    CanonicalPeriodicFinitePhysicalLimitAction Nx Ny Nz hx hy hz :=
10185  fun ξ =>
10186    (1 / 2) *
10187      canonicalDirichletEnergy
10188        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10189        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10190        ξ
10191
10192/-- The canonical finite EH/Dirichlet action instantiates the finite physical
10193limit interface by definition. -/
10194theorem canonicalPeriodicFiniteEHDirichletLimitTarget
10195    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10196    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
10197    CanonicalPeriodicFiniteDirichletPhysicalLimitTarget Nx Ny Nz hx hy hz
10198      (CanonicalPeriodicFiniteEHDirichletLimitAction Nx Ny Nz hx hy hz) := by
10199  intro ξ
10200  rfl
10201
10202/-- Normalized full nonlinear Regge finite aggregates converge to the canonical
10203finite EH/Dirichlet action.  This is still a finite-probe theorem, not the
10204full finite-to-integral or manifold Einstein-Hilbert convergence theorem. -/
10205theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_finiteEHDirichletLimit
10206    {α : Type*} {l : Filter α}
10207    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10208    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10209    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
10210    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
10211      ∀ {n : ℕ}
10212        (spacing : α → ℝ)
10213        (probe :
10214          Fin n →
10215            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10216        (weight : α → Fin n → ℝ)
10217        (limitWeight : Fin n → ℝ),
10218        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
10219          Filter.Tendsto spacing l (nhds 0) →
10220            (∀ᶠ t : α in l, spacing t ≠ 0) →
10221              Filter.Tendsto
10222                (fun t : α =>
10223                  ∑ i : Fin n,
10224                    weight t i *
10225                      (reggeAction
10226                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10227                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10228                        (spacing t • probe i) /
10229                        ‖spacing t‖ ^ (2 : ℕ)))
10230                l
10231                (nhds
10232                  (∑ i : Fin n,
10233                    limitWeight i *
10234                      CanonicalPeriodicFiniteEHDirichletLimitAction Nx Ny Nz hx hy hz
10235                        (probe i))) :=
10236  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_physicalLimit_of_finiteDirichletTarget
10237    Nx Ny Nz hx hy hz hLocal
10238    (CanonicalPeriodicFiniteEHDirichletLimitAction Nx Ny Nz hx hy hz)
10239    (canonicalPeriodicFiniteEHDirichletLimitTarget Nx Ny Nz hx hy hz)
10240
10241/-- Residual form against the canonical finite EH/Dirichlet action. -/
10242theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_finiteEHDirichletLimit_residual_tendsto_zero
10243    {α : Type*} {l : Filter α}
10244    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10245    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10246    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
10247    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
10248      ∀ {n : ℕ}
10249        (spacing : α → ℝ)
10250        (probe :
10251          Fin n →
10252            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10253        (weight : α → Fin n → ℝ)
10254        (limitWeight : Fin n → ℝ),
10255        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
10256          Filter.Tendsto spacing l (nhds 0) →
10257            (∀ᶠ t : α in l, spacing t ≠ 0) →
10258              Filter.Tendsto
10259                (fun t : α =>
10260                  (∑ i : Fin n,
10261                    weight t i *
10262                      (reggeAction
10263                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10264                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10265                        (spacing t • probe i) /
10266                        ‖spacing t‖ ^ (2 : ℕ))) -
10267                    ∑ i : Fin n,
10268                      limitWeight i *
10269                        CanonicalPeriodicFiniteEHDirichletLimitAction Nx Ny Nz hx hy hz
10270                          (probe i))
10271                l (nhds 0) :=
10272  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_physicalLimit_residual_tendsto_zero_of_finiteDirichletTarget
10273    Nx Ny Nz hx hy hz hLocal
10274    (CanonicalPeriodicFiniteEHDirichletLimitAction Nx Ny Nz hx hy hz)
10275    (canonicalPeriodicFiniteEHDirichletLimitTarget Nx Ny Nz hx hy hz)
10276
10277/-- A supplied continuum Einstein-Hilbert integral value for the canonical
10278periodic Freudenthal finite-to-integral interface.  It is intentionally just a
10279real number here: the analytic work lives in the Riemann-sum hypothesis that
10280identifies finite EH/Dirichlet aggregates with this value. -/
10281abbrev CanonicalPeriodicContinuumEHIntegral := ℝ
10282
10283/-- The finite EH/Dirichlet aggregate associated to a fixed finite probe family
10284and a weight vector.  This is the object whose refinement-indexed versions are
10285expected to converge to the continuum EH integral. -/
10286def CanonicalPeriodicFiniteEHDirichletAggregate
10287    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10288    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10289    {n : ℕ}
10290    (probe :
10291      Fin n →
10292        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10293    (weight : Fin n → ℝ) : ℝ :=
10294  ∑ i : Fin n,
10295    weight i *
10296      CanonicalPeriodicFiniteEHDirichletLimitAction Nx Ny Nz hx hy hz
10297        (probe i)
10298
10299/-- If the finite mesh weights converge componentwise, the corresponding finite
10300EH/Dirichlet aggregates converge to the limiting weighted aggregate. -/
10301theorem canonicalPeriodicFiniteEHDirichletAggregate_tendsto_of_weights
10302    {α : Type*} {l : Filter α}
10303    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10304    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10305    {n : ℕ}
10306    (probe :
10307      Fin n →
10308        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10309    (weight : α → Fin n → ℝ)
10310    (limitWeight : Fin n → ℝ)
10311    (hWeight : ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) :
10312    Filter.Tendsto
10313      (fun t : α =>
10314        CanonicalPeriodicFiniteEHDirichletAggregate Nx Ny Nz hx hy hz probe (weight t))
10315      l
10316      (nhds
10317        (CanonicalPeriodicFiniteEHDirichletAggregate Nx Ny Nz hx hy hz probe limitWeight)) := by
10318  classical
10319  unfold CanonicalPeriodicFiniteEHDirichletAggregate
10320  simpa using
10321    (tendsto_finset_sum (Finset.univ : Finset (Fin n))
10322      (f := fun i (t : α) =>
10323        weight t i *
10324          CanonicalPeriodicFiniteEHDirichletLimitAction Nx Ny Nz hx hy hz (probe i))
10325      (a := fun i =>
10326        limitWeight i *
10327          CanonicalPeriodicFiniteEHDirichletLimitAction Nx Ny Nz hx hy hz (probe i))
10328      (by
10329        intro i _hi
10330        exact (hWeight i).mul tendsto_const_nhds))
10331
10332/-- Residual form against the variable finite EH/Dirichlet aggregate.  The
10333session-60 theorem compared full Regge to the limiting finite aggregate; this
10334version subtracts the mesh-weighted finite EH aggregate at the same refinement
10335index. -/
10336theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_finiteEHDirichletVariableAggregate_residual_tendsto_zero
10337    {α : Type*} {l : Filter α}
10338    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10339    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10340    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
10341    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
10342      ∀ {n : ℕ}
10343        (spacing : α → ℝ)
10344        (probe :
10345          Fin n →
10346            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10347        (weight : α → Fin n → ℝ)
10348        (limitWeight : Fin n → ℝ),
10349        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
10350          Filter.Tendsto spacing l (nhds 0) →
10351            (∀ᶠ t : α in l, spacing t ≠ 0) →
10352              Filter.Tendsto
10353                (fun t : α =>
10354                  (∑ i : Fin n,
10355                    weight t i *
10356                      (reggeAction
10357                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10358                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10359                        (spacing t • probe i) /
10360                        ‖spacing t‖ ^ (2 : ℕ))) -
10361                    CanonicalPeriodicFiniteEHDirichletAggregate
10362                      Nx Ny Nz hx hy hz probe (weight t))
10363                l (nhds 0) := by
10364  rcases
10365    canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_finiteEHDirichletLimit
10366      Nx Ny Nz hx hy hz hLocal with
10367    ⟨r, C, hr, hC, hFull⟩
10368  refine ⟨r, C, hr, hC, ?_⟩
10369  intro n spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
10370  have hFinite :
10371      Filter.Tendsto
10372        (fun t : α =>
10373          CanonicalPeriodicFiniteEHDirichletAggregate Nx Ny Nz hx hy hz probe (weight t))
10374        l
10375        (nhds
10376          (CanonicalPeriodicFiniteEHDirichletAggregate Nx Ny Nz hx hy hz probe limitWeight)) :=
10377    canonicalPeriodicFiniteEHDirichletAggregate_tendsto_of_weights
10378      Nx Ny Nz hx hy hz probe weight limitWeight hWeight
10379  have hFull' :=
10380    hFull spacing probe weight limitWeight hWeight hSpacing hSpacing_ne
10381  simpa [CanonicalPeriodicFiniteEHDirichletAggregate] using hFull'.sub hFinite
10382
10383/-- Riemann-sum target for the finite-to-integral bridge: the mesh-weighted
10384finite EH/Dirichlet aggregate converges to the supplied continuum EH integral.
10385This is the explicit analytic hypothesis needed before claiming a manifold
10386integral. -/
10387def CanonicalPeriodicFiniteEHDirichletToContinuumIntegralTarget
10388    {α : Type*} (l : Filter α)
10389    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10390    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10391    {n : ℕ}
10392    (probe :
10393      Fin n →
10394        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10395    (weight : α → Fin n → ℝ)
10396    (continuumIntegral : CanonicalPeriodicContinuumEHIntegral) : Prop :=
10397  Filter.Tendsto
10398    (fun t : α =>
10399      CanonicalPeriodicFiniteEHDirichletAggregate Nx Ny Nz hx hy hz probe (weight t))
10400    l
10401    (nhds continuumIntegral)
10402
10403/-- Stronger finite-integral identification at the limiting finite aggregate:
10404after the mesh weights converge, this equality is enough to supply the
10405finite-to-integral target above. -/
10406def CanonicalPeriodicFiniteEHDirichletLimitWeightIntegralTarget
10407    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10408    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10409    {n : ℕ}
10410    (probe :
10411      Fin n →
10412        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10413    (limitWeight : Fin n → ℝ)
10414    (continuumIntegral : CanonicalPeriodicContinuumEHIntegral) : Prop :=
10415  CanonicalPeriodicFiniteEHDirichletAggregate
10416    Nx Ny Nz hx hy hz probe limitWeight = continuumIntegral
10417
10418/-- Componentwise mesh-weight convergence plus identification of the limiting
10419finite EH/Dirichlet aggregate with the continuum integral supplies the
10420Riemann-sum target used by the session-61 bridge. -/
10421theorem canonicalPeriodicFiniteEHDirichletToContinuumIntegralTarget_of_limitWeightIntegralTarget
10422    {α : Type*} {l : Filter α}
10423    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10424    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10425    {n : ℕ}
10426    (probe :
10427      Fin n →
10428        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
10429    (weight : α → Fin n → ℝ)
10430    (limitWeight : Fin n → ℝ)
10431    (continuumIntegral : CanonicalPeriodicContinuumEHIntegral)
10432    (hWeight : ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i)))
10433    (hLimit :
10434      CanonicalPeriodicFiniteEHDirichletLimitWeightIntegralTarget
10435        Nx Ny Nz hx hy hz probe limitWeight continuumIntegral) :
10436    CanonicalPeriodicFiniteEHDirichletToContinuumIntegralTarget
10437      l Nx Ny Nz hx hy hz probe weight continuumIntegral := by
10438  have hAgg :=
10439    canonicalPeriodicFiniteEHDirichletAggregate_tendsto_of_weights
10440      Nx Ny Nz hx hy hz probe weight limitWeight hWeight
10441  have hEq :
10442      CanonicalPeriodicFiniteEHDirichletAggregate
10443        Nx Ny Nz hx hy hz probe limitWeight = continuumIntegral := by
10444    simpa [CanonicalPeriodicFiniteEHDirichletLimitWeightIntegralTarget] using hLimit
10445  rw [hEq] at hAgg
10446  exact hAgg
10447
10448/-- Refinement data for the finite-to-integral Track 1.B bridge.  The fields are
10449only the theorem-grade ingredients currently needed: a spacing schedule, finite
10450probe family, mesh weights with limiting weights, nonzero quadratic scaling, and
10451the Riemann-sum convergence to a supplied continuum EH integral. -/
10452structure CanonicalPeriodicFiniteEHDirichletIntegralRefinementData
10453    {α : Type*} (l : Filter α)
10454    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10455    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
10456  n : ℕ
10457  spacing : α → ℝ
10458  probe :
10459    Fin n →
10460      VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10461  weight : α → Fin n → ℝ
10462  limitWeight : Fin n → ℝ
10463  continuumIntegral : CanonicalPeriodicContinuumEHIntegral
10464  weight_tendsto :
10465    ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))
10466  spacing_tendsto_zero : Filter.Tendsto spacing l (nhds 0)
10467  spacing_eventually_ne_zero : ∀ᶠ t : α in l, spacing t ≠ 0
10468  finite_to_integral :
10469    CanonicalPeriodicFiniteEHDirichletToContinuumIntegralTarget
10470      l Nx Ny Nz hx hy hz probe weight continuumIntegral
10471
10472/-- A refinement package whose integral identification is stated at the limiting
10473finite EH/Dirichlet aggregate.  This is often the more usable theorem shape:
10474prove the mesh weights converge, then prove the limiting finite aggregate is
10475the desired continuum integral. -/
10476structure CanonicalPeriodicFiniteEHDirichletLimitWeightRefinementData
10477    {α : Type*} (l : Filter α)
10478    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10479    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
10480  n : ℕ
10481  spacing : α → ℝ
10482  probe :
10483    Fin n →
10484      VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10485  weight : α → Fin n → ℝ
10486  limitWeight : Fin n → ℝ
10487  continuumIntegral : CanonicalPeriodicContinuumEHIntegral
10488  weight_tendsto :
10489    ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))
10490  spacing_tendsto_zero : Filter.Tendsto spacing l (nhds 0)
10491  spacing_eventually_ne_zero : ∀ᶠ t : α in l, spacing t ≠ 0
10492  limit_weight_integral :
10493    CanonicalPeriodicFiniteEHDirichletLimitWeightIntegralTarget
10494      Nx Ny Nz hx hy hz probe limitWeight continuumIntegral
10495
10496/-- Convert the limiting-aggregate package into the explicit Riemann-sum package
10497by applying finite EH aggregate convergence of the mesh weights. -/
10498def CanonicalPeriodicFiniteEHDirichletLimitWeightRefinementData.toIntegralRefinementData
10499    {α : Type*} {l : Filter α}
10500    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10501    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10502    (D : CanonicalPeriodicFiniteEHDirichletLimitWeightRefinementData l Nx Ny Nz hx hy hz) :
10503    CanonicalPeriodicFiniteEHDirichletIntegralRefinementData l Nx Ny Nz hx hy hz where
10504  n := D.n
10505  spacing := D.spacing
10506  probe := D.probe
10507  weight := D.weight
10508  limitWeight := D.limitWeight
10509  continuumIntegral := D.continuumIntegral
10510  weight_tendsto := D.weight_tendsto
10511  spacing_tendsto_zero := D.spacing_tendsto_zero
10512  spacing_eventually_ne_zero := D.spacing_eventually_ne_zero
10513  finite_to_integral :=
10514    canonicalPeriodicFiniteEHDirichletToContinuumIntegralTarget_of_limitWeightIntegralTarget
10515      Nx Ny Nz hx hy hz D.probe D.weight D.limitWeight D.continuumIntegral
10516      D.weight_tendsto D.limit_weight_integral
10517
10518/-- Finite-to-integral bridge theorem for the current Track 1.B finite EH layer.
10519Given a refinement data package whose finite EH/Dirichlet aggregates converge
10520to a supplied continuum integral, the normalized full nonlinear Regge finite
10521aggregates converge to the same continuum integral.  This does not assert the
10522final manifold EH theorem; it composes the closed finite Regge theorem with the
10523explicit Riemann-sum hypothesis. -/
10524theorem CanonicalPeriodicFiniteEHDirichletIntegralRefinementData.fullRegge_tendsto_continuumIntegral
10525    {α : Type*} {l : Filter α}
10526    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10527    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10528    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
10529    (D : CanonicalPeriodicFiniteEHDirichletIntegralRefinementData l Nx Ny Nz hx hy hz) :
10530    Filter.Tendsto
10531      (fun t : α =>
10532        ∑ i : Fin D.n,
10533          D.weight t i *
10534            (reggeAction
10535              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10536              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10537              (D.spacing t • D.probe i) /
10538              ‖D.spacing t‖ ^ (2 : ℕ)))
10539      l
10540      (nhds D.continuumIntegral) := by
10541  rcases
10542    canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_finiteEHDirichletVariableAggregate_residual_tendsto_zero
10543      Nx Ny Nz hx hy hz hLocal with
10544    ⟨_r, _C, _hr, _hC, hResidual⟩
10545  have hRes :=
10546    hResidual D.spacing D.probe D.weight D.limitWeight
10547      D.weight_tendsto D.spacing_tendsto_zero D.spacing_eventually_ne_zero
10548  have hInt : Filter.Tendsto
10549      (fun t : α =>
10550        CanonicalPeriodicFiniteEHDirichletAggregate
10551          Nx Ny Nz hx hy hz D.probe (D.weight t))
10552      l
10553      (nhds D.continuumIntegral) :=
10554    D.finite_to_integral
10555  simpa [CanonicalPeriodicFiniteEHDirichletAggregate, sub_add_cancel] using hRes.add hInt
10556
10557/-- Finite-to-integral bridge from the limiting-aggregate data package.  This is
10558the same full-Regge conclusion as the explicit Riemann-sum package, but its
10559analytic input is split into mesh-weight convergence plus a limiting finite
10560aggregate equality. -/
10561theorem CanonicalPeriodicFiniteEHDirichletLimitWeightRefinementData.fullRegge_tendsto_continuumIntegral
10562    {α : Type*} {l : Filter α}
10563    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10564    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10565    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
10566    (D : CanonicalPeriodicFiniteEHDirichletLimitWeightRefinementData l Nx Ny Nz hx hy hz) :
10567    Filter.Tendsto
10568      (fun t : α =>
10569        ∑ i : Fin D.n,
10570          D.weight t i *
10571            (reggeAction
10572              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10573              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10574              (D.spacing t • D.probe i) /
10575              ‖D.spacing t‖ ^ (2 : ℕ)))
10576      l
10577      (nhds D.continuumIntegral) :=
10578  CanonicalPeriodicFiniteEHDirichletIntegralRefinementData.fullRegge_tendsto_continuumIntegral
10579    Nx Ny Nz hx hy hz hLocal
10580    (CanonicalPeriodicFiniteEHDirichletLimitWeightRefinementData.toIntegralRefinementData
10581      Nx Ny Nz hx hy hz D)
10582
10583/-- A named finite EH/Dirichlet quadrature rule on the canonical periodic
10584Freudenthal torus: a finite probe family plus fixed quadrature weights.  This is
10585still finite data, not a manifold integral. -/
10586structure CanonicalPeriodicFiniteEHDirichletQuadratureRule
10587    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10588    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
10589  n : ℕ
10590  probe :
10591    Fin n →
10592      VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10593  weight : Fin n → ℝ
10594
10595/-- The finite continuum-integral proxy represented by a quadrature rule.  It is
10596definitionally the finite EH/Dirichlet aggregate for the rule's probes and
10597weights. -/
10598def CanonicalPeriodicFiniteEHDirichletQuadratureRule.continuumIntegral
10599    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10600    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10601    (Q : CanonicalPeriodicFiniteEHDirichletQuadratureRule Nx Ny Nz hx hy hz) :
10602    CanonicalPeriodicContinuumEHIntegral :=
10603  CanonicalPeriodicFiniteEHDirichletAggregate
10604    Nx Ny Nz hx hy hz Q.probe Q.weight
10605
10606/-- The named finite quadrature proxy supplies the limiting-aggregate integral
10607target by definition. -/
10608theorem CanonicalPeriodicFiniteEHDirichletQuadratureRule.limitWeightIntegralTarget
10609    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10610    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10611    (Q : CanonicalPeriodicFiniteEHDirichletQuadratureRule Nx Ny Nz hx hy hz) :
10612    CanonicalPeriodicFiniteEHDirichletLimitWeightIntegralTarget
10613      Nx Ny Nz hx hy hz Q.probe Q.weight
10614      (Q.continuumIntegral Nx Ny Nz hx hy hz) := by
10615  rfl
10616
10617/-- Refinement data toward a named finite EH/Dirichlet quadrature rule.  The
10618mesh-dependent weights converge to the rule's weights; the quadrature rule
10619itself supplies the finite integral proxy. -/
10620structure CanonicalPeriodicFiniteEHDirichletQuadratureRefinementData
10621    {α : Type*} (l : Filter α)
10622    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10623    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
10624  rule : CanonicalPeriodicFiniteEHDirichletQuadratureRule Nx Ny Nz hx hy hz
10625  spacing : α → ℝ
10626  weight : α → Fin rule.n → ℝ
10627  weight_tendsto :
10628    ∀ i : Fin rule.n, Filter.Tendsto (fun t : α => weight t i) l (nhds (rule.weight i))
10629  spacing_tendsto_zero : Filter.Tendsto spacing l (nhds 0)
10630  spacing_eventually_ne_zero : ∀ᶠ t : α in l, spacing t ≠ 0
10631
10632/-- Convert a named quadrature refinement package into the limit-weight package
10633from session 62. -/
10634def CanonicalPeriodicFiniteEHDirichletQuadratureRefinementData.toLimitWeightRefinementData
10635    {α : Type*} {l : Filter α}
10636    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10637    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10638    (D : CanonicalPeriodicFiniteEHDirichletQuadratureRefinementData l Nx Ny Nz hx hy hz) :
10639    CanonicalPeriodicFiniteEHDirichletLimitWeightRefinementData l Nx Ny Nz hx hy hz where
10640  n := D.rule.n
10641  spacing := D.spacing
10642  probe := D.rule.probe
10643  weight := D.weight
10644  limitWeight := D.rule.weight
10645  continuumIntegral := D.rule.continuumIntegral Nx Ny Nz hx hy hz
10646  weight_tendsto := D.weight_tendsto
10647  spacing_tendsto_zero := D.spacing_tendsto_zero
10648  spacing_eventually_ne_zero := D.spacing_eventually_ne_zero
10649  limit_weight_integral :=
10650    D.rule.limitWeightIntegralTarget Nx Ny Nz hx hy hz
10651
10652/-- Normalized full nonlinear Regge aggregates converge to the finite
10653EH/Dirichlet quadrature proxy when the mesh-dependent weights converge to the
10654rule's weights.  This is a named finite/quadrature theorem, not the final
10655manifold Einstein-Hilbert limit. -/
10656theorem CanonicalPeriodicFiniteEHDirichletQuadratureRefinementData.fullRegge_tendsto_quadratureIntegral
10657    {α : Type*} {l : Filter α}
10658    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10659    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10660    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
10661    (D : CanonicalPeriodicFiniteEHDirichletQuadratureRefinementData l Nx Ny Nz hx hy hz) :
10662    Filter.Tendsto
10663      (fun t : α =>
10664        ∑ i : Fin D.rule.n,
10665          D.weight t i *
10666            (reggeAction
10667              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10668              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10669              (D.spacing t • D.rule.probe i) /
10670              ‖D.spacing t‖ ^ (2 : ℕ)))
10671      l
10672      (nhds (D.rule.continuumIntegral Nx Ny Nz hx hy hz)) :=
10673  CanonicalPeriodicFiniteEHDirichletLimitWeightRefinementData.fullRegge_tendsto_continuumIntegral
10674    Nx Ny Nz hx hy hz hLocal
10675    (CanonicalPeriodicFiniteEHDirichletQuadratureRefinementData.toLimitWeightRefinementData
10676      Nx Ny Nz hx hy hz D)
10677
10678/-- Geometric quadrature over the actual typed periodic Freudenthal tetrahedra.
10679The weights are carried on `PeriodicTet` itself, then encoded through
10680`tetFinEquiv` only when feeding the finite quadrature theorem. -/
10681structure CanonicalPeriodicTetGeometricQuadratureRule
10682    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10683    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
10684  tetProbe :
10685    PeriodicTet Nx Ny Nz →
10686      VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10687  tetVolumeWeight : PeriodicTet Nx Ny Nz → ℝ
10688
10689/-- Encode a typed periodic-tetrahedron quadrature rule as the finite
10690`Fin n` quadrature rule used by the current Track 1.B interface. -/
10691def CanonicalPeriodicTetGeometricQuadratureRule.toFiniteQuadratureRule
10692    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10693    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10694    (Q : CanonicalPeriodicTetGeometricQuadratureRule Nx Ny Nz hx hy hz) :
10695    CanonicalPeriodicFiniteEHDirichletQuadratureRule Nx Ny Nz hx hy hz where
10696  n := Fintype.card (PeriodicTet Nx Ny Nz)
10697  probe := fun τ => Q.tetProbe (tetFinEquiv Nx Ny Nz τ)
10698  weight := fun τ => Q.tetVolumeWeight (tetFinEquiv Nx Ny Nz τ)
10699
10700/-- The finite EH/Dirichlet integral proxy for a typed periodic-tetrahedron
10701quadrature rule. -/
10702def CanonicalPeriodicTetGeometricQuadratureRule.continuumIntegral
10703    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10704    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10705    (Q : CanonicalPeriodicTetGeometricQuadratureRule Nx Ny Nz hx hy hz) :
10706    CanonicalPeriodicContinuumEHIntegral :=
10707  (Q.toFiniteQuadratureRule Nx Ny Nz hx hy hz).continuumIntegral Nx Ny Nz hx hy hz
10708
10709/-- Typed periodic-tetrahedron quadrature supplies the finite limit-weight
10710integral target after applying `tetFinEquiv`. -/
10711theorem CanonicalPeriodicTetGeometricQuadratureRule.limitWeightIntegralTarget
10712    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10713    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10714    (Q : CanonicalPeriodicTetGeometricQuadratureRule Nx Ny Nz hx hy hz) :
10715    CanonicalPeriodicFiniteEHDirichletLimitWeightIntegralTarget
10716      Nx Ny Nz hx hy hz
10717      (fun τ => Q.tetProbe (tetFinEquiv Nx Ny Nz τ))
10718      (fun τ => Q.tetVolumeWeight (tetFinEquiv Nx Ny Nz τ))
10719      (Q.continuumIntegral Nx Ny Nz hx hy hz) := by
10720  rfl
10721
10722/-- Refinement data toward a typed periodic-tetrahedron quadrature rule.  The
10723mesh-dependent weights are expressed on `PeriodicTet`, not an anonymous finite
10724index. -/
10725structure CanonicalPeriodicTetGeometricQuadratureRefinementData
10726    {α : Type*} (l : Filter α)
10727    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10728    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
10729  rule : CanonicalPeriodicTetGeometricQuadratureRule Nx Ny Nz hx hy hz
10730  spacing : α → ℝ
10731  tetWeight : α → PeriodicTet Nx Ny Nz → ℝ
10732  tetWeight_tendsto :
10733    ∀ τ : PeriodicTet Nx Ny Nz,
10734      Filter.Tendsto (fun t : α => tetWeight t τ) l (nhds (rule.tetVolumeWeight τ))
10735  spacing_tendsto_zero : Filter.Tendsto spacing l (nhds 0)
10736  spacing_eventually_ne_zero : ∀ᶠ t : α in l, spacing t ≠ 0
10737
10738/-- Encode typed tetrahedron refinement data as the finite quadrature refinement
10739data used by the current theorem. -/
10740def CanonicalPeriodicTetGeometricQuadratureRefinementData.toFiniteQuadratureRefinementData
10741    {α : Type*} {l : Filter α}
10742    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10743    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10744    (D : CanonicalPeriodicTetGeometricQuadratureRefinementData l Nx Ny Nz hx hy hz) :
10745    CanonicalPeriodicFiniteEHDirichletQuadratureRefinementData l Nx Ny Nz hx hy hz where
10746  rule := D.rule.toFiniteQuadratureRule Nx Ny Nz hx hy hz
10747  spacing := D.spacing
10748  weight := fun t τ => D.tetWeight t (tetFinEquiv Nx Ny Nz τ)
10749  weight_tendsto := by
10750    intro τ
10751    exact D.tetWeight_tendsto (tetFinEquiv Nx Ny Nz τ)
10752  spacing_tendsto_zero := D.spacing_tendsto_zero
10753  spacing_eventually_ne_zero := D.spacing_eventually_ne_zero
10754
10755/-- Full-Regge convergence to the typed periodic-tetrahedron finite quadrature
10756proxy.  This gives the abstract quadrature theorem actual periodic
10757Freudenthal-tetrahedron indices, while still remaining finite. -/
10758theorem CanonicalPeriodicTetGeometricQuadratureRefinementData.fullRegge_tendsto_geometricQuadratureIntegral
10759    {α : Type*} {l : Filter α}
10760    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10761    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10762    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
10763    (D : CanonicalPeriodicTetGeometricQuadratureRefinementData l Nx Ny Nz hx hy hz) :
10764    Filter.Tendsto
10765      (fun t : α =>
10766        ∑ τ : Fin (Fintype.card (PeriodicTet Nx Ny Nz)),
10767          D.tetWeight t (tetFinEquiv Nx Ny Nz τ) *
10768            (reggeAction
10769              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10770              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10771              (D.spacing t • D.rule.tetProbe (tetFinEquiv Nx Ny Nz τ)) /
10772              ‖D.spacing t‖ ^ (2 : ℕ)))
10773      l
10774      (nhds (D.rule.continuumIntegral Nx Ny Nz hx hy hz)) :=
10775  CanonicalPeriodicFiniteEHDirichletQuadratureRefinementData.fullRegge_tendsto_quadratureIntegral
10776    Nx Ny Nz hx hy hz hLocal
10777    (CanonicalPeriodicTetGeometricQuadratureRefinementData.toFiniteQuadratureRefinementData
10778      Nx Ny Nz hx hy hz D)
10779
10780/-- Canonical Freudenthal six-tet volume weight: each tetrahedron in a cubic
10781cell receives one sixth of the cell-volume weight. -/
10782def canonicalPeriodicFreudenthalTetVolumeWeight
10783    (Nx Ny Nz : ℕ) (_cellVolume : ℝ)
10784    (_τ : PeriodicTet Nx Ny Nz) : ℝ :=
10785  _cellVolume / 6
10786
10787theorem canonicalPeriodicFreudenthalTetVolumeWeight_nonneg
10788    (Nx Ny Nz : ℕ) (cellVolume : ℝ)
10789    (hCell : 0 ≤ cellVolume)
10790    (τ : PeriodicTet Nx Ny Nz) :
10791    0 ≤ canonicalPeriodicFreudenthalTetVolumeWeight Nx Ny Nz cellVolume τ := by
10792  unfold canonicalPeriodicFreudenthalTetVolumeWeight
10793  exact div_nonneg hCell (by norm_num : (0 : ℝ) ≤ 6)
10794
10795/-- If the cell-volume weights converge, then the induced six-tet
10796Freudenthal tetrahedron weights converge. -/
10797theorem canonicalPeriodicFreudenthalTetVolumeWeight_tendsto
10798    {α : Type*} {l : Filter α}
10799    (Nx Ny Nz : ℕ)
10800    (cellVolume : α → ℝ)
10801    (limitCellVolume : ℝ)
10802    (hCellVolume :
10803      Filter.Tendsto cellVolume l (nhds limitCellVolume)) :
10804    ∀ τ : PeriodicTet Nx Ny Nz,
10805      Filter.Tendsto
10806        (fun t : α =>
10807          canonicalPeriodicFreudenthalTetVolumeWeight Nx Ny Nz (cellVolume t) τ)
10808        l
10809        (nhds
10810          (canonicalPeriodicFreudenthalTetVolumeWeight
10811            Nx Ny Nz limitCellVolume τ)) := by
10812  intro τ
10813  unfold canonicalPeriodicFreudenthalTetVolumeWeight
10814  simpa [div_eq_mul_inv] using hCellVolume.mul tendsto_const_nhds
10815
10816/-- The canonical six-tet cell-volume quadrature rule over typed periodic
10817Freudenthal tetrahedra.  The only geometric weight formula in this finite layer
10818is the Freudenthal cell split `cellVolume / 6`; the probe assignment remains the
10819supplied field being quadrature-sampled. -/
10820def canonicalPeriodicTetSixTetVolumeQuadratureRule
10821    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10822    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10823    (cellVolume : ℝ)
10824    (tetProbe :
10825      PeriodicTet Nx Ny Nz →
10826        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K) :
10827    CanonicalPeriodicTetGeometricQuadratureRule Nx Ny Nz hx hy hz where
10828  tetProbe := tetProbe
10829  tetVolumeWeight :=
10830    canonicalPeriodicFreudenthalTetVolumeWeight Nx Ny Nz cellVolume
10831
10832/-- Refinement data for the canonical six-tet volume quadrature rule.  The
10833mesh-dependent cell-volume weights converge to the limiting cell-volume weight;
10834tetrahedron weights are then fixed by the Freudenthal `1/6` split. -/
10835structure CanonicalPeriodicTetSixTetVolumeQuadratureRefinementData
10836    {α : Type*} (l : Filter α)
10837    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10838    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) where
10839  limitCellVolume : ℝ
10840  cellVolume : α → ℝ
10841  cellVolume_tendsto :
10842    Filter.Tendsto cellVolume l (nhds limitCellVolume)
10843  tetProbe :
10844    PeriodicTet Nx Ny Nz →
10845      VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10846  spacing : α → ℝ
10847  spacing_tendsto_zero : Filter.Tendsto spacing l (nhds 0)
10848  spacing_eventually_ne_zero : ∀ᶠ t : α in l, spacing t ≠ 0
10849
10850/-- Convert canonical six-tet volume refinement data into the typed geometric
10851quadrature refinement package. -/
10852def CanonicalPeriodicTetSixTetVolumeQuadratureRefinementData.toTetGeometricQuadratureRefinementData
10853    {α : Type*} {l : Filter α}
10854    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10855    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10856    (D : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementData l Nx Ny Nz hx hy hz) :
10857    CanonicalPeriodicTetGeometricQuadratureRefinementData l Nx Ny Nz hx hy hz where
10858  rule :=
10859    canonicalPeriodicTetSixTetVolumeQuadratureRule
10860      Nx Ny Nz hx hy hz D.limitCellVolume D.tetProbe
10861  spacing := D.spacing
10862  tetWeight := fun t =>
10863    canonicalPeriodicFreudenthalTetVolumeWeight Nx Ny Nz (D.cellVolume t)
10864  tetWeight_tendsto :=
10865    canonicalPeriodicFreudenthalTetVolumeWeight_tendsto
10866      Nx Ny Nz D.cellVolume D.limitCellVolume D.cellVolume_tendsto
10867  spacing_tendsto_zero := D.spacing_tendsto_zero
10868  spacing_eventually_ne_zero := D.spacing_eventually_ne_zero
10869
10870/-- Full-Regge convergence to the finite quadrature proxy with the canonical
10871Freudenthal `cellVolume / 6` tetrahedron weights.  This is the first
10872geometrically weighted version of the finite quadrature theorem; it is not yet
10873a varying-cardinality or manifold integral theorem. -/
10874theorem CanonicalPeriodicTetSixTetVolumeQuadratureRefinementData.fullRegge_tendsto_sixTetVolumeQuadratureIntegral
10875    {α : Type*} {l : Filter α}
10876    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
10877    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
10878    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
10879    (D : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementData l Nx Ny Nz hx hy hz) :
10880    Filter.Tendsto
10881      (fun t : α =>
10882        ∑ τ : Fin (Fintype.card (PeriodicTet Nx Ny Nz)),
10883          canonicalPeriodicFreudenthalTetVolumeWeight
10884              Nx Ny Nz (D.cellVolume t) (tetFinEquiv Nx Ny Nz τ) *
10885            (reggeAction
10886              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
10887              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
10888              (D.spacing t • D.tetProbe (tetFinEquiv Nx Ny Nz τ)) /
10889              ‖D.spacing t‖ ^ (2 : ℕ)))
10890      l
10891      (nhds
10892        ((canonicalPeriodicTetSixTetVolumeQuadratureRule
10893          Nx Ny Nz hx hy hz D.limitCellVolume D.tetProbe).continuumIntegral
10894            Nx Ny Nz hx hy hz)) :=
10895  CanonicalPeriodicTetGeometricQuadratureRefinementData.fullRegge_tendsto_geometricQuadratureIntegral
10896    Nx Ny Nz hx hy hz hLocal
10897    (CanonicalPeriodicTetSixTetVolumeQuadratureRefinementData.toTetGeometricQuadratureRefinementData
10898      Nx Ny Nz hx hy hz D)
10899
10900/-- One slice of a varying-cardinality periodic Freudenthal refinement family.
10901Each slice carries its own side lengths, nonzero witnesses, local nonlinear
10902correspondence, and finite six-tet quadrature data. -/
10903structure CanonicalPeriodicTetSixTetVolumeQuadratureSlice
10904    {α : Type*} (l : Filter α) where
10905  Nx : ℕ
10906  Ny : ℕ
10907  Nz : ℕ
10908  instNx : NeZero Nx
10909  instNy : NeZero Ny
10910  instNz : NeZero Nz
10911  hx : 2 < Nx
10912  hy : 2 < Ny
10913  hz : 2 < Nz
10914  hLocal :
10915    letI : NeZero Nx := instNx
10916    letI : NeZero Ny := instNy
10917    letI : NeZero Nz := instNz
10918    CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz
10919  data :
10920    letI : NeZero Nx := instNx
10921    letI : NeZero Ny := instNy
10922    letI : NeZero Nz := instNz
10923    CanonicalPeriodicTetSixTetVolumeQuadratureRefinementData
10924      l Nx Ny Nz hx hy hz
10925
10926/-- The normalized full-Regge aggregate for a varying-cardinality slice. -/
10927noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.fullReggeAggregate
10928    {α : Type*} {l : Filter α}
10929    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) : α → ℝ := by
10930  letI : NeZero S.Nx := S.instNx
10931  letI : NeZero S.Ny := S.instNy
10932  letI : NeZero S.Nz := S.instNz
10933  exact
10934    fun t : α =>
10935      ∑ τ : Fin (Fintype.card (PeriodicTet S.Nx S.Ny S.Nz)),
10936        canonicalPeriodicFreudenthalTetVolumeWeight
10937            S.Nx S.Ny S.Nz (S.data.cellVolume t)
10938            (tetFinEquiv S.Nx S.Ny S.Nz τ) *
10939          (reggeAction
10940            (canonicalEncodedPeriodicFreudenthalTorus S.Nx S.Ny S.Nz S.hx S.hy S.hz).K
10941            (canonicalEncodedPeriodicFreudenthalTorus S.Nx S.Ny S.Nz S.hx S.hy S.hz).hK
10942            (S.data.spacing t • S.data.tetProbe (tetFinEquiv S.Nx S.Ny S.Nz τ)) /
10943            S.data.spacing t ^ (2 : ℕ))
10944
10945/-- The finite six-tet quadrature proxy attached to a varying-cardinality
10946slice. -/
10947noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.quadratureIntegral
10948    {α : Type*} {l : Filter α}
10949    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) : ℝ := by
10950  letI : NeZero S.Nx := S.instNx
10951  letI : NeZero S.Ny := S.instNy
10952  letI : NeZero S.Nz := S.instNz
10953  exact
10954    ((canonicalPeriodicTetSixTetVolumeQuadratureRule
10955      S.Nx S.Ny S.Nz S.hx S.hy S.hz
10956      S.data.limitCellVolume S.data.tetProbe).continuumIntegral
10957        S.Nx S.Ny S.Nz S.hx S.hy S.hz)
10958
10959/-- Every varying-cardinality slice feeds the finite six-tet volume quadrature
10960theorem.  This theorem is per-slice; it does not yet compare different
10961cardinalities in one limit. -/
10962theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.fullRegge_tendsto_quadratureIntegral
10963    {α : Type*} {l : Filter α}
10964    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) :
10965    Filter.Tendsto
10966      (S.fullReggeAggregate)
10967      l
10968      (nhds S.quadratureIntegral) := by
10969  letI : NeZero S.Nx := S.instNx
10970  letI : NeZero S.Ny := S.instNy
10971  letI : NeZero S.Nz := S.instNz
10972  simpa [CanonicalPeriodicTetSixTetVolumeQuadratureSlice.fullReggeAggregate,
10973    CanonicalPeriodicTetSixTetVolumeQuadratureSlice.quadratureIntegral] using
10974    CanonicalPeriodicTetSixTetVolumeQuadratureRefinementData.fullRegge_tendsto_sixTetVolumeQuadratureIntegral
10975      S.Nx S.Ny S.Nz S.hx S.hy S.hz S.hLocal S.data
10976
10977/-- A varying-cardinality family is a collection of finite six-tet quadrature
10978slices indexed by a refinement parameter type. -/
10979structure CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily
10980    {α : Type*} (l : Filter α) (ρ : Type*) where
10981  slice : ρ → CanonicalPeriodicTetSixTetVolumeQuadratureSlice l
10982
10983/-- Each slice of a varying-cardinality family inherits the finite six-tet
10984full-Regge convergence theorem.  The next analytic step is to put a filter on
10985the `ρ`-index and compare these slice limits across cardinalities. -/
10986theorem CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily.slice_fullRegge_tendsto_quadratureIntegral
10987    {α ρ : Type*} {l : Filter α}
10988    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ)
10989    (r : ρ) :
10990    Filter.Tendsto
10991      ((F.slice r).fullReggeAggregate)
10992      l
10993      (nhds ((F.slice r).quadratureIntegral)) :=
10994  CanonicalPeriodicTetSixTetVolumeQuadratureSlice.fullRegge_tendsto_quadratureIntegral
10995    (F.slice r)
10996
10997/-- Cross-cardinality finite-to-integral target for a varying-cardinality
10998six-tet quadrature family.  It compares the finite quadrature proxies attached
10999to each slice along a refinement-index filter. -/
11000def CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityTarget
11001    {α ρ : Type*} {l : Filter α}
11002    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ)
11003    (refinementFilter : Filter ρ)
11004    (continuumIntegral : ℝ) : Prop :=
11005  Filter.Tendsto
11006    (fun r : ρ => (F.slice r).quadratureIntegral)
11007    refinementFilter
11008    (nhds continuumIntegral)
11009
11010/-- Cross-cardinality data: every finite slice has the full-Regge-to-quadrature
11011theorem, and the finite quadrature proxies converge along the refinement-index
11012filter to a supplied continuum integral.  This is a staged interface, not a
11013single product-filter or uniform convergence theorem. -/
11014structure CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData
11015    {α ρ : Type*} (l : Filter α) where
11016  family : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ
11017  refinementFilter : Filter ρ
11018  continuumIntegral : ℝ
11019  quadrature_tendsto :
11020    CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityTarget
11021      family refinementFilter continuumIntegral
11022
11023/-- The per-slice full-Regge convergence supplied by cross-cardinality data. -/
11024theorem CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData.slice_fullRegge_tendsto_quadratureIntegral
11025    {α ρ : Type*} {l : Filter α}
11026    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData l)
11027    (r : ρ) :
11028    Filter.Tendsto
11029      ((D.family.slice r).fullReggeAggregate)
11030      l
11031      (nhds ((D.family.slice r).quadratureIntegral)) :=
11032  D.family.slice_fullRegge_tendsto_quadratureIntegral r
11033
11034/-- The cross-cardinality quadrature convergence supplied by the data package. -/
11035theorem CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData.quadratureIntegral_tendsto_continuum
11036    {α ρ : Type*} {l : Filter α}
11037    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData l) :
11038    Filter.Tendsto
11039      (fun r : ρ => (D.family.slice r).quadratureIntegral)
11040      D.refinementFilter
11041      (nhds D.continuumIntegral) :=
11042  D.quadrature_tendsto
11043
11044/-- Staged cross-cardinality conclusion: finite full-Regge aggregates converge
11045to each slice's finite quadrature proxy, and those proxies converge along the
11046refinement-index filter to the supplied continuum integral.  A future theorem
11047must add uniformity or a product-filter argument before collapsing this staged
11048statement into one global limit. -/
11049theorem CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData.staged_fullRegge_to_continuum
11050    {α ρ : Type*} {l : Filter α}
11051    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData l) :
11052    (∀ r : ρ,
11053      Filter.Tendsto
11054        ((D.family.slice r).fullReggeAggregate)
11055        l
11056        (nhds ((D.family.slice r).quadratureIntegral))) ∧
11057      Filter.Tendsto
11058        (fun r : ρ => (D.family.slice r).quadratureIntegral)
11059        D.refinementFilter
11060        (nhds D.continuumIntegral) := by
11061  exact ⟨
11062    fun r => D.slice_fullRegge_tendsto_quadratureIntegral r,
11063    D.quadratureIntegral_tendsto_continuum⟩
11064
11065/-- Product-indexed full-Regge aggregate for a varying-cardinality family.  The
11066first coordinate chooses the finite cardinality slice; the second coordinate is
11067the within-slice refinement parameter. -/
11068noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11069    {α ρ : Type*} {l : Filter α}
11070    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ) :
11071    ρ × α → ℝ :=
11072  fun p => ((F.slice p.1).fullReggeAggregate) p.2
11073
11074/-- Product-indexed finite quadrature proxy for a varying-cardinality family. -/
11075noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral
11076    {α ρ : Type*} {l : Filter α}
11077    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ) :
11078    ρ × α → ℝ :=
11079  fun p => (F.slice p.1).quadratureIntegral
11080
11081/-- Uniform two-scale residual target.  This is the extra hypothesis needed to
11082collapse the staged cross-cardinality statement into one product-filter limit:
11083the full-Regge-to-quadrature residual must vanish on the product filter, not
11084merely on each fixed slice. -/
11085def CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget
11086    {α ρ : Type*} {l : Filter α}
11087    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ)
11088    (refinementFilter : Filter ρ) : Prop :=
11089  Filter.Tendsto
11090    (fun p : ρ × α =>
11091      CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate F p -
11092        CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral F p)
11093    (refinementFilter ×ˢ l)
11094    (nhds 0)
11095
11096/-- A bounded-envelope criterion for the product uniform residual target.  It
11097is enough to bound the absolute full-Regge-to-quadrature residual by an envelope
11098that tends to zero on the product filter. -/
11099theorem canonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget_of_abs_bound
11100    {α ρ : Type*} {l : Filter α}
11101    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ)
11102    (refinementFilter : Filter ρ)
11103    (envelope : ρ × α → ℝ)
11104    (hEnvelope :
11105      Filter.Tendsto envelope (refinementFilter ×ˢ l : Filter (ρ × α)) (nhds 0))
11106    (hBound :
11107      ∀ᶠ p : ρ × α in (refinementFilter ×ˢ l),
11108        |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate F p -
11109          CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral F p| ≤
11110          envelope p) :
11111    CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget
11112      F refinementFilter := by
11113  apply tendsto_iff_dist_tendsto_zero.mpr
11114  have hAbs :
11115      Filter.Tendsto
11116        (fun p : ρ × α =>
11117          |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate F p -
11118            CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral F p|)
11119        (refinementFilter ×ˢ l)
11120        (nhds 0) := by
11121    exact squeeze_zero' (Filter.Eventually.of_forall (fun p => abs_nonneg _)) hBound hEnvelope
11122  simpa [
11123    CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget,
11124    Real.dist_eq,
11125    sub_zero] using hAbs
11126
11127/-- Cross-slice envelope criterion for the product uniform residual target.  If
11128one envelope depending only on the within-slice refinement parameter controls
11129every slice along the product filter, then the residual is uniform in the
11130cardinality index. -/
11131theorem canonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget_of_snd_abs_bound
11132    {α ρ : Type*} {l : Filter α}
11133    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ)
11134    (refinementFilter : Filter ρ)
11135    (envelope : α → ℝ)
11136    (hEnvelope : Filter.Tendsto envelope l (nhds 0))
11137    (hBound :
11138      ∀ᶠ p : ρ × α in (refinementFilter ×ˢ l),
11139        |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate F p -
11140          CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral F p| ≤
11141          envelope p.2) :
11142    CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget
11143      F refinementFilter :=
11144  canonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget_of_abs_bound
11145    F refinementFilter (fun p : ρ × α => envelope p.2)
11146    (hEnvelope.comp
11147      (Filter.tendsto_snd :
11148        Filter.Tendsto (Prod.snd : ρ × α → α)
11149          (refinementFilter ×ˢ l) l))
11150    hBound
11151
11152/-- Global cross-slice envelope criterion.  A pointwise bound for all slice
11153indices and all within-slice refinement parameters gives the eventual product
11154bound required by the cross-slice envelope theorem. -/
11155theorem canonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget_of_forall_snd_abs_bound
11156    {α ρ : Type*} {l : Filter α}
11157    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ)
11158    (refinementFilter : Filter ρ)
11159    (envelope : α → ℝ)
11160    (hEnvelope : Filter.Tendsto envelope l (nhds 0))
11161    (hBound :
11162      ∀ (r : ρ) (t : α),
11163        |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate F (r, t) -
11164          CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral F (r, t)| ≤
11165          envelope t) :
11166    CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget
11167      F refinementFilter :=
11168  canonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget_of_snd_abs_bound
11169    F refinementFilter envelope hEnvelope
11170    (Filter.Eventually.of_forall (fun p : ρ × α => hBound p.1 p.2))
11171
11172/-- Product-filter bridge from uniform residual plus cross-cardinality
11173quadrature convergence to a single continuum limit for the full nonlinear
11174Regge aggregate. -/
11175theorem canonicalPeriodicTetSixTetVolumeQuadratureProduct_fullRegge_tendsto_continuum
11176    {α ρ : Type*} {l : Filter α}
11177    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ)
11178    (refinementFilter : Filter ρ)
11179    (continuumIntegral : ℝ)
11180    (hQuadrature :
11181      CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityTarget
11182        F refinementFilter continuumIntegral)
11183    (hResidual :
11184      CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget
11185        F refinementFilter) :
11186    Filter.Tendsto
11187      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate F)
11188      (refinementFilter ×ˢ l)
11189      (nhds continuumIntegral) := by
11190  have hResidual' :
11191      Filter.Tendsto
11192        (fun p : ρ × α =>
11193          CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate F p -
11194            CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral F p)
11195        (refinementFilter ×ˢ l)
11196        (nhds 0) := by
11197    simpa [CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget] using hResidual
11198  have hQuadrature' :
11199      Filter.Tendsto
11200        (CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral F)
11201        (refinementFilter ×ˢ l)
11202        (nhds continuumIntegral) := by
11203    have h :=
11204      hQuadrature.comp
11205        (Filter.tendsto_fst :
11206          Filter.Tendsto (Prod.fst : ρ × α → ρ)
11207            (refinementFilter ×ˢ l) refinementFilter)
11208    simpa [
11209      CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityTarget,
11210      CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral,
11211      Function.comp] using h
11212  have hSum := hResidual'.add hQuadrature'
11213  simpa [
11214    CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate,
11215    CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral] using hSum
11216
11217/-- Data package for the product-filter version of the six-tet volume
11218quadrature limit.  Unlike the staged cross-cardinality package, this includes
11219the uniform product residual required to obtain one global limit. -/
11220structure CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData
11221    {α ρ : Type*} (l : Filter α) where
11222  family : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ
11223  refinementFilter : Filter ρ
11224  continuumIntegral : ℝ
11225  quadrature_tendsto :
11226    CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityTarget
11227      family refinementFilter continuumIntegral
11228  uniform_residual :
11229    CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget
11230      family refinementFilter
11231
11232/-- Forget the product-filter uniformity hypothesis and retain the staged
11233cross-cardinality package. -/
11234def CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData.toCrossCardinalityData
11235    {α ρ : Type*} {l : Filter α}
11236    (D : CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l) :
11237    CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l where
11238  family := D.family
11239  refinementFilter := D.refinementFilter
11240  continuumIntegral := D.continuumIntegral
11241  quadrature_tendsto := D.quadrature_tendsto
11242
11243/-- Upgrade staged cross-cardinality data to product-filter data when a
11244uniform residual proof is supplied separately. -/
11245def CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData.toProductFilterData_of_uniformResidual
11246    {α ρ : Type*} {l : Filter α}
11247    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l)
11248    (hResidual :
11249      CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget
11250        D.family D.refinementFilter) :
11251    CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l where
11252  family := D.family
11253  refinementFilter := D.refinementFilter
11254  continuumIntegral := D.continuumIntegral
11255  quadrature_tendsto := D.quadrature_tendsto
11256  uniform_residual := hResidual
11257
11258/-- Upgrade staged cross-cardinality data to product-filter data from an
11259absolute residual envelope tending to zero on the product filter. -/
11260def CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData.toProductFilterData_of_residualEnvelope
11261    {α ρ : Type*} {l : Filter α}
11262    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l)
11263    (envelope : ρ × α → ℝ)
11264    (hEnvelope :
11265      Filter.Tendsto envelope (D.refinementFilter ×ˢ l : Filter (ρ × α)) (nhds 0))
11266    (hBound :
11267      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11268        |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate D.family p -
11269          CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral D.family p| ≤
11270          envelope p) :
11271    CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l :=
11272  D.toProductFilterData_of_uniformResidual
11273    (canonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget_of_abs_bound
11274      D.family D.refinementFilter envelope hEnvelope hBound)
11275
11276/-- Upgrade staged cross-cardinality data to product-filter data from a
11277cross-slice residual envelope depending only on the within-slice refinement
11278parameter. -/
11279def CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData.toProductFilterData_of_sndResidualEnvelope
11280    {α ρ : Type*} {l : Filter α}
11281    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l)
11282    (envelope : α → ℝ)
11283    (hEnvelope : Filter.Tendsto envelope l (nhds 0))
11284    (hBound :
11285      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11286        |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate D.family p -
11287          CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral D.family p| ≤
11288          envelope p.2) :
11289    CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l :=
11290  D.toProductFilterData_of_uniformResidual
11291    (canonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget_of_snd_abs_bound
11292      D.family D.refinementFilter envelope hEnvelope hBound)
11293
11294/-- Upgrade staged cross-cardinality data to product-filter data from a global
11295cross-slice residual envelope. -/
11296def CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData.toProductFilterData_of_forallSndResidualEnvelope
11297    {α ρ : Type*} {l : Filter α}
11298    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l)
11299    (envelope : α → ℝ)
11300    (hEnvelope : Filter.Tendsto envelope l (nhds 0))
11301    (hBound :
11302      ∀ (r : ρ) (t : α),
11303        |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate D.family (r, t) -
11304          CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral D.family (r, t)| ≤
11305          envelope t) :
11306    CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l :=
11307  D.toProductFilterData_of_uniformResidual
11308    (canonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget_of_forall_snd_abs_bound
11309      D.family D.refinementFilter envelope hEnvelope hBound)
11310
11311/-- Named package for the first concrete global residual estimate still needed
11312for the six-tet product-filter path.  Future geometry only has to fill these
11313fields: an envelope on the within-slice refinement parameter, convergence of
11314that envelope to zero, and a slice-uniform absolute residual bound. -/
11315structure CanonicalPeriodicTetSixTetVolumeQuadratureGlobalResidualEnvelopeData
11316    {α ρ : Type*} {l : Filter α}
11317    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l) where
11318  envelope : α → ℝ
11319  envelope_tendsto_zero : Filter.Tendsto envelope l (nhds 0)
11320  global_residual_bound :
11321    ∀ (r : ρ) (t : α),
11322      |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate D.family (r, t) -
11323        CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral D.family (r, t)| ≤
11324        envelope t
11325
11326/-- Convert a named global residual envelope package into product-filter data. -/
11327def CanonicalPeriodicTetSixTetVolumeQuadratureGlobalResidualEnvelopeData.toProductFilterData
11328    {α ρ : Type*} {l : Filter α}
11329    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11330    (E : CanonicalPeriodicTetSixTetVolumeQuadratureGlobalResidualEnvelopeData D) :
11331    CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l :=
11332  D.toProductFilterData_of_forallSndResidualEnvelope
11333    E.envelope E.envelope_tendsto_zero E.global_residual_bound
11334
11335/-- A named global residual envelope package gives product-filter convergence of
11336the normalized full-Regge aggregate to the supplied continuum integral. -/
11337theorem CanonicalPeriodicTetSixTetVolumeQuadratureGlobalResidualEnvelopeData.fullReggeProduct_tendsto_continuum
11338    {α ρ : Type*} {l : Filter α}
11339    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11340    (E : CanonicalPeriodicTetSixTetVolumeQuadratureGlobalResidualEnvelopeData D) :
11341    Filter.Tendsto
11342      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11343        (α := α) (ρ := ρ) D.family)
11344      (D.refinementFilter ×ˢ l : Filter (ρ × α))
11345      (nhds D.continuumIntegral) :=
11346  canonicalPeriodicTetSixTetVolumeQuadratureProduct_fullRegge_tendsto_continuum
11347    (α := α) (ρ := ρ) D.family D.refinementFilter D.continuumIntegral
11348    D.quadrature_tendsto
11349    (canonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget_of_forall_snd_abs_bound
11350      D.family D.refinementFilter E.envelope E.envelope_tendsto_zero
11351      E.global_residual_bound)
11352
11353/-- The actual product full-Regge-to-quadrature residual magnitude.  Naming this
11354keeps future geometric estimates from restating the long product aggregate
11355expression. -/
11356noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
11357    {α ρ : Type*} {l : Filter α}
11358    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ) :
11359    ρ → α → ℝ :=
11360  fun r t =>
11361    |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate F (r, t) -
11362      CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral F (r, t)|
11363
11364theorem canonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude_nonneg
11365    {α ρ : Type*} {l : Filter α}
11366    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ)
11367    (r : ρ) (t : α) :
11368    0 ≤ CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude F r t := by
11369  simp [CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude]
11370
11371theorem canonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude_bounds_residual
11372    {α ρ : Type*} {l : Filter α}
11373    (F : CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l ρ)
11374    (r : ρ) (t : α) :
11375    |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate F (r, t) -
11376      CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral F (r, t)| ≤
11377      CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude F r t := by
11378  rfl
11379
11380/-- Two-stage residual-bound package.  This is useful when the geometric proof
11381first produces a slice-dependent residual bound and only afterward proves that
11382the bound is dominated by a slice-independent vanishing envelope. -/
11383structure CanonicalPeriodicTetSixTetVolumeQuadratureResidualBoundEnvelopeData
11384    {α ρ : Type*} {l : Filter α}
11385    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l) where
11386  residualBound : ρ → α → ℝ
11387  envelope : α → ℝ
11388  envelope_tendsto_zero : Filter.Tendsto envelope l (nhds 0)
11389  residual_le_bound :
11390    ∀ (r : ρ) (t : α),
11391      |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate D.family (r, t) -
11392        CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral D.family (r, t)| ≤
11393        residualBound r t
11394  bound_le_envelope :
11395    ∀ (r : ρ) (t : α), residualBound r t ≤ envelope t
11396
11397/-- Collapse a two-stage residual-bound package into the single-envelope data
11398package consumed by the product-filter theorem. -/
11399def CanonicalPeriodicTetSixTetVolumeQuadratureResidualBoundEnvelopeData.toGlobalResidualEnvelopeData
11400    {α ρ : Type*} {l : Filter α}
11401    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11402    (B : CanonicalPeriodicTetSixTetVolumeQuadratureResidualBoundEnvelopeData D) :
11403    CanonicalPeriodicTetSixTetVolumeQuadratureGlobalResidualEnvelopeData D where
11404  envelope := B.envelope
11405  envelope_tendsto_zero := B.envelope_tendsto_zero
11406  global_residual_bound := fun r t =>
11407    le_trans (B.residual_le_bound r t) (B.bound_le_envelope r t)
11408
11409/-- A two-stage residual-bound package gives product-filter convergence of the
11410normalized full-Regge aggregate to the supplied continuum integral. -/
11411theorem CanonicalPeriodicTetSixTetVolumeQuadratureResidualBoundEnvelopeData.fullReggeProduct_tendsto_continuum
11412    {α ρ : Type*} {l : Filter α}
11413    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11414    (B : CanonicalPeriodicTetSixTetVolumeQuadratureResidualBoundEnvelopeData D) :
11415    Filter.Tendsto
11416      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11417        (α := α) (ρ := ρ) D.family)
11418      (D.refinementFilter ×ˢ l : Filter (ρ × α))
11419      (nhds D.continuumIntegral) :=
11420  B.toGlobalResidualEnvelopeData.fullReggeProduct_tendsto_continuum
11421
11422/-- Residual-magnitude envelope package.  The remaining analytic work is just to
11423prove that the named product residual magnitude is dominated by a vanishing
11424envelope. -/
11425structure CanonicalPeriodicTetSixTetVolumeQuadratureResidualMagnitudeEnvelopeData
11426    {α ρ : Type*} {l : Filter α}
11427    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l) where
11428  envelope : α → ℝ
11429  envelope_tendsto_zero : Filter.Tendsto envelope l (nhds 0)
11430  magnitude_le_envelope :
11431    ∀ (r : ρ) (t : α),
11432      CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude D.family r t ≤ envelope t
11433
11434/-- Convert residual-magnitude domination into the two-stage residual-bound
11435package by taking the residual bound to be the residual magnitude itself. -/
11436def CanonicalPeriodicTetSixTetVolumeQuadratureResidualMagnitudeEnvelopeData.toResidualBoundEnvelopeData
11437    {α ρ : Type*} {l : Filter α}
11438    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11439    (M : CanonicalPeriodicTetSixTetVolumeQuadratureResidualMagnitudeEnvelopeData D) :
11440    CanonicalPeriodicTetSixTetVolumeQuadratureResidualBoundEnvelopeData D where
11441  residualBound := CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude D.family
11442  envelope := M.envelope
11443  envelope_tendsto_zero := M.envelope_tendsto_zero
11444  residual_le_bound :=
11445    canonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude_bounds_residual D.family
11446  bound_le_envelope := M.magnitude_le_envelope
11447
11448/-- A residual-magnitude envelope package gives product-filter convergence of
11449the normalized full-Regge aggregate to the supplied continuum integral. -/
11450theorem CanonicalPeriodicTetSixTetVolumeQuadratureResidualMagnitudeEnvelopeData.fullReggeProduct_tendsto_continuum
11451    {α ρ : Type*} {l : Filter α}
11452    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11453    (M : CanonicalPeriodicTetSixTetVolumeQuadratureResidualMagnitudeEnvelopeData D) :
11454    Filter.Tendsto
11455      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11456        (α := α) (ρ := ρ) D.family)
11457      (D.refinementFilter ×ˢ l : Filter (ρ × α))
11458      (nhds D.continuumIntegral) :=
11459  M.toResidualBoundEnvelopeData.fullReggeProduct_tendsto_continuum
11460
11461/-- The product quadrature proxy converges to the supplied continuum integral. -/
11462theorem CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData.quadratureProduct_tendsto_continuum
11463    {α ρ : Type*} {l : Filter α}
11464    (D : CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l) :
11465    Filter.Tendsto
11466      (CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral
11467        (α := α) (ρ := ρ) D.family)
11468      (D.refinementFilter ×ˢ l : Filter (ρ × α))
11469      (nhds D.continuumIntegral) := by
11470  have h :=
11471    D.quadrature_tendsto.comp
11472      (Filter.tendsto_fst :
11473        Filter.Tendsto (Prod.fst : ρ × α → ρ)
11474          (D.refinementFilter ×ˢ l) D.refinementFilter)
11475  simpa [
11476    CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityTarget,
11477    CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral,
11478    Function.comp] using h
11479
11480/-- Product-filter full-Regge convergence to the supplied continuum integral. -/
11481theorem CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData.fullReggeProduct_tendsto_continuum
11482    {α ρ : Type*} {l : Filter α}
11483    (D : CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l) :
11484    Filter.Tendsto
11485      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11486        (α := α) (ρ := ρ) D.family)
11487      (D.refinementFilter ×ˢ l : Filter (ρ × α))
11488      (nhds D.continuumIntegral) :=
11489  canonicalPeriodicTetSixTetVolumeQuadratureProduct_fullRegge_tendsto_continuum
11490    (α := α) (ρ := ρ) D.family D.refinementFilter D.continuumIntegral
11491    D.quadrature_tendsto D.uniform_residual
11492
11493/-- Direct product-filter convergence theorem from staged cross-cardinality
11494data plus a cross-slice residual envelope. -/
11495theorem CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData.fullReggeProduct_tendsto_continuum_of_sndResidualEnvelope
11496    {α ρ : Type*} {l : Filter α}
11497    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l)
11498    (envelope : α → ℝ)
11499    (hEnvelope : Filter.Tendsto envelope l (nhds 0))
11500    (hBound :
11501      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11502        |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate D.family p -
11503          CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral D.family p| ≤
11504          envelope p.2) :
11505    Filter.Tendsto
11506      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11507        (α := α) (ρ := ρ) D.family)
11508      (D.refinementFilter ×ˢ l : Filter (ρ × α))
11509      (nhds D.continuumIntegral) :=
11510  (D.toProductFilterData_of_sndResidualEnvelope envelope hEnvelope hBound).fullReggeProduct_tendsto_continuum
11511
11512/-- Direct product-filter convergence theorem from staged cross-cardinality
11513data plus a global cross-slice residual envelope. -/
11514theorem CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData.fullReggeProduct_tendsto_continuum_of_forallSndResidualEnvelope
11515    {α ρ : Type*} {l : Filter α}
11516    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l)
11517    (envelope : α → ℝ)
11518    (hEnvelope : Filter.Tendsto envelope l (nhds 0))
11519    (hBound :
11520      ∀ (r : ρ) (t : α),
11521        |CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate D.family (r, t) -
11522          CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral D.family (r, t)| ≤
11523          envelope t) :
11524    Filter.Tendsto
11525      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11526        (α := α) (ρ := ρ) D.family)
11527      (D.refinementFilter ×ˢ l : Filter (ρ × α))
11528      (nhds D.continuumIntegral) :=
11529  (D.toProductFilterData_of_forallSndResidualEnvelope envelope hEnvelope hBound).fullReggeProduct_tendsto_continuum
11530
11531/-- Diagonal-filter corollary: any diagonal schedule into the product filter
11532inherits the product-filter full-Regge continuum limit. -/
11533theorem CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData.fullReggeDiagonal_tendsto_continuum
11534    {α ρ δ : Type*} {l : Filter α} {m : Filter δ}
11535    (D : CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l)
11536    (diagonal : δ → ρ × α)
11537    (hDiagonal :
11538      Filter.Tendsto diagonal m (D.refinementFilter ×ˢ l : Filter (ρ × α))) :
11539    Filter.Tendsto
11540      (fun s : δ =>
11541        CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11542          (α := α) (ρ := ρ) D.family (diagonal s))
11543      m
11544      (nhds D.continuumIntegral) := by
11545  simpa [Function.comp] using
11546    (CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData.fullReggeProduct_tendsto_continuum
11547      (α := α) (ρ := ρ) D).comp hDiagonal
11548
11549/-- Absolute spacing size for a six-tet quadrature slice. -/
11550noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
11551    {α : Type*} {l : Filter α}
11552    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) : α → ℝ := by
11553  letI : NeZero S.Nx := S.instNx
11554  letI : NeZero S.Ny := S.instNy
11555  letI : NeZero S.Nz := S.instNz
11556  exact fun t : α => |S.data.spacing t|
11557
11558/-- Absolute cell-volume error against the limiting cell volume for a six-tet
11559quadrature slice. -/
11560noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
11561    {α : Type*} {l : Filter α}
11562    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) : α → ℝ := by
11563  letI : NeZero S.Nx := S.instNx
11564  letI : NeZero S.Ny := S.instNy
11565  letI : NeZero S.Nz := S.instNz
11566  exact fun t : α => |S.data.cellVolume t - S.data.limitCellVolume|
11567
11568/-- The named slice spacing magnitude vanishes along the within-slice
11569refinement filter. -/
11570theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude_tendsto_zero
11571    {α : Type*} {l : Filter α}
11572    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) :
11573    Filter.Tendsto S.spacingMagnitude l (nhds 0) := by
11574  letI : NeZero S.Nx := S.instNx
11575  letI : NeZero S.Ny := S.instNy
11576  letI : NeZero S.Nz := S.instNz
11577  simpa [CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude] using
11578    S.data.spacing_tendsto_zero.abs
11579
11580/-- The named slice cell-volume error vanishes along the within-slice
11581refinement filter. -/
11582theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError_tendsto_zero
11583    {α : Type*} {l : Filter α}
11584    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) :
11585    Filter.Tendsto S.cellVolumeError l (nhds 0) := by
11586  letI : NeZero S.Nx := S.instNx
11587  letI : NeZero S.Ny := S.instNy
11588  letI : NeZero S.Nz := S.instNz
11589  have hSub :
11590      Filter.Tendsto
11591        (fun t : α => S.data.cellVolume t - S.data.limitCellVolume)
11592        l
11593        (nhds 0) := by
11594    simpa using
11595      S.data.cellVolume_tendsto.sub
11596        (tendsto_const_nhds (x := S.data.limitCellVolume))
11597  simpa [CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError] using hSub.abs
11598
11599/-- Uniform spacing/cell-volume envelope used by the product residual estimate.
11600The coefficient is supplied by the future geometric estimate; the two envelope
11601terms are the uniform spacing and cell-volume error controls. -/
11602def CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope
11603    {α : Type*}
11604    (coefficient : ℝ)
11605    (spacingEnvelope cellVolumeEnvelope : α → ℝ) : α → ℝ :=
11606  fun t : α => coefficient * (spacingEnvelope t + cellVolumeEnvelope t)
11607
11608/-- If the spacing and cell-volume envelopes vanish, then their coefficient
11609weighted sum vanishes. -/
11610theorem canonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope_tendsto_zero
11611    {α : Type*} {l : Filter α}
11612    (coefficient : ℝ)
11613    (spacingEnvelope cellVolumeEnvelope : α → ℝ)
11614    (hSpacing : Filter.Tendsto spacingEnvelope l (nhds 0))
11615    (hCell : Filter.Tendsto cellVolumeEnvelope l (nhds 0)) :
11616    Filter.Tendsto
11617      (CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope
11618        coefficient spacingEnvelope cellVolumeEnvelope)
11619      l
11620      (nhds 0) := by
11621  have hSum : Filter.Tendsto (fun t : α => spacingEnvelope t + cellVolumeEnvelope t) l (nhds 0) := by
11622    simpa using hSpacing.add hCell
11623  simpa [CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope] using
11624    hSum.const_mul coefficient
11625
11626/-- A fixed slice's spacing/cell-volume envelope vanishes using only the slice's
11627own refinement data.  Cross-slice uniformity is still a separate product-filter
11628obligation. -/
11629theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingCellEnvelope_tendsto_zero
11630    {α : Type*} {l : Filter α}
11631    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
11632    (coefficient : ℝ) :
11633    Filter.Tendsto
11634      (CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope
11635        coefficient S.spacingMagnitude S.cellVolumeError)
11636      l
11637      (nhds 0) :=
11638  canonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope_tendsto_zero
11639    coefficient S.spacingMagnitude S.cellVolumeError
11640    S.spacingMagnitude_tendsto_zero
11641    S.cellVolumeError_tendsto_zero
11642
11643/-- Raw spacing schedule carried by a six-tet quadrature slice, with the slice's
11644side-length instances installed locally. -/
11645noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawSpacingSchedule
11646    {α : Type*} {l : Filter α}
11647    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) : α → ℝ := by
11648  letI : NeZero S.Nx := S.instNx
11649  letI : NeZero S.Ny := S.instNy
11650  letI : NeZero S.Nz := S.instNz
11651  exact S.data.spacing
11652
11653/-- Raw cell-volume schedule carried by a six-tet quadrature slice, with the
11654slice's side-length instances installed locally. -/
11655noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawCellVolumeSchedule
11656    {α : Type*} {l : Filter α}
11657    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) : α → ℝ := by
11658  letI : NeZero S.Nx := S.instNx
11659  letI : NeZero S.Ny := S.instNy
11660  letI : NeZero S.Nz := S.instNz
11661  exact S.data.cellVolume
11662
11663/-- Raw limiting cell volume carried by a six-tet quadrature slice, with the
11664slice's side-length instances installed locally. -/
11665noncomputable def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawLimitCellVolume
11666    {α : Type*} {l : Filter α}
11667    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) : ℝ := by
11668  letI : NeZero S.Nx := S.instNx
11669  letI : NeZero S.Ny := S.instNy
11670  letI : NeZero S.Nz := S.instNz
11671  exact S.data.limitCellVolume
11672
11673/-- The named spacing magnitude is the absolute value of the raw slice spacing
11674schedule. -/
11675theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude_eq_abs_rawSpacingSchedule
11676    {α : Type*} {l : Filter α}
11677    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
11678    (t : α) :
11679    S.spacingMagnitude t = |S.rawSpacingSchedule t| := by
11680  letI : NeZero S.Nx := S.instNx
11681  letI : NeZero S.Ny := S.instNy
11682  letI : NeZero S.Nz := S.instNz
11683  simp [
11684    CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude,
11685    CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawSpacingSchedule]
11686
11687/-- The named cell-volume error is the absolute difference between the raw
11688cell-volume schedule and the raw limiting cell volume. -/
11689theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError_eq_abs_rawCellVolumeSchedule_sub_rawLimitCellVolume
11690    {α : Type*} {l : Filter α}
11691    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
11692    (t : α) :
11693    S.cellVolumeError t = |S.rawCellVolumeSchedule t - S.rawLimitCellVolume| := by
11694  letI : NeZero S.Nx := S.instNx
11695  letI : NeZero S.Ny := S.instNy
11696  letI : NeZero S.Nz := S.instNz
11697  simp [
11698    CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError,
11699    CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawCellVolumeSchedule,
11700    CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawLimitCellVolume]
11701
11702/-- Eventual residual-magnitude envelope package.  This is the proof shape
11703expected from geometric estimates: after passing far enough along the product
11704refinement filter, the named residual magnitude is bounded by one
11705slice-independent envelope tending to zero. -/
11706structure CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData
11707    {α ρ : Type*} {l : Filter α}
11708    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l) where
11709  envelope : α → ℝ
11710  envelope_tendsto_zero : Filter.Tendsto envelope l (nhds 0)
11711  eventually_magnitude_le_envelope :
11712    ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11713      CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude D.family p.1 p.2 ≤
11714        envelope p.2
11715
11716/-- Convert eventual residual-magnitude domination into product-filter data. -/
11717def CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData.toProductFilterData
11718    {α ρ : Type*} {l : Filter α}
11719    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11720    (M : CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData D) :
11721    CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := ρ) l :=
11722  D.toProductFilterData_of_sndResidualEnvelope
11723    M.envelope M.envelope_tendsto_zero
11724    (M.eventually_magnitude_le_envelope.mono (fun p hp => by
11725      exact le_trans
11726        (canonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude_bounds_residual
11727          D.family p.1 p.2)
11728        hp))
11729
11730/-- Eventual residual-magnitude domination gives product-filter full-Regge
11731convergence to the supplied continuum integral. -/
11732theorem CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData.fullReggeProduct_tendsto_continuum
11733    {α ρ : Type*} {l : Filter α}
11734    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11735    (M : CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData D) :
11736    Filter.Tendsto
11737      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11738        (α := α) (ρ := ρ) D.family)
11739      (D.refinementFilter ×ˢ l : Filter (ρ × α))
11740      (nhds D.continuumIntegral) :=
11741  M.toProductFilterData.fullReggeProduct_tendsto_continuum
11742
11743/-- Any diagonal schedule into the product filter inherits convergence from an
11744eventual residual-magnitude envelope. -/
11745theorem CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData.fullReggeDiagonal_tendsto_continuum
11746    {α ρ δ : Type*} {l : Filter α} {m : Filter δ}
11747    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11748    (M : CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData D)
11749    (diagonal : δ → ρ × α)
11750    (hDiagonal :
11751      Filter.Tendsto diagonal m (D.refinementFilter ×ˢ l : Filter (ρ × α))) :
11752    Filter.Tendsto
11753      (fun s : δ =>
11754        CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
11755          (α := α) (ρ := ρ) D.family (diagonal s))
11756      m
11757      (nhds D.continuumIntegral) :=
11758  M.toProductFilterData.fullReggeDiagonal_tendsto_continuum diagonal hDiagonal
11759
11760/-- Eventual residual-magnitude domination also gives direct product-filter
11761vanishing of the named residual magnitude itself. -/
11762theorem CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData.residualMagnitude_tendsto_zero
11763    {α ρ : Type*} {l : Filter α}
11764    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11765    (M : CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData D) :
11766    Filter.Tendsto
11767      (fun p : ρ × α =>
11768        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
11769          D.family p.1 p.2)
11770      (D.refinementFilter ×ˢ l : Filter (ρ × α))
11771      (nhds 0) := by
11772  exact squeeze_zero'
11773    (Filter.Eventually.of_forall (fun p : ρ × α =>
11774      canonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude_nonneg
11775        D.family p.1 p.2))
11776    M.eventually_magnitude_le_envelope
11777    (M.envelope_tendsto_zero.comp
11778      (Filter.tendsto_snd :
11779        Filter.Tendsto (Prod.snd : ρ × α → α)
11780          (D.refinementFilter ×ˢ l) l))
11781
11782/-- Any diagonal schedule into the product filter inherits residual-magnitude
11783vanishing from an eventual residual-magnitude envelope. -/
11784theorem CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData.residualMagnitudeDiagonal_tendsto_zero
11785    {α ρ δ : Type*} {l : Filter α} {m : Filter δ}
11786    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11787    (M : CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData D)
11788    (diagonal : δ → ρ × α)
11789    (hDiagonal :
11790      Filter.Tendsto diagonal m (D.refinementFilter ×ˢ l : Filter (ρ × α))) :
11791    Filter.Tendsto
11792      (fun s : δ =>
11793        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
11794          D.family (diagonal s).1 (diagonal s).2)
11795      m
11796      (nhds 0) := by
11797  simpa [Function.comp] using
11798    M.residualMagnitude_tendsto_zero.comp hDiagonal
11799
11800/-- Cross-slice schedule envelope data.  This separates the uniform
11801spacing/cell-volume schedule control from the later geometric residual
11802inequality. -/
11803structure CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData
11804    {α ρ : Type*} {l : Filter α}
11805    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l) where
11806  spacingEnvelope : α → ℝ
11807  cellVolumeEnvelope : α → ℝ
11808  spacingEnvelope_tendsto_zero : Filter.Tendsto spacingEnvelope l (nhds 0)
11809  cellVolumeEnvelope_tendsto_zero : Filter.Tendsto cellVolumeEnvelope l (nhds 0)
11810  eventually_spacingMagnitude_le_envelope :
11811    ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11812      CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
11813        (D.family.slice p.1) p.2 ≤ spacingEnvelope p.2
11814  eventually_cellVolumeError_le_envelope :
11815    ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11816      CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
11817        (D.family.slice p.1) p.2 ≤ cellVolumeEnvelope p.2
11818
11819/-- The cross-slice spacing/cell-volume envelope supplied by schedule data
11820vanishes along the within-slice filter. -/
11821theorem CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData.spacingCellEnvelope_tendsto_zero
11822    {α ρ : Type*} {l : Filter α}
11823    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11824    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData D)
11825    (coefficient : ℝ) :
11826    Filter.Tendsto
11827      (CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope
11828        coefficient S.spacingEnvelope S.cellVolumeEnvelope)
11829      l
11830      (nhds 0) :=
11831  canonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope_tendsto_zero
11832    coefficient S.spacingEnvelope S.cellVolumeEnvelope
11833    S.spacingEnvelope_tendsto_zero
11834    S.cellVolumeEnvelope_tendsto_zero
11835
11836/-- Common spacing/cell-volume schedule data for a genuinely varying-cardinality
11837family.  The side lengths may vary with the slice index, but eventually on the
11838product filter all slices use the same within-slice spacing schedule, the same
11839cell-volume schedule, and the same limiting cell volume. -/
11840structure CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData
11841    {α ρ : Type*} {l : Filter α}
11842    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l) where
11843  spacingSchedule : α → ℝ
11844  cellVolumeSchedule : α → ℝ
11845  limitCellVolume : ℝ
11846  spacingSchedule_tendsto_zero :
11847    Filter.Tendsto spacingSchedule l (nhds 0)
11848  cellVolumeSchedule_tendsto_limit :
11849    Filter.Tendsto cellVolumeSchedule l (nhds limitCellVolume)
11850  eventually_spacingMagnitude_eq_schedule :
11851    ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11852      CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
11853        (D.family.slice p.1) p.2 = |spacingSchedule p.2|
11854  eventually_cellVolumeError_eq_schedule :
11855    ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11856      CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
11857        (D.family.slice p.1) p.2 =
11858          |cellVolumeSchedule p.2 - limitCellVolume|
11859
11860/-- A common spacing/cell-volume schedule supplies the cross-slice schedule
11861envelopes required by the product-filter bridge. -/
11862def CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData.toSpacingCellScheduleEnvelopeData
11863    {α ρ : Type*} {l : Filter α}
11864    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11865    (C : CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData D) :
11866    CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData D where
11867  spacingEnvelope := fun t : α => |C.spacingSchedule t|
11868  cellVolumeEnvelope := fun t : α => |C.cellVolumeSchedule t - C.limitCellVolume|
11869  spacingEnvelope_tendsto_zero := by
11870    simpa using C.spacingSchedule_tendsto_zero.abs
11871  cellVolumeEnvelope_tendsto_zero := by
11872    have hSub :
11873        Filter.Tendsto
11874          (fun t : α => C.cellVolumeSchedule t - C.limitCellVolume)
11875          l
11876          (nhds 0) := by
11877      simpa using
11878        C.cellVolumeSchedule_tendsto_limit.sub
11879          (tendsto_const_nhds (x := C.limitCellVolume))
11880    simpa using hSub.abs
11881  eventually_spacingMagnitude_le_envelope :=
11882    C.eventually_spacingMagnitude_eq_schedule.mono (fun _ hp => le_of_eq hp)
11883  eventually_cellVolumeError_le_envelope :=
11884    C.eventually_cellVolumeError_eq_schedule.mono (fun _ hp => le_of_eq hp)
11885
11886/-- The spacing/cell envelope from a common varying-cardinality schedule
11887vanishes along the within-slice filter. -/
11888theorem CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData.spacingCellEnvelope_tendsto_zero
11889    {α ρ : Type*} {l : Filter α}
11890    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11891    (C : CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData D)
11892    (coefficient : ℝ) :
11893    Filter.Tendsto
11894      (CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope
11895        coefficient
11896        (fun t : α => |C.spacingSchedule t|)
11897        (fun t : α => |C.cellVolumeSchedule t - C.limitCellVolume|))
11898      l
11899      (nhds 0) := by
11900  simpa using
11901    C.toSpacingCellScheduleEnvelopeData.spacingCellEnvelope_tendsto_zero coefficient
11902
11903/-- Build common schedule-envelope data from raw slice schedules.  This is the
11904handoff wanted by explicit side-length families: they can state eventual
11905agreement of each slice's raw spacing, raw cell-volume schedule, and raw limit
11906cell volume with one common schedule, while this constructor handles the named
11907absolute-value error quantities used by the product-filter bridge. -/
11908def CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData.ofRawSchedules
11909    {α ρ : Type*} {l : Filter α}
11910    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l)
11911    (spacingSchedule cellVolumeSchedule : α → ℝ)
11912    (limitCellVolume : ℝ)
11913    (hSpacingTendsto :
11914      Filter.Tendsto spacingSchedule l (nhds 0))
11915    (hCellTendsto :
11916      Filter.Tendsto cellVolumeSchedule l (nhds limitCellVolume))
11917    (hSpacing :
11918      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11919        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawSpacingSchedule
11920          (D.family.slice p.1) p.2 = spacingSchedule p.2)
11921    (hCell :
11922      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11923        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawCellVolumeSchedule
11924          (D.family.slice p.1) p.2 = cellVolumeSchedule p.2)
11925    (hLimit :
11926      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11927        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawLimitCellVolume
11928          (D.family.slice p.1) = limitCellVolume) :
11929    CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData D where
11930  spacingSchedule := spacingSchedule
11931  cellVolumeSchedule := cellVolumeSchedule
11932  limitCellVolume := limitCellVolume
11933  spacingSchedule_tendsto_zero := hSpacingTendsto
11934  cellVolumeSchedule_tendsto_limit := hCellTendsto
11935  eventually_spacingMagnitude_eq_schedule :=
11936    hSpacing.mono (fun p hp => by
11937      calc
11938        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
11939            (D.family.slice p.1) p.2 =
11940            |CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawSpacingSchedule
11941              (D.family.slice p.1) p.2| :=
11942          CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude_eq_abs_rawSpacingSchedule
11943            (D.family.slice p.1) p.2
11944        _ = |spacingSchedule p.2| := by simp [hp])
11945  eventually_cellVolumeError_eq_schedule :=
11946    ((hCell.and hLimit).mono (fun p h => by
11947      rcases h with ⟨hCellEq, hLimitEq⟩
11948      calc
11949        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
11950            (D.family.slice p.1) p.2 =
11951            |CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawCellVolumeSchedule
11952                (D.family.slice p.1) p.2 -
11953              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.rawLimitCellVolume
11954                (D.family.slice p.1)| :=
11955          CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError_eq_abs_rawCellVolumeSchedule_sub_rawLimitCellVolume
11956            (D.family.slice p.1) p.2
11957        _ = |cellVolumeSchedule p.2 - limitCellVolume| := by
11958          simp [hCellEq, hLimitEq]))
11959
11960/-- Spacing/cell-volume residual envelope package.  This is the first interface
11961that names the concrete geometric quantities expected to control the residual:
11962the slice spacing magnitude and the slice cell-volume error.  The future
11963geometric estimate supplies the coefficient and the residual bound by those two
11964quantities; this package adds uniform vanishing envelopes for both quantities. -/
11965structure CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData
11966    {α ρ : Type*} {l : Filter α}
11967    (D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l) where
11968  coefficient : ℝ
11969  coefficient_nonneg : 0 ≤ coefficient
11970  spacingEnvelope : α → ℝ
11971  cellVolumeEnvelope : α → ℝ
11972  spacingEnvelope_tendsto_zero : Filter.Tendsto spacingEnvelope l (nhds 0)
11973  cellVolumeEnvelope_tendsto_zero : Filter.Tendsto cellVolumeEnvelope l (nhds 0)
11974  eventually_spacingMagnitude_le_envelope :
11975    ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11976      CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
11977        (D.family.slice p.1) p.2 ≤ spacingEnvelope p.2
11978  eventually_cellVolumeError_le_envelope :
11979    ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11980      CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
11981        (D.family.slice p.1) p.2 ≤ cellVolumeEnvelope p.2
11982  eventually_magnitude_le_spacing_cell :
11983    ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
11984      CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
11985          D.family p.1 p.2 ≤
11986        coefficient *
11987          (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
11988              (D.family.slice p.1) p.2 +
11989            CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
11990              (D.family.slice p.1) p.2)
11991
11992/-- Add the geometric residual estimate to cross-slice schedule envelope data,
11993producing the full spacing/cell-volume residual package. -/
11994def CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData.toSpacingCellResidualEnvelopeData
11995    {α ρ : Type*} {l : Filter α}
11996    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
11997    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData D)
11998    (coefficient : ℝ)
11999    (coefficient_nonneg : 0 ≤ coefficient)
12000    (hMagnitude :
12001      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
12002        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12003            D.family p.1 p.2 ≤
12004          coefficient *
12005            (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12006                (D.family.slice p.1) p.2 +
12007              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12008                (D.family.slice p.1) p.2)) :
12009    CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData D where
12010  coefficient := coefficient
12011  coefficient_nonneg := coefficient_nonneg
12012  spacingEnvelope := S.spacingEnvelope
12013  cellVolumeEnvelope := S.cellVolumeEnvelope
12014  spacingEnvelope_tendsto_zero := S.spacingEnvelope_tendsto_zero
12015  cellVolumeEnvelope_tendsto_zero := S.cellVolumeEnvelope_tendsto_zero
12016  eventually_spacingMagnitude_le_envelope := S.eventually_spacingMagnitude_le_envelope
12017  eventually_cellVolumeError_le_envelope := S.eventually_cellVolumeError_le_envelope
12018  eventually_magnitude_le_spacing_cell := hMagnitude
12019
12020/-- Convert spacing/cell-volume residual control into the eventual residual
12021magnitude envelope package. -/
12022def CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData.toEventuallyResidualMagnitudeEnvelopeData
12023    {α ρ : Type*} {l : Filter α}
12024    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12025    (M : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData D) :
12026    CanonicalPeriodicTetSixTetVolumeQuadratureEventuallyResidualMagnitudeEnvelopeData D where
12027  envelope :=
12028    CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope
12029      M.coefficient M.spacingEnvelope M.cellVolumeEnvelope
12030  envelope_tendsto_zero :=
12031    canonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope_tendsto_zero
12032      M.coefficient M.spacingEnvelope M.cellVolumeEnvelope
12033      M.spacingEnvelope_tendsto_zero M.cellVolumeEnvelope_tendsto_zero
12034  eventually_magnitude_le_envelope := by
12035    exact
12036      ((M.eventually_magnitude_le_spacing_cell.and
12037          M.eventually_spacingMagnitude_le_envelope).and
12038        M.eventually_cellVolumeError_le_envelope).mono
12039        (fun p h => by
12040          rcases h with ⟨⟨hMagnitude, hSpacing⟩, hCell⟩
12041          have hSum :
12042              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12043                  (D.family.slice p.1) p.2 +
12044                CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12045                  (D.family.slice p.1) p.2 ≤
12046              M.spacingEnvelope p.2 + M.cellVolumeEnvelope p.2 := by
12047            exact add_le_add hSpacing hCell
12048          have hMul :=
12049            mul_le_mul_of_nonneg_left hSum M.coefficient_nonneg
12050          exact le_trans hMagnitude hMul)
12051
12052/-- Spacing/cell-volume residual control gives product-filter full-Regge
12053convergence to the supplied continuum integral. -/
12054theorem CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData.fullReggeProduct_tendsto_continuum
12055    {α ρ : Type*} {l : Filter α}
12056    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12057    (M : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData D) :
12058    Filter.Tendsto
12059      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
12060        (α := α) (ρ := ρ) D.family)
12061      (D.refinementFilter ×ˢ l : Filter (ρ × α))
12062      (nhds D.continuumIntegral) :=
12063  M.toEventuallyResidualMagnitudeEnvelopeData.fullReggeProduct_tendsto_continuum
12064
12065/-- A diagonal schedule into the product filter inherits convergence from
12066spacing/cell-volume residual control. -/
12067theorem CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData.fullReggeDiagonal_tendsto_continuum
12068    {α ρ δ : Type*} {l : Filter α} {m : Filter δ}
12069    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12070    (M : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData D)
12071    (diagonal : δ → ρ × α)
12072    (hDiagonal :
12073      Filter.Tendsto diagonal m (D.refinementFilter ×ˢ l : Filter (ρ × α))) :
12074    Filter.Tendsto
12075      (fun s : δ =>
12076        CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
12077          (α := α) (ρ := ρ) D.family (diagonal s))
12078      m
12079      (nhds D.continuumIntegral) :=
12080  M.toEventuallyResidualMagnitudeEnvelopeData.fullReggeDiagonal_tendsto_continuum
12081    diagonal hDiagonal
12082
12083/-- Spacing/cell-volume residual control gives direct product-filter vanishing
12084of the named residual magnitude. -/
12085theorem CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData.residualMagnitude_tendsto_zero
12086    {α ρ : Type*} {l : Filter α}
12087    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12088    (M : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData D) :
12089    Filter.Tendsto
12090      (fun p : ρ × α =>
12091        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12092          D.family p.1 p.2)
12093      (D.refinementFilter ×ˢ l : Filter (ρ × α))
12094      (nhds 0) :=
12095  M.toEventuallyResidualMagnitudeEnvelopeData.residualMagnitude_tendsto_zero
12096
12097/-- A diagonal schedule inherits residual-magnitude vanishing from
12098spacing/cell-volume residual control. -/
12099theorem CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData.residualMagnitudeDiagonal_tendsto_zero
12100    {α ρ δ : Type*} {l : Filter α} {m : Filter δ}
12101    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12102    (M : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellResidualEnvelopeData D)
12103    (diagonal : δ → ρ × α)
12104    (hDiagonal :
12105      Filter.Tendsto diagonal m (D.refinementFilter ×ˢ l : Filter (ρ × α))) :
12106    Filter.Tendsto
12107      (fun s : δ =>
12108        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12109          D.family (diagonal s).1 (diagonal s).2)
12110      m
12111      (nhds 0) :=
12112  M.toEventuallyResidualMagnitudeEnvelopeData.residualMagnitudeDiagonal_tendsto_zero
12113    diagonal hDiagonal
12114
12115/-- Cross-slice schedule envelope data plus the geometric residual estimate gives
12116product-filter full-Regge convergence. -/
12117theorem CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData.fullReggeProduct_tendsto_continuum
12118    {α ρ : Type*} {l : Filter α}
12119    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12120    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData D)
12121    (coefficient : ℝ)
12122    (coefficient_nonneg : 0 ≤ coefficient)
12123    (hMagnitude :
12124      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
12125        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12126            D.family p.1 p.2 ≤
12127          coefficient *
12128            (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12129                (D.family.slice p.1) p.2 +
12130              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12131                (D.family.slice p.1) p.2)) :
12132    Filter.Tendsto
12133      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
12134        (α := α) (ρ := ρ) D.family)
12135      (D.refinementFilter ×ˢ l : Filter (ρ × α))
12136      (nhds D.continuumIntegral) :=
12137  (S.toSpacingCellResidualEnvelopeData
12138    coefficient coefficient_nonneg hMagnitude).fullReggeProduct_tendsto_continuum
12139
12140/-- A diagonal schedule into the product filter inherits convergence from
12141cross-slice schedule envelope data plus the geometric residual estimate. -/
12142theorem CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData.fullReggeDiagonal_tendsto_continuum
12143    {α ρ δ : Type*} {l : Filter α} {m : Filter δ}
12144    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12145    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData D)
12146    (coefficient : ℝ)
12147    (coefficient_nonneg : 0 ≤ coefficient)
12148    (hMagnitude :
12149      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
12150        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12151            D.family p.1 p.2 ≤
12152          coefficient *
12153            (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12154                (D.family.slice p.1) p.2 +
12155              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12156                (D.family.slice p.1) p.2))
12157    (diagonal : δ → ρ × α)
12158    (hDiagonal :
12159      Filter.Tendsto diagonal m (D.refinementFilter ×ˢ l : Filter (ρ × α))) :
12160    Filter.Tendsto
12161      (fun s : δ =>
12162        CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
12163          (α := α) (ρ := ρ) D.family (diagonal s))
12164      m
12165      (nhds D.continuumIntegral) :=
12166  (S.toSpacingCellResidualEnvelopeData
12167    coefficient coefficient_nonneg hMagnitude).fullReggeDiagonal_tendsto_continuum
12168      diagonal hDiagonal
12169
12170/-- Cross-slice schedule envelope data plus the geometric residual estimate gives
12171direct product-filter vanishing of the named residual magnitude. -/
12172theorem CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData.residualMagnitude_tendsto_zero
12173    {α ρ : Type*} {l : Filter α}
12174    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12175    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData D)
12176    (coefficient : ℝ)
12177    (coefficient_nonneg : 0 ≤ coefficient)
12178    (hMagnitude :
12179      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
12180        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12181            D.family p.1 p.2 ≤
12182          coefficient *
12183            (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12184                (D.family.slice p.1) p.2 +
12185              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12186                (D.family.slice p.1) p.2)) :
12187    Filter.Tendsto
12188      (fun p : ρ × α =>
12189        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12190          D.family p.1 p.2)
12191      (D.refinementFilter ×ˢ l : Filter (ρ × α))
12192      (nhds 0) :=
12193  (S.toSpacingCellResidualEnvelopeData
12194    coefficient coefficient_nonneg hMagnitude).residualMagnitude_tendsto_zero
12195
12196/-- A diagonal schedule inherits residual-magnitude vanishing from cross-slice
12197schedule envelope data plus the geometric residual estimate. -/
12198theorem CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData.residualMagnitudeDiagonal_tendsto_zero
12199    {α ρ δ : Type*} {l : Filter α} {m : Filter δ}
12200    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12201    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData D)
12202    (coefficient : ℝ)
12203    (coefficient_nonneg : 0 ≤ coefficient)
12204    (hMagnitude :
12205      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
12206        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12207            D.family p.1 p.2 ≤
12208          coefficient *
12209            (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12210                (D.family.slice p.1) p.2 +
12211              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12212                (D.family.slice p.1) p.2))
12213    (diagonal : δ → ρ × α)
12214    (hDiagonal :
12215      Filter.Tendsto diagonal m (D.refinementFilter ×ˢ l : Filter (ρ × α))) :
12216    Filter.Tendsto
12217      (fun s : δ =>
12218        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12219          D.family (diagonal s).1 (diagonal s).2)
12220      m
12221      (nhds 0) :=
12222  (S.toSpacingCellResidualEnvelopeData
12223    coefficient coefficient_nonneg hMagnitude).residualMagnitudeDiagonal_tendsto_zero
12224      diagonal hDiagonal
12225
12226/-- Common varying-cardinality schedule data plus the geometric residual estimate
12227gives product-filter full-Regge convergence. -/
12228theorem CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData.fullReggeProduct_tendsto_continuum
12229    {α ρ : Type*} {l : Filter α}
12230    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12231    (C : CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData D)
12232    (coefficient : ℝ)
12233    (coefficient_nonneg : 0 ≤ coefficient)
12234    (hMagnitude :
12235      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
12236        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12237            D.family p.1 p.2 ≤
12238          coefficient *
12239            (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12240                (D.family.slice p.1) p.2 +
12241              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12242                (D.family.slice p.1) p.2)) :
12243    Filter.Tendsto
12244      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
12245        (α := α) (ρ := ρ) D.family)
12246      (D.refinementFilter ×ˢ l : Filter (ρ × α))
12247      (nhds D.continuumIntegral) :=
12248  C.toSpacingCellScheduleEnvelopeData.fullReggeProduct_tendsto_continuum
12249    coefficient coefficient_nonneg hMagnitude
12250
12251/-- Common varying-cardinality schedule data plus the geometric residual estimate
12252gives diagonal full-Regge convergence for any schedule into the product filter. -/
12253theorem CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData.fullReggeDiagonal_tendsto_continuum
12254    {α ρ δ : Type*} {l : Filter α} {m : Filter δ}
12255    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12256    (C : CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData D)
12257    (coefficient : ℝ)
12258    (coefficient_nonneg : 0 ≤ coefficient)
12259    (hMagnitude :
12260      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
12261        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12262            D.family p.1 p.2 ≤
12263          coefficient *
12264            (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12265                (D.family.slice p.1) p.2 +
12266              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12267                (D.family.slice p.1) p.2))
12268    (diagonal : δ → ρ × α)
12269    (hDiagonal :
12270      Filter.Tendsto diagonal m (D.refinementFilter ×ˢ l : Filter (ρ × α))) :
12271    Filter.Tendsto
12272      (fun s : δ =>
12273        CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
12274          (α := α) (ρ := ρ) D.family (diagonal s))
12275      m
12276      (nhds D.continuumIntegral) :=
12277  C.toSpacingCellScheduleEnvelopeData.fullReggeDiagonal_tendsto_continuum
12278    coefficient coefficient_nonneg hMagnitude diagonal hDiagonal
12279
12280/-- Common varying-cardinality schedule data plus the geometric residual estimate
12281also gives direct product-filter vanishing of the named residual magnitude. -/
12282theorem CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData.residualMagnitude_tendsto_zero
12283    {α ρ : Type*} {l : Filter α}
12284    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12285    (C : CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData D)
12286    (coefficient : ℝ)
12287    (coefficient_nonneg : 0 ≤ coefficient)
12288    (hMagnitude :
12289      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
12290        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12291            D.family p.1 p.2 ≤
12292          coefficient *
12293            (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12294                (D.family.slice p.1) p.2 +
12295              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12296                (D.family.slice p.1) p.2)) :
12297    Filter.Tendsto
12298      (fun p : ρ × α =>
12299        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12300          D.family p.1 p.2)
12301      (D.refinementFilter ×ˢ l : Filter (ρ × α))
12302      (nhds 0) :=
12303  C.toSpacingCellScheduleEnvelopeData.residualMagnitude_tendsto_zero
12304    coefficient coefficient_nonneg hMagnitude
12305
12306/-- Any diagonal schedule into the product filter inherits residual-magnitude
12307vanishing from common varying-cardinality schedule data plus the residual
12308estimate. -/
12309theorem CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData.residualMagnitudeDiagonal_tendsto_zero
12310    {α ρ δ : Type*} {l : Filter α} {m : Filter δ}
12311    {D : CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := ρ) l}
12312    (C : CanonicalPeriodicTetSixTetVolumeQuadratureCommonScheduleEnvelopeData D)
12313    (coefficient : ℝ)
12314    (coefficient_nonneg : 0 ≤ coefficient)
12315    (hMagnitude :
12316      ∀ᶠ p : ρ × α in (D.refinementFilter ×ˢ l),
12317        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12318            D.family p.1 p.2 ≤
12319          coefficient *
12320            (CanonicalPeriodicTetSixTetVolumeQuadratureSlice.spacingMagnitude
12321                (D.family.slice p.1) p.2 +
12322              CanonicalPeriodicTetSixTetVolumeQuadratureSlice.cellVolumeError
12323                (D.family.slice p.1) p.2))
12324    (diagonal : δ → ρ × α)
12325    (hDiagonal :
12326      Filter.Tendsto diagonal m (D.refinementFilter ×ˢ l : Filter (ρ × α))) :
12327    Filter.Tendsto
12328      (fun s : δ =>
12329        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12330          D.family (diagonal s).1 (diagonal s).2)
12331      m
12332      (nhds 0) :=
12333  C.toSpacingCellScheduleEnvelopeData.residualMagnitudeDiagonal_tendsto_zero
12334    coefficient coefficient_nonneg hMagnitude diagonal hDiagonal
12335
12336/-- The single-slice varying-cardinality family.  This is the first concrete
12337schedule-envelope instantiation: no cross-cardinality variation is present, so
12338the slice's own spacing and cell-volume error functions are the uniform
12339envelopes. -/
12340def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceRefinementFamily
12341    {α : Type*} {l : Filter α}
12342    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l) :
12343    CanonicalPeriodicTetSixTetVolumeQuadratureRefinementFamily l PUnit where
12344  slice := fun _ => S
12345
12346/-- A single-slice family has constant quadrature proxy along any
12347refinement-index filter on `PUnit`. -/
12348theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.singleSlice_crossCardinalityTarget
12349    {α : Type*} {l : Filter α}
12350    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
12351    (refinementFilter : Filter PUnit) :
12352    CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityTarget
12353      S.toSingleSliceRefinementFamily refinementFilter S.quadratureIntegral := by
12354  simpa [
12355    CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityTarget,
12356    CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceRefinementFamily] using
12357    (tendsto_const_nhds :
12358      Filter.Tendsto
12359        (fun _ : PUnit => S.quadratureIntegral)
12360        refinementFilter
12361        (nhds S.quadratureIntegral))
12362
12363/-- Cross-cardinality data for the single-slice family. -/
12364def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceCrossCardinalityData
12365    {α : Type*} {l : Filter α}
12366    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
12367    (refinementFilter : Filter PUnit) :
12368    CanonicalPeriodicTetSixTetVolumeQuadratureCrossCardinalityData (α := α) (ρ := PUnit) l where
12369  family := S.toSingleSliceRefinementFamily
12370  refinementFilter := refinementFilter
12371  continuumIntegral := S.quadratureIntegral
12372  quadrature_tendsto := S.singleSlice_crossCardinalityTarget refinementFilter
12373
12374/-- Product-filter data for the single-slice family.
12375
12376Since the cardinality index is `PUnit`, there is no genuine cross-cardinality
12377variation.  The product-filter residual is just the existing per-slice
12378full-Regge-to-quadrature residual pulled back along `Prod.snd`. -/
12379def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceProductFilterData
12380    {α : Type*} {l : Filter α}
12381    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
12382    (refinementFilter : Filter PUnit) :
12383    CanonicalPeriodicTetSixTetVolumeQuadratureProductFilterData (α := α) (ρ := PUnit) l where
12384  family := S.toSingleSliceRefinementFamily
12385  refinementFilter := refinementFilter
12386  continuumIntegral := S.quadratureIntegral
12387  quadrature_tendsto := S.singleSlice_crossCardinalityTarget refinementFilter
12388  uniform_residual := by
12389    have hFull := S.fullRegge_tendsto_quadratureIntegral
12390    have hResidual :
12391        Filter.Tendsto
12392          (fun t : α => S.fullReggeAggregate t - S.quadratureIntegral)
12393          l
12394          (nhds 0) := by
12395      simpa using hFull.sub (tendsto_const_nhds (x := S.quadratureIntegral))
12396    have hProduct :=
12397      hResidual.comp
12398        (Filter.tendsto_snd :
12399          Filter.Tendsto (Prod.snd : PUnit × α → α)
12400            (refinementFilter ×ˢ l) l)
12401    simpa [
12402      CanonicalPeriodicTetSixTetVolumeQuadratureProductUniformResidualTarget,
12403      CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate,
12404      CanonicalPeriodicTetSixTetVolumeQuadratureProductQuadratureIntegral,
12405      CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceRefinementFamily]
12406      using hProduct
12407
12408/-- The single-slice schedule envelope package, using the slice's own
12409`spacingMagnitude` and `cellVolumeError` as the envelopes. -/
12410def CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceScheduleEnvelopeData
12411    {α : Type*} {l : Filter α}
12412    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
12413    (refinementFilter : Filter PUnit) :
12414    CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellScheduleEnvelopeData
12415      (S.toSingleSliceCrossCardinalityData refinementFilter) where
12416  spacingEnvelope := S.spacingMagnitude
12417  cellVolumeEnvelope := S.cellVolumeError
12418  spacingEnvelope_tendsto_zero := S.spacingMagnitude_tendsto_zero
12419  cellVolumeEnvelope_tendsto_zero := S.cellVolumeError_tendsto_zero
12420  eventually_spacingMagnitude_le_envelope :=
12421    Filter.Eventually.of_forall (fun p : PUnit × α => by
12422      simp [
12423        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceCrossCardinalityData,
12424        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceRefinementFamily])
12425  eventually_cellVolumeError_le_envelope :=
12426    Filter.Eventually.of_forall (fun p : PUnit × α => by
12427      simp [
12428        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceCrossCardinalityData,
12429        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceRefinementFamily])
12430
12431/-- In the single-slice case, the explicit spacing/cell-volume residual estimate
12432implies that the named product residual magnitude tends to zero along the
12433within-slice filter. -/
12434theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.singleSlice_residualMagnitude_tendsto_zero_of_residualEstimate
12435    {α : Type*} {l : Filter α}
12436    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
12437    (coefficient : ℝ)
12438    (hMagnitude :
12439      ∀ᶠ t : α in l,
12440        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12441            S.toSingleSliceRefinementFamily PUnit.unit t ≤
12442          coefficient * (S.spacingMagnitude t + S.cellVolumeError t)) :
12443    Filter.Tendsto
12444      (fun t : α =>
12445        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12446          S.toSingleSliceRefinementFamily PUnit.unit t)
12447      l
12448      (nhds 0) := by
12449  have hUpper :
12450      Filter.Tendsto
12451        (CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope
12452          coefficient S.spacingMagnitude S.cellVolumeError)
12453        l
12454        (nhds 0) :=
12455    S.spacingCellEnvelope_tendsto_zero coefficient
12456  exact squeeze_zero'
12457    (Filter.Eventually.of_forall (fun t : α =>
12458      canonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude_nonneg
12459        S.toSingleSliceRefinementFamily PUnit.unit t))
12460    hMagnitude
12461    (by
12462      simpa [CanonicalPeriodicTetSixTetVolumeQuadratureSpacingCellEnvelope] using hUpper)
12463
12464/-- Single-slice product-filter convergence from the explicit spacing/cell-volume
12465residual estimate.  This is the complete single-slice schedule path; the only
12466remaining input is the geometric residual bound itself. -/
12467theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.singleSlice_fullReggeProduct_tendsto_continuum_of_residualEstimate
12468    {α : Type*} {l : Filter α}
12469    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
12470    (refinementFilter : Filter PUnit)
12471    (coefficient : ℝ)
12472    (coefficient_nonneg : 0 ≤ coefficient)
12473    (hMagnitude :
12474      ∀ᶠ p : PUnit × α in (refinementFilter ×ˢ l),
12475        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12476            S.toSingleSliceRefinementFamily p.1 p.2 ≤
12477          coefficient * (S.spacingMagnitude p.2 + S.cellVolumeError p.2)) :
12478    Filter.Tendsto
12479      (CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
12480        (α := α) (ρ := PUnit) S.toSingleSliceRefinementFamily)
12481      (refinementFilter ×ˢ l : Filter (PUnit × α))
12482      (nhds S.quadratureIntegral) :=
12483  (S.toSingleSliceScheduleEnvelopeData refinementFilter).fullReggeProduct_tendsto_continuum
12484    coefficient coefficient_nonneg
12485    (by
12486      simpa [
12487        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceCrossCardinalityData,
12488        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceRefinementFamily] using hMagnitude)
12489
12490/-- Single-slice diagonal convergence from the explicit spacing/cell-volume
12491residual estimate. -/
12492theorem CanonicalPeriodicTetSixTetVolumeQuadratureSlice.singleSlice_fullReggeDiagonal_tendsto_continuum_of_residualEstimate
12493    {α δ : Type*} {l : Filter α} {m : Filter δ}
12494    (S : CanonicalPeriodicTetSixTetVolumeQuadratureSlice l)
12495    (refinementFilter : Filter PUnit)
12496    (coefficient : ℝ)
12497    (coefficient_nonneg : 0 ≤ coefficient)
12498    (hMagnitude :
12499      ∀ᶠ p : PUnit × α in (refinementFilter ×ˢ l),
12500        CanonicalPeriodicTetSixTetVolumeQuadratureProductResidualMagnitude
12501            S.toSingleSliceRefinementFamily p.1 p.2 ≤
12502          coefficient * (S.spacingMagnitude p.2 + S.cellVolumeError p.2))
12503    (diagonal : δ → PUnit × α)
12504    (hDiagonal :
12505      Filter.Tendsto diagonal m (refinementFilter ×ˢ l : Filter (PUnit × α))) :
12506    Filter.Tendsto
12507      (fun s : δ =>
12508        CanonicalPeriodicTetSixTetVolumeQuadratureProductFullReggeAggregate
12509          (α := α) (ρ := PUnit) S.toSingleSliceRefinementFamily (diagonal s))
12510      m
12511      (nhds S.quadratureIntegral) :=
12512  (S.toSingleSliceScheduleEnvelopeData refinementFilter).fullReggeDiagonal_tendsto_continuum
12513    coefficient coefficient_nonneg
12514    (by
12515      simpa [
12516        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceCrossCardinalityData,
12517        CanonicalPeriodicTetSixTetVolumeQuadratureSlice.toSingleSliceRefinementFamily] using hMagnitude)
12518    diagonal hDiagonal
12519
12520/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
12521explicit Freudenthal coordinate realization, with the remaining flatness input
12522stated as the exact incident Freudenthal dihedral-angle sum. -/
12523theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_angleSum
12524    {α : Type*} {l : Filter α}
12525    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12526    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12527    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
12528    (hAngleSum : CanonicalPeriodicZeroDeficitAngleSumTarget Nx Ny Nz hx hy hz) :
12529    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
12530      ∀ {n : ℕ}
12531        (spacing : α → ℝ)
12532        (probe :
12533          Fin n →
12534            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12535        (weight : α → Fin n → ℝ)
12536        (limitWeight : Fin n → ℝ),
12537        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
12538          Filter.Tendsto spacing l (nhds 0) →
12539            (∀ᶠ t : α in l, spacing t ≠ 0) →
12540              Filter.Tendsto
12541                (fun t : α =>
12542                  ∑ i : Fin n,
12543                    weight t i *
12544                      (reggeAction
12545                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12546                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12547                        (spacing t • probe i) /
12548                        ‖spacing t‖ ^ (2 : ℕ)))
12549                l
12550                (nhds
12551                  (∑ i : Fin n,
12552                    limitWeight i *
12553                      ((1 / 2) *
12554                        canonicalDirichletEnergy
12555                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12556                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12557                          (probe i)))) :=
12558  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_zeroDeficit
12559    Nx Ny Nz hx hy hz hLocal
12560    (canonicalPeriodicGlobalZeroDeficitAtFlat_of_incidentAngleSum
12561      Nx Ny Nz hx hy hz hAngleSum)
12562
12563/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
12564explicit Freudenthal coordinate realization, with the remaining flatness input
12565stated as the typed periodic-edge angle-sum target. -/
12566theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_typedEdgeAngleSum
12567    {α : Type*} {l : Filter α}
12568    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12569    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12570    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
12571    (hTyped : CanonicalPeriodicTypedEdgeAngleSumTarget Nx Ny Nz) :
12572    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
12573      ∀ {n : ℕ}
12574        (spacing : α → ℝ)
12575        (probe :
12576          Fin n →
12577            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12578        (weight : α → Fin n → ℝ)
12579        (limitWeight : Fin n → ℝ),
12580        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
12581          Filter.Tendsto spacing l (nhds 0) →
12582            (∀ᶠ t : α in l, spacing t ≠ 0) →
12583              Filter.Tendsto
12584                (fun t : α =>
12585                  ∑ i : Fin n,
12586                    weight t i *
12587                      (reggeAction
12588                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12589                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12590                        (spacing t • probe i) /
12591                        ‖spacing t‖ ^ (2 : ℕ)))
12592                l
12593                (nhds
12594                  (∑ i : Fin n,
12595                    limitWeight i *
12596                      ((1 / 2) *
12597                        canonicalDirichletEnergy
12598                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12599                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12600                          (probe i)))) :=
12601  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_angleSum
12602    Nx Ny Nz hx hy hz hLocal
12603    (canonicalPeriodicZeroDeficitAngleSumTarget_of_typedEdgeAngleSum
12604      Nx Ny Nz hx hy hz hTyped)
12605
12606/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
12607explicit Freudenthal coordinate realization, with the remaining flatness input
12608stated as the direct typed cell/tetrahedron angle-sum target. -/
12609theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_directTypedAngleSum
12610    {α : Type*} {l : Filter α}
12611    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12612    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12613    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
12614    (hDirect : CanonicalPeriodicDirectTypedEdgeAngleSumTarget Nx Ny Nz) :
12615    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
12616      ∀ {n : ℕ}
12617        (spacing : α → ℝ)
12618        (probe :
12619          Fin n →
12620            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12621        (weight : α → Fin n → ℝ)
12622        (limitWeight : Fin n → ℝ),
12623        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
12624          Filter.Tendsto spacing l (nhds 0) →
12625            (∀ᶠ t : α in l, spacing t ≠ 0) →
12626              Filter.Tendsto
12627                (fun t : α =>
12628                  ∑ i : Fin n,
12629                    weight t i *
12630                      (reggeAction
12631                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12632                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12633                        (spacing t • probe i) /
12634                        ‖spacing t‖ ^ (2 : ℕ)))
12635                l
12636                (nhds
12637                  (∑ i : Fin n,
12638                    limitWeight i *
12639                      ((1 / 2) *
12640                        canonicalDirichletEnergy
12641                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12642                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12643                          (probe i)))) :=
12644  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_typedEdgeAngleSum
12645    Nx Ny Nz hx hy hz hLocal
12646    (canonicalPeriodicTypedEdgeAngleSumTarget_of_directTyped Nx Ny Nz hDirect)
12647
12648/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
12649explicit Freudenthal coordinate realization, with the remaining flatness input
12650stated as the explicit local-slot triple-sum angle target. -/
12651theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_localSlotTripleAngleSum
12652    {α : Type*} {l : Filter α}
12653    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12654    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12655    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
12656    (hTriple : CanonicalPeriodicLocalSlotTripleAngleSumTarget Nx Ny Nz) :
12657    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
12658      ∀ {n : ℕ}
12659        (spacing : α → ℝ)
12660        (probe :
12661          Fin n →
12662            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12663        (weight : α → Fin n → ℝ)
12664        (limitWeight : Fin n → ℝ),
12665        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
12666          Filter.Tendsto spacing l (nhds 0) →
12667            (∀ᶠ t : α in l, spacing t ≠ 0) →
12668              Filter.Tendsto
12669                (fun t : α =>
12670                  ∑ i : Fin n,
12671                    weight t i *
12672                      (reggeAction
12673                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12674                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12675                        (spacing t • probe i) /
12676                        ‖spacing t‖ ^ (2 : ℕ)))
12677                l
12678                (nhds
12679                  (∑ i : Fin n,
12680                    limitWeight i *
12681                      ((1 / 2) *
12682                        canonicalDirichletEnergy
12683                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12684                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12685                          (probe i)))) :=
12686  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_directTypedAngleSum
12687    Nx Ny Nz hx hy hz hLocal
12688    (canonicalPeriodicDirectTypedEdgeAngleSumTarget_of_localSlotTriple
12689      Nx Ny Nz hTriple)
12690
12691/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
12692explicit Freudenthal coordinate realization, with the remaining flatness input
12693stated as the displacement-filtered local-slot triple-sum angle target. -/
12694theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_dispFilteredLocalSlotTripleAngleSum
12695    {α : Type*} {l : Filter α}
12696    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12697    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12698    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
12699    (hDisp :
12700      CanonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget Nx Ny Nz) :
12701    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
12702      ∀ {n : ℕ}
12703        (spacing : α → ℝ)
12704        (probe :
12705          Fin n →
12706            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12707        (weight : α → Fin n → ℝ)
12708        (limitWeight : Fin n → ℝ),
12709        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
12710          Filter.Tendsto spacing l (nhds 0) →
12711            (∀ᶠ t : α in l, spacing t ≠ 0) →
12712              Filter.Tendsto
12713                (fun t : α =>
12714                  ∑ i : Fin n,
12715                    weight t i *
12716                      (reggeAction
12717                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12718                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12719                        (spacing t • probe i) /
12720                        ‖spacing t‖ ^ (2 : ℕ)))
12721                l
12722                (nhds
12723                  (∑ i : Fin n,
12724                    limitWeight i *
12725                      ((1 / 2) *
12726                        canonicalDirichletEnergy
12727                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12728                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12729                          (probe i)))) :=
12730  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_localSlotTripleAngleSum
12731    Nx Ny Nz hx hy hz hLocal
12732    (canonicalPeriodicLocalSlotTripleAngleSumTarget_of_dispFiltered
12733      Nx Ny Nz hDisp)
12734
12735/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
12736explicit Freudenthal coordinate realization, with the remaining flatness input
12737stated as the base-and-displacement filtered local-slot triple-sum angle
12738target. -/
12739theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_baseDispFilteredLocalSlotTripleAngleSum
12740    {α : Type*} {l : Filter α}
12741    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12742    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12743    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
12744    (hBase :
12745      CanonicalPeriodicBaseDispFilteredLocalSlotTripleAngleSumTarget Nx Ny Nz) :
12746    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
12747      ∀ {n : ℕ}
12748        (spacing : α → ℝ)
12749        (probe :
12750          Fin n →
12751            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12752        (weight : α → Fin n → ℝ)
12753        (limitWeight : Fin n → ℝ),
12754        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
12755          Filter.Tendsto spacing l (nhds 0) →
12756            (∀ᶠ t : α in l, spacing t ≠ 0) →
12757              Filter.Tendsto
12758                (fun t : α =>
12759                  ∑ i : Fin n,
12760                    weight t i *
12761                      (reggeAction
12762                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12763                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12764                        (spacing t • probe i) /
12765                        ‖spacing t‖ ^ (2 : ℕ)))
12766                l
12767                (nhds
12768                  (∑ i : Fin n,
12769                    limitWeight i *
12770                      ((1 / 2) *
12771                        canonicalDirichletEnergy
12772                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12773                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12774                          (probe i)))) :=
12775  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_dispFilteredLocalSlotTripleAngleSum
12776    Nx Ny Nz hx hy hz hLocal
12777    (canonicalPeriodicDispFilteredLocalSlotTripleAngleSumTarget_of_baseDispFiltered
12778      Nx Ny Nz hBase)
12779
12780/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
12781explicit Freudenthal coordinate realization, with the remaining flatness input
12782stated as the filtered incident typed cell/tetrahedron angle-sum target. -/
12783theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_incidentFilteredAngleSum
12784    {α : Type*} {l : Filter α}
12785    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12786    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12787    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
12788    (hIncident : CanonicalPeriodicIncidentFilteredEdgeAngleSumTarget Nx Ny Nz) :
12789    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
12790      ∀ {n : ℕ}
12791        (spacing : α → ℝ)
12792        (probe :
12793          Fin n →
12794            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12795        (weight : α → Fin n → ℝ)
12796        (limitWeight : Fin n → ℝ),
12797        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
12798          Filter.Tendsto spacing l (nhds 0) →
12799            (∀ᶠ t : α in l, spacing t ≠ 0) →
12800              Filter.Tendsto
12801                (fun t : α =>
12802                  ∑ i : Fin n,
12803                    weight t i *
12804                      (reggeAction
12805                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12806                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12807                        (spacing t • probe i) /
12808                        ‖spacing t‖ ^ (2 : ℕ)))
12809                l
12810                (nhds
12811                  (∑ i : Fin n,
12812                    limitWeight i *
12813                      ((1 / 2) *
12814                        canonicalDirichletEnergy
12815                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12816                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12817                          (probe i)))) :=
12818  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_directTypedAngleSum
12819    Nx Ny Nz hx hy hz hLocal
12820    (canonicalPeriodicDirectTypedEdgeAngleSumTarget_of_incidentFiltered
12821      Nx Ny Nz hIncident)
12822
12823/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
12824explicit Freudenthal coordinate realization, with the remaining flatness input
12825stated as the slot-witness filtered incident angle-sum target. -/
12826theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_slotWitnessFilteredAngleSum
12827    {α : Type*} {l : Filter α}
12828    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12829    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12830    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
12831    (hSlot :
12832      CanonicalPeriodicSlotWitnessFilteredEdgeAngleSumTarget Nx Ny Nz) :
12833    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
12834      ∀ {n : ℕ}
12835        (spacing : α → ℝ)
12836        (probe :
12837          Fin n →
12838            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12839        (weight : α → Fin n → ℝ)
12840        (limitWeight : Fin n → ℝ),
12841        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
12842          Filter.Tendsto spacing l (nhds 0) →
12843            (∀ᶠ t : α in l, spacing t ≠ 0) →
12844              Filter.Tendsto
12845                (fun t : α =>
12846                  ∑ i : Fin n,
12847                    weight t i *
12848                      (reggeAction
12849                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12850                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12851                        (spacing t • probe i) /
12852                        ‖spacing t‖ ^ (2 : ℕ)))
12853                l
12854                (nhds
12855                  (∑ i : Fin n,
12856                    limitWeight i *
12857                      ((1 / 2) *
12858                        canonicalDirichletEnergy
12859                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12860                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12861                          (probe i)))) :=
12862  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_incidentFilteredAngleSum
12863    Nx Ny Nz hx hy hz hLocal
12864    (canonicalPeriodicIncidentFilteredEdgeAngleSumTarget_of_slotWitnessFiltered
12865      Nx Ny Nz hSlot)
12866
12867/-- Full nonlinear Regge finite aggregate in Dirichlet-energy form from the
12868explicit Freudenthal coordinate realization, with the remaining flatness input
12869stated as the geometric `localEdgeOf` filtered angle-sum target. -/
12870theorem canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_localEdgeOfFilteredAngleSum
12871    {α : Type*} {l : Filter α}
12872    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12873    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12874    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
12875    (hEdgeOf :
12876      CanonicalPeriodicLocalEdgeOfFilteredEdgeAngleSumTarget Nx Ny Nz) :
12877    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
12878      ∀ {n : ℕ}
12879        (spacing : α → ℝ)
12880        (probe :
12881          Fin n →
12882            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12883        (weight : α → Fin n → ℝ)
12884        (limitWeight : Fin n → ℝ),
12885        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
12886          Filter.Tendsto spacing l (nhds 0) →
12887            (∀ᶠ t : α in l, spacing t ≠ 0) →
12888              Filter.Tendsto
12889                (fun t : α =>
12890                  ∑ i : Fin n,
12891                    weight t i *
12892                      (reggeAction
12893                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12894                        (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12895                        (spacing t • probe i) /
12896                        ‖spacing t‖ ^ (2 : ℕ)))
12897                l
12898                (nhds
12899                  (∑ i : Fin n,
12900                    limitWeight i *
12901                      ((1 / 2) *
12902                        canonicalDirichletEnergy
12903                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12904                          (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12905                          (probe i)))) :=
12906  canonicalPeriodicFullRegge_variable_weighted_finite_probe_spacing_scaled_div_spacing_norm_sq_tendsto_dirichlet_of_freudenthalRealization_slotWitnessFilteredAngleSum
12907    Nx Ny Nz hx hy hz hLocal
12908    (canonicalPeriodicSlotWitnessFilteredEdgeAngleSumTarget_of_localEdgeOfFiltered
12909      Nx Ny Nz hEdgeOf)
12910
12911/-- Spacing-scaled finite residual from canonical second-order Regge aggregates
12912to a supplied fixed physical action.  This uses only the fixed-action `C a^2`
12913estimate in `D`; it does not assume continuity or homogeneity of the supplied
12914fixed action. -/
12915theorem CanonicalPeriodicFixedPhysicalActionComparisonData.variable_weighted_finite_probe_spacing_scaled_secondOrder_residual_tendsto_zero
12916    {α : Type*} {l : Filter α}
12917    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
12918    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
12919    (D : CanonicalPeriodicFixedPhysicalActionComparisonData l Nx Ny Nz hx hy hz)
12920    {n : ℕ}
12921    (probe :
12922      Fin n →
12923        VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
12924    (weight : α → Fin n → ℝ)
12925    (limitWeight : Fin n → ℝ)
12926    (hWeight :
12927      ∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) :
12928    Filter.Tendsto
12929      (fun t : α =>
12930        (∑ i : Fin n,
12931          weight t i *
12932            reggeActionSecondOrder
12933              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12934              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12935              (canonicalReggeHessian
12936                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12937                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
12938              (D.spacing t • probe i)) -
12939          ∑ i : Fin n,
12940            weight t i *
12941              D.fixedAction (D.spacing t • probe i))
12942      l (nhds 0) := by
12943  classical
12944  have hEnvelope :
12945      Filter.Tendsto
12946        (fun t : α => D.errorConstant t * D.spacing t ^ (2 : ℕ))
12947        l (nhds 0) := by
12948    apply squeeze_zero
12949    · intro t
12950      exact mul_nonneg (D.error_nonneg t) (sq_nonneg (D.spacing t))
12951    · intro t
12952      exact mul_le_mul_of_nonneg_right (D.error_bound t) (sq_nonneg (D.spacing t))
12953    · have hcont : Continuous (fun a : ℝ => D.errorBound * a ^ (2 : ℕ)) := by
12954        continuity
12955      have ht := hcont.tendsto (0 : ℝ)
12956      simpa using ht.comp D.spacing_tendsto_zero
12957  have hSum :
12958      Filter.Tendsto
12959        (fun t : α =>
12960          ∑ i : Fin n,
12961            weight t i *
12962              (reggeActionSecondOrder
12963                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12964                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12965                (canonicalReggeHessian
12966                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12967                  (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
12968                (D.spacing t • probe i) -
12969              D.fixedAction (D.spacing t • probe i)))
12970        l (nhds 0) := by
12971    simpa using
12972      (tendsto_finset_sum (Finset.univ : Finset (Fin n))
12973        (f := fun i (t : α) =>
12974          weight t i *
12975            (reggeActionSecondOrder
12976              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12977              (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12978              (canonicalReggeHessian
12979                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12980                (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
12981              (D.spacing t • probe i) -
12982            D.fixedAction (D.spacing t • probe i)))
12983        (a := fun _i => 0)
12984        (by
12985          intro i _hi
12986          have hAbs :
12987              Filter.Tendsto
12988                (fun t : α =>
12989                  |reggeActionSecondOrder
12990                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12991                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
12992                    (canonicalReggeHessian
12993                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
12994                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
12995                    (D.spacing t • probe i) -
12996                    D.fixedAction (D.spacing t • probe i)|)
12997                l (nhds 0) := by
12998            apply squeeze_zero
12999            · intro t
13000              exact abs_nonneg _
13001            · intro t
13002              exact D.estimate t (D.spacing t • probe i)
13003            · exact hEnvelope
13004          have hScalar :
13005              Filter.Tendsto
13006                (fun t : α =>
13007                  reggeActionSecondOrder
13008                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
13009                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
13010                    (canonicalReggeHessian
13011                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
13012                      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK)
13013                    (D.spacing t • probe i) -
13014                  D.fixedAction (D.spacing t • probe i))
13015                l (nhds 0) := by
13016            apply tendsto_iff_dist_tendsto_zero.mpr
13017            simpa [Real.dist_eq] using hAbs
13018          simpa using (hWeight i).mul hScalar))
13019  simpa [Finset.sum_sub_distrib, mul_sub] using hSum
13020
13021/-- Total finite variable-weight residual from full nonlinear Regge aggregates
13022to a supplied fixed physical action, for spacing-scaled probes.  This composes
13023the local nonlinear residual layer with the fixed-action `C a^2` comparison
13024layer.  The target remains finite and local; no global EH integral statement is
13025claimed here. -/
13026theorem CanonicalPeriodicFixedPhysicalActionComparisonData.variable_weighted_finite_probe_spacing_scaled_full_regge_residual_tendsto_zero
13027    {α : Type*} {l : Filter α}
13028    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
13029    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
13030    (D : CanonicalPeriodicFixedPhysicalActionComparisonData l Nx Ny Nz hx hy hz)
13031    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz) :
13032    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
13033      ∀ {n : ℕ}
13034        (probe :
13035          Fin n →
13036            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
13037        (weight : α → Fin n → ℝ)
13038        (limitWeight : Fin n → ℝ),
13039        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
13040          Filter.Tendsto
13041            (fun t : α =>
13042              (∑ i : Fin n,
13043                weight t i *
13044                  reggeAction
13045                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
13046                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
13047                    (D.spacing t • probe i)) -
13048                ∑ i : Fin n,
13049                  weight t i *
13050                    D.fixedAction (D.spacing t • probe i))
13051            l (nhds 0) := by
13052  rcases canonicalPeriodicNonlinearAggregate_variable_weighted_finite_probe_spacing_scaled_to_secondOrder_residual_tendsto_zero
13053      Nx Ny Nz hx hy hz hLocal with
13054    ⟨r, C, hr, hC, hNonlinear⟩
13055  refine ⟨r, C, hr, hC, ?_⟩
13056  intro n probe weight limitWeight hWeight
13057  have hFirst :=
13058    hNonlinear D.spacing probe weight limitWeight hWeight D.spacing_tendsto_zero
13059  have hSecond :=
13060    CanonicalPeriodicFixedPhysicalActionComparisonData.variable_weighted_finite_probe_spacing_scaled_secondOrder_residual_tendsto_zero
13061      Nx Ny Nz hx hy hz D probe weight limitWeight hWeight
13062  simpa [sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using hFirst.add hSecond
13063
13064/-- If the supplied fixed physical action is continuous at the zero
13065perturbation, the spacing-scaled finite full-Regge aggregate converges to the
13066corresponding zero-perturbation fixed-action aggregate.  This is the next
13067interface toward a fixed-continuum Riemann-sum statement; it only adds the
13068explicit continuity-at-zero hypothesis and still does not identify the global
13069Einstein-Hilbert integral. -/
13070theorem CanonicalPeriodicFixedPhysicalActionComparisonData.variable_weighted_finite_probe_spacing_scaled_full_regge_tendsto_fixed_zero
13071    {α : Type*} {l : Filter α}
13072    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
13073    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
13074    (D : CanonicalPeriodicFixedPhysicalActionComparisonData l Nx Ny Nz hx hy hz)
13075    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
13076    (hFixedContinuousAtZero : ContinuousAt D.fixedAction 0) :
13077    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
13078      ∀ {n : ℕ}
13079        (probe :
13080          Fin n →
13081            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
13082        (weight : α → Fin n → ℝ)
13083        (limitWeight : Fin n → ℝ),
13084        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
13085          Filter.Tendsto
13086            (fun t : α =>
13087              (∑ i : Fin n,
13088                weight t i *
13089                  reggeAction
13090                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
13091                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
13092                    (D.spacing t • probe i)) -
13093                ∑ i : Fin n,
13094                  limitWeight i * D.fixedAction 0)
13095            l (nhds 0) := by
13096  classical
13097  rcases CanonicalPeriodicFixedPhysicalActionComparisonData.variable_weighted_finite_probe_spacing_scaled_full_regge_residual_tendsto_zero
13098      Nx Ny Nz hx hy hz D hLocal with
13099    ⟨r, C, hr, hC, hFullResidual⟩
13100  refine ⟨r, C, hr, hC, ?_⟩
13101  intro n probe weight limitWeight hWeight
13102  have hResidual := hFullResidual probe weight limitWeight hWeight
13103  have hFixedAggregate :
13104      Filter.Tendsto
13105        (fun t : α =>
13106          ∑ i : Fin n,
13107            weight t i * D.fixedAction (D.spacing t • probe i))
13108        l (nhds (∑ i : Fin n, limitWeight i * D.fixedAction 0)) := by
13109    simpa using
13110      (tendsto_finset_sum (Finset.univ : Finset (Fin n))
13111        (f := fun i (t : α) =>
13112          weight t i * D.fixedAction (D.spacing t • probe i))
13113        (a := fun i => limitWeight i * D.fixedAction 0)
13114        (by
13115          intro i _hi
13116          have hScaledNorm :
13117              Filter.Tendsto
13118                (fun t : α => ‖D.spacing t • probe i‖) l (nhds 0) := by
13119            have hSpacingNorm :
13120                Filter.Tendsto (fun t : α => ‖D.spacing t‖) l (nhds (0 : ℝ)) := by
13121              simpa using D.spacing_tendsto_zero.norm
13122            have hMul :
13123                Filter.Tendsto (fun t : α => ‖D.spacing t‖ * ‖probe i‖) l
13124                  (nhds ((0 : ℝ) * ‖probe i‖)) :=
13125              hSpacingNorm.mul tendsto_const_nhds
13126            simpa [norm_smul] using hMul
13127          have hScaled :
13128              Filter.Tendsto (fun t : α => D.spacing t • probe i) l (nhds 0) := by
13129            apply Metric.tendsto_nhds.mpr
13130            intro ε hε
13131            have hDist := (Metric.tendsto_nhds.mp hScaledNorm) ε hε
13132            exact hDist.mono (fun t ht => by
13133              simpa [Real.dist_eq, dist_zero_right] using ht)
13134          have hAction :
13135              Filter.Tendsto
13136                (fun t : α => D.fixedAction (D.spacing t • probe i))
13137                l (nhds (D.fixedAction 0)) :=
13138            hFixedContinuousAtZero.tendsto.comp hScaled
13139          exact (hWeight i).mul hAction))
13140  let limitSum : ℝ := ∑ i : Fin n, limitWeight i * D.fixedAction 0
13141  have hConst : Filter.Tendsto (fun _t : α => limitSum) l (nhds limitSum) :=
13142    tendsto_const_nhds
13143  have hFixedResidual :
13144      Filter.Tendsto
13145        (fun t : α =>
13146          (∑ i : Fin n,
13147            weight t i * D.fixedAction (D.spacing t • probe i)) - limitSum)
13148        l (nhds 0) := by
13149    simpa [limitSum] using hFixedAggregate.sub hConst
13150  simpa [limitSum, sub_eq_add_neg, add_comm, add_left_comm, add_assoc] using
13151    hResidual.add hFixedResidual
13152
13153/-- Zero-normalized form of the finite spacing-scaled full-Regge aggregate
13154limit.  If the supplied fixed physical action is continuous at zero and
13155vanishes at zero, the finite mesh-weighted full nonlinear Regge aggregate on
13156spacing-scaled probes tends to zero. -/
13157theorem CanonicalPeriodicFixedPhysicalActionComparisonData.variable_weighted_finite_probe_spacing_scaled_full_regge_tendsto_zero_of_fixed_zero
13158    {α : Type*} {l : Filter α}
13159    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
13160    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz)
13161    (D : CanonicalPeriodicFixedPhysicalActionComparisonData l Nx Ny Nz hx hy hz)
13162    (hLocal : CanonicalPeriodicEdgeStencilLocalCorrespondence Nx Ny Nz hx hy hz)
13163    (hFixedContinuousAtZero : ContinuousAt D.fixedAction 0)
13164    (hFixedZero : D.fixedAction 0 = 0) :
13165    ∃ (r C : ℝ), 0 < r ∧ 0 ≤ C ∧
13166      ∀ {n : ℕ}
13167        (probe :
13168          Fin n →
13169            VertexPotential (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K)
13170        (weight : α → Fin n → ℝ)
13171        (limitWeight : Fin n → ℝ),
13172        (∀ i : Fin n, Filter.Tendsto (fun t : α => weight t i) l (nhds (limitWeight i))) →
13173          Filter.Tendsto
13174            (fun t : α =>
13175              ∑ i : Fin n,
13176                weight t i *
13177                  reggeAction
13178                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
13179                    (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK
13180                    (D.spacing t • probe i))
13181            l (nhds 0) := by
13182  rcases CanonicalPeriodicFixedPhysicalActionComparisonData.variable_weighted_finite_probe_spacing_scaled_full_regge_tendsto_fixed_zero
13183      Nx Ny Nz hx hy hz D hLocal hFixedContinuousAtZero with
13184    ⟨r, C, hr, hC, hFixedZeroLimit⟩
13185  refine ⟨r, C, hr, hC, ?_⟩
13186  intro n probe weight limitWeight hWeight
13187  simpa [hFixedZero] using hFixedZeroLimit probe weight limitWeight hWeight
13188
13189theorem exactPeriodicFreudenthalComparisonCertificate_hessian_is_dirichlet
13190    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
13191    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) :
13192    (exactPeriodicFreudenthalComparisonCertificate P).canonicalHessian_is_dirichlet :=
13193  canonicalHessianIsDirichlet_of_encodedPeriodicFreudenthal P
13194
13195theorem exactPeriodicFreudenthalComparisonCertificate_physicalFiniteDifference_identification
13196    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
13197    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) :
13198    PhysicalFiniteDifferenceDirichletTarget P
13199      (exactPeriodicFreudenthalComparisonCertificate P).physicalFiniteDifferenceAction :=
13200  (exactPeriodicFreudenthalComparisonCertificate P).physicalFiniteDifference_identification
13201
13202def exactPhysicalSixTetModel_of_encodedPeriodicFreudenthal
13203    {Nx Ny Nz : ℕ} [NeZero Nx] [NeZero Ny] [NeZero Nz]
13204    (P : EncodedPeriodicFreudenthalTorus Nx Ny Nz) :
13205    PhysicalSixTetCubicDirichletModel P.K P.hK :=
13206  physicalSixTetModel_of_periodicFreudenthalCertificate
13207    (exactPeriodicFreudenthalComparisonCertificate P)
13208
13209theorem canonicalPeriodicEdgeStencilComparisonCertificate_physicalFiniteDifference
13210    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
13211    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
13212    PhysicalFiniteDifferenceDirichletTarget
13213      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz)
13214      (canonicalPeriodicEdgeStencilComparisonCertificate Nx Ny Nz hx hy hz).physicalFiniteDifferenceAction :=
13215  (canonicalPeriodicEdgeStencilComparisonCertificate Nx Ny Nz hx hy hz).physicalFiniteDifference_identification
13216
13217def physicalSixTetModel_of_canonicalPeriodicEdgeStencil
13218    (Nx Ny Nz : ℕ) [NeZero Nx] [NeZero Ny] [NeZero Nz]
13219    (hx : 2 < Nx) (hy : 2 < Ny) (hz : 2 < Nz) :
13220    PhysicalSixTetCubicDirichletModel
13221      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).K
13222      (canonicalEncodedPeriodicFreudenthalTorus Nx Ny Nz hx hy hz).hK :=
13223  physicalSixTetModel_of_periodicFreudenthalCertificate
13224    (canonicalPeriodicEdgeStencilComparisonCertificate Nx Ny Nz hx hy hz)
13225
13226end
13227
13228end PhysicalSixTetCubicDirichletInstance
13229end Gravity
13230end IndisputableMonolith
13231

source mirrored from github.com/jonwashburn/shape-of-logic