Round-eight alternating residual transport interface
DefinitionIntMul_Kappa_R8_AlternatingTransportThe computational interface fixes the two-mask residual, its thirteen-step phase-corrected gate list, and the binary weight, pairing and Fourier kernel.
Definition code
import Definitions.Def_IntMul_Kappa_R6_Defs2
import Mathlib.Algebra.BigOperators.Group.Finset.Sigma
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Field.ZMod
import Mathlib.Data.Complex.Basic
import Mathlib.Data.Fintype.Card
import Mathlib.Data.Fintype.Pi
import Mathlib.LinearAlgebra.Matrix.Notation
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.FinCases
import Mathlib.Tactic.IntervalCases
import Mathlib.Tactic.Linarith
import Mathlib.Tactic.LinearCombination
import Mathlib.Tactic.NormNum
import Mathlib.Tactic.Ring
namespace CxGaussSigned
open Complex
variable {r n : ℕ}
abbrev Bit := ZMod 2
abbrev Vector (r : ℕ) := Fin r → Bit
def sign (x : Bit) : ℂ := if x = 0 then 1 else -1
def phaseBit (neg : Bool) (x : Bit) : ℂ :=
if x = 0 then 1 else if neg then -I else I
/-- The quadratic phase of a basis embedding with arbitrary coordinate signs. -/
def weightPhase (L : Vector r →ₗ[Bit] Vector n) (neg : Fin n → Bool) (x : Vector r) : ℂ :=
∏ i, phaseBit (neg i) (L x i)
def gram (L : Vector r →ₗ[Bit] Vector n) (y t : Vector r) : Bit := ∑ i, L y i * L t i
end CxGaussSigned
namespace CxPhaseWrap
open Matrix Complex Butterfly P8Lift IntMul.Kappa.R6.Cx
variable {R : Type} {m : ℕ}
abbrev Other (j : Fin m) := {i : Fin m // i ≠ j}
/-- Accumulate the indicated row parity on j, phase it, then undo the address changes. -/
def program (w : R) (j : Fin m) (a : ℕ) : List (Other j) → List (HStep R m)
| [] => [HStep.phase w 0 0 (fun t => if t = j then a else 0)]
| i :: is => HStep.rowAdd w i.val j i.property :: (program w j a is ++ [HStep.rowAdd w i.val j i.property])
end CxPhaseWrap
namespace CxAlternatingPlane
open Matrix Complex Butterfly P8Lift IntMul.Kappa.R6.Cx
def paritySteps : List (HStep Unit 2) := CxPhaseWrap.program () 0 3 [⟨1, by decide⟩]
def swapSteps : List (HStep Unit 2) :=
[.rowAdd () 0 1 (by decide), .rowAdd () 1 0 (by decide), .rowAdd () 0 1 (by decide)]
def middle : HStep Unit 2 := .child () Finset.univ ∅
def scalar : HStep Unit 2 := .phase () 0 1 (fun _ => 0)
/-- One rank-two child, with an address swap and phases on either side. -/
def steps : List (HStep Unit 2) := paritySteps ++ swapSteps ++ [middle] ++ paritySteps ++ [scalar]
end CxAlternatingPlane
namespace CxPlaneFourier
open CxGaussSigned
def coords (a b : Fin 2) : Vector 2 := ![a, b]
end CxPlaneFourier
namespace CxPlaneReuse
open CxGaussSigned Complex
def rawWeight {n : ℕ} (L : Vector 2 →ₗ[Bit] Vector n) (z : Vector 2) : ℕ :=
∑ i, (L z i).val
noncomputable def modelKernel {n : ℕ} (L : Vector 2 →ₗ[Bit] Vector n) (u v : Vector 2) : ℂ :=
(∑ z : Vector 2, weightPhase L (fun _ => false) z * sign (gram L z (u+v))) / 4
/-- Basis embedding specified by two ambient bit masks. Bit zero denotes
the first point in the upstream integer-mask representation. -/
def twoMasks (n a b : ℕ) : Vector 2 →ₗ[Bit] Vector n where
toFun z i := (if a.testBit i.val then z 0 else 0) + (if b.testBit i.val then z 1 else 0)
map_add' x y := by
funext i
by_cases h : a.testBit i.val <;> by_cases k : b.testBit i.val <;> simp [h,k,add_assoc,add_comm,add_left_comm]
map_smul' w y := by
funext i
by_cases h : a.testBit i.val <;> by_cases k : b.testBit i.val <;> simp [h,k,mul_add]
end CxPlaneReuse
namespace CxH24
open Butterfly P8Lift IntMul.Kappa.R6.Cx CxPlaneReuse CxAlternatingPlane
abbrev firstPlane := twoMasks 24 18 16777162
def charStep (k : ℕ) : HStep Unit 2 := .phase () 0 k ![0,2]
def firstSteps : List (HStep Unit 2) := [charStep 0] ++ steps ++ [charStep 2]
end CxH24
Source