import Mathlib.Data.Vector.Basicimport Mathlib.Data.Matrix.Notationimport Mathlib.Data.ZMod.Basicimport Mathlib.LinearAlgebra.Matrix.ToLinnamespace FibonacciMeansdef witness : ℕ := 10746306683562733203036660980572774916552278570437493abbrev R := ZMod witnessabbrev M := Matrix (Fin 5) (Fin 5) Rdef step : M := !![1,4,4,0,0; 2,7,6,0,0; 4,12,9,0,0; 0,0,1,1,0; 1,0,0,0,1]def initial : Fin 5 → R := ![1,1,1,0,0]def bits : ℕ → ℕ → List Bool| 0, _ => []| t+1, n => decide (n%2=1) :: bits t (n/2)def value : List Bool → ℕ| [] => 0| b::bs => 2*value bs + if b then 1 else 0def fast {α : Type} [Monoid α] (x : α) : List Bool → α| [] => 1| b::bs => let y := fast x bs; (y*y)*(if b then x else 1)theorem fast_correct {α : Type} [Monoid α] (x : α) (bs : List Bool) :fast x bs = x^(value bs) := byinduction bs with| nil => simp [value,fast]| cons b bs ih =>cases b <;> simp [fast,value,ih,two_mul,pow_add]abbrev Rows := Mathlib.Vector (Mathlib.Vector R 5) 5def pack (m : M) : Rows := Mathlib.Vector.ofFn (fun i => Mathlib.Vector.ofFn (m i))def unpack (v : Rows) : M := fun i j => (v.get i).get jtheorem unpack_pack (m : M) : unpack (pack m) = m := byfunext i jsimp [pack,unpack, Mathlib.Vector.get_ofFn]def dense : List Bool → Rows| [] => pack 1| b::bs => let y := dense bs; let s := pack (unpack y * unpack y)if b then pack (unpack s * step) else stheorem dense_correct (bs : List Bool) : unpack (dense bs) = fast step bs := byinduction bs with| nil => exact unpack_pack _| cons b bs ih => cases b <;> simp [dense,fast,unpack_pack,ih]def digits := bits 174 witnesstheorem witness_residue :((step^witness).mulVec initial) 4 = 0 := byhave e : value digits = witness := by native_decidehave hp : fast step digits = step^witness := (fast_correct step digits).trans (congrArg (fun n : ℕ => step^n) e)calc_ = (unpack (dense digits)).mulVec initial 4 :=congrArg (fun m : M => m.mulVec initial 4) ((dense_correct digits).trans hp).symm_ = 0 := by native_decideend FibonacciMeans#print axioms FibonacciMeans.witness_residue