import ECDSAAdd.Framework.RunAppendAgreement import ECDSAAdd.Submission.Entrant.BOptimizations import ECDSAAdd.Submission.Entrant.StairSideA import ECDSAAdd.Submission.Entrant.QTop import ECDSAAdd.Submission.Entrant.Stair44Stock import Mathlib.Tactic import ECDSAAdd.Framework.WireRenamePool import ECDSAAdd.Submission.Entrant.CRT import ECDSAAdd.Submission.Entrant.OddField import ECDSAAdd.Framework.RecordedPaths import ECDSAAdd.Framework.MeasuredLocality import ECDSAAdd.Submission.Entrant.MainP1 import ECDSAAdd.Submission.Entrant.Mixed20D section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldCosts open Arithmetic MappedCompressed Stair44Resources StairConcreteAssembly StairArchiveInactive open StairArchiveRelease StairArchiveNativeCut StairArchiveTen StairArchiveGates set_option maxRecDepth 14000 set_option maxHeartbeats 1600000 set_option linter.unusedSimpArgs false attribute [local irreducible] toffoliCount measurementCount StairGroups.packet StairArchiveInactive.packet fieldHook def distributed (d : Bool) (j n : Nat) := PacketSequence.program d (StairArchiveInactive.packet d) j n theorem ren (f : Wire → Wire) (a b : Program) : renameProgram f (a++b)=renameProgram f a++renameProgram f b := List.map_append theorem distribute (d : Bool) (j n : Nat) : StairHostsSchedule.hostedGroup hostPlan d 0 j n = distributed d j n := by change StairLoan.rebindMany StairSchedule.exclusiveRoles (StairPhysicalLayout.hosts 87) (renameProgram (OB5.sig 511) (PacketSequence.program d (StairGroups.packet d 0) j n)) = _ simp only [hosts_eq,distributed,renameProgram_comp] induction n generalizing j with | zero => rfl | succ n ih => cases d <;> simp only [PacketSequence.program,if_true,if_false,Bool.false_eq_true, ren,ih,StairArchiveInactive.packet,hosts_eq,renameProgram_comp] def group (d : Bool) (j n : Nat) := StairHostsSchedule.hostedGroup hostPlan d 0 j n def ordered (d : Bool) (a b : Program) := if d then a++b else b++a /-- oddten: packets `1..84` of both kernels run the odd-word cell (`dstart` / `dend` on the division kernel, `mend` / `mstart` on the multiplication kernel), inside the archive ten-blocks too; packets `85..84` run the record packets. -/ def oddPk (d : Bool) (k : Nat) : Program := if 1≤k ∧ k<84 then RouteA.Rolling1588.packet d k else if k=84 then OddFullPass.P1LifeLoan.packet d 0 84 else ECDSAAdd.Entrant.Rolling1588.packet d k /-- packet `k` of the field group, hosted like the record packets. -/ def opk (d : Bool) (k : Nat) : Program := StairLoan.rebindMany StairSchedule.exclusiveRoles (StairPhysicalLayout.hosts 87) (renameProgram (OB5.sig 511) (oddPk d k)) def ogroup (d : Bool) (j n : Nat) : Program := PacketSequence.program d (opk d) j n def ofirst (j : Nat) (rev : Bool) := opk (!rev) (if rev then j+1 else j) def osecond (j : Nat) (rev : Bool) := opk (!rev) (if rev then j else j+1) /-- dadon's archive ten-block around the field group's own packets `j`, `j+1`. -/ def oten (j : Nat) (rev : Bool) := fieldHook j (enter rev) ++ (ofirst j rev ++ (fieldHook j (shift rev) ++ (osecond j rev ++ fieldHook j (leave rev)))) /-- the field group: the odd-word cell on packets 1..84 with the archive ten-blocks of the window banks 25, 28, ..., 55 (bank `b` belongs to the block starting at tick `5b-5`) around the cell's own packets. -/ def group84 (d : Bool) : Program := ordered d (ogroup d 1 9) (ordered d (oten 10 (!d)) (ordered d (ogroup d 12 1) (ordered d (oten 13 (!d)) (ordered d (ogroup d 15 1) (ordered d (oten 16 (!d)) (ordered d (ogroup d 18 1) (ordered d (oten 19 (!d)) (ordered d (ogroup d 21 1) (ordered d (oten 22 (!d)) (ordered d (ogroup d 24 1) (ordered d (oten 25 (!d)) (ordered d (ogroup d 27 1) (ordered d (oten 28 (!d)) (ordered d (ogroup d 30 1) (ordered d (oten 31 (!d)) (ordered d (ogroup d 33 2) (ordered d (oten 35 (!d)) (ordered d (ogroup d 37 2) (ordered d (oten 39 (!d)) (ordered d (ogroup d 41 2) (ordered d (oten 43 (!d)) (ordered d (ogroup d 45 2) (ordered d (oten 47 (!d)) (ordered d (ogroup d 49 2) (ordered d (oten 51 (!d)) (ordered d (ogroup d 53 2) (ordered d (oten 55 (!d)) (ordered d (ogroup d 57 2) (ordered d (oten 59 (!d)) (ordered d (ogroup d 61 2) (ordered d (oten 63 (!d)) (ordered d (ogroup d 65 2) (ordered d (oten 67 (!d)) (ordered d (ogroup d 69 1) (ordered d (oten 70 (!d)) (ordered d (ogroup d 72 1) (ordered d (oten 73 (!d)) (ordered d (ogroup d 75 1) (ordered d (oten 76 (!d)) (ordered d (ogroup d 78 1) (ordered d (oten 79 (!d)) (ordered d (ogroup d 81 1) (ordered d (oten 82 (!d)) ((ogroup d 84 1))))))))))))))))))))))))))))))))))))))))))))) theorem oddPk_mid (d : Bool) (k : Nat) (h1 : 1≤k) (h2 : k<84) : oddPk d k=RouteA.Rolling1588.packet d k := by unfold oddPk; rw [if_pos ⟨h1,h2⟩] theorem oddPk_end (d : Bool) : oddPk d 84=OddFullPass.P1LifeLoan.packet d 0 84 := by unfold oddPk; rw [if_neg (by decide),if_pos rfl] theorem oddPk_std (d : Bool) (k : Nat) (h : 84 ot_opk_sub d k) j n theorem ot_oten_sub (j : Nat) (rev : Bool) : wires (oten j rev) ⊆ wires (ten j rev) := by simp only [oten,ten,ofirst,osecond,StairArchiveTen.first,StairArchiveTen.second] exact StairLoanGroupSupport.append_sub _ _ _ _ (Finset.Subset.refl _) (StairLoanGroupSupport.append_sub _ _ _ _ (ot_opk_sub _ _) (StairLoanGroupSupport.append_sub _ _ _ _ (Finset.Subset.refl _) (StairLoanGroupSupport.append_sub _ _ _ _ (ot_opk_sub _ _) (Finset.Subset.refl _)))) -- oddten:end WDEF /-- the tape of the reference run is the actual tape (no cell any more). -/ def cellTape (_d : Bool) (m : List Bool) : List Bool := m theorem ord (c : Cost) (d : Bool) (a b : Program) : c.measure (ordered d a b)=c.measure a+c.measure b := by cases d <;> simp [ordered,c.append,Nat.add_comm] /-- every cost measure of a hosted record group is that of the record group. -/ theorem group_measure (c : Cost) (d : Bool) (j n : Nat) : c.measure (group d j n) = c.measure (ECDSAAdd.Entrant.Rolling1588.groups d j n) := by rw [group, distribute] unfold distributed ECDSAAdd.Entrant.Rolling1588.groups induction n generalizing j with | zero => rfl | succ n ih => cases d <;> simp only [PacketSequence.program, if_true, if_false, Bool.false_eq_true, c.append, ih, StairArchiveInactive.packet, StairArchiveInactive.hosts_eq, c.rename, StairGroups.packet_zero] attribute [local irreducible] opk theorem opk_measure (c : Cost) (d : Bool) (k : Nat) : c.measure (opk d k)=c.measure (oddPk d k) := by simp only [opk,StairArchiveInactive.hosts_eq,c.rename] theorem ogroup_measure (c : Cost) (d : Bool) (j n : Nat) : c.measure (ogroup d j n)=c.measure (PacketSequence.program d (oddPk d) j n) := by unfold ogroup induction n generalizing j with | zero => rfl | succ n ih => cases d <;> simp only [PacketSequence.program,if_true,if_false,Bool.false_eq_true,c.append,ih,opk_measure] private theorem gsplit (c : Cost) (d : Bool) (p : Nat→Program) (j n k : Nat) : c.measure (PacketSequence.program d p j (n+k))= c.measure (PacketSequence.program d p j n)+c.measure (PacketSequence.program d p (j+n) k) := by cases d · rw [RouteA.Rolling1588.odd45_program_false_add,c.append]; omega · rw [RouteA.Rolling1588.odd45_program_true_add,c.append] private theorem oneP (c : Cost) (d : Bool) (p : Nat→Program) (j : Nat) : c.measure (PacketSequence.program d p j 1)=c.measure (p j) := by cases d <;> simp only [PacketSequence.program,if_true,if_false,Bool.false_eq_true,List.append_nil,List.nil_append] private theorem oseq_congr (d : Bool) (p q : Nat→Program) : ∀ (n j : Nat), (∀ k, j≤k → k rfl | n+1, j, h => by have hj := h j (Nat.le_refl j) (by omega) have rest := oseq_congr d p q n (j+1) (fun k a b => h k (by omega) (by omega)) cases d <;> simp only [PacketSequence.program,if_true,if_false,Bool.false_eq_true,hj,rest] private theorem opartition (c : Cost) (d : Bool) : c.measure (ogroup d 1 84) = c.measure (ogroup d 1 9)+c.measure (ogroup d 10 2)+c.measure (ogroup d 12 1)+c.measure (ogroup d 13 2)+c.measure (ogroup d 15 1)+c.measure (ogroup d 16 2)+c.measure (ogroup d 18 1)+c.measure (ogroup d 19 2)+c.measure (ogroup d 21 1)+c.measure (ogroup d 22 2)+c.measure (ogroup d 24 1)+c.measure (ogroup d 25 2)+c.measure (ogroup d 27 1)+c.measure (ogroup d 28 2)+c.measure (ogroup d 30 1)+c.measure (ogroup d 31 2)+c.measure (ogroup d 33 2)+c.measure (ogroup d 35 2)+c.measure (ogroup d 37 2)+c.measure (ogroup d 39 2)+c.measure (ogroup d 41 2)+c.measure (ogroup d 43 2)+c.measure (ogroup d 45 2)+c.measure (ogroup d 47 2)+c.measure (ogroup d 49 2)+c.measure (ogroup d 51 2)+c.measure (ogroup d 53 2)+c.measure (ogroup d 55 2)+c.measure (ogroup d 57 2)+c.measure (ogroup d 59 2)+c.measure (ogroup d 61 2)+c.measure (ogroup d 63 2)+c.measure (ogroup d 65 2)+c.measure (ogroup d 67 2)+c.measure (ogroup d 69 1)+c.measure (ogroup d 70 2)+c.measure (ogroup d 72 1)+c.measure (ogroup d 73 2)+c.measure (ogroup d 75 1)+c.measure (ogroup d 76 2)+c.measure (ogroup d 78 1)+c.measure (ogroup d 79 2)+c.measure (ogroup d 81 1)+c.measure (ogroup d 82 2)+c.measure (ogroup d 84 1) := by have p0 := gsplit c d (opk d) 1 9 75 have p1 := gsplit c d (opk d) 10 2 73 have p2 := gsplit c d (opk d) 12 1 72 have p3 := gsplit c d (opk d) 13 2 70 have p4 := gsplit c d (opk d) 15 1 69 have p5 := gsplit c d (opk d) 16 2 67 have p6 := gsplit c d (opk d) 18 1 66 have p7 := gsplit c d (opk d) 19 2 64 have p8 := gsplit c d (opk d) 21 1 63 have p9 := gsplit c d (opk d) 22 2 61 have p10 := gsplit c d (opk d) 24 1 60 have p11 := gsplit c d (opk d) 25 2 58 have p12 := gsplit c d (opk d) 27 1 57 have p13 := gsplit c d (opk d) 28 2 55 have p14 := gsplit c d (opk d) 30 1 54 have p15 := gsplit c d (opk d) 31 2 52 have p16 := gsplit c d (opk d) 33 2 50 have p17 := gsplit c d (opk d) 35 2 48 have p18 := gsplit c d (opk d) 37 2 46 have p19 := gsplit c d (opk d) 39 2 44 have p20 := gsplit c d (opk d) 41 2 42 have p21 := gsplit c d (opk d) 43 2 40 have p22 := gsplit c d (opk d) 45 2 38 have p23 := gsplit c d (opk d) 47 2 36 have p24 := gsplit c d (opk d) 49 2 34 have p25 := gsplit c d (opk d) 51 2 32 have p26 := gsplit c d (opk d) 53 2 30 have p27 := gsplit c d (opk d) 55 2 28 have p28 := gsplit c d (opk d) 57 2 26 have p29 := gsplit c d (opk d) 59 2 24 have p30 := gsplit c d (opk d) 61 2 22 have p31 := gsplit c d (opk d) 63 2 20 have p32 := gsplit c d (opk d) 65 2 18 have p33 := gsplit c d (opk d) 67 2 16 have p34 := gsplit c d (opk d) 69 1 15 have p35 := gsplit c d (opk d) 70 2 13 have p36 := gsplit c d (opk d) 72 1 12 have p37 := gsplit c d (opk d) 73 2 10 have p38 := gsplit c d (opk d) 75 1 9 have p39 := gsplit c d (opk d) 76 2 7 have p40 := gsplit c d (opk d) 78 1 6 have p41 := gsplit c d (opk d) 79 2 4 have p42 := gsplit c d (opk d) 81 1 3 have p43 := gsplit c d (opk d) 82 2 1 simp only [ogroup] norm_num only [] at p0 p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12 p13 p14 p15 p16 p17 p18 p19 p20 p21 p22 p23 p24 p25 p26 p27 p28 p29 p30 p31 p32 p33 p34 p35 p36 p37 p38 p39 p40 p41 p42 p43 omega theorem ooverhead (j : Nat) (d : Bool) : toffoliCount (oten j (!d)) = toffoliCount (ogroup d j 2)+(if d then 105 else 101) ∧ measurementCount (oten j (!d)) = measurementCount (ogroup d j 2)+(if d then 106 else 101) := by cases d <;> simp only [ogroup,PacketSequence.program,Bool.not_true,Bool.not_false,oten,ofirst,osecond, enter,shift,leave,fieldHook,program,if_true,if_false,Bool.false_eq_true,List.nil_append, List.append_nil,toffoliCount_append,measurementCount_append,(renameProgram_counts _ _).1, (renameProgram_counts _ _).2,ReducedWindowArchives.enter0_counts.2.1,ReducedWindowArchives.switch0_counts.2.1,ReducedWindowArchives.leave0_counts.2.1, ReducedWindowArchives.enter1_counts.2.1,ReducedWindowArchives.switch1_counts.2.1,ReducedWindowArchives.leave1_counts.2.1,ReducedWindowArchives.enter0_counts.2.2.1, ReducedWindowArchives.switch0_counts.2.2.1,ReducedWindowArchives.leave0_counts.2.2.1,ReducedWindowArchives.enter1_counts.2.2.1, ReducedWindowArchives.switch1_counts.2.2.1,ReducedWindowArchives.leave1_counts.2.2.1] <;> constructor <;> omega private theorem ofield_pieces (c : Cost) (d : Bool) : c.measure (ogroup d 1 84)=c.measure (RouteA.Rolling1588.groups d 1 83)+ c.measure (oddPk d 84) := by rw [ogroup_measure] have b := gsplit c d (oddPk d) 1 83 1 have p3 := oneP c d (oddPk d) 84 have p2 := congrArg c.measure (oseq_congr d (oddPk d) (RouteA.Rolling1588.packet d) 83 1 (fun k l u => oddPk_mid d k l (by omega))) norm_num only [] at b unfold RouteA.Rolling1588.groups omega private theorem rfield_pieces (c : Cost) (d : Bool) : c.measure (group d 1 84)=c.measure (ECDSAAdd.Entrant.Rolling1588.groups d 1 83)+ c.measure (ECDSAAdd.Entrant.Rolling1588.packet d 84) := by rw [group_measure] unfold ECDSAAdd.Entrant.Rolling1588.groups have b := gsplit c d (ECDSAAdd.Entrant.Rolling1588.packet d) 1 83 1 have p3 := oneP c d (ECDSAAdd.Entrant.Rolling1588.packet d) 84 norm_num only [] at b omega /-- the hosted odd field packets 1..84 save 1260 T / 1680 M against the record packets 1..84. -/ theorem ofield_counts (d : Bool) : toffoliCount (ogroup d 1 84)+1260=toffoliCount (group d 1 84) ∧ measurementCount (ogroup d 1 84)+1680=measurementCount (group d 1 84) := by have o1 := ofield_pieces tc d have o2 := ofield_pieces mc d have r1 := rfield_pieces tc d have r2 := rfield_pieces mc d rw [show tc.measure=toffoliCount from rfl] at o1 r1 rw [show mc.measure=measurementCount from rfl] at o2 r2 have g := RouteA.Rolling1588.groups_count_delta d 1 83 (by decide) rw [if_neg (by cases d <;> decide)] at g have h84 := OddFullPass.P1LifeLoan.packet_counts d 0 84 (by decide) (by decide) rw [StairGroups.packet_zero] at h84 rw [oddPk_end] at o1 o2 norm_num only at h84 simp only [if_true,if_false] at h84 exact ⟨by omega,by omega⟩ theorem half760OddLoan_zero_eq (d : Bool) : OddFullPass.P1LifeLoan.half760OddLoan 0 d = P1Life.half (base 760) d base (base 2409) := by cases d <;> simp only [OddFullPass.P1LifeLoan.half760OddLoan,P1Life.half, OddFullPass.P1LifeLoan.forwardLoan,P1Life.forward, OddFullPass.P1LifeLoan.inverseLoan,P1Life.inverse, OddFullPass.P1LifeLoan.p1Seed,P1Life.p1Seed, OddFullPass.P1LifeLoan.rawAddLoan,P1Life.rawAdd, OddFullPass.P1LifeLoan.foldLoan,P1Life.fold, OddFullPass.P1LifeLoan.rawSubLoan,P1Life.rawSub, OddFullPass.P1LifeLoan.unfoldLoan,P1Life.unfoldStep, OddFullPass.P1LifeLoan.compareBlockLoan,P1Life.compare, OddFullPass.P1LifeLoan.short_zero,OddFullPass.P1LifeLoan.previousShort,P1Life.shortConstAdd, OddFullPass.P1LifeLoan.orMajor,P1Life.orMajor, OddFullPass.P1LifeLoan.orErase,P1Life.orErase, OddFullPass.P1LifeLoan.prepareCompare,P1Life.prepareCompare, OddFullPass.P1LifeLoan.exposure,P1Life.exposure, StairLoan.addPrefixLoan_zero,StairLoan.mappedAddLoan_zero, StairLoan.addTopLoan_zero,StairLoan.mappedSubLoan_zero, FoldTop.foldAdd_zero,FoldTop.unfoldSub_zero, StairLoan.compareLoan_zero,StairLoan.literalConstAddLoan_zero, show (0 : Nat) < 6 by decide,if_true,if_false,Bool.false_eq_true] /-- gate slots of the hosted odd field packets against the record packets 1..84. -/ theorem ofield_slots (d : Bool) : slots.measure (ogroup d 1 84)+(if d then 14280 else 11760)= slots.measure (group d 1 84)+(if d then 0 else 0) := by have o := ofield_pieces slots d have r := rfield_pieces slots d rw [show slots.measure=Challenge.gateSlots from rfl] at o r ⊢ have g := RouteA.Rolling1588.groups_slot_delta d 1 83 (by decide) rw [if_neg (by cases d <;> decide)] at g have h0eq := half760OddLoan_zero_eq d have h84sl : Challenge.gateSlots (OddFullPass.P1LifeLoan.packet d 0 84) + 5 * RouteA.Rolling1588.halfSlotSaving d = Challenge.gateSlots (ECDSAAdd.Entrant.Rolling1588.packet d 84) := by have h32 := RouteA.Rolling1588.cell_slot_delta d 84 3 2 have h42 := RouteA.Rolling1588.cell_slot_delta d 84 4 2 have hcEq : ∀ a b, OddFullPass.P1LifeLoan.cell d 0 84 a b = RouteA.Rolling1588.cell d 84 a b := by intro a b; cases d <;> simp only [OddFullPass.P1LifeLoan.cell,RouteA.Rolling1588.cell, OddFullPass.P1LifeLoan.halfWindow,RouteA.Rolling1588.halfWindow,RouteA.Rolling1588.halfWindowWith, Bool.false_eq_true,if_false,if_true,h0eq] cases d <;> simp only [OddFullPass.P1LifeLoan.packet,ECDSAAdd.Entrant.Rolling1588.packet, OddFullPass.P1LifeLoan.basePacket,ECDSAAdd.Entrant.Rolling1588.basePacket, Bool.false_eq_true,if_false,if_true,Baselines.rename_gateSlots,Challenge.gateSlots_append,hcEq] at h32 h42 ⊢ <;> omega rw [oddPk_end] at o cases d <;> simp only [RouteA.Rolling1588.halfSlotSaving,Bool.false_eq_true,if_false,if_true] at g h84sl o ⊢ <;> omega private theorem osolve (c : Cost) (d : Bool) (delta : Nat) (h : ∀j,c.measure (oten j (!d))=c.measure (ogroup d j 2)+delta) : c.measure (group84 d)=c.measure (ogroup d 1 84)+22*delta := by simp only [group84,ord,h,opartition] omega /-- the field group (odd cell on packets 1..84, ten-blocks included) against the record packets 1..84. -/ theorem group_cost (d : Bool) : toffoliCount (group84 d)+0=toffoliCount (group d 1 84)+(if d then 1050 else 962) ∧ measurementCount (group84 d)+0=measurementCount (group d 1 84)+(if d then 652 else 542) := by have t := osolve tc d (if d then 105 else 101) (fun j => (ooverhead j d).1) have m := osolve mc d (if d then 106 else 101) (fun j => (ooverhead j d).2) have f := ofield_counts d rw [show tc.measure = toffoliCount from rfl] at t rw [show mc.measure = measurementCount from rfl] at m cases d <;> simp only [if_true,if_false,Bool.false_eq_true] at t m ⊢ <;> exact ⟨by omega, by omega⟩ /-- Static syntax counts include both correction lists of every measurement. -/ theorem group_slots (d : Bool) : slots.measure (group84 d)+(if d then 14280 else 11760)= slots.measure (group d 1 84)+22*(if d then 5322 else 6122)+(if d then 0 else 0) := by have hc := ofield_slots d have h (j : Nat) : slots.measure (oten j (!d)) = slots.measure (ogroup d j 2)+(if d then 5322 else 6122) := by rw [show slots.measure=Challenge.gateSlots from rfl] cases d <;> simp only [ogroup,PacketSequence.program,Bool.not_true,Bool.not_false,oten,ofirst,osecond, enter,shift,leave,fieldHook,program,if_true,if_false,Bool.false_eq_true,List.nil_append, List.append_nil,Challenge.gateSlots_append,Baselines.rename_gateSlots,ReducedWindowArchives.enter0_counts.2.2.2, ReducedWindowArchives.switch0_counts.2.2.2,ReducedWindowArchives.leave0_counts.2.2.2,ReducedWindowArchives.enter1_counts.2.2.2,ReducedWindowArchives.switch1_counts.2.2.2,ReducedWindowArchives.leave1_counts.2.2.2] <;> omega have w := osolve slots d (if d then 5322 else 6122) h cases d <;> simp only [if_true,if_false,Bool.false_eq_true] at hc w ⊢ <;> omega theorem group_cost_div : toffoliCount (group84 true) = toffoliCount (group true 1 84)+1050 ∧ measurementCount (group84 true) = measurementCount (group true 1 84)+652 := by have t := (group_cost true).1 have m := (group_cost true).2 simp only [if_true] at t m exact ⟨by omega,by omega⟩ theorem group_cost_mul : toffoliCount (group84 false) = toffoliCount (group false 1 84)+962 ∧ measurementCount (group84 false) = measurementCount (group false 1 84)+542 := by have t := (group_cost false).1 have m := (group_cost false).2 simp only [Bool.false_eq_true,if_false] at t m exact ⟨by omega,by omega⟩ -- oddten:end WCOST -- Static syntax counts include both correction lists of every measurement. end ECDSAAdd.Entrant.StairPacket.WindowFieldCosts end section namespace ECDSAAdd.Entrant.StairPacket.WindowWalkCosts open Arithmetic MappedCompressed Stair44Resources Partial PartialCosts set_option maxHeartbeats 1250000 set_option maxRecDepth 16000 /-- The replacement occupies [45,406); the initial fifteen ticks use a distinct placement. -/ def forward (d : Bool) (tail : Nat) : Program := renameProgram Stair44WalkMap.first (Rolling1588TickGap.forward d 1 15) ++ renameProgram Stair44WalkMap.rest (Rolling1588TickGap.forward d 16 29 ++ Shadow20.MixedWindow.forwardMixedCut d ++ Rolling1588TickGap.forward d 421 tail) def backward (d : Bool) (tail : Nat) : Program := renameProgram Stair44WalkMap.rest (Rolling1588.reverse d 421 tail ++ TickCut.Mixed.reverse d ++ Rolling1588.reverse d 16 29) ++ renameProgram Stair44WalkMap.first (Rolling1588.reverse d 1 15) private theorem walk (c : Cost) (d : Bool) (tail f r : Nat) (hf : c.measure (Shadow20.MixedWindow.forwardMixedCut d)+f=c.measure (Rolling1588TickGap.forward d 45 376)) (hr : c.measure (TickCut.Mixed.reverse d)+r=c.measure (Rolling1588.reverse d 45 376)) : c.measure (forward d tail)+f=c.measure (Stair44WalkRun.forward d (405+tail)) ∧ c.measure (backward d tail)+r=c.measure (Stair44WalkRun.backward d (405+tail)) := by have a := StairRestSupport.forward_append d 29 16 (376+tail) have b := StairRestSupport.forward_append d 376 45 tail have x := StairRestSupport.reverse_append d 29 16 (376+tail) have y := StairRestSupport.reverse_append d 376 45 tail change Rolling1588TickGap.forward d 16 (29+(376+tail)) = Rolling1588TickGap.forward d 16 29 ++ Rolling1588TickGap.forward d 45 (376+tail) at a change Rolling1588.reverse d 16 (29+(376+tail)) = Rolling1588.reverse d 45 (376+tail) ++ Rolling1588.reverse d 16 29 at x rw [b] at a rw [y] at x have num : 405+tail=29+(376+tail) := by omega simp only [Stair44WalkRun.forward, Stair44WalkRun.backward,forward,backward,num,a,x, c.append,c.rename] norm_num only [] constructor <;> omega attribute [local irreducible] Shadow20.MixedWindow.forwardMixedCut TickCut.Mixed.reverse Rolling1588TickGap.forward Rolling1588.reverse Stair44WalkRun.forward Stair44WalkRun.backward toffoliCount measurementCount forward backward private theorem subEq {x y a b : Nat} (n : Nat) (hx : x=a) (hy : y=b) (h : a+n=b) : x+n=y := by omega theorem exactWalks (d : Bool) (tail : Nat) : toffoliCount (forward d tail)+(if d then 39140 else 39140)= toffoliCount (Stair44WalkRun.forward d (405+tail)) ∧ toffoliCount (backward d tail)+(if d then 39051 else 39029)= toffoliCount (Stair44WalkRun.backward d (405+tail)) ∧ measurementCount (forward d tail)+(if d then 17758 else 17736)=measurementCount (Stair44WalkRun.forward d (405+tail)) ∧ measurementCount (backward d tail)+(if d then 17767 else 17745)=measurementCount (Stair44WalkRun.backward d (405+tail)) := by have sf := StockWindowCosts420.stock420from45 d have mcw := TickCut.Mixed.mixed_counts d cases d · simp only [Bool.false_eq_true, ↓reduceIte] at mcw ⊢ have t := walk tc false tail 39140 39029 (subEq 39140 mcw.1 sf.1 (by omega)) (subEq 39029 mcw.2.1 sf.2.2.1 (by omega)) have mv := walk mc false tail 17736 17745 (subEq 17736 mcw.2.2.1 sf.2.1 (by omega)) (subEq 17745 mcw.2.2.2 sf.2.2.2 (by omega)) exact ⟨t.1,t.2,mv⟩ · simp only [↓reduceIte] at mcw ⊢ have t := walk tc true tail 39140 39051 (subEq 39140 mcw.1 sf.1 (by omega)) (subEq 39051 mcw.2.1 sf.2.2.1 (by omega)) have mv := walk mc true tail 17758 17767 (subEq 17758 mcw.2.2.1 sf.2.1 (by omega)) (subEq 17767 mcw.2.2.2 sf.2.2.2 (by omega)) exact ⟨t.1,t.2,mv⟩ /-- Rewrite small arithmetic arguments before instantiating either physical walk. -/ theorem inst (d : Bool) (tail n f r : Nat) (hn : 405+tail=n) (hf : (if d then 39140 else 39140)=f) (hr : (if d then 39051 else 39029)=r) : tc.measure (forward d tail)+f=tc.measure (Stair44WalkRun.forward d n) ∧ tc.measure (backward d tail)+r=tc.measure (Stair44WalkRun.backward d n) ∧ mc.measure (forward d tail)+(if d then 17758 else 17736)=mc.measure (Stair44WalkRun.forward d n) ∧ mc.measure (backward d tail)+(if d then 17767 else 17745)=mc.measure (Stair44WalkRun.backward d n) := by subst n; subst f; subst r exact exactWalks d tail theorem instMeasurements (d : Bool) (tail n f r : Nat) (hn : 405+tail=n) (hf : (if d then 17758 else 17736)=f) (hr : (if d then 17767 else 17745)=r) : mc.measure (forward d tail)+f=mc.measure (Stair44WalkRun.forward d n) ∧ mc.measure (backward d tail)+r=mc.measure (Stair44WalkRun.backward d n) := by subst n; subst f; subst r exact ⟨(exactWalks d tail).2.2.1, (exactWalks d tail).2.2.2⟩ end ECDSAAdd.Entrant.StairPacket.WindowWalkCosts end section namespace ECDSAAdd.Entrant.StairPacket.WindowCallerCosts open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines DirectSkywalk OB5 open StairConcreteAssembly Stair44Resources StairHostsSchedule set_option maxRecDepth 16000 set_option maxHeartbeats 1500000 set_option linter.unusedSimpArgs false def entryTailPrefix (p : StairSchedule.StairPrimitives) : Program := WindowFieldCosts.group84 true ++ StairSchedule.forwardSegment p 87 62 425 450 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 5 ++ StairSchedule.forwardSegment p 62 47 450 465 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 3 ++ StairSchedule.forwardSegment p 47 32 465 480 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 3 ++ StairSchedule.forwardSegment p 32 22 480 490 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 2 ++ StairSchedule.forwardSegment p 22 12 490 500 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 2 ++ StairSchedule.forwardLast p def exitHeadSuffix (p : StairSchedule.StairPrimitives) : Program := StairSchedule.reverseLast p ++ PackCutOddExit.cutRowOddPk 22 12 490 500 41 98 1 ++ PackCutOddExit.cutRowOddPk 32 22 480 490 36 96 1 ++ PackCutOddExit.cutRowOddPk 47 32 465 480 30 93 2 ++ PackCutOddExit.cutRowOddPk 62 47 450 465 22 90 2 ++ PackCutOddExit.cutRowOddPk 87 62 425 450 13 85 4 ++ WindowFieldCosts.group84 false /-- Odd-word half-cell on `base 760` used for cells 2, 3, 4 of `placedFirstPacketOdd`. -/ def oddFirstHalf (divide : Bool) : Program := P1Life.half (base 760) divide base (base 2409) theorem oddFirstHalf_physical (divide : Bool) : GatePhysical (oddFirstHalf divide) := (P1Life.half_resources (base 760) divide base (base 2409) Rolling1588Lifetime.half_ports_nodup RouteA.Rolling1588.route_retired_member).1 theorem oddFirstHalf_support (divide : Bool) : JointOdd1588.OddHalfSupport (oddFirstHalf divide) := by have hchk : (base 2409 :: base 768 :: base 1797 :: base 1027 :: (wireBlock base 2056 256 ++ wireBlock base 770 256 ++ (wireBlock base 512 253 ++ [base 1540]))).all (fun q => decide (q = base 760 ∨ (q ∈ StairFirstPacketKernel.LT48T.env ∧ q ∉ StairFirstPacketKernel.LT48T.bad))) = true := by decide +kernel intro q hq have hsub := (P1Life.half_resources (base 760) divide base (base 2409) Rolling1588Lifetime.half_ports_nodup RouteA.Rolling1588.route_retired_member).2 hq have hne := (Finset.mem_erase.mp hsub).1 have hmem := Finset.mem_of_mem_erase hsub rw [P1Life.junction_footprint_ports, List.mem_toFinset] at hmem exact (of_decide_eq_true (List.all_eq_true.mp hchk q hmem)).resolve_left hne theorem oddFirstHalf_slots_le (divide : Bool) : Challenge.gateSlots (oddFirstHalf divide) ≤ Challenge.gateSlots (R2Life760.half760 divide) := by have h1 := RouteA.slot_half (base 760) divide base (base 2409) have h2 := RouteA.slot_record_half divide cases divide <;> simp only [oddFirstHalf, Bool.false_eq_true, if_false, if_true] at h1 h2 ⊢ <;> omega theorem fpSup_bounds (w : Wire) (h : StairWireCheck.fpSup w = true) : (16 ≤ w ∧ w < 2330) ∨ w = 2425 := by have hlt : w < 2426 := StairWireCheck.fpSup_lt w h have hchk : (List.range 2426).all (fun x : Nat => !StairWireCheck.fpSup x || (decide (16 ≤ x ∧ x < 2330) || decide (x = 2425))) = true := by decide +kernel have hw := List.all_eq_true.mp hchk w (List.mem_range.mpr hlt) simp only [h, Bool.not_true, Bool.false_or, Bool.or_eq_true, decide_eq_true_eq] at hw exact hw private theorem rebindMany_slots_eq (roles hosts : List Wire) (P : Program) : Challenge.gateSlots (StairLoan.rebindMany roles hosts P) = Challenge.gateSlots P := by induction roles generalizing hosts with | nil => rfl | cons r roles ih => cases hosts with | nil => rfl | cons h hosts => simp only [StairLoan.rebindMany, Baselines.rename_gateSlots, ih] def entryLowPrefix (p : StairSchedule.StairPrimitives) : Program := StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket true) (JointOdd1588.placedFirstPacketOdd oddFirstHalf true) ++ FourScratchWindow.clearProgram ++ renameProgram Prefix1590.borrow (entryTailPrefix p) ++ FourScratchWindow.unprefix def exitLowSuffix (p : StairSchedule.StairPrimitives) : Program := FourScratchWindow.clearProgram ++ renameProgram Prefix1590.borrow (exitHeadSuffix p) ++ FourScratchWindow.unprefix ++ StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket false) (JointOdd1588.placedFirstPacketOdd oddFirstHalf false) def entryFieldHosted (p : StairSchedule.StairPrimitives) : Program := StairSchedule.fieldRename (entryLowPrefix p) ++ StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.entryLowSuffixOdd hostPlan) ++ StairSchedule.hostedX ++ StairSchedule.paritySetup def exitFieldHosted (p : StairSchedule.StairPrimitives) : Program := StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.exitLowPrefixOdd hostPlan) ++ StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename (exitLowSuffix p) /-- The division field's tail prefix with the five packet-cut odd rows. -/ def entryTailPrefixCut : Program := WindowFieldCosts.group84 true ++ (PackCutOdd.cutRowOdd 87 62 425 450 13 85 4 ++ (PackCutOdd.cutRowOdd 62 47 450 465 22 90 2 ++ (PackCutOdd.cutRowOdd 47 32 465 480 30 93 2 ++ (PackCutOdd.cutRowOdd 32 22 480 490 36 96 1 ++ (PackCutOdd.cutRowOdd 22 12 490 500 41 98 1 ++ StairSchedule.forwardLast checkpointPrimitives))))) def entryLowPrefixCut : Program := StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket true) (JointOdd1588.placedFirstPacketOdd oddFirstHalf true) ++ FourScratchWindow.clearProgram ++ renameProgram Prefix1590.borrow entryTailPrefixCut ++ FourScratchWindow.unprefix def entryFieldHostedCut : Program := StairSchedule.fieldRename entryLowPrefixCut ++ StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.entryLowSuffixOdd hostPlan) ++ StairSchedule.hostedX ++ StairSchedule.paritySetup theorem field_delta_tc_div (n : Nat) (h : tc.measure (WindowFieldCosts.group84 true)=tc.measure (WindowFieldCosts.group true 1 84)+n) : tc.measure (entryFieldHosted checkpointPrimitives)+953 = tc.measure (StairHostsSchedule.entryFieldHosted checkpointPrimitives hostPlan)+n := by have g13 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 13 85 5 (by decide) (by decide)).1 have g22 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 22 90 3 (by decide) (by decide)).1 have g30 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 30 93 3 (by decide) (by decide)).1 have g36 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 36 96 2 (by decide) (by decide)).1 have g41 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 41 98 2 (by decide) (by decide)).1 have g43 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 43 100 2 (by decide) (by decide)).1 have hc := OddFullPass.HalfConvertOdd.canon760OddLoan_counts.1 have hcn := StairBoundaryLoan.canon760Loan_counts.1 have hcb : toffoliCount R2SqEp760.canon760 = 254 := by rw [StairBoundaryLoan.canon760_eq] exact (HalfConvert.counts StairBoundaryLoan.converterLayout760 StairBoundaryLoan.converterLayout760_facts.widths).2.2.1 have hde := OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan_counts.1 have hfp := (JointOdd1588.placedFirstPacketOdd_counts_delta oddFirstHalf true (P1Life.half_counts (base 760) true base (base 2409)).1 (P1Life.half_counts (base 760) true base (base 2409)).2).1 have hrNew := (StairLoan.rebindMany_counts StairSchedule.exclusiveRoles (hostPlan.firstPacket true) (JointOdd1588.placedFirstPacketOdd oddFirstHalf true)).1 have hrOld := (StairLoan.rebindMany_counts StairSchedule.exclusiveRoles (hostPlan.firstPacket true) (Rolling1588.placedFirstPacket true)).1 rw [show tc.measure=toffoliCount from rfl] at h ⊢ simp only [if_true,WindowFieldCosts.group,entryFieldHosted,entryLowPrefix,entryTailPrefix, OddFullPass.P1LifeLoan.entryLowSuffixOdd,OddFullPass.P1LifeLoan.entryTailSuffixOdd, StairHostsSchedule.entryFieldHosted,StairHostsSchedule.entryLowPrefix, StairHostsSchedule.entryTailPrefix,StairHostsSchedule.entryLowSuffix, StairHostsSchedule.entryTailSuffix,StairConcrete.bestLoans_divEndpoint, StairConcrete.bestLoans,StairSchedule.fieldRename,StairSchedule.parityRename, renameProgram_counts,toffoliCount_append] at * norm_num only at g13 g22 g30 g36 g41 g43 simp only [if_false,if_true] at g13 g22 g30 g36 g41 g43 omega theorem field_delta_tc_mul (n : Nat) (h : tc.measure (WindowFieldCosts.group84 false)=tc.measure (WindowFieldCosts.group false 1 84)+n) : tc.measure (exitFieldHosted checkpointPrimitives)+1020 = tc.measure (StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan)+n := by have g13 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 13 85 5 (by decide) (by decide)).1 have g22 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 22 90 3 (by decide) (by decide)).1 have g30 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 30 93 3 (by decide) (by decide)).1 have g36 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 36 96 2 (by decide) (by decide)).1 have g41 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 41 98 2 (by decide) (by decide)).1 have g43 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 43 100 2 (by decide) (by decide)).1 have hct := OddFullPass.HalfConvertOdd.center760OddLoan_counts.1 have hctn := StairBoundaryLoan.center760Loan_counts.1 have hctb : toffoliCount R2SqEp760.center760 = 254 := by rw [StairBoundaryLoan.center760_eq] exact (HalfConvert.counts StairBoundaryLoan.converterLayout760 StairBoundaryLoan.converterLayout760_facts.widths).1 have hme := OddFullPass.InverseTailCOdd.endPacket760OddLoan44_counts.1 have hfp := (JointOdd1588.placedFirstPacketOdd_counts_delta oddFirstHalf false (P1Life.half_counts (base 760) false base (base 2409)).1 (P1Life.half_counts (base 760) false base (base 2409)).2).1 have hrNew := (StairLoan.rebindMany_counts StairSchedule.exclusiveRoles (hostPlan.firstPacket false) (JointOdd1588.placedFirstPacketOdd oddFirstHalf false)).1 have hrOld := (StairLoan.rebindMany_counts StairSchedule.exclusiveRoles (hostPlan.firstPacket false) (Rolling1588.placedFirstPacket false)).1 have cr0 := PackCutOddExit.cutRow0_counts.1 have cr1 := PackCutOddExit.cutRow1_counts.1 have cr2 := PackCutOddExit.cutRow2_counts.1 have cr3 := PackCutOddExit.cutRow3_counts.1 have cr4 := PackCutOddExit.cutRow4_counts.1 rw [show tc.measure=toffoliCount from rfl] at h ⊢ simp only [WindowFieldCosts.group,exitFieldHosted,exitLowSuffix,exitHeadSuffix, OddFullPass.P1LifeLoan.exitLowPrefixOdd,OddFullPass.P1LifeLoan.exitHeadPrefixOdd, StairHostsSchedule.exitFieldHosted,StairHostsSchedule.exitLowSuffix, StairHostsSchedule.exitHeadSuffix,StairHostsSchedule.exitLowPrefix, StairHostsSchedule.exitHeadPrefix,StairHostsSchedule.hostedEndpoint, StairSchedule.placedEndPacket,StairConcrete.bestLoans,StairConcrete.endPacket, Bool.false_eq_true,if_false,if_true,StairSchedule.fieldRename,StairSchedule.parityRename, renameProgram_counts,toffoliCount_append] at * norm_num only at g13 g22 g30 g36 g41 g43 simp only [if_false,if_true] at g13 g22 g30 g36 g41 g43 omega theorem field_delta_mc_div (n : Nat) (h : mc.measure (WindowFieldCosts.group84 true)=mc.measure (WindowFieldCosts.group true 1 84)+n) : mc.measure (entryFieldHosted checkpointPrimitives)+1718 = mc.measure (StairHostsSchedule.entryFieldHosted checkpointPrimitives hostPlan)+n := by have g13 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 13 85 5 (by decide) (by decide)).2 have g22 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 22 90 3 (by decide) (by decide)).2 have g30 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 30 93 3 (by decide) (by decide)).2 have g36 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 36 96 2 (by decide) (by decide)).2 have g41 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 41 98 2 (by decide) (by decide)).2 have g43 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan true 43 100 2 (by decide) (by decide)).2 have hc := OddFullPass.HalfConvertOdd.canon760OddLoan_counts.2 have hcn := StairBoundaryLoan.canon760Loan_counts.2 have hcb : measurementCount R2SqEp760.canon760 = 254 := by rw [StairBoundaryLoan.canon760_eq] exact (HalfConvert.counts StairBoundaryLoan.converterLayout760 StairBoundaryLoan.converterLayout760_facts.widths).2.2.2 have hde := OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan_counts.2 have hfp := (JointOdd1588.placedFirstPacketOdd_counts_delta oddFirstHalf true (P1Life.half_counts (base 760) true base (base 2409)).1 (P1Life.half_counts (base 760) true base (base 2409)).2).2 have hrNew := (StairLoan.rebindMany_counts StairSchedule.exclusiveRoles (hostPlan.firstPacket true) (JointOdd1588.placedFirstPacketOdd oddFirstHalf true)).2 have hrOld := (StairLoan.rebindMany_counts StairSchedule.exclusiveRoles (hostPlan.firstPacket true) (Rolling1588.placedFirstPacket true)).2 rw [show mc.measure=measurementCount from rfl] at h ⊢ simp only [WindowFieldCosts.group,entryFieldHosted,entryLowPrefix,entryTailPrefix, OddFullPass.P1LifeLoan.entryLowSuffixOdd,OddFullPass.P1LifeLoan.entryTailSuffixOdd, StairHostsSchedule.entryFieldHosted,StairHostsSchedule.entryLowPrefix, StairHostsSchedule.entryTailPrefix,StairHostsSchedule.entryLowSuffix, StairHostsSchedule.entryTailSuffix,StairConcrete.bestLoans_divEndpoint, StairConcrete.bestLoans,StairSchedule.fieldRename,StairSchedule.parityRename, renameProgram_counts,measurementCount_append] at * norm_num only at g13 g22 g30 g36 g41 g43 simp only [if_false,if_true] at g13 g22 g30 g36 g41 g43 omega theorem field_delta_mc_mul (n : Nat) (h : mc.measure (WindowFieldCosts.group84 false)=mc.measure (WindowFieldCosts.group false 1 84)+n) : mc.measure (exitFieldHosted checkpointPrimitives)+1744 = mc.measure (StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan)+n := by have g13 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 13 85 5 (by decide) (by decide)).2 have g22 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 22 90 3 (by decide) (by decide)).2 have g30 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 30 93 3 (by decide) (by decide)).2 have g36 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 36 96 2 (by decide) (by decide)).2 have g41 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 41 98 2 (by decide) (by decide)).2 have g43 := (OddFullPass.P1LifeLoan.hostedGroup_counts hostPlan false 43 100 2 (by decide) (by decide)).2 have hct := OddFullPass.HalfConvertOdd.center760OddLoan_counts.2 have hctn := StairBoundaryLoan.center760Loan_counts.2 have hctb : measurementCount R2SqEp760.center760 = 254 := by rw [StairBoundaryLoan.center760_eq] exact (HalfConvert.counts StairBoundaryLoan.converterLayout760 StairBoundaryLoan.converterLayout760_facts.widths).2.1 have hme := OddFullPass.InverseTailCOdd.endPacket760OddLoan44_counts.2 have hfp := (JointOdd1588.placedFirstPacketOdd_counts_delta oddFirstHalf false (P1Life.half_counts (base 760) false base (base 2409)).1 (P1Life.half_counts (base 760) false base (base 2409)).2).2 have hrNew := (StairLoan.rebindMany_counts StairSchedule.exclusiveRoles (hostPlan.firstPacket false) (JointOdd1588.placedFirstPacketOdd oddFirstHalf false)).2 have hrOld := (StairLoan.rebindMany_counts StairSchedule.exclusiveRoles (hostPlan.firstPacket false) (Rolling1588.placedFirstPacket false)).2 have cr0 := PackCutOddExit.cutRow0_counts.2 have cr1 := PackCutOddExit.cutRow1_counts.2 have cr2 := PackCutOddExit.cutRow2_counts.2 have cr3 := PackCutOddExit.cutRow3_counts.2 have cr4 := PackCutOddExit.cutRow4_counts.2 rw [show mc.measure=measurementCount from rfl] at h ⊢ simp only [WindowFieldCosts.group,exitFieldHosted,exitLowSuffix,exitHeadSuffix, OddFullPass.P1LifeLoan.exitLowPrefixOdd,OddFullPass.P1LifeLoan.exitHeadPrefixOdd, StairHostsSchedule.exitFieldHosted,StairHostsSchedule.exitLowSuffix, StairHostsSchedule.exitHeadSuffix,StairHostsSchedule.exitLowPrefix, StairHostsSchedule.exitHeadPrefix,StairHostsSchedule.hostedEndpoint, StairSchedule.placedEndPacket,StairConcrete.bestLoans,StairConcrete.endPacket, Bool.false_eq_true,if_false,if_true,StairSchedule.fieldRename,StairSchedule.parityRename, renameProgram_counts,measurementCount_append] at * norm_num only at g13 g22 g30 g36 g41 g43 simp only [if_false,if_true] at g13 g22 g30 g36 g41 g43 omega theorem field_delta_slots (d : Bool) (n : Nat) (h : slots.measure (WindowFieldCosts.group84 d)=slots.measure (WindowFieldCosts.group d 1 84)+n) : (if d then slots.measure (entryFieldHosted checkpointPrimitives) else slots.measure (exitFieldHosted checkpointPrimitives)) ≤ (if d then slots.measure (StairHostsSchedule.entryFieldHosted checkpointPrimitives hostPlan) else slots.measure (StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan))+n+ (if d then 7900 else 8160) := by have g13 := OddFullPass.P1LifeLoan.hostedGroup_slots_le hostPlan d 13 85 5 (by decide) (by decide) (by decide) have g22 := OddFullPass.P1LifeLoan.hostedGroup_slots_le hostPlan d 22 90 3 (by decide) (by decide) (by decide) have g30 := OddFullPass.P1LifeLoan.hostedGroup_slots_le hostPlan d 30 93 3 (by decide) (by decide) (by decide) have g36 := OddFullPass.P1LifeLoan.hostedGroup_slots_le hostPlan d 36 96 2 (by decide) (by decide) (by decide) have g41 := OddFullPass.P1LifeLoan.hostedGroup_slots_le hostPlan d 41 98 2 (by decide) (by decide) (by decide) have g43 := OddFullPass.P1LifeLoan.hostedGroup_slots_le hostPlan d 43 100 2 (by decide) (by decide) (by decide) have hc := OddFullPass.HalfConvertOdd.canon760OddLoan_slots_le have hct := OddFullPass.HalfConvertOdd.center760OddLoan_slots_le have hde := OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan_slots_le have hme := OddFullPass.InverseTailCOdd.endPacket760OddLoan44_slots_le have hfp := JointOdd1588.placedFirstPacketOdd_slots_le oddFirstHalf d (oddFirstHalf_slots_le d) have hrNew := rebindMany_slots_eq StairSchedule.exclusiveRoles (hostPlan.firstPacket d) (JointOdd1588.placedFirstPacketOdd oddFirstHalf d) have hrOld := rebindMany_slots_eq StairSchedule.exclusiveRoles (hostPlan.firstPacket d) (Rolling1588.placedFirstPacket d) have cs0 := PackCutOddExit.cutRow0_slots have cs1 := PackCutOddExit.cutRow1_slots have cs2 := PackCutOddExit.cutRow2_slots have cs3 := PackCutOddExit.cutRow3_slots have cs4 := PackCutOddExit.cutRow4_slots rw [show slots.measure=Challenge.gateSlots from rfl] at h ⊢ cases d <;> simp only [Bool.false_eq_true,if_true,if_false,WindowFieldCosts.group, entryFieldHosted,exitFieldHosted,entryLowPrefix,exitLowSuffix, entryTailPrefix,exitHeadSuffix,OddFullPass.P1LifeLoan.entryLowSuffixOdd, OddFullPass.P1LifeLoan.exitLowPrefixOdd,OddFullPass.P1LifeLoan.entryTailSuffixOdd, OddFullPass.P1LifeLoan.exitHeadPrefixOdd, StairHostsSchedule.entryFieldHosted,StairHostsSchedule.exitFieldHosted, StairHostsSchedule.entryLowPrefix,StairHostsSchedule.exitLowSuffix, StairHostsSchedule.entryTailPrefix,StairHostsSchedule.exitHeadSuffix, StairHostsSchedule.entryLowSuffix,StairHostsSchedule.exitLowPrefix, StairHostsSchedule.entryTailSuffix,StairHostsSchedule.exitHeadPrefix, StairHostsSchedule.hostedEndpoint,StairSchedule.placedEndPacket, StairConcrete.bestLoans_divEndpoint,StairConcrete.bestLoans,StairConcrete.endPacket, StairSchedule.fieldRename,StairSchedule.parityRename, Baselines.rename_gateSlots,Challenge.gateSlots_append] at * <;> omega open Stair44Outer def divide : Program := phasePlace (WindowWalkCosts.forward true 4) ++ phasePlace checkpointPrimitives.firstPack ++ kernelPlace entryFieldHostedCut ++ phasePlace reverseEnd ++ phasePlace (WindowWalkCosts.backward false 85) ++ phasePlace (renameProgram Stair44WalkMap.first (FrontierEntry1591NativeH.inverse base)) def multiply (k : Nat) : Program := phasePlace (WindowWalkCosts.forward false 84) ++ phasePlace forwardEnd ++ kernelPlace (exitFieldHosted checkpointPrimitives) ++ phasePlace checkpointPrimitives.firstUnpack ++ phasePlace (WindowWalkCosts.backward true 4) ++ Stair44PointMap.switchX (phasePlace (ParityXExitInverse23Kernel.x1N k)) def generic (cx cy : Fp) : Program := Stair44PointMap.encodeY (EntryFuseOdd.entryYAllOdd layout (-cy)) ++ Stair44PointMap.switchX (FlagEntry.entryXNew layout (FlagEntry.pkW layout) (-cx)) ++ divide ++ Stair44Square.program (ReflectionE1.correction cx) ++ multiply cx.val ++ Stair44PointMap.encodeY (EntryFuseOdd.exitYAllOdd layout cy) def borrowGeneric (cx cy : Fp) := renameProgram (Equiv.swap layout.doubleSelect layout.control) (renameProgram (FlagTop.rho layout) (generic cx cy)) def finite (C : Point) (cx cy : Fp) : Program := Stair44PointMap.encode (FlagTop.stageNew layout C (FlagEntry.pkW layout) ++ AboveFieldPointDevelop.encode C ++ AboveFieldPointDevelop.eraseB) ++ borrowGeneric cx cy ++ Stair44PointMap.encode (AboveFieldPointDevelop.loadB ++ AboveFieldPointDevelop.decode C ++ ControlPointEncodingDevelop.borrowOut C) def program (C : Point) : Program := match C with | .zero => [] | @WeierstrassCurve.Affine.Point.some _ _ _ cx cy hc => renameProgram (Wrapper5.U layout) (finite (.some hc) cx cy) theorem tailPrefix_rows : entryTailPrefix checkpointPrimitives = WindowFieldCosts.group84 true ++ ((StairSchedule.forwardSegment checkpointPrimitives 87 62 425 450 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 (4 + 1)) ++ ((StairSchedule.forwardSegment checkpointPrimitives 62 47 450 465 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 (2 + 1)) ++ ((StairSchedule.forwardSegment checkpointPrimitives 47 32 465 480 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 (2 + 1)) ++ ((StairSchedule.forwardSegment checkpointPrimitives 32 22 480 490 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 (1 + 1)) ++ ((StairSchedule.forwardSegment checkpointPrimitives 22 12 490 500 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 (1 + 1)) ++ StairSchedule.forwardLast checkpointPrimitives))))) := by simp only [entryTailPrefix, List.append_assoc] theorem tail_sublist : entryTailPrefixCut.Sublist (entryTailPrefix checkpointPrimitives) := by rw [tailPrefix_rows] unfold entryTailPrefixCut exact (List.Sublist.refl _).append ((PackCutOdd.row_subOdd 87 62 425 450 13 85 4 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp1).append ((PackCutOdd.row_subOdd 62 47 450 465 22 90 2 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp2).append ((PackCutOdd.row_subOdd 47 32 465 480 30 93 2 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp3).append ((PackCutOdd.row_subOdd 32 22 480 490 36 96 1 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp4).append ((PackCutOdd.row_subOdd 22 12 490 500 41 98 1 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp5).append (List.Sublist.refl _)))))) theorem low_sublist : entryLowPrefixCut.Sublist (entryLowPrefix checkpointPrimitives) := by unfold entryLowPrefixCut entryLowPrefix exact ((List.Sublist.refl _).append (PackCutSub.rename_sub _ tail_sublist)).append (List.Sublist.refl _) theorem field_sublist : entryFieldHostedCut.Sublist (entryFieldHosted checkpointPrimitives) := by have f : (StairSchedule.fieldRename entryLowPrefixCut).Sublist (StairSchedule.fieldRename (entryLowPrefix checkpointPrimitives)) := PackCutSub.rename_sub _ (PackCutSub.rename_sub _ low_sublist) unfold entryFieldHostedCut entryFieldHosted exact ((((f.append (List.Sublist.refl _)).append (List.Sublist.refl _)).append (List.Sublist.refl _)).append (List.Sublist.refl _)).append (List.Sublist.refl _) /-- One cut odd row costs the placed `ep` and `dp` less, for every additive renaming-invariant cost. -/ theorem rowOdd_cost (c : Cost) (B N s f d first cc : Nat) (h1 : s + 1 ≤ 5 * first + 5) (h2 : 5 * first + 5 + 1 ≤ f) (h5 : 5 * first + 5 ≠ 5) (hdue : History5.packDue (5 * first + 5) = true) (hf0 : first ≠ 0) (hdp : StairLoan.rebindMany (StairSchedule.exclusiveRoles.drop d) (StairConcreteAssembly.hostPlan.group true d first (cc + 1)) (renameProgram (OB5.sig 511) (renameProgram (shifted (Placement5.pi first)) (Rolling1588.onPacket first Rolling1588.dp))) = renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (s + 1))) (5 * first))) Rolling1588.dp) : c.measure (StairSchedule.forwardSegment checkpointPrimitives B N s f ++ OddFullPass.P1LifeLoan.hostedGroup StairConcreteAssembly.hostPlan true d first (cc + 1)) = c.measure (PackCutOdd.cutRowOdd B N s f d first cc) + (c.measure Rolling1588.ep + c.measure Rolling1588.dp) := by obtain ⟨X, M, Y, ho, hc⟩ := PackCutOdd.row_shapeOdd B N s f d first cc h1 h2 h5 hdue hf0 hdp rw [ho, hc] simp only [c.append, c.rename] omega theorem rows_cost (c : Cost) : c.measure (entryTailPrefix checkpointPrimitives) = c.measure entryTailPrefixCut + 5 * (c.measure Rolling1588.ep + c.measure Rolling1588.dp) := by have r1 := rowOdd_cost c 87 62 425 450 13 85 4 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp1 have r2 := rowOdd_cost c 62 47 450 465 22 90 2 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp2 have r3 := rowOdd_cost c 47 32 465 480 30 93 2 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp3 have r4 := rowOdd_cost c 32 22 480 490 36 96 1 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp4 have r5 := rowOdd_cost c 22 12 490 500 41 98 1 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp5 rw [tailPrefix_rows] simp only [entryTailPrefixCut, c.append] at r1 r2 r3 r4 r5 ⊢ omega theorem field_cut (c : Cost) : c.measure (entryFieldHosted checkpointPrimitives) = c.measure entryFieldHostedCut + 5 * (c.measure Rolling1588.ep + c.measure Rolling1588.dp) := by have hr := rows_cost c simp only [entryFieldHosted, entryFieldHostedCut, entryLowPrefix, entryLowPrefixCut, StairSchedule.fieldRename, StairSchedule.parityRename, c.rename, c.append] omega theorem kernels (c : Cost) (gainF gainR tailSave fieldExtra : Nat) (dF : c.measure (WindowWalkCosts.forward true 4)+gainF=c.measure (Stair44WalkRun.forward true 409)) (dR : c.measure (WindowWalkCosts.backward false 85)+gainR=c.measure (Stair44WalkRun.backward false 490)) (h : c.measure (entryFieldHosted checkpointPrimitives)+tailSave= c.measure (StairHostsSchedule.entryFieldHosted checkpointPrimitives hostPlan)+fieldExtra) : c.measure divide+gainF+gainR+tailSave+5 * (c.measure Rolling1588.ep + c.measure Rolling1588.dp)= c.measure Stair44Outer.divide+fieldExtra := by have hc := field_cut c simp only [divide,Stair44Outer.divide,phasePlace,kernelPlace,c.append,c.rename] omega theorem kernelsM (c : Cost) (k gainF gainR tailSave fieldExtra : Nat) (mF : c.measure (WindowWalkCosts.forward false 84)+gainF=c.measure (Stair44WalkRun.forward false 489)) (mR : c.measure (WindowWalkCosts.backward true 4)+gainR=c.measure (Stair44WalkRun.backward true 409)) (h : c.measure (exitFieldHosted checkpointPrimitives)+tailSave= c.measure (StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan)+fieldExtra) : c.measure (multiply k)+gainF+gainR+tailSave=c.measure (Stair44Outer.multiply k)+fieldExtra := by simp only [multiply,Stair44Outer.multiply,phasePlace,kernelPlace,c.append,c.rename,Stair44PointMap.switchX] omega theorem finite_delta (c : Cost) (C : Point) (cx cy : Fp) (gain : Nat) (hEn : c.measure (EntryFuseOdd.entryYAllOdd layout (-cy)) = c.measure (ParityUniform.entryYAll layout (-cy))) (hEx : c.measure (EntryFuseOdd.exitYAllOdd layout cy) = c.measure (ParityUniform.exitYAll layout cy)) (h : c.measure divide+c.measure (multiply cx.val)+gain = c.measure Stair44Outer.divide+c.measure (Stair44Outer.multiply cx.val)) : c.measure (finite C cx cy)+gain=c.measure (Stair44Outer.finite C cx cy) := by simp only [finite,Stair44Outer.finite,borrowGeneric,Stair44Outer.borrowGeneric, generic,Stair44Outer.generic,Stair44PointMap.encodeY,c.append,c.rename,hEn,hEx] omega end ECDSAAdd.Entrant.StairPacket.WindowCallerCosts section namespace ECDSAAdd.Entrant.StairPacket.WindowCallerCosts open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines DirectSkywalk OB5 open StairConcreteAssembly Stair44Resources StairHostsSchedule set_option maxRecDepth 16000 set_option maxHeartbeats 1500000 set_option linter.unusedSimpArgs false private theorem fieldTcDiv : tc.measure (WindowFieldCosts.group84 true)=tc.measure (WindowFieldCosts.group true 1 84)+1050 := by rw [show tc.measure=toffoliCount from rfl] exact WindowFieldCosts.group_cost_div.1 private theorem fieldMcDiv : mc.measure (WindowFieldCosts.group84 true)=mc.measure (WindowFieldCosts.group true 1 84)+652 := by rw [show mc.measure=measurementCount from rfl] exact WindowFieldCosts.group_cost_div.2 private theorem fieldTcMul : tc.measure (WindowFieldCosts.group84 false)=tc.measure (WindowFieldCosts.group false 1 84)+962 := by rw [show tc.measure=toffoliCount from rfl] exact WindowFieldCosts.group_cost_mul.1 private theorem fieldMcMul : mc.measure (WindowFieldCosts.group84 false)=mc.measure (WindowFieldCosts.group false 1 84)+542 := by rw [show mc.measure=measurementCount from rfl] exact WindowFieldCosts.group_cost_mul.2 private theorem pair_delta2 {a b x y g h i j t1 t2 f1 f2 r : Nat} (l : a+g+h+t1=x+f1) (rr : b+i+j+t2=y+f2) (v : g+h+t1+i+j+t2=r+f1+f2) : a+b+r=x+y := by omega attribute [local irreducible] Stair44Outer.divide Stair44Outer.multiply divide multiply finite Stair44Outer.finite WindowWalkCosts.forward WindowWalkCosts.backward WindowFieldCosts.group84 WindowFieldCosts.group Stair44WalkRun.forward Stair44WalkRun.backward toffoliCount measurementCount theorem tc_div : tc.measure divide+39140+39029+1018=tc.measure Stair44Outer.divide+1050 := by have k := kernels tc 39140 39029 953 1050 (WindowWalkCosts.inst true 4 409 39140 39051 rfl rfl rfl).1 (WindowWalkCosts.inst false 85 490 39140 39029 rfl rfl rfl).2.1 (field_delta_tc_div 1050 fieldTcDiv) have e : tc.measure Rolling1588.ep + tc.measure Rolling1588.dp = 13 := by show toffoliCount Rolling1588.ep + toffoliCount Rolling1588.dp = 13 rw [PackCutCounts.tc_ep, PackCutCounts.tc_dp] omega theorem tc_mul (k : Nat) : tc.measure (multiply k)+39140+39051+1020=tc.measure (Stair44Outer.multiply k)+962 := kernelsM tc k 39140 39051 1020 962 (WindowWalkCosts.inst false 84 489 39140 39029 rfl rfl rfl).1 (WindowWalkCosts.inst true 4 409 39140 39051 rfl rfl rfl).2.1 (field_delta_tc_mul 962 fieldTcMul) theorem mc_div : mc.measure divide+17758+17745+1743=mc.measure Stair44Outer.divide+652 := by have k := kernels mc 17758 17745 1718 652 (WindowWalkCosts.instMeasurements true 4 409 17758 17767 rfl rfl rfl).1 (WindowWalkCosts.instMeasurements false 85 490 17736 17745 rfl rfl rfl).2 (field_delta_mc_div 652 fieldMcDiv) have e : mc.measure Rolling1588.ep + mc.measure Rolling1588.dp = 5 := by show measurementCount Rolling1588.ep + measurementCount Rolling1588.dp = 5 exact PackCutCounts.mc_epdp omega theorem mc_mul (k : Nat) : mc.measure (multiply k)+17736+17767+1744=mc.measure (Stair44Outer.multiply k)+542 := kernelsM mc k 17736 17767 1744 542 (WindowWalkCosts.instMeasurements false 84 489 17736 17745 rfl rfl rfl).1 (WindowWalkCosts.instMeasurements true 4 409 17758 17767 rfl rfl rfl).2 (field_delta_mc_mul 542 fieldMcMul) theorem deltas (C : Point) (cx cy : Fp) : toffoliCount (finite C cx cy)+156386=toffoliCount (Stair44Outer.finite C cx cy) ∧ measurementCount (finite C cx cy)+73299=measurementCount (Stair44Outer.finite C cx cy) := ⟨finite_delta tc C cx cy 156386 (OddOuterBridge.entryYAllOdd_tc_eq layout layout_widths (-cy)) (OddOuterBridge.exitYAllOdd_tc_eq layout layout_widths cy) (pair_delta2 tc_div (tc_mul _) rfl), finite_delta mc C cx cy 73299 (OddOuterBridge.entryYAllOdd_mc_eq layout layout_widths (-cy)) (OddOuterBridge.exitYAllOdd_mc_eq layout layout_widths cy) (pair_delta2 mc_div (mc_mul _) rfl)⟩ theorem totals (C : Point) : toffoliCount (program C) ≤ 2011335 ∧ measurementCount (program C) ≤ 1446134 := by have h := Stair44Resources.totals C cases C with | zero => change toffoliCount [] ≤ _ ∧ measurementCount [] ≤ _; simp [toffoliCount,measurementCount] | @some cx cy hc => have d := deltas (.some hc) cx cy simp only [program,Stair44Outer.program,(renameProgram_counts _ _).1, (renameProgram_counts _ _).2] at h ⊢ exact ⟨by omega,by omega⟩ end ECDSAAdd.Entrant.StairPacket.WindowCallerCosts section namespace ECDSAAdd.Entrant.StairPacket.WindowSites open Arithmetic MappedCompressed StairSiteAvoidance StairSiteEasy StairConcreteAssembly open ArchiveFieldScratch StairArchiveRelease StairArchiveNativeCut StairArchiveTen def reserved : List Wire := List.range' 4836 39 ++ List.range' 4876 4 private theorem subset {q : Wire} (h : q∈reserved) : q∈StairPhysicalInventory.physicalHoles := by rw [StairPhysicalLayout.physicalHoles_eq_nat] simp only [reserved,StairPhysicalLayout.newHolesNat,List.mem_append,List.mem_range'_1] at * omega theorem weaken {P : Program} {f : Wire → Wire} (h : PieceOK StairPhysicalInventory.physicalHoles f P) : PieceOK reserved f P := ⟨h.1,fun x hx bad => h.2 x hx (subset bad)⟩ theorem app {a b : Program} {f : Wire → Wire} {hs : List Wire} : PieceOK hs f (a++b) ↔ PieceOK hs f a ∧ PieceOK hs f b := by refine ⟨fun h => ⟨?_,?_⟩,fun h => h.1.append h.2⟩ <;> constructor <;> intro q hq · exact h.1 q (wires_append a b ▸ Finset.mem_union_left _ hq) · exact h.2 q (wires_append a b ▸ Finset.mem_union_left _ hq) · exact h.1 q (wires_append a b ▸ Finset.mem_union_right _ hq) · exact h.2 q (wires_append a b ▸ Finset.mem_union_right _ hq) theorem ren {a : Program} {f g : Wire → Wire} {hs : List Wire} : PieceOK hs f (renameProgram g a) ↔ PieceOK hs (fun q => f (g q)) a := by refine ⟨fun h => ⟨?_,?_⟩,PieceOK.rename⟩ <;> intro x hx · exact h.1 (g x) (renameProgram_support g a ▸ Finset.mem_image.mpr ⟨x,hx,rfl⟩) · exact h.2 (g x) (renameProgram_support g a ▸ Finset.mem_image.mpr ⟨x,hx,rfl⟩) private theorem singleton_ok {q : Wire} (h : Stair44OuterSites.fit q=true) : q∈StairHoleSupport.recordArena ∧ q∉StairHoleSupport.oldHoles ∧ q∉reserved := by let P : Program := [.X q] have inv : PieceOK StairPhysicalInventory.physicalHoles id P := Stair44OuterSites.fits (fun x hx => by have eq : x=q := by simpa [P,wires,Instr.wires] using hx exact eq ▸ h) have here : q∈wires P := by simp [P,wires,Instr.wires] exact ⟨(inv.1 q here).1,(inv.1 q here).2,(weaken inv).2 q here⟩ private theorem tagOK : 4835∈StairHoleSupport.recordArena ∧ 4835∉StairHoleSupport.oldHoles ∧ 4835∉reserved := by rw [StairPhysicalLayout.recordArena_eq,StairPhysicalLayout.oldHoles_eq] decide +kernel private theorem addresses (j : Nat) (hj : j∈List.range' 1 83) (q : Wire) (hq : q∈layout j) : Stair44OuterSites.fit q=true ∨ q=4835 := by have p := List.all_eq_true.mp packets_exact j hj dsimp only [packetOK,Id.run,pure] at p simp only [Bool.and_eq_true] at p simp only [layout,transient_exact,List.mem_append,List.mem_cons] at hq rcases hq with a | a | a · have z := List.all_eq_true.mp p.2 q a simp only [Bool.and_eq_true] at z exact Or.inl z.1 · exact Or.inr a · exact Or.inl (List.all_eq_true.mp permanent_exact.2 q a) theorem hook (j : Nat) (hj : j∈List.range' 1 83) (op : Stage) : PieceOK reserved TP (fieldHook j op) := by rw [fieldHook,ren] have cover (x : Wire) (hx : x∈wires (program op)) : TP (fieldPort j x)∈StairHoleSupport.recordArena ∧ TP (fieldPort j x)∉StairHoleSupport.oldHoles ∧ TP (fieldPort j x)∉reserved := by have lt := Finset.mem_range.mp (sub op hx) have sl := (layout_frame j hj).2 have small : x < (layout j).length := sl ▸ lt have member : port j x ∈ layout j := by simp only [port,List.getElem?_eq_getElem small,Option.getD_some,List.getElem_mem] change StairOuterPlacement.outerPlace _ ∈ _ ∧ _ ∧ _ simp only [show TP=StairOuterPlacement.outerPlace from rfl,StairPlaceFast.outerPlace_eqB,placed_port j hj x lt] rcases addresses j hj _ member with p|e · exact singleton_ok p · rw [e]; exact tagOK exact ⟨fun x hx => ⟨(cover x hx).1,(cover x hx).2.1⟩,fun x hx => (cover x hx).2.2⟩ theorem width {P : Program} (h : PieceOK reserved id P) : Challenge.qubits P ≤ 1543 := by have listOK := StairCertificate.holeList_of_physical_sub reserved (by decide +kernel) (fun _ hx => subset hx) exact StairCertificate.qubits_le_holes reserved listOK P (holePlacement_of_ok h) end ECDSAAdd.Entrant.StairPacket.WindowSites end section namespace ECDSAAdd.Entrant.StairPacket.PartialSites open Arithmetic MappedCompressed Partial StairSiteAvoidance set_option maxRecDepth 50000 set_option maxHeartbeats 6000000 attribute [local irreducible] wires domain theorem forwardMixed_domain (d : Bool) : Covered (Shadow20.MixedWindow.forwardMixedCut d) := by intro q h rw [domain_eq] exact (Shadow20.MixedWindow.mixedCut_covered d).1 q h theorem reverseMixed_domain (d : Bool) : Covered (TickCut.Mixed.reverse d) := by intro q h rw [domain_eq] exact TickCut.Mixed.covered d q h theorem forwardMixed_fits (d : Bool) : ∀ q ∈ wires (Shadow20.MixedWindow.forwardMixedCut d), Stair44PhaseSites.valid (Stair44WalkMap.rest q) = true := fun q h => valid (forwardMixed_domain d q h) theorem reverseMixed_fits (d : Bool) : ∀ q ∈ wires (TickCut.Mixed.reverse d), Stair44PhaseSites.valid (Stair44WalkMap.rest q) = true := fun q h => valid (reverseMixed_domain d q h) end ECDSAAdd.Entrant.StairPacket.PartialSites end section namespace ECDSAAdd.Entrant.StairPacket.WindowSlots open Arithmetic MappedCompressed Secp256k1 Baselines Challenge Stair44Resources Stair44Outer open StairConcreteAssembly WindowWalkCosts WindowFold Partial set_option maxHeartbeats 1400000 set_option maxRecDepth 14000 set_option linter.unusedSimpArgs false attribute [local irreducible] toffoliCount gateSlots measurementCount wires renameProgram Rolling1588TickGap.forward Rolling1588.reverse Shadow20.MixedWindow.forwardMixedCut TickCut.Mixed.reverse theorem walk (c : Cost) (d : Bool) (tail f r n : Nat) (hn : 405+tail=n) (hf : c.measure (Shadow20.MixedWindow.forwardMixedCut d) ≤ f) (hr : c.measure (TickCut.Mixed.reverse d) ≤ r) : c.measure (WindowWalkCosts.forward d tail) ≤ c.measure (Stair44WalkRun.forward d n)+f ∧ c.measure (WindowWalkCosts.backward d tail) ≤ c.measure (Stair44WalkRun.backward d n)+r := by subst n have a := StairRestSupport.forward_append d 29 16 (376+tail) have b := StairRestSupport.forward_append d 376 45 tail have x := StairRestSupport.reverse_append d 29 16 (376+tail) have y := StairRestSupport.reverse_append d 376 45 tail change Rolling1588TickGap.forward d 16 (29+(376+tail)) = Rolling1588TickGap.forward d 16 29 ++ Rolling1588TickGap.forward d 45 (376+tail) at a change Rolling1588.reverse d 16 (29+(376+tail)) = Rolling1588.reverse d 45 (376+tail) ++ Rolling1588.reverse d 16 29 at x rw [b] at a rw [y] at x have num : 405+tail=29+(376+tail) := by omega simp only [Stair44WalkRun.forward, Stair44WalkRun.backward,WindowWalkCosts.forward,WindowWalkCosts.backward,num,a,x, c.append,c.rename] norm_num only [] constructor <;> omega private theorem kernels (gainF gainR fieldExtra : Nat) (dF : slots.measure (WindowWalkCosts.forward true 4) ≤ slots.measure (Stair44WalkRun.forward true 409)+gainF) (dR : slots.measure (WindowWalkCosts.backward false 85) ≤ slots.measure (Stair44WalkRun.backward false 490)+gainR) (g : slots.measure (WindowFieldCosts.group84 true)=slots.measure (WindowFieldCosts.group true 1 84)+fieldExtra) : slots.measure WindowCallerCosts.divide ≤ slots.measure Stair44Outer.divide+gainF+gainR+fieldExtra+7900 := by have h := WindowCallerCosts.field_delta_slots true _ g have hc := WindowCallerCosts.field_cut slots simp only [if_true] at h simp only [WindowCallerCosts.divide,Stair44Outer.divide,phasePlace,kernelPlace, Stair44Resources.slots.append,Stair44Resources.slots.rename] omega private theorem kernelsM (k gainF gainR fieldExtra : Nat) (mF : slots.measure (WindowWalkCosts.forward false 84) ≤ slots.measure (Stair44WalkRun.forward false 489)+gainF) (mR : slots.measure (WindowWalkCosts.backward true 4) ≤ slots.measure (Stair44WalkRun.backward true 409)+gainR) (g : slots.measure (WindowFieldCosts.group84 false)=slots.measure (WindowFieldCosts.group false 1 84)+fieldExtra) : slots.measure (WindowCallerCosts.multiply k) ≤ slots.measure (Stair44Outer.multiply k)+gainF+gainR+fieldExtra+8160 := by have h := WindowCallerCosts.field_delta_slots false _ g simp only [Bool.false_eq_true,if_false] at h simp only [WindowCallerCosts.multiply,Stair44Outer.multiply,phasePlace,kernelPlace, Stair44Resources.slots.append,Stair44Resources.slots.rename,Stair44PointMap.switchX] omega private theorem finite_upper (C : Point) (cx cy : Fp) (gain : Nat) (h : slots.measure WindowCallerCosts.divide+slots.measure (WindowCallerCosts.multiply cx.val)+7144 ≤ slots.measure Stair44Outer.divide+slots.measure (Stair44Outer.multiply cx.val)+gain) : slots.measure (WindowCallerCosts.finite C cx cy) ≤ slots.measure (Stair44Outer.finite C cx cy)+gain := by have hy := OddOuterBridge.outerY_slots_delta cy rw [show slots.measure=Challenge.gateSlots from rfl] at h ⊢ simp only [WindowCallerCosts.finite,Stair44Outer.finite,WindowCallerCosts.borrowGeneric,Stair44Outer.borrowGeneric, WindowCallerCosts.generic,Stair44Outer.generic,Challenge.gateSlots_append,Baselines.rename_gateSlots] at * omega private theorem route20_slots (j : Fin 9) (i n : Nat) : gateSlots (Shadow20.routed20 j i n) ≤ 5000 * n ∧ gateSlots (Shadow20.unrouted20 j i n) ≤ 5000 * n := by induction n generalizing i with | zero => simp only [Shadow20.routed20, Shadow20.unrouted20, gateSlots_nil, Nat.mul_zero, Nat.le_refl, and_self] | succ n ih => have tail := ih (i + 1) have t := WindowSlots.tick (Shadow20.shape20 j) i have u := WindowSlots7.untickR_slots (Shadow20.shape20 j) i simp only [Shadow20.routed20, Shadow20.unrouted20, gateSlots_append, rename_gateSlots, Nat.mul_succ] exact ⟨by omega, by omega⟩ private theorem sum_flatten_slots (ps : List Program) : gateSlots ps.flatten = (ps.map gateSlots).sum := by induction ps with | nil => simp only [List.flatten_nil, gateSlots_nil, List.map_nil, List.sum_nil] | cons p ps ih => simp only [List.flatten_cons, gateSlots_append, List.map_cons, List.sum_cons, ih] private theorem sum_flatMap_slots_le {α : Type} (f : α → List Program) (b : α → Nat) (xs : List α) (h : ∀ x ∈ xs, ((f x).map gateSlots).sum ≤ b x) : ((xs.flatMap f).map gateSlots).sum ≤ (xs.map b).sum := by induction xs with | nil => exact Nat.le_refl 0 | cons x xs ih => simp only [List.flatMap_cons, List.map_append, List.sum_append, List.map_cons, List.sum_cons] exact Nat.add_le_add (h x List.mem_cons_self) (ih fun y hy => h y (List.mem_cons_of_mem _ hy)) private def b15SF (j : Fin 26) : Nat := 35 + 5000 + 168 + 15988 + 70000 + (6 * Shadow7.wpP (start j) + 5 * Shadow7.liveW (start j) + 10 * Shadow7.lowsP (start j) + 650 + 3 * Shadow7.wpP (start j + 15) + CRTBarrel.barrelSlots (start j) false) private def b15SR (j : Fin 26) : Nat := 36 + 5000 + 166 + 12262 + 70098 + (6 * Shadow7.wpP (start j) + 5 * Shadow7.liveW (start j) + 11 * Shadow7.lowsP (start j) + 619 + 3 * Shadow7.wpP (start j + 15) + CRTBarrel.barrelSlots (start j) true) private def b20SF (j : Fin 9) : Nat := let s := Shadow20.start20 j 35 + 5000 + (if j.val = 0 then 168 else 336) + 15988 + 95000 + (6 * Shadow20.wpP20 s + 5 * Shadow20.liveW20 s + 10 * Shadow20.lowsP20 s + 847 + 3 * Shadow20.nextWp20 s + Shadow20.barrel20Slots s false) private def b20SR (j : Fin 9) : Nat := let s := Shadow20.start20 j 36 + 5000 + (if j.val = 0 then 166 else 332) + 12262 + 95000 + (6 * Shadow20.wpP20 s + 5 * Shadow20.liveW20 s + 11 * Shadow20.lowsP20 s + 805 + 3 * Shadow20.nextWp20 s + Shadow20.barrel20Slots s true) private theorem packW_slots_le (d : Bool) (s t : Nat) (hd : WindowParams.dueTick t = true) : gateSlots (Shadow20.MixedWindow.packW d s t) ≤ 168 ∧ gateSlots (Shadow20.MixedWindow.unpackW d s t) ≤ 166 := by have h1 := WindowParams7.slots_le.pack d s t have h2 := WindowParams7.slots_le.unpack d s t simp only [Pieces.map, Shadow7.params, ofParts, WindowParams7.slotsV, hd, ↓reduceIte] at h1 h2 change gateSlots (Shadow20.MixedWindow.packW d s t) ≤ _ at h1 change gateSlots (Shadow20.MixedWindow.unpackW d s t) ≤ _ at h2 cases d <;> simp only [if_true, if_false, Bool.false_eq_true] at h1 h2 <;> exact ⟨by omega, by omega⟩ private theorem arch15_slots_le (j : Fin 26) (d : Bool) : gateSlots (Shadow7.archiveLoadP j d) ≤ 15988 ∧ gateSlots (Shadow7.archiveRestoreP j d) ≤ 12262 := by have h1 := WindowParams7.slots_le.load j d have h2 := WindowParams7.slots_le.restore j d simp only [Pieces.map, Shadow7.params, ofParts, WindowParams7.slotsV] at h1 h2 cases d <;> simp only [if_true, if_false, Bool.false_eq_true] at h1 h2 <;> exact ⟨by omega, by omega⟩ private theorem arch20_slots_le (j : Fin 9) (d : Bool) : gateSlots (Shadow20.archiveLoadP20 j d) ≤ 15988 ∧ gateSlots (Shadow20.archiveRestoreP20 j d) ≤ 12262 := by have h := Shadow20.archive20_counts j d have h1 := (Shadow7.archive_counts WindowParams.first 0 d).2.2.1 have h2 := (Shadow7.archive_counts WindowParams.first 0 d).2.2.2.2.2.1 have a := arch15_slots_le WindowParams.first d exact ⟨by omega, by omega⟩ private theorem arch150_slots_le (d : Bool) : gateSlots (Shadow20.archiveLoad150To20 d) ≤ 15988 ∧ gateSlots (Shadow20.archiveRestore150To20 d) ≤ 12262 := by obtain ⟨_, _, l3, _, _, l6⟩ := moves_counts 165 (Shadow20.e0P20 165 + 6) obtain ⟨_, _, m3, _, _, m6⟩ := moves240_counts have hL : gateSlots (Shadow20.archiveLoad150To20 d) = gateSlots (archiveLoad240 d) := by simp only [Shadow20.archiveLoad150To20, archiveLoad240, gateSlots_append, rename_gateSlots, l3, m3] have hR : gateSlots (Shadow20.archiveRestore150To20 d) = gateSlots (archiveRestore240 d) := by simp only [Shadow20.archiveRestore150To20, archiveRestore240, gateSlots_append, rename_gateSlots, l6, m6] have h1 := (Shadow7.archive_counts WindowParams.first 0 d).2.2.1 have h2 := (Shadow7.archive_counts WindowParams.first 0 d).2.2.2.2.2.1 have a := arch15_slots_le WindowParams.first d exact ⟨by omega, by omega⟩ private theorem exit420_slots_le (d : Bool) : gateSlots (Shadow7.exitLoadP 420 d) ≤ 15988 ∧ gateSlots (Shadow7.exitRestoreP 420 d) ≤ 12262 := by have h1 := WindowParams7.slots_le.exitLoad 420 d have h2 := WindowParams7.slots_le.exitRestore 420 d simp only [Pieces.map, Shadow7.params, ofParts, WindowParams7.slotsV] at h1 h2 cases d <;> simp only [if_true, if_false, Bool.false_eq_true] at h1 h2 <;> exact ⟨by omega, by omega⟩ private theorem mixed_slot_sum_vals : ((22 * Shadow7.wpP 45 - 9) + (35 + (5000 + (168 + (70000 + ((6 * Shadow7.wpP 45 + 5 * Shadow7.liveW 45 + 10 * Shadow7.lowsP 45 + 650 + 3 * Shadow7.wpP 60 + CRTBarrel.barrelSlots 45 false) + 0)))))) + (Shadow20.MixedWindow.prefixPairs.map fun p => b15SF p.2).sum + (35 + (5000 + (168 + (15988 + (70000 + (11695 + 0)))))) + ((List.finRange 9).map b20SF).sum + (35 + (5000 + (168 + (168 + (15988 + (70000 + ((6 * Shadow7.wpP 345 + 5 * Shadow7.liveW 345 + 10 * Shadow7.lowsP 345 + 650 + 3 * Shadow7.wpP 360 + CRTBarrel.barrelSlots 345 false) + 0))))))) + (Shadow20.MixedWindow.suffixPairs.map fun p => b15SF p.2).sum + (9 + ((21 * Shadow7.wpP 420 - 7) + (6004 + (168 + (15988 + 0))))) ≤ 2710000 ∧ (12262 + (166 + (6001 + ((22 * Shadow7.wpP 420 - 9) + (9 + 0))))) + (Shadow20.MixedWindow.suffixPairs.reverse.map fun p => b15SR p.2).sum + ((6 * Shadow7.wpP 345 + 5 * Shadow7.liveW 345 + 11 * Shadow7.lowsP 345 + 619 + 3 * Shadow7.wpP 360 + CRTBarrel.barrelSlots 345 true) + (70098 + (12262 + (166 + (166 + (5000 + (36 + 0))))))) + ((List.finRange 9).reverse.map b20SR).sum + (11671 + (70098 + (12262 + (166 + (5000 + (36 + 0)))))) + (Shadow20.MixedWindow.prefixPairs.reverse.map fun p => b15SR p.2).sum + ((6 * Shadow7.wpP 45 + 5 * Shadow7.liveW 45 + 11 * Shadow7.lowsP 45 + 619 + 3 * Shadow7.wpP 60 + CRTBarrel.barrelSlots 45 true) + (70098 + (166 + (5000 + (36 + ((21 * Shadow7.wpP 45 - 7) + 0)))))) ≤ 2610000 := by decide +kernel private theorem tick420_slots_le : gateSlots (Shadow20.MixedWindow.tickW 420) ≤ 6004 ∧ gateSlots (Shadow20.MixedWindow.recvW 420) ≤ 6001 := by unfold Shadow20.MixedWindow.tickW Shadow20.MixedWindow.recvW rw [rename_gateSlots, rename_gateSlots] decide +kernel private theorem b15F_slots_le (d : Bool) (i j : Fin 26) (hj : j.val ≤ 24) (hd : WindowParams.dueTick (start j - 10) = true) : ((Shadow20.MixedWindow.block15F d i j).map gateSlots).sum ≤ b15SF j := by have e := (Shadow7.enter_counts j).2.2.2.2.1 have r0 := (WindowSlots7.route j 0 1).1 have r1 := (WindowSlots7.route j 1 14).1 have pk := (packW_slots_le d (start j) (start j - 10) hd).1 have ar := (arch15_slots_le i d).1 have lv := (CRTWindow.leave_metrics j (Nat.zero_le _) hj).2.2.2.2.1 simp only [Shadow20.MixedWindow.block15F, b15SF, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] omega private theorem sel14_slots (j : Fin 26) : gateSlots (TickCut.Tail.selected j 1 14) ≤ 70098 := by have c := (TickCut.Tail.tail_counts j).2.2 have r := (WindowSlots7.route j 1 14).2 rw [TickCut.Tail.selected, if_pos (show (1:Nat) = 1 ∧ (14:Nat) = 14 from ⟨rfl, rfl⟩)] omega private theorem b15R_slots_le (d : Bool) (i j : Fin 26) (hj : j.val ≤ 24) (hd : WindowParams.dueTick (start j - 10) = true) : ((Shadow20.MixedWindow.block15R d i j).map gateSlots).sum ≤ b15SR j := by have e := (Shadow7.enter_counts j).2.2.2.2.2 have r0 := (WindowSlots7.route j 0 1).2 have r1 := sel14_slots j have pk := (packW_slots_le d (start j) (start j - 10) hd).2 have ar := (arch15_slots_le i d).2 have lv := (CRTWindow.leave_metrics j (Nat.zero_le _) hj).2.2.2.2.2 simp only [Shadow20.MixedWindow.block15R, b15SR, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] omega private theorem b20F_slots_le (d : Bool) (j : Fin 9) : ((Shadow20.MixedWindow.block20F d j).map gateSlots).sum ≤ b20SF j := by have e := (Shadow20.enter20_counts j).2.2.2.2.1 have r0 := (route20_slots j 0 1).1 have r1 := (route20_slots j 1 19).1 have lv := (Shadow20.leave20Red_counts j).2.2.2.2.1 by_cases h0 : j.val = 0 · have pk := (packW_slots_le d 165 155 (by decide)).1 have ar := (arch150_slots_le d).1 simp only [Shadow20.MixedWindow.block20F, b20SF, h0, ↓reduceDIte, ↓reduceIte, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] omega · have hd1 : WindowParams.dueTick (Shadow20.start20 j - 15) = true := by have h : ∀ k : Fin 9, k.val ≠ 0 → WindowParams.dueTick (Shadow20.start20 k - 15) = true := by decide +kernel exact h j h0 have hd2 : WindowParams.dueTick (Shadow20.start20 j - 10) = true := by have h : ∀ k : Fin 9, k.val ≠ 0 → WindowParams.dueTick (Shadow20.start20 k - 10) = true := by decide +kernel exact h j h0 have pk1 := (packW_slots_le d (Shadow20.start20 j) (Shadow20.start20 j - 15) hd1).1 have pk2 := (packW_slots_le d (Shadow20.start20 j) (Shadow20.start20 j - 10) hd2).1 have ar := (arch20_slots_le ⟨j.val - 1, by omega⟩ d).1 simp only [Shadow20.MixedWindow.block20F, b20SF, h0, ↓reduceDIte, ↓reduceIte, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] omega private theorem b20R_slots_le (d : Bool) (j : Fin 9) : ((Shadow20.MixedWindow.block20R d j).map gateSlots).sum ≤ b20SR j := by have e := (Shadow20.enter20_counts j).2.2.2.2.2 have r0 := (route20_slots j 0 1).2 have r1 := (route20_slots j 1 19).2 have lv := (Shadow20.leave20Red_counts j).2.2.2.2.2 by_cases h0 : j.val = 0 · have pk := (packW_slots_le d 165 155 (by decide)).2 have ar := (arch150_slots_le d).2 simp only [Shadow20.MixedWindow.block20R, b20SR, h0, ↓reduceDIte, ↓reduceIte, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] omega · have hd1 : WindowParams.dueTick (Shadow20.start20 j - 15) = true := by have h : ∀ k : Fin 9, k.val ≠ 0 → WindowParams.dueTick (Shadow20.start20 k - 15) = true := by decide +kernel exact h j h0 have hd2 : WindowParams.dueTick (Shadow20.start20 j - 10) = true := by have h : ∀ k : Fin 9, k.val ≠ 0 → WindowParams.dueTick (Shadow20.start20 k - 10) = true := by decide +kernel exact h j h0 have pk1 := (packW_slots_le d (Shadow20.start20 j) (Shadow20.start20 j - 15) hd1).2 have pk2 := (packW_slots_le d (Shadow20.start20 j) (Shadow20.start20 j - 10) hd2).2 have ar := (arch20_slots_le ⟨j.val - 1, by omega⟩ d).2 simp only [Shadow20.MixedWindow.block20R, b20SR, h0, ↓reduceDIte, ↓reduceIte, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] omega private theorem sum_map_append7 (m : Program → Nat) (a b c d e f g : List Program) : ((a ++ b ++ c ++ d ++ e ++ f ++ g).map m).sum = (a.map m).sum + (b.map m).sum + (c.map m).sum + (d.map m).sum + (e.map m).sum + (f.map m).sum + (g.map m).sum := by simp only [List.map_append, List.sum_append] private theorem sum_map5 (m : Program → Nat) (a b c d e : Program) : ([a, b, c, d, e].map m).sum = m a + (m b + (m c + (m d + (m e + 0)))) := by simp only [List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] private theorem sum_map6 (m : Program → Nat) (a b c d e f : Program) : ([a, b, c, d, e, f].map m).sum = m a + (m b + (m c + (m d + (m e + (m f + 0))))) := by simp only [List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] private theorem sum_map7 (m : Program → Nat) (a b c d e f g : Program) : ([a, b, c, d, e, f, g].map m).sum = m a + (m b + (m c + (m d + (m e + (m f + (m g + 0)))))) := by simp only [List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] attribute [local irreducible] Shadow7.enterP Shadow7.enterInvP Shadow7.portalP Shadow7.portalInvP Shadow7.parkP Shadow7.parkInvP Shadow7.routed Shadow7.unrouted Shadow7.archiveLoadP Shadow7.archiveRestoreP Shadow7.exitLoadP Shadow7.exitRestoreP CRTBarrel.leave CRTBarrel.unleave Shadow20.enterP20 Shadow20.enterInvP20 Shadow20.leaveP20 Shadow20.leaveInvP20 Shadow20.leaveP20Red Shadow20.leaveInvP20Red Shadow20.routed20 Shadow20.unrouted20 Shadow20.archiveLoadP20 Shadow20.archiveRestoreP20 Shadow20.leave150To20 Shadow20.leaveInv150To20 Shadow20.leave150To20Red Shadow20.leaveInv150To20Red Shadow20.archiveLoad150To20 Shadow20.archiveRestore150To20 Shadow20.MixedWindow.packW Shadow20.MixedWindow.unpackW Shadow20.MixedWindow.tickW Shadow20.MixedWindow.recvW Shadow20.MixedWindow.block15F Shadow20.MixedWindow.block15R Shadow20.MixedWindow.block20F Shadow20.MixedWindow.block20R in private theorem mixed_slots_F (d : Bool) : gateSlots (Shadow20.MixedWindow.forwardMixed d) ≤ 2710000 := by have hp15 : ∀ p ∈ Shadow20.MixedWindow.prefixPairs, p.2.val ≤ 24 ∧ WindowParams.dueTick (start p.2 - 10) = true := by decide have hs15 : ∀ p ∈ Shadow20.MixedWindow.suffixPairs, p.2.val ≤ 24 ∧ WindowParams.dueTick (start p.2 - 10) = true := by decide have hprF := sum_flatMap_slots_le (fun p : Fin 26 × Fin 26 => Shadow20.MixedWindow.block15F d p.1 p.2) (fun p => b15SF p.2) Shadow20.MixedWindow.prefixPairs (fun p hp => by have h := hp15 p hp; exact b15F_slots_le d p.1 p.2 h.1 h.2) have hsuF := sum_flatMap_slots_le (fun p : Fin 26 × Fin 26 => Shadow20.MixedWindow.block15F d p.1 p.2) (fun p => b15SF p.2) Shadow20.MixedWindow.suffixPairs (fun p hp => by have h := hs15 p hp; exact b15F_slots_le d p.1 p.2 h.1 h.2) have h20F := sum_flatMap_slots_le (Shadow20.MixedWindow.block20F d) b20SF (List.finRange 9) (fun j _ => b20F_slots_le d j) have p45 := (Shadow7.portal_counts 45 (by decide)).2.2.2.2.1 have p420 := (Shadow7.portal_counts 420 (by decide)).2.2.2.2.2 have pk420 := (Shadow7.park_counts 420).2.2.2.2.1 have t420 := tick420_slots_le.1 have exF := (exit420_slots_le d).1 have e0 := (Shadow7.enter_counts Shadow20.MixedWindow.j0).2.2.2.2.1 have r0a : gateSlots (Shadow7.routed Shadow20.MixedWindow.j0 0 1) ≤ 5000 := by simpa only [show 5000 * 1 = 5000 from rfl] using (WindowSlots7.route Shadow20.MixedWindow.j0 0 1).1 have r0b : gateSlots (Shadow7.routed Shadow20.MixedWindow.j0 1 14) ≤ 70000 := by simpa only [show 5000 * 14 = 70000 from rfl] using (WindowSlots7.route Shadow20.MixedWindow.j0 1 14).1 have l0 := (CRTWindow.leave_metrics Shadow20.MixedWindow.j0 (by decide) (by decide)).2.2.2.2.1 have e7 := (Shadow7.enter_counts Shadow20.MixedWindow.j7).2.2.2.2.1 have r7a : gateSlots (Shadow7.routed Shadow20.MixedWindow.j7 0 1) ≤ 5000 := by simpa only [show 5000 * 1 = 5000 from rfl] using (WindowSlots7.route Shadow20.MixedWindow.j7 0 1).1 have r7b : gateSlots (Shadow7.routed Shadow20.MixedWindow.j7 1 14) ≤ 70000 := by simpa only [show 5000 * 14 = 70000 from rfl] using (WindowSlots7.route Shadow20.MixedWindow.j7 1 14).1 have a6 := (arch15_slots_le Shadow20.MixedWindow.j6 d).1 have l7 := Shadow20.leave150To20Red_counts.2.2.2.2.1 have e20 := (Shadow7.enter_counts Shadow20.MixedWindow.j20).2.2.2.2.1 have r20a : gateSlots (Shadow7.routed Shadow20.MixedWindow.j20 0 1) ≤ 5000 := by simpa only [show 5000 * 1 = 5000 from rfl] using (WindowSlots7.route Shadow20.MixedWindow.j20 0 1).1 have r20b : gateSlots (Shadow7.routed Shadow20.MixedWindow.j20 1 14) ≤ 70000 := by simpa only [show 5000 * 14 = 70000 from rfl] using (WindowSlots7.route Shadow20.MixedWindow.j20 1 14).1 have a8 := (arch20_slots_le Shadow20.MixedWindow.k8 d).1 have l20 := (CRTWindow.leave_metrics Shadow20.MixedWindow.j20 (by decide) (by decide)).2.2.2.2.1 have pk45 := (packW_slots_le d 45 45 (by decide)).1 have pk140 := (packW_slots_le d 150 140 (by decide)).1 have pk330 := (packW_slots_le d 345 330 (by decide)).1 have pk335 := (packW_slots_le d 345 335 (by decide)).1 have pk410 := (packW_slots_le d 420 410 (by decide)).1 have mv := mixed_slot_sum_vals.1 rw [show start Shadow20.MixedWindow.j0 = 45 from rfl, show (45 : Nat) + 15 = 60 from rfl] at l0 rw [show start Shadow20.MixedWindow.j20 = 345 from rfl, show (345 : Nat) + 15 = 360 from rfl] at l20 have hdef : Shadow20.MixedWindow.forwardMixed d = (Shadow20.MixedWindow.forwardL d).flatten := by unfold Shadow20.MixedWindow.forwardMixed; rfl rw [hdef, sum_flatten_slots, Shadow20.MixedWindow.forwardL, sum_map_append7, sum_map6, sum_map6, sum_map7, sum_map5] rw [p45, e0, l0, e7, l7, e20, l20, pk420, p420] refine Nat.le_trans ?_ mv exact Nat.add_le_add (Nat.add_le_add (Nat.add_le_add (Nat.add_le_add (Nat.add_le_add (Nat.add_le_add (Nat.add_le_add_left (Nat.add_le_add_left (Nat.add_le_add r0a (Nat.add_le_add pk45 (Nat.add_le_add r0b (Nat.le_refl _)))) _) _) hprF) (Nat.add_le_add_left (Nat.add_le_add r7a (Nat.add_le_add pk140 (Nat.add_le_add a6 (Nat.add_le_add r7b (Nat.le_refl _))))) _)) h20F) (Nat.add_le_add_left (Nat.add_le_add r20a (Nat.add_le_add pk330 (Nat.add_le_add pk335 (Nat.add_le_add a8 (Nat.add_le_add r20b (Nat.le_refl _)))))) _)) hsuF) (Nat.add_le_add_left (Nat.add_le_add_left (Nat.add_le_add t420 (Nat.add_le_add pk410 (Nat.add_le_add exF (Nat.le_refl _)))) _) _) attribute [local irreducible] Shadow7.enterP Shadow7.enterInvP Shadow7.portalP Shadow7.portalInvP Shadow7.parkP Shadow7.parkInvP Shadow7.routed Shadow7.unrouted Shadow7.archiveLoadP Shadow7.archiveRestoreP Shadow7.exitLoadP Shadow7.exitRestoreP CRTBarrel.leave CRTBarrel.unleave Shadow20.enterP20 Shadow20.enterInvP20 Shadow20.leaveP20 Shadow20.leaveInvP20 Shadow20.leaveP20Red Shadow20.leaveInvP20Red Shadow20.routed20 Shadow20.unrouted20 Shadow20.archiveLoadP20 Shadow20.archiveRestoreP20 Shadow20.leave150To20 Shadow20.leaveInv150To20 Shadow20.leave150To20Red Shadow20.leaveInv150To20Red Shadow20.archiveLoad150To20 Shadow20.archiveRestore150To20 Shadow20.MixedWindow.packW Shadow20.MixedWindow.unpackW Shadow20.MixedWindow.tickW Shadow20.MixedWindow.recvW Shadow20.MixedWindow.block15F Shadow20.MixedWindow.block15R Shadow20.MixedWindow.block20F Shadow20.MixedWindow.block20R in private theorem mixed_slots_R (d : Bool) : gateSlots (Shadow20.MixedWindow.reverseMixed d) ≤ 2610000 := by have hp15 : ∀ p ∈ Shadow20.MixedWindow.prefixPairs, p.2.val ≤ 24 ∧ WindowParams.dueTick (start p.2 - 10) = true := by decide have hs15 : ∀ p ∈ Shadow20.MixedWindow.suffixPairs, p.2.val ≤ 24 ∧ WindowParams.dueTick (start p.2 - 10) = true := by decide have hprR := sum_flatMap_slots_le (fun p : Fin 26 × Fin 26 => Shadow20.MixedWindow.block15R d p.1 p.2) (fun p => b15SR p.2) Shadow20.MixedWindow.prefixPairs.reverse (fun p hp => by have h := hp15 p (List.mem_reverse.mp hp); exact b15R_slots_le d p.1 p.2 h.1 h.2) have hsuR := sum_flatMap_slots_le (fun p : Fin 26 × Fin 26 => Shadow20.MixedWindow.block15R d p.1 p.2) (fun p => b15SR p.2) Shadow20.MixedWindow.suffixPairs.reverse (fun p hp => by have h := hs15 p (List.mem_reverse.mp hp); exact b15R_slots_le d p.1 p.2 h.1 h.2) have h20R := sum_flatMap_slots_le (Shadow20.MixedWindow.block20R d) b20SR (List.finRange 9).reverse (fun j _ => b20R_slots_le d j) have p45 := (Shadow7.portal_counts 45 (by decide)).2.2.2.2.2 have p420 := (Shadow7.portal_counts 420 (by decide)).2.2.2.2.1 have pk420 := (Shadow7.park_counts 420).2.2.2.2.2 have t420 := tick420_slots_le.2 have exR := (exit420_slots_le d).2 have e0 := (Shadow7.enter_counts Shadow20.MixedWindow.j0).2.2.2.2.2 have r0a : gateSlots (Shadow7.unrouted Shadow20.MixedWindow.j0 0 1) ≤ 5000 := by simpa only [show 5000 * 1 = 5000 from rfl] using (WindowSlots7.route Shadow20.MixedWindow.j0 0 1).2 have r0b : gateSlots (TickCut.Tail.selected Shadow20.MixedWindow.j0 1 14) ≤ 70098 := sel14_slots _ have l0 := (CRTWindow.leave_metrics Shadow20.MixedWindow.j0 (by decide) (by decide)).2.2.2.2.2 have e7 := (Shadow7.enter_counts Shadow20.MixedWindow.j7).2.2.2.2.2 have r7a : gateSlots (Shadow7.unrouted Shadow20.MixedWindow.j7 0 1) ≤ 5000 := by simpa only [show 5000 * 1 = 5000 from rfl] using (WindowSlots7.route Shadow20.MixedWindow.j7 0 1).2 have r7b : gateSlots (TickCut.Tail.selected Shadow20.MixedWindow.j7 1 14) ≤ 70098 := sel14_slots _ have a6 := (arch15_slots_le Shadow20.MixedWindow.j6 d).2 have l7 := Shadow20.leave150To20Red_counts.2.2.2.2.2 have e20 := (Shadow7.enter_counts Shadow20.MixedWindow.j20).2.2.2.2.2 have r20a : gateSlots (Shadow7.unrouted Shadow20.MixedWindow.j20 0 1) ≤ 5000 := by simpa only [show 5000 * 1 = 5000 from rfl] using (WindowSlots7.route Shadow20.MixedWindow.j20 0 1).2 have r20b : gateSlots (TickCut.Tail.selected Shadow20.MixedWindow.j20 1 14) ≤ 70098 := sel14_slots _ have a8 := (arch20_slots_le Shadow20.MixedWindow.k8 d).2 have l20 := (CRTWindow.leave_metrics Shadow20.MixedWindow.j20 (by decide) (by decide)).2.2.2.2.2 have pk45 := (packW_slots_le d 45 45 (by decide)).2 have pk140 := (packW_slots_le d 150 140 (by decide)).2 have pk330 := (packW_slots_le d 345 330 (by decide)).2 have pk335 := (packW_slots_le d 345 335 (by decide)).2 have pk410 := (packW_slots_le d 420 410 (by decide)).2 have mv := mixed_slot_sum_vals.2 rw [show start Shadow20.MixedWindow.j0 = 45 from rfl, show (45 : Nat) + 15 = 60 from rfl] at l0 rw [show start Shadow20.MixedWindow.j20 = 345 from rfl, show (345 : Nat) + 15 = 360 from rfl] at l20 have hdef : Shadow20.MixedWindow.reverseMixed d = (Shadow20.MixedWindow.reverseL d).flatten := by unfold Shadow20.MixedWindow.reverseMixed; rfl rw [hdef, sum_flatten_slots, Shadow20.MixedWindow.reverseL, sum_map_append7, sum_map5, sum_map7, sum_map6, sum_map6] rw [p45, e0, l0, e7, l7, e20, l20, pk420, p420] refine Nat.le_trans ?_ mv exact Nat.add_le_add (Nat.add_le_add (Nat.add_le_add (Nat.add_le_add (Nat.add_le_add (Nat.add_le_add (Nat.add_le_add exR (Nat.add_le_add pk410 (Nat.add_le_add t420 (Nat.le_refl _)))) hsuR) (Nat.add_le_add_left (Nat.add_le_add r20b (Nat.add_le_add a8 (Nat.add_le_add pk335 (Nat.add_le_add pk330 (Nat.add_le_add r20a (Nat.le_refl _)))))) _)) h20R) (Nat.add_le_add_left (Nat.add_le_add r7b (Nat.add_le_add a6 (Nat.add_le_add pk140 (Nat.add_le_add r7a (Nat.le_refl _))))) _)) hprR) (Nat.add_le_add_left (Nat.add_le_add r0b (Nat.add_le_add pk45 (Nat.add_le_add r0a (Nat.le_refl _)))) _) private theorem mixed_slots (d : Bool) : gateSlots (Shadow20.MixedWindow.forwardMixed d) ≤ 2710000 ∧ gateSlots (Shadow20.MixedWindow.reverseMixed d) ≤ 2610000 := ⟨mixed_slots_F d, mixed_slots_R d⟩ private theorem casts {P : Program} {n : Nat} (h : gateSlots P ≤ n) : slots.measure P ≤ n := h private theorem groupCap (d : Bool) (n : Nat) (hn : 22*(if d then 5322 else 6122)+(if d then 0 else 0)=n+(if d then 14280 else 11760)) : slots.measure (WindowFieldCosts.group84 d)=slots.measure (WindowFieldCosts.group d 1 84)+n := by have h := WindowFieldCosts.group_slots d omega private theorem div : slots.measure WindowCallerCosts.divide ≤ slots.measure Stair44Outer.divide+2710000+2611197+102804+7900 := kernels 2710000 2611197 102804 (walk slots true 4 2710000 2611197 409 rfl (casts ((Shadow20.MixedWindow.mixedCut_slots_le true).1.trans (mixed_slots true).1)) (casts ((TickCut.Mixed.slots_le true).trans (Nat.add_le_add_right ((Shadow20.MixedWindow.mixedCut_slots_le true).2.trans (mixed_slots true).2) 1197)))).1 (walk slots false 85 2710000 2611197 490 rfl (casts ((Shadow20.MixedWindow.mixedCut_slots_le false).1.trans (mixed_slots false).1)) (casts ((TickCut.Mixed.slots_le false).trans (Nat.add_le_add_right ((Shadow20.MixedWindow.mixedCut_slots_le false).2.trans (mixed_slots false).2) 1197)))).2 (groupCap true 102804 rfl) private theorem mul (k : Nat) : slots.measure (WindowCallerCosts.multiply k) ≤ slots.measure (Stair44Outer.multiply k)+2710000+2611197+122924+8160 := kernelsM k 2710000 2611197 122924 (walk slots false 84 2710000 2611197 489 rfl (casts ((Shadow20.MixedWindow.mixedCut_slots_le false).1.trans (mixed_slots false).1)) (casts ((TickCut.Mixed.slots_le false).trans (Nat.add_le_add_right ((Shadow20.MixedWindow.mixedCut_slots_le false).2.trans (mixed_slots false).2) 1197)))).1 (walk slots true 4 2710000 2611197 409 rfl (casts ((Shadow20.MixedWindow.mixedCut_slots_le true).1.trans (mixed_slots true).1)) (casts ((TickCut.Mixed.slots_le true).trans (Nat.add_le_add_right ((Shadow20.MixedWindow.mixedCut_slots_le true).2.trans (mixed_slots true).2) 1197)))).2 (groupCap false 122924 rfl) private theorem sum_caps {a b x y : Nat} (hd : a ≤ x+2710000+2611197+102804+7900) (hm : b ≤ y+2710000+2611197+122924+8160) : a+b+7144 ≤ x+y+10891326 := by omega private theorem cap (C : Point) (cx cy : Fp) : slots.measure (WindowCallerCosts.finite C cx cy) ≤ slots.measure (Stair44Outer.finite C cx cy)+10891326 := finite_upper C cx cy 10891326 (sum_caps div (mul _)) theorem slotBound (C : Point) : gateSlots (WindowCallerCosts.program C) ≤ 67241790 := by have h := Stair44Resources.slotBound C cases C with | zero => change gateSlots [] ≤ _; simp [gateSlots] | @some cx cy hc => have f := cap (.some hc) cx cy rw [show slots.measure=gateSlots from rfl] at f simp only [WindowCallerCosts.program,Stair44Outer.program,rename_gateSlots] at h ⊢ omega end ECDSAAdd.Entrant.StairPacket.WindowSlots end section namespace ECDSAAdd.Entrant.StairPacket.WindowPhysical open StairRestSupport StairPhysicalV3 ArchiveFieldScratch StairArchiveRelease StairArchiveGates Baselines open Arithmetic MappedCompressed StairSiteAvoidance StairSiteEasy StairConcreteAssembly open StairArchiveInactive StairArchiveNativeCut StairArchiveTen WindowFieldCosts set_option maxRecDepth 18000 set_option maxHeartbeats 1200000 attribute [local irreducible] wires renameProgram StairArchiveInactive.packet theorem app {p q : Program} : Sound (p++q) ↔ Sound p ∧ Sound q := ⟨fun h => ⟨⟨gp_left h.physical,good_left h.good⟩,⟨gp_right h.physical,good_right h.good⟩⟩, fun h => sound_append h.1 h.2⟩ theorem emitted (op : Stage) : GatePhysical (StairArchiveRelease.program op) := by cases op exacts [ReducedWindowArchives.enter0_counts.1,ReducedWindowArchives.switch0_counts.1,ReducedWindowArchives.leave0_counts.1, ReducedWindowArchives.enter1_counts.1,ReducedWindowArchives.switch1_counts.1,ReducedWindowArchives.leave1_counts.1] theorem hook (j : Nat) (hj : j∈[10,13,16,19,22,25,28,31,35,39,43,47,51,55,59,63,67,70,73,76,79,82]) (op : Stage) : Sound (fieldHook j op) := by have span : j∈List.range' 1 83 := by simp only [List.mem_cons,List.not_mem_nil,or_false] at hj; apply List.mem_range'_1.mpr; omega have chk : (fieldSites j).all (fun q => decide (InDom q))=true := by simp only [List.mem_cons,List.not_mem_nil,or_false] at hj rcases hj with rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl <;> decide +kernel refine ⟨gatePhysical_rename_support _ _ (fun a ha b hb eq => field_inj j span a (sub op ha) b (sub op hb) eq) (emitted op),?_⟩ intro q hq rw [fieldHook,renameProgram_support] at hq obtain ⟨x,hx,rfl⟩ := Finset.mem_image.mp hq have len : (fieldSites j).length=121 := by have hh := (layout_frame j span).2 rwa [←field_layout,List.length_map] at hh have lt : x < (fieldSites j).length := len ▸ (Finset.mem_range.mp (sub op hx)) apply of_decide_eq_true (List.all_eq_true.mp chk _ ?_) simp only [fieldPort,List.getElem?_eq_getElem lt,Option.getD_some,List.getElem_mem] private theorem distributed_ok (d : Bool) (j n : Nat) : Sound (distributed d j n) ↔ ∀ (i : Nat), j ≤ i → i < j+n → Sound (packet d i) := by induction n generalizing j with | zero => change Sound [] ↔ _ exact ⟨fun _ i lo hi => False.elim (by omega),fun _ => ⟨by simp [GatePhysical],fun _ h => by simp [wires] at h⟩⟩ | succ n ih => change Sound (if d then packet d j ++ distributed d (j+1) n else distributed d (j+1) n ++ packet d j) ↔ _ have both : (Sound (packet d j) ∧ Sound (distributed d (j+1) n)) ↔ ∀ (i : Nat), j ≤ i → i < j+(n+1) → Sound (packet d i) := by rw [ih] refine ⟨fun h i l u => ?_,fun h => ⟨h j (by omega) (by omega),?_⟩⟩ · by_cases e : j=i · exact e ▸ h.1 · exact h.2 i (by omega) (by omega) · exact fun i l u => h i (by omega) (by omega) cases d <;> simp only [Bool.false_eq_true,if_false,if_true,app] · exact and_comm.trans both · exact both theorem whole (d : Bool) : ∀ (i : Nat), 1 ≤ i → i < 85 → Sound (packet d i) := by apply (distributed_ok d 1 84).mp rw [←distribute] exact sound_hostedGroup StairOpenWiring.half760 hostSlots_v3 d 0 1 84 (by decide) (by decide) (by decide) (by decide) /-- oddten: the field group's own packets are sound (record footprint, odd packets physical). -/ private theorem ot_opk_sound (d : Bool) (k : Nat) (lo : 1≤k) (hi : k≤84) : Sound (opk d k) := by by_cases big : 84 show Sound [] exact ⟨by simp [GatePhysical],fun _ h => by simp [wires] at h⟩ | succ n ih => have head := ot_opk_sound d j lo (by omega) have tail := ih (j+1) (by omega) (by omega) cases d <;> simp only [PacketSequence.program,Bool.false_eq_true,if_false,if_true] · exact sound_append tail head · exact sound_append head tail private theorem ot_pair (d : Bool) (j : Nat) (pick : j∈[10,13,16,19,22,25,28,31,35,39,43,47,51,55,59,63,67,70,73,76,79,82]) (lo : 1≤j) (hi : j≤83) : Sound (oten j (!d)) := by have here := ot_opk_sound d j lo (by omega) have next := ot_opk_sound d (j+1) (by omega) (by omega) have firstOK : Sound (ofirst j (!d)) := by cases d <;> first | exact here | exact next have lastOK : Sound (osecond j (!d)) := by cases d <;> first | exact here | exact next exact sound_append (hook j pick _) (sound_append firstOK (sound_append (hook j pick _) (sound_append lastOK (hook j pick _)))) theorem group84_ok (d : Bool) : Sound (group84 d) := by have ord {a b : Program} (ha : Sound a) (hb : Sound b) : Sound (ordered d a b) := by cases d <;> first | exact sound_append ha hb | exact sound_append hb ha have c43 := ord (ot_pair d 82 (by decide) (by decide) (by decide)) (ot_ogroup_sound d 84 1 (by decide) (by decide)) have c42 := ord (ot_ogroup_sound d 81 1 (by decide) (by decide)) c43 have c41 := ord (ot_pair d 79 (by decide) (by decide) (by decide)) c42 have c40 := ord (ot_ogroup_sound d 78 1 (by decide) (by decide)) c41 have c39 := ord (ot_pair d 76 (by decide) (by decide) (by decide)) c40 have c38 := ord (ot_ogroup_sound d 75 1 (by decide) (by decide)) c39 have c37 := ord (ot_pair d 73 (by decide) (by decide) (by decide)) c38 have c36 := ord (ot_ogroup_sound d 72 1 (by decide) (by decide)) c37 have c35 := ord (ot_pair d 70 (by decide) (by decide) (by decide)) c36 have c34 := ord (ot_ogroup_sound d 69 1 (by decide) (by decide)) c35 have c33 := ord (ot_pair d 67 (by decide) (by decide) (by decide)) c34 have c32 := ord (ot_ogroup_sound d 65 2 (by decide) (by decide)) c33 have c31 := ord (ot_pair d 63 (by decide) (by decide) (by decide)) c32 have c30 := ord (ot_ogroup_sound d 61 2 (by decide) (by decide)) c31 have c29 := ord (ot_pair d 59 (by decide) (by decide) (by decide)) c30 have c28 := ord (ot_ogroup_sound d 57 2 (by decide) (by decide)) c29 have c27 := ord (ot_pair d 55 (by decide) (by decide) (by decide)) c28 have c26 := ord (ot_ogroup_sound d 53 2 (by decide) (by decide)) c27 have c25 := ord (ot_pair d 51 (by decide) (by decide) (by decide)) c26 have c24 := ord (ot_ogroup_sound d 49 2 (by decide) (by decide)) c25 have c23 := ord (ot_pair d 47 (by decide) (by decide) (by decide)) c24 have c22 := ord (ot_ogroup_sound d 45 2 (by decide) (by decide)) c23 have c21 := ord (ot_pair d 43 (by decide) (by decide) (by decide)) c22 have c20 := ord (ot_ogroup_sound d 41 2 (by decide) (by decide)) c21 have c19 := ord (ot_pair d 39 (by decide) (by decide) (by decide)) c20 have c18 := ord (ot_ogroup_sound d 37 2 (by decide) (by decide)) c19 have c17 := ord (ot_pair d 35 (by decide) (by decide) (by decide)) c18 have c16 := ord (ot_ogroup_sound d 33 2 (by decide) (by decide)) c17 have c15 := ord (ot_pair d 31 (by decide) (by decide) (by decide)) c16 have c14 := ord (ot_ogroup_sound d 30 1 (by decide) (by decide)) c15 have c13 := ord (ot_pair d 28 (by decide) (by decide) (by decide)) c14 have c12 := ord (ot_ogroup_sound d 27 1 (by decide) (by decide)) c13 have c11 := ord (ot_pair d 25 (by decide) (by decide) (by decide)) c12 have c10 := ord (ot_ogroup_sound d 24 1 (by decide) (by decide)) c11 have c9 := ord (ot_pair d 22 (by decide) (by decide) (by decide)) c10 have c8 := ord (ot_ogroup_sound d 21 1 (by decide) (by decide)) c9 have c7 := ord (ot_pair d 19 (by decide) (by decide) (by decide)) c8 have c6 := ord (ot_ogroup_sound d 18 1 (by decide) (by decide)) c7 have c5 := ord (ot_pair d 16 (by decide) (by decide) (by decide)) c6 have c4 := ord (ot_ogroup_sound d 15 1 (by decide) (by decide)) c5 have c3 := ord (ot_pair d 13 (by decide) (by decide) (by decide)) c4 have c2 := ord (ot_ogroup_sound d 12 1 (by decide) (by decide)) c3 have c1 := ord (ot_pair d 10 (by decide) (by decide) (by decide)) c2 exact ord (ot_ogroup_sound d 1 9 (by decide) (by decide)) c1 end ECDSAAdd.Entrant.StairPacket.WindowPhysical end section namespace ECDSAAdd.Entrant.StairPacket.WindowSites open Arithmetic MappedCompressed StairSiteAvoidance StairSiteEasy StairConcreteAssembly open StairArchiveInactive StairArchiveNativeCut StairArchiveTen WindowFieldCosts set_option maxRecDepth 18000 set_option maxHeartbeats 1200000 attribute [local irreducible] wires renameProgram StairArchiveInactive.packet private theorem distributed_ok (d : Bool) (j n : Nat) : PieceOK reserved TP (distributed d j n) ↔ ∀ (i : Nat), j ≤ i → i < j+n → PieceOK reserved TP (packet d i) := by induction n generalizing j with | zero => change PieceOK _ _ [] ↔ _ exact ⟨fun _ i lo hi => False.elim (by omega),fun _ => pieceOK_nil _ _⟩ | succ n ih => change PieceOK _ _ (if d then packet d j ++ distributed d (j+1) n else distributed d (j+1) n ++ packet d j) ↔ _ have both : (PieceOK reserved TP (packet d j) ∧ PieceOK reserved TP (distributed d (j+1) n)) ↔ ∀ (i : Nat), j ≤ i → i < j+(n+1) → PieceOK reserved TP (packet d i) := by rw [ih] refine ⟨fun h i l u => ?_,fun h => ⟨h j (by omega) (by omega),?_⟩⟩ · by_cases e : j=i · exact e ▸ h.1 · exact h.2 i (by omega) (by omega) · exact fun i l u => h i (by omega) (by omega) cases d <;> simp only [Bool.false_eq_true,if_false,if_true,app] · exact and_comm.trans both · exact both theorem whole (d : Bool) : ∀ (i : Nat), 1 ≤ i → i < 85 → PieceOK reserved TP (packet d i) := by apply (distributed_ok d 1 84).mp rw [←distribute] exact Stair44Groups.hostedGroup44 d 0 1 84 (by decide) theorem ordinary (d : Bool) (j n : Nat) (lo : 1≤j) (hi : j+n≤85) : PieceOK reserved TP (group d j n) := by rw [group,distribute,distributed_ok] exact fun i l u => whole d i (by omega) (by omega) theorem pair (d : Bool) (j : Nat) (lo : 1≤j) (hi : j≤83) : PieceOK reserved TP (ten j (!d)) := by have jmem : j∈List.range' 1 83 := List.mem_range'_1.mpr ⟨lo,by omega⟩ have here := whole d j lo (by omega) have next := whole d (j+1) (by omega) (by omega) have firstOK : PieceOK reserved TP (first j (!d)) := by cases d <;> first | exact here | exact next have lastOK : PieceOK reserved TP (second j (!d)) := by cases d <;> first | exact here | exact next exact (hook j jmem _).append (firstOK.append ((hook j jmem _).append (lastOK.append (hook j jmem _)))) -- oddten:begin SITES /-- oddten: the field group's own packets avoid the reserved holes (their wires are record wires). -/ private theorem ot_ogroup_piece (d : Bool) (j n : Nat) (lo : 1≤j) (hi : j+n≤85) : PieceOK reserved TP (ogroup d j n) := by have hrec := ordinary d j n lo hi exact ⟨fun x hx => hrec.1 x (WindowFieldCosts.ot_ogroup_sub d j n hx), fun x hx => hrec.2 x (WindowFieldCosts.ot_ogroup_sub d j n hx)⟩ private theorem ot_oten_piece (d : Bool) (j : Nat) (lo : 1≤j) (hi : j≤83) : PieceOK reserved TP (oten j (!d)) := by have hrec := pair d j lo hi exact ⟨fun x hx => hrec.1 x (WindowFieldCosts.ot_oten_sub j (!d) hx), fun x hx => hrec.2 x (WindowFieldCosts.ot_oten_sub j (!d) hx)⟩ theorem group84_ok (d : Bool) : PieceOK reserved TP (group84 d) := by have ord {a b : Program} (ha : PieceOK reserved TP a) (hb : PieceOK reserved TP b) : PieceOK reserved TP (ordered d a b) := by cases d <;> first | exact ha.append hb | exact hb.append ha have c43 := ord (ot_oten_piece d 82 (by decide) (by decide)) (ot_ogroup_piece d 84 1 (by decide) (by decide)) have c42 := ord (ot_ogroup_piece d 81 1 (by decide) (by decide)) c43 have c41 := ord (ot_oten_piece d 79 (by decide) (by decide)) c42 have c40 := ord (ot_ogroup_piece d 78 1 (by decide) (by decide)) c41 have c39 := ord (ot_oten_piece d 76 (by decide) (by decide)) c40 have c38 := ord (ot_ogroup_piece d 75 1 (by decide) (by decide)) c39 have c37 := ord (ot_oten_piece d 73 (by decide) (by decide)) c38 have c36 := ord (ot_ogroup_piece d 72 1 (by decide) (by decide)) c37 have c35 := ord (ot_oten_piece d 70 (by decide) (by decide)) c36 have c34 := ord (ot_ogroup_piece d 69 1 (by decide) (by decide)) c35 have c33 := ord (ot_oten_piece d 67 (by decide) (by decide)) c34 have c32 := ord (ot_ogroup_piece d 65 2 (by decide) (by decide)) c33 have c31 := ord (ot_oten_piece d 63 (by decide) (by decide)) c32 have c30 := ord (ot_ogroup_piece d 61 2 (by decide) (by decide)) c31 have c29 := ord (ot_oten_piece d 59 (by decide) (by decide)) c30 have c28 := ord (ot_ogroup_piece d 57 2 (by decide) (by decide)) c29 have c27 := ord (ot_oten_piece d 55 (by decide) (by decide)) c28 have c26 := ord (ot_ogroup_piece d 53 2 (by decide) (by decide)) c27 have c25 := ord (ot_oten_piece d 51 (by decide) (by decide)) c26 have c24 := ord (ot_ogroup_piece d 49 2 (by decide) (by decide)) c25 have c23 := ord (ot_oten_piece d 47 (by decide) (by decide)) c24 have c22 := ord (ot_ogroup_piece d 45 2 (by decide) (by decide)) c23 have c21 := ord (ot_oten_piece d 43 (by decide) (by decide)) c22 have c20 := ord (ot_ogroup_piece d 41 2 (by decide) (by decide)) c21 have c19 := ord (ot_oten_piece d 39 (by decide) (by decide)) c20 have c18 := ord (ot_ogroup_piece d 37 2 (by decide) (by decide)) c19 have c17 := ord (ot_oten_piece d 35 (by decide) (by decide)) c18 have c16 := ord (ot_ogroup_piece d 33 2 (by decide) (by decide)) c17 have c15 := ord (ot_oten_piece d 31 (by decide) (by decide)) c16 have c14 := ord (ot_ogroup_piece d 30 1 (by decide) (by decide)) c15 have c13 := ord (ot_oten_piece d 28 (by decide) (by decide)) c14 have c12 := ord (ot_ogroup_piece d 27 1 (by decide) (by decide)) c13 have c11 := ord (ot_oten_piece d 25 (by decide) (by decide)) c12 have c10 := ord (ot_ogroup_piece d 24 1 (by decide) (by decide)) c11 have c9 := ord (ot_oten_piece d 22 (by decide) (by decide)) c10 have c8 := ord (ot_ogroup_piece d 21 1 (by decide) (by decide)) c9 have c7 := ord (ot_oten_piece d 19 (by decide) (by decide)) c8 have c6 := ord (ot_ogroup_piece d 18 1 (by decide) (by decide)) c7 have c5 := ord (ot_oten_piece d 16 (by decide) (by decide)) c6 have c4 := ord (ot_ogroup_piece d 15 1 (by decide) (by decide)) c5 have c3 := ord (ot_oten_piece d 13 (by decide) (by decide)) c4 have c2 := ord (ot_ogroup_piece d 12 1 (by decide) (by decide)) c3 have c1 := ord (ot_oten_piece d 10 (by decide) (by decide)) c2 exact ord (ot_ogroup_piece d 1 9 (by decide) (by decide)) c1 end ECDSAAdd.Entrant.StairPacket.WindowSites end section namespace ECDSAAdd.Entrant.StairPacket.WindowPhysical open Arithmetic MappedCompressed Baselines StairPhysicalV3 StairRestSupport StairConcreteAssembly variable {p : StairSchedule.StairPrimitives} set_option maxRecDepth 14000 set_option maxHeartbeats 1200000 theorem sound_entryTailPrefix (H : LoanHyp) (P : PrimitiveSlots p) (hs : HostSlots hostPlan) : Sound (WindowCallerCosts.entryTailPrefix p) := by have g0 := group84_ok true have oddSound (d f c : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (hfc : f + c ≤ 102) (ho : Sound (StairHostsSchedule.hostedGroup hostPlan true d f c)) : Sound (OddFullPass.P1LifeLoan.hostedGroup hostPlan true d f c) := ⟨OddFullPass.P1LifeLoan.hostedGroup_physical hostPlan true d f c hfc, good_of_subset (OddFullPass.P1LifeLoan.hostedGroup_wires_sub hostPlan true d f c hd h42) ho.good⟩ have g14 := oddSound 13 85 5 (by decide) (by decide) (by decide) (sound_hostedGroup H hs true 13 85 5 (by decide) (by omega) (by omega) (by omega)) have g23 := oddSound 22 90 3 (by decide) (by decide) (by decide) (sound_hostedGroup H hs true 22 90 3 (by decide) (by omega) (by omega) (by omega)) have g31 := oddSound 30 93 3 (by decide) (by decide) (by decide) (sound_hostedGroup H hs true 30 93 3 (by decide) (by omega) (by omega) (by omega)) have g37 := oddSound 36 96 2 (by decide) (by decide) (by decide) (sound_hostedGroup H hs true 36 96 2 (by decide) (by omega) (by omega) (by omega)) have g42 := oddSound 41 98 2 (by decide) (by decide) (by decide) (sound_hostedGroup H hs true 41 98 2 (by decide) (by omega) (by omega) (by omega)) have s1 := sound_forwardSegment P 87 62 425 450 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega) have s2 := sound_forwardSegment P 62 47 450 465 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega) have s3 := sound_forwardSegment P 47 32 465 480 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega) have s4 := sound_forwardSegment P 32 22 480 490 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega) have s5 := sound_forwardSegment P 22 12 490 500 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega) have sl := sound_forwardLast P unfold WindowCallerCosts.entryTailPrefix exact sound_append (sound_append (sound_append (sound_append (sound_append (sound_append (sound_append (sound_append (sound_append (sound_append (sound_append g0 s1) g14) s2) g23) s3) g31) s4) g37) s5) g42) sl theorem sound_exitHeadSuffix (H : LoanHyp) (P : PrimitiveSlots p) (hs : HostSlots hostPlan) : Sound (WindowCallerCosts.exitHeadSuffix p) := by have g0 := group84_ok false have oddSound (d f c : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (hfc : f + c ≤ 102) (ho : Sound (StairHostsSchedule.hostedGroup hostPlan false d f c)) : Sound (OddFullPass.P1LifeLoan.hostedGroup hostPlan false d f c) := ⟨OddFullPass.P1LifeLoan.hostedGroup_physical hostPlan false d f c hfc, good_of_subset (OddFullPass.P1LifeLoan.hostedGroup_wires_sub hostPlan false d f c hd h42) ho.good⟩ let Pc := StairPhysicalV3.primitiveSlots_v3 StairPhysicalV3.primitiveChecks have cut0 := PackCutOddExit.cutRow0_sound (oddSound 13 85 5 (by decide) (by decide) (by decide) (sound_hostedGroup H hs false 13 85 5 (by decide) (by omega) (by omega) (by omega))) (sound_reverseSegment Pc 87 62 425 450 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega)) have cut1 := PackCutOddExit.cutRow1_sound (oddSound 22 90 3 (by decide) (by decide) (by decide) (sound_hostedGroup H hs false 22 90 3 (by decide) (by omega) (by omega) (by omega))) (sound_reverseSegment Pc 62 47 450 465 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega)) have cut2 := PackCutOddExit.cutRow2_sound (oddSound 30 93 3 (by decide) (by decide) (by decide) (sound_hostedGroup H hs false 30 93 3 (by decide) (by omega) (by omega) (by omega))) (sound_reverseSegment Pc 47 32 465 480 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega)) have cut3 := PackCutOddExit.cutRow3_sound (oddSound 36 96 2 (by decide) (by decide) (by decide) (sound_hostedGroup H hs false 36 96 2 (by decide) (by omega) (by omega) (by omega))) (sound_reverseSegment Pc 32 22 480 490 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega)) have cut4 := PackCutOddExit.cutRow4_sound (oddSound 41 98 2 (by decide) (by decide) (by decide) (sound_hostedGroup H hs false 41 98 2 (by decide) (by omega) (by omega) (by omega))) (sound_reverseSegment Pc 22 12 490 500 (by decide) (by decide) (by decide) (by decide) (by decide) (by omega) (by omega)) have rl := sound_reverseLast P unfold WindowCallerCosts.exitHeadSuffix exact sound_append (sound_append (sound_append (sound_append (sound_append (sound_append rl cut4) cut3) cut2) cut1) cut0) g0 private theorem sound_firstPacketOdd (divide : Bool) : Sound (JointOdd1588.placedFirstPacketOdd WindowCallerCosts.oddFirstHalf divide) := by refine ⟨JointOdd1588.placedFirstPacketOdd_physical WindowCallerCosts.oddFirstHalf divide (WindowCallerCosts.oddFirstHalf_physical divide), ?_⟩ intro q hq have hsup := StairWireCheck.allSites_sound StairWireCheck.fpSup _ (JointOdd1588.placedFirstPacketOdd_passSup WindowCallerCosts.oddFirstHalf divide (WindowCallerCosts.oddFirstHalf_support divide)) q hq rcases WindowCallerCosts.fpSup_bounds q hsup with h1 | h2 · exact Or.inl h1 · exact Or.inr (by rw [h2]; decide) theorem sound_entryFieldHosted (H : LoanHyp) (P : PrimitiveSlots p) (B : BoundarySlots) (hs : HostSlots hostPlan) : Sound (WindowCallerCosts.entryFieldHosted p) := by have first := sound_rebindMany _ _ exclusiveRoles_indom (hs.firstPacket true) (sound_firstPacketOdd true) have pre : Sound (WindowCallerCosts.entryLowPrefix p) := by unfold WindowCallerCosts.entryLowPrefix exact sound_append (sound_append (sound_append first sound_clearProgram) (sound_borrow (sound_entryTailPrefix H P hs))) sound_unprefix have tailStd : Sound (StairHostsSchedule.entryTailSuffix hostPlan) := by have g := sound_hostedGroup H hs true 43 100 2 (by decide) (by omega) (by omega) (by omega) unfold StairHostsSchedule.entryTailSuffix exact sound_append (sound_append (sound_append g (sound_sig 511 (by omega) B.divEndpoint)) sound_copyN) B.canon have tail : Sound (OddFullPass.P1LifeLoan.entryTailSuffixOdd hostPlan) := by refine ⟨?_, good_of_subset (OddFullPass.P1LifeLoan.entryTailSuffixOdd_wires_sub hostPlan) tailStd.good⟩ unfold OddFullPass.P1LifeLoan.entryTailSuffixOdd simp only [gatePhysical_append] exact ⟨⟨⟨OddFullPass.P1LifeLoan.hostedGroup_physical hostPlan true 43 100 2 (by decide), gatePhysical_rename _ (OB5.sig_injective 511 (by decide)) _ OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan_physical⟩, sound_copyN.physical⟩, OddFullPass.HalfConvertOdd.canon760OddLoan_physical⟩ have suf : Sound (OddFullPass.P1LifeLoan.entryLowSuffixOdd hostPlan) := by unfold OddFullPass.P1LifeLoan.entryLowSuffixOdd exact sound_append (sound_append sound_clearProgram (sound_borrow tail)) sound_unprefix unfold WindowCallerCosts.entryFieldHosted exact sound_append (sound_append (sound_append (sound_append (sound_append (sound_fieldRename pre) sound_paritySetup) sound_hostedX) (sound_fieldRename suf)) sound_hostedX) sound_paritySetup theorem sound_exitFieldHosted (H : LoanHyp) (P : PrimitiveSlots p) (B : BoundarySlots) (hs : HostSlots hostPlan) : Sound (WindowCallerCosts.exitFieldHosted p) := by have headStd : Sound (StairHostsSchedule.exitHeadPrefix hostPlan) := by have g := sound_hostedGroup H hs false 43 100 2 (by decide) (by omega) (by omega) (by omega) unfold StairHostsSchedule.exitHeadPrefix StairHostsSchedule.hostedEndpoint StairSchedule.placedEndPacket exact sound_append (sound_append (sound_append B.center sound_copyN) (sound_sig 511 (by omega) B.multEndpoint)) g have head : Sound (OddFullPass.P1LifeLoan.exitHeadPrefixOdd hostPlan) := by refine ⟨?_, good_of_subset (OddFullPass.P1LifeLoan.exitHeadPrefixOdd_wires_sub hostPlan) headStd.good⟩ unfold OddFullPass.P1LifeLoan.exitHeadPrefixOdd simp only [gatePhysical_append] exact ⟨⟨⟨OddFullPass.HalfConvertOdd.center760OddLoan_physical, sound_copyN.physical⟩, gatePhysical_rename _ (OB5.sig_injective 511 (by decide)) _ OddFullPass.InverseTailCOdd.endPacket760OddLoan44_physical⟩, OddFullPass.P1LifeLoan.hostedGroup_physical hostPlan false 43 100 2 (by decide)⟩ have pre : Sound (OddFullPass.P1LifeLoan.exitLowPrefixOdd hostPlan) := by unfold OddFullPass.P1LifeLoan.exitLowPrefixOdd exact sound_append (sound_append sound_clearProgram (sound_borrow head)) sound_unprefix have last := sound_rebindMany _ _ exclusiveRoles_indom (hs.firstPacket false) (sound_firstPacketOdd false) have suf : Sound (WindowCallerCosts.exitLowSuffix p) := by unfold WindowCallerCosts.exitLowSuffix exact sound_append (sound_append (sound_append sound_clearProgram (sound_borrow (sound_exitHeadSuffix H P hs))) sound_unprefix) last unfold WindowCallerCosts.exitFieldHosted exact sound_append (sound_append (sound_append (sound_append (sound_append sound_paritySetup sound_hostedX) (sound_fieldRename pre)) sound_paritySetup) sound_hostedX) (sound_fieldRename suf) end ECDSAAdd.Entrant.StairPacket.WindowPhysical end section namespace ECDSAAdd.Entrant.StairPacket.WindowSites open Arithmetic MappedCompressed StairSiteAvoidance StairSiteEasy StairConcreteAssembly open StairRestSupport set_option maxRecDepth 14000 set_option maxHeartbeats 1000000 attribute [local irreducible] wires renameProgram Shadow20.MixedWindow.forwardMixedCut TickCut.Mixed.reverse Rolling1588TickGap.forward Rolling1588.reverse Stair44WalkMap.rest Stair44WalkMap.first abbrev GoodWindow (p : Program) := ∀ q∈wires p, Stair44PhaseSites.valid (Stair44WalkMap.rest q)=true theorem native {p : Program} (h : GoodWindow p) : PieceOK reserved (fun x => PP (Stair44WalkMap.rest x)) p := by apply weaken apply Stair44OuterSites.fits intro x hx change Stair44OuterSites.fit (StairOuterPlacement.phasePlace (Stair44WalkMap.rest x))=true rw [StairPlaceFast.phasePlace_eqB] exact h x hx theorem walkF (d : Bool) (tail : Nat) (bound : 16+(405+tail)≤506) (new : GoodWindow (Shadow20.MixedWindow.forwardMixedCut d)) : PieceOK reserved PP (WindowWalkCosts.forward d tail) := by have old := weaken (Stair44PhaseSites.forward d (405+tail) bound) have a := StairRestSupport.forward_append d 29 16 (376+tail) have b := StairRestSupport.forward_append d 376 45 tail change Rolling1588TickGap.forward d 16 (29+(376+tail)) = Rolling1588TickGap.forward d 16 29 ++ Rolling1588TickGap.forward d 45 (376+tail) at a rw [b] at a have num : 405+tail=29+(376+tail) := by omega simp only [Stair44WalkRun.forward,num,a,app,ren] at old simp only [WindowWalkCosts.forward,app,ren] exact ⟨old.1,⟨old.2.1,native new⟩,old.2.2.2⟩ theorem walkR (d : Bool) (tail : Nat) (bound : 16+(405+tail)≤506) (new : GoodWindow (TickCut.Mixed.reverse d)) : PieceOK reserved PP (WindowWalkCosts.backward d tail) := by have old := weaken (Stair44PhaseSites.backward d (405+tail) bound) have a := StairRestSupport.reverse_append d 29 16 (376+tail) have b := StairRestSupport.reverse_append d 376 45 tail change Rolling1588.reverse d 16 (29+(376+tail)) = Rolling1588.reverse d 45 (376+tail) ++ Rolling1588.reverse d 16 29 at a rw [b] at a have num : 405+tail=29+(376+tail) := by omega simp only [Stair44WalkRun.backward,num,a,app,ren] at old simp only [WindowWalkCosts.backward,app,ren] exact ⟨⟨⟨old.1.1.1,native new⟩,old.1.2⟩,old.2⟩ end ECDSAAdd.Entrant.StairPacket.WindowSites end section namespace ECDSAAdd.Entrant.StairPacket.WindowPhysical open Arithmetic MappedCompressed Secp256k1 Baselines StairPhysicalV3 StairRestSupport open Stair44Outer StairConcreteAssembly Stair44WalkMap set_option maxHeartbeats 1400000 set_option maxRecDepth 20000 attribute [local irreducible] wires GatePhysical theorem parts {P Q : Program} (h : Sound (P ++ Q)) : Sound P ∧ Sound Q := ⟨⟨gp_left h.physical,good_left h.good⟩,⟨gp_right h.physical,good_right h.good⟩⟩ private theorem firstDom (q : Wire) (h : InDom q) : InDom (first q) := by unfold first shared simp only [Equiv.trans_apply] exact indom_swap _ _ (by decide) (by decide) _ (indom_swap _ _ (by decide) (by decide) _ (indom_swap _ _ (by decide) (by decide) _ h)) private theorem restDom (q : Wire) (h : InDom q) : InDom (rest q) := by unfold rest shared simp only [Equiv.trans_apply] exact indom_swap _ _ (by decide) (by decide) _ (indom_swap _ _ (by decide) (by decide) _ (indom_swap _ _ (by decide) (by decide) _ h)) theorem dom {p : Program} (cover : PartialSites.Covered p) : Good p := by intro q hq have h := cover q hq simp only [PartialSites.domain,Bool.or_eq_true,Bool.and_eq_true,decide_eq_true_eq] at h unfold InDom InDomN left constructor all_goals omega private theorem fw (d : Bool) (tail n : Nat) (hn : 15+(405+tail)=n) (ref_ : Sound (Rolling1588TickGap.forward d 1 n)) (p : GatePhysical (Shadow20.MixedWindow.forwardMixedCut d)) : Sound (WindowWalkCosts.forward d tail) := by subst n rw [forward_append d 15 1 (405+tail)] at ref_ obtain ⟨early,late⟩ := parts ref_ change Sound (Rolling1588TickGap.forward d 16 (405+tail)) at late rw [show 405+tail=29+(376+tail) by omega,forward_append d 29 16 (376+tail)] at late obtain ⟨pre,ms⟩ := parts late change Sound (Rolling1588TickGap.forward d 45 (376+tail)) at ms rw [forward_append d 376 45 tail] at ms have patch : Sound (Shadow20.MixedWindow.forwardMixedCut d) := ⟨p,dom (PartialSites.forwardMixed_domain d)⟩ have last : Sound (Rolling1588TickGap.forward d 421 tail) := (parts ms).2 exact sound_append (sound_rename _ first.injective firstDom early) (sound_rename _ rest.injective restDom (sound_append (sound_append pre patch) last)) private theorem bw (d : Bool) (tail n : Nat) (hn : 15+(405+tail)=n) (ref_ : Sound (Rolling1588.reverse d 1 n)) (p : GatePhysical (TickCut.Mixed.reverse d)) : Sound (WindowWalkCosts.backward d tail) := by subst n rw [reverse_append d 15 1 (405+tail)] at ref_ obtain ⟨late,early⟩ := parts ref_ change Sound (Rolling1588.reverse d 16 (405+tail)) at late rw [show 405+tail=29+(376+tail) by omega,reverse_append d 29 16 (376+tail)] at late obtain ⟨ms,pre⟩ := parts late change Sound (Rolling1588.reverse d 45 (376+tail)) at ms rw [reverse_append d 376 45 tail] at ms have patch : Sound (TickCut.Mixed.reverse d) := ⟨p,dom (PartialSites.reverseMixed_domain d)⟩ have last : Sound (Rolling1588.reverse d 421 tail) := (parts ms).1 exact sound_append (sound_rename _ rest.injective restDom (sound_append (sound_append last patch) pre)) (sound_rename _ first.injective firstDom early) theorem phase {P : Program} (h : Sound P) : GatePhysical (phasePlace P) := rest_physical _ (sound_phaseHost h) variable (ff : ∀d,GatePhysical (Shadow20.MixedWindow.forwardMixedCut d)) (rr : ∀d,GatePhysical (TickCut.Mixed.reverse d)) include ff rr in theorem dividePhysical : GatePhysical WindowCallerCosts.divide := by have eq : InverseFive23.lastPhase15 false = reverseEnd ++ Rolling1588.reverse false 1 505 ++ FrontierEntry1591NativeH.inverse base := by simp only [InverseFive23.lastPhase15,InverseFive23.stackReverse15,InverseFive23.reverseTail15, reverseEnd,List.append_assoc] have h := sound_lastPhase15 rw [eq] at h have ⟨a,native⟩ := parts h have ⟨tail,walk⟩ := parts a let P := primitiveSlots_v3 primitiveChecks have field := PackCutSub.sound_sub WindowCallerCosts.field_sublist (sound_entryFieldHosted StairOpenWiring.half760 P boundarySlots_current hostSlots_v3) simp only [WindowCallerCosts.divide,gatePhysical_append] exact ⟨⟨⟨⟨⟨phase (fw true 4 424 rfl sound_forward424 (ff _)),phase P.firstPack⟩,rest_physical _ field⟩, phase tail⟩,phase (bw false 85 505 rfl walk (rr _))⟩,phase (sound_rename _ first.injective firstDom native)⟩ include ff rr in theorem multiplyPhysical (k : Nat) : GatePhysical (WindowCallerCosts.multiply k) := by have eq : Rolling1588TickGap.tailPhase false = Rolling1588TickGap.forward false 1 504 ++ forwardEnd := by simp only [Rolling1588TickGap.tailPhase,Rolling1588TickGap.stackForward,Six505.stackForward6, forwardEnd,List.append_assoc] have h := sound_tailPhase rw [eq] at h have ⟨walk,tail⟩ := parts h let P := primitiveSlots_v3 primitiveChecks have field := sound_exitFieldHosted StairOpenWiring.half760 P boundarySlots_current hostSlots_v3 simp only [WindowCallerCosts.multiply,gatePhysical_append] exact ⟨⟨⟨⟨⟨phase (fw false 84 504 rfl walk (ff _)),phase tail⟩,rest_physical _ field⟩,phase P.firstUnpack⟩, phase (bw true 4 424 rfl sound_reverse424 (rr _))⟩, gatePhysical_rename _ Stair44PointMap.duringX.injective _ (phase (sound_x1N k))⟩ include ff rr in theorem genericPhysical (cx cy : Fp) : GatePhysical (WindowCallerCosts.generic cx cy) := by have g := FlagTop2.genericN_physical cx cy simp only [FlagExit.genericN,FlagExit.secondStageN,gatePhysical_append] at g simp only [WindowCallerCosts.generic,gatePhysical_append] exact ⟨⟨⟨⟨⟨gatePhysical_rename _ Stair44PointMap.duringY.injective _ (EntryFuseOdd.entryYAllOdd_physical layout layout_widths layout_nodup (-cy)), gatePhysical_rename _ Stair44PointMap.duringX.injective _ g.1.1.2⟩,dividePhysical ff rr⟩, Stair44Square.physical _⟩,multiplyPhysical ff rr _⟩, gatePhysical_rename _ Stair44PointMap.duringY.injective _ (EntryFuseOdd.exitYAllOdd_physical layout layout_widths layout_nodup cy)⟩ include ff rr in theorem physical (C : Point) : GatePhysical (WindowCallerCosts.program C) := by cases C with | zero => simp [WindowCallerCosts.program,GatePhysical] | @some cx cy hc => let C : Point := .some hc have m := AboveFieldPointDevelop.middle_physical C cx cy simp only [AboveFieldPointDevelop.middle,gatePhysical_append] at m apply gatePhysical_rename _ (Wrapper5.U layout).injective simp only [WindowCallerCosts.finite,gatePhysical_append] refine ⟨⟨gatePhysical_rename _ Stair44PointMap.outer.injective _ ?_,?_⟩, gatePhysical_rename _ Stair44PointMap.outer.injective _ ?_⟩ · simp only [gatePhysical_append] exact ⟨⟨FlagTop.stageNew_physical hc,m.1.1.1.1⟩,m.1.1.1.2⟩ · exact gatePhysical_rename _ (Equiv.swap _ _).injective _ (gatePhysical_rename _ FlagTop.rho_injective _ (genericPhysical ff rr cx cy)) · simp only [gatePhysical_append] exact ⟨⟨m.1.2,m.2⟩,ControlPointEncodingDevelop.borrowOut_physical hc⟩ end ECDSAAdd.Entrant.StairPacket.WindowPhysical end section namespace ECDSAAdd.Entrant.StairPacket.WindowSites open Arithmetic MappedCompressed Secp256k1 Baselines StairSiteAvoidance StairSiteEasy open StairConcreteAssembly Stair44Outer set_option maxRecDepth 18000 set_option maxHeartbeats 3000000 set_option linter.unusedSimpArgs false attribute [local irreducible] wires renameProgram /-- Replacing a child leaves the safety contract on the other children intact. -/ private def SafeChange (f : Wire → Wire) (old new : Program) := PieceOK reserved f old → PieceOK reserved f new theorem same (f : Wire → Wire) (p : Program) : SafeChange f p p := id theorem fresh {f : Wire → Wire} {p q : Program} (h : PieceOK reserved f q) : SafeChange f p q := fun _ => h private theorem appendChange {f : Wire → Wire} {a b x y : Program} (l : SafeChange f a x) (r : SafeChange f b y) : SafeChange f (a++b) (x++y) := fun old => (l (app.mp old).1).append (r (app.mp old).2) private theorem renameChange {f g : Wire → Wire} {a b : Program} (h : SafeChange (fun x => f (g x)) a b) : SafeChange f (renameProgram g a) (renameProgram g b) := fun old => ren.mpr (h (ren.mp old)) theorem tail (p : StairSchedule.StairPrimitives) : SafeChange TP (StairHostsSchedule.entryTailPrefix p hostPlan) (WindowCallerCosts.entryTailPrefix p) := by have subCh (d f c : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) : SafeChange TP (StairHostsSchedule.hostedGroup hostPlan true d f c) (OddFullPass.P1LifeLoan.hostedGroup hostPlan true d f c) := fun h => ⟨fun q hq => h.1 q (OddFullPass.P1LifeLoan.hostedGroup_wires_sub hostPlan true d f c hd h42 hq), fun q hq => h.2 q (OddFullPass.P1LifeLoan.hostedGroup_wires_sub hostPlan true d f c hd h42 hq)⟩ unfold StairHostsSchedule.entryTailPrefix WindowCallerCosts.entryTailPrefix refine appendChange ?_ (same _ _) refine appendChange ?_ (subCh 41 98 2 (by decide) (by decide)) refine appendChange ?_ (same _ _) refine appendChange ?_ (subCh 36 96 2 (by decide) (by decide)) refine appendChange ?_ (same _ _) refine appendChange ?_ (subCh 30 93 3 (by decide) (by decide)) refine appendChange ?_ (same _ _) refine appendChange ?_ (subCh 22 90 3 (by decide) (by decide)) refine appendChange ?_ (same _ _) refine appendChange ?_ (subCh 13 85 5 (by decide) (by decide)) refine appendChange ?_ (same _ _) exact fresh (group84_ok true) theorem head (p : StairSchedule.StairPrimitives) (hp : p = StairConcreteAssembly.checkpointPrimitives) : SafeChange TP (StairHostsSchedule.exitHeadSuffix p hostPlan) (WindowCallerCosts.exitHeadSuffix p) := by subst hp unfold StairHostsSchedule.exitHeadSuffix WindowCallerCosts.exitHeadSuffix refine appendChange ?_ (fresh (group84_ok false)) intro h exact ⟨fun q hq => h.1 q (PackCutOddExit.cutRows_sub hq), fun q hq => h.2 q (PackCutOddExit.cutRows_sub hq)⟩ private theorem entryField : PieceOK reserved KP (WindowCallerCosts.entryFieldHosted checkpointPrimitives) := by have h : PieceOK reserved KP (StairHostsSchedule.entryFieldHosted checkpointPrimitives hostPlan) := Stair44FieldSites.entry apply (show SafeChange KP (StairHostsSchedule.entryFieldHosted checkpointPrimitives hostPlan) (WindowCallerCosts.entryFieldHosted checkpointPrimitives) from ?_) h have fpOk : PieceOK reserved lowPlace (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf true) := weaken (JointOdd1588.hostedFirstPacketOdd_pieceOK WindowCallerCosts.oddFirstHalf StairPhysicalInventory.physicalHoles (fun _ h => h) true (WindowCallerCosts.oddFirstHalf_support true)) have low : SafeChange lowPlace (StairHostsSchedule.entryLowPrefix checkpointPrimitives hostPlan) (WindowCallerCosts.entryLowPrefix checkpointPrimitives) := appendChange (appendChange (appendChange (fresh fpOk) (same _ _)) (renameChange (tail _))) (same _ _) have field : SafeChange KP (StairSchedule.fieldRename (StairHostsSchedule.entryLowPrefix checkpointPrimitives hostPlan)) (StairSchedule.fieldRename (WindowCallerCosts.entryLowPrefix checkpointPrimitives)) := renameChange (renameChange low) have sufLow : SafeChange lowPlace (StairHostsSchedule.entryLowSuffix hostPlan) (OddFullPass.P1LifeLoan.entryLowSuffixOdd hostPlan) := fun ok => ⟨fun q hq => ok.1 q (OddFullPass.P1LifeLoan.entryLowSuffixOdd_wires_sub hostPlan hq), fun q hq => ok.2 q (OddFullPass.P1LifeLoan.entryLowSuffixOdd_wires_sub hostPlan hq)⟩ have sufCh : SafeChange KP (StairSchedule.fieldRename (StairHostsSchedule.entryLowSuffix hostPlan)) (StairSchedule.fieldRename (OddFullPass.P1LifeLoan.entryLowSuffixOdd hostPlan)) := renameChange (renameChange sufLow) exact appendChange (appendChange (appendChange (appendChange (appendChange field (same _ _)) (same _ _)) sufCh) (same _ _)) (same _ _) private theorem exitField : PieceOK reserved KP (WindowCallerCosts.exitFieldHosted checkpointPrimitives) := by have h : PieceOK reserved KP (StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan) := Stair44FieldSites.exit apply (show SafeChange KP (StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan) (WindowCallerCosts.exitFieldHosted checkpointPrimitives) from ?_) h have preLow : SafeChange lowPlace (StairHostsSchedule.exitLowPrefix hostPlan) (OddFullPass.P1LifeLoan.exitLowPrefixOdd hostPlan) := fun ok => ⟨fun q hq => ok.1 q (OddFullPass.P1LifeLoan.exitLowPrefixOdd_wires_sub hostPlan hq), fun q hq => ok.2 q (OddFullPass.P1LifeLoan.exitLowPrefixOdd_wires_sub hostPlan hq)⟩ have preCh : SafeChange KP (StairSchedule.fieldRename (StairHostsSchedule.exitLowPrefix hostPlan)) (StairSchedule.fieldRename (OddFullPass.P1LifeLoan.exitLowPrefixOdd hostPlan)) := renameChange (renameChange preLow) have fpOk : PieceOK reserved lowPlace (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf false) := weaken (JointOdd1588.hostedFirstPacketOdd_pieceOK WindowCallerCosts.oddFirstHalf StairPhysicalInventory.physicalHoles (fun _ h => h) false (WindowCallerCosts.oddFirstHalf_support false)) have low : SafeChange lowPlace (StairHostsSchedule.exitLowSuffix checkpointPrimitives hostPlan) (WindowCallerCosts.exitLowSuffix checkpointPrimitives) := appendChange (appendChange (appendChange (same _ _) (renameChange (head _ rfl))) (same _ _)) (fresh fpOk) exact appendChange (appendChange (appendChange (appendChange (appendChange (same _ _) (same _ _)) preCh) (same _ _)) (same _ _)) (renameChange (renameChange low)) section private theorem pieceOK_sub {holes : List Wire} {f : Wire → Wire} {P Q : Program} (h : ∀ q ∈ wires P, q ∈ wires Q) (hq : PieceOK holes f Q) : PieceOK holes f P := ⟨fun x hx => hq.1 x (h x hx), fun x hx => hq.2 x (h x hx)⟩ private theorem entryFieldCut : PieceOK reserved KP WindowCallerCosts.entryFieldHostedCut := pieceOK_sub (PackCutSub.wires_sub WindowCallerCosts.field_sublist) entryField end theorem phase {P : Program} (v : PieceOK reserved PP P) : PieceOK reserved UG (Stair44Outer.phasePlace P) := ok_kernel (ok_phase v) theorem division (f : GoodWindow (Shadow20.MixedWindow.forwardMixedCut true)) (r : GoodWindow (TickCut.Mixed.reverse false)) : PieceOK reserved UG WindowCallerCosts.divide := (((((phase (walkF true 4 (by decide) f)).append (weaken (ok_kernel (ok_phase Stair44FirstRow.pack)))).append (ok_kernel entryFieldCut)).append (weaken (ok_kernel (ok_phase Stair44PhaseSites.reverseTail)))).append (phase (walkR false 85 (by decide) r))).append (weaken (ok_kernel (ok_phase Stair44PhaseSites.native))) theorem multiplication (k : Nat) (f : GoodWindow (Shadow20.MixedWindow.forwardMixedCut false)) (r : GoodWindow (TickCut.Mixed.reverse true)) : PieceOK reserved UG (WindowCallerCosts.multiply k) := (((((phase (walkF false 84 (by decide) f)).append (weaken (ok_kernel (ok_phase Stair44PhaseSites.forwardTail)))).append (ok_kernel exitField)).append (weaken (ok_kernel (ok_phase Stair44FirstRow.unpack)))).append (phase (walkR true 4 (by decide) r))).append (weaken (Stair44PhaseSites.exitX k)) theorem program_width (C : Point) (f : ∀d, GoodWindow (Shadow20.MixedWindow.forwardMixedCut d)) (r : ∀d,GoodWindow (TickCut.Mixed.reverse d)) : Challenge.qubits (WindowCallerCosts.program C) ≤ 1543 := by apply width cases C with | zero => exact pieceOK_nil _ _ | @some cx cy hc => apply ok_wrapper exact ((weaken (Stair44OuterSites.initial hc)).append (ok_generic ((((((weaken (Stair44OuterSites.entryY (-cy))).append (weaken (Stair44OuterSites.entryX (-cx)))).append (division (f _) (r _))).append (weaken (Stair44Release.squareSites (ReflectionE1.correction cx)))).append (multiplication cx.val (f _) (r _))).append (weaken (Stair44OuterSites.exitY cy))))).append (weaken (Stair44OuterSites.finalPart hc)) end ECDSAAdd.Entrant.StairPacket.WindowSites end section namespace ECDSAAdd.Entrant.StairPacket.WindowCallerCosts open Arithmetic Secp256k1 theorem physical (C : Point) : GatePhysical (program C) := WindowPhysical.physical (fun d => (Shadow20.MixedWindow.mixedCut_physical d).1) (fun d => TickCut.Mixed.physical d) C end ECDSAAdd.Entrant.StairPacket.WindowCallerCosts end section namespace ECDSAAdd.Entrant.StairPacket.WindowCallerCosts open Secp256k1 theorem qubitBound (C : Point) : Challenge.qubits (program C) ≤ 1543 := WindowSites.program_width C PartialSites.forwardMixed_fits PartialSites.reverseMixed_fits end ECDSAAdd.Entrant.StairPacket.WindowCallerCosts end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem wl35 : (slots 35).map (fun q => OB5.sig 511 (StairArchiveInactive.host.symm q)) = cellsW 35 := by decide +kernel theorem wl39 : (slots 39).map (fun q => OB5.sig 511 (StairArchiveInactive.host.symm q)) = cellsW 39 := by decide +kernel theorem wl47 : (slots 47).map (fun q => OB5.sig 511 (StairArchiveInactive.host.symm q)) = cellsW 47 := by decide +kernel theorem wl51 : (slots 51).map (fun q => OB5.sig 511 (StairArchiveInactive.host.symm q)) = cellsW 51 := by decide +kernel theorem wl59 : (slots 59).map (fun q => OB5.sig 511 (StairArchiveInactive.host.symm q)) = cellsW 59 := by decide +kernel theorem wl63 : (slots 63).map (fun q => OB5.sig 511 (StairArchiveInactive.host.symm q)) = cellsW 63 := by decide +kernel theorem h35_1 : part 35 1 7 = true := by rw [part_eq_W 35 1 7 _ wl35] exact partW_cells 35 1 7 (by decide) (by decide) (by decide) theorem h35_8 : part 35 8 7 = true := by rw [part_eq_W 35 8 7 _ wl35] exact partW_cells 35 8 7 (by decide) (by decide) (by decide) theorem h35_15 : part 35 15 7 = true := by rw [part_eq_W 35 15 7 _ wl35] exact partW_cells 35 15 7 (by decide) (by decide) (by decide) theorem h35_22 : part 35 22 7 = true := by rw [part_eq_W 35 22 7 _ wl35] exact partW_cells 35 22 7 (by decide) (by decide) (by decide) theorem h35_29 : part 35 29 7 = true := by rw [part_eq_W 35 29 7 _ wl35] exact partW_cells 35 29 7 (by decide) (by decide) (by decide) theorem h35_36 : part 35 36 7 = true := by rw [part_eq_W 35 36 7 _ wl35] exact partW_cells 35 36 7 (by decide) (by decide) (by decide) theorem h35_43 : part 35 43 7 = true := by rw [part_eq_W 35 43 7 _ wl35] exact partW_cells 35 43 7 (by decide) (by decide) (by decide) theorem h35_50 : part 35 50 7 = true := by rw [part_eq_W 35 50 7 _ wl35] exact partW_cells 35 50 7 (by decide) (by decide) (by decide) theorem h35_57 : part 35 57 7 = true := by rw [part_eq_W 35 57 7 _ wl35] exact partW_cells 35 57 7 (by decide) (by decide) (by decide) theorem h35_64 : part 35 64 7 = true := by rw [part_eq_W 35 64 7 _ wl35] exact partW_cells 35 64 7 (by decide) (by decide) (by decide) theorem h35_71 : part 35 71 7 = true := by rw [part_eq_W 35 71 7 _ wl35] exact partW_cells 35 71 7 (by decide) (by decide) (by decide) theorem h35_78 : part 35 78 7 = true := by rw [part_eq_W 35 78 7 _ wl35] exact partW_cells 35 78 7 (by decide) (by decide) (by decide) theorem h39_1 : part 39 1 7 = true := by rw [part_eq_W 39 1 7 _ wl39] exact partW_cells 39 1 7 (by decide) (by decide) (by decide) theorem h39_8 : part 39 8 7 = true := by rw [part_eq_W 39 8 7 _ wl39] exact partW_cells 39 8 7 (by decide) (by decide) (by decide) theorem h39_15 : part 39 15 7 = true := by rw [part_eq_W 39 15 7 _ wl39] exact partW_cells 39 15 7 (by decide) (by decide) (by decide) theorem h39_22 : part 39 22 7 = true := by rw [part_eq_W 39 22 7 _ wl39] exact partW_cells 39 22 7 (by decide) (by decide) (by decide) theorem h39_29 : part 39 29 7 = true := by rw [part_eq_W 39 29 7 _ wl39] exact partW_cells 39 29 7 (by decide) (by decide) (by decide) theorem h39_36 : part 39 36 7 = true := by rw [part_eq_W 39 36 7 _ wl39] exact partW_cells 39 36 7 (by decide) (by decide) (by decide) theorem h39_43 : part 39 43 7 = true := by rw [part_eq_W 39 43 7 _ wl39] exact partW_cells 39 43 7 (by decide) (by decide) (by decide) theorem h39_50 : part 39 50 7 = true := by rw [part_eq_W 39 50 7 _ wl39] exact partW_cells 39 50 7 (by decide) (by decide) (by decide) theorem h39_57 : part 39 57 7 = true := by rw [part_eq_W 39 57 7 _ wl39] exact partW_cells 39 57 7 (by decide) (by decide) (by decide) theorem h39_64 : part 39 64 7 = true := by rw [part_eq_W 39 64 7 _ wl39] exact partW_cells 39 64 7 (by decide) (by decide) (by decide) theorem h39_71 : part 39 71 7 = true := by rw [part_eq_W 39 71 7 _ wl39] exact partW_cells 39 71 7 (by decide) (by decide) (by decide) theorem h39_78 : part 39 78 7 = true := by rw [part_eq_W 39 78 7 _ wl39] exact partW_cells 39 78 7 (by decide) (by decide) (by decide) theorem h47_1 : part 47 1 7 = true := by rw [part_eq_W 47 1 7 _ wl47] exact partW_cells 47 1 7 (by decide) (by decide) (by decide) theorem h47_8 : part 47 8 7 = true := by rw [part_eq_W 47 8 7 _ wl47] exact partW_cells 47 8 7 (by decide) (by decide) (by decide) theorem h47_15 : part 47 15 7 = true := by rw [part_eq_W 47 15 7 _ wl47] exact partW_cells 47 15 7 (by decide) (by decide) (by decide) theorem h47_22 : part 47 22 7 = true := by rw [part_eq_W 47 22 7 _ wl47] exact partW_cells 47 22 7 (by decide) (by decide) (by decide) theorem h47_29 : part 47 29 7 = true := by rw [part_eq_W 47 29 7 _ wl47] exact partW_cells 47 29 7 (by decide) (by decide) (by decide) theorem h47_36 : part 47 36 7 = true := by rw [part_eq_W 47 36 7 _ wl47] exact partW_cells 47 36 7 (by decide) (by decide) (by decide) theorem h47_43 : part 47 43 7 = true := by rw [part_eq_W 47 43 7 _ wl47] exact partW_cells 47 43 7 (by decide) (by decide) (by decide) theorem h47_50 : part 47 50 7 = true := by rw [part_eq_W 47 50 7 _ wl47] exact partW_cells 47 50 7 (by decide) (by decide) (by decide) theorem h47_57 : part 47 57 7 = true := by rw [part_eq_W 47 57 7 _ wl47] exact partW_cells 47 57 7 (by decide) (by decide) (by decide) theorem h47_64 : part 47 64 7 = true := by rw [part_eq_W 47 64 7 _ wl47] exact partW_cells 47 64 7 (by decide) (by decide) (by decide) theorem h47_71 : part 47 71 7 = true := by rw [part_eq_W 47 71 7 _ wl47] exact partW_cells 47 71 7 (by decide) (by decide) (by decide) theorem h47_78 : part 47 78 7 = true := by rw [part_eq_W 47 78 7 _ wl47] exact partW_cells 47 78 7 (by decide) (by decide) (by decide) theorem h51_1 : part 51 1 7 = true := by rw [part_eq_W 51 1 7 _ wl51] exact partW_cells 51 1 7 (by decide) (by decide) (by decide) theorem h51_8 : part 51 8 7 = true := by rw [part_eq_W 51 8 7 _ wl51] exact partW_cells 51 8 7 (by decide) (by decide) (by decide) theorem h51_15 : part 51 15 7 = true := by rw [part_eq_W 51 15 7 _ wl51] exact partW_cells 51 15 7 (by decide) (by decide) (by decide) theorem h51_22 : part 51 22 7 = true := by rw [part_eq_W 51 22 7 _ wl51] exact partW_cells 51 22 7 (by decide) (by decide) (by decide) theorem h51_29 : part 51 29 7 = true := by rw [part_eq_W 51 29 7 _ wl51] exact partW_cells 51 29 7 (by decide) (by decide) (by decide) theorem h51_36 : part 51 36 7 = true := by rw [part_eq_W 51 36 7 _ wl51] exact partW_cells 51 36 7 (by decide) (by decide) (by decide) theorem h51_43 : part 51 43 7 = true := by rw [part_eq_W 51 43 7 _ wl51] exact partW_cells 51 43 7 (by decide) (by decide) (by decide) theorem h51_50 : part 51 50 7 = true := by rw [part_eq_W 51 50 7 _ wl51] exact partW_cells 51 50 7 (by decide) (by decide) (by decide) theorem h51_57 : part 51 57 7 = true := by rw [part_eq_W 51 57 7 _ wl51] exact partW_cells 51 57 7 (by decide) (by decide) (by decide) theorem h51_64 : part 51 64 7 = true := by rw [part_eq_W 51 64 7 _ wl51] exact partW_cells 51 64 7 (by decide) (by decide) (by decide) theorem h51_71 : part 51 71 7 = true := by rw [part_eq_W 51 71 7 _ wl51] exact partW_cells 51 71 7 (by decide) (by decide) (by decide) theorem h51_78 : part 51 78 7 = true := by rw [part_eq_W 51 78 7 _ wl51] exact partW_cells 51 78 7 (by decide) (by decide) (by decide) theorem h59_1 : part 59 1 7 = true := by rw [part_eq_W 59 1 7 _ wl59] exact partW_cells 59 1 7 (by decide) (by decide) (by decide) theorem h59_8 : part 59 8 7 = true := by rw [part_eq_W 59 8 7 _ wl59] exact partW_cells 59 8 7 (by decide) (by decide) (by decide) theorem h59_15 : part 59 15 7 = true := by rw [part_eq_W 59 15 7 _ wl59] exact partW_cells 59 15 7 (by decide) (by decide) (by decide) theorem h59_22 : part 59 22 7 = true := by rw [part_eq_W 59 22 7 _ wl59] exact partW_cells 59 22 7 (by decide) (by decide) (by decide) theorem h59_29 : part 59 29 7 = true := by rw [part_eq_W 59 29 7 _ wl59] exact partW_cells 59 29 7 (by decide) (by decide) (by decide) theorem h59_36 : part 59 36 7 = true := by rw [part_eq_W 59 36 7 _ wl59] exact partW_cells 59 36 7 (by decide) (by decide) (by decide) theorem h59_43 : part 59 43 7 = true := by rw [part_eq_W 59 43 7 _ wl59] exact partW_cells 59 43 7 (by decide) (by decide) (by decide) theorem h59_50 : part 59 50 7 = true := by rw [part_eq_W 59 50 7 _ wl59] exact partW_cells 59 50 7 (by decide) (by decide) (by decide) theorem h59_57 : part 59 57 7 = true := by rw [part_eq_W 59 57 7 _ wl59] exact partW_cells 59 57 7 (by decide) (by decide) (by decide) theorem h59_64 : part 59 64 7 = true := by rw [part_eq_W 59 64 7 _ wl59] exact partW_cells 59 64 7 (by decide) (by decide) (by decide) theorem h59_71 : part 59 71 7 = true := by rw [part_eq_W 59 71 7 _ wl59] exact partW_cells 59 71 7 (by decide) (by decide) (by decide) theorem h59_78 : part 59 78 7 = true := by rw [part_eq_W 59 78 7 _ wl59] exact partW_cells 59 78 7 (by decide) (by decide) (by decide) theorem h63_1 : part 63 1 7 = true := by rw [part_eq_W 63 1 7 _ wl63] exact partW_cells 63 1 7 (by decide) (by decide) (by decide) theorem h63_8 : part 63 8 7 = true := by rw [part_eq_W 63 8 7 _ wl63] exact partW_cells 63 8 7 (by decide) (by decide) (by decide) theorem h63_15 : part 63 15 7 = true := by rw [part_eq_W 63 15 7 _ wl63] exact partW_cells 63 15 7 (by decide) (by decide) (by decide) theorem h63_22 : part 63 22 7 = true := by rw [part_eq_W 63 22 7 _ wl63] exact partW_cells 63 22 7 (by decide) (by decide) (by decide) theorem h63_29 : part 63 29 7 = true := by rw [part_eq_W 63 29 7 _ wl63] exact partW_cells 63 29 7 (by decide) (by decide) (by decide) theorem h63_36 : part 63 36 7 = true := by rw [part_eq_W 63 36 7 _ wl63] exact partW_cells 63 36 7 (by decide) (by decide) (by decide) theorem h63_43 : part 63 43 7 = true := by rw [part_eq_W 63 43 7 _ wl63] exact partW_cells 63 43 7 (by decide) (by decide) (by decide) theorem h63_50 : part 63 50 7 = true := by rw [part_eq_W 63 50 7 _ wl63] exact partW_cells 63 50 7 (by decide) (by decide) (by decide) theorem h63_57 : part 63 57 7 = true := by rw [part_eq_W 63 57 7 _ wl63] exact partW_cells 63 57 7 (by decide) (by decide) (by decide) theorem h63_64 : part 63 64 7 = true := by rw [part_eq_W 63 64 7 _ wl63] exact partW_cells 63 64 7 (by decide) (by decide) (by decide) theorem h63_71 : part 63 71 7 = true := by rw [part_eq_W 63 71 7 _ wl63] exact partW_cells 63 71 7 (by decide) (by decide) (by decide) theorem h63_78 : part 63 78 7 = true := by rw [part_eq_W 63 78 7 _ wl63] exact partW_cells 63 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h43_1 : part 43 1 7 = true := by rw [part_eq_W 43 1 7 _ wl43] exact partW_cells 43 1 7 (by decide) (by decide) (by decide) theorem h43_8 : part 43 8 7 = true := by rw [part_eq_W 43 8 7 _ wl43] exact partW_cells 43 8 7 (by decide) (by decide) (by decide) theorem h43_15 : part 43 15 7 = true := by rw [part_eq_W 43 15 7 _ wl43] exact partW_cells 43 15 7 (by decide) (by decide) (by decide) theorem h43_22 : part 43 22 7 = true := by rw [part_eq_W 43 22 7 _ wl43] exact partW_cells 43 22 7 (by decide) (by decide) (by decide) theorem h43_29 : part 43 29 7 = true := by rw [part_eq_W 43 29 7 _ wl43] exact partW_cells 43 29 7 (by decide) (by decide) (by decide) theorem h43_36 : part 43 36 7 = true := by rw [part_eq_W 43 36 7 _ wl43] exact partW_cells 43 36 7 (by decide) (by decide) (by decide) theorem h43_43 : part 43 43 7 = true := by rw [part_eq_W 43 43 7 _ wl43] exact partW_cells 43 43 7 (by decide) (by decide) (by decide) theorem h43_50 : part 43 50 7 = true := by rw [part_eq_W 43 50 7 _ wl43] exact partW_cells 43 50 7 (by decide) (by decide) (by decide) theorem h43_57 : part 43 57 7 = true := by rw [part_eq_W 43 57 7 _ wl43] exact partW_cells 43 57 7 (by decide) (by decide) (by decide) theorem h43_64 : part 43 64 7 = true := by rw [part_eq_W 43 64 7 _ wl43] exact partW_cells 43 64 7 (by decide) (by decide) (by decide) theorem h43_71 : part 43 71 7 = true := by rw [part_eq_W 43 71 7 _ wl43] exact partW_cells 43 71 7 (by decide) (by decide) (by decide) theorem h43_78 : part 43 78 7 = true := by rw [part_eq_W 43 78 7 _ wl43] exact partW_cells 43 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end end section section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h55_1 : part 55 1 7 = true := by rw [part_eq_W 55 1 7 _ wl55] exact partW_cells 55 1 7 (by decide) (by decide) (by decide) theorem h55_8 : part 55 8 7 = true := by rw [part_eq_W 55 8 7 _ wl55] exact partW_cells 55 8 7 (by decide) (by decide) (by decide) theorem h55_15 : part 55 15 7 = true := by rw [part_eq_W 55 15 7 _ wl55] exact partW_cells 55 15 7 (by decide) (by decide) (by decide) theorem h55_22 : part 55 22 7 = true := by rw [part_eq_W 55 22 7 _ wl55] exact partW_cells 55 22 7 (by decide) (by decide) (by decide) theorem h55_29 : part 55 29 7 = true := by rw [part_eq_W 55 29 7 _ wl55] exact partW_cells 55 29 7 (by decide) (by decide) (by decide) theorem h55_36 : part 55 36 7 = true := by rw [part_eq_W 55 36 7 _ wl55] exact partW_cells 55 36 7 (by decide) (by decide) (by decide) theorem h55_43 : part 55 43 7 = true := by rw [part_eq_W 55 43 7 _ wl55] exact partW_cells 55 43 7 (by decide) (by decide) (by decide) theorem h55_50 : part 55 50 7 = true := by rw [part_eq_W 55 50 7 _ wl55] exact partW_cells 55 50 7 (by decide) (by decide) (by decide) theorem h55_57 : part 55 57 7 = true := by rw [part_eq_W 55 57 7 _ wl55] exact partW_cells 55 57 7 (by decide) (by decide) (by decide) theorem h55_64 : part 55 64 7 = true := by rw [part_eq_W 55 64 7 _ wl55] exact partW_cells 55 64 7 (by decide) (by decide) (by decide) theorem h55_71 : part 55 71 7 = true := by rw [part_eq_W 55 71 7 _ wl55] exact partW_cells 55 71 7 (by decide) (by decide) (by decide) theorem h55_78 : part 55 78 7 = true := by rw [part_eq_W 55 78 7 _ wl55] exact partW_cells 55 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h67_1 : part 67 1 7 = true := by rw [part_eq_W 67 1 7 _ wl67] exact partW_cells 67 1 7 (by decide) (by decide) (by decide) theorem h67_8 : part 67 8 7 = true := by rw [part_eq_W 67 8 7 _ wl67] exact partW_cells 67 8 7 (by decide) (by decide) (by decide) theorem h67_15 : part 67 15 7 = true := by rw [part_eq_W 67 15 7 _ wl67] exact partW_cells 67 15 7 (by decide) (by decide) (by decide) theorem h67_22 : part 67 22 7 = true := by rw [part_eq_W 67 22 7 _ wl67] exact partW_cells 67 22 7 (by decide) (by decide) (by decide) theorem h67_29 : part 67 29 7 = true := by rw [part_eq_W 67 29 7 _ wl67] exact partW_cells 67 29 7 (by decide) (by decide) (by decide) theorem h67_36 : part 67 36 7 = true := by rw [part_eq_W 67 36 7 _ wl67] exact partW_cells 67 36 7 (by decide) (by decide) (by decide) theorem h67_43 : part 67 43 7 = true := by rw [part_eq_W 67 43 7 _ wl67] exact partW_cells 67 43 7 (by decide) (by decide) (by decide) theorem h67_50 : part 67 50 7 = true := by rw [part_eq_W 67 50 7 _ wl67] exact partW_cells 67 50 7 (by decide) (by decide) (by decide) theorem h67_57 : part 67 57 7 = true := by rw [part_eq_W 67 57 7 _ wl67] exact partW_cells 67 57 7 (by decide) (by decide) (by decide) theorem h67_64 : part 67 64 7 = true := by rw [part_eq_W 67 64 7 _ wl67] exact partW_cells 67 64 7 (by decide) (by decide) (by decide) theorem h67_71 : part 67 71 7 = true := by rw [part_eq_W 67 71 7 _ wl67] exact partW_cells 67 71 7 (by decide) (by decide) (by decide) theorem h67_78 : part 67 78 7 = true := by rw [part_eq_W 67 78 7 _ wl67] exact partW_cells 67 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h70_1 : part 70 1 7 = true := by rw [part_eq_W 70 1 7 _ wl70] exact partW_cells 70 1 7 (by decide) (by decide) (by decide) theorem h70_8 : part 70 8 7 = true := by rw [part_eq_W 70 8 7 _ wl70] exact partW_cells 70 8 7 (by decide) (by decide) (by decide) theorem h70_15 : part 70 15 7 = true := by rw [part_eq_W 70 15 7 _ wl70] exact partW_cells 70 15 7 (by decide) (by decide) (by decide) theorem h70_22 : part 70 22 7 = true := by rw [part_eq_W 70 22 7 _ wl70] exact partW_cells 70 22 7 (by decide) (by decide) (by decide) theorem h70_29 : part 70 29 7 = true := by rw [part_eq_W 70 29 7 _ wl70] exact partW_cells 70 29 7 (by decide) (by decide) (by decide) theorem h70_36 : part 70 36 7 = true := by rw [part_eq_W 70 36 7 _ wl70] exact partW_cells 70 36 7 (by decide) (by decide) (by decide) theorem h70_43 : part 70 43 7 = true := by rw [part_eq_W 70 43 7 _ wl70] exact partW_cells 70 43 7 (by decide) (by decide) (by decide) theorem h70_50 : part 70 50 7 = true := by rw [part_eq_W 70 50 7 _ wl70] exact partW_cells 70 50 7 (by decide) (by decide) (by decide) theorem h70_57 : part 70 57 7 = true := by rw [part_eq_W 70 57 7 _ wl70] exact partW_cells 70 57 7 (by decide) (by decide) (by decide) theorem h70_64 : part 70 64 7 = true := by rw [part_eq_W 70 64 7 _ wl70] exact partW_cells 70 64 7 (by decide) (by decide) (by decide) theorem h70_71 : part 70 71 7 = true := by rw [part_eq_W 70 71 7 _ wl70] exact partW_cells 70 71 7 (by decide) (by decide) (by decide) theorem h70_78 : part 70 78 7 = true := by rw [part_eq_W 70 78 7 _ wl70] exact partW_cells 70 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h73_1 : part 73 1 7 = true := by rw [part_eq_W 73 1 7 _ wl73] exact partW_cells 73 1 7 (by decide) (by decide) (by decide) theorem h73_8 : part 73 8 7 = true := by rw [part_eq_W 73 8 7 _ wl73] exact partW_cells 73 8 7 (by decide) (by decide) (by decide) theorem h73_15 : part 73 15 7 = true := by rw [part_eq_W 73 15 7 _ wl73] exact partW_cells 73 15 7 (by decide) (by decide) (by decide) theorem h73_22 : part 73 22 7 = true := by rw [part_eq_W 73 22 7 _ wl73] exact partW_cells 73 22 7 (by decide) (by decide) (by decide) theorem h73_29 : part 73 29 7 = true := by rw [part_eq_W 73 29 7 _ wl73] exact partW_cells 73 29 7 (by decide) (by decide) (by decide) theorem h73_36 : part 73 36 7 = true := by rw [part_eq_W 73 36 7 _ wl73] exact partW_cells 73 36 7 (by decide) (by decide) (by decide) theorem h73_43 : part 73 43 7 = true := by rw [part_eq_W 73 43 7 _ wl73] exact partW_cells 73 43 7 (by decide) (by decide) (by decide) theorem h73_50 : part 73 50 7 = true := by rw [part_eq_W 73 50 7 _ wl73] exact partW_cells 73 50 7 (by decide) (by decide) (by decide) theorem h73_57 : part 73 57 7 = true := by rw [part_eq_W 73 57 7 _ wl73] exact partW_cells 73 57 7 (by decide) (by decide) (by decide) theorem h73_64 : part 73 64 7 = true := by rw [part_eq_W 73 64 7 _ wl73] exact partW_cells 73 64 7 (by decide) (by decide) (by decide) theorem h73_71 : part 73 71 7 = true := by rw [part_eq_W 73 71 7 _ wl73] exact partW_cells 73 71 7 (by decide) (by decide) (by decide) theorem h73_78 : part 73 78 7 = true := by rw [part_eq_W 73 78 7 _ wl73] exact partW_cells 73 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h76_1 : part 76 1 7 = true := by rw [part_eq_W 76 1 7 _ wl76] exact partW_cells 76 1 7 (by decide) (by decide) (by decide) theorem h76_8 : part 76 8 7 = true := by rw [part_eq_W 76 8 7 _ wl76] exact partW_cells 76 8 7 (by decide) (by decide) (by decide) theorem h76_15 : part 76 15 7 = true := by rw [part_eq_W 76 15 7 _ wl76] exact partW_cells 76 15 7 (by decide) (by decide) (by decide) theorem h76_22 : part 76 22 7 = true := by rw [part_eq_W 76 22 7 _ wl76] exact partW_cells 76 22 7 (by decide) (by decide) (by decide) theorem h76_29 : part 76 29 7 = true := by rw [part_eq_W 76 29 7 _ wl76] exact partW_cells 76 29 7 (by decide) (by decide) (by decide) theorem h76_36 : part 76 36 7 = true := by rw [part_eq_W 76 36 7 _ wl76] exact partW_cells 76 36 7 (by decide) (by decide) (by decide) theorem h76_43 : part 76 43 7 = true := by rw [part_eq_W 76 43 7 _ wl76] exact partW_cells 76 43 7 (by decide) (by decide) (by decide) theorem h76_50 : part 76 50 7 = true := by rw [part_eq_W 76 50 7 _ wl76] exact partW_cells 76 50 7 (by decide) (by decide) (by decide) theorem h76_57 : part 76 57 7 = true := by rw [part_eq_W 76 57 7 _ wl76] exact partW_cells 76 57 7 (by decide) (by decide) (by decide) theorem h76_64 : part 76 64 7 = true := by rw [part_eq_W 76 64 7 _ wl76] exact partW_cells 76 64 7 (by decide) (by decide) (by decide) theorem h76_71 : part 76 71 7 = true := by rw [part_eq_W 76 71 7 _ wl76] exact partW_cells 76 71 7 (by decide) (by decide) (by decide) theorem h76_78 : part 76 78 7 = true := by rw [part_eq_W 76 78 7 _ wl76] exact partW_cells 76 78 7 (by decide) (by decide) (by decide) theorem h79_1 : part 79 1 7 = true := by rw [part_eq_W 79 1 7 _ wl79] exact partW_cells 79 1 7 (by decide) (by decide) (by decide) theorem h79_8 : part 79 8 7 = true := by rw [part_eq_W 79 8 7 _ wl79] exact partW_cells 79 8 7 (by decide) (by decide) (by decide) theorem h79_15 : part 79 15 7 = true := by rw [part_eq_W 79 15 7 _ wl79] exact partW_cells 79 15 7 (by decide) (by decide) (by decide) theorem h79_22 : part 79 22 7 = true := by rw [part_eq_W 79 22 7 _ wl79] exact partW_cells 79 22 7 (by decide) (by decide) (by decide) theorem h79_29 : part 79 29 7 = true := by rw [part_eq_W 79 29 7 _ wl79] exact partW_cells 79 29 7 (by decide) (by decide) (by decide) theorem h79_36 : part 79 36 7 = true := by rw [part_eq_W 79 36 7 _ wl79] exact partW_cells 79 36 7 (by decide) (by decide) (by decide) theorem h79_43 : part 79 43 7 = true := by rw [part_eq_W 79 43 7 _ wl79] exact partW_cells 79 43 7 (by decide) (by decide) (by decide) theorem h79_50 : part 79 50 7 = true := by rw [part_eq_W 79 50 7 _ wl79] exact partW_cells 79 50 7 (by decide) (by decide) (by decide) theorem h79_57 : part 79 57 7 = true := by rw [part_eq_W 79 57 7 _ wl79] exact partW_cells 79 57 7 (by decide) (by decide) (by decide) theorem h79_64 : part 79 64 7 = true := by rw [part_eq_W 79 64 7 _ wl79] exact partW_cells 79 64 7 (by decide) (by decide) (by decide) theorem h79_71 : part 79 71 7 = true := by rw [part_eq_W 79 71 7 _ wl79] exact partW_cells 79 71 7 (by decide) (by decide) (by decide) theorem h79_78 : part 79 78 7 = true := by rw [part_eq_W 79 78 7 _ wl79] exact partW_cells 79 78 7 (by decide) (by decide) (by decide) theorem h82_1 : part 82 1 7 = true := by rw [part_eq_W 82 1 7 _ wl82] exact partW_cells 82 1 7 (by decide) (by decide) (by decide) theorem h82_8 : part 82 8 7 = true := by rw [part_eq_W 82 8 7 _ wl82] exact partW_cells 82 8 7 (by decide) (by decide) (by decide) theorem h82_15 : part 82 15 7 = true := by rw [part_eq_W 82 15 7 _ wl82] exact partW_cells 82 15 7 (by decide) (by decide) (by decide) theorem h82_22 : part 82 22 7 = true := by rw [part_eq_W 82 22 7 _ wl82] exact partW_cells 82 22 7 (by decide) (by decide) (by decide) theorem h82_29 : part 82 29 7 = true := by rw [part_eq_W 82 29 7 _ wl82] exact partW_cells 82 29 7 (by decide) (by decide) (by decide) theorem h82_36 : part 82 36 7 = true := by rw [part_eq_W 82 36 7 _ wl82] exact partW_cells 82 36 7 (by decide) (by decide) (by decide) theorem h82_43 : part 82 43 7 = true := by rw [part_eq_W 82 43 7 _ wl82] exact partW_cells 82 43 7 (by decide) (by decide) (by decide) theorem h82_50 : part 82 50 7 = true := by rw [part_eq_W 82 50 7 _ wl82] exact partW_cells 82 50 7 (by decide) (by decide) (by decide) theorem h82_57 : part 82 57 7 = true := by rw [part_eq_W 82 57 7 _ wl82] exact partW_cells 82 57 7 (by decide) (by decide) (by decide) theorem h82_64 : part 82 64 7 = true := by rw [part_eq_W 82 64 7 _ wl82] exact partW_cells 82 64 7 (by decide) (by decide) (by decide) theorem h82_71 : part 82 71 7 = true := by rw [part_eq_W 82 71 7 _ wl82] exact partW_cells 82 71 7 (by decide) (by decide) (by decide) theorem h82_78 : part 82 78 7 = true := by rw [part_eq_W 82 78 7 _ wl82] exact partW_cells 82 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h10_1 : part 10 1 7 = true := by rw [part_eq_W 10 1 7 _ wl10] exact partW_cells 10 1 7 (by decide) (by decide) (by decide) theorem h10_8 : part 10 8 7 = true := by rw [part_eq_W 10 8 7 _ wl10] exact partW_cells 10 8 7 (by decide) (by decide) (by decide) theorem h10_15 : part 10 15 7 = true := by rw [part_eq_W 10 15 7 _ wl10] exact partW_cells 10 15 7 (by decide) (by decide) (by decide) theorem h10_22 : part 10 22 7 = true := by rw [part_eq_W 10 22 7 _ wl10] exact partW_cells 10 22 7 (by decide) (by decide) (by decide) theorem h10_29 : part 10 29 7 = true := by rw [part_eq_W 10 29 7 _ wl10] exact partW_cells 10 29 7 (by decide) (by decide) (by decide) theorem h10_36 : part 10 36 7 = true := by rw [part_eq_W 10 36 7 _ wl10] exact partW_cells 10 36 7 (by decide) (by decide) (by decide) theorem h10_43 : part 10 43 7 = true := by rw [part_eq_W 10 43 7 _ wl10] exact partW_cells 10 43 7 (by decide) (by decide) (by decide) theorem h10_50 : part 10 50 7 = true := by rw [part_eq_W 10 50 7 _ wl10] exact partW_cells 10 50 7 (by decide) (by decide) (by decide) theorem h10_57 : part 10 57 7 = true := by rw [part_eq_W 10 57 7 _ wl10] exact partW_cells 10 57 7 (by decide) (by decide) (by decide) theorem h10_64 : part 10 64 7 = true := by rw [part_eq_W 10 64 7 _ wl10] exact partW_cells 10 64 7 (by decide) (by decide) (by decide) theorem h10_71 : part 10 71 7 = true := by rw [part_eq_W 10 71 7 _ wl10] exact partW_cells 10 71 7 (by decide) (by decide) (by decide) theorem h10_78 : part 10 78 7 = true := by rw [part_eq_W 10 78 7 _ wl10] exact partW_cells 10 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h13_1 : part 13 1 7 = true := by rw [part_eq_W 13 1 7 _ wl13] exact partW_cells 13 1 7 (by decide) (by decide) (by decide) theorem h13_8 : part 13 8 7 = true := by rw [part_eq_W 13 8 7 _ wl13] exact partW_cells 13 8 7 (by decide) (by decide) (by decide) theorem h13_15 : part 13 15 7 = true := by rw [part_eq_W 13 15 7 _ wl13] exact partW_cells 13 15 7 (by decide) (by decide) (by decide) theorem h13_22 : part 13 22 7 = true := by rw [part_eq_W 13 22 7 _ wl13] exact partW_cells 13 22 7 (by decide) (by decide) (by decide) theorem h13_29 : part 13 29 7 = true := by rw [part_eq_W 13 29 7 _ wl13] exact partW_cells 13 29 7 (by decide) (by decide) (by decide) theorem h13_36 : part 13 36 7 = true := by rw [part_eq_W 13 36 7 _ wl13] exact partW_cells 13 36 7 (by decide) (by decide) (by decide) theorem h13_43 : part 13 43 7 = true := by rw [part_eq_W 13 43 7 _ wl13] exact partW_cells 13 43 7 (by decide) (by decide) (by decide) theorem h13_50 : part 13 50 7 = true := by rw [part_eq_W 13 50 7 _ wl13] exact partW_cells 13 50 7 (by decide) (by decide) (by decide) theorem h13_57 : part 13 57 7 = true := by rw [part_eq_W 13 57 7 _ wl13] exact partW_cells 13 57 7 (by decide) (by decide) (by decide) theorem h13_64 : part 13 64 7 = true := by rw [part_eq_W 13 64 7 _ wl13] exact partW_cells 13 64 7 (by decide) (by decide) (by decide) theorem h13_71 : part 13 71 7 = true := by rw [part_eq_W 13 71 7 _ wl13] exact partW_cells 13 71 7 (by decide) (by decide) (by decide) theorem h13_78 : part 13 78 7 = true := by rw [part_eq_W 13 78 7 _ wl13] exact partW_cells 13 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h16_1 : part 16 1 7 = true := by rw [part_eq_W 16 1 7 _ wl16] exact partW_cells 16 1 7 (by decide) (by decide) (by decide) theorem h16_8 : part 16 8 7 = true := by rw [part_eq_W 16 8 7 _ wl16] exact partW_cells 16 8 7 (by decide) (by decide) (by decide) theorem h16_15 : part 16 15 7 = true := by rw [part_eq_W 16 15 7 _ wl16] exact partW_cells 16 15 7 (by decide) (by decide) (by decide) theorem h16_22 : part 16 22 7 = true := by rw [part_eq_W 16 22 7 _ wl16] exact partW_cells 16 22 7 (by decide) (by decide) (by decide) theorem h16_29 : part 16 29 7 = true := by rw [part_eq_W 16 29 7 _ wl16] exact partW_cells 16 29 7 (by decide) (by decide) (by decide) theorem h16_36 : part 16 36 7 = true := by rw [part_eq_W 16 36 7 _ wl16] exact partW_cells 16 36 7 (by decide) (by decide) (by decide) theorem h16_43 : part 16 43 7 = true := by rw [part_eq_W 16 43 7 _ wl16] exact partW_cells 16 43 7 (by decide) (by decide) (by decide) theorem h16_50 : part 16 50 7 = true := by rw [part_eq_W 16 50 7 _ wl16] exact partW_cells 16 50 7 (by decide) (by decide) (by decide) theorem h16_57 : part 16 57 7 = true := by rw [part_eq_W 16 57 7 _ wl16] exact partW_cells 16 57 7 (by decide) (by decide) (by decide) theorem h16_64 : part 16 64 7 = true := by rw [part_eq_W 16 64 7 _ wl16] exact partW_cells 16 64 7 (by decide) (by decide) (by decide) theorem h16_71 : part 16 71 7 = true := by rw [part_eq_W 16 71 7 _ wl16] exact partW_cells 16 71 7 (by decide) (by decide) (by decide) theorem h16_78 : part 16 78 7 = true := by rw [part_eq_W 16 78 7 _ wl16] exact partW_cells 16 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h19_1 : part 19 1 7 = true := by rw [part_eq_W 19 1 7 _ wl19] exact partW_cells 19 1 7 (by decide) (by decide) (by decide) theorem h19_8 : part 19 8 7 = true := by rw [part_eq_W 19 8 7 _ wl19] exact partW_cells 19 8 7 (by decide) (by decide) (by decide) theorem h19_15 : part 19 15 7 = true := by rw [part_eq_W 19 15 7 _ wl19] exact partW_cells 19 15 7 (by decide) (by decide) (by decide) theorem h19_22 : part 19 22 7 = true := by rw [part_eq_W 19 22 7 _ wl19] exact partW_cells 19 22 7 (by decide) (by decide) (by decide) theorem h19_29 : part 19 29 7 = true := by rw [part_eq_W 19 29 7 _ wl19] exact partW_cells 19 29 7 (by decide) (by decide) (by decide) theorem h19_36 : part 19 36 7 = true := by rw [part_eq_W 19 36 7 _ wl19] exact partW_cells 19 36 7 (by decide) (by decide) (by decide) theorem h19_43 : part 19 43 7 = true := by rw [part_eq_W 19 43 7 _ wl19] exact partW_cells 19 43 7 (by decide) (by decide) (by decide) theorem h19_50 : part 19 50 7 = true := by rw [part_eq_W 19 50 7 _ wl19] exact partW_cells 19 50 7 (by decide) (by decide) (by decide) theorem h19_57 : part 19 57 7 = true := by rw [part_eq_W 19 57 7 _ wl19] exact partW_cells 19 57 7 (by decide) (by decide) (by decide) theorem h19_64 : part 19 64 7 = true := by rw [part_eq_W 19 64 7 _ wl19] exact partW_cells 19 64 7 (by decide) (by decide) (by decide) theorem h19_71 : part 19 71 7 = true := by rw [part_eq_W 19 71 7 _ wl19] exact partW_cells 19 71 7 (by decide) (by decide) (by decide) theorem h19_78 : part 19 78 7 = true := by rw [part_eq_W 19 78 7 _ wl19] exact partW_cells 19 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck set_option maxRecDepth 36000 set_option maxHeartbeats 3500000 theorem h22_1 : part 22 1 7 = true := by rw [part_eq_W 22 1 7 _ wl22] exact partW_cells 22 1 7 (by decide) (by decide) (by decide) theorem h22_8 : part 22 8 7 = true := by rw [part_eq_W 22 8 7 _ wl22] exact partW_cells 22 8 7 (by decide) (by decide) (by decide) theorem h22_15 : part 22 15 7 = true := by rw [part_eq_W 22 15 7 _ wl22] exact partW_cells 22 15 7 (by decide) (by decide) (by decide) theorem h22_22 : part 22 22 7 = true := by rw [part_eq_W 22 22 7 _ wl22] exact partW_cells 22 22 7 (by decide) (by decide) (by decide) theorem h22_29 : part 22 29 7 = true := by rw [part_eq_W 22 29 7 _ wl22] exact partW_cells 22 29 7 (by decide) (by decide) (by decide) theorem h22_36 : part 22 36 7 = true := by rw [part_eq_W 22 36 7 _ wl22] exact partW_cells 22 36 7 (by decide) (by decide) (by decide) theorem h22_43 : part 22 43 7 = true := by rw [part_eq_W 22 43 7 _ wl22] exact partW_cells 22 43 7 (by decide) (by decide) (by decide) theorem h22_50 : part 22 50 7 = true := by rw [part_eq_W 22 50 7 _ wl22] exact partW_cells 22 50 7 (by decide) (by decide) (by decide) theorem h22_57 : part 22 57 7 = true := by rw [part_eq_W 22 57 7 _ wl22] exact partW_cells 22 57 7 (by decide) (by decide) (by decide) theorem h22_64 : part 22 64 7 = true := by rw [part_eq_W 22 64 7 _ wl22] exact partW_cells 22 64 7 (by decide) (by decide) (by decide) theorem h22_71 : part 22 71 7 = true := by rw [part_eq_W 22 71 7 _ wl22] exact partW_cells 22 71 7 (by decide) (by decide) (by decide) theorem h22_78 : part 22 78 7 = true := by rw [part_eq_W 22 78 7 _ wl22] exact partW_cells 22 78 7 (by decide) (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldMask open Arithmetic MappedCompressed StairArchiveRelease StairArchiveNativeCut StairArchiveInactive open ArchiveFieldScratch StairArchiveTen CodecBitSliceVerify attribute [local irreducible] run StairArchiveInactive.packet StairArchiveRelease.fieldHook StairArchiveTen.first StairArchiveTen.second StairArchiveTen.ten StairArchiveRelease.fieldPort StairArchiveRelease.outputCols StairArchiveRelease.inputCols StairArchiveNativeCut.canonical CodecBitSliceVerify.get set_option maxRecDepth 1200 set_option maxHeartbeats 360000 end ECDSAAdd.Entrant.StairPacket.WindowFieldMask end section namespace ECDSAAdd.Entrant.StairPacket.WindowBankCheck open Arithmetic MappedCompressed ArchiveFieldScratch StairArchiveInactive StairArchiveNativeCut StairArchiveRelease WindowFieldMask set_option maxRecDepth 10000 set_option maxHeartbeats 1200000 set_option exponentiation.threshold 100000 private theorem splitRange : List.range' 1 84 = List.range' 1 7 ++ List.range' 8 7 ++ List.range' 15 7 ++ List.range' 22 7 ++ List.range' 29 7 ++ List.range' 36 7 ++ List.range' 43 7 ++ List.range' 50 7 ++ List.range' 57 7 ++ List.range' 64 7 ++ List.range' 71 7 ++ List.range' 78 7 := by decide +kernel attribute [local irreducible] allowed fieldPort packet cover preimage private theorem pass55 : (List.range' 1 84).all (allowed 55)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h55_1,h55_8⟩,h55_15⟩,h55_22⟩,h55_29⟩,h55_36⟩,h55_43⟩,h55_50⟩,h55_57⟩,h55_64⟩,h55_71⟩,h55_78⟩ private theorem pass67 : (List.range' 1 84).all (allowed 67)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h67_1,h67_8⟩,h67_15⟩,h67_22⟩,h67_29⟩,h67_36⟩,h67_43⟩,h67_50⟩,h67_57⟩,h67_64⟩,h67_71⟩,h67_78⟩ private theorem pass70 : (List.range' 1 84).all (allowed 70)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h70_1,h70_8⟩,h70_15⟩,h70_22⟩,h70_29⟩,h70_36⟩,h70_43⟩,h70_50⟩,h70_57⟩,h70_64⟩,h70_71⟩,h70_78⟩ private theorem pass73 : (List.range' 1 84).all (allowed 73)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h73_1,h73_8⟩,h73_15⟩,h73_22⟩,h73_29⟩,h73_36⟩,h73_43⟩,h73_50⟩,h73_57⟩,h73_64⟩,h73_71⟩,h73_78⟩ private theorem pass76 : (List.range' 1 84).all (allowed 76)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h76_1,h76_8⟩,h76_15⟩,h76_22⟩,h76_29⟩,h76_36⟩,h76_43⟩,h76_50⟩,h76_57⟩,h76_64⟩,h76_71⟩,h76_78⟩ private theorem pass79 : (List.range' 1 84).all (allowed 79)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h79_1,h79_8⟩,h79_15⟩,h79_22⟩,h79_29⟩,h79_36⟩,h79_43⟩,h79_50⟩,h79_57⟩,h79_64⟩,h79_71⟩,h79_78⟩ private theorem pass82 : (List.range' 1 84).all (allowed 82)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h82_1,h82_8⟩,h82_15⟩,h82_22⟩,h82_29⟩,h82_36⟩,h82_43⟩,h82_50⟩,h82_57⟩,h82_64⟩,h82_71⟩,h82_78⟩ private theorem pass10 : (List.range' 1 84).all (allowed 10)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h10_1,h10_8⟩,h10_15⟩,h10_22⟩,h10_29⟩,h10_36⟩,h10_43⟩,h10_50⟩,h10_57⟩,h10_64⟩,h10_71⟩,h10_78⟩ private theorem pass13 : (List.range' 1 84).all (allowed 13)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h13_1,h13_8⟩,h13_15⟩,h13_22⟩,h13_29⟩,h13_36⟩,h13_43⟩,h13_50⟩,h13_57⟩,h13_64⟩,h13_71⟩,h13_78⟩ private theorem pass16 : (List.range' 1 84).all (allowed 16)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h16_1,h16_8⟩,h16_15⟩,h16_22⟩,h16_29⟩,h16_36⟩,h16_43⟩,h16_50⟩,h16_57⟩,h16_64⟩,h16_71⟩,h16_78⟩ private theorem pass19 : (List.range' 1 84).all (allowed 19)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h19_1,h19_8⟩,h19_15⟩,h19_22⟩,h19_29⟩,h19_36⟩,h19_43⟩,h19_50⟩,h19_57⟩,h19_64⟩,h19_71⟩,h19_78⟩ private theorem pass22 : (List.range' 1 84).all (allowed 22)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h22_1,h22_8⟩,h22_15⟩,h22_22⟩,h22_29⟩,h22_36⟩,h22_43⟩,h22_50⟩,h22_57⟩,h22_64⟩,h22_71⟩,h22_78⟩ private theorem pass25 : (List.range' 1 84).all (allowed 25)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h25_1,h25_8⟩,h25_15⟩,h25_22⟩,h25_29⟩,h25_36⟩,h25_43⟩,h25_50⟩,h25_57⟩,h25_64⟩,h25_71⟩,h25_78⟩ private theorem pass28 : (List.range' 1 84).all (allowed 28)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h28_1,h28_8⟩,h28_15⟩,h28_22⟩,h28_29⟩,h28_36⟩,h28_43⟩,h28_50⟩,h28_57⟩,h28_64⟩,h28_71⟩,h28_78⟩ private theorem pass31 : (List.range' 1 84).all (allowed 31)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h31_1,h31_8⟩,h31_15⟩,h31_22⟩,h31_29⟩,h31_36⟩,h31_43⟩,h31_50⟩,h31_57⟩,h31_64⟩,h31_71⟩,h31_78⟩ private theorem pass43 : (List.range' 1 84).all (allowed 43)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h43_1,h43_8⟩,h43_15⟩,h43_22⟩,h43_29⟩,h43_36⟩,h43_43⟩,h43_50⟩,h43_57⟩,h43_64⟩,h43_71⟩,h43_78⟩ private theorem pass35 : (List.range' 1 84).all (allowed 35)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h35_1,h35_8⟩,h35_15⟩,h35_22⟩,h35_29⟩,h35_36⟩,h35_43⟩,h35_50⟩,h35_57⟩,h35_64⟩,h35_71⟩,h35_78⟩ private theorem pass39 : (List.range' 1 84).all (allowed 39)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h39_1,h39_8⟩,h39_15⟩,h39_22⟩,h39_29⟩,h39_36⟩,h39_43⟩,h39_50⟩,h39_57⟩,h39_64⟩,h39_71⟩,h39_78⟩ private theorem pass47 : (List.range' 1 84).all (allowed 47)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h47_1,h47_8⟩,h47_15⟩,h47_22⟩,h47_29⟩,h47_36⟩,h47_43⟩,h47_50⟩,h47_57⟩,h47_64⟩,h47_71⟩,h47_78⟩ private theorem pass51 : (List.range' 1 84).all (allowed 51)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h51_1,h51_8⟩,h51_15⟩,h51_22⟩,h51_29⟩,h51_36⟩,h51_43⟩,h51_50⟩,h51_57⟩,h51_64⟩,h51_71⟩,h51_78⟩ private theorem pass59 : (List.range' 1 84).all (allowed 59)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h59_1,h59_8⟩,h59_15⟩,h59_22⟩,h59_29⟩,h59_36⟩,h59_43⟩,h59_50⟩,h59_57⟩,h59_64⟩,h59_71⟩,h59_78⟩ private theorem pass63 : (List.range' 1 84).all (allowed 63)=true := by rw [splitRange] simp only [List.all_append, Bool.and_eq_true] exact ⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨⟨h63_1,h63_8⟩,h63_15⟩,h63_22⟩,h63_29⟩,h63_36⟩,h63_43⟩,h63_50⟩,h63_57⟩,h63_64⟩,h63_71⟩,h63_78⟩ private theorem pass (h : Nat) (hm : h ∈ banks) : (List.range' 1 84).all (allowed h) = true := by simp only [banks,List.mem_cons,List.mem_nil_iff,or_false] at hm rcases hm with rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl · exact pass10 · exact pass13 · exact pass16 · exact pass19 · exact pass22 · exact pass25 · exact pass28 · exact pass31 · exact pass35 · exact pass39 · exact pass43 · exact pass47 · exact pass51 · exact pass55 · exact pass59 · exact pass63 · exact pass67 · exact pass70 · exact pass73 · exact pass76 · exact pass79 · exact pass82 theorem packet_free (h k : Nat) (hm : h∈banks) (km : k∈List.range' 1 84) (not0 : k≠h) (not1 : k≠h+1) (d : Bool) : avoids (packet d k) (bank h) := by have once := List.all_eq_true.mp (pass h hm) k km simp only [allowed, decide_eq_false not0, decide_eq_false not1, Bool.false_or] at once intro q member used obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp member have qmem : fieldPort h i ∈ slots h := List.mem_map.mpr ⟨i,List.mem_range.mpr (Finset.mem_range.mp hi),rfl⟩ have outside := List.all_eq_true.mp once _ qmem have limit := (List.mem_range'_1.mp km).2 have inside := original d k (by omega) used simp [compactCover_present inside] at outside /-- Bit mask of a wire list (kernel-cheap: `Nat.lor`/`Nat.shiftLeft` are GMP-accelerated). -/ def maskOf (l : List Wire) : Nat := l.foldl (fun acc q => acc ||| (1 <<< (q:Nat))) 0 theorem testBit_maskFold (l : List Wire) (acc q : Nat) : (l.foldl (fun acc q => acc ||| (1 <<< (q:Nat))) acc).testBit q = (acc.testBit q || l.contains q) := by induction l generalizing acc with | nil => simp | cons a l ih => rw [List.foldl_cons, ih, Nat.testBit_or, Nat.one_shiftLeft, Nat.testBit_two_pow, List.contains_cons] by_cases h : (a:Nat) = q · subst h; simp · have h' : (q == a) = false := by simp only [beq_eq_false_iff_ne]; exact fun e => h e.symm simp [h, h'] theorem testBit_maskOf {l : List Wire} {q : Wire} (h : q ∈ l) : (maskOf l).testBit q = true := by rw [maskOf, testBit_maskFold] simp [h] /-- Banks `j ≠ h`: no slot of `h` is a field port of `j` (one `&&&` of two masks per pair). -/ private def distinct (j h : Nat) := j=h || ((maskOf (slots h)) &&& (maskOf ((List.range 121).map (fieldPort j))) == 0) private theorem distinct_ok : banks.all (fun j=>banks.all (distinct j))=true := by decide +kernel theorem separate (j h : Nat) (jm : j∈banks) (hm : h∈banks) (ne : j≠h) : ∀ q∈inside j, q∉bank h := by have ok := List.all_eq_true.mp (List.all_eq_true.mp distinct_ok j jm) h hm simp only [distinct, decide_eq_false ne, Bool.false_or, beq_iff_eq] at ok intro q own other obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp other have qmem : fieldPort h i ∈ slots h := List.mem_map.mpr ⟨i,List.mem_range.mpr (Finset.mem_range.mp hi),rfl⟩ have inside' : fieldPort h i ∈ (List.range 121).map (fieldPort j) := by obtain ⟨t,ht,eq⟩ := Finset.mem_image.mp own exact List.mem_map.mpr ⟨t,List.mem_range.mpr (Finset.mem_range.mp ht),eq⟩ have b := congrArg (fun n : Nat => n.testBit (fieldPort h i)) ok simp only [Nat.testBit_and, testBit_maskOf qmem, testBit_maskOf inside', Bool.and_self, Nat.zero_testBit] at b exact Bool.noConfusion b end ECDSAAdd.Entrant.StairPacket.WindowBankCheck end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldMask open Arithmetic MappedCompressed StairArchiveRelease StairArchiveNativeCut StairArchiveInactive open ArchiveFieldScratch StairArchiveTen CodecBitSliceVerify def bankIds : Finset Nat := {10,13,16,19,22,25,28,31,35,39,43,47,51,55,59,63,67,70,73,76,79,82} def allBanks : Finset Wire := bankIds.biUnion bank def others (j : Nat) : Finset Wire := (bankIds.erase j).biUnion bank def byteFrame (j row : Nat) (cs : Cols) (a : State) := ∀ q∈Finset.range 16, a.basis (fieldPort j q) = (get cs q).testBit row structure Fits (rows : Nat → Nat) (code : Nat → Cols) (a r : State) : Prop where phase : a.phase = r.phase outside : ∀ q∉allBanks, a.basis q=r.basis q bytes : ∀ j∈bankIds, byteFrame j (rows j) (code j) a set_option maxRecDepth 4000 set_option maxHeartbeats 1000000 set_option exponentiation.threshold 100000 theorem decompose (j : Nat) (hj : j∈bankIds) : allBanks=bank j ∪ others j := by ext q simp only [allBanks,others,Finset.mem_union,Finset.mem_biUnion,Finset.mem_erase] constructor · rintro ⟨k,hk,hq⟩ by_cases same : k=j · subst k; exact Or.inl hq · exact Or.inr ⟨k,⟨same,hk⟩,hq⟩ · rintro (own|⟨k,⟨_,hk⟩,hq⟩) · exact ⟨j,hj,own⟩ · exact ⟨k,hk,hq⟩ private theorem run_on_bank_complement (P : Program) (B : Finset Wire) (m : List Bool) (a r : State) (phase : a.phase = r.phase) (rest : ∀ q ∉ B, a.basis q = r.basis q) (safe : avoids P B) : (run P m a).phase = (run P m r).phase ∧ ∀ q ∉ B, (run P m a).basis q = (run P m r).basis q := by have same : mask B a r = a := by apply congrArg₂ State.mk phase.symm funext q by_cases member : q ∈ B · exact if_pos member · exact (if_neg member).trans (rest q member).symm have outcome := mask_run P B m a r safe rw [same] at outcome have matched := congrArg State.phase outcome refine ⟨matched, ?_⟩ intro q outside exact (congrArg (fun s : State => s.basis q) outcome).trans (if_neg outside) theorem plain (P : Program) (rows : Nat→Nat) (code : Nat→Cols) (m : List Bool) (a r : State) (h : Fits rows code a r) (safe : avoids P allBanks) : Fits rows code (run P m a) (run P m r) := by obtain ⟨phase, outside⟩ := run_on_bank_complement P allBanks m a r h.phase h.outside safe refine ⟨phase, outside, ?_⟩ intro j hj q hq have member : fieldPort j q ∈ allBanks := Finset.mem_biUnion.mpr ⟨j, hj, Finset.mem_image.mpr ⟨q, hq, rfl⟩⟩ exact (run_preserves_outside P m a _ (safe _ member)).trans (h.bytes j hj q hq) private theorem initRest (rev : Bool) : (List.range' 16 105).all (fun q => get (inputCols (enter rev)) q == get (StairArchiveNativeCut.canonical (!rev) (!rev)) q) = true := by cases rev <;> decide +kernel attribute [local irreducible] run fieldPort StairArchiveNativeCut.canonical inputCols enter CodecBitSliceVerify.get theorem beforeFrame (j : Nat) (hj : j∈bankIds) (rows : Nat→Nat) (code : Nat→Cols) (rev : Bool) (a r : State) (h : Fits rows code a r) (active : code j=inputCols (enter rev)) (apart : ∀ q∈inside j, q∉others j) (before_ : frame j (rows j) (StairArchiveNativeCut.canonical (!rev) (!rev)) r) (nd : ∀ i∈Finset.range 121,∀ k∈Finset.range 121, fieldPort j i=fieldPort j k→i=k) : frame j (rows j) (inputCols (enter rev)) a := by intro q hq by_cases lo : q<16 · rw [←active] exact h.bytes j hj q (Finset.mem_range.mpr lo) · have lq := Finset.mem_range.mp hq have own : fieldPort j q ∉ bank j := by intro mem obtain ⟨k,hk,heq⟩ := Finset.mem_image.mp mem have lk := Finset.mem_range.mp hk have eq := nd k (Finset.mem_range.mpr (by omega)) q hq heq omega have outsider : fieldPort j q ∉ allBanks := by rw [decompose j hj,Finset.mem_union] exact fun hit => hit.elim own (apart _ (Finset.mem_image.mpr ⟨q,hq,rfl⟩)) have range : q∈List.range' 16 105 := List.mem_range'_1.mpr ⟨by omega,by omega⟩ have c := beq_iff_eq.mp (List.all_eq_true.mp (initRest rev) q range) rw [h.outside _ outsider, before_ q hq, c] end ECDSAAdd.Entrant.StairPacket.WindowFieldMask end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldMask open Arithmetic MappedCompressed StairArchiveInactive WindowFieldCosts attribute [local irreducible] packet run allBanks def nativeRanges (j n : Nat) := (j=1 ∧ n=9) ∨ (j=12 ∧ n=1) ∨ (j=15 ∧ n=1) ∨ (j=18 ∧ n=1) ∨ (j=21 ∧ n=1) ∨ (j=24 ∧ n=1) ∨ (j=27 ∧ n=1) ∨ (j=30 ∧ n=1) ∨ (j=33 ∧ n=2) ∨ (j=37 ∧ n=2) ∨ (j=41 ∧ n=2) ∨ (j=45 ∧ n=2) ∨ (j=49 ∧ n=2) ∨ (j=53 ∧ n=2) ∨ (j=57 ∧ n=2) ∨ (j=61 ∧ n=2) ∨ (j=65 ∧ n=2) ∨ (j=69 ∧ n=1) ∨ (j=72 ∧ n=1) ∨ (j=75 ∧ n=1) ∨ (j=78 ∧ n=1) ∨ (j=81 ∧ n=1) ∨ (j=84 ∧ n=1) private theorem disjointRange {j n k h : Nat} (valid : nativeRanges j n) (hk : j≤k ∧ k intro q _ used; simp [PacketSequence.program,wires] at used | succ n ih => have head := h j (by omega) (by omega) have tail := ih (j+1) (fun k l u=>h k (by omega) (by omega)) intro q inbank used cases d <;> simp only [PacketSequence.program,Bool.false_eq_true,if_false,if_true, wires_append,Finset.mem_union] at used · exact used.elim (tail q inbank) (head q inbank) · exact used.elim (head q inbank) (tail q inbank) theorem groupSafe (d : Bool) (j n : Nat) (valid : nativeRanges j n) : avoids (group d j n) allBanks := by rw [group,distribute] apply seqSafe intro k lower upper q mem used rw [allBanks] at mem obtain ⟨h,hm,hq⟩ := Finset.mem_biUnion.mp mem have triple := disjointRange valid ⟨lower,upper⟩ hm have hlist : h∈WindowBankCheck.banks := by simpa [bankIds,WindowBankCheck.banks] using hm exact WindowBankCheck.packet_free h k hlist triple.1 triple.2.1 triple.2.2 d q hq used end ECDSAAdd.Entrant.StairPacket.WindowFieldMask end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldMask open Arithmetic MappedCompressed StairArchiveRelease StairArchiveNativeCut StairArchiveInactive open ArchiveFieldScratch StairArchiveTen CodecBitSliceVerify set_option maxRecDepth 1600 set_option maxHeartbeats 400000 attribute [local irreducible] run packet fieldPort StairArchiveNativeCut.canonical inputCols outputCols CodecBitSliceVerify.get private theorem memberList {j : Nat} (h : j∈bankIds) : j∈WindowBankCheck.banks := by simpa [bankIds,WindowBankCheck.banks] using h private theorem geometry {j : Nat} (h : j∈bankIds) : j∈ECDSAAdd.Entrant.StairPacket.Shadow20.MixedFieldBanks.mixedBankList ∧ j∈List.range' 1 83 := by simp only [bankIds,Finset.mem_insert,Finset.mem_singleton] at h rcases h with rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl <;> decide private theorem apart {j : Nat} (hj : j∈bankIds) : ∀ q∈inside j, q∉others j := by intro q hi ho obtain ⟨k,hk,mem⟩ := Finset.mem_biUnion.mp ho obtain ⟨ne,kid⟩ := Finset.mem_erase.mp hk exact WindowBankCheck.separate j k (memberList hj) (memberList kid) ne.symm q hi mem private theorem native_safe (j k : Nat) (hj : j∈bankIds) (which : k=j ∨ k=j+1) (d : Bool) : avoids (packet d k) (others j) := by intro q ho used obtain ⟨h,hm,mem⟩ := Finset.mem_biUnion.mp ho obtain ⟨ne,hid⟩ := Finset.mem_erase.mp hm apply WindowBankCheck.packet_free h k (memberList hid) _ _ _ d q mem used all_goals simp only [bankIds,Finset.mem_insert,Finset.mem_singleton] at hj hid · apply List.mem_range'_1.mpr; omega all_goals omega private theorem hook_safe (j : Nat) (hj : j∈bankIds) (s : Stage) : avoids (fieldHook j s) (others j) := by intro q ho used rw [fieldHook,renameProgram_support] at used obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp used exact apart hj _ (Finset.mem_image.mpr ⟨i,sub s hi,rfl⟩) ho private theorem append_safe {P Q : Program} {W : Finset Wire} (p : avoids P W) (q : avoids Q W) : avoids (P++Q) W := by intro i hi used rw [wires_append, Finset.mem_union] at used exact used.elim (p i hi) (q i hi) def update (code : Nat→Cols) (j : Nat) (out : Cols) := fun k => if k=j then out else code k attribute [local irreducible] inside StairArchiveRelease.fieldHook StairArchiveTen.first StairArchiveTen.second StairArchiveTen.ten end ECDSAAdd.Entrant.StairPacket.WindowFieldMask end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldJourney open Arithmetic MappedCompressed StairArchiveRelease StairArchiveNativeCut StairArchiveTen open CodecBitSliceVerify WindowFieldMask WindowFieldCosts ArchiveFieldScratch attribute [local irreducible] run measurementCount WindowFieldCosts.group StairArchiveTen.ten refExit inputCols outputCols StairArchiveNativeCut.canonical enter leave inductive Leg where | native (j n : Nat) | paired (j : Nat) def emitted (d : Bool) : Leg → Program | .native j n => group d j n | .paired j => ten j (!d) def stock (d : Bool) (m : List Bool) (r : State) : Leg → State | .native j n => run (group d j n) m r | .paired j => refExit j (!d) m r def codes (d : Bool) (c : Nat→Cols) : Leg → Nat→Cols | .native _ _ => c | .paired j => update c j (outputCols (leave (!d))) def nextTape (d : Bool) (l : Leg) (m : List Bool) := m.drop (measurementCount (emitted d l)) def concatenate (d : Bool) : List Leg → Program | [] => [] | l::ls => emitted d l ++ concatenate d ls def destination (d : Bool) : List Leg → List Bool → State → State | [],_,r => r | l::ls,m,r => destination d ls (nextTape d l m) (stock d m r l) def finalCode (d : Bool) : List Leg → (Nat→Cols) → Nat→Cols | [],c => c | l::ls,c => finalCode d ls (codes d c l) def validLeg (d : Bool) (c : Nat→Cols) : Leg → Prop | .native j n => nativeRanges j n | .paired j => j∈bankIds ∧ c j=inputCols (enter (!d)) def valid (d : Bool) : List Leg → (Nat→Cols) → Prop | [],_ => True | l::ls,c => validLeg d c l ∧ valid d ls (codes d c l) def plan : Bool→List Leg | true => [.native 1 9,.paired 10,.native 12 1,.paired 13,.native 15 1,.paired 16,.native 18 1,.paired 19,.native 21 1,.paired 22,.native 24 1,.paired 25,.native 27 1,.paired 28,.native 30 1,.paired 31,.native 33 2,.paired 35,.native 37 2,.paired 39,.native 41 2,.paired 43,.native 45 2,.paired 47,.native 49 2,.paired 51,.native 53 2,.paired 55,.native 57 2,.paired 59,.native 61 2,.paired 63,.native 65 2,.paired 67,.native 69 1,.paired 70,.native 72 1,.paired 73,.native 75 1,.paired 76,.native 78 1,.paired 79,.native 81 1,.paired 82,.native 84 1] | false => [.native 84 1,.paired 82,.native 81 1,.paired 79,.native 78 1,.paired 76,.native 75 1,.paired 73,.native 72 1,.paired 70,.native 69 1,.paired 67,.native 65 2,.paired 63,.native 61 2,.paired 59,.native 57 2,.paired 55,.native 53 2,.paired 51,.native 49 2,.paired 47,.native 45 2,.paired 43,.native 41 2,.paired 39,.native 37 2,.paired 35,.native 33 2,.paired 31,.native 30 1,.paired 28,.native 27 1,.paired 25,.native 24 1,.paired 22,.native 21 1,.paired 19,.native 18 1,.paired 16,.native 15 1,.paired 13,.native 12 1,.paired 10,.native 1 9] def initialCode (d : Bool) : Nat→Cols := fun _=>inputCols (enter (!d)) private theorem valid_plan (d : Bool) : valid d (plan d) (initialCode d) := by cases d <;> simp [valid,plan,validLeg,nativeRanges,bankIds,codes,update,initialCode] end ECDSAAdd.Entrant.StairPacket.WindowFieldJourney end section namespace ECDSAAdd.Entrant.Stair44DivTerm open ECDSAAdd Arithmetic MappedCompressed Secp256k1 OB5 open Rolling1588.Integer set_option maxRecDepth 30000 set_option maxHeartbeats 8000000 set_option linter.unusedSimpArgs false attribute [local irreducible] run wires measurementCount Rolling1588.forward Rolling1588.reverse Rolling1588.Integer.forward regularForward abbrev Z1 : Program := renameProgram (sig 510) (Rolling1588.Integer.decodeBefore base false 510 ++ tickMR8) abbrev Z2 : Program := renameProgram (sig 507) (W.ReverseCarry.compactReceiverTick base 507) abbrev Y : Program := (renameProgram (sig 510) (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510) ++ renameProgram (sig 509) (W.ReverseCarry.compactReceiverTick base 509)) ++ renameProgram (sig 508) (W.ReverseCarry.compactReceiverTick base 508) theorem stage_after (x : Nat) (hx0 : 0 < x) (hx : x < p) (s1 : State) (first : W.CompactSkywalkStage base (SkywalkRails.encode false false (x:Int) (p:Int)) 1 s1.basis) (k : Nat) (hk : 1 + k ≤ 512) (m : List Bool) : Rolling1588.Integer.Stage base false x p (1 + k) (run (Rolling1588.Integer.regularForward base false 1 k) m s1).basis := by obtain ⟨hp0,hpo,hp,cop⟩ := StackOB5.prime_facts x hx0 hx have gap : p+2^32 ≤ 2^256 := by norm_num [p] exact ((Rolling1588.Integer.regularForward_spec base false base_pool_nodup StackOB5.historyAbove x p 1 k hp0 hx0 hpo hp gap hx cop hk) s1 m (Rolling1588.Integer.stage_one base false x p s1 first)).2 abbrev Q2 : Program := renameProgram (sig 506) (W.ReverseCarry.compactReceiverTick base 506) theorem run_congr_append (A A' B : Program) (s : State) (h : ∀ r, run A r s = run A' r s) (hc : measurementCount A = measurementCount A') (r : List Bool) : run (A ++ B) r s = run (A' ++ B) r s := by rw [run_append, run_append, hc, h] theorem cZ : measurementCount Z1 = measurementCount Y := by decide +kernel theorem agree_split (u s1 : State) (M : List Bool) (A B : Program) (h : Rolling1588.Integer.regularForward base false 1 510 = A ++ B) (hu : ∀ q ∈ skywalkPoolWires base, u.basis q = (run (Rolling1588.Integer.regularForward base false 1 510) M s1).basis q) : ∀ q ∈ skywalkPoolWires base, u.basis q = (run B (M.drop (measurementCount A)) (run A (M.take (measurementCount A)) s1)).basis q := by intro q hq rw [hu q hq, h, run_append] abbrev Q1 : Program := renameProgram (sig 510) (Rolling1588.unpackAtTick false 510 ++ InverseFour15.candidate15) theorem PE2 : renameProgram (sig 510) (Rolling1588.unpackAtTick false 510 ++ InverseFour15.old15) = Z1 ++ Z2 := by rw [InverseFour15.unpack51015] simp only [Z1, Z2, InverseFour15.same50715, InverseFour15.old15, Six505.rename_append, List.append_assoc] theorem cQ : measurementCount Q1 = measurementCount (Y ++ Z2) := by decide +kernel theorem split507 : Rolling1588.Integer.regularForward base false 1 510 = Rolling1588.Integer.regularForward base false 1 506 ++ ((MorningFour.tick507 ++ tripF) ++ Rolling1588.Integer.packAfter base false 510) := by rw [Rolling1588.Integer.regularForward_snoc base false 1 509,show (1:Nat)+509=510 by rfl, Rolling1588.Integer.regularForward_snoc base false 1 508,show (1:Nat)+508=509 by rfl, Rolling1588.Integer.regularForward_snoc base false 1 507,show (1:Nat)+507=508 by rfl, Rolling1588.Integer.regularForward_snoc base false 1 506,show (1:Nat)+506=507 by rfl, MorningPlacement.pack507,Rolling1588.Integer.pack508,Rolling1588.Integer.pack509, MorningFour.explicit507,tick508ExF_explicit,tick509ExF_explicit,tick510ExF_explicit] simp only [tripF,List.append_assoc,List.append_nil] abbrev P1 : Program := renameProgram (sig 510) (Rolling1588.unpackAtTick false 510 ++ InverseFive23.candidate15) theorem PE1 : renameProgram (sig 510) (Rolling1588.unpackAtTick false 510 ++ TerminalFivePlacement.old) = Q1 ++ Q2 := by rw [Six505.rename_append, TerminalFivePlacement.old_placed] simp only [Q1, Q2, Six505.rename_append, List.append_assoc] rfl theorem split506 : Rolling1588.Integer.regularForward base false 1 510 = Rolling1588.Integer.regularForward base false 1 505 ++ (TerminalFiveBridge.forward ++ Rolling1588.Integer.packAfter base false 510) := by rw [Rolling1588.Integer.regularForward_snoc base false 1 509,show (1:Nat)+509=510 by rfl, Rolling1588.Integer.regularForward_snoc base false 1 508,show (1:Nat)+508=509 by rfl, Rolling1588.Integer.regularForward_snoc base false 1 507,show (1:Nat)+507=508 by rfl, Rolling1588.Integer.regularForward_snoc base false 1 506,show (1:Nat)+506=507 by rfl, Rolling1588.Integer.regularForward_snoc base false 1 505,show (1:Nat)+505=506 by rfl, InverseFive23.pack506,MorningPlacement.pack507,Rolling1588.Integer.pack508, Rolling1588.Integer.pack509, MorningFour.explicit507,tick508ExF_explicit,tick509ExF_explicit,tick510ExF_explicit] simp only [TerminalFiveBridge.forward,tripF,List.append_assoc,List.append_nil] theorem split508 : Rolling1588.Integer.regularForward base false 1 510 = Rolling1588.Integer.regularForward base false 1 507 ++ (((W.repairedTick base 508 ++ W.repairedTick base 509) ++ W.repairedTick base 510) ++ Rolling1588.Integer.packAfter base false 510) := by rw [Rolling1588.Integer.regularForward_snoc base false 1 509,show (1:Nat)+509=510 from rfl, Rolling1588.Integer.regularForward_snoc base false 1 508,show (1:Nat)+508=509 from rfl, Rolling1588.Integer.regularForward_snoc base false 1 507,show (1:Nat)+507=508 from rfl, Rolling1588.Integer.pack508 false,Rolling1588.Integer.pack509 false] simp only [List.append_assoc,List.append_nil] theorem PE4 : (Y ++ Z2) ++ Q2 = Rolling1588.Integer.reverse false 506 5 := by decide +kernel end ECDSAAdd.Entrant.Stair44DivTerm end section namespace ECDSAAdd.Entrant.Stair44HostedCut open ECDSAAdd Arithmetic StairField13V3 StairConcreteAssembly set_option maxRecDepth 30000 attribute [local irreducible] run wires private theorem takeCuts (pre : State → Prop) (j : Nat) : ∀ ps : List Piece, ∀ X : Program, Cuts pre X ps → Cuts pre X (ps.take j) := by induction j with | zero => intro ps X _; trivial | succ j ih => intro ps X hc cases ps with | nil => trivial | cons p ps => exact ⟨hc.1,hc.2.1,ih ps (X ++ p.L) hc.2.2⟩ theorem runPrefix (pre : State → Prop) (ps : List Piece) (j : Nat) (loc : ∀ p∈ps,p.Local) (cuts : ∀ i (hi : i by simpa only [List.nil_append] using cuts i hi) exact run_eq_of_cuts pre (ps.take j) [] (fun pc h => loc pc (List.mem_of_mem_take h)) (takeCuts pre j ps [] all) s hs m theorem entry (j : Nat) (s : State) (hs : EntryPre s) (m : List Bool) : let ps := entryPieces checkpointPrimitives hostPlan run (((ps.take j).map Piece.H).flatten) m s=run (((ps.take j).map Piece.L).flatten) m s := by have c := StairField13V3Clean.entryClean_of_planR StairOpenWiring.entryPlans StairOpenWiring.half760 have cuts := entrySlotsClean_of _ _ _ (entrySlots_of_v3 (entrySlotsV3_of_parts (StairField13V3Fresh.entryParts_of_clean c))) exact runPrefix _ _ _ (entryPieces_local _ _) cuts s hs m theorem exit (k j : Nat) (s : State) (hs : ExitPre k s) (m : List Bool) : let ps := exitPieces checkpointPrimitives hostPlan k run (((ps.take j).map Piece.H).flatten) m s=run (((ps.take j).map Piece.L).flatten) m s := by have c := StairField13V3Clean.exitClean_of_planR StairOpenWiring.exitPlans StairOpenWiring.half760 k have cuts := exitSlotsClean_of _ _ _ _ (exitSlots_of_v3 k (exitSlotsV3_of_parts k (StairField13V3Fresh.exitParts_of_clean k c))) exact runPrefix _ _ _ (exitPieces_local _ _ k) cuts s hs m end ECDSAAdd.Entrant.Stair44HostedCut end section namespace ECDSAAdd.Entrant.Stair44OuterX open Arithmetic Secp256k1 ControlledPointLayout MappedCompressed CompressedPointDialog CompressedAllocation CompressedFieldSupport DirectSkywalk E1QubitPlacement Baselines ParityXEntry FlagEntry ParityEven Stair44PointMap set_option maxRecDepth 30000 set_option maxHeartbeats 1800000 attribute [local irreducible] run wires layout pmapR def cleanIndex (i : Nat) : Prop := i < 515 ∨ (1026 ≤ i ∧ i < 1285) ∨ (1540 ≤ i ∧ i < 1798) ∨ i = 721 ∨ i = 722 private theorem pool (i : Nat) (hi : cleanIndex i) : pmapR layout (base i) ∈ layout.dialogPool := by apply pmap_pool _ layout_widths layout_nodup · exact List.mem_toFinset.mpr (E1Merge.in_mSites base (base 2400) i (by unfold cleanIndex at hi; omega)) · intro h obtain ⟨j,hj,e⟩ := List.mem_map.mp h simp only [List.mem_range'_1] at hj have := base_injective e unfold cleanIndex at hi omega · intro e; have := base_injective e; unfold cleanIndex at hi; omega private def exitIndices : List Nat := [1542,1541,721,722,500,501,502,503,504,514] private theorem direct (s : State) (m : List Bool) (X : Nat) (hx : regValue layout.point.x s.basis=X) (hX : X s.basis (f q)) = X rw [regValue_pull,pmap_x layout layout_widths layout_nodup,hx] have kv : regValue (E1Merge.kR base) t.basis = X := by rw [E1Merge.kR_x base base_pool_nodup, show E1Merge.xR base=wireBlock base 770 256 from rfl, Hx,blk 1026 2 (by decide)] simp have seed : LiteralSkywalkSeedValues (literalSkywalkPoolSeed base) 0 X t.basis := ⟨blk 0 258 (by decide), kv, blk 1540 257 (by decide), cl 1797 (by unfold cleanIndex; decide), cl 1028 (by unfold cleanIndex; decide),cl 1797 (by unfold cleanIndex; decide)⟩ have range : cleanIndex i := by simp [exitIndices] at hi; unfold cleanIndex; omega have isS : base i∈S := List.mem_toFinset.mpr (E1Merge.in_mSites base (base 2400) i (by unfold cleanIndex at range; omega)) have phys := run_rename_pool f S (pmap_inj _ layout_widths layout_nodup) _ forward_S m t s rfl (fun _ _ => rfl) rw [E1QubitPlacement.tickF,phys.2 _ isS] have out := NativeFirstDirect.forward_spec base base_pool_nodup X hX t m seed have cold : base i∉NativeFirstDirect.mutable base := (by decide +kernel : ∀ i ∈ exitIndices,base i∉NativeFirstDirect.mutable base) i hi exact (out.2.2.2.2.2 _ cold).trans (cl i range) theorem tickZero (s : State) (m : List Bool) (X : Nat) (hx : regValue layout.point.x s.basis=X) (hX : X facts.2.2 q ((E1QubitPlacement.lay layout layout_widths layout_nodup q).2.1 hq).1)).trans hc apply direct s1 _ _ facts.2.1 _ fresh i hi exact Nat.mod_lt _ (by decide) theorem stockExit (X k : Fp) (s : State) (m : List Bool) (hx : regValue layout.point.x s.basis=X.val) (hc : regValue layout.dialogPool s.basis=0) : ∀ q∈firstClean, (run (entryXNew layout (pkW layout) k) m (put s (pkW layout) (if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val+k.val) else false))).basis q=false := by rw [entryXNew_run layout layout_widths layout_nodup _ X k s hx hc (pk_pool layout layout_widths) (pk_ne_flag layout layout_widths layout_nodup) (pk_ne_high layout layout_widths layout_nodup) (pk_ne_x layout layout_widths layout_nodup) (by rw [pmap_g layout layout_widths layout_nodup]; decide +kernel), entryXAll_eq layout layout_widths layout_nodup X k s _ hx hc] have mapTable : ∀ q∈firstClean, ∃i∈exitIndices, pmapR layout (base i)=q := by decide +kernel intro q hq obtain ⟨i,hi,rfl⟩ := mapTable q hq exact afterAdd k s _ X hx hc i hi theorem execute (X k : Fp) (s : State) (m : List Bool) (hx : regValue layout.point.x s.basis=X.val) (hc : regValue layout.dialogPool s.basis=0) : let P := entryXNew layout (pkW layout) k let logical := put s (pkW layout) (if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val+k.val) else false) run (switchX P) m (pullState outer.symm logical) = pullState integerFirst.symm (run P m logical) := by intro P logical have prep : ∀q∈([4836,4629]:List Wire), logical.basis q=false := by have table : ∀q∈([4836,4629]:List Wire),q∈layout.dialogPool ∧ q≠pkW layout := by decide +kernel intro q hq have ⟨member,notFlag⟩ := table q hq change (put s (pkW layout) _).basis q = false simpa [put,writeBit,Function.update_apply,notFlag] using (regValue_zero _ _).mp hc q member have full (e : Equiv.Perm Wire) (a : State) : pullState e (pullState e.symm a) = a := by apply State.extensionality · rfl · funext q; exact congrArg a.basis (e.symm_apply_apply q) rw [at_x_input logical prep, ← at_x_output _ (stockExit X k s m hx hc)] have r := run_rename duringX duringX.injective P m (pullState duringX.symm logical) rw [full] at r have e := congrArg (pullState duringX.symm) r have back (a : State) : pullState duringX.symm (pullState duringX a)=a := by simpa only [Equiv.symm_symm] using full duringX.symm a rw [back] at e exact e end ECDSAAdd.Entrant.Stair44OuterX end section namespace ECDSAAdd.Entrant.Stair44WalkCuts open Arithmetic MappedCompressed Stair44WalkMap set_option maxRecDepth 8000 attribute [local irreducible] run wires Rolling1588TickGap.forward Rolling1588.Integer.regularForward theorem release (s : State) (hp : ∀q∈Stair44WalkExit.atExit,s.basis q=false) (h : s.basis (base 514)=false) : pullState rest s=s := by have a := cleanWireRebind id s s _ _ rfl (hp _ (by decide : base 1026∈Stair44WalkExit.atExit)) h have b := cleanWireRebind _ s s _ _ a (hp _ (by decide : base 1541∈Stair44WalkExit.atExit)) (hp _ (by decide : base (Placement5.H 1)∈Stair44WalkExit.atExit)) exact cleanWireRebind _ s s _ _ b (hp _ (by decide : base 1542∈Stair44WalkExit.atExit)) (hp _ (by decide : base (Placement5.H 0)∈Stair44WalkExit.atExit)) private theorem cancel (e : Equiv.Perm Wire) {s t : State} (h : pullState e s = pullState e t) : s=t := by apply State.extensionality · have r := congrArg State.phase h exact r · funext q; simpa only [pullState, Equiv.apply_symm_apply] using congrFun (congrArg State.basis h) (e.symm q) theorem forward_done (d : Bool) (a x : Nat) (atCut : 1+(15+a) ∈ [425,505,506]) (hx0 : 0 get integer_load0Trace0In ((if high then 10 else 0)+q)) /-- The literal incumbent's complete encoding program acts on the unmodified chronological G/S pairs. The byte uses the same eight physical slots for both A and B. -/ theorem stock_code (isA high : Bool) : eval ones (Rolling1588.codeEncode isA) (chronological high) = (true, storage (native isA high)) := by cases isA <;> cases high <;> decide +kernel end ECDSAAdd.Entrant.StairArchiveNativeRows end section namespace ECDSAAdd.Entrant.StairPacket open Arithmetic MappedCompressed IntegerPacket SkywalkRails ArchivePortAction set_option maxRecDepth 18000 set_option maxHeartbeats 2300000 attribute [local irreducible] run routed measurementCount body namespace NativePack270 open ArchiveBoundary270 end NativePack270 end ECDSAAdd.Entrant.StairPacket end section namespace ECDSAAdd.Entrant.StairPacket.WideReference open Arithmetic MappedCompressed attribute [local irreducible] run W.compactSkywalkTick theorem pastOffSpan (i n q:Nat) (bound:i+n≤512) (early:Earlier i q) : q∉wires (span i n) := by induction n generalizing i with | zero => simp [span,wires] | succ n ih => rw [span,wires_append,Finset.mem_union] rintro (head|tail) · have sub:=W.compactSkywalkTick_support base i (by omega) base_pool_nodup exact away (by omega) early (List.mem_toFinset.mp (sub head)) · exact ih (i+1) (by omega) (earlier_mono (by omega) early) tail theorem preservePast (i n x p r:Nat) (bound:i+n≤512) (good:Bounds x p) (raw:State) (dom:Domain i x p raw) (rOld:r < i) (m:List Bool) : let out:=run (span i n) m raw out.basis (base r)=raw.basis (base r) ∧ out.basis (base (1028+r))=raw.basis (base (1028+r)) := by by_cases old:r+2 ≤ i · exact ⟨run_preserves_outside _ _ _ _ (pastOffSpan _ _ _ bound ⟨r,old,Or.inl rfl⟩), run_preserves_outside _ _ _ _ (pastOffSpan _ _ _ bound ⟨r,old,Or.inr rfl⟩)⟩ obtain ⟨ref,same,stage⟩:=dom have h1:¬Earlier i (base r) := by rintro ⟨k,prev,h|h⟩ <;> simp only [base,Wire] at * <;> omega have h2:¬Earlier i (base (1028+r)) := by rintro ⟨k,prev,h|h⟩ <;> simp only [base,Wire] at * <;> omega have link:=fixed_span i i n (Nat.le_refl _) bound raw ref m same have endStage:=full_span i n x p bound good.positive good.nonzero good.odd good.cap good.gap good.small good.coprime ref m stage have before:=(W.compactSkywalkStage_fields_iff base _ i (by omega) base_pool_nodup _).mp stage have after:=(W.compactSkywalkStage_fields_iff base _ (i+n) bound base_pool_nodup _).mp endStage have a:=before.2.2.2.1 r rOld have b:=after.2.2.2.1 r (by omega) exact ⟨(link.2 _ h1).trans (b.1.trans (a.1.symm.trans (same.2 _ h1).symm)), (link.2 _ h2).trans (b.2.trans (a.2.symm.trans (same.2 _ h2).symm))⟩ end ECDSAAdd.Entrant.StairPacket.WideReference end section namespace ECDSAAdd.Entrant.StairPacket.StockCanonicalRow open Arithmetic ArchivePortAction SkywalkRails IntegerPacket StairArchiveRaw CodecBitSliceVerify StairArchiveTrace set_option maxRecDepth 18000 set_option maxHeartbeats 3000000 def key (b:Nat) (z:SkywalkNat.State) (cross:Bool) (trace:List (Bool×Bool)) (q:Nat):Bool:= let f:=decide (Shadow.far b 15 z) rawBit (read (trace.drop 5)) f (f && afterFlags (decide (z.vn.testBit r) (io true true ⟨q,by omega⟩).1).trans (frame ⟨q,by omega⟩).symm).trans (kept q) by_cases h:q.val<20 · have eq:=row_truth j ps chron r z g sg before out prior.records kept frame ⟨q,h⟩ simpa only [key,rawBit,if_pos h] using eq · rcases q with ⟨q,bound⟩ change ¬q<20 at h have cases:q=20 ∨ q=21 ∨ q=22:=by omega rcases cases with rfl|rfl|rfl · exact same.trans prior.far · simpa only [←prior.records] using same.trans prior.suffix · exact same.trans prior.crossed theorem reframe {v r} (limit:r<63145) (eq:Encodes v r) (ps:Ports) (out:State) (frame:Frame ps raw r out):Frame ps raw (select v) out:=by have ⟨_,selected⟩:=select_spec ⟨r,limit,eq⟩ intro i rw [frame i] by_cases old:i.val<23 · have read:get raw i=rawCol i:=(io true true i).1.symm rw [read,eq ⟨i,old⟩,selected ⟨i,old⟩] · have empty:get raw i=0:=(blank true true i (by omega)).1 rw [empty,Nat.zero_testBit,Nat.zero_testBit] end ECDSAAdd.Entrant.StairPacket.StockCanonicalRow end section namespace ECDSAAdd.Entrant.StairPacket.StockDelayed open Arithmetic MappedCompressed WideReference Rolling1588.Integer Secp256k1 attribute [local irreducible] run W.compactSkywalkTick def packs (d:Bool) (i:Nat):Nat→Program | 0=>[] | n+1=>packAfter base d i ++ packs d (i+1) n private theorem off (d:Bool) (k i n:Nat) (lo:k < i) (hi:i+n≤512): Disjoint (wires (packAfter base d k)) (wires (span i n)):=by induction n generalizing i with | zero=>simp [span,wires] | succ n ih=> have offPre:=prefix_disjoint_tick base d base_pool_nodup (k+1) i lo (by omega) rw [encodePrefix,wires_append] at offPre have step:=Disjoint.mono_left (Finset.subset_union_right (s₁:=wires (encodePrefix base d k))) offPre have tail:=ih (i+1) (by omega) (by omega) rw [span,wires_append,Finset.disjoint_union_right];exact ⟨step,tail⟩ theorem deferred (d:Bool) (i n:Nat) (hi:i+n≤512) (s:State): run (compactForward base d i n) [] s=run (packs d i n) [] (run (span i n) [] s):=by induction n generalizing i s with | zero=>simp only [compactForward,packs,span,run] | succ n ih=> simp only [compactForward,packs,span,run_append,run_take,List.drop_nil] rw [ih (i+1) (by omega),run_disjoint_commute _ _ (off d i (i+1) n (by omega) (by omega))] theorem window (d:Bool) (x:Nat) (hx0:0 group d j n | .paired j => first j (!d) ++ second j (!d) def legTape (d : Bool) (m : List Bool) : Leg → List Bool | .native _ _ => m | .paired j => joinTapes (first j (!d)) (tapeA j (!d) m) (tapeB j (!d) m) def referenceTape0 (d : Bool) : List Leg → List Bool → List Bool | [],_ => [] | l::ls,m => joinTapes (referenceLeg d l) (legTape d m l) (referenceTape0 d ls (nextTape d l m)) /-- the reference tape of the record run, seen from the actual tape `m` of the field group. -/ def referenceTape (d : Bool) (ls : List Leg) (m : List Bool) : List Bool := referenceTape0 d ls (WindowFieldCosts.cellTape d m) set_option maxRecDepth 8000 set_option maxHeartbeats 900000 private theorem shape' (d : Bool) (p : Nat→Program) : PacketSequence.program d p 1 84 = let seq := PacketSequence.program d p if d then seq 1 9 ++ ((p 10 ++ p 11) ++ (seq 12 1 ++ ((p 13 ++ p 14) ++ (seq 15 1 ++ ((p 16 ++ p 17) ++ (seq 18 1 ++ ((p 19 ++ p 20) ++ (seq 21 1 ++ ((p 22 ++ p 23) ++ (seq 24 1 ++ ((p 25 ++ p 26) ++ (seq 27 1 ++ ((p 28 ++ p 29) ++ (seq 30 1 ++ ((p 31 ++ p 32) ++ (seq 33 2 ++ ((p 35 ++ p 36) ++ (seq 37 2 ++ ((p 39 ++ p 40) ++ (seq 41 2 ++ ((p 43 ++ p 44) ++ (seq 45 2 ++ ((p 47 ++ p 48) ++ (seq 49 2 ++ ((p 51 ++ p 52) ++ (seq 53 2 ++ ((p 55 ++ p 56) ++ (seq 57 2 ++ ((p 59 ++ p 60) ++ (seq 61 2 ++ ((p 63 ++ p 64) ++ (seq 65 2 ++ ((p 67 ++ p 68) ++ (seq 69 1 ++ ((p 70 ++ p 71) ++ (seq 72 1 ++ ((p 73 ++ p 74) ++ (seq 75 1 ++ ((p 76 ++ p 77) ++ (seq 78 1 ++ ((p 79 ++ p 80) ++ (seq 81 1 ++ ((p 82 ++ p 83) ++ (seq 84 1 ++ [])))))))))))))))))))))))))))))))))))))))))))) else seq 84 1 ++ ((p 83 ++ p 82) ++ (seq 81 1 ++ ((p 80 ++ p 79) ++ (seq 78 1 ++ ((p 77 ++ p 76) ++ (seq 75 1 ++ ((p 74 ++ p 73) ++ (seq 72 1 ++ ((p 71 ++ p 70) ++ (seq 69 1 ++ ((p 68 ++ p 67) ++ (seq 65 2 ++ ((p 64 ++ p 63) ++ (seq 61 2 ++ ((p 60 ++ p 59) ++ (seq 57 2 ++ ((p 56 ++ p 55) ++ (seq 53 2 ++ ((p 52 ++ p 51) ++ (seq 49 2 ++ ((p 48 ++ p 47) ++ (seq 45 2 ++ ((p 44 ++ p 43) ++ (seq 41 2 ++ ((p 40 ++ p 39) ++ (seq 37 2 ++ ((p 36 ++ p 35) ++ (seq 33 2 ++ ((p 32 ++ p 31) ++ (seq 30 1 ++ ((p 29 ++ p 28) ++ (seq 27 1 ++ ((p 26 ++ p 25) ++ (seq 24 1 ++ ((p 23 ++ p 22) ++ (seq 21 1 ++ ((p 20 ++ p 19) ++ (seq 18 1 ++ ((p 17 ++ p 16) ++ (seq 15 1 ++ ((p 14 ++ p 13) ++ (seq 12 1 ++ ((p 11 ++ p 10) ++ (seq 1 9 ++ [])))))))))))))))))))))))))))))))))))))))))))) := by cases d <;> simp [PacketSequence.program,List.append_assoc] end ECDSAAdd.Entrant.StairPacket.WindowFieldJourney end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityDirty abbrev Hops := List (Wire×Wire) /-- Each step adds previous carry times a control into a borrowed bit. The identical gate on exit restores its original value. -/ def chain (src last target : Wire) : Hops→Program | [] => [.CCX src last target] | (c,b)::xs => [.CCX src c b] ++ chain b last target xs ++ [.CCX src c b] def mcx (a b src last t : Wire) (xs : Hops) := chain src last t xs ++ ([Instr.CCX a b src] ++ (chain src last t xs ++ [Instr.CCX a b src])) inductive Aff where | x (dst : Wire) | cx (src dst : Wire) deriving DecidableEq def gate : Aff→Instr | .x w => .X w | .cx c w => .CX c w end ECDSAAdd.Entrant.StairPacket.WindowParityDirty namespace ECDSAAdd.Entrant.StairPacket.WindowFieldParity open Arithmetic MappedCompressed WindowParityDirty def region : Program := [] def site (j i : Nat) := OB5.sig 511 (NewHistory5.payloadWire base (8*j+i)) def other (j : Nat) := if j=43 then 47 else 43 def port (j q : Nat) : Wire := if q<16 then site j q else if q=16 then FrontierEntry1591Field.host else site (other j) (q-17) def bankCorrection (j : Nat) := renameProgram (port j) region def correction := bankCorrection 10 ++ (bankCorrection 13 ++ (bankCorrection 16 ++ (bankCorrection 19 ++ (bankCorrection 22 ++ (bankCorrection 25 ++ (bankCorrection 28 ++ (bankCorrection 31 ++ (bankCorrection 35 ++ (bankCorrection 39 ++ (bankCorrection 43 ++ (bankCorrection 47 ++ (bankCorrection 51 ++ (bankCorrection 55 ++ (bankCorrection 59 ++ (bankCorrection 63 ++ (bankCorrection 67 ++ (bankCorrection 70 ++ (bankCorrection 73 ++ (bankCorrection 76 ++ (bankCorrection 79 ++ (bankCorrection 82))))))))))))))))))))) def setup := StairSchedule.paritySetup ++ correction end ECDSAAdd.Entrant.StairPacket.WindowFieldParity end section namespace ECDSAAdd.Entrant.Stair44DivTerm open ECDSAAdd Arithmetic MappedCompressed Secp256k1 OB5 open Rolling1588.Integer set_option maxRecDepth 30000 set_option maxHeartbeats 8000000 set_option linter.unusedSimpArgs false attribute [local irreducible] run wires measurementCount Rolling1588.forward Rolling1588.reverse Rolling1588.Integer.forward regularForward theorem key510 (x : Nat) (hx0 : 0 < x) (hx : x < p) (a u : State) (stage : Rolling1588.Integer.Stage base false x p 508 a.basis) (r2 : List Bool) (hu : ∀ q ∈ skywalkPoolWires base, u.basis q = (run (((W.repairedTick base 508 ++ W.repairedTick base 509) ++ W.repairedTick base 510) ++ Rolling1588.Integer.packAfter base false 510) r2 a).basis q) (r : List Bool) : run Z1 r (pullState (sig 510) u) = run Y r (pullState (sig 510) u) := by obtain ⟨hp0,hpo,hp,cop⟩ := StackOB5.prime_facts x hx0 hx have hgap : p+2^32 ≤ 2^256 := by norm_num [p] have pool : ∀ q∈sitesT8,q∈(skywalkPoolWires base).toFinset := fun q hq => List.mem_toFinset.mpr (sitesT8_pool q hq) have dec : wires (Rolling1588.Integer.decodeBefore base false 510)⊆(skywalkPoolWires base).toFinset := by have d := (History5.pack_support5 base 510 (by omega)).2.trans (History5.integerSites5_pool base) rw [←Rolling1588.Integer.decodeBefore_support_eq base false 510] at d exact d have hB : wires (Rolling1588.Integer.decodeBefore base false 510 ++ tickMR8)⊆(skywalkPoolWires base).toFinset := by rw [wires_append,Finset.union_subset_iff] exact ⟨dec,fun q hq => pool q (List.mem_toFinset.mp (tickMR8_wires hq))⟩ have u10 := Rolling1588.Integer.untick_pool base false base_pool_nodup 510 (by omega) have u9 := Rolling1588.Integer.untick_pool base false base_pool_nodup 509 (by omega) rw [Rolling1588.Integer.decode509 false,List.nil_append] at u9 have u8 := Rolling1588.Integer.untick_pool base false base_pool_nodup 508 (by omega) rw [Rolling1588.Integer.decode508 false,List.nil_append] at u8 have hO : wires (Rolling1588.Integer.decodeBefore base false 510 ++ ((W.ReverseCarry.compactReceiverTick base 510 ++ W.ReverseCarry.compactReceiverTick base 509) ++ W.ReverseCarry.compactReceiverTick base 508))⊆(skywalkPoolWires base).toFinset := by rw [←List.append_assoc,←List.append_assoc,wires_append,wires_append,Finset.union_subset_iff, Finset.union_subset_iff] exact ⟨⟨u10,u9⟩,u8⟩ have inner (r : List Bool) : run (Rolling1588.Integer.decodeBefore base false 510 ++ tickMR8) r u= run (Rolling1588.Integer.decodeBefore base false 510 ++ ((W.ReverseCarry.compactReceiverTick base 510 ++ W.ReverseCarry.compactReceiverTick base 509) ++ W.ReverseCarry.compactReceiverTick base 508)) r u := Stack5.local_replace _ _ _ hB hO u _ r r (fun q hq => hu q (List.mem_toFinset.mp hq)) (Rolling1588.Integer.blockN_eq_new false x hx0 hx a stage r2 r) have s9 := (Rolling1588.Integer.step_spec base false base_pool_nodup StackOB5.historyAbove x p 508 hp0 hx0 hpo hp hgap hx cop (by omega) a [] stage).2 simp only [Rolling1588.Integer.pack508 false,List.append_nil] at s9 obtain ⟨b8,hb8⟩ : ∃ b8 : State,run (W.repairedTick base 508) [] a=b8 := ⟨_,rfl⟩ rw [hb8] at s9 have s10 := (Rolling1588.Integer.step_spec base false base_pool_nodup StackOB5.historyAbove x p 509 hp0 hx0 hpo hp hgap hx cop (by omega) b8 [] s9).2 simp only [Rolling1588.Integer.pack509 false,List.append_nil] at s10 obtain ⟨b9,hb9⟩ : ∃ b9 : State,run (W.repairedTick base 509) [] b8=b9 := ⟨_,rfl⟩ rw [hb9] at s10 have rawE : run (((W.repairedTick base 508 ++ W.repairedTick base 509) ++ W.repairedTick base 510) ++ Rolling1588.Integer.packAfter base false 510) [] a= run (W.repairedTick base 510 ++ Rolling1588.Integer.packAfter base false 510) [] b9 := by rw [←hb9,←hb8] simp only [List.append_assoc,run_append,List.take_nil,List.drop_nil] have hu' : ∀ q∈skywalkPoolWires base, u.basis q=(run (W.repairedTick base 510 ++ Rolling1588.Integer.packAfter base false 510) [] b9).basis q := by intro q hq rw [hu q hq,←rawE] exact congrFun (run_basis_records _ a a r2 [] rfl) q have z10 := Rolling1588.Integer.stage_zero false x 510 (by omega) b9.basis s10 have z9 := Rolling1588.Integer.stage_zero false x 509 (by omega) b8.basis s9 have c9 := Rolling1588.Integer.stage_zero_gen false x 508 509 (by omega) (by omega) a.basis stage have c10 := Rolling1588.Integer.stage_zero_gen false x 508 510 (by omega) (by omega) a.basis stage have rt10 (r1 : List Bool) := Rolling1588.Integer.oneStep_roundtrip base false base_pool_nodup x p 510 hp0 hx0 hpo hp hgap hx cop (by omega) b9 s10 [] r1 have rt9 (r1 : List Bool) := Rolling1588.Integer.oneStep_roundtrip base false base_pool_nodup x p 509 hp0 hx0 hpo hp hgap hx cop (by omega) b8 s9 [] r1 simp only [Rolling1588.Integer.decode509 false,Rolling1588.Integer.pack509 false,List.nil_append,List.append_nil,hb9] at rt9 have rt8 (r1 : List Bool) := Rolling1588.Integer.oneStep_roundtrip base false base_pool_nodup x p 508 hp0 hx0 hpo hp hgap hx cop (by omega) a stage [] r1 simp only [Rolling1588.Integer.decode508 false,Rolling1588.Integer.pack508 false,List.nil_append,List.append_nil,hb8] at rt8 have rn10 := (renameProgram_counts (sig 510) (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510)).2 have rn9 := (renameProgram_counts (sig 509) (W.ReverseCarry.compactReceiverTick base 509)).2 show run (renameProgram (sig 510) (Rolling1588.Integer.decodeBefore base false 510 ++ tickMR8)) r (pullState (sig 510) u)= run ((renameProgram (sig 510) (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510) ++ renameProgram (sig 509) (W.ReverseCarry.compactReceiverTick base 509)) ++ renameProgram (sig 508) (W.ReverseCarry.compactReceiverTick base 508)) r (pullState (sig 510) u) rw [OB5.run_rename 510 (by omega),inner r] have e : Rolling1588.Integer.decodeBefore base false 510 ++ ((W.ReverseCarry.compactReceiverTick base 510 ++ W.ReverseCarry.compactReceiverTick base 509) ++ W.ReverseCarry.compactReceiverTick base 508)= ((Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510) ++ W.ReverseCarry.compactReceiverTick base 509) ++ W.ReverseCarry.compactReceiverTick base 508 := by simp only [List.append_assoc] rw [e,Rolling1588.Integer.run_append3,Rolling1588.Integer.run_append3,rn10,rn9] obtain ⟨r1,hr1⟩ : ∃ r1 : List Bool,r.take (measurementCount (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510))=r1 := ⟨_,rfl⟩ obtain ⟨r3,hr3⟩ : ∃ r3 : List Bool,(r.drop (measurementCount (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510))).take (measurementCount (W.ReverseCarry.compactReceiverTick base 509))=r3 := ⟨_,rfl⟩ obtain ⟨r5,hr5⟩ : ∃ r5 : List Bool,r.drop (measurementCount (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510)+ measurementCount (W.ReverseCarry.compactReceiverTick base 509))=r5 := ⟨_,rfl⟩ rw [hr1,hr3,hr5,OB5.run_rename 510 (by omega)] have a1 := OB5.pool_agree _ u10 r1 u _ hu' rw [rt10 r1] at a1 have a2 := OB5.pool_agree _ u9 r3 _ _ a1 rw [rt9 r3] at a2 have a3 := OB5.pool_agree _ u8 r5 _ _ a2 rw [rt8 r5] at a3 have v1c : (run (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510) r1 u).basis (base (1028+510))=false := (a1 _ (OB5.base_pool _ (by omega))).trans z10.1 have v1d : 257 ≤ 510 → (run (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510) r1 u).basis (base (2053-510))=false := fun big => (a1 _ (OB5.base_pool _ (by omega))).trans (z10.2 big) rw [←OB5.pull_step 510 (by omega) _ v1c v1d,OB5.run_rename 509 (by omega)] have v2c : (run (W.ReverseCarry.compactReceiverTick base 509) r3 (run (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510) r1 u)).basis (base (1028+509))=false := (a2 _ (OB5.base_pool _ (by omega))).trans z9.1 have v2d : 257 ≤ 509 → (run (W.ReverseCarry.compactReceiverTick base 509) r3 (run (Rolling1588.Integer.decodeBefore base false 510 ++ W.ReverseCarry.compactReceiverTick base 510) r1 u)).basis (base (2053-509))=false := fun big => (a2 _ (OB5.base_pool _ (by omega))).trans (z9.2 big) rw [←OB5.pull_step 509 (by omega) _ v2c v2d,OB5.run_rename 508 (by omega)] have p9 := OB5.pull_step 509 (by omega) _ ((a3 _ (OB5.base_pool _ (by omega))).trans c9.1) (fun big => (a3 _ (OB5.base_pool _ (by omega))).trans (c9.2 big)) have p10 := OB5.pull_step 510 (by omega) _ ((a3 _ (OB5.base_pool _ (by omega))).trans c10.1) (fun big => (a3 _ (OB5.base_pool _ (by omega))).trans (c10.2 big)) exact (p9.trans p10).symm end ECDSAAdd.Entrant.Stair44DivTerm end section namespace ECDSAAdd.Entrant.Stair44DivisionCut open ECDSAAdd Arithmetic MappedCompressed Secp256k1 open StairField13V3 StairConcreteAssembly set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 attribute [local irreducible] run wires renameProgram def beforeClose (pr : StairSchedule.StairPrimitives) (h : StairHostsSchedule.HostPlan) := renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase pr) ++ StairHostsSchedule.entryFieldHosted pr h theorem selected (pr : StairSchedule.StairPrimitives) (h : StairHostsSchedule.HostPlan) : (((entryPieces pr h).take 24).map Piece.H).flatten = beforeClose pr h := by simp only [entryPieces,List.take_succ_cons,List.take_zero,groupSlot,firstSlot,lowCommon,common, List.map_cons,List.map_nil,List.flatten_cons,List.flatten_nil,List.append_nil,beforeClose, StairHostsSchedule.entryFieldHosted,StairHostsSchedule.entryLowPrefix,StairHostsSchedule.entryTailPrefix, StairHostsSchedule.entryLowSuffix,StairHostsSchedule.entryTailSuffix,fieldRename_append,rename_append,List.append_assoc] theorem logical (h : StairHostsSchedule.HostPlan) : (((entryPieces checkpointPrimitives h).take 24).map Piece.L).flatten = StairLoanField7Cores.entrySelectedArithmeticFor StairConcrete.bestLoans := by simp only [entryPieces,List.take_succ_cons,List.take_zero,groupSlot,firstSlot,lowCommon,common, List.map_cons,List.map_nil,List.flatten_cons,List.flatten_nil,List.append_nil, StairLoanField7Cores.entrySelectedArithmeticFor,StairSchedule.entryFieldHosted, StairSchedule.entryLowPrefix,StairSchedule.entryTailPrefix,StairSchedule.entryLowSuffix, StairSchedule.entryTailSuffix,fieldRename_append,rename_append,List.append_assoc] theorem reference {t : State} (F : EntryFrame t) (m : List Bool) : run (beforeClose checkpointPrimitives hostPlan) m t = run (StairLoanRecordSupport.entryFieldHostedShape StairConcrete.bestLoans) [] (run (Rolling1588.firstPhase true) [] t) := by have bridge := Stair44HostedCut.entry 24 t ⟨F⟩ m change run (((entryPieces checkpointPrimitives hostPlan).take 24).map Piece.H).flatten m t = run (((entryPieces checkpointPrimitives hostPlan).take 24).map Piece.L).flatten m t at bridge rw [selected,logical] at bridge have core := StairLoanField7RR.entryCoreR_best StairOpenWiring.half760 StairOpenWiring.entryPlans t ⟨F⟩ m [] rw [bridge,core,StairLoanField7Cores.entryReferenceArithmeticFor,run_append] simp only [List.take_nil,List.drop_nil] rw [StairLoanField7Values.first_phase_hosted true F.sharedNodup F.historyAbove F.x _ F.x_pos F.x_lt t [] (StairField13V3Clean.entryInput F)] theorem pool {t : State} (F : EntryFrame t) (m : List Bool) : let z := run (beforeClose checkpointPrimitives hostPlan) m t let y := run (Rolling1588.firstPhase false) [] t z.phase=y.phase ∧ ∀q∈skywalkPoolWires base,z.basis q=y.basis q := by rw [reference F] have r := StairLoanRecordKernel.shape_entry_boundary StairOpenWiring.half760 F.sharedNodup F.historyAbove F.selectorsAway F.transcript F.x F.Y F.x_pos F.x_lt F.source t [] [] F.input F.selectorG_zero F.selectorS_zero F.phase F.outsideNumerator F.numerator refine ⟨r.1,fun q hq => r.2.2 q (FrontierEntry1591Kernel.pool_away_numerator q hq)⟩ end ECDSAAdd.Entrant.Stair44DivisionCut end section namespace ECDSAAdd.Entrant.Stair44MultiplyCut open Arithmetic MappedCompressed Secp256k1 open StairConcreteAssembly StairField13V3 StairField13V3Clean open StairField2V3Replay StairField2V3Delta StairField2V3Couple StairField2V3Entry open StairField2V3ExitPlan StairField2V3ExitPlanR StairField2V3Final open StairLoanField7Transport StairLoanField7R StairLoanExitReachX set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 attribute [local irreducible] run wires renameProgram def lastRows := (XS21 ++ grpFL StairConcrete.bestLoans 0 1 84) ++ lowTail private theorem reached (k x : Nat) : ∃ Q, CRel (XPreX k x) (RowRelL k x 87 (YFL StairConcrete.bestLoans)) lastRows Q := by obtain ⟨Q,h⟩ := rch21 k x (StairOpenWiring.exitPlans k x) StairOpenWiring.half760 have next := sharedL k x 87 (grpFL StairConcrete.bestLoans 0 1 84) ZE (away_of_sub _ _ _ exitGroupSub_best.2.2.2.2.2 (grpF_away 87 (by decide) 1 84 (by decide))) exact ⟨_,crel_append (crel_append h next) (sharedL k x 87 lowTail (ZE ++ grpFL StairConcrete.bestLoans 0 1 84) low_away)⟩ theorem recover (k x : Nat) (u : State) (hp : ExitMiddleX k x u) (rows unpack : List Bool) : let a := run (closeSel cp) unpack (run lastRows rows u) ∃ (s1 : State) (enc : List Bool), W.CompactSkywalkStage base (SkywalkRails.encode false false (x:Int) (p:Int)) 1 s1.basis ∧ pullState Rolling1588Lifetime.phaseHost a = run (Rolling1588TickGap.forward true 1 424) enc s1 := by obtain ⟨Q,h⟩ := reached k x obtain ⟨old,rel,ref⟩ := h u u ⟨hp,rfl⟩ rows have ordinary := (exitReachTransportR_best StairOpenWiring.half760 k x).f _ ref obtain ⟨t0,c,adm,eq⟩ := StairField2V3ExitRecClose.closeRec_of StairField2V3JuncSel2.ExtraSel StairField2V3JuncSel2.extraSel_genuine k x _ ordinary rw [eq] at rel have before := relX_unique x 87 _ _ _ rel (StairField2V3JuncSel2.junc x t0 adm [] c) have back := StairField2V3JuncSel2.firstTrip_sel x t0 adm [] unpack dsimp only rw [before,back] exact adm.2.2.2 def beforeClose (h : StairHostsSchedule.HostPlan) := exitReferenceOpening ++ StairHostsSchedule.exitFieldHosted cp h theorem selected (k : Nat) (h : StairHostsSchedule.HostPlan) : (((exitPieces cp h k).take 24).map Piece.H).flatten = beforeClose h := by simp only [exitPieces,List.take_succ_cons,List.take_zero,groupSlot,firstSlot,lowCommon,common, List.map_cons,List.map_nil,List.flatten_cons,List.flatten_nil,List.append_nil,beforeClose, exitReferenceOpening,StairHostsSchedule.exitFieldHosted,StairHostsSchedule.exitLowPrefix, StairHostsSchedule.exitHeadPrefix,StairHostsSchedule.exitLowSuffix,StairHostsSchedule.exitHeadSuffix, StairHostsSchedule.hostedEndpoint,fieldRename_append,rename_append,List.append_assoc] theorem logical (k : Nat) : (((exitPieces cp hostPlan k).take 24).map Piece.L).flatten = exitReferenceOpening ++ lastRows := by change cut (xps k) 24=_ rw [cut_succ (xps k) 23 (xL k 23 (by decide)),xcut23] change (exitReferenceOpening ++ XS23) ++ StairSchedule.fieldRename (Rolling1588.placedFirstPacket false)=_ simp only [XS23,lastRows,lowTail,fieldRename_append,List.append_assoc] theorem pool (k : Nat) {t : State} (F : ExitFrame k t) (m tail : List Bool) : let a := run (closeSel cp) tail (run (beforeClose hostPlan) m t) ∃ (s1 : State) (enc : List Bool), W.CompactSkywalkStage base (SkywalkRails.encode false false (F.x:Int) (p:Int)) 1 s1.basis ∧ pullState Rolling1588Lifetime.phaseHost a = run (Rolling1588TickGap.forward true 1 424) enc s1 := by have bridge := Stair44HostedCut.exit k 24 t ⟨F⟩ m change run (((exitPieces cp hostPlan k).take 24).map Piece.H).flatten m t = run (((exitPieces cp hostPlan k).take 24).map Piece.L).flatten m t at bridge rw [selected,logical,run_append exitReferenceOpening lastRows] at bridge dsimp only rw [bridge] exact recover k F.x _ ⟨t,F,rfl,_,rfl⟩ _ tail end ECDSAAdd.Entrant.Stair44MultiplyCut end section namespace ECDSAAdd.Entrant.Stair44PlacedHead open Arithmetic MappedCompressed Secp256k1 Baselines ControlledPointLayout CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite FlagEntry ParityUniform ParityEven Stair44PointMap set_option maxRecDepth 16000 set_option maxHeartbeats 1600000 attribute [local irreducible] run measurementCount def plain (kx ky : Fp) := OddOuterBridge.plainOdd kx ky def routed (kx ky : Fp) := OddOuterBridge.routedOdd kx ky theorem unpull (f : Equiv.Perm Wire) (s : State) : pullState f.symm (pullState f s)=s := by apply State.extensionality · rfl · funext q; exact congrArg s.basis (f.apply_symm_apply q) theorem encoded_head (X Y kx ky : Fp) (s : State) (m : List Bool) (hx : regValue layout.point.x s.basis=X.val) (hy : regValue layout.point.y s.basis=Y.val) (clean : regValue layout.dialogPool s.basis=0) : let flag := if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val+kx.val) else false let initial := put s (pkW layout) flag run (routed kx ky) m (pullState outer.symm initial)=pullState integerFirst.symm (run (plain kx ky) m initial) := OddOuterBridge.encoded_head_odd X Y kx ky s m hx hy clean (fun sY mX xc pc => Stair44OuterX.execute X kx sY mX xc pc) theorem cleanInteger (s : State) (hc : regValue layout.dialogPool s.basis=0) : pullState integerFirst s=s := by let pairs : List (Wire × Wire) := [(4835,4615),(4837,4616),(4836,4629)] have members : ∀ab∈pairs,ab.1∈layout.dialogPool ∧ ab.2∈layout.dialogPool := by decide +kernel apply (clean_chain pairs id s s (fun ab hab => ⟨(regValue_zero _ _).mp hc _ (members ab hab).1, (regValue_zero _ _).mp hc _ (members ab hab).2⟩)).mpr rfl theorem encodedTick (s : State) (m : List Bool) (hc : regValue layout.dialogPool s.basis=0) : run (renameProgram integerFirst (E1QubitPlacement.tickF layout)) m s= pullState integerFirst.symm (run (E1QubitPlacement.tickF layout) m s) := by have e := congrArg (pullState integerFirst.symm) (run_rename integerFirst integerFirst.injective (E1QubitPlacement.tickF layout) m s) rw [unpull,cleanInteger s hc] at e exact e end ECDSAAdd.Entrant.Stair44PlacedHead end section namespace ECDSAAdd.Entrant.Stair44WalkCuts open Arithmetic MappedCompressed Stair44WalkMap set_option maxRecDepth 8000 attribute [local irreducible] run wires Rolling1588.reverse Rolling1588TickGap.forward Rolling1588.Integer.regularForward Rolling1588.Integer.regularReverse measurementCount Rolling1588.Integer.reverse Stair44WalkRun.backward theorem early514 (d : Bool) (x p : Nat) (s : State) (hs : Rolling1588.Integer.Stage base d x p 16 s.basis) : s.basis (base 514)=false := by obtain ⟨raw,hraw,bits⟩ := hs rw [congrFun bits _, Rolling1588.Integer.encodePrefix_index base d 3] have far : base 514 ∉ wires (Rolling1588.allEncode base d 3) := by intro used have h := List.mem_toFinset.mp (Rolling1588.allEncode_history_support base d 3 (by decide) used) rcases List.mem_append.mp h with a|a all_goals obtain ⟨t,ht,et⟩ := List.mem_map.mp a all_goals have r := List.mem_range'_1.mp ht all_goals have e := Nat.add_right_cancel et all_goals omega rw [run_preserves_outside _ [] raw _ far] have exp := (W.compactSkywalkStage_fields_iff base _ 16 (by decide) base_pool_nodup raw.basis).mp hraw exact (exp.2.2.2.2.1 256 (by decide) (by decide)).1 theorem backward_start (d : Bool) (a x : Nat) (atCut : 16+a ∈ [425,505,506]) (hx0 : 0 (same q (List.mem_cons_of_mem _ hq)).trans (flags q hq)) t514 exact Stair44WalkRun.backward_run d a x (by omega) hx0 hx s v t enc m hs agree fix private theorem fsplit (d : Bool) (i n m : Nat) : Rolling1588.Integer.regularForward base d i (n+m) = Rolling1588.Integer.regularForward base d i n ++ Rolling1588.Integer.regularForward base d (i+n) m := by induction n generalizing i with | zero => simp [Rolling1588.Integer.regularForward] | succ n ih => simp only [Nat.succ_add,Rolling1588.Integer.regularForward,List.append_assoc] rw [ih] rw [show i+(n+1)=i+1+n by omega] theorem start16 (d : Bool) (x : Nat) (hx0 : 0 decide +kernel private theorem cols (hi:Bool):∀q:Fin 10,get (chronological hi) q=rawCol ((if hi then 10 else 0)+q.val):=by cases hi <;> decide +kernel theorem run_byte (d hi:Bool) (row:Nat) (hr:row<63145) (f:Fin 10→Wire) (inj:Function.Injective f) (s:State) (m:List Bool) (data:∀q:Fin 10,s.basis (f q)=(rawCol ((if hi then 10 else 0)+q.val)).testBit row): (run (codeEncodeAt d f) m s).phase=s.phase ∧ ∀q:Fin 10, (run (codeEncodeAt d f) m s).basis (f q)=(get (storage (native d hi)) q).testBit row:=by let map:=MeasuredCodec5.label f let t:=pullState map s let x:=value (chronological hi) row have rel:Rel (chronological hi) x row:=value_rel _ _ have checked:=stock_code d hi have active:ones.testBit row=true:=by rw [ones,Nat.testBit_two_pow_sub_one];exact decide_eq_true hr have bounds:∀a∈codeEncode d,target a<(chronological hi).length:=by cases d <;> cases hi <;> decide +kernel have eqs(q:Nat)(hq:q∈wires (codeEncode d)):t.basis q=x.testBit q:=by have lt:q<10:=Finset.mem_range.mp ((geom d) ▸ hq) let i:Fin 10:=⟨q,lt⟩ have h:map q=f i:=by simp [map,MeasuredCodec5.label,lt,i] exact (congrArg s.basis h).trans ((data i).trans ((congrArg (fun n:Nat=>n.testBit row) (cols hi i)).symm.trans (rel q).symm)) have result:=run_row (codeEncode d) ones row x m t _ _ active bounds rel checked eqs have placed:=run_rename_pool map (Finset.range 10) (FirstNonzeroCodec.label_inj' f inj) (codeEncode d) (by rw [geom]) m t s rfl (fun _ _=>rfl) refine ⟨placed.1.trans result.1,?_⟩ intro j have ge:j.val∈wires (codeEncode d):=(geom d).symm ▸ Finset.mem_range.mpr j.isLt have lay:map j.val=f j:=by simp [map,MeasuredCodec5.label,j.isLt] exact (congrArg (run (codeEncodeAt d f) m s).basis lay).symm.trans ((placed.2 j.val (Finset.mem_range.mpr j.isLt)).trans (result.2.1 j.val ge)) end ECDSAAdd.Entrant.StairPacket.StockArchiveByte end -- ==== w4: build-w4b B2-b selected_receipt (b2b/Main_SelectedReceipt.lean) ==== -- BEGIN build-w4b NativeJ.selected_receipt (B2-b part 4) -- Main (w4r): next to dadon's `NativePack{240,255}.selected_receipt` (after `StockCanonicalRow`, Main ~5436). section namespace ECDSAAdd.Entrant.StairPacket.NativeJ7 open Arithmetic MappedCompressed IntegerPacket SkywalkRails ArchivePortAction StairArchiveTrace StockCanonicalRow Partial set_option maxRecDepth 25000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false set_option linter.unusedSimpArgs false attribute [local irreducible] run Shadow7.onRails Shadow7.routed measurementCount Shadow7.body /-- dadon's `NativePack{s}.selected_receipt`, generic: block `j` keeps the previous block's archive at the row `select` picks from the recorded key. -/ theorem selected_receipt (j : Fin 26) (h2 : 1≤j.val) (h19 : j.val≤24) (d:Bool) (raw s:State) (m:List Bool) (z:SkywalkNat.State) (G S:Bool) (odd:z.v%2=1) (small:Shadow7.SmallIfFar (Shadow7.sbP (start j)) 15 z) (cut:PackedCut (EnterJ7.lowerPairs j) (EnterJ7.upperPairs j) (EnterJ7.gate j) (EnterJ7.flagN j) (EnterJ7.flagF j) (EnterJ7.flagU j) (PortalValues.negative S z.u) (decide (Shadow.far (Shadow7.sbP (start j)) 15 z)) (decide (Shadow.far (Shadow7.sbP (start j)) 15 z ∧ 2^(Shadow7.sbP (start j))≤z.u)) (pullState (EnterJ7.pull j) raw) (eraseSites (EnterJ7.pending j) s)) (input:SkywalkIntegerInput (EnterJ7.lay j) (encode G S z.u z.v).a (encode G S z.u z.v).b G raw.basis) (hist:∀r:Fin 15,raw.basis (EnterJ7.pull j (windowNet j (IntegerPacket.ports (Shadow7.shape j) r).history))=false) (scratch:∀k:Fin 157,23≤k.val → let pre:=run (Shadow7.enterP j) m s let tape:=m.drop (measurementCount (Shadow7.enterP j)) (run (program j d) (tape.drop (measurementCount (Shadow7.routed j 0 1))) (run (Shadow7.routed j 0 1) tape pre)).basis (ArchiveJ7.rawPorts (prev j) k)=false) (past:SkywalkNat.State) (pg ps cross:Bool) (po:past.v%2=1) (pm:Shadow7.SmallIfFar (Shadow7.sbP (start (prev j))) 15 past) (prior:PastFacts (prev j) (ArchiveJ7.rawPorts (prev j)) (Shadow7.sbP (start (prev j))) past pg ps cross s) : let out:=run (nextWindow j d) m s let v:=key (Shadow7.sbP (start (prev j))) past cross (SkywalkTrace.trace 15 (encode pg ps past.u past.v)) select v<63145 ∧ Encodes v (select v) ∧ Kept (ArchiveJ7.codePorts (prev j)) d (select v) out:=by let pre:=run (Shadow7.enterP j) m s let tape:=m.drop (measurementCount (Shadow7.enterP j)) let T:=Shadow.reduced (Shadow7.sbP (start j)) 15 z let Z:=encode G S T.u T.v have to':T.v%2=1:=shadow_odd_shadow7 (Shadow7.sbP (start j)) z small odd have parity:(Z.a+Z.b)%2=1:=encode_odd_sum G S _ _ (by omega) have ready:=EnterJ7.ready_pending_at j raw s z G S m small cut input hist obtain ⟨_,row,limit,frame⟩:=admits j (by omega) (by omega) d s m tape (tape.drop (measurementCount (Shadow7.routed j 0 1))) Z parity ready.2.1 scratch past pg ps cross po pm prior have held:=bank_kept j (by omega) (by omega) d s m tape (tape.drop (measurementCount (Shadow7.routed j 0 1))) Z parity ready.2.1 have all:=frame_key (prev j) (ArchiveJ7.rawPorts (prev j)) (ArchiveJ7.chronological_all (prev j) (by simp only [prev]; omega)) row (Shadow7.sbP (start (prev j))) past pg ps cross s _ prior held frame have spec:=select_spec ⟨row,limit,all⟩ have final:=receipt j (by omega) (by omega) d pre tape _ spec.1 (reframe limit all (ArchiveJ7.rawPorts (prev j)) _ frame) dsimp only [nextWindow,window] simp only [run_append,run_take] exact ⟨spec.1,spec.2,final.1⟩ end ECDSAAdd.Entrant.StairPacket.NativeJ7 end -- END build-w4b NativeJ.selected_receipt -- ==== w4: end selected_receipt ==== section namespace ECDSAAdd.Entrant.StairPacket.NativePack270 open Arithmetic MappedCompressed Secp256k1 IntegerPacket ArchivePortAction ArchiveBoundary270 set_option maxRecDepth 25000 set_option maxHeartbeats 3500000 attribute [local irreducible] run open StockCanonicalRow ArchiveBoundary270 ParkEndpoint Portal270Flag Secp256k1 SkywalkRails StairArchiveTrace end ECDSAAdd.Entrant.StairPacket.NativePack270 end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityCaller open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines DirectSkywalk OB5 open StairConcreteAssembly Stair44Resources StairHostsSchedule def entryFieldHosted (p : StairSchedule.StairPrimitives) : Program := StairSchedule.fieldRename (WindowCallerCosts.entryLowPrefix p) ++ WindowFieldParity.setup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.entryLowSuffixOdd hostPlan) ++ StairSchedule.hostedX ++ WindowFieldParity.setup def exitFieldHosted (p : StairSchedule.StairPrimitives) : Program := WindowFieldParity.setup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.exitLowPrefixOdd hostPlan) ++ WindowFieldParity.setup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename (WindowCallerCosts.exitLowSuffix p) def entryFieldHostedCut : Program := StairSchedule.fieldRename WindowCallerCosts.entryLowPrefixCut ++ WindowFieldParity.setup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.entryLowSuffixOdd hostPlan) ++ StairSchedule.hostedX ++ WindowFieldParity.setup theorem field_sublist : entryFieldHostedCut.Sublist (entryFieldHosted checkpointPrimitives) := by have f : (StairSchedule.fieldRename WindowCallerCosts.entryLowPrefixCut).Sublist (StairSchedule.fieldRename (WindowCallerCosts.entryLowPrefix checkpointPrimitives)) := PackCutSub.rename_sub _ (PackCutSub.rename_sub _ WindowCallerCosts.low_sublist) unfold entryFieldHostedCut entryFieldHosted exact ((((f.append (List.Sublist.refl _)).append (List.Sublist.refl _)).append (List.Sublist.refl _)).append (List.Sublist.refl _)).append (List.Sublist.refl _) open Stair44Outer def divide : Program := phasePlace (WindowWalkCosts.forward true 4) ++ phasePlace checkpointPrimitives.firstPack ++ kernelPlace entryFieldHostedCut ++ phasePlace reverseEnd ++ phasePlace (WindowWalkCosts.backward false 85) ++ phasePlace (renameProgram Stair44WalkMap.first (FrontierEntry1591NativeH.inverse base)) def multiply (k : Nat) : Program := phasePlace (WindowWalkCosts.forward false 84) ++ phasePlace forwardEnd ++ kernelPlace (exitFieldHosted checkpointPrimitives) ++ phasePlace checkpointPrimitives.firstUnpack ++ phasePlace (WindowWalkCosts.backward true 4) ++ Stair44PointMap.switchX (phasePlace (ParityXExitInverse23Kernel.x1N k)) def generic (cx cy : Fp) : Program := Stair44PointMap.encodeY (EntryFuseOdd.entryYAllOdd layout (-cy)) ++ Stair44PointMap.switchX (FlagEntry.entryXNew layout (FlagEntry.pkW layout) (-cx)) ++ divide ++ Stair44Square.program (ReflectionE1.correction cx) ++ multiply cx.val ++ Stair44PointMap.encodeY (EntryFuseOdd.exitYAllOdd layout cy) def borrowGeneric (cx cy : Fp) := renameProgram (Equiv.swap layout.doubleSelect layout.control) (renameProgram (FlagTop.rho layout) (generic cx cy)) def finite (C : Point) (cx cy : Fp) : Program := Stair44PointMap.encode (FlagTop.stageNew layout C (FlagEntry.pkW layout) ++ AboveFieldPointDevelop.encode C ++ AboveFieldPointDevelop.eraseB) ++ borrowGeneric cx cy ++ Stair44PointMap.encode (AboveFieldPointDevelop.loadB ++ AboveFieldPointDevelop.decode C ++ ControlPointEncodingDevelop.borrowOut C) def program (C : Point) : Program := match C with | .zero => [] | @WeierstrassCurve.Affine.Point.some _ _ _ cx cy hc => renameProgram (Wrapper5.U layout) (finite (.some hc) cx cy) end ECDSAAdd.Entrant.StairPacket.WindowParityCaller end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityDirty set_option linter.unusedSimpArgs false def flip (q : Wire) (v : Bool) (s : State) : State := ⟨s.phase, writeBit s.basis q (s.basis q ^^ v)⟩ @[simp] theorem at_flip (s : State) (q : Wire) (v : Bool) : (flip q v s).basis q = (s.basis q ^^ v) := by simp [flip,writeBit] theorem at_other (s : State) (q t : Wire) (v : Bool) (ne : q≠t) : (flip t v s).basis q=s.basis q := by simp [flip,writeBit,ne] theorem flip_twice (s : State) (t : Wire) (a b : Bool) : flip t b (flip t a s) = flip t (a^^b) s := by apply congrArg₂ State.mk rfl; funext q by_cases e : q=t · subst q; simp [flip,writeBit,Bool.xor_assoc] · simp [flip,writeBit,e] @[simp] theorem flip_zero (s : State) (t : Wire) : flip t false s=s := by apply congrArg₂ State.mk rfl; funext q by_cases e : q=t <;> simp [flip,writeBit,e] def outside (q last : Wire) (xs : Hops) := q≠last ∧ ∀ e∈xs,q≠e.1 ∧ q≠e.2 def safe (last target : Wire) : Wire→Hops→Prop | src,[] => src≠target ∧ last≠target | src,(c,b)::xs => src≠target ∧ c≠target ∧ b≠target ∧ src≠b ∧ c≠b ∧ outside b last xs ∧ safe last target b xs end ECDSAAdd.Entrant.StairPacket.WindowParityDirty end section namespace ECDSAAdd.Entrant.Stair44DivTerm open ECDSAAdd Arithmetic MappedCompressed Secp256k1 OB5 open Rolling1588.Integer set_option maxRecDepth 30000 set_option maxHeartbeats 8000000 set_option linter.unusedSimpArgs false attribute [local irreducible] run wires measurementCount Rolling1588.forward Rolling1588.reverse Rolling1588.Integer.forward regularForward theorem head_chain (x : Nat) (hx0 : 0 < x) (hx : x < p) (s1 : State) (first : W.CompactSkywalkStage base (SkywalkRails.encode false false (x:Int) (p:Int)) 1 s1.basis) (M : List Bool) (u : State) (hu : ∀ q ∈ skywalkPoolWires base, u.basis q = (run (Rolling1588.Integer.regularForward base false 1 510) M s1).basis q) (mD : List Bool) : run P1 mD (pullState (sig 510) u) = run (Rolling1588.Integer.reverse false 506 5) mD (pullState (sig 510) u) := by have st6 := stage_after x hx0 hx s1 first 505 (by omega) (M.take (measurementCount (Rolling1588.Integer.regularForward base false 1 505))) have ag6 := agree_split u s1 M _ _ split506 hu have st7 := stage_after x hx0 hx s1 first 506 (by omega) (M.take (measurementCount (Rolling1588.Integer.regularForward base false 1 506))) have ag7 := agree_split u s1 M _ _ split507 hu have st8 := stage_after x hx0 hx s1 first 507 (by omega) (M.take (measurementCount (Rolling1588.Integer.regularForward base false 1 507))) have ag8 := agree_split u s1 M _ _ split508 hu have hb : ∀ r, run P1 r (pullState (sig 510) u) = run (Q1 ++ Q2) r (pullState (sig 510) u) := by intro r rw [← PE1] show run (renameProgram (sig 510) (Rolling1588.unpackAtTick false 510 ++ InverseFive23.candidate15)) r (pullState (sig 510) u) = _ rw [InverseFour15.unpack51015, OB5.run_rename 510 (by omega), OB5.run_rename 510 (by omega), InverseFive23.decoded_replace_pool15 false x hx0 hx _ u st6 _ r ag6] have hc : ∀ r, run Q1 r (pullState (sig 510) u) = run (Z1 ++ Z2) r (pullState (sig 510) u) := by intro r rw [← PE2] exact InverseFour15.placed_block15 false x hx0 hx _ u st7 _ r ag7 have hd : ∀ r, run Z1 r (pullState (sig 510) u) = run Y r (pullState (sig 510) u) := key510 x hx0 hx _ u st8 _ ag8 have hQ : ∀ r, run Q1 r (pullState (sig 510) u) = run (Y ++ Z2) r (pullState (sig 510) u) := fun r => (hc r).trans (run_congr_append Z1 Y Z2 _ hd cZ r) have hP : ∀ r, run P1 r (pullState (sig 510) u) = run ((Y ++ Z2) ++ Q2) r (pullState (sig 510) u) := fun r => (hb r).trans (run_congr_append Q1 (Y ++ Z2) Q2 _ hQ cQ r) rw [hP mD, PE4] end ECDSAAdd.Entrant.Stair44DivTerm end section namespace ECDSAAdd.Entrant.Stair44WalkCuts open Arithmetic MappedCompressed Stair44WalkMap Rolling1588.Integer set_option maxRecDepth 12000 attribute [local irreducible] run wires measurementCount Rolling1588.reverse Rolling1588TickGap.forward regularForward Stair44WalkRun.backward theorem backward_record (d : Bool) (a x : Nat) (atCut : 16+a ∈ [425,505,506]) (hx0 : 0 w.basis q) cut) exact backward_start d a x atCut hx0 hx mid v post m st pool end ECDSAAdd.Entrant.Stair44WalkCuts end section namespace ECDSAAdd.Entrant.StairPacket.ArchiveHistoryCompare open Arithmetic MappedCompressed WideReference attribute [local irreducible] run W.compactSkywalkTick def Except (qs:List Wire) (s t:State) := ∀q∉qs,s.basis q=t.basis q theorem runEq {qs:List Wire} (P:Program) (s t:State) (m n:List Bool) (initial:Except qs s t) (off:∀q∈qs,q∉wires P) : Except qs (run P m s) (run P n t) := by let aligned:State:=⟨s.phase,t.basis⟩ have localEq:=run_measured_locality P (wires P) (Finset.Subset.refl _) s aligned m rfl (fun q used=>initial q (fun mem=>off q mem used)) have records:=StairDivLoanTop.run_basis_records P m n aligned t rfl intro q hq by_cases used:q∈wires P · exact (localEq.2 q used).trans (congrFun records q) · rw [run_preserves_outside _ _ _ _ used,run_preserves_outside _ _ _ _ used] exact initial q hq theorem spanAppend (i n k:Nat) : span i (n+k)=span i n++span (i+n) k := by induction n generalizing i with | zero=>simp [span] | succ n ih=>rw [Nat.succ_add,span,span,ih (i+1),List.append_assoc];simp [Nat.succ_add,Nat.add_assoc] theorem moveEarlier (i n:Nat) (lim:i+n≤512) (P:Program) (old:∀q∈wires P,Earlier i q) (s:State) : run (span i n) [] (run P [] s)=run P [] (run (span i n) [] s) := by have disjoint:Disjoint (wires P) (wires (span i n)) := Finset.disjoint_left.mpr (fun _ h=>pastOffSpan _ _ _ lim (old _ h)) exact (run_disjoint_commute _ _ disjoint [] [] s).symm theorem join {old added:List Wire} {s a b:State} (h:Except added s a) (k:Except old a b): Except (old++added) s b := by intro q off exact (h q (fun hit=>off (List.mem_append.mpr (Or.inr hit)))).trans (k q (fun hit=>off (List.mem_append.mpr (Or.inl hit)))) /-- Move earlier encoders past the untouched tick span and then add this window's encoder. -/ theorem extend (i n:Nat) (lim:i+n≤512) (old added:List Wire) (prefixProgram nextProgram:Program) (raw reference out:State) (pre:Except old raw (run prefixProgram [] reference)) (window:Except added out (run nextProgram [] (run (span i n) [] raw))) (priorOld:∀q∈old,Earlier i q) (opsOld:∀q∈wires prefixProgram,Earlier i q) (avoid:∀q∈old,q∉wires nextProgram) : Except (old++added) out (run (prefixProgram++nextProgram) [] (run (span i n) [] reference)) := by have stable:=runEq (span i n) raw (run prefixProgram [] reference) [] [] pre (fun q mem=>pastOffSpan _ _ _ lim (priorOld q mem)) rw [moveEarlier _ _ lim _ opsOld reference] at stable have next:=runEq nextProgram _ _ [] [] stable avoid rw [run_append,run_take,List.drop_nil] exact join window next end ECDSAAdd.Entrant.StairPacket.ArchiveHistoryCompare end section namespace ECDSAAdd.Entrant.StairPacket.ArchiveOrdinaryFive open Arithmetic MappedCompressed Rolling1588 set_option maxRecDepth 25000 set_option maxHeartbeats 2400000 attribute [local irreducible] run theorem stock_relocated (d:Bool) (f g:Fin 10→Wire) (inj:Function.Injective f) (inj':Function.Injective g) (s t:State) (m n:List Bool) (initial:∀i,s.basis (f i)=t.basis (g i)) (i:Fin 10) : (run (codeEncodeAt d f) m s).basis (f i)=(run (codeEncodeAt d g) n t).basis (g i) := by let a:=MeasuredCodec5.label f let b:=MeasuredCodec5.label g let src:=pullState a s let dst:State:=⟨t.phase,src.basis⟩ have footprint:wires (codeEncode d)⊆Finset.range 10:=by cases d <;> decide +kernel have input (q:Nat) (hq:q∈Finset.range 10) : dst.basis q=t.basis (b q) := by have lt:=Finset.mem_range.mp hq simpa [dst,src,pullState,a,b,MeasuredCodec5.label,lt] using initial ⟨q,lt⟩ have srcStep:=run_rename_pool a _ (FirstNonzeroCodec.label_inj' _ inj) _ footprint m src s rfl (fun _ _=>rfl) have dstStep:=run_rename_pool b _ (FirstNonzeroCodec.label_inj' _ inj') _ footprint n dst t rfl input have basis:=StairDivLoanTop.run_basis_records (codeEncode d) m n src dst rfl have h: i.val∈Finset.range 10:=Finset.mem_range.mpr i.isLt have srcBit:=srcStep.2 _ h have dstBit:=dstStep.2 _ h change (run (codeEncodeAt d f) m s).basis (a i.val)=_ at srcBit change (run (codeEncodeAt d g) n t).basis (b i.val)=_ at dstBit simpa only [a,b,MeasuredCodec5.label,dif_pos i.isLt] using srcBit.trans ((congrFun basis i.val).trans dstBit.symm) end ECDSAAdd.Entrant.StairPacket.ArchiveOrdinaryFive end section namespace ECDSAAdd.Entrant.StairPacket.StockArchiveTruth open Arithmetic MappedCompressed WideReference SkywalkRails StairArchiveTrace StairArchiveRaw StairArchiveNativeRows CodecBitSliceVerify attribute [local irreducible] run SkywalkNat.step span WideReference.canonical StairArchiveRaw.rawCol SkywalkTrace.trace private theorem nextCanon (k j x p:Nat):SkywalkTrace.next^[j] (WideReference.canonical k x p)=WideReference.canonical (k+j) x p:=by unfold WideReference.canonical rw [Nat.add_comm k j] exact (Function.iterate_add_apply _ j k _).symm theorem observedLabel (k x p row:Nat) (truth:ArchiveStockRows.Chronology k x p row) (e:Fin 20): (rawCol e).testBit row=letterBit (SkywalkTrace.code (WideReference.canonical (k+(5+e.val/2)) x p)) e:=by have h:=truth e have drop (cs:List (Bool×Bool)):read (cs.drop 5) (e.val/2)=read cs (5+e.val/2):=by simp only [StairArchiveRaw.read,List.getElem?_drop] rw [drop,read_trace _ _ (by omega),nextCanon] at h exact h end ECDSAAdd.Entrant.StairPacket.StockArchiveTruth end end section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryJ open Arithmetic MappedCompressed IntegerPacket Partial WideReference set_option maxRecDepth 25000 set_option maxHeartbeats 2800000 set_option linter.unnecessarySeqFocus false set_option linter.unreachableTactic false set_option linter.unusedSimpArgs false set_option linter.unusedTactic false set_option linter.unusedVariables false attribute [local irreducible] run Shadow7.body Shadow7.routed measurementCount /-! Generic history hand-off of an interior window block `j` (par-c2; dadon's `Ordinary{s}Exit`, `Ordinary{s}Native`, `Logical{s}Exit`). The block's pack re-encodes the cells of ticks `s-15..s-11` exactly as the stock encoder of group `s-15` does, and the logical end state differs from the stock run only on the archived cells of ticks `s-10..s-1` (`newBank`). Interior: `oldStart s = s-15` (par-a's `oldStart_interior`). Blocks `1 ≤ j ≤ 21`. -/ def plain (j : Fin 26) : Fin 10 → Wire := History5.historyMap base (start j-15) def newBank (j : Fin 26) : List Wire := (List.range' (start j-10) 10).flatMap (fun r=>[base r,base (1028+r)]) theorem plain_cell (j : Fin 26) (i : Fin 10) : (i.val%2=0 ∧ (plain j i:Nat)=start j-15+i.val/2+16) ∨ (i.val%2≠0 ∧ (plain j i:Nat)=start j-15+i.val/2+1044) := by simp only [plain,History5.historyMap,History5.historyId,base,Wire] split · left; constructor; assumption; omega · right; constructor; assumption; omega theorem plain_inj (j : Fin 26) : Function.Injective (plain j) := by intro a b e have ha:=a.isLt; have hb:=b.isLt have ca:=plain_cell j a; have cb:=plain_cell j b have e':(plain j a:Nat)=plain j b:=e apply Fin.ext simp only [Wire] at ca cb e' omega /-- `OB5.sig s` and `OB5.sig (s+14)` agree on these cells (both swap the moved history cells). -/ theorem sig_same (j : Fin 26) (i : Fin 10) : (OB5.sig (start j) (plain j i):Nat)=OB5.sig (start j+14) (plain j i) := by have c:=plain_cell j i have hj:=j.isLt; have hi:=i.isLt simp only [OB5.sig,Wire] simp only [start,Wire] at * split <;> split <;> omega /-- Cells of the stock encoder of group `t`: ticks `t..t+4`. -/ theorem encode_cells (d:Bool) (t:Nat) : ∀q∈wires (Rolling1588.encodeAt base d t), ∃r,t≤r ∧ r≤t+4 ∧ (q=r+16 ∨ q=r+1044) := by intro q h change q∈wires (renameProgram (MeasuredCodec5.label (History5.historyMap base t)) (Rolling1588.codeEncode d)) at h rw [renameProgram_support] at h obtain ⟨a,ha,rfl⟩:=Finset.mem_image.mp h rw [(Rolling1588.code_support d).1,Finset.mem_range] at ha refine ⟨t+a/2,by omega,by omega,?_⟩ simp only [MeasuredCodec5.label,ha,dif_pos,History5.historyMap,History5.historyId,base,Wire] split <;> omega theorem heads_all : ∀ j : Fin 26, 1≤j.val → j.val≤24 → ∀i:Fin 10, oldRange (start j+1) (windowNet j (NativeJ7.history j i)) ∧ NativeJ7.history j i∉ArchiveJ7.rawHead (NativeJ7.prev j) ∧ ArchiveJ7.Band (start (NativeJ7.prev j)+15) (NativeJ7.history j i) ∧ NativeJ7.history j i∉EnterJ7.pending j ∧ NativeJ7.history j i≠EnterJ7.flagN j ∧ NativeJ7.history j i≠EnterJ7.flagF j ∧ NativeJ7.history j i≠EnterJ7.flagU j ∧ NativeJ7.history j i∉RailPair.sites (EnterJ7.upperPairs j) ∧ EnterJ7.pull j (NativeJ7.history j i)=plain j i := by decide +kernel theorem kept (j:Fin 26) (admin:Program) (m:List Bool) (s:State) (q:Wire) (early:oldRange (start j+1) (windowNet j q)) : (run (Shadow7.body j admin) m s).basis q= (run admin (m.drop (measurementCount (Shadow7.routed j 0 1))) (run (Shadow7.routed j 0 1) m s)).basis q := by simp only [Shadow7.body,run_append,run_take] exact Shadow7.route_outside j 1 14 (by decide) q (Shadow7.old_clear (by decide) early) _ _ theorem pastInput (j : Fin 26) (h1 : 1≤j.val) (h21 : j.val≤24) (x p:Nat) (good:Bounds x p) (raw:State) (dom:Domain (start j) x p raw) (i:Fin 10) : raw.basis (plain j i)=(run (span (start j) 15) [] raw).basis (plain j i) := by have pp:=preservePast (start j) 15 x p (start j-15+i.val/2) (by simp only [start]; omega) good raw dom (by simp only [start]; omega) [] rcases plain_cell j i with ⟨-,e⟩|⟨-,e⟩ · rw [e]; exact pp.1.symm · rw [e,show start j-15+i.val/2+1044=base (1028+(start j-15+i.val/2)) by simp only [base]; omega]; exact pp.2.symm theorem encode (j : Fin 26) (h1 : 1≤j.val) (d:Bool) (a b:State) (tape:List Bool) (agree:∀i,a.basis (NativeJ7.history j i)=b.basis (plain j i)) (i:Fin 10) : (run (NativeJ7.program j d) tape a).basis (NativeJ7.history j i)= (run (Rolling1588.encodeAt base d (start j-15)) [] b).basis (plain j i) := by rw [(NativeJ7.equals j (by omega) d).1] exact ArchiveOrdinaryFive.stock_relocated d (NativeJ7.history j) (plain j) (NativeJ7.histInj j) (plain_inj j) a b tape [] agree i theorem readback (j : Fin 26) (h1 : 1≤j.val) (h21 : j.val≤24) (d:Bool) (raw pre wide out:State) (tape:List Bool) (input:∀i,pre.basis (NativeJ7.history j i)=raw.basis (plain j i)) (stable:∀i,raw.basis (plain j i)=wide.basis (plain j i)) (last:∀i,out.basis (NativeJ7.history j i)=(run (NativeJ7.withArchive j d) tape pre).basis (NativeJ7.history j i)) (i:Fin 10) : out.basis (NativeJ7.history j i)=(run (Rolling1588.encodeAt base d (start j-15)) [] wide).basis (plain j i) := by apply (last i).trans rw [NativeJ7.withArchive,run_append,run_take] have hp:(NativeJ7.prev j).val≤23:=by simp only [NativeJ7.prev]; omega obtain ⟨-,offHead,band,-⟩:=heads_all j (by omega) h21 i have off:NativeJ7.history j i∉ArchiveJ7.rawPortsList (NativeJ7.prev j):=by rw [ArchiveJ7.raw_split,List.mem_append] rintro (h|h) · exact offHead h · obtain ⟨k,hk,eq⟩:=List.mem_map.mp h exact ArchiveJ7.band_off _ (ArchiveJ.tick_lt _) (List.mem_range.mp hk) band eq rw [run_preserves_outside (Shadow7.archiveLoadP (NativeJ7.prev j) d) _ _ _ (fun h=>off (List.mem_toFinset.mp (ArchiveJ7.load_cover (NativeJ7.prev j) (by omega) d h)))] exact encode j (by omega) d pre wide tape (fun k=>(input k).trans (stable k)) i /-- `Ordinary{s}Exit.result` for every interior block. -/ theorem result (j : Fin 26) (h1 : 1≤j.val) (h21 : j.val≤24) (d:Bool) (raw s:State) (m:List Bool) (x p:Nat) (good:Bounds x p) (dom:Domain (start j) x p raw) (input:∀i,(run (Shadow7.routed j 0 1) m s).basis (NativeJ7.history j i)=raw.basis (plain j i)) : ∀i,(run (Shadow7.body j (NativeJ7.withArchive j d)) m s).basis (NativeJ7.history j i)= (run (Rolling1588.encodeAt base d (start j-15)) [] (run (span (start j) 15) [] raw)).basis (plain j i) := readback j (by omega) h21 d raw (run (Shadow7.routed j 0 1) m s) (run (span (start j) 15) [] raw) _ _ input (pastInput j (by omega) h21 x p good raw dom) (fun i=>kept j _ m s _ (heads_all j (by omega) h21 i).1) /-- `Logical{s}Exit.window` for every interior block (par-a's `Fixed`-free `endRaw_*_gen`). -/ theorem window (j : Fin 26) (h1 : 1≤j.val) (h21 : j.val≤24) (interior:oldStart (start j)=start j-15 ∧ oldCount (start j)=15) (d:Bool) (raw historyState:State) (ordinaryBits:∀i,historyState.basis (NativeJ7.history j i)= (run (Rolling1588.encodeAt base d (start j-15)) [] (run (span (start j) 15) [] raw)).basis (plain j i)) (q:Wire) (ordinarySite:q∉newBank j) : (endRaw (start j) raw historyState).basis q= (run (Rolling1588.encodeAt base d (start j-15)) [] (run (span (start j) 15) [] raw)).basis q := by have bound:start j+14≤511:=by simp only [start]; omega have s15:15≤start j:=by simp only [start]; omega by_cases inside:q∈oldSites (start j) · obtain ⟨r,r1,r2,hq⟩:=old_cell inside rw [interior.1] at r1 r2 rw [interior.2] at r2 have young:rwindow j (by omega) h21 interior d raw _ (result j (by omega) h21 d raw e b x p good domain input) q hq end ECDSAAdd.Entrant.StairPacket.OrdinaryJ end -- ==== end PrizeTail8dd9f9e60 ==== -- ==== begin PrizeTail05e06b1e9 ==== section section namespace ECDSAAdd.Entrant.StairPacket.StockStrongChain open Arithmetic MappedCompressed Secp256k1 IntegerPacket WideReference StockWindowTicket StockCanonicalRow Partial ArchivePortAction ArchiveStockRows set_option maxRecDepth 16000 set_option maxHeartbeats 4500000 attribute [local irreducible] run measurementCount Partial.leave225 Partial.leave240 Partial.leave255 NativePack270.lastWindow noncomputable def value (x p i b:Nat) (c:SkywalkNat.State→Bool):Nat→Bool:= key b (unsigned i x p) (c (unsigned i x p)) (SkywalkTrace.trace 15 (WideReference.canonical i x p)) def SavedKey (v:Nat→Bool) (ps:Ports) (d:Bool) (s:State):Prop:= select v<63145 ∧ Encodes v (select v) ∧ Kept ps d (select v) s attribute [local irreducible] key select WideReference.canonical theorem kept_frame (ps:Ports) (d:Bool) (r:Nat) (s:State) (h:Frame ps (code d) r s): Kept ps d r s:=fun j=>h ⟨j,by omega⟩ end ECDSAAdd.Entrant.StairPacket.StockStrongChain end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityCaller open Arithmetic MappedCompressed Secp256k1 Baselines Challenge Stair44Resources Stair44Outer open StairConcreteAssembly WindowFieldParity set_option maxRecDepth 16000 set_option maxHeartbeats 1500000 set_option linter.unusedSimpArgs false private theorem setup_eq : setup = StairSchedule.paritySetup := by have empty : correction = [] := rfl rw [setup, empty, List.append_nil] theorem program_eq (C : Point) : program C = WindowCallerCosts.program C := by cases C with | zero => rfl | @some cx cy hc => simp only [program, WindowCallerCosts.program, finite, WindowCallerCosts.finite, borrowGeneric, WindowCallerCosts.borrowGeneric, generic, WindowCallerCosts.generic, divide, WindowCallerCosts.divide, multiply, WindowCallerCosts.multiply, entryFieldHosted, WindowCallerCosts.entryFieldHosted, entryFieldHostedCut, WindowCallerCosts.entryFieldHostedCut, exitFieldHosted, WindowCallerCosts.exitFieldHosted, setup_eq] theorem metrics (C : Point) : toffoliCount (program C) ≤ 2011335 ∧ measurementCount (program C) ≤ 1446134 ∧ gateSlots (program C) ≤ 67241790 := by rw [program_eq] exact ⟨(WindowCallerCosts.totals C).1, (WindowCallerCosts.totals C).2, WindowSlots.slotBound C⟩ end ECDSAAdd.Entrant.StairPacket.WindowParityCaller end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityDirty set_option linter.unusedSimpArgs false attribute [local irreducible] run chain end ECDSAAdd.Entrant.StairPacket.WindowParityDirty end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityCaller open Arithmetic MappedCompressed Secp256k1 Baselines Stair44Outer StairConcreteAssembly WindowFieldParity set_option maxRecDepth 16000 set_option maxHeartbeats 2000000 set_option linter.unusedSimpArgs false theorem physical (C : Point) : GatePhysical (program C) := by rw [program_eq] exact WindowCallerCosts.physical C end ECDSAAdd.Entrant.StairPacket.WindowParityCaller end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityCaller open Arithmetic MappedCompressed Secp256k1 Challenge Baselines Stair44Outer WindowFieldParity set_option maxHeartbeats 3000000 set_option maxRecDepth 16000 theorem width (C : Point) : qubits (program C) ≤ 1543 := by rw [program_eq] exact WindowCallerCosts.qubitBound C end ECDSAAdd.Entrant.StairPacket.WindowParityCaller end section namespace ECDSAAdd.Entrant.Stair44DivTerm open Arithmetic MappedCompressed Secp256k1 OB5 Rolling1588.Integer set_option maxHeartbeats 8000000 set_option maxRecDepth 30000 attribute [local irreducible] run wires measurementCount regularForward Rolling1588.reverse def head := renameProgram (sig 511) tickR ++ P1 theorem after_head (x : Nat) (hx0 : 0 ht (List.mem_toFinset.mp (tickR_wires h)) have hf : q∉wires tickF := fun h => ht (List.mem_toFinset.mp (tickF_wires h)) rw [run_preserves_outside tickR [] t5 q hr,agree q hq,run_preserves_outside tickF [] a q hf] have z := stage_zero false x 511 (by omega) a.basis aStage have move : pullState (sig 511) (run tickR [] t5)=pullState (sig 510) (run tickR [] t5) := (OB5.pull_step 511 (by omega) _ ((uAgree _ (StackOB5Base.base_pool _ (by omega))).trans z.1) (fun big => (uAgree _ (StackOB5Base.base_pool _ (by omega))).trans (z.2 big))).symm have hu (q : Wire) (hq : q∈skywalkPoolWires base) : (run tickR [] t5).basis q = (run (regularForward base false 1 510) M s1).basis q := (uAgree q hq).trans (congrArg (fun w : State => w.basis q) whole) let pr := regularForward base false 1 505 obtain ⟨s6,e6⟩ : ∃ u : State,run pr (M.take (measurementCount pr)) s1=u := ⟨_,rfl⟩ have stage6 := stage_after x hx0 hx s1 first 505 (by decide) (M.take (measurementCount pr)) change Stage base false x p 506 (run pr (M.take (measurementCount pr)) s1).basis at stage6 rw [e6] at stage6 have split := Stair44WalkCuts.decompose false 1 505 5 s1 M change run (regularForward base false 1 510) M s1 = run (regularForward base false 506 5) (M.drop (measurementCount pr)) (run pr (M.take (measurementCount pr)) s1) at split rw [e6] at split have hb (q : Wire) (hq : q∈skywalkPoolWires base) := (hu q hq).trans (congrArg (fun w : State => w.basis q) split) have rg := reverse_gen false x hx0 hx 5 506 (by decide) (by decide) s6 (M.drop (measurementCount pr)) (run tickR [] t5) mD stage6 hb refine ⟨run (regularReverse base false 506 5) mD (run tickR [] t5),?_,?_⟩ · have cn := (renameProgram_counts (sig 511) tickR).2.trans tickR_counts.2 rw [head,run_append,cn] simp only [List.take_zero,List.drop_zero] rw [OB5.run_rename 511 (by decide),tickR_run,move,head_chain x hx0 hx s1 first M _ hu mD] simpa only [Rolling1588.Integer.reverse_eq_packets] using rg.1 · intro q hq exact (rg.2 q hq).trans (congrArg (fun w : State => w.basis q) (e6.symm.trans (run_take pr M s1))) end ECDSAAdd.Entrant.Stair44DivTerm end section namespace ECDSAAdd.Entrant.StairPacket.Ordinary270Terminal open Arithmetic MappedCompressed NativePack270 ArchivePortAction ArchiveBoundary270 ParkEndpoint CodecBitSliceVerify set_option maxRecDepth 40000 set_option maxHeartbeats 3800000 attribute [local irreducible] run end ECDSAAdd.Entrant.StairPacket.Ordinary270Terminal end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldHistory open Arithmetic Secp256k1 MappedCompressed BalancedField Rolling1588 StairArchiveRaw StairArchiveTrace open CodecBitSliceVerify StairArchiveNativeRows StairField2V3Seg attribute [local irreducible] run wires rawCol CodecBitSliceVerify.get SkywalkTrace.next set_option linter.unnecessarySeqFocus false set_option maxRecDepth 1400 set_option maxHeartbeats 400000 /-- Identify the 20 row columns with real raw field history at a ten-cell suffix. -/ theorem originBits (j x row : Nat) (jb : 5*j+10≤512) (lb : 5≤5*j) (origin : BasisState) (tr : TraceOK x origin) (record : ArchiveStockRows.Chronology (5*j-5) x ECDSAAdd.p row) (hi : Bool) (q : Fin 10) : origin (History5.historyMap base (5*(j+(if hi then 1 else 0))) q) = (rawCol ((if hi then 10 else 0)+q.val)).testBit row := by let u : Nat := (if hi then 10 else 0)+q.val have ql := q.isLt have u20 : u<20 := by cases hi <;> simp [u] <;> omega let start := 5*(j+(if hi then 1 else 0)) let tick := start+q.val/2 have plus : tick=5*j+u/2 := by cases hi <;> simp [tick,start,u] <;> omega have full : (5*j-5)+(5+u/2)=tick := by omega have small : tick<512 := by omega have bits := StairField2V3Trace.origin_letters x origin tr tick small have col := StockArchiveTruth.observedLabel (5*j-5) x ECDSAAdd.p row record ⟨u,u20⟩ change (rawCol u).testBit row=letterBit (SkywalkTrace.code (WideReference.canonical ((5*j-5)+(5+u/2)) x ECDSAAdd.p)) u at col rw [full] at col unfold WideReference.canonical at col change origin (base (if q.val%2=0 then start+q.val/2 else 1028+start+q.val/2))=(rawCol u).testBit row rw [col]; unfold letterBit have parity : u%2=q.val%2 := by cases hi <;> simp [u] <;> omega rw [parity] split · exact bits.1 · simpa only [tick,Nat.add_assoc] using bits.2 end ECDSAAdd.Entrant.StairPacket.WindowFieldHistory end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityDirty set_option linter.unusedSimpArgs false def lawful (t : Wire) : Aff→Prop | .x w => w≠t | .cx c w => c≠w ∧ c≠t ∧ w≠t end ECDSAAdd.Entrant.StairPacket.WindowParityDirty end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityRelease open Arithmetic Secp256k1 Challenge Baselines def entry : Challenge.Entry := fun C => normalizeProgram (WindowParityCaller.program C) def bounds : Challenge.Bounds := ⟨2011335,1446134,1543,67241790⟩ theorem certificateOfSemantics (sem : ∀ C b R, Triple (encodes b R) (WindowParityCaller.program C) (encodes b (if b then R+C else R))) : Certificate entry bounds where correct C b R := (normalize_triple _ _ _).mpr (sem C b R) physical C := Baselines.normalize_physical _ (WindowParityCaller.physical C) toffoli_le C := (normalize_toffoli _).trans (WindowParityCaller.metrics C).1 measurements_le C := by change measurementCount (normalizeProgram _) ≤ 1446134 rw [normalize_measurements] exact (WindowParityCaller.metrics C).2.1 qubits_le C := by change qubits (normalizeProgram _) ≤ 1543 rw [normalize_qubits] exact WindowParityCaller.width C gateSlots_le C := by change gateSlots (normalizeProgram _) ≤ 67241790 rw [normalize_slots] exact (WindowParityCaller.metrics C).2.2 end ECDSAAdd.Entrant.StairPacket.WindowParityRelease end section namespace ECDSAAdd.Entrant.Stair44DivTerm open Arithmetic MappedCompressed Secp256k1 OB5 DirectSkywalk Rolling1588.Integer set_option maxRecDepth 12000 set_option maxHeartbeats 2000000 attribute [local irreducible] run wires measurementCount regularForward Rolling1588.reverse theorem sig_pool (i : Nat) (hi : i≤511) (q : Wire) (hq : q∈skywalkPoolWires base) : sig i q∈skywalkPoolWires base := by obtain ⟨j,hj,rfl⟩ := List.mem_map.mp hq have b := List.mem_range'_1.mp hj rw [sig_base i j hi] apply OB5.base_pool split <;> omega theorem host_pool (q : Wire) (hq : q∈skywalkPoolWires base) : Rolling1588Lifetime.phaseHost q∈skywalkPoolWires base := by simp only [Rolling1588Lifetime.phaseHost,Equiv.trans_apply,Equiv.swap_apply_def] split_ifs <;> first | assumption | exact OB5.base_pool _ (by decide) theorem raw511 (hn : (skywalkSharedWires base).Nodup) (d : Bool) (x : Nat) (hx0 : 0 matchB q (List.mem_toFinset.mp hq)) have twice : run C [] (run C [] (pullState (sig 511) ref))=pullState (sig 511) ref := by exact skywalkTerminalClear_twice (base 511) (base 512) (base 770) (arith_clear_gates base hn) _ [] [] rw [twice] at same let v5 := pullState (sig 511) w have eq5 : w=pullState (sig 511) v5 := by apply State.extensionality · rfl · funext q; exact congrArg w.basis (sig_invol 511 (by decide) q).symm have eqb (q : Wire) (hq : q∈skywalkPoolWires base) : v5.basis q=ref.basis q := by have r := same.2 _ (List.mem_toFinset.mpr (sig_pool 511 (by decide) q hq)) simpa only [pullState,sig_invol 511 (by decide)] using r have noM : measurementCount (skywalkArithmeticClear base)=0 := by simp [skywalkArithmeticClear,skywalkTerminalClear,measurementCount] rw [run_append,noM,List.take_zero,List.drop_zero] change ∃ raw,run head m w=pullState (sig 505) raw ∧ _ rw [eq5] rw [←er] at eqb exact after_head x hx0 hx one st [] v5 eqb m end ECDSAAdd.Entrant.Stair44DivTerm end section namespace ECDSAAdd.Entrant.StairPacket.StockBaseline open Arithmetic MappedCompressed WideReference Secp256k1 attribute [local irreducible] run Rolling1588TickGap.forward Rolling1588.Integer.regularForward theorem forward_phase (d:Bool) (x:Nat) (good:Bounds x p) (i n:Nat) (lo:1 ≤ i) (hi:i+n≤512) (s:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p i s.basis): (run (Rolling1588TickGap.forward d i n) m (pullState (OB5.sig (i-1)) s)).phase=s.phase:=by have spec:=Rolling1588TickGap.forward_gen d x good.nonzero good.small n i lo hi s m stage obtain ⟨hp0,odd,cap,cop⟩:=StackOB5.prime_facts x good.nonzero good.small have ph:=(Rolling1588.Integer.regularForward_spec base d base_pool_nodup StackOB5.historyAbove x p i n hp0 good.nonzero odd cap (by norm_num [p]) good.small cop hi s m stage).1 exact (congrArg State.phase spec).trans ph end ECDSAAdd.Entrant.StairPacket.StockBaseline end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed BalancedField Rolling1588 StairArchiveRaw StairArchiveTrace open CodecBitSliceVerify StairArchiveNativeRows StairArchiveNativeCut StairArchiveRelease open WindowFieldMask ArchiveFieldScratch StairField2V3Seg def wire (q : Wire) := StairArchiveInactive.host (OB5.sig 511 q) theorem injective : Function.Injective wire := StairArchiveInactive.host.injective.comp (OB5.sig_injective 511 (by decide)) def high (q : Nat) := decide (8≤q) def lane (q : Nat) : Fin 10 := ⟨if q%8<5 then q%8 else q%8+1,by split <;> omega⟩ def histPort (j q : Nat) := History5.historyMap base (5*(j+(if high q then 1 else 0))) (lane q) def physical (j : Nat) := ((List.range 16).all (fun q=>fieldPort j q == wire (histPort j q))) && (fieldPort j 16 == base 720) && (List.range' 17 104).all (fun q=>fieldPort j q == wire (base (Placement5.H (8+(q-17))))) private theorem physicalHead : WindowBankCheck.banks.all (fun j => (List.range 16).all (fun q=>fieldPort j q == wire (histPort j q)))=true := by decide +kernel private theorem physicalTail : ((fieldPort 0 16 == base 720) && (List.range' 17 104).all (fun q=>fieldPort 0 q == wire (base (Placement5.H (8+(q-17))))))=true := by decide +kernel private theorem physical_ok : WindowBankCheck.banks.all physical=true := by rw [List.all_eq_true] intro j hj have hh := List.all_eq_true.mp physicalHead j hj have tl := physicalTail simp only [physical, Bool.and_eq_true, List.all_eq_true, beq_iff_eq] at hh tl ⊢ refine ⟨⟨hh, by rw [fieldPort_tail j 16 (le_refl _)]; exact tl.1⟩, fun q hq => ?_⟩ rw [fieldPort_tail j q (by have := List.mem_range'_1.mp hq; omega)] exact tl.2 q hq def lookup (l h : Bool) := (List.range 16).all (fun q=> CodecBitSliceVerify.get (StairArchiveNativeCut.canonical l h) q == CodecBitSliceVerify.get (storage (native (if high q then h else l) (high q))) (lane q)) private theorem lookup_ok (l h : Bool) : lookup l h=true := by cases l <;> cases h <;> decide +kernel private theorem upper_zero (l h : Bool) : (List.range' 16 105).all (fun q=>CodecBitSliceVerify.get (StairArchiveNativeCut.canonical l h) q == 0)=true := by cases l <;> cases h <;> decide +kernel set_option maxRecDepth 4000 set_option maxHeartbeats 600000 attribute [local irreducible] run wire StairArchiveNativeCut.canonical StairArchiveRelease.fieldPort CodecBitSliceVerify.get def boundaryCols (j c : Nat) := StairArchiveNativeCut.canonical (decide (c≤j)) (decide (c≤j+1)) end ECDSAAdd.Entrant.StairPacket.WindowFieldView end section namespace ECDSAAdd.Entrant.StairPacket.WindowParityDirty set_option maxRecDepth 3000 set_option maxHeartbeats 500000 set_option linter.unusedSimpArgs false attribute [local irreducible] run mcx chain instance (t : Wire) (g : Aff) : Decidable (lawful t g) := by cases g <;> unfold lawful <;> infer_instance instance (q j : Wire) (xs : Hops) : Decidable (outside q j xs) := by unfold outside; infer_instance instance dsafe (last target src : Wire) (xs : Hops) : Decidable (safe last target src xs) := by cases xs with | nil => unfold safe; infer_instance | cons pair tail => obtain ⟨c,b⟩ := pair letI := dsafe last target b tail unfold safe; infer_instance end ECDSAAdd.Entrant.StairPacket.WindowParityDirty end section namespace ECDSAAdd.Entrant.Stair44DivTerm open Arithmetic MappedCompressed Secp256k1 OB5 DirectSkywalk Rolling1588.Integer Stair44WalkMap set_option maxRecDepth 12000 set_option maxHeartbeats 2000000 attribute [local irreducible] run wires measurementCount regularForward Rolling1588.reverse Stair44WalkRun.backward FrontierEntry1591NativeH.inverse FrontierEntry1591Native.forward private def firstSites := [1026,514,1541,501,1542,500] private theorem fixed (s : State) (z : ∀j∈firstSites,s.basis (base j)=false) : pullState first s=s := by have a := cleanWireRebind id s s _ _ rfl (z 1026 (by decide)) (z 514 (by decide)) have b := cleanWireRebind _ s s _ _ a (z 1541 (by decide)) (z 501 (by decide)) exact cleanWireRebind _ s s _ _ b (z 1542 (by decide)) (z 500 (by decide)) private theorem input_zero (x y : Nat) (s : State) (input : SkywalkArithmeticInput base x y s.basis) : ∀j∈firstSites,s.basis (base j)=false := by have chk : ∀j∈firstSites,base j∈skywalkSharedWires base ∧ base j∉skywalkArithmeticDivisor base ∧ base j∉skywalkArithmeticNumerator base := by decide +kernel intro j hj obtain ⟨a,b,c⟩ := chk j hj exact input.2.2 _ a b c private theorem byPool {P : Program} (bound : wires P ⊆ (skywalkPoolWires base).toFinset) (t u : State) (bits : ∀q∈skywalkPoolWires base,t.basis q=u.basis q) (m : List Bool) : ∀q∈skywalkPoolWires base,(run P m t).basis q=(run P m u).basis q := by let v : State := ⟨t.phase,u.basis⟩ have h := pool_run_agrees P _ bound m t v rfl (fun q hq => bits q (List.mem_toFinset.mp hq)) intro q hq exact (h.2 q (List.mem_toFinset.mpr hq)).trans (congrFun (run_basis_records P v u m m rfl) q) theorem inverse_end (x y : Nat) (hx : x.mp ((StackOB5.support_gen i n lo hi).2 q h) exact List.mem_toFinset.mpr (StackOB5Base.base_pool k (by omega)) end ECDSAAdd.Entrant.StairPacket.PartialSites end section namespace ECDSAAdd.Entrant.StairPacket.StockRowVector open Arithmetic MappedCompressed Secp256k1 StockCanonicalRow StockStrongChain open StairArchiveRaw WideReference ArchiveStockSuffix ArchivePortAction set_option maxHeartbeats 2500000 set_option maxRecDepth 10000 theorem historical (b i x p:Nat) (c:SkywalkNat.State→Bool) (r:Nat) (labels:Encodes (value x p i b c) r):ArchiveStockRows.Chronology i x p r:=by intro j have bit:=labels ⟨j,by omega⟩ simpa only [value,key,rawBit,j.isLt,if_true] using bit end ECDSAAdd.Entrant.StairPacket.StockRowVector end section namespace ECDSAAdd.Entrant.StairPacket.StockWalkPrefix open Arithmetic MappedCompressed Secp256k1 WideReference set_option maxRecDepth 8500 set_option maxHeartbeats 2000000 attribute [local irreducible] run Rolling1588TickGap.forward Rolling1588.Integer.regularForward measurementCount renameProgram def first (d:Bool):Program:=Stair44WalkRun.forward d 29 def regular (d:Bool) (s:State) (m:List Bool):State:=run (Rolling1588.Integer.regularForward base d 1 44) m s theorem cut120 (d:Bool) (x:Nat) (good:Bounds x p) (s a:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 1 s.basis) (input:pullState Stair44WalkMap.first a=s): Rolling1588.Integer.Stage base d x p 45 (regular d s m).basis ∧ pullState Stair44WalkMap.rest (run (first d) m a)=pullState (OB5.sig 44) (regular d s m):=by obtain ⟨hp0,odd,cap,cop⟩:=StackOB5.prime_facts x good.nonzero good.small have spec:=Rolling1588.Integer.regularForward_spec base d base_pool_nodup StackOB5.historyAbove x p 1 44 hp0 good.nonzero odd cap (by norm_num [p]) good.small cop (by decide) s m stage refine ⟨spec.2,?_⟩ have entry:=Stair44WalkRun.forward_run d 29 x good.nonzero good.small s a m stage input have logical:=Rolling1588TickGap.forward_gen d x good.nonzero good.small 44 1 (by decide) (by decide) s m stage have init:pullState (OB5.sig 0) s=s:=by apply State.extensionality _ s · rfl · funext q;exact congrArg s.basis (OB5.sig_zero q) rw [show 1-1=0 from rfl,init] at logical exact entry.trans logical def forwardEnd (d:Bool) (n:Nat):Program:=Shadow20.MixedWindow.forwardMixedCut d++Rolling1588TickGap.forward d 421 n theorem split (d:Bool) (n:Nat):WindowWalkCosts.forward d n=first d++renameProgram Stair44WalkMap.rest (forwardEnd d n):=by simp only [WindowWalkCosts.forward,first,Stair44WalkRun.forward,forwardEnd,renameProgram,List.map_append,List.append_assoc] theorem placed (d:Bool) (n x:Nat) (good:Bounds x p) (s a:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 1 s.basis) (input:pullState Stair44WalkMap.first a=s): pullState Stair44WalkMap.rest (run (WindowWalkCosts.forward d n) m a)= run (forwardEnd d n) (m.drop (measurementCount (first d))) (pullState (OB5.sig 44) (regular d s m)):=by rw [split,run_append,run_take,run_rename _ Stair44WalkMap.rest.injective,(cut120 d x good s a m stage input).2] end ECDSAAdd.Entrant.StairPacket.StockWalkPrefix end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed BalancedField StairArchiveTen StairArchiveInactive open StairArchiveNativeCut ArchiveFieldScratch WindowFieldMask WindowFieldCosts StairField2V3Seg attribute [local irreducible] run wires measurementCount wire group StairArchiveInactive.packet set_option maxRecDepth 2600 set_option maxHeartbeats 500000 def surface : Finset Wire := ((Finset.Icc 1 84).biUnion (fun j=>wires (packet false j) ∪ wires (packet true j))) ∪ bankIds.biUnion inside def tracks (actual ideal : State) := ∀q∈surface,q≠base 720→actual.basis q=ideal.basis q def StockCut (c : Nat) (origin : BasisState) (r : State) : Prop := r.basis (base 720)=false ∧ ∃ (X Y : Fp) (ideal : State), Rolling1588.CutFrame c origin X Y (pullState wire ideal) ∧ tracks r ideal private def allowedTag (k : Nat) := !(cover k).contains (preimage k (base 720)) private theorem tagged : (List.range' 1 84).all allowedTag=true := by decide +kernel private theorem packetUses (d : Bool) (k : Nat) (lo : 1≤k) (hi : k≤84) {q : Wire} (h : q∈wires (packet d k)) : q∈surface ∧ q≠base 720 := by constructor · apply Finset.mem_union_left apply Finset.mem_biUnion.mpr refine ⟨k,Finset.mem_Icc.mpr ⟨lo,hi⟩,?_⟩ cases d · exact Finset.mem_union_left _ h · exact Finset.mem_union_right _ h · rintro rfl have yes := original d k (by omega) h have no := List.all_eq_true.mp tagged k (List.mem_range'_1.mpr ⟨lo,by omega⟩) simp [allowedTag,yes] at no private theorem follow (P : Program) (m : List Bool) (a b : State) (h : tracks a b) (tag : a.basis (base 720)=false) (incl : ∀q∈wires P,q∈surface ∧ q≠base 720) : tracks (run P m a) (run P m b) ∧ (run P m a).basis (base 720)=false := by have bound := Arithmetic.run_local_increment P a b m (fun q hq=>h q (incl q hq).1 (incl q hq).2) constructor · intro q use off by_cases gate : q∈wires P · exact bound.2 q gate · rw [run_preserves_outside _ _ _ _ gate,run_preserves_outside _ _ _ _ gate,h q use off] · rw [run_preserves_outside _ _ _ _ (fun use=>(incl _ use).2 rfl),tag] end ECDSAAdd.Entrant.StairPacket.WindowFieldView end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldParity open Arithmetic MappedCompressed CodecBitSliceVerify StairArchiveNativeRows WindowParityDirty set_option maxRecDepth 8000 set_option maxHeartbeats 2500000 set_option exponentiation.threshold 100000 set_option linter.unusedSimpArgs false def parity (cs : Cols) := ((List.range 16).map (get cs)).foldr (· ^^^ ·) 0 theorem matchedParity (d : Bool) : parity (ArchivePortAction.code d) = parity (StairArchiveNativeCut.canonical d d) := by cases d <;> decide +kernel theorem region_run (d : Bool) (row : Nat) (_rb : row<63145) (m : List Bool) (s : State) (_data : ∀i<16,s.basis i=(get (ArchivePortAction.code d) i).testBit row) : run region m s = flip 16 (((parity (ArchivePortAction.code d)).testBit row) ^^ ((parity (StairArchiveNativeCut.canonical d d)).testBit row)) s := by simp [region, run, matchedParity] end ECDSAAdd.Entrant.StairPacket.WindowFieldParity end section namespace ECDSAAdd.Entrant.Stair44Kernel open Arithmetic MappedCompressed Secp256k1 OB5 DirectSkywalk Rolling1588.Integer Stair44WalkMap set_option maxRecDepth 12000 set_option maxHeartbeats 2000000 attribute [local irreducible] run wires measurementCount regularForward Rolling1588TickGap.forward Stair44WalkRun.forward FrontierEntry1591Native.forward def firstR := renameProgram first (FrontierEntry1591Native.forward base) def openR (d : Bool) (a : Nat) := firstR ++ Stair44WalkRun.forward d a def openS (d : Bool) (a : Nat) := FrontierEntry1591Native.forward base ++ Rolling1588TickGap.forward d 1 (15+a) private theorem inFix (x y : Nat) (s : State) (h : SkywalkArithmeticInput base x y s.basis) : pullState first s=s := by let l := [1026,514,1541,501,1542,500] have tab : ∀j∈l,base j∈skywalkSharedWires base ∧ base j∉skywalkArithmeticDivisor base ∧ base j∉skywalkArithmeticNumerator base := by decide +kernel have z (j : Nat) (hj : j∈l) := h.2.2 _ (tab j hj).1 (tab j hj).2.1 (tab j hj).2.2 have a := cleanWireRebind id s s _ _ rfl (z 1026 (by decide)) (z 514 (by decide)) have b := cleanWireRebind _ s s _ _ a (z 1541 (by decide)) (z 501 (by decide)) exact cleanWireRebind _ s s _ _ b (z 1542 (by decide)) (z 500 (by decide)) theorem open_count (d : Bool) (a : Nat) : measurementCount (openR d a)=measurementCount (openS d a) := by rw [openR,openS,measurementCount_append,measurementCount_append,firstR,(renameProgram_counts _ _).2, (Stair44WalkRun.metrics d a).1.2.1] theorem open_run (d : Bool) (a x y : Nat) (atCut : 1+(15+a)∈[425,505,506]) (hx0 : 0 q==16 || regular (host.symm (fieldPort j q))) private theorem portsHead : WindowBankCheck.banks.all (fun j => (List.range 16).all (fun q => regular (host.symm (fieldPort j q))))=true := by decide +kernel private theorem portsTail : (List.range' 16 105).all (fun q => q==16 || regular (host.symm (fieldPort 0 q)))=true := by decide +kernel private theorem portsCheck : WindowBankCheck.banks.all archiveGood=true := by rw [List.all_eq_true] intro j hj have hh := List.all_eq_true.mp portsHead j hj rw [archiveGood, List.all_eq_true] intro q hq have hq' := List.mem_range.mp hq by_cases lo : q < 16 · have e := List.all_eq_true.mp hh q (List.mem_range.mpr lo) simp only [e, Bool.or_true] · have e := List.all_eq_true.mp portsTail q (List.mem_range'_1.mpr ⟨by omega, by omega⟩) rw [fieldPort_tail j q (by omega)] exact e private theorem cleanPort (j q : Nat) (jb : j∈bankIds) (qb : q<121) (ne : fieldPort j q≠base 720) : Off (host.symm (fieldPort j q)) ∧ host.symm (fieldPort j q)∉futurePayload 87 := by have jm : j∈WindowBankCheck.banks := by simpa [bankIds,WindowBankCheck.banks] using jb have ok := List.all_eq_true.mp (List.all_eq_true.mp portsCheck _ jm) q (List.mem_range.mpr qb) have eq16 : fieldPort j 16=base 720 := by simp only [bankIds,Finset.mem_insert,Finset.mem_singleton] at jb rcases jb with rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl <;> decide have qne : q≠16 := fun h=>ne (h ▸ eq16) simp only [beq_iff_eq,Bool.or_eq_true,regular,Bool.and_eq_true,Bool.not_eq_true'] at ok rcases ok with h|⟨f,g⟩ · contradiction · refine ⟨off_of_not_EP _ ?_,?_⟩ · intro h; simp [h] at f · intro h; simp [h] at g private theorem packet_original (d : Bool) (k : Nat) : packet d k=renameProgram host (renameProgram (OB5.sig 511) (Rolling1588.packet d k)) := by rw [packet,hosts_eq,StairGroups.packet_zero]; rfl private theorem groupOne (d : Bool) (k : Nat) : Rolling1588.groups d k 1=Rolling1588.packet d k := by cases d <;> simp only [Rolling1588.groups,PacketSequence.program,Bool.false_eq_true,if_true,if_false, List.nil_append,List.append_nil] attribute [local irreducible] surface StairArchiveInactive.host OB5.sig wires Rolling1588.packet Rolling1588.groups StairArchiveInactive.packet futurePayload Off theorem reliable {q : Wire} (use : q∈surface) (ntag : q≠base 720) : Off (host.symm q) ∧ host.symm q∉futurePayload 87 := by rw [surface,Finset.mem_union] at use rcases use with packet_|archive_ · obtain ⟨k,hk,dirs⟩ := Finset.mem_biUnion.mp packet_ obtain ⟨lo,hi⟩ := Finset.mem_Icc.mp hk have both (d : Bool) (used : q∈wires (packet d k)) : Off (host.symm q) ∧ host.symm q∉futurePayload 87 := by rw [packet_original,renameProgram_support] at used obtain ⟨v,hv,rfl⟩ := Finset.mem_image.mp used rw [Equiv.symm_apply_apply] rw [←groupOne d k] at hv constructor · cases d · exact StairField2V3ExitRec.groupsF_off k 1 lo (by omega) v hv · exact groups_off k 1 lo (by omega) v hv · intro bad exact StairField2V3Groups.groups_avoid_payload d 87 (by decide) 1 k (by change k+1≤85; omega) v bad hv exact (Finset.mem_union.mp dirs).elim (both false) (both true) · obtain ⟨j,hj,hq⟩ := Finset.mem_biUnion.mp archive_ obtain ⟨i,hi,rfl⟩ := Finset.mem_image.mp hq exact cleanPort j i hj (Finset.mem_range.mp hi) ntag theorem from_record (c : Nat) (origin : BasisState) (X Y : Fp) (r s : State) (cut : Rolling1588.CutFrame c origin X Y (pullState (OB5.sig 511) s)) (tag : r.basis (base 720)=false) (hosted : ∀q, r.basis (host q)=r.basis q) (agrees : ∀ q, Off q → q∉futurePayload 87 → r.basis q=s.basis q) : StockCut c origin r := by let b := pullState host.symm s have back : pullState wire b=pullState (OB5.sig 511) s := by apply State.extensionality; · rfl funext q; change s.basis (host.symm (host (OB5.sig 511 q)))=_ rw [Equiv.symm_apply_apply]; rfl refine ⟨tag,X,Y,b,back.symm ▸ cut,?_⟩ intro q hq ntag have ready := reliable hq ntag have fixed := hosted (host.symm q) rw [Equiv.apply_symm_apply] at fixed exact fixed.trans (agrees _ ready.1 ready.2) theorem host_fixed (r : State) (zero : ∀q∈StairSchedule.exclusiveRoles++hosts 87,r.basis q=false) : ∀q,r.basis (host q)=r.basis q := by have general (rs hs : List Wire) (clean : ∀q∈rs++hs,r.basis q=false) : ∀q,r.basis (rebinder rs hs q)=r.basis q := by induction rs generalizing hs with | nil => cases hs <;> intro q <;> rfl | cons a rest ih => cases hs with | nil => intro q; rfl | cons b tail => intro q have a0 := clean a (by simp) have b0 := clean b (by simp) have tails := ih tail (fun q h => clean q (by simpa only [List.mem_append,List.mem_cons] using (show (q=a ∨ q∈rest) ∨ q=b ∨ q∈tail from by rcases List.mem_append.mp h with left|right; exact Or.inl (Or.inr left); exact Or.inr (Or.inr right)))) change r.basis ((Equiv.swap a b) (rebinder rest tail q)) = _ rw [←tails q]; generalize rebinder rest tail q=v by_cases av : v=a · subst v; simp [a0,b0] by_cases bv : v=b · subst v; simp [a0,b0] rw [Equiv.swap_apply_of_ne_of_ne av bv] rw [host]; exact general _ _ zero end ECDSAAdd.Entrant.StairPacket.WindowFieldView end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed BalancedField StairArchiveTen StairArchiveInactive open StairArchiveNativeCut ArchiveFieldScratch WindowFieldMask WindowFieldCosts StairField2V3Seg WindowFieldJourney attribute [local irreducible] run group ten measurementCount packet surface ArchiveStockRows.Chronology Rolling1588.CutFrame StairArchiveNativeCut.canonical set_option maxRecDepth 1600 set_option maxHeartbeats 400000 def span : Leg → Nat×Nat | .native j n => (j,n) | .paired j => (j,2) def next (d : Bool) (l : Leg) := if d then (span l).1+(span l).2 else (span l).1 def prev (d : Bool) (l : Leg) := if d then (span l).1 else (span l).1+(span l).2 def feasible : Leg→Prop | .native j n => 1≤j ∧ j+n≤85 | .paired j => j∈bankIds def path (d : Bool) : Nat→List Leg→Prop | _,[] => True | c,l::ls => c=prev d l ∧ feasible l ∧ path d (next d l) ls end ECDSAAdd.Entrant.StairPacket.WindowFieldView end -- oddten:begin SEM section namespace ECDSAAdd.Entrant.StairArchiveInactive set_option maxHeartbeats 900000 set_option maxRecDepth 22000 attribute [local irreducible] StairPacket.WindowFieldCosts.opk wires preimage cover savedSites /-- oddten: dadon's `packet_avoids` for the field group's own packets (through the record footprint). -/ theorem ot_packet_avoids (j : Nat) (hj : j∈ECDSAAdd.Entrant.StairPacket.Shadow20.MixedFieldBanks.mixedBankList) (d second : Bool) (q : Wire) (save : q∈savedSites j second) : q∉wires (StairPacket.WindowFieldCosts.opk d (if second then j+1 else j)) := fun used => ECDSAAdd.Entrant.StairPacket.Shadow20.MixedFieldBanks.packet_avoids_mixed j hj d second q save (StairPacket.WindowFieldCosts.ot_opk_sub d _ used) /-- oddten: dadon's `advance`, packet := the field group's own packet. -/ theorem ot_advance (start : Nat) (hs : start∈ECDSAAdd.Entrant.StairPacket.Shadow20.MixedFieldBanks.mixedBankList) (d second : Bool) (m : List Bool) (reference actual : State) (same : ∀ q ∉ savedSites start second, actual.basis q = reference.basis q) : let p := StairPacket.WindowFieldCosts.opk d (if second then start+1 else start) ((run p m actual).phase ^^ actual.phase) = ((run p m reference).phase ^^ reference.phase) ∧ (∀ q ∉ savedSites start second, (run p m actual).basis q = (run p m reference).basis q) ∧ (∀ q ∈ savedSites start second, (run p m actual).basis q = actual.basis q) := by let p := StairPacket.WindowFieldCosts.opk d (if second then start+1 else start) have unchanged := ot_packet_avoids start hs d second have act := Arithmetic.run_local_increment p actual reference m (fun q hq => same q (fun h => unchanged q h hq)) refine ⟨act.1, ?_, fun q hq => run_preserves_outside p m actual q (unchanged q hq)⟩ intro q keep by_cases used : q∈wires p · exact act.2 q used · exact (run_preserves_outside p m actual q used).trans ((same q keep).trans (run_preserves_outside p m reference q used).symm) end ECDSAAdd.Entrant.StairArchiveInactive end section namespace ECDSAAdd.Entrant.StairArchiveNativeCut open Arithmetic CodecBitSliceVerify StairArchiveRelease StairArchiveSlots StairArchiveNativeRows open StairArchiveInactive set_option maxRecDepth 20000 set_option maxHeartbeats 3000000 attribute [local irreducible] run StairPacket.WindowFieldCosts.opk fieldHook fieldPort inputCols outputCols CodecBitSliceVerify.get savedSites theorem ot_xor_cancel (a b c : Bool) (h : (a ^^ c)=(b ^^ c)) : a=b := by cases a <;> cases b <;> cases c <;> simp_all /-- oddten: dadon's `stage_packet` (one hook, then the field group's own packet). -/ theorem ot_stage_packet (j : Nat) (hstart : j∈ECDSAAdd.Entrant.StairPacket.Shadow20.MixedFieldBanks.mixedBankList) (hj : j∈List.range' 1 83) (rev last : Bool) (row : Nat) (hr : row<63145) (m n : List Bool) (a ref : State) (change : frame j row (inputCols (fromStage rev last)) a) (out : exterior j a ref) (phase : a.phase=ref.phase) (entryFrame : frame j row (before rev last) ref) (endFrame : frame j row (after rev last) (run (StairPacket.WindowFieldCosts.opk (!rev) (if rev ^^ last then j+1 else j)) n ref)) : let c := run (fieldHook j (fromStage rev last)) m a let p := StairPacket.WindowFieldCosts.opk (!rev) (if rev ^^ last then j+1 else j) let s := run p n c let t := run p n ref s.phase=t.phase ∧ exterior j s t ∧ frame j row (inputCols (toStage rev last)) s := by let active := rev ^^ last let fromC := outputCols (fromStage rev last) let toC := inputCols (toStage rev last) let c := run (fieldHook j (fromStage rev last)) m a let p := StairPacket.WindowFieldCosts.opk (!rev) (if active then j+1 else j) have admin := StairArchiveAllPorts.field_run j hj _ row hr m a change have hchecks := all_checks rev last change (agrees active false fromC (before rev last) && agrees active false toC (after rev last) && agrees active true fromC toC)=true at hchecks simp only [Bool.and_eq_true] at hchecks have same : ∀ z∉savedSites j active, c.basis z=ref.basis z := by intro z hz by_cases hz' : z∈inside j · obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp hz' have hh : q∉held active := fun h => hz ((held_at j hj active q hq).mpr h) exact (admin.2.1 q hq).trans ((congrArg (fun v : Nat => v.testBit row) (column _ _ _ _ hchecks.1.1 q hq (decide_eq_false hh))).trans (entryFrame q hq).symm) · exact (admin.2.2 z hz').trans (out z hz') have body : ((run p n c).phase ^^ c.phase) = ((run p n ref).phase ^^ ref.phase) ∧ (∀ z ∉ savedSites j active, (run p n c).basis z = (run p n ref).basis z) ∧ (∀ z ∈ savedSites j active, (run p n c).basis z = c.basis z) := ot_advance j hstart (!rev) active n ref c same have cphase : c.phase=ref.phase := admin.1.trans phase change (run p n c).phase = (run p n ref).phase ∧ exterior j (run p n c) (run p n ref) ∧ frame j row toC (run p n c) refine ⟨?_, ?_, ?_⟩ · have v := body.1 change ((run p n c).phase ^^ c.phase) = ((run p n ref).phase ^^ ref.phase) at v rw [cphase] at v exact ot_xor_cancel _ _ _ v · intro z hz apply body.2.1 z intro h rw [held_eq j hj active] at h obtain ⟨q,hq,rfl⟩ := List.mem_map.mp h exact hz (Finset.mem_image.mpr ⟨q,held_bounded _ hq,rfl⟩) · intro q hq by_cases hold : q∈held active · exact (body.2.2 _ ((held_at j hj active q hq).mpr hold)).trans ((admin.2.1 q hq).trans (congrArg (fun v : Nat => v.testBit row) (column _ _ _ _ hchecks.2 q hq (decide_eq_true hold)))) · exact (body.2.1 _ (fun z => hold ((held_at j hj active q hq).mp z))).trans ((endFrame q hq).trans (congrArg (fun v : Nat => v.testBit row) (column _ _ _ _ hchecks.1.2 q hq (decide_eq_false hold))).symm) end ECDSAAdd.Entrant.StairArchiveNativeCut end section namespace ECDSAAdd.Entrant.StairArchiveTen open CodecBitSliceVerify StairArchiveRelease StairArchiveNativeCut StairArchiveInactive open ArchiveFieldScratch StairPacket.WindowFieldCosts def otapeS (j : Nat) (rev : Bool) (m : List Bool) := (tapeA j rev m).drop (measurementCount (ofirst j rev)) def otapeB (j : Nat) (rev : Bool) (m : List Bool) := (otapeS j rev m).drop (measurementCount (fieldHook j (shift rev))) def otapeL (j : Nat) (rev : Bool) (m : List Bool) := (otapeB j rev m).drop (measurementCount (osecond j rev)) def orefMiddle (j : Nat) (rev : Bool) (m : List Bool) (s : State) := run (ofirst j rev) (tapeA j rev m) s def orefExit (j : Nat) (rev : Bool) (m : List Bool) (s : State) := run (osecond j rev) (otapeB j rev m) (orefMiddle j rev m s) set_option maxRecDepth 20000 set_option maxHeartbeats 800000 /-- oddten: dadon's `ten_run` around the field group's own packets. -/ theorem ot_ten_run (j : Nat) (hs : j∈ECDSAAdd.Entrant.StairPacket.Shadow20.MixedFieldBanks.mixedBankList) (hj : j∈List.range' 1 83) (rev : Bool) (row : Nat) (hr : row<63145) (m : List Bool) (a r : State) (arch : frame j row (inputCols (enter rev)) a) (same : exterior j a r) (ph : a.phase = r.phase) (before_ : frame j row (canonical (!rev) (!rev)) r) (middle_ : frame j row middle (orefMiddle j rev m r)) (after_ : frame j row (canonical rev rev) (orefExit j rev m r)) : let actual := run (oten j rev) m a let final := orefExit j rev m r actual.phase=final.phase ∧ exterior j actual final ∧ frame j row (outputCols (leave rev)) actual := by let a0 := run (fieldHook j (enter rev)) m a let a1 := run (ofirst j rev) (tapeA j rev m) a0 let a2 := run (fieldHook j (shift rev)) (otapeS j rev m) a1 let a3 := run (osecond j rev) (otapeB j rev m) a2 let a4 := run (fieldHook j (leave rev)) (otapeL j rev m) a3 have f : a1.phase=(orefMiddle j rev m r).phase ∧ exterior j a1 (orefMiddle j rev m r) ∧ frame j row (inputCols (shift rev)) a1 := by simpa only [fromStage, toStage, before, after, Bool.false_eq_true, if_false, Bool.xor_false, ofirst, orefMiddle] using ot_stage_packet j hs hj rev false row hr m (tapeA j rev m) a r arch same ph before_ (by simpa only [after, Bool.false_eq_true, if_false, Bool.xor_false, ofirst, orefMiddle] using middle_) have z : a3.phase=(orefExit j rev m r).phase ∧ exterior j a3 (orefExit j rev m r) ∧ frame j row (inputCols (leave rev)) a3 := by have eq : (if rev ^^ true then j+1 else j) = (if rev then j else j+1) := by cases rev <;> rfl simpa only [fromStage, toStage, before, after, if_true, eq, osecond, orefExit] using ot_stage_packet j hs hj rev true row hr (otapeS j rev m) (otapeB j rev m) a1 (orefMiddle j rev m r) f.2.2 f.2.1 f.1 middle_ (by simpa only [after, if_true, eq, osecond, orefExit] using after_) have last := StairArchiveAllPorts.field_run j hj (leave rev) row hr (otapeL j rev m) a3 z.2.2 have shape : run (oten j rev) m a = a4 := by simp only [oten, run_append, run_take] rfl rw [shape] exact ⟨last.1.trans z.1, fun q hq => (last.2.2 q hq).trans (z.2.1 q hq), last.2.1⟩ end ECDSAAdd.Entrant.StairArchiveTen end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldMask open Arithmetic MappedCompressed StairArchiveRelease StairArchiveNativeCut StairArchiveInactive open ArchiveFieldScratch StairArchiveTen CodecBitSliceVerify WindowFieldCosts attribute [local irreducible] run StairArchiveInactive.packet StairArchiveRelease.fieldHook WindowFieldCosts.ofirst WindowFieldCosts.osecond WindowFieldCosts.oten StairArchiveRelease.fieldPort StairArchiveRelease.outputCols StairArchiveRelease.inputCols StairArchiveNativeCut.canonical CodecBitSliceVerify.get set_option maxRecDepth 1200 set_option maxHeartbeats 360000 set_option linter.constructorNameAsVariable false /-- oddten: dadon's `ten_masked` around the field group's own packets. -/ theorem ot_ten_masked (j : Nat) (hs : j ∈ ECDSAAdd.Entrant.StairPacket.Shadow20.MixedFieldBanks.mixedBankList) (hj : j ∈ List.range' 1 83) (rev : Bool) (row : Nat) (hr : row < 63145) (m : List Bool) (a r : State) (other : Finset Wire) (apart : ∀ q ∈ inside j, q ∉ other) (ha : avoids (ofirst j rev) other) (hb : avoids (osecond j rev) other) (arch : frame j row (inputCols (enter rev)) a) (same : offBanks (bank j) other a r) (ph : a.phase = r.phase) (before_ : frame j row (StairArchiveNativeCut.canonical (!rev) (!rev)) r) (middle_ : frame j row middle (orefMiddle j rev m r)) (after_ : frame j row (StairArchiveNativeCut.canonical rev rev) (orefExit j rev m r)) : let next := run (oten j rev) m a let final := orefExit j rev m r next.phase = final.phase ∧ offBanks (bank j) other next final ∧ frame j row (outputCols (leave rev)) next := by let shadow := mask other a r have mid : orefMiddle j rev m shadow = mask other a (orefMiddle j rev m r) := by exact mask_run (ofirst j rev) other _ a r ha have fin : orefExit j rev m shadow = mask other a (orefExit j rev m r) := by unfold orefExit rw [mid, mask_run] exact hb have outer : exterior j a shadow := by intro q hq by_cases qmem : q ∈ other · simp [shadow, mask, qmem] · have qbank : q ∉ bank j := by intro bad obtain ⟨k,hk,rfl⟩ := Finset.mem_image.mp bad exact hq (Finset.mem_image.mpr ⟨k,Finset.mem_range.mpr (by have := Finset.mem_range.mp hk; omega),rfl⟩) simpa [shadow,mask,qmem] using same q qbank qmem have mm : frame j row middle (orefMiddle j rev m shadow) := mid ▸ mask_frame _ _ _ _ _ _ apart middle_ have ff : frame j row (StairArchiveNativeCut.canonical rev rev) (orefExit j rev m shadow) := fin ▸ mask_frame _ _ _ _ _ _ apart after_ have result := ot_ten_run j hs hj rev row hr m a shadow arch outer ph (mask_frame _ _ _ _ _ _ apart before_) mm ff obtain ⟨phase,ext,stored⟩ := result refine ⟨?_,?_,stored⟩ · rw [fin] at phase exact phase · intro q notbank notother by_cases qin : q ∈ inside j · obtain ⟨k,hk,rfl⟩ := Finset.mem_image.mp qin have lower : 16 ≤ k := by by_contra! h exact notbank (Finset.mem_image.mpr ⟨k, Finset.mem_range.mpr h, rfl⟩) have upper := Finset.mem_range.mp hk have kn : k ∈ List.range' 16 105 := List.mem_range'_1.mpr ⟨lower,by omega⟩ have col := beq_iff_eq.mp (List.all_eq_true.mp (restored rev) k kn) rw [stored k hk,after_ k hk,col] · have x := ext q qin rw [fin] at x simpa [mask, notother] using x end ECDSAAdd.Entrant.StairPacket.WindowFieldMask end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldMask open Arithmetic MappedCompressed StairArchiveRelease StairArchiveNativeCut StairArchiveInactive open ArchiveFieldScratch StairArchiveTen CodecBitSliceVerify WindowFieldCosts set_option maxRecDepth 1600 set_option maxHeartbeats 400000 set_option linter.constructorNameAsVariable false attribute [local irreducible] run packet fieldPort StairArchiveNativeCut.canonical inputCols outputCols CodecBitSliceVerify.get attribute [local irreducible] inside StairArchiveRelease.fieldHook WindowFieldCosts.ofirst WindowFieldCosts.osecond WindowFieldCosts.oten WindowFieldCosts.opk WindowFieldCosts.ogroup WindowFieldCosts.group allBanks wires private theorem ot_native_safe (j k : Nat) (hj : j∈bankIds) (which : k=j ∨ k=j+1) (d : Bool) : avoids (opk d k) (others j) := fun q ho used => native_safe j k hj which d q ho (WindowFieldCosts.ot_opk_sub d k used) /-- oddten: dadon's `stepTen` around the field group's own packets. -/ theorem ot_stepTen (j : Nat) (hj : j∈bankIds) (rows : Nat→Nat) (code : Nat→Cols) (rev : Bool) (bound : rows j < 63145) (m : List Bool) (a r : State) (h : Fits rows code a r) (active : code j=inputCols (enter rev)) (before_ : frame j (rows j) (StairArchiveNativeCut.canonical (!rev) (!rev)) r) (middle_ : frame j (rows j) middle (orefMiddle j rev m r)) (after_ : frame j (rows j) (StairArchiveNativeCut.canonical rev rev) (orefExit j rev m r)) : Fits rows (update code j (outputCols (leave rev))) (run (oten j rev) m a) (orefExit j rev m r) := by have ⟨hs,hr⟩ := geometry hj have fa : avoids (ofirst j rev) (others j) := by rw [ofirst]; apply ot_native_safe _ _ hj; cases rev <;> simp have sa : avoids (osecond j rev) (others j) := by rw [osecond]; apply ot_native_safe _ _ hj; cases rev <;> simp have ea : avoids (oten j rev) (others j) := by rw [oten]; exact append_safe (hook_safe j hj _) (append_safe fa (append_safe (hook_safe j hj _) (append_safe sa (hook_safe j hj _)))) have same : offBanks (bank j) (others j) a r := by intro q a0 a1; apply h.outside; rw [decompose j hj,Finset.mem_union]; exact fun hit => hit.elim a0 a1 have result := ot_ten_masked j hs hr rev (rows j) bound m a r (others j) (apart hj) fa sa (beforeFrame j hj rows code rev a r h active (apart hj) before_ (field_inj j hr)) same h.phase before_ middle_ after_ refine ⟨result.1,?_,?_⟩ · intro q off rw [decompose j hj,Finset.mem_union] at off exact result.2.1 q (fun a=>off (Or.inl a)) (fun b=>off (Or.inr b)) · intro k hk i hi by_cases eq : k=j · subst k simpa only [update,if_pos rfl] using result.2.2 i (Finset.mem_range.mpr (by have := Finset.mem_range.mp hi; omega)) · have ho : fieldPort k i∈others j := Finset.mem_biUnion.mpr ⟨k,Finset.mem_erase.mpr ⟨eq,hk⟩,Finset.mem_image.mpr ⟨i,hi,rfl⟩⟩ rw [run_preserves_outside _ m a _ (ea _ ho)] simpa only [update,if_neg eq] using h.bytes k hk i hi theorem ot_groupSafe (d : Bool) (j n : Nat) (valid : nativeRanges j n) : avoids (ogroup d j n) allBanks := fun q hq used => groupSafe d j n valid q hq (WindowFieldCosts.ot_ogroup_sub d j n used) end ECDSAAdd.Entrant.StairPacket.WindowFieldMask end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldHistory open Arithmetic Secp256k1 MappedCompressed BalancedField Rolling1588 StairArchiveRaw StairArchiveTrace open CodecBitSliceVerify StairArchiveNativeRows StairField2V3Seg attribute [local irreducible] run wires rawCol CodecBitSliceVerify.get SkywalkTrace.next set_option linter.unnecessarySeqFocus false set_option maxRecDepth 1400 set_option maxHeartbeats 400000 /-- oddten: `cut_byte` for any word code of the field registers (the bytes are history letters). -/ theorem ot_cut_byte (w : Fp → Nat) (cut j x row : Nat) (positive : 1≤j) (bound : j+2≤102) (rowBound : row<63145) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (tr : TraceOK x origin) (record : ArchiveStockRows.Chronology (5*j-5) x ECDSAAdd.p row) (X Y : Fp) (s : State) (fr : RouteA.Rolling1588.CutFrame w w cut origin X Y s) (hi : Bool) (q : Fin 10) : let k := j+(if hi then 1 else 0) s.basis (History5.historyMap base (5*k) q) = (CodecBitSliceVerify.get (storage (native (decide (cut≤k)) hi)) q).testBit row := by let k := j+(if hi then 1 else 0) have boundK : k<102 := by cases hi <;> simp [k] <;> omega have posK : k≠0 := by cases hi <;> simp [k] <;> omega change s.basis (History5.historyMap base (5*k) q) = (CodecBitSliceVerify.get (storage (native (decide (cut≤k)) hi)) q).testBit row obtain ⟨raw,_,pair,eq⟩ := fr rw [eq,allEncodeCut_factor base cut base_pool_nodup 102 k (by decide) boundK raw] rw [run_preserves_outside _ _ _ _ (StairField2V3LastRecXPar.other_away base cut k base_pool_nodup 102 (by decide) boundK q),encodeGroup,if_neg posK,encodeAt] apply (StockArchiveByte.run_byte (decide (cut≤k)) hi row rowBound (History5.historyMap base (5*k)) (History5.historyMap_injective base base_pool_nodup _ (by omega)) raw [] ?_).2 q intro i have away := History5.history_words_away base (base 2409) ctx.hn (ctx.hp _ (by simp)) (5*k) (by omega) i rw [pair.2.2 _ away.1 away.2] exact originBits j x row (by omega) (by omega) origin tr record hi i end ECDSAAdd.Entrant.StairPacket.WindowFieldHistory end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed BalancedField Rolling1588 StairArchiveRaw StairArchiveTrace open CodecBitSliceVerify StairArchiveNativeRows StairArchiveNativeCut StairArchiveRelease open WindowFieldMask ArchiveFieldScratch StairField2V3Seg set_option maxRecDepth 4000 set_option maxHeartbeats 600000 attribute [local irreducible] run wire StairArchiveNativeCut.canonical StairArchiveRelease.fieldPort CodecBitSliceVerify.get /-- oddten: `observed` for any word code of the field registers. -/ theorem oobserved (w : Fp → Nat) (j c x row : Nat) (hj : j∈WindowBankCheck.banks) (rb : row<63145) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (tr : TraceOK x origin) (history : ArchiveStockRows.Chronology (5*j-5) x ECDSAAdd.p row) (X Y : Fp) (ideal actual : State) (cf : RouteA.Rolling1588.CutFrame w w c origin X Y (pullState wire ideal)) (tag : actual.basis (base 720)=false) (view : ∀q∈inside j,q≠base 720→actual.basis q=ideal.basis q) : frame j row (boundaryCols j c) actual := by have geometry := List.all_eq_true.mp physical_ok j hj simp only [physical,Bool.and_eq_true,beq_iff_eq] at geometry have jBounds : 1≤j ∧ j+2≤102 := by simp only [WindowBankCheck.banks,List.mem_cons,List.mem_nil_iff,or_false] at hj; omega intro q hq have upper := Finset.mem_range.mp hq have eq16 := geometry.1.2 have nd := field_inj j (List.mem_range'_1.mpr (by simp only [WindowBankCheck.banks,List.mem_cons,List.mem_nil_iff,or_false] at hj; omega)) by_cases isTag : q=16 · subst q rw [eq16,tag] have zero := beq_iff_eq.mp (List.all_eq_true.mp (upper_zero (decide (c≤j)) (decide (c≤j+1))) 16 (by decide)) simp [boundaryCols,zero] · have off : fieldPort j q ≠ base 720 := fun he=>isTag (nd _ hq 16 (by decide) (he.trans eq16.symm)) rw [view _ (Finset.mem_image.mpr ⟨q,hq,rfl⟩) off] by_cases low : q<16 · have loc := beq_iff_eq.mp (List.all_eq_true.mp geometry.1.1 q (List.mem_range.mpr low)) rw [loc] have byte := WindowFieldHistory.ot_cut_byte w c j x row jBounds.1 jBounds.2 rb origin ctx tr history X Y (pullState wire ideal) cf (high q) (lane q) change ideal.basis (wire (histPort j q))=_ at byte rw [byte] have col := beq_iff_eq.mp (List.all_eq_true.mp (lookup_ok (decide (c≤j)) (decide (c≤j+1))) q (List.mem_range.mpr low)) unfold boundaryCols; rw [col] cases high q <;> simp · have member : q∈List.range' 17 104 := List.mem_range'_1.mpr ⟨by omega,by omega⟩ have loc := beq_iff_eq.mp (List.all_eq_true.mp geometry.2 q member) rw [loc] have clean := RouteA.Rolling1588.cutFrame_zero_region w w c origin ctx X Y _ cf (Placement5.H (8+(q-17))) (Or.inr (Placement5.H_region (8+(q-17)) (by omega))) change ideal.basis (wire (base (Placement5.H (8+(q-17)))))=false at clean have zero := beq_iff_eq.mp (List.all_eq_true.mp (upper_zero (decide (c≤j)) (decide (c≤j+1))) q (List.mem_range'_1.mpr ⟨by omega,by omega⟩)) simp only [boundaryCols,zero,clean,Nat.zero_testBit] end ECDSAAdd.Entrant.StairPacket.WindowFieldView end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed BalancedField CompressedFieldSupport StairArchiveTen StairArchiveInactive open StairArchiveNativeCut ArchiveFieldScratch WindowFieldMask WindowFieldCosts StairField2V3Seg set_option maxRecDepth 4000 set_option maxHeartbeats 800000 set_option linter.constructorNameAsVariable false attribute [local irreducible] run wires measurementCount StairArchiveInactive.packet WindowFieldCosts.opk WindowFieldCosts.ogroup /-- the word code of the field registers at cut `c` (odd words on cuts 1..85). -/ def oddCutWord (c : Nat) : Fp → Nat := if 1≤c ∧ c≤85 then P1Life.oddWord else centerWord theorem oddCutWord_odd {c : Nat} (h1 : 1≤c) (h2 : c≤85) : oddCutWord c=P1Life.oddWord := if_pos ⟨h1,h2⟩ theorem oddCutWord_center {c : Nat} (h : c<1 ∨ 85 let V := directionalPayload false (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (X,Y) RouteA.Rolling1588.CutFrame (oddCutWord (k+1)) (oddCutWord (k+1)) (k+1) origin V.1 V.2 state) := by rcases (show (1≤k ∧ k<84) ∨ k=84 ∨ 84 by omega) origin ctx enabled X Y · subst h rw [oddPk_end,oddCutWord_odd (c := 84) (by omega) (by omega),oddCutWord_odd (c := 84+1) (by omega) (by omega)] have h0eq := WindowFieldCosts.half760OddLoan_zero_eq true intro state records input have raw := RouteA.Rolling1588.cut_window_frame P1Life.oddWord P1Life.oddWord P1Life.oddWord P1Life.oddWord 84 85 84 (by decide) origin X Y _ _ (OddFullPass.P1LifeLoan.basePacket true 0 84) (ECDSAAdd.Entrant.Rolling1588.otherEncodeCut_step base 84 102) (ECDSAAdd.Entrant.Rolling1588.otherEncodeCut_body_disjoint 84 84 (by decide) origin ctx _ (by have hsub : wires (OddFullPass.P1LifeLoan.basePacket true 0 84) ⊆ wires (ECDSAAdd.Entrant.Rolling1588.basePacket true 84) := by have hp := OddFullPass.P1LifeLoan.packet_wires_sub true 0 84 (by decide) (by decide) rw [OddFullPass.P1LifeLoan.packet,StairGroups.packet_zero,ECDSAAdd.Entrant.Rolling1588.packet, renameProgram_support,renameProgram_support] at hp intro q hq have hi := Finset.mem_image.mp (hp (Finset.mem_image.mpr ⟨q,hq,rfl⟩)) obtain ⟨v,hv,eq⟩ := hi; exact (Equiv.injective _ eq) ▸ hv exact hsub.trans (ECDSAAdd.Entrant.Rolling1588.basePacket_read_support true 84 (by decide)))) (fun current tape frame => by have hcEq : ∀ a b, OddFullPass.P1LifeLoan.cell true 0 84 a b = RouteA.Rolling1588.cell true 84 a b := by intro a b; simp only [OddFullPass.P1LifeLoan.cell,RouteA.Rolling1588.cell, OddFullPass.P1LifeLoan.halfWindow,RouteA.Rolling1588.halfWindow,RouteA.Rolling1588.halfWindowWith,if_true,h0eq] have normalized : RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (ECDSAAdd.Entrant.Rolling1588.codeEncodeAt true (History5.historyMap base (5*84))) origin X Y current := by simpa [ECDSAAdd.Entrant.Rolling1588.encodeGroup] using frame let Frame (k : Nat) (V : Fp×Fp) := RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (ECDSAAdd.Entrant.Rolling1588.stageCodeAt true k (History5.historyMap base (5*84))) origin V.1 V.2 have opening (V : Fp×Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (ECDSAAdd.Entrant.Rolling1588.codeEncodeAt true (History5.historyMap base (5*84))) origin V.1 V.2) (ECDSAAdd.Entrant.Rolling1588.onPacket 84 ECDSAAdd.Entrant.Rolling1588.stageOpen) (Frame 0 V) := fun s r h => RouteA.Rolling1588.regular_open_frame P1Life.oddWord P1Life.oddWord true 84 (by decide) origin ctx V.1 V.2 s r h have step (k logical physical : Nat) (hk : k<3) (used : (logical,physical)∈ECDSAAdd.Entrant.Rolling1588.activeSlots true k) (V : Fp×Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (Frame k V) (RouteA.Rolling1588.cell true 84 physical 2) (Frame k (ECDSAAdd.Entrant.Rolling1588.regularStep true 84 origin logical V)) := fun s r h => RouteA.Rolling1588.regular_cell_frame true 84 k logical physical (by decide) hk used origin ctx enabled V.1 V.2 s r h have transfer (k : Nat) (hk : k<2) (V : Fp×Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (Frame k V) (ECDSAAdd.Entrant.Rolling1588.onPacket 84 (ECDSAAdd.Entrant.Rolling1588.stageTransition true k)) (Frame (k+1) V) := fun s r h => RouteA.Rolling1588.regular_transition_frame P1Life.oddWord P1Life.oddWord true 84 k (by decide) hk origin ctx V.1 V.2 s r h have closing (V : Fp×Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (Frame 2 V) (ECDSAAdd.Entrant.Rolling1588.onPacket 84 ECDSAAdd.Entrant.Rolling1588.stageClose) (RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (ECDSAAdd.Entrant.Rolling1588.codeEncodeAt false (History5.historyMap base (5*84))) origin V.1 V.2) := fun s r h => RouteA.Rolling1588.regular_close_frame P1Life.oddWord P1Life.oddWord true 84 (by decide) origin ctx V.1 V.2 s r h let V1 := ECDSAAdd.Entrant.Rolling1588.regularStep true 84 origin 0 (X,Y) let V2 := ECDSAAdd.Entrant.Rolling1588.regularStep true 84 origin 1 V1 let V3 := ECDSAAdd.Entrant.Rolling1588.regularStep true 84 origin 2 V2 let V4 := ECDSAAdd.Entrant.Rolling1588.regularStep true 84 origin 3 V3 let V5 := ECDSAAdd.Entrant.Rolling1588.regularStep true 84 origin 4 V4 have hres := (opening (X,Y)).seq ((step 0 0 3 (by decide) (by decide) (X,Y)).seq ((step 0 1 4 (by decide) (by decide) V1).seq ((transfer 0 (by decide) V2).seq ((step 1 2 4 (by decide) (by decide) V2).seq ((step 1 3 3 (by decide) (by decide) V3).seq ((transfer 1 (by decide) V4).seq ((step 2 4 4 (by decide) (by decide) V4).seq (closing V5)))))))) have hstep := hres current tape normalized rw [show V5 = ECDSAAdd.Entrant.Rolling1588.regularPayload true 84 origin (X,Y) from by simp only [V5,V4,V3,V2,V1,ECDSAAdd.Entrant.Rolling1588.regularPayload,if_true], ECDSAAdd.Entrant.Rolling1588.regularPayload_eq true 84 (by decide) origin enabled] at hstep simpa only [OddFullPass.P1LifeLoan.basePacket,hcEq,ECDSAAdd.Entrant.Rolling1588.stageOpen, ECDSAAdd.Entrant.Rolling1588.stageClose,ECDSAAdd.Entrant.Rolling1588.stageTransition, if_true,if_false,List.append_assoc,ECDSAAdd.Entrant.Rolling1588.encodeGroup] using hstep) state records input have same := Replay5.placed_eq (Placement5.pi 84) (OddFullPass.P1LifeLoan.basePacket true 0 84) (fun q hq => Placement5.pi_outside 84 q (by decide) hq) state records (RouteA.Rolling1588.cutFrame_zero_region P1Life.oddWord P1Life.oddWord _ origin ctx X Y state input) (RouteA.Rolling1588.cutFrame_zero_region P1Life.oddWord P1Life.oddWord _ origin ctx _ _ _ raw.2) change run (OddFullPass.P1LifeLoan.packet true 0 84) records state = run (OddFullPass.P1LifeLoan.basePacket true 0 84) records state at same rw [same]; exact raw · rw [oddPk_std true k h,oddCutWord_center (c := k) (by omega),oddCutWord_center (c := k+1) (by omega)] exact ECDSAAdd.Entrant.Rolling1588.packet_cut_frame true k lo (by omega) origin ctx enabled X Y /-- multiplication-kernel packet `k` of the family between its cut frames. -/ theorem pk_frame_mul (k : Nat) (lo : 1≤k) (hi : k≤84) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (X Y : Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CutFrame (oddCutWord (k+1)) (oddCutWord (k+1)) (k+1) origin X Y) (oddPk false k) (fun state => let V := directionalPayload true (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (X,Y) RouteA.Rolling1588.CutFrame (oddCutWord k) (oddCutWord k) k origin V.1 V.2 state) := by rcases (show (1≤k ∧ k<84) ∨ k=84 ∨ 84 absurd e Bool.false_ne_true) origin ctx enabled X Y · subst h rw [oddPk_end,oddCutWord_odd (c := 84+1) (by omega) (by omega),oddCutWord_odd (c := 84) (by omega) (by omega)] have h0eq : OddFullPass.P1LifeLoan.packet false 0 84 = RouteA.Rolling1588.packet false 84 := by have hh := WindowFieldCosts.half760OddLoan_zero_eq false simp only [OddFullPass.P1LifeLoan.packet,RouteA.Rolling1588.packet, OddFullPass.P1LifeLoan.basePacket,RouteA.Rolling1588.basePacket, OddFullPass.P1LifeLoan.cell,RouteA.Rolling1588.cell, OddFullPass.P1LifeLoan.halfWindow,RouteA.Rolling1588.halfWindow,RouteA.Rolling1588.halfWindowWith, hh,Bool.false_eq_true,if_false,if_true] rw [h0eq] exact RouteA.Rolling1588.packet_cut_frame false 84 (by decide) (by decide) (fun e => absurd e Bool.false_ne_true) origin ctx enabled X Y · rw [oddPk_std false k h,oddCutWord_center (c := k+1) (by omega),oddCutWord_center (c := k) (by omega)] exact ECDSAAdd.Entrant.Rolling1588.packet_cut_frame false k lo (by omega) origin ctx enabled X Y private theorem ofield_cut_frame_mul' (j n : Nat) (first : 1≤j) (bound : j+n≤85) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (X Y : Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CutFrame (oddCutWord (j+n)) (oddCutWord (j+n)) (j+n) origin X Y) (PacketSequence.program false (oddPk false) j n) (fun state => let V := PacketSequence.payload false (fun k V => directionalPayload true (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) V) j n (X,Y) RouteA.Rolling1588.CutFrame (oddCutWord j) (oddCutWord j) j origin V.1 V.2 state) := RouteA.Rolling1588.route_cut_sequence_frame false (oddPk false) (fun k V => directionalPayload true (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) V) (fun k (V : Fp×Fp) => RouteA.Rolling1588.CutFrame (oddCutWord k) (oddCutWord k) k origin V.1 V.2) 85 (fun k hk kb V => pk_frame_mul k hk (by omega) origin ctx enabled V.1 V.2) j n first bound (X,Y) /-- the multiplication field packets `j+n-1..j` between cut frames. -/ theorem ofield_cut_frame_mul (j n : Nat) (first : 1≤j) (bound : j+n≤85) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (X Y : Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CutFrame (oddCutWord (j+n)) (oddCutWord (j+n)) (j+n) origin X Y) (PacketSequence.program false (oddPk false) j n) (fun state => let V := Replay5.groupsPayload false origin j n (X,Y) RouteA.Rolling1588.CutFrame (oddCutWord j) (oddCutWord j) j origin V.1 V.2 state) := ofield_cut_frame_mul' j n first bound origin ctx enabled X Y /-- the division packet law in the exact shape `route_cut_sequence_frame` instantiates (payload as a redex). -/ private theorem lawDiv (k : Nat) (hk : 1≤k) (kb : k<85) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (V : Fp×Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple ((fun k (V : Fp×Fp) => RouteA.Rolling1588.CutFrame (oddCutWord k) (oddCutWord k) k origin V.1 V.2) (if true then k else k+1) V) (oddPk true k) ((fun k (V : Fp×Fp) => RouteA.Rolling1588.CutFrame (oddCutWord k) (oddCutWord k) k origin V.1 V.2) (if true then k+1 else k) ((fun k (V : Fp×Fp) => directionalPayload false (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) V) k V)) := by have h : (fun k (V : Fp×Fp) => directionalPayload false (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) V) k V = directionalPayload false (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (V.1,V.2) := rfl rw [h] exact pk_frame_div k hk (by omega) origin ctx enabled V.1 V.2 private theorem ofield_cut_frame_div' (j n : Nat) (first : 1≤j) (bound : j+n≤85) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (X Y : Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CutFrame (oddCutWord j) (oddCutWord j) j origin X Y) (PacketSequence.program true (oddPk true) j n) (fun state => let V := PacketSequence.payload true (fun k V => directionalPayload false (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) V) j n (X,Y) RouteA.Rolling1588.CutFrame (oddCutWord (j+n)) (oddCutWord (j+n)) (j+n) origin V.1 V.2 state) := RouteA.Rolling1588.route_cut_sequence_frame true (oddPk true) (fun k (V : Fp×Fp) => directionalPayload false (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) V) (fun k (V : Fp×Fp) => RouteA.Rolling1588.CutFrame (oddCutWord k) (oddCutWord k) k origin V.1 V.2) 85 (fun k hk kb V => lawDiv k hk kb origin ctx enabled V) j n first bound (X,Y) /-- the division field packets `j..j+n-1` between cut frames. -/ theorem ofield_cut_frame_div (j n : Nat) (first : 1≤j) (bound : j+n≤85) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (X Y : Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CutFrame (oddCutWord j) (oddCutWord j) j origin X Y) (PacketSequence.program true (oddPk true) j n) (fun state => let V := Replay5.groupsPayload true origin j n (X,Y) RouteA.Rolling1588.CutFrame (oddCutWord (j+n)) (oddCutWord (j+n)) (j+n) origin V.1 V.2 state) := ofield_cut_frame_div' j n first bound origin ctx enabled X Y /-- the odd field packets 1..84 run directly between odd-word cut frames at cuts 1 and 85. -/ theorem ofield_cut_frame_odd (d : Bool) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (X Y : Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if d then 1 else 85) origin X Y) (PacketSequence.program d (oddPk d) 1 84) (fun state => let V := Replay5.groupsPayload d origin 1 84 (X,Y) RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if d then 85 else 1) origin V.1 V.2 state) := by have c1 : oddCutWord 1=P1Life.oddWord := oddCutWord_odd (by decide) (by decide) have c85 : oddCutWord (1+84)=P1Life.oddWord := oddCutWord_odd (by decide) (by decide) cases d · simpa only [Bool.false_eq_true,if_false,c1,c85] using ofield_cut_frame_mul 1 84 (by decide) (by decide) origin ctx enabled X Y · simpa only [if_true,c1,c85] using ofield_cut_frame_div 1 84 (by decide) (by decide) origin ctx enabled X Y end ECDSAAdd.Entrant.StairPacket.WindowFieldView end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed BalancedField CompressedFieldSupport StairArchiveTen StairArchiveInactive open StairArchiveNativeCut ArchiveFieldScratch WindowFieldMask WindowFieldCosts StairField2V3Seg WindowFieldJourney set_option maxRecDepth 2600 set_option maxHeartbeats 800000 set_option linter.constructorNameAsVariable false attribute [local irreducible] run wires measurementCount wire group StairArchiveInactive.packet WindowFieldCosts.opk WindowFieldCosts.ogroup theorem ot_opk_map (d : Bool) (k : Nat) : opk d k=renameProgram wire (oddPk d k) := by unfold opk calc _ = renameProgram StairArchiveInactive.host (renameProgram (OB5.sig 511) (oddPk d k)) := StairArchiveInactive.hosts_eq _ _ _ _ = _ := by rw [renameProgram_comp]; unfold wire; rfl /-- oddten: dadon's `step` for the field group's own packet, multiplication kernel (packet `k`: cut `k+1` to cut `k`). -/ theorem ostep_mul (k : Nat) (lo : 1≤k) (hi : k≤84) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (r : State) (m : List Bool) (initial : OCut (k+1) origin r) : OCut k origin (run (opk false k) m r) := by have uses : ∀ q∈wires (opk false k), q∈surface ∧ q≠base 720 := fun q h => packetUses false k lo hi (WindowFieldCosts.ot_opk_sub false k h) obtain ⟨zero,X,Y,b,fr,match_⟩ := initial obtain ⟨same,afterZero⟩ := follow _ m r b match_ zero uses have actual := pk_frame_mul k lo hi origin ctx enabled X Y _ m fr refine ⟨afterZero,(directionalPayload true (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (X,Y)).1, (directionalPayload true (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (X,Y)).2, run (opk false k) m b,?_,same⟩ rw [ot_opk_map,run_rename wire injective]; exact actual.2 /-- oddten: dadon's `step` for the field group's own packet, division kernel (packet `k`: cut `k` to cut `k+1`). -/ theorem ostep_div (k : Nat) (lo : 1≤k) (hi : k≤84) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (r : State) (m : List Bool) (initial : OCut k origin r) : OCut (k+1) origin (run (opk true k) m r) := by have uses : ∀ q∈wires (opk true k), q∈surface ∧ q≠base 720 := fun q h => packetUses true k lo hi (WindowFieldCosts.ot_opk_sub true k h) obtain ⟨zero,X,Y,b,fr,match_⟩ := initial obtain ⟨same,afterZero⟩ := follow _ m r b match_ zero uses have actual := pk_frame_div k lo hi origin ctx enabled X Y _ m fr refine ⟨afterZero,(directionalPayload false (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (X,Y)).1, (directionalPayload false (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (X,Y)).2, run (opk true k) m b,?_,same⟩ rw [ot_opk_map,run_rename wire injective]; exact actual.2 /-- oddten: dadon's `step` for the field group's own packet. -/ theorem ostep (d : Bool) (k : Nat) (lo : 1≤k) (hi : k≤84) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (r : State) (m : List Bool) (initial : OCut (if d then k else k+1) origin r) : OCut (if d then k+1 else k) origin (run (opk d k) m r) := by cases d · exact ostep_mul k lo hi origin ctx enabled r m initial · exact ostep_div k lo hi origin ctx enabled r m initial /-- oddten: dadon's `selected` for the field group's own packets. -/ theorem oselected (d : Bool) (j n : Nat) (lo : 1≤j) (hi : j+n≤85) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400)=true) (r : State) (m : List Bool) (initial : OCut (if d then j else j+n) origin r) : OCut (if d then j+n else j) origin (run (ogroup d j n) m r) := by rw [ogroup] induction n generalizing j r m with | zero => simpa only [PacketSequence.program,run,Nat.add_zero] using initial | succ n ih => cases d with | false => simp only [Bool.false_eq_true,if_false] at initial ⊢ simp only [PacketSequence.program,Bool.false_eq_true,if_false,run_append,run_take] apply ostep false j lo (by omega) origin ctx enabled apply ih (j+1) (by omega) (by omega) r m simpa only [Nat.add_assoc,Nat.add_comm 1 n] using initial | true => simp only [if_true] at initial ⊢ simp only [PacketSequence.program,if_true,run_append,run_take] have first := ostep true j lo (by omega) origin ctx enabled r m initial have last := ih (j+1) (by omega) (by omega) _ (m.drop (measurementCount (opk true j))) first simpa only [if_true,Nat.add_assoc,Nat.add_comm 1 n] using last end ECDSAAdd.Entrant.StairPacket.WindowFieldView end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed BalancedField CompressedFieldSupport StairArchiveTen StairArchiveInactive open StairArchiveNativeCut ArchiveFieldScratch WindowFieldMask WindowFieldCosts StairField2V3Seg WindowFieldJourney set_option maxRecDepth 1600 set_option maxHeartbeats 800000 set_option linter.constructorNameAsVariable false attribute [local irreducible] run group ten measurementCount packet surface ArchiveStockRows.Chronology Rolling1588.CutFrame StairArchiveNativeCut.canonical WindowFieldCosts.opk theorem osee (j c x row : Nat) (hj : j∈bankIds) (rb : row<63145) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (tr : TraceOK x origin) (history : ArchiveStockRows.Chronology (5*j-5) x ECDSAAdd.p row) (r : State) (state : OCut c origin r) : frame j row (boundaryCols j c) r := by obtain ⟨zero,X,Y,model,fr,view⟩ := state have list : j∈WindowBankCheck.banks := by simpa [WindowBankCheck.banks,bankIds] using hj apply oobserved (oddCutWord c) j c x row list rb origin ctx tr history X Y model r fr zero intro q inside_ off exact view q (by rw [surface];exact Finset.mem_union_right _ (Finset.mem_biUnion.mpr ⟨j,hj,inside_⟩)) off /-- oddten: dadon's `pair_cuts` for the field group's own packets. -/ theorem opair_cuts (d : Bool) (j x row : Nat) (hj : j∈bankIds) (rb : row<63145) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400)=true) (tr : TraceOK x origin) (history : ArchiveStockRows.Chronology (5*j-5) x ECDSAAdd.p row) (r : State) (m : List Bool) (state : OCut (if d then j else j+2) origin r) : (frame j row (StairArchiveNativeCut.canonical d d) r ∧ frame j row middle (orefMiddle j (!d) m r) ∧ frame j row (StairArchiveNativeCut.canonical (!d) (!d)) (orefExit j (!d) m r)) ∧ OCut (if d then j+2 else j) origin (orefExit j (!d) m r) := by have bounds : 1≤j ∧ j+1≤84 := by simp only [bankIds,Finset.mem_insert,Finset.mem_singleton] at hj; omega let observe := fun c t (h : OCut c origin t) => osee j c x row hj rb origin ctx tr history t h have lo : boundaryCols j j=StairArchiveNativeCut.canonical true true := by simp [boundaryCols] have mid : boundaryCols j (j+1)=middle := by simp [boundaryCols,middle] have hi : boundaryCols j (j+2)=StairArchiveNativeCut.canonical false false := by simp [boundaryCols] cases d · have one : OCut (j+1) origin (orefMiddle j true m r) := ostep false (j+1) (by omega) (by omega) origin ctx en r _ state have two : OCut j origin (orefExit j true m r) := ostep false j (by omega) (by omega) origin ctx en _ _ one exact ⟨⟨hi ▸ observe _ _ state,mid ▸ observe _ _ one,lo ▸ observe _ _ two⟩,two⟩ · have one : OCut (j+1) origin (orefMiddle j false m r) := ostep true j (by omega) (by omega) origin ctx en r _ state have two : OCut (j+2) origin (orefExit j false m r) := ostep true (j+1) (by omega) (by omega) origin ctx en _ _ one exact ⟨⟨lo ▸ observe _ _ state,mid ▸ observe _ _ one,hi ▸ observe _ _ two⟩,two⟩ end ECDSAAdd.Entrant.StairPacket.WindowFieldView end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldJourney open Arithmetic MappedCompressed StairArchiveRelease StairArchiveNativeCut StairArchiveTen open CodecBitSliceVerify WindowFieldMask WindowFieldCosts ArchiveFieldScratch attribute [local irreducible] run measurementCount WindowFieldCosts.ogroup WindowFieldCosts.oten orefExit inputCols outputCols StairArchiveNativeCut.canonical enter leave WindowFieldCosts.opk set_option linter.constructorNameAsVariable false def oemitted (d : Bool) : Leg → Program | .native j n => ogroup d j n | .paired j => oten j (!d) def ostock (d : Bool) (m : List Bool) (r : State) : Leg → State | .native j n => run (ogroup d j n) m r | .paired j => orefExit j (!d) m r def onextTape (d : Bool) (l : Leg) (m : List Bool) := m.drop (measurementCount (oemitted d l)) def oconcatenate (d : Bool) : List Leg → Program | [] => [] | l::ls => oemitted d l ++ oconcatenate d ls def odestination (d : Bool) : List Leg → List Bool → State → State | [],_,r => r | l::ls,m,r => odestination d ls (onextTape d l m) (ostock d m r l) def OCuts (d : Bool) (row : Nat→Nat) (m : List Bool) (r : State) : Leg → Prop | .native _ _ => True | .paired j => frame j (row j) (StairArchiveNativeCut.canonical d d) r ∧ frame j (row j) middle (orefMiddle j (!d) m r) ∧ frame j (row j) (StairArchiveNativeCut.canonical (!d) (!d)) (orefExit j (!d) m r) def ONativeTrail (d : Bool) (row : Nat→Nat) : List Leg → List Bool → State → Prop | [],_,_ => True | l::ls,m,r => OCuts d row m r l ∧ ONativeTrail d row ls (onextTape d l m) (ostock d m r l) theorem otravel (d : Bool) (row : Nat→Nat) (bounded : ∀j∈bankIds,row j<63145) (ls : List Leg) (m : List Bool) (a r : State) (c : Nat→Cols) (shape : valid d ls c) (cuts : ONativeTrail d row ls m r) (initial : Fits row c a r) : Fits row (finalCode d ls c) (run (oconcatenate d ls) m a) (odestination d ls m r) := by induction ls generalizing c m a r with | nil => simpa only [oconcatenate,run,finalCode,odestination] using initial | cons l ls ih => obtain ⟨loc,tail⟩ := shape obtain ⟨here,rest⟩ := cuts have one : Fits row (codes d c l) (run (oemitted d l) m a) (ostock d m r l) := by cases l with | native j n => exact plain _ _ _ _ _ _ initial (ot_groupSafe d j n loc) | paired j => exact ot_stepTen j loc.1 row c (!d) (bounded j loc.1) m a r initial loc.2 (by simpa only [Bool.not_not] using here.1) here.2.1 here.2.2 rw [oconcatenate,run_append,run_take] exact ih _ _ _ _ tail rest one theorem oemits (d : Bool) : group84 d=oconcatenate d (plan d) := by cases d <;> simp only [group84,ordered,oconcatenate,oemitted,plan,if_true,if_false,Bool.false_eq_true, List.append_assoc,List.append_nil] theorem ogroup_run (d : Bool) (row : Nat→Nat) (bounded : ∀j∈bankIds,row j<63145) (m : List Bool) (a r : State) (initial : Fits row (initialCode d) a r) (native : ONativeTrail d row (plan d) m r) : Fits row (finalCode d (plan d) (initialCode d)) (run (group84 d) m a) (odestination d (plan d) m r) := by rw [oemits] exact otravel d row bounded _ m a r _ (valid_plan d) native initial end ECDSAAdd.Entrant.StairPacket.WindowFieldJourney end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldJourney open Arithmetic MappedCompressed StairArchiveRelease StairArchiveNativeCut StairArchiveTen open WindowFieldMask WindowFieldCosts ArchiveFieldScratch StairArchiveInactive set_option linter.constructorNameAsVariable false attribute [local irreducible] run measurementCount StairArchiveInactive.packet fieldHook WindowFieldCosts.opk set_option maxRecDepth 8000 set_option maxHeartbeats 900000 def oreferenceLeg (d : Bool) : Leg → Program | .native j n => ogroup d j n | .paired j => ofirst j (!d) ++ osecond j (!d) def olegTape (d : Bool) (m : List Bool) : Leg → List Bool | .native _ _ => m | .paired j => joinTapes (ofirst j (!d)) (tapeA j (!d) m) (otapeB j (!d) m) theorem olocalTape (d : Bool) (m : List Bool) (s : State) (l : Leg) : ostock d m s l = run (oreferenceLeg d l) (olegTape d m l) s := by cases l with | native j n => rfl | paired j => exact (joined _ _ _ _ _).symm def oreferenceProgram (d : Bool) : List Leg → Program | [] => [] | l::ls => oreferenceLeg d l ++ oreferenceProgram d ls def oreferenceTape (d : Bool) : List Leg → List Bool → List Bool | [],_ => [] | l::ls,m => joinTapes (oreferenceLeg d l) (olegTape d m l) (oreferenceTape d ls (onextTape d l m)) theorem oref_run (d : Bool) (ls : List Leg) (m : List Bool) (r : State) : odestination d ls m r = run (oreferenceProgram d ls) (oreferenceTape d ls m) r := by induction ls generalizing m r with | nil => simp only [odestination,oreferenceProgram,oreferenceTape,run] | cons l ls ih => rw [odestination,oreferenceProgram,oreferenceTape,joined,←olocalTape,←ih] theorem oreference_eq (d : Bool) : oreferenceProgram d (plan d)=PacketSequence.program d (opk d) 1 84 := by rw [shape' d (opk d)] cases d <;> simp only [oreferenceProgram,plan,oreferenceLeg,ofirst,osecond,ogroup, Bool.not_false,Bool.not_true,Bool.false_eq_true,if_true,if_false] end ECDSAAdd.Entrant.StairPacket.WindowFieldJourney end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed BalancedField CompressedFieldSupport StairArchiveTen StairArchiveInactive open StairArchiveNativeCut ArchiveFieldScratch WindowFieldMask WindowFieldCosts StairField2V3Seg WindowFieldJourney set_option maxRecDepth 1600 set_option maxHeartbeats 800000 set_option linter.constructorNameAsVariable false attribute [local irreducible] run group ten measurementCount packet surface ArchiveStockRows.Chronology Rolling1588.CutFrame StairArchiveNativeCut.canonical WindowFieldCosts.opk /-- oddten: dadon's `trail` for the field group's own packets. -/ theorem otrail (d : Bool) (x : Nat) (rows : Nat→Nat) (rb : ∀j∈bankIds,rows j<63145) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400)=true) (tr : TraceOK x origin) (history : ∀j∈bankIds,ArchiveStockRows.Chronology (5*j-5) x ECDSAAdd.p (rows j)) (c : Nat) (ls : List Leg) (m : List Bool) (r : State) (route : path d c ls) (start : OCut c origin r) : ONativeTrail d rows ls m r := by induction ls generalizing c m r with | nil => trivial | cons l ls ih => obtain ⟨rfl,good,more⟩ := route cases l with | native j n => have post := oselected d j n good.1 good.2 origin ctx en r m start exact ⟨trivial,ih _ _ _ more post⟩ | paired j => have event := opair_cuts d j x (rows j) good (rb _ good) origin ctx en tr (history _ good) r m start exact ⟨event.1,ih _ _ _ more event.2⟩ /-- two runs that agree from `b` agree from any `a` that matches `b` on the larger footprint. -/ theorem ot_lift (P Q : Program) (sub : wires P⊆wires Q) (m n : List Bool) (a b : State) (agree : ∀ q∈wires Q, a.basis q=b.basis q) (same : run P m b=run Q n b) : run P m a=run Q n a := by have hp := Arithmetic.run_local_increment P a b m (fun q hq => agree q (sub hq)) have hq := Arithmetic.run_local_increment Q a b n agree apply State.extensionality · have e1 := hp.1 rw [same] at e1 have e := e1.trans hq.1.symm revert e generalize (run P m a).phase = x generalize (run Q n a).phase = y generalize a.phase = z cases x <;> cases y <;> cases z <;> decide · funext q by_cases inQ : q∈wires Q · rw [hq.2 q inQ] by_cases inP : q∈wires P · rw [hp.2 q inP,same] · rw [run_preserves_outside P m a q inP,agree q inQ,←run_preserves_outside P m b q inP,same] · have inP : q∉wires P := fun h => inQ (sub h) rw [run_preserves_outside P m a q inP,run_preserves_outside Q n a q inQ] set_option linter.unusedSimpArgs false in theorem ot_seqWires (d : Bool) (p : Nat→Program) (j n : Nat) {q : Wire} (h : q∈wires (PacketSequence.program d p j n)) : ∃ k, j≤k ∧ k simp [PacketSequence.program,wires] at h | succ n ih => cases d <;> simp only [PacketSequence.program,Bool.false_eq_true,if_false,if_true, wires_append,Finset.mem_union] at h · rcases h with h|h · obtain ⟨k,l,u,hk⟩ := ih (j+1) h exact ⟨k,by omega,by omega,hk⟩ · exact ⟨j,Nat.le_refl j,by omega,h⟩ · rcases h with h|h · exact ⟨j,Nat.le_refl j,by omega,h⟩ · obtain ⟨k,l,u,hk⟩ := ih (j+1) h exact ⟨k,by omega,by omega,hk⟩ theorem ot_groupUses (d : Bool) {q : Wire} (h : q∈wires (group d 1 84)) : q∈surface ∧ q≠base 720 := by rw [WindowFieldCosts.group,WindowFieldCosts.distribute,WindowFieldCosts.distributed] at h obtain ⟨k,l,u,hk⟩ := ot_seqWires d _ 1 84 h exact packetUses d k (by omega) (by omega) hk theorem ot_group_map (d : Bool) (j n : Nat) : group d j n=renameProgram wire (Rolling1588.groups d j n) := by rw [WindowFieldCosts.ot_group_eq,StairArchiveInactive.hosts_eq,renameProgram_comp] have g := StairGroups.groups_zero d j n unfold StairGroups.groups at g rw [g] unfold wire rfl theorem ot_ogroup_map (d : Bool) (j n : Nat) : PacketSequence.program d (opk d) j n=renameProgram wire (PacketSequence.program d (oddPk d) j n) := by have ren (f : Wire → Wire) (a b : Program) : renameProgram f (a++b)=renameProgram f a++renameProgram f b := List.map_append induction n generalizing j with | zero => rfl | succ n ih => cases d <;> simp only [PacketSequence.program,if_true,if_false,Bool.false_eq_true,ren,ih,ot_opk_map] theorem ofield_sub (d : Bool) : wires (PacketSequence.program d (oddPk d) 1 84) ⊆ wires (Rolling1588.groups d 1 84) := StairLoanGroupSupport.sequence_sub d _ _ (fun k => oddPk_sub d k) 1 84 -- `ofinal` retired: `othree_run` directly relates `group84 d` to `PacketSequence.program d (opk d) 1 84` on `OCut`. end ECDSAAdd.Entrant.StairPacket.WindowFieldView end -- oddten:end SEM section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed BalancedField StairArchiveTen StairArchiveInactive open StairArchiveNativeCut ArchiveFieldScratch WindowFieldMask WindowFieldCosts StairField2V3Seg WindowFieldJourney set_option maxRecDepth 1600 set_option maxHeartbeats 400000 /-- Archive-coupled field-group runner directly between odd-word `OCut` endpoints (cuts 1 and 85). -/ theorem othree_run (d : Bool) (x : Nat) (rows : Nat→Nat) (rb : ∀j∈bankIds,rows j<63145) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400)=true) (tr : TraceOK x origin) (history : ∀j∈bankIds,ArchiveStockRows.Chronology (5*j-5) x ECDSAAdd.p (rows j)) (m : List Bool) (a r : State) (initial : Fits rows (initialCode d) a r) (start : OCut (if d then 1 else 85) origin r) : Fits rows (finalCode d (plan d) (initialCode d)) (run (group84 d) m a) (run (PacketSequence.program d (opk d) 1 84) (oreferenceTape d (plan d) m) r) := by have route : path d (if d then 1 else 85) (plan d) := by cases d <;> simp [path,plan,prev,next,span,feasible,bankIds] have all := ogroup_run d rows rb m a r initial (otrail d x rows rb origin ctx en tr history _ _ m r route start) rwa [oref_run,oreference_eq] at all end ECDSAAdd.Entrant.StairPacket.WindowFieldView end end section section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldParity open Arithmetic MappedCompressed CodecBitSliceVerify WindowParityDirty set_option linter.unusedSimpArgs false set_option maxHeartbeats 1000000 set_option maxRecDepth 4000 def addr (i : Nat) := OB5.sig 511 (NewHistory5.payloadWire base i) private def block (j : Nat) := (List.range 16).map (8*j+·) private def stable0 := List.range 80 private def stable1 := List.range' 96 8 private def stable2 := List.range' 120 8 private def stable3 := List.range' 144 8 private def stable4 := List.range' 168 8 private def stable5 := List.range' 192 8 private def stable6 := List.range' 216 8 private def stable7 := List.range' 240 8 private def stable8 := List.range' 264 16 private def stable9 := List.range' 296 16 private def stable10 := List.range' 328 16 private def stable11 := List.range' 360 16 private def stable12 := List.range' 392 16 private def stable13 := List.range' 424 16 private def stable14 := List.range' 456 16 private def stable15 := List.range' 488 16 private def stable16 := List.range' 520 16 private def stable17 := List.range' 552 8 private def stable18 := List.range' 576 8 private def stable19 := List.range' 600 8 private def stable20 := List.range' 624 8 private def stable21 := List.range' 648 8 private def stable22 := List.range' 672 144 private theorem split : List.range 816 = stable0 ++ block 10 ++ stable1 ++ block 13 ++ stable2 ++ block 16 ++ stable3 ++ block 19 ++ stable4 ++ block 22 ++ stable5 ++ block 25 ++ stable6 ++ block 28 ++ stable7 ++ block 31 ++ stable8 ++ block 35 ++ stable9 ++ block 39 ++ stable10 ++ block 43 ++ stable11 ++ block 47 ++ stable12 ++ block 51 ++ stable13 ++ block 55 ++ stable14 ++ block 59 ++ stable15 ++ block 63 ++ stable16 ++ block 67 ++ stable17 ++ block 70 ++ stable18 ++ block 73 ++ stable19 ++ block 76 ++ stable20 ++ block 79 ++ stable21 ++ block 82 ++ stable22 := by decide +kernel private theorem join (l r : List Bool) : TraceParity5.parity (l++r) = (TraceParity5.parity l ^^ TraceParity5.parity r) := by induction l with | nil => simp [TraceParity5.parity] | cons x xs ih => simp only [List.cons_append,TraceParity5.parity,ih,Bool.xor_assoc] private theorem reduce (cs : Cols) (r : Nat) (l : List Nat) : TraceParity5.parity (l.map (fun i=>(get cs i).testBit r)) = (((l.map (get cs)).foldr (· ^^^ ·) 0).testBit r) := by induction l with | nil => simp [TraceParity5.parity] | cons i xs ih => simp only [List.map_cons,List.foldr_cons,TraceParity5.parity,ih,Nat.testBit_xor] private def sum (l : List Nat) (s : State) := TraceParity5.parity (l.map (fun i=>s.basis (addr i))) private theorem fromData (s : State) (j : Nat) (cs : Cols) (r : Nat) (bits : ∀ i<16,s.basis (site j i)=(get cs i).testBit r) : sum (block j) s=(parity cs).testBit r := by unfold sum block parity rw [List.map_map,←reduce] congr 1 apply List.map_congr_left intro i hi; exact bits i (List.mem_range.mp hi) private theorem stable_sum (l : List Nat) (a b : State) (eq : ∀i∈l,a.basis (addr i)=b.basis (addr i)) : sum l a=sum l b := congrArg TraceParity5.parity (List.map_congr_left eq) def Elsewhere (i : Nat) := i<80 ∨ (96 ≤ i ∧ i<104) ∨ (120 ≤ i ∧ i<128) ∨ (144 ≤ i ∧ i<152) ∨ (168 ≤ i ∧ i<176) ∨ (192 ≤ i ∧ i<200) ∨ (216 ≤ i ∧ i<224) ∨ (240 ≤ i ∧ i<248) ∨ (264 ≤ i ∧ i<280) ∨ (296 ≤ i ∧ i<312) ∨ (328 ≤ i ∧ i<344) ∨ (360 ≤ i ∧ i<376) ∨ (392 ≤ i ∧ i<408) ∨ (424 ≤ i ∧ i<440) ∨ (456 ≤ i ∧ i<472) ∨ (488 ≤ i ∧ i<504) ∨ (520 ≤ i ∧ i<536) ∨ (552 ≤ i ∧ i<560) ∨ (576 ≤ i ∧ i<584) ∨ (600 ≤ i ∧ i<608) ∨ (624 ≤ i ∧ i<632) ∨ (648 ≤ i ∧ i<656) ∨ (672 ≤ i ∧ i<816) def stockParity (s : State) := TraceParity5.parity (FrontierEntry1591Field.controls.map s.basis) private theorem allSum (s : State) : stockParity s= ((((((((((((((((((((((((((((((((((((((((((((sum stable0 s ^^ sum (block 10) s) ^^ sum stable1 s) ^^ sum (block 13) s) ^^ sum stable2 s) ^^ sum (block 16) s) ^^ sum stable3 s) ^^ sum (block 19) s) ^^ sum stable4 s) ^^ sum (block 22) s) ^^ sum stable5 s) ^^ sum (block 25) s) ^^ sum stable6 s) ^^ sum (block 28) s) ^^ sum stable7 s) ^^ sum (block 31) s) ^^ sum stable8 s) ^^ sum (block 35) s) ^^ sum stable9 s) ^^ sum (block 39) s) ^^ sum stable10 s) ^^ sum (block 43) s) ^^ sum stable11 s) ^^ sum (block 47) s) ^^ sum stable12 s) ^^ sum (block 51) s) ^^ sum stable13 s) ^^ sum (block 55) s) ^^ sum stable14 s) ^^ sum (block 59) s) ^^ sum stable15 s) ^^ sum (block 63) s) ^^ sum stable16 s) ^^ sum (block 67) s) ^^ sum stable17 s) ^^ sum (block 70) s) ^^ sum stable18 s) ^^ sum (block 73) s) ^^ sum stable19 s) ^^ sum (block 76) s) ^^ sum stable20 s) ^^ sum (block 79) s) ^^ sum stable21 s) ^^ sum (block 82) s) ^^ sum stable22 s) := by unfold stockParity FrontierEntry1591Field.controls ParityHost5.payloadControls rw [split] simp only [List.map_append,List.map_map,join,sum,Function.comp_def,addr] private theorem pair_step (p q s x y : Bool) : (((p ^^ x) ^^ s) ^^ ((q ^^ y) ^^ s)) = ((p ^^ q) ^^ (x ^^ y)) := by cases p <;> cases q <;> cases s <;> cases x <;> cases y <;> rfl theorem fold_pair (rows : Nat→Nat) (dirs : Nat→Bool) (a b : State) (rest : ∀i,Elsewhere i→a.basis (addr i)=b.basis (addr i)) (custom : ∀j,j=10 ∨ j=13 ∨ j=16 ∨ j=19 ∨ j=22 ∨ j=25 ∨ j=28 ∨ j=31 ∨ j=35 ∨ j=39 ∨ j=43 ∨ j=47 ∨ j=51 ∨ j=55 ∨ j=59 ∨ j=63 ∨ j=67 ∨ j=70 ∨ j=73 ∨ j=76 ∨ j=79 ∨ j=82 → ∀i<16,a.basis (site j i)=(get (ArchivePortAction.code (dirs j)) i).testBit (rows j)) (stock : ∀j,j=10 ∨ j=13 ∨ j=16 ∨ j=19 ∨ j=22 ∨ j=25 ∨ j=28 ∨ j=31 ∨ j=35 ∨ j=39 ∨ j=43 ∨ j=47 ∨ j=51 ∨ j=55 ∨ j=59 ∨ j=63 ∨ j=67 ∨ j=70 ∨ j=73 ∨ j=76 ∨ j=79 ∨ j=82 → ∀i<16,b.basis (site j i)=(get (StairArchiveNativeCut.canonical (dirs j) (dirs j)) i).testBit (rows j)) : (stockParity a ^^ stockParity b) = (((((((((((((((((((((((parity (ArchivePortAction.code (dirs 10))).testBit (rows 10) ^^ (parity (StairArchiveNativeCut.canonical (dirs 10) (dirs 10))).testBit (rows 10)) ^^ ((parity (ArchivePortAction.code (dirs 13))).testBit (rows 13) ^^ (parity (StairArchiveNativeCut.canonical (dirs 13) (dirs 13))).testBit (rows 13))) ^^ ((parity (ArchivePortAction.code (dirs 16))).testBit (rows 16) ^^ (parity (StairArchiveNativeCut.canonical (dirs 16) (dirs 16))).testBit (rows 16))) ^^ ((parity (ArchivePortAction.code (dirs 19))).testBit (rows 19) ^^ (parity (StairArchiveNativeCut.canonical (dirs 19) (dirs 19))).testBit (rows 19))) ^^ ((parity (ArchivePortAction.code (dirs 22))).testBit (rows 22) ^^ (parity (StairArchiveNativeCut.canonical (dirs 22) (dirs 22))).testBit (rows 22))) ^^ ((parity (ArchivePortAction.code (dirs 25))).testBit (rows 25) ^^ (parity (StairArchiveNativeCut.canonical (dirs 25) (dirs 25))).testBit (rows 25))) ^^ ((parity (ArchivePortAction.code (dirs 28))).testBit (rows 28) ^^ (parity (StairArchiveNativeCut.canonical (dirs 28) (dirs 28))).testBit (rows 28))) ^^ ((parity (ArchivePortAction.code (dirs 31))).testBit (rows 31) ^^ (parity (StairArchiveNativeCut.canonical (dirs 31) (dirs 31))).testBit (rows 31))) ^^ ((parity (ArchivePortAction.code (dirs 35))).testBit (rows 35) ^^ (parity (StairArchiveNativeCut.canonical (dirs 35) (dirs 35))).testBit (rows 35))) ^^ ((parity (ArchivePortAction.code (dirs 39))).testBit (rows 39) ^^ (parity (StairArchiveNativeCut.canonical (dirs 39) (dirs 39))).testBit (rows 39))) ^^ ((parity (ArchivePortAction.code (dirs 43))).testBit (rows 43) ^^ (parity (StairArchiveNativeCut.canonical (dirs 43) (dirs 43))).testBit (rows 43))) ^^ ((parity (ArchivePortAction.code (dirs 47))).testBit (rows 47) ^^ (parity (StairArchiveNativeCut.canonical (dirs 47) (dirs 47))).testBit (rows 47))) ^^ ((parity (ArchivePortAction.code (dirs 51))).testBit (rows 51) ^^ (parity (StairArchiveNativeCut.canonical (dirs 51) (dirs 51))).testBit (rows 51))) ^^ ((parity (ArchivePortAction.code (dirs 55))).testBit (rows 55) ^^ (parity (StairArchiveNativeCut.canonical (dirs 55) (dirs 55))).testBit (rows 55))) ^^ ((parity (ArchivePortAction.code (dirs 59))).testBit (rows 59) ^^ (parity (StairArchiveNativeCut.canonical (dirs 59) (dirs 59))).testBit (rows 59))) ^^ ((parity (ArchivePortAction.code (dirs 63))).testBit (rows 63) ^^ (parity (StairArchiveNativeCut.canonical (dirs 63) (dirs 63))).testBit (rows 63))) ^^ ((parity (ArchivePortAction.code (dirs 67))).testBit (rows 67) ^^ (parity (StairArchiveNativeCut.canonical (dirs 67) (dirs 67))).testBit (rows 67))) ^^ ((parity (ArchivePortAction.code (dirs 70))).testBit (rows 70) ^^ (parity (StairArchiveNativeCut.canonical (dirs 70) (dirs 70))).testBit (rows 70))) ^^ ((parity (ArchivePortAction.code (dirs 73))).testBit (rows 73) ^^ (parity (StairArchiveNativeCut.canonical (dirs 73) (dirs 73))).testBit (rows 73))) ^^ ((parity (ArchivePortAction.code (dirs 76))).testBit (rows 76) ^^ (parity (StairArchiveNativeCut.canonical (dirs 76) (dirs 76))).testBit (rows 76))) ^^ ((parity (ArchivePortAction.code (dirs 79))).testBit (rows 79) ^^ (parity (StairArchiveNativeCut.canonical (dirs 79) (dirs 79))).testBit (rows 79))) ^^ ((parity (ArchivePortAction.code (dirs 82))).testBit (rows 82) ^^ (parity (StairArchiveNativeCut.canonical (dirs 82) (dirs 82))).testBit (rows 82))) := by have h0 := stable_sum stable0 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable0,List.mem_range,List.mem_range'_1] at hi omega)) have h1 := stable_sum stable1 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable1,List.mem_range,List.mem_range'_1] at hi omega)) have h2 := stable_sum stable2 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable2,List.mem_range,List.mem_range'_1] at hi omega)) have h3 := stable_sum stable3 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable3,List.mem_range,List.mem_range'_1] at hi omega)) have h4 := stable_sum stable4 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable4,List.mem_range,List.mem_range'_1] at hi omega)) have h5 := stable_sum stable5 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable5,List.mem_range,List.mem_range'_1] at hi omega)) have h6 := stable_sum stable6 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable6,List.mem_range,List.mem_range'_1] at hi omega)) have h7 := stable_sum stable7 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable7,List.mem_range,List.mem_range'_1] at hi omega)) have h8 := stable_sum stable8 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable8,List.mem_range,List.mem_range'_1] at hi omega)) have h9 := stable_sum stable9 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable9,List.mem_range,List.mem_range'_1] at hi omega)) have h10 := stable_sum stable10 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable10,List.mem_range,List.mem_range'_1] at hi omega)) have h11 := stable_sum stable11 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable11,List.mem_range,List.mem_range'_1] at hi omega)) have h12 := stable_sum stable12 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable12,List.mem_range,List.mem_range'_1] at hi omega)) have h13 := stable_sum stable13 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable13,List.mem_range,List.mem_range'_1] at hi omega)) have h14 := stable_sum stable14 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable14,List.mem_range,List.mem_range'_1] at hi omega)) have h15 := stable_sum stable15 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable15,List.mem_range,List.mem_range'_1] at hi omega)) have h16 := stable_sum stable16 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable16,List.mem_range,List.mem_range'_1] at hi omega)) have h17 := stable_sum stable17 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable17,List.mem_range,List.mem_range'_1] at hi omega)) have h18 := stable_sum stable18 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable18,List.mem_range,List.mem_range'_1] at hi omega)) have h19 := stable_sum stable19 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable19,List.mem_range,List.mem_range'_1] at hi omega)) have h20 := stable_sum stable20 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable20,List.mem_range,List.mem_range'_1] at hi omega)) have h21 := stable_sum stable21 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable21,List.mem_range,List.mem_range'_1] at hi omega)) have h22 := stable_sum stable22 a b (fun i hi=>rest i (by unfold Elsewhere simp only [stable22,List.mem_range,List.mem_range'_1] at hi omega)) rw [allSum a, allSum b, h0, h1, h2, h3, h4, h5, h6, h7, h8, h9, h10, h11, h12, h13, h14, h15, h16, h17, h18, h19, h20, h21, h22, fromData _ _ _ _ (custom 10 (by decide)), fromData _ _ _ _ (custom 13 (by decide)), fromData _ _ _ _ (custom 16 (by decide)), fromData _ _ _ _ (custom 19 (by decide)), fromData _ _ _ _ (custom 22 (by decide)), fromData _ _ _ _ (custom 25 (by decide)), fromData _ _ _ _ (custom 28 (by decide)), fromData _ _ _ _ (custom 31 (by decide)), fromData _ _ _ _ (custom 35 (by decide)), fromData _ _ _ _ (custom 39 (by decide)), fromData _ _ _ _ (custom 43 (by decide)), fromData _ _ _ _ (custom 47 (by decide)), fromData _ _ _ _ (custom 51 (by decide)), fromData _ _ _ _ (custom 55 (by decide)), fromData _ _ _ _ (custom 59 (by decide)), fromData _ _ _ _ (custom 63 (by decide)), fromData _ _ _ _ (custom 67 (by decide)), fromData _ _ _ _ (custom 70 (by decide)), fromData _ _ _ _ (custom 73 (by decide)), fromData _ _ _ _ (custom 76 (by decide)), fromData _ _ _ _ (custom 79 (by decide)), fromData _ _ _ _ (custom 82 (by decide)), fromData _ _ _ _ (stock 10 (by decide)), fromData _ _ _ _ (stock 13 (by decide)), fromData _ _ _ _ (stock 16 (by decide)), fromData _ _ _ _ (stock 19 (by decide)), fromData _ _ _ _ (stock 22 (by decide)), fromData _ _ _ _ (stock 25 (by decide)), fromData _ _ _ _ (stock 28 (by decide)), fromData _ _ _ _ (stock 31 (by decide)), fromData _ _ _ _ (stock 35 (by decide)), fromData _ _ _ _ (stock 39 (by decide)), fromData _ _ _ _ (stock 43 (by decide)), fromData _ _ _ _ (stock 47 (by decide)), fromData _ _ _ _ (stock 51 (by decide)), fromData _ _ _ _ (stock 55 (by decide)), fromData _ _ _ _ (stock 59 (by decide)), fromData _ _ _ _ (stock 63 (by decide)), fromData _ _ _ _ (stock 67 (by decide)), fromData _ _ _ _ (stock 70 (by decide)), fromData _ _ _ _ (stock 73 (by decide)), fromData _ _ _ _ (stock 76 (by decide)), fromData _ _ _ _ (stock 79 (by decide)), fromData _ _ _ _ (stock 82 (by decide))] rw [pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,pair_step,Bool.xor_self,Bool.false_xor] end ECDSAAdd.Entrant.StairPacket.WindowFieldParity end section namespace ECDSAAdd.Entrant.Stair44Kernel open Arithmetic MappedCompressed Secp256k1 DirectSkywalk StairConcreteAssembly open Rolling1588Lifetime set_option maxRecDepth 16000 set_option maxHeartbeats 3000000 attribute [local irreducible] run measurementCount wires renameProgram abbrev divLead := renameProgram phaseHost (openR true 409 ++ checkpointPrimitives.firstPack) abbrev fieldD := StairHostsSchedule.entryFieldHosted checkpointPrimitives hostPlan def division := (divLead ++ fieldD) ++ renameProgram phaseHost Stair44DivTerm.routedClose private theorem reallead : StairSchedule.firstPhase checkpointPrimitives = openS true 409 ++ checkpointPrimitives.firstPack := by simp only [openS,StairSchedule.firstPhase,StairSchedule.stackForward6,List.append_assoc] private theorem leadCount : measurementCount divLead = measurementCount (renameProgram phaseHost (StairSchedule.firstPhase checkpointPrimitives)) := by rw [reallead,(renameProgram_counts _ _).2,(renameProgram_counts _ _).2,measurementCount_append,measurementCount_append,open_count] private theorem leadRun {t : State} (F : EntryFrame t) (m : List Bool) : run divLead m t=run (renameProgram phaseHost (StairSchedule.firstPhase checkpointPrimitives)) m t := by apply MappedCompressed.pullState_perm_injective phaseHost rw [run_rename _ phaseHost.injective,run_rename _ phaseHost.injective, StairField13V3Clean.pull_phaseHost_entry F,reallead] exact with_tail true 409 F.x _ (by decide) F.x_pos F.x_lt F.sharedNodup t (StairField13V3Clean.entryInput F) _ m private theorem transferPool (v old target : State) (e : pullState phaseHost old=target) (h : v.phase=old.phase ∧ ∀q∈skywalkPoolWires base,v.basis q=old.basis q) : (pullState phaseHost v).phase=target.phase ∧ ∀q∈skywalkPoolWires base,(pullState phaseHost v).basis q=target.basis q := by subst target exact ⟨h.1,fun q hq => h.2 _ (Stair44DivTerm.host_pool q hq)⟩ theorem division_run {t : State} (F : EntryFrame t) (m : List Bool) : run division m t = run (StairHostsSchedule.entryKernel checkpointPrimitives hostPlan) m t := by let A := Stair44DivisionCut.beforeClose checkpointPrimitives hostPlan let L := renameProgram phaseHost (InverseFive23.lastPhase15 false) have stock : StairHostsSchedule.entryKernel checkpointPrimitives hostPlan=A++L := rfl have same (u : List Bool) : run (divLead ++ fieldD) u t=run A u t := by change _=run (_++_) u t rw [run_append,run_append,leadCount,leadRun F] have cnt : measurementCount (divLead++fieldD)=measurementCount A := by change _=measurementCount (_++_) rw [measurementCount_append,measurementCount_append,leadCount] rw [division,stock,run_append (divLead++fieldD),run_append A,cnt,same] obtain ⟨v,ev⟩ : ∃ v : State,run A (m.take (measurementCount A)) t=v := ⟨_,rfl⟩ rw [ev] have h := Stair44DivisionCut.pool F (m.take (measurementCount A)) change (run A _ t).phase=_ ∧ ∀q∈skywalkPoolWires base,(run A _ t).basis q=_ at h rw [ev] at h let P := Rolling1588TickGap.firstPhase false have first := StairLoanField7Values.first_phase_hosted false F.sharedNodup F.historyAbove F.x _ F.x_pos F.x_lt t [] (StairField13V3Clean.entryInput F) have before := run_rename phaseHost phaseHost.injective P [] t change pullState phaseHost (run (renameProgram phaseHost (Rolling1588TickGap.firstPhase false)) [] t)=_ at before rw [first,StairField13V3Clean.pull_phaseHost_entry F] at before apply MappedCompressed.pullState_perm_injective phaseHost change pullState phaseHost (run (renameProgram phaseHost _) _ v)=pullState phaseHost (run (renameProgram phaseHost _) _ v) rw [run_rename _ phaseHost.injective,run_rename _ phaseHost.injective] have good := transferPool v _ _ before h exact Stair44DivTerm.close F.x _ F.x_pos F.x_lt F.sharedNodup t _ (StairField13V3Clean.entryInput F) good.1 good.2 _ theorem hostReplay : ∀ k,StairSemanticComposition.HostedReplayInterface k := StairSemanticComposition.hostedReplayInterface_of (StairHostReplayField.hostReplay_of_field (StairOpenWiring.host_replay_of StairOpenWiring.remaining)) (StairCertificate.replay_interfaces (StairOpenWiring.stairOpen_of_remaining StairOpenWiring.remaining)) theorem division_correct : FrontierEntry1591Callers.EntryCorrect division := by intro hn hl ho hf x Y hx0 hx s t m input hg hs phase eq val let F : EntryFrame t := ⟨hn,hl,ho,hf,x,Y,hx0,hx,s,input,hg,hs,phase,eq,val⟩ have old := StairCallerReplay.hostedEntry_correct hostReplay hn hl ho hf x Y hx0 hx s t m input hg hs phase eq val dsimp only at old ⊢ rw [division_run F] exact old end ECDSAAdd.Entrant.Stair44Kernel end section namespace ECDSAAdd.Entrant.Stair44Kernel open Arithmetic MappedCompressed Stair44WalkMap set_option maxRecDepth 12000 set_option maxHeartbeats 1200000 def rawOut := Stair44PointMap.chain [(base 1542,base 500),(base 1026,base 501),(base 1541,base 502), (base 723,base 503),(base 724,base 504)] def rawX := rawOut.trans (Equiv.swap (base 501) (base 514)) def changeList := [1542,1026,1541,723,724,500,501,502,503,504,514].map base private theorem off (w : Wire) (h : w∉changeList) : rawOut.symm w=w ∧ rawX.symm w=w ∧ first.symm w=w := by simp only [changeList,List.map_cons,List.map_nil,List.mem_cons,List.not_mem_nil,or_false,not_or] at h obtain ⟨a,b,c,d,e,f,g,i,j,k,l⟩ := h simp [rawOut,rawX,Stair44PointMap.chain,first,shared,Equiv.swap_apply_def,a,b,c,d,e,f,g,i,j,k,l] private theorem encode_eq (f g : Equiv.Perm Wire) (z : List Wire) (chk : ∀q∈changeList,f.symm q=g.symm q ∨ f.symm q∈z ∧ g.symm q∈z) (far : ∀q,q∉changeList → f.symm q=g.symm q) (u : State) (hu : ∀q∈z,u.basis q=false) : pullState f.symm u = pullState g.symm u := by apply State.extensionality · rfl · funext q;change u.basis (f.symm q)=u.basis (g.symm q) by_cases h : q∈changeList · rcases chk q h with eq|⟨a,b⟩ · rw [eq] · rw [hu _ a,hu _ b] · rw [far q h] theorem xBefore (u : State) (hz : ∀j∈Stair44WalkExit.firstClean,u.basis (base j)=false) : pullState first.symm u=pullState rawX.symm u := by apply encode_eq first rawX (Stair44WalkExit.firstClean.map base) (by decide +kernel) (fun q h => (off q h).2.2.trans (off q h).2.1.symm) intro q h obtain ⟨j,hj,rfl⟩ := List.mem_map.mp h exact hz _ hj theorem xAfter (u : State) (a : u.basis (base 1026)=false) (b : u.basis (base 514)=false) : pullState rawX.symm u=pullState rawOut.symm u := by apply encode_eq rawX rawOut [base 1026,base 514] (by decide +kernel) (fun q h => (off q h).2.1.trans (off q h).1.symm) intro q h simp only [List.mem_cons,List.not_mem_nil,or_false] at h rcases h with rfl|rfl · exact a · exact b attribute [local irreducible] run wires measurementCount Rolling1588.reverse Rolling1588TickGap.forward Rolling1588.Integer.regularForward Stair44WalkRun.backward ParityXExitInverse23Kernel.x1N theorem routed_at_X (a x : Nat) (cut : 16+a∈[425,505,506]) (hx0 : 0 u.basis q) er).symm let R := Rolling1588.reverse true 1 (15+a) obtain ⟨v,ev⟩ : ∃ w,run R mr t=w := ⟨_,rfl⟩ obtain ⟨act,ea⟩ : ∃ w,run (Stair44WalkRun.backward true a) mr t=w := ⟨_,rfl⟩ have dec : pullState first act=v := by rw [←ea,←ev,et] exact Stair44WalkCuts.backward_record true a x cut hx0 hx s1 raw enc mr h1 eqb have pool : ∀q∈skywalkPoolWires base,v.basis q = s1.basis q := by rw [←ev,et] exact Stair44WalkCuts.restore_raw true a x cut hx0 hx s1 raw enc mr h1 eqb have z (j : Nat) (hj : j∈Stair44WalkExit.firstClean) : v.basis (base j)=false := (pool _ (OB5.base_pool _ (by simp [Stair44WalkExit.firstClean] at hj; omega))).trans (Stair44WalkExit.first_ready true x p s1 h1 j hj) have revertEq (e : Equiv.Perm Wire) (u : State) : pullState e.symm (pullState e u)=u := by apply State.extensionality · rfl · funext q; exact congrArg u.basis (e.apply_symm_apply q) have registered := congrArg (pullState first.symm) dec rw [revertEq,xBefore v z] at registered change run (Stair44WalkRun.backward true a) mr t=pullState rawX.symm (run R mr t) rw [ea,ev]; exact registered theorem reverseX (k x : Nat) (hx0 : 0 1+3*b) /-- Groups the archives hold: two per bank. -/ def packed (n : Nat) : List Nat := (List.range n).flatMap (fun b => [2+3*b, 3+3*b]) /-- The two letters of each archived group that no code cell keeps (letters 5 and 9). -/ def holes (s1 n : Nat) : List Wire := (packed n).flatMap (fun i => [base (1028+gstart s1 i+2), base (1028+gstart s1 i+4)]) def logical (sw : Bool) (r : Nat) : Wire := if sw then base (1028+r) else base r /-- A history cell of tick `r < e` in the exit-tick frame. -/ def site (e : Nat) (sw : Bool) (r : Nat) : Wire := OB5.sig e (logical sw r) def offset (j : Fin 16) : Nat := 5*(j.val/8)+[0,0,1,1,2,3,3,4].getD (j.val%8) 0 def swap (j : Fin 16) : Bool := j.val%8∈[1,3,6] def index (j : Fin 16) : Fin 10 := ⟨if j.val%8<5 then j.val%8 else j.val%8+1,by split <;> omega⟩ def group (b : Nat) (j : Fin 16) : Nat := 2+3*b+j.val/8 /-- Block start of bank `b` (the archive of block `j1+b`, or the exit archive for `b = n-1`). -/ def tick (s1 b : Nat) : Nat := s1+15*b /-- Code cell `j` of bank `b`: the first 16 code ports of the archive at tick `tick s1 b+15`. -/ def bankSite (s1 b : Nat) (j : Fin 16) : Wire := (Partial.cellsRestoreP (tick s1 b+15)).getD j 0 def packet (s1 i : Nat) : Nat := s1+15*((i-2)/3) def high (i : Nat) : Bool := decide ((i-2)%3=1) /-- `StockArchiveTruth.tile` (same body, so the two agree by `rfl`). -/ def tile (k : Nat) (hi : Bool) : Nat := k+5+(if hi then 5 else 0) /-- All archive cells of the window. -/ def archives (s1 n : Nat) : List Wire := (List.range n).flatMap (fun b => (List.finRange 16).map (bankSite s1 b)) /-- `OB5.sig` keeps the history cell of tick `r` fixed in every frame later than `r`. -/ theorem stable (i e r : Nat) (hi : i ≤ 511) (he : e ≤ 511) (ri : r < i) (re : r < e) (sw : Bool) : OB5.sig i (logical sw r)=site e sw r := by show OB5.sigNat i (logical sw r)=OB5.sigNat e (logical sw r) cases sw <;> simp only [logical,base,Bool.false_eq_true,if_false,if_true,OB5.sigNat] <;> split_ifs with h1 h2 h2 <;> (try rcases h1 with h1|h1) <;> (try rcases h2 with h2|h2) <;> omega /-- The 16 code cells of the archive at tick `t` are the history cells of ticks `t-10..t-1`. -/ theorem cells (t : Nat) (lo : 10≤t) (hi : t≤511) (j : Fin 16) : (Partial.cellsRestoreP t).getD j 0=OB5.sig t (logical (swap j) (t-10+offset j)) := by show _=OB5.sigNat t (logical (swap j) (t-10+offset j)) rcases j with ⟨j,hj⟩ interval_cases j <;> simp only [Partial.cellsRestoreP,List.getD_cons_zero,List.getD_cons_succ,logical,swap,offset,base, OB5.sig_nat,List.mem_cons,List.not_mem_nil,or_false,List.getD,List.getElem?_cons_zero, List.getElem?_cons_succ,Option.getD_some] <;> first | rfl | (simp only [OB5.sigNat]; split_ifs with h1 h2 <;> (try rcases h1 with h1|h1) <;> (try rcases h2 with h2|h2) <;> omega) | (norm_num [OB5.sigNat]; split_ifs <;> omega) /-- Bank cells in the exit frame: tick `tick s1 b+5+offset j`, older than the exit. -/ theorem bank_site (s1 b e : Nat) (lo : 5≤s1) (hb : tick s1 b+15≤e) (he : e≤511) (j : Fin 16) : bankSite s1 b j=site e (swap j) (tick s1 b+5+offset j) ∧ tick s1 b+5+offset j simp [offset] refine ⟨?_,by omega⟩ rw [bankSite,cells _ (by simp only [tick]; omega) (by omega)] rw [show tick s1 b+15-10+offset j=tick s1 b+5+offset j by omega] exact stable _ e _ (by omega) he (by omega) (by omega) _ /-- `StockArchiveBanks.chart`, generic: bank cell `j` of bank `b` is letter `index j` of group `group b j`, a packed group whose packet tick is the bank's block start. -/ theorem chart (s1 n b e : Nat) (lo : 5≤s1) (hb : b simp [logical,swap,offset,slot,History5.historyMap,History5.historyId,index,group, gstart,tick,base] <;> omega · simp only [packet,group]; rw [show (2+3*b+j.val/8-2)/3=b by have:=j.isLt; omega]; rfl · simp only [packed,group,List.mem_flatMap,List.mem_range,List.mem_cons,List.not_mem_nil,or_false] exact ⟨b,hb,by have:=j.isLt; omega⟩ · simp only [high,group]; have:=j.isLt; congr 1; apply propext; omega theorem bank_mem (s1 n b : Nat) (hb : b omega · right; simp [slot,History5.historyMap,History5.historyId,base] <;> omega · right -- the bank cell holding letter `j` of group `i` let k:Nat:=8*(i-2-3*b)+(if j.val<5 then j.val else j.val-1) have hk:k<16:=by have:=j.isLt; simp only [k]; split <;> omega have gi:group b ⟨k,hk⟩=i:=by simp only [group,k]; split <;> omega have ij:index ⟨k,hk⟩=j:=by apply Fin.ext; simp only [index,k] have:=j.isLt have h5:j.val≠5:=fun h=>hole (Or.inl (Fin.ext h)) have h9:j.val≠9:=fun h=>hole (Or.inr (Fin.ext h)) split <;> split <;> omega have c:=(chart s1 n b e lo hb he le ⟨k,hk⟩).1 rw [gi,ij] at c rw [←c] exact bank_mem s1 n b hb _ theorem hole_slot (s1 n : Nat) : ∀q∈holes s1 n,∃i∈packed n,∃j:Fin 10,q=slot s1 i j := by intro q hq simp only [holes,List.mem_flatMap,List.mem_cons,List.not_mem_nil,or_false] at hq obtain ⟨i,hi,e|e⟩:=hq · exact ⟨i,hi,5,by simp [e,slot,History5.historyMap,History5.historyId,base] <;> omega⟩ · exact ⟨i,hi,9,by simp [e,slot,History5.historyMap,History5.historyId,base] <;> omega⟩ /-- `StockGroups.distinct`, generic: different groups use different history cells. -/ theorem distinct (s1 : Nat) (lo : 5≤s1) (i h : Nat) (hi : gstart s1 i+5≤1028) (hh : gstart s1 h+5≤1028) (ne : i≠h) (a b : Fin 10) : slot s1 i a≠slot s1 h b := by have:=a.isLt; have:=b.isLt intro eq have e2:History5.historyId (gstart s1 i) a+16=History5.historyId (gstart s1 h) b+16:=eq simp only [History5.historyId,gstart] at e2 hi hh split_ifs at e2 <;> omega theorem split (n i : Nat) (hi : i<3*n+1) : i∈plain n ∨ i∈packed n := by simp only [plain,packed,List.mem_cons,List.mem_map,List.mem_range,List.mem_flatMap,List.not_mem_nil,or_false] rcases Nat.lt_or_ge i 1 with h|h · left; left; omega · have:=Nat.mod_lt (i-1) (show 0<3 by decide) rcases (show (i-1)%3=0 ∨ (i-1)%3=1 ∨ (i-1)%3=2 by omega) with r|r|r · left; right; exact ⟨(i-1)/3,by omega,by omega⟩ · right; exact ⟨(i-1)/3,by omega,by omega⟩ · right; exact ⟨(i-1)/3,by omega,by omega⟩ end ECDSAAdd.Entrant.StairPacket.StockWindowGeo end -- ArchiveStockRows.FinalW / bankPorts / FinalW.bank: in Window (build-chain switch) section namespace ECDSAAdd.Entrant.StairPacket.ArchiveStockSuffixW open Arithmetic MappedCompressed StockWindowGeo set_option maxRecDepth 10000 set_option maxHeartbeats 5000000 set_option linter.unnecessarySeqFocus false set_option linter.unreachableTactic false set_option linter.unusedSimpArgs false set_option linter.unusedTactic false set_option linter.unusedVariables false /-! par-d2: `ArchiveStockSuffix`, generic in the exit tick `e` (dadon: 270, a multiple of 5) and over the window's archive cells `StockWindowGeo.archives s1 n` (dadon: four banks). The stock suffix ticks after `e` never touch an archive cell. The proofs are dadon's with 270/271 replaced by `e`/`e+1`. Ticks `e+1..e+4` are not due, which dadon special-cased as `i < 275`; here the `packDue` split alone handles them. -/ private theorem no_pack (e i:Nat) (e5:e%5=0) (lo:e+1 ≤ i) (hi:i < 512) (r:Nat) (old:r < e) (d sw:Bool): logical sw r∉wires (Rolling1588.Integer.packFirst base d i) ∧ logical sw r∉wires (Rolling1588.unpackAtTick d i):=by have disjoint (due:History5.packDue i=true) (j:Fin 10):logical sw r≠History5.historyMap base (i-5) j:=by simp only [History5.packDue,decide_eq_true_eq] at due have lim:=j.isLt cases sw <;> simp only [logical,Bool.false_eq_true,if_false,if_true,History5.historyMap,History5.historyId,base,Wire] all_goals split_ifs <;> omega constructor · intro h rw [Rolling1588.Integer.packFirst,if_neg (show i≠5 by omega),Rolling1588.Integer.pack_support_eq] at h unfold History5.packAfter at h split at h · rename_i due obtain ⟨j,eq⟩:=History5.history_gate_mem base (i-5) _ (Or.inl rfl) _ h exact disjoint due j eq · simp [wires] at h · intro h rw [←Rolling1588.Integer.unpackFirst_base,Rolling1588.Integer.unpackFirst,if_neg (show i≠5 by omega), Rolling1588.Integer.decodeBefore_support_eq] at h unfold History5.decodeBefore at h split at h · rename_i due obtain ⟨j,eq⟩:=History5.history_gate_mem base (i-5) _ (Or.inr rfl) _ h exact disjoint due j eq · simp [wires] at h private theorem one (e:Nat) (e5:e%5=0) (he:e≤511) (d sw:Bool) (r i:Nat) (old:r < e) (lo:e+1 ≤ i) (hi:i < 512): site e sw r∉wires (renameProgram (OB5.sig i) (TickRanges.tick base i ++ Rolling1588.Integer.packFirst base d i)) ∧ site e sw r∉wires (renameProgram (OB5.sig i) (Rolling1588.unpackAtTick d i ++ W.ReverseCarry.compactReceiverTick base i)):=by have past:WideReference.Earlier i (logical sw r):=⟨r,by omega,by cases sw <;> simp [logical]⟩ have off:=WideReference.away hi past have pack:=no_pack e i e5 lo hi r old d sw have pre (q:Wire) (eq:OB5.sig i q=site e sw r):q=logical sw r:=by -- `StairPacket.stable` (parent) hides the opened name rw [←StockWindowGeo.stable i e r (by omega) he (by omega) old sw] at eq have inj:Function.Injective (OB5.sig i):=(OB5.sig_injective i (by omega)) exact inj eq constructor <;> intro h <;> rw [renameProgram_support] at h <;> obtain ⟨q,mem,eq⟩:=Finset.mem_image.mp h <;> rw [pre q eq,wires_append,Finset.mem_union] at mem · rcases mem with tick|packet · exact off (List.mem_toFinset.mp (W.repairedTick_support base i hi base_pool_nodup (TickRanges.tick_support base i hi base_pool_nodup tick))) · exact pack.1 packet · rcases mem with packet|tick · exact pack.2 packet · exact off (List.mem_toFinset.mp (W.ReverseCarry.compactReceiverTick_support base i hi base_pool_nodup tick)) theorem suffix (e:Nat) (e5:e%5=0) (he:e≤511) (d sw:Bool) (r i n:Nat) (old:r < e) (lo:e+1 ≤ i) (hi:i+n≤512): site e sw r∉wires (Rolling1588TickGap.forward d i n) ∧ site e sw r∉wires (Rolling1588.reverse d i n):=by induction n generalizing i with | zero=>simp [Rolling1588TickGap.forward,Rolling1588.reverse,wires] | succ n ih=> have a:=one e e5 he d sw r i old lo (by omega) have b:=ih (i+1) (by omega) (by omega) simp only [Rolling1588TickGap.forward,Rolling1588.reverse,wires_append,Finset.mem_union,not_or] exact ⟨⟨a.1,b.1⟩,⟨b.2,a.2⟩⟩ /-- `ArchiveStockSuffix.safe`, generic over the window's archive cells. -/ theorem safe (s1 n e:Nat) (lo5:5≤s1) (he:e=s1+15*n) (le:e≤511) (e5:e%5=0) (d:Bool) (i m:Nat) (lo:e+1 ≤ i) (hi:i+m≤512) (q:Wire) (mem:q∈archives s1 n): q∉wires (Rolling1588TickGap.forward d i m) ∧ q∉wires (Rolling1588.reverse d i m):=by obtain ⟨sw,r,old,rfl⟩:=archive_old s1 n e lo5 he le q mem exact suffix e e5 le d sw r i m old lo hi def Same (s1 n:Nat) (a b:State):Prop:=a.phase=b.phase ∧ ∀q,q∉archives s1 n → a.basis q=b.basis q theorem independent (s1 n:Nat) (P:Program) (off:∀q∈archives s1 n,q∉wires P) (m:List Bool) (s t:State) (same:Same s1 n s t): Same s1 n (run P m s) (run P m t) ∧ ∀q∈archives s1 n,(run P m s).basis q=s.basis q:=by have eqs:=pool_run_agrees P (wires P) (Finset.Subset.refl _) m s t same.1 (fun q h=>same.2 q (fun mem=>off q mem h)) refine ⟨⟨eqs.1,?_⟩,fun q mem=>run_preserves_outside _ m s _ (off q mem)⟩ intro q ext by_cases use:q∈wires P · exact eqs.2 q use · rw [run_preserves_outside _ m s _ use,run_preserves_outside _ m t _ use] exact same.2 q ext end ECDSAAdd.Entrant.StairPacket.ArchiveStockSuffixW end section namespace ECDSAAdd.Entrant.StairPacket.StockGroupsW open Arithmetic MappedCompressed StockWindowGeo set_option maxRecDepth 10000 set_option maxHeartbeats 4000000 set_option linter.unnecessarySeqFocus false set_option linter.unreachableTactic false set_option linter.unusedSimpArgs false set_option linter.unusedTactic false set_option linter.unusedVariables false /-! par-d2: `StockGroups` for the `n`-block window from `s1`. Group `i < 3n+1` packs ticks `gstart s1 i .. +4`. Groups are `Nat` indices; dadon used `Fin 13`. dadon's `stockEq` was `rfl` at 210/61; here it is an induction over the window's due ticks. -/ def ports (s1 i:Nat):Finset Wire:=Finset.univ.image (slot s1 i) def one (s1:Nat) (d:Bool) (i:Nat):Program:=Rolling1588.encodeAt base d (gstart s1 i) def batch (s1:Nat) (d:Bool) (seq:List Nat):Program:=seq.flatMap (one s1 d) def all (n:Nat):List Nat:=List.range (3*n+1) /-- `packs`, restated here (parallel chain); `StockTailW.packs_bridge` equates the two. -/ def packs (d:Bool) (i:Nat):Nat→Program | 0=>[] | n+1=>Rolling1588.Integer.packAfter base d i ++ packs d (i+1) n theorem packs_add (d:Bool) (i a b:Nat): packs d i (a+b)=packs d i a++packs d (i+a) b:=by induction a generalizing i with | zero=>simp [packs] | succ a ih=> rw [show a+1+b=(a+b)+1 by omega,packs,packs,ih (i+1),List.append_assoc, show i+1+a=i+(a+1) by omega] theorem pack_idle (d:Bool) (k:Nat) (hk:k%5≠0):Rolling1588.Integer.packAfter base d k=[]:=by unfold Rolling1588.Integer.packAfter rw [if_neg (by simp only [History5.packDue,decide_eq_true_eq]; omega)] theorem packs_idle (d:Bool) (i:Nat) (h:i%5=1):packs d i 4=[]:=by simp only [packs,List.append_nil] rw [pack_idle d i (by omega),pack_idle d (i+1) (by omega),pack_idle d (i+1+1) (by omega), pack_idle d (i+1+1+1) (by omega)] rfl theorem packs_due (d:Bool) (i:Nat) (h5:10≤ i) (h:i%5=0): packs d i 1=Rolling1588.encodeAt base d (i-5):=by simp only [packs,List.append_nil] unfold Rolling1588.Integer.packAfter Rolling1588.Integer.encode rw [if_pos (by simp only [History5.packDue,decide_eq_true_eq]; omega),if_neg (by omega)] /-- `StockGroups.stockEq`, generic: the stock walk's packs over the window are the batch of its `3n+1` groups. -/ theorem stockEq (d:Bool) (s1 n:Nat) (lo:10≤s1) (h5:s1%5=0): packs d s1 (15*n+1)=batch s1 d (all n):=by have g:∀ m k,packs d (s1+5*k) (5*m+1)=(List.range' k (m+1)).flatMap (one s1 d):=by intro m induction m with | zero=> intro k rw [show 5*0+1=1 by rfl,packs_due d _ (by omega) (by omega)] simp only [List.range'_succ,List.range'_zero,List.flatMap_cons,List.flatMap_nil,List.append_nil,one,gstart] congr 1; omega | succ m ih=> intro k rw [show 5*(m+1)+1=1+(4+(5*m+1)) by omega,packs_add,packs_add,packs_due d _ (by omega) (by omega), packs_idle d _ (by omega),show s1+5*k+1+4=s1+5*(k+1) by omega,ih (k+1)] -- unfold both sides together; a `rw` of `range'_succ` hits only the left copy simp only [List.append_nil,List.range'_succ,List.flatMap_cons,List.nil_append,one,gstart] rw [show s1 - 5 + 5 * k = s1 + 5 * k - 5 by omega] have e:=g (3*n) 0 rw [show 5*(3*n)+1=15*n+1 by omega,show s1+5*0=s1 by omega] at e rw [e,batch,all,List.range_eq_range'] theorem allNodup (n:Nat):(all n).Nodup:=List.nodup_range theorem inAll {n i:Nat} (h:i<3*n+1):i∈all n:=List.mem_range.mpr h theorem plainNodup (n:Nat):(plain n).Nodup:=by simp only [plain,List.nodup_cons,List.mem_map,List.mem_range,not_exists,not_and] refine ⟨fun b _ e=>by omega,?_⟩ exact (List.nodup_range).map (fun a b e=>by omega) theorem cover (s1:Nat) (d:Bool) (i:Nat):wires (one s1 d i)⊆ports s1 i:=by intro q h change q∈wires (renameProgram (MeasuredCodec5.label (slot s1 i)) (Rolling1588.codeEncode d)) at h rw [renameProgram_support] at h obtain ⟨a,ha,rfl⟩:=Finset.mem_image.mp h rw [(Rolling1588.code_support d).1,Finset.mem_range] at ha exact Finset.mem_image.mpr ⟨⟨a,ha⟩,Finset.mem_univ _,by simp [MeasuredCodec5.label,ha]⟩ private theorem distant (s1:Nat) (lo:5≤s1) {i h:Nat} (hi:gstart s1 i+5≤1028) (hh:gstart s1 h+5≤1028) (ne:i≠h) {q:Wire} (mem:q∈ports s1 i):q∉ports s1 h:=by intro hit obtain ⟨a,_,ea⟩:=Finset.mem_image.mp mem obtain ⟨b,_,eb⟩:=Finset.mem_image.mp hit exact distinct s1 lo i h hi hh ne a b (ea.trans eb.symm) theorem batch_cover (s1:Nat) (d:Bool) (seq:List Nat) (q:Wire) (hit:q∈wires (batch s1 d seq)): ∃i∈seq,q∈ports s1 i:=by induction seq with | nil=>simp [batch,wires] at hit | cons h t ih=> change q∈wires (one s1 d h++batch s1 d t) at hit rw [wires_append,Finset.mem_union] at hit rcases hit with a|b · exact ⟨h,by simp,cover _ _ _ a⟩ · obtain ⟨i,ii,v⟩:=ih b exact ⟨i,by simp [ii],v⟩ theorem outside (s1:Nat) (d:Bool) (seq:List Nat) (s:State) (q:Wire) (off:∀i∈seq,q∉ports s1 i): (run (batch s1 d seq) [] s).basis q=s.basis q:=by apply run_preserves_outside intro hit;obtain ⟨i,mem,h⟩:=batch_cover s1 d seq q hit;exact off i mem h theorem isolated (s1:Nat) (lo:5≤s1) (d:Bool) (seq:List Nat) (nd:seq.Nodup) (small:∀i∈seq,gstart s1 i+5≤1028) (s:State) (i:Nat) (mem:i∈seq) (q:Wire) (hq:q∈ports s1 i): (run (batch s1 d seq) [] s).basis q=(run (one s1 d i) [] s).basis q:=by induction seq generalizing s with | nil=>simp at mem | cons h t ih=> change (run (one s1 d h++batch s1 d t) [] s).basis q=_ rw [run_append,run_take,List.drop_nil] obtain ⟨not,unique⟩:=List.nodup_cons.mp nd have sh:gstart s1 h+5≤1028:=small h (by simp) have st:∀k∈t,gstart s1 k+5≤1028:=fun k hk=>small k (by simp [hk]) rcases List.mem_cons.mp mem with rfl|im · exact outside s1 d t _ q (fun j jj=>distant s1 lo sh (st j jj) (fun eq=>not (eq.symm ▸ jj)) hq) · have ne:i≠h:=fun eq=>not (eq ▸ im) have si:=st i im have hd:Disjoint (wires (one s1 d i)) (wires (one s1 d h)):=by rw [Finset.disjoint_left] intro q' a b exact distant s1 lo si sh ne (cover _ _ _ a) (cover _ _ _ b) rw [ih unique st (run (one s1 d h) [] s) im,run_disjoint_commute _ _ hd] exact run_preserves_outside _ _ _ _ (fun bad=>distant s1 lo si sh ne hq (cover _ _ _ bad)) /-- Window groups stay inside the history pool. -/ theorem small_all (s1 n:Nat) (ge:5≤s1) (le:s1+15*n≤511) :∀i∈all n,gstart s1 i+5≤1028:=by intro i hi; have:=List.mem_range.mp hi; simp only [gstart]; omega theorem small_plain (s1 n:Nat) (ge:5≤s1) (le:s1+15*n≤511) :∀i∈plain n,gstart s1 i+5≤1028:=by intro i hi simp only [plain,List.mem_cons,List.mem_map,List.mem_range] at hi rcases hi with rfl|⟨b,hb,rfl⟩ <;> simp only [gstart] <;> omega /-- dadon's instance: the 13 groups of 210..270. -/ example (d:Bool) : packs d 210 61=batch 210 d (all 4) := stockEq d 210 4 (by decide) (by decide) end ECDSAAdd.Entrant.StairPacket.StockGroupsW end section namespace ECDSAAdd.Entrant.StairPacket.StockArchiveReferenceW open Arithmetic MappedCompressed WideReference StockWindowGeo set_option linter.unusedVariables false /-- par-d2: `StockArchiveReference.common` for the `n`-block window from `s1` (exit `s1+15n`). The native packs of the window are the batch of its `plain` groups. -/ def ordinary (s1 n:Nat) (d:Bool):Program:=StockGroupsW.batch s1 d (plain n) def common (s1 n:Nat) (d:Bool) (raw:State):State:= pullState (OB5.sig (s1+15*n)) (eraseSites (holes s1 n) (run (ordinary s1 n d) [] (run (span s1 (15*n+1)) [] raw))) end ECDSAAdd.Entrant.StairPacket.StockArchiveReferenceW namespace ECDSAAdd.Entrant.StairPacket.StockBaselineW open Arithmetic MappedCompressed Secp256k1 WideReference StockWindowGeo StockGroupsW open StairArchiveNativeRows CodecBitSliceVerify set_option maxRecDepth 14000 set_option maxHeartbeats 4000000 set_option linter.unnecessarySeqFocus false set_option linter.unreachableTactic false set_option linter.unusedSimpArgs false set_option linter.unusedTactic false set_option linter.unusedVariables false attribute [local irreducible] run span WideReference.canonical theorem high_lo (b:Nat):high (2+3*b)=false:=by simp only [high]; rw [decide_eq_false_iff_not]; omega theorem high_hi (b:Nat):high (3+3*b)=true:=by simp only [high]; rw [decide_eq_true_eq]; omega theorem packed_lt {n i:Nat} (h:i∈StockWindowGeo.packed n):i<3*n+1:=by -- `StairPacket.packed` (parent) hides `StockWindowGeo.packed` simp only [StockWindowGeo.packed,List.mem_flatMap,List.mem_range,List.mem_cons,List.not_mem_nil,or_false] at h obtain ⟨b,hb,h|h⟩:=h <;> omega theorem plain_lt {n i:Nat} (h:i∈plain n):i<3*n+1:=by simp only [plain,List.mem_cons,List.mem_map,List.mem_range] at h rcases h with rfl|⟨b,hb,rfl⟩ <;> omega /-- `StockBaseline.chart`, generic: an archived group is the young/old half of its bank's tile. -/ theorem chart (s1 n i:Nat) (lo:5≤s1) (hi:i∈StockWindowGeo.packed n):gstart s1 i=tile (packet s1 i) (high i) ∧ s1≤packet s1 i ∧ packet s1 i+15≤s1+15*n ∧ ∃b subst h · rw [high_lo] simp only [gstart,tile,packet,Bool.false_eq_true,if_false] exact ⟨by omega,by omega,by omega,b,hb,by omega⟩ · rw [high_hi] simp only [gstart,tile,packet,if_true] exact ⟨by omega,by omega,by omega,b,hb,by omega⟩ theorem small512 (s1 n:Nat) (ge:5≤s1) (le:s1+15*n≤511) (seq:List Nat) (bound:∀i∈seq,i<3*n+1):∀i∈seq,gstart s1 i+5≤512:=by intro i hi; have:=bound i hi; simp only [gstart]; omega theorem phase_batch (s1:Nat) (d:Bool) (seq:List Nat) (small:∀i∈seq,gstart s1 i+5≤512) (s:State): (run (batch s1 d seq) [] s).phase=s.phase:=by induction seq generalizing s with | nil=>simp only [batch,List.flatMap_nil,run] | cons h t ih=> change (run (one s1 d h++batch s1 d t) [] s).phase=_ rw [run_append,run_take,List.drop_nil,ih (fun k hk=>small k (by simp [hk]))] exact Rolling1588.codeEncodeAt_zero_phase d (slot s1 h) (History5.historyMap_injective base base_pool_nodup (gstart s1 h) (small h (by simp))) s end ECDSAAdd.Entrant.StairPacket.StockBaselineW namespace ECDSAAdd.Entrant.StairPacket.StockArchiveBanksW open Arithmetic MappedCompressed Secp256k1 WideReference StockWindowGeo StockGroupsW open ArchivePortAction StairArchiveNativeRows CodecBitSliceVerify set_option maxRecDepth 16000 set_option maxHeartbeats 5000000 set_option exponentiation.threshold 100000 set_option linter.unnecessarySeqFocus false set_option linter.unreachableTactic false set_option linter.unusedSimpArgs false set_option linter.unusedTactic false set_option linter.unusedVariables false attribute [local irreducible] run span /-! par-d2: `StockArchiveBanks` for the window of blocks `j1 .. jn` (`n = jn-j1+1` banks, exit at `start j1+15n`). Bank `b < n` is the archive of block `j1+b`, or the exit archive for the last bank. `exitCells` is the one fact needed from par-c2's exit form: its first 16 code ports are the cells of the exit tick. `ArchiveBoundary270.codePortsList` starts with `cellsRestoreP 270`, as the generic exit form will. -/ theorem window_cells (k:Fin 26) (j:Fin 16): ArchiveJ7.codePorts k ⟨j.val,by omega⟩=(Partial.cellsRestoreP (start k+15)).getD j 0:=by rw [ArchiveJ7.codePorts,ArchiveJ7.code_split,List.append_assoc, List.getD_append _ _ _ _ (by simp [Partial.cellsRestoreP])] def siteAt (j1 jn:Fin 26) (exitPorts:Ports) (b:Nat) (j:Fin 16):Wire:= ArchiveStockRows.bankPorts j1 jn exitPorts b ⟨j.val,by omega⟩ theorem site_eq (j1 jn:Fin 26) (exitPorts:Ports) (exitCells:∀j:Fin 16,exitPorts ⟨j.val,by omega⟩=(Partial.cellsRestoreP (start jn+15)).getD j 0) (b:Nat) (hb:j1.val+b≤jn.val) (j:Fin 16):siteAt j1 jn exitPorts b j=bankSite (start j1) b j:=by simp only [siteAt,ArchiveStockRows.bankPorts,bankSite,tick] split · rw [ArchiveJ7.head_port_eq _ j, window_cells]; congr 2; simp only [start]; omega · rw [exitCells]; congr 2; simp only [start]; omega /-- dadon's `byte`, now independent of the bank: one small decide over `Bool × Fin 16`. -/ theorem byte:∀(d:Bool)(j:Fin 16), get (storage (native d (decide (8≤j.val)))) (index j)=get (StairArchiveNativeCut.canonical d d) j:=by decide +kernel def nativeAt (ps:Fin 16→Wire) (d:Bool) (r:Nat) (s:State):Prop:= ∀j:Fin 16,s.basis (ps j)=(get (StairArchiveNativeCut.canonical d d) j).testBit r theorem readback (e:Nat) (he:e≤511) (z:State) (q w:Wire) (eq:q=OB5.sig e w): (pullState (OB5.sig e) z).basis q=z.basis w:=by change z.basis (OB5.sig e q)=z.basis w rw [eq,OB5.sig_invol e he] end ECDSAAdd.Entrant.StairPacket.StockArchiveBanksW end -- END par-d2 StockWindowW -- BEGIN par-d2 OrdinaryChainW (Tail8dd, serial tail; after ArchiveHistoryCompare) section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainW open Arithmetic MappedCompressed WideReference ArchiveHistoryCompare set_option maxRecDepth 10000 set_option maxHeartbeats 4000000 set_option linter.unnecessarySeqFocus false set_option linter.unreachableTactic false set_option linter.unusedSimpArgs false set_option linter.unusedTactic false set_option linter.unusedVariables false attribute [local irreducible] run /-! par-d2: the mask/program half of dadon's `OrdinaryChain` (`mask{s}`, `progW{s}`, `add{s}`), as a fold over the window's blocks from `s1`. Block `k` (start `s1+15k`) has two parts: - its exit hands the previous block's archive cells (ticks `s-10..s-1`) to the stock frame (`newBank`, empty for the first block; dadon's `Logical{s}Exit.newBank`); - its ordinary program is the stock encoder of its plain group (`s1-5` for the first block, `s-15` after). dadon's three per-step decides over the growing masks (`maskEarly`, `progEarly`, `apart`) become `omega` bounds: mask cells are older than `s-15`, and program cells are older than `s-10`. -/ /-- History cells of ticks `t .. t+9`. -/ def cells10 (t:Nat):List Wire:=(List.range' t 10).flatMap (fun r=>[base r,base (1028+r)]) def newBank (s1 s:Nat):List Wire:=if s=s1 then [] else cells10 (s-10) /-- Plain group of block `k`. -/ def group (s1 k:Nat):Nat:=if k=0 then s1-5 else s1+15*k-15 def mask (s1:Nat):Nat→List Wire | 0=>[] | k+1=>mask s1 k++newBank s1 (s1+15*k) def progW (s1:Nat) (d:Bool):Nat→Program | 0=>[] | k+1=>progW s1 d k++Rolling1588.encodeAt base d (group s1 k) theorem mask_cells (s1:Nat) (lo:10≤s1) : ∀k,∀q∈mask s1 k,∃r,r+16≤s1+15*k ∧ (q=base r ∨ q=base (1028+r)) | 0,q,h=>by simp [mask] at h | k+1,q,h=>by simp only [mask,List.mem_append] at h rcases h with h|h · obtain ⟨r,hr,e⟩:=mask_cells s1 lo k q h exact ⟨r,by omega,e⟩ · unfold newBank at h split at h · simp at h · simp only [cells10,List.mem_flatMap,List.mem_range'_1,List.mem_cons,List.not_mem_nil,or_false] at h obtain ⟨r,⟨r1,r2⟩,e⟩:=h exact ⟨r,by omega,e⟩ theorem encode_cells (d:Bool) (t:Nat) : ∀q∈wires (Rolling1588.encodeAt base d t), ∃r,t≤r ∧ r≤t+4 ∧ (q=base r ∨ q=base (1028+r)) := by intro q h change q∈wires (renameProgram (MeasuredCodec5.label (History5.historyMap base t)) (Rolling1588.codeEncode d)) at h rw [renameProgram_support] at h obtain ⟨a,ha,rfl⟩:=Finset.mem_image.mp h rw [(Rolling1588.code_support d).1,Finset.mem_range] at ha refine ⟨t+a/2,by omega,by omega,?_⟩ simp only [MeasuredCodec5.label,ha,dif_pos,History5.historyMap,History5.historyId] split · left; rfl · right; congr 1; omega theorem prog_cells (s1:Nat) (lo:10≤s1) (d:Bool) : ∀k,∀q∈wires (progW s1 d k),∃r,r+11≤s1+15*k ∧ (q=base r ∨ q=base (1028+r)) | 0,q,h=>by simp [progW,wires] at h | k+1,q,h=>by simp only [progW,wires_append,Finset.mem_union] at h rcases h with h|h · obtain ⟨r,hr,e⟩:=prog_cells s1 lo d k q h exact ⟨r,by omega,e⟩ · obtain ⟨r,r1,r2,e⟩:=encode_cells d _ q h refine ⟨r,?_,e⟩ simp only [group] at r1 r2 split at r1 <;> split at r2 <;> omega /-- `OrdinaryChain.add{s}`, generic: block `k ≥ 1` extends the mask and the ordinary program by one block. -/ theorem add (s1:Nat) (lo:10≤s1) (k:Nat) (hk:1≤k) (lim:s1+15*k+15≤512) (d:Bool) (raw baseRaw out:State) (old:Except (mask s1 k) raw (run (progW s1 d k) [] (run (span s1 (15*k)) [] baseRaw))) (step:Except (newBank s1 (s1+15*k)) out (run (Rolling1588.encodeAt base d (group s1 k)) [] (run (span (s1+15*k) 15) [] raw))) : Except (mask s1 (k+1)) out (run (progW s1 d (k+1)) [] (run (span s1 (15*(k+1))) [] baseRaw)) := by have h:=extend (s1+15*k) 15 lim _ _ _ _ raw (run (span s1 (15*k)) [] baseRaw) out old step (fun q hit=>by obtain ⟨r,hr,e⟩:=mask_cells s1 lo k q hit; exact ⟨r,by omega,e⟩) (fun q hit=>by obtain ⟨r,hr,e⟩:=prog_cells s1 lo d k q hit; exact ⟨r,by omega,e⟩) (fun q hit used=>by obtain ⟨r,hr,e⟩:=mask_cells s1 lo k q hit obtain ⟨r',r1,r2,e'⟩:=encode_cells d _ q used simp only [group,if_neg (show k≠0 by omega)] at r1 r2 rcases e with rfl|rfl <;> rcases e' with e'|e' <;> simp only [base,Wire] at e' <;> omega) have chronology:run (span s1 (15*(k+1))) [] baseRaw=run (span (s1+15*k) 15) [] (run (span s1 (15*k)) [] baseRaw):=by rw [show 15*(k+1)=15*k+15 by omega,spanAppend s1 (15*k) 15,run_append,run_take,List.drop_nil] rw [chronology] exact h /-- The exit tick (`OrdinaryChain.add270`, generic): the stock tick `e` itself and the last archive's cells. -/ theorem add_last (s1:Nat) (lo:10≤s1) (n:Nat) (hn:1≤n) (lim:s1+15*n+1≤512) (d:Bool) (raw baseRaw out:State) (old:Except (mask s1 n) raw (run (progW s1 d n) [] (run (span s1 (15*n)) [] baseRaw))) (step:Except (cells10 (s1+15*n-10)) out (run (Rolling1588.encodeAt base d (s1+15*n-15)) [] (run (span (s1+15*n) 1) [] raw))) : Except (mask s1 n++cells10 (s1+15*n-10)) out (run (progW s1 d n++Rolling1588.encodeAt base d (s1+15*n-15)) [] (run (span s1 (15*n+1)) [] baseRaw)) := by have h:=extend (s1+15*n) 1 lim _ _ _ _ raw (run (span s1 (15*n)) [] baseRaw) out old step (fun q hit=>by obtain ⟨r,hr,e⟩:=mask_cells s1 lo n q hit; exact ⟨r,by omega,e⟩) (fun q hit=>by obtain ⟨r,hr,e⟩:=prog_cells s1 lo d n q hit; exact ⟨r,by omega,e⟩) (fun q hit used=>by obtain ⟨r,hr,e⟩:=mask_cells s1 lo n q hit obtain ⟨r',r1,r2,e'⟩:=encode_cells d _ q used rcases e with rfl|rfl <;> rcases e' with e'|e' <;> simp only [base,Wire] at e' <;> omega) have chronology:run (span s1 (15*n+1)) [] baseRaw=run (span (s1+15*n) 1) [] (run (span s1 (15*n)) [] baseRaw):=by rw [spanAppend s1 (15*n) 1,run_append,run_take,List.drop_nil] rw [chronology] exact h /-! First ship 120..255 (s1 = 120, n = 10 blocks, exit 270). -/ example : group 120 0=115 ∧ group 120 9=240 ∧ newBank 120 120=[] ∧ newBank 120 135=cells10 125 := ⟨rfl,rfl,rfl,rfl⟩ -- needs par-a WideReference patch (oldSites, endRaw_inside_gen/outside_gen); goes inside OrdinaryChainW after `add_last` /-! Hole carry, generic (`OrdinaryChain.carry240/255` and `holes225/240/255`). dadon decided `q∉sites` and `oldRange` per block. Here both are hypotheses, so the proof does not grow with the window. `clear` is par-c2's `cleared_holes` (still per block). `endRaw_inside_gen` reads the snapshot through `OB5.sig (s+14)`, which is the identity on these wires only while `Fixed s` holds; the statement does not assume that. -/ theorem carry (s:Nat) (hs:s+14≤511) (holes:List Wire) (off:∀q∈holes,q∉oldSites s) (aged:∀q∈holes,oldRange s q) (raw history:State) (clear:∀q∈holes,raw.basis q=false) : ∀q∈holes,(endRaw s raw history).basis q=false := by intro q hq rw [endRaw_outside_gen s hs raw history q (off q hq)] rw [run_preserves_outside (span s 15) [] raw q (pastOffSpan s 15 q (by omega) (OrdinaryChain.early s q (aged q hq)))] exact clear q hq end ECDSAAdd.Entrant.StairPacket.OrdinaryChainW end -- END par-d2 OrdinaryChainW -- ==== w4: build-w4b StockTailW + StockRowVectorW ==== -- BEGIN par-d2 StockTailW (serial tail: Tail8dd; only what needs StockDelayed.window / StockArchiveByte) section namespace ECDSAAdd.Entrant.StairPacket.StockGroupsW set_option linter.unusedVariables false /-- The parallel chain's `packs` is dadon's `StockDelayed.packs`. -/ theorem packs_bridge (d:Bool) (i n:Nat):StockDelayed.packs d i n=packs d i n:=by induction n generalizing i with | zero=>rfl | succ n ih=>rw [StockDelayed.packs,packs,ih] end ECDSAAdd.Entrant.StairPacket.StockGroupsW namespace ECDSAAdd.Entrant.StairPacket.StockArchiveTruthW open Arithmetic MappedCompressed WideReference SkywalkRails StairArchiveTrace StairArchiveRaw StairArchiveNativeRows CodecBitSliceVerify set_option linter.unnecessarySeqFocus false set_option linter.unreachableTactic false set_option linter.unusedSimpArgs false set_option linter.unusedTactic false set_option linter.unusedVariables false attribute [local irreducible] run SkywalkNat.step span WideReference.canonical StairArchiveRaw.rawCol SkywalkTrace.trace private theorem observeSite (b:BasisState) (t:Nat) (q:Fin 10) (v:Bool×Bool) (a:b (base (t+q.val/2))=v.1) (c:b (base (1028+(t+q.val/2)))=v.2): b (History5.historyMap base t q)=letterBit v q:=by unfold History5.historyMap History5.historyId letterBit by_cases h:q.val%2=0 · simpa only [if_pos h] using a · simpa only [if_neg h,Nat.add_assoc] using c /-- `StockArchiveTruth.raw_for`, generic in the window start `s1` and length `len` (dadon: 210, 61). -/ theorem raw_for (s1 len x p:Nat) (lim:s1+len≤512) (good:Bounds x p) (s:State) (dom:Domain s1 x p s) (k:Nat) (start:s1≤k) (stop:k+15≤s1+len) (row:Nat) (truth:ArchiveStockRows.Chronology k x p row) (hi:Bool) (q:Fin 10): (run (span s1 len) [] s).basis (History5.historyMap base (StockWindowGeo.tile k hi) q)= (rawCol ((if hi then 10 else 0)+q.val)).testBit row:=by let e:Nat:=(if hi then 10 else 0)+q.val have bound:e<20:=by cases hi <;> simp [e] <;> omega have lo:s1≤StockWindowGeo.tile k hi+q.val/2:=by unfold StockWindowGeo.tile;omega have lim':StockWindowGeo.tile k hi+q.val/2 simp [StockWindowGeo.tile] <;> omega have obs:=trace_sites s1 len x p lim good s [] dom (StockWindowGeo.tile k hi+q.val/2) lo lim' have exactBit:=observeSite (run (span s1 len) [] s).basis (StockWindowGeo.tile k hi) q _ obs.1 obs.2 have label:=StockArchiveTruth.observedLabel k x p row truth ⟨e,bound⟩ change (rawCol e).testBit row=letterBit (SkywalkTrace.code (WideReference.canonical (k+(5+e/2)) x p)) e at label have shift : k+(5+e/2)=StockWindowGeo.tile k hi+q.val/2:=by cases hi <;> simp [StockWindowGeo.tile,e] <;> omega have parity:e%2=q.val%2:=by cases hi <;> simp [e] omega rw [shift] at label have bit (v:Bool×Bool):letterBit v e=letterBit v q:=by simp only [letterBit,parity] exact exactBit.trans ((bit _).symm.trans label.symm) theorem native_byte (s1 len x p:Nat) (lim:s1+len≤512) (good:Bounds x p) (s:State) (dom:Domain s1 x p s) (k:Nat) (start:s1≤k) (stop:k+15≤s1+len) (row:Nat) (lm:row<63145) (truth:ArchiveStockRows.Chronology k x p row) (d hi:Bool) (m:List Bool): let raw:=run (span s1 len) [] s let f:=History5.historyMap base (StockWindowGeo.tile k hi) let out:=run (Rolling1588.codeEncodeAt d f) m raw out.phase=raw.phase ∧ ∀q:Fin 10,out.basis (f q)=(get (storage (native d hi)) q).testBit row:=by exact StockArchiveByte.run_byte d hi row lm _ (History5.historyMap_injective base base_pool_nodup _ (by cases hi <;> simp [StockWindowGeo.tile] <;> omega)) _ m (raw_for s1 len x p lim good s dom k start stop row truth hi) end ECDSAAdd.Entrant.StairPacket.StockArchiveTruthW namespace ECDSAAdd.Entrant.StairPacket.StockBaselineW open Arithmetic MappedCompressed Secp256k1 WideReference StockWindowGeo StockGroupsW open StairArchiveNativeRows CodecBitSliceVerify set_option maxRecDepth 14000 set_option maxHeartbeats 4000000 set_option linter.unnecessarySeqFocus false set_option linter.unreachableTactic false set_option linter.unusedSimpArgs false set_option linter.unusedTactic false set_option linter.unusedVariables false attribute [local irreducible] run span WideReference.canonical theorem receipt (s1 n:Nat) (lo:10≤s1) (le:s1+15*n≤511) (d:Bool) (x:Nat) (good:Bounds x p) (s:State) (dom:Domain s1 x p s) (i:Nat) (active:i∈StockWindowGeo.packed n) (row:Nat) (lim:row<63145) (truth:ArchiveStockRows.Chronology (packet s1 i) x p row) (j:Fin 10): let raw:=run (span s1 (15*n+1)) [] s (run (batch s1 d (all n)) [] raw).basis (slot s1 i j)=(get (storage (native d (high i))) j).testBit row:=by have ⟨shape,lo',hi',_⟩:=chart s1 n i (by omega) active let raw:=run (span s1 (15*n+1)) [] s have obs:=StockArchiveTruthW.native_byte s1 (15*n+1) x p (by omega) good s dom (packet s1 i) lo' (by omega) row lim truth d (high i) [] have bit:=obs.2 j change (run (batch s1 d (all n)) [] raw).basis (slot s1 i j)=_ rw [isolated s1 (by omega) d (all n) (allNodup n) (small_all s1 n (by omega) le) raw i (inAll (packed_lt active)) (slot s1 i j) (Finset.mem_image.mpr ⟨j,Finset.mem_univ _,rfl⟩)] change (run (Rolling1588.codeEncodeAt d (History5.historyMap base (gstart s1 i))) [] raw).basis (History5.historyMap base (gstart s1 i) j)=_ rwa [shape] /-- `StockBaseline.from_final`, generic over the window's banks. -/ theorem from_final {j1 jn:Fin 26} {exitPorts:ArchivePortAction.Ports} (n:Nat) (hn:jn.val+1=j1.val+n) (d:Bool) (x:Nat) (a:State) (results:ArchiveStockRows.FinalW j1 jn exitPorts d x p a) (i:Nat) (active:i∈StockWindowGeo.packed n) : ∃row<63145,ArchiveStockRows.Chronology (packet (start j1) i) x p row:=by obtain ⟨-,-,-,b,hb,eq⟩:=chart (start j1) n i (by simp only [start]; omega) active obtain ⟨r,l,t,_⟩:=results.bank b (by omega) exact ⟨r,l,by rw [eq]; exact t⟩ /-- `StockBaseline.comparison`, generic: after the window, the stock walk and the window's reference state agree off the archive cells. -/ theorem comparison {j1 jn:Fin 26} {exitPorts:ArchivePortAction.Ports} (n:Nat) (hn:jn.val+1=j1.val+n) (le:start j1+15*n≤511) (d:Bool) (x:Nat) (good:Bounds x p) (s a:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p (start j1) s.basis) (results:ArchiveStockRows.FinalW j1 jn exitPorts d x p a): ArchiveStockSuffixW.Same (start j1) n (run (Rolling1588TickGap.forward d (start j1) (15*n+1)) m (pullState (OB5.sig (start j1-1)) s)) (StockArchiveReferenceW.common (start j1) n d s):=by have lo:10≤start j1:=by simp only [start]; omega have h5:start j1%5=0:=by simp only [start]; omega let s1:=start j1 let raw:=run (span s1 (15*n+1)) [] s have stock:=StockDelayed.window d x good.nonzero good.small s1 (15*n+1) (by omega) (by omega) s m stage rw [show s1+(15*n+1)-1=s1+15*n by omega] at stock change run (Rolling1588TickGap.forward d s1 (15*n+1)) m (pullState (OB5.sig (s1-1)) s)= pullState (OB5.sig (s1+15*n)) (run (StockDelayed.packs d s1 (15*n+1)) [] raw) at stock rw [stock,packs_bridge,stockEq d s1 n lo h5,StockArchiveReferenceW.common,StockArchiveReferenceW.ordinary] refine ⟨(phase_batch s1 d (all n) (small512 s1 n (by omega) le _ (fun i hi=>List.mem_range.mp hi)) raw).trans (phase_batch s1 d (plain n) (small512 s1 n (by omega) le _ (fun i hi=>plain_lt hi)) raw).symm,?_⟩ intro q safe let y:=OB5.sig (s1+15*n) q change (run (batch s1 d (all n)) [] raw).basis y= (if y∈holes s1 n then false else (run (batch s1 d (plain n)) [] raw).basis y) have away:OB5.sig (s1+15*n) y∉archives s1 n:=by simpa only [y,OB5.sig_invol (s1+15*n) (by omega)] using safe by_cases old:∃i∈StockWindowGeo.packed n,y∈ports s1 i · obtain ⟨i,used,inside⟩:=old obtain ⟨j,_,atSite⟩:=Finset.mem_image.mp inside have hs:=sparse s1 n (s1+15*n) (by omega) rfl le i used j rcases hs with ⟨blank,hit⟩|covered · rw [←atSite,if_pos hit] obtain ⟨row,lim,history⟩:=from_final n hn d x a results i used have dom:=WideReference.initial s1 x p (by omega) d s stage have bit:=receipt s1 n lo le d x good s dom i used row lim history j have cleared (k:Nat) (ok:k=5 ∨ k=9):CodecBitSliceVerify.get (storage (native d (high i))) k=0:=by rcases ok with rfl|rfl <;> rfl exact bit.trans ((congrArg (fun a:Nat=>a.testBit row) (cleared j (by rcases blank with rfl|rfl <;> decide))).trans (Nat.zero_testBit row)) · exact (away (atSite ▸ covered)).elim · have nh:y∉holes s1 n:=by intro h;obtain ⟨i,used,j,e⟩:=hole_slot s1 n y h exact old ⟨i,used,Finset.mem_image.mpr ⟨j,Finset.mem_univ _,e.symm⟩⟩ rw [if_neg nh] by_cases saved:∃i∈plain n,y∈ports s1 i · obtain ⟨i,mem,h⟩:=saved exact (isolated s1 (by omega) d (all n) (allNodup n) (small_all s1 n (by omega) le) raw i (inAll (plain_lt mem)) y h).trans (isolated s1 (by omega) d (plain n) (plainNodup n) (small_plain s1 n (by omega) le) raw i mem y h).symm · have off (i:Nat) (hi:i<3*n+1):y∉ports s1 i:=by intro h;rcases StockWindowGeo.split n i hi with m|m · exact saved ⟨i,m,h⟩ · exact old ⟨i,m,h⟩ exact (outside s1 d (all n) raw y (fun i hi=>off i (List.mem_range.mp hi))).trans (outside s1 d (plain n) raw y (fun i hi=>off i (plain_lt hi))).symm end ECDSAAdd.Entrant.StairPacket.StockBaselineW namespace ECDSAAdd.Entrant.StairPacket.StockArchiveBanksW open Arithmetic MappedCompressed Secp256k1 WideReference StockWindowGeo StockGroupsW open ArchivePortAction StairArchiveNativeRows CodecBitSliceVerify set_option maxRecDepth 16000 set_option maxHeartbeats 5000000 set_option exponentiation.threshold 100000 set_option linter.unnecessarySeqFocus false set_option linter.unreachableTactic false set_option linter.unusedSimpArgs false set_option linter.unusedTactic false set_option linter.unusedVariables false attribute [local irreducible] run span /-! par-d2: `StockArchiveBanks` for the window of blocks `j1 .. jn` (`n = jn-j1+1` banks, exit at `start j1+15n`). Bank `b < n` is the archive of block `j1+b`, or the exit archive for the last bank. `exitCells` is the one fact needed from par-c2's exit form: its first 16 code ports are the cells of the exit tick. `ArchiveBoundary270.codePortsList` starts with `cellsRestoreP 270`, as the generic exit form will. -/ theorem stock_state (s1 n:Nat) (lo:10≤s1) (h5:s1%5=0) (le:s1+15*n≤511) (d:Bool) (x:Nat) (good:Bounds x p) (s:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p s1 s.basis): run (Rolling1588TickGap.forward d s1 (15*n+1)) m (pullState (OB5.sig (s1-1)) s)= pullState (OB5.sig (s1+15*n)) (run (batch s1 d (all n)) [] (run (span s1 (15*n+1)) [] s)):=by rw [←stockEq d s1 n lo h5,←packs_bridge] have w:=StockDelayed.window d x good.nonzero good.small s1 (15*n+1) (by omega) (by omega) s m stage rwa [show s1+(15*n+1)-1=s1+15*n by omega] at w theorem stored (j1 jn:Fin 26) (exitPorts:Ports) (exitCells:∀j:Fin 16,exitPorts ⟨j.val,by omega⟩=(Partial.cellsRestoreP (start jn+15)).getD j 0) (n:Nat) (hn:jn.val+1=j1.val+n) (le:start j1+15*n≤511) (d:Bool) (x:Nat) (good:Bounds x p) (s:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p (start j1) s.basis) (b:Nat) (hb:ba.testBit row) (by rw [hj]; exact byte d j)) structure Paired (j1 jn:Fin 26) (exitPorts:Ports) (n:Nat) (d:Bool) (x:Nat) (a s:State) (rows:Nat→Nat):Prop where equality:ArchiveStockSuffixW.Same (start j1) n a s labels:∀b false /-- dadon's `StockRowVector.rows`: a function of `(x, p)` only (the pairing across runs needs that). -/ noncomputable def rows (j1 : Fin 26) (x p : Nat) (b : Nat) : Nat := select (keys j1 x p b) /-- dadon's `StockStrongChain.final`, generic: every bank holds its key-selected row. -/ def final (j1 jn : Fin 26) (exitPorts : Ports) (d : Bool) (x p : Nat) (s : State) : Prop := ∀ b, j1.val + b ≤ jn.val → SavedKey (keys j1 x p b) (ArchiveStockRows.bankPorts j1 jn exitPorts b) d s theorem trace {j1 jn exitPorts d x p s} (h : final j1 jn exitPorts d x p s) (b : Nat) (hb : j1.val + b ≤ jn.val) : ArchiveStockRows.Chronology (start j1 + 15*b) x p (rows j1 x p b) := by have k := (h b hb).2.1 have lt : j1.val + b < 26 := by have := jn.isLt; omega simp only [rows, keys, dif_pos lt] at k ⊢ exact StockRowVector.historical _ _ x p _ _ k /-- dadon's `StockRowVector.binding`, generic over the window's banks. -/ theorem binding (j1 jn : Fin 26) (exitPorts : Ports) (exitCells : ∀ j : Fin 16, exitPorts ⟨j.val, by omega⟩ = (Partial.cellsRestoreP (start jn+15)).getD j 0) (n : Nat) (hn : jn.val+1 = j1.val+n) (le : start j1+15*n ≤ 511) (d : Bool) (x : Nat) (good : Bounds x p) (raw a : State) (m : List Bool) (stage : Rolling1588.Integer.Stage base d x p (start j1) raw.basis) (stored : final j1 jn exitPorts d x p a) (same : ArchiveStockSuffixW.Same (start j1) n a (run (Rolling1588TickGap.forward d (start j1) (15*n+1)) m (pullState (OB5.sig (start j1-1)) raw))) : Paired j1 jn exitPorts n d x a (run (Rolling1588TickGap.forward d (start j1) (15*n+1)) m (pullState (OB5.sig (start j1-1)) raw)) (rows j1 x p) := by refine ⟨same, fun b hb => ⟨(stored b (by omega)).1, trace stored b (by omega)⟩, fun b hb => (stored b (by omega)).2.2, fun b hb => ?_⟩ exact StockArchiveBanksW.stored j1 jn exitPorts exitCells n hn le d x good raw m stage b hb _ (stored b (by omega)).1 (trace stored b (by omega)) end ECDSAAdd.Entrant.StairPacket.StockRowVectorW end -- END build-w4b StockRowVectorW -- ==== w4: end stocktail ==== -- ==== build-main2: generic OrdinaryChain (build-leaves OrdW) ==== /-! build-ordinary (build-leaves): the generic `OrdinaryChain` Ref half for the window 120..255 (exit 270). Replaces dadon's literal `OrdinaryChain` (`Ref240/255/270`, `begin225`, `next240/255`, `last270`, `terminal`, `finish`, `project`, `readOld`, `keepTick`, `keepEncode`, `holes240/255`, `carry255`, `seven`, `wires`) by one induction over the fold's blocks. Every proof here is O(1) in the number of blocks: no decide over the window's growing lists. -/ -- ===== Part 1: generic list facts and the finish (any window `s1`, `n` blocks, exit `s1+15n`) ===== section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainG open Arithmetic MappedCompressed WideReference ArchiveHistoryCompare set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false set_option linter.unusedSimpArgs false attribute [local irreducible] run theorem plain_succ (n : Nat) : StockWindowGeo.plain (n+1)=StockWindowGeo.plain n++[1+3*n] := by simp only [StockWindowGeo.plain,List.range_succ,List.map_append,List.map_cons,List.map_nil,List.cons_append] theorem packed_succ (n : Nat) : StockWindowGeo.packed (n+1)=StockWindowGeo.packed n++[2+3*n,3+3*n] := by simp only [StockWindowGeo.packed,List.range_succ,List.flatMap_append,List.flatMap_cons,List.flatMap_nil, List.append_nil] theorem holes_succ (s1 n : Nat) : StockWindowGeo.holes s1 (n+1)=StockWindowGeo.holes s1 n++ [base (1028+StockWindowGeo.gstart s1 (2+3*n)+2),base (1028+StockWindowGeo.gstart s1 (2+3*n)+4), base (1028+StockWindowGeo.gstart s1 (3+3*n)+2),base (1028+StockWindowGeo.gstart s1 (3+3*n)+4)] := by simp only [StockWindowGeo.holes,packed_succ,List.flatMap_append,List.flatMap_cons,List.flatMap_nil,List.append_nil, List.cons_append,List.nil_append] theorem batch_append (s1 : Nat) (d : Bool) (a b : List Nat) : StockGroupsW.batch s1 d (a++b)=StockGroupsW.batch s1 d a++StockGroupsW.batch s1 d b := by simp only [StockGroupsW.batch,List.flatMap_append] /-- The window's ordinary program after `n+1` blocks is the reference's batch of the `plain` groups. -/ theorem progW_plain (s1 : Nat) (lo : 5≤s1) (d : Bool) : ∀n,OrdinaryChainW.progW s1 d (n+1)=StockGroupsW.batch s1 d (StockWindowGeo.plain n) | 0=>by show []++Rolling1588.encodeAt base d (OrdinaryChainW.group s1 0)=_ simp only [OrdinaryChainW.group,↓reduceIte,List.nil_append,StockWindowGeo.plain,List.range_zero,List.map_nil, StockGroupsW.batch,List.flatMap_cons,List.flatMap_nil,List.append_nil,StockGroupsW.one,StockWindowGeo.gstart, Nat.mul_zero,Nat.add_zero] | n+1=>by have e:OrdinaryChainW.progW s1 d (n+1+1)=OrdinaryChainW.progW s1 d (n+1)++ Rolling1588.encodeAt base d (OrdinaryChainW.group s1 (n+1)):=rfl rw [e,progW_plain s1 lo d n,plain_succ,batch_append] congr 1 simp only [StockGroupsW.batch,List.flatMap_cons,List.flatMap_nil,List.append_nil,StockGroupsW.one, OrdinaryChainW.group,if_neg (show n+1≠0 by omega),StockWindowGeo.gstart] congr 1; omega theorem progW_last (s1 n : Nat) (lo : 5≤s1) (hn : 1≤n) (d : Bool) : OrdinaryChainW.progW s1 d n++Rolling1588.encodeAt base d (s1+15*n-15)= StockGroupsW.batch s1 d (StockWindowGeo.plain n) := by rw [←progW_plain s1 lo d n] show _=OrdinaryChainW.progW s1 d n++Rolling1588.encodeAt base d (OrdinaryChainW.group s1 n) rw [OrdinaryChainW.group,if_neg (by omega)] /-- Every hole is a B-side history cell of a tick inside the window (after its first five ticks). -/ theorem hole_cell (s1 n : Nat) (lo : 5≤s1) : ∀w∈StockWindowGeo.holes s1 n,∃r:Nat,s1+7≤r ∧ r+1≤s1+15*n ∧ w=base (1028+r) := by intro w hw simp only [StockWindowGeo.holes,StockWindowGeo.packed,List.mem_flatMap,List.mem_range,List.mem_cons, List.not_mem_nil,or_false] at hw obtain ⟨i,⟨b,hb,hi⟩,e⟩:=hw simp only [StockWindowGeo.gstart] at e rcases hi with rfl|rfl <;> rcases e with rfl|rfl · exact ⟨s1-5+5*(2+3*b)+2,by omega,by omega,by congr 1⟩ · exact ⟨s1-5+5*(2+3*b)+4,by omega,by omega,by congr 1⟩ · exact ⟨s1-5+5*(3+3*b)+2,by omega,by omega,by congr 1⟩ · exact ⟨s1-5+5*(3+3*b)+4,by omega,by omega,by congr 1⟩ /-- Letter `a` of bank `b`'s ten ticks is a letter of one of its two archived groups. -/ theorem cell_letter (s1 b a : Nat) (lo : 5≤s1) (ha : a<10) : base (s1+15*b+5+a)=StockWindowGeo.slot s1 (2+3*b+a/5) ⟨2*(a%5),by omega⟩ ∧ base (1028+(s1+15*b+5+a))=StockWindowGeo.slot s1 (2+3*b+a/5) ⟨2*(a%5)+1,by omega⟩ := by simp only [StockWindowGeo.slot,History5.historyMap,History5.historyId,StockWindowGeo.gstart,Fin.val_mk] constructor · rw [if_pos (by omega)]; congr 1; omega · rw [if_neg (by omega)]; congr 1; omega /-- `StockGroups.sparse` read on bank `b`'s ten ticks: each cell is a hole or, in the exit frame, an archive cell. -/ theorem cells_census (s1 n b : Nat) (lo : 5≤s1) (hb : bby simp [OrdinaryChainW.mask] at h | k+1,w,h=>by have e:OrdinaryChainW.mask s1 (k+1)=OrdinaryChainW.mask s1 k++OrdinaryChainW.newBank s1 (s1+15*k):=rfl rw [e,List.mem_append] at h rcases h with h|h · obtain ⟨b,hb,m⟩:=mask_mem s1 k w h exact ⟨b,by omega,m⟩ · unfold OrdinaryChainW.newBank at h split at h · simp at h · rename_i hne refine ⟨k-1,by omega,?_⟩ have e2:s1+15*k-10=s1+15*(k-1)+5:=by omega rw [←e2]; exact h /-- dadon's `census` (`finish`), generic: the masked cells are holes or archive cells in the exit frame. -/ theorem census (s1 n : Nat) (lo : 5≤s1) (hn : 1≤n) (le : s1+15*n≤511) : ∀w∈OrdinaryChainW.mask s1 n++OrdinaryChainW.cells10 (s1+15*n-10), w∈StockWindowGeo.holes s1 n ∨ OB5.sig (s1+15*n) w∈StockWindowGeo.archives s1 n := by intro w hw rcases List.mem_append.mp hw with h|h · obtain ⟨b,hb,m⟩:=mask_mem s1 n w h exact cells_census s1 n b lo (by omega) le w m · have e:s1+15*n-10=s1+15*(n-1)+5:=by omega rw [e] at h exact cells_census s1 n (n-1) lo (by omega) le w h /-- dadon's `OrdinaryChain.finish`, generic: the stock-masked exit state plus clear holes is the reference off the archive cells. -/ theorem finishW (s1 n : Nat) (lo : 5≤s1) (hn : 1≤n) (le : s1+15*n≤511) (d:Bool) (out initial:State) (all:Except (OrdinaryChainW.mask s1 n++OrdinaryChainW.cells10 (s1+15*n-10)) (pullState (OB5.sig (s1+15*n)) out) (run (OrdinaryChainW.progW s1 d n++Rolling1588.encodeAt base d (s1+15*n-15)) [] (run (span s1 (15*n+1)) [] initial))) (zero:∀w∈StockWindowGeo.holes s1 n,out.basis (OB5.sig (s1+15*n) w)=false) : ∀q∉StockWindowGeo.archives s1 n,out.basis q=(StockArchiveReferenceW.common s1 n d initial).basis q := by intro q away have inv:OB5.sig (s1+15*n) (OB5.sig (s1+15*n) q)=q:=OB5.sig_invol (s1+15*n) le q generalize ey:OB5.sig (s1+15*n) q=y at inv have goal:(StockArchiveReferenceW.common s1 n d initial).basis q=(eraseSites (StockWindowGeo.holes s1 n) (run (StockArchiveReferenceW.ordinary s1 n d) [] (run (span s1 (15*n+1)) [] initial))).basis y:=by rw [←ey]; rfl rw [goal] by_cases hole:y∈StockWindowGeo.holes s1 n · simp only [eraseSites,if_pos hole] have z:=zero y hole rw [inv] at z exact z · have free:y∉OrdinaryChainW.mask s1 n++OrdinaryChainW.cells10 (s1+15*n-10):=by intro hit rcases census s1 n lo hn le y hit with h|h · exact hole h · rw [inv] at h; exact away h have value:=all y free change out.basis (OB5.sig (s1+15*n) y)=_ at value rw [inv,progW_last s1 n lo hn d] at value simpa only [eraseSites,if_neg hole,StockArchiveReferenceW.ordinary] using value end ECDSAAdd.Entrant.StairPacket.OrdinaryChainG end -- ===== Part 2: the exit at 270 (dadon's `terminal`, without `At270`'s saved keys) ===== section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainG open Arithmetic IntegerPacket MappedCompressed Secp256k1 WideReference SkywalkRails NativePack270 Partial ParkEndpoint StockWindowTicket set_option maxRecDepth 30000 set_option maxHeartbeats 3500000 attribute [local irreducible] run end ECDSAAdd.Entrant.StairPacket.OrdinaryChainG end -- ===== Part 3: the window's reference hand-off `RefW` and the exit block (dadon's `Ref270`, `last270`) ===== section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainG open Arithmetic MappedCompressed IntegerPacket WideReference SkywalkRails Partial ArchivePortAction ArchiveStockRows open StockWindowTicket WindowFold WindowChain Secp256k1 ArchiveHistoryCompare StockWindowW7 set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false attribute [local irreducible] run measurementCount /-- dadon's `Ref240/255/270` for any block `j` of the window from block `f` (tick `start f`): the block's stock hand-off (build-chain's `AtJ`), the logical state agrees with the stock run of `j-3` blocks off the archived cells (par-d2's `mask`/`progW`), and the holes of the banks of blocks `3..j-2` (cleared by blocks `4..j-1`) are zero. -/ def RefW (f j : Fin 26) (d:Bool) (x:Nat) (initial s:State) : Prop := ∃raw g sg pg ps,AtJ j d x p raw s g sg pg ps ∧ Except (OrdinaryChainW.mask (start f) (j.val-f.val)) raw (run (OrdinaryChainW.progW (start f) d (j.val-f.val)) [] (run (span (start f) (15*(j.val-f.val))) [] initial)) ∧ ∀q∈StockWindowGeo.holes (start f) (j.val-f.val-1),raw.basis q=false end ECDSAAdd.Entrant.StairPacket.OrdinaryChainG end -- ===== Part 4: interior blocks 4..12 (dadon's `next240/255`), first block (`begin225`), the fold, `wiresW` ===== section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainG open Arithmetic MappedCompressed IntegerPacket WideReference SkywalkRails Partial ArchivePortAction ArchiveStockRows open StockWindowTicket WindowFold WindowChain Secp256k1 ArchiveHistoryCompare StockWindowW7 set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false attribute [local irreducible] run measurementCount Shadow7.body /-- L11 (new, first form at 90 (block 1); dadon's `StockWindowTicket.ordinary225`): the first block's logical end state is the stock run of its 15 ticks with the five pre-window letters (group 85) encoded. -/ abbrev FirstOrdinarySpec : Prop := ∀ (d:Bool) (x p:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis), Except [] (endRaw 45 raw (run (Shadow7.portalP 45 ++ NativeFirstJ7.enteredWindow WindowParams.first d) m (pullState (OB5.sig 44) raw))) (run (Rolling1588.encodeAt base d 40) [] (run (span 45 15) [] raw)) theorem not_firstF (f k : Fin 26) (hfb : start f=firstBlock) (hk : f.val split <;> omega theorem pastInputF (j : Fin 26) (h1 : 0≤j.val) (h21 : j.val≤24) (x p:Nat) (good:Bounds x p) (raw:State) (dom:Domain (start j) x p raw) (i:Fin 10) : raw.basis (plainF j i)=(run (span (start j) 15) [] raw).basis (plainF j i) := by have pp:=preservePast (start j) 15 x p (start j-5+i.val/2) (by simp only [start]; omega) good raw dom (by simp only [start]; omega) [] rcases plainF_cell j i with ⟨-,e⟩|⟨-,e⟩ · rw [e]; exact pp.1.symm · rw [e,show start j-5+i.val/2+1044=base (1028+(start j-5+i.val/2)) by simp only [base]; omega]; exact pp.2.symm theorem encodeF (j : Fin 26) (h1 : 0≤j.val) (d:Bool) (a b:State) (tape:List Bool) (agree:∀i,a.basis (NativeFirstJ7.history j i)=b.basis (plainF j i)) (i:Fin 10) : (run (NativeFirstJ7.program j d) tape a).basis (NativeFirstJ7.history j i)= (run (Rolling1588.encodeAt base d (start j-5)) [] b).basis (plainF j i) := by rw [(NativeFirstJ7.equals j h1 d).1] exact ArchiveOrdinaryFive.stock_relocated d (NativeFirstJ7.history j) (plainF j) (NativeFirstJ7.histInj j) (plainF_inj j) a b tape [] agree i /-- `Ordinary225Exit.result` for the first block `j`. -/ theorem resultF (j : Fin 26) (h1 : 0≤j.val) (h21 : j.val≤24) (old:∀i,oldRange (start j+1) (windowNet j (NativeFirstJ7.history j i))) (d:Bool) (raw s:State) (m:List Bool) (x p:Nat) (good:Bounds x p) (dom:Domain (start j) x p raw) (input:∀i,(run (Shadow7.routed j 0 1) m s).basis (NativeFirstJ7.history j i)=raw.basis (plainF j i)) : ∀i,(run (Shadow7.body j (NativeFirstJ7.program j d)) m s).basis (NativeFirstJ7.history j i)= (run (Rolling1588.encodeAt base d (start j-5)) [] (run (span (start j) 15) [] raw)).basis (plainF j i) := by intro i rw [OrdinaryJ.kept j _ m s _ (old i)] exact encodeF j h1 d _ _ _ (fun k=>(input k).trans (pastInputF j h1 h21 x p good raw dom k)) i /-- `Logical225Exit.window` for the first block `j` (old cells = the five ticks before it). -/ theorem windowF (j : Fin 26) (h1 : 0≤j.val) (h21 : j.val≤24) (first:oldStart (start j)=start j-5 ∧ oldCount (start j)=5) (d:Bool) (raw historyState:State) (ordinaryBits:∀i,historyState.basis (NativeFirstJ7.history j i)= (run (Rolling1588.encodeAt base d (start j-5)) [] (run (span (start j) 15) [] raw)).basis (plainF j i)) (q:Wire) : (endRaw (start j) raw historyState).basis q= (run (Rolling1588.encodeAt base d (start j-5)) [] (run (span (start j) 15) [] raw)).basis q := by have bound:start j+14≤511:=by simp only [start]; omega have s5:5≤start j:=by simp only [start]; omega by_cases inside:q∈oldSites (start j) · obtain ⟨r,r1,r2,hq⟩:=old_cell inside rw [first.1] at r1 r2 rw [first.2] at r2 have ex:∃i:Fin 10,q=plainF j i:=by simp only [Wire] at * rcases hq with hq|hq · refine ⟨⟨2*(r-(start j-5)),by omega⟩,?_⟩ rcases plainF_cell j ⟨2*(r-(start j-5)),by omega⟩ with ⟨-,e⟩|⟨od,-⟩ · rw [e]; dsimp only; omega · exfalso; simp only at od; omega · refine ⟨⟨2*(r-(start j-5))+1,by omega⟩,?_⟩ rcases plainF_cell j ⟨2*(r-(start j-5))+1,by omega⟩ with ⟨ev,-⟩|⟨-,e⟩ · exfalso; simp only at ev; omega · rw [e]; dsimp only; omega obtain ⟨i,rfl⟩:=ex rw [endRaw_inside_gen _ bound _ _ _ inside,← sigF_same j i] exact ordinaryBits i · rw [endRaw_outside_gen _ bound _ _ _ inside] apply (run_preserves_outside _ _ _ q _).symm intro used obtain ⟨r,r1,r2,hq⟩:=OrdinaryJ.encode_cells d _ q used apply inside simp only [oldSites,first.1,first.2,List.mem_flatMap,List.mem_range'_1,List.mem_cons,List.not_mem_nil, or_false,base] simp only [Wire] at * exact ⟨r,⟨by omega,by omega⟩,by omega⟩ theorem old_first : ∀i:Fin 10,oldRange (start WindowParams.first+1) (windowNet WindowParams.first (NativeFirstJ7.history WindowParams.first i)) := by decide +kernel /-- `FirstOrdinarySpec` (dadon's `ordinary225` at 120), from build-chain's `NativeFirstJ7.first_core` (portal frame). -/ theorem firstOrdinary : FirstOrdinarySpec := by intro d x p good raw m stage let j:=WindowParams.first let z:=unsigned 45 x p let origin:=pullState (OB5.sig 44) raw let cut:=run (Shadow7.portalP 45) m origin let n:=m.drop (measurementCount (Shadow7.portalP 45)) let pre:=run (Shadow7.enterP j) n cut let tape:=n.drop (measurementCount (Shadow7.enterP j)) let T:=Shadow.reduced (Shadow7.sbP 45) 15 z obtain ⟨G,S,inputAt,frame,-⟩:=NativeFirstJ7.first_core d x p good raw m stage have eqg:(SkywalkRails.encode G S (unsigned 45 x p).u (unsigned 45 x p).v).g=G:=by cases G <;> rfl have input:SkywalkIntegerInput (W.compactSkywalkTickLayout base 45) (SkywalkRails.encode G S (unsigned 45 x p).u (unsigned 45 x p).v).a (SkywalkRails.encode G S (unsigned 45 x p).u (unsigned 45 x p).v).b G raw.basis:=by unfold InputAt at inputAt; rwa [eqg] at inputAt have nums:=LeaveJ7.Admission.actualNumbers j (by decide) (by decide) x p good have dom:=initial 45 x p (by decide) d raw stage have hist:=pulled_history j rfl dom have sh:∀r:Fin 15,(IntegerPacket.ports (Shadow7.shape j) ↑r).history=(IntegerPacket.ports (StairPacket.shape j) ↑r).history:=by decide +kernel have hist':∀r:Fin 15,raw.basis (EnterJ7.pull j (windowNet j (IntegerPacket.ports (Shadow7.shape j) ↑r).history))=false:=by intro r; rw [sh r]; exact hist r have ready:=EnterJ7.ready_from_cut_at j raw cut z G S n nums.farSmall frame input hist' have to':T.v%2=1:=shadow_odd_shadow7 (Shadow7.sbP 45) z nums.farSmall nums.odd have parity:((encode G S T.u T.v).a+(encode G S T.u T.v).b)%2=1:=encode_odd_sum G S _ _ (by omega) have inp:=NativeFirstJ7.history_from_stock j (by decide) (by decide) raw cut pre frame n tape rfl _ parity ready.2 have res:=resultF j (by decide) (by decide) old_first d raw pre tape x p good dom inp have fb:start j=firstBlock:=rfl have firstB:oldStart (start j)=start j-5 ∧ oldCount (start j)=5:=by rw [fb]; exact ⟨oldStart_first,oldCount_first⟩ intro q _ have w:=windowF j (by decide) (by decide) firstB d raw _ res q have e:run (Shadow7.portalP 45++NativeFirstJ7.enteredWindow WindowParams.first d) m origin= run (Shadow7.body j (NativeFirstJ7.program j d)) tape pre:=by simp only [NativeFirstJ7.enteredWindow,NativeFirstJ7.window,run_append,run_take]; rfl rw [e] exact w end ECDSAAdd.Entrant.StairPacket.OrdinaryChainG end section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainG open Arithmetic MappedCompressed WideReference Secp256k1 StockWindowW7 end ECDSAAdd.Entrant.StairPacket.OrdinaryChainG end -- ==== window405: Main's exit-270 pieces at the exit 405 (build-chain's exit360/renderM360.py via helpers/window405/main/renderM_x.py, from Main 74aa223): the exit's -- blank holes, dadon's finalBank receipt (selected_*), the terminal bank (Ordinary420Terminal) and resultW405. ==== section namespace ECDSAAdd.Entrant.StairPacket open Arithmetic MappedCompressed IntegerPacket SkywalkRails ArchivePortAction set_option maxRecDepth 18000 set_option maxHeartbeats 2300000 attribute [local irreducible] run routed measurementCount body namespace NativePack4207 open ArchiveBoundary4207 def fourHoles : List Wire := [1657,1655,1652,1650] theorem blank_slots : ∀q∈fourHoles,∃i:Fin 157,16 ≤ i.val ∧ codePorts i=q := by decide +kernel theorem cleared_holes (d:Bool) (row:Nat) (s:State) (frame:Frame codePorts (code d) row s) : ∀q∈fourHoles,s.basis q=false := by intro q hq obtain ⟨i,hi,rfl⟩:=blank_slots q hq rw [frame,archive_blank d i hi,Nat.zero_testBit] end NativePack4207 end ECDSAAdd.Entrant.StairPacket end section namespace ECDSAAdd.Entrant.StairPacket.NativePack4207 open Arithmetic MappedCompressed Secp256k1 IntegerPacket ArchivePortAction ArchiveBoundary4207 set_option maxRecDepth 25000 set_option maxHeartbeats 3500000 attribute [local irreducible] run open StockCanonicalRow ArchiveBoundary4207 ParkEndpoint4207 Portal420Flag7 Secp256k1 SkywalkRails StairArchiveTrace theorem selected_generic (p q:Program) (d:Bool) (s:State) (m:List Bool) (step:Transition q s (run p m s)) (past:SkywalkNat.State) (G S cross:Bool) (odd:past.v%2=1) (small:Shadow7.SmallIfFar 46 15 past) (prior:PastFacts sourceIdx rawPorts 46 past G S cross s) : let out:=run (p ++ (program d ++ (Shadow7.exitLoadP 420) d)) m s out.phase=s.phase ∧ (let v:=key 46 past cross (SkywalkTrace.trace 15 (encode G S past.u past.v)); select v<63145 ∧ Encodes v (select v) ∧ Frame codePorts (code d) (select v) out) ∧ ∀n,run ((Shadow7.exitRestoreP 420) d ++ (reverse d ++ q)) n out=s := by let tick:=run p m s let e:=m.drop (measurementCount p) let pre:=run (program d) e tick let f:=e.drop (measurementCount (program d)) have ⟨legal,row,limit,frame⟩:=archive_ready d s tick e past G S cross odd small prior step.keptFive step.keptBank step.scratch have truth:=frame_key sourceIdx rawPorts chronological row 46 past G S cross s pre prior (fun i=>(outside d _ (bank_out i) e tick).trans (step.keptBank i)) frame have spec:=select_spec ⟨row,limit,truth⟩ have fresh:=reframe limit truth rawPorts pre frame have enc:=source_law d tick e legal have act:=load_run d _ spec.1 pre f fresh exact sequence_law p (program d) ((Shadow7.exitLoadP 420) d) ((Shadow7.exitRestoreP 420) d) (reverse d) q s m (fun out=>let v:=key 46 past cross (SkywalkTrace.trace 15 (encode G S past.u past.v)); select v<63145 ∧ Encodes v (select v) ∧ Frame codePorts (code d) (select v) out) tick rfl step.phase step.undo pre rfl enc.1 enc.2 (run ((Shadow7.exitLoadP 420) d) f pre) rfl act.1 ⟨spec.1,spec.2,act.2.1⟩ (fun n=>roundtrip d _ spec.1 pre f n fresh) theorem selected_slice (d:Bool) (s:State) (m:List Bool) (step:TickStep s (run EndTick4207.physP m s)) (past:SkywalkNat.State) (G S cross:Bool) (odd:past.v%2=1) (small:Shadow7.SmallIfFar 46 15 past) (prior:PastFacts sourceIdx rawPorts 46 past G S cross s) : let out:=run (endSlice d) m s out.phase=s.phase ∧ (let v:=key 46 past cross (SkywalkTrace.trace 15 (encode G S past.u past.v)); select v<63145 ∧ Encodes v (select v) ∧ Frame codePorts (code d) (select v) out) ∧ ∀n,run (endUndo d) n out=s := selected_generic EndTick4207.physP EndTick4207.physQ d s m step past G S cross odd small prior theorem selected_last (d:Bool) (x:Nat) (hx0:0[OB5.sig 420 (base r), OB5.sig 420 (base (1028+r))]) def ordinary := (List.finRange 10).map history def zeros:=(List.range 134).map (Shadow7.scratchX 420)++dst theorem basis (d:Bool) (raw payload:State) (m n:List Bool) (row:Nat) (clear:∀q∈zeros,raw.basis (OB5.sig 420 q)=false) (frame:Frame codePorts (code d) row (run ((Shadow7.exitLoadP 420) d) n (run (program d) m (stash payload (pullState (OB5.sig 420) raw))))) : let out:=run ((Shadow7.exitLoadP 420) d) n (run (program d) m (stash payload (pullState (OB5.sig 420) raw))) let wide:=run (Rolling1588.encodeAt base d 405) [] raw ∀q∉newBank,out.basis q=wide.basis (OB5.sig 420 q) := by let inp:=stash payload (pullState (OB5.sig 420) raw) let mid:=run (program d) m inp let wide:=run (Rolling1588.encodeAt base d 405) [] raw let coords:=History5.historyMap base 405 have geom:∀i:Fin 10,history i∉dst ∧ OB5.sig 420 (history i)=coords i ∧ history i∉rawPortsList := by dsimp only [coords];decide +kernel have agree (i:Fin 10):inp.basis (history i)=raw.basis (coords i):=by simp only [inp,stash,if_neg (geom i).1,pullState,(geom i).2.1] have injected:Function.Injective coords:=by dsimp only [coords];decide +kernel have keep (q:Wire) (no:q∉ordinary) : wide.basis (OB5.sig 420 q)=raw.basis (OB5.sig 420 q) := by have cover:wires (Rolling1588.encodeAt base d 405) ⊆ ((List.finRange 10).map coords).toFinset:=by dsimp only [coords];cases d <;> decide +kernel apply run_preserves_outside intro h obtain ⟨i,_,e⟩:=List.mem_map.mp (List.mem_toFinset.mp (cover h)) have e':OB5.sig 420 (history i)=OB5.sig 420 q:=(geom i).2.1.trans e have unique:history i=q:=by simpa only [OB5.sig_invol 420 (by decide)] using congrArg (OB5.sig 420) e' exact no (List.mem_map.mpr ⟨i,List.mem_finRange i,unique⟩) dsimp only intro q outside by_cases normal:q∈ordinary · obtain ⟨i,_,rfl⟩:=List.mem_map.mp normal rw [run_preserves_outside ((Shadow7.exitLoadP 420) d) _ _ _ (fun h=>(geom i).2.2 (List.mem_toFinset.mp (load_cover d h))), (geom i).2.1] have encoded:=ArchiveOrdinaryFive.stock_relocated d history coords histInj injected inp raw m [] agree i rw [←(equals d).1] at encoded exact encoded rw [keep q normal] by_cases touched:q∈rawPortsList · have mask:∀q∈rawPortsList,q∈newBank ∨ (q∈zeros ∧ ∃i:Fin 157,16≤ i.val ∧ codePorts i=q) := by decide +kernel obtain ⟨blank,i,hi,slot⟩:=(mask q touched).resolve_left outside rw [clear q blank,←slot,frame,archive_blank _ _ hi,Nat.zero_testBit] · have no:q∉wires ((Shadow7.exitLoadP 420) d):=fun h=>touched (List.mem_toFinset.mp (load_cover d h)) have mask:∀q∈dst,q∈rawPortsList:=by decide +kernel have notDst:q∉dst:=fun h=>touched (mask q h) rw [run_preserves_outside _ _ _ _ no] exact (NativePack4207.outside d q (fun i e=>normal (List.mem_map.mpr ⟨i,List.mem_finRange i,e.symm⟩)) _ _).trans (by simp only [stash,if_neg notDst,pullState]) end ECDSAAdd.Entrant.StairPacket.Ordinary420Terminal end section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainG open Arithmetic IntegerPacket MappedCompressed Secp256k1 WideReference SkywalkRails NativePack4207 Partial ParkEndpoint4207 StockWindowTicket set_option maxRecDepth 30000 set_option maxHeartbeats 3500000 attribute [local irreducible] run /-- `Ordinary270Native.result` with the exit frame as a hypothesis (dadon took it from `step270`, which needs `At270.saved225/240`; the generic hand-off `AtJ 13` has no saved keys). Proof otherwise dadon's. -/ theorem resultW420 (d:Bool) (x:Nat) (good:Bounds x p) (raw s:State) (g sg:Bool) (m:List Bool) (domain:Domain 420 x p raw) (input:InputAt 420 (signedAt 420 x p g sg) raw) (cut:PackedCut Portal420Flag7.loPairs Portal420Flag7.hiPairs 435 1618 1616 1617 (flagNeg 420 x p sg) (decide (farAt 39 420 x p)) (decide (farAt 39 420 x p ∧ 2^39≤(unsigned 420 x p).u)) (pullState (OB5.sig 419) raw) (eraseSites ParkEndpoint4207.src s)) (last:StockWindowW7.LastAt ArchiveBoundary4207.codePorts ⟨24,by decide⟩ d x p (run (lastWindow d) m s)) : ArchiveHistoryCompare.Except Ordinary420Terminal.newBank (run (lastWindow d) m s) (pullState (OB5.sig 420) (run (Rolling1588.encodeAt base d 405) [] (run EndTick4207.canonical [] raw))) := by obtain ⟨ref,stage,read,hist,spare,spaces,hosts⟩:=WideReference.terminal4207 d x raw domain let z:=unsigned 420 x p let v:=run EndTick4207.canonical [] raw let p1:=m.drop (measurementCount (Shadow7.parkP 420)) let p2:=p1.drop (measurementCount (Shadow7.portalInvP 420)) let p3:=p2.drop (measurementCount EndTick4207.physP) let p4:=p3.drop (measurementCount (program d)) have lim:Shadow7.SmallIfFar 39 15 z:=(Shadow7.Envelope.inputs x p 420 (lt_trans good.small good.cap) good.cap (by decide)).1 have mode:farAt 39 420 x p=(2*2^54≤z.u+z.v):=by apply propext;unfold farAt Shadow.far Shadow.high Shadow.limb;exact Nat.le_div_iff_mul_le (by positivity) have first:=parked_release z lim raw s m p1 g sg (readInput 420 x p raw g sg input) (by simpa only [mode] using cut) (empty_from_cut _ _ _ _ _ cut spaces) have tick:=EndTick4207.physical d x good.nonzero good.small raw ref s read stage hist spare p2 let loaded:=run ((Shadow7.exitLoadP 420) d) p4 (run (program d) p3 (stash s (pullState (OB5.sig 420) v))) have actual:run (lastWindow d) m s=loaded := by simp only [lastWindow,endSlice,run_append,run_take] change run ((Shadow7.exitLoadP 420) d) p4 (run (program d) p3 (run EndTick4207.physP p2 (run (Shadow7.portalInvP 420) p1 (run (Shadow7.parkP 420) m s))))=_ rw [first.1,tick.1] obtain ⟨row,_,_,frame⟩:=last rw [actual] at frame have zeros (q:Wire) (h:q∈Ordinary420Terminal.zeros) : v.basis (OB5.sig 420 q)=false:=by rcases List.mem_append.mp h with carryLane|tag · have table:∀q∈(List.range 134).map (Shadow7.scratchX 420),∃k:Fin 134,OB5.sig 420 q=Shadow7.scratchX 420 k.val:=by decide +kernel obtain ⟨k,eq⟩:=table _ carryLane rw [eq];exact (EndTick4207.after_cells d x good.nonzero good.small raw ref read stage hosts).2 k · have coords:∀q∈dst,OB5.sig 420 q=OB5.sig 419 q := by decide +kernel have nocell:=EndTick4207.spared q tag have cover:=W.compactSkywalkTick_support base 420 (by decide) base_pool_nodup have no:OB5.sig 420 q∉wires EndTick4207.canonical:=fun used=>nocell (List.mem_toFinset.mp (cover used)) exact (run_preserves_outside _ _ _ _ no).trans (by rw [coords q tag];exact spaces q tag) rw [actual] exact Ordinary420Terminal.basis d v s p3 p4 row zeros frame end ECDSAAdd.Entrant.StairPacket.OrdinaryChainG end -- ==== end window405 Main exit pieces ==== section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainG open Arithmetic IntegerPacket MappedCompressed Secp256k1 WideReference SkywalkRails Partial StockWindowTicket StockWindowW7 set_option maxRecDepth 30000 set_option maxHeartbeats 3500000 attribute [local irreducible] run /-- The generic hand-off at block 21 is the exit-405 cut (build-chain's (at 375) `exitBridge405`). -/ theorem exitCut420 (d:Bool) (x:Nat) (raw s:State) (g sg pg ps:Bool) (pre:AtJ ⟨25,by decide⟩ d x p raw s g sg pg ps) : PackedCut Portal420Flag7.loPairs Portal420Flag7.hiPairs 435 1618 1616 1617 (flagNeg 420 x p sg) (decide (farAt 39 420 x p)) (decide (farAt 39 420 x p ∧ 2^39≤(unsigned 420 x p).u)) (pullState (OB5.sig 419) raw) (eraseSites ParkEndpoint4207.src s) := by obtain ⟨bl,bu,bg,bn,bf,bu',bp,-,-,-⟩:=StockWindowW7.exitBridge420 have cut:=pre.cut rw [bl,bu,bg,bn,bf,bu',bp] at cut have e19:start (⟨25,by decide⟩:Fin 26)=420:=rfl have sb:Shadow7.sbP 420=39:=by decide have pl:EnterJ7.pull ⟨25,by decide⟩=OB5.sig 419:=rfl simp only [e19,sb,pl] at cut exact cut /-- The exit frame at 420 from the generic hand-off (build-chain's (at 375) `exitStep420`, its `LastAt` part). -/ theorem exitLast420 (d:Bool) (x:Nat) (good:Bounds x p) (raw s:State) (g sg pg ps:Bool) (pre:AtJ ⟨25,by decide⟩ d x p raw s g sg pg ps) (m:List Bool) : LastAt ArchiveBoundary4207.codePorts ⟨24,by decide⟩ d x p (run (NativePack4207.lastWindow d) m s) := by have h:=StockWindowW7.exitStep420 d x good s m ⟨⟨25,by decide⟩,rfl,raw,g,sg,pg,ps,pre⟩ have e420:start (⟨24,by decide⟩:Fin 26)+15=420:=rfl rw [e420,(StockWindowW7.exitProg420 d).1] at h exact h.2.1 end ECDSAAdd.Entrant.StairPacket.OrdinaryChainG end -- ===== Part 6: generic over the window's length (blocks 4..J, exit e = 120+15n) ===== section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainG open Arithmetic MappedCompressed IntegerPacket WideReference SkywalkRails Partial ArchivePortAction ArchiveStockRows open StockWindowTicket WindowFold WindowChain Secp256k1 ArchiveHistoryCompare StockWindowW7 set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false set_option linter.unusedSimpArgs false attribute [local irreducible] run measurementCount Shadow7.body /-- build-chain's `EndpointSpec` for interior blocks `I..J` (`EndpointSpec = EndpointBetween 4 12`). -/ abbrev EndpointBetween (I J : Nat) : Prop := ∀ (j k : Fin 26), k.val=j.val+1 → I≤j.val → j.val≤J → ∀ (d:Bool) (x p:Nat) (good:Bounds x p) (raw s:State) (m n:List Bool) (domain:Domain (start j) x p raw) (G S:Bool) (cut:PackedCut (EnterJ7.lowerPairs j) (EnterJ7.upperPairs j) (EnterJ7.gate j) (EnterJ7.flagN j) (EnterJ7.flagF j) (EnterJ7.flagU j) (PortalValues.negative S (unsigned (start j) x p).u) (decide (Shadow.far (Shadow7.sbP (start j)) 15 (unsigned (start j) x p))) (decide (Shadow.far (Shadow7.sbP (start j)) 15 (unsigned (start j) x p) ∧ 2^(Shadow7.sbP (start j))≤(unsigned (start j) x p).u)) (pullState (EnterJ7.pull j) raw) (eraseSites (EnterJ7.pending j) s)) (input:SkywalkIntegerInput (EnterJ7.lay j) (encode G S (unsigned (start j) x p).u (unsigned (start j) x p).v).a (encode G S (unsigned (start j) x p).u (unsigned (start j) x p).v).b G raw.basis) (scratch:ScratchAt j d m s) (pg ps cross:Bool) (prior:PastFacts (NativeJ7.prev j) (ArchiveJ7.rawPorts (NativeJ7.prev j)) (Shadow7.sbP (start (NativeJ7.prev j))) (unsigned (start (NativeJ7.prev j)) x p) pg ps cross s), PackedCut (EnterJ7.lowerPairs k) (EnterJ7.upperPairs k) (EnterJ7.gate k) (EnterJ7.flagN k) (EnterJ7.flagF k) (EnterJ7.flagU k) (PortalValues.negative (LeaveJ7.Admission.flags (unsigned (start j) x p) G S).2 (unsigned (start k) x p).u) (decide (Shadow.far (Shadow7.sbP (start k)) 15 (unsigned (start k) x p))) (decide (Shadow.far (Shadow7.sbP (start k)) 15 (unsigned (start k) x p) ∧ 2^(Shadow7.sbP (start k))≤(unsigned (start k) x p).u)) (pullState (EnterJ7.pull k) (endRaw (start j) raw (run (NativeJ7.nextWindow j d) m s))) (eraseSites (EnterJ7.pending k) (run (Shadow7.leaveP j) n (run (NativeJ7.nextWindow j d) m s))) ∧ PastFacts j (ArchiveJ7.rawPorts j) (Shadow7.sbP (start j)) (unsigned (start j) x p) G S (HighBankSum.crossBit (LeaveJ7.TrueMiddle.d j (unsigned (start j) x p))) (run (Shadow7.leaveP j) n (run (NativeJ7.nextWindow j d) m s)) /-- dadon's `pinned{s}` for block `k ≤ J`. -/ theorem pinnedG (I J:Nat) (hI2:1≤I) (hJ:J≤24) (L1:EndpointBetween I J) (L2:ScratchSpec) (k k1:Fin 26) (hk:k1.val=k.val+1) (hIk:I≤k.val) (hkJ:k.val≤J) (d:Bool) (x:Nat) (good:Bounds x p) (raw s:State) (g sg pg ps:Bool) (m:List Bool) (pre:AtJ k d x p raw s g sg pg ps) : ∃a b c e,AtJ k1 d x p (endRaw (start k) raw (run (NativeJ7.nextWindow k d) m s)) (run (Shadow7.leaveP k) (m.drop (measurementCount (NativeJ7.nextWindow k d))) (run (NativeJ7.nextWindow k d) m s)) a b c e := by let v:=run (NativeJ7.nextWindow k d) m s let n:=m.drop (measurementCount (NativeJ7.nextWindow k d)) have p1:NativeJ7.prev k1=k:=prev_of k k1 hk have s1:start k1=start k+15:=start_succ k k1 hk let flags:=LeaveJ7.Admission.flags (unsigned (start k) x p) g sg have h2 : 1≤k.val := by omega have h19 : k.val≤24 := by omega have curr:=readInput (start k) x p raw g sg pre.input have scr:=L2 k h2 h19 d x p good raw s g sg pg ps m pre have native:=NativeJ7.from_domain_matched k h2 h19 d x p good raw s m pre.domain g sg pre.cut curr scr pg ps _ pre.facts obtain ⟨cut,facts⟩:=L1 k k1 hk hIk hkJ d x p good raw s m n pre.domain g sg pre.cut curr scr pg ps _ pre.facts have hin:=native.1 have carried:=stepInput_gen_shadow7 (start k) (Shadow7.sbP (start k)) x p (by simp only [StairPacket.start]; omega) (by simp only [StairPacket.start]; omega) good raw v g sg pre.domain pre.input hin.farSmall have canon:=unique_input pre.input (fixed_input _ _ _ (by simp only [StairPacket.start]; omega) good raw pre.domain) refine ⟨flags.1,flags.2,g,sg,⟨?_,?_,cut,?_,?_⟩⟩ · rw [s1]; exact carried.1 · rw [s1]; exact carried.2 · rw [p1]; exact facts · rw [p1]; exact canon /-- `OB5.sig s` and `OB5.sig (s+14)` move a B-side cell of the block's last ten ticks alike (any block). -/ theorem sigNat_same (s r : Nat) (hs : s≤405) (h1 : s≤r+8) (h2 : r+1≤s) : OB5.sigNat (s+14) (1028+r+16)=OB5.sigNat s (1028+r+16) := by unfold OB5.sigNat by_cases a : 1301≤1028+r+16 · rw [if_pos (Or.inl ⟨a,by omega⟩),if_pos (Or.inl ⟨a,by omega⟩)] · rw [if_neg (by rintro (⟨x,_⟩|⟨x,_⟩) <;> omega),if_neg (by rintro (⟨x,_⟩|⟨x,_⟩) <;> omega)] theorem hole_sig (k : Fin 26) (h18 : k.val≤24) (r : Nat) (h1 : start k≤r+8) (h2 : r+1≤start k) : OB5.sig (start k+14) (base (1028+r))=OB5.sig (start k) (base (1028+r)) := by have s0 : start k≤405 := by simp only [StairPacket.start]; omega exact sigNat_same (start k) r s0 h1 h2 theorem hole_four (k : Fin 26) (h1 : 1≤k.val) (h18 : k.val≤24) (r : Nat) (hr : r=start k-8 ∨ r=start k-6 ∨ r=start k-3 ∨ r=start k-1) : OB5.sig (start k) (base (1028+r))∈NativeJ7.fourHoles k := by rw [NativeJ7.fourHoles_eq k h1] have s0 : 45 ≤ start k := by simp only [StairPacket.start]; omega simp only [List.mem_cons,List.not_mem_nil,or_false] rcases hr with rfl|rfl|rfl|rfl · left; congr 1; simp only [base,Wire]; omega · right; left; congr 1; simp only [base,Wire]; omega · right; right; left; congr 1; simp only [base,Wire]; omega · right; right; right; congr 1; simp only [base,Wire]; omega /-- dadon's `ordinary{s}` for block `k ≤ 19`. -/ theorem ordinaryG (f:Fin 26) (hfb:start f=firstBlock) (k:Fin 26) (hfk:f.val omega have mem:base (1028+r)∈oldSites (start k):=by simp only [oldSites,oldStart_interior hne,oldCount_interior hne,List.mem_flatMap,List.mem_range'_1, List.mem_cons,List.not_mem_nil,or_false] exact ⟨r,⟨by omega,by omega⟩,Or.inr rfl⟩ rw [endRaw_inside_gen _ bound _ _ _ mem,hole_sig k h18 r (by omega) (by omega)] exact clear _ (hole_four k (by omega) h18 r hr) /-- dadon's `next240/next255` for any interior block `k` (`I ≤ k ≤ J`) of the window from block `f`. -/ theorem nextG (f:Fin 26) (hfb:start f=firstBlock) (I J:Nat) (hI2:1≤I) (hIf:f.val+1≤I) (hJ:J≤24) (L1:EndpointBetween I J) (L2:ScratchSpec) (d:Bool) (x:Nat) (good:Bounds x p) (initial s:State) (k k1:Fin 26) (hk:k1.val=k.val+1) (hIk:I≤k.val) (hkJ:k.val≤J) (m:List Bool) (h:RefW f k d x initial s) : RefW f k1 d x initial (run (NativeJ7.nextWindow k d++CRTBarrel.leave k) m s) := by obtain ⟨raw,g,sg,pg,ps,pre,old,zeros⟩:=h rw [run_append,run_take,sameAt L2 k (by omega) (by omega) d x p good raw s g sg pg ps m pre] obtain ⟨a,b,c,e,pre'⟩:=pinnedG I J hI2 hJ L1 L2 k k1 hk hIk hkJ d x good raw s g sg pg ps m pre have hfk:f.val simp only [base,Wire] at e' <;> omega · intro w hw obtain ⟨r,r1,r2,rfl⟩:=hole_cell (start f) (k.val-f.val-1) (by omega) w hw right; simp only [base,Wire]; omega · simp only [List.mem_cons,List.not_mem_nil,or_false] at h have g0:∀i,StockWindowGeo.gstart (start f) i=start f-5+5*i:=fun i=>by simp only [StockWindowGeo.gstart] rcases h with rfl|rfl|rfl|rfl · have := holesG f hfb L2 k hfk (by omega) (by omega) d x good raw s g sg pg ps m pre (start k-8) (Or.inl rfl) rw [show 1028+StockWindowGeo.gstart (start f) (2+3*(k.val-f.val-1))+2=1028+(start k-8) by rw [g0]; omega]; exact this · have := holesG f hfb L2 k hfk (by omega) (by omega) d x good raw s g sg pg ps m pre (start k-6) (Or.inr (Or.inl rfl)) rw [show 1028+StockWindowGeo.gstart (start f) (2+3*(k.val-f.val-1))+4=1028+(start k-6) by rw [g0]; omega]; exact this · have := holesG f hfb L2 k hfk (by omega) (by omega) d x good raw s g sg pg ps m pre (start k-3) (Or.inr (Or.inr (Or.inl rfl))) rw [show 1028+StockWindowGeo.gstart (start f) (3+3*(k.val-f.val-1))+2=1028+(start k-3) by rw [g0]; omega]; exact this · have := holesG f hfb L2 k hfk (by omega) (by omega) d x good raw s g sg pg ps m pre (start k-1) (Or.inr (Or.inr (Or.inr rfl))) rw [show 1028+StockWindowGeo.gstart (start f) (3+3*(k.val-f.val-1))+4=1028+(start k-1) by rw [g0]; omega]; exact this /-- The interior fold over blocks `I..J` of the window from block `f`. -/ theorem chainG (f:Fin 26) (hfb:start f=firstBlock) (I J:Nat) (hI2:1≤I) (hIf:f.val+1≤I) (hJ:J≤24) (L1:EndpointBetween I J) (L2:ScratchSpec) (d:Bool) (x:Nat) (good:Bounds x p) (initial:State) : ∀(i:Fin 26) (js:List (Fin 26)),Consec i js → (∀k∈js,I≤k.val ∧ k.val≤J) → ∀(j j':Fin 26),j.val=i.val+1 → j'.val=(lastBlock i js).val+1 → ∀s m,RefW f j d x initial s → RefW f j' d x initial (run (chainF CRTBarrel.params d i js).flatten m s) | i,[],_,_,j,j',hj,hj',s,m,h=>by have e:j'=j:=Fin.ext (by simp only [lastBlock] at hj'; omega) subst e rw [chainF,List.flatten_nil,run_nil_eq] exact h | i,k::js,⟨hk,rest⟩,hb,j,j',hj,hj',s,m,h=>by have e:j=k:=Fin.ext (by omega) subst e have bk:=hb j List.mem_cons_self rw [chainF,List.flatten_append,run_append,next_eq d i j hk] exact chainG f hfb I J hI2 hIf hJ L1 L2 d x good initial j js rest (fun k hk=>hb k (List.mem_cons_of_mem _ hk)) ⟨j.val+1,by omega⟩ j' rfl (by simpa only [lastBlock] using hj') _ _ (nextG f hfb I J hI2 hIf hJ L1 L2 d x good initial s j ⟨j.val+1,by omega⟩ rfl bk.1 bk.2 _ h) /-- The exit's stock-frame bank: the cells of its last ten ticks in the exit frame. -/ def newBankE (e:Nat) : List Wire := (OrdinaryChainW.cells10 (e-10)).map (OB5.sig e) /-- The window's exit at `e` (hand-off block `jx`): the exit pieces agree with the stock exit tick off the last bank, and the last bank's four holes are zero (the exit archive's blank code slots). Ship: `exitShip`. -/ abbrev ExitSpec (e:Nat) (jx:Fin 26) : Prop := ∀ (d:Bool) (x:Nat) (good:Bounds x p) (raw s:State) (g sg pg ps:Bool) (m:List Bool), AtJ jx d x p raw s g sg pg ps → Except (newBankE e) (run (exitF CRTBarrel.params d e).flatten m s) (pullState (OB5.sig e) (run (Rolling1588.encodeAt base d (e-15)) [] (run (span e 1) [] raw))) ∧ ∀ r, (r=e-8 ∨ r=e-6 ∨ r=e-3 ∨ r=e-1) → (run (exitF CRTBarrel.params d e).flatten m s).basis (OB5.sig e (base (1028+r)))=false theorem projectG (e:Nat) (he:e≤511) (raw out W:State) (direct:Except (newBankE e) out (pullState (OB5.sig e) W)) : Except (OrdinaryChainW.cells10 (e-10)) (pullState (OB5.sig e) out) W := by intro q absent have free:OB5.sig e q∉newBankE e:=by intro hit obtain ⟨w,hw,ew⟩:=List.mem_map.mp hit have := OB5.sig_injective e he ew exact absent (this ▸ hw) have := direct _ free simpa only [pullState,OB5.sig_invol e he] using this theorem old_hole_G (e:Nat) (he:e+1≤512) (d:Bool) (raw out:State) (r:Nat) (r2:r+16≤e) (direct:Except (newBankE e) out (pullState (OB5.sig e) (run (Rolling1588.encodeAt base d (e-15)) [] (run (span e 1) [] raw)))) (clear:raw.basis (base (1028+r))=false) : out.basis (OB5.sig e (base (1028+r)))=false := by have notNew:OB5.sig e (base (1028+r))∉newBankE e:=by intro hit obtain ⟨w,hw,ew⟩:=List.mem_map.mp hit have ew' := OB5.sig_injective e (by omega) ew subst ew' simp only [OrdinaryChainW.cells10,List.mem_flatMap,List.mem_range'_1,List.mem_cons,List.not_mem_nil, or_false] at hw obtain ⟨r',⟨a,b⟩,e1|e1⟩:=hw <;> simp only [base,Wire] at e1 <;> omega have eq:=direct _ notNew change out.basis _=(run (Rolling1588.encodeAt base d (e-15)) [] (run (span e 1) [] raw)).basis (OB5.sig e (OB5.sig e (base (1028+r)))) at eq rw [OB5.sig_invol e (by omega)] at eq have enc:base (1028+r)∉wires (Rolling1588.encodeAt base d (e-15)):=by intro used obtain ⟨r',a,b,e'|e'⟩:=OrdinaryChainW.encode_cells d (e-15) _ used <;> simp only [base,Wire] at e' <;> omega have tick:base (1028+r)∉wires (span e 1):=pastOffSpan e 1 _ he ⟨r,by omega,Or.inr rfl⟩ rw [eq,run_preserves_outside _ _ _ _ enc,run_preserves_outside _ _ _ _ tick] exact clear /-- dadon's `last270`/`terminal`, generic: window from block `f`, `n` banks, exit `start f+15n` (hand-off `jx`). -/ theorem lastG (f:Fin 26) (n:Nat) (hn:1≤n) (he:start f+15*n+1≤512) (jx:Fin 26) (hjx:jx.val=n+f.val) (X:ExitSpec (start f+15*n) jx) (d:Bool) (x:Nat) (good:Bounds x p) (initial s:State) (m:List Bool) (h:RefW f jx d x initial s) : ∀q∉StockWindowGeo.archives (start f) n,(run (exitF CRTBarrel.params d (start f+15*n)).flatten m s).basis q= (StockArchiveReferenceW.common (start f) n d initial).basis q := by obtain ⟨raw,g,sg,pg,ps,pre,old,zeros⟩:=h obtain ⟨direct,lastHoles⟩:=X d x good raw s g sg pg ps m pre have sf : 45≤start f := by simp only [StairPacket.start]; omega have e3:jx.val-f.val=n:=by omega have e4:jx.val-f.val-1=n-1:=by omega rw [e3] at old rw [e4] at zeros have all:=OrdinaryChainW.add_last (start f) (by omega) n hn he d raw initial _ old (projectG (start f+15*n) (by omega) raw _ _ direct) apply finishW (start f) n (by omega) hn (by omega) d _ initial all obtain ⟨n',rfl⟩:∃n',n=n'+1:=⟨n-1,by omega⟩ intro w hw rw [holes_succ] at hw rcases List.mem_append.mp hw with h|h · obtain ⟨r,r1,r2,rfl⟩:=hole_cell (start f) n' (by omega) w h exact old_hole_G (start f+15*(n'+1)) he d raw _ r (by omega) direct (zeros _ (by simpa only [show n'+1-1=n' by omega] using h)) · have g0:∀i,StockWindowGeo.gstart (start f) i=start f-5+5*i:=fun i=>by simp only [StockWindowGeo.gstart] simp only [List.mem_cons,List.not_mem_nil,or_false] at h rcases h with rfl|rfl|rfl|rfl · rw [show 1028+StockWindowGeo.gstart (start f) (2+3*n')+2=1028+(start f+15*(n'+1)-8) by rw [g0]; omega] exact lastHoles _ (Or.inl rfl) · rw [show 1028+StockWindowGeo.gstart (start f) (2+3*n')+4=1028+(start f+15*(n'+1)-6) by rw [g0]; omega] exact lastHoles _ (Or.inr (Or.inl rfl)) · rw [show 1028+StockWindowGeo.gstart (start f) (3+3*n')+2=1028+(start f+15*(n'+1)-3) by rw [g0]; omega] exact lastHoles _ (Or.inr (Or.inr (Or.inl rfl))) · rw [show 1028+StockWindowGeo.gstart (start f) (3+3*n')+4=1028+(start f+15*(n'+1)-1) by rw [g0]; omega] exact lastHoles _ (Or.inr (Or.inr (Or.inr rfl))) /-- dadon's `begin225` at the first block `f` (next block `k1`), from the first-form leaves only. -/ theorem beginG (f k1:Fin 26) (hf1:0≤f.val) (hf20:f.val≤24) (hk1:k1.val=f.val+1) (F:FirstSpecF f k1) (FO:FirstOrdinarySpecF f) (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p (start f) raw.basis) : RefW f k1 d x raw (run ((Shadow7.portalP (start f)++NativeFirstJ7.enteredWindow f d)++ CRTBarrel.leave f) m (pullState (OB5.sig (start f-1)) raw)) := by rw [run_append,run_take,firstSameF f k1 (by omega) hf20 hk1 F d x p good raw m _ stage] have sf : 45≤start f ∧ start f≤405 := by simp only [StairPacket.start]; omega let v:=run (Shadow7.portalP (start f)++NativeFirstJ7.enteredWindow f d) m (pullState (OB5.sig (start f-1)) raw) let n:=m.drop (measurementCount (Shadow7.portalP (start f)++NativeFirstJ7.enteredWindow f d)) obtain ⟨g,sg,input,hin,cut,facts⟩:=F d x p good raw m n stage let flags:=LeaveJ7.Admission.flags (unsigned (start f) x p) g sg have dom:=initial (start f) x p (by omega) d raw stage have carried:=stepInput_gen_shadow7 (start f) (Shadow7.sbP (start f)) x p (by omega) (by omega) good raw v g sg dom input hin.farSmall have s1:start k1=start f+15:=by simp only [StairPacket.start]; omega have p1:NativeJ7.prev k1=f:=Fin.ext (by simp only [NativeJ7.prev]; omega) refine ⟨endRaw (start f) raw v,flags.1,flags.2,g,sg,⟨?_,?_,?_,?_,?_⟩,?_,?_⟩ · rw [s1]; exact carried.1 · rw [s1]; exact carried.2 · rw [s1]; exact cut · rw [p1]; exact facts · rw [p1]; exact unique_input input (fixed_input (start f) x p (by omega) good raw dom) · rw [show k1.val-f.val=1 by omega] have fo:=FO d x p good raw m stage simp only [OrdinaryChainW.mask,OrdinaryChainW.progW,OrdinaryChainW.newBank,OrdinaryChainW.group, Nat.mul_zero,Nat.add_zero,if_true,List.nil_append,Nat.mul_one] exact fo · rw [show k1.val-f.val-1=0 by omega] intro q hq simp [StockWindowGeo.holes,StockWindowGeo.packed] at hq /-- `OrdinaryChain.wires` for any window over the fold: first block `f` (tick `start f`), interior blocks `I..J`, `n` banks, exit `start f+15n`. Ship: f = 3, n = 10; 345: f = 3, n = 16; 90..345: f = 1, n = 18; 90..360: f = 1, n = 19. -/ theorem wiresFold (f k1:Fin 26) (hk1:k1.val=f.val+1) (hfb:start f=firstBlock) (I J:Nat) (hI2:1≤I) (hIf:f.val+1≤I) (hJ:J≤24) (L1:EndpointBetween I J) (L2:ScratchSpec) (F:FirstSpecF f k1) (FO:FirstOrdinarySpecF f) (js:List (Fin 26)) (consec:Consec f js) (hb:∀k∈js,I≤k.val ∧ k.val≤J) (n:Nat) (hn:1≤n) (he:start f+15*n+1≤512) (hl:(lastBlock f js).val+1=n+f.val) (jx:Fin 26) (hjx:jx.val=n+f.val) (X:ExitSpec (start f+15*n) jx) (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p (start f) raw.basis) : ∀q∉StockWindowGeo.archives (start f) n, (run (forwardW CRTBarrel.params d f js) m (pullState (OB5.sig (start f-1)) raw)).basis q= (StockArchiveReferenceW.common (start f) n d raw).basis q := by have et:exitTick f js=start f+15*n:=by simp only [exitTick,lastStart_eq,StairPacket.start]; omega have sp:forwardW CRTBarrel.params d f js= (((CRTBarrel.params.portal (start f) :: firstF CRTBarrel.params d f).flatten++ (chainF CRTBarrel.params d f js).flatten)++ (exitF CRTBarrel.params d (start f+15*n)).flatten):=by rw [forwardW,forwardL,et] simp only [List.flatten_cons,List.flatten_append,List.append_assoc] have beg:∀k,RefW f k1 d x raw (run ((CRTBarrel.params.portal (start f) :: firstF CRTBarrel.params d f).flatten) k (pullState (OB5.sig (start f-1)) raw)):=by intro k rw [first_eqF d f] have first_index : f.val = 0 := by have e : 45 + 15*f.val = 45 + 15*WindowParams.first.val := hfb have first_val : WindowParams.first.val=0:=rfl omega exact beginG f k1 (by omega) (by omega) hk1 F FO d x good raw k stage rw [sp,run_append,run_append] exact lastG f n hn he jx hjx X d x good raw _ _ (chainG f hfb I J hI2 hIf hJ L1 L2 d x good raw f js consec hb k1 jx hk1 (by omega) _ _ (beg _)) /-- Blocks of the 90..390 window (`WindowParams.rest = 2..21`, SA's `WindowCovered.rest_eq`). -/ theorem mem_rest21 {k : Fin 26} (h : k ∈ WindowParams.rest) : 2 ≤ k.val ∧ k.val ≤ 24 := by simp only [WindowParams.rest,List.mem_filter,Bool.and_eq_true,decide_eq_true_eq] at h omega /-- window390 (from build-chain's (at 360) main360): the exit at 405 (`resultW420` + the exit's blank holes), as `exitShip` at 270. -/ theorem exit420 : ExitSpec 420 ⟨25,by decide⟩ := by intro d x good raw s g sg pg ps m pre rw [(StockWindowW7.exitProg420 d).1] have lastF:=exitLast420 d x good raw s g sg pg ps pre m have direct:=resultW420 d x good raw s g sg m pre.domain pre.input (exitCut420 d x raw s g sg pg ps pre) lastF have nb:Ordinary420Terminal.newBank=newBankE 420:=by decide have one:span 420 1=EndTick4207.canonical:=by simp [span,EndTick4207.canonical] refine ⟨?_,?_⟩ · rw [←nb,one,show 420-15=405 from rfl]; exact direct · obtain ⟨row,_,_,frame⟩:=lastF have cleared:=NativePack4207.cleared_holes d row _ frame intro r hr rcases hr with rfl|rfl|rfl|rfl <;> exact cleared _ (by decide) theorem wires405 (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) : ∀q∉StockWindowGeo.archives 45 25,(run (CRTWindow.forwardCut d) m (pullState (OB5.sig 44) raw)).basis q= (StockArchiveReferenceW.common 45 25 d raw).basis q := by have h := wiresFold WindowParams.first ⟨1,by decide⟩ rfl rfl 1 24 (by decide) (by decide) (by decide) leaves22.endpoint leaves22.scratch (first_ship leaves22.first) (firstOrdinary_ship firstOrdinary) WindowParams7.rest7 WindowParams7.consec7 (fun k hk=>WindowParams7.mem_rest22 hk) 25 (by decide) (by decide) (by rw [WindowParams7.lastBlock_405]; rfl) ⟨25,by decide⟩ rfl exit420 d x good raw m stage -- restate the conclusion in the statement's syntax, so the kernel never unifies through the window program have e1 : start WindowParams.first = 45 := rfl have e2 : (45:Nat) - 1 = 44 := rfl rw [e1, e2, ← CRTWindow.run_cut] at h exact h end ECDSAAdd.Entrant.StairPacket.OrdinaryChainG end section namespace ECDSAAdd.Entrant.StairPacket.OrdinaryChainG open Arithmetic MappedCompressed WideReference Secp256k1 StockWindowW7 /-- `OrdinaryChain.wires` of the ship (window 120..255, exit 270). -/ theorem wiresShip (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) : ∀q∉StockWindowGeo.archives 45 25,(run (CRTWindow.forwardCut d) m (pullState (OB5.sig 44) raw)).basis q= (StockArchiveReferenceW.common 45 25 d raw).basis q := wires405 d x good raw m stage end ECDSAAdd.Entrant.StairPacket.OrdinaryChainG end -- ==== end build-main2 OrdW ==== -- ==== build-main2: the ship's stock comparison API (window 90..390, exit 405, 21 banks) ==== -- dadon's 3-bank names (StockArchiveReference.common, StockStrongChain.result, StockArchiveBanks.*, -- StockRowVector.rows/binding, StockBaseline.comparison) re-opened as instances of the generic W sections. section namespace ECDSAAdd.Entrant.StairPacket.StockWindowChainP open Arithmetic MappedCompressed IntegerPacket WideReference SkywalkRails Partial ArchivePortAction ArchiveStockRows open StockWindowTicket WindowFold WindowChain Secp256k1 StockCanonicalRow StockWindowW7 StockStrongChain set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false attribute [local irreducible] run measurementCount key select WideReference.canonical /-- window390: the exit archive's code ports at 405 (first 16 = `cellsRestoreP 405`). -/ def ExitPorts420 : Ports := ArchiveBoundary4207.codePorts /-- window390: the exit at 420 (its step to the last frame and the keys it keeps). -/ theorem exitLeaves420 : ExitLeaves ⟨24,by decide⟩ ExitPorts420 := StockWindowW7.exitLeaves420 /-- window390 (from build-chain's (at 360) main360): dadon's `finalBank` at 420 (the exit archive keeps block 21's key; `finalS` at 270). -/ theorem finalKey420 : ∀ (d:Bool) (x:Nat) (good:Bounds x p) (s:State) (m:List Bool), ReadyW d x p 420 s → SavedKey (value x p 405 (Shadow7.sbP 405) (StockRowVectorW.crossW ⟨24,by decide⟩)) ExitPorts420 d (run (exitF CRTBarrel.params d 420).flatten m s) := by intro d x good s m h obtain ⟨k,ek,raw,g,sg,pg,ps,pre⟩:=h have k19:k=⟨25,by decide⟩:=Fin.ext (by have := ek; simp only [StairPacket.start] at this; show k.val=25; omega) subst k19 rw [(StockWindowW7.exitProg420 d).1] have cut:=OrdinaryChainG.exitCut420 d x raw s g sg pg ps pre obtain ⟨-,-,-,-,-,-,-,r20,r21,r22⟩:=StockWindowW7.exitBridge420 let z:=unsigned 420 x p have short:Shadow7.SmallIfFar 39 15 z:=(Shadow7.Envelope.inputs x p 420 (lt_trans good.small good.cap) good.cap (by decide)).1 have old:=LeaveJ7.Admission.actualNumbers ⟨24,by decide⟩ (by decide) (by decide) x p good have eq:farAt 39 420 x p=(2*2^54≤z.u+z.v):=by apply propext;unfold farAt Shadow.far Shadow.high Shadow.limb;exact Nat.le_div_iff_mul_le (by positivity) have facts:=pre.facts have mode:s.basis 1619=decide (Shadow.far 46 15 (unsigned 405 x p)):=by rw [←r20]; exact facts.far have side:s.basis 1620=(decide (Shadow.far 46 15 (unsigned 405 x p)) && StairArchiveTrace.afterFlags (decide ((unsigned 405 x p).v<(unsigned 405 x p).u)) ((Shadow7.physicalCells ArchiveBoundary4207.sourceIdx s).take 5)):=by rw [←r21]; simpa only [Shadow7.physicalCells_eq] using facts.suffix have cross:s.basis 1621=(decide (Shadow.far 46 15 (unsigned 405 x p)) && HighBankSum.crossBit (LeaveJ7.TrueMiddle.d ⟨24,by decide⟩ (unsigned 405 x p))):=by rw [←r22]; exact facts.crossed have last:=NativePack4207.selected_from_domain d x good.nonzero good.small raw s m pre.domain z short g sg (readInput 420 x p raw g sg pre.input) (by simpa only [eq] using cut) (unsigned 405 x p) pg ps _ old.odd old.farSmall (by simpa only [Shadow7.physicalCells_eq] using facts.records) mode side cross have canon:signedAt 405 x p pg ps=WideReference.canonical 405 x p:=pre.pastCanonical unfold signedAt at canon have cert:=last.2.1 dsimp only at cert rw [canon] at cert have sbq:Shadow7.sbP 405=46:=by decide rw [sbq] exact ⟨cert.1,cert.2.1,kept_frame _ _ _ _ cert.2.2⟩ theorem mem21 {k : Fin 26} (h : k ∈ WindowParams.rest) : 2 ≤ k.val ∧ k.val ≤ (⟨21,by decide⟩:Fin 26).val := by simp only [WindowParams.rest,List.mem_filter,Bool.and_eq_true,decide_eq_true_eq] at h show 2 ≤ k.val ∧ k.val ≤ 21 omega theorem exitT420 : exitTick WindowParams.first WindowParams7.rest7=start ⟨24,by decide⟩+15 := by rw [WindowParams7.rest7_eq]; rfl /-- `StockWindowChain.result` of the 90..390 window (Final = FinalW 1 21 at 405), from build-chain's `checkedG`. -/ theorem result (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) : let start:=pullState (OB5.sig 44) raw let out:=run (CRTWindow.forwardCut d) m start out.phase=raw.phase ∧ FinalW ⟨0,by decide⟩ ⟨24,by decide⟩ ExitPorts420 d x p out ∧ ∀n,run (CRTWindow.reverseCut d) n out=start := by have law:=checkedG ⟨24,by decide⟩ (by decide) (by decide) ExitPorts420 WindowParams7.rest7 WindowParams7.consec7 (fun k hk=>WindowParams7.mem_rest22 hk) exitT420 leaves22 exitLeaves420 d x good have law := law (pullState (OB5.sig 44) raw) m ⟨raw,stage,rfl⟩ rw [←CRTWindow.run_cut,←CRTWindow.run_cut_rev] at law exact law /-- Block `i`'s saved key (dadon's `SavedKey (value x p s b cross{s}) codePorts{s+15}`), for every block. -/ def KeyS (d:Bool) (x p:Nat) (i:Fin 26) (s:State) : Prop := SavedKey (value x p (start i) (Shadow7.sbP (start i)) (StockRowVectorW.crossW i)) (ArchiveJ7.codePorts i) d s def KeyLast (d:Bool) (x p:Nat) (s:State) : Prop := SavedKey (value x p 405 (Shadow7.sbP 405) (StockRowVectorW.crossW ⟨24,by decide⟩)) ExitPorts420 d s def LastS (d:Bool) (x p:Nat) (s:State) : Prop := LastAt ExitPorts420 ⟨24,by decide⟩ d x p s ∧ KeyLast d x p s /-- dadon's `selected{s}` receipt for any interior block `k ≤ 22` (saves block `i = k-1`'s key). -/ theorem receiptS (d:Bool) (x p:Nat) (good:Bounds x p) (i k:Fin 26) (hk:k.val=i.val+1) (h2:1≤k.val) (h18:k.val≤24) : ∀ s m, ReadyW d x p (start k) s → KeyS d x p i (run (nextF CRTBarrel.params d i k).flatten m s) := by intro s m h obtain ⟨k1',e0,raw,g,sg,pg,ps,pre⟩:=h have same0:k1'=k:=Fin.ext (by have := e0; simp only [StairPacket.start] at this; omega) rw [same0] at pre have pk:=prev_of i k hk rw [next_eq d i k hk,←pk] simp only [run_append,run_take] have nums:=LeaveJ7.Admission.actualNumbers k (by omega) (by omega) x p good have old:=LeaveJ7.Admission.actualNumbers (NativeJ7.prev k) (by simp only [NativeJ7.prev]; omega) (by simp only [NativeJ7.prev]; omega) x p good have hist:=pulled_history k rfl pre.domain have curr:=readInput (start k) x p raw g sg pre.input have scr:=leaves22.scratch k (by omega) (by omega) d x p good raw s g sg pg ps m pre have cert:=NativeJ7.selected_receipt k (by omega) (by omega) d raw s m (unsigned (start k) x p) g sg nums.odd nums.farSmall pre.cut curr hist scr (unsigned (start (NativeJ7.prev k)) x p) pg ps _ old.odd old.farSmall pre.facts have canon:=pre.pastCanonical unfold signedAt at canon dsimp only at cert rw [canon] at cert exact ⟨cert.1,cert.2.1,ArchiveWindowPreserve.keep cert.2.2 (fun q hq=>leaves22.keepLeave k (by omega) h18 q hq _ _)⟩ theorem keyS_eq (x p b:Nat) (hb:0+b<26) : StockRowVectorW.keys ⟨0,by decide⟩ x p b=value x p (start ⟨0+b,hb⟩) (Shadow7.sbP (start ⟨0+b,hb⟩)) (StockRowVectorW.crossW ⟨0+b,hb⟩) := by have e:start (⟨0,by decide⟩:Fin 26)+15*b=start ⟨0+b,hb⟩:=by simp only [StairPacket.start]; omega simp only [StockRowVectorW.keys,dif_pos hb] rw [e] /-- The window's strong chain with the 22 saved keys (window_strong instance; dadon's `StockStrongChain.result`). -/ theorem strong (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) : let start0:=pullState (OB5.sig 44) raw let out:=run (CRTWindow.forwardCut d) m start0 out.phase=raw.phase ∧ StockRowVectorW.final ⟨0,by decide⟩ ⟨24,by decide⟩ ExitPorts420 d x p out ∧ ∀n,run (CRTWindow.reverseCut d) n out=start0 := by have bl:blockOf (exitTick WindowParams.first WindowParams7.rest7)=25:=by rw [exitT420]; rfl have lastC:Checked (exitF CRTBarrel.params d (exitTick WindowParams.first WindowParams7.rest7)).flatten (exitR CRTBarrel.params d (exitTick WindowParams.first WindowParams7.rest7)).flatten (ReadyW d x p (exitTick WindowParams.first WindowParams7.rest7)) (LastS d x p):=by rw [exitT420] intro s n h have e:=exitLeaves420.step d x good s n h exact ⟨e.1,⟨e.2.1,finalKey420 d x good s n h⟩,e.2.2⟩ have strong:=window_strong CRTBarrel.params d (ReadyW d x p) (KeyS d x p) (BeforeW d x p) (LastS d x p) WindowParams.first WindowParams7.rest7 WindowParams7.consec7 (firstStepG 24 leaves22 d x p good) (fun i k hm hk=>interiorG 24 (by decide) leaves22 d x p good i k hk (WindowParams7.mem_rest22 hm).1 (WindowParams7.mem_rest22 hm).2) (fun i k hm hk=>receiptS d x p good i k hk (by have h:1 ≤ k.val:=(WindowParams7.mem_rest22 hm).1; omega) (by have h:k.val ≤ 24:=(WindowParams7.mem_rest22 hm).2; omega)) (fun i k hm hk s n _ i' h1 h2 key=>by obtain ⟨rr,c,kept⟩:=key have f3:WindowParams.first.val=0:=rfl exact ⟨rr,c,ArchiveWindowPreserve.keep kept (fun q hq=>leaves22.keepOlder i k i' hk (by omega) (by omega) (by have h:k.val ≤ 24:=(WindowParams7.mem_rest22 hm).2; exact h) d q hq s n)⟩) lastC (by intro s n _ i h1 h2 key rw [bl] at h2 revert key rw [exitT420] intro key obtain ⟨r,c,kept⟩:=key exact ⟨r,c,ArchiveWindowPreserve.keep kept (fun q hq=>exitLeaves420.keep i h1 (by show i.val < 24; omega) d q hq s n)⟩) rw [CRTWindow.run_cut,CRTWindow.run_cut_rev] intro start0 out have hout:out=run (WindowFold.forwardW CRTBarrel.params d WindowParams.first WindowParams7.rest7) m start0:= rfl rw [hout] obtain ⟨ph,⟨⟨_,lastKey⟩,saved⟩,undo⟩:=strong start0 m ⟨raw,stage,rfl⟩ refine ⟨ph,?_,undo⟩ intro b hb change 0+b ≤ 24 at hb have lt:0+b<26:=by omega rw [keyS_eq x p b lt] unfold ArchiveStockRows.bankPorts by_cases h:(⟨0,by decide⟩:Fin 26).val+b<(⟨24,by decide⟩:Fin 26).val · rw [dif_pos h] change 0+b < 24 at h obtain ⟨bound,encoded,kept⟩ := saved ⟨0+b,lt⟩ (by show 0 ≤ 0+b; omega) (by rw [bl]; show 0+b+2 ≤ 25; omega) exact ⟨bound,encoded,ArchiveJ7.kept_stock _ _ _ _ kept⟩ · rw [dif_neg h] change ¬(0+b < 24) at h have e:(⟨0+b,lt⟩:Fin 26)=⟨24,by decide⟩:=Fin.ext (by show 0+b=24; omega) rw [e] have s20:start (⟨24,by decide⟩:Fin 26)=405:=rfl rw [s20] exact lastKey end ECDSAAdd.Entrant.StairPacket.StockWindowChainP end section namespace ECDSAAdd.Entrant.StairPacket.StockArchiveBanks open ECDSAAdd.Entrant.StairPacket.Partial theorem exitCells : ∀j:Fin 16,StockWindowChainP.ExitPorts420 ⟨j.val,by omega⟩= (Partial.cellsRestoreP (start ⟨24, by decide⟩+15)).getD j 0 := by decide +kernel end ECDSAAdd.Entrant.StairPacket.StockArchiveBanks end -- ==== begin Shadow7Wide20Trans150 ==== section /-! # Transition Block `s = 150 -> 165` (`Shadow7Wide20Trans150`) Proves the complete semantics, frame preservation, exact roundtrip, and certified endpoint handoff for the `s = 150 -> 165` transition leave (`leave150To20` / `leaveInv150To20`), bridging 15-tick `NativeJ7` (`MixedWindow.j7`, tick `150`) directly into 20-tick `EnterJ20` (`k0 = ⟨0, by decide⟩`, tick `165`) and `Archive150.rawPorts`. -/ namespace ECDSAAdd.Entrant.StairPacket.Shadow20.Trans150 open ECDSAAdd.Arithmetic open ECDSAAdd.Arithmetic.MappedCompressed open ECDSAAdd.Entrant.IntegerPacket open ECDSAAdd.Entrant.StairPacket open ECDSAAdd.Entrant.StairPacket.Partial open ECDSAAdd.Entrant.StairPacket.GateMirror open ECDSAAdd.Entrant.StairPacket.PortalAnd open ECDSAAdd.Entrant.StairPacket.RailPair open ECDSAAdd.Entrant.StairPacket.Shadow open ECDSAAdd.Entrant.StairPacket.WideReference open ECDSAAdd.Entrant.StairPacket.Shadow20 open ECDSAAdd.Entrant.StairPacket.Shadow20.LeaveCut20 open SkywalkNat IntegerHigh set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false set_option linter.unusedSimpArgs false /-! ### Section 1: `swap1` / `swap2` Head Bridge (`s = 150`) -/ def swap1 (a b : Wire) (f : BasisState) : BasisState := fun q => f (if q = a then b else if q = b then a else q) def swap2 (f : BasisState) : BasisState := swap1 364 984 (swap1 365 985 f) def swapSt (a b : Wire) (s : State) : State := ⟨s.phase, swap1 a b s.basis⟩ def swap2St (s : State) : State := ⟨s.phase, swap2 s.basis⟩ theorem swap1_symm (a b : Wire) (f : BasisState) : swap1 a b (swap1 a b f) = f := by funext q; unfold swap1 by_cases h1 : q = a · rw [h1]; by_cases h2 : b = a <;> simp [h2] · by_cases h2 : q = b · rw [h2]; simp [h1, Ne.symm (show b ≠ a from h2 ▸ h1)] · simp [h1, h2] theorem swap1_other {a b q : Wire} (h1 : q ≠ a) (h2 : q ≠ b) (f : BasisState) : swap1 a b f q = f q := by simp [swap1, h1, h2] theorem swap1_fst {a b : Wire} (f : BasisState) : swap1 a b f a = f b := by simp [swap1] theorem swap1_snd {a b : Wire} (hne : a ≠ b) (f : BasisState) : swap1 a b f b = f a := by simp [swap1, Ne.symm hne] theorem swap2_other {q : Wire} (h1 : q ≠ 364) (h2 : q ≠ 984) (h3 : q ≠ 365) (h4 : q ≠ 985) (f : BasisState) : swap2 f q = f q := by simp [swap2, swap1, h1, h2, h3, h4] private theorem writeBit_swap1 {a b x : Wire} (h1 : x ≠ a) (h2 : x ≠ b) (f : BasisState) (v : Bool) : writeBit (swap1 a b f) x v = swap1 a b (writeBit f x v) := by funext q; unfold writeBit swap1 Function.update by_cases hqa : q = a · rw [hqa]; simp [h1.symm, h2.symm] · by_cases hqb : q = b · rw [hqb]; by_cases hab : b = a <;> simp [hqa, hqb, hab, h1.symm, h2.symm] · simp [hqa, hqb] private theorem swap1_comm_gate (a b : Wire) (g : Gate) (ha : a ∉ g.wires) (hb : b ∉ g.wires) (s : State) (m : List Bool) : run [front g] m (swapSt a b s) = swapSt a b (run [front g] m s) := by cases g with | x t => simp only [Gate.wires, List.mem_singleton] at ha hb simp only [front, run, swapSt, writeBit_swap1 (Ne.symm ha) (Ne.symm hb), swap1_other (Ne.symm ha) (Ne.symm hb)] | cx c t => simp only [Gate.wires, List.mem_cons, List.not_mem_nil, or_false, not_or] at ha hb simp only [front, run, swapSt, writeBit_swap1 (Ne.symm ha.2) (Ne.symm hb.2), swap1_other (Ne.symm ha.1) (Ne.symm hb.1), swap1_other (Ne.symm ha.2) (Ne.symm hb.2)] | ccx c1 c2 t => simp only [Gate.wires, List.mem_cons, List.not_mem_nil, or_false, not_or] at ha hb simp only [front, run, swapSt, writeBit_swap1 (Ne.symm ha.2.2) (Ne.symm hb.2.2), swap1_other (Ne.symm ha.1) (Ne.symm hb.1), swap1_other (Ne.symm ha.2.1) (Ne.symm hb.2.1), swap1_other (Ne.symm ha.2.2) (Ne.symm hb.2.2)] | make c1 c2 t => simp only [Gate.wires, List.mem_cons, List.not_mem_nil, or_false, not_or] at ha hb simp only [front, run, swapSt, writeBit_swap1 (Ne.symm ha.2.2) (Ne.symm hb.2.2), swap1_other (Ne.symm ha.1) (Ne.symm hb.1), swap1_other (Ne.symm ha.2.1) (Ne.symm hb.2.1), swap1_other (Ne.symm ha.2.2) (Ne.symm hb.2.2)] | pop c1 c2 t => simp only [Gate.wires, List.mem_cons, List.not_mem_nil, or_false, not_or] at ha hb simp only [front, erase, run, measureAndCorrect, swapSt] rw [swap1_other (Ne.symm ha.2.2) (Ne.symm hb.2.2), writeBit_swap1 (Ne.symm ha.2.2) (Ne.symm hb.2.2)] cases hhd : m.headD false · simp [ECDSAAdd.correct] · simp only [↓reduceIte, ECDSAAdd.correct] rw [swap1_other (Ne.symm ha.1) (Ne.symm hb.1), swap1_other (Ne.symm ha.2.1) (Ne.symm hb.2.1)] private theorem prepared_append : ∀ (a b : List Gate) (s : State), Prepared s a → Prepared (run (GateMirror.forward a) [] s) b → Prepared s (a ++ b) | [], _, _, _, hb => hb | g :: gs, b, s, ⟨h1, h2⟩, hb => by refine ⟨h1, prepared_append gs b (transition g s) h2 ?_⟩ change Prepared (run ([front g] ++ GateMirror.forward gs) [] s) b at hb simpa only [run_append, run_take, List.drop_nil] using hb private theorem swap1_comm_valid (a b : Wire) : ∀ (gs : List Gate) (s : State), (∀ g ∈ gs, a ∉ g.wires ∧ b ∉ g.wires) → (CRTBarrel.LeaveSplice.Valid s gs → CRTBarrel.LeaveSplice.Valid (swapSt a b s) gs) ∧ (∀ m, run (GateMirror.forward gs) m (swapSt a b s) = swapSt a b (run (GateMirror.forward gs) m s)) | [], s, _ => ⟨fun v => ⟨v.physical, trivial, trivial⟩, fun _ => rfl⟩ | g :: gs, s, hall => by obtain ⟨ha, hb⟩ := hall g List.mem_cons_self have hrest : ∀ g' ∈ gs, a ∉ g'.wires ∧ b ∉ g'.wires := fun g' hg' => hall g' (List.mem_cons_of_mem _ hg') have htr : transition g (swapSt a b s) = swapSt a b (transition g s) := swap1_comm_gate a b g ha hb s [] have ih := swap1_comm_valid a b gs (transition g s) hrest constructor · intro v have hval : ValueOK (swapSt a b s) g := by have hv := v.prepared.1 cases g with | pop c1 c2 t => simp only [Gate.wires, List.mem_cons, List.not_mem_nil, or_false, not_or] at ha hb simp only [ValueOK, swapSt, swap1_other (Ne.symm ha.1) (Ne.symm hb.1), swap1_other (Ne.symm ha.2.1) (Ne.symm hb.2.1), swap1_other (Ne.symm ha.2.2) (Ne.symm hb.2.2)] at hv ⊢ exact hv | _ => trivial have hfr : Fresh (swapSt a b s) g := by have hf := v.ready.1 cases g with | make c1 c2 t => simp only [Gate.wires, List.mem_cons, List.not_mem_nil, or_false, not_or] at ha hb simp only [Fresh, swapSt, swap1_other (Ne.symm ha.2.2) (Ne.symm hb.2.2)] at hf ⊢ exact hf | _ => trivial have vtail := ih.1 ⟨fun x hx => v.physical x (List.mem_cons_of_mem _ hx), v.prepared.2, v.ready.2⟩ exact ⟨v.physical, ⟨hval, htr ▸ vtail.prepared⟩, ⟨hfr, htr ▸ vtail.ready⟩⟩ · intro m change run ([front g] ++ GateMirror.forward gs) m (swapSt a b s) = swapSt a b (run ([front g] ++ GateMirror.forward gs) m s) rw [run_append, run_take, swap1_comm_gate a b g ha hb s, (swap1_comm_valid a b gs (run [front g] m s) hrest).2, run_append, run_take] private theorem pairGM_swap (a s t : Wire) (has : a ≠ s) (hat : a ≠ t) (hst : s ≠ t) (u : State) (v : CRTBarrel.LeaveSplice.Valid u (pairGM false a s t)) : CRTBarrel.LeaveSplice.Valid u (pairGM true a s t) ∧ (∀ m, run (GateMirror.forward (pairGM true a s t)) m u = swapSt s t (run (GateMirror.forward (pairGM false a s t)) [] u)) := by have hval : u.basis t = (u.basis a && (u.basis s ^^ u.basis t)) := by have hp := v.prepared.2.2.1 simp only [pairGM, Bool.false_eq_true, ↓reduceIte, transition, front, run, ValueOK, writeBit, Function.update_of_ne has, Function.update_of_ne hat, Function.update_of_ne hst, Function.update_of_ne hst.symm, Function.update_self] at hp simpa [Bool.xor_assoc, Bool.xor_self, Bool.xor_false, Bool.xor_comm] using hp have hphys : ∀ g ∈ pairGM true a s t, proper g = true := by intro g hg; simp only [pairGM, ↓reduceIte, List.mem_cons, List.not_mem_nil, or_false] at hg rcases hg with rfl | rfl · simp [proper, hst.symm] · simp [proper, has, hat, hst] have hprep : Prepared u (pairGM true a s t) := by simp only [pairGM, ↓reduceIte, Prepared, ValueOK, transition, front, run, writeBit, Function.update_of_ne has, Function.update_of_ne hat, Function.update_of_ne hst, Function.update_of_ne hst.symm, Function.update_self, true_and, and_true] exact hval have hready : Ready u (pairGM true a s t) := by simp only [pairGM, ↓reduceIte, Ready, Fresh, true_and, and_true] have hvt : CRTBarrel.LeaveSplice.Valid u (pairGM true a s t) := ⟨hphys, hprep, hready⟩ refine ⟨hvt, fun m => ?_⟩ rw [hvt.default_run m] apply State.extensionality · simp [pairGM, GateMirror.forward, front, erase, run, measureAndCorrect, ECDSAAdd.correct, swapSt] · funext q simp only [pairGM, ↓reduceIte, Bool.false_eq_true, GateMirror.forward, List.map_cons, List.map_nil, front, erase, run, measureAndCorrect, ECDSAAdd.correct, swapSt, swap1, writeBit] by_cases hqs : q = s · rw [hqs] cases hba : u.basis a <;> cases hbs : u.basis s <;> cases hbt : u.basis t <;> simp [hba, hbs, hbt, Function.update_of_ne hst, Function.update_of_ne hst.symm, Function.update_of_ne has, Function.update_of_ne hat, Function.update_self] at hval ⊢ · by_cases hqt : q = t · rw [hqt] cases hba : u.basis a <;> cases hbs : u.basis s <;> cases hbt : u.basis t <;> simp [hba, hbs, hbt, hst.symm, Function.update_of_ne hst, Function.update_of_ne hst.symm, Function.update_of_ne has, Function.update_of_ne hat, Function.update_self] at hval ⊢ · simp [hqs, hqt, Function.update_of_ne hqs, Function.update_of_ne hqt] private theorem wordGM_flip_one (a : Wire) (r : HighBankJoin.Column) (rs : List HighBankJoin.Column) (hlow : r.low = false) (has : a ≠ r.shadow) (hat : a ≠ r.tube) (hst : r.shadow ≠ r.tube) (htog : ∀ g ∈ toggleG a r.hot, r.shadow ∉ g.wires ∧ r.tube ∉ g.wires) (hrest : ∀ g ∈ wordGM a rs, r.shadow ∉ g.wires ∧ r.tube ∉ g.wires) (u : State) (v : CRTBarrel.LeaveSplice.Valid u (wordGM a (r :: rs))) : let r' : HighBankJoin.Column := ⟨true, r.hot, r.shadow, r.tube⟩ CRTBarrel.LeaveSplice.Valid u (wordGM a (r' :: rs)) ∧ (∀ m, run (GateMirror.forward (wordGM a (r' :: rs))) m u = swapSt r.shadow r.tube (run (GateMirror.forward (wordGM a (r :: rs))) [] u)) := by intro r' have hw0 : wordGM a (r :: rs) = toggleG a r.hot ++ (pairGM false a r.shadow r.tube ++ (wordGM a rs ++ toggleG a r.hot)) := by change toggleG a r.hot ++ (pairGM r.low a r.shadow r.tube ++ (wordGM a rs ++ toggleG a r.hot)) = _ rw [hlow] have hv0 : CRTBarrel.LeaveSplice.Valid u (toggleG a r.hot ++ (pairGM false a r.shadow r.tube ++ (wordGM a rs ++ toggleG a r.hot))) := hw0 ▸ v obtain ⟨v1, v234⟩ := hv0.parts obtain ⟨v2, v34⟩ := v234.parts obtain ⟨v3, v4⟩ := v34.parts let u1 := run (GateMirror.forward (toggleG a r.hot)) [] u have hp := pairGM_swap a r.shadow r.tube has hat hst u1 v2 have hc34 := swap1_comm_valid r.shadow r.tube (wordGM a rs ++ toggleG a r.hot) (run (GateMirror.forward (pairGM false a r.shadow r.tube)) [] u1) (fun g hg => (List.mem_append.mp hg).elim (hrest g) (htog g)) have hv34' : CRTBarrel.LeaveSplice.Valid (run (GateMirror.forward (pairGM true a r.shadow r.tube)) [] u1) (wordGM a rs ++ toggleG a r.hot) := by rw [hp.2 []]; exact hc34.1 v34 have hv234' : CRTBarrel.LeaveSplice.Valid u1 (pairGM true a r.shadow r.tube ++ (wordGM a rs ++ toggleG a r.hot)) := ⟨proper_append hp.1.physical hv34'.physical, prepared_append _ _ _ hp.1.prepared hv34'.prepared, ready_append _ _ _ hp.1.ready hv34'.ready⟩ have hv' : CRTBarrel.LeaveSplice.Valid u (wordGM a (r' :: rs)) := by change CRTBarrel.LeaveSplice.Valid u (toggleG a r.hot ++ (pairGM true a r.shadow r.tube ++ (wordGM a rs ++ toggleG a r.hot))) exact ⟨proper_append v1.physical hv234'.physical, prepared_append _ _ _ v1.prepared hv234'.prepared, ready_append _ _ _ v1.ready hv234'.ready⟩ refine ⟨hv', fun m => ?_⟩ rw [hv'.default_run m, hw0] change run (GateMirror.forward (toggleG a r.hot ++ (pairGM true a r.shadow r.tube ++ (wordGM a rs ++ toggleG a r.hot)))) [] u = swapSt r.shadow r.tube (run (GateMirror.forward (toggleG a r.hot ++ (pairGM false a r.shadow r.tube ++ (wordGM a rs ++ toggleG a r.hot)))) [] u) rw [forward_app (toggleG a r.hot), forward_app (toggleG a r.hot), forward_app (pairGM true a r.shadow r.tube), forward_app (pairGM false a r.shadow r.tube), run_append, run_take, List.drop_nil, run_append, run_take, List.drop_nil, run_append, run_take, List.drop_nil, run_append, run_take, List.drop_nil] change run (GateMirror.forward (wordGM a rs ++ toggleG a r.hot)) [] (run (GateMirror.forward (pairGM true a r.shadow r.tube)) [] u1) = swapSt r.shadow r.tube (run (GateMirror.forward (wordGM a rs ++ toggleG a r.hot)) [] (run (GateMirror.forward (pairGM false a r.shadow r.tube)) [] u1)) rw [hp.2 [], hc34.2 []] private theorem wordGM_step_valid (a : Wire) (r : HighBankJoin.Column) (rs1 rs2 : List HighBankJoin.Column) (w1 w2 : Wire) (htog : ∀ g ∈ toggleG a r.hot, w1 ∉ g.wires ∧ w2 ∉ g.wires) (hpair : ∀ g ∈ pairGM r.low a r.shadow r.tube, w1 ∉ g.wires ∧ w2 ∉ g.wires) (hsub : ∀ st, CRTBarrel.LeaveSplice.Valid st (wordGM a rs1) → CRTBarrel.LeaveSplice.Valid st (wordGM a rs2) ∧ ∀ m, run (GateMirror.forward (wordGM a rs2)) m st = swapSt w1 w2 (run (GateMirror.forward (wordGM a rs1)) [] st)) (u : State) (v : CRTBarrel.LeaveSplice.Valid u (wordGM a (r :: rs1))) : CRTBarrel.LeaveSplice.Valid u (wordGM a (r :: rs2)) ∧ (∀ m, run (GateMirror.forward (wordGM a (r :: rs2))) m u = swapSt w1 w2 (run (GateMirror.forward (wordGM a (r :: rs1))) [] u)) := by change CRTBarrel.LeaveSplice.Valid u (toggleG a r.hot ++ (pairGM r.low a r.shadow r.tube ++ (wordGM a rs1 ++ toggleG a r.hot))) at v obtain ⟨v1, v234⟩ := v.parts obtain ⟨v2, v34⟩ := v234.parts obtain ⟨v3, v4⟩ := v34.parts let u1 := run (GateMirror.forward (toggleG a r.hot)) [] u let u2 := run (GateMirror.forward (pairGM r.low a r.shadow r.tube)) [] u1 obtain ⟨v3', hrun3⟩ := hsub u2 v3 have hc4 := swap1_comm_valid w1 w2 (toggleG a r.hot) (run (GateMirror.forward (wordGM a rs1)) [] u2) htog have hv4' : CRTBarrel.LeaveSplice.Valid (run (GateMirror.forward (wordGM a rs2)) [] u2) (toggleG a r.hot) := by rw [hrun3 []]; exact hc4.1 v4 have hv34' : CRTBarrel.LeaveSplice.Valid u2 (wordGM a rs2 ++ toggleG a r.hot) := ⟨proper_append v3'.physical hv4'.physical, prepared_append _ _ _ v3'.prepared hv4'.prepared, ready_append _ _ _ v3'.ready hv4'.ready⟩ have hv234' : CRTBarrel.LeaveSplice.Valid u1 (pairGM r.low a r.shadow r.tube ++ (wordGM a rs2 ++ toggleG a r.hot)) := ⟨proper_append v2.physical hv34'.physical, prepared_append _ _ _ v2.prepared hv34'.prepared, ready_append _ _ _ v2.ready hv34'.ready⟩ have hv' : CRTBarrel.LeaveSplice.Valid u (wordGM a (r :: rs2)) := ⟨proper_append v1.physical hv234'.physical, prepared_append _ _ _ v1.prepared hv234'.prepared, ready_append _ _ _ v1.ready hv234'.ready⟩ refine ⟨hv', fun m => ?_⟩ rw [hv'.default_run m] change run (GateMirror.forward (toggleG a r.hot ++ (pairGM r.low a r.shadow r.tube ++ (wordGM a rs2 ++ toggleG a r.hot)))) [] u = swapSt w1 w2 (run (GateMirror.forward (toggleG a r.hot ++ (pairGM r.low a r.shadow r.tube ++ (wordGM a rs1 ++ toggleG a r.hot)))) [] u) simp only [forward_app, run_append, run_take, List.drop_nil] rw [hrun3 [], hc4.2 []] private def colsMid150 : List HighBankJoin.Column := (List.range 17).map fun i => ⟨decide (i < 11), if i < 16 then some (tagsP.getD i 0) else none, Shadow7.a0P 150 - 1 + i, Shadow7.bankW 150 i⟩ private theorem wordGM_step_prefix (a w1 w2 : Wire) (pref rs1 rs2 : List HighBankJoin.Column) (hpref : ∀ r ∈ pref, (∀ g ∈ toggleG a r.hot, w1 ∉ g.wires ∧ w2 ∉ g.wires) ∧ (∀ g ∈ pairGM r.low a r.shadow r.tube, w1 ∉ g.wires ∧ w2 ∉ g.wires)) (hsub : ∀ st, CRTBarrel.LeaveSplice.Valid st (wordGM a rs1) → CRTBarrel.LeaveSplice.Valid st (wordGM a rs2) ∧ ∀ m, run (GateMirror.forward (wordGM a rs2)) m st = swapSt w1 w2 (run (GateMirror.forward (wordGM a rs1)) [] st)) (u : State) (v : CRTBarrel.LeaveSplice.Valid u (wordGM a (pref ++ rs1))) : CRTBarrel.LeaveSplice.Valid u (wordGM a (pref ++ rs2)) ∧ (∀ m, run (GateMirror.forward (wordGM a (pref ++ rs2))) m u = swapSt w1 w2 (run (GateMirror.forward (wordGM a (pref ++ rs1))) [] u)) := by induction pref generalizing u with | nil => exact hsub u v | cons r ps ih => have hr := hpref r List.mem_cons_self exact wordGM_step_valid a r (ps ++ rs1) (ps ++ rs2) w1 w2 hr.1 hr.2 (fun st vst => ih (fun r' hr' => hpref r' (List.mem_cons_of_mem _ hr')) st vst) u v private theorem cols150_step1_eq : let p10 := (Shadow7.columnsP 150).take 10 let c10 : HighBankJoin.Column := ⟨false, some (tagsP.getD 10 0), 364, 984⟩ let c10' : HighBankJoin.Column := ⟨true, some (tagsP.getD 10 0), 364, 984⟩ let t10 := (Shadow7.columnsP 150).drop 11 Shadow7.columnsP 150 = p10 ++ c10 :: t10 ∧ colsMid150 = p10 ++ c10' :: t10 := ⟨rfl, rfl⟩ private theorem cols150_step1_away : let p10 := (Shadow7.columnsP 150).take 10 let c10 : HighBankJoin.Column := ⟨false, some (tagsP.getD 10 0), 364, 984⟩ let t10 := (Shadow7.columnsP 150).drop 11 p10.all (fun r => (toggleG 1614 r.hot ++ pairGM r.low 1614 r.shadow r.tube).all (fun g => g.wires.all fun q => decide (q ≠ 364 ∧ q ≠ 984))) = true ∧ (toggleG 1614 c10.hot ++ wordGM 1614 t10).all (fun g => g.wires.all fun q => decide (q ≠ 364 ∧ q ≠ 984)) = true := by decide +kernel private theorem cols150_step2_eq : let p11 := colsMid150.take 11 let c11 : HighBankJoin.Column := ⟨false, some (tagsP.getD 11 0), 365, 985⟩ let c11' : HighBankJoin.Column := ⟨true, some (tagsP.getD 11 0), 365, 985⟩ let t11 := colsMid150.drop 12 colsMid150 = p11 ++ c11 :: t11 ∧ columnsP150 = p11 ++ c11' :: t11 := ⟨rfl, rfl⟩ private theorem cols150_step2_away : let p11 := colsMid150.take 11 let c11 : HighBankJoin.Column := ⟨false, some (tagsP.getD 11 0), 365, 985⟩ let t11 := colsMid150.drop 12 p11.all (fun r => (toggleG 1614 r.hot ++ pairGM r.low 1614 r.shadow r.tube).all (fun g => g.wires.all fun q => decide (q ≠ 365 ∧ q ≠ 985))) = true ∧ (toggleG 1614 c11.hot ++ wordGM 1614 t11).all (fun g => g.wires.all fun q => decide (q ≠ 365 ∧ q ≠ 985)) = true := by decide +kernel private theorem wordGM_swap2 (u : State) (v : CRTBarrel.LeaveSplice.Valid u (wordGM 1614 (Shadow7.columnsP 150))) : CRTBarrel.LeaveSplice.Valid u (wordGM 1614 columnsP150) ∧ (∀ m, run (GateMirror.forward (wordGM 1614 columnsP150)) m u = swap2St (run (GateMirror.forward (wordGM 1614 (Shadow7.columnsP 150))) [] u)) := by obtain ⟨e1a, e1b⟩ := cols150_step1_eq obtain ⟨hp1, hr1⟩ := cols150_step1_away obtain ⟨e2a, e2b⟩ := cols150_step2_eq obtain ⟨hp2, hr2⟩ := cols150_step2_away have mkNot : ∀ (w1 w2 : Wire) (gs : List Gate), gs.all (fun g => g.wires.all fun q => decide (q ≠ w1 ∧ q ≠ w2)) = true → ∀ g ∈ gs, w1 ∉ g.wires ∧ w2 ∉ g.wires := fun w1 w2 gs h g hg => ⟨fun hm => (of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp h g hg) w1 hm)).1 rfl, fun hm => (of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp h g hg) w2 hm)).2 rfl⟩ have h1 : CRTBarrel.LeaveSplice.Valid u (wordGM 1614 colsMid150) ∧ ∀ m, run (GateMirror.forward (wordGM 1614 colsMid150)) m u = swapSt 364 984 (run (GateMirror.forward (wordGM 1614 (Shadow7.columnsP 150))) [] u) := by rw [e1a] at v ⊢; rw [e1b] refine wordGM_step_prefix 1614 364 984 _ _ _ (fun r hr => ?_) (fun st vst => ?_) u v · have h := mkNot 364 984 _ (List.all_eq_true.mp hp1 r hr) exact ⟨fun g hg => h g (List.mem_append_left _ hg), fun g hg => h g (List.mem_append_right _ hg)⟩ · have h := mkNot 364 984 _ hr1 exact wordGM_flip_one 1614 ⟨false, some (tagsP.getD 10 0), 364, 984⟩ _ rfl (by decide) (by decide) (by decide) (fun g hg => h g (List.mem_append_left _ hg)) (fun g hg => h g (List.mem_append_right _ hg)) st vst have h2 : CRTBarrel.LeaveSplice.Valid u (wordGM 1614 columnsP150) ∧ ∀ m, run (GateMirror.forward (wordGM 1614 columnsP150)) m u = swapSt 365 985 (run (GateMirror.forward (wordGM 1614 colsMid150)) [] u) := by rw [e2a] at h1 ⊢; rw [e2b] refine wordGM_step_prefix 1614 365 985 _ _ _ (fun r hr => ?_) (fun st vst => ?_) u h1.1 · have h := mkNot 365 985 _ (List.all_eq_true.mp hp2 r hr) exact ⟨fun g hg => h g (List.mem_append_left _ hg), fun g hg => h g (List.mem_append_right _ hg)⟩ · have h := mkNot 365 985 _ hr2 exact wordGM_flip_one 1614 ⟨false, some (tagsP.getD 11 0), 365, 985⟩ _ rfl (by decide) (by decide) (by decide) (fun g hg => h g (List.mem_append_left _ hg)) (fun g hg => h g (List.mem_append_right _ hg)) st vst refine ⟨h2.1, fun m => ?_⟩ rw [h2.2 m, h1.2 []] apply State.extensionality · rfl · funext q; unfold swap2St swapSt swap2 swap1 by_cases h1 : q = 364 <;> by_cases h2 : q = 984 <;> by_cases h3 : q = 365 <;> by_cases h4 : q = 985 <;> simp [h1, h2, h3, h4] def afterHead150 : List Gate := Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150 ++ leaveJoinMove150 ++ Shadow7.fix10P 150 (Shadow7.sbP 150) ++ leaveFix11 150 (Shadow7.sbP 150) ++ leaveFix12 150 (Shadow7.sbP 150) ++ Shadow7.lowSign 150 def afterHeadStock150 : List Gate := Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150 ++ Shadow7.leaveJoinMove 150 ++ Shadow7.fix10P 150 (Shadow7.sbP 150) ++ leaveFix11 150 (Shadow7.sbP 150) ++ leaveFix12 150 (Shadow7.sbP 150) ++ Shadow7.lowSign 150 private def fixTail150 : List Gate := Shadow7.fix10P 150 (Shadow7.sbP 150) ++ leaveFix11 150 (Shadow7.sbP 150) ++ leaveFix12 150 (Shadow7.sbP 150) ++ Shadow7.lowSign 150 private theorem fixTail150_away : fixTail150.all (fun g => g.wires.all fun q => decide (q ≠ 364 ∧ q ≠ 984 ∧ q ≠ 365 ∧ q ≠ 985)) = true := by decide +kernel private theorem hsp_move150 : Shadow7.leaveMoveOps 150 = (CRTBarrel.beforeReference 150 ++ Shadow7.leaveBarrel 150) ++ (afterHeadStock150 ++ (Shadow7.lowRest 150 ++ Shadow7.leaveStoreMapped 150 ++ Shadow7.leaveLowClose 150 ++ Shadow7.leaveClose 150)) := by simp only [Shadow7.leaveMoveOps, CRTBarrel.beforeReference, afterHeadStock150, Shadow7.leaveLowStore, Shadow7.lowSign, Shadow7.lowRest, List.append_assoc] private theorem haS_150 : afterHeadStock150 = (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150 ++ keptG (tagsP.getD · 0) (fun i => Shadow7.a0P 150 - 1 + i) 1613 0 8) ++ (wordGM 1614 (Shadow7.columnsP 150) ++ fixTail150) := by simp only [afterHeadStock150, Shadow7.leaveJoinMove, fixTail150, List.append_assoc] private theorem ha150_eq : afterHead150 = (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150 ++ KeptParity.placed 150) ++ (wordGM 1614 columnsP150 ++ fixTail150) := by simp only [afterHead150, leaveJoinMove150, fixTail150, List.append_assoc] private theorem hC_shape_150 : (CRTBarrel.beforeReference 150 ++ Shadow7.leaveBarrel 150) ++ afterHeadStock150 = Shadow7.moveA 150 ++ (rowGates (Shadow7.e0P 150 + 6) (Shadow7.moveRows 150) ++ (Shadow7.moveB 150 ++ (Shadow7.moveKept 150 ++ (wordGM 1614 (Shadow7.columnsP 150) ++ fixTail150)))) := by simp only [CRTBarrel.beforeReference, afterHeadStock150, Shadow7.moveA, Shadow7.moveB, Shadow7.moveKept, Shadow7.leaveJoinMove, Shadow7.leaveFix5Move, fixTail150, List.append_assoc] private theorem hO_shape_150 : Shadow7.leaveHeadOps 150 = Shadow7.moveA 150 ++ (Shadow7.moveMux 150 ++ (Shadow7.moveB 150 ++ (Shadow7.moveDig 150 ++ (wordGM 1614 (Shadow7.columnsP 150) ++ fixTail150)))) := by have e : Shadow7.fix5P 150 (Shadow7.sbP 150) = (Shadow7.fix5P 150 (Shadow7.sbP 150)).take 27 ++ (((Shadow7.fix5P 150 (Shadow7.sbP 150)).drop 27).take 16 ++ (Shadow7.fix5P 150 (Shadow7.sbP 150)).drop 43) := rfl unfold Shadow7.leaveHeadOps Shadow7.moveA Shadow7.moveMux Shadow7.moveB Shadow7.moveDig Shadow7.leaveJoin fixTail150 conv_lhs => rw [e] simp only [List.append_assoc] private theorem hK_shape_150 : Shadow7.moveA 150 ++ (GateMirror.rowGates (Shadow7.e0P 150 + 6) (Shadow7.moveRows 150) ++ Shadow7.moveB 150) = (CRTBarrel.beforeReference 150 ++ Shadow7.leaveBarrel 150) ++ (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150) := by simp only [CRTBarrel.beforeReference, Shadow7.leaveFix5Move, Shadow7.moveA, Shadow7.moveB, List.append_assoc] attribute [local irreducible] run in private theorem before5_150 (s : State) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) : DeadJoin.RawValid s (DeadJoin.before5 150) ∧ run (GateMirror.forward (DeadJoin.before5 150)) [] s = run (GateMirror.forward (CRTBarrel.beforeReference 150)) [] s := by have hi : MixedWindow.j7.val ≤ 24 := by decide have original : CRTBarrel.LeaveSplice.Valid s (DeadJoin.referenceOps (start MixedWindow.j7)) := by change CRTBarrel.LeaveSplice.Valid s (Shadow7.leaveMoveOps (start MixedWindow.j7)) exact CRTBarrel.LeaveSplice.moved_valid (by decide) hi h have raw : DeadJoin.RawValid s (DeadJoin.referenceOps (start MixedWindow.j7)) := ⟨original.physical, original.prepared, original.ready⟩ have rel : FlagLeave.Rel (Shadow7.e0P (start MixedWindow.j7) + 3) (Shadow7.e0P (start MixedWindow.j7) + 4) (Shadow7.e0P (start MixedWindow.j7) + 6) false s := by simp only [FlagLeave.Rel, Bool.false_and, Bool.xor_false] rw [h.far, h.side] cases decide (Shadow.far (Shadow7.sbP (start MixedWindow.j7)) 15 z) <;> cases decide (2 ^ Shadow7.sbP (start MixedWindow.j7) ≤ z.u) <;> rfl have zero6 : s.basis (Shadow7.e0P (start MixedWindow.j7) + 6) = false := h.zero _ (by simp [LeaveJ7.watched]) obtain ⟨v0, _, beforeEq⟩ := DeadJoin.raw_all_valid MixedWindow.j7 hi s raw (DeadJoin.pair_zero MixedWindow.j7 hi s (DeadJoin.entry_top_zero hi h)) (DeadJoin.admitted_scan_eq hi h) rel have shape0 : DeadJoin.allOps (start MixedWindow.j7) = DeadJoin.beforePre5Cut (start MixedWindow.j7) ++ (DeadJoin.row0Old (start MixedWindow.j7) ++ (DeadJoin.beforePost5 (start MixedWindow.j7) ++ (Shadow7.leaveBarrel (start MixedWindow.j7) ++ DeadJoin.afterAll (start MixedWindow.j7)))) := by rw [DeadJoin.all_split MixedWindow.j7 hi, DeadJoin.beforeAll_split5 MixedWindow.j7 hi] simp only [List.append_assoc] rw [shape0] at v0 have hy6 : (run (GateMirror.forward (DeadJoin.beforePre5Cut (start MixedWindow.j7))) [] s).basis (Shadow7.e0P (start MixedWindow.j7) + 6) = false := (DeadJoin.keeps_of_targets57 _ _ (fun g hg => of_decide_eq_true (List.all_eq_true.mp (DeadJoin.pre5Cut_targets MixedWindow.j7 hi) g hg)) [] s).trans zero6 obtain ⟨hxy, htx, hty⟩ := DeadJoin.row0_distinct57 MixedWindow.j7 hi have eqRow0 : run (GateMirror.forward (DeadJoin.row0New (start MixedWindow.j7))) [] (run (GateMirror.forward (DeadJoin.beforePre5Cut (start MixedWindow.j7))) [] s) = run (GateMirror.forward (DeadJoin.row0Old (start MixedWindow.j7))) [] (run (GateMirror.forward (DeadJoin.beforePre5Cut (start MixedWindow.j7))) [] s) := DeadJoin.swap_make57 _ _ _ _ hxy htx hty hy6 have vRow0 : DeadJoin.RawValid (run (GateMirror.forward (DeadJoin.beforePre5Cut (start MixedWindow.j7))) [] s) (DeadJoin.row0New (start MixedWindow.j7)) := ⟨fun x hx => List.all_eq_true.mp (DeadJoin.row0New_proper MixedWindow.j7 hi) x hx, ⟨trivial, trivial, trivial⟩, ⟨hy6, trivial, trivial⟩⟩ obtain ⟨v5, _⟩ := DeadJoin.raw_swap_mid v0 vRow0 eqRow0 have before5Eq : run (GateMirror.forward (DeadJoin.before5 (start MixedWindow.j7))) [] s = run (GateMirror.forward (DeadJoin.beforeAll (start MixedWindow.j7))) [] s := by rw [DeadJoin.before5, DeadJoin.beforeAll_split5 MixedWindow.j7 hi] simp only [forward_app, run_append, run_take, List.drop_nil, eqRow0] have v5' : DeadJoin.RawValid s (DeadJoin.before5 (start MixedWindow.j7) ++ (Shadow7.leaveBarrel (start MixedWindow.j7) ++ DeadJoin.afterAll (start MixedWindow.j7))) := by simpa only [DeadJoin.before5, List.append_assoc] using v5 have det5 : ∀ m', run (GateMirror.forward (DeadJoin.before5 (start MixedWindow.j7))) m' s = run (GateMirror.forward (DeadJoin.before5 (start MixedWindow.j7))) [] s := fun m' => v5'.parts.1.default_run m' exact ⟨v5'.parts.1, before5Eq.trans beforeEq⟩ attribute [local irreducible] run in theorem before150_state (s : State) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (m : List Bool) : run (GateMirror.forward (CRTBarrel.before 150)) m s = run (GateMirror.forward (CRTBarrel.beforeReference 150)) [] s := by have hi : MixedWindow.j7.val ≤ 24 := by decide obtain ⟨v5, eq5⟩ := before5_150 s z g0 s0 h have small := (LeaveShadowRails.inputRow14 (Shadow7.sbP (start MixedWindow.j7)) z h.farSmall).1 obtain ⟨cFwd, _⟩ := ScanRowGordo.cell_pair MixedWindow.j7 hi s _ _ _ _ h.ready h.fresh small have sp := ScanRowGordo.before5_split MixedWindow.j7 hi have hmcF : measurementCount (GateMirror.forward (ScanRowGordo.firstRows 150 (Shadow7.sbP 150))) = 0 := by decide +kernel have hmcC : measurementCount (GateMirror.forward (ScanRowGordo.cell 150 (Shadow7.sbP 150))) = 0 := rfl rw [show start MixedWindow.j7 = 150 from rfl] at sp cFwd rw [← eq5, ← v5.default_run (m.drop (measurementCount (GateMirror.forward (ScanRowGordo.shortCell 150 (Shadow7.sbP 150)))))] rw [CRTBarrel.before, ScanRowGordo.before5Row, sp, forward_app, forward_app, forward_app, forward_app] simp only [run_append, hmcF, List.take_zero, List.drop_zero, hmcC] rw [cFwd] attribute [local irreducible] run in theorem before150_undo (s : State) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (n : List Bool) : run (inverse (CRTBarrel.before 150)) n (run (GateMirror.forward (CRTBarrel.before 150)) [] s) = s := by have hi : MixedWindow.j7.val ≤ 24 := by decide obtain ⟨v5, _⟩ := before5_150 s z g0 s0 h have small := (LeaveShadowRails.inputRow14 (Shadow7.sbP (start MixedWindow.j7)) z h.farSmall).1 obtain ⟨cFwd, cRev⟩ := ScanRowGordo.cell_pair MixedWindow.j7 hi s _ _ _ _ h.ready h.fresh small have sp := ScanRowGordo.before5_split MixedWindow.j7 hi rw [show start MixedWindow.j7 = 150 from rfl] at sp cFwd cRev rw [sp] at v5 obtain ⟨vF, vR⟩ := v5.parts obtain ⟨_, vT⟩ := vR.parts rw [CRTBarrel.before, ScanRowGordo.before5Row, DeadJoin.inverse_append, DeadJoin.inverse_append, forward_app, forward_app] simp only [run_append, run_take, List.take_nil, List.drop_nil] rw [cFwd [], vT.undo_run [] _, cRev _, vF.undo_run [] _] attribute [local irreducible] run CRTBarrel.barrel in theorem leaveMove150_head_eq (s : State) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) : CRTBarrel.LeaveSplice.Valid (run (GateMirror.forward (CRTBarrel.before 150 ++ Shadow7.leaveBarrel 150)) [] s) afterHead150 ∧ (∀ m, run (GateMirror.forward (CRTBarrel.before 150) ++ CRTBarrel.barrel 150 false ++ GateMirror.forward afterHead150) m s = swap2St (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s)) := by have hb := before150_state s z g0 s0 h have hpreEq : run (GateMirror.forward (CRTBarrel.before 150 ++ Shadow7.leaveBarrel 150)) [] s = run (GateMirror.forward (CRTBarrel.beforeReference 150 ++ Shadow7.leaveBarrel 150)) [] s := by simp only [forward_app, run_append, run_take, List.drop_nil, hb []] rw [hpreEq] have v := CRTBarrel.LeaveSplice.moved_valid (j := MixedWindow.j7) (by decide) (by decide) h rw [show start MixedWindow.j7 = 150 from rfl, hsp_move150] at v obtain ⟨vPre, vRest⟩ := v.parts obtain ⟨vHeadS, _⟩ := vRest.parts rw [haS_150] at vHeadS obtain ⟨vFK, vWT⟩ := vHeadS.parts obtain ⟨vW, vT⟩ := vWT.parts let uPreB := run (GateMirror.forward (CRTBarrel.beforeReference 150 ++ Shadow7.leaveBarrel 150)) [] s let uFK := run (GateMirror.forward (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150 ++ keptG (tagsP.getD · 0) (fun i => Shadow7.a0P 150 - 1 + i) 1613 0 8)) [] uPreB obtain ⟨vW', hrunW⟩ := wordGM_swap2 uFK vW have hFT1 : ∀ g ∈ fixTail150, (364 : Wire) ∉ g.wires ∧ (984 : Wire) ∉ g.wires := fun g hg => ⟨fun hm => (of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp fixTail150_away g hg) 364 hm)).1 rfl, fun hm => (of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp fixTail150_away g hg) 984 hm)).2.1 rfl⟩ have hFT2 : ∀ g ∈ fixTail150, (365 : Wire) ∉ g.wires ∧ (985 : Wire) ∉ g.wires := fun g hg => ⟨fun hm => (of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp fixTail150_away g hg) 365 hm)).2.2.1 rfl, fun hm => (of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp fixTail150_away g hg) 985 hm)).2.2.2 rfl⟩ have hc1 := swap1_comm_valid 365 985 fixTail150 (run (GateMirror.forward (wordGM 1614 (Shadow7.columnsP 150))) [] uFK) hFT2 have hc2 := swap1_comm_valid 364 984 fixTail150 (swapSt 365 985 (run (GateMirror.forward (wordGM 1614 (Shadow7.columnsP 150))) [] uFK)) hFT1 have hvT' : CRTBarrel.LeaveSplice.Valid (run (GateMirror.forward (wordGM 1614 columnsP150)) [] uFK) fixTail150 := by rw [hrunW []]; exact hc2.1 (hc1.1 vT) have hvWT' : CRTBarrel.LeaveSplice.Valid uFK (wordGM 1614 columnsP150 ++ fixTail150) := ⟨proper_append vW'.physical hvT'.physical, prepared_append _ _ _ vW'.prepared hvT'.prepared, ready_append _ _ _ vW'.ready hvT'.ready⟩ have hkp150_rel := h.movedRelation (by decide) (by decide) rw [show start MixedWindow.j7 = 150 from rfl, hK_shape_150] at hkp150_rel have hkp150_pair := KeptParity.placed_pair MixedWindow.j7 (by decide) _ hkp150_rel rw [show start MixedWindow.j7 = 150 from rfl] at hkp150_pair have hmc8 : measurementCount (GateMirror.forward (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150)) = 0 := rfl have hkpState : run (GateMirror.forward ((CRTBarrel.beforeReference 150 ++ Shadow7.leaveBarrel 150) ++ (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150))) [] s = run (GateMirror.forward (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150)) [] uPreB := by simp only [uPreB, forward_app, run_append, run_take, List.drop_nil, List.take_nil] rw [hkpState] at hkp150_pair have hfk_eq : ∀ m', run (GateMirror.forward (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150 ++ KeptParity.placed 150)) m' uPreB = uFK := by intro m' rw [forward_app, run_append, hmc8, List.take_zero, List.drop_zero, hkp150_pair.1] simp only [uFK, Shadow7.moveKept, forward_app, run_append, hmc8, List.take_zero, List.drop_zero, List.take_nil, List.drop_nil] have hvFK_kp : CRTBarrel.LeaveSplice.Valid uPreB (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150 ++ KeptParity.placed 150) := by have hkp_p : Proper (KeptParity.placed 150) := fun g hg => List.all_eq_true.mp (by decide +kernel : (KeptParity.placed 150).all proper = true) g hg have hkp_pl : (KeptParity.placed 150).all plainGate = true := by decide +kernel have hv8 := vFK.parts.1 refine ⟨proper_append hv8.physical hkp_p, prepared_append _ _ _ hv8.prepared (by repeat' constructor), ready_append _ _ _ hv8.ready (ready_plain _ hkp_pl _)⟩ have hvHead150 : CRTBarrel.LeaveSplice.Valid uPreB afterHead150 := by rw [ha150_eq] refine ⟨proper_append hvFK_kp.physical hvWT'.physical, prepared_append _ _ _ hvFK_kp.prepared (by rw [hfk_eq []]; exact hvWT'.prepared), ready_append _ _ _ hvFK_kp.ready (by rw [hfk_eq []]; exact hvWT'.ready)⟩ have hstock_eq : run (GateMirror.forward ((CRTBarrel.beforeReference 150 ++ Shadow7.leaveBarrel 150) ++ afterHeadStock150)) [] s = run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s := by have hhot := h.hot (by decide) (by decide) [] have hdead := h.dead (by decide) (by decide) [] rw [show start MixedWindow.j7 = 150 from rfl] at hhot hdead rw [hC_shape_150, hO_shape_150] have h16 : run (GateMirror.forward (Shadow7.moveA 150 ++ (rowGates (Shadow7.e0P 150 + 6) (Shadow7.moveRows 150) ++ (Shadow7.moveB 150 ++ (Shadow7.moveKept16 150 ++ (wordGM 1614 (Shadow7.columnsP 150) ++ fixTail150)))))) [] s = run (GateMirror.forward (Shadow7.moveA 150 ++ (Shadow7.moveMux 150 ++ (Shadow7.moveB 150 ++ (Shadow7.moveDig 150 ++ (wordGM 1614 (Shadow7.columnsP 150) ++ fixTail150)))))) [] s := by simp only [forward_app] rw [rowGates_forward, Shadow7.mux_forward, Shadow7.dig_forward] exact MoveChain.splice (Shadow7.e0P 150 + 6) (Shadow7.moveRows 150) (GateMirror.forward (Shadow7.moveA 150)) (GateMirror.forward (Shadow7.moveB 150)) (GateMirror.forward (wordGM 1614 (Shadow7.columnsP 150) ++ fixTail150)) (GateMirror.forward (Shadow7.moveKept16 150)) s [] _ (Shadow7.apart_move (by decide) (by decide)) (Shadow7.lone_move 150) (Shadow7.stillB (by decide) (by decide)) (Shadow7.woven_move (by decide) (by decide)) hhot.1 hhot.2 rw [← h16, Shadow7.moveKept16_split] simp only [forward_app, rowGates_forward, List.append_assoc, run_append, run_take, List.drop_nil] have hpre : run (GateMirror.forward (Shadow7.moveB 150)) [] (run (MoveChain.rows (Shadow7.e0P 150 + 6) (Shadow7.moveRows 150)) [] (run (GateMirror.forward (Shadow7.moveA 150)) [] s)) = MoveChain.clrAll (Shadow7.e0P 150 + 6) (Shadow7.moveRows 150) (run (GateMirror.forward (Shadow7.moveA 150 ++ (Shadow7.moveMux 150 ++ Shadow7.moveB 150))) [] s) := by have hp := Shadow7.prefix_rows (by decide) (by decide) s [] _ hhot.1 hhot.2 simp only [forward_app, run_append, run_take, List.drop_nil] at hp have hr : run (GateMirror.forward (Shadow7.moveA 150 ++ (Shadow7.moveMux 150 ++ Shadow7.moveB 150))) [] s = run (GateMirror.forward (Shadow7.moveB 150)) [] (run (GateMirror.forward (Shadow7.moveMux 150)) [] (run (GateMirror.forward (Shadow7.moveA 150)) [] s)) := by simp only [forward_app, run_append, run_take, List.drop_nil] rw [hr]; exact hp rw [hpre] have hti := Shadow7.tail_idle (s := 150) (by decide) (by decide) (run (GateMirror.forward (Shadow7.moveA 150 ++ (Shadow7.moveMux 150 ++ Shadow7.moveB 150))) [] s) [] [] hdead rw [hti] obtain ⟨sameB, _⟩ := CRTBarrel.LeaveCut.barrel_pair MixedWindow.j7 (by decide) (by decide) _ (CRTBarrel.LeaveCut.input (by decide) (by decide) h) rw [show start MixedWindow.j7 = 150 from rfl] at sameB refine ⟨hvHead150, fun m => ?_⟩ simp only [run_append, run_take] rw [hb, sameB] have hpreRun : run (GateMirror.forward (Shadow7.leaveBarrel 150)) [] (run (GateMirror.forward (CRTBarrel.beforeReference 150)) [] s) = uPreB := by simp only [uPreB, forward_app, run_append, run_take, List.drop_nil] rw [hpreRun, hvHead150.default_run, ha150_eq] rw [forward_app (Shadow7.fix8P 150 (Shadow7.sbP 150) ++ Shadow7.glueG3 150 ++ KeptParity.placed 150), run_append, run_take, List.drop_nil, hfk_eq [], forward_app (wordGM 1614 columnsP150), run_append, run_take, List.drop_nil] change run (GateMirror.forward fixTail150) [] (run (GateMirror.forward (wordGM 1614 columnsP150)) [] uFK) = _ rw [hrunW []] change run (GateMirror.forward fixTail150) [] (swapSt 364 984 (swapSt 365 985 (run (GateMirror.forward (wordGM 1614 (Shadow7.columnsP 150))) [] uFK))) = _ rw [hc2.2 [], hc1.2 [], ← hstock_eq, haS_150] simp only [uFK, uPreB, forward_app, run_append, run_take, List.drop_nil] rfl /-! ### Section 2: Tail Forward Semantics (`s = 150 -> 165`) -/ def smallA150 : List Wire := (List.range (lows150 - 1)).map (Shadow7.a0P 150 + ·) def smallM150 : List Wire := (List.range (lows150 - 1)).map (Shadow7.b0P 150 + ·) def smallC150 : List Wire := (List.range (lows150 - 1 - 1)).map (1559 + ·) def borrowG4_150 : Program := [.CX (Shadow7.a0P 150 - 1) 1557, .X 1557, .CCX (Shadow7.b0P 150 - 1) 1557 1558] def releaseMaskP150 : Program := GateMirror.forward [.pop (Shadow7.b0P 150 - 1) 1557 1558, .cx (Shadow7.a0P 150 - 1) 1557, .x 1557] def lowRest150 : List Gate := let L := lows150 - 1 let bs := (List.range L).map (Shadow7.b0P 150 + ·) [.cx (Shadow7.a0P 150 - 1) 1557, .x 1557, .make (Shadow7.b0P 150 - 1) 1557 1558] ++ ((List.range L).map fun i => .make 1556 (Shadow7.a0P 150 + i) (Shadow7.b0P 150 + i)) ++ xsG bs ++ addG bs ((List.range (L - 1)).map (1559 + ·)) 1558 ++ xsG bs ++ [.pop (Shadow7.b0P 150 - 1) 1557 1558, .cx (Shadow7.a0P 150 - 1) 1557, .x 1557] def pendingPairs150 : List (Wire × Wire) := let L := lows150 let H := Shadow7.liveW 150 - L (List.range (H + 1)).map fun k => (if k = 0 then Shadow7.a0P 150 + L - 2 else Shadow7.bankW 150 (L + k - 1), Shadow7.storeW 150 (k + 1)) def clearFlagPairs150 : List (Wire × Wire) := (List.range lows150).map fun k => (Shadow7.b0P 150 - 1 + k, 1559 + k) def low150 : List (Wire × Wire) := (List.range lows150).map fun i => (Shadow7.a0P 150 - 1 + i, Shadow7.b0P 150 - 1 + i) def head150Prog : Program := GateMirror.forward (CRTBarrel.before 150) ++ CRTBarrel.barrel 150 false ++ GateMirror.forward afterHead150 def full150Prog : Program := head150Prog ++ (borrowG4_150 ++ Companion.restore smallA150 smallM150 smallC150 1556 1558) def beforeStore150Prog : Program := full150Prog ++ (releaseMaskP150 ++ GateMirror.forward leaveStoreMapped150) def storeMapped150Prog : Program := beforeStore150Prog ++ GateMirror.forward leaveLowClose150 private theorem lowStore150_parts : GateMirror.forward leaveLowStore150 = GateMirror.forward (Shadow7.lowSign 150) ++ (borrowG4_150 ++ (Companion.restore smallA150 smallM150 smallC150 1556 1558 ++ releaseMaskP150)) := by have hc : GateMirror.forward ((List.range (lows150 - 1)).map fun i => Gate.make 1556 (Shadow7.a0P 150 + i) (Shadow7.b0P 150 + i)) = copyRegister (some 1556) smallA150 smallM150 := by rw [smallA150, smallM150, LeaveJ7.copy_map]; simp only [GateMirror.forward, List.map_map]; rfl simp only [leaveLowStore150, Shadow7.lowSign, forward_app, forward_addG, LeaveJ7.forward_xsG', hc, Companion.restore, HighBankUnit.sub, mappedSub, smallM150, smallC150, releaseMaskP150, borrowG4_150, List.append_assoc] rfl private theorem pending150_fst : pendingPairs150.map Prod.fst = (Shadow7.a0P 150 + lows150 - 2) :: (List.range (Shadow7.liveW 150 - lows150)).map (fun i => Shadow7.bankW 150 (lows150 + i)) := by simp only [pendingPairs150, List.map_map, Function.comp] rw [List.range_succ_eq_map, List.map_cons, List.map_map] simp only [Function.comp, if_pos, Nat.succ_ne_zero, if_false] congr 1 private theorem clearFlag150_fst : clearFlagPairs150.map Prod.fst = (List.range lows150).map (Shadow7.b0P 150 - 1 + ·) := by simp only [clearFlagPairs150, List.map_map]; rfl private theorem storeMapped150_parts : GateMirror.forward leaveStoreMapped150 = latch true none 1557 1558 pendingPairs150 ++ ([.CCX 1556 1557 1558] ++ latch true none 1556 1558 clearFlagPairs150) := by have ch1 : GateMirror.forward (chainG (Shadow7.storeW 150) (fun i => if i = 0 then Shadow7.a0P 150 + lows150 - 2 else Shadow7.bankW 150 (lows150 + i - 1)) [.cx (Shadow7.storeW 150 (Shadow7.liveW 150 - lows150 + 1)) 1557, .x 1557] 0 (Shadow7.liveW 150 - lows150 + 1)) = PortalAnd.chain true none 1557 1558 pendingPairs150 := by rw [LeaveJ7.forward_chainG0, LeaveJ7.storeW_zero7]; rfl have ch2 : GateMirror.forward (chainG (fun i => (1558 + i : Wire)) (fun i => Shadow7.b0P 150 - 1 + i) [.cx (1558 + lows150) 1556, .x 1556] 0 lows150) = PortalAnd.chain true none 1556 1558 clearFlagPairs150 := by have h := LeaveJ7.forward_chainG0 (fun i => (1558 + i : Wire)) (fun i => Shadow7.b0P 150 - 1 + i) 1556 lows150 have e : (List.range lows150).map (fun k => (Shadow7.b0P 150 - 1 + k, (1558 + (k + 1) : Wire))) = clearFlagPairs150 := by decide +kernel rw [← e]; exact h have fc (g : Gate) (gs : List Gate) : GateMirror.forward (g :: gs) = front g :: GateMirror.forward gs := rfl have fn : GateMirror.forward [] = [] := rfl simp only [leaveStoreMapped150, forward_app, LeaveJ7.forward_xsG', ch1, ch2, PortalAnd.latch, PortalAnd.digits, pending150_fst, clearFlag150_fst, fc, fn, front, GateMirror.erase, notRegister, List.map_cons, List.map_nil, List.map_append, List.reverse_cons, List.append_assoc, List.cons_append, List.singleton_append, List.nil_append, if_true, ↓reduceIte] private theorem lowClose150_parts : GateMirror.forward leaveLowClose150 = notRegister (LeaveJ7.history MixedWindow.j7) ++ RailPair.store 180 (Shadow7.e0P 150 + 5) low150 [] := by have e1 : GateMirror.forward ((List.range lows150).map fun i => Gate.cx (Shadow7.e0P 150 + 5) (Shadow7.b0P 150 - 1 + i)) = signComplement (Shadow7.e0P 150 + 5) (low150.map Prod.snd) := by simp only [GateMirror.forward, signComplement, low150, List.map_map]; rfl have e2 : GateMirror.forward ((List.range lows150).flatMap fun i => cswapG (150 + 30) (Shadow7.b0P 150 - 1 + i) (Shadow7.a0P 150 - 1 + i)) = exchange 180 low150 := by simp only [GateMirror.forward, exchange, low150, List.map_flatMap, List.flatMap_map]; rfl simp only [leaveLowClose150, forward_app, LeaveJ7.forward_xsG', e1, e2, RailPair.store, RailPair.transfer, List.flatMap_nil, List.nil_append, List.append_assoc, LeaveJ7.history] rfl private theorem close150_parts : GateMirror.forward leaveClose150To20 = GateMirror.forward (Shadow7.closeFlag 150) ++ LeaveRelocation.program movesP150To20 := by unfold leaveClose150To20 rw [forward_app] have hsw : ∀ ps : List (Wire × Wire), GateMirror.forward (swapsG ps) = LeaveRelocation.program ps := by intro ps; induction ps with | nil => rfl | cons p ps ih => show GateMirror.forward ([.cx p.1 p.2, .cx p.2 p.1, .cx p.1 p.2] ++ swapsG ps) = _ rw [forward_app, ih]; rfl rw [hsw] private theorem leave150To20_split : leave150To20 = storeMapped150Prog ++ GateMirror.forward leaveClose150To20 := by unfold leave150To20 storeMapped150Prog beforeStore150Prog full150Prog head150Prog leaveAfter150To20 afterHead150 simp only [forward_app, List.append_assoc] rw [lowStore150_parts] simp only [List.append_assoc] private theorem small150_geom : Companion.Geometry smallA150 smallM150 smallC150 1556 1558 := by constructor <;> decide +kernel private theorem low150_geom : StoreGeometry 180 (Shadow7.e0P 150 + 5) low150 [] := by constructor <;> decide +kernel private theorem pending150_layout : (1557 :: (1558 : Wire) :: PortalAnd.sites pendingPairs150).Nodup := by have hg : Shadow7.sbP 150 = 173 ∧ Shadow7.a0P 150 = 355 ∧ Shadow7.b0P 150 = 960 ∧ Shadow7.wpP 150 = 70 ∧ Shadow7.e0P 150 = 1747 ∧ Shadow7.liveW 150 = 84 ∧ bTopP 150 = 1043 ∧ lows150 = 12 := by decide have hperm : (1557 :: (1558 : Wire) :: PortalAnd.sites pendingPairs150).Perm (1557 :: (1558 : Wire) :: (pendingPairs150.map Prod.fst ++ pendingPairs150.map Prod.snd)) := List.Perm.cons _ (List.Perm.cons _ (LeaveJ7.sites_perm _)) rw [hperm.nodup_iff] have hfst_nd : (pendingPairs150.map Prod.fst).Nodup := by rw [pending150_fst, List.nodup_cons] refine ⟨?_, List.Nodup.map_on (fun a ha b hb e => ?_) List.nodup_range⟩ · intro hm; obtain ⟨i, hi, e⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi have hbc := Shadow7.bank_cases (s := 150) (i := lows150 + i) (by decide) (by decide) (by omega) rcases hbc with ⟨_, eb⟩ | ⟨_, _, eb, _, _⟩ | ⟨_, eb, _⟩ <;> (unfold Wire at *; omega) · rw [List.mem_range] at ha hb have := Shadow7.bank_inj (s := 150) (by decide) (by decide) (by omega) (by omega) e omega have hsnd_nd : (pendingPairs150.map Prod.snd).Nodup := by simp only [pendingPairs150, List.map_map, Function.comp] refine List.Nodup.map_on (fun a ha b hb e => ?_) List.nodup_range simp only [Function.comp_apply] at e have h1 := Shadow7.storeW_cases (s := 150) (by decide) (by decide) (a + 1) have h2 := Shadow7.storeW_cases (s := 150) (by decide) (by decide) (b + 1) unfold Wire at *; omega have hfst_r : ∀ q ∈ pendingPairs150.map Prod.fst, (q : Nat) ≤ 1043 ∨ (1598 ≤ (q : Nat) ∧ (q : Nat) ≤ 1612) := by intro q hq; rw [pending150_fst, List.mem_cons] at hq rcases hq with rfl | hm · left; decide · obtain ⟨i, hi, rfl⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi have hbc := Shadow7.bank_cases (s := 150) (i := lows150 + i) (by decide) (by decide) (by omega) rcases hbc with ⟨_, _⟩ | ⟨_, _, _, _, _⟩ | ⟨_, _, _⟩ · omega · left; unfold Wire at *; omega · right; unfold Wire at *; omega have hsnd_r : ∀ q ∈ pendingPairs150.map Prod.snd, (1559 ≤ (q : Nat) ∧ (q : Nat) ≤ 1597) ∨ 1613 ≤ (q : Nat) := by intro q hq; simp only [pendingPairs150, List.map_map, Function.comp, List.mem_map, List.mem_range] at hq obtain ⟨k, _, rfl⟩ := hq have hs := Shadow7.storeW_cases (s := 150) (by decide) (by decide) (k + 1) unfold Wire at *; omega have hdisj : ∀ a ∈ pendingPairs150.map Prod.fst, ∀ b ∈ pendingPairs150.map Prod.snd, a ≠ b := by intro a ha b hb eq; subst eq rcases hfst_r a ha with x | x <;> rcases hsnd_r a hb with y | y <;> unfold Wire at * <;> omega rw [List.nodup_cons, List.nodup_cons] refine ⟨?_, ?_, List.nodup_append.mpr ⟨hfst_nd, hsnd_nd, hdisj⟩⟩ · intro hm; simp only [List.mem_cons, List.mem_append] at hm rcases hm with h | h | h · exact (by decide : (1557 : Wire) ≠ 1558) h · rcases hfst_r 1557 h with a | a <;> unfold Wire at * <;> omega · rcases hsnd_r 1557 h with a | a <;> unfold Wire at * <;> omega · intro hm; simp only [List.mem_append] at hm rcases hm with h | h · rcases hfst_r 1558 h with a | a <;> unfold Wire at * <;> omega · rcases hsnd_r 1558 h with a | a <;> unfold Wire at * <;> omega def bankW150Lit (i : Nat) : Wire := if i < 70 then 974 + i else 1598 + (i - 70) private theorem bankW150_lit (i : Nat) (h10 : 10 ≤ i) (hlt : i < 85) : Shadow7.bankW 150 i = bankW150Lit i := by have hg : Shadow7.sbP 150 = 173 ∧ Shadow7.b0P 150 = 960 ∧ Shadow7.wpP 150 = 70 ∧ Shadow7.lowsP 150 = 10 ∧ Shadow7.liveW 150 = 84 ∧ bTopP 150 = 1043 := by decide have hbc := Shadow7.bank_cases (s := 150) (i := i) (by decide) (by decide) (by omega) unfold bankW150Lit rcases hbc with ⟨h1, _⟩ | ⟨h1, h2, eb, _, _⟩ | ⟨h1, eb, _⟩ · omega · rw [if_pos (by omega)]; unfold Wire at *; omega · rw [if_neg (by omega)]; unfold Wire at *; omega def bankPair150 (i : Nat) : Wire × Wire := (if i < 58 then (986 + i : Wire) else (1598 + (i - 58) : Wire), (971 + i : Wire)) def flagPairs150 : List (Wire × Wire) := [(1557, 1745), (1558, 1746), (1752, 1747), (1750, 1748), (1754, 1749), (1753, 1750)] def movesP150Lit : List (Wire × Wire) := (List.range 73).map bankPair150 ++ flagPairs150 theorem movesP150_eq : movesP150To20 = movesP150Lit := by have hg : wpP20 165 - 2 = 73 ∧ bTopP 165 = 1043 ∧ wpP20 165 = 75 ∧ lows150 = 12 ∧ e0P20 165 = 1742 ∧ Shadow7.e0P 150 = 1747 := by decide unfold movesP150To20 movesP150Lit flagPairs150 rw [hg.1] apply congrArg₂ List.append · refine List.map_congr_left fun i hi => ?_ rw [List.mem_range] at hi rw [hg.2.2.2.1, bankW150_lit (12 + i) (by omega) (by omega)] unfold bankW150Lit bankPair150 refine Prod.ext ?_ (by rw [hg.2.1, hg.2.2.1]; unfold Wire; omega) by_cases h57 : i < 58 · rw [if_pos (by omega), if_pos h57]; unfold Wire; omega · rw [if_neg (by omega), if_neg h57]; unfold Wire; omega · rw [hg.2.2.2.2.1, hg.2.2.2.2.2] private theorem geom150_check : Companion.Geometry smallA150 smallM150 smallC150 1556 1558 ∧ (1557 :: (1558 : Wire) :: PortalAnd.sites pendingPairs150).Nodup ∧ (1556 :: (1558 : Wire) :: PortalAnd.sites clearFlagPairs150).Nodup ∧ StoreGeometry 180 (Shadow7.e0P 150 + 5) low150 [] ∧ (∀ p ∈ movesP150To20, p.1 ≠ p.2) ∧ (∀ p ∈ pendingPairs150, (1559 ≤ (p.2 : Nat) ∧ (p.2 : Nat) ≤ 1597) ∨ (1613 ≤ (p.2 : Nat) ∧ (p.2 : Nat) + 2 < Shadow7.e0P 150)) ∧ (∀ p ∈ clearFlagPairs150, 1559 ≤ (p.2 : Nat) ∧ (p.2 : Nat) ≤ 1597) := by refine ⟨small150_geom, pending150_layout, by decide +kernel, low150_geom, ?_, ?_, by decide +kernel⟩ · rw [movesP150_eq]; intro p hp; rw [movesP150Lit, List.mem_append] at hp rcases hp with hp | hp · obtain ⟨k, hk, rfl⟩ := List.mem_map.mp hp; rw [List.mem_range] at hk unfold bankPair150; split_ifs <;> (unfold Wire; omega) · simp only [flagPairs150, List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl | rfl | rfl | rfl <;> decide · intro p hp simp only [pendingPairs150, List.mem_map, List.mem_range] at hp obtain ⟨k, hk, rfl⟩ := hp have hs := Shadow7.storeW_cases (s := 150) (by decide) (by decide) (k + 1) have hlt : k + 1 ≤ 73 := by have : Shadow7.liveW 150 = 84 ∧ lows150 = 12 := by decide omega have he : Shadow7.e0P 150 = 1747 := by decide rcases hs with ⟨_, e⟩ | ⟨_, _, e⟩ | ⟨_, _, e⟩ · left; dsimp only; unfold Wire at *; omega · right; dsimp only; unfold Wire at *; omega · omega theorem src150_bank_out (q : Wire) (hq : (q : Nat) < 971 ∨ (1043 < (q : Nat) ∧ (q : Nat) < 1598) ∨ 1612 < (q : Nat)) : LeaveRelocation.source ((List.range 73).map bankPair150) q = q := by apply LeaveRelocation.outside; intro p hp obtain ⟨k, hk, rfl⟩ := List.mem_map.mp hp; rw [List.mem_range] at hk unfold bankPair150; split_ifs <;> rcases hq with h | ⟨h1, h2⟩ | h <;> exact ⟨by unfold Wire at *; omega, by unfold Wire at *; omega⟩ theorem src150_flags_out (q : Wire) (hq : (q : Nat) < 1557) : LeaveRelocation.source flagPairs150 q = q := by apply LeaveRelocation.outside; intro p hp simp only [flagPairs150, List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl | rfl | rfl | rfl <;> exact ⟨by unfold Wire at *; omega, by unfold Wire at *; omega⟩ private theorem src150_bank_at (i : Nat) (hi : i < 73) : LeaveRelocation.source ((List.range 73).map bankPair150) (971 + i) = bankW150Lit (12 + i) := by have hsplit : List.range 73 = List.range i ++ (i :: (List.range (73 - (i + 1))).map (i + 1 + ·)) := by have h1 : 73 = i + (1 + (73 - (i + 1))) := by omega conv_lhs => rw [h1, List.range_add, List.range_add] simp [List.range_one, Nat.add_assoc] rw [hsplit, List.map_append, List.map_cons, LeaveRelocation.append] have hafter : LeaveRelocation.source ((List.map (i + 1 + ·) (List.range (73 - (i + 1)))).map bankPair150) (971 + i) = 971 + i := by apply LeaveRelocation.outside; intro p hp obtain ⟨k, hk, rfl⟩ := List.mem_map.mp hp obtain ⟨r, hr, rfl⟩ := List.mem_map.mp hk; rw [List.mem_range] at hr unfold bankPair150; split_ifs <;> exact ⟨by unfold Wire; omega, by unfold Wire; omega⟩ have hcons : LeaveRelocation.source (bankPair150 i :: (List.map (i + 1 + ·) (List.range (73 - (i + 1)))).map bankPair150) (971 + i) = bankW150Lit (12 + i) := by change LeaveRelocation.flip (bankPair150 i).1 (bankPair150 i).2 (LeaveRelocation.source ((List.map (i + 1 + ·) (List.range (73 - (i + 1)))).map bankPair150) (971 + i)) = _ rw [hafter] unfold LeaveRelocation.flip bankPair150 bankW150Lit dsimp only split_ifs <;> (unfold Wire at *; omega) rw [hcons] apply LeaveRelocation.outside; intro p hp obtain ⟨k, hk, rfl⟩ := List.mem_map.mp hp; rw [List.mem_range] at hk unfold bankPair150 bankW150Lit by_cases hi57 : i < 58 <;> by_cases hk57 : k < 58 · rw [if_pos (by omega), if_pos hk57]; exact ⟨by unfold Wire; omega, by unfold Wire; omega⟩ · omega · rw [if_neg (by omega), if_pos hk57]; exact ⟨by unfold Wire; omega, by unfold Wire; omega⟩ · rw [if_neg (by omega), if_neg hk57]; exact ⟨by unfold Wire; omega, by unfold Wire; omega⟩ theorem reloc150_lit : LeaveRelocation.source movesP150Lit 1745 = 1557 ∧ LeaveRelocation.source movesP150Lit 1746 = 1558 ∧ LeaveRelocation.source movesP150Lit 1747 = 1752 ∧ LeaveRelocation.source movesP150Lit 1748 = 1750 ∧ LeaveRelocation.source movesP150Lit 1749 = 1754 ∧ LeaveRelocation.source movesP150Lit 1750 = 1753 ∧ (∀ i : Fin 15, LeaveRelocation.source movesP150Lit (166 + i.val) = 166 + i.val) ∧ (∀ i : Fin 12, LeaveRelocation.source movesP150Lit (354 + i.val) = 354 + i.val ∧ LeaveRelocation.source movesP150Lit (959 + i.val) = 959 + i.val) ∧ (∀ i : Fin 73, LeaveRelocation.source movesP150Lit (971 + i.val) = bankW150Lit (12 + i.val) ∧ LeaveRelocation.source movesP150Lit (367 + i.val) = 367 + i.val) := by have hfl : LeaveRelocation.source flagPairs150 1745 = 1557 ∧ LeaveRelocation.source flagPairs150 1746 = 1558 ∧ LeaveRelocation.source flagPairs150 1747 = 1752 ∧ LeaveRelocation.source flagPairs150 1748 = 1750 ∧ LeaveRelocation.source flagPairs150 1749 = 1754 ∧ LeaveRelocation.source flagPairs150 1750 = 1753 := by decide refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ · rw [movesP150Lit, LeaveRelocation.append, hfl.1, src150_bank_out _ (by decide)] · rw [movesP150Lit, LeaveRelocation.append, hfl.2.1, src150_bank_out _ (by decide)] · rw [movesP150Lit, LeaveRelocation.append, hfl.2.2.1, src150_bank_out _ (by decide)] · rw [movesP150Lit, LeaveRelocation.append, hfl.2.2.2.1, src150_bank_out _ (by decide)] · rw [movesP150Lit, LeaveRelocation.append, hfl.2.2.2.2.1, src150_bank_out _ (by decide)] · rw [movesP150Lit, LeaveRelocation.append, hfl.2.2.2.2.2, src150_bank_out _ (by decide)] · intro i; rw [movesP150Lit, LeaveRelocation.append, src150_flags_out _ (by have := i.isLt; unfold Wire; omega), src150_bank_out _ (Or.inl (by have := i.isLt; unfold Wire; omega))] · intro i; constructor · rw [movesP150Lit, LeaveRelocation.append, src150_flags_out _ (by have := i.isLt; unfold Wire; omega), src150_bank_out _ (Or.inl (by have := i.isLt; unfold Wire; omega))] · rw [movesP150Lit, LeaveRelocation.append, src150_flags_out _ (by have := i.isLt; unfold Wire; omega), src150_bank_out _ (Or.inl (by have := i.isLt; unfold Wire; omega))] · intro i; constructor · rw [movesP150Lit, LeaveRelocation.append, src150_flags_out _ (by have := i.isLt; unfold Wire; omega)] exact src150_bank_at i.val i.isLt · rw [movesP150Lit, LeaveRelocation.append, src150_flags_out _ (by have := i.isLt; unfold Wire; omega), src150_bank_out _ (Or.inl (by have := i.isLt; unfold Wire; omega))] private theorem reloc150_check : LeaveRelocation.source movesP150To20 (e0P20 165 + 3) = 1557 ∧ LeaveRelocation.source movesP150To20 (e0P20 165 + 4) = 1558 ∧ LeaveRelocation.source movesP150To20 (e0P20 165 + 5) = Shadow7.e0P 150 + 5 ∧ LeaveRelocation.source movesP150To20 (e0P20 165 + 6) = Shadow7.e0P 150 + 3 ∧ LeaveRelocation.source movesP150To20 (e0P20 165 + 7) = Shadow7.e0P 150 + 7 ∧ LeaveRelocation.source movesP150To20 (e0P20 165 + 8) = Shadow7.e0P 150 + 6 ∧ (∀ i : Fin 15, LeaveRelocation.source movesP150To20 (166 + i.val) = 166 + i.val) ∧ (∀ i : Fin 12, LeaveRelocation.source movesP150To20 (Shadow7.a0P 150 - 1 + i.val) = Shadow7.a0P 150 - 1 + i.val ∧ LeaveRelocation.source movesP150To20 (Shadow7.b0P 150 - 1 + i.val) = Shadow7.b0P 150 - 1 + i.val) ∧ (∀ i : Fin (wpP20 165 - 2), LeaveRelocation.source movesP150To20 (Shadow7.b0P 150 + lows150 - 1 + i.val) = Shadow7.bankW 150 (lows150 + i.val) ∧ LeaveRelocation.source movesP150To20 (Shadow7.a0P 150 + lows150 + i.val) = Shadow7.a0P 150 + lows150 + i.val) := by rw [movesP150_eq] have hr := reloc150_lit refine ⟨hr.1, hr.2.1, hr.2.2.1, hr.2.2.2.1, hr.2.2.2.2.1, hr.2.2.2.2.2.1, hr.2.2.2.2.2.2.1, hr.2.2.2.2.2.2.2.1, fun i => ?_⟩ have h1 := hr.2.2.2.2.2.2.2.2 ⟨i.val, i.isLt⟩ have hwp : wpP20 165 - 2 = 73 := by decide refine ⟨?_, h1.2⟩ rw [show lows150 = 12 from rfl, bankW150_lit (12 + i.val) (by omega) (by have := i.isLt; omega)] exact h1.1 private theorem nextFlag150_orientation (a : SkywalkNat.State) (sign : Nat) (bit : sign ≤ 1) (small : Shadow7.SmallIfFar 163 20 a) (hfar : Shadow.far 163 20 a) : (2 ^ 173 ≤ a.u - sign) ↔ (2 ^ 163 ≤ a.u) := by have hsm := small hfar have lower := (Nat.le_div_iff_mul_le (by unfold Shadow.limb; positivity : 0 < Shadow.limb 163 20)).mp hfar unfold Shadow.limb at lower have p2 : (2 : Nat) ^ (163 + 20) = 2 ^ 20 * 2 ^ 163 := by rw [← Nat.pow_add, Nat.add_comm] have p1 : (2 : Nat) ^ 173 = 1024 * 2 ^ 163 := by rw [show (173 : Nat) = 163 + 10 by decide, Nat.pow_add, Nat.mul_comm] rw [p2] at lower; rw [p1] generalize (2 : Nat) ^ 163 = P at * constructor <;> intro h <;> omega private theorem nextFlag150_boundNear (a : SkywalkNat.State) (sign : Nat) (hnear : ¬ Shadow.far 163 20 a) : a.u - sign < (2 * 2 ^ 173) * 2 ^ smallM150.length := by have lo : (a.u + a.v) / Shadow.limb 163 20 < 2 := Nat.lt_of_not_ge hnear have lim := (Nat.div_lt_iff_lt_mul (by unfold Shadow.limb; positivity : 0 < Shadow.limb 163 20)).mp lo have he : 2 * Shadow.limb 163 20 ≤ (2 * 2 ^ 173) * 2 ^ smallM150.length := by unfold Shadow.limb have hl : smallM150.length = 11 := rfl rw [hl] have h1 : 2 * 2 ^ (163 + 20) = 2 ^ 184 := by rw [← Nat.pow_succ'] have h2 : 2 * 2 ^ 173 * 2 ^ 11 = 2 ^ 185 := by rw [← Nat.pow_succ', ← Nat.pow_add] rw [h1, h2]; exact Nat.pow_le_pow_right (by decide) (by decide) omega private theorem bankW150_ne_swap : ∀ k : Fin (Shadow7.wpP 150 + 15), 12 ≤ k.val → (Shadow7.bankW 150 k.val : Wire) ≠ 364 ∧ (Shadow7.bankW 150 k.val : Wire) ≠ 984 ∧ (Shadow7.bankW 150 k.val : Wire) ≠ 365 ∧ (Shadow7.bankW 150 k.val : Wire) ≠ 985 := by intro k h12 rw [bankW150_lit k.val (by omega) k.isLt] unfold bankW150Lit; split_ifs <;> refine ⟨by unfold Wire; omega, by unfold Wire; omega, by unfold Wire; omega, by unfold Wire; omega⟩ private theorem bankW150_ne_store : ∀ r : Fin 72, (Shadow7.bankW 150 (12 + r.val) : Wire) ≠ 1557 ∧ (Shadow7.bankW 150 (12 + r.val) : Wire) ≠ 1558 ∧ Shadow7.bankW 150 (12 + r.val) ∉ smallM150 := by intro r rw [bankW150_lit (12 + r.val) (by omega) (by omega)] unfold bankW150Lit have hnotM (q : Wire) (hq : 986 ≤ (q : Nat)) : q ∉ smallM150 := by intro hm; obtain ⟨i, hi, e⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi have hb : Shadow7.b0P 150 = 960 ∧ lows150 = 12 := by decide unfold Wire at *; omega split_ifs <;> refine ⟨by unfold Wire; omega, by unfold Wire; omega, hnotM _ (by unfold Wire; omega)⟩ private theorem events150_away : ∀ w ∈ [Shadow7.e0P 150 + 3, Shadow7.e0P 150 + 4, Shadow7.e0P 150 + 6, Shadow7.e0P 150 + 7] ++ (LeaveJ7.Close.events MixedWindow.j7).flatMap (fun p => [p.1, p.2]), w ≠ 364 ∧ w ≠ 984 ∧ w ≠ 365 ∧ w ≠ 985 ∧ w ∉ RailPair.sites low150 ∧ w ∉ LeaveJ7.history MixedWindow.j7 ∧ w ∉ smallM150 ∧ w ≠ 1557 ∧ w ≠ 1558 ∧ w ∉ RailPair.sites (LeaveJ7.Close.low MixedWindow.j7) ∧ w ∉ LeaveJ7.smallM MixedWindow.j7 := by decide +kernel private theorem bankW150_away : ∀ k : Fin (wpP20 165 - 2), (Shadow7.bankW 150 (lows150 + k.val) : Wire) ≠ Shadow7.e0P 150 + 4 ∧ Shadow7.bankW 150 (lows150 + k.val) ∉ RailPair.sites low150 ∧ Shadow7.bankW 150 (lows150 + k.val) ∉ LeaveJ7.history MixedWindow.j7 ∧ (Shadow7.bankW 150 (lows150 + k.val) : Wire) ≠ 1556 ∧ (Shadow7.bankW 150 (lows150 + k.val) : Wire) ≠ 1557 ∧ (Shadow7.bankW 150 (lows150 + k.val) : Wire) ≠ 1558 ∧ Shadow7.bankW 150 (lows150 + k.val) ∉ smallM150 := by intro k have hg : wpP20 165 - 2 = 73 ∧ lows150 = 12 ∧ Shadow7.e0P 150 = 1747 ∧ Shadow7.a0P 150 = 355 ∧ Shadow7.b0P 150 = 960 := by decide rw [hg.2.1, bankW150_lit (12 + k.val) (by omega) (by omega)] have hr : 986 ≤ (bankW150Lit (12 + k.val) : Nat) ∧ (bankW150Lit (12 + k.val) : Nat) ≤ 1043 ∨ (1598 ≤ (bankW150Lit (12 + k.val) : Nat) ∧ (bankW150Lit (12 + k.val) : Nat) ≤ 1612) := by unfold bankW150Lit; split_ifs <;> [left; right] <;> (unfold Wire; omega) have hnotL : bankW150Lit (12 + k.val) ∉ RailPair.sites low150 := by intro hm; obtain ⟨p, hp, hq⟩ := List.mem_flatMap.mp hm obtain ⟨i, hi, rfl⟩ := List.mem_map.mp hp; rw [List.mem_range] at hi simp only [List.mem_cons, List.not_mem_nil, or_false] at hq rcases hr with ⟨_, _⟩ | ⟨_, _⟩ <;> rcases hq with hq | hq <;> (unfold Wire at *; omega) have hnotH : bankW150Lit (12 + k.val) ∉ LeaveJ7.history MixedWindow.j7 := by intro hm; unfold LeaveJ7.history at hm; rw [show start MixedWindow.j7 = 150 from rfl] at hm obtain ⟨i, hi, e⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi rcases hr with ⟨_, _⟩ | ⟨_, _⟩ <;> (unfold Wire at *; omega) have hnotM : bankW150Lit (12 + k.val) ∉ smallM150 := by intro hm; obtain ⟨i, hi, e⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi rcases hr with ⟨_, _⟩ | ⟨_, _⟩ <;> (unfold Wire at *; omega) refine ⟨by rcases hr with ⟨_, _⟩ | ⟨_, _⟩ <;> (unfold Wire at *; omega), hnotL, hnotH, by rcases hr with ⟨_, _⟩ | ⟨_, _⟩ <;> (unfold Wire at *; omega), by rcases hr with ⟨_, _⟩ | ⟨_, _⟩ <;> (unfold Wire at *; omega), by rcases hr with ⟨_, _⟩ | ⟨_, _⟩ <;> (unfold Wire at *; omega), hnotM⟩ theorem not_mem_smallM150 (q : Wire) (hq : (q : Nat) < 960 ∨ 972 ≤ (q : Nat)) : q ∉ smallM150 := by intro hm; obtain ⟨i, hi, e⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi have hg : Shadow7.b0P 150 = 960 ∧ lows150 = 12 := by decide unfold Wire at *; omega theorem swap2St_other (q : Nat) (h1 : q ≠ 364) (h2 : q ≠ 984) (h3 : q ≠ 365) (h4 : q ≠ 985) (u : State) : (swap2St u).basis q = u.basis q := swap2_other h1 h2 h3 h4 u.basis private theorem releaseMaskP150_eq : releaseMaskP150 = [.measureX 1558 [] [.CZ (Shadow7.b0P 150 - 1) 1557], .CX (Shadow7.a0P 150 - 1) 1557, .X 1557] := rfl private theorem borrowG4_150_phase (t : State) : (run borrowG4_150 [] t).phase = t.phase := by simp [borrowG4_150, run] private theorem borrowG4_150_keep (t : State) (q : Wire) (n7 : q ≠ 1557) (n8 : q ≠ 1558) : (run borrowG4_150 [] t).basis q = t.basis q := by simp [borrowG4_150, run, writeBit, Function.update_apply, n7, n8] private theorem borrowG4_150_57 (t : State) (h57 : t.basis 1557 = false) : (run borrowG4_150 [] t).basis 1557 = !t.basis (Shadow7.a0P 150 - 1) := by have na : (Shadow7.a0P 150 - 1 : Wire) ≠ 1557 := by decide simp [borrowG4_150, run, writeBit, Function.update_apply, na, na.symm, h57] private theorem borrowG4_150_58 (t : State) (h57 : t.basis 1557 = false) (h58 : t.basis 1558 = false) : (run borrowG4_150 [] t).basis 1558 = (t.basis (Shadow7.b0P 150 - 1) && !t.basis (Shadow7.a0P 150 - 1)) := by have na : (Shadow7.a0P 150 - 1 : Wire) ≠ 1557 ∧ (Shadow7.a0P 150 - 1 : Wire) ≠ 1558 := by decide have nb : (Shadow7.b0P 150 - 1 : Wire) ≠ 1557 ∧ (Shadow7.b0P 150 - 1 : Wire) ≠ 1558 := by decide simp [borrowG4_150, run, writeBit, Function.update_apply, na.1, na.2, nb.1, nb.2, na.1.symm, na.2.symm, nb.1.symm, nb.2.symm, h57, h58] private theorem F150_eq (z : SkywalkNat.State) : LeaveJ7.TrueMiddle.F MixedWindow.j7 z = ((step^[15] z).u + (step^[15] z).v) / 2 ^ 173 := by unfold LeaveJ7.TrueMiddle.F HighBankSum.total rw [show Shadow7.sbP (start MixedWindow.j7) = 173 by decide] private theorem scan150_sites_lt : ∀ q ∈ RailPair.sites (LeaveJ7.scanPairs MixedWindow.j7), q < 976 := by decide +kernel section Forward150 attribute [local irreducible] run SkywalkNat.step Shadow.far CRTBarrel.barrel GateMirror.forward head150Prog full150Prog beforeStore150Prog storeMapped150Prog leave150To20 Shadow7.leaveHeadOps Shadow7.fix0P leaveFix1 leaveStoreMapped150 leaveLowClose150 leaveClose150To20 afterHead150 lowRest150 Companion.restore releaseMaskP150 PortalAnd.latch RailPair.store private theorem stock_full_eq_head150 (s : State) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (q : Wire) (hq : q ∉ LeaveJ7.smallM MixedWindow.j7) (h7 : q ≠ 1557) (h8 : q ≠ 1558) : (run (LeaveJ7.fullProgram MixedWindow.j7) [] s).basis q = (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s).basis q := by let u := LeaveJ7.Admission.flags z g0 s0 have hi : MixedWindow.j7.val ≤ 24 := by decide have par := LeaveJ7.RecordedParity.result MixedWindow.j7 (by decide) hi s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record have mode : LeaveSelector.actualMode (Shadow7.sbP (start MixedWindow.j7)) z = LeaveSelector.farMode (s.basis (Shadow7.e0P (start MixedWindow.j7) + 3)) (s.basis (Shadow7.e0P (start MixedWindow.j7) + 4)) z.u := by rw [h.far, h.side]; exact LeaveTraceHistory.flags _ _ have ev := LeaveJ7.RecordedEvents.result MixedWindow.j7 (by decide) hi s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record have gflag := LeaveJ7.RecordedEvents.glueFlag MixedWindow.j7 (by decide) hi s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record h.far h.side have front := LeaveJ7.entry_core MixedWindow.j7 (by decide) hi s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp (Shadow.far (Shadow7.sbP (start MixedWindow.j7)) 15 z ∧ LeaveShadowRails.farKey (Shadow7.sbP (start MixedWindow.j7)) z = 0) (LeaveJ7.glueBound MixedWindow.j7 z u.2 ⟨h.farSmall, h.endSmall⟩) gflag have used := LeaveJ7.full_routed MixedWindow.j7 (by decide) hi s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 gflag have bm1 := LeaveJ7.full_bm1 MixedWindow.j7 (by decide) hi s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 gflag dsimp only at front used rw [List.drop_nil] at used bm1 have restored := LeaveJ7.routedRestore_result MixedWindow.j7 (by decide) hi z u.2 (run (GateMirror.forward (LeaveJ7.entryOps (start MixedWindow.j7))) [] s) [] [] ⟨h.farSmall, h.endSmall⟩ front.2.1 ⟨front.2.2.2.1, front.2.2.2.2.1⟩ used.2.1 bm1 used.2.2.2.1 dsimp only at restored have hhead : run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s = run (GateMirror.forward (LeaveJ7.bodyOps MixedWindow.j7)) [] (run (GateMirror.forward (LeaveJ7.entryOps 150)) [] s) := by rw [show Shadow7.leaveHeadOps 150 = LeaveJ7.entryOps 150 ++ LeaveJ7.bodyOps MixedWindow.j7 from (LeaveJ7.head_eq MixedWindow.j7).symm, forward_app, run_append, run_take, List.drop_nil] have r := restored.2.1 q h7 h8 hq rw [hhead] simp only [LeaveJ7.fullProgram, forward_app, List.append_assoc, run_append, run_take, List.drop_nil, List.take_nil] at r ⊢ rw [show start MixedWindow.j7 = 150 from rfl] at r exact r private theorem beforeStore150_result (s : State) (m : List Bool) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) : let a := step^[15] z let u := LeaveJ7.Admission.flags z g0 s0 let sign := PortalValues.negative u.2 a.u let mag := a.u - sign.toNat let next := decide (Shadow.far 163 20 a) let bs := run beforeStore150Prog m s bs.phase = s.phase ∧ bs.basis 1556 = false ∧ bs.basis 1557 = next ∧ bs.basis 1558 = (next && decide (2 ^ 163 ≤ a.u)) ∧ bs.basis (Shadow7.e0P 150 + 5) = sign ∧ (∀ q ∈ LeaveJ7.history MixedWindow.j7, bs.basis q = !s.basis q) ∧ (∀ i : Fin 12, bs.basis (Shadow7.a0P 150 - 1 + i.val) = (a.u + a.v).testBit (173 + i.val) ∧ bs.basis (Shadow7.b0P 150 - 1 + i.val) = mag.testBit (173 + i.val)) ∧ (∀ i : Fin (wpP20 165 - 2), (run head150Prog m s).basis (Shadow7.bankW 150 (lows150 + i.val)) = (LeaveJ7.TrueMiddle.F MixedWindow.j7 z).testBit (lows150 + i.val)) ∧ (∀ q : Nat, q ≠ 1556 → q ≠ 1557 → q ≠ 1558 → q ∉ smallM150 → bs.basis q = (run head150Prog m s).basis q) ∧ (∀ q : Nat, q ≠ 364 → q ≠ 984 → q ≠ 365 → q ≠ 985 → (run head150Prog m s).basis q = (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s).basis q) := by let a := step^[15] z let u := LeaveJ7.Admission.flags z g0 s0 let sign := PortalValues.negative u.2 a.u let mag := a.u - sign.toNat have hi : MixedWindow.j7.val ≤ 24 := by decide have par := LeaveJ7.RecordedParity.result MixedWindow.j7 (by decide) hi s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record have mode : LeaveSelector.actualMode (Shadow7.sbP (start MixedWindow.j7)) z = LeaveSelector.farMode (s.basis (Shadow7.e0P (start MixedWindow.j7) + 3)) (s.basis (Shadow7.e0P (start MixedWindow.j7) + 4)) z.u := by rw [h.far, h.side]; exact LeaveTraceHistory.flags _ _ have ev := LeaveJ7.RecordedEvents.result MixedWindow.j7 (by decide) hi s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record have gflag := LeaveJ7.RecordedEvents.glueFlag MixedWindow.j7 (by decide) hi s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record h.far h.side have hfront := LeaveJ7.entry_core MixedWindow.j7 (by decide) hi s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp (Shadow.far (Shadow7.sbP (start MixedWindow.j7)) 15 z ∧ LeaveShadowRails.farKey (Shadow7.sbP (start MixedWindow.j7)) z = 0) (LeaveJ7.glueBound MixedWindow.j7 z u.2 ⟨h.farSmall, h.endSmall⟩) gflag have hrouted := LeaveJ7.full_routed MixedWindow.j7 (by decide) hi s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 gflag have hbm1 := LeaveJ7.full_bm1 MixedWindow.j7 (by decide) hi s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 gflag have hpar0 := LeaveJ7.entry_parity MixedWindow.j7 (by decide) hi s [] have hck := LeaveJ7.CoreCheckpoint.result MixedWindow.j7 (by decide) hi s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 gflag have hck_prog : LeaveJ7.CoreCheckpoint.program MixedWindow.j7 = GateMirror.forward (Shadow7.leaveHeadOps 150) := rfl dsimp only at hck rw [hck_prog] at hck dsimp only at hfront hrouted rw [List.drop_nil] at hrouted hbm1 rw [show start MixedWindow.j7 = 150 from rfl] at hfront hrouted hbm1 hpar0 have hsb : Shadow7.sbP 150 = 173 := by decide have ha0 : Shadow7.a0P 150 = 355 := by decide have hb0 : Shadow7.b0P 150 = 960 := by decide have hwp : Shadow7.wpP 150 = 70 := by decide have he0 : Shadow7.e0P 150 = 1747 := by decide have hlows : Shadow7.lowsP 150 = 10 := by decide have hwp20 : wpP20 165 = 75 := by decide have hlow12 : lows150 = 12 := by decide rw [hsb] at hfront hrouted hbm1 -- the stock head state and the transition head state let E := run (GateMirror.forward (LeaveJ7.entryOps 150)) [] s let U := run (GateMirror.forward (LeaveJ7.bodyOps MixedWindow.j7)) [] E have hst_eq : run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s = U := by rw [show Shadow7.leaveHeadOps 150 = LeaveJ7.entryOps 150 ++ LeaveJ7.bodyOps MixedWindow.j7 from (LeaveJ7.head_eq MixedWindow.j7).symm, forward_app, run_append, run_take, List.drop_nil] let hst := run head150Prog m s have hhst_eq : hst = swap2St U := by show run head150Prog m s = _; unfold head150Prog; rw [← hst_eq]; exact (leaveMove150_head_eq s z g0 s0 h).2 m have hst_ph : hst.phase = s.phase := by rw [hhst_eq]; exact hrouted.1.trans hfront.1 have hst_basis (q : Nat) (h1 : q ≠ 364) (h2 : q ≠ 984) (h3 : q ≠ 365) (h4 : q ≠ 985) : hst.basis q = U.basis q := by rw [hhst_eq]; exact swap2St_other q h1 h2 h3 h4 _ have keepE (q : Nat) (hm : ¬ LeaveJ7.midT MixedWindow.j7 q) : U.basis q = E.basis q := LeaveReadoutFrame.preserved _ _ _ _ (fun hit => hm (LeaveJ7.body_dest MixedWindow.j7 (by decide) hi q hit)) have hF_low : ∀ (i : Nat), i < 12 → hst.basis (Shadow7.a0P 150 - 1 + i) = (LeaveJ7.TrueMiddle.F MixedWindow.j7 z).testBit i := by intro i hi' by_cases h10 : i < 10 · rw [hst_basis (Shadow7.a0P 150 - 1 + i) (by rw [ha0]; omega) (by rw [ha0]; omega) (by rw [ha0]; omega) (by rw [ha0]; omega)] have hr := hrouted.2.1 i (by rw [hwp]; omega) unfold LeaveJ7.live at hr rw [show start MixedWindow.j7 = 150 from rfl, if_pos (by rw [hlows]; omega)] at hr exact hr · have hi'' : i = 10 ∨ i = 11 := by omega rcases hi'' with rfl | rfl · have hr := hrouted.2.1 10 (by rw [hwp]; decide) unfold LeaveJ7.live at hr rw [show start MixedWindow.j7 = 150 from rfl, if_neg (by rw [hlows]; decide)] at hr have hb10 : Shadow7.bankW 150 10 = 984 := by decide have ha10 : (Shadow7.a0P 150 - 1 + 10 : Wire) = 364 := by decide rw [hb10] at hr rw [hhst_eq, ha10, show (swap2St U).basis 364 = U.basis 984 by simp [swap2St, swap2, swap1]] exact hr · have hr := hrouted.2.1 11 (by rw [hwp]; decide) unfold LeaveJ7.live at hr rw [show start MixedWindow.j7 = 150 from rfl, if_neg (by rw [hlows]; decide)] at hr have hb11 : Shadow7.bankW 150 11 = 985 := by decide have ha11 : (Shadow7.a0P 150 - 1 + 11 : Wire) = 365 := by decide rw [hb11] at hr rw [hhst_eq, ha11, show (swap2St U).basis 365 = U.basis 985 by simp [swap2St, swap2, swap1]] exact hr have hF_hi : ∀ i, 12 ≤ i → i < Shadow7.wpP 150 + 15 → hst.basis (Shadow7.bankW 150 i) = (LeaveJ7.TrueMiddle.F MixedWindow.j7 z).testBit i := by intro i h12 hlt have hne := bankW150_ne_swap ⟨i, hlt⟩ h12 rw [hst_basis _ hne.1 hne.2.1 hne.2.2.1 hne.2.2.2] have hr := hrouted.2.1 i hlt unfold LeaveJ7.live at hr rw [show start MixedWindow.j7 = 150 from rfl, if_neg (by rw [hlows]; omega)] at hr exact hr have h56E : E.basis 1556 = decide (2 ^ 173 ≤ mag) := by have ch := LeaveRestoreTruth.truth_shadow7 173 z h.farSmall u.2 dsimp only at ch show E.basis 1556 = decide (2 ^ 173 ≤ (step^[15] z).u - (PortalValues.negative u.2 (step^[15] z).u).toNat) rw [hfront.2.2.2.1, ch.1, ← ch.2.1]; simp have h56 : hst.basis 1556 = decide (2 ^ 173 ≤ mag) := by rw [hst_basis 1556 (by decide) (by decide) (by decide) (by decide), keepE 1556 (by unfold LeaveJ7.midT LeaveJ7.workT; decide)] exact h56E have h57 : hst.basis 1557 = false := by rw [hst_basis 1557 (by decide) (by decide) (by decide) (by decide), keepE 1557 (by unfold LeaveJ7.midT LeaveJ7.workT; decide)] exact hfront.2.2.2.2.1.1 have h58 : hst.basis 1558 = false := by rw [hst_basis 1558 (by decide) (by decide) (by decide) (by decide), keepE 1558 (by unfold LeaveJ7.midT LeaveJ7.workT; decide)] exact hfront.2.2.2.2.1.2 have hbB : hst.basis (Shadow7.b0P 150 - 1) = (mag / 2 ^ 173).testBit 0 := by rw [hst_basis _ (by rw [hb0]; decide) (by rw [hb0]; decide) (by rw [hb0]; decide) (by rw [hb0]; decide)] exact hbm1 have hbA : hst.basis (Shadow7.a0P 150 - 1) = ((a.u + a.v) / 2 ^ 173).testBit 0 := by have e0 := hF_low 0 (by decide); rw [Nat.add_zero] at e0; rw [e0, F150_eq] have hret : ∀ i : Fin 39, hst.basis (1559 + i.val) = false := by intro i rw [hst_basis _ (by omega) (by omega) (by omega) (by omega)] exact hrouted.2.2.2.1 i have hM0 : regValue smallM150 hst.basis = 0 := by rw [regValue_zero]; intro q hq obtain ⟨i, hi', rfl⟩ := List.mem_map.mp hq; rw [List.mem_range, hlow12] at hi' rw [hst_basis _ (by rw [hb0]; omega) (by rw [hb0]; omega) (by rw [hb0]; omega) (by rw [hb0]; omega), keepE _ (by unfold LeaveJ7.midT LeaveJ7.workT; rw [show start MixedWindow.j7 = 150 from rfl, ha0, hb0, he0]; omega)] exact (regValue_zero _ _).mp hfront.2.1 _ (List.mem_map.mpr ⟨i, List.mem_range.mpr (by omega), rfl⟩) have hhst_def : run head150Prog m s = hst := rfl clear_value hst -- borrow G4 and the eleven-bit restore let m1 := m.drop (measurementCount head150Prog) have hmcG : measurementCount borrowG4_150 = 0 := rfl let g := run borrowG4_150 [] hst have hg_run : run borrowG4_150 m1 hst = g := by rw [← run_take, hmcG, List.take_zero] have na : (Shadow7.a0P 150 - 1 : Wire) ≠ 1557 ∧ (Shadow7.a0P 150 - 1 : Wire) ≠ 1558 := by decide have nb : (Shadow7.b0P 150 - 1 : Wire) ≠ 1557 ∧ (Shadow7.b0P 150 - 1 : Wire) ≠ 1558 := by decide have gph : g.phase = hst.phase := borrowG4_150_phase hst have gq (q : Nat) (n7 : q ≠ 1557) (n8 : q ≠ 1558) : g.basis q = hst.basis q := borrowG4_150_keep hst q n7 n8 have g57 : g.basis 1557 = !hst.basis (Shadow7.a0P 150 - 1) := borrowG4_150_57 hst h57 have g58 : g.basis 1558 = (hst.basis (Shadow7.b0P 150 - 1) && !hst.basis (Shadow7.a0P 150 - 1)) := borrowG4_150_58 hst h57 h58 have gClean : ∀ q ∈ smallC150, g.basis q = false := by intro q hq; obtain ⟨i, hi', rfl⟩ := List.mem_map.mp hq; rw [List.mem_range, hlow12] at hi' rw [gq (1559 + i) (by omega) (by omega)]; exact hret ⟨i, by omega⟩ have gM0 : regValue smallM150 g.basis = 0 := by rw [← hM0]; apply (regValue_eq_iff _ _ _).mpr; intro q hq obtain ⟨i, hi', rfl⟩ := List.mem_map.mp hq; rw [List.mem_range, hlow12] at hi' exact gq _ (by rw [hb0]; omega) (by rw [hb0]; omega) let m2 := m1.drop (measurementCount borrowG4_150) have hrest := Companion.write smallA150 smallM150 smallC150 1556 1558 geom150_check.1 g m2 gClean gM0 have hfull_eq : run full150Prog m s = run (Companion.restore smallA150 smallM150 smallC150 1556 1558) m2 g := by rw [show full150Prog = head150Prog ++ (borrowG4_150 ++ Companion.restore smallA150 smallM150 smallC150 1556 1558) by unfold full150Prog; rfl, run_append, run_take, run_append, run_take, hhst_def] show run (Companion.restore smallA150 smallM150 smallC150 1556 1558) m2 (run borrowG4_150 m1 hst) = _ rw [hg_run] have hmag_smallM : regValue smallM150 (run full150Prog m s).basis = (mag / 2 ^ 174) % 2 ^ 11 := by have gLatch : g.basis 1556 = decide (2 ^ 173 ≤ mag) := by rw [gq 1556 (by decide) (by decide)]; exact h56 have gBorrow : (g.basis 1558).toNat = LeaveCompanion.upperBorrow (2 ^ 173) a.u a.v sign.toNat := by rw [g58, hbB, hbA, LeaveShadowRails.borrow_bits _ _ _ _ (Nat.two_pow_pos _), Nat.testBit_zero, Nat.testBit_zero] show (decide ((((step^[15] z).u - (PortalValues.negative u.2 (step^[15] z).u).toNat) / 2 ^ 173) % 2 = 1) && !decide ((((step^[15] z).u + (step^[15] z).v) / 2 ^ 173) % 2 = 1)).toNat = if (((step^[15] z).u - (PortalValues.negative u.2 (step^[15] z).u).toNat) / 2 ^ 173) % 2 = 1 ∧ (((step^[15] z).u + (step^[15] z).v) / 2 ^ 173) % 2 = 0 then 1 else 0 generalize (((step^[15] z).u - (PortalValues.negative u.2 (step^[15] z).u).toNat) / 2 ^ 173) = X generalize (((step^[15] z).u + (step^[15] z).v) / 2 ^ 173) = S rcases Nat.mod_two_eq_zero_or_one X with p1 | p1 <;> rcases Nat.mod_two_eq_zero_or_one S with p2 | p2 <;> simp [p1, p2] have gReg : regValue smallA150 g.basis = ((a.u + a.v) / 2 ^ 174) % 2 ^ 11 := by have hv := EnterProof.value_of_bits smallA150 g.basis (LeaveJ7.TrueMiddle.F MixedWindow.j7 z / 2) (by intro i hi' have hlen : smallA150.length = 11 := rfl rw [hlen] at hi' have hg' : smallA150.getD i 0 = Shadow7.a0P 150 - 1 + (i + 1) := by simp only [smallA150, lows150, List.getD_eq_getElem?_getD, List.getElem?_map, List.getElem?_range (show i < 12 - 1 by omega), Option.map_some, Option.getD_some] show (Shadow7.a0P 150 + i : Nat) = Shadow7.a0P 150 - 1 + (i + 1) rw [ha0]; omega rw [hg', gq (Shadow7.a0P 150 - 1 + (i + 1)) (by rw [ha0]; omega) (by rw [ha0]; omega), hF_low (i + 1) (by omega), Nat.testBit_div_two]) have hlen : smallA150.length = 11 := rfl rw [hlen] at hv rw [hv, F150_eq, Nat.div_div_eq_div_mul, ← pow_succ] rw [hfull_eq, hrest.2.2, show smallM150.length = 11 from rfl, gReg, gBorrow] simp only [copyValue, gLatch, decide_eq_true_eq] have hrt := LeaveRestoreTruth.restored_shadow7 173 11 z h.endSmall u.2 dsimp only at hrt exact hrt have hfull_keep (q : Nat) (n7 : q ≠ 1557) (n8 : q ≠ 1558) (hM : q ∉ smallM150) : (run full150Prog m s).basis q = hst.basis q := by rw [hfull_eq, hrest.2.1 q hM, gq q n7 n8] have hnotA : (Shadow7.a0P 150 - 1 : Wire) ∉ smallM150 := by decide have hnotB : (Shadow7.b0P 150 - 1 : Wire) ∉ smallM150 := by decide have hfull_1557 : (run full150Prog m s).basis 1557 = !(run full150Prog m s).basis (Shadow7.a0P 150 - 1) := by rw [hfull_eq, hrest.2.1 _ (by decide), hrest.2.1 _ hnotA, g57, gq _ na.1 na.2] have hfull_1558 : (run full150Prog m s).basis 1558 = ((run full150Prog m s).basis (Shadow7.b0P 150 - 1) && (run full150Prog m s).basis 1557) := by rw [hfull_1557, hfull_eq, hrest.2.1 _ (by decide), hrest.2.1 _ hnotB, hrest.2.1 _ hnotA, g58, gq _ nb.1 nb.2, gq _ na.1 na.2] have hfull_ph : (run full150Prog m s).phase = s.phase := by rw [hfull_eq, hrest.1, gph, hst_ph] -- release the mask let nRel := m.drop (measurementCount full150Prog) let uRel := run releaseMaskP150 nRel (run full150Prog m s) have huRel : uRel = ⟨(run full150Prog m s).phase, writeBit (writeBit (run full150Prog m s).basis 1557 false) 1558 false⟩ := by dsimp only [uRel]; rw [releaseMaskP150_eq] exact LeaveJ7.release_ok MixedWindow.j7 (by decide) hi (run full150Prog m s) nRel hfull_1557 hfull_1558 have hrel_keep (q : Nat) (h7 : q ≠ 1557) (h8 : q ≠ 1558) : uRel.basis q = (run full150Prog m s).basis q := by rw [huRel]; simp [writeBit, h7, h8] let nSM := nRel.drop (measurementCount releaseMaskP150) have hclean_pen : ∀ p ∈ pendingPairs150, uRel.basis p.2 = false := by clear hmag_smallM hrest rintro ⟨pa, q⟩ hp have hr := geom150_check.2.2.2.2.2.1 (pa, q) hp dsimp only at hr ⊢ unfold Wire at * have hq_r : (1559 ≤ q ∧ q ≤ 1597) ∨ (1613 ≤ q ∧ q + 2 < 1747) := by rcases hr with ⟨lo, hi'⟩ | ⟨lo, hi'⟩ · exact Or.inl ⟨lo, hi'⟩ · rw [he0] at hi'; exact Or.inr ⟨lo, hi'⟩ have hq7 : q ≠ 1557 ∧ q ≠ 1558 ∧ 972 ≤ q := by rcases hq_r with ⟨_, _⟩ | ⟨_, _⟩ <;> omega have hnotM : q ∉ smallM150 := not_mem_smallM150 q (Or.inr hq7.2.2) rw [hrel_keep q hq7.1 hq7.2.1, hfull_keep q hq7.1 hq7.2.1 hnotM] rcases hq_r with ⟨lo, hi'⟩ | ⟨lo, hi'⟩ · rw [show q = 1559 + (q - 1559) by omega] exact hret ⟨q - 1559, by omega⟩ · have e1 : q ∉ (1556 : Wire) :: (1557 : Wire) :: (1558 : Wire) :: LeaveJ7.fullM MixedWindow.j7 := by simp only [List.mem_cons, not_or] refine ⟨by omega, by omega, by omega, ?_⟩ intro hm; obtain ⟨i, hi2, e⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi2 rw [show start MixedWindow.j7 = 150 from rfl, hb0] at e; omega have e2 : q < 150 + 16 ∨ 150 + 30 < q := Or.inr (by omega) have e3 : q ≠ Shadow7.e0P 150 + 5 := by rw [he0]; omega have hq976 : ¬ (q < 976) := by omega have e4 : q ∉ RailPair.sites (LeaveJ7.scanPairs MixedWindow.j7) := fun hm => hq976 (scan150_sites_lt q hm) have n1 : q ≠ 364 ∧ q ≠ 984 ∧ q ≠ 365 ∧ q ≠ 985 ∧ 1556 ≤ q := by omega have hraw : q ∈ LeaveJ7.CoreCheckpoint.rawSites MixedWindow.j7 := by simp only [LeaveJ7.CoreCheckpoint.rawSites, List.mem_append, List.mem_range'_1] left; left; exact ⟨lo, by rw [show start MixedWindow.j7 = 150 from rfl, he0]; omega⟩ rw [hst_basis q n1.1 n1.2.1 n1.2.2.1 n1.2.2.2.1, ← hst_eq, hck.2.2.1 q hraw] exact LeaveJ7.native_carryJ_lt MixedWindow.j7 (by decide) hi _ s h.ready q n1.2.2.2.2 (by rw [show start MixedWindow.j7 = 150 from rfl, he0]; exact hi') have hclean_clr : ∀ p ∈ clearFlagPairs150, uRel.basis p.2 = false := by clear hmag_smallM hrest intro p hp have hr := geom150_check.2.2.2.2.2.2 p hp let q : Nat := p.2 have hq_r : 1559 ≤ q ∧ q ≤ 1597 := hr have hnotM : p.2 ∉ smallM150 := not_mem_smallM150 p.2 (Or.inr (by change 972 ≤ q; omega)) change uRel.basis q = false rw [hrel_keep q (by omega) (by omega), hfull_keep q (by omega) (by omega) hnotM] rw [show q = 1559 + (q - 1559) by omega] exact hret ⟨q - 1559, by omega⟩ have hpen_any : (PortalAnd.digits 1558 pendingPairs150).any uRel.basis = decide (Shadow.far 163 20 a) := by clear hrest change (uRel.basis 1558 || (pendingPairs150.map Prod.fst).any uRel.basis) = _ rw [show uRel.basis 1558 = false by rw [huRel]; simp [writeBit], Bool.false_or] have hscan_eq : regValue (pendingPairs150.map Prod.fst) uRel.basis = (a.u + a.v) / 2 ^ 184 := by have hfit : LeaveJ7.TrueMiddle.F MixedWindow.j7 z < 2 ^ 84 := h.fit apply Nat.eq_of_testBit_eq; intro i have hlen : (pendingPairs150.map Prod.fst).length = 73 := by rw [pending150_fst]; simp only [List.length_cons, List.length_map, List.length_range]; decide by_cases hi' : i < 73 · rw [← HighBankAdjust.bit_read (pendingPairs150.map Prod.fst) i uRel.basis (by rw [hlen]; exact hi')] rw [Nat.testBit_div_two_pow] cases i with | zero => have hg0 : (pendingPairs150.map Prod.fst).getD 0 0 = Shadow7.a0P 150 - 1 + 11 := by rw [pending150_fst]; show Shadow7.a0P 150 + lows150 - 2 = Shadow7.a0P 150 - 1 + 11; rw [ha0, hlow12] rw [hg0, hrel_keep _ (by rw [ha0]; decide) (by rw [ha0]; decide), hfull_keep _ (by rw [ha0]; decide) (by rw [ha0]; decide) (by rw [ha0]; decide), hF_low 11 (by decide), F150_eq, Nat.testBit_div_two_pow] | succ k => have hlw : Shadow7.liveW 150 = 84 := by decide have hgk : (pendingPairs150.map Prod.fst).getD (k + 1) 0 = Shadow7.bankW 150 (12 + k) := by rw [pending150_fst, List.getD_cons_succ, List.getD_eq_getElem?_getD, List.getElem?_map, List.getElem?_range (by rw [hlw, hlow12]; omega)]; rw [hlow12]; rfl have hnot78 := bankW150_ne_store ⟨k, by omega⟩ rw [hgk, hrel_keep _ hnot78.1 hnot78.2.1, hfull_keep _ hnot78.1 hnot78.2.1 hnot78.2.2, hF_hi (12 + k) (by omega) (by rw [hwp]; omega), F150_eq, Nat.testBit_div_two_pow, show 12 + k + 173 = k + 1 + 184 by omega] · rw [Nat.testBit_lt_two_pow ((regValue_lt _ _).trans_le (Nat.pow_le_pow_right (by decide) (by rw [hlen]; omega)))] have hlt : (a.u + a.v) / 2 ^ 184 < 2 ^ 73 := by rw [F150_eq] at hfit have e : (a.u + a.v) / 2 ^ 184 = (a.u + a.v) / 2 ^ 173 / 2 ^ 11 := by rw [Nat.div_div_eq_div_mul, ← Nat.pow_add] rw [e] exact Nat.div_lt_of_lt_mul (by rw [← Nat.pow_add]; exact hfit) rw [Nat.testBit_lt_two_pow (hlt.trans_le (Nat.pow_le_pow_right (by decide) (by omega)))] rw [LeaveCompanion.any_positive, hscan_eq] have hiff : 0 < (a.u + a.v) / 2 ^ 184 ↔ Shadow.far 163 20 a := by unfold Shadow.far Shadow.high Shadow.limb rw [Nat.pos_iff_ne_zero, ne_eq, Nat.div_eq_zero_iff, not_or] have hdiv : 2 ≤ (a.u + a.v) / 2 ^ (163 + 20) ↔ 2 * 2 ^ (163 + 20) ≤ a.u + a.v := Nat.le_div_iff_mul_le (by positivity) rw [hdiv, show (2 : Nat) * 2 ^ (163 + 20) = 2 ^ 184 by rw [← Nat.pow_succ']] constructor <;> intro hh · exact Nat.le_of_not_lt hh.2 · exact ⟨by positivity, Nat.not_lt.mpr hh⟩ exact decide_eq_decide.mpr hiff have hsm_run : run (GateMirror.forward leaveStoreMapped150) nSM uRel = ⟨uRel.phase, writeBit (writeBit (writeBit uRel.basis 1557 (decide (Shadow.far 163 20 a))) 1558 (decide (Shadow.far 163 20 a) && decide (2 ^ 163 ≤ a.u))) 1556 false⟩ := by let f20 := decide (Shadow.far 163 20 a) let u20 := f20 && decide (2 ^ 163 ≤ a.u) have h56R : uRel.basis 1556 = decide (2 ^ 173 ≤ mag) := by rw [hrel_keep 1556 (by decide) (by decide), hfull_keep 1556 (by decide) (by decide) (by decide), h56] have hside : (uRel.basis 1556 && f20) = u20 := by rw [h56R] by_cases hf : Shadow.far 163 20 a · simp only [f20, u20, hf, decide_true, Bool.and_true, Bool.true_and] exact decide_eq_decide.mpr (nextFlag150_orientation a sign.toNat (by cases sign <;> decide) nextSmall20 hf) · simp [f20, u20, hf] have h1 := PortalAnd.run_latch true none 1557 1558 pendingPairs150 geom150_check.2.1 (by simp) uRel nSM hclean_pen simp only [PortalAnd.active, Option.elim_none, Bool.true_and] at h1 rw [hpen_any, show uRel.basis 1557 = false by rw [huRel]; simp [writeBit], Bool.false_xor] at h1 let st1 : State := ⟨uRel.phase, writeBit uRel.basis 1557 f20⟩ have h2 : run ([.CCX 1556 1557 1558] : Program) (nSM.drop (measurementCount (latch true none 1557 1558 pendingPairs150))) st1 = ⟨uRel.phase, writeBit st1.basis 1558 u20⟩ := by rw [LeaveJ7.nextU_run st1 _ (by simp [st1, writeBit, huRel])] simp [st1, writeBit, hside] let st2 : State := ⟨uRel.phase, writeBit st1.basis 1558 u20⟩ have h3 : run (latch true none 1556 1558 clearFlagPairs150) ((nSM.drop (measurementCount (latch true none 1557 1558 pendingPairs150))).drop (measurementCount [.CCX 1556 1557 1558])) st2 = ⟨uRel.phase, writeBit st2.basis 1556 false⟩ := by have hr := PortalAnd.run_latch true none 1556 1558 clearFlagPairs150 geom150_check.2.2.1 (by simp) st2 ((nSM.drop (measurementCount (latch true none 1557 1558 pendingPairs150))).drop (measurementCount [.CCX 1556 1557 1558])) (fun p hp => by have hr' := geom150_check.2.2.2.2.2.2 p hp simp only [st2, st1, writeBit, Function.update_of_ne (show p.2 ≠ 1558 by unfold Wire at *; omega), Function.update_of_ne (show p.2 ≠ 1557 by unfold Wire at *; omega)] exact hclean_clr p hp) simp only [PortalAnd.active, Option.elim_none, Bool.true_and] at hr have hdig : PortalAnd.digits 1558 clearFlagPairs150 = 1558 :: (Shadow7.b0P 150 - 1) :: smallM150 := by decide rw [hr, hdig] have hst2_keep : ∀ q : Wire, q ≠ 1557 → q ≠ 1558 → st2.basis q = uRel.basis q := fun q h7 h8 => by simp [st2, st1, writeBit, h7, h8] have hlow_b0 : st2.basis (Shadow7.b0P 150 - 1) = decide (2 ^ 173 ≤ mag % (2 * 2 ^ 173)) := by rw [hst2_keep _ (by decide) (by decide), hrel_keep _ (by decide) (by decide), hfull_keep _ nb.1 nb.2 hnotB, hbB, LeaveCompanion.thresholdBit _ _ (Nat.two_pow_pos _)] have hup_sm : regValue smallM150 st2.basis = (mag / (2 * 2 ^ 173)) % 2 ^ smallM150.length := by rw [(regValue_eq_iff _ _ _).mpr (fun q hq => by have hne : q ≠ 1557 ∧ q ≠ 1558 := by obtain ⟨i, hi', rfl⟩ := List.mem_map.mp hq; rw [List.mem_range] at hi' exact ⟨by rw [hb0]; unfold Wire; omega, by rw [hb0]; unfold Wire; omega⟩ rw [hst2_keep q hne.1 hne.2, hrel_keep q hne.1 hne.2]), hmag_smallM] rw [show (2 : Nat) * 2 ^ 173 = 2 ^ 174 by rw [← Nat.pow_succ']]; rfl have h56_st2 : st2.basis 1556 = decide (2 ^ 173 ≤ mag) := by rw [hst2_keep 1556 (by decide) (by decide), h56R] have h58_st2 : st2.basis 1558 = (st2.basis 1556 && st2.basis 1557) := by rw [show st2.basis 1558 = u20 by simp [st2, writeBit], show st2.basis 1557 = f20 by simp [st2, st1, writeBit], hst2_keep 1556 (by decide) (by decide), hside] have hnear_st2 : st2.basis 1557 = false → mag < (2 * 2 ^ 173) * 2 ^ smallM150.length := fun hf => nextFlag150_boundNear a sign.toNat (of_decide_eq_false (by simpa [st2, st1, writeBit, f20] using hf)) have hwid : 2 ^ 173 ≤ (2 * 2 ^ 173) * 2 ^ smallM150.length := by have := Nat.mul_le_mul_left (2 * 2 ^ 173) (Nat.one_le_two_pow (n := smallM150.length)); omega simp only [List.any_cons, LeaveCompanion.any_positive, hup_sm, hlow_b0, h58_st2, h56_st2] rw [LeaveCompanion.lower_nonzero (2 ^ 173) _ mag (Nat.two_pow_pos _), LeaveCompanion.retain_flag (2 ^ 173) _ mag _ hwid hnear_st2] simp [st2, st1] rw [storeMapped150_parts, run_append, run_take, h1, run_append, run_take, h2, h3] have hbs_eq : run beforeStore150Prog m s = run (GateMirror.forward leaveStoreMapped150) nSM uRel := by simp only [beforeStore150Prog, run_append, run_take, nRel, uRel, nSM] have hbs_ph : (run beforeStore150Prog m s).phase = s.phase := by rw [hbs_eq, hsm_run]; show uRel.phase = _; rw [huRel]; exact hfull_ph have hbs_frame (q : Nat) (h6 : q ≠ 1556) (h7 : q ≠ 1557) (h8 : q ≠ 1558) (hM : q ∉ smallM150) : (run beforeStore150Prog m s).basis q = hst.basis q := by rw [hbs_eq, hsm_run]; simp only [writeBit, Function.update_of_ne h6, Function.update_of_ne h8, Function.update_of_ne h7] rw [hrel_keep q h7 h8, hfull_keep q h7 h8 hM] have hswap_frame (q : Nat) (h1 : q ≠ 364) (h2 : q ≠ 984) (h3 : q ≠ 365) (h4 : q ≠ 985) : hst.basis q = (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s).basis q := by rw [hst_eq]; exact hst_basis q h1 h2 h3 h4 rw [hhst_def] refine ⟨hbs_ph, ?_, ?_, ?_, ?_, ?_, ?_, ?_, hbs_frame, hswap_frame⟩ · rw [hbs_eq, hsm_run]; simp only [writeBit, Function.update_self] · rw [hbs_eq, hsm_run]; simp only [writeBit, Function.update_of_ne (by decide : (1557 : Wire) ≠ 1556), Function.update_of_ne (by decide : (1557 : Wire) ≠ 1558), Function.update_self]; rfl · rw [hbs_eq, hsm_run]; simp only [writeBit, Function.update_of_ne (by decide : (1558 : Wire) ≠ 1556), Function.update_self]; rfl · rw [hbs_frame _ (by decide) (by decide) (by decide) (by decide), hst_basis _ (by decide) (by decide) (by decide) (by decide), keepE _ (by unfold LeaveJ7.midT LeaveJ7.workT; decide)] exact hfront.2.2.1.trans (LeaveRestoreTruth.truth_shadow7 173 z h.farSmall u.2).1.symm · intro q hq unfold LeaveJ7.history at hq; rw [show start MixedWindow.j7 = 150 from rfl] at hq obtain ⟨i, hi', rfl⟩ := List.mem_map.mp hq; rw [List.mem_range] at hi' rw [hbs_frame (150 + 16 + i) (by omega) (by omega) (by omega) (not_mem_smallM150 _ (Or.inl (by change (150 : Nat) + 16 + i < 960; omega))), hst_basis (150 + 16 + i) (by omega) (by omega) (by omega) (by omega), keepE (150 + 16 + i) (by unfold LeaveJ7.midT LeaveJ7.workT; rw [show start MixedWindow.j7 = 150 from rfl, ha0, hb0, he0]; omega)] unfold LeaveSelector.parityBits LeaveJ7.oddRead at hpar0 exact (List.map_inj_left.mp hpar0) i (List.mem_range.mpr hi') · rintro ⟨k, hk⟩ cases k with | zero => simp only [Nat.add_zero] constructor · rw [hbs_frame _ (by decide) (by decide) (by decide) hnotA, hbA, Nat.testBit_div_two_pow, Nat.zero_add] · rw [hbs_frame _ (by decide) (by decide) (by decide) hnotB, hbB, Nat.testBit_div_two_pow, Nat.zero_add] | succ k => have hka : Shadow7.a0P 150 - 1 + (k + 1) = Shadow7.a0P 150 + k := by rw [ha0]; omega have hkb : Shadow7.b0P 150 - 1 + (k + 1) = Shadow7.b0P 150 + k := by rw [hb0]; omega constructor · rw [hka, hbs_frame (Shadow7.a0P 150 + k) (by rw [ha0]; omega) (by rw [ha0]; omega) (by rw [ha0]; omega) (not_mem_smallM150 _ (Or.inl (by change Shadow7.a0P 150 + k < 960; rw [ha0]; omega))), ← hka, hF_low (k + 1) (by omega), F150_eq, Nat.testBit_div_two_pow, show k + 1 + 173 = 173 + (k + 1) by omega] · rw [hkb, hbs_eq, hsm_run] simp only [writeBit, Function.update_of_ne (show (Shadow7.b0P 150 + k : Wire) ≠ 1556 by rw [hb0]; omega), Function.update_of_ne (show (Shadow7.b0P 150 + k : Wire) ≠ 1558 by rw [hb0]; omega), Function.update_of_ne (show (Shadow7.b0P 150 + k : Wire) ≠ 1557 by rw [hb0]; omega)] rw [hrel_keep (Shadow7.b0P 150 + k) (by rw [hb0]; omega) (by rw [hb0]; omega)] have hlenM : smallM150.length = 11 := rfl have hbit := HighBankAdjust.bit_read smallM150 k (run full150Prog m s).basis (by rw [hlenM]; omega) have hg : smallM150.getD k 0 = Shadow7.b0P 150 + k := by simp only [smallM150, lows150, List.getD_eq_getElem?_getD, List.getElem?_map, List.getElem?_range (show k < 12 - 1 by omega), Option.map_some, Option.getD_some] rw [hg, hmag_smallM, Nat.testBit_mod_two_pow, decide_eq_true (show k < 11 by omega), Bool.true_and, Nat.testBit_div_two_pow, show k + 174 = 173 + (k + 1) by omega] at hbit exact hbit · intro i have hi' : i.val < 73 := Nat.lt_of_lt_of_eq i.isLt (by rw [hwp20]) exact hF_hi (lows150 + i.val) (by rw [hlow12]; omega) (by rw [hwp, hlow12]; omega) private theorem lowClose150_result (s : State) (m : List Bool) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) : let a := step^[15] z let u := LeaveJ7.Admission.flags z g0 s0 let sign := PortalValues.negative u.2 a.u let mag := a.u - sign.toNat let mid := run storeMapped150Prog m s mid.phase = s.phase ∧ (∀ q ∈ LeaveJ7.history MixedWindow.j7, mid.basis q = s.basis q) ∧ (∀ i : Fin 12, let pos := (a.u + a.v).testBit (173 + i.val) let neg := mag.testBit (173 + i.val) ^^ sign mid.basis (Shadow7.a0P 150 - 1 + i.val) = (if u.1 then neg else pos) ∧ mid.basis (Shadow7.b0P 150 - 1 + i.val) = (if u.1 then pos else neg)) ∧ (∀ q, q ∉ RailPair.sites low150 → q ∉ LeaveJ7.history MixedWindow.j7 → mid.basis q = (run beforeStore150Prog m s).basis q) := by let a := step^[15] z let u := LeaveJ7.Admission.flags z g0 s0 let sign := PortalValues.negative u.2 a.u let mag := a.u - sign.toNat obtain ⟨hbs_ph, _, _, _, hlc_sign, hlc_hist, hlc_words, _, _, _⟩ := beforeStore150_result s m z g0 s0 h nextSmall20 have hlc_prev : s.basis 180 = u.1 := by have hr := h.ready.2.2.1 change s.basis (start MixedWindow.j7 + 30) = u.1 rw [(LeaveJ7.scan_ports MixedWindow.j7 (by decide) (by decide)).2.2.2.2.1] cases h1 : u.1 <;> simpa only [u, h1] using hr let nLC := m.drop (measurementCount beforeStore150Prog) have hndH : (LeaveJ7.history MixedWindow.j7).Nodup := by decide have hw := RailPair.store_run 180 (Shadow7.e0P 150 + 5) low150 [] geom150_check.2.2.2.1 ⟨(run beforeStore150Prog m s).phase, fun q => if q ∈ LeaveJ7.history MixedWindow.j7 then !(run beforeStore150Prog m s).basis q else (run beforeStore150Prog m s).basis q⟩ (nLC.drop (measurementCount (notRegister (LeaveJ7.history MixedWindow.j7)))) (by simp) have hsep : ∀ q ∈ LeaveJ7.history MixedWindow.j7, q ∉ RailPair.sites low150 := by decide have h180_mem : (180 : Wire) ∈ LeaveJ7.history MixedWindow.j7 := by decide have hnot_hist_e5 : (Shadow7.e0P 150 + 5 : Wire) ∉ LeaveJ7.history MixedWindow.j7 := by decide have hsm_split : run storeMapped150Prog m s = run (RailPair.store 180 (Shadow7.e0P 150 + 5) low150 []) (nLC.drop (measurementCount (notRegister (LeaveJ7.history MixedWindow.j7)))) ⟨(run beforeStore150Prog m s).phase, fun q => if q ∈ LeaveJ7.history MixedWindow.j7 then !(run beforeStore150Prog m s).basis q else (run beforeStore150Prog m s).basis q⟩ := by simp only [storeMapped150Prog, run_append, run_take, lowClose150_parts, nLC] rw [notRegister_correct _ hndH] dsimp only; rw [hsm_split] refine ⟨hw.1.trans hbs_ph, ?_, ?_, ?_⟩ · intro q hq; rw [hw.2.1 q (hsep q hq) (by simp [RailPair.sites])]; dsimp only; rw [if_pos hq, hlc_hist q hq, Bool.not_not] · intro i have hmem : (Shadow7.a0P 150 - 1 + i.val, Shadow7.b0P 150 - 1 + i.val) ∈ low150 := List.mem_map.mpr ⟨i.val, List.mem_range.mpr i.isLt, rfl⟩ have hl := hw.2.2.2 _ hmem have hnh1 : (Shadow7.a0P 150 - 1 + i.val : Wire) ∉ LeaveJ7.history MixedWindow.j7 := by have : ∀ k : Fin 12, (Shadow7.a0P 150 - 1 + k.val : Wire) ∉ LeaveJ7.history MixedWindow.j7 := by decide exact this i have hnh2 : (Shadow7.b0P 150 - 1 + i.val : Wire) ∉ LeaveJ7.history MixedWindow.j7 := by have : ∀ k : Fin 12, (Shadow7.b0P 150 - 1 + k.val : Wire) ∉ LeaveJ7.history MixedWindow.j7 := by decide exact this i simp only [if_pos h180_mem, hlc_hist 180 h180_mem, Bool.not_not, hlc_prev, if_neg hnot_hist_e5, hlc_sign, if_neg hnh1, if_neg hnh2, (hlc_words i).1, (hlc_words i).2] at hl exact hl · intro q hnl hnh; rw [hw.2.1 q hnl (by simp [RailPair.sites])]; dsimp only; rw [if_neg hnh] private theorem mid150_eq_stock (s : State) (m : List Bool) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) (q : Wire) (hq : q = Shadow7.e0P 150 + 3 ∨ q = Shadow7.e0P 150 + 4 ∨ q = Shadow7.e0P 150 + 6 ∨ q = Shadow7.e0P 150 + 7 ∨ (∃ p ∈ LeaveJ7.Close.events MixedWindow.j7, q = p.1 ∨ q = p.2)) : (run storeMapped150Prog m s).basis q = (run (LeaveJ7.StoreMapped.program MixedWindow.j7) [] s).basis q := by let u := LeaveJ7.Admission.flags z g0 s0 obtain ⟨_, hbs_1556, _, _, _, _, _, _, hbs_frame, hst_basis⟩ := beforeStore150_result s m z g0 s0 h nextSmall20 have hlc_frame := (lowClose150_result s m z g0 s0 h nextSmall20).2.2.2 have par := LeaveJ7.RecordedParity.result MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record have mode : LeaveSelector.actualMode (Shadow7.sbP 150) z = LeaveSelector.farMode (s.basis (Shadow7.e0P 150 + 3)) (s.basis (Shadow7.e0P 150 + 4)) z.u := by have hf := h.far; have hs := h.side rw [show start MixedWindow.j7 = 150 from rfl] at hf hs rw [hf, hs]; exact LeaveTraceHistory.flags _ _ have ev := LeaveJ7.RecordedEvents.result MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record have hbsStock := LeaveJ7.BeforeStore.result MixedWindow.j7 (by decide) (by decide) s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 ⟨h.nextFarSmall, h.endSmall⟩ h.fit (LeaveJ7.RecordedEvents.glueFlag MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record h.far h.side) have hsm_st := (LeaveJ7.StoreMapped.result MixedWindow.j7 (by decide) (by decide) s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 ⟨h.nextFarSmall, h.endSmall⟩ h.fit (LeaveJ7.RecordedEvents.glueFlag MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record h.far h.side)).2.2.2 have haway : q ≠ 364 ∧ q ≠ 984 ∧ q ≠ 365 ∧ q ≠ 985 ∧ q ∉ RailPair.sites low150 ∧ q ∉ LeaveJ7.history MixedWindow.j7 ∧ q ∉ smallM150 ∧ q ≠ 1557 ∧ q ≠ 1558 ∧ q ∉ RailPair.sites (LeaveJ7.Close.low MixedWindow.j7) ∧ q ∉ LeaveJ7.smallM MixedWindow.j7 := by have hlist : q ∈ [Shadow7.e0P 150 + 3, Shadow7.e0P 150 + 4, Shadow7.e0P 150 + 6, Shadow7.e0P 150 + 7] ++ (LeaveJ7.Close.events MixedWindow.j7).flatMap (fun p => [p.1, p.2]) := by simp only [List.mem_append, List.mem_cons, List.not_mem_nil, or_false, List.mem_flatMap] rcases hq with rfl | rfl | rfl | rfl | ⟨p, hp, rfl | rfl⟩ · exact Or.inl (Or.inl rfl) · exact Or.inl (Or.inr (Or.inl rfl)) · exact Or.inl (Or.inr (Or.inr (Or.inl rfl))) · exact Or.inl (Or.inr (Or.inr (Or.inr rfl))) · exact Or.inr ⟨p, hp, Or.inl rfl⟩ · exact Or.inr ⟨p, hp, Or.inr rfl⟩ exact events150_away q hlist rw [hlc_frame q haway.2.2.2.2.1 haway.2.2.2.2.2.1, hsm_st q haway.2.2.2.2.2.2.2.2.2.1 haway.2.2.2.2.2.1] by_cases h56 : q = 1556 · subst h56; rw [hbs_1556, hbsStock.2.1] · rw [hbs_frame q h56 haway.2.2.2.2.2.2.2.1 haway.2.2.2.2.2.2.2.2.1 haway.2.2.2.2.2.2.1, hst_basis q haway.1 haway.2.1 haway.2.2.1 haway.2.2.2.1, hbsStock.2.2.2.2.2.2 q h56 haway.2.2.2.2.2.2.2.1 haway.2.2.2.2.2.2.2.2.1] exact (stock_full_eq_head150 s z g0 s0 h q haway.2.2.2.2.2.2.2.2.2.2 haway.2.2.2.2.2.2.2.1 haway.2.2.2.2.2.2.2.2.1).symm theorem whole150_result (s : State) (m : List Bool) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) : let a := step^[15] z let u := LeaveJ7.Admission.flags z g0 s0 let sign := PortalValues.negative u.2 a.u let mag := a.u - sign.toNat let f15 := decide (Shadow.far (Shadow7.sbP 150) 15 z) let next := decide (Shadow.far 163 20 a) let xs := SkywalkTrace.trace 15 (SkywalkRails.encode g0 s0 z.u z.v) let out := run leave150To20 m s let mid := run storeMapped150Prog m s out.phase = s.phase ∧ out.basis (e0P20 165 + 3) = next ∧ out.basis (e0P20 165 + 4) = (next && decide (2 ^ 163 ≤ a.u)) ∧ out.basis (e0P20 165 + 5) = sign ∧ out.basis (e0P20 165 + 6) = f15 ∧ out.basis (e0P20 165 + 7) = (f15 && StairArchiveTrace.afterFlags (decide (2 ^ (Shadow7.sbP 150) ≤ z.u)) (xs.take 5)) ∧ out.basis (e0P20 165 + 8) = (f15 && HighBankSum.crossBit (LeaveJ7.TrueMiddle.d MixedWindow.j7 z)) ∧ (∀ q ∈ LeaveJ7.Close.history MixedWindow.j7, out.basis q = s.basis q) ∧ (∀ i : Fin 12, let pos := (a.u + a.v).testBit (173 + i.val) let neg := mag.testBit (173 + i.val) ^^ sign out.basis (Shadow7.a0P 150 - 1 + i.val) = (if u.1 then neg else pos) ∧ out.basis (Shadow7.b0P 150 - 1 + i.val) = (if u.1 then pos else neg)) ∧ (∀ i : Fin (wpP20 165 - 2), out.basis (Shadow7.b0P 150 + lows150 - 1 + i.val) = (a.u + a.v).testBit (173 + lows150 + i.val)) ∧ (∀ q, out.basis q = writeBit mid.basis (Shadow7.e0P 150 + 4) false (LeaveRelocation.source movesP150To20 q)) ∧ (run beforeStore150Prog m s).basis 1556 = false ∧ (∀ q : Nat, q ≠ 1556 → q ≠ 1557 → q ≠ 1558 → q ∉ smallM150 → (run beforeStore150Prog m s).basis q = (run head150Prog m s).basis q) ∧ (∀ q, q ∉ RailPair.sites low150 → q ∉ LeaveJ7.history MixedWindow.j7 → mid.basis q = (run beforeStore150Prog m s).basis q) := by let a := step^[15] z let u := LeaveJ7.Admission.flags z g0 s0 let sign := PortalValues.negative u.2 a.u let mag := a.u - sign.toNat let xs := SkywalkTrace.trace 15 (SkywalkRails.encode g0 s0 z.u z.v) have hsb : Shadow7.sbP 150 = 173 := by decide obtain ⟨_, hbs_1556, hbs_1557, hbs_1558, hlc_sign, _, _, hF_hi, hbs_frame, _⟩ := beforeStore150_result s m z g0 s0 h nextSmall20 have hlc_run := lowClose150_result s m z g0 s0 h nextSmall20 have hmid_eq_stock := mid150_eq_stock s m z g0 s0 h nextSmall20 have par := LeaveJ7.RecordedParity.result MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record have mode : LeaveSelector.actualMode (Shadow7.sbP 150) z = LeaveSelector.farMode (s.basis (Shadow7.e0P 150 + 3)) (s.basis (Shadow7.e0P 150 + 4)) z.u := by have hf := h.far; have hs := h.side rw [show start MixedWindow.j7 = 150 from rfl] at hf hs rw [hf, hs]; exact LeaveTraceHistory.flags _ _ have ev := LeaveJ7.RecordedEvents.result MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record have hpostStock := LeaveJ7.PostReady.result MixedWindow.j7 (by decide) (by decide) s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 ⟨h.nextFarSmall, h.endSmall⟩ h.fit (LeaveJ7.RecordedEvents.glueFlag MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record h.far h.side) have hp3 : (run (LeaveJ7.StoreMapped.program MixedWindow.j7) [] s).basis (Shadow7.e0P 150 + 3) = s.basis (Shadow7.e0P 150 + 3) := hpostStock.1 have hp4 : (run (LeaveJ7.StoreMapped.program MixedWindow.j7) [] s).basis (Shadow7.e0P 150 + 4) = s.basis (Shadow7.e0P 150 + 4) := hpostStock.2.1 have hp7 : (run (LeaveJ7.StoreMapped.program MixedWindow.j7) [] s).basis (Shadow7.e0P 150 + 7) = LeaveSelector.nearby (LeaveSelector.actualMode (Shadow7.sbP 150) z) := hpostStock.2.2.1 have hp6 : (run (LeaveJ7.StoreMapped.program MixedWindow.j7) [] s).basis (Shadow7.e0P 150 + 6) = (decide (Shadow.far (Shadow7.sbP 150) 15 z) && HighBankSum.crossBit (LeaveJ7.TrueMiddle.d MixedWindow.j7 z)) := hpostStock.2.2.2.1 have hpEv := hpostStock.2.2.2.2 let mid := run storeMapped150Prog m s let nCl := m.drop (measurementCount storeMapped150Prog) have hcl_run : run (GateMirror.forward leaveClose150To20) nCl mid = ⟨mid.phase, fun q => (writeBit mid.basis (Shadow7.e0P 150 + 4) false) (LeaveRelocation.source movesP150To20 q)⟩ := by have hcold : ∀ p ∈ LeaveJ7.Close.events MixedWindow.j7, mid.basis p.2 = false := fun p hp => (hmid_eq_stock p.2 (Or.inr (Or.inr (Or.inr (Or.inr ⟨p, hp, Or.inr rfl⟩))))).trans (hpEv p hp).2 have hreads : (LeaveJ7.Close.events MixedWindow.j7).map (fun p => mid.basis p.1) = (xs.take 5).map Prod.snd := (List.map_congr_left fun p hp => (hmid_eq_stock p.1 (Or.inr (Or.inr (Or.inr (Or.inr ⟨p, hp, Or.inl rfl⟩))))).trans (hpEv p hp).1).trans ev.1 have hvp := LeavePendingHistory.pending (decide (Shadow.far (Shadow7.sbP 150) 15 z)) (decide (2 ^ (Shadow7.sbP 150) ≤ z.u)) xs ⟨IntegerHigh.wait 15 z.u, by have hw := IntegerHigh.wait_le 15 z.u; omega⟩ (SkywalkTrace.trace_length _ _) (fun hf => LeaveJ7.Far.certifiedChain _ _ _ _ ⟨h.farSmall, h.endSmall⟩ h.odd (of_decide_eq_true hf)) (fun hf hu => LeaveJ7.Far.firstSwap _ _ _ _ ⟨h.farSmall, h.endSmall⟩ h.odd (of_decide_eq_true hf) hu) have hev_all : (LeaveJ7.Close.events MixedWindow.j7).all (fun p => !mid.basis p.1) = !(xs.take 5).any Prod.snd := by have hm : (LeaveJ7.Close.events MixedWindow.j7).any (fun p => mid.basis p.1) = (xs.take 5).any Prod.snd := by simpa only [List.any_map, Function.comp_def, id_eq] using congrArg (List.any · id) hreads rw [← hm]; simp only [List.all_eq_not_any_not, Bool.not_not] have hclr : (mid.basis (Shadow7.e0P 150 + 4) ^^ (mid.basis (Shadow7.e0P 150 + 7) && (LeaveJ7.Close.events MixedWindow.j7).all (fun p => !mid.basis p.1))) = false := by rw [hmid_eq_stock _ (Or.inr (Or.inl rfl)), hmid_eq_stock _ (Or.inr (Or.inr (Or.inr (Or.inl rfl)))), hp4, hp7, show s.basis (Shadow7.e0P 150 + 4) = _ from h.side, hev_all] exact hvp.2 have hrecs150_map : ([OB5.sig 164 1194, OB5.sig 164 1195, OB5.sig 164 1196, OB5.sig 164 1197, OB5.sig 164 1198] : List Wire).map mid.basis = (xs.take 5).map Prod.snd := hreads have hval150 : mid.basis (Shadow7.e0P 150 + 4) = (mid.basis (Shadow7.e0P 150 + 7) && !HighBankControl.parity mid.basis [OB5.sig 164 1194, OB5.sig 164 1195, OB5.sig 164 1196, OB5.sig 164 1197, OB5.sig 164 1198]) := by by_cases hf : Shadow.far (Shadow7.sbP 150) 15 z · have hcp := Shadow7.chain_parity 5 _ xs (LeaveJ7.Far.certifiedChain _ _ _ _ ⟨h.farSmall, h.endSmall⟩ h.odd hf) have hpar : HighBankControl.parity mid.basis [OB5.sig 164 1194, OB5.sig 164 1195, OB5.sig 164 1196, OB5.sig 164 1197, OB5.sig 164 1198] = (xs.take 5).any Prod.snd := by rw [Shadow7.parity_bits, hrecs150_map, hcp] rw [hpar, hmid_eq_stock _ (Or.inr (Or.inl rfl)), hmid_eq_stock _ (Or.inr (Or.inr (Or.inr (Or.inl rfl)))), hp4, hp7, show s.basis (Shadow7.e0P 150 + 4) = _ from h.side] have hxor : ∀ a b : Bool, (a ^^ b) = false → a = b := by decide exact hxor _ _ hvp.2 · rw [hmid_eq_stock _ (Or.inr (Or.inl rfl)), hmid_eq_stock _ (Or.inr (Or.inr (Or.inr (Or.inl rfl)))), hp4, hp7, show s.basis (Shadow7.e0P 150 + 4) = _ from h.side, show start MixedWindow.j7 = 150 from rfl, decide_eq_false hf] have hn0 : LeaveSelector.nearby (LeaveSelector.actualMode (Shadow7.sbP 150) z) = false := by unfold LeaveSelector.actualMode; rw [decide_eq_false hf]; rfl rw [hn0]; rfl have hc56 : mid.basis 1556 = false := hcold (OB5.sig 164 1194, 1556) (by decide) rw [close150_parts, run_append, run_take, Shadow7.closeFlag, Shadow7.parity_run _ _ _ _ mid _ (by decide) (by decide) (by decide) (by decide) (by decide) hc56 hval150, LeaveRelocation.actual _ geom150_check.2.2.2.2.1] have hout_eq : run leave150To20 m s = run (GateMirror.forward leaveClose150To20) nCl mid := by simp only [leave150To20_split, run_append, run_take, mid, nCl] have hrc := reloc150_check have hvp := LeavePendingHistory.pending (decide (Shadow.far (Shadow7.sbP 150) 15 z)) (decide (2 ^ (Shadow7.sbP 150) ≤ z.u)) xs ⟨IntegerHigh.wait 15 z.u, by have hw := IntegerHigh.wait_le 15 z.u; omega⟩ (SkywalkTrace.trace_length _ _) (fun hf => LeaveJ7.Far.certifiedChain _ _ _ _ ⟨h.farSmall, h.endSmall⟩ h.odd (of_decide_eq_true hf)) (fun hf hu => LeaveJ7.Far.firstSwap _ _ _ _ ⟨h.farSmall, h.endSmall⟩ h.odd (of_decide_eq_true hf) hu) dsimp only refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, hbs_1556, hbs_frame, hlc_run.2.2.2⟩ · rw [hout_eq, hcl_run]; exact hlc_run.1 · rw [hout_eq, hcl_run]; dsimp only; rw [hrc.1] simp only [writeBit, Function.update_of_ne (by decide : (1557 : Wire) ≠ Shadow7.e0P 150 + 4)] rw [hlc_run.2.2.2 1557 (by decide) (by decide)]; exact hbs_1557 · rw [hout_eq, hcl_run]; dsimp only; rw [hrc.2.1] simp only [writeBit, Function.update_of_ne (by decide : (1558 : Wire) ≠ Shadow7.e0P 150 + 4)] rw [hlc_run.2.2.2 1558 (by decide) (by decide)]; exact hbs_1558 · rw [hout_eq, hcl_run]; dsimp only; rw [hrc.2.2.1] simp only [writeBit, Function.update_of_ne (by decide : Shadow7.e0P 150 + 5 ≠ Shadow7.e0P 150 + 4)] rw [hlc_run.2.2.2 _ (by decide) (by decide)]; exact hlc_sign · rw [hout_eq, hcl_run]; dsimp only; rw [hrc.2.2.2.1] simp only [writeBit, Function.update_of_ne (by decide : Shadow7.e0P 150 + 3 ≠ Shadow7.e0P 150 + 4)] rw [hmid_eq_stock _ (Or.inl rfl), hp3]; exact h.far · rw [hout_eq, hcl_run]; dsimp only; rw [hrc.2.2.2.2.1] simp only [writeBit, Function.update_of_ne (by decide : Shadow7.e0P 150 + 7 ≠ Shadow7.e0P 150 + 4)] rw [hmid_eq_stock _ (Or.inr (Or.inr (Or.inr (Or.inl rfl)))), hp7] exact hvp.1 · rw [hout_eq, hcl_run]; dsimp only; rw [hrc.2.2.2.2.2.1] simp only [writeBit, Function.update_of_ne (by decide : Shadow7.e0P 150 + 6 ≠ Shadow7.e0P 150 + 4)] rw [hmid_eq_stock _ (Or.inr (Or.inr (Or.inl rfl))), hp6] · intro q hq; obtain ⟨i, hi, rfl⟩ := List.mem_map.mp hq; rw [List.mem_range] at hi rw [hout_eq, hcl_run]; dsimp only rw [show start MixedWindow.j7 + 16 + i = 166 + i from rfl, hrc.2.2.2.2.2.2.1 ⟨i, hi⟩] simp only [writeBit, Function.update_of_ne (show (166 + i : Wire) ≠ Shadow7.e0P 150 + 4 by unfold Shadow7.e0P Shadow7.sbP Wire; omega)] exact hlc_run.2.1 _ hq · intro i rw [hout_eq, hcl_run]; dsimp only rw [(hrc.2.2.2.2.2.2.2.1 i).1, (hrc.2.2.2.2.2.2.2.1 i).2] have h1 : (Shadow7.a0P 150 - 1 + i.val : Wire) ≠ Shadow7.e0P 150 + 4 := by have := i.isLt; unfold Shadow7.a0P Shadow7.e0P Shadow7.sbP Wire; omega have h2 : (Shadow7.b0P 150 - 1 + i.val : Wire) ≠ Shadow7.e0P 150 + 4 := by have := i.isLt; unfold Shadow7.b0P Shadow7.e0P Shadow7.sbP Wire; omega simp only [writeBit, Function.update_of_ne h1, Function.update_of_ne h2] exact hlc_run.2.2.1 i · intro i rw [hout_eq, hcl_run]; dsimp only rw [(hrc.2.2.2.2.2.2.2.2 i).1] have haway := bankW150_away i simp only [writeBit, Function.update_of_ne haway.1] rw [hlc_run.2.2.2 _ haway.2.1 haway.2.2.1, hbs_frame _ haway.2.2.2.1 haway.2.2.2.2.1 haway.2.2.2.2.2.1 haway.2.2.2.2.2.2, hF_hi i] unfold LeaveJ7.TrueMiddle.F HighBankSum.total rw [show start MixedWindow.j7 = 150 from rfl, hsb, Nat.testBit_div_two_pow, show lows150 + i.val + 173 = 173 + lows150 + i.val by omega] · intro q; rw [hout_eq, hcl_run] end Forward150 /-! ### Section 3: Frame Preservation (`leave150To20_keeps`) & Exact Roundtrip (`leave150To20_roundtrip`) -/ private theorem leaveAfter150_box2 : leaveAfter150To20.all (fun g => g.wires.all fun q => decide ((166 ≤ (q : Nat) ∧ (q : Nat) ≤ 180) ∨ (Shadow7.a0P 150 - 1 ≤ (q : Nat) ∧ (q : Nat) ≤ Shadow7.a0P 150 + 15) ∨ (Shadow7.b0P 150 - 1 ≤ (q : Nat) ∧ (q : Nat) ≤ bTopP 150) ∨ (1194 ≤ (q : Nat) ∧ (q : Nat) ≤ 1208) ∨ (1556 ≤ (q : Nat) ∧ (q : Nat) ≤ 1812))) = true ∧ leaveAfter150To20.all (fun g => g.wires.all fun q => decide ((q : Nat) + 150 ≤ 2069)) = true := by decide +kernel private theorem box2_150_consts : Shadow7.a0P 150 = 355 ∧ Shadow7.b0P 150 = 960 ∧ bTopP 150 = 1043 ∧ railP 150 = 258 ∧ railP 164 = 258 ∧ Shadow7.wpP 150 = 70 := by decide private theorem before150_box2 (q : Wire) (h : q ∈ wires (GateMirror.forward (CRTBarrel.before 150))) : Shadow7.leaveBox2 150 q := by have hi : MixedWindow.j7.val ≤ 24 := by decide have pieces := Shadow7.allW_leaveMove (start MixedWindow.j7) (Shadow7.leaveOps_box2 MixedWindow.j7 (Nat.zero_le _) hi) rw [CRTWindow.split_ops, allW_append_iff, allW_append_iff] at pieces have preAll : AllW (Shadow7.leaveBox2 (start MixedWindow.j7)) (DeadJoin.beforeAll (start MixedWindow.j7)) := FlagLeave.cut_allW (Shadow7.e0P (start MixedWindow.j7) + 3) (Shadow7.e0P (start MixedWindow.j7) + 4) 1559 2 (DeadJoin.beforeScan (start MixedWindow.j7)) (DeadJoin.before_scan_allW _ pieces.1) exact (allW_programs (P := Shadow7.leaveBox2 (start MixedWindow.j7)) (ops := CRTBarrel.before (start MixedWindow.j7)) (ScanRowGordo.before5Row_allW MixedWindow.j7 hi (DeadJoin.before5_allW MixedWindow.j7 hi preAll))).1 q h attribute [local irreducible] run CRTBarrel.barrel GateMirror.forward leave150To20 leaveAfter150To20 in theorem leave150To20_keeps (q : Wire) (hq : ¬ Shadow7.leaveBox2 150 q) (m : List Bool) (s : State) : (run leave150To20 m s).basis q = s.basis q := by obtain ⟨ha0, hb0, hbt, hr0, hr14, hwp⟩ := box2_150_consts refine run_preserves_outside leave150To20 m s q (fun hm => hq ?_) unfold leave150To20 at hm; simp only [wires_append, Finset.mem_union] at hm rcases hm with (h | h) | h · exact before150_box2 q h · exact CRTWindow.barrel_box2 MixedWindow.j7 (by decide) (by decide) false q h · have hall : AllW (fun w => Shadow7.leaveBox2 150 w) leaveAfter150To20 := fun g hg w hw => by have h' := of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp leaveAfter150_box2.1 g hg) w hw) unfold Shadow7.leaveBox2; rw [show 150 + 14 = 164 from rfl, hr14, hr0, ha0, hb0, hwp] rw [ha0, hb0, hbt] at h' unfold Wire at *; omega exact (allW_programs hall).1 q h attribute [local irreducible] run CRTBarrel.barrel GateMirror.forward leave150To20 leaveAfter150To20 in theorem leave150To20_keeps_mirror (q : Wire) (lo : 2070 ≤ (q : Nat) + 150) (m : List Bool) (s : State) : (run leave150To20 m s).basis q = s.basis q := by obtain ⟨ha0, hb0, hbt, hr0, hr14, hwp⟩ := box2_150_consts refine run_preserves_outside leave150To20 m s q (fun hm => ?_) have hle : (q : Nat) + 150 ≤ 2069 := by unfold leave150To20 at hm; simp only [wires_append, Finset.mem_union] at hm rcases hm with (h | h) | h · have hbox := before150_box2 q h unfold Shadow7.leaveBox2 at hbox rw [show 150 + 14 = 164 from rfl, hr14, hr0] at hbox unfold Wire at *; omega · have hbox := CRTWindow.barrel_box2 MixedWindow.j7 (by decide) (by decide) false q h unfold Shadow7.leaveBox2 at hbox; rw [show start MixedWindow.j7 = 150 from rfl] at hbox rw [show 150 + 14 = 164 from rfl, hr14, hr0] at hbox unfold Wire at *; omega · have hall : AllW (fun w => (w : Nat) + 150 ≤ 2069) leaveAfter150To20 := fun g hg w hw => of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp leaveAfter150_box2.2 g hg) w hw) exact (allW_programs hall).1 q h unfold Wire at *; omega private def maskSubset150 (a b : Nat) : Bool := (a ||| b) == b private def checkMask150 (gs : List Gate) (post allow : Nat) : Bool := match bitCheck gs post with | some pre => maskSubset150 pre allow | none => false private theorem masked_of_subset150 {s : State} {a b : Nat} (hsub : maskSubset150 a b = true) (hb : Masked s b) : Masked s a := by intro q hq have heq : a ||| b = b := of_decide_eq_true hsub have htb : (a ||| b).testBit q = b.testBit q := congrArg (fun n : Nat => n.testBit q) heq rw [Nat.testBit_or, hq, Bool.true_or] at htb exact hb q htb.symm private theorem ready_of_checkMask150 (gs : List Gate) (s : State) (post allow : Nat) (hc : checkMask150 gs post allow = true) (hallow : Masked s allow) : Ready s gs ∧ Masked (run (GateMirror.forward gs) [] s) post := by unfold checkMask150 at hc cases hx : bitCheck gs post with | none => simp [hx] at hc | some pre => simp only [hx] at hc have hs := bit_sound gs s pre post hx (masked_of_subset150 hc hallow) exact ⟨hs.2.1, hs.2.2⟩ private def storePart1Mid150 : List Gate := let L := lows150 let top := Shadow7.a0P 150 + L - 2 let H := Shadow7.liveW 150 - L let hi := (List.range H).map fun i => Shadow7.bankW 150 (L + i) let seq := fun i => if i = 0 then top else Shadow7.bankW 150 (L + i - 1) [.x top] ++ xsG hi ++ chainG (Shadow7.storeW 150) seq [.cx (Shadow7.storeW 150 (H + 1)) 1557, .x 1557] 0 (H + 1) ++ xsG hi.reverse ++ [.x top] private def storePart1_150 : List Gate := [.x 1558] ++ storePart1Mid150 ++ [.x 1558] private def storePart2_150 : List Gate := let L := lows150 let seq2 := (List.range L).map (Shadow7.b0P 150 - 1 + ·) [.x 1558] ++ xsG seq2 ++ chainG (1558 + ·) (Shadow7.b0P 150 - 1 + ·) [.cx (1558 + L) 1556, .x 1556] 0 L ++ xsG seq2.reverse ++ [.x 1558] private def storeAllow1_150 : Nat := GateMirror.interval 1559 39 ||| GateMirror.interval 1613 (Shadow7.e0P 150 - 1615) private theorem tail150_checks : checkMask150 lowRest150 (1 <<< 1558) (GateMirror.interval (Shadow7.b0P 150) lows150 ||| GateMirror.interval 1559 39 ||| (1 <<< 1558)) = true ∧ checkMask150 storePart1_150 (GateMirror.interval 1559 39) storeAllow1_150 = true ∧ storePart1Mid150.all (fun g => decide (GateMirror.target g ≠ 1558)) = true ∧ checkMask150 storePart2_150 0 (GateMirror.interval 1559 39) = true ∧ leaveAfter150To20.all proper = true := by decide +kernel private theorem testBit_one_shl150 (a q : Nat) : (1 <<< a).testBit q = decide (a = q) := by rw [Nat.testBit_shiftLeft] by_cases h : a ≤ q · by_cases he : a = q · subst he; simp · have hdiv : 1 / 2 ^ (q - a) = 0 := Nat.div_eq_of_lt (Nat.one_lt_two_pow (by omega)) rw [decide_eq_true h, Bool.true_and, decide_eq_false he, Nat.testBit, Nat.shiftRight_eq_div_pow, hdiv]; rfl · rw [decide_eq_false h, Bool.false_and] exact Bool.eq_iff_iff.mpr (by simp only [decide_eq_true_eq, Bool.false_eq_true, false_iff]; omega) private theorem testBit_interval150 (lo w q : Nat) : (GateMirror.interval lo w).testBit q = decide (lo ≤ q ∧ q < lo + w) := by unfold GateMirror.interval; rw [Nat.testBit_shiftLeft] by_cases h1 : lo ≤ q · simp only [decide_eq_true h1, Bool.true_and, Nat.testBit_two_pow_sub_one, ge_iff_le] exact Bool.eq_iff_iff.mpr (by simp only [decide_eq_true_eq]; omega) · simp only [decide_eq_false h1, Bool.false_and] exact Bool.eq_iff_iff.mpr (by simp only [decide_eq_true_eq, Bool.false_eq_true, false_iff, not_and]; omega) private theorem close150_ev_away : ∀ p ∈ ([(OB5.sig 164 (150 + 1044), (1556 : Wire)), (OB5.sig 164 (150 + 1045), 1559), (OB5.sig 164 (150 + 1046), 1560), (OB5.sig 164 (150 + 1047), 1561), (OB5.sig 164 (150 + 1048), 1562)]), ¬ (p.1 = 1556 ∨ (1559 ≤ (p.1 : Nat) ∧ (p.1 : Nat) ≤ 1562)) ∧ (p.2 = 1556 ∨ (1559 ≤ (p.2 : Nat) ∧ (p.2 : Nat) ≤ 1562)) := by decide +kernel private theorem lowClose150_safe : Safe (leaveLowClose150 ++ leaveClose150To20) (fun q => q = 1556 ∨ (1559 ≤ q ∧ q ≤ 1562)) (fun _ => False) := by have hlc : Safe leaveLowClose150 (fun q => q = 1556 ∨ (1559 ≤ q ∧ q ≤ 1562)) (fun q => q = 1556 ∨ (1559 ≤ q ∧ q ≤ 1562)) := by refine safe_lit ?_ ?_ · unfold leaveLowClose150 exact noMake_append (noMake_append (noMake_xsG _) (noMake_map _ _ fun _ _ => rfl)) (noMake_flatMap _ _ fun _ _ => noMake_cswapG _ _ _) · intro g hg have hall : leaveLowClose150.all (fun g => decide (¬ (GateMirror.target g = 1556 ∨ (1559 ≤ GateMirror.target g ∧ GateMirror.target g ≤ 1562)))) = true := by decide +kernel exact of_decide_eq_true (List.all_eq_true.mp hall g hg) have hcl : Safe leaveClose150To20 (fun q => q = 1556 ∨ (1559 ≤ q ∧ q ≤ 1562)) (fun _ => False) := by unfold leaveClose150To20 Shadow7.closeFlag exact safe_append (safe_drop (Shadow7.noMake_parityG _ _ _ _)) (safe_drop (noMake_swapsG _)) exact safe_append hlc hcl private theorem storePart1_150_fwd : GateMirror.forward storePart1_150 = [.X 1558] ++ GateMirror.forward storePart1Mid150 ++ [.X 1558] := by simp only [storePart1_150, forward_app]; rfl private theorem run_x150 (a : Wire) (t : List Bool) (s : State) : run [.X a] t s = ⟨s.phase, writeBit s.basis a (!s.basis a)⟩ := rfl private theorem fwd_make150 (a b c : Wire) : GateMirror.forward [.make a b c] = [.CCX a b c] := rfl private theorem run_ccx150 (a b c : Wire) (t : List Bool) (s : State) : run [.CCX a b c] t s = ⟨s.phase, writeBit s.basis c (s.basis c ^^ (s.basis a && s.basis b))⟩ := rfl attribute [local irreducible] run SkywalkNat.step Shadow.far CRTBarrel.barrel GateMirror.forward inverse leave150To20 leaveInv150To20 leaveAfter150To20 afterHead150 lowRest150 leaveStoreMapped150 storePart1_150 storePart1Mid150 storePart2_150 leaveLowClose150 leaveClose150To20 head150Prog full150Prog beforeStore150Prog storeMapped150Prog in theorem leaveAfter150_valid (s : State) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) : CRTBarrel.LeaveSplice.Valid (run (GateMirror.forward (CRTBarrel.before 150 ++ Shadow7.leaveBarrel 150)) [] s) leaveAfter150To20 := by have vMov := CRTBarrel.LeaveSplice.moved_valid (j := MixedWindow.j7) (by decide) (by decide) h rw [show start MixedWindow.j7 = 150 from rfl, CRTWindow.split_ops] at vMov obtain ⟨va, vbc⟩ := vMov.parts have hb := before150_state s z g0 s0 h obtain ⟨sameB, backB⟩ := CRTBarrel.LeaveCut.barrel_pair MixedWindow.j7 (by decide) (by decide) _ (CRTBarrel.LeaveCut.input (by decide) (by decide) h) rw [show start MixedWindow.j7 = 150 from rfl] at sameB backB obtain ⟨vHead150, hhead_eq⟩ := leaveMove150_head_eq s z g0 s0 h have hhead_prog : ∀ m', run head150Prog m' s = swap2St (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s) := by intro m'; unfold head150Prog; exact hhead_eq m' let uA := run (GateMirror.forward (CRTBarrel.before 150)) [] s have huA : uA = run (GateMirror.forward (CRTBarrel.beforeReference 150)) [] s := hb [] let uB := run (GateMirror.forward (Shadow7.leaveBarrel 150)) [] uA have huB_eq : uB = run (GateMirror.forward (CRTBarrel.before 150 ++ Shadow7.leaveBarrel 150)) [] s := by simp only [uB, uA, forward_app, run_append, run_take, List.drop_nil] have hspAfter : leaveAfter150To20 = afterHead150 ++ (lowRest150 ++ (leaveStoreMapped150 ++ (leaveLowClose150 ++ leaveClose150To20))) := by simp only [leaveAfter150To20, afterHead150, lowRest150, leaveLowStore150, Shadow7.lowSign, List.append_assoc] let uH := run (GateMirror.forward afterHead150) [] uB have huH_eq : uH = run head150Prog [] s := by simp only [uH, uB, uA, head150Prog, run_append, run_take, List.drop_nil] rw [hb [], sameB] have gflag := LeaveJ7.RecordedEvents.glueFlag MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record h.far h.side have hfront := LeaveJ7.entry_core MixedWindow.j7 (by decide) (by decide) s [] z (LeaveJ7.Admission.flags z g0 s0).1 (LeaveJ7.Admission.flags z g0 s0).2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp (Shadow.far (Shadow7.sbP (start MixedWindow.j7)) 15 z ∧ LeaveShadowRails.farKey (Shadow7.sbP (start MixedWindow.j7)) z = 0) (LeaveJ7.glueBound MixedWindow.j7 z (LeaveJ7.Admission.flags z g0 s0).2 ⟨h.farSmall, h.endSmall⟩) gflag dsimp only at hfront rw [show start MixedWindow.j7 = 150 from rfl] at hfront have h1558H : (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s).basis 1558 = false := by rw [show Shadow7.leaveHeadOps 150 = LeaveJ7.entryOps 150 ++ LeaveJ7.bodyOps MixedWindow.j7 from (LeaveJ7.head_eq MixedWindow.j7).symm, forward_app, run_append, run_take, List.drop_nil, LeaveReadoutFrame.preserved _ _ _ 1558 (fun hit => absurd (LeaveJ7.body_dest MixedWindow.j7 (by decide) (by decide) 1558 hit) (by unfold LeaveJ7.midT LeaveJ7.workT; decide))] exact hfront.2.2.2.2.1.2 have hck := LeaveJ7.CoreCheckpoint.result MixedWindow.j7 (by decide) (by decide) s [] z (LeaveJ7.Admission.flags z g0 s0).1 (LeaveJ7.Admission.flags z g0 s0).2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero (LeaveJ7.RecordedParity.result MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record) (by rw [h.far, h.side]; exact LeaveTraceHistory.flags _ _) (LeaveJ7.RecordedEvents.result MixedWindow.j7 (by decide) (by decide) s z g0 s0 ⟨h.farSmall, h.endSmall⟩ h.odd h.record).2 gflag have hck_prog : LeaveJ7.CoreCheckpoint.program MixedWindow.j7 = GateMirror.forward (Shadow7.leaveHeadOps 150) := rfl rw [hck_prog] at hck have hgeo : Shadow7.sbP 150 = 173 ∧ Shadow7.b0P 150 = 960 ∧ Shadow7.e0P 150 = 1747 ∧ lows150 = 12 := by decide obtain ⟨hsb, hb0, he0, hlow12⟩ := hgeo have hmaskLR : Masked uH (GateMirror.interval (Shadow7.b0P 150) lows150 ||| GateMirror.interval 1559 39 ||| (1 <<< 1558)) := by intro q hq rw [Nat.testBit_or, Nat.testBit_or, testBit_interval150, testBit_interval150, testBit_one_shl150, Bool.or_eq_true, Bool.or_eq_true, decide_eq_true_eq, decide_eq_true_eq, decide_eq_true_eq] at hq rw [huH_eq, hhead_prog] rcases hq with (⟨h1, h2⟩ | ⟨h1, h2⟩) | h3 · rw [hb0] at h1 h2; rw [hlow12] at h2 rw [swap2St_other q (by omega) (by omega) (by omega) (by omega)] exact hck.2.2.2 _ (List.mem_map.mpr ⟨q - 960, List.mem_range.mpr (by omega), by change Shadow7.b0P (start MixedWindow.j7) + (q - 960) = q rw [show start MixedWindow.j7 = 150 from rfl, hb0]; omega⟩) · rw [swap2St_other q (by omega) (by omega) (by omega) (by omega)] rw [show q = 1559 + (q - 1559) by omega] exact hck.1 ⟨q - 1559, by omega⟩ · subst h3; rw [swap2St_other 1558 (by decide) (by decide) (by decide) (by decide)]; exact h1558H have hlr := ready_of_checkMask150 lowRest150 uH (1 <<< 1558) _ tail150_checks.1 hmaskLR let uLR := run (GateMirror.forward lowRest150) [] uH have hlr_prog : GateMirror.forward lowRest150 = borrowG4_150 ++ (Companion.restore smallA150 smallM150 smallC150 1556 1558 ++ releaseMaskP150) := by have h1 := lowStore150_parts have h2 : GateMirror.forward leaveLowStore150 = GateMirror.forward (Shadow7.lowSign 150) ++ GateMirror.forward lowRest150 := by unfold leaveLowStore150 Shadow7.lowSign lowRest150; simp only [forward_app, List.append_assoc] rw [h2] at h1; exact List.append_cancel_left h1 have huLR_keep : ∀ q : Wire, q ≠ 1557 → q ≠ 1558 → q ∉ smallM150 → uLR.basis q = uH.basis q := by intro q h7 h8 hM change (run (GateMirror.forward lowRest150) [] uH).basis q = uH.basis q rw [hlr_prog, run_append, run_take, List.drop_nil, run_append, run_take, List.drop_nil] have hnr : q ∉ releaseMaskP150.map LeaveReadoutFrame.destination := by intro hm; simp only [releaseMaskP150, GateMirror.forward, front, erase, List.map_cons, List.map_nil, List.mem_cons, List.not_mem_nil, or_false, LeaveReadoutFrame.destination] at hm rcases hm with rfl | rfl | rfl <;> contradiction rw [LeaveReadoutFrame.preserved _ _ _ q hnr] have hrest := Companion.write smallA150 smallM150 smallC150 1556 1558 geom150_check.1 (run borrowG4_150 [] uH) [] (fun w hw => by obtain ⟨i, hi, rfl⟩ := List.mem_map.mp hw; rw [List.mem_range] at hi have hl : lows150 = 12 := rfl rw [hl] at hi rw [borrowG4_150_keep uH (1559 + i) (by unfold Wire; omega) (by unfold Wire; omega)] exact hmaskLR (1559 + i) (by rw [Nat.testBit_or, Nat.testBit_or, testBit_interval150, testBit_interval150] simp only [Bool.or_eq_true, decide_eq_true_eq] left; right; omega)) (by rw [regValue_zero]; intro w hw obtain ⟨i, hi, rfl⟩ := List.mem_map.mp hw; rw [List.mem_range] at hi have hl : lows150 = 12 := rfl rw [hl] at hi rw [borrowG4_150_keep uH (Shadow7.b0P 150 + i) (by rw [hb0]; unfold Wire; omega) (by rw [hb0]; unfold Wire; omega)] exact hmaskLR (Shadow7.b0P 150 + i) (by rw [Nat.testBit_or, Nat.testBit_or, testBit_interval150] simp only [Bool.or_eq_true, decide_eq_true_eq] left; left; rw [hlow12]; omega)) rw [hrest.2.1 q hM, borrowG4_150_keep uH q h7 h8] have hmaskSM1 : Masked uLR storeAllow1_150 := by intro q hq unfold storeAllow1_150 at hq rw [Nat.testBit_or, testBit_interval150, testBit_interval150, Bool.or_eq_true, decide_eq_true_eq, decide_eq_true_eq] at hq have hnotM : (q : Wire) ∉ smallM150 := by intro hm; obtain ⟨i, hi, e⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi rcases hq with ⟨_, _⟩ | ⟨_, _⟩ <;> (unfold Wire at *; omega) rw [huLR_keep q (by rcases hq with ⟨_, _⟩ | ⟨_, _⟩ <;> (unfold Wire; omega)) (by rcases hq with ⟨_, _⟩ | ⟨_, _⟩ <;> (unfold Wire; omega)) hnotM, huH_eq, hhead_prog] rcases hq with ⟨h1, h2⟩ | ⟨h1, h2⟩ · rw [swap2St_other q (by omega) (by omega) (by omega) (by omega)] rw [show q = 1559 + (q - 1559) by omega] exact hck.1 ⟨q - 1559, by omega⟩ · rw [swap2St_other q (by omega) (by omega) (by omega) (by omega)] have hraw : (q : Wire) ∈ LeaveJ7.CoreCheckpoint.rawSites MixedWindow.j7 := by simp only [LeaveJ7.CoreCheckpoint.rawSites, List.mem_append, List.mem_range'_1] left; left; exact ⟨h1, by rw [show start MixedWindow.j7 = 150 from rfl]; omega⟩ rw [hck.2.2.1 q hraw] exact LeaveJ7.native_carryJ_lt MixedWindow.j7 (by decide) (by decide) _ s h.ready q (by change 1556 ≤ q; omega) (by change q + 2 < Shadow7.e0P (start MixedWindow.j7); rw [show start MixedWindow.j7 = 150 from rfl, he0]; rw [he0] at h2; omega) have hsm1 := ready_of_checkMask150 storePart1_150 uLR (GateMirror.interval 1559 39) storeAllow1_150 tail150_checks.2.1 hmaskSM1 let uSM1 := run (GateMirror.forward storePart1_150) [] uLR have h1558_uLR : uLR.basis 1558 = false := hlr.2 1558 (by rw [testBit_one_shl150]; decide) have h1558_uSM1 : uSM1.basis 1558 = false := by have hnot58 : (1558 : Wire) ∉ (GateMirror.forward storePart1Mid150).map LeaveReadoutFrame.destination := by rw [forward_map_dest]; intro hm; obtain ⟨g, hg, e⟩ := List.mem_map.mp hm exact of_decide_eq_true (List.all_eq_true.mp tail150_checks.2.2.1 g hg) e show (run (GateMirror.forward storePart1_150) [] uLR).basis 1558 = false rw [storePart1_150_fwd, run_append, run_take, List.drop_nil, run_append, run_take, List.drop_nil, run_x150] simp only [writeBit, Function.update_self] rw [LeaveReadoutFrame.preserved _ _ _ 1558 hnot58, run_x150] simp only [writeBit, Function.update_self, h1558_uLR]; rfl have hmake : Ready uSM1 [.make 1556 1557 1558] := ⟨h1558_uSM1, trivial⟩ let uMk := run (GateMirror.forward [.make 1556 1557 1558]) [] uSM1 have hmaskSM2 : Masked uMk (GateMirror.interval 1559 39) := by intro q hq rw [testBit_interval150, decide_eq_true_eq] at hq have hne58 : (q : Wire) ≠ 1558 := by omega dsimp only [uMk]; rw [fwd_make150, run_ccx150] simp only [writeBit, Function.update_of_ne hne58] exact hsm1.2 q (by rw [testBit_interval150, decide_eq_true_eq]; exact hq) have hsm2 := ready_of_checkMask150 storePart2_150 uMk 0 (GateMirror.interval 1559 39) tail150_checks.2.2.2.1 hmaskSM2 have hsm_split : leaveStoreMapped150 = storePart1_150 ++ ([.make 1556 1557 1558] ++ storePart2_150) := by simp only [leaveStoreMapped150, storePart1_150, storePart1Mid150, storePart2_150, List.append_assoc, List.cons_append, List.nil_append] have hsm_ready : Ready uLR leaveStoreMapped150 := by rw [hsm_split]; exact ready_append _ _ _ hsm1.1 (ready_append _ _ _ hmake hsm2.1) have hw := whole150_result s [] z g0 s0 h nextSmall20 have huBS_eq : run (GateMirror.forward leaveStoreMapped150) [] uLR = run beforeStore150Prog [] s := by have hfull : uLR = run (full150Prog ++ releaseMaskP150) [] s := by simp only [uLR, huH_eq, full150Prog, hlr_prog, run_append, run_take, List.drop_nil] rw [hfull]; simp only [beforeStore150Prog, run_append, run_take, List.drop_nil] have hclean_lc : ∀ q, (q = 1556 ∨ (1559 ≤ q ∧ q ≤ 1562)) → (run (GateMirror.forward leaveStoreMapped150) [] uLR).basis q = false := by intro q hq; rw [huBS_eq] rcases hq with rfl | ⟨h1, h2⟩ · exact hw.2.2.2.2.2.2.2.2.2.2.2.1 · have hnotM : (q : Wire) ∉ smallM150 := by intro hm; obtain ⟨i, hi, e⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi unfold Wire at *; omega rw [hw.2.2.2.2.2.2.2.2.2.2.2.2.1 q (by unfold Wire at *; omega) (by unfold Wire at *; omega) (by unfold Wire at *; omega) hnotM, hhead_prog, swap2St_other q (by unfold Wire at *; omega) (by unfold Wire at *; omega) (by unfold Wire at *; omega) (by unfold Wire at *; omega)] rw [show (q : Nat) = 1559 + ((q : Nat) - 1559) by unfold Wire at *; omega] exact hck.1 ⟨(q : Nat) - 1559, by unfold Wire at *; omega⟩ have hlc_ready := (lowClose150_safe _ hclean_lc).1 have hAfter_ready : Ready uB leaveAfter150To20 := by rw [hspAfter] exact ready_append _ _ _ (huB_eq ▸ vHead150.ready) (ready_append _ _ _ hlr.1 (ready_append _ _ _ hsm_ready hlc_ready)) have hAfter_phys : ∀ g ∈ leaveAfter150To20, proper g = true := fun g hg => List.all_eq_true.mp tail150_checks.2.2.2.2 g hg have hAfter_phase : ∀ t, (run (GateMirror.forward leaveAfter150To20) t uB).phase = uB.phase := by intro t have hpre_ph : uB.phase = s.phase := by rw [huB_eq]; exact GateMirror.no_phase _ s have hlen : (List.replicate (measurementCount (GateMirror.forward (CRTBarrel.before 150) ++ CRTBarrel.barrel 150 false)) false).length = measurementCount (GateMirror.forward (CRTBarrel.before 150) ++ CRTBarrel.barrel 150 false) := List.length_replicate let t0 := List.replicate (measurementCount (GateMirror.forward (CRTBarrel.before 150) ++ CRTBarrel.barrel 150 false)) false have hw_ph := (whole150_result s (t0 ++ t) z g0 s0 h nextSmall20).1 unfold leave150To20 at hw_ph rw [run_append, run_take, show (t0 ++ t).drop (measurementCount (GateMirror.forward (CRTBarrel.before 150) ++ CRTBarrel.barrel 150 false)) = t by rw [← hlen, List.drop_left]] at hw_ph have hrun_uB : run (GateMirror.forward (CRTBarrel.before 150) ++ CRTBarrel.barrel 150 false) (t0 ++ t) s = uB := by rw [run_append, run_take, hb, sameB] show _ = run (GateMirror.forward (Shadow7.leaveBarrel 150)) [] uA rw [huA] rw [hrun_uB] at hw_ph exact hw_ph.trans hpre_ph.symm rw [← huB_eq] exact ⟨hAfter_phys, all_prepared _ uB hAfter_phys hAfter_phase, hAfter_ready⟩ attribute [local irreducible] run SkywalkNat.step Shadow.far CRTBarrel.barrel GateMirror.forward inverse leave150To20 leaveInv150To20 leaveAfter150To20 in theorem leave150To20_roundtrip (s : State) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) (m n : List Bool) : run leaveInv150To20 n (run leave150To20 m s) = s := by obtain ⟨sameB, backB⟩ := CRTBarrel.LeaveCut.barrel_pair MixedWindow.j7 (by decide) (by decide) _ (CRTBarrel.LeaveCut.input (by decide) (by decide) h) rw [show start MixedWindow.j7 = 150 from rfl] at sameB backB have hb := before150_state s z g0 s0 h have hAfter_valid : CRTBarrel.LeaveSplice.Valid (run (GateMirror.forward (Shadow7.leaveBarrel 150)) [] (run (GateMirror.forward (CRTBarrel.beforeReference 150)) [] s)) leaveAfter150To20 := by have v := leaveAfter150_valid s z g0 s0 h nextSmall20 rw [forward_app, run_append, run_take, List.drop_nil, hb []] at v exact v unfold leave150To20 leaveInv150To20 simp only [run_append, run_take] rw [hb, sameB, hAfter_valid.undo_run, backB, ← hb []] exact before150_undo s z g0 s0 h _ /-! ### Section 4 (Stage 6B3): `leave150To20Red_pair`, `leave150To20Red_keeps`, `leave150To20Red_keeps_mirror` -/ section LeaveRed150Proofs open CRTBarrel.LeaveSplice CRTBarrel.FlagCut CRTBarrel.FlagCut4 CRTBarrel.FlagCut6 private theorem columnsP150_snoc : columnsP150 = colsC150 ++ [⟨false, none, Shadow7.a0P 150 - 1 + 16, Shadow7.bankW 150 16⟩] := rfl private theorem leaveAfter150_split4 : let top := Shadow7.a0P 150 + lows150 - 2 leaveAfter150To20 = tailD0_150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ (tailD1_150 ++ ([.pop (Shadow7.e0P 150 + 3) (Shadow7.e0P 150 + 4) 1559] ++ (tailE0_150 ++ ([.make 1558 top 1559] ++ (chainMid150 ++ ([.pop 1558 top 1559] ++ tailE1_150))))))) := by have hw : wordGM 1614 columnsP150 = CRTBarrel.wordPre 1614 colsC150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ CRTBarrel.wordPost 1614 colsC150) := by rw [columnsP150_snoc] exact CRTWindow.wordGM_snoc 1614 ⟨false, none, Shadow7.a0P 150 - 1 + 16, Shadow7.bankW 150 16⟩ rfl colsC150 have hsw0 : Shadow7.storeW 150 0 = 1558 := by decide have hsw1 : Shadow7.storeW 150 1 = 1559 := by decide have hch : chainG (Shadow7.storeW 150) (fun i => if i = 0 then Shadow7.a0P 150 + lows150 - 2 else Shadow7.bankW 150 (lows150 + i - 1)) [.cx (Shadow7.storeW 150 (Shadow7.liveW 150 - lows150 + 1)) 1557, .x 1557] 0 (Shadow7.liveW 150 - lows150 + 1) = [.make 1558 (Shadow7.a0P 150 + lows150 - 2) 1559] ++ (chainMid150 ++ [.pop 1558 (Shadow7.a0P 150 + lows150 - 2) 1559]) := by simp only [chainG, chainMid150, hsw0, hsw1, Nat.zero_add, ↓reduceIte, List.append_assoc, List.cons_append, List.nil_append] unfold leaveAfter150To20 leaveJoinMove150 leaveLowStore150 leaveStoreMapped150 tailD0_150 tailD1_150 tailE0_150 lowRest150_pub storeHead150 tailE1_150 dsimp only rw [hw, hch] simp only [List.append_assoc, List.cons_append, List.nil_append] /-- `CRTBarrel.beforeReference` around its flag make (`leaveFix3`'s first gate). -/ private theorem ref150_split_flag : CRTBarrel.beforeReference 150 = LeaveJ7.entryOps 150 ++ ([.make (Shadow7.sbP 150 + 1577) (Shadow7.sbP 150 + 1578) 1559] ++ (([.cx (Shadow7.sbP 150 + 1577) 1560, .cx 1559 1560] ++ leaveFix4 150 (Shadow7.sbP 150) ++ Shadow7.leaveFix5Move 150 (Shadow7.sbP 150)) ++ Shadow7.leaveAdjust 150)) := by unfold CRTBarrel.beforeReference LeaveJ7.entryOps leaveFix3 simp only [List.append_assoc, List.cons_append, List.nil_append] private theorem red150_targets : ([Gate.make (Shadow7.sbP 150 + 1577) (Shadow7.sbP 150 + 1578) 1559, Gate.cx (Shadow7.sbP 150 + 1577) 1560, Gate.cx 1559 1560] ++ leaveFix4 150 (Shadow7.sbP 150) ++ Shadow7.leaveFix5Move 150 (Shadow7.sbP 150) ++ Shadow7.leaveAdjust 150 ++ Shadow7.leaveBarrel 150 ++ tailD0_150).all (fun g => decide (GateMirror.target g ≠ Shadow7.a0P 150 - 1 + 16)) = true ∧ (LeaveJ7.entryOps 150).all (fun g => decide (GateMirror.target g ≠ Shadow7.sbP 150 + 1577 ∧ GateMirror.target g ≠ Shadow7.sbP 150 + 1578)) = true ∧ ([Gate.cx (Shadow7.sbP 150 + 1577) 1560, Gate.cx 1559 1560] ++ leaveFix4 150 (Shadow7.sbP 150) ++ Shadow7.leaveFix5Move 150 (Shadow7.sbP 150) ++ Shadow7.leaveAdjust 150 ++ Shadow7.leaveBarrel 150 ++ tailD0_150 ++ pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ tailD1_150).all (fun g => decide (GateMirror.target g ≠ 1559 ∧ GateMirror.target g ≠ Shadow7.e0P 150 + 4)) = true ∧ (storeHead150.drop 1).all (fun g => decide (GateMirror.target g ≠ 1558)) = true ∧ chainMid150.all (fun g => decide (GateMirror.target g ≠ 1558)) = true ∧ Shadow7.sbP 150 + 1578 = Shadow7.e0P 150 + 4 ∧ Shadow7.sbP 150 + 1577 = Shadow7.e0P 150 + 3 := by decide +kernel private theorem lowRest150_1558 (t : State) : (run (GateMirror.forward lowRest150_pub) [] t).basis 1558 = false := by obtain ⟨X, hX⟩ : ∃ X, lowRest150_pub = X ++ [.pop (Shadow7.b0P 150 - 1) 1557 1558, .cx (Shadow7.a0P 150 - 1) 1557, .x 1557] := ⟨_, rfl⟩ rw [hX, run_nil_append] generalize run (GateMirror.forward X) [] t = u obtain ⟨ph, f⟩ := u simp [GateMirror.forward, front, GateMirror.erase, run, measureAndCorrect, ECDSAAdd.correct, writeBit, Function.update_apply] private theorem red150_box2 : (CRTBarrel.before 150).all (fun g => g.wires.all fun q => decide ((166 ≤ (q : Nat) ∧ (q : Nat) ≤ 180) ∨ (Shadow7.a0P 150 - 1 ≤ (q : Nat) ∧ (q : Nat) ≤ Shadow7.a0P 150 + 15) ∨ (Shadow7.b0P 150 - 1 ≤ (q : Nat) ∧ (q : Nat) ≤ bTopP 150) ∨ (1194 ≤ (q : Nat) ∧ (q : Nat) ≤ 1208) ∨ (1556 ≤ (q : Nat) ∧ (q : Nat) ≤ 1812))) = true ∧ (CRTBarrel.before 150).all (fun g => g.wires.all fun q => decide ((q : Nat) + 150 ≤ 2069)) = true ∧ afterRow150.all (fun g => g.wires.all fun q => decide ((166 ≤ (q : Nat) ∧ (q : Nat) ≤ 180) ∨ (Shadow7.a0P 150 - 1 ≤ (q : Nat) ∧ (q : Nat) ≤ Shadow7.a0P 150 + 15) ∨ (Shadow7.b0P 150 - 1 ≤ (q : Nat) ∧ (q : Nat) ≤ bTopP 150) ∨ (1194 ≤ (q : Nat) ∧ (q : Nat) ≤ 1208) ∨ (1556 ≤ (q : Nat) ∧ (q : Nat) ≤ 1812))) = true ∧ afterRow150.all (fun g => g.wires.all fun q => decide ((q : Nat) + 150 ≤ 2069)) = true := by decide +kernel private theorem red150_1558_make (t : State) : (run (GateMirror.forward tailE0_150) [] t).basis 1558 = true := by have hrt := red150_targets have he : storeHead150 = [.x 1558] ++ storeHead150.drop 1 := rfl rw [tailE0_150, run_nil_append, he, run_nil_append, keeps_of_targets _ _ (fun g hg => of_decide_eq_true (List.all_eq_true.mp hrt.2.2.2.1 g hg))] have hz := lowRest150_1558 t generalize run (GateMirror.forward lowRest150_pub) [] t = w at hz ⊢ obtain ⟨ph, f⟩ := w; simp only at hz simp [GateMirror.forward, front, run, writeBit, Function.update_apply, hz] private theorem red150_aft_fprog : let top : Wire := Shadow7.a0P 150 + lows150 - 2 GateMirror.forward afterRow150 = GateMirror.forward tailD0_150 ++ [] ++ GateMirror.forward tailD1_150 ++ [.CX (Shadow7.e0P 150 + 4) 1559] ++ GateMirror.forward tailE0_150 ++ [.CX top 1559] ++ GateMirror.forward chainMid150 ++ [.CX top 1559] ++ GateMirror.forward tailE1_150 := by simp only [afterRow150, forward_app, fwd_cons, front, List.append_assoc, List.cons_append, List.nil_append, List.append_nil] private theorem red150_aft_rprog : let top : Wire := Shadow7.a0P 150 + lows150 - 2 inverse afterRow150 = inverse tailE1_150 ++ [.CX top 1559] ++ inverse chainMid150 ++ [.CX top 1559] ++ inverse tailE0_150 ++ [.CX (Shadow7.e0P 150 + 4) 1559] ++ inverse tailD1_150 ++ [] ++ inverse tailD0_150 := by simp only [afterRow150, inv_app, inv_cons, GateMirror.back, List.append_assoc, List.cons_append, List.nil_append, List.append_nil] private theorem red150_run_nil_any (t : List Bool) (u : State) : run [] t u = u := rfl attribute [local irreducible] run SkywalkNat.step Shadow.far CRTBarrel.barrel CRTBarrel.before CRTBarrel.beforeReference LeaveJ7.entryOps leaveFix4 Shadow7.leaveFix5Move Shadow7.leaveAdjust Shadow7.leaveBarrel leaveAfter150To20 afterRow150 tailD0_150 tailD1_150 tailE0_150 chainMid150 tailE1_150 pairGM in theorem leave150To20Red_pair (s : State) (z : SkywalkNat.State) (g0 s0 : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z g0 s0) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) : (∀ m, run leave150To20Red m s = run leave150To20 m s) ∧ (∀ m n, run leaveInv150To20Red n (run leave150To20Red m s) = s) := by have vMov := CRTBarrel.LeaveSplice.moved_valid (j := MixedWindow.j7) (by decide) (by decide) h rw [show start MixedWindow.j7 = 150 from rfl, CRTBarrel.LeaveCut.move_shape] at vMov obtain ⟨vRef, _⟩ := vMov.parts obtain ⟨sameB, backB⟩ := CRTBarrel.LeaveCut.barrel_pair MixedWindow.j7 (by decide) (by decide) _ (CRTBarrel.LeaveCut.input (by decide) (by decide) h) rw [show start MixedWindow.j7 = 150 from rfl] at sameB backB have hrt := red150_targets -- the shared before part: the reduced `CRTBarrel.before 150` runs as the reference on admitted inputs let uA := run (GateMirror.forward (CRTBarrel.beforeReference 150)) [] s have hbef (m : List Bool) : run (GateMirror.forward (CRTBarrel.before 150)) m s = uA := before150_state s z g0 s0 h m let uB := run (GateMirror.forward (Shadow7.leaveBarrel 150)) [] uA have huB_eq : uB = run (GateMirror.forward (CRTBarrel.before 150 ++ Shadow7.leaveBarrel 150)) [] s := by simp only [uB, forward_app, run_append, run_take, List.drop_nil, hbef] have vAft : Valid uB leaveAfter150To20 := huB_eq ▸ leaveAfter150_valid s z g0 s0 h nextSmall20 let top : Wire := Shadow7.a0P 150 + lows150 - 2 -- 1. the high column (16) of the join word is idle: its shadow is clear after the entry have huB_a16 : (run (GateMirror.forward tailD0_150) [] uB).basis (Shadow7.a0P 150 - 1 + 16) = false := by have e0 := DeadJoin.entry_top_zero (j := MixedWindow.j7) (by decide) h rw [show start MixedWindow.j7 = 150 from rfl] at e0 have kR : ∀ g ∈ [Gate.make (Shadow7.sbP 150 + 1577) (Shadow7.sbP 150 + 1578) 1559, Gate.cx (Shadow7.sbP 150 + 1577) 1560, Gate.cx 1559 1560] ++ leaveFix4 150 (Shadow7.sbP 150) ++ Shadow7.leaveFix5Move 150 (Shadow7.sbP 150) ++ Shadow7.leaveAdjust 150 ++ Shadow7.leaveBarrel 150 ++ tailD0_150, GateMirror.target g ≠ Shadow7.a0P 150 - 1 + 16 := fun g hg => of_decide_eq_true (List.all_eq_true.mp hrt.1 g hg) have hsplit : CRTBarrel.beforeReference 150 ++ (Shadow7.leaveBarrel 150 ++ tailD0_150) = LeaveJ7.entryOps 150 ++ (([Gate.make (Shadow7.sbP 150 + 1577) (Shadow7.sbP 150 + 1578) 1559, Gate.cx (Shadow7.sbP 150 + 1577) 1560, Gate.cx 1559 1560] ++ leaveFix4 150 (Shadow7.sbP 150) ++ Shadow7.leaveFix5Move 150 (Shadow7.sbP 150) ++ Shadow7.leaveAdjust 150 ++ Shadow7.leaveBarrel 150 ++ tailD0_150)) := by rw [ref150_split_flag]; simp only [List.append_assoc, List.cons_append, List.nil_append] have hrun : run (GateMirror.forward tailD0_150) [] uB = run (GateMirror.forward (CRTBarrel.beforeReference 150 ++ (Shadow7.leaveBarrel 150 ++ tailD0_150))) [] s := by simp only [uB, uA, forward_app, run_append, run_take, List.drop_nil] rw [hrun, hsplit, run_nil_append, keeps_of_targets _ _ kR] exact e0 -- 2. the flag 1559 equals the side flag `e0P + 4` before the after-part pop have hv1559 : let uMid := run (GateMirror.forward (tailD0_150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ tailD1_150))) [] uB uMid.basis 1559 = uMid.basis (Shadow7.e0P 150 + 4) := by have vFl : Valid s (LeaveJ7.entryOps 150 ++ ([.make (Shadow7.sbP 150 + 1577) (Shadow7.sbP 150 + 1578) 1559] ++ (([.cx (Shadow7.sbP 150 + 1577) 1560, .cx 1559 1560] ++ leaveFix4 150 (Shadow7.sbP 150) ++ Shadow7.leaveFix5Move 150 (Shadow7.sbP 150)) ++ Shadow7.leaveAdjust 150))) := ref150_split_flag ▸ vRef have imp0 : s.basis (Shadow7.sbP 150 + 1578) = true → s.basis (Shadow7.sbP 150 + 1577) = true := by have hf := h.far; have hs := h.side rw [show start MixedWindow.j7 = 150 from rfl] at hf hs rw [hrt.2.2.2.2.2.1, hrt.2.2.2.2.2.2, hs, hf] intro h'; exact ((Bool.and_eq_true _ _).mp h').1 have imp1 : (run (GateMirror.forward (LeaveJ7.entryOps 150)) [] s).basis (Shadow7.sbP 150 + 1578) = true → (run (GateMirror.forward (LeaveJ7.entryOps 150)) [] s).basis (Shadow7.sbP 150 + 1577) = true := by rw [keeps_of_targets _ _ (fun g hg => (of_decide_eq_true (List.all_eq_true.mp hrt.2.1 g hg)).2), keeps_of_targets _ _ (fun g hg => (of_decide_eq_true (List.all_eq_true.mp hrt.2.1 g hg)).1)] exact imp0 have hmk := make_flag (Shadow7.sbP 150 + 1577) (Shadow7.sbP 150 + 1578) 1559 _ vFl.parts.2.parts.1.ready.1 (by decide) imp1 have hkeep (q : Wire) (hq : q = 1559 ∨ q = Shadow7.e0P 150 + 4) : (run (GateMirror.forward (tailD0_150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ tailD1_150))) [] uB).basis q = (run (GateMirror.forward [.make (Shadow7.sbP 150 + 1577) (Shadow7.sbP 150 + 1578) 1559]) [] (run (GateMirror.forward (LeaveJ7.entryOps 150)) [] s)).basis q := by have kA : ∀ g ∈ [Gate.cx (Shadow7.sbP 150 + 1577) 1560, Gate.cx 1559 1560] ++ leaveFix4 150 (Shadow7.sbP 150) ++ Shadow7.leaveFix5Move 150 (Shadow7.sbP 150) ++ Shadow7.leaveAdjust 150 ++ Shadow7.leaveBarrel 150 ++ tailD0_150 ++ pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ tailD1_150, GateMirror.target g ≠ q := fun g hg => by have ht := of_decide_eq_true (List.all_eq_true.mp hrt.2.2.1 g hg) rcases hq with rfl | rfl; exact ht.1; exact ht.2 have hrun : run (GateMirror.forward (tailD0_150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ tailD1_150))) [] uB = run (GateMirror.forward ([Gate.cx (Shadow7.sbP 150 + 1577) 1560, Gate.cx 1559 1560] ++ leaveFix4 150 (Shadow7.sbP 150) ++ Shadow7.leaveFix5Move 150 (Shadow7.sbP 150) ++ Shadow7.leaveAdjust 150 ++ Shadow7.leaveBarrel 150 ++ tailD0_150 ++ pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ tailD1_150)) [] (run (GateMirror.forward [.make (Shadow7.sbP 150 + 1577) (Shadow7.sbP 150 + 1578) 1559]) [] (run (GateMirror.forward (LeaveJ7.entryOps 150)) [] s)) := by simp only [uB, uA, ref150_split_flag, forward_app, run_append, run_take, List.drop_nil, List.append_assoc] rw [hrun, keeps_of_targets _ q kA] dsimp only rw [hkeep 1559 (Or.inl rfl), hkeep (Shadow7.e0P 150 + 4) (Or.inr rfl), ← hrt.2.2.2.2.2.1] exact hmk -- 3. the chain head 1558 is set at the store's make and pop have vAft4 : Valid uB (tailD0_150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ (tailD1_150 ++ ([.pop (Shadow7.e0P 150 + 3) (Shadow7.e0P 150 + 4) 1559] ++ (tailE0_150 ++ ([.make 1558 top 1559] ++ (chainMid150 ++ ([.pop 1558 top 1559] ++ tailE1_150)))))))) := leaveAfter150_split4 ▸ vAft have h1558_M : (run (GateMirror.forward (tailD0_150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ (tailD1_150 ++ ([.pop (Shadow7.e0P 150 + 3) (Shadow7.e0P 150 + 4) 1559] ++ tailE0_150))))) [] uB).basis 1558 = true := by simp only [run_nil_append]; exact red150_1558_make _ have h1558_P : (run (GateMirror.forward (tailD0_150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ (tailD1_150 ++ ([.pop (Shadow7.e0P 150 + 3) (Shadow7.e0P 150 + 4) 1559] ++ (tailE0_150 ++ ([.make 1558 top 1559] ++ chainMid150))))))) [] uB).basis 1558 = true := by simp only [run_nil_append] rw [keeps_of_targets _ _ (fun g hg => of_decide_eq_true (List.all_eq_true.mp hrt.2.2.2.2.1 g hg)), keeps_of_targets [.make 1558 top 1559] 1558 (fun g hg => by simp at hg; subst hg; simp [GateMirror.target])] exact red150_1558_make _ have hvPop59 : let uP := run (GateMirror.forward (tailD0_150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ (tailD1_150 ++ ([.pop (Shadow7.e0P 150 + 3) (Shadow7.e0P 150 + 4) 1559] ++ (tailE0_150 ++ ([.make 1558 top 1559] ++ chainMid150))))))) [] uB uP.basis 1559 = uP.basis top := by have vP : Valid uB ((tailD0_150 ++ (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16) ++ (tailD1_150 ++ ([.pop (Shadow7.e0P 150 + 3) (Shadow7.e0P 150 + 4) 1559] ++ (tailE0_150 ++ ([.make 1558 top 1559] ++ chainMid150)))))) ++ ([.pop 1558 top 1559] ++ tailE1_150)) := by simpa only [List.append_assoc] using vAft4 have val := vP.parts.2.parts.1.prepared.1 simp only [GateMirror.ValueOK] at val dsimp only; rw [val, h1558_P, Bool.true_and] -- 4. the four after-part cuts have haft_rep := replace4 tailD0_150 (pairGM false 1614 (Shadow7.a0P 150 - 1 + 16) (Shadow7.bankW 150 16)) tailD1_150 [.pop (Shadow7.e0P 150 + 3) (Shadow7.e0P 150 + 4) 1559] tailE0_150 [.make 1558 top 1559] chainMid150 [.pop 1558 top 1559] tailE1_150 [] [] [.CX (Shadow7.e0P 150 + 4) 1559] [.CX (Shadow7.e0P 150 + 4) 1559] [.CX top 1559] [.CX top 1559] [.CX top 1559] [.CX top 1559] uB vAft4 (fun t => (red150_run_nil_any t _).trans (pair_high_id 1614 _ _ _ (by decide) huB_a16).symm) (fun t => (red150_run_nil_any t _).trans (pair_high_id 1614 _ _ _ (by decide) huB_a16)) (fun t => erase_cx _ _ _ _ hv1559 t) (fun t => erase_cx_back _ _ _ _ (by decide) hv1559 t) (fun t => ccx_cx 1558 top 1559 _ (fun _ => h1558_M) t) (fun t => ccx_cx_back 1558 top 1559 _ (by decide) (fun _ => h1558_M) t) (fun t => erase_cx 1558 top 1559 _ hvPop59 t) (fun t => erase_cx_back 1558 top 1559 _ (by decide) hvPop59 t) have haft_fwd (m : List Bool) : run (GateMirror.forward afterRow150) m uB = run (GateMirror.forward leaveAfter150To20) [] uB := by rw [red150_aft_fprog, haft_rep.1 m, ← leaveAfter150_split4]; exact vAft.default_run m have haft_rev (n : List Bool) : run (inverse afterRow150) n (run (GateMirror.forward leaveAfter150To20) [] uB) = uB := by rw [← haft_fwd [], red150_aft_rprog, red150_aft_fprog]; exact haft_rep.2 [] n -- 5. compose the shared before, the barrel and the two after parts have hred_eq (m : List Bool) : run leave150To20Red m s = run (GateMirror.forward leaveAfter150To20) [] uB := by unfold leave150To20Red; simp only [run_append, run_take] rw [hbef, sameB, haft_fwd] have hold_eq (m : List Bool) : run leave150To20 m s = run (GateMirror.forward leaveAfter150To20) [] uB := by unfold leave150To20; simp only [run_append, run_take] rw [hbef, sameB, vAft.default_run] refine ⟨fun m => (hred_eq m).trans (hold_eq m).symm, fun m n => ?_⟩ rw [hred_eq m] unfold leaveInv150To20Red; simp only [run_append, run_take] rw [haft_rev, backB] rw [show run (GateMirror.forward (CRTBarrel.beforeReference 150)) [] s = run (GateMirror.forward (CRTBarrel.before 150)) [] s from (hbef []).symm] exact before150_undo s z g0 s0 h _ attribute [local irreducible] run CRTBarrel.barrel in theorem leave150To20Red_keeps (q : Wire) (hq : ¬ Shadow7.leaveBox2 150 q) (m : List Bool) (s : State) : (run leave150To20Red m s).basis q = s.basis q := by obtain ⟨ha0, hb0, hbt, hr0, hr14, hwp⟩ := box2_150_consts have hb := red150_box2 refine run_preserves_outside leave150To20Red m s q (fun hm => hq ?_) unfold leave150To20Red at hm; simp only [wires_append, Finset.mem_union] at hm rcases hm with (h | h) | h · have hall : AllW (fun w => Shadow7.leaveBox2 150 w) (CRTBarrel.before 150) := fun g hg w hw => by have h' := of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp hb.1 g hg) w hw) unfold Shadow7.leaveBox2; rw [show 150 + 14 = 164 from rfl, hr14, hr0, ha0, hb0, hwp] rw [ha0, hb0, hbt] at h'; unfold Wire at *; omega exact (allW_programs hall).1 q h · exact CRTWindow.barrel_box2 MixedWindow.j7 (by decide) (by decide) false q h · have hall : AllW (fun w => Shadow7.leaveBox2 150 w) afterRow150 := fun g hg w hw => by have h' := of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp hb.2.2.1 g hg) w hw) unfold Shadow7.leaveBox2; rw [show 150 + 14 = 164 from rfl, hr14, hr0, ha0, hb0, hwp] rw [ha0, hb0, hbt] at h'; unfold Wire at *; omega exact (allW_programs hall).1 q h attribute [local irreducible] run CRTBarrel.barrel in theorem leave150To20Red_keeps_mirror (q : Wire) (lo : 2070 ≤ (q : Nat) + 150) (m : List Bool) (s : State) : (run leave150To20Red m s).basis q = s.basis q := by obtain ⟨ha0, hb0, hbt, hr0, hr14, hwp⟩ := box2_150_consts have hb := red150_box2 refine run_preserves_outside leave150To20Red m s q (fun hm => ?_) have hle : (q : Nat) + 150 ≤ 2069 := by unfold leave150To20Red at hm; simp only [wires_append, Finset.mem_union] at hm rcases hm with (h | h) | h · have hall : AllW (fun w => (w : Nat) + 150 ≤ 2069) (CRTBarrel.before 150) := fun g hg w hw => of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp hb.2.1 g hg) w hw) exact (allW_programs hall).1 q h · have hbox := CRTWindow.barrel_box2 MixedWindow.j7 (by decide) (by decide) false q h unfold Shadow7.leaveBox2 at hbox rw [show start MixedWindow.j7 = 150 from rfl, show 150 + 14 = 164 from rfl, hr14, hr0] at hbox unfold Wire at *; omega · have hall : AllW (fun w => (w : Nat) + 150 ≤ 2069) afterRow150 := fun g hg w hw => of_decide_eq_true (List.all_eq_true.mp (List.all_eq_true.mp hb.2.2.2 g hg) w hw) exact (allW_programs hall).1 q h unfold Wire at *; omega end LeaveRed150Proofs end ECDSAAdd.Entrant.StairPacket.Shadow20.Trans150 end -- ==== end Shadow7Wide20Trans150 ==== -- ==== begin Shadow7Wide20End150 ==== section /-! # Transition Block `s = 150 -> 165` Endpoint & Mixed Window Slot Bounds (`Shadow7Wide20End150`) -/ namespace ECDSAAdd.Entrant.StairPacket.Shadow20.Trans150 open ECDSAAdd.Arithmetic open ECDSAAdd.Arithmetic.MappedCompressed open ECDSAAdd.Challenge open ECDSAAdd.Entrant.IntegerPacket open ECDSAAdd.Entrant.StairPacket open ECDSAAdd.Entrant.StairPacket.Partial open ECDSAAdd.Entrant.StairPacket.GateMirror open ECDSAAdd.Entrant.StairPacket.PortalAnd open ECDSAAdd.Entrant.StairPacket.RailPair open ECDSAAdd.Entrant.StairPacket.Shadow open ECDSAAdd.Entrant.StairPacket.WideReference open ECDSAAdd.Entrant.StairPacket.Shadow20 open ECDSAAdd.Entrant.StairPacket.Shadow20.LeaveCut20 open SkywalkNat IntegerHigh set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false set_option linter.unusedSimpArgs false /-! ### Section 4: `endpoint150To20` -/ private theorem swaps150_entry_no_target : (LeaveJ7.entryOps 150).all (fun g => decide (¬ (1194 ≤ (GateMirror.target g : Nat) ∧ (GateMirror.target g : Nat) ≤ 1208))) = true := by decide +kernel private theorem swaps150_away : ∀ i : Fin 15, (1194 + i.val : Wire) ≠ Shadow7.e0P 150 + 4 ∧ (1194 + i.val : Wire) ∉ RailPair.sites low150 ∧ (1194 + i.val : Wire) ∉ LeaveJ7.history MixedWindow.j7 ∧ (1194 + i.val : Wire) ∉ smallM150 := by decide +kernel attribute [local irreducible] run SkywalkNat.step Shadow.far GateMirror.forward leave150To20 beforeStore150Prog storeMapped150Prog head150Prog in private theorem swaps150_kept (s : State) (m : List Bool) (z : SkywalkNat.State) (G S : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z G S) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) (i : Fin 15) : (run leave150To20 m s).basis (1194 + i.val) = s.basis (1194 + i.val) := by have hi := i.isLt have w := whole150_result s m z G S h nextSmall20 have hhead := (leaveMove150_head_eq s z G S h).2 m have hhst_eq : run head150Prog m s = swap2St (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s) := by unfold head150Prog; exact hhead have hsrc : LeaveRelocation.source movesP150Lit (1194 + i.val) = 1194 + i.val := by unfold movesP150Lit rw [LeaveRelocation.append, src150_flags_out _ (by unfold Wire; omega), src150_bank_out _ (Or.inr (Or.inl ⟨by unfold Wire; omega, by unfold Wire; omega⟩))] have haw := swaps150_away i rw [w.2.2.2.2.2.2.2.2.2.2.1 _, movesP150_eq, hsrc] simp only [writeBit, Function.update_of_ne haw.1] rw [w.2.2.2.2.2.2.2.2.2.2.2.2.2 _ haw.2.1 haw.2.2.1, w.2.2.2.2.2.2.2.2.2.2.2.2.1 (1194 + i.val) (by omega) (by omega) (by omega) haw.2.2.2, hhst_eq, swap2St_other (1194 + i.val) (by omega) (by omega) (by omega) (by omega)] have hst_eq : run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s = run (GateMirror.forward (LeaveJ7.bodyOps MixedWindow.j7)) [] (run (GateMirror.forward (LeaveJ7.entryOps 150)) [] s) := by rw [show Shadow7.leaveHeadOps 150 = LeaveJ7.entryOps 150 ++ LeaveJ7.bodyOps MixedWindow.j7 from (LeaveJ7.head_eq MixedWindow.j7).symm, forward_app, run_append, run_take, List.drop_nil] rw [hst_eq] have hnm : ¬ LeaveJ7.midT MixedWindow.j7 (1194 + i.val) := by unfold LeaveJ7.midT LeaveJ7.workT rw [show start MixedWindow.j7 = 150 from rfl, show Shadow7.a0P 150 = 355 by decide, show Shadow7.b0P 150 = 960 by decide, show Shadow7.e0P 150 = 1747 by decide] omega rw [LeaveReadoutFrame.preserved _ _ _ _ (fun hit => hnm (LeaveJ7.body_dest MixedWindow.j7 (by decide) (by decide) _ hit))] refine LeaveReadoutFrame.preserved _ _ _ _ (fun hit => ?_) rw [forward_map_dest] at hit; obtain ⟨g, hg, e⟩ := List.mem_map.mp hit have ht := of_decide_eq_true (List.all_eq_true.mp swaps150_entry_no_target g hg) rw [e] at ht; unfold Wire at ht; omega private theorem readCells_congr (sh : IntegerPacket.Shape) (b1 b2 : BasisState) : ∀ a n, (∀ k, a ≤ k → k < a + n → IntegerPacket.cell sh k b1 = IntegerPacket.cell sh k b2) → IntegerPacket.readCells sh a n b1 = IntegerPacket.readCells sh a n b2 | _, 0, _ => rfl | a, n + 1, h => by simp only [IntegerPacket.readCells, h a (Nat.le_refl _) (by omega), readCells_congr sh b1 b2 (a + 1) n (fun k h1 h2 => h k (by omega) (by omega))] private theorem physicalCells150_eq (s t : State) (ha : ∀ i : Fin 15, t.basis (166 + i.val) = s.basis (166 + i.val)) (hs : ∀ i : Fin 15, t.basis (1194 + i.val) = s.basis (1194 + i.val)) : Shadow7.physicalCells MixedWindow.j7 t = Shadow7.physicalCells MixedWindow.j7 s := by apply readCells_congr intro k _ hk have hgeo : windowNet MixedWindow.j7 (IntegerPacket.ports (Shadow7.shape MixedWindow.j7) k).a0 = 166 + k ∧ windowNet MixedWindow.j7 (IntegerPacket.ports (Shadow7.shape MixedWindow.j7) k).history = 1194 + k := by constructor · show OB5.sig 164 (150 + k + 16) = 166 + k unfold OB5.sig; rw [if_neg (by unfold Wire; omega)]; unfold Wire; omega · show OB5.sig 164 (150 + k + 16 + 1028) = 1194 + k unfold OB5.sig; rw [if_neg (by unfold Wire; omega)]; unfold Wire; omega unfold IntegerPacket.cell mappedBasis rw [hgeo.1, hgeo.2, ha ⟨k, by omega⟩, hs ⟨k, by omega⟩] private theorem archive150_flag_ports : Archive150.rawPorts 20 = e0P20 165 + 6 ∧ Archive150.rawPorts 21 = e0P20 165 + 7 ∧ Archive150.rawPorts 22 = e0P20 165 + 8 := by decide +kernel theorem archiveCut150To20 (s : State) (m : List Bool) (z : SkywalkNat.State) (G S : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z G S) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) : PastFacts MixedWindow.j7 Archive150.rawPorts (Shadow7.sbP 150) z G S (HighBankSum.crossBit (LeaveJ7.TrueMiddle.d MixedWindow.j7 z)) (run leave150To20 m s) := by have w := whole150_result s m z G S h nextSmall20 have hkept : Shadow7.physicalCells MixedWindow.j7 (run leave150To20 m s) = Shadow7.physicalCells MixedWindow.j7 s := physicalCells150_eq s (run leave150To20 m s) (fun i => w.2.2.2.2.2.2.2.1 (166 + i.val) (List.mem_map.mpr ⟨i.val, List.mem_range.mpr i.isLt, rfl⟩)) (fun i => swaps150_kept s m z G S h nextSmall20 i) have hrec : Shadow7.physicalCells MixedWindow.j7 (run leave150To20 m s) = SkywalkTrace.trace 15 (SkywalkRails.encode G S z.u z.v) := hkept.trans h.record have hfp := archive150_flag_ports refine ⟨hrec, ?_, ?_, ?_⟩ · rw [hfp.1]; exact w.2.2.2.2.1 · rw [hfp.2.1, ← Shadow7.physicalCells_eq, hrec, w.2.2.2.2.2.1] by_cases active : Shadow.far (Shadow7.sbP 150) 15 z · rw [LeaveJ7.Far.orient (Shadow7.sbP 150) z ⟨h.farSmall, h.endSmall⟩ active] · simp [active] · rw [hfp.2.2]; exact w.2.2.2.2.2.2.1 def zeros150 : List Nat := List.range' 1556 (e0P20 165 + 3 - 1556) ++ List.range' (e0P20 165 + 9) (1813 - (e0P20 165 + 9)) private theorem src150_flags_out_gen (q : Nat) (h57 : q ≠ 1557) (h58 : q ≠ 1558) (hfl : q < 1745 ∨ 1754 < q) : LeaveRelocation.source flagPairs150 q = q := by apply LeaveRelocation.outside; intro p hp simp only [flagPairs150, List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl | rfl | rfl | rfl <;> exact ⟨by unfold Wire at *; omega, by unfold Wire at *; omega⟩ private theorem zeros150_active_class : ∀ q ∈ ([1556, 1557, 1558, 1751, 1752, 1753, 1754] ++ List.range' 1598 15 : List Nat), let r := LeaveRelocation.source movesP150Lit q r = Shadow7.e0P 150 + 4 ∨ (r ≠ Shadow7.e0P 150 + 4 ∧ r ∉ RailPair.sites low150 ∧ r ∉ LeaveJ7.history MixedWindow.j7 ∧ (r = 1556 ∨ (r ≠ 1556 ∧ r ≠ 1557 ∧ r ≠ 1558 ∧ r ∉ smallM150 ∧ ((r = 984 ∨ r = 985) ∨ (r ≠ 364 ∧ r ≠ 984 ∧ r ≠ 365 ∧ r ≠ 985 ∧ ((1559 ≤ r ∧ r < 1598) ∨ (1613 ≤ r ∧ r < Shadow7.e0P 150 + 3) ∨ (Shadow7.e0P 150 + 8 ≤ r ∧ r < 1813) ∨ (Shadow7.b0P 150 + 11 ≤ r ∧ r < Shadow7.b0P 150 + 24))))))) := by decide +kernel private theorem zeros150_src_class : ∀ q ∈ zeros150, let r := LeaveRelocation.source movesP150Lit q r = Shadow7.e0P 150 + 4 ∨ (r ≠ Shadow7.e0P 150 + 4 ∧ r ∉ RailPair.sites low150 ∧ r ∉ LeaveJ7.history MixedWindow.j7 ∧ (r = 1556 ∨ (r ≠ 1556 ∧ r ≠ 1557 ∧ r ≠ 1558 ∧ r ∉ smallM150 ∧ ((r = 984 ∨ r = 985) ∨ (r ≠ 364 ∧ r ≠ 984 ∧ r ≠ 365 ∧ r ≠ 985 ∧ ((1559 ≤ r ∧ r < 1598) ∨ (1613 ≤ r ∧ r < Shadow7.e0P 150 + 3) ∨ (Shadow7.e0P 150 + 8 ≤ r ∧ r < 1813) ∨ (Shadow7.b0P 150 + 11 ≤ r ∧ r < Shadow7.b0P 150 + 24))))))) := by intro q hq by_cases hact : q ∈ ([1556, 1557, 1558, 1751, 1752, 1753, 1754] ++ List.range' 1598 15 : List Nat) · exact zeros150_active_class q hact · simp only [zeros150, show e0P20 165 = 1742 by decide, List.mem_append, List.mem_range'_1] at hq simp only [List.mem_append, List.mem_cons, List.not_mem_nil, or_false, List.mem_range'_1, not_or, not_and] at hact have hsrc : LeaveRelocation.source movesP150Lit q = q := by unfold movesP150Lit rw [LeaveRelocation.append, src150_flags_out_gen q (by omega) (by omega) (by omega), src150_bank_out q (by change q < 971 ∨ (1043 < q ∧ q < 1598) ∨ 1612 < q; omega)] rw [hsrc] have hnotL : (q : Wire) ∉ RailPair.sites low150 := by intro hm; obtain ⟨p, hp, hqp⟩ := List.mem_flatMap.mp hm; obtain ⟨i, hi, rfl⟩ := List.mem_map.mp hp rw [List.mem_range] at hi; simp only [List.mem_cons, List.not_mem_nil, or_false] at hqp have hg : Shadow7.a0P 150 = 355 ∧ Shadow7.b0P 150 = 960 ∧ lows150 = 12 := by decide rcases hqp with e | e <;> (unfold Wire at *; omega) have hnotH : (q : Wire) ∉ LeaveJ7.history MixedWindow.j7 := by intro hm; unfold LeaveJ7.history at hm; rw [show start MixedWindow.j7 = 150 from rfl] at hm obtain ⟨i, hi, e⟩ := List.mem_map.mp hm; rw [List.mem_range] at hi; unfold Wire at *; omega have hnotM : (q : Wire) ∉ smallM150 := not_mem_smallM150 q (Or.inr (by change 972 ≤ q; omega)) have he0 : Shadow7.e0P 150 = 1747 := by decide have hb0 : Shadow7.b0P 150 = 960 := by decide refine Or.inr ⟨by change q ≠ Shadow7.e0P 150 + 4; rw [he0]; omega, hnotL, hnotH, Or.inr ⟨by change q ≠ 1556; omega, by change q ≠ 1557; omega, by change q ≠ 1558; omega, hnotM, Or.inr ⟨by change q ≠ 364; omega, by change q ≠ 984; omega, by change q ≠ 365; omega, by change q ≠ 985; omega, ?_⟩⟩⟩ rw [he0, hb0]; unfold Wire; omega private theorem row150_free_vals : (LeaveJ7.row MixedWindow.j7 ⟨10, by decide⟩).free = 364 ∧ (LeaveJ7.row MixedWindow.j7 ⟨11, by decide⟩).free = 365 ∧ (∀ k : Fin 5, (LeaveJ7.row MixedWindow.j7 ⟨12 + k.val, by omega⟩).free = Shadow7.a0P 150 + 11 + k.val) := by have ha0 : Shadow7.a0P 150 = 355 := by decide have hlows : Shadow7.lowsP 150 = 10 := by decide refine ⟨?_, ?_, ?_⟩ · rw [LeaveJ7.row_free, if_neg (by decide), show start MixedWindow.j7 = 150 from rfl, ha0] · rw [LeaveJ7.row_free, if_neg (by decide), show start MixedWindow.j7 = 150 from rfl, ha0] · intro k; rw [LeaveJ7.row_free, if_neg (by rw [show start MixedWindow.j7 = 150 from rfl, hlows]; omega), show start MixedWindow.j7 = 150 from rfl, ha0]; simp only [Wire] at *; omega private theorem upperA150_src : ∀ i : Fin 5, LeaveRelocation.source movesP150Lit (Shadow7.a0P 150 + 11 + i.val) = Shadow7.a0P 150 + 11 + i.val ∧ (Shadow7.a0P 150 + 11 + i.val : Wire) ≠ Shadow7.e0P 150 + 4 ∧ Shadow7.a0P 150 + 11 + i.val ∉ RailPair.sites low150 ∧ Shadow7.a0P 150 + 11 + i.val ∉ LeaveJ7.history MixedWindow.j7 ∧ (Shadow7.a0P 150 + 11 + i.val : Wire) ≠ 1556 ∧ (Shadow7.a0P 150 + 11 + i.val : Wire) ≠ 1557 ∧ (Shadow7.a0P 150 + 11 + i.val : Wire) ≠ 1558 ∧ Shadow7.a0P 150 + 11 + i.val ∉ smallM150 ∧ (Shadow7.a0P 150 + 11 + i.val : Wire) ≠ 364 ∧ (Shadow7.a0P 150 + 11 + i.val : Wire) ≠ 984 ∧ (Shadow7.a0P 150 + 11 + i.val : Wire) ≠ 365 ∧ (Shadow7.a0P 150 + 11 + i.val : Wire) ≠ 985 := by intro i refine ⟨?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_, ?_⟩ all_goals (revert i; decide +kernel) section Endpoint150 attribute [local irreducible] run SkywalkNat.step Shadow.far GateMirror.forward CRTBarrel.barrel Shadow7.leaveHeadOps leave150To20 leaveAfter150To20 beforeStore150Prog storeMapped150Prog head150Prog movesP150Lit movesP150To20 NativeJ7.nextWindow Shadow7.enterP Shadow7.body private theorem boundaryClean150To20 (s : State) (m : List Bool) (z : SkywalkNat.State) (G S : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z G S) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) (quiet : ∀ q ∈ LeaveJ7.CoreCheckpoint.rawSites MixedWindow.j7, s.basis q = false) : ∀ q ∈ zeros150, (run leave150To20 m s).basis q = false := by let u := LeaveJ7.Admission.flags z G S have w := whole150_result s m z G S h nextSmall20 have par := LeaveJ7.RecordedParity.result MixedWindow.j7 (by decide) (by decide) s z G S ⟨h.farSmall, h.endSmall⟩ h.odd h.record have mode : LeaveSelector.actualMode (Shadow7.sbP 150) z = LeaveSelector.farMode (s.basis (Shadow7.e0P 150 + 3)) (s.basis (Shadow7.e0P 150 + 4)) z.u := by have hf := h.far; have hs := h.side rw [show start MixedWindow.j7 = 150 from rfl] at hf hs rw [hf, hs]; exact LeaveTraceHistory.flags _ _ have ev := LeaveJ7.RecordedEvents.result MixedWindow.j7 (by decide) (by decide) s z G S ⟨h.farSmall, h.endSmall⟩ h.odd h.record have hck := LeaveJ7.CoreCheckpoint.result MixedWindow.j7 (by decide) (by decide) s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 (LeaveJ7.RecordedEvents.glueFlag MixedWindow.j7 (by decide) (by decide) s z G S ⟨h.farSmall, h.endSmall⟩ h.odd h.record h.far h.side) have hhead := (leaveMove150_head_eq s z G S h).2 m have hhst_eq : run head150Prog m s = swap2St (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s) := by unfold head150Prog; exact hhead have hck_prog : LeaveJ7.CoreCheckpoint.program MixedWindow.j7 = GateMirror.forward (Shadow7.leaveHeadOps 150) := rfl rw [hck_prog] at hck intro q hq rw [w.2.2.2.2.2.2.2.2.2.2.1 q, movesP150_eq] rcases zeros150_src_class q hq with heq | ⟨hne4, hnl, hnh, hsrc⟩ · rw [heq]; simp [writeBit] · simp only [writeBit, Function.update_of_ne hne4] rw [w.2.2.2.2.2.2.2.2.2.2.2.2.2 _ hnl hnh] rcases hsrc with h56 | ⟨hn56, hn57, hn58, hnM, h98 | ⟨h1, h2, h3, h4, hr⟩⟩ · rw [h56]; exact w.2.2.2.2.2.2.2.2.2.2.2.1 · rw [w.2.2.2.2.2.2.2.2.2.2.2.2.1 _ hn56 hn57 hn58 hnM, hhst_eq] rcases h98 with hA10 | hA11 · rw [hA10, show (swap2St _).basis 984 = (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s).basis 364 by simp [swap2St, swap2, swap1]] rw [← row150_free_vals.1]; exact hck.2.1 ⟨10, by decide⟩ · rw [hA11, show (swap2St _).basis 985 = (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s).basis 365 by simp [swap2St, swap2, swap1]] rw [← row150_free_vals.2.1]; exact hck.2.1 ⟨11, by decide⟩ · rw [w.2.2.2.2.2.2.2.2.2.2.2.2.1 _ hn56 hn57 hn58 hnM, hhst_eq, swap2St_other _ h1 h2 h3 h4] have hmem : LeaveRelocation.source movesP150Lit q ∈ LeaveJ7.CoreCheckpoint.targets MixedWindow.j7 := LeaveJ7.BoundaryClean.mem_targets MixedWindow.j7 (by decide) (by decide) _ (by rw [show start MixedWindow.j7 = 150 from rfl, show Shadow7.lowsP 150 = 10 by decide] rcases hr with h | h | h | h · left; exact h · right; left; exact h · right; right; left; exact ⟨h.1, by simp only [Wire] at h ⊢; omega⟩ · right; right; right; have hb960 : Shadow7.b0P 150 = 960 := by decide simp only [Wire] at h ⊢; omega) simp only [LeaveJ7.CoreCheckpoint.targets, List.mem_append, List.mem_range'_1, List.mem_map, List.mem_finRange, true_and] at hmem rcases hmem with ((⟨lo, hi⟩ | ⟨r, hrf⟩) | hraw) | hmag · rw [← Nat.add_sub_of_le lo] exact hck.1 ⟨_, Nat.sub_lt_left_of_lt_add lo hi⟩ · rw [← hrf]; exact hck.2.1 r · exact (hck.2.2.1 _ hraw).trans (quiet _ hraw) · exact hck.2.2.2 _ hmag private theorem boundaryRails150To20 (s : State) (m : List Bool) (z : SkywalkNat.State) (G S : Bool) (h : LeaveJ7.Admission.Inputs MixedWindow.j7 s z G S) (nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] z)) (highZero : ∀ q : Nat, Shadow7.a0P 150 + 16 ≤ q → q ≤ 180 + railP 165 → s.basis q = false) (raw : State) (input : let a := step^[15] z let u := LeaveJ7.Admission.flags z G S SkywalkIntegerInput (LeaveJ7.WideWords.L MixedWindow.j7) (SkywalkRails.encode u.1 u.2 a.u a.v).a (SkywalkRails.encode u.1 u.2 a.u a.v).b u.1 raw.basis) : let o := pullState (OB5.sig 164) raw let out := run leave150To20 m s (∀ i : Fin (sbP20 165 + 22), out.basis (165 + 16 + i.val) = o.basis (165 + 16 + i.val) ∧ out.basis (786 + i.val) = o.basis (786 + i.val)) ∧ (∀ i : Fin (wpP20 165 - 2), out.basis (Shadow7.a0P 150 - 1 + lows150 + i.val) = false ∧ out.basis (Shadow7.b0P 150 - 1 + lows150 + i.val) = (if o.basis 180 then o.basis (Shadow7.b0P 150 - 1 + lows150 + i.val) else o.basis (Shadow7.a0P 150 - 1 + lows150 + i.val))) := by let a := step^[15] z let u := LeaveJ7.Admission.flags z G S let o := pullState (OB5.sig 164) raw have w := whole150_result s m z G S h nextSmall20 have hsb : Shadow7.sbP 150 = 173 := by decide have ha0 : Shadow7.a0P 150 = 355 := by decide have hb0 : Shadow7.b0P 150 = 960 := by decide have hr165 : railP 165 = 258 := by decide have hlow12 : lows150 = 12 := by decide have hsb20 : sbP20 165 = 163 := by decide have hwp20 : wpP20 165 = 75 := by decide have orient : o.basis 180 = u.1 := by have geo : (LeaveJ7.WideWords.L MixedWindow.j7).previous = OB5.sig 164 180 := by decide change raw.basis (OB5.sig 164 180) = u.1 rw [← geo]; exact input.2.2.1 have law := LeaveShadowRails.retainedLow_shadow7 173 z h.farSmall u.2 have par := LeaveJ7.RecordedParity.result MixedWindow.j7 (by decide) (by decide) s z G S ⟨h.farSmall, h.endSmall⟩ h.odd h.record have mode : LeaveSelector.actualMode (Shadow7.sbP 150) z = LeaveSelector.farMode (s.basis (Shadow7.e0P 150 + 3)) (s.basis (Shadow7.e0P 150 + 4)) z.u := by have hf := h.far; have hs := h.side rw [show start MixedWindow.j7 = 150 from rfl] at hf hs rw [hf, hs]; exact LeaveTraceHistory.flags _ _ have ev := LeaveJ7.RecordedEvents.result MixedWindow.j7 (by decide) (by decide) s z G S ⟨h.farSmall, h.endSmall⟩ h.odd h.record have hck := LeaveJ7.CoreCheckpoint.result MixedWindow.j7 (by decide) (by decide) s [] z u.1 u.2 ⟨h.farSmall, h.endSmall⟩ h.ready h.fresh h.scratch h.temp h.odd h.room h.clean h.padding h.bank h.zero par mode ev.2 (LeaveJ7.RecordedEvents.glueFlag MixedWindow.j7 (by decide) (by decide) s z G S ⟨h.farSmall, h.endSmall⟩ h.odd h.record h.far h.side) have hhead := (leaveMove150_head_eq s z G S h).2 m have hhst_eq : run head150Prog m s = swap2St (run (GateMirror.forward (Shadow7.leaveHeadOps 150)) [] s) := by unfold head150Prog; exact hhead have hck_prog : LeaveJ7.CoreCheckpoint.program MixedWindow.j7 = GateMirror.forward (Shadow7.leaveHeadOps 150) := rfl rw [hck_prog] at hck constructor · intro i have hi : i.val < 185 := by have := i.isLt; omega have ref := LeaveJ7.WideWords.wide MixedWindow.j7 (by decide) (by decide) a u.1 u.2 raw input ⟨i.val, by rw [show start MixedWindow.j7 = 150 from rfl, hr165]; omega⟩ dsimp only at ref rw [show start MixedWindow.j7 = 150 from rfl] at ref by_cases low : i.val < 173 · have hw := LeaveJ7.WideWords.short MixedWindow.j7 (by decide) (by decide) (step^[15] (Shadow.reduced (Shadow7.sbP 150) 15 z)) u.1 u.2 s h.ready ⟨i.val, by rw [show start MixedWindow.j7 = 150 from rfl, hsb]; exact low⟩ dsimp only at hw; rw [show start MixedWindow.j7 = 150 from rfl] at hw have hna : ¬ Shadow7.leaveBox2 150 (165 + 16 + i.val) := by unfold Shadow7.leaveBox2 rw [show 150 + 14 = 164 from rfl, show railP 164 = 258 by decide, show railP 150 = 258 by decide, ha0, hb0, show Shadow7.wpP 150 = 70 by decide] omega have hnb : ¬ Shadow7.leaveBox2 150 (786 + i.val) := by unfold Shadow7.leaveBox2 rw [show 150 + 14 = 164 from rfl, show railP 164 = 258 by decide, show railP 150 = 258 by decide, ha0, hb0, show Shadow7.wpP 150 = 70 by decide] omega have ua := leave150To20_keeps _ hna m s have ub := leave150To20_keeps _ hnb m s have spos := LeaveJ7.BoundaryRails.sharedDigitLow _ _ 173 i.val law.2.1 low have smag := LeaveJ7.BoundaryRails.sharedDigitLow _ _ 173 i.val law.2.2 low rw [law.1, spos, smag] at ref rw [hsb] at hw exact ⟨ua.trans (hw.1.trans ref.1.symm), ub.trans (hw.2.trans ref.2.symm)⟩ · have hk : i.val - 173 < 12 := by omega have vals := w.2.2.2.2.2.2.2.2.1 ⟨i.val - 173, hk⟩ dsimp only at vals rw [show 173 + (i.val - 173) = i.val by omega, show Shadow7.a0P 150 - 1 + (i.val - 173) = 165 + 16 + i.val by rw [ha0]; omega, show Shadow7.b0P 150 - 1 + (i.val - 173) = 786 + i.val by rw [hb0]; omega] at vals exact ⟨vals.1.trans ref.1.symm, vals.2.trans ref.2.symm⟩ · intro i have hi : i.val < 73 := by have := i.isLt; omega have ref := LeaveJ7.WideWords.wide MixedWindow.j7 (by decide) (by decide) a u.1 u.2 raw input ⟨185 + i.val, by rw [show start MixedWindow.j7 = 150 from rfl, hr165]; omega⟩ dsimp only at ref; rw [show start MixedWindow.j7 = 150 from rfl] at ref rw [show 150 + 31 + (185 + i.val) = Shadow7.a0P 150 - 1 + lows150 + i.val by rw [ha0, hlow12]; omega, show 786 + (185 + i.val) = Shadow7.b0P 150 - 1 + lows150 + i.val by rw [hb0, hlow12]; omega] at ref constructor · by_cases h5 : i.val < 5 · have ua := upperA150_src ⟨i.val, h5⟩ have hloc : Shadow7.a0P 150 - 1 + lows150 + i.val = Shadow7.a0P 150 + 11 + i.val := by have := ha0; have := hlow12; omega rw [hloc, w.2.2.2.2.2.2.2.2.2.2.1 _, movesP150_eq, ua.1] simp only [writeBit, Function.update_of_ne ua.2.1] rw [w.2.2.2.2.2.2.2.2.2.2.2.2.2 _ ua.2.2.1 ua.2.2.2.1, w.2.2.2.2.2.2.2.2.2.2.2.2.1 _ ua.2.2.2.2.1 ua.2.2.2.2.2.1 ua.2.2.2.2.2.2.1 ua.2.2.2.2.2.2.2.1, hhst_eq, swap2St_other _ ua.2.2.2.2.2.2.2.2.1 ua.2.2.2.2.2.2.2.2.2.1 ua.2.2.2.2.2.2.2.2.2.2.1 ua.2.2.2.2.2.2.2.2.2.2.2] rw [← row150_free_vals.2.2 ⟨i.val, h5⟩] exact hck.2.1 ⟨12 + i.val, by omega⟩ · have hna : ¬ Shadow7.leaveBox2 150 (Shadow7.a0P 150 - 1 + lows150 + i.val) := by unfold Shadow7.leaveBox2 rw [show 150 + 14 = 164 from rfl, show railP 164 = 258 by decide, show railP 150 = 258 by decide, ha0, hb0, show Shadow7.wpP 150 = 70 by decide, hlow12] omega rw [leave150To20_keeps _ hna m s] exact highZero _ (by rw [ha0, hlow12]; omega) (by rw [ha0, hlow12, hr165]; omega) · have hb := w.2.2.2.2.2.2.2.2.2.1 i rw [show Shadow7.b0P 150 + lows150 - 1 + i.val = Shadow7.b0P 150 - 1 + lows150 + i.val by have := hb0; omega, show 173 + lows150 + i.val = 185 + i.val by simp [hlow12]] at hb rw [orient, hb] cases h1 : u.1 <;> simp only [h1, Bool.false_eq_true, ite_false, ite_true] at ref ⊢ · exact ref.1.symm · exact ref.2.symm private theorem assembleCut150To20 (s o : State) (neg far long : Bool) (phase : s.phase = o.phase) (sign : s.basis (EnterJ20.flagN ⟨0, by decide⟩) = neg) (mode : s.basis (EnterJ20.flagF ⟨0, by decide⟩) = far) (side : s.basis (EnterJ20.flagU ⟨0, by decide⟩) = long) (low : ∀ i : Fin (sbP20 165 + 22), s.basis (165 + 16 + i.val) = o.basis (165 + 16 + i.val) ∧ s.basis (786 + i.val) = o.basis (786 + i.val)) (high : ∀ i : Fin (wpP20 165 - 2), s.basis (165 + EnterJ20.h20 ⟨0, by decide⟩ + 33 + i.val) = false ∧ s.basis (EnterJ20.h20 ⟨0, by decide⟩ + 803 + i.val) = (if o.basis (EnterJ20.gate ⟨0, by decide⟩) then o.basis (EnterJ20.h20 ⟨0, by decide⟩ + 803 + i.val) else o.basis (165 + EnterJ20.h20 ⟨0, by decide⟩ + 33 + i.val))) (ext : ∀ q : Wire, ¬ WideReference.Box 150 q → ¬ LeaveJ7.AssembleCut.leftovers MixedWindow.j7 q → ¬ (2070 ≤ (q : Nat) + 150 ∧ (q : Nat) ≤ 1812) → s.basis q = o.basis q) (mirror : ∀ q : Nat, 2070 ≤ q + 150 → q ≤ 1812 → s.basis q = o.basis q) (left : ∀ q, LeaveJ7.AssembleCut.leftovers MixedWindow.j7 q → s.basis q = o.basis q) (clear : ∀ q ∈ zeros150, s.basis q = false) (carry : ∀ q : Nat, 1556 ≤ q → q + 150 ≤ 2054 → q ≤ 1812 → o.basis q = false) : PackedCut (EnterJ20.lowerPairs ⟨0, by decide⟩) (EnterJ20.upperPairs ⟨0, by decide⟩) (EnterJ20.gate ⟨0, by decide⟩) (EnterJ20.flagN ⟨0, by decide⟩) (EnterJ20.flagF ⟨0, by decide⟩) (EnterJ20.flagU ⟨0, by decide⟩) neg far long o (eraseSites (EnterJ20.pending ⟨0, by decide⟩) s) := by let k0 : Fin 9 := ⟨0, by decide⟩ have hk0 : EnterJ20.flagN k0 = 1747 ∧ EnterJ20.flagF k0 = 1745 ∧ EnterJ20.flagU k0 = 1746 ∧ EnterJ20.pending k0 = [1748, 1749, 1750] ∧ EnterJ20.h20 k0 = 168 ∧ EnterJ20.lowerPairs k0 = [(364, 969), (365, 970)] ∧ EnterJ20.upperPairs k0 = (List.range 73).map (fun i => (366 + i, 971 + i)) := by decide +kernel have away (q : Wire) (hq : (q : Nat) < 1556) : (eraseSites (EnterJ20.pending k0) s).basis q = s.basis q := by have no : q ∉ EnterJ20.pending k0 := by rw [hk0.2.2.2.1]; simp only [List.mem_cons, List.not_mem_nil, or_false]; unfold Wire at *; omega simp [eraseSites, no] have flagOff (q : Wire) (hq : q = 1747 ∨ q = 1745 ∨ q = 1746) : (eraseSites (EnterJ20.pending k0) s).basis q = s.basis q := by have no : q ∉ EnterJ20.pending k0 := by rw [hk0.2.2.2.1]; simp only [List.mem_cons, List.not_mem_nil, or_false]; rcases hq with rfl | rfl | rfl <;> decide simp [eraseSites, no] refine ⟨phase, ?_, ?_, ?_, ?_, ?_, ?_⟩ · rw [flagOff _ (Or.inl hk0.1)]; exact sign · rw [flagOff _ (Or.inr (Or.inl hk0.2.1))]; exact mode · rw [flagOff _ (Or.inr (Or.inr hk0.2.2.1))]; exact side · intro pair mem rw [hk0.2.2.2.2.2.1] at mem; simp only [List.mem_cons, List.not_mem_nil, or_false] at mem rcases mem with rfl | rfl <;> dsimp only <;> · rw [away _ (by decide), away _ (by decide)] first | exact low ⟨183, by decide⟩ | exact low ⟨184, by decide⟩ · intro pair mem rw [hk0.2.2.2.2.2.2] at mem; obtain ⟨i, hi, rfl⟩ := List.mem_map.mp mem; rw [List.mem_range] at hi; dsimp only rw [away _ (by unfold Wire; omega), away _ (by unfold Wire; omega)] have h' := high ⟨i, by rw [show wpP20 165 = 75 by decide]; omega⟩ dsimp only at h' rw [hk0.2.2.2.2.1] at h' exact h' · intro q notN notF notU notLo notHi have hsb20 : sbP20 165 = 163 := by decide change (eraseSites (EnterJ20.pending k0) s).basis q = o.basis q by_cases pend : q ∈ EnterJ20.pending k0 · have r : 1556 ≤ (q : Nat) ∧ (q : Nat) + 150 ≤ 2054 ∧ (q : Nat) ≤ 1812 := by rw [hk0.2.2.2.1] at pend; simp only [List.mem_cons, List.not_mem_nil, or_false] at pend rcases pend with rfl | rfl | rfl <;> decide simp [eraseSites, pend, carry q r.1 r.2.1 r.2.2] simp only [eraseSites, if_neg pend] by_cases lf : LeaveJ7.AssembleCut.leftovers MixedWindow.j7 q · exact left q lf have lf' := lf; unfold LeaveJ7.AssembleCut.leftovers LeaveJ7.ReleasedOrigin.releasedSite at lf' rw [show start MixedWindow.j7 = 150 from rfl] at lf'; simp only [not_or, not_and] at lf' by_cases inBox : WideReference.Box 150 q · have inBox' := inBox; unfold WideReference.Box at inBox' rw [LeaveJ7.AssembleCut.route_rail 150 (by decide), LeaveJ7.AssembleCut.route_rail 164 (by decide), show railP 150 = 258 by decide, show railP 164 = 258 by decide] at inBox' by_cases hc : 1556 ≤ (q : Nat) · have top : (q : Nat) + 150 ≤ 2054 ∧ (q : Nat) ≤ 1812 := by unfold Wire at *; rcases inBox' with h | h | h | h <;> omega rw [carry q hc top.1 top.2] apply clear q simp only [zeros150, List.mem_append, List.mem_range'_1, show e0P20 165 = 1742 by decide] rw [hk0.1] at notN; rw [hk0.2.1] at notF; rw [hk0.2.2.1] at notU; rw [hk0.2.2.2.1] at pend simp only [List.mem_cons, List.not_mem_nil, or_false, not_or] at pend unfold Wire at hc top notN notF notU pend rcases Nat.lt_or_ge q 1745 with hlt | hlt · left; omega · right; omega · have hrails : (181 ≤ (q : Nat) ∧ (q : Nat) < 439) ∨ (786 ≤ (q : Nat) ∧ (q : Nat) < 1044) := by unfold Wire at *; rcases inBox' with h | h | h | h <;> omega rcases hrails with ⟨a1, a2⟩ | ⟨b1, b2⟩ · by_cases lo : (q : Nat) < 366 · have l := (low ⟨q - 181, by rw [hsb20]; unfold Wire at *; omega⟩).1; dsimp only at l rwa [show 165 + 16 + ((q : Nat) - 181) = q by unfold Wire at *; omega] at l · exfalso; apply notHi rw [hk0.2.2.2.2.2.2] simp only [RailPair.sites, List.mem_flatMap, List.mem_map, List.mem_range] exact ⟨_, ⟨q - 366, by unfold Wire at *; omega, rfl⟩, by simp only [List.mem_cons]; left; unfold Wire at *; omega⟩ · by_cases lo : (q : Nat) < 971 · have l := (low ⟨q - 786, by rw [hsb20]; unfold Wire at *; omega⟩).2; dsimp only at l rwa [show 786 + ((q : Nat) - 786) = q by unfold Wire at *; omega] at l · exfalso; apply notHi rw [hk0.2.2.2.2.2.2] simp only [RailPair.sites, List.mem_flatMap, List.mem_map, List.mem_range] exact ⟨_, ⟨q - 971, by unfold Wire at *; omega, rfl⟩, by simp only [List.mem_cons, List.mem_singleton]; right; unfold Wire at *; omega⟩ · by_cases mi : 2070 ≤ (q : Nat) + 150 ∧ (q : Nat) ≤ 1812 · exact mirror q mi.1 mi.2 · exact ext q inBox lf mi private theorem frameHistory150To20 (x p : Nat) (good : Bounds x p) (raw s : State) (m : List Bool) (G S : Bool) (domain : Domain 150 x p raw) (input : InputAt 150 (SkywalkRails.encode G S (unsigned 150 x p).u (unsigned 150 x p).v) raw) (record : Shadow7.physicalCells MixedWindow.j7 s = SkywalkTrace.trace 15 (SkywalkRails.encode G S (unsigned 150 x p).u (unsigned 150 x p).v)) (kept : Shadow7.physicalCells MixedWindow.j7 (run leave150To20 m s) = Shadow7.physicalCells MixedWindow.j7 s) : ∀ q, LeaveJ7.AssembleCut.leftovers MixedWindow.j7 q → (run leave150To20 m s).basis q = (WideReference.origin 150 raw s).basis q := by let out := run leave150To20 m s let o := WideReference.origin 150 raw s have hgeo : ∀ i : Fin 15, windowNet MixedWindow.j7 (IntegerPacket.ports (Shadow7.shape MixedWindow.j7) i.val).a0 = 166 + i.val ∧ windowNet MixedWindow.j7 (IntegerPacket.ports (Shadow7.shape MixedWindow.j7) i.val).history = LeaveJ7.swaps MixedWindow.j7 i.val := by intro i; have hi := i.isLt constructor · show OB5.sig 164 (150 + i.val + 16) = 166 + i.val unfold OB5.sig; rw [if_neg (by unfold Wire; omega)]; unfold Wire; omega · show OB5.sig 164 (150 + i.val + 16 + 1028) = OB5.sig 164 (150 + 1044 + i.val) congr 1; unfold Wire; omega have agree (i : Fin 15) : out.basis (166 + i.val) = o.basis (166 + i.val) ∧ out.basis (LeaveJ7.swaps MixedWindow.j7 i.val) = o.basis (LeaveJ7.swaps MixedWindow.j7 i.val) := by have old := WideReference.recorded_equal 150 MixedWindow.j7 x p (by decide) (WideReference.places MixedWindow.j7) good raw s domain G S input record i have now := congrArg (fun a => StairArchiveRaw.read a i.val) kept change StairArchiveRaw.read (readCells (Shadow7.shape MixedWindow.j7) 0 15 (mappedBasis MixedWindow.j7 out.basis)) i.val = StairArchiveRaw.read (readCells (Shadow7.shape MixedWindow.j7) 0 15 (mappedBasis MixedWindow.j7 s.basis)) i.val at now rw [StairPacket.read_cells _ _ _ _ _ i.isLt, StairPacket.read_cells _ _ _ _ _ i.isLt, Nat.zero_add] at now have eq := now.trans old change (out.basis (windowNet MixedWindow.j7 (IntegerPacket.ports (Shadow7.shape MixedWindow.j7) i.val).a0), out.basis (windowNet MixedWindow.j7 (IntegerPacket.ports (Shadow7.shape MixedWindow.j7) i.val).history)) = (o.basis (windowNet MixedWindow.j7 (IntegerPacket.ports (Shadow7.shape MixedWindow.j7) i.val).a0), o.basis (windowNet MixedWindow.j7 (IntegerPacket.ports (Shadow7.shape MixedWindow.j7) i.val).history)) at eq rw [(hgeo i).1, (hgeo i).2] at eq exact ⟨congrArg Prod.fst eq, congrArg Prod.snd eq⟩ have inSites : (165 : Wire) ∈ WideReference.sites 150 := by apply (WideReference.mem_sites (i := 150) (by decide) 165).mpr rw [show OB5.sig 164 165 = 165 by decide] unfold WideReference.oldSites refine List.mem_flatMap.mpr ⟨149, List.mem_range'_1.mpr (by decide), ?_⟩ simp only [List.mem_cons, List.not_mem_nil, or_false, MappedCompressed.base]; decide have previous : out.basis 165 = o.basis 165 := by rw [show o.basis 165 = s.basis 165 from WideReference.inside 150 raw s 165 inSites] exact leave150To20_keeps 165 (by unfold Shadow7.leaveBox2; decide) m s have noRel : ∀ q : Wire, ¬ LeaveJ7.ReleasedOrigin.releasedSite MixedWindow.j7 q := by intro q hr; unfold LeaveJ7.ReleasedOrigin.releasedSite at hr rw [show start MixedWindow.j7 = 150 from rfl, show railP 150 = 258 by decide, show railP 165 = 258 by decide] at hr omega intro q residual unfold LeaveJ7.AssembleCut.leftovers at residual rw [show start MixedWindow.j7 = 150 from rfl] at residual rcases residual with ⟨lo, hi⟩ | ⟨lo, hi⟩ | rel | ⟨lo, hi, top⟩ · by_cases e : (q : Nat) = 165 · rw [show q = 165 from e]; exact previous · have a := (agree ⟨(q : Nat) - 166, by unfold Wire at *; omega⟩).1; dsimp only at a rwa [show 166 + ((q : Nat) - 166) = q by unfold Wire at *; omega] at a · have a := (agree ⟨(q : Nat) - 1194, by unfold Wire at *; omega⟩).2; dsimp only at a rwa [show LeaveJ7.swaps MixedWindow.j7 ((q : Nat) - 1194) = q by unfold LeaveJ7.swaps OB5.sig; rw [show start MixedWindow.j7 = 150 from rfl, if_neg (by unfold Wire at *; omega)] unfold Wire at *; omega] at a · exact absurd rel (noRel q) · unfold Wire at *; omega theorem endpoint150To20 (d : Bool) (x p : Nat) (good : Bounds x p) (raw s : State) (m n : List Bool) (domain : Domain 150 x p raw) (G S : Bool) (cut : PackedCut (EnterJ7.lowerPairs MixedWindow.j7) (EnterJ7.upperPairs MixedWindow.j7) (EnterJ7.gate MixedWindow.j7) (EnterJ7.flagN MixedWindow.j7) (EnterJ7.flagF MixedWindow.j7) (EnterJ7.flagU MixedWindow.j7) (PortalValues.negative S (unsigned 150 x p).u) (decide (Shadow.far (Shadow7.sbP 150) 15 (unsigned 150 x p))) (decide (Shadow.far (Shadow7.sbP 150) 15 (unsigned 150 x p) ∧ 2 ^ Shadow7.sbP 150 ≤ (unsigned 150 x p).u)) (pullState (EnterJ7.pull MixedWindow.j7) raw) (eraseSites (EnterJ7.pending MixedWindow.j7) s)) (input : SkywalkIntegerInput (EnterJ7.lay MixedWindow.j7) (SkywalkRails.encode G S (unsigned 150 x p).u (unsigned 150 x p).v).a (SkywalkRails.encode G S (unsigned 150 x p).u (unsigned 150 x p).v).b G raw.basis) (scratch : ∀ k : Fin 157, 23 ≤ k.val → let pre := run (Shadow7.enterP MixedWindow.j7) m s let tape := m.drop (measurementCount (Shadow7.enterP MixedWindow.j7)) (run (NativeJ7.program MixedWindow.j7 d) (tape.drop (measurementCount (Shadow7.routed MixedWindow.j7 0 1))) (run (Shadow7.routed MixedWindow.j7 0 1) tape pre)).basis (ArchiveJ7.rawPorts (NativeJ7.prev MixedWindow.j7) k) = false) (pg ps cross : Bool) (prior : PastFacts (NativeJ7.prev MixedWindow.j7) (ArchiveJ7.rawPorts (NativeJ7.prev MixedWindow.j7)) (Shadow7.sbP (start (NativeJ7.prev MixedWindow.j7))) (unsigned (start (NativeJ7.prev MixedWindow.j7)) x p) pg ps cross s) : let v := run (NativeJ7.nextWindow MixedWindow.j7 d) m s let out := run leave150To20 n v PackedCut (EnterJ20.lowerPairs ⟨0, by decide⟩) (EnterJ20.upperPairs ⟨0, by decide⟩) (EnterJ20.gate ⟨0, by decide⟩) (EnterJ20.flagN ⟨0, by decide⟩) (EnterJ20.flagF ⟨0, by decide⟩) (EnterJ20.flagU ⟨0, by decide⟩) (PortalValues.negative (LeaveJ7.Admission.flags (unsigned 150 x p) G S).2 (unsigned 165 x p).u) (decide (Shadow.far (sbP20 165) 20 (unsigned 165 x p))) (decide (Shadow.far (sbP20 165) 20 (unsigned 165 x p) ∧ 2 ^ sbP20 165 ≤ (unsigned 165 x p).u)) (pullState (EnterJ20.pull ⟨0, by decide⟩) (WideReference.endRaw 150 raw v)) (eraseSites (EnterJ20.pending ⟨0, by decide⟩) out) ∧ PastFacts MixedWindow.j7 Archive150.rawPorts (Shadow7.sbP 150) (unsigned 150 x p) G S (HighBankSum.crossBit (LeaveJ7.TrueMiddle.d MixedWindow.j7 (unsigned 150 x p))) out ∧ (∀ r, run leaveInv150To20 r out = v) := by have numbers := LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good have old := LeaveJ7.Admission.actualNumbers (NativeJ7.prev MixedWindow.j7) (by decide) (by decide) x p good have next20 := actualNumbers20 ⟨0, by decide⟩ x p good have hist := WideReference.pulled_history MixedWindow.j7 rfl domain have native := NativeJ7.from_domain MixedWindow.j7 (by decide) (by decide) d x p good raw s m domain G S cut input scratch pg ps cross prior obtain ⟨_, _, _, _, tags⟩ := NativeJ7.real_receipt MixedWindow.j7 (by decide) (by decide) d raw s m (unsigned 150 x p) G S numbers.odd numbers.farSmall cut input hist scratch (unsigned (start (NativeJ7.prev MixedWindow.j7)) x p) pg ps cross old.odd old.farSmall prior let pre := run (Shadow7.enterP MixedWindow.j7) m s let tape := m.drop (measurementCount (Shadow7.enterP MixedWindow.j7)) let T := Shadow.reduced (Shadow7.sbP 150) 15 (unsigned 150 x p) let Z := SkywalkRails.encode G S T.u T.v have to' : T.v % 2 = 1 := shadow_odd_shadow7 (Shadow7.sbP 150) (unsigned 150 x p) numbers.farSmall numbers.odd have parity : (Z.a + Z.b) % 2 = 1 := SkywalkRails.encode_odd_sum G S _ _ (by omega) have ready := EnterJ7.ready_pending_at MixedWindow.j7 raw s (unsigned 150 x p) G S m numbers.farSmall cut input hist obtain ⟨_, row, limit, frame⟩ := NativeJ7.admits MixedWindow.j7 (by decide) (by decide) d s m tape (tape.drop (measurementCount (Shadow7.routed MixedWindow.j7 0 1))) Z parity ready.2.1 scratch (unsigned (start (NativeJ7.prev MixedWindow.j7)) x p) pg ps cross old.odd old.farSmall prior have final := NativeJ7.archive_result MixedWindow.j7 (by decide) (by decide) d row limit _ _ frame have tail := NativeJ7.tail_clean MixedWindow.j7 (by decide) (by decide) d x p raw s domain m tape _ _ _ cut row final let v := run (NativeJ7.nextWindow MixedWindow.j7 d) m s have runEq : v = run (Shadow7.body MixedWindow.j7 (NativeJ7.withArchive MixedWindow.j7 d)) tape pre := by simp only [v, NativeJ7.nextWindow, NativeJ7.window, run_append, run_take, pre, tape] have gg : ∀ (g sg : Bool) (u v : Int), (SkywalkRails.encode g sg u v).g = g := fun g _ _ _ => by cases g <;> rfl have origIn : InputAt 150 (SkywalkRails.encode G S (unsigned 150 x p).u (unsigned 150 x p).v) raw := by unfold InputAt; rw [gg]; exact input have hAdm := native.1 have hPh := native.2.1 have endpointState : step^[15] (unsigned 150 x p) = unsigned 165 x p := by show step^[15] (step^[150] (init x p)) = step^[165] (init x p) rw [show (165 : Nat) = 150 + 15 by decide, Nat.add_comm, Function.iterate_add_apply] have nextSmall20 : Shadow7.SmallIfFar 163 20 (step^[15] (unsigned 150 x p)) := by rw [endpointState]; exact next20.small.1 have harch := archiveCut150To20 v n (unsigned 150 x p) G S hAdm nextSmall20 have hrt := fun r => leave150To20_roundtrip v (unsigned 150 x p) G S hAdm nextSmall20 n r refine ⟨?_, harch, hrt⟩ have bit : v.basis (Shadow7.e0P 150 + 8) = false := by have t2 := tags ⟨2, by decide⟩ have e : Shadow7.e0P 150 + 8 = Shadow7.sbP 150 + 1580 + (⟨2, by decide⟩ : Fin 3).val := by decide rw [e]; exact t2 have quiet : ∀ q ∈ LeaveJ7.CoreCheckpoint.rawSites MixedWindow.j7, v.basis q = false := by intro q hq simp only [LeaveJ7.CoreCheckpoint.rawSites, List.mem_append, List.mem_range'_1, List.mem_singleton] at hq rcases hq with (⟨lo, hi⟩ | ⟨lo, hi⟩) | p17 rotate_right · rw [p17]; exact hAdm.parked · exact LeaveJ7.native_carryJ MixedWindow.j7 (by decide) (by decide) _ v hAdm.ready hAdm.top hAdm.top2 q (by unfold Wire at *; omega) (by unfold Wire at *; omega) · by_cases e8 : (q : Nat) = Shadow7.e0P 150 + 8 · rw [show q = Shadow7.e0P 150 + 8 from e8]; exact bit · rw [runEq]; exact tail q (by simp only [NativeJ7.tailTemps, List.mem_range'_1, show start MixedWindow.j7 = 150 from rfl, show Shadow7.e0P 150 = 1747 by decide] at lo hi e8 ⊢ unfold Wire at *; omega) have hclear := boundaryClean150To20 v n (unsigned 150 x p) G S hAdm nextSmall20 quiet have hup : ∀ q : Nat, Shadow7.a0P 150 + 16 ≤ q → q ≤ 180 + railP 165 → v.basis q = false := by intro q lo hi; rw [runEq] exact NativeJ7.upper_clear MixedWindow.j7 (by decide) (by decide) d raw s x p domain m tape _ _ _ cut q (by unfold Shadow7.a0P at lo; rw [show start MixedWindow.j7 = 150 from rfl]; omega) (by rw [show start MixedWindow.j7 = 150 from rfl, show (150 : Nat) + 14 = 164 from rfl, show railP 164 = 258 by decide]; rw [show railP 165 = 258 by decide] at hi; omega) have carried := StockWindowTicket.stepInput_gen_shadow7 150 (Shadow7.sbP 150) x p (by decide) (by decide) good raw v G S domain origIn hAdm.farSmall have nextInput : let a := step^[15] (unsigned 150 x p) let u := LeaveJ7.Admission.flags (unsigned 150 x p) G S SkywalkIntegerInput (LeaveJ7.WideWords.L MixedWindow.j7) (SkywalkRails.encode u.1 u.2 a.u a.v).a (SkywalkRails.encode u.1 u.2 a.u a.v).b u.1 (WideReference.endRaw 150 raw v).basis := by have c2 := carried.2; unfold InputAt StockWindowTicket.signedAt at c2; rw [gg] at c2 rw [endpointState]; exact c2 have hrails := boundaryRails150To20 v n (unsigned 150 x p) G S hAdm nextSmall20 hup (WideReference.endRaw 150 raw v) nextInput have eo : pullState (OB5.sig 164) (WideReference.endRaw 150 raw v) = WideReference.origin 150 raw v := WideReference.endpoint 150 (by decide) raw v dsimp only at hrails; rw [eo] at hrails have hkept : Shadow7.physicalCells MixedWindow.j7 (run leave150To20 n v) = Shadow7.physicalCells MixedWindow.j7 v := harch.records.trans hAdm.record.symm have hleft := frameHistory150To20 x p good raw v n G S domain origIn hAdm.record hkept have w := whole150_result v n (unsigned 150 x p) G S hAdm nextSmall20 have pk : pullState (EnterJ20.pull ⟨0, by decide⟩) (WideReference.endRaw 150 raw v) = WideReference.origin 150 raw v := eo have hboth : ∀ P Q : Prop, [Decidable P] → [Decidable Q] → (decide P && decide Q) = decide (P ∧ Q) := fun P Q _ _ => by by_cases hp : P <;> by_cases hq : Q <;> simp [hp, hq] have hfl0 : EnterJ20.flagN ⟨0, by decide⟩ = e0P20 165 + 5 ∧ EnterJ20.flagF ⟨0, by decide⟩ = e0P20 165 + 3 ∧ EnterJ20.flagU ⟨0, by decide⟩ = e0P20 165 + 4 := by decide rw [pk] refine assembleCut150To20 (run leave150To20 n v) (WideReference.origin 150 raw v) _ _ _ (w.1.trans (hPh.trans (cut.phase.trans (WideReference.origin_phase 150 x p (by decide) good raw v domain).symm))) ?_ ?_ ?_ hrails.1 ?_ ?_ ?_ hleft hclear ?_ · rw [hfl0.1, ← endpointState]; exact w.2.2.2.1 · rw [hfl0.2.1, ← endpointState]; exact w.2.1 · rw [hfl0.2.2, ← endpointState]; exact w.2.2.1.trans (hboth _ _) · intro i have r := hrails.2 i have e1 : 165 + EnterJ20.h20 ⟨0, by decide⟩ + 33 + i.val = Shadow7.a0P 150 - 1 + lows150 + i.val := by have : 165 + EnterJ20.h20 ⟨0, by decide⟩ + 33 = Shadow7.a0P 150 - 1 + lows150 := by decide omega have e2 : EnterJ20.h20 ⟨0, by decide⟩ + 803 + i.val = Shadow7.b0P 150 - 1 + lows150 + i.val := by have : EnterJ20.h20 ⟨0, by decide⟩ + 803 = Shadow7.b0P 150 - 1 + lows150 := by decide omega have e3 : EnterJ20.gate ⟨0, by decide⟩ = 180 := by decide rw [e1, e2, e3]; exact r · intro q nb nl nm rw [leave150To20_keeps q (fun hb => nb (LeaveJ7.AssembleCut.box_of_box2 MixedWindow.j7 (by decide) (by decide) q hb)) n v, runEq] unfold LeaveJ7.AssembleCut.leftovers LeaveJ7.ReleasedOrigin.releasedSite at nl rw [show start MixedWindow.j7 = 150 from rfl] at nl; simp only [not_or, not_and] at nl exact NativeJ7.agree_origin MixedWindow.j7 (by decide) (by decide) (by decide) d raw s m tape _ _ _ cut q nb (by rw [show start MixedWindow.j7 = 150 from rfl]; unfold Wire at *; omega) (by rw [show start MixedWindow.j7 = 150 from rfl]; unfold Wire at *; omega) (by rw [show start MixedWindow.j7 = 150 from rfl]; unfold Wire at *; omega) · intro q lo hi rw [leave150To20_keeps_mirror q lo n v, runEq] exact NativeJ7.mirror_origin MixedWindow.j7 (by decide) (by decide) (by decide) d raw s m tape _ _ _ cut q lo hi · intro q lo hs hi exact WideReference.carry_origin (i := 150) (upper := 1812) (by decide) (by decide) good raw v domain (fun q' l u' => sig_fixed (by intro h; unfold Wire at *; omega) (by intro h; unfold Wire at *; omega)) q lo hi end Endpoint150 end ECDSAAdd.Entrant.StairPacket.Shadow20.Trans150 end -- ==== end Shadow7Wide20End150 ==== -- ==== begin Shadow7Wide20ReentryEnd ==== section /-! # Re-entry Block `j20` (`s = 345`) Endpoint, Selected Receipt & Ordinary Step (`Shadow7Wide20ReentryEnd`) Bridges the 20-tick block `k8` (`s = 325..344`) back into the standard 15-tick suffix (`j21..j24`, exit `420`) by: 1. Packing ticks `325..329` into `rawPack325 d raw := run (Rolling1588.encodeAt base d 325) [] raw`, proving `Domain 345`, `InputAt 345`, and `WideReference.origin 345 (rawPack325 d raw) out = WideReference20.origin 345 20 15 raw out`. 2. Proving `admitted345`, `mirror_origin345`, `band_clean345`, `upper_clear345`, and `endpoint345` (reusing `LeaveJ7.CertifiedCut.result j20 j21`, `LeaveJ7.ArchiveCut.result j20`, and `CRTBarrel.leave j20` verbatim!). 3. Defining `value20` (canonical 20-tick archive key) and proving `value20_chronology`, `selected_receipt345`, `cleared_holes345`, and `ordinary345`. -/ namespace ECDSAAdd.Entrant.StairPacket.Shadow20.Reentry345 open ECDSAAdd.Arithmetic open ECDSAAdd.Arithmetic.MappedCompressed open ECDSAAdd.Entrant.IntegerPacket open ECDSAAdd.Entrant.StairPacket open ECDSAAdd.Entrant.StairPacket.Partial open ECDSAAdd.Entrant.StairPacket.ArchivePortAction open ECDSAAdd.Entrant.StairArchiveRaw open ECDSAAdd.Entrant.StairArchiveTrace open ECDSAAdd.Entrant.StairPacket.EnterProof open ECDSAAdd.Entrant.StairPacket.WideReference open ECDSAAdd.Entrant.StairPacket.StockCanonicalRow open ECDSAAdd.Entrant.StairPacket.StockStrongChain open ECDSAAdd.Entrant.StairPacket.Shadow20 open ECDSAAdd.Entrant.StairPacket.Shadow20.WideReference20 open ECDSAAdd.Entrant.StairPacket.Shadow20.LeaveCut20 open SkywalkRails set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false set_option linter.unusedSimpArgs false /-! ### Section 1: Reference Packing `rawPack325` & `origin` Equivalence -/ def rawPack325 (d : Bool) (raw : State) : State := run (Rolling1588.encodeAt base d 325) [] raw def plain325 : Fin 10 → Wire := History5.historyMap base 325 def plain330 : Fin 10 → Wire := History5.historyMap base 330 private theorem plain325_inj : Function.Injective plain325 := History5.historyMap_injective base base_pool_nodup 325 (by decide) private theorem plain330_inj : Function.Injective plain330 := History5.historyMap_injective base base_pool_nodup 330 (by decide) private theorem hist345_geom : Function.Injective histA345 ∧ Function.Injective histB345 ∧ (∀ i : Fin 10, OB5.sig 344 (histA345 i) = plain325 i ∧ OB5.sig 359 (histA345 i) = plain325 i ∧ OB5.sig 344 (histB345 i) = plain330 i ∧ OB5.sig 359 (histB345 i) = plain330 i ∧ oldRange 346 (windowNet j20 (histA345 i)) ∧ oldRange 346 (windowNet j20 (histB345 i)) ∧ histA345 i ∉ EnterJ7.pending j20 ∧ histB345 i ∉ EnterJ7.pending j20 ∧ histA345 i ≠ EnterJ7.flagN j20 ∧ histA345 i ≠ EnterJ7.flagF j20 ∧ histA345 i ≠ EnterJ7.flagU j20 ∧ histB345 i ≠ EnterJ7.flagN j20 ∧ histB345 i ≠ EnterJ7.flagF j20 ∧ histB345 i ≠ EnterJ7.flagU j20 ∧ histA345 i ∉ RailPair.sites (EnterJ7.upperPairs j20) ∧ histB345 i ∉ RailPair.sites (EnterJ7.upperPairs j20) ∧ histA345 i ∉ ArchiveJ20.rawPortsList k8 ∧ histB345 i ∉ ArchiveJ20.rawPortsList k8) ∧ (∀ i j : Fin 10, histA345 i ≠ histB345 j) := by decide +kernel private theorem encode325_off_lay : ∀ r : Fin 5, base (325 + r.val) ∉ (W.compactSkywalkTickLayout base 345).a ∧ base (325 + r.val) ∉ (W.compactSkywalkTickLayout base 345).b ∧ base (325 + r.val) ≠ (W.compactSkywalkTickLayout base 345).previous ∧ base (325 + r.val) ≠ (W.compactSkywalkTickLayout base 345).ext ∧ base (325 + r.val) ≠ (W.compactSkywalkTickLayout base 345).history ∧ base (325 + r.val) ∉ (W.compactSkywalkTickLayout base 345).carry ∧ base (1028 + (325 + r.val)) ∉ (W.compactSkywalkTickLayout base 345).a ∧ base (1028 + (325 + r.val)) ∉ (W.compactSkywalkTickLayout base 345).b ∧ base (1028 + (325 + r.val)) ≠ (W.compactSkywalkTickLayout base 345).previous ∧ base (1028 + (325 + r.val)) ≠ (W.compactSkywalkTickLayout base 345).ext ∧ base (1028 + (325 + r.val)) ≠ (W.compactSkywalkTickLayout base 345).history ∧ base (1028 + (325 + r.val)) ∉ (W.compactSkywalkTickLayout base 345).carry := by decide +kernel private theorem encode325_off_hist : ∀ (r : Fin 5) (k : Fin 15), base (325 + r.val) ≠ EnterJ7.pull j20 (windowNet j20 (IntegerPacket.ports (Shadow7.shape j20) k).history) ∧ base (1028 + (325 + r.val)) ≠ EnterJ7.pull j20 (windowNet j20 (IntegerPacket.ports (Shadow7.shape j20) k).history) := by decide +kernel private theorem moves_wires_local (ps : List (Wire × Wire)) : ∀ q ∈ wires (moves ps), ∃ p ∈ ps, q = p.1 ∨ q = p.2 := by induction ps with | nil => intro q h; simp [moves, wires] at h | cons p ps ih => intro q h; obtain ⟨a, b⟩ := p simp only [moves, List.flatMap_cons, wires_append, Finset.mem_union] at h rcases h with h | h · refine ⟨(a, b), List.mem_cons_self, ?_⟩ simp [swapBits, wires, Instr.wires] at h ⊢; tauto · obtain ⟨p', hp', e⟩ := ih q (by simpa [moves] using h) exact ⟨p', List.mem_cons_of_mem _ hp', e⟩ private theorem load_cover_k8_pub (d : Bool) : wires (archiveLoadP20 k8 d) ⊆ (ArchiveJ20.rawPortsList k8).toFinset := by rw [ArchiveJ20.load_program, wires_append, Finset.union_subset_iff] constructor · rw [StairArchiveIntegerHook.placed, renameProgram_support] intro q hq; obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp hq have small : w < 155 := by cases d; exact Partial.load1_ports w hw; exact Partial.load0_ports w hw rw [ArchiveJ20.load_map k8 ⟨w, small⟩, List.mem_toFinset, ArchiveJ20.rawPorts, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem (by rw [ArchiveJ20.rawLength]; omega), Option.getD_some] exact List.getElem_mem _ · intro q hq; obtain ⟨p, hp, e⟩ := moves_wires_local _ q hq have hm : ∀ r ∈ ArchiveJ20.loadMoves k8, r.1 ∈ ArchiveJ20.rawHead k8 ∧ r.2 ∈ ArchiveJ20.rawHead k8 := by decide +kernel obtain ⟨h1, h2⟩ := hm p hp rw [List.mem_toFinset, ArchiveJ20.raw_split] rcases e with rfl | rfl · exact List.mem_append_left _ h1 · exact List.mem_append_left _ h2 private theorem rawPack325_outside (d : Bool) (raw : State) (q : Wire) (hq : ∀ r : Nat, 325 ≤ r → r ≤ 329 → q ≠ base r ∧ q ≠ base (1028 + r)) : (rawPack325 d raw).basis q = raw.basis q := by apply run_preserves_outside intro used obtain ⟨r, r1, r2, e | e⟩ := OrdinaryChainW.encode_cells d 325 q used · exact (hq r r1 r2).1 e · exact (hq r r1 r2).2 e theorem rawPack325_phase (d : Bool) (raw : State) : (rawPack325 d raw).phase = raw.phase := Rolling1588.codeEncodeAt_zero_phase d plain325 plain325_inj raw theorem rawPack325_domain (d : Bool) (x p : Nat) (raw : State) (dom : Domain 345 x p raw) : Domain 345 x p (rawPack325 d raw) := by obtain ⟨ref, coh, st⟩ := dom refine ⟨ref, ⟨(rawPack325_phase d raw).trans coh.1, fun q hq => ?_⟩, st⟩ refine (rawPack325_outside d raw q fun r r1 r2 => ?_).trans (coh.2 q hq) exact ⟨fun e => hq ⟨r, by omega, Or.inl e⟩, fun e => hq ⟨r, by omega, Or.inr e⟩⟩ theorem rawPack325_input (d : Bool) (raw : State) (Z : SkywalkRails.State) (inp : InputAt 345 Z raw) : InputAt 345 Z (rawPack325 d raw) := by let L := W.compactSkywalkTickLayout base 345 have agree : ∀ q, (q ∈ L.a ∨ q ∈ L.b ∨ q = L.previous ∨ q = L.ext ∨ q = L.history ∨ q ∈ L.carry) → (rawPack325 d raw).basis q = raw.basis q := by intro q hq apply rawPack325_outside d raw q intro r r1 r2 have h := encode325_off_lay ⟨r - 325, by omega⟩ rw [show 325 + (r - 325) = r by omega] at h rcases hq with hq | hq | rfl | rfl | rfl | hq · exact ⟨fun e => h.1 (e ▸ hq), fun e => h.2.2.2.2.2.2.1 (e ▸ hq)⟩ · exact ⟨fun e => h.2.1 (e ▸ hq), fun e => h.2.2.2.2.2.2.2.1 (e ▸ hq)⟩ · exact ⟨h.2.2.1.symm, h.2.2.2.2.2.2.2.2.1.symm⟩ · exact ⟨h.2.2.2.1.symm, h.2.2.2.2.2.2.2.2.2.1.symm⟩ · exact ⟨h.2.2.2.2.1.symm, h.2.2.2.2.2.2.2.2.2.2.1.symm⟩ · exact ⟨fun e => h.2.2.2.2.2.1 (e ▸ hq), fun e => h.2.2.2.2.2.2.2.2.2.2.2 (e ▸ hq)⟩ have hreg : ∀ (xs : List Wire), (∀ q ∈ xs, (rawPack325 d raw).basis q = raw.basis q) → signedRegValue xs (rawPack325 d raw).basis = signedRegValue xs raw.basis := by intro xs hxs unfold signedRegValue rw [regValue_congr xs (rawPack325 d raw).basis raw.basis hxs] refine ⟨?_, ?_, ?_, ?_, ?_, ?_⟩ · rw [hreg L.a (fun q hq => agree q (Or.inl hq))]; exact inp.1 · rw [hreg L.b (fun q hq => agree q (Or.inr (Or.inl hq)))]; exact inp.2.1 · rw [agree L.previous (Or.inr (Or.inr (Or.inl rfl)))]; exact inp.2.2.1 · rw [agree L.ext (Or.inr (Or.inr (Or.inr (Or.inl rfl))))]; exact inp.2.2.2.1 · rw [agree L.history (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))]; exact inp.2.2.2.2.1 · rw [regValue_congr L.carry (rawPack325 d raw).basis raw.basis (fun q hq => agree q (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr hq))))))]; exact inp.2.2.2.2.2 theorem rawPack325_span_comm (d : Bool) (raw : State) : run (span 345 15) [] (rawPack325 d raw) = rawPack325 d (run (span 345 15) [] raw) := by have disj : Disjoint (wires (span 345 15)) (wires (Rolling1588.encodeAt base d 325)) := by rw [Finset.disjoint_left] intro q hsp hen obtain ⟨r, r1, r2, e | e⟩ := OrdinaryChainW.encode_cells d 325 q hen · exact pastOffSpan 345 15 q (by decide) ⟨r, by omega, Or.inl e⟩ hsp · exact pastOffSpan 345 15 q (by decide) ⟨r, by omega, Or.inr e⟩ hsp have hcm := run_disjoint_commute (span 345 15) (Rolling1588.encodeAt base d 325) disj [] [] raw simpa only [rawPack325] using hcm attribute [local irreducible] run SkywalkNat.step Shadow.far nextWindow345 window345 withArchive345 packProg345 archiveLoadP20 Shadow7.enterP Shadow7.body Shadow7.routed in theorem pack345_hist_vals (d : Bool) (x p : Nat) (good : Bounds x p) (raw s : State) (m : List Bool) (dom : Domain 345 x p raw) (neg far long : Bool) (cut : PackedCut (EnterJ7.lowerPairs j20) (EnterJ7.upperPairs j20) (EnterJ7.gate j20) (EnterJ7.flagN j20) (EnterJ7.flagF j20) (EnterJ7.flagU j20) neg far long (pullState (EnterJ7.pull j20) raw) (eraseSites (EnterJ7.pending j20) s)) (Z : SkywalkRails.State) (parity : (Z.a + Z.b) % 2 = 1) (active : Shadow7.onRails j20 0 Z (run (Shadow7.enterP j20) m s).basis) : let out := run (nextWindow345 d) m s (∀ i : Fin 10, out.basis (histA345 i) = (rawPack325 d raw).basis (plain325 i)) ∧ (∀ i : Fin 10, out.basis (histB345 i) = (run (Rolling1588.encodeAt base d 330) [] (run (span 345 15) [] (rawPack325 d raw))).basis (plain330 i)) := by let pre := run (Shadow7.enterP j20) m s let tape := m.drop (measurementCount (Shadow7.enterP j20)) let st1 := run (Shadow7.routed j20 0 1) tape pre let t1 := tape.drop (measurementCount (Shadow7.routed j20 0 1)) have runEq : run (nextWindow345 d) m s = run (Shadow7.body j20 (withArchive345 d)) tape pre := by simp only [nextWindow345, window345, run_append, run_take, pre, tape] have hc := pack_codes345_aux d have hA_in : ∀ i : Fin 10, st1.basis (histA345 i) = raw.basis (plain325 i) := by intro i have g := hist345_geom.2.2.1 i have h1 := Shadow7.first_preserves j20 Z parity pre tape active (histA345 i) (firstFree345 (heads345_ok.2.1 i).1) have h2 := run_preserves_outside (Shadow7.enterP j20) m s (histA345 i) (EnterJ7.notWire j20 (heads345_ok.2.1 i).2.1) have h3 := cut.unchanged (histA345 i) g.2.2.2.2.2.2.2.2.1 g.2.2.2.2.2.2.2.2.2.1 g.2.2.2.2.2.2.2.2.2.2.1 g.2.2.2.2.2.2.2.2.2.2.2.2.2.2.1 rw [h1, h2] have e : s.basis (histA345 i) = (eraseSites (EnterJ7.pending j20) s).basis (histA345 i) := by simp [eraseSites, g.2.2.2.2.2.2.1] rw [e, h3]; change raw.basis (OB5.sig 344 (histA345 i)) = _; rw [g.1] have hB_in : ∀ i : Fin 10, st1.basis (histB345 i) = raw.basis (plain330 i) := by intro i have g := hist345_geom.2.2.1 i have h1 := Shadow7.first_preserves j20 Z parity pre tape active (histB345 i) (firstFree345 (heads345_ok.2.1 i).2.2.1) have h2 := run_preserves_outside (Shadow7.enterP j20) m s (histB345 i) (EnterJ7.notWire j20 (heads345_ok.2.1 i).2.2.2) have h3 := cut.unchanged (histB345 i) g.2.2.2.2.2.2.2.2.2.2.2.1 g.2.2.2.2.2.2.2.2.2.2.2.2.1 g.2.2.2.2.2.2.2.2.2.2.2.2.2.1 g.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.1 rw [h1, h2] have e : s.basis (histB345 i) = (eraseSites (EnterJ7.pending j20) s).basis (histB345 i) := by simp [eraseSites, g.2.2.2.2.2.2.2.1] rw [e, h3]; change raw.basis (OB5.sig 344 (histB345 i)) = _; rw [g.2.2.1] have hA_offB (i : Fin 10) : histA345 i ∉ wires (MixedWindow.packW d 345 335) := by intro used rw [hc.2.2.2.2.2.2.1, Rolling1588.codeEncodeAt, renameProgram_support, (Rolling1588.code_support d).1] at used obtain ⟨w, hw, eq⟩ := Finset.mem_image.mp used have lt := Finset.mem_range.mp hw simp only [MeasuredCodec5.label, dif_pos lt] at eq exact hist345_geom.2.2.2 i ⟨w, lt⟩ eq.symm have hB_offA (i : Fin 10) : histB345 i ∉ wires (MixedWindow.packW d 345 330) := by intro used rw [hc.2.2.2.2.1, Rolling1588.codeEncodeAt, renameProgram_support, (Rolling1588.code_support d).1] at used obtain ⟨w, hw, eq⟩ := Finset.mem_image.mp used have lt := Finset.mem_range.mp hw simp only [MeasuredCodec5.label, dif_pos lt] at eq exact hist345_geom.2.2.2 ⟨w, lt⟩ i eq have hP330_stable (i : Fin 10) : raw.basis (plain330 i) = (run (span 345 15) [] (rawPack325 d raw)).basis (plain330 i) := by have hr : ∃ r, 330 ≤ r ∧ r ≤ 334 ∧ (plain330 i = base r ∨ plain330 i = base (1028 + r)) := by refine ⟨330 + i.val / 2, by omega, by omega, ?_⟩ unfold plain330 History5.historyMap History5.historyId split_ifs · left; rfl · right; congr 1; omega obtain ⟨r, r1, r2, hq | hq⟩ := hr · have hsp : plain330 i ∉ wires (span 345 15) := pastOffSpan 345 15 _ (by decide) ⟨r, by omega, Or.inl hq⟩ rw [run_preserves_outside _ _ _ _ hsp, rawPack325_outside d raw _ (fun r' a b => by rw [hq]; exact ⟨by simp only [base, Wire]; omega, by simp only [base, Wire]; omega⟩)] · have hsp : plain330 i ∉ wires (span 345 15) := pastOffSpan 345 15 _ (by decide) ⟨r, by omega, Or.inr hq⟩ rw [run_preserves_outside _ _ _ _ hsp, rawPack325_outside d raw _ (fun r' a b => by rw [hq]; exact ⟨by simp only [base, Wire]; omega, by simp only [base, Wire]; omega⟩)] constructor · intro i have g := hist345_geom.2.2.1 i rw [runEq, OrdinaryJ.kept j20 (withArchive345 d) tape pre (histA345 i) g.2.2.2.2.1] simp only [withArchive345, packProg345, run_append, run_take] rw [run_preserves_outside (archiveLoadP20 k8 d) _ _ _ (fun h => g.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.1 (List.mem_toFinset.mp (load_cover_k8_pub d h))), run_preserves_outside (MixedWindow.packW d 345 335) _ _ _ (hA_offB i), hc.2.2.2.2.1] exact ArchiveOrdinaryFive.stock_relocated d histA345 plain325 hist345_geom.1 plain325_inj st1 raw _ [] hA_in i · intro i have g := hist345_geom.2.2.1 i rw [runEq, OrdinaryJ.kept j20 (withArchive345 d) tape pre (histB345 i) g.2.2.2.2.2.1] simp only [withArchive345, packProg345, run_append, run_take] rw [run_preserves_outside (archiveLoadP20 k8 d) _ _ _ (fun h => g.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2.2 (List.mem_toFinset.mp (load_cover_k8_pub d h))), hc.2.2.2.2.2.2.1] have hB_mid : ∀ k : Fin 10, (run (MixedWindow.packW d 345 330) t1 st1).basis (histB345 k) = (run (span 345 15) [] (rawPack325 d raw)).basis (plain330 k) := fun k => (run_preserves_outside (MixedWindow.packW d 345 330) t1 st1 (histB345 k) (hB_offA k)).trans ((hB_in k).trans (hP330_stable k)) exact ArchiveOrdinaryFive.stock_relocated d histB345 plain330 hist345_geom.2.1 plain330_inj _ _ _ [] hB_mid i private theorem cell325_eq_plain325 {q : Wire} (hr : ∃ r, 325 ≤ r ∧ r ≤ 329 ∧ (q = base r ∨ q = base (1028 + r))) : ∃ i : Fin 10, q = plain325 i := by obtain ⟨r, r1, r2, rfl | rfl⟩ := hr · refine ⟨⟨2 * (r - 325), by omega⟩, ?_⟩ simp only [plain325, History5.historyMap, History5.historyId, Fin.val_mk] rw [if_pos (by omega)]; congr 1; omega · refine ⟨⟨2 * (r - 325) + 1, by omega⟩, ?_⟩ simp only [plain325, History5.historyMap, History5.historyId, Fin.val_mk] rw [if_neg (by omega)]; congr 1; omega theorem origin345_eq (d : Bool) (raw out : State) (hA : ∀ i : Fin 10, out.basis (histA345 i) = (rawPack325 d raw).basis (plain325 i)) : ∀ q : Wire, (WideReference.origin 345 (rawPack325 d raw) out).basis q = (WideReference20.origin 345 20 15 raw out).basis q := by intro q by_cases h15 : q ∈ WideReference.sites 345 · have h20 : q ∈ WideReference20.sites 345 20 15 := by rw [WideReference.mem_sites (by decide)] at h15 rw [WideReference20.mem_sites (by decide)] obtain ⟨r, r1, r2, e⟩ := WideReference.old_cell h15 have hs : oldStart 345 = 330 ∧ oldCount 345 = 15 := by decide rw [hs.1] at r1 r2; rw [hs.2] at r2 simp only [WideReference20.oldSites, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] refine ⟨r, ⟨by omega, by omega⟩, ?_⟩ rw [show (345 : Nat) + 15 - 1 = 345 + 14 from rfl] rcases e with e | e · left; exact e · right; simp only [base, Wire] at e ⊢; omega rw [WideReference.inside 345 _ out q h15, WideReference20.inside 345 20 15 raw out q h20] · rw [WideReference.outside 345 _ out q h15] by_cases h20 : q ∈ WideReference20.sites 345 20 15 · rw [WideReference20.inside 345 20 15 raw out q h20] rw [WideReference20.mem_sites (by decide)] at h20 have hnot : OB5.sig 359 q ∉ WideReference.oldSites 345 := fun h => h15 ((WideReference.mem_sites (by decide) q).mpr h) obtain ⟨r, r1, r2, e⟩ := WideReference20.old_cell h20 rw [show (345 : Nat) + 15 - 1 = 359 from rfl] at e have hr : 325 ≤ r ∧ r ≤ 329 := by by_contra hbad apply hnot have hs : oldStart 345 = 330 ∧ oldCount 345 = 15 := by decide simp only [WideReference.oldSites, hs.1, hs.2, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] refine ⟨r, ⟨by omega, by omega⟩, ?_⟩ rcases e with e | e · left; exact e · right; simp only [base, Wire] at e ⊢; omega obtain ⟨i, hi⟩ := cell325_eq_plain325 ⟨r, hr.1, hr.2, by rcases e with e | e; exact Or.inl e; exact Or.inr (by simp only [base, Wire] at e ⊢; omega)⟩ have hq : q = histA345 i := by have h1 := (hist345_geom.2.2.1 i).2.1 have h2 : OB5.sig 359 q = OB5.sig 359 (histA345 i) := hi.trans h1.symm exact OB5.sig_injective 359 (by decide) h2 have hsp : plain325 i ∉ wires (span 345 15) := by apply pastOffSpan 345 15 _ (by decide) rcases e with e | e · exact ⟨r, by omega, Or.inl (hi.symm.trans e)⟩ · exact ⟨r, by omega, Or.inr (hi.symm.trans (by simp only [base, Wire] at e ⊢; omega))⟩ rw [show (345 : Nat) + 14 = 359 from rfl, hi, run_preserves_outside _ _ _ _ hsp, hq, hA i] · rw [WideReference20.outside 345 20 15 raw out q h20, show (345 : Nat) + 14 = 359 from rfl, show (345 : Nat) + 15 - 1 = 359 from rfl, rawPack325_span_comm] apply rawPack325_outside d _ _ intro r r1 r2 have hnot : OB5.sig 359 q ∉ WideReference20.oldSites 345 20 := fun h => h20 ((WideReference20.mem_sites (by decide) q).mpr h) refine ⟨fun e => hnot ?_, fun e => hnot ?_⟩ · simp only [WideReference20.oldSites, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] exact ⟨r, ⟨by omega, by omega⟩, Or.inl e⟩ · simp only [WideReference20.oldSites, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] exact ⟨r, ⟨by omega, by omega⟩, Or.inr e⟩ /-! ### Section 2: `mirror_origin345`, `band_clean345`, `upper_clear345`, `admitted345`, `endpoint345` -/ private theorem j20_vals : start j20 = 345 ∧ Shadow7.sbP 345 = 76 ∧ Shadow7.wpP 345 = 77 ∧ Shadow7.e0P 345 = 1650 ∧ EnterJ7.flagN j20 = 1655 ∧ EnterJ7.flagF j20 = 1653 ∧ EnterJ7.flagU j20 = 1654 ∧ EnterJ7.pending j20 = [1656, 1657, 1658] ∧ railP 345 = 168 ∧ railP 359 = 154 := by decide +kernel private theorem admin345_away (q : Wire) (hq : (1301 ≤ (q : Nat) ∧ (q : Nat) ≤ 1058 + 345) ∨ (2070 ≤ (q : Nat) + 345 ∧ (q : Nat) ≤ 1812 ∧ ¬ (2070 ≤ (q : Nat) + 345 ∧ (q : Nat) + 345 < 2090))) : q ∉ support345 ++ ArchiveJ20.rawPortsList k8 := by intro mem rw [List.mem_append, ArchiveJ20.raw_split, List.mem_append] at mem have hall : (support345 ++ ArchiveJ20.rawHead k8).all (fun w => decide ((w : Nat) < 1301 ∨ (1058 + 345 < (w : Nat) ∧ (w : Nat) + 345 < 2070) ∨ (2070 ≤ (w : Nat) + 345 ∧ (w : Nat) + 345 < 2090))) = true := by decide +kernel rcases mem with h | h | h · have := of_decide_eq_true (List.all_eq_true.mp hall q (List.mem_append_left _ h)) simp only [Wire] at *; omega · have := of_decide_eq_true (List.all_eq_true.mp hall q (List.mem_append_right _ h)) simp only [Wire] at *; omega · obtain ⟨k, hk, eq⟩ := List.mem_map.mp h; rw [List.mem_range] at hk have hb : 1556 ≤ (q : Nat) ∧ (q : Nat) ≤ 1699 := by rw [← eq]; unfold archScratch20; dsimp only; split_ifs <;> (unfold Wire; omega) simp only [Wire] at *; omega attribute [local irreducible] run SkywalkNat.step nextWindow345 window345 withArchive345 Shadow7.enterP Shadow7.body in private theorem mirror_origin345 (d : Bool) (raw s : State) (m t : List Bool) (neg far long : Bool) (packed : PackedCut (EnterJ7.lowerPairs j20) (EnterJ7.upperPairs j20) (EnterJ7.gate j20) (EnterJ7.flagN j20) (EnterJ7.flagF j20) (EnterJ7.flagU j20) neg far long (pullState (EnterJ7.pull j20) raw) (eraseSites (EnterJ7.pending j20) s)) (q : Wire) (lo : 2070 ≤ (q : Nat) + 345) (hi : (q : Nat) ≤ 1812) : let history := run (window345 d) t (run (Shadow7.enterP j20) m s) history.basis q = (WideReference20.origin 345 20 15 raw history).basis q := by intro history have ext : ¬ WideReference20.Box20 345 15 q := by unfold WideReference20.Box20 rw [show 345 + 15 - 1 = 359 from rfl, WideReference.route_eq 345 (by decide), WideReference.route_eq 359 (by decide)] simp only [Wire] at *; split_ifs <;> omega have wn : windowNet j20 q = 3113 - q := by show OB5.sig 359 q = _ exact NativeJ7.sig_moved 359 q (Or.inr ⟨by simp only [Wire] at *; omega, hi⟩) have free : ¬ Shadow7.MayTouch j20 (windowNet j20 q) := by rw [wn]; unfold Shadow7.MayTouch have jv := j20_vals; simp only [Shadow7.shape, Shadow7.smallBits, jv.1, jv.2.1, Wire] at *; omega have port : q ∉ EnterJ7.ports j20 := fun mem => by have r := EnterJ7.portsRegion j20 mem; have jv := j20_vals simp only [jv.1, jv.2.1, Wire] at *; omega apply WideReference20.box_origin20 (by decide) (by decide) (by decide) ext raw history intro notSite have notAdmin : q ∉ support345 ++ ArchiveJ20.rawPortsList k8 := by by_cases hb : 2070 ≤ (q : Nat) + 345 ∧ (q : Nat) + 345 < 2090 · exfalso; apply notSite rw [WideReference20.mem_sites (by decide), show 345 + 15 - 1 = 359 from rfl, show OB5.sig 359 q = 3113 - q from wn] simp only [WideReference20.oldSites, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] exact ⟨2069 - (q : Nat), ⟨by simp only [Wire] at *; omega, by simp only [Wire] at *; omega⟩, Or.inr (by simp only [base, Wire] at *; omega)⟩ · exact admin345_away q (Or.inr ⟨lo, hi, hb⟩) have stay := Shadow7.ext_head (Shadow7.enterP j20) j20 (withArchive345 d) (support345 ++ ArchiveJ20.rawPortsList k8) s m t q free (EnterJ7.notWire j20 port) notAdmin (admin_cover345 d) have jv := j20_vals have hn : q ≠ EnterJ7.flagN j20 := by rw [jv.2.2.2.2.1]; simp only [Wire] at *; omega have hf : q ≠ EnterJ7.flagF j20 := by rw [jv.2.2.2.2.2.1]; simp only [Wire] at *; omega have hu : q ≠ EnterJ7.flagU j20 := by rw [jv.2.2.2.2.2.2.1]; simp only [Wire] at *; omega have hi' : q ∉ RailPair.sites (EnterJ7.upperPairs j20) := fun mm => by have u := EnterJ7.upperSites j20 mm; simp only [jv.1, jv.2.1, jv.2.2.1, Wire] at *; omega have pend : q ∉ EnterJ7.pending j20 := by rw [jv.2.2.2.2.2.2.2.1]; simp only [List.mem_cons, List.not_mem_nil, or_false, Wire] at *; omega have old := packed.unchanged q hn hf hu hi' have pullEq : OB5.sig 344 q = 3113 - q := NativeJ7.sig_moved 344 q (Or.inr ⟨by simp only [Wire] at *; omega, hi⟩) have hwEq : window345 d = Shadow7.body j20 (withArchive345 d) := by unfold window345; rfl change (run (window345 d) t (run (Shadow7.enterP j20) m s)).basis q = _ rw [hwEq, stay] have e : s.basis q = (eraseSites (EnterJ7.pending j20) s).basis q := by simp [eraseSites, pend] rw [e, old]; rfl attribute [local irreducible] run SkywalkNat.step nextWindow345 window345 withArchive345 Shadow7.enterP Shadow7.body in private theorem band_clean345 (d : Bool) (x p : Nat) (good : Bounds x p) (raw s : State) (m : List Bool) (domain : Domain 345 x p raw) (neg far long : Bool) (cut : PackedCut (EnterJ7.lowerPairs j20) (EnterJ7.upperPairs j20) (EnterJ7.gate j20) (EnterJ7.flagN j20) (EnterJ7.flagF j20) (EnterJ7.flagU j20) neg far long (pullState (EnterJ7.pull j20) raw) (eraseSites (EnterJ7.pending j20) s)) : ∀ q : Nat, 1301 ≤ q → q ≤ 1058 + 345 → (run (nextWindow345 d) m s).basis q = false := by intro q lo hi have jv := j20_vals have split : run (nextWindow345 d) m s = run (Shadow7.body j20 (withArchive345 d)) (m.drop (measurementCount (Shadow7.enterP j20))) (run (Shadow7.enterP j20) m s) := by simp only [nextWindow345, window345, run_append, run_take] rw [split] have wn : windowNet j20 q = 3113 - q := NativeJ7.sig_moved 359 q (Or.inl ⟨lo, by omega⟩) have free : ¬ Shadow7.MayTouch j20 (windowNet j20 q) := by rw [wn]; unfold Shadow7.MayTouch; simp only [Shadow7.shape, Shadow7.smallBits, jv.1, jv.2.1, Wire] at *; omega have port : q ∉ EnterJ7.ports j20 := fun mem => by have r := EnterJ7.portsRegion j20 mem; simp only [jv.1, jv.2.1, Wire] at *; omega have notAdmin := admin345_away q (Or.inl ⟨lo, hi⟩) rw [Shadow7.ext_head (Shadow7.enterP j20) j20 (withArchive345 d) _ s m _ q free (EnterJ7.notWire j20 port) notAdmin (admin_cover345 d)] have hn : (q : Wire) ≠ EnterJ7.flagN j20 := by rw [jv.2.2.2.2.1]; omega have hf : (q : Wire) ≠ EnterJ7.flagF j20 := by rw [jv.2.2.2.2.2.1]; omega have hu : (q : Wire) ≠ EnterJ7.flagU j20 := by rw [jv.2.2.2.2.2.2.1]; omega have hi' : (q : Wire) ∉ RailPair.sites (EnterJ7.upperPairs j20) := fun mm => by have u := EnterJ7.upperSites j20 mm; simp only [jv.1, jv.2.1, jv.2.2.1, Wire] at *; omega have pend : (q : Wire) ∉ EnterJ7.pending j20 := by rw [jv.2.2.2.2.2.2.2.1]; simp only [List.mem_cons, List.not_mem_nil, or_false, Wire]; omega have old := cut.unchanged q hn hf hu hi' have e1 : s.basis q = (eraseSites (EnterJ7.pending j20) s).basis q := by simp [eraseSites, pend] rw [e1, old]; show raw.basis (OB5.sig 344 q) = false by_cases mv : q ≤ 1043 + 345 · rw [NativeJ7.sig_moved 344 q (Or.inl ⟨lo, by omega⟩)] have c := WideReference.full_carry 345 0 x p (by decide) good raw domain [] (3113 - q) (by omega) (by omega) simpa only [WideReference.span, run] using c · rw [NativeJ7.sig_kept 344 q (by omega) (by omega)] rw [show (q : Wire) = base (1028 + (q - 1044)) by simp only [base, Wire]; omega] exact WideReference.future_history (show 345 ≤ q - 1044 by omega) (by omega) domain attribute [local irreducible] run SkywalkNat.step nextWindow345 window345 withArchive345 Shadow7.enterP Shadow7.body in private theorem upper_clear345 (d : Bool) (raw s : State) (x p : Nat) (domain : Domain 345 x p raw) (m t : List Bool) (neg far long : Bool) (cut : PackedCut (EnterJ7.lowerPairs j20) (EnterJ7.upperPairs j20) (EnterJ7.gate j20) (EnterJ7.flagN j20) (EnterJ7.flagF j20) (EnterJ7.flagU j20) neg far long (pullState (EnterJ7.pull j20) raw) (eraseSites (EnterJ7.pending j20) s)) : ∀ q : Nat, 345 + Shadow7.sbP 345 + 48 ≤ q → q ≤ min (345 + 30 + railP 359) 529 → (run (window345 d) t (run (Shadow7.enterP j20) m s)).basis q = false := by intro q lo hi have jv := j20_vals have hq : 469 ≤ q ∧ q ≤ 529 := by omega have wn : windowNet j20 q = q := NativeJ7.sig_kept 359 q (by omega) (by omega) have free : ¬ Shadow7.MayTouch j20 (windowNet j20 q) := by rw [wn]; unfold Shadow7.MayTouch; simp only [Shadow7.shape, Shadow7.smallBits, jv.1, jv.2.1, Wire] at *; omega have port : (q : Wire) ∉ EnterJ7.ports j20 := fun mem => by have r := EnterJ7.portsRegion j20 mem; simp only [jv.1, jv.2.1, Wire] at *; omega have notAdmin : (q : Wire) ∉ support345 ++ ArchiveJ20.rawPortsList k8 := by intro mem; rw [List.mem_append, ArchiveJ20.raw_split, List.mem_append] at mem rcases mem with h | h | h · have := (codesOld345.2.2.2.2 q (List.mem_append_right _ h)).2.2.2; simp only [Wire] at *; omega · have := (codesOld345.2.2.2.2 q (List.mem_append_left _ h)).2.2.2; simp only [Wire] at *; omega · obtain ⟨k, hk, eq⟩ := List.mem_map.mp h; rw [List.mem_range] at hk have hb : 1556 ≤ q ∧ q ≤ 1699 := by rw [← eq]; unfold archScratch20; dsimp only; split_ifs <;> (unfold Wire; omega) omega have stay := Shadow7.ext_head (Shadow7.enterP j20) j20 (withArchive345 d) _ s m t q free (EnterJ7.notWire j20 port) notAdmin (admin_cover345 d) have pend : (q : Wire) ∉ EnterJ7.pending j20 := by rw [jv.2.2.2.2.2.2.2.1]; simp only [List.mem_cons, List.not_mem_nil, or_false, Wire]; omega have hwEq : window345 d = Shadow7.body j20 (withArchive345 d) := by unfold window345; rfl rw [hwEq, stay] have e : s.basis q = (eraseSites (EnterJ7.pending j20) s).basis q := by simp [eraseSites, pend] rw [e] by_cases hq529 : q < 529 · have hup : (q : Wire) ∈ (EnterJ7.upperPairs j20).map Prod.fst := by have hu : EnterJ7.upperPairs j20 = (List.range 75).map (fun i => (454 + i, 879 + i)) := by decide +kernel rw [hu, List.mem_map] refine ⟨(q, q + 425), ?_, rfl⟩ rw [List.mem_map]; exact ⟨q - 454, List.mem_range.mpr (by omega), by ext <;> (simp only [Wire]; omega)⟩ obtain ⟨pair, hpm, rfl⟩ := List.mem_map.mp hup exact (cut.upper pair hpm).1 · have hqeq : q = 529 := by omega subst hqeq have hn : (529 : Wire) ≠ EnterJ7.flagN j20 := by rw [jv.2.2.2.2.1]; decide have hf : (529 : Wire) ≠ EnterJ7.flagF j20 := by rw [jv.2.2.2.2.2.1]; decide have hu : (529 : Wire) ≠ EnterJ7.flagU j20 := by rw [jv.2.2.2.2.2.2.1]; decide have notHi : (529 : Wire) ∉ RailPair.sites (EnterJ7.upperPairs j20) := fun mm => by have u := EnterJ7.upperSites j20 mm; simp only [jv.1, jv.2.1, jv.2.2.1, Wire] at *; omega have same : EnterJ7.pull j20 529 = 529 := by decide have free : (529 : Wire) ∈ (W.compactSkywalkSignPoolA base 345).released ∨ 345 + 274 ≤ 529 ∧ 529 < 786 := by decide +kernel have src := WideReference.incoming_free_A 345 x p (by decide) raw domain 529 (by omega) (by omega) free exact (cut.unchanged 529 hn hf hu notHi).trans (by simpa only [pullState, same] using src) attribute [local irreducible] run SkywalkNat.step Shadow.far nextWindow345 nextUnwind345 window345 withArchive345 Shadow7.enterP Shadow7.body in theorem admitted345 (d : Bool) (x p : Nat) (good : Bounds x p) (raw s : State) (m : List Bool) (domain : Domain 345 x p raw) (G S : Bool) (cut : PackedCut (EnterJ7.lowerPairs j20) (EnterJ7.upperPairs j20) (EnterJ7.gate j20) (EnterJ7.flagN j20) (EnterJ7.flagF j20) (EnterJ7.flagU j20) (PortalValues.negative S (unsigned 345 x p).u) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p))) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p) ∧ 2 ^ Shadow7.sbP 345 ≤ (unsigned 345 x p).u)) (pullState (EnterJ7.pull j20) raw) (eraseSites (EnterJ7.pending j20) s)) (input : SkywalkIntegerInput (EnterJ7.lay j20) (encode G S (unsigned 345 x p).u (unsigned 345 x p).v).a (encode G S (unsigned 345 x p).u (unsigned 345 x p).v).b G raw.basis) (pg ps cross : Bool) (prior : PastFacts20 k8 (ArchiveJ20.rawPorts k8) (unsigned 325 x p) pg ps cross s) : let out := run (nextWindow345 d) m s LeaveJ7.Admission.Inputs j20 out (unsigned 345 x p) G S ∧ out.phase = s.phase ∧ (∀ t, run (TickCut.Reentry20.nextUnwind345 d) t out = s) := by have nums := LeaveJ7.Admission.actualNumbers j20 (by decide) (by decide) x p good have old := actualNumbers20 k8 x p good have hist := WideReference.pulled_history j20 rfl domain let pre := run (Shadow7.enterP j20) m s let tape := m.drop (measurementCount (Shadow7.enterP j20)) let T := Shadow.reduced (Shadow7.sbP 345) 15 (unsigned 345 x p) let Z := encode G S T.u T.v have to' : T.v % 2 = 1 := shadow_odd_shadow7 (Shadow7.sbP 345) (unsigned 345 x p) nums.farSmall nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum G S _ _ (by omega) have ready := EnterJ7.ready_pending_at j20 raw s (unsigned 345 x p) G S m nums.farSmall cut input hist have scr := scratch_raw_clean345 d raw s m x p good domain _ _ _ Z parity ready.2.1 cut have nw := TickCut.Reentry20.next_window345 d raw s m (unsigned 345 x p) G S nums.odd nums.farSmall cut input hist scr (unsigned 325 x p) pg ps cross old.odd old.small.1 prior obtain ⟨_, _, _, _, tags⟩ := real_receipt345 d raw s m (unsigned 345 x p) G S nums.odd nums.farSmall cut input hist scr (unsigned 325 x p) pg ps cross old.odd old.small.1 prior have sv := saved_with_pending345 d raw s (unsigned 345 x p) G S m tape nums.farSmall cut input have pk := parked_clean345 d raw s (unsigned 345 x p) G S m tape nums.farSmall cut input obtain ⟨_, _, row, limit, frame⟩ := admits345 d s m tape (tape.drop (measurementCount (Shadow7.routed j20 0 1))) Z parity ready.2.1 scr (unsigned 325 x p) pg ps cross old.odd old.small.1 prior have cframe : Frame (ArchiveJ20.codePorts k8) (code d) row (run (withArchive345 d) (tape.drop (measurementCount (Shadow7.routed j20 0 1))) (run (Shadow7.routed j20 0 1) tape pre)) := by rw [show withArchive345 d = packProg345 d ++ archiveLoadP20 k8 d by unfold withArchive345; rfl] exact from_append (prop := Frame (ArchiveJ20.codePorts k8) (code d) row) (ArchiveJ20.load_run k8 d row limit _ _ frame).2.1 have top := top_clean345 d x p raw s domain m tape _ _ _ cut row cframe have top2 := top_clean345' d x p raw s domain m tape _ _ _ cut row cframe have tail := tail_clean345 d x p raw s domain m tape _ _ _ cut row cframe have runEq : run (nextWindow345 d) m s = run (window345 d) tape pre := by simp only [nextWindow345, run_append, run_take, pre, tape] refine ⟨?_, nw.1, nw.2.2.2⟩ apply LeaveJ7.Admission.assemble j20 (by decide) (by decide) _ (unsigned 345 x p) G S nums nw.2.1 nw.2.2.1 · rw [runEq, ← NativeJ7.saved_ys j20 (by decide) (by decide)] have jv := j20_vals refine ⟨sv.1, ?_, ?_, ?_⟩ · rw [show Shadow7.e0P (start j20) + 5 = EnterJ7.flagN j20 by rw [jv.1, jv.2.2.2.1, jv.2.2.2.2.1]]; exact sv.2.1 · rw [show Shadow7.e0P (start j20) + 3 = EnterJ7.flagF j20 by rw [jv.1, jv.2.2.2.1, jv.2.2.2.2.2.1]]; exact sv.2.2.1 · rw [show Shadow7.e0P (start j20) + 4 = EnterJ7.flagU j20 by rw [jv.1, jv.2.2.2.1, jv.2.2.2.2.2.2.1]]; exact sv.2.2.2 · intro q hq rw [LeaveJ7.Admission.mem_spare] at hq have jv := j20_vals rcases hq with rfl | rfl | ⟨lo, hi⟩ · have t := tags ⟨0, by decide⟩ rw [show Shadow7.e0P (start j20) + 6 = 1656 + 0 by rw [jv.1, jv.2.2.2.1]]; exact t · have t := tags ⟨1, by decide⟩ rw [show Shadow7.e0P (start j20) + 7 = 1656 + 1 by rw [jv.1, jv.2.2.2.1]]; exact t · rw [runEq] apply tail q simp only [tailTemps345, List.mem_range'_1, jv.1, jv.2.2.1, jv.2.2.2.1] at lo hi ⊢ simp only [Wire] at *; omega · intro q lo hi have jv := j20_vals rw [jv.1] at lo hi; rw [jv.2.2.1] at hi; omega · rw [runEq]; exact top · rw [runEq]; exact top2 · rw [runEq]; exact pk /-! ### Section 3: Canonical 20-Tick Key `value20`, `selected_receipt345`, `endpoint345`, `cleared_holes345` -/ noncomputable def value20 (x p : Nat) (k : Fin 9) : Nat → Bool := let s := start20 k let z := unsigned s x p let xs := SkywalkTrace.trace 20 (WideReference.canonical s x p) let f := decide (Shadow.far (sbP20 s) 20 z) let u := f && StairArchiveTrace.afterFlags (decide (z.v < z.u)) (xs.take 10) let c := f && HighBankSum.crossBit (TrueMiddle20.d k z) StairArchiveRaw.rawBit (StairArchiveRaw.read (xs.drop 10)) f u c private theorem trace_drop_eq (n k : Nat) (z : SkywalkRails.State) : (SkywalkTrace.trace (k + n) z).drop k = SkywalkTrace.trace n (SkywalkTrace.next^[k] z) := by induction k generalizing z with | zero => simp | succ k ih => rw [show k + 1 + n = (k + n) + 1 by omega, SkywalkTrace.trace, List.drop_succ_cons, Function.iterate_succ_apply] exact ih (SkywalkTrace.next z) theorem value20_chronology (x p : Nat) (k : Fin 9) (r : Nat) (h : Encodes (value20 x p k) r) : ArchiveStockRows.Chronology (start20 k + 5) x p r := by intro q have bit := h ⟨q.val, by omega⟩ simp only [value20, StairArchiveRaw.rawBit, q.isLt, ↓reduceIte] at bit have h1 : (SkywalkTrace.trace 20 (WideReference.canonical (start20 k) x p)).drop 10 = SkywalkTrace.trace 10 (SkywalkTrace.next^[10] (WideReference.canonical (start20 k) x p)) := trace_drop_eq 10 10 _ have h2 : (SkywalkTrace.trace 15 (WideReference.canonical (start20 k + 5) x p)).drop 5 = SkywalkTrace.trace 10 (SkywalkTrace.next^[5] (WideReference.canonical (start20 k + 5) x p)) := trace_drop_eq 10 5 _ have h3 : SkywalkTrace.next^[5] (WideReference.canonical (start20 k + 5) x p) = SkywalkTrace.next^[10] (WideReference.canonical (start20 k) x p) := by unfold WideReference.canonical rw [← Function.iterate_add_apply, ← Function.iterate_add_apply, show 5 + (start20 k + 5) = 10 + start20 k by omega] rw [h1, ← h3, ← h2] at bit exact bit theorem frame_key20 (k : Fin 9) (ps : Ports) (chron : ∀ i : Fin 20, ps ⟨i, by omega⟩ = nativeRawPort20 k i) (r : Nat) (z : SkywalkNat.State) (g sg cross : Bool) (before out : State) (prior : PastFacts20 k ps z g sg cross before) (kept : ∀ i : Fin 23, out.basis (ps ⟨i, by omega⟩) = before.basis (ps ⟨i, by omega⟩)) (frame : Frame ps raw r out) : let xs := SkywalkTrace.trace 20 (encode g sg z.u z.v) let f := decide (Shadow.far (sbP20 (start20 k)) 20 z) let u := f && StairArchiveTrace.afterFlags (decide (z.v < z.u)) (xs.take 10) Encodes (StairArchiveRaw.rawBit (StairArchiveRaw.read (xs.drop 10)) f u (f && cross)) r := by intro xs f u q have same : (rawCol q).testBit r = before.basis (ps ⟨q, by omega⟩) := ((congrArg (fun n : Nat => n.testBit r) (io true true ⟨q, by omega⟩).1).trans (frame ⟨q, by omega⟩).symm).trans (kept q) by_cases h : q.val < 20 · have eq := row_truth20 k ps chron r z g sg before out prior.records kept frame ⟨q, h⟩ simpa only [StairArchiveRaw.rawBit, if_pos h] using eq · rcases q with ⟨q, bound⟩ change ¬ q < 20 at h have cases : q = 20 ∨ q = 21 ∨ q = 22 := by omega rcases cases with rfl | rfl | rfl · exact same.trans prior.far · have h := same.trans prior.suffix; rw [prior.records] at h; exact h · exact same.trans prior.crossed private theorem fourHoles345_eq : fourHoles345 = (List.finRange 4).map (fun i : Fin 4 => ArchiveJ20.codePorts k8 ⟨150 + i.val, by omega⟩) := by decide +kernel attribute [local irreducible] run SkywalkNat.step nextWindow345 window345 withArchive345 Shadow7.enterP Shadow7.body in theorem selected_receipt345 (d : Bool) (x p : Nat) (good : Bounds x p) (raw s : State) (m : List Bool) (domain : Domain 345 x p raw) (G S : Bool) (cut : PackedCut (EnterJ7.lowerPairs j20) (EnterJ7.upperPairs j20) (EnterJ7.gate j20) (EnterJ7.flagN j20) (EnterJ7.flagF j20) (EnterJ7.flagU j20) (PortalValues.negative S (unsigned 345 x p).u) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p))) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p) ∧ 2 ^ Shadow7.sbP 345 ≤ (unsigned 345 x p).u)) (pullState (EnterJ7.pull j20) raw) (eraseSites (EnterJ7.pending j20) s)) (input : SkywalkIntegerInput (EnterJ7.lay j20) (encode G S (unsigned 345 x p).u (unsigned 345 x p).v).a (encode G S (unsigned 345 x p).u (unsigned 345 x p).v).b G raw.basis) (pg ps : Bool) (canon : StockWindowTicket.signedAt 325 x p pg ps = WideReference.canonical 325 x p) (prior : PastFacts20 k8 (ArchiveJ20.rawPorts k8) (unsigned 325 x p) pg ps (HighBankSum.crossBit (TrueMiddle20.d k8 (unsigned 325 x p))) s) : SavedKey (value20 x p k8) (ArchiveJ20.codePorts k8) d (run (nextWindow345 d) m s) := by have nums := LeaveJ7.Admission.actualNumbers j20 (by decide) (by decide) x p good have old := actualNumbers20 k8 x p good have hist := WideReference.pulled_history j20 rfl domain let pre := run (Shadow7.enterP j20) m s let tape := m.drop (measurementCount (Shadow7.enterP j20)) let T := Shadow.reduced (Shadow7.sbP 345) 15 (unsigned 345 x p) let Z := encode G S T.u T.v have to' : T.v % 2 = 1 := shadow_odd_shadow7 (Shadow7.sbP 345) (unsigned 345 x p) nums.farSmall nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum G S _ _ (by omega) have ready := EnterJ7.ready_pending_at j20 raw s (unsigned 345 x p) G S m nums.farSmall cut input hist have scr := scratch_raw_clean345 d raw s m x p good domain _ _ _ Z parity ready.2.1 cut obtain ⟨_, _, row, limit, frame⟩ := admits345 d s m tape (tape.drop (measurementCount (Shadow7.routed j20 0 1))) Z parity ready.2.1 scr (unsigned 325 x p) pg ps _ old.odd old.small.1 prior have held := bank_kept345 d s m tape (tape.drop (measurementCount (Shadow7.routed j20 0 1))) Z parity ready.2.1 have all := frame_key20 k8 (ArchiveJ20.rawPorts k8) chron345 row (unsigned 325 x p) pg ps _ s _ prior held frame have hval : StairArchiveRaw.rawBit (StairArchiveRaw.read ((SkywalkTrace.trace 20 (encode pg ps (unsigned 325 x p).u (unsigned 325 x p).v)).drop 10)) (decide (Shadow.far (sbP20 (start20 k8)) 20 (unsigned 325 x p))) (decide (Shadow.far (sbP20 (start20 k8)) 20 (unsigned 325 x p)) && StairArchiveTrace.afterFlags (decide ((unsigned 325 x p).v < (unsigned 325 x p).u)) ((SkywalkTrace.trace 20 (encode pg ps (unsigned 325 x p).u (unsigned 325 x p).v)).take 10)) (decide (Shadow.far (sbP20 (start20 k8)) 20 (unsigned 325 x p)) && HighBankSum.crossBit (TrueMiddle20.d k8 (unsigned 325 x p))) = value20 x p k8 := by unfold value20; dsimp only change _ = StairArchiveRaw.rawBit (StairArchiveRaw.read ((SkywalkTrace.trace 20 (WideReference.canonical 325 x p)).drop 10)) _ _ _ unfold StockWindowTicket.signedAt at canon; rw [canon]; rfl dsimp only at all; rw [hval] at all have spec := select_spec ⟨row, limit, all⟩ have rf := reframe limit all (ArchiveJ20.rawPorts k8) _ frame have cframe : Frame (ArchiveJ20.codePorts k8) (code d) (select (value20 x p k8)) (run (withArchive345 d) (tape.drop (measurementCount (Shadow7.routed j20 0 1))) (run (Shadow7.routed j20 0 1) tape pre)) := by rw [show withArchive345 d = packProg345 d ++ archiveLoadP20 k8 d by unfold withArchive345; rfl] exact from_append (prop := Frame (ArchiveJ20.codePorts k8) (code d) (select (value20 x p k8))) (ArchiveJ20.load_run k8 d _ spec.1 _ _ rf).2.1 have runEq : run (nextWindow345 d) m s = run (Shadow7.body j20 (withArchive345 d)) tape pre := by simp only [nextWindow345, window345, run_append, run_take, pre, tape] rw [runEq] exact ⟨spec.1, spec.2, Shadow7.body_keeps j20 (withArchive345 d) (ArchiveJ20.codePorts k8) d _ pre tape (fun i => Shadow7.old_clear (by decide) (codesOld345.1 i)) cframe⟩ attribute [local irreducible] run SkywalkNat.step nextWindow345 window345 withArchive345 Shadow7.enterP Shadow7.body in theorem cleared_holes345 (d : Bool) (x p : Nat) (good : Bounds x p) (raw s : State) (m : List Bool) (domain : Domain 345 x p raw) (G S : Bool) (cut : PackedCut (EnterJ7.lowerPairs j20) (EnterJ7.upperPairs j20) (EnterJ7.gate j20) (EnterJ7.flagN j20) (EnterJ7.flagF j20) (EnterJ7.flagU j20) (PortalValues.negative S (unsigned 345 x p).u) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p))) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p) ∧ 2 ^ Shadow7.sbP 345 ≤ (unsigned 345 x p).u)) (pullState (EnterJ7.pull j20) raw) (eraseSites (EnterJ7.pending j20) s)) (input : SkywalkIntegerInput (EnterJ7.lay j20) (encode G S (unsigned 345 x p).u (unsigned 345 x p).v).a (encode G S (unsigned 345 x p).u (unsigned 345 x p).v).b G raw.basis) (pg ps cross : Bool) (prior : PastFacts20 k8 (ArchiveJ20.rawPorts k8) (unsigned 325 x p) pg ps cross s) : ∀ q ∈ fourHoles345, (run (nextWindow345 d) m s).basis q = false := by have nums := LeaveJ7.Admission.actualNumbers j20 (by decide) (by decide) x p good have old := actualNumbers20 k8 x p good have hist := WideReference.pulled_history j20 rfl domain let pre := run (Shadow7.enterP j20) m s let tape := m.drop (measurementCount (Shadow7.enterP j20)) let T := Shadow.reduced (Shadow7.sbP 345) 15 (unsigned 345 x p) let Z := encode G S T.u T.v have to' : T.v % 2 = 1 := shadow_odd_shadow7 (Shadow7.sbP 345) (unsigned 345 x p) nums.farSmall nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum G S _ _ (by omega) have ready := EnterJ7.ready_pending_at j20 raw s (unsigned 345 x p) G S m nums.farSmall cut input hist have scr := scratch_raw_clean345 d raw s m x p good domain _ _ _ Z parity ready.2.1 cut obtain ⟨_, _, row, limit, frame⟩ := admits345 d s m tape (tape.drop (measurementCount (Shadow7.routed j20 0 1))) Z parity ready.2.1 scr (unsigned 325 x p) pg ps cross old.odd old.small.1 prior have cframe : Frame (ArchiveJ20.codePorts k8) (code d) row (run (withArchive345 d) (tape.drop (measurementCount (Shadow7.routed j20 0 1))) (run (Shadow7.routed j20 0 1) tape pre)) := by rw [show withArchive345 d = packProg345 d ++ archiveLoadP20 k8 d by unfold withArchive345; rfl] exact from_append (prop := Frame (ArchiveJ20.codePorts k8) (code d) row) (ArchiveJ20.load_run k8 d row limit _ _ frame).2.1 have runEq : run (nextWindow345 d) m s = run (Shadow7.body j20 (withArchive345 d)) tape pre := by simp only [nextWindow345, window345, run_append, run_take, pre, tape] intro q hq have hmem : ∃ i : Fin 4, ArchiveJ20.codePorts k8 ⟨150 + i.val, by omega⟩ = q := by rw [fourHoles345_eq, List.mem_map] at hq obtain ⟨i, _, eq⟩ := hq; exact ⟨i, eq⟩ obtain ⟨i, hi⟩ := hmem rw [runEq] exact Shadow7.after_encoded j20 (withArchive345 d) (ArchiveJ20.codePorts k8) d row pre tape cframe ⟨150 + i.val, by omega⟩ (by dsimp; omega) q hi (codesOld345.2.2.1 q hq) attribute [local irreducible] run SkywalkNat.step Shadow.far nextWindow345 nextUnwind345 window345 withArchive345 Shadow7.enterP Shadow7.body CRTBarrel.leave CRTBarrel.unleave Shadow7.leaveP in theorem endpoint345 (d : Bool) (x p : Nat) (good : Bounds x p) (raw s : State) (m n : List Bool) (domain : Domain 345 x p raw) (G S : Bool) (cut : PackedCut (EnterJ7.lowerPairs j20) (EnterJ7.upperPairs j20) (EnterJ7.gate j20) (EnterJ7.flagN j20) (EnterJ7.flagF j20) (EnterJ7.flagU j20) (PortalValues.negative S (unsigned 345 x p).u) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p))) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p) ∧ 2 ^ Shadow7.sbP 345 ≤ (unsigned 345 x p).u)) (pullState (EnterJ7.pull j20) raw) (eraseSites (EnterJ7.pending j20) s)) (input : SkywalkIntegerInput (EnterJ7.lay j20) (encode G S (unsigned 345 x p).u (unsigned 345 x p).v).a (encode G S (unsigned 345 x p).u (unsigned 345 x p).v).b G raw.basis) (pg ps cross : Bool) (prior : PastFacts20 k8 (ArchiveJ20.rawPorts k8) (unsigned 325 x p) pg ps cross s) : let v := run (nextWindow345 d) m s let out := run (CRTBarrel.leave j20) n v out.phase = s.phase ∧ PackedCut (EnterJ7.lowerPairs ⟨21, by decide⟩) (EnterJ7.upperPairs ⟨21, by decide⟩) (EnterJ7.gate ⟨21, by decide⟩) (EnterJ7.flagN ⟨21, by decide⟩) (EnterJ7.flagF ⟨21, by decide⟩) (EnterJ7.flagU ⟨21, by decide⟩) (PortalValues.negative (LeaveJ7.Admission.flags (unsigned 345 x p) G S).2 (unsigned 360 x p).u) (decide (Shadow.far (Shadow7.sbP 360) 15 (unsigned 360 x p))) (decide (Shadow.far (Shadow7.sbP 360) 15 (unsigned 360 x p) ∧ 2 ^ Shadow7.sbP 360 ≤ (unsigned 360 x p).u)) (pullState (EnterJ7.pull ⟨21, by decide⟩) (WideReference.endRaw 345 (rawPack325 d raw) v)) (eraseSites (EnterJ7.pending ⟨21, by decide⟩) out) ∧ PastFacts j20 (ArchiveJ7.rawPorts j20) (Shadow7.sbP 345) (unsigned 345 x p) G S (HighBankSum.crossBit (LeaveJ7.TrueMiddle.d j20 (unsigned 345 x p))) out ∧ (∀ r, run (CRTBarrel.unleave j20) r out = v) ∧ (∀ r, run (TickCut.Reentry20.nextUnwind345 d) r v = s) := by have nums := LeaveJ7.Admission.actualNumbers j20 (by decide) (by decide) x p good have old := actualNumbers20 k8 x p good have hist := WideReference.pulled_history j20 rfl domain let pre := run (Shadow7.enterP j20) m s let tape := m.drop (measurementCount (Shadow7.enterP j20)) let T := Shadow.reduced (Shadow7.sbP 345) 15 (unsigned 345 x p) let Z := encode G S T.u T.v have to' : T.v % 2 = 1 := shadow_odd_shadow7 (Shadow7.sbP 345) (unsigned 345 x p) nums.farSmall nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum G S _ _ (by omega) have ready := EnterJ7.ready_pending_at j20 raw s (unsigned 345 x p) G S m nums.farSmall cut input hist have scr := scratch_raw_clean345 d raw s m x p good domain _ _ _ Z parity ready.2.1 cut have adm := admitted345 d x p good raw s m domain G S cut input pg ps cross prior obtain ⟨_, _, _, _, tags⟩ := real_receipt345 d raw s m (unsigned 345 x p) G S nums.odd nums.farSmall cut input hist scr (unsigned 325 x p) pg ps cross old.odd old.small.1 prior obtain ⟨_, _, row, limit, frame⟩ := admits345 d s m tape (tape.drop (measurementCount (Shadow7.routed j20 0 1))) Z parity ready.2.1 scr (unsigned 325 x p) pg ps cross old.odd old.small.1 prior have cframe : Frame (ArchiveJ20.codePorts k8) (code d) row (run (withArchive345 d) (tape.drop (measurementCount (Shadow7.routed j20 0 1))) (run (Shadow7.routed j20 0 1) tape pre)) := by rw [show withArchive345 d = packProg345 d ++ archiveLoadP20 k8 d by unfold withArchive345; rfl] exact from_append (prop := Frame (ArchiveJ20.codePorts k8) (code d) row) (ArchiveJ20.load_run k8 d row limit _ _ frame).2.1 have tail := tail_clean345 d x p raw s domain m tape _ _ _ cut row cframe have hpack := pack345_hist_vals d x p good raw s m domain _ _ _ cut Z parity ready.2.1 let v := run (nextWindow345 d) m s have runEq : v = run (window345 d) tape pre := by simp only [v, nextWindow345, run_append, run_take, pre, tape] have origEq := origin345_eq d raw v hpack.1 have crt := LeaveJ7.Admission.Inputs.crt_pair (j := j20) (by decide) (by decide) adm.1 have hsame : run (CRTBarrel.leave j20) n v = run (Shadow7.leaveP j20) n v := crt.1 n have domP := rawPack325_domain d x p raw domain have gg : ∀ (g sg : Bool) (u v : Int), (encode g sg u v).g = g := fun g _ _ _ => by cases g <;> rfl have origIn : InputAt 345 (encode G S (unsigned 345 x p).u (unsigned 345 x p).v) raw := by unfold InputAt; rw [gg]; exact input have inpP := rawPack325_input d raw _ origIn have ph : v.phase = (WideReference.origin 345 (rawPack325 d raw) v).phase := by have h1 : v.phase = s.phase := adm.2.1 have h2 : s.phase = raw.phase := cut.phase have h3 : (WideReference.origin 345 (rawPack325 d raw) v).phase = (rawPack325 d raw).phase := WideReference.origin_phase 345 x p (by decide) good (rawPack325 d raw) v domP rw [h1, h2, h3, rawPack325_phase] have ag : ∀ q : Wire, ¬ WideReference.Box 345 q → ¬ LeaveJ7.AssembleCut.leftovers j20 q → ¬ (2070 ≤ (q : Nat) + 345 ∧ (q : Nat) ≤ 1812) → v.basis q = (WideReference.origin 345 (rawPack325 d raw) v).basis q := by intro q nb nl nm rw [origEq q, runEq] unfold LeaveJ7.AssembleCut.leftovers LeaveJ7.ReleasedOrigin.releasedSite at nl rw [show start j20 = 345 from rfl] at nl; simp only [not_or, not_and] at nl have nb20 : ¬ WideReference20.Box20 345 15 q := by intro h; apply nb; unfold WideReference20.Box20 at h; unfold WideReference.Box simpa only [show 345 + 15 - 1 = 345 + 14 from rfl] using h exact agree_origin345 d raw s m tape _ _ _ cut q nb20 (by simp only [Wire] at *; omega) (by simp only [Wire] at *; omega) have mir : ∀ q : Nat, 2070 ≤ q + 345 → q ≤ 1812 → v.basis q = (WideReference.origin 345 (rawPack325 d raw) v).basis q := fun q lo hi => by rw [origEq q, runEq] exact mirror_origin345 d raw s m tape _ _ _ cut q lo hi have up : ∀ q : Nat, Shadow7.a0P 345 + 16 ≤ q → q ≤ min (345 + 30 + railP 359) 529 → v.basis q = false := fun q lo hi => by rw [runEq]; exact upper_clear345 d raw s x p domain m tape _ _ _ cut q (by unfold Shadow7.a0P at lo; omega) hi have band := band_clean345 d x p good raw s m domain _ _ _ cut have hj20 : start j20 = 345 := rfl have quiet : ∀ q ∈ LeaveJ7.CoreCheckpoint.rawSites j20, v.basis q = false := by intro q hq simp only [LeaveJ7.CoreCheckpoint.rawSites, List.mem_append, List.mem_range'_1, List.mem_singleton] at hq rcases hq with (⟨lo, hi⟩ | ⟨lo, hi⟩) | p17 rotate_right · rw [p17]; exact adm.1.parked · exact LeaveJ7.native_carryJ j20 (by decide) (by decide) _ v adm.1.ready adm.1.top adm.1.top2 q (by unfold Wire at *; omega) (by unfold Wire at *; omega) · by_cases e8 : (q : Nat) = Shadow7.e0P 345 + 8 · have t2 := tags ⟨2, by decide⟩ rw [show q = 1656 + 2 by unfold Wire at e8 ⊢; have := j20_vals; omega]; exact t2 · rw [runEq]; exact tail q (by simp only [tailTemps345, List.mem_range'_1, hj20, show Shadow7.e0P 345 = 1650 by decide] at lo hi e8 ⊢ unfold Wire at *; omega) have hcut := LeaveJ7.CertifiedCut.result j20 ⟨21, by decide⟩ (by decide) (by decide) (by decide) (by decide) rfl x p good (rawPack325 d raw) v n G S adm.1 domP inpP ph ag mir up band (fun _ h _ _ => by rw [hj20] at h; omega) quiet have harch := LeaveJ7.ArchiveCut.result j20 (by decide) (by decide) v n (unsigned 345 x p) G S adm.1 have hph : (run (Shadow7.leaveP j20) n v).phase = s.phase := by have h1 := StockWindowTicket.cutPhase hcut have h2 := WideReference.endRaw_phase 345 x p (by decide) good (rawPack325 d raw) v domP rw [hj20] at h1 rw [h1, h2, rawPack325_phase] exact cut.phase.symm dsimp only refine ⟨by rw [hsame]; exact hph, by rw [hsame]; exact hcut, by rw [hsame]; exact harch, fun r => crt.2 n r, adm.2.2⟩ end ECDSAAdd.Entrant.StairPacket.Shadow20.Reentry345 end -- ==== end Shadow7Wide20ReentryEnd ==== -- ==== begin Shadow7Wide20Chain ==== section /-! # End-to-End Mixed 15/20-Tick Strong Chain (`Shadow7Wide20Chain`) Proves `MixedChain.strong`: running `MixedWindow.forwardMixed d` from `pullState (OB5.sig 44) raw` (at a valid `Rolling1588.Integer.Stage ... 45`) preserves phase, stores all 22 key-selected archive banks (`MixedGeo.Bank = Fin 22`), and roundtrips exactly under `MixedWindow.reverseMixed d` for arbitrary measurement tapes. -/ namespace ECDSAAdd.Entrant.StairPacket.Shadow20.MixedChain open ECDSAAdd.Arithmetic open ECDSAAdd.Arithmetic.MappedCompressed open ECDSAAdd.Secp256k1 open ECDSAAdd.Entrant.IntegerPacket open ECDSAAdd.Entrant.StairPacket open ECDSAAdd.Entrant.StairPacket.Partial open ECDSAAdd.Entrant.StairPacket.ArchivePortAction open ECDSAAdd.Entrant.StairPacket.ArchiveStockRows open ECDSAAdd.Entrant.StairPacket.WideReference open ECDSAAdd.Entrant.StairPacket.StockWindowTicket open ECDSAAdd.Entrant.StairPacket.WindowFold open ECDSAAdd.Entrant.StairPacket.WindowChain open ECDSAAdd.Entrant.StairPacket.StockCanonicalRow open ECDSAAdd.Entrant.StairPacket.StockWindowW7 open ECDSAAdd.Entrant.StairPacket.StockStrongChain open ECDSAAdd.Entrant.StairPacket.Shadow20 open ECDSAAdd.Entrant.StairPacket.Shadow20.NativeJ20 open ECDSAAdd.Entrant.StairPacket.Shadow20.LeaveCut20 open ECDSAAdd.Entrant.StairPacket.Shadow20.Trans150 open ECDSAAdd.Entrant.StairPacket.Shadow20.Reentry345 open SkywalkRails set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false set_option linter.unusedSimpArgs false attribute [local irreducible] run Shadow7.portalP Shadow7.portalInvP Shadow7.parkP Shadow7.parkInvP Shadow7.enterP Shadow7.enterInvP Shadow7.routed Shadow7.unrouted Shadow7.archiveLoadP Shadow7.archiveRestoreP Shadow7.exitLoadP Shadow7.exitRestoreP CRTBarrel.leave CRTBarrel.unleave leave150To20 leaveInv150To20 leave150To20Red leaveInv150To20Red enterP20 enterInvP20 routed20 unrouted20 leaveP20 leaveInvP20 leaveP20Red leaveInvP20Red archiveLoadP20 archiveRestoreP20 archiveLoad150To20 archiveRestore150To20 Rolling1588.packAtTick Rolling1588.unpackAtTick /-! ### Section 1: Canonical 22-Bank Keys & Bank Cell Ranges -/ /-- Canonical archive key for each of the 22 mixed-window banks. -/ noncomputable def mixedKey (x p : Nat) (b : MixedGeo.Bank) : Nat → Bool := if h1 : b.val < 7 then value x p (start ⟨b.val, by omega⟩) (Shadow7.sbP (start ⟨b.val, by omega⟩)) (StockRowVectorW.crossW ⟨b.val, by omega⟩) else if h2 : b.val = 7 then value x p 150 (Shadow7.sbP 150) (StockRowVectorW.crossW MixedWindow.j7) else if h3 : b.val < 17 then Reentry345.value20 x p ⟨b.val - 8, by omega⟩ else value x p (start ⟨b.val + 3, by have := b.isLt; omega⟩) (Shadow7.sbP (start ⟨b.val + 3, by have := b.isLt; omega⟩)) (StockRowVectorW.crossW ⟨b.val + 3, by have := b.isLt; omega⟩) noncomputable def mixedRow (x p : Nat) (b : MixedGeo.Bank) : Nat := select (mixedKey x p b) /-- Every bank `b : Fin 22` holds its key-selected row at `MixedGeo.bankPorts exitPorts b`. -/ def mixedFinal (exitPorts : Ports) (d : Bool) (x p : Nat) (s : State) : Prop := ∀ b : MixedGeo.Bank, SavedKey (mixedKey x p b) (MixedGeo.bankPorts exitPorts b) d s def BankKey (d : Bool) (x p : Nat) (b : MixedGeo.Bank) (s : State) : Prop := SavedKey (mixedKey x p b) (MixedGeo.bankPorts StockWindowChainP.ExitPorts420 b) d s def SavedBefore (d : Bool) (x p n : Nat) (s : State) : Prop := ∀ b : MixedGeo.Bank, b.val < n → BankKey d x p b s private theorem bank_tick_match : ∀ b : MixedGeo.Bank, (∀ h : b.val < 7, MixedGeo.bankTick b = start ⟨b.val, by omega⟩) ∧ (b.val = 7 → MixedGeo.bankTick b = 150) ∧ (∀ h1 : 8 ≤ b.val, ∀ h2 : b.val < 17, MixedGeo.bankTick b = start20 ⟨b.val - 8, by omega⟩ + 5) ∧ (∀ h1 : 17 ≤ b.val, MixedGeo.bankTick b = start ⟨b.val + 3, by have := b.isLt; omega⟩) ∧ 60 ≤ MixedGeo.endTick b ∧ MixedGeo.endTick b ≤ 420 := by decide +kernel theorem mixedKey_chronology (x p : Nat) (b : MixedGeo.Bank) (r : Nat) (h : Encodes (mixedKey x p b) r) : ArchiveStockRows.Chronology (MixedGeo.bankTick b) x p r := by have tm := bank_tick_match b unfold mixedKey at h split_ifs at h with h1 h2 h3 · rw [tm.1 h1]; exact StockRowVector.historical _ _ x p _ _ h · rw [tm.2.1 h2]; exact StockRowVector.historical _ _ x p _ _ h · rw [tm.2.2.1 (by omega) h3]; exact value20_chronology x p ⟨b.val - 8, by omega⟩ r h · rw [tm.2.2.2.1 (by omega)]; exact StockRowVector.historical _ _ x p _ _ h theorem mixedFinal_trace {exitPorts d x p s} (h : mixedFinal exitPorts d x p s) (b : MixedGeo.Bank) : ArchiveStockRows.Chronology (MixedGeo.bankTick b) x p (mixedRow x p b) := mixedKey_chronology x p b _ (h b).2.1 private theorem bank_cells_mem (b : MixedGeo.Bank) (q : Wire) (hq : q ∈ ArchiveWindowPreserve.bank (MixedGeo.bankPorts StockWindowChainP.ExitPorts420 b)) : q ∈ cellsRestoreP (MixedGeo.endTick b) := by simp only [ArchiveWindowPreserve.bank, List.mem_map, List.mem_finRange, true_and] at hq obtain ⟨i, rfl⟩ := hq have eq := MixedGeo.site_eq StockWindowChainP.ExitPorts420 StockArchiveBanks.exitCells b i change MixedGeo.siteAt StockWindowChainP.ExitPorts420 b i ∈ cellsRestoreP (MixedGeo.endTick b) rw [eq, MixedGeo.bankSite, List.getD_eq_getElem?_getD, List.getElem?_eq_getElem (by simp [cellsRestoreP]), Option.getD_some] exact List.getElem_mem _ private theorem bank_range (b : MixedGeo.Bank) (q : Wire) (hq : q ∈ ArchiveWindowPreserve.bank (MixedGeo.bankPorts StockWindowChainP.ExitPorts420 b)) : let t := MixedGeo.endTick b (t + 6 ≤ (q : Nat) ∧ (q : Nat) ≤ t + 15) ∨ (t + 1034 ≤ (q : Nat) ∧ (q : Nat) ≤ t + 1042 ∧ (q : Nat) ≤ 1300) ∨ (2071 ≤ (q : Nat) + t ∧ (q : Nat) + t ≤ 2079 ∧ (q : Nat) ≤ 1812) := StockWindowW7.cells_rangeG (MixedGeo.endTick b) (bank_tick_match b).2.2.2.2.2 q (bank_cells_mem b q hq) private theorem keep_savedKey {k : Nat → Bool} {ps : Ports} {d : Bool} {s t : State} (h : SavedKey k ps d s) (eq : ∀ q ∈ ArchiveWindowPreserve.bank ps, t.basis q = s.basis q) : SavedKey k ps d t := ⟨h.1, h.2.1, ArchiveWindowPreserve.keep h.2.2 eq⟩ /-! ### Section 2: Hand-Off Predicates `At20`, `Ready20`, `At345`, `Ready345` -/ def prevTick20 (j : Fin 9) : Nat := if j.val = 0 then 150 else start20 (prev20 j) def prevCross20 (j : Fin 9) (x p : Nat) : Bool := if j.val = 0 then HighBankSum.crossBit (LeaveJ7.TrueMiddle.d MixedWindow.j7 (unsigned 150 x p)) else HighBankSum.crossBit (TrueMiddle20.d (prev20 j) (unsigned (start20 (prev20 j)) x p)) structure At20 (j : Fin 9) (d : Bool) (x p : Nat) (raw s : State) (g sg pg ps : Bool) : Prop where domain : Domain (start20 j) x p raw input : InputAt (start20 j) (signedAt (start20 j) x p g sg) raw cut : PackedCut (EnterJ20.lowerPairs j) (EnterJ20.upperPairs j) (EnterJ20.gate j) (EnterJ20.flagN j) (EnterJ20.flagF j) (EnterJ20.flagU j) (PortalValues.negative sg (unsigned (start20 j) x p).u) (decide (Shadow.far (sbP20 (start20 j)) 20 (unsigned (start20 j) x p))) (decide (Shadow.far (sbP20 (start20 j)) 20 (unsigned (start20 j) x p) ∧ 2 ^ sbP20 (start20 j) ≤ (unsigned (start20 j) x p).u)) (pullState (EnterJ20.pull j) raw) (eraseSites (EnterJ20.pending j) s) facts : PrevPast20 j (unsigned (prevTick20 j) x p) pg ps (prevCross20 j x p) s pastCanonical : signedAt (prevTick20 j) x p pg ps = WideReference.canonical (prevTick20 j) x p def Ready20 (j : Fin 9) (d : Bool) (x p : Nat) (s : State) : Prop := ∃ raw g sg pg ps, At20 j d x p raw s g sg pg ps structure At345 (d : Bool) (x p : Nat) (raw s : State) (g sg pg ps : Bool) : Prop where domain : Domain 345 x p raw input : InputAt 345 (signedAt 345 x p g sg) raw cut : PackedCut (EnterJ7.lowerPairs MixedWindow.j20) (EnterJ7.upperPairs MixedWindow.j20) (EnterJ7.gate MixedWindow.j20) (EnterJ7.flagN MixedWindow.j20) (EnterJ7.flagF MixedWindow.j20) (EnterJ7.flagU MixedWindow.j20) (PortalValues.negative sg (unsigned 345 x p).u) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p))) (decide (Shadow.far (Shadow7.sbP 345) 15 (unsigned 345 x p) ∧ 2 ^ Shadow7.sbP 345 ≤ (unsigned 345 x p).u)) (pullState (EnterJ7.pull MixedWindow.j20) raw) (eraseSites (EnterJ7.pending MixedWindow.j20) s) facts : PastFacts20 MixedWindow.k8 (ArchiveJ20.rawPorts MixedWindow.k8) (unsigned 325 x p) pg ps (HighBankSum.crossBit (TrueMiddle20.d MixedWindow.k8 (unsigned 325 x p))) s pastCanonical : signedAt 325 x p pg ps = WideReference.canonical 325 x p def Ready345 (d : Bool) (x p : Nat) (s : State) : Prop := ∃ raw g sg pg ps, At345 d x p raw s g sg pg ps /-! ### Section 3: 20-Tick Selected Receipt (`selected_receipt20`) -/ private theorem prev20_chron : (∀ i : Fin 20, Archive150.rawPorts ⟨i, by omega⟩ = nativeRawPort MixedWindow.j7 i) ∧ (∀ j : Fin 9, 1 ≤ j.val → ∀ i : Fin 20, ArchiveJ20.rawPorts (prev20 j) ⟨i, by omega⟩ = nativeRawPort20 (prev20 j) i) ∧ (∀ j : Fin 9, ∀ i : Fin 16, oldRange (start20 j + 1) (windowNet20 j (prevCodePorts20 j ⟨i.val, by omega⟩))) := by decide +kernel attribute [local irreducible] SkywalkNat.step Shadow.far nextWindow20 window20 withArchive20 body20 in theorem selected_receipt20 (j : Fin 9) (d : Bool) (x p : Nat) (good : Bounds x p) (raw s : State) (g sg pg ps : Bool) (m : List Bool) (pre : At20 j d x p raw s g sg pg ps) : SavedKey (mixedKey x p ⟨7 + j.val, by have := j.isLt; omega⟩) (prevCodePorts20 j) d (run (nextWindow20 j d) m s) := by have hj := j.isLt have nums := actualNumbers20 j x p good have hist := WideReference20.pulled_history20 j pre.domain have inp : SkywalkIntegerInput (EnterJ20.lay j) (encode g sg (unsigned (start20 j) x p).u (unsigned (start20 j) x p).v).a (encode g sg (unsigned (start20 j) x p).u (unsigned (start20 j) x p).v).b g raw.basis := readInput (start20 j) x p raw g sg pre.input let preS := run (enterP20 j) m s let tape := m.drop (measurementCount (enterP20 j)) let T := Shadow.reduced (sbP20 (start20 j)) 20 (unsigned (start20 j) x p) let Z := encode g sg T.u T.v have to' : T.v % 2 = 1 := shadow_odd20 (sbP20 (start20 j)) (unsigned (start20 j) x p) nums.small.1 nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum g sg _ _ (by omega) have ready := EnterJ20.ready_pending_at j raw s (unsigned (start20 j) x p) g sg m nums.small.1 pre.cut inp hist have scr := scratch_raw_clean20 j d raw s m x p good pre.domain _ _ _ Z parity ready.2.1 pre.cut have hold := bank_kept20 j d s m tape (tape.drop (measurementCount (routed20 j 0 1))) Z parity ready.2.1 have prevOdd : (unsigned (prevTick20 j) x p).v % 2 = 1 := by unfold prevTick20; split_ifs with h0 · exact (LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good).odd · exact (actualNumbers20 (prev20 j) x p good).odd have prevSm : PrevSmall20 j (unsigned (prevTick20 j) x p) := by unfold PrevSmall20 prevTick20; split_ifs with h0 · exact (LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good).farSmall · exact (actualNumbers20 (prev20 j) x p good).small.1 obtain ⟨_, row, limit, _, frame⟩ := admits20 j d s m tape (tape.drop (measurementCount (routed20 j 0 1))) Z parity ready.2.1 scr (unsigned (prevTick20 j) x p) pg ps (prevCross20 j x p) prevOdd prevSm pre.facts have hEnc : Encodes (mixedKey x p ⟨7 + j.val, by omega⟩) row := by by_cases h0 : j.val = 0 · have hj0 : j = ⟨0, by decide⟩ := Fin.ext h0 subst hj0 have all := StockCanonicalRow.frame_key MixedWindow.j7 Archive150.rawPorts prev20_chron.1 row (Shadow7.sbP 150) (unsigned 150 x p) pg ps _ s _ pre.facts hold frame have hcanon := pre.pastCanonical simp only [prevTick20, ↓reduceIte, signedAt] at hcanon dsimp only [mixedKey, prevCross20] at all ⊢ rw [hcanon] at all exact all · have all := frame_key20 (prev20 j) (ArchiveJ20.rawPorts (prev20 j)) (prev20_chron.2.1 j (by omega)) row (unsigned (start20 (prev20 j)) x p) pg ps _ s _ (by simpa only [PrevPast20, prevTick20, prevCross20, if_neg h0] using pre.facts) (by simpa only [prevRawPorts20, if_neg h0] using hold) (by simpa only [prevRawPorts20, if_neg h0] using frame) have hcanon := pre.pastCanonical simp only [prevTick20, if_neg h0, signedAt] at hcanon dsimp only at all rw [hcanon] at all have hmk : mixedKey x p ⟨7 + j.val, by omega⟩ = Reentry345.value20 x p (prev20 j) := by unfold mixedKey rw [dif_neg (by dsimp; omega), dif_neg (by dsimp; omega), dif_pos (by dsimp; omega)] congr 1; apply Fin.ext; simp [prev20]; omega rw [hmk]; exact all have spec := select_spec ⟨row, limit, hEnc⟩ have rf := reframe limit hEnc (prevRawPorts20 j) _ frame have final := archive_result20 j d _ spec.1 _ _ rf have runEq : run (nextWindow20 j d) m s = run (body20 j (withArchive20 j d)) tape preS := by simp only [nextWindow20, window20, run_append, run_take, preS, tape] rw [runEq] exact ⟨spec.1, spec.2, body20_keeps j (withArchive20 j d) (prevCodePorts20 j) d _ preS tape (fun i => old_clear20 (by decide) (prev20_chron.2.2 j i)) final⟩ /-! ### Section 4: Bank Preservation Across 15-Tick, Transition-150, 20-Tick, Reentry-345 & Exit-420 -/ private theorem keep_cells_15 (i k : Fin 26) (hk : k.val = i.val + 1) (h1 : 1 ≤ k.val) (h24 : k.val ≤ 24) (d : Bool) (t : Nat) (ht0 : 60 ≤ t) (ht1 : t + 15 ≤ start k) (q : Wire) (hq : q ∈ cellsRestoreP t) (s : State) (m : List Bool) : (run (MixedWindow.block15F d i k).flatten m s).basis q = s.basis q := by have c := StockWindowW7.cells_rangeG t (by simp only [start] at ht1; omega) q hq have w1 : 45 ≤ start k := by simp only [start]; omega have w2 : start k ≤ 405 := by simp only [start]; omega obtain ⟨r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, ew, ew', ee, ee', et, et', ea, eb, el, r20, r21⟩ := Shadow7.rail_win w1 w2 have sk : start k ≤ 405 := by simp only [start]; omega have pk : NativeJ7.prev k = i := Fin.ext (by simp only [NativeJ7.prev]; omega) have hfl : (MixedWindow.block15F d i k).flatten = NativeJ7.nextWindow k d ++ CRTBarrel.leave k := by rw [← pk] simp only [MixedWindow.block15F, MixedWindow.packW, NativeJ7.nextWindow, NativeJ7.window, Shadow7.body, NativeJ7.withArchive, NativeJ7.program, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] rw [hfl, run_append, run_take] rw [CRTWindow.leave_keeps k (by omega) (by omega) q (by unfold Shadow7.leaveBox2; simp only [Wire] at *; omega)] simp only [NativeJ7.nextWindow, NativeJ7.window, run_append, run_take] have native : ¬ Shadow7.MayTouch k (windowNet k q) := by have mid : (Shadow7.shape k).mid = Shadow7.sbP (start k) + 15 := rfl rcases c with c | c | c · rw [show windowNet k q = q from NativeJ7.sig_kept _ _ (by omega) (by omega)] unfold Shadow7.MayTouch; rw [mid]; simp only [Wire] at *; omega · rw [show windowNet k q = q from NativeJ7.sig_kept _ _ (by omega) (by omega)] unfold Shadow7.MayTouch; rw [mid]; simp only [Wire] at *; omega · rw [show windowNet k q = 3113 - q from NativeJ7.sig_moved _ _ (Or.inr ⟨by omega, c.2.2⟩)] unfold Shadow7.MayTouch; rw [mid]; simp only [Wire] at *; omega have port : q ∉ EnterJ7.ports k := fun hm => by have r := EnterJ7.portsRegion k hm simp only [Wire] at *; omega have admin : q ∉ NativeJ7.support k ++ ArchiveJ7.rawPortsList (NativeJ7.prev k) := by rw [List.mem_append, ArchiveJ7.raw_split] intro mem rcases mem with mem | mem · simp only [NativeJ7.support, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] at mem obtain ⟨v, ⟨v1, v2⟩, e | e⟩ := mem · rw [NativeJ7.sig_kept _ _ (by simp only [base, Wire] at *; omega) (by simp only [base, Wire] at *; omega)] at e simp only [base, Wire] at *; omega · by_cases mv : 1301 ≤ 1044 + v · rw [NativeJ7.sig_moved _ _ (Or.inl ⟨by simp only [base, Wire] at *; omega, by simp only [base, Wire] at *; omega⟩)] at e simp only [base, Wire] at *; omega · rw [NativeJ7.sig_kept _ _ (by simp only [base, Wire] at *; omega) (by simp only [base, Wire] at *; omega)] at e simp only [base, Wire] at *; omega · rw [List.mem_append] at mem rcases mem with mem | mem · rw [ArchiveJ7.rawHead, cellsLoadP, List.mem_append] at mem have hs : start (NativeJ7.prev k) + 15 = start k := by simp only [NativeJ7.prev, start]; omega rcases mem with mem | mem · simp only [List.mem_flatMap, List.mem_range, List.mem_cons, List.not_mem_nil, or_false] at mem obtain ⟨v, hv, e | e⟩ := mem · rw [hs] at e; simp only [Wire] at *; omega · rw [hs] at e by_cases mv : 1301 ≤ start k + 1034 + v · rw [NativeJ7.sig_moved _ _ (Or.inl ⟨mv, by omega⟩)] at e; simp only [Wire] at *; omega · rw [NativeJ7.sig_kept _ _ (by omega) (by omega)] at e; simp only [Wire] at *; omega · simp only [List.mem_cons, List.not_mem_nil, or_false, hs] at mem rcases mem with rfl | rfl | rfl <;> (simp only [Shadow7.e0P, Wire] at *; omega) · obtain ⟨v, hv, eq⟩ := List.mem_map.mp mem have hv' := List.mem_range.mp hv have hs : start (NativeJ7.prev k) + 15 = start k := by simp only [NativeJ7.prev, start]; omega rw [hs] at eq have qv : (q : Nat) = Shadow7.scratchS (start k) v := eq.symm rcases Shadow7.scratchS_cases (start k) v (by omega) hv' with ⟨_, _, _⟩ | ⟨_, _, _⟩ <;> (simp only [Wire] at *; omega) exact Shadow7.ext_head (Shadow7.enterP k) k (NativeJ7.withArchive k d) _ s _ _ q native (EnterJ7.notWire k port) admin (NativeJ7.admin_cover k (by omega) h24 d) private theorem keep_leave150 (t : Nat) (ht0 : 60 ≤ t) (ht1 : t ≤ 150) (q : Wire) (hq : q ∈ cellsRestoreP t) (s : State) (m : List Bool) : (run leave150To20Red m s).basis q = s.basis q := by have c := StockWindowW7.cells_rangeG t (by omega) q hq rcases c with c | c | c · exact leave150To20Red_keeps q (by unfold Shadow7.leaveBox2 Shadow7.a0P Shadow7.b0P Shadow7.sbP railP; simp only [Wire] at *; split_ifs <;> omega) m s · exact leave150To20Red_keeps q (by unfold Shadow7.leaveBox2 Shadow7.a0P Shadow7.b0P Shadow7.sbP railP; simp only [Wire] at *; split_ifs <;> omega) m s · exact leave150To20Red_keeps_mirror q (by simp only [Wire] at *; omega) m s private theorem keep_leave20 (j : Fin 9) (t : Nat) (ht0 : 60 ≤ t) (ht1 : t ≤ start20 j) (q : Wire) (hq : q ∈ cellsRestoreP t) (s : State) (m : List Bool) : (run (leaveP20Red j) m s).basis q = s.basis q := by have hg := geom20_facts j have hbt : bTopP (start20 j) ≤ 1043 := by unfold bTopP railP; split_ifs <;> omega have c := StockWindowW7.cells_rangeG t (by omega) q hq rcases c with c | c | c · exact leaveP20Red_keeps j q (by unfold leaveBox20 a0P20 b0P20; simp only [Wire] at *; omega) m s · exact leaveP20Red_keeps j q (by unfold leaveBox20 a0P20 b0P20; simp only [Wire] at *; omega) m s · exact leaveP20Red_keeps_mirror j q (by simp only [Wire] at *; omega) m s private theorem keep_cells_20 (j : Fin 9) (d : Bool) (t : Nat) (ht0 : 60 ≤ t) (ht1 : t + prevLen20 j ≤ start20 j) (q : Wire) (hq : q ∈ cellsRestoreP t) (s : State) (m : List Bool) : (run (nextWindow20 j d ++ leaveP20Red j) m s).basis q = s.basis q := by have hg := geom20_facts j have hpl : 15 ≤ prevLen20 j ∧ prevLen20 j ≤ 20 := by unfold prevLen20; split_ifs <;> omega have c := StockWindowW7.cells_rangeG t (by omega) q hq rw [run_append, run_take, keep_leave20 j t ht0 (by omega) q hq] simp only [nextWindow20, window20, run_append, run_take] have native : ¬ MayTouch20 j (windowNet20 j q) := by have mid : (shape20 j).mid = sbP20 (start20 j) + 20 := rfl rcases c with c | c | c · rw [show windowNet20 j q = q from NativeJ7.sig_kept _ _ (by omega) (by omega)] unfold MayTouch20; rw [mid]; simp only [Wire] at *; omega · rw [show windowNet20 j q = q from NativeJ7.sig_kept _ _ (by omega) (by omega)] unfold MayTouch20; rw [mid]; simp only [Wire] at *; omega · rw [show windowNet20 j q = 3113 - q from NativeJ7.sig_moved _ _ (Or.inr ⟨by omega, c.2.2⟩)] unfold MayTouch20; rw [mid]; simp only [Wire] at *; omega have port : q ∉ EnterJ20.ports j := fun hm => by have r := EnterJ20.portsRegion j hm have hsum : ∀ m : Fin 9, e0P20 (start20 m) + start20 m ≤ 2045 := by decide +kernel have := hsum j; simp only [EnterJ20.h20, e0P20, Wire] at *; omega have admin : q ∉ support20 j ++ prevRawPortsList20 j := by rw [List.mem_append, prevRaw_split, List.mem_append] rintro (mem | mem | mem) · simp only [support20, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] at mem obtain ⟨v, ⟨v1, v2⟩, e | e⟩ := mem · have hv : start20 j - prevLen20 j ≤ v ∧ v < start20 j := by unfold prevLen20 at *; split_ifs at v1 v2 ⊢ <;> (try simp only [start20] at *) <;> omega rw [NativeJ7.sig_kept _ _ (by simp only [base, Wire] at *; omega) (by simp only [base, Wire] at *; omega)] at e simp only [base, Wire] at *; omega · have hv : start20 j - prevLen20 j ≤ v ∧ v < start20 j := by unfold prevLen20 at *; split_ifs at v1 v2 ⊢ <;> (try simp only [start20] at *) <;> omega by_cases mv : 1301 ≤ 1044 + v · rw [NativeJ7.sig_moved _ _ (Or.inl ⟨by simp only [base, Wire] at *; omega, by simp only [base, Wire] at *; omega⟩)] at e simp only [base, Wire] at *; omega · rw [NativeJ7.sig_kept _ _ (by simp only [base, Wire] at *; omega) (by simp only [base, Wire] at *; omega)] at e simp only [base, Wire] at *; omega · have hhead : prevRawHead20 j = cellsLoadP (start20 j) ++ [e0P20 (start20 j) + 6, e0P20 (start20 j) + 7, e0P20 (start20 j) + 8] := by unfold prevRawHead20; split_ifs with h0 · simp only [Archive150.rawHead, Archive150.flagBase, show start20 j = 165 by simp [start20, h0]] · simp only [ArchiveJ20.rawHead, ArchiveJ20.endTick, ArchiveJ20.flagBase] have hpv : (prev20 j).val = j.val - 1 := rfl have he : start20 (prev20 j) + 20 = start20 j := by unfold start20; rw [hpv]; omega have hn : nextE0_20 (start20 (prev20 j)) = e0P20 (start20 j) := by unfold nextE0_20; rw [he, if_pos (by omega)] rw [he, hn] rw [hhead, cellsLoadP, List.mem_append] at mem rcases mem with mem | mem · simp only [List.mem_flatMap, List.mem_range, List.mem_cons, List.not_mem_nil, or_false] at mem obtain ⟨v, hv, e | e⟩ := mem · simp only [Wire] at *; omega · by_cases mv : 1301 ≤ start20 j + 1034 + v · rw [NativeJ7.sig_moved _ _ (Or.inl ⟨mv, by omega⟩)] at e; simp only [Wire] at *; omega · rw [NativeJ7.sig_kept _ _ (by omega) (by omega)] at e; simp only [Wire] at *; omega · have hsum : ∀ m : Fin 9, e0P20 (start20 m) + start20 m ≤ 2045 := by decide +kernel have := hsum j simp only [List.mem_cons, List.not_mem_nil, or_false] at mem rcases mem with rfl | rfl | rfl <;> (simp only [Wire] at *; omega) · have sb : 1556 ≤ (q : Nat) ∧ (q : Nat) < 1700 := by unfold prevScratch20 at mem; split_ifs at mem with h0 · obtain ⟨v, hv, rfl⟩ := List.mem_map.mp mem; rw [List.mem_range] at hv unfold archScratch150; split_ifs <;> (unfold Wire; omega) · obtain ⟨v, hv, rfl⟩ := List.mem_map.mp mem; rw [List.mem_range] at hv unfold archScratch20; dsimp only; split_ifs <;> (unfold Wire; omega) simp only [Wire] at *; omega exact ext_head20 (enterP20 j) j (withArchive20 j d) _ s _ _ q native (EnterJ20.notWire j port) admin (admin_cover20 j d) private theorem keep_cells_345 (d : Bool) (t : Nat) (ht0 : 60 ≤ t) (ht1 : t ≤ 325) (q : Wire) (hq : q ∈ cellsRestoreP t) (s : State) (m : List Bool) : (run (nextWindow345 d ++ CRTBarrel.leave MixedWindow.j20) m s).basis q = s.basis q := by have c := StockWindowW7.cells_rangeG t (by omega) q hq rw [run_append, run_take] rw [CRTWindow.leave_keeps MixedWindow.j20 (by decide) (by decide) q (by unfold Shadow7.leaveBox2 Shadow7.a0P Shadow7.b0P Shadow7.sbP railP rw [show start MixedWindow.j20 = 345 from rfl]; simp only [Wire] at *; split_ifs <;> omega)] simp only [nextWindow345, window345, run_append, run_take] have native : ¬ Shadow7.MayTouch MixedWindow.j20 (windowNet MixedWindow.j20 q) := by have mid : (Shadow7.shape MixedWindow.j20).mid = 91 := by decide rcases c with c | c | c · rw [show windowNet MixedWindow.j20 q = q from NativeJ7.sig_kept 359 q (by omega) (by omega)] unfold Shadow7.MayTouch; rw [mid]; rw [show start MixedWindow.j20 = 345 from rfl]; simp only [Wire] at *; omega · rw [show windowNet MixedWindow.j20 q = q from NativeJ7.sig_kept 359 q (by omega) (by omega)] unfold Shadow7.MayTouch; rw [mid]; rw [show start MixedWindow.j20 = 345 from rfl]; simp only [Wire] at *; omega · rw [show windowNet MixedWindow.j20 q = 3113 - q from NativeJ7.sig_moved 359 q (Or.inr ⟨by omega, c.2.2⟩)] unfold Shadow7.MayTouch; rw [mid]; rw [show start MixedWindow.j20 = 345 from rfl]; simp only [Wire] at *; omega have port : q ∉ EnterJ7.ports MixedWindow.j20 := fun hm => by have r := EnterJ7.portsRegion MixedWindow.j20 hm rw [show start MixedWindow.j20 = 345 from rfl, show Shadow7.sbP 345 = 76 by decide] at r simp only [Wire] at *; omega have admin : q ∉ support345 ++ ArchiveJ20.rawPortsList MixedWindow.k8 := by rw [List.mem_append, ArchiveJ20.raw_split, List.mem_append] have hall : (support345 ++ ArchiveJ20.rawHead MixedWindow.k8).all (fun w => decide ((341 ≤ (w : Nat) ∧ (w : Nat) ≤ 360) ∨ (1725 ≤ (w : Nat) ∧ (w : Nat) ≤ 1744) ∨ (1656 ≤ (w : Nat) ∧ (w : Nat) ≤ 1658))) = true := by decide +kernel rintro (h | h | h) · have := of_decide_eq_true (List.all_eq_true.mp hall q (List.mem_append_left _ h)); simp only [Wire] at *; omega · have := of_decide_eq_true (List.all_eq_true.mp hall q (List.mem_append_right _ h)); simp only [Wire] at *; omega · obtain ⟨v, hv, rfl⟩ := List.mem_map.mp h; rw [List.mem_range] at hv have sb : 1556 ≤ (archScratch20 (start20 MixedWindow.k8) v : Nat) ∧ (archScratch20 (start20 MixedWindow.k8) v : Nat) < 1700 := by unfold archScratch20; dsimp only; split_ifs <;> (unfold Wire; omega) simp only [Wire] at *; omega exact Shadow7.ext_head (Shadow7.enterP MixedWindow.j20) MixedWindow.j20 (withArchive345 d) _ s _ _ q native (EnterJ7.notWire MixedWindow.j20 port) admin (admin_cover345 d) private theorem keep_cells_exit420 (d : Bool) (t : Nat) (ht0 : 60 ≤ t) (ht1 : t ≤ 405) (q : Wire) (hq : q ∈ cellsRestoreP t) (s : State) (m : List Bool) : (run (exitF CRTBarrel.params d 420).flatten m s).basis q = s.basis q := by have c := StockWindowW7.cells_rangeG t (by omega) q hq simp only [exitF, CRTBarrel.params, Shadow7.params, ofParts, List.flatten_cons, List.flatten_nil, List.append_nil, run_append, run_take] rw [run_preserves_outside (Shadow7.exitLoadP 420 d) _ _ q (fun hit => by have r := StockWindowW7.raw420_ranges q (List.mem_toFinset.mp (ArchiveBoundary4207.load_cover d hit)) simp only [Wire] at *; omega)] rw [run_preserves_outside _ _ _ q (fun hit => by rw [renameProgram_support] at hit obtain ⟨w, hw, e⟩ := Finset.mem_image.mp hit have pc := (WindowCovered.pack_cells d 410 (by decide) (by decide)).1 w hw obtain ⟨r, r1, r2, er | er⟩ := pc · rw [er, NativeJ7.sig_kept 420 _ (by simp only [base, Wire]; omega) (by simp only [base, Wire]; omega)] at e rcases c with ⟨lo, hi⟩ | ⟨lo, hi, hh⟩ | ⟨lo, hi, hh⟩ <;> (simp only [base, Wire] at *; omega) · rw [er, NativeJ7.sig_moved 420 _ (Or.inl ⟨by simp only [base, Wire]; omega, by simp only [base, Wire]; omega⟩)] at e rcases c with ⟨lo, hi⟩ | ⟨lo, hi, hh⟩ | ⟨lo, hi, hh⟩ <;> (simp only [base, Wire] at *; omega))] have nt : q ∉ wires (renameProgram (OB5.sig 420) (TickRanges.tick base 420)) := EndTick4207.physical_free EndTick4207.P EndTick4207.supports.1 q (by apply WideReference.away (by decide) rcases c with ⟨lo, hi⟩ | ⟨lo, hi, hh⟩ | ⟨lo, hi, hh⟩ · rw [NativeJ7.sig_kept _ _ (by omega) (by omega)] exact ⟨q - 16, by omega, Or.inl (by simp only [base, Wire]; omega)⟩ · rw [NativeJ7.sig_kept _ _ (by omega) (by omega)] exact ⟨q - 1044, by omega, Or.inr (by simp only [base, Wire]; omega)⟩ · rw [NativeJ7.sig_moved _ _ (Or.inr ⟨by omega, hh⟩)] exact ⟨2069 - q, by omega, Or.inr (by simp only [base, Wire]; omega)⟩) rw [run_preserves_outside _ _ _ q nt] rw [run_preserves_outside (Shadow7.portalInvP 420) _ _ q (fun hit => by have f := StockWindowW7.portalInv_low420 q hit have f2 := (Shadow7.portal_wires 420 (by decide) (by decide)).2 q hit have hr : railP 420 = 93 := by decide unfold footP at f2; rw [hr] at f2 rcases c with ⟨lo, hi⟩ | ⟨lo, hi, hh⟩ | ⟨lo, hi, hh⟩ <;> (simp only [Wire] at *; omega))] rw [run_preserves_outside (Shadow7.parkP 420) _ _ q (fun hit => by have f := StockWindowW7.park_low420 q hit have f2 := (Shadow7.park_wires 420 (by decide) (by decide)).1 q hit have hr : railP 420 = 93 := by decide unfold parkFootP at f2; rw [hr] at f2 rcases c with ⟨lo, hi⟩ | ⟨lo, hi, hh⟩ | ⟨lo, hi, hh⟩ <;> (simp only [Wire] at *; omega))] /-! ### Section 5: 7-Chunk Strong Composition (`MixedChain.strong`) -/ private theorem chunk1_checked (d : Bool) (x : Nat) (good : Bounds x p) : Checked ([Shadow7.portalP 45, Shadow7.enterP MixedWindow.j0, Shadow7.routed MixedWindow.j0 0 1, MixedWindow.packW d 45 45, Shadow7.routed MixedWindow.j0 1 14, CRTBarrel.leave MixedWindow.j0]).flatten ([CRTBarrel.unleave MixedWindow.j0, TickCut.Hosted.unroutedHigh MixedWindow.j0 1 14, MixedWindow.unpackW d 45 45, Shadow7.unrouted MixedWindow.j0 0 1, Shadow7.enterInvP MixedWindow.j0, Shadow7.portalInvP 45]).flatten (BeforeW d x p) (fun s => ReadyW d x p 60 s ∧ SavedBefore d x p 0 s) := by have h := StockWindowW7.firstStepG 24 StockWindowW7.leaves22 d x p good intro s m hb obtain ⟨ph, post, undo⟩ := h s m hb exact ⟨ph, ⟨post, fun b hb0 => by omega⟩, undo⟩ private theorem chunk15_step (d : Bool) (x : Nat) (good : Bounds x p) (i k : Fin 26) (hk : k.val = i.val + 1) (h1 : 1 ≤ k.val) (h24 : k.val ≤ 24) (n : Nat) (bNew : MixedGeo.Bank) (hbn : bNew.val = n) (hb_ports : MixedGeo.bankPorts StockWindowChainP.ExitPorts420 bNew = ArchiveJ7.codePorts i) (hb_key : mixedKey x p bNew = value x p (start i) (Shadow7.sbP (start i)) (StockRowVectorW.crossW i)) (hprev : ∀ b : MixedGeo.Bank, b.val < n → MixedGeo.endTick b + 15 ≤ start k) : Checked (MixedWindow.block15F d i k).flatten (TickCut.Mixed.block15R d i k).flatten (fun s => ReadyW d x p (start k) s ∧ SavedBefore d x p n s) (fun s => ReadyW d x p (start k + 15) s ∧ SavedBefore d x p (n + 1) s) := by have step := StockWindowW7.interiorG 24 (by decide) StockWindowW7.leaves22 d x p good i k hk h1 h24 have hrec := StockWindowChainP.receiptS d x p good i k hk h1 h24 have hfe : (MixedWindow.block15F d i k).flatten = (nextF CRTBarrel.params d i k).flatten := by simp only [MixedWindow.block15F, MixedWindow.packW, nextF, CRTBarrel.params, Shadow7.params, ofParts, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] have hre : (TickCut.Mixed.block15R d i k).flatten = (nextR CRTBarrel.params d i k).flatten := by simp only [TickCut.Mixed.block15R, MixedWindow.unpackW, nextR, CRTBarrel.params, Shadow7.params, ofParts, TickCut.Tail.selected14_eq, TickCut.Tail.sel01, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] rw [hfe, hre] intro s m ⟨hr, hs⟩ obtain ⟨ph, post, undo⟩ := step s m hr refine ⟨ph, ⟨post, fun b hb => ?_⟩, undo⟩ by_cases he : b.val = n · have hbeq : b = bNew := Fin.ext (he.trans hbn.symm) subst hbeq unfold BankKey rw [hb_ports, hb_key] exact hrec s m hr · have hlt : b.val < n := by omega exact keep_savedKey (hs b hlt) (fun q hq => by rw [← hfe]; exact keep_cells_15 i k hk h1 h24 d (MixedGeo.endTick b) (bank_tick_match b).2.2.2.2.1 (hprev b hlt) q (bank_cells_mem b q hq) s m) private theorem chunk2_checked (d : Bool) (x : Nat) (good : Bounds x p) : Checked (MixedWindow.prefixPairs.flatMap fun p => MixedWindow.block15F d p.1 p.2).flatten (MixedWindow.prefixPairs.reverse.flatMap fun p => TickCut.Mixed.block15R d p.1 p.2).flatten (fun s => ReadyW d x p 60 s ∧ SavedBefore d x p 0 s) (fun s => ReadyW d x p 150 s ∧ SavedBefore d x p 6 s) := by have mk (n : Nat) (hn : n < 6) := chunk15_step d x good ⟨n, by omega⟩ ⟨n + 1, by omega⟩ rfl (by dsimp; omega) (by dsimp; omega) n ⟨n, by omega⟩ rfl (by simp only [MixedGeo.bankPorts, dif_pos (show n < 7 by omega)]) (by unfold mixedKey; rw [dif_pos (show n < 7 by omega)]) (fun b hb => by have h : ∀ k : MixedGeo.Bank, k.val < 6 → ∀ m : Nat, m < 6 → k.val < m → MixedGeo.endTick k + 15 ≤ 45 + 15 * (m + 1) := by decide +kernel exact h b (by omega) n hn hb) have c := composition (mk 0 (by decide)) (composition (mk 1 (by decide)) (composition (mk 2 (by decide)) (composition (mk 3 (by decide)) (composition (mk 4 (by decide)) (mk 5 (by decide)))))) simpa only [MixedWindow.prefixPairs, List.reverse_cons, List.reverse_nil, List.nil_append, List.cons_append, List.flatMap_cons, List.flatMap_nil, List.append_nil, List.flatten_append, List.append_assoc] using c theorem flags15_eq (s x p : Nat) (g sg : Bool) : LeaveJ7.Admission.flags (unsigned s x p) g sg = SharedSigned.flags g sg (SkywalkTrace.trace 15 (signedAt s x p g sg)) := rfl theorem flags20_eq (s x p : Nat) (g sg : Bool) : flags20 (unsigned s x p) g sg = SharedSigned.flags g sg (SkywalkTrace.trace 20 (signedAt s x p g sg)) := rfl private theorem eraseSites_phase (ws : List Wire) (s : State) : (eraseSites ws s).phase = s.phase := by induction ws generalizing s with | nil => rfl | cons w ws ih => exact ih _ private theorem pullState_phase (f : Wire → Wire) (s : State) : (pullState f s).phase = s.phase := rfl private theorem chunk3_checked (d : Bool) (x : Nat) (good : Bounds x p) : Checked ([Shadow7.enterP MixedWindow.j7, Shadow7.routed MixedWindow.j7 0 1, MixedWindow.packW d 150 140, Shadow7.archiveLoadP MixedWindow.j6 d, Shadow7.routed MixedWindow.j7 1 14, leave150To20Red]).flatten ([leaveInv150To20Red, TickCut.Hosted.unroutedHigh MixedWindow.j7 1 14, Shadow7.archiveRestoreP MixedWindow.j6 d, MixedWindow.unpackW d 150 140, Shadow7.unrouted MixedWindow.j7 0 1, Shadow7.enterInvP MixedWindow.j7]).flatten (fun s => ReadyW d x p 150 s ∧ SavedBefore d x p 6 s) (fun s => Ready20 ⟨0, by decide⟩ d x p s ∧ SavedBefore d x p 7 s) := by have hfl : ([Shadow7.enterP MixedWindow.j7, Shadow7.routed MixedWindow.j7 0 1, MixedWindow.packW d 150 140, Shadow7.archiveLoadP MixedWindow.j6 d, Shadow7.routed MixedWindow.j7 1 14, leave150To20Red]).flatten = NativeJ7.nextWindow MixedWindow.j7 d ++ leave150To20Red := by simp only [NativeJ7.nextWindow, NativeJ7.window, Shadow7.body, NativeJ7.withArchive, NativeJ7.program, MixedWindow.packW, show NativeJ7.prev MixedWindow.j7 = MixedWindow.j6 from rfl, show start MixedWindow.j7 = 150 from rfl, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] have hrl : ([leaveInv150To20Red, TickCut.Hosted.unroutedHigh MixedWindow.j7 1 14, Shadow7.archiveRestoreP MixedWindow.j6 d, MixedWindow.unpackW d 150 140, Shadow7.unrouted MixedWindow.j7 0 1, Shadow7.enterInvP MixedWindow.j7]).flatten = leaveInv150To20Red ++ NativeJ7.nextUnwind MixedWindow.j7 d := by simp only [NativeJ7.nextUnwind, NativeJ7.unwind, TickCut.Tail.unbodySelected, TickCut.Tail.selected14_eq, TickCut.Tail.sel01, NativeJ7.fromArchive, NativeJ7.reverse, MixedWindow.unpackW, show NativeJ7.prev MixedWindow.j7 = MixedWindow.j6 from rfl, show start MixedWindow.j7 = 150 from rfl, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] rw [hfl, hrl] intro s m ⟨hr, hs⟩ obtain ⟨k, ek, raw, g, sg, pg, ps, pre⟩ := hr have hk7 : k = MixedWindow.j7 := Fin.ext (by simp only [start] at ek; show k.val = 7; omega) subst hk7 have hs150 : start MixedWindow.j7 = 150 := rfl have hdom150 : Domain 150 x p raw := hs150 ▸ pre.domain have hinp150 : InputAt 150 (signedAt 150 x p g sg) raw := hs150 ▸ pre.input have hcut150 := pre.cut rw [hs150] at hcut150 have nums := LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good have old := LeaveJ7.Admission.actualNumbers MixedWindow.j6 (by decide) (by decide) x p good have hist := WideReference.pulled_history MixedWindow.j7 rfl pre.domain have inp := readInput 150 x p raw g sg hinp150 have scr := StockWindowW7.leaves22.scratch MixedWindow.j7 (by decide) (by decide) d x p good raw s g sg pg ps m pre have nat := NativeJ7.from_domain_matched MixedWindow.j7 (by decide) (by decide) d x p good raw s m pre.domain g sg pre.cut (hs150.symm ▸ inp) scr pg ps _ pre.facts have ep := endpoint150To20 d x p good raw s m (m.drop (measurementCount (NativeJ7.nextWindow MixedWindow.j7 d))) hdom150 g sg hcut150 inp scr pg ps _ pre.facts have carried := stepInput_gen_shadow7 150 (Shadow7.sbP 150) x p (by decide) (by decide) good raw (run (NativeJ7.nextWindow MixedWindow.j7 d) m s) g sg hdom150 hinp150 (hs150 ▸ nums.farSmall) have canon := unique_input hinp150 (fixed_input 150 x p (by decide) good raw hdom150) have hnextSmall20 : Shadow7.SmallIfFar 163 20 (SkywalkNat.step^[15] (unsigned 150 x p)) := by have hs165 : start20 ⟨0, by decide⟩ = 165 := rfl have hsb163 : sbP20 (start20 ⟨0, by decide⟩) = 163 := rfl have h1 := (actualNumbers20 ⟨0, by decide⟩ x p good).small.1 rw [hsb163, hs165] at h1 have he165 : SkywalkNat.step^[15] (unsigned 150 x p) = unsigned 165 x p := by show SkywalkNat.step^[15] (SkywalkNat.step^[150] (SkywalkNat.init x p)) = SkywalkNat.step^[165] (SkywalkNat.init x p) rw [show (165 : Nat) = 150 + 15 by decide, Nat.add_comm, Function.iterate_add_apply] rw [he165]; exact h1 have hred150 := leave150To20Red_pair (run (NativeJ7.nextWindow MixedWindow.j7 d) m s) (unsigned 150 x p) g sg nat.1 hnextSmall20 have hph : (run (NativeJ7.nextWindow MixedWindow.j7 d ++ leave150To20Red) m s).phase = s.phase := by rw [run_append, run_take, hred150.1] have cph := ep.1.phase rw [eraseSites_phase, pullState_phase] at cph have hcp := hcut150.phase rw [eraseSites_phase, pullState_phase] at hcp have eph := WideReference.endRaw_phase 150 x p (by decide) good raw (run (NativeJ7.nextWindow MixedWindow.j7 d) m s) hdom150 exact cph.trans (eph.trans hcp.symm) refine ⟨hph, ⟨?_, ?_⟩, ?_⟩ · rw [run_append, run_take, hred150.1] have h165 : (150 : Nat) + 15 = start20 ⟨0, by decide⟩ := rfl have hpt0 : (150 : Nat) = prevTick20 ⟨0, by decide⟩ := rfl refine ⟨WideReference.endRaw 150 raw (run (NativeJ7.nextWindow MixedWindow.j7 d) m s), (LeaveJ7.Admission.flags (unsigned 150 x p) g sg).1, (LeaveJ7.Admission.flags (unsigned 150 x p) g sg).2, g, sg, ⟨h165 ▸ carried.1, ?_, ?_, ?_, hpt0 ▸ canon⟩⟩ · rw [← h165, flags15_eq]; exact carried.2 · simpa only [← h165] using ep.1 · simpa only [PrevPast20, prevTick20, prevCross20, ↓reduceIte] using ep.2.1 · intro b hb rw [run_append, run_take] by_cases h6 : b.val = 6 · have hbeq : b = ⟨6, by decide⟩ := Fin.ext h6 subst hbeq have cert := NativeJ7.selected_receipt MixedWindow.j7 (by decide) (by decide) d raw s m (unsigned 150 x p) g sg (hs150 ▸ nums.odd) (hs150 ▸ nums.farSmall) (hs150 ▸ pre.cut) (hs150.symm ▸ inp) hist scr (unsigned 135 x p) pg ps _ (by simpa only [show start MixedWindow.j6 = 135 from rfl] using old.odd) (by simpa only [show start MixedWindow.j6 = 135 from rfl] using old.farSmall) (by simpa only [show start (NativeJ7.prev MixedWindow.j7) = 135 from rfl] using pre.facts) have hpc := pre.pastCanonical rw [show start (NativeJ7.prev MixedWindow.j7) = 135 from rfl] at hpc unfold signedAt at hpc; dsimp only at cert; rw [hpc] at cert have hk6 : BankKey d x p ⟨6, by decide⟩ (run (NativeJ7.nextWindow MixedWindow.j7 d) m s) := by unfold BankKey MixedGeo.bankPorts mixedKey simp only [show (6 : Nat) < 7 by decide, ↓reduceDIte] rw [show NativeJ7.prev MixedWindow.j7 = ⟨6, by decide⟩ from rfl] at cert exact ⟨cert.1, cert.2.1, cert.2.2⟩ exact keep_savedKey hk6 (fun q hq => keep_leave150 150 (by decide) (by decide) q (bank_cells_mem ⟨6, by decide⟩ q hq) _ _) · have hlt : b.val < 6 := by omega have hend : MixedGeo.endTick b ≤ 135 := by have h : ∀ k : MixedGeo.Bank, k.val < 6 → MixedGeo.endTick k ≤ 135 := by decide +kernel exact h b hlt exact keep_savedKey (hs b hlt) (fun q hq => by rw [keep_leave150 (MixedGeo.endTick b) (bank_tick_match b).2.2.2.2.1 (by omega) q (bank_cells_mem b q hq)] have h15 := keep_cells_15 MixedWindow.j6 MixedWindow.j7 rfl (by decide) (by decide) d (MixedGeo.endTick b) (bank_tick_match b).2.2.2.2.1 (by show MixedGeo.endTick b + 15 ≤ 150; omega) q (bank_cells_mem b q hq) s m have hfl15 : (MixedWindow.block15F d MixedWindow.j6 MixedWindow.j7).flatten = NativeJ7.nextWindow MixedWindow.j7 d ++ CRTBarrel.leave MixedWindow.j7 := by simp only [MixedWindow.block15F, MixedWindow.packW, NativeJ7.nextWindow, NativeJ7.window, Shadow7.body, NativeJ7.withArchive, NativeJ7.program, show NativeJ7.prev MixedWindow.j7 = MixedWindow.j6 from rfl, show start MixedWindow.j7 = 150 from rfl, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] rw [hfl15, run_append, run_take, CRTWindow.leave_keeps MixedWindow.j7 (by decide) (by decide) q (by have c := bank_range b q hq have h60 := (bank_tick_match b).2.2.2.2.1 unfold Shadow7.leaveBox2 Shadow7.a0P Shadow7.b0P Shadow7.sbP railP rw [show start MixedWindow.j7 = 150 from rfl] simp only [Wire] at *; split_ifs <;> omega)] at h15 exact h15) · intro t rw [run_append, run_take, run_append, run_take, hred150.2 _ t, nat.2.2.2] private theorem endRaw_phase20 (s prevLen x p : Nat) (lim : s + 20 ≤ 512) (good : Bounds x p) (raw history : State) (dom : Domain s x p raw) : (WideReference20.endRaw s prevLen 20 raw history).phase = raw.phase := by show (run (span s 20) [] raw).phase = raw.phase obtain ⟨ref, same, stage⟩ := dom have match' := WideReference.fixed_span s s 20 (Nat.le_refl _) lim raw ref [] same exact match'.1.trans ((WideReference.span_phase s 20 x p lim good ref [] stage).trans same.1.symm) private theorem endTick20_eq : ∀ r : Fin 9, MixedGeo.endTick ⟨7 + r.val, by have := r.isLt; omega⟩ = start20 r := by decide +kernel private theorem block20_flatten (d : Bool) (j : Fin 9) : (MixedWindow.block20F d j).flatten = nextWindow20 j d ++ leaveP20Red j ∧ (TickCut.Mixed.block20R d j).flatten = leaveInvP20Red j ++ TickCut.Wide.nextUnwind20 j d := by unfold MixedWindow.block20F TickCut.Mixed.block20R nextWindow20 window20 body20 withArchive20 packProg20 archLoad20 TickCut.Wide.nextUnwind20 TickCut.Wide.unwind20 TickCut.Wide.unbodySelected fromArchive20 packRev20 archRestore20 prev20 by_cases h0 : j.val = 0 · simp only [h0, ↓reduceDIte, ↓reduceIte, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc, and_self] · simp only [h0, ↓reduceDIte, ↓reduceIte, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc, and_self] private theorem step20_next_checked (d : Bool) (x : Nat) (good : Bounds x p) (j k : Fin 9) (hk : k.val = j.val + 1) : Checked (MixedWindow.block20F d j).flatten (TickCut.Mixed.block20R d j).flatten (fun s => Ready20 j d x p s ∧ SavedBefore d x p (7 + j.val) s) (fun s => Ready20 k d x p s ∧ SavedBefore d x p (7 + j.val + 1) s) := by have hj := j.isLt rw [(block20_flatten d j).1, (block20_flatten d j).2] intro s m ⟨⟨raw, g, sg, pg, ps, pre⟩, hs⟩ have nums := actualNumbers20 j x p good have hist := WideReference20.pulled_history20 j pre.domain have inp := readInput (start20 j) x p raw g sg pre.input let preS := run (enterP20 j) m s let tape := m.drop (measurementCount (enterP20 j)) let T := Shadow.reduced (sbP20 (start20 j)) 20 (unsigned (start20 j) x p) let Z := encode g sg T.u T.v have to' : T.v % 2 = 1 := shadow_odd20 (sbP20 (start20 j)) (unsigned (start20 j) x p) nums.small.1 nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum g sg _ _ (by omega) have ready := EnterJ20.ready_pending_at j raw s (unsigned (start20 j) x p) g sg m nums.small.1 pre.cut inp hist have scr := scratch_raw_clean20 j d raw s m x p good pre.domain _ _ _ Z parity ready.2.1 pre.cut have prevOdd : (unsigned (prevTick20 j) x p).v % 2 = 1 := by unfold prevTick20; split_ifs with h0 · exact (LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good).odd · exact (actualNumbers20 (prev20 j) x p good).odd have prevSm : PrevSmall20 j (unsigned (prevTick20 j) x p) := by unfold PrevSmall20 prevTick20; split_ifs with h0 · exact (LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good).farSmall · exact (actualNumbers20 (prev20 j) x p good).small.1 have adm := TickCut.Leaf20.admitted20 j d x p good raw s m pre.domain g sg pre.cut inp scr (unsigned (prevTick20 j) x p) pg ps (prevCross20 j x p) prevOdd prevSm pre.facts have ep := endpoint20_next j k hk d x p good raw s m (m.drop (measurementCount (nextWindow20 j d))) pre.domain g sg pre.cut inp scr (unsigned (prevTick20 j) x p) pg ps (prevCross20 j x p) prevOdd prevSm pre.facts have hprev_le : prevLen20 j ≤ start20 j := by unfold prevLen20 start20; split_ifs <;> omega have carried := WideReference20.stepInput20 (start20 j) (prevLen20 j) (sbP20 (start20 j)) x p hprev_le (by unfold start20; omega) good raw (run (nextWindow20 j d) m s) g sg pre.domain pre.input nums.small.1 have canon := unique_input pre.input (fixed_input (start20 j) x p (by unfold start20; omega) good raw pre.domain) have hsk : start20 k = start20 j + 20 := by unfold start20; omega have hpk : prev20 k = j := Fin.ext (by simp only [prev20]; omega) have hred20 := leaveP20Red_pair j (run (nextWindow20 j d) m s) (unsigned (start20 j) x p) g sg adm.1 have hph : (run (nextWindow20 j d ++ leaveP20Red j) m s).phase = s.phase := by rw [run_append, run_take, hred20.1] have cph := ep.1.phase rw [eraseSites_phase, pullState_phase] at cph have hcp := pre.cut.phase rw [eraseSites_phase, pullState_phase] at hcp have eph := endRaw_phase20 (start20 j) (prevLen20 j) x p (by unfold start20; omega) good raw (run (nextWindow20 j d) m s) pre.domain exact cph.trans (eph.trans hcp.symm) refine ⟨hph, ⟨?_, ?_⟩, ?_⟩ · rw [run_append, run_take, hred20.1] refine ⟨WideReference20.endRaw (start20 j) (prevLen20 j) 20 raw (run (nextWindow20 j d) m s), (flags20 (unsigned (start20 j) x p) g sg).1, (flags20 (unsigned (start20 j) x p) g sg).2, g, sg, ⟨hsk ▸ carried.1, by rw [flags20_eq]; exact hsk ▸ carried.2, ep.1, ?_, ?_⟩⟩ · simp only [PrevPast20, prevTick20, prevCross20, if_neg (show k.val ≠ 0 by omega), hpk]; exact ep.2 · simp only [prevTick20, if_neg (show k.val ≠ 0 by omega), hpk]; exact canon · intro b hb rw [run_append, run_take] by_cases he : b.val = 7 + j.val · have hbeq : b = ⟨7 + j.val, by omega⟩ := Fin.ext he rw [hbeq] have hrec := selected_receipt20 j d x p good raw s g sg pg ps m pre have hp : MixedGeo.bankPorts StockWindowChainP.ExitPorts420 ⟨7 + j.val, by omega⟩ = prevCodePorts20 j := by unfold MixedGeo.bankPorts prevCodePorts20 by_cases h0 : j.val = 0 · simp only [h0, Nat.add_zero, show ¬ ((7 : Nat) < 7) by decide, ↓reduceDIte, ↓reduceIte] · simp only [h0, show ¬ (7 + j.val < 7) by omega, show ¬ (7 + j.val = 7) by omega, show 7 + j.val < 17 by omega, ↓reduceDIte, ↓reduceIte] congr 1; apply Fin.ext; simp [prev20]; omega have hbk : BankKey d x p ⟨7 + j.val, by omega⟩ (run (nextWindow20 j d) m s) := by unfold BankKey; rw [hp]; exact hrec have hend : MixedGeo.endTick ⟨7 + j.val, by omega⟩ = start20 j := endTick20_eq j exact keep_savedKey hbk (fun q hq => keep_leave20 j (MixedGeo.endTick ⟨7 + j.val, by omega⟩) (bank_tick_match _).2.2.2.2.1 (by omega) q (bank_cells_mem _ q hq) _ _) · have hlt : b.val < 7 + j.val := by omega have hend : MixedGeo.endTick b + prevLen20 j ≤ start20 j := by have h : ∀ r : Fin 9, ∀ k' : MixedGeo.Bank, k'.val < 7 + r.val → MixedGeo.endTick k' + prevLen20 r ≤ start20 r := by decide +kernel exact h j b hlt exact keep_savedKey (hs b hlt) (fun q hq => by have hk := keep_cells_20 j d (MixedGeo.endTick b) (bank_tick_match b).2.2.2.2.1 hend q (bank_cells_mem b q hq) s m rw [run_append, run_take] at hk; exact hk) · intro t rw [run_append, run_take, run_append, run_take, hred20.2 _ t, adm.2.2.2.2] private theorem step20_last_checked (d : Bool) (x : Nat) (good : Bounds x p) : Checked (MixedWindow.block20F d MixedWindow.k8).flatten (TickCut.Mixed.block20R d MixedWindow.k8).flatten (fun s => Ready20 MixedWindow.k8 d x p s ∧ SavedBefore d x p 15 s) (fun s => Ready345 d x p s ∧ SavedBefore d x p 16 s) := by rw [(block20_flatten d MixedWindow.k8).1, (block20_flatten d MixedWindow.k8).2] intro s m ⟨⟨raw, g, sg, pg, ps, pre⟩, hs⟩ have hs325 : start20 MixedWindow.k8 = 325 := rfl have hdom325 : Domain 325 x p raw := hs325 ▸ pre.domain have hinp325 : InputAt 325 (signedAt 325 x p g sg) raw := hs325 ▸ pre.input have hcut325 := pre.cut rw [hs325] at hcut325 have nums := actualNumbers20 MixedWindow.k8 x p good have hnums_sm : Shadow7.SmallIfFar (sbP20 325) 20 (unsigned 325 x p) := hs325 ▸ nums.small.1 have hnums_odd : (unsigned 325 x p).v % 2 = 1 := hs325 ▸ nums.odd have hist := WideReference20.pulled_history20 MixedWindow.k8 pre.domain have inp := readInput 325 x p raw g sg hinp325 let preS := run (enterP20 MixedWindow.k8) m s let tape := m.drop (measurementCount (enterP20 MixedWindow.k8)) let T := Shadow.reduced (sbP20 325) 20 (unsigned 325 x p) let Z := encode g sg T.u T.v have to' : T.v % 2 = 1 := shadow_odd20 (sbP20 325) (unsigned 325 x p) hnums_sm hnums_odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum g sg _ _ (by omega) have ready := EnterJ20.ready_pending_at MixedWindow.k8 raw s (unsigned (start20 MixedWindow.k8) x p) g sg m nums.small.1 pre.cut (hs325.symm ▸ inp) hist have scr := scratch_raw_clean20 MixedWindow.k8 d raw s m x p good pre.domain _ _ _ Z parity (by simpa only [hs325] using ready.2.1) pre.cut have hpt305 : prevTick20 MixedWindow.k8 = start20 (prev20 MixedWindow.k8) := rfl have prevOdd : (unsigned (prevTick20 MixedWindow.k8) x p).v % 2 = 1 := hpt305.symm ▸ (actualNumbers20 (prev20 MixedWindow.k8) x p good).odd have prevSm : PrevSmall20 MixedWindow.k8 (unsigned (prevTick20 MixedWindow.k8) x p) := hpt305.symm ▸ (actualNumbers20 (prev20 MixedWindow.k8) x p good).small.1 have adm := TickCut.Leaf20.admitted20 MixedWindow.k8 d x p good raw s m pre.domain g sg pre.cut (hs325.symm ▸ inp) scr (unsigned (prevTick20 MixedWindow.k8) x p) pg ps (prevCross20 MixedWindow.k8 x p) prevOdd prevSm pre.facts have ep := endpoint20_reentry d x p good raw s m (m.drop (measurementCount (nextWindow20 MixedWindow.k8 d))) hdom325 g sg hcut325 inp scr (unsigned (prevTick20 MixedWindow.k8) x p) pg ps (prevCross20 MixedWindow.k8 x p) prevOdd prevSm pre.facts have carried := WideReference20.stepInput20 325 20 (sbP20 325) x p (by decide) (by decide) good raw (run (nextWindow20 MixedWindow.k8 d) m s) g sg hdom325 hinp325 hnums_sm have canon := unique_input hinp325 (fixed_input 325 x p (by decide) good raw hdom325) have hred20 := leaveP20Red_pair MixedWindow.k8 (run (nextWindow20 MixedWindow.k8 d) m s) (unsigned (start20 MixedWindow.k8) x p) g sg adm.1 have hph : (run (nextWindow20 MixedWindow.k8 d ++ leaveP20Red MixedWindow.k8) m s).phase = s.phase := by rw [run_append, run_take, hred20.1] have cph := ep.1.phase rw [eraseSites_phase, pullState_phase] at cph have hcp := hcut325.phase rw [eraseSites_phase, pullState_phase] at hcp have eph := endRaw_phase20 325 20 x p (by decide) good raw (run (nextWindow20 MixedWindow.k8 d) m s) hdom325 exact cph.trans (eph.trans hcp.symm) refine ⟨hph, ⟨?_, ?_⟩, ?_⟩ · rw [run_append, run_take, hred20.1] have h345 : (325 : Nat) + 20 = 345 := rfl exact ⟨WideReference20.endRaw 325 20 20 raw (run (nextWindow20 MixedWindow.k8 d) m s), (flags20 (unsigned 325 x p) g sg).1, (flags20 (unsigned 325 x p) g sg).2, g, sg, ⟨h345 ▸ carried.1, by rw [← h345, flags20_eq]; exact carried.2, ep.1, ep.2, canon⟩⟩ · intro b hb rw [run_append, run_take] by_cases h15 : b.val = 15 · have hbeq : b = ⟨15, by decide⟩ := Fin.ext h15 subst hbeq have hrec := selected_receipt20 MixedWindow.k8 d x p good raw s g sg pg ps m pre have hp : MixedGeo.bankPorts StockWindowChainP.ExitPorts420 ⟨15, by decide⟩ = prevCodePorts20 MixedWindow.k8 := by unfold MixedGeo.bankPorts prevCodePorts20 simp only [show ¬ ((15 : Nat) < 7) by decide, show ¬ ((15 : Nat) = 7) by decide, show (15 : Nat) < 17 by decide, show MixedWindow.k8.val ≠ 0 by decide, ↓reduceDIte, ↓reduceIte] rfl have hbk : BankKey d x p ⟨15, by decide⟩ (run (nextWindow20 MixedWindow.k8 d) m s) := by unfold BankKey; rw [hp]; exact hrec exact keep_savedKey hbk (fun q hq => keep_leave20 MixedWindow.k8 325 (by decide) (by decide) q (bank_cells_mem ⟨15, by decide⟩ q hq) _ _) · have hlt : b.val < 15 := by omega have hend : MixedGeo.endTick b + prevLen20 MixedWindow.k8 ≤ start20 MixedWindow.k8 := by have h : ∀ k' : MixedGeo.Bank, k'.val < 15 → MixedGeo.endTick k' + prevLen20 MixedWindow.k8 ≤ start20 MixedWindow.k8 := by decide +kernel exact h b hlt exact keep_savedKey (hs b hlt) (fun q hq => by have hk := keep_cells_20 MixedWindow.k8 d (MixedGeo.endTick b) (bank_tick_match b).2.2.2.2.1 hend q (bank_cells_mem b q hq) s m rw [run_append, run_take] at hk; exact hk) · intro t rw [run_append, run_take, run_append, run_take, hred20.2 _ t, adm.2.2.2.2] private theorem chunk4_checked (d : Bool) (x : Nat) (good : Bounds x p) : Checked ((List.finRange 9).flatMap (MixedWindow.block20F d)).flatten ((List.finRange 9).reverse.flatMap (TickCut.Mixed.block20R d)).flatten (fun s => Ready20 ⟨0, by decide⟩ d x p s ∧ SavedBefore d x p 7 s) (fun s => Ready345 d x p s ∧ SavedBefore d x p 16 s) := by have c := composition (step20_next_checked d x good ⟨0, by decide⟩ ⟨1, by decide⟩ rfl) (composition (step20_next_checked d x good ⟨1, by decide⟩ ⟨2, by decide⟩ rfl) (composition (step20_next_checked d x good ⟨2, by decide⟩ ⟨3, by decide⟩ rfl) (composition (step20_next_checked d x good ⟨3, by decide⟩ ⟨4, by decide⟩ rfl) (composition (step20_next_checked d x good ⟨4, by decide⟩ ⟨5, by decide⟩ rfl) (composition (step20_next_checked d x good ⟨5, by decide⟩ ⟨6, by decide⟩ rfl) (composition (step20_next_checked d x good ⟨6, by decide⟩ ⟨7, by decide⟩ rfl) (composition (step20_next_checked d x good ⟨7, by decide⟩ ⟨8, by decide⟩ rfl) (step20_last_checked d x good)))))))) have hfr : List.finRange 9 = [⟨0, by decide⟩, ⟨1, by decide⟩, ⟨2, by decide⟩, ⟨3, by decide⟩, ⟨4, by decide⟩, ⟨5, by decide⟩, ⟨6, by decide⟩, ⟨7, by decide⟩, ⟨8, by decide⟩] := by decide rw [hfr] simpa only [List.reverse_cons, List.reverse_nil, List.nil_append, List.cons_append, List.flatMap_cons, List.flatMap_nil, List.append_nil, List.flatten_append, List.append_assoc] using c private theorem chunk5_checked (d : Bool) (x : Nat) (good : Bounds x p) : Checked ([Shadow7.enterP MixedWindow.j20, Shadow7.routed MixedWindow.j20 0 1, MixedWindow.packW d 345 330, MixedWindow.packW d 345 335, archiveLoadP20 MixedWindow.k8 d, Shadow7.routed MixedWindow.j20 1 14, CRTBarrel.leave MixedWindow.j20]).flatten ([CRTBarrel.unleave MixedWindow.j20, TickCut.Hosted.unroutedHigh MixedWindow.j20 1 14, archiveRestoreP20 MixedWindow.k8 d, MixedWindow.unpackW d 345 335, MixedWindow.unpackW d 345 330, Shadow7.unrouted MixedWindow.j20 0 1, Shadow7.enterInvP MixedWindow.j20]).flatten (fun s => Ready345 d x p s ∧ SavedBefore d x p 16 s) (fun s => ReadyW d x p 360 s ∧ SavedBefore d x p 17 s) := by have hfl : ([Shadow7.enterP MixedWindow.j20, Shadow7.routed MixedWindow.j20 0 1, MixedWindow.packW d 345 330, MixedWindow.packW d 345 335, archiveLoadP20 MixedWindow.k8 d, Shadow7.routed MixedWindow.j20 1 14, CRTBarrel.leave MixedWindow.j20]).flatten = nextWindow345 d ++ CRTBarrel.leave MixedWindow.j20 := by simp only [nextWindow345, window345, Shadow7.body, withArchive345, packProg345, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] have hrl : ([CRTBarrel.unleave MixedWindow.j20, TickCut.Hosted.unroutedHigh MixedWindow.j20 1 14, archiveRestoreP20 MixedWindow.k8 d, MixedWindow.unpackW d 345 335, MixedWindow.unpackW d 345 330, Shadow7.unrouted MixedWindow.j20 0 1, Shadow7.enterInvP MixedWindow.j20]).flatten = CRTBarrel.unleave MixedWindow.j20 ++ TickCut.Reentry20.nextUnwind345 d := by simp only [TickCut.Reentry20.nextUnwind345, TickCut.Reentry20.unwind345, TickCut.Tail.unbodySelected, TickCut.Tail.selected14_eq, TickCut.Tail.sel01, fromArchive345, packRev345, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] rw [hfl, hrl] intro s m ⟨⟨raw, g, sg, pg, ps, pre⟩, hs⟩ have nums := LeaveJ7.Admission.actualNumbers MixedWindow.j20 (by decide) (by decide) x p good have inp := readInput 345 x p raw g sg pre.input have ep := endpoint345 d x p good raw s m (m.drop (measurementCount (nextWindow345 d))) pre.domain g sg pre.cut inp pg ps _ pre.facts have domP := rawPack325_domain d x p raw pre.domain have inpP := rawPack325_input d raw _ pre.input have carried := stepInput_gen_shadow7 345 (Shadow7.sbP 345) x p (by decide) (by decide) good (rawPack325 d raw) (run (nextWindow345 d) m s) g sg domP inpP nums.farSmall have canon := unique_input pre.input (fixed_input 345 x p (by decide) good raw pre.domain) refine ⟨by rw [run_append, run_take]; exact ep.1, ⟨?_, ?_⟩, ?_⟩ · rw [run_append, run_take] exact ⟨⟨21, by decide⟩, rfl, WideReference.endRaw 345 (rawPack325 d raw) (run (nextWindow345 d) m s), (LeaveJ7.Admission.flags (unsigned 345 x p) g sg).1, (LeaveJ7.Admission.flags (unsigned 345 x p) g sg).2, g, sg, ⟨carried.1, by rw [flags15_eq]; exact carried.2, ep.2.1, ep.2.2.1, canon⟩⟩ · intro b hb by_cases h16 : b.val = 16 · have hbeq : b = ⟨16, by decide⟩ := Fin.ext h16 subst hbeq rw [run_append, run_take] have hrec := selected_receipt345 d x p good raw s m pre.domain g sg pre.cut inp pg ps pre.pastCanonical pre.facts have hbk : BankKey d x p ⟨16, by decide⟩ (run (nextWindow345 d) m s) := by unfold BankKey MixedGeo.bankPorts mixedKey simp only [show ¬ ((16 : Nat) < 7) by decide, show ¬ ((16 : Nat) = 7) by decide, show (16 : Nat) < 17 by decide, ↓reduceDIte] exact hrec exact keep_savedKey hbk (fun q hq => CRTWindow.leave_keeps MixedWindow.j20 (by decide) (by decide) q (by have c := bank_range ⟨16, by decide⟩ q hq unfold Shadow7.leaveBox2 Shadow7.a0P Shadow7.b0P Shadow7.sbP railP rw [show start MixedWindow.j20 = 345 from rfl, show MixedGeo.endTick ⟨16, by decide⟩ = 345 by decide] at * simp only [Wire] at *; split_ifs <;> omega) _ _) · have hlt : b.val < 16 := by omega have hend : MixedGeo.endTick b ≤ 325 := by have h : ∀ k' : MixedGeo.Bank, k'.val < 16 → MixedGeo.endTick k' ≤ 325 := by decide +kernel exact h b hlt exact keep_savedKey (hs b hlt) (fun q hq => keep_cells_345 d (MixedGeo.endTick b) (bank_tick_match b).2.2.2.2.1 hend q (bank_cells_mem b q hq) s m) · intro t rw [run_append, run_take, run_append, run_take, ep.2.2.2.1 t, ep.2.2.2.2] private theorem chunk6_checked (d : Bool) (x : Nat) (good : Bounds x p) : Checked (MixedWindow.suffixPairs.flatMap fun p => MixedWindow.block15F d p.1 p.2).flatten (MixedWindow.suffixPairs.reverse.flatMap fun p => TickCut.Mixed.block15R d p.1 p.2).flatten (fun s => ReadyW d x p 360 s ∧ SavedBefore d x p 17 s) (fun s => ReadyW d x p 420 s ∧ SavedBefore d x p 21 s) := by have mk (r : Nat) (hr : r < 4) := chunk15_step d x good ⟨20 + r, by omega⟩ ⟨21 + r, by omega⟩ (by dsimp; omega) (by dsimp; omega) (by dsimp; omega) (17 + r) ⟨17 + r, by omega⟩ rfl (by unfold MixedGeo.bankPorts rw [dif_neg (by dsimp; omega), dif_neg (by dsimp; omega), dif_neg (by dsimp; omega), dif_pos (by dsimp; omega)] congr 1; apply Fin.ext; dsimp; omega) (by unfold mixedKey rw [dif_neg (by dsimp; omega), dif_neg (by dsimp; omega), dif_neg (by dsimp; omega)] have hfe : (⟨(⟨17 + r, by omega⟩ : MixedGeo.Bank).val + 3, by dsimp; omega⟩ : Fin 26) = ⟨20 + r, by omega⟩ := Fin.ext (by dsimp; omega) rw [hfe]) (fun b hb => by have h : ∀ k : MixedGeo.Bank, ∀ m : Nat, m < 4 → k.val < 17 + m → MixedGeo.endTick k + 15 ≤ 45 + 15 * (21 + m) := by decide +kernel exact h b r hr hb) have c := composition (mk 0 (by decide)) (composition (mk 1 (by decide)) (composition (mk 2 (by decide)) (mk 3 (by decide)))) simpa only [MixedWindow.suffixPairs, List.reverse_cons, List.reverse_nil, List.nil_append, List.cons_append, List.flatMap_cons, List.flatMap_nil, List.append_nil, List.flatten_append, List.append_assoc] using c private theorem chunk7_checked (d : Bool) (x : Nat) (good : Bounds x p) : Checked ([Shadow7.parkP 420, Shadow7.portalInvP 420, MixedWindow.tickW 420, MixedWindow.packW d 420 410, Shadow7.exitLoadP 420 d]).flatten ([Shadow7.exitRestoreP 420 d, MixedWindow.unpackW d 420 410, MixedWindow.recvW 420, Shadow7.portalP 420, Shadow7.parkInvP 420]).flatten (fun s => ReadyW d x p 420 s ∧ SavedBefore d x p 21 s) (mixedFinal StockWindowChainP.ExitPorts420 d x p) := by have hfe : ([Shadow7.parkP 420, Shadow7.portalInvP 420, MixedWindow.tickW 420, MixedWindow.packW d 420 410, Shadow7.exitLoadP 420 d]).flatten = (exitF CRTBarrel.params d 420).flatten := by simp only [exitF, CRTBarrel.params, Shadow7.params, ofParts, MixedWindow.tickW, MixedWindow.packW, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] have hre : ([Shadow7.exitRestoreP 420 d, MixedWindow.unpackW d 420 410, MixedWindow.recvW 420, Shadow7.portalP 420, Shadow7.parkInvP 420]).flatten = (exitR CRTBarrel.params d 420).flatten := by simp only [exitR, CRTBarrel.params, Shadow7.params, ofParts, MixedWindow.recvW, MixedWindow.unpackW, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] rw [hfe, hre] intro s m ⟨hr, hs⟩ have e := StockWindowW7.exitLeaves420.step d x good s m hr refine ⟨e.1, fun b => ?_, e.2.2⟩ by_cases h21 : b.val = 21 · have hbeq : b = ⟨21, by decide⟩ := Fin.ext h21 subst hbeq have fk := StockWindowChainP.finalKey420 d x good s m hr unfold MixedGeo.bankPorts mixedKey simp only [show ¬ ((21 : Nat) < 7) by decide, show ¬ ((21 : Nat) = 7) by decide, show ¬ ((21 : Nat) < 17) by decide, show ¬ ((21 : Nat) < 21) by decide, ↓reduceDIte] exact fk · have hlt : b.val < 21 := by have := b.isLt; omega have hend : MixedGeo.endTick b ≤ 405 := by have h : ∀ k' : MixedGeo.Bank, k'.val < 21 → MixedGeo.endTick k' ≤ 405 := by decide +kernel exact h b hlt exact keep_savedKey (hs b hlt) (fun q hq => keep_cells_exit420 d (MixedGeo.endTick b) (bank_tick_match b).2.2.2.2.1 hend q (bank_cells_mem b q hq) s m) /-- End-to-end mixed 15/20-tick strong chain: phase preservation, all 22 saved archive keys, and exact roundtrip under `MixedWindow.reverseMixed d`. -/ theorem strong (d : Bool) (x : Nat) (good : Bounds x p) (raw : State) (m : List Bool) (stage : Rolling1588.Integer.Stage base d x p 45 raw.basis) : let start0 := pullState (OB5.sig 44) raw let out := run (MixedWindow.forwardMixed d) m start0 out.phase = raw.phase ∧ mixedFinal StockWindowChainP.ExitPorts420 d x p out ∧ ∀ n, run (TickCut.Mixed.reverseUncut d) n out = start0 := by have all := composition (chunk1_checked d x good) (composition (chunk2_checked d x good) (composition (chunk3_checked d x good) (composition (chunk4_checked d x good) (composition (chunk5_checked d x good) (composition (chunk6_checked d x good) (chunk7_checked d x good)))))) have hf : MixedWindow.forwardMixed d = ([Shadow7.portalP 45, Shadow7.enterP MixedWindow.j0, Shadow7.routed MixedWindow.j0 0 1, MixedWindow.packW d 45 45, Shadow7.routed MixedWindow.j0 1 14, CRTBarrel.leave MixedWindow.j0]).flatten ++ ((MixedWindow.prefixPairs.flatMap fun p => MixedWindow.block15F d p.1 p.2).flatten ++ (([Shadow7.enterP MixedWindow.j7, Shadow7.routed MixedWindow.j7 0 1, MixedWindow.packW d 150 140, Shadow7.archiveLoadP MixedWindow.j6 d, Shadow7.routed MixedWindow.j7 1 14, leave150To20Red]).flatten ++ (((List.finRange 9).flatMap (MixedWindow.block20F d)).flatten ++ (([Shadow7.enterP MixedWindow.j20, Shadow7.routed MixedWindow.j20 0 1, MixedWindow.packW d 345 330, MixedWindow.packW d 345 335, archiveLoadP20 MixedWindow.k8 d, Shadow7.routed MixedWindow.j20 1 14, CRTBarrel.leave MixedWindow.j20]).flatten ++ ((MixedWindow.suffixPairs.flatMap fun p => MixedWindow.block15F d p.1 p.2).flatten ++ ([Shadow7.parkP 420, Shadow7.portalInvP 420, MixedWindow.tickW 420, MixedWindow.packW d 420 410, Shadow7.exitLoadP 420 d]).flatten))))) := by simp only [MixedWindow.forwardMixed, MixedWindow.forwardL, List.flatten_append, List.append_assoc] have hr : TickCut.Mixed.reverseUncut d = (((((([Shadow7.exitRestoreP 420 d, MixedWindow.unpackW d 420 410, MixedWindow.recvW 420, Shadow7.portalP 420, Shadow7.parkInvP 420]).flatten ++ (MixedWindow.suffixPairs.reverse.flatMap fun p => TickCut.Mixed.block15R d p.1 p.2).flatten) ++ ([CRTBarrel.unleave MixedWindow.j20, TickCut.Hosted.unroutedHigh MixedWindow.j20 1 14, archiveRestoreP20 MixedWindow.k8 d, MixedWindow.unpackW d 345 335, MixedWindow.unpackW d 345 330, Shadow7.unrouted MixedWindow.j20 0 1, Shadow7.enterInvP MixedWindow.j20]).flatten) ++ ((List.finRange 9).reverse.flatMap (TickCut.Mixed.block20R d)).flatten) ++ ([leaveInv150To20Red, TickCut.Hosted.unroutedHigh MixedWindow.j7 1 14, Shadow7.archiveRestoreP MixedWindow.j6 d, MixedWindow.unpackW d 150 140, Shadow7.unrouted MixedWindow.j7 0 1, Shadow7.enterInvP MixedWindow.j7]).flatten) ++ (MixedWindow.prefixPairs.reverse.flatMap fun p => TickCut.Mixed.block15R d p.1 p.2).flatten) ++ ([CRTBarrel.unleave MixedWindow.j0, TickCut.Hosted.unroutedHigh MixedWindow.j0 1 14, MixedWindow.unpackW d 45 45, Shadow7.unrouted MixedWindow.j0 0 1, Shadow7.enterInvP MixedWindow.j0, Shadow7.portalInvP 45]).flatten := by simp only [TickCut.Mixed.reverseUncut, TickCut.Mixed.reverseL, List.flatten_append, List.append_assoc] rw [hf, hr] exact all (pullState (OB5.sig 44) raw) m ⟨raw, stage, rfl⟩ end ECDSAAdd.Entrant.StairPacket.Shadow20.MixedChain end -- ==== end Shadow7Wide20Chain ==== -- ==== begin Shadow7Wide20Ord ==== section /-! # Mixed 15/20-Tick Ordinary Chain & 22-Bank Stock Comparison API (`Shadow7Wide20Ord`) 1. `MixedArchiveReference`: `ordinary d := StockGroupsW.batch 45 d MixedGeo.plain` and `common d raw := pullState (OB5.sig 420) (eraseSites MixedGeo.holes (run (ordinary d) [] (run (span 45 376) [] raw)))`. 2. `MixedOrdinary.wiresMixed`: proves `MixedWindow.forwardMixed d` agrees with `MixedArchiveReference.common d raw` off `MixedGeo.archives` (`352` archive cells). 3. `MixedBaseline.comparison`, `MixedArchiveBanks.Paired`, `MixedRowVector.binding`, `MixedNativeCompare.normalized`: drop-in 22-bank stock comparison API for `Main.lean`. -/ namespace ECDSAAdd.Entrant.StairPacket.Shadow20.MixedOrd open ECDSAAdd.Arithmetic open ECDSAAdd.Arithmetic.MappedCompressed open ECDSAAdd.Secp256k1 open ECDSAAdd.Entrant.IntegerPacket open ECDSAAdd.Entrant.StairPacket open ECDSAAdd.Entrant.StairPacket.Partial open ECDSAAdd.Entrant.StairPacket.ArchivePortAction open ECDSAAdd.Entrant.StairPacket.ArchiveStockRows open ECDSAAdd.Entrant.StairPacket.WideReference open ECDSAAdd.Entrant.StairPacket.ArchiveHistoryCompare open ECDSAAdd.Entrant.StairPacket.StockWindowTicket open ECDSAAdd.Entrant.StairPacket.WindowFold open ECDSAAdd.Entrant.StairPacket.StockCanonicalRow open ECDSAAdd.Entrant.StairPacket.StockWindowW7 open ECDSAAdd.Entrant.StairPacket.Shadow20 open ECDSAAdd.Entrant.StairPacket.Shadow20.NativeJ20 open ECDSAAdd.Entrant.StairPacket.Shadow20.LeaveCut20 open ECDSAAdd.Entrant.StairPacket.Shadow20.Trans150 open ECDSAAdd.Entrant.StairPacket.Shadow20.Reentry345 open ECDSAAdd.Entrant.StairPacket.Shadow20.MixedChain open SkywalkRails set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false set_option linter.unusedSimpArgs false attribute [local irreducible] run Shadow7.portalP Shadow7.portalInvP Shadow7.parkP Shadow7.parkInvP Shadow7.enterP Shadow7.enterInvP Shadow7.routed Shadow7.unrouted Shadow7.archiveLoadP Shadow7.archiveRestoreP Shadow7.exitLoadP Shadow7.exitRestoreP CRTBarrel.leave CRTBarrel.unleave leave150To20 leaveInv150To20 leave150To20Red leaveInv150To20Red enterP20 enterInvP20 routed20 unrouted20 leaveP20 leaveInvP20 leaveP20Red leaveInvP20Red archiveLoadP20 archiveRestoreP20 archiveLoad150To20 archiveRestore150To20 /-! ### Section 1: `MixedArchiveReference` & Generalized Ordinary State `OrdInv` -/ def ordinary (d : Bool) : Program := StockGroupsW.batch 45 d MixedGeo.plain def common (d : Bool) (raw : State) : State := pullState (OB5.sig 420) (eraseSites MixedGeo.holes (run (ordinary d) [] (run (span 45 376) [] raw))) /-- Banks `0..n-1` masked cells. -/ def bankMask (n : Nat) : List Wire := ((List.finRange 22).take n).flatMap fun b => MixedGeo.cells10 (MixedGeo.endTick b - 10) /-- Banks `0..n-1` erased holes. -/ def bankHoles (n : Nat) : List Wire := ((List.finRange 22).take n).flatMap fun b => [base (1028 + (MixedGeo.endTick b - 8)), base (1028 + (MixedGeo.endTick b - 6)), base (1028 + (MixedGeo.endTick b - 3)), base (1028 + (MixedGeo.endTick b - 1))] /-- Plain groups encoded before tick `t`. -/ def groupProg (d : Bool) (gs : List Nat) : Program := StockGroupsW.batch 45 d gs private theorem groupProg_append (d : Bool) (a b : List Nat) : groupProg d (a ++ b) = groupProg d a ++ groupProg d b := OrdinaryChainG.batch_append 45 d a b private theorem groupProg_singleton (d : Bool) (i : Nat) : groupProg d [i] = Rolling1588.encodeAt base d (40 + 5 * i) := by simp only [groupProg, StockGroupsW.batch, List.flatMap_cons, List.flatMap_nil, List.append_nil, StockGroupsW.one, StockWindowGeo.gstart] private theorem bankMask_succ (b : MixedGeo.Bank) : bankMask (b.val + 1) = bankMask b.val ++ MixedGeo.cells10 (MixedGeo.endTick b - 10) := by have hb := b.isLt have ht : (List.finRange 22).take (b.val + 1) = (List.finRange 22).take b.val ++ [b] := by rw [List.take_add_one, List.getElem?_eq_getElem (by simp [hb]), Option.toList_some, List.getElem_finRange] simp only [Fin.cast_mk, Fin.eta, Fin.cast_eq_self] simp only [bankMask, ht, List.flatMap_append, List.flatMap_cons, List.flatMap_nil, List.append_nil] private theorem bankHoles_succ (b : MixedGeo.Bank) : bankHoles (b.val + 1) = bankHoles b.val ++ [base (1028 + (MixedGeo.endTick b - 8)), base (1028 + (MixedGeo.endTick b - 6)), base (1028 + (MixedGeo.endTick b - 3)), base (1028 + (MixedGeo.endTick b - 1))] := by have hb := b.isLt have ht : (List.finRange 22).take (b.val + 1) = (List.finRange 22).take b.val ++ [b] := by rw [List.take_add_one, List.getElem?_eq_getElem (by simp [hb]), Option.toList_some, List.getElem_finRange] simp only [Fin.cast_mk, Fin.eta, Fin.cast_eq_self] simp only [bankHoles, ht, List.flatMap_append, List.flatMap_cons, List.flatMap_nil, List.append_nil] private theorem bankMask_cells (n : Nat) (bound : Nat) (hb : ∀ b : MixedGeo.Bank, b.val < n → MixedGeo.endTick b ≤ bound) : ∀ q ∈ bankMask n, ∃ r, r < bound ∧ (q = base r ∨ q = base (1028 + r)) := by intro q hq simp only [bankMask, List.mem_flatMap] at hq obtain ⟨b, hbt, hcq⟩ := hq have hblt : b.val < n := by obtain ⟨i, hi, eq⟩ := List.mem_iff_getElem.mp hbt have hlen : ((List.finRange 22).take n).length = min n 22 := by simp have hin : i < n := by rw [hlen] at hi; omega rw [List.getElem_take, List.getElem_finRange] at eq rw [← eq]; exact hin have hbe := hb b hblt simp only [MixedGeo.cells10, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] at hcq obtain ⟨r, ⟨r1, r2⟩, e⟩ := hcq have hge : 10 ≤ MixedGeo.endTick b := by have : ∀ k : MixedGeo.Bank, 60 ≤ MixedGeo.endTick k := by decide +kernel have := this b; omega exact ⟨r, by omega, e⟩ private theorem bankHoles_cells (n : Nat) (bound : Nat) (hb : ∀ b : MixedGeo.Bank, b.val < n → MixedGeo.endTick b ≤ bound) : ∀ q ∈ bankHoles n, ∃ r, 50 ≤ r ∧ r < bound ∧ q = base (1028 + r) := by intro q hq simp only [bankHoles, List.mem_flatMap, List.mem_cons, List.not_mem_nil, or_false] at hq obtain ⟨b, hbt, e⟩ := hq have hblt : b.val < n := by obtain ⟨i, hi, eq⟩ := List.mem_iff_getElem.mp hbt have hlen : ((List.finRange 22).take n).length = min n 22 := by simp have hin : i < n := by rw [hlen] at hi; omega rw [List.getElem_take, List.getElem_finRange] at eq rw [← eq]; exact hin have hbe := hb b hblt have hge : 60 ≤ MixedGeo.endTick b := by have : ∀ k : MixedGeo.Bank, 60 ≤ MixedGeo.endTick k := by decide +kernel exact this b rcases e with rfl | rfl | rfl | rfl · exact ⟨MixedGeo.endTick b - 8, by omega, by omega, rfl⟩ · exact ⟨MixedGeo.endTick b - 6, by omega, by omega, rfl⟩ · exact ⟨MixedGeo.endTick b - 3, by omega, by omega, rfl⟩ · exact ⟨MixedGeo.endTick b - 1, by omega, by omega, rfl⟩ private theorem groupProg_cells (d : Bool) (gs : List Nat) (bound : Nat) (hg : ∀ i ∈ gs, 40 + 5 * i + 5 ≤ bound) : ∀ q ∈ wires (groupProg d gs), ∃ r, r < bound ∧ (q = base r ∨ q = base (1028 + r)) := by induction gs with | nil => intro q h; simp [groupProg, StockGroupsW.batch, wires] at h | cons i gs ih => intro q h change q ∈ wires (Rolling1588.encodeAt base d (40 + 5 * i) ++ groupProg d gs) at h rw [wires_append, Finset.mem_union] at h rcases h with h | h · obtain ⟨r, r1, r2, e⟩ := OrdinaryChainW.encode_cells d (40 + 5 * i) q h have hi := hg i List.mem_cons_self exact ⟨r, by omega, e⟩ · exact ih (fun j hj => hg j (List.mem_cons_of_mem _ hj)) q h /-- Generic ordinary-chain extension step of arbitrary tick length `len`, adding bank `b` (or none) and plain groups `newGs`. -/ private theorem extend_step (d : Bool) (t len : Nat) (h45 : 45 ≤ t) (hlim : t + len ≤ 512) (mask addedMask : List Wire) (oldGs newGs : List Nat) (raw initial out : State) (old : Except mask raw (run (groupProg d oldGs) [] (run (span 45 (t - 45)) [] initial))) (step : Except addedMask out (run (groupProg d newGs) [] (run (span t len) [] raw))) (hmask : ∀ q ∈ mask, ∃ r, r + 2 ≤ t ∧ (q = base r ∨ q = base (1028 + r))) (hprog : ∀ q ∈ wires (groupProg d oldGs), ∃ r, r + 2 ≤ t ∧ (q = base r ∨ q = base (1028 + r))) (havoid : ∀ q ∈ mask, q ∉ wires (groupProg d newGs)) : Except (mask ++ addedMask) out (run (groupProg d (oldGs ++ newGs)) [] (run (span 45 (t + len - 45)) [] initial)) := by have h := extend t len hlim mask addedMask (groupProg d oldGs) (groupProg d newGs) raw (run (span 45 (t - 45)) [] initial) out old step (fun q hq => by obtain ⟨r, hr, e⟩ := hmask q hq; exact ⟨r, hr, e⟩) (fun q hq => by obtain ⟨r, hr, e⟩ := hprog q hq; exact ⟨r, hr, e⟩) havoid rw [groupProg_append] have hsp : run (span 45 (t + len - 45)) [] initial = run (span t len) [] (run (span 45 (t - 45)) [] initial) := by rw [show t + len - 45 = (t - 45) + len by omega, spanAppend 45 (t - 45) len, show 45 + (t - 45) = t by omega, run_append, run_take, List.drop_nil] rw [hsp] exact h private theorem carry20_holes (s prevLen : Nat) (hprev1 : 1 ≤ prevLen) (hprev : prevLen ≤ s) (hs : s + 19 ≤ 511) (holes : List Wire) (hcells : ∀ q ∈ holes, ∃ r, r + prevLen < s ∧ q = base (1028 + r)) (raw history : State) (clear : ∀ q ∈ holes, raw.basis q = false) : ∀ q ∈ holes, (WideReference20.endRaw s prevLen 20 raw history).basis q = false := by intro q hq obtain ⟨r, hr, rfl⟩ := hcells q hq have hoff : base (1028 + r) ∉ WideReference20.oldSites s prevLen := by intro hit obtain ⟨r', r1, r2, e | e⟩ := WideReference20.old_cell hit <;> simp only [base, Wire] at e <;> omega rw [WideReference20.endRaw_outside (by omega) raw history _ hoff, run_preserves_outside (span s 20) [] raw _ (pastOffSpan s 20 _ (by omega) ⟨r, by omega, Or.inr rfl⟩)] exact clear _ hq /-! ### Section 2: Ordinary Step for 20-Tick Blocks & Re-Entry `j20` -/ private theorem packW_eq_local (s t : Nat) (hs : s ≤ 511) (ht1 : t ≠ 5) (ht2 : History5.packDue t = true) (d : Bool) : MixedWindow.packW d s t = Rolling1588.codeEncodeAt d (hist20 s (t - 5)) := by have h1 : Rolling1588.packAtTick d t = Rolling1588.encodeAt base d (t - 5) := by simp only [Rolling1588.packAtTick, Rolling1588.Integer.packFirst, if_neg ht1, History5.packAfter, ht2, ↓reduceIte]; rfl rw [MixedWindow.packW, h1, Rolling1588.encodeAt, Rolling1588.codeEncodeAt, Rolling1588.codeEncodeAt, renameProgram_comp] apply renameProgram_congr_support intro q hq have lt : q < 10 := Finset.mem_range.mp ((Rolling1588.code_support d).1 ▸ hq) simp only [Function.comp, MeasuredCodec5.label, dif_pos lt, hist20] attribute [local irreducible] Rolling1588.packAtTick Rolling1588.unpackAtTick measurementCount private theorem hist20_inj_local (s t : Nat) (hs : s ≤ 511) (ht : t + 5 ≤ 1028) : Function.Injective (hist20 s t) := by intro a b eq have inv := OB5.sig_invol s hs have e := congrArg (OB5.sig s) eq simp only [hist20, inv, History5.historyMap, History5.historyId, base] at e have ha := a.isLt; have hb := b.isLt apply Fin.ext split at e <;> split at e <;> simp only [Wire] at * <;> omega private theorem hist20_geom : ∀ j : Fin 9, ∀ t : Nat, ((j.val = 0 ∧ t = 150) ∨ (1 ≤ j.val ∧ (t = start20 j - 20 ∨ t = start20 j - 15))) → ∀ i : Fin 10, OB5.sig (start20 j - 1) (hist20 (start20 j) t i) = History5.historyMap base t i ∧ OB5.sig (start20 j + 19) (hist20 (start20 j) t i) = History5.historyMap base t i ∧ oldRange (start20 j + 1) (windowNet20 j (hist20 (start20 j) t i)) ∧ hist20 (start20 j) t i ∉ EnterJ20.pending j ∧ hist20 (start20 j) t i ≠ EnterJ20.flagN j ∧ hist20 (start20 j) t i ≠ EnterJ20.flagF j ∧ hist20 (start20 j) t i ≠ EnterJ20.flagU j ∧ hist20 (start20 j) t i ∉ RailPair.sites (EnterJ20.upperPairs j) ∧ hist20 (start20 j) t i ∉ prevRawPortsList20 j ∧ hist20 (start20 j) t i ∉ EnterJ20.ports j ∧ (windowNet20 j (hist20 (start20 j) t i) = start20 j + 15 ∨ ¬(windowNet20 j (hist20 (start20 j) t i) = start20 j + 1044 ∨ start20 j + 16 ≤ windowNet20 j (hist20 (start20 j) t i) ∧ windowNet20 j (hist20 (start20 j) t i) ≤ start20 j + sbP20 (start20 j) + 39 ∨ 786 ≤ windowNet20 j (hist20 (start20 j) t i) ∧ windowNet20 j (hist20 (start20 j) t i) ≤ sbP20 (start20 j) + 808 ∨ 1556 ≤ windowNet20 j (hist20 (start20 j) t i) ∧ windowNet20 j (hist20 (start20 j) t i) ≤ sbP20 (start20 j) + 1576)) := by intro j t ht i have hj := j.isLt have hcheck : ∀ (r : Fin 9) (k : Fin 10), let ts : List Nat := if r.val = 0 then [150] else [start20 r - 20, start20 r - 15] ts.all (fun u => decide ( OB5.sig (start20 r - 1) (hist20 (start20 r) u k) = History5.historyMap base u k ∧ OB5.sig (start20 r + 19) (hist20 (start20 r) u k) = History5.historyMap base u k ∧ oldRange (start20 r + 1) (windowNet20 r (hist20 (start20 r) u k)) ∧ hist20 (start20 r) u k ∉ EnterJ20.pending r ∧ hist20 (start20 r) u k ≠ EnterJ20.flagN r ∧ hist20 (start20 r) u k ≠ EnterJ20.flagF r ∧ hist20 (start20 r) u k ≠ EnterJ20.flagU r ∧ hist20 (start20 r) u k ∉ RailPair.sites (EnterJ20.upperPairs r) ∧ hist20 (start20 r) u k ∉ prevRawHead20 r ∧ hist20 (start20 r) u k ∉ EnterJ20.ports r ∧ (hist20 (start20 r) u k < 1556 ∨ 1700 ≤ hist20 (start20 r) u k) ∧ (windowNet20 r (hist20 (start20 r) u k) = start20 r + 15 ∨ ¬(windowNet20 r (hist20 (start20 r) u k) = start20 r + 1044 ∨ start20 r + 16 ≤ windowNet20 r (hist20 (start20 r) u k) ∧ windowNet20 r (hist20 (start20 r) u k) ≤ start20 r + sbP20 (start20 r) + 39 ∨ 786 ≤ windowNet20 r (hist20 (start20 r) u k) ∧ windowNet20 r (hist20 (start20 r) u k) ≤ sbP20 (start20 r) + 808 ∨ 1556 ≤ windowNet20 r (hist20 (start20 r) u k) ∧ windowNet20 r (hist20 (start20 r) u k) ≤ sbP20 (start20 r) + 1576)))) = true := by decide +kernel have hm : t ∈ (if j.val = 0 then [150] else [start20 j - 20, start20 j - 15]) := by rcases ht with ⟨h0, rfl⟩ | ⟨h1, rfl | rfl⟩ · simp [h0] · simp [show j.val ≠ 0 by omega] · simp [show j.val ≠ 0 by omega] have hp := of_decide_eq_true (List.all_eq_true.mp (hcheck j i) t hm) refine ⟨hp.1, hp.2.1, hp.2.2.1, hp.2.2.2.1, hp.2.2.2.2.1, hp.2.2.2.2.2.1, hp.2.2.2.2.2.2.1, hp.2.2.2.2.2.2.2.1, ?_, hp.2.2.2.2.2.2.2.2.2.1, hp.2.2.2.2.2.2.2.2.2.2.2⟩ rw [prevRaw_split, List.mem_append] rintro (h | h) · exact hp.2.2.2.2.2.2.2.2.1 h · have sb : 1556 ≤ (hist20 (start20 j) t i : Nat) ∧ (hist20 (start20 j) t i : Nat) < 1700 := by unfold prevScratch20 at h; split_ifs at h with h0 · obtain ⟨v, hv, eq⟩ := List.mem_map.mp h; rw [List.mem_range] at hv rw [← eq]; unfold archScratch150; split_ifs <;> (unfold Wire; omega) · obtain ⟨v, hv, eq⟩ := List.mem_map.mp h; rw [List.mem_range] at hv rw [← eq]; unfold archScratch20; dsimp only; split_ifs <;> (unfold Wire; omega) have hnb := hp.2.2.2.2.2.2.2.2.2.2.1; simp only [Wire] at *; omega def groups20 (j : Fin 9) : List Nat := if j.val = 0 then [22] else [(start20 j - 20 - 40) / 5, (start20 j - 15 - 40) / 5] attribute [local irreducible] SkywalkNat.step Shadow.far nextWindow20 window20 withArchive20 body20 in private theorem ordinary20_step (j : Fin 9) (d : Bool) (x : Nat) (good : Bounds x p) (raw s : State) (g sg pg ps : Bool) (m : List Bool) (pre : At20 j d x p raw s g sg pg ps) : Except (MixedGeo.cells10 (start20 j - 10)) (WideReference20.endRaw (start20 j) (prevLen20 j) 20 raw (run (nextWindow20 j d) m s)) (run (groupProg d (groups20 j)) [] (run (span (start20 j) 20) [] raw)) := by have hj := j.isLt have hs_le : start20 j + 19 ≤ 511 := by unfold start20; omega have nums := actualNumbers20 j x p good have hist := WideReference20.pulled_history20 j pre.domain have inp := readInput (start20 j) x p raw g sg pre.input let preS := run (enterP20 j) m s let tape := m.drop (measurementCount (enterP20 j)) let st1 := run (routed20 j 0 1) tape preS let t1 := tape.drop (measurementCount (routed20 j 0 1)) let T := Shadow.reduced (sbP20 (start20 j)) 20 (unsigned (start20 j) x p) let Z := encode g sg T.u T.v have to' : T.v % 2 = 1 := shadow_odd20 (sbP20 (start20 j)) (unsigned (start20 j) x p) nums.small.1 nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum g sg _ _ (by omega) have ready := EnterJ20.ready_pending_at j raw s (unsigned (start20 j) x p) g sg m nums.small.1 pre.cut inp hist have runEq : run (nextWindow20 j d) m s = run (body20 j (withArchive20 j d)) tape preS := by simp only [nextWindow20, window20, run_append, run_take, preS, tape] have hIn (t : Nat) (ht : (j.val = 0 ∧ t = 150) ∨ (1 ≤ j.val ∧ (t = start20 j - 20 ∨ t = start20 j - 15))) (i : Fin 10) : st1.basis (hist20 (start20 j) t i) = raw.basis (History5.historyMap base t i) := by have g' := hist20_geom j t ht i have h1 := first_preserves20 j Z parity preS tape ready.2.1 (hist20 (start20 j) t i) (firstFree20 j g'.2.2.2.2.2.2.2.2.2.2) have h2 := run_preserves_outside (enterP20 j) m s (hist20 (start20 j) t i) (EnterJ20.notWire j g'.2.2.2.2.2.2.2.2.2.1) have h3 := pre.cut.unchanged _ g'.2.2.2.2.1 g'.2.2.2.2.2.1 g'.2.2.2.2.2.2.1 g'.2.2.2.2.2.2.2.1 rw [h1, h2] have e : s.basis (hist20 (start20 j) t i) = (eraseSites (EnterJ20.pending j) s).basis (hist20 (start20 j) t i) := by simp [eraseSites, g'.2.2.2.1] rw [e, h3]; change raw.basis (OB5.sig (start20 j - 1) _) = _; rw [g'.1] have hPast (t : Nat) (ht1 : t + 7 ≤ start20 j) (i : Fin 10) : raw.basis (History5.historyMap base t i) = (run (span (start20 j) 20) [] raw).basis (History5.historyMap base t i) := by have hsp : History5.historyMap base t i ∉ wires (span (start20 j) 20) := by apply pastOffSpan (start20 j) 20 _ (by omega) refine ⟨t + i.val / 2, by have := i.isLt; omega, ?_⟩ unfold History5.historyMap History5.historyId; split_ifs · left; rfl · right; congr 1; omega exact (run_preserves_outside _ _ _ _ hsp).symm have cellMap (t : Nat) (q : Wire) (hr : ∃ r, t ≤ r ∧ r ≤ t + 4 ∧ (q = base r ∨ q = base (1028 + r))) : ∃ i : Fin 10, q = History5.historyMap base t i := by obtain ⟨r, r1, r2, rfl | rfl⟩ := hr · refine ⟨⟨2 * (r - t), by omega⟩, ?_⟩ simp only [History5.historyMap, History5.historyId, Fin.val_mk]; rw [if_pos (by omega)]; congr 1; omega · refine ⟨⟨2 * (r - t) + 1, by omega⟩, ?_⟩ simp only [History5.historyMap, History5.historyId, Fin.val_mk]; rw [if_neg (by omega)]; congr 1; omega intro q hnot by_cases hold : q ∈ WideReference20.oldSites (start20 j) (prevLen20 j) · rw [WideReference20.endRaw_inside hs_le _ _ q hold, show start20 j + 20 - 1 = start20 j + 19 by omega] obtain ⟨r, r1, r2, er⟩ := WideReference20.old_cell hold have hpl_le : prevLen20 j ≤ start20 j := by unfold prevLen20 start20; split_ifs <;> omega have hr_lt : r < start20 j - 10 := by by_contra hge apply hnot simp only [MixedGeo.cells10, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] exact ⟨r, ⟨by omega, by omega⟩, by rcases er with e | e; exact Or.inl e; exact Or.inr (by simp only [base, Wire] at e ⊢; omega)⟩ have hr_base : q = base r ∨ q = base (1028 + r) := by rcases er with e | e; exact Or.inl e; exact Or.inr (by simp only [base, Wire] at e ⊢; omega) by_cases h0 : j.val = 0 · have hs0 : start20 j = 165 := by simp [start20, h0] have hpl0 : prevLen20 j = 15 := by simp [prevLen20, h0] rw [hs0, hpl0] at r1 rw [hs0] at hr_lt obtain ⟨i, hi⟩ := cellMap 150 q ⟨r, by omega, by omega, hr_base⟩ have g' := hist20_geom j 150 (Or.inl ⟨h0, rfl⟩) i have hsig : OB5.sig (start20 j + 19) q = hist20 (start20 j) 150 i := by rw [hi, ← g'.2.1, OB5.sig_invol (start20 j + 19) hs_le] rw [hsig, runEq, body20, run_append, run_take, run_append, run_take, route20_outside j 1 19 (by decide) _ (old_clear20 (by decide) g'.2.2.1), withArchive20, run_append, run_take, run_preserves_outside (archLoad20 j d) _ _ _ (fun h => g'.2.2.2.2.2.2.2.2.1 (List.mem_toFinset.mp (prevArch_load_cover j d h)))] have hp0 : packProg20 j d = Rolling1588.codeEncodeAt d (hist20 (start20 j) 150) := by unfold packProg20; rw [if_pos h0, ← hs0] exact packW_eq_local (start20 j) 155 (by omega) (by decide) (by decide) d have hg0 : groupProg d (groups20 j) = Rolling1588.encodeAt base d 150 := by unfold groups20; rw [if_pos h0, groupProg_singleton] rw [hp0, hg0, hi] exact ArchiveOrdinaryFive.stock_relocated d (hist20 (start20 j) 150) (History5.historyMap base 150) (hist20_inj_local (start20 j) 150 (by omega) (by decide)) (History5.historyMap_injective base base_pool_nodup 150 (by decide)) st1 (run (span (start20 j) 20) [] raw) _ [] (fun k => (hIn 150 (Or.inl ⟨h0, rfl⟩) k).trans (hPast 150 (by omega) k)) i · have hpl : prevLen20 j = 20 := by simp [prevLen20, h0] have hs_rng : 185 ≤ start20 j ∧ start20 j ≤ 325 := by unfold start20; omega rw [hpl] at r1 have hdue1 : History5.packDue (start20 j - 15) = true := by simp only [History5.packDue, start20, decide_eq_true_eq]; omega have hdue2 : History5.packDue (start20 j - 10) = true := by simp only [History5.packDue, start20, decide_eq_true_eq]; omega have he1 := packW_eq_local (start20 j) (start20 j - 15) (by omega) (by unfold start20; omega) hdue1 d have he2 := packW_eq_local (start20 j) (start20 j - 10) (by omega) (by unfold start20; omega) hdue2 d rw [show start20 j - 15 - 5 = start20 j - 20 by omega] at he1 rw [show start20 j - 10 - 5 = start20 j - 15 by omega] at he2 have hg_eq : groupProg d (groups20 j) = Rolling1588.encodeAt base d (start20 j - 20) ++ Rolling1588.encodeAt base d (start20 j - 15) := by unfold groups20; rw [if_neg h0] change groupProg d ([(start20 j - 20 - 40) / 5] ++ [(start20 j - 15 - 40) / 5]) = _ rw [groupProg_append, groupProg_singleton, groupProg_singleton] congr 1 <;> (congr 1; unfold start20; omega) have hdisjH : ∀ a b : Fin 10, hist20 (start20 j) (start20 j - 20) a ≠ hist20 (start20 j) (start20 j - 15) b := by intro a b eq have e := congrArg (OB5.sig (start20 j)) eq simp only [hist20, OB5.sig_invol (start20 j) (by omega), History5.historyMap, History5.historyId, base] at e have := a.isLt; have := b.isLt; split at e <;> split at e <;> simp only [start20, Wire] at * <;> omega have hdisjP : Disjoint (wires (Rolling1588.encodeAt base d (start20 j - 20))) (wires (Rolling1588.encodeAt base d (start20 j - 15))) := by rw [Finset.disjoint_left]; intro w hw1 hw2 obtain ⟨a, a1, a2, ea⟩ := OrdinaryChainW.encode_cells d (start20 j - 20) w hw1 obtain ⟨b, b1, b2, eb⟩ := OrdinaryChainW.encode_cells d (start20 j - 15) w hw2 rcases ea with rfl | rfl <;> rcases eb with eb | eb <;> simp only [base, Wire] at eb <;> omega by_cases hr1 : r < start20 j - 15 · obtain ⟨i, hi⟩ := cellMap (start20 j - 20) q ⟨r, by omega, by omega, hr_base⟩ have g' := hist20_geom j (start20 j - 20) (Or.inr ⟨by omega, Or.inl rfl⟩) i have hsig : OB5.sig (start20 j + 19) q = hist20 (start20 j) (start20 j - 20) i := by rw [hi, ← g'.2.1, OB5.sig_invol (start20 j + 19) hs_le] have hoff2 : hist20 (start20 j) (start20 j - 20) i ∉ wires (MixedWindow.packW d (start20 j) (start20 j - 10)) := by rw [he2, Rolling1588.codeEncodeAt, renameProgram_support, (Rolling1588.code_support d).1] intro hm; obtain ⟨w, hw, eq⟩ := Finset.mem_image.mp hm; have lt := Finset.mem_range.mp hw simp only [MeasuredCodec5.label, dif_pos lt] at eq; exact hdisjH i ⟨w, lt⟩ eq.symm have hoffR : q ∉ wires (Rolling1588.encodeAt base d (start20 j - 15)) := by intro hm; obtain ⟨b, b1, b2, eb⟩ := OrdinaryChainW.encode_cells d (start20 j - 15) q hm rcases hr_base with rfl | rfl <;> rcases eb with eb | eb <;> simp only [base, Wire] at eb <;> omega rw [hsig, runEq, body20, run_append, run_take, run_append, run_take, route20_outside j 1 19 (by decide) _ (old_clear20 (by decide) g'.2.2.1), withArchive20, run_append, run_take, run_preserves_outside (archLoad20 j d) _ _ _ (fun h => g'.2.2.2.2.2.2.2.2.1 (List.mem_toFinset.mp (prevArch_load_cover j d h))), packProg20, if_neg h0, run_append, run_take, run_preserves_outside _ _ _ _ hoff2, he1, hg_eq, run_append, run_take, List.drop_nil, run_preserves_outside _ _ _ _ hoffR, hi] exact ArchiveOrdinaryFive.stock_relocated d _ _ (hist20_inj_local _ _ (by omega) (by unfold start20; omega)) (History5.historyMap_injective base base_pool_nodup _ (by unfold start20; omega)) st1 (run (span (start20 j) 20) [] raw) _ [] (fun k => (hIn _ (Or.inr ⟨by omega, Or.inl rfl⟩) k).trans (hPast _ (by omega) k)) i · obtain ⟨i, hi⟩ := cellMap (start20 j - 15) q ⟨r, by omega, by omega, hr_base⟩ have g' := hist20_geom j (start20 j - 15) (Or.inr ⟨by omega, Or.inr rfl⟩) i have hsig : OB5.sig (start20 j + 19) q = hist20 (start20 j) (start20 j - 15) i := by rw [hi, ← g'.2.1, OB5.sig_invol (start20 j + 19) hs_le] have hoff1 (k : Fin 10) : hist20 (start20 j) (start20 j - 15) k ∉ wires (MixedWindow.packW d (start20 j) (start20 j - 15)) := by rw [he1, Rolling1588.codeEncodeAt, renameProgram_support, (Rolling1588.code_support d).1] intro hm; obtain ⟨w, hw, eq⟩ := Finset.mem_image.mp hm; have lt := Finset.mem_range.mp hw simp only [MeasuredCodec5.label, dif_pos lt] at eq; exact hdisjH ⟨w, lt⟩ k eq have hoffR (k : Fin 10) : History5.historyMap base (start20 j - 15) k ∉ wires (Rolling1588.encodeAt base d (start20 j - 20)) := by intro hm; obtain ⟨a, a1, a2, ea⟩ := OrdinaryChainW.encode_cells d (start20 j - 20) _ hm have := k.isLt; unfold History5.historyMap History5.historyId at ea split_ifs at ea <;> rcases ea with ea | ea <;> simp only [base, Wire] at ea <;> omega rw [hsig, runEq, body20, run_append, run_take, run_append, run_take, route20_outside j 1 19 (by decide) _ (old_clear20 (by decide) g'.2.2.1), withArchive20, run_append, run_take, run_preserves_outside (archLoad20 j d) _ _ _ (fun h => g'.2.2.2.2.2.2.2.2.1 (List.mem_toFinset.mp (prevArch_load_cover j d h))), packProg20, if_neg h0, run_append, run_take, he2, hg_eq, run_append, run_take, List.drop_nil, hi] exact ArchiveOrdinaryFive.stock_relocated d _ _ (hist20_inj_local _ _ (by omega) (by unfold start20; omega)) (History5.historyMap_injective base base_pool_nodup _ (by unfold start20; omega)) _ _ _ [] (fun k => (run_preserves_outside _ _ _ _ (hoff1 k)).trans ((hIn _ (Or.inr ⟨by omega, Or.inr rfl⟩) k).trans ((hPast _ (by omega) k).trans (run_preserves_outside _ _ _ _ (hoffR k)).symm))) i · rw [WideReference20.endRaw_outside hs_le _ _ q hold] symm; apply run_preserves_outside intro used apply hold have hcells : ∃ r, start20 j - prevLen20 j ≤ r ∧ r < start20 j - 10 ∧ (q = base r ∨ q = base (1028 + r)) := by unfold groups20 at used; split_ifs at used with h0 · rw [groupProg_singleton] at used obtain ⟨r, r1, r2, e⟩ := OrdinaryChainW.encode_cells d 150 q used have hs0 : start20 j = 165 := by simp [start20, h0] have hpl0 : prevLen20 j = 15 := by simp [prevLen20, h0] exact ⟨r, by omega, by omega, e⟩ · have hpl : prevLen20 j = 20 := by simp [prevLen20, h0] change q ∈ wires (groupProg d ([(start20 j - 20 - 40) / 5] ++ [(start20 j - 15 - 40) / 5])) at used rw [groupProg_append, wires_append, Finset.mem_union, groupProg_singleton, groupProg_singleton] at used rcases used with u | u · obtain ⟨r, r1, r2, e⟩ := OrdinaryChainW.encode_cells d _ q u exact ⟨r, by unfold start20 at *; omega, by unfold start20 at *; omega, e⟩ · obtain ⟨r, r1, r2, e⟩ := OrdinaryChainW.encode_cells d _ q u exact ⟨r, by unfold start20 at *; omega, by unfold start20 at *; omega, e⟩ obtain ⟨r, r1, r2, e⟩ := hcells simp only [WideReference20.oldSites, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] exact ⟨r, ⟨by omega, by omega⟩, e⟩ attribute [local irreducible] SkywalkNat.step Shadow.far nextWindow20 window20 withArchive20 body20 in private theorem holes20_step (j : Fin 9) (d : Bool) (x : Nat) (good : Bounds x p) (raw s : State) (g sg pg ps : Bool) (m : List Bool) (pre : At20 j d x p raw s g sg pg ps) (r : Nat) (hr : r = start20 j - 8 ∨ r = start20 j - 6 ∨ r = start20 j - 3 ∨ r = start20 j - 1) : (WideReference20.endRaw (start20 j) (prevLen20 j) 20 raw (run (nextWindow20 j d) m s)).basis (base (1028 + r)) = false := by have hj := j.isLt have hs_le : start20 j + 19 ≤ 511 := by unfold start20; omega have nums := actualNumbers20 j x p good have hist := WideReference20.pulled_history20 j pre.domain have inp := readInput (start20 j) x p raw g sg pre.input let T := Shadow.reduced (sbP20 (start20 j)) 20 (unsigned (start20 j) x p) let Z := encode g sg T.u T.v have to' : T.v % 2 = 1 := shadow_odd20 (sbP20 (start20 j)) (unsigned (start20 j) x p) nums.small.1 nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum g sg _ _ (by omega) have ready := EnterJ20.ready_pending_at j raw s (unsigned (start20 j) x p) g sg m nums.small.1 pre.cut inp hist have scr := scratch_raw_clean20 j d raw s m x p good pre.domain _ _ _ Z parity ready.2.1 pre.cut have prevOdd : (unsigned (prevTick20 j) x p).v % 2 = 1 := by unfold prevTick20; split_ifs with h0 · exact (LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good).odd · exact (actualNumbers20 (prev20 j) x p good).odd have prevSm : PrevSmall20 j (unsigned (prevTick20 j) x p) := by unfold PrevSmall20 prevTick20; split_ifs with h0 · exact (LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good).farSmall · exact (actualNumbers20 (prev20 j) x p good).small.1 have cl := cleared_holes20 j d raw s m (unsigned (start20 j) x p) g sg nums.odd nums.small.1 pre.cut inp hist scr (unsigned (prevTick20 j) x p) pg ps (prevCross20 j x p) prevOdd prevSm pre.facts have hmem : base (1028 + r) ∈ WideReference20.oldSites (start20 j) (prevLen20 j) := by have hpl : 15 ≤ prevLen20 j := by unfold prevLen20; split_ifs <;> decide simp only [WideReference20.oldSites, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] exact ⟨r, ⟨by rcases hr with rfl | rfl | rfl | rfl <;> omega, by rcases hr with rfl | rfl | rfl | rfl <;> omega⟩, Or.inr rfl⟩ rw [WideReference20.endRaw_inside hs_le _ _ _ hmem, show start20 j + 20 - 1 = start20 j + 19 by omega] have hsig : ∀ k : Fin 9, ∀ δ ∈ [8, 6, 3, 1], OB5.sig (start20 k + 19) (base (1028 + (start20 k - δ))) = OB5.sig (start20 k) (base (1028 + (start20 k - δ))) := by decide +kernel have h4 : ∀ k : Fin 9, ∀ δ ∈ [8, 6, 3, 1], OB5.sig (start20 k) (base (1028 + (start20 k - δ))) ∈ fourHoles20 k := by decide +kernel rcases hr with rfl | rfl | rfl | rfl · rw [hsig j 8 (by decide)]; exact cl _ (h4 j 8 (by decide)) · rw [hsig j 6 (by decide)]; exact cl _ (h4 j 6 (by decide)) · rw [hsig j 3 (by decide)]; exact cl _ (h4 j 3 (by decide)) · rw [hsig j 1 (by decide)]; exact cl _ (h4 j 1 (by decide)) private theorem ordinary345_step (d : Bool) (x : Nat) (good : Bounds x p) (raw s : State) (g sg pg ps : Bool) (m : List Bool) (pre : At345 d x p raw s g sg pg ps) : Except (MixedGeo.cells10 335) (WideReference.endRaw 345 (rawPack325 d raw) (run (nextWindow345 d) m s)) (run (groupProg d [57, 58]) [] (run (span 345 15) [] raw)) := by have nums := LeaveJ7.Admission.actualNumbers MixedWindow.j20 (by decide) (by decide) x p good have hist := WideReference.pulled_history MixedWindow.j20 rfl pre.domain have inp := readInput 345 x p raw g sg pre.input let T := Shadow.reduced (Shadow7.sbP 345) 15 (unsigned 345 x p) let Z := encode g sg T.u T.v have to' : T.v % 2 = 1 := shadow_odd_shadow7 (Shadow7.sbP 345) (unsigned 345 x p) nums.farSmall nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum g sg _ _ (by omega) have ready := EnterJ7.ready_pending_at MixedWindow.j20 raw s (unsigned 345 x p) g sg m nums.farSmall pre.cut inp hist have hp := pack345_hist_vals d x p good raw s m pre.domain _ _ _ pre.cut Z parity ready.2.1 have hgp : groupProg d [57, 58] = Rolling1588.encodeAt base d 325 ++ Rolling1588.encodeAt base d 330 := by change groupProg d ([57] ++ [58]) = _ rw [groupProg_append, groupProg_singleton, groupProg_singleton] have hrun : run (groupProg d [57, 58]) [] (run (span 345 15) [] raw) = run (Rolling1588.encodeAt base d 330) [] (run (span 345 15) [] (rawPack325 d raw)) := by rw [hgp, run_append, run_take, List.drop_nil, rawPack325_span_comm]; rfl rw [hrun] intro q hnot by_cases hold : q ∈ WideReference.oldSites 345 · rw [WideReference.endRaw_inside_gen 345 (by decide) _ _ q hold] obtain ⟨r, r1, r2, er⟩ := WideReference.old_cell hold have hs345 : oldStart 345 = 330 ∧ oldCount 345 = 15 := by decide rw [hs345.1] at r1 r2; rw [hs345.2] at r2 have hr_lt : r < 335 := by by_contra hge; apply hnot simp only [MixedGeo.cells10, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] exact ⟨r, ⟨by omega, by omega⟩, by rcases er with e | e; exact Or.inl e; exact Or.inr (by simp only [base, Wire] at e ⊢; omega)⟩ have hi : ∃ i : Fin 10, q = plain330 i := by rcases er with rfl | rfl · refine ⟨⟨2 * (r - 330), by omega⟩, ?_⟩ simp only [plain330, History5.historyMap, History5.historyId, base, Wire, Fin.val_mk]; rw [if_pos (by omega)]; omega · refine ⟨⟨2 * (r - 330) + 1, by omega⟩, ?_⟩ simp only [plain330, History5.historyMap, History5.historyId, base, Wire, Fin.val_mk]; rw [if_neg (by omega)]; omega obtain ⟨i, rfl⟩ := hi have hsig : OB5.sig 359 (plain330 i) = histB345 i := by have h : ∀ k : Fin 10, OB5.sig 359 (plain330 k) = histB345 k := by decide +kernel exact h i rw [show (345 : Nat) + 14 = 359 from rfl, hsig] exact hp.2 i · rw [WideReference.endRaw_outside_gen 345 (by decide) _ _ q hold] symm; apply run_preserves_outside intro used; apply hold obtain ⟨r, r1, r2, e⟩ := OrdinaryChainW.encode_cells d 330 q used have hs345 : oldStart 345 = 330 ∧ oldCount 345 = 15 := by decide simp only [WideReference.oldSites, hs345.1, hs345.2, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] exact ⟨r, ⟨by omega, by omega⟩, e⟩ private theorem holes345_step (d : Bool) (x : Nat) (good : Bounds x p) (raw s : State) (g sg pg ps : Bool) (m : List Bool) (pre : At345 d x p raw s g sg pg ps) (r : Nat) (hr : r = 337 ∨ r = 339 ∨ r = 342 ∨ r = 344) : (WideReference.endRaw 345 (rawPack325 d raw) (run (nextWindow345 d) m s)).basis (base (1028 + r)) = false := by have inp := readInput 345 x p raw g sg pre.input have cl := cleared_holes345 d x p good raw s m pre.domain g sg pre.cut inp pg ps _ pre.facts have hmem : base (1028 + r) ∈ WideReference.oldSites 345 := by have hs345 : oldStart 345 = 330 ∧ oldCount 345 = 15 := by decide simp only [WideReference.oldSites, hs345.1, hs345.2, List.mem_flatMap, List.mem_range'_1, List.mem_cons, List.not_mem_nil, or_false] exact ⟨r, ⟨by rcases hr with rfl | rfl | rfl | rfl <;> omega, by rcases hr with rfl | rfl | rfl | rfl <;> omega⟩, Or.inr rfl⟩ rw [WideReference.endRaw_inside_gen 345 (by decide) _ _ _ hmem, show (345 : Nat) + 14 = 359 from rfl] have h4 : ∀ v ∈ [337, 339, 342, 344], OB5.sig 359 (base (1028 + v)) ∈ fourHoles345 := by decide +kernel exact cl _ (h4 r (by rcases hr with rfl | rfl | rfl | rfl <;> decide)) /-! ### Section 3: End-to-End Mixed Ordinary Chain (`wiresMixed`) -/ attribute [local irreducible] WideReference.endRaw WideReference20.endRaw private def Ord15 (j : Fin 26) (n : Nat) (gs : List Nat) (d : Bool) (x : Nat) (initial s : State) : Prop := ∃ (raw : State) (g sg pg ps : Bool), AtJ j d x p raw s g sg pg ps ∧ Except (bankMask n) raw (run (groupProg d gs) [] (run (span 45 (start j - 45)) [] initial)) ∧ ∀ q ∈ bankHoles n, raw.basis q = false private def Ord20 (j : Fin 9) (n : Nat) (gs : List Nat) (d : Bool) (x : Nat) (initial s : State) : Prop := ∃ (raw : State) (g sg pg ps : Bool), At20 j d x p raw s g sg pg ps ∧ Except (bankMask n) raw (run (groupProg d gs) [] (run (span 45 (start20 j - 45)) [] initial)) ∧ ∀ q ∈ bankHoles n, raw.basis q = false private def Ord345 (n : Nat) (gs : List Nat) (d : Bool) (x : Nat) (initial s : State) : Prop := ∃ (raw : State) (g sg pg ps : Bool), At345 d x p raw s g sg pg ps ∧ Except (bankMask n) raw (run (groupProg d gs) [] (run (span 45 300) [] initial)) ∧ ∀ q ∈ bankHoles n, raw.basis q = false private theorem ord_prefix (d : Bool) (x : Nat) (good : Bounds x p) (initial : State) (m : List Bool) (stage : Rolling1588.Integer.Stage base d x p 45 initial.basis) : let ch1 := ([Shadow7.portalP 45, Shadow7.enterP MixedWindow.j0, Shadow7.routed MixedWindow.j0 0 1, MixedWindow.packW d 45 45, Shadow7.routed MixedWindow.j0 1 14, CRTBarrel.leave MixedWindow.j0]).flatten let ch2 := (MixedWindow.prefixPairs.flatMap fun p => MixedWindow.block15F d p.1 p.2).flatten Ord15 MixedWindow.j7 6 [0, 1, 4, 7, 10, 13, 16] d x initial (run (ch1 ++ ch2) m (pullState (OB5.sig 44) initial)) := by have beg := OrdinaryChainG.beginG WindowParams.first ⟨1, by decide⟩ (by decide) (by decide) rfl (OrdinaryChainG.first_ship StockWindowW7.leaves22.first) (OrdinaryChainG.firstOrdinary_ship OrdinaryChainG.firstOrdinary) d x good initial m stage let js : List (Fin 26) := [⟨1, by decide⟩, ⟨2, by decide⟩, ⟨3, by decide⟩, ⟨4, by decide⟩, ⟨5, by decide⟩, ⟨6, by decide⟩] have hconsec : Consec WindowParams.first js := ⟨rfl, rfl, rfl, rfl, rfl, rfl, trivial⟩ have ch := OrdinaryChainG.chainG WindowParams.first rfl 1 24 (by decide) (by decide) (by decide) StockWindowW7.leaves22.endpoint StockWindowW7.leaves22.scratch d x good initial WindowParams.first js hconsec (by intro k hk; simp only [js, List.mem_cons, List.not_mem_nil, or_false] at hk; rcases hk with rfl | rfl | rfl | rfl | rfl | rfl <;> decide) ⟨1, by decide⟩ MixedWindow.j7 rfl rfl _ (m.drop (measurementCount ((Shadow7.portalP 45 ++ NativeFirstJ7.enteredWindow WindowParams.first d) ++ CRTBarrel.leave WindowParams.first))) beg have heq1 : ([Shadow7.portalP 45, Shadow7.enterP MixedWindow.j0, Shadow7.routed MixedWindow.j0 0 1, MixedWindow.packW d 45 45, Shadow7.routed MixedWindow.j0 1 14, CRTBarrel.leave MixedWindow.j0]).flatten = (Shadow7.portalP 45 ++ NativeFirstJ7.enteredWindow WindowParams.first d) ++ CRTBarrel.leave WindowParams.first := by have := OrdinaryChainG.first_eqF d WindowParams.first simpa only [firstF, CRTBarrel.params, Shadow7.params, ofParts, MixedWindow.packW, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] using this have heq2 : (MixedWindow.prefixPairs.flatMap fun p => MixedWindow.block15F d p.1 p.2).flatten = (chainF CRTBarrel.params d WindowParams.first js).flatten := by simp only [MixedWindow.prefixPairs, MixedWindow.block15F, MixedWindow.packW, js, chainF, nextF, WindowParams.first, CRTBarrel.params, Shadow7.params, ofParts, List.flatMap_cons, List.flatMap_nil, List.flatten_cons, List.flatten_nil, List.flatten_append, List.append_nil, List.append_assoc] dsimp only rw [run_append, run_take, heq1, heq2] obtain ⟨raw, g, sg, pg, ps, atJ, hist, zeros⟩ := ch have hm : OrdinaryChainW.mask 45 7 = bankMask 6 := by decide +kernel have hp : OrdinaryChainW.progW 45 d 7 = groupProg d [0, 1, 4, 7, 10, 13, 16] := by have := OrdinaryChainG.progW_plain 45 (by decide) d 6 simpa only [groupProg, show StockWindowGeo.plain 6 = [0, 1, 4, 7, 10, 13, 16] by decide +kernel] using this have hh : StockWindowGeo.holes 45 6 = bankHoles 6 := by decide +kernel rw [show start WindowParams.first = 45 from rfl, show MixedWindow.j7.val - WindowParams.first.val = 7 from rfl, show 15 * 7 = start MixedWindow.j7 - 45 from rfl, hm, hp] at hist rw [show start WindowParams.first = 45 from rfl, show MixedWindow.j7.val - WindowParams.first.val - 1 = 6 from rfl, hh] at zeros exact ⟨raw, g, sg, pg, ps, atJ, hist, zeros⟩ private theorem ord_150To20 (d : Bool) (x : Nat) (good : Bounds x p) (initial s : State) (m : List Bool) (h : Ord15 MixedWindow.j7 6 [0, 1, 4, 7, 10, 13, 16] d x initial s) : let ch3 := ([Shadow7.enterP MixedWindow.j7, Shadow7.routed MixedWindow.j7 0 1, MixedWindow.packW d 150 140, Shadow7.archiveLoadP MixedWindow.j6 d, Shadow7.routed MixedWindow.j7 1 14, leave150To20Red]).flatten Ord20 ⟨0, by decide⟩ 7 [0, 1, 4, 7, 10, 13, 16, 19] d x initial (run ch3 m s) := by have hfl : ([Shadow7.enterP MixedWindow.j7, Shadow7.routed MixedWindow.j7 0 1, MixedWindow.packW d 150 140, Shadow7.archiveLoadP MixedWindow.j6 d, Shadow7.routed MixedWindow.j7 1 14, leave150To20Red]).flatten = NativeJ7.nextWindow MixedWindow.j7 d ++ leave150To20Red := by simp only [NativeJ7.nextWindow, NativeJ7.window, Shadow7.body, NativeJ7.withArchive, NativeJ7.program, MixedWindow.packW, show NativeJ7.prev MixedWindow.j7 = MixedWindow.j6 from rfl, show start MixedWindow.j7 = 150 from rfl, show (150 : Nat) - 10 = 140 from rfl, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] dsimp only rw [hfl, run_append, run_take] obtain ⟨raw, g, sg, pg, ps, pre, old, zeros⟩ := h have hs150 : start MixedWindow.j7 = 150 := rfl have hdom150 : Domain 150 x p raw := hs150 ▸ pre.domain have hinp150 : InputAt 150 (signedAt 150 x p g sg) raw := hs150 ▸ pre.input have hcut150 := pre.cut rw [hs150] at hcut150 have nums := LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good have inp := readInput 150 x p raw g sg hinp150 have scr := StockWindowW7.leaves22.scratch MixedWindow.j7 (by decide) (by decide) d x p good raw s g sg pg ps m pre have nat := NativeJ7.from_domain_matched MixedWindow.j7 (by decide) (by decide) d x p good raw s m pre.domain g sg pre.cut (hs150.symm ▸ inp) scr pg ps _ pre.facts have hnextSmall20 : Shadow7.SmallIfFar 163 20 (SkywalkNat.step^[15] (unsigned 150 x p)) := by have hs165 : start20 ⟨0, by decide⟩ = 165 := rfl have hsb163 : sbP20 (start20 ⟨0, by decide⟩) = 163 := rfl have h1 := (actualNumbers20 ⟨0, by decide⟩ x p good).small.1 rw [hsb163, hs165] at h1 have he165 : SkywalkNat.step^[15] (unsigned 150 x p) = unsigned 165 x p := by show SkywalkNat.step^[15] (SkywalkNat.step^[150] (SkywalkNat.init x p)) = SkywalkNat.step^[165] (SkywalkNat.init x p) rw [show (165 : Nat) = 150 + 15 by decide, Nat.add_comm, Function.iterate_add_apply] rw [he165]; exact h1 have hred150 := leave150To20Red_pair (run (NativeJ7.nextWindow MixedWindow.j7 d) m s) (unsigned 150 x p) g sg nat.1 hnextSmall20 rw [hred150.1] have ep := endpoint150To20 d x p good raw s m (m.drop (measurementCount (NativeJ7.nextWindow MixedWindow.j7 d))) hdom150 g sg hcut150 inp scr pg ps _ pre.facts have carried := stepInput_gen_shadow7 150 (Shadow7.sbP 150) x p (by decide) (by decide) good raw (run (NativeJ7.nextWindow MixedWindow.j7 d) m s) g sg hdom150 hinp150 (hs150 ▸ nums.farSmall) have canon := unique_input hinp150 (fixed_input 150 x p (by decide) good raw hdom150) have step := OrdinaryChainG.ordinaryG WindowParams.first rfl MixedWindow.j7 (by decide) (by decide) d x good raw s g sg pg ps m pre rw [hs150] at step have hbm : bankMask 7 = bankMask 6 ++ OrdinaryJ.newBank MixedWindow.j7 := by rw [bankMask_succ ⟨6, by decide⟩] have hnb : MixedGeo.cells10 (MixedGeo.endTick ⟨6, by decide⟩ - 10) = OrdinaryJ.newBank MixedWindow.j7 := by decide +kernel rw [hnb] have h165 : (150 : Nat) + 15 = start20 ⟨0, by decide⟩ := rfl have hpt0 : (150 : Nat) = prevTick20 ⟨0, by decide⟩ := rfl have hend6 : ∀ b : MixedGeo.Bank, b.val < 6 → MixedGeo.endTick b ≤ 135 := by decide +kernel refine ⟨WideReference.endRaw 150 raw (run (NativeJ7.nextWindow MixedWindow.j7 d) m s), (LeaveJ7.Admission.flags (unsigned 150 x p) g sg).1, (LeaveJ7.Admission.flags (unsigned 150 x p) g sg).2, g, sg, ⟨h165 ▸ carried.1, by rw [← h165, flags15_eq]; exact carried.2, by simpa only [← h165] using ep.1, by simpa only [PrevPast20, prevTick20, prevCross20, ↓reduceIte] using ep.2.1, hpt0 ▸ canon⟩, ?_, ?_⟩ · rw [hbm, ← h165] rw [hs150] at old have h19 : [0, 1, 4, 7, 10, 13, 16, 19] = [0, 1, 4, 7, 10, 13, 16] ++ [19] := rfl rw [h19] refine extend_step d 150 15 (by decide) (by decide) (bankMask 6) (OrdinaryJ.newBank MixedWindow.j7) [0, 1, 4, 7, 10, 13, 16] [19] raw initial _ old (by rw [groupProg_singleton, show (40 : Nat) + 5 * 19 = 150 - 15 from rfl]; exact step) ?_ ?_ ?_ · intro q hq obtain ⟨r, hr, e⟩ := bankMask_cells 6 135 hend6 q hq exact ⟨r, by omega, e⟩ · intro q hq obtain ⟨r, hr, e⟩ := groupProg_cells d [0, 1, 4, 7, 10, 13, 16] 135 (by decide +kernel) q hq exact ⟨r, by omega, e⟩ · intro q hq used rw [groupProg_singleton] at used obtain ⟨r, hr, e⟩ := bankMask_cells 6 135 hend6 q hq obtain ⟨r', r1, r2, e'⟩ := OrdinaryChainW.encode_cells d 135 q used rcases e with rfl | rfl <;> rcases e' with e' | e' <;> simp only [base, Wire] at e' <;> omega · rw [bankHoles_succ ⟨6, by decide⟩] intro q hq rcases List.mem_append.mp hq with hq | hq · apply OrdinaryChainW.carry 150 (by decide) (bankHoles 6) ?_ ?_ raw _ zeros q hq · intro w hw hit obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells 6 135 hend6 w hw obtain ⟨r', r1, r2, e'⟩ := WideReference.old_cell hit have hs150 : oldStart 150 = 135 ∧ oldCount 150 = 15 := by decide rw [hs150.1] at r1 r2; rw [hs150.2] at r2 rcases e' with e' | e' <;> simp only [base, Wire] at e' <;> omega · intro w hw obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells 6 135 hend6 w hw right; simp only [base, Wire]; omega · simp only [show MixedGeo.endTick ⟨6, by decide⟩ = 150 by decide +kernel, List.mem_cons, List.not_mem_nil, or_false] at hq have hG := fun r hr => hs150 ▸ OrdinaryChainG.holesG WindowParams.first rfl StockWindowW7.leaves22.scratch MixedWindow.j7 (by decide) (by decide) (by decide) d x good raw s g sg pg ps m pre r hr rcases hq with rfl | rfl | rfl | rfl · exact hG (150 - 8) (Or.inl rfl) · exact hG (150 - 6) (Or.inr (Or.inl rfl)) · exact hG (150 - 3) (Or.inr (Or.inr (Or.inl rfl))) · exact hG (150 - 1) (Or.inr (Or.inr (Or.inr rfl))) private theorem endTick20_prev_ord : ∀ (r : Fin 9) (b : MixedGeo.Bank), b.val < 7 + r.val → MixedGeo.endTick b ≤ start20 r - prevLen20 r := by decide +kernel private theorem endTick20_cur_ord : ∀ r : Fin 9, MixedGeo.endTick ⟨7 + r.val, by have := r.isLt; omega⟩ = start20 r := by decide +kernel private theorem endTick15_prev_ord : ∀ (r : Fin 26), 21 ≤ r.val → r.val ≤ 24 → ∀ b' : MixedGeo.Bank, b'.val < r.val - 4 → MixedGeo.endTick b' ≤ start r - 15 := by decide +kernel private theorem endTick15_cur_ord : ∀ (r : Fin 26), 21 ≤ r.val → r.val ≤ 24 → MixedGeo.endTick ⟨r.val - 4, by have := r.isLt; omega⟩ = start r := by decide +kernel private theorem ord_20_next (j k : Fin 9) (hk : k.val = j.val + 1) (gs : List Nat) (d : Bool) (x : Nat) (good : Bounds x p) (hgs : ∀ i ∈ gs, 40 + 5 * i + 5 ≤ start20 j - prevLen20 j) (initial s : State) (m : List Bool) (h : Ord20 j (7 + j.val) gs d x initial s) : Ord20 k (7 + k.val) (gs ++ groups20 j) d x initial (run (MixedWindow.block20F d j).flatten m s) := by have hj := j.isLt have hfl : (MixedWindow.block20F d j).flatten = nextWindow20 j d ++ leaveP20Red j := by unfold MixedWindow.block20F nextWindow20 window20 body20 withArchive20 packProg20 archLoad20 prev20 by_cases h0 : j.val = 0 <;> simp only [h0, ↓reduceDIte, ↓reduceIte, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] rw [hfl, run_append, run_take] obtain ⟨raw, g, sg, pg, ps, pre, old, zeros⟩ := h have nums := actualNumbers20 j x p good have hist := WideReference20.pulled_history20 j pre.domain have inp := readInput (start20 j) x p raw g sg pre.input let T := Shadow.reduced (sbP20 (start20 j)) 20 (unsigned (start20 j) x p) let Z := encode g sg T.u T.v have to' : T.v % 2 = 1 := shadow_odd20 (sbP20 (start20 j)) (unsigned (start20 j) x p) nums.small.1 nums.odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum g sg _ _ (by omega) have ready := EnterJ20.ready_pending_at j raw s (unsigned (start20 j) x p) g sg m nums.small.1 pre.cut inp hist have scr := scratch_raw_clean20 j d raw s m x p good pre.domain _ _ _ Z parity ready.2.1 pre.cut have prevOdd : (unsigned (prevTick20 j) x p).v % 2 = 1 := by unfold prevTick20; split_ifs with h0 · exact (LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good).odd · exact (actualNumbers20 (prev20 j) x p good).odd have prevSm : PrevSmall20 j (unsigned (prevTick20 j) x p) := by unfold PrevSmall20 prevTick20; split_ifs with h0 · exact (LeaveJ7.Admission.actualNumbers MixedWindow.j7 (by decide) (by decide) x p good).farSmall · exact (actualNumbers20 (prev20 j) x p good).small.1 have adm := admitted20 j d x p good raw s m pre.domain g sg pre.cut inp scr (unsigned (prevTick20 j) x p) pg ps (prevCross20 j x p) prevOdd prevSm pre.facts have hred20 := leaveP20Red_pair j (run (nextWindow20 j d) m s) (unsigned (start20 j) x p) g sg adm.1 rw [hred20.1] have ep := endpoint20_next j k hk d x p good raw s m (m.drop (measurementCount (nextWindow20 j d))) pre.domain g sg pre.cut inp scr (unsigned (prevTick20 j) x p) pg ps (prevCross20 j x p) prevOdd prevSm pre.facts have hprev_le : prevLen20 j ≤ start20 j := by unfold prevLen20 start20; split_ifs <;> omega have carried := WideReference20.stepInput20 (start20 j) (prevLen20 j) (sbP20 (start20 j)) x p hprev_le (by unfold start20; omega) good raw (run (nextWindow20 j d) m s) g sg pre.domain pre.input nums.small.1 have canon := unique_input pre.input (fixed_input (start20 j) x p (by unfold start20; omega) good raw pre.domain) have hsk : start20 k = start20 j + 20 := by unfold start20; omega have hpk : prev20 k = j := Fin.ext (by simp only [prev20]; omega) have hend_prev : ∀ b : MixedGeo.Bank, b.val < 7 + j.val → MixedGeo.endTick b ≤ start20 j - prevLen20 j := endTick20_prev_ord j have hend_cur : MixedGeo.endTick ⟨7 + j.val, by omega⟩ = start20 j := endTick20_cur_ord j refine ⟨WideReference20.endRaw (start20 j) (prevLen20 j) 20 raw (run (nextWindow20 j d) m s), (flags20 (unsigned (start20 j) x p) g sg).1, (flags20 (unsigned (start20 j) x p) g sg).2, g, sg, ⟨hsk ▸ carried.1, by rw [flags20_eq]; exact hsk ▸ carried.2, ep.1, by simp only [PrevPast20, prevTick20, prevCross20, if_neg (show k.val ≠ 0 by omega), hpk]; exact ep.2, by simp only [prevTick20, if_neg (show k.val ≠ 0 by omega), hpk]; exact canon⟩, ?_, ?_⟩ · rw [hk, show 7 + (j.val + 1) = (7 + j.val) + 1 by omega, bankMask_succ ⟨7 + j.val, by omega⟩, hend_cur, hsk] refine extend_step d (start20 j) 20 (by unfold start20; omega) (by unfold start20; omega) (bankMask (7 + j.val)) (MixedGeo.cells10 (start20 j - 10)) gs (groups20 j) raw initial _ old (ordinary20_step j d x good raw s g sg pg ps m pre) ?_ ?_ ?_ · intro q hq; obtain ⟨r, hr, e⟩ := bankMask_cells (7 + j.val) (start20 j - prevLen20 j) hend_prev q hq have : 15 ≤ prevLen20 j := by unfold prevLen20; split_ifs <;> decide exact ⟨r, by omega, e⟩ · intro q hq; obtain ⟨r, hr, e⟩ := groupProg_cells d gs (start20 j - prevLen20 j) hgs q hq have : 15 ≤ prevLen20 j := by unfold prevLen20; split_ifs <;> decide exact ⟨r, by omega, e⟩ · intro q hq used obtain ⟨r, hr, e⟩ := bankMask_cells (7 + j.val) (start20 j - prevLen20 j) hend_prev q hq have hge : ∃ r', start20 j - prevLen20 j ≤ r' ∧ r' < 512 ∧ (q = base r' ∨ q = base (1028 + r')) := by unfold groups20 at used; split_ifs at used with h0 · rw [groupProg_singleton] at used; obtain ⟨r', r1, r2, e'⟩ := OrdinaryChainW.encode_cells d 150 q used have : start20 j - prevLen20 j = 150 := by simp [start20, prevLen20, h0] exact ⟨r', by omega, by omega, e'⟩ · change q ∈ wires (groupProg d ([(start20 j - 20 - 40) / 5] ++ [(start20 j - 15 - 40) / 5])) at used rw [groupProg_append, wires_append, Finset.mem_union, groupProg_singleton, groupProg_singleton] at used have : prevLen20 j = 20 := by simp [prevLen20, h0] rcases used with u | u · obtain ⟨r', r1, r2, e'⟩ := OrdinaryChainW.encode_cells d _ q u exact ⟨r', by unfold start20 at *; omega, by unfold start20 at *; omega, e'⟩ · obtain ⟨r', r1, r2, e'⟩ := OrdinaryChainW.encode_cells d _ q u exact ⟨r', by unfold start20 at *; omega, by unfold start20 at *; omega, e'⟩ obtain ⟨r', hr', hr2', e'⟩ := hge rcases e with rfl | rfl <;> rcases e' with e' | e' <;> simp only [base, Wire] at e' <;> omega · rw [hk, show 7 + (j.val + 1) = (7 + j.val) + 1 by omega, bankHoles_succ ⟨7 + j.val, by omega⟩, hend_cur] intro q hq rcases List.mem_append.mp hq with hq | hq · exact carry20_holes (start20 j) (prevLen20 j) (by unfold prevLen20; split_ifs <;> decide) hprev_le (by unfold start20; omega) (bankHoles (7 + j.val)) (fun w hw => by obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells (7 + j.val) (start20 j - prevLen20 j) hend_prev w hw; exact ⟨r, by omega, rfl⟩) raw _ zeros q hq · simp only [List.mem_cons, List.not_mem_nil, or_false] at hq rcases hq with rfl | rfl | rfl | rfl · exact holes20_step j d x good raw s g sg pg ps m pre _ (Or.inl rfl) · exact holes20_step j d x good raw s g sg pg ps m pre _ (Or.inr (Or.inl rfl)) · exact holes20_step j d x good raw s g sg pg ps m pre _ (Or.inr (Or.inr (Or.inl rfl))) · exact holes20_step j d x good raw s g sg pg ps m pre _ (Or.inr (Or.inr (Or.inr rfl))) private theorem ord_20_last (gs : List Nat) (d : Bool) (x : Nat) (good : Bounds x p) (hgs : ∀ i ∈ gs, 40 + 5 * i + 5 ≤ 305) (initial s : State) (m : List Bool) (h : Ord20 MixedWindow.k8 15 gs d x initial s) : Ord345 16 (gs ++ groups20 MixedWindow.k8) d x initial (run (MixedWindow.block20F d MixedWindow.k8).flatten m s) := by have hfl : (MixedWindow.block20F d MixedWindow.k8).flatten = nextWindow20 MixedWindow.k8 d ++ leaveP20Red MixedWindow.k8 := by unfold MixedWindow.block20F nextWindow20 window20 body20 withArchive20 packProg20 archLoad20 prev20 simp only [show MixedWindow.k8.val ≠ 0 by decide, ↓reduceDIte, ↓reduceIte, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] rw [hfl, run_append, run_take] obtain ⟨raw, g, sg, pg, ps, pre, old, zeros⟩ := h have hs325 : start20 MixedWindow.k8 = 325 := rfl have hdom325 : Domain 325 x p raw := hs325 ▸ pre.domain have hinp325 : InputAt 325 (signedAt 325 x p g sg) raw := hs325 ▸ pre.input have hcut325 := pre.cut rw [hs325] at hcut325 have nums := actualNumbers20 MixedWindow.k8 x p good have hnums_sm : Shadow7.SmallIfFar (sbP20 325) 20 (unsigned 325 x p) := hs325 ▸ nums.small.1 have hnums_odd : (unsigned 325 x p).v % 2 = 1 := hs325 ▸ nums.odd have hist := WideReference20.pulled_history20 MixedWindow.k8 pre.domain have inp := readInput 325 x p raw g sg hinp325 let T := Shadow.reduced (sbP20 325) 20 (unsigned 325 x p) let Z := encode g sg T.u T.v have to' : T.v % 2 = 1 := shadow_odd20 (sbP20 325) (unsigned 325 x p) hnums_sm hnums_odd have parity : (Z.a + Z.b) % 2 = 1 := encode_odd_sum g sg _ _ (by omega) have ready := EnterJ20.ready_pending_at MixedWindow.k8 raw s (unsigned (start20 MixedWindow.k8) x p) g sg m nums.small.1 pre.cut (hs325.symm ▸ inp) hist have scr := scratch_raw_clean20 MixedWindow.k8 d raw s m x p good pre.domain _ _ _ Z parity (by simpa only [hs325] using ready.2.1) pre.cut have hpt305 : prevTick20 MixedWindow.k8 = start20 (prev20 MixedWindow.k8) := rfl have prevOdd : (unsigned (prevTick20 MixedWindow.k8) x p).v % 2 = 1 := hpt305.symm ▸ (actualNumbers20 (prev20 MixedWindow.k8) x p good).odd have prevSm : PrevSmall20 MixedWindow.k8 (unsigned (prevTick20 MixedWindow.k8) x p) := hpt305.symm ▸ (actualNumbers20 (prev20 MixedWindow.k8) x p good).small.1 have adm := admitted20 MixedWindow.k8 d x p good raw s m pre.domain g sg pre.cut (hs325.symm ▸ inp) scr (unsigned (prevTick20 MixedWindow.k8) x p) pg ps (prevCross20 MixedWindow.k8 x p) prevOdd prevSm pre.facts have hred20 := leaveP20Red_pair MixedWindow.k8 (run (nextWindow20 MixedWindow.k8 d) m s) (unsigned (start20 MixedWindow.k8) x p) g sg adm.1 rw [hred20.1] have ep := endpoint20_reentry d x p good raw s m (m.drop (measurementCount (nextWindow20 MixedWindow.k8 d))) hdom325 g sg hcut325 inp scr (unsigned (prevTick20 MixedWindow.k8) x p) pg ps (prevCross20 MixedWindow.k8 x p) prevOdd prevSm pre.facts have carried := WideReference20.stepInput20 325 20 (sbP20 325) x p (by decide) (by decide) good raw (run (nextWindow20 MixedWindow.k8 d) m s) g sg hdom325 hinp325 hnums_sm have canon := unique_input hinp325 (fixed_input 325 x p (by decide) good raw hdom325) have hend_prev : ∀ b : MixedGeo.Bank, b.val < 15 → MixedGeo.endTick b ≤ 305 := by decide +kernel have h345 : (325 : Nat) + 20 = 345 := rfl refine ⟨WideReference20.endRaw 325 20 20 raw (run (nextWindow20 MixedWindow.k8 d) m s), (flags20 (unsigned 325 x p) g sg).1, (flags20 (unsigned 325 x p) g sg).2, g, sg, ⟨h345 ▸ carried.1, by rw [← h345, flags20_eq]; exact carried.2, ep.1, ep.2, canon⟩, ?_, ?_⟩ · rw [bankMask_succ ⟨15, by decide⟩, show MixedGeo.endTick ⟨15, by decide⟩ = 325 by decide, show (300 : Nat) = 325 + 20 - 45 from rfl] rw [hs325] at old have hstep := ordinary20_step MixedWindow.k8 d x good raw s g sg pg ps m pre rw [hs325, show prevLen20 MixedWindow.k8 = 20 from rfl] at hstep refine extend_step d 325 20 (by decide) (by decide) (bankMask 15) (MixedGeo.cells10 (325 - 10)) gs (groups20 MixedWindow.k8) raw initial _ old hstep ?_ ?_ ?_ · intro q hq; obtain ⟨r, hr, e⟩ := bankMask_cells 15 305 hend_prev q hq; exact ⟨r, by omega, e⟩ · intro q hq; obtain ⟨r, hr, e⟩ := groupProg_cells d gs 305 hgs q hq; exact ⟨r, by omega, e⟩ · intro q hq used obtain ⟨r, hr, e⟩ := bankMask_cells 15 305 hend_prev q hq have hge : ∃ r', 305 ≤ r' ∧ r' < 512 ∧ (q = base r' ∨ q = base (1028 + r')) := by rw [show groups20 MixedWindow.k8 = [53] ++ [54] by decide, groupProg_append, wires_append, Finset.mem_union, groupProg_singleton, groupProg_singleton] at used rcases used with u | u · obtain ⟨r', r1, r2, e'⟩ := OrdinaryChainW.encode_cells d _ q u; exact ⟨r', by omega, by omega, e'⟩ · obtain ⟨r', r1, r2, e'⟩ := OrdinaryChainW.encode_cells d _ q u; exact ⟨r', by omega, by omega, e'⟩ obtain ⟨r', hr', hr2', e'⟩ := hge rcases e with rfl | rfl <;> rcases e' with e' | e' <;> simp only [base, Wire] at e' <;> omega · rw [bankHoles_succ ⟨15, by decide⟩, show MixedGeo.endTick ⟨15, by decide⟩ = 325 by decide] intro q hq rcases List.mem_append.mp hq with hq | hq · exact carry20_holes 325 20 (by decide) (by decide) (by decide) (bankHoles 15) (fun w hw => by obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells 15 305 hend_prev w hw; exact ⟨r, by omega, rfl⟩) raw _ zeros q hq · simp only [List.mem_cons, List.not_mem_nil, or_false] at hq have hH := fun r hr => by have hh := holes20_step MixedWindow.k8 d x good raw s g sg pg ps m pre r hr rw [hs325, show prevLen20 MixedWindow.k8 = 20 from rfl] at hh exact hh rcases hq with rfl | rfl | rfl | rfl · exact hH (325 - 8) (Or.inl rfl) · exact hH (325 - 6) (Or.inr (Or.inl rfl)) · exact hH (325 - 3) (Or.inr (Or.inr (Or.inl rfl))) · exact hH (325 - 1) (Or.inr (Or.inr (Or.inr rfl))) private theorem ord_345 (gs : List Nat) (d : Bool) (x : Nat) (good : Bounds x p) (hgs : ∀ i ∈ gs, 40 + 5 * i + 5 ≤ 325) (initial s : State) (m : List Bool) (h : Ord345 16 gs d x initial s) : let ch5 := ([Shadow7.enterP MixedWindow.j20, Shadow7.routed MixedWindow.j20 0 1, MixedWindow.packW d 345 330, MixedWindow.packW d 345 335, archiveLoadP20 MixedWindow.k8 d, Shadow7.routed MixedWindow.j20 1 14, CRTBarrel.leave MixedWindow.j20]).flatten Ord15 ⟨21, by decide⟩ 17 (gs ++ [57, 58]) d x initial (run ch5 m s) := by have hfl : ([Shadow7.enterP MixedWindow.j20, Shadow7.routed MixedWindow.j20 0 1, MixedWindow.packW d 345 330, MixedWindow.packW d 345 335, archiveLoadP20 MixedWindow.k8 d, Shadow7.routed MixedWindow.j20 1 14, CRTBarrel.leave MixedWindow.j20]).flatten = nextWindow345 d ++ CRTBarrel.leave MixedWindow.j20 := by simp only [nextWindow345, window345, Shadow7.body, withArchive345, packProg345, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] dsimp only rw [hfl, run_append, run_take] obtain ⟨raw, g, sg, pg, ps, pre, old, zeros⟩ := h have nums := LeaveJ7.Admission.actualNumbers MixedWindow.j20 (by decide) (by decide) x p good have inp := readInput 345 x p raw g sg pre.input have ep := endpoint345 d x p good raw s m (m.drop (measurementCount (nextWindow345 d))) pre.domain g sg pre.cut inp pg ps _ pre.facts have domP := rawPack325_domain d x p raw pre.domain have inpP := rawPack325_input d raw _ pre.input have carried := stepInput_gen_shadow7 345 (Shadow7.sbP 345) x p (by decide) (by decide) good (rawPack325 d raw) (run (nextWindow345 d) m s) g sg domP inpP nums.farSmall have canon := unique_input pre.input (fixed_input 345 x p (by decide) good raw pre.domain) have hend_prev : ∀ b : MixedGeo.Bank, b.val < 16 → MixedGeo.endTick b ≤ 325 := by decide +kernel refine ⟨WideReference.endRaw 345 (rawPack325 d raw) (run (nextWindow345 d) m s), (LeaveJ7.Admission.flags (unsigned 345 x p) g sg).1, (LeaveJ7.Admission.flags (unsigned 345 x p) g sg).2, g, sg, ⟨carried.1, by rw [flags15_eq]; exact carried.2, ep.2.1, ep.2.2.1, canon⟩, ?_, ?_⟩ · rw [bankMask_succ ⟨16, by decide⟩, show MixedGeo.endTick ⟨16, by decide⟩ = 345 by decide, show start ⟨21, by decide⟩ = 345 + 15 from rfl] rw [show (300 : Nat) = 345 - 45 from rfl] at old refine extend_step d 345 15 (by decide) (by decide) (bankMask 16) (MixedGeo.cells10 (345 - 10)) gs [57, 58] raw initial _ old (ordinary345_step d x good raw s g sg pg ps m pre) ?_ ?_ ?_ · intro q hq; obtain ⟨r, hr, e⟩ := bankMask_cells 16 325 hend_prev q hq; exact ⟨r, by omega, e⟩ · intro q hq; obtain ⟨r, hr, e⟩ := groupProg_cells d gs 325 hgs q hq; exact ⟨r, by omega, e⟩ · intro q hq used obtain ⟨r, hr, e⟩ := bankMask_cells 16 325 hend_prev q hq change q ∈ wires (groupProg d ([57] ++ [58])) at used rw [groupProg_append, wires_append, Finset.mem_union, groupProg_singleton, groupProg_singleton] at used rcases used with u | u · obtain ⟨r', r1, r2, e'⟩ := OrdinaryChainW.encode_cells d _ q u rcases e with rfl | rfl <;> rcases e' with e' | e' <;> simp only [base, Wire] at e' <;> omega · obtain ⟨r', r1, r2, e'⟩ := OrdinaryChainW.encode_cells d _ q u rcases e with rfl | rfl <;> rcases e' with e' | e' <;> simp only [base, Wire] at e' <;> omega · rw [bankHoles_succ ⟨16, by decide⟩, show MixedGeo.endTick ⟨16, by decide⟩ = 345 by decide] intro q hq rcases List.mem_append.mp hq with hq | hq · apply OrdinaryChainW.carry 345 (by decide) (bankHoles 16) ?_ ?_ (rawPack325 d raw) _ ?_ q hq · intro w hw hit obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells 16 325 hend_prev w hw obtain ⟨r', r1, r2, e'⟩ := WideReference.old_cell hit have hs345 : oldStart 345 = 330 ∧ oldCount 345 = 15 := by decide rw [hs345.1] at r1 r2; rw [hs345.2] at r2 rcases e' with e' | e' <;> simp only [base, Wire] at e' <;> omega · intro w hw obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells 16 325 hend_prev w hw right; simp only [base, Wire]; omega · intro w hw obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells 16 325 hend_prev w hw have hout : (rawPack325 d raw).basis (base (1028 + r)) = raw.basis (base (1028 + r)) := by apply run_preserves_outside; intro used obtain ⟨r', r1, r2, e' | e'⟩ := OrdinaryChainW.encode_cells d 325 _ used <;> simp only [base, Wire] at e' <;> omega rw [hout]; exact zeros _ hw · simp only [List.mem_cons, List.not_mem_nil, or_false] at hq rcases hq with rfl | rfl | rfl | rfl · exact holes345_step d x good raw s g sg pg ps m pre (345 - 8) (Or.inl rfl) · exact holes345_step d x good raw s g sg pg ps m pre (345 - 6) (Or.inr (Or.inl rfl)) · exact holes345_step d x good raw s g sg pg ps m pre (345 - 3) (Or.inr (Or.inr (Or.inl rfl))) · exact holes345_step d x good raw s g sg pg ps m pre (345 - 1) (Or.inr (Or.inr (Or.inr rfl))) private theorem ord_15_suffix_step (i k k1 : Fin 26) (hk : k.val = i.val + 1) (hk1 : k1.val = k.val + 1) (h21 : 21 ≤ k.val) (h24 : k.val ≤ 24) (n : Nat) (hn : n = k.val - 4) (gs : List Nat) (d : Bool) (x : Nat) (good : Bounds x p) (hgs : ∀ g ∈ gs, 40 + 5 * g + 5 ≤ start k - 15) (initial s : State) (m : List Bool) (h : Ord15 k n gs d x initial s) : Ord15 k1 (n + 1) (gs ++ [(start k - 15 - 40) / 5]) d x initial (run (MixedWindow.block15F d i k).flatten m s) := by have pk : NativeJ7.prev k = i := Fin.ext (by simp only [NativeJ7.prev]; omega) have hfl : (MixedWindow.block15F d i k).flatten = NativeJ7.nextWindow k d ++ CRTBarrel.leave k := by rw [← pk] simp only [MixedWindow.block15F, MixedWindow.packW, NativeJ7.nextWindow, NativeJ7.window, Shadow7.body, NativeJ7.withArchive, NativeJ7.program, List.flatten_cons, List.flatten_nil, List.append_nil, List.append_assoc] rw [hfl, run_append, run_take] obtain ⟨raw, g, sg, pg, ps, pre, old, zeros⟩ := h have hwf : WindowParams.first.val = 0 := rfl have hfb : WideReference.firstBlock = 45 := rfl have hsk : start k = 45 + 15 * k.val := rfl rw [StockWindowW7.sameAt StockWindowW7.leaves22.scratch k (by omega) h24 d x p good raw s g sg pg ps m pre] obtain ⟨a, b, c, e, pre'⟩ := OrdinaryChainG.pinnedG 1 24 (by decide) (by decide) StockWindowW7.leaves22.endpoint StockWindowW7.leaves22.scratch k k1 hk1 (by omega) h24 d x good raw s g sg pg ps m pre have step := OrdinaryChainG.ordinaryG WindowParams.first rfl k (by omega) h24 d x good raw s g sg pg ps m pre have hsk1 : start k1 = start k + 15 := by simp only [start]; omega have hend_prev : ∀ b' : MixedGeo.Bank, b'.val < n → MixedGeo.endTick b' ≤ start k - 15 := fun b' hb' => endTick15_prev_ord k h21 h24 b' (by omega) have hend_cur : MixedGeo.endTick ⟨n, by omega⟩ = start k := by have := endTick15_cur_ord k h21 h24; simpa only [hn] using this have hgp_eq : groupProg d [(start k - 15 - 40) / 5] = Rolling1588.encodeAt base d (start k - 15) := by rw [groupProg_singleton]; congr 1; simp only [start]; omega refine ⟨WideReference.endRaw (start k) raw (run (NativeJ7.nextWindow k d) m s), a, b, c, e, pre', ?_, ?_⟩ · rw [bankMask_succ ⟨n, by omega⟩, hend_cur, hsk1] refine extend_step d (start k) 15 (by simp only [start]; omega) (by simp only [start]; omega) (bankMask n) (MixedGeo.cells10 (start k - 10)) gs [(start k - 15 - 40) / 5] raw initial _ old (by rw [hgp_eq]; exact step) ?_ ?_ ?_ · intro q hq; obtain ⟨r, hr, e'⟩ := bankMask_cells n (start k - 15) hend_prev q hq; exact ⟨r, by omega, e'⟩ · intro q hq; obtain ⟨r, hr, e'⟩ := groupProg_cells d gs (start k - 15) hgs q hq; exact ⟨r, by omega, e'⟩ · intro q hq used rw [hgp_eq] at used obtain ⟨r, hr, e'⟩ := bankMask_cells n (start k - 15) hend_prev q hq obtain ⟨r', r1, r2, e''⟩ := OrdinaryChainW.encode_cells d (start k - 15) q used rcases e' with rfl | rfl <;> rcases e'' with e'' | e'' <;> simp only [base, Wire] at e'' <;> omega · rw [bankHoles_succ ⟨n, by omega⟩, hend_cur] intro q hq rcases List.mem_append.mp hq with hq | hq · apply OrdinaryChainW.carry (start k) (by simp only [start]; omega) (bankHoles n) ?_ ?_ raw _ zeros q hq · intro w hw hit obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells n (start k - 15) hend_prev w hw obtain ⟨r', r1, r2, e'⟩ := WideReference.old_cell hit have hne : start k ≠ WideReference.firstBlock := by simp only [start, WideReference.firstBlock]; omega rw [oldStart_interior hne] at r1 r2; rw [oldCount_interior hne] at r2 rcases e' with e' | e' <;> simp only [base, Wire] at e' <;> omega · intro w hw obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells n (start k - 15) hend_prev w hw right; simp only [base, Wire]; omega · simp only [List.mem_cons, List.not_mem_nil, or_false] at hq rcases hq with rfl | rfl | rfl | rfl · exact OrdinaryChainG.holesG WindowParams.first rfl StockWindowW7.leaves22.scratch k (by omega) (by omega) h24 d x good raw s g sg pg ps m pre _ (Or.inl rfl) · exact OrdinaryChainG.holesG WindowParams.first rfl StockWindowW7.leaves22.scratch k (by omega) (by omega) h24 d x good raw s g sg pg ps m pre _ (Or.inr (Or.inl rfl)) · exact OrdinaryChainG.holesG WindowParams.first rfl StockWindowW7.leaves22.scratch k (by omega) (by omega) h24 d x good raw s g sg pg ps m pre _ (Or.inr (Or.inr (Or.inl rfl))) · exact OrdinaryChainG.holesG WindowParams.first rfl StockWindowW7.leaves22.scratch k (by omega) (by omega) h24 d x good raw s g sg pg ps m pre _ (Or.inr (Or.inr (Or.inr rfl))) private theorem mixed_plain_eq : ((((((((((((([0, 1, 4, 7, 10, 13, 16, 19] ++ groups20 ⟨0, by decide⟩) ++ groups20 ⟨1, by decide⟩) ++ groups20 ⟨2, by decide⟩) ++ groups20 ⟨3, by decide⟩) ++ groups20 ⟨4, by decide⟩) ++ groups20 ⟨5, by decide⟩) ++ groups20 ⟨6, by decide⟩) ++ groups20 ⟨7, by decide⟩) ++ groups20 ⟨8, by decide⟩) ++ [57, 58]) ++ [(start ⟨21, by decide⟩ - 15 - 40) / 5]) ++ [(start ⟨22, by decide⟩ - 15 - 40) / 5]) ++ [(start ⟨23, by decide⟩ - 15 - 40) / 5]) ++ [(start ⟨24, by decide⟩ - 15 - 40) / 5] ++ [73] = MixedGeo.plain := by decide +kernel private theorem bankHoles_22_eq : bankHoles 22 = MixedGeo.holes := by decide +kernel private theorem census_mixed (w : Wire) (hw : w ∈ bankMask 22) : w ∈ MixedGeo.holes ∨ OB5.sig 420 w ∈ MixedGeo.archives := by simp only [bankMask, List.take_of_length_le (by simp : (List.finRange 22).length ≤ 22), List.mem_flatMap, List.mem_finRange, true_and] at hw obtain ⟨b, hb⟩ := hw exact MixedGeo.cells_census b w hb /-- End-to-end ordinary-chain agreement of `MixedWindow.forwardMixed d` with `common d raw` off `MixedGeo.archives`. -/ theorem wiresMixed (d : Bool) (x : Nat) (good : Bounds x p) (raw : State) (m : List Bool) (stage : Rolling1588.Integer.Stage base d x p 45 raw.basis) : ∀ q ∉ MixedGeo.archives, (run (MixedWindow.forwardMixed d) m (pullState (OB5.sig 44) raw)).basis q = (common d raw).basis q := by let ch1 := ([Shadow7.portalP 45, Shadow7.enterP MixedWindow.j0, Shadow7.routed MixedWindow.j0 0 1, MixedWindow.packW d 45 45, Shadow7.routed MixedWindow.j0 1 14, CRTBarrel.leave MixedWindow.j0]).flatten let ch2 := (MixedWindow.prefixPairs.flatMap fun p => MixedWindow.block15F d p.1 p.2).flatten let ch3 := ([Shadow7.enterP MixedWindow.j7, Shadow7.routed MixedWindow.j7 0 1, MixedWindow.packW d 150 140, Shadow7.archiveLoadP MixedWindow.j6 d, Shadow7.routed MixedWindow.j7 1 14, leave150To20Red]).flatten let ch5 := ([Shadow7.enterP MixedWindow.j20, Shadow7.routed MixedWindow.j20 0 1, MixedWindow.packW d 345 330, MixedWindow.packW d 345 335, archiveLoadP20 MixedWindow.k8 d, Shadow7.routed MixedWindow.j20 1 14, CRTBarrel.leave MixedWindow.j20]).flatten let ch7 := (exitF CRTBarrel.params d 420).flatten let p0 := ch1 ++ ch2 let p1 := p0 ++ ch3 let p2 := p1 ++ (MixedWindow.block20F d ⟨0, by decide⟩).flatten let p3 := p2 ++ (MixedWindow.block20F d ⟨1, by decide⟩).flatten let p4 := p3 ++ (MixedWindow.block20F d ⟨2, by decide⟩).flatten let p5 := p4 ++ (MixedWindow.block20F d ⟨3, by decide⟩).flatten let p6 := p5 ++ (MixedWindow.block20F d ⟨4, by decide⟩).flatten let p7 := p6 ++ (MixedWindow.block20F d ⟨5, by decide⟩).flatten let p8 := p7 ++ (MixedWindow.block20F d ⟨6, by decide⟩).flatten let p9 := p8 ++ (MixedWindow.block20F d ⟨7, by decide⟩).flatten let p10 := p9 ++ (MixedWindow.block20F d ⟨8, by decide⟩).flatten let p11 := p10 ++ ch5 let p12 := p11 ++ (MixedWindow.block15F d ⟨20, by decide⟩ ⟨21, by decide⟩).flatten let p13 := p12 ++ (MixedWindow.block15F d ⟨21, by decide⟩ ⟨22, by decide⟩).flatten let p14 := p13 ++ (MixedWindow.block15F d ⟨22, by decide⟩ ⟨23, by decide⟩).flatten let p15 := p14 ++ (MixedWindow.block15F d ⟨23, by decide⟩ ⟨24, by decide⟩).flatten have hf : MixedWindow.forwardMixed d = p15 ++ ch7 := by have hfr : List.finRange 9 = [⟨0, by decide⟩, ⟨1, by decide⟩, ⟨2, by decide⟩, ⟨3, by decide⟩, ⟨4, by decide⟩, ⟨5, by decide⟩, ⟨6, by decide⟩, ⟨7, by decide⟩, ⟨8, by decide⟩] := by decide simp only [MixedWindow.forwardMixed, MixedWindow.forwardL, p15, p14, p13, p12, p11, p10, p9, p8, p7, p6, p5, p4, p3, p2, p1, p0, ch1, ch2, ch3, ch5, ch7, hfr, MixedWindow.suffixPairs, exitF, CRTBarrel.params, Shadow7.params, ofParts, MixedWindow.tickW, MixedWindow.packW, List.flatMap_cons, List.flatMap_nil, List.flatten_cons, List.flatten_nil, List.flatten_append, List.append_nil, List.append_assoc] let init := pullState (OB5.sig 44) raw let g1 : List Nat := [0, 1, 4, 7, 10, 13, 16, 19] let g2 := g1 ++ groups20 ⟨0, by decide⟩ let g3 := g2 ++ groups20 ⟨1, by decide⟩ let g4 := g3 ++ groups20 ⟨2, by decide⟩ let g5 := g4 ++ groups20 ⟨3, by decide⟩ let g6 := g5 ++ groups20 ⟨4, by decide⟩ let g7 := g6 ++ groups20 ⟨5, by decide⟩ let g8 := g7 ++ groups20 ⟨6, by decide⟩ let g9 := g8 ++ groups20 ⟨7, by decide⟩ let g10 := g9 ++ groups20 ⟨8, by decide⟩ let g11 := g10 ++ [57, 58] let g12 := g11 ++ [(start ⟨21, by decide⟩ - 15 - 40) / 5] let g13 := g12 ++ [(start ⟨22, by decide⟩ - 15 - 40) / 5] let g14 := g13 ++ [(start ⟨23, by decide⟩ - 15 - 40) / 5] let g15 := g14 ++ [(start ⟨24, by decide⟩ - 15 - 40) / 5] have o0 : Ord15 MixedWindow.j7 6 [0, 1, 4, 7, 10, 13, 16] d x raw (run p0 m init) := ord_prefix d x good raw m stage have o1 : Ord20 ⟨0, by decide⟩ 7 g1 d x raw (run p1 m init) := by rw [show p1 = p0 ++ ch3 from rfl, run_append, run_take]; exact ord_150To20 d x good raw _ _ o0 have o2 : Ord20 ⟨1, by decide⟩ 8 g2 d x raw (run p2 m init) := by rw [show p2 = p1 ++ (MixedWindow.block20F d ⟨0, by decide⟩).flatten from rfl, run_append, run_take] exact ord_20_next ⟨0, by decide⟩ ⟨1, by decide⟩ rfl g1 d x good (by decide +kernel) raw _ _ o1 have o3 : Ord20 ⟨2, by decide⟩ 9 g3 d x raw (run p3 m init) := by rw [show p3 = p2 ++ (MixedWindow.block20F d ⟨1, by decide⟩).flatten from rfl, run_append, run_take] exact ord_20_next ⟨1, by decide⟩ ⟨2, by decide⟩ rfl g2 d x good (by decide +kernel) raw _ _ o2 have o4 : Ord20 ⟨3, by decide⟩ 10 g4 d x raw (run p4 m init) := by rw [show p4 = p3 ++ (MixedWindow.block20F d ⟨2, by decide⟩).flatten from rfl, run_append, run_take] exact ord_20_next ⟨2, by decide⟩ ⟨3, by decide⟩ rfl g3 d x good (by decide +kernel) raw _ _ o3 have o5 : Ord20 ⟨4, by decide⟩ 11 g5 d x raw (run p5 m init) := by rw [show p5 = p4 ++ (MixedWindow.block20F d ⟨3, by decide⟩).flatten from rfl, run_append, run_take] exact ord_20_next ⟨3, by decide⟩ ⟨4, by decide⟩ rfl g4 d x good (by decide +kernel) raw _ _ o4 have o6 : Ord20 ⟨5, by decide⟩ 12 g6 d x raw (run p6 m init) := by rw [show p6 = p5 ++ (MixedWindow.block20F d ⟨4, by decide⟩).flatten from rfl, run_append, run_take] exact ord_20_next ⟨4, by decide⟩ ⟨5, by decide⟩ rfl g5 d x good (by decide +kernel) raw _ _ o5 have o7 : Ord20 ⟨6, by decide⟩ 13 g7 d x raw (run p7 m init) := by rw [show p7 = p6 ++ (MixedWindow.block20F d ⟨5, by decide⟩).flatten from rfl, run_append, run_take] exact ord_20_next ⟨5, by decide⟩ ⟨6, by decide⟩ rfl g6 d x good (by decide +kernel) raw _ _ o6 have o8 : Ord20 ⟨7, by decide⟩ 14 g8 d x raw (run p8 m init) := by rw [show p8 = p7 ++ (MixedWindow.block20F d ⟨6, by decide⟩).flatten from rfl, run_append, run_take] exact ord_20_next ⟨6, by decide⟩ ⟨7, by decide⟩ rfl g7 d x good (by decide +kernel) raw _ _ o7 have o9 : Ord20 ⟨8, by decide⟩ 15 g9 d x raw (run p9 m init) := by rw [show p9 = p8 ++ (MixedWindow.block20F d ⟨7, by decide⟩).flatten from rfl, run_append, run_take] exact ord_20_next ⟨7, by decide⟩ ⟨8, by decide⟩ rfl g8 d x good (by decide +kernel) raw _ _ o8 have o10 : Ord345 16 g10 d x raw (run p10 m init) := by rw [show p10 = p9 ++ (MixedWindow.block20F d ⟨8, by decide⟩).flatten from rfl, run_append, run_take] exact ord_20_last g9 d x good (by decide +kernel) raw _ _ o9 have o11 : Ord15 ⟨21, by decide⟩ 17 g11 d x raw (run p11 m init) := by rw [show p11 = p10 ++ ch5 from rfl, run_append, run_take] exact ord_345 g10 d x good (by decide +kernel) raw _ _ o10 have o12 : Ord15 ⟨22, by decide⟩ 18 g12 d x raw (run p12 m init) := by rw [show p12 = p11 ++ (MixedWindow.block15F d ⟨20, by decide⟩ ⟨21, by decide⟩).flatten from rfl, run_append, run_take] exact ord_15_suffix_step ⟨20, by decide⟩ ⟨21, by decide⟩ ⟨22, by decide⟩ rfl rfl (by decide) (by decide) 17 rfl g11 d x good (by decide +kernel) raw _ _ o11 have o13 : Ord15 ⟨23, by decide⟩ 19 g13 d x raw (run p13 m init) := by rw [show p13 = p12 ++ (MixedWindow.block15F d ⟨21, by decide⟩ ⟨22, by decide⟩).flatten from rfl, run_append, run_take] exact ord_15_suffix_step ⟨21, by decide⟩ ⟨22, by decide⟩ ⟨23, by decide⟩ rfl rfl (by decide) (by decide) 18 rfl g12 d x good (by decide +kernel) raw _ _ o12 have o14 : Ord15 ⟨24, by decide⟩ 20 g14 d x raw (run p14 m init) := by rw [show p14 = p13 ++ (MixedWindow.block15F d ⟨22, by decide⟩ ⟨23, by decide⟩).flatten from rfl, run_append, run_take] exact ord_15_suffix_step ⟨22, by decide⟩ ⟨23, by decide⟩ ⟨24, by decide⟩ rfl rfl (by decide) (by decide) 19 rfl g13 d x good (by decide +kernel) raw _ _ o13 have o15 : Ord15 ⟨25, by decide⟩ 21 g15 d x raw (run p15 m init) := by rw [show p15 = p14 ++ (MixedWindow.block15F d ⟨23, by decide⟩ ⟨24, by decide⟩).flatten from rfl, run_append, run_take] exact ord_15_suffix_step ⟨23, by decide⟩ ⟨24, by decide⟩ ⟨25, by decide⟩ rfl rfl (by decide) (by decide) 20 rfl g14 d x good (by decide +kernel) raw _ _ o14 obtain ⟨rawF, gF, sgF, pgF, psF, preF, oldF, zerosF⟩ := o15 let s15 := run p15 m init let m15 := m.drop (measurementCount p15) rw [hf, run_append, run_take] change ∀ q ∉ MixedGeo.archives, (run ch7 m15 s15).basis q = (common d raw).basis q obtain ⟨direct, lastHoles⟩ := OrdinaryChainG.exit420 d x good rawF s15 gF sgF pgF psF m15 preF have hend21 : ∀ b' : MixedGeo.Bank, b'.val < 21 → MixedGeo.endTick b' ≤ 405 := by decide +kernel have all : Except (bankMask 22) (pullState (OB5.sig 420) (run ch7 m15 s15)) (run (ordinary d) [] (run (span 45 376) [] raw)) := by rw [bankMask_succ ⟨21, by decide⟩, show MixedGeo.endTick ⟨21, by decide⟩ = 420 by decide, ordinary, ← mixed_plain_eq, show (376 : Nat) = 420 + 1 - 45 from rfl] rw [show start ⟨25, by decide⟩ = 420 from rfl] at oldF refine extend_step d 420 1 (by decide) (by decide) (bankMask 21) (MixedGeo.cells10 (420 - 10)) _ [73] rawF raw _ oldF (by rw [groupProg_singleton, show (40 : Nat) + 5 * 73 = 420 - 15 from rfl] exact OrdinaryChainG.projectG 420 (by decide) rawF _ _ direct) ?_ ?_ ?_ · intro q hq; obtain ⟨r, hr, e⟩ := bankMask_cells 21 405 hend21 q hq; exact ⟨r, by omega, e⟩ · intro q hq; obtain ⟨r, hr, e⟩ := groupProg_cells d _ 405 (by decide +kernel) q hq; exact ⟨r, by omega, e⟩ · intro q hq used rw [groupProg_singleton] at used obtain ⟨r, hr, e⟩ := bankMask_cells 21 405 hend21 q hq obtain ⟨r', r1, r2, e'⟩ := OrdinaryChainW.encode_cells d 405 q used rcases e with rfl | rfl <;> rcases e' with e' | e' <;> simp only [base, Wire] at e' <;> omega have zeroH : ∀ w ∈ MixedGeo.holes, (run ch7 m15 s15).basis (OB5.sig 420 w) = false := by rw [← bankHoles_22_eq, bankHoles_succ ⟨21, by decide⟩, show MixedGeo.endTick ⟨21, by decide⟩ = 420 by decide] intro w hw rcases List.mem_append.mp hw with h | h · obtain ⟨r, _, hr, rfl⟩ := bankHoles_cells 21 405 hend21 w h exact OrdinaryChainG.old_hole_G 420 (by decide) d rawF _ r (by omega) direct (zerosF _ h) · simp only [List.mem_cons, List.not_mem_nil, or_false] at h rcases h with rfl | rfl | rfl | rfl · exact lastHoles (420 - 8) (Or.inl rfl) · exact lastHoles (420 - 6) (Or.inr (Or.inl rfl)) · exact lastHoles (420 - 3) (Or.inr (Or.inr (Or.inl rfl))) · exact lastHoles (420 - 1) (Or.inr (Or.inr (Or.inr rfl))) intro q away have inv : OB5.sig 420 (OB5.sig 420 q) = q := OB5.sig_invol 420 (by decide) q generalize ey : OB5.sig 420 q = y at inv have goal : (common d raw).basis q = (eraseSites MixedGeo.holes (run (ordinary d) [] (run (span 45 376) [] raw))).basis y := by rw [← ey]; rfl rw [goal] by_cases hole : y ∈ MixedGeo.holes · simp only [eraseSites, if_pos hole] have z := zeroH y hole; rw [inv] at z; exact z · have free : y ∉ bankMask 22 := fun hit => by rcases census_mixed y hit with h | h · exact hole h · rw [inv] at h; exact away h have val := all y free change (run ch7 m15 s15).basis (OB5.sig 420 y) = _ at val rw [inv] at val simpa only [eraseSites, if_neg hole] using val /-! ### Section 4: 22-Bank Stock Comparison API (`comparison`, `stored`, `Paired`, `binding`, `normalized`) -/ private theorem receipt_mixed (d : Bool) (x : Nat) (good : Bounds x p) (s : State) (dom : Domain 45 x p s) (i : Nat) (active : i ∈ MixedGeo.packed) (row : Nat) (lim : row < 63145) (truth : ArchiveStockRows.Chronology (MixedGeo.packet i) x p row) (j : Fin 10) : let raw := run (span 45 376) [] s (run (StockGroupsW.batch 45 d (StockGroupsW.all 25)) [] raw).basis (MixedGeo.slot i j) = (CodecBitSliceVerify.get (StairArchiveNativeRows.storage (StairArchiveNativeRows.native d (MixedGeo.high i))) j).testBit row := by have ⟨shape, lo', hi', _⟩ := MixedGeo.packed_chart active let raw := run (span 45 376) [] s have obs := StockArchiveTruthW.native_byte 45 376 x p (by decide) good s dom (MixedGeo.packet i) lo' (by omega) row lim truth d (MixedGeo.high i) [] have bit := obs.2 j have hlt : i < 76 := MixedGeo.packed_lt active have hslot : MixedGeo.slot i j = StockWindowGeo.slot 45 i j := rfl dsimp only rw [hslot, StockGroupsW.isolated 45 (by decide) d (StockGroupsW.all 25) (StockGroupsW.allNodup 25) (StockGroupsW.small_all 45 25 (by decide) (by decide)) raw i (StockGroupsW.inAll hlt) _ (Finset.mem_image.mpr ⟨j, Finset.mem_univ _, rfl⟩)] change (run (Rolling1588.codeEncodeAt d (History5.historyMap base (MixedGeo.gstart i))) [] raw).basis (History5.historyMap base (MixedGeo.gstart i) j) = _ rw [shape] exact bit theorem comparison (d : Bool) (x : Nat) (good : Bounds x p) (s a : State) (m : List Bool) (stage : Rolling1588.Integer.Stage base d x p 45 s.basis) (results : mixedFinal StockWindowChainP.ExitPorts420 d x p a) : MixedArchiveSuffix.Same (run (Rolling1588TickGap.forward d 45 376) m (pullState (OB5.sig 44) s)) (common d s) := by let raw := run (span 45 376) [] s have stock := StockDelayed.window d x good.nonzero good.small 45 376 (by decide) (by decide) s m stage change run (Rolling1588TickGap.forward d 45 376) m (pullState (OB5.sig 44) s) = pullState (OB5.sig 420) (run (StockDelayed.packs d 45 376) [] raw) at stock rw [stock, StockGroupsW.packs_bridge, StockGroupsW.stockEq d 45 25 (by decide) (by decide), common, ordinary] have hsmall_plain : ∀ i ∈ MixedGeo.plain, StockWindowGeo.gstart 45 i + 5 ≤ 512 := fun i hi => by have := MixedGeo.plain_lt hi; simp only [StockWindowGeo.gstart]; omega refine ⟨(StockBaselineW.phase_batch 45 d (StockGroupsW.all 25) (StockBaselineW.small512 45 25 (by decide) (by decide) _ (fun i hi => List.mem_range.mp hi)) raw).trans (StockBaselineW.phase_batch 45 d MixedGeo.plain hsmall_plain raw).symm, ?_⟩ intro q safe let y := OB5.sig 420 q change (run (StockGroupsW.batch 45 d (StockGroupsW.all 25)) [] raw).basis y = (if y ∈ MixedGeo.holes then false else (run (StockGroupsW.batch 45 d MixedGeo.plain) [] raw).basis y) have away : OB5.sig 420 y ∉ MixedGeo.archives := by simpa only [y, OB5.sig_invol 420 (by decide)] using safe by_cases old : ∃ i ∈ MixedGeo.packed, y ∈ StockGroupsW.ports 45 i · obtain ⟨i, used, inside⟩ := old obtain ⟨j, _, atSite⟩ := Finset.mem_image.mp inside rcases MixedGeo.sparse i used j with ⟨blank, hit⟩ | covered · have hslot : StockWindowGeo.slot 45 i j = MixedGeo.slot i j := rfl rw [← atSite, hslot, if_pos hit] obtain ⟨_, _, _, b, hb⟩ := MixedGeo.packed_chart used have dom := WideReference.initial 45 x p (by decide) d s stage have bit := receipt_mixed d x good s dom i used (mixedRow x p b) (results b).1 (by rw [hb]; exact mixedFinal_trace results b) j have cleared (k : Nat) (ok : k = 5 ∨ k = 9) : CodecBitSliceVerify.get (StairArchiveNativeRows.storage (StairArchiveNativeRows.native d (MixedGeo.high i))) k = 0 := by rcases ok with rfl | rfl <;> rfl exact bit.trans ((congrArg (fun n : Nat => n.testBit _) (cleared j (by rcases blank with rfl | rfl <;> decide))).trans (Nat.zero_testBit _)) · exact (away (atSite ▸ covered)).elim · have nh : y ∉ MixedGeo.holes := fun h => by obtain ⟨i, used, j, e⟩ := MixedGeo.hole_slot y h exact old ⟨i, used, Finset.mem_image.mpr ⟨j, Finset.mem_univ _, e.symm⟩⟩ rw [if_neg nh] have hsp_plain : ∀ i ∈ MixedGeo.plain, StockWindowGeo.gstart 45 i + 5 ≤ 1028 := fun i hi => by have := MixedGeo.plain_lt hi; simp only [StockWindowGeo.gstart]; omega by_cases saved : ∃ i ∈ MixedGeo.plain, y ∈ StockGroupsW.ports 45 i · obtain ⟨i, mem, h⟩ := saved exact (StockGroupsW.isolated 45 (by decide) d (StockGroupsW.all 25) (StockGroupsW.allNodup 25) (StockGroupsW.small_all 45 25 (by decide) (by decide)) raw i (StockGroupsW.inAll (MixedGeo.plain_lt mem)) y h).trans (StockGroupsW.isolated 45 (by decide) d MixedGeo.plain MixedGeo.plain_nodup hsp_plain raw i mem y h).symm · have off (i : Nat) (hi : i < 76) : y ∉ StockGroupsW.ports 45 i := fun h => by rcases MixedGeo.split_all i hi with m' | m' · exact saved ⟨i, m', h⟩ · exact old ⟨i, m', h⟩ exact (StockGroupsW.outside 45 d (StockGroupsW.all 25) raw y (fun i hi => off i (List.mem_range.mp hi))).trans (StockGroupsW.outside 45 d MixedGeo.plain raw y (fun i hi => off i (MixedGeo.plain_lt hi))).symm theorem stored (d : Bool) (x : Nat) (good : Bounds x p) (s : State) (m : List Bool) (stage : Rolling1588.Integer.Stage base d x p 45 s.basis) (b : MixedGeo.Bank) (row : Nat) (lim : row < 63145) (truth : ArchiveStockRows.Chronology (MixedGeo.bankTick b) x p row) : StockArchiveBanksW.nativeAt (MixedGeo.siteAt StockWindowChainP.ExitPorts420 b) d row (run (Rolling1588TickGap.forward d 45 376) m (pullState (OB5.sig 44) s)) := by intro j obtain ⟨addr, clock, used, hj⟩ := MixedGeo.chart b j have dom := WideReference.initial 45 x p (by decide) d s stage have bit := receipt_mixed d x good s dom (MixedGeo.groupOf b j) used row lim (by rw [clock]; exact truth) (MixedGeo.index j) rw [StockArchiveBanksW.stock_state 45 25 (by decide) (by decide) (by decide) d x good s m stage, StockArchiveBanksW.readback 420 (by decide) _ _ _ ((MixedGeo.site_eq StockWindowChainP.ExitPorts420 StockArchiveBanks.exitCells b j).trans addr)] have hbyte : CodecBitSliceVerify.get (StairArchiveNativeRows.storage (StairArchiveNativeRows.native d (MixedGeo.high (MixedGeo.groupOf b j)))) (MixedGeo.index j) = CodecBitSliceVerify.get (StairArchiveNativeCut.canonical d d) j := by rw [hj]; exact StockArchiveBanksW.byte d j exact bit.trans (congrArg (fun n : Nat => n.testBit row) hbyte) theorem common_phase (d : Bool) (x : Nat) (good : Bounds x p) (s : State) (stage : Rolling1588.Integer.Stage base d x p 45 s.basis) : (common d s).phase = s.phase := by have final := (MixedChain.strong d x good s [] stage).2.1 have same := comparison d x good s _ [] stage final exact same.1.symm.trans (StockBaseline.forward_phase d x good 45 376 (by decide) (by decide) s [] stage) theorem normalized (d : Bool) (x : Nat) (good : Bounds x p) (raw : State) (m : List Bool) (stage : Rolling1588.Integer.Stage base d x p 45 raw.basis) : MixedArchiveSuffix.Same (run (MixedWindow.forwardMixed d) m (pullState (OB5.sig 44) raw)) (common d raw) := ⟨(MixedChain.strong d x good raw m stage).1.trans (common_phase d x good raw stage).symm, wiresMixed d x good raw m stage⟩ end ECDSAAdd.Entrant.StairPacket.Shadow20.MixedOrd end -- ==== end Shadow7Wide20Ord ==== section namespace ECDSAAdd.Entrant.StairPacket.StockStrongChain open Arithmetic MappedCompressed IntegerPacket WideReference SkywalkRails Partial ArchivePortAction ArchiveStockRows open StockWindowTicket WindowFold WindowChain Secp256k1 StockCanonicalRow StockWindowW7 set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false attribute [local irreducible] run measurementCount key select WideReference.canonical theorem result (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) : let start0:=pullState (OB5.sig 44) raw let out:=run (Shadow20.MixedWindow.forwardMixedCut d) m start0 out.phase=raw.phase ∧ Shadow20.MixedChain.mixedFinal StockWindowChainP.ExitPorts420 d x p out ∧ ∀n,run (TickCut.Mixed.reverse d) n out=start0 := by have h := Shadow20.MixedChain.strong d x good raw m stage rw [← (Shadow20.MixedWindow.mixedCut_run_eq d).1, ← TickCut.Mixed.reverse_run_eq d] at h exact h end ECDSAAdd.Entrant.StairPacket.StockStrongChain end section namespace ECDSAAdd.Entrant.StairPacket.StockArchiveReference open Arithmetic MappedCompressed WideReference def common (d:Bool) (raw:State):State:=Shadow20.MixedOrd.common d raw end ECDSAAdd.Entrant.StairPacket.StockArchiveReference namespace ECDSAAdd.Entrant.StairPacket.StockArchiveBanks open Arithmetic MappedCompressed Secp256k1 WideReference ArchivePortAction StairArchiveNativeRows CodecBitSliceVerify set_option maxRecDepth 16000 set_option maxHeartbeats 4000000 set_option linter.unusedVariables false attribute [local irreducible] run span abbrev Bank := Shadow20.MixedGeo.Bank def ports (b:Bank):Ports:=Shadow20.MixedGeo.bankPorts StockWindowChainP.ExitPorts420 b def siteAt (b:Bank) (j:Fin 16):Wire:=ports b ⟨j.val,by omega⟩ def tick (b:Bank):Nat:=Shadow20.MixedGeo.bankTick b def archives:List Wire:=Shadow20.MixedGeo.archives def Same (a b:State):Prop:=Shadow20.MixedArchiveSuffix.Same a b def nativeAt (d:Bool) (b:Bank) (r:Nat) (s:State):Prop:=StockArchiveBanksW.nativeAt (siteAt b) d r s theorem site_eq (b:Bank) (j:Fin 16) : siteAt b j=Shadow20.MixedGeo.bankSite b j := Shadow20.MixedGeo.site_eq StockWindowChainP.ExitPorts420 exitCells b j theorem mem (b:Bank) (j:Fin 16) : siteAt b j∈archives := by rw [site_eq]; exact Shadow20.MixedGeo.bank_mem b j theorem bank_rep (q:Wire) (h:q∈archives) : ∃(b:Bank)(j:Fin 16),siteAt b j=q := Shadow20.MixedGeo.bank_rep StockWindowChainP.ExitPorts420 exitCells q h structure Paired (d:Bool) (x:Nat) (a s:State) (rows:Bank→Nat):Prop where equality:Same a s labels:∀b,rows b<63145 ∧ ArchiveStockRows.Chronology (tick b) x p (rows b) custom:∀b,Kept (ports b) d (rows b) a stock:∀b,nativeAt d b (rows b) s theorem Paired.through {d x a s rows} (pair:Paired d x a s rows) (P:Program) (off:∀q∈archives,q∉wires P) (m:List Bool):Paired d x (run P m a) (run P m s) rows:=by have h:=Shadow20.MixedArchiveSuffix.independent P off m a s pair.equality refine ⟨h.1,pair.labels,?_,?_⟩ · intro b j exact (h.2 (siteAt b j) (mem b j)).trans (pair.custom b j) · intro b j exact (run_preserves_outside P m s (siteAt b j) (off _ (mem b j))).trans (pair.stock b j) theorem safe (d:Bool) (i n:Nat) (lo:421 ≤ i) (hi:i+n ≤ 512) (q:Wire) (mem:q∈archives) : q∉wires (Rolling1588TickGap.forward d i n) ∧ q∉wires (Rolling1588.reverse d i n) := Shadow20.MixedArchiveSuffix.safe d i n lo hi q mem end ECDSAAdd.Entrant.StairPacket.StockArchiveBanks namespace ECDSAAdd.Entrant.StairPacket.StockRowVector open Arithmetic MappedCompressed Secp256k1 WideReference StockArchiveBanks noncomputable def rows (x p:Nat) (b:Bank):Nat:=Shadow20.MixedChain.mixedRow x p b theorem binding (d:Bool) (x:Nat) (good:Bounds x p) (raw a:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) (stored:Shadow20.MixedChain.mixedFinal StockWindowChainP.ExitPorts420 d x p a) (same:Same a (run (Rolling1588TickGap.forward d 45 376) m (pullState (OB5.sig 44) raw))) : Paired d x a (run (Rolling1588TickGap.forward d 45 376) m (pullState (OB5.sig 44) raw)) (rows x p) := by refine ⟨same, fun b => ⟨(stored b).1, Shadow20.MixedChain.mixedFinal_trace stored b⟩, fun b => (stored b).2.2, fun b => ?_⟩ exact Shadow20.MixedOrd.stored d x good raw m stage b (rows x p b) (stored b).1 (Shadow20.MixedChain.mixedFinal_trace stored b) end ECDSAAdd.Entrant.StairPacket.StockRowVector namespace ECDSAAdd.Entrant.StairPacket.StockBaseline open Arithmetic MappedCompressed WideReference Secp256k1 StockArchiveBanks theorem comparison (d:Bool) (x:Nat) (good:Bounds x p) (s a:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 s.basis) (results:Shadow20.MixedChain.mixedFinal StockWindowChainP.ExitPorts420 d x p a) : Same (run (Rolling1588TickGap.forward d 45 376) m (pullState (OB5.sig 44) s)) (StockArchiveReference.common d s) := Shadow20.MixedOrd.comparison d x good s a m stage results end ECDSAAdd.Entrant.StairPacket.StockBaseline end -- ==== end build-main2 ship API ==== section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldView open Arithmetic Secp256k1 MappedCompressed StairArchiveRelease StairArchiveNativeCut StairArchiveTen open WindowFieldMask WindowFieldCosts WindowFieldJourney StairField2V3Seg StairPhysicalLayout open StairField2V3LastRecX StairField2V3RecScratch StairField2V3Replay StairField2V3Delta open StairOuterPlacement set_option maxRecDepth 1600 set_option maxHeartbeats 300000 attribute [local irreducible] run theorem exitFrame (c x : Nat) (t : State) (h : StairField2V3ExitRec.InvE x c t) : FrameAt x c t := by obtain ⟨o,X,Y,s,ctx,en,tr,_,frame,agree⟩ := h exact ⟨o,X,Y,s,ctx,en,tr,frame,agree⟩ /-- Instantiate the three real windows from an odd-word cut endpoint `OCut`. -/ theorem ocaller (d : Bool) (x : Nat) (rows : Nat→Nat) (rb : ∀j∈bankIds,rows j<63145) (history : ∀j∈bankIds,ArchiveStockRows.Chronology (5*j-5) x ECDSAAdd.p (rows j)) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400)=true) (tr : TraceOK x origin) (actual ref : State) (m : List Bool) (initial : Fits rows (initialCode d) actual (pullIn ref)) (start : OCut (if d then 1 else 85) origin (pullIn ref)) : Fits rows (finalCode d (plan d) (initialCode d)) (run (group84 d) m actual) (run (PacketSequence.program d (opk d) 1 84) (oreferenceTape d (plan d) m) (pullIn ref)) := othree_run d x rows rb origin ctx en tr history m actual (pullIn ref) initial start end ECDSAAdd.Entrant.StairPacket.WindowFieldView end section namespace ECDSAAdd.Entrant.Stair44Kernel open Arithmetic MappedCompressed Secp256k1 DirectSkywalk StairConcreteAssembly Rolling1588Lifetime open ParityXExitInverse23Kernel set_option maxRecDepth 16000 set_option maxHeartbeats 3000000 attribute [local irreducible] run measurementCount wires renameProgram def finishM := Six505.merged6 ++ Six505.packP false ++ ForwardSixPlacement.after false ++ skywalkArithmeticClear base def mulLead := renameProgram phaseHost (openR false 489 ++ finishM) def beforeX := (mulLead ++ StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan) ++ renameProgram phaseHost checkpointPrimitives.firstUnpack def stockBeforeX := Stair44MultiplyCut.beforeClose hostPlan ++ renameProgram phaseHost checkpointPrimitives.firstUnpack def mulRawTail (k : Nat) := Stair44WalkRun.backward true 409 ++ renameProgram rawX (x1N k) def stockTail (k : Nat) := Rolling1588.reverse true 1 424 ++ x1N k def multiplication (k : Nat) := beforeX ++ renameProgram phaseHost (mulRawTail k) def outMap : Equiv.Perm Wire := (phaseHost.symm.trans rawOut).trans phaseHost private theorem actualOpening : Rolling1588TickGap.firstPhase false = openS false 489 ++ finishM := by simp only [Rolling1588TickGap.firstPhase, Rolling1588TickGap.tailPhase, Rolling1588TickGap.stackForward, Six505.stackForward6,openS,finishM,List.append_assoc] private theorem leadCountM : measurementCount mulLead = measurementCount StairField2V3Replay.exitReferenceOpening := by rw [StairField2V3Replay.exitReferenceOpening,actualOpening,mulLead,(renameProgram_counts _ _).2, (renameProgram_counts _ _).2,measurementCount_append,measurementCount_append,open_count] private theorem leadRunM (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : run mulLead m s=run StairField2V3Replay.exitReferenceOpening m s := by apply MappedCompressed.pullState_perm_injective phaseHost rw [mulLead, StairField2V3Replay.exitReferenceOpening,run_rename _ phaseHost.injective, run_rename _ phaseHost.injective,StairField13V3Clean.pull_phaseHost_exit F,actualOpening] exact with_tail false 489 F.x _ (by decide) F.x_pos F.x_lt F.sharedNodup s F.input _ m private theorem prefixCount (A B V W : Program) (h : measurementCount A=measurementCount B) : measurementCount ((A++V)++W)=measurementCount ((B++V)++W) := by simp only [measurementCount_append,h] private theorem prefixRun (A B V W : Program) (s : State) (m : List Bool) (cnt : measurementCount A=measurementCount B) (same : ∀ n,run A n s=run B n s) : run ((A++V)++W) m s=run ((B++V)++W) m s := by simp only [run_append,measurementCount_append,cnt,same] private theorem countHead : measurementCount beforeX=measurementCount stockBeforeX := prefixCount mulLead StairField2V3Replay.exitReferenceOpening (StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan) (renameProgram phaseHost checkpointPrimitives.firstUnpack) leadCountM private theorem runHead (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : run beforeX m s=run stockBeforeX m s := prefixRun mulLead StairField2V3Replay.exitReferenceOpening (StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan) (renameProgram phaseHost checkpointPrimitives.firstUnpack) s m leadCountM (leadRunM k F) private theorem stockShape (k : Nat) : StairHostsSchedule.exitKernel checkpointPrimitives hostPlan k= stockBeforeX ++ renameProgram phaseHost (stockTail k) := by simp only [StairHostsSchedule.exitKernel,stockBeforeX,Stair44MultiplyCut.beforeClose, StairField2V3Replay.exitReferenceOpening,StairHostsSchedule.lastXN,StairSchedule.stackReverse15, stockTail,Six505.rename_append,List.append_assoc] private theorem actualStockZeros (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : let out := run (StairHostsSchedule.exitKernel checkpointPrimitives hostPlan k) m s (pullState phaseHost out).basis (base 1026)=false ∧ (pullState phaseHost out).basis (base 514)=false := by have old := StairCallerReplay.hostedExit_pw hostReplay k F.k_lt F.sharedNodup F.historyAbove F.selectorsAway F.transcript F.x F.Y F.x_pos F.x_lt s m F.input F.selectorG_zero F.selectorS_zero have info := kernelX_correct k F.k_lt F.sharedNodup F.historyAbove F.selectorsAway F.transcript F.x F.Y F.x_pos F.x_lt s m F.input F.selectorG_zero F.selectorS_zero dsimp only rw [old] have z (j : Nat) (h : j=721 ∨ j=514) : (run (kernelX k) m s).basis (base j)=false := by rcases h with rfl|rfl all_goals exact (info.2.2.2 _ (by decide) (by decide)).trans (F.input.2.2 _ (by decide) (by decide) (by decide)) simp only [pullState,show phaseHost (base 1026)=base 721 by decide +kernel, show phaseHost (base 514)=base 514 by decide +kernel] simpa only [ParityEven.put,writeBit,Function.update_of_ne (by decide : base 721≠pkP), Function.update_of_ne (by decide : base 514≠pkP)] using And.intro (z 721 (Or.inl rfl)) (z 514 (Or.inr rfl)) private theorem tailJoin (beforeX stockBeforeX : Program) (old : Nat→Program) (k x : Nat) {s : State} (m : List Bool) (countHead : measurementCount beforeX=measurementCount stockBeforeX) (runHead : ∀ u,run beforeX u s=run stockBeforeX u s) (hp : 0 (Nat.not_lt_of_ge h) (eq ▸ hi) have hrest : 12≤q-16-2400 := Nat.le_sub_of_add_le (Nat.le_sub_of_add_le h) have ne2 (i : Nat) (hi : i<12) : q-16-2400≠i := fun eq => (Nat.not_lt_of_ge hrest) (eq ▸ hi) have above : ¬q-16<2314 := Nat.not_lt_of_ge (Nat.le_trans (by decide : 2314≤2412) (Nat.le_sub_of_add_le h)) simp only [fast,phaseHostB,swB_eq,pwB_eq,sw,pwN,metaN,above, ne _ (by decide : 1042<2428),ne _ (by decide : 737<2428),ne _ (by decide : 1557<2428), ne _ (by decide : 738<2428),ne _ (by decide : 1558<2428),ne _ (by decide : 736<2428), ne _ (by decide : 785<2428),ne _ (by decide : 1813<2428),ite_false] simp (disch := decide) only [ne2,ite_false] private theorem boundMap (q : Wire) (h : 2428 ≤ q) : first q=q ∧ rawX q=q ∧ rawOut q=q := by have ne (i : Nat) (hi : base i<2428) : q≠base i := fun eq => (Nat.not_lt_of_ge h) (eq ▸ hi) simp (disch := decide) only [rawX,rawOut,first,shared,chain,Equiv.trans_apply,Equiv.swap_apply_def, ne,ite_false,Equiv.refl_apply,and_self] def test (q : Wire) := fast (first q)==integerFirst (fast q) && fast (rawX q)==duringX (fast q) && fast (rawOut q)==outer (fast q) private theorem checked : (List.range 2428).all test=true := by decide +kernel theorem maps (q : Wire) : phys (first q)=integerFirst (phys q) ∧ phys (rawX q)=duringX (phys q) ∧ phys (rawOut q)=outer (phys q) := by simp only [phys_fast] by_cases h : q<2428 · have t := List.all_eq_true.mp checked q (List.mem_range.mpr h) simpa only [test,Bool.and_eq_true,beq_iff_eq,and_assoc] using t · have f := boundMap q (Nat.le_of_not_gt h) rw [f.1,f.2.1,f.2.2,high q (Nat.le_of_not_gt h)] decide +kernel end ECDSAAdd.Entrant.Stair44Placement end section namespace ECDSAAdd.Entrant.Stair44CallerSupport open Arithmetic MappedCompressed DirectSkywalk StairConcreteAssembly StairSemanticFinal open Stair44WalkMap Stair44Kernel set_option maxRecDepth 30000 set_option maxHeartbeats 3000000 attribute [local irreducible] wires renameProgram private theorem swap (i j : Nat) (hi : i < 2314) (hj : j < 2314) : PreservesCaller (Equiv.swap (base i) (base j)) := preserves_swap _ _ (base_mem_caller _ (Or.inl hi)) (base_mem_caller _ (Or.inl hj)) private theorem firstOK : PreservesCaller Stair44WalkMap.first := by unfold Stair44WalkMap.first shared repeat' apply preserves_perm_trans all_goals exact swap _ _ (by decide) (by decide) private theorem restOK : PreservesCaller rest := by unfold rest shared repeat' apply preserves_perm_trans all_goals exact swap _ _ (by decide) (by decide) private theorem rawOK : PreservesCaller rawX := by unfold rawX rawOut simp only [Stair44PointMap.chain] repeat' apply preserves_perm_trans all_goals first | exact swap _ _ (by decide) (by decide) | exact fun _ h => h private theorem forward (d : Bool) (a : Nat) (h : 15+a ≤ 504) : wires (Stair44WalkRun.forward d a) ⊆ callerDomain := by have both := forward_own d (15+a) h rw [tickGap_forward_split d 15 1 a, wires_append, Finset.union_subset_iff] at both exact wires_sub_of_parts _ _ (rename_caller _ firstOK _ both.1) (rename_caller _ restOK _ both.2) private theorem backward (d : Bool) (a : Nat) (h : 15+a ≤ 505) : wires (Stair44WalkRun.backward d a) ⊆ callerDomain := by have both := reverse_own d (15+a) h rw [reverse_split d 15 1 a,wires_append,Finset.union_subset_iff] at both exact wires_sub_of_parts _ _ (rename_caller _ restOK _ both.1) (rename_caller _ firstOK _ both.2) private theorem opening (d : Bool) (a : Nat) (h : 15+a ≤ 504) : wires (openR d a) ⊆ callerDomain := wires_sub_of_parts _ _ (rename_caller _ firstOK _ nativeForward_own) (forward d a h) private theorem closing : wires Stair44DivTerm.routedClose ⊆ callerDomain := by have h := lastPhase_false_own simp only [InverseFive23.lastPhase15,InverseFive23.stackReverse15,InverseFive23.reverseTail15, wires_append,Finset.union_subset_iff] at h unfold Stair44DivTerm.routedClose Stair44DivTerm.head exact wires_sub_of_parts _ _ (wires_sub_of_parts _ _ h.1.1 (wires_sub_of_parts _ _ h.1.2.1 h.1.2.2.1)) (wires_sub_of_parts _ _ (backward false 490 (by decide)) (rename_caller _ firstOK _ h.2)) theorem division : wires Stair44Kernel.division ⊆ callerDomain := wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (phaseHost_caller _ (wires_sub_of_parts _ _ (opening true 409 (by decide)) cp_firstPack)) entryFieldHostedV3_caller) (phaseHost_caller _ closing) private theorem finish : wires finishM ⊆ callerDomain := by have h := firstPhase_own false simp only [Rolling1588TickGap.firstPhase, Rolling1588TickGap.tailPhase, Rolling1588TickGap.stackForward,Six505.stackForward6,wires_append,Finset.union_subset_iff] at h exact wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ h.2.1.2.1 h.2.1.2.2.1) h.2.1.2.2.2) h.2.2 theorem multiplication (k : Nat) : wires (Stair44Kernel.multiplication k) ⊆ callerDomain := wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (phaseHost_caller _ (wires_sub_of_parts _ _ (opening false 489 (by decide)) finish)) exitFieldHostedV3_caller) (phaseHost_caller _ cp_firstUnpack)) (phaseHost_caller _ (wires_sub_of_parts _ _ (backward true 409 (by decide)) (rename_caller _ rawOK _ (x1N_own k)))) end ECDSAAdd.Entrant.Stair44CallerSupport end section namespace ECDSAAdd.Entrant.Stair44Splits open Arithmetic MappedCompressed Baselines Stair44Placement Stair44PointMap Stair44WalkMap Stair44Kernel open Stair44Outer Rolling1588Lifetime Secp256k1 set_option maxRecDepth 16000 set_option maxHeartbeats 1600000 def tick := renameProgram integerFirst (E1QubitPlacement.tickF layout) theorem placeMove (f g : Wire → Wire) (h : ∀q,phys (f q)=g (phys q)) (P : Program) : phasePlace (renameProgram f P)=renameProgram g (phasePlace P) := by simp only [phasePlace,kernelPlace,renameProgram_comp] congr 1; funext q;exact h q theorem tick_eq : phasePlace firstR=tick := by rw [firstR,placeMove first integerFirst (fun q => (maps q).1)] exact congrArg (renameProgram integerFirst) (E1QubitPlacement.tick_eq layout) end ECDSAAdd.Entrant.Stair44Splits end section namespace ECDSAAdd.Entrant.Stair44PointWord open Arithmetic MappedCompressed DirectSkywalk Secp256k1 Rolling1588Lifetime BalancedField ControlledPointLayout CompressedPointDialog ParityEven ParityXExitInverse23Kernel StairSemanticFinal Stair44Kernel Stair44PointMap Baselines StairConcreteAssembly set_option maxRecDepth 18000 set_option maxHeartbeats 2500000 attribute [local irreducible] run wires measurementCount end ECDSAAdd.Entrant.Stair44PointWord end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorCaller open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines StairSemanticFinal StairConcreteAssembly open StairRestSupport StairPhysicalV3 ArchiveFieldScratch StairArchiveRelease StairArchiveGates open StairArchiveInactive StairArchiveNativeCut StairArchiveTen WindowFieldCosts set_option maxRecDepth 25000 set_option maxHeartbeats 3500000 attribute [local irreducible] wires packet renameProgram def GoodP (P:Program):Prop:=wires P ⊆ callerDomain private theorem app {a b:Program} (ha:GoodP a) (hb:GoodP b):GoodP (a++b):=by intro w hit exact (Finset.mem_union.mp (wires_append a b ▸ hit)).elim (fun x=>ha x) (fun x=>hb x) private theorem ordinary (d:Bool) (j n:Nat) (hi:j+n≤102):GoodP (group d j n):=hostedGroupV3_caller d 0 j n (by decide) hi private theorem singleton (d:Bool) (j:Nat) (hi:j+1≤102):GoodP (packet d j):=by have pass:=ordinary d j 1 hi change GoodP (StairHostsSchedule.hostedGroup hostPlan d 0 j 1) at pass rw [distribute] at pass cases d <;> simpa only [distributed,PacketSequence.program,if_true,if_false,Bool.false_eq_true,List.append_nil,List.nil_append] using pass private theorem hook (j:Nat) (hj:j∈[10,13,16,19,22,25,28,31,35,39,43,47,51,55,59,63,67,70,73,76,79,82]) (op:Stage):GoodP (fieldHook j op):=by have span:j∈List.range' 1 83:=by simp only [List.mem_cons,List.not_mem_nil,or_false] at hj;apply List.mem_range'_1.mpr;omega have chk:(fieldSites j).all (fun q=>decide (16 ≤ q ∧ q < 2330))=true:=by simp only [List.mem_cons,List.not_mem_nil,or_false] at hj rcases hj with rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl <;> decide +kernel intro q hit rw [fieldHook,renameProgram_support] at hit obtain ⟨w,hw,rfl⟩:=Finset.mem_image.mp hit have len:(fieldSites j).length=121:=by have hh:=(layout_frame j span).2;rwa [←field_layout,List.length_map] at hh have lt:w < (fieldSites j).length:=len ▸ (Finset.mem_range.mp (sub op hw)) have pos:=of_decide_eq_true (List.all_eq_true.mp chk ((fieldSites j)[w]) (List.getElem_mem lt)) have toCaller (v:Nat) (h:16≤v ∧ v<2330):v∈callerDomain:=by have baseEq:base (v-16)=v:=by simp only [base,Wire];omega rw [←baseEq] exact base_mem_caller _ (Or.inl (by omega)) have yes:=toCaller _ pos simpa only [fieldPort,List.getElem?_eq_getElem lt,Option.getD_some] using yes private theorem pair (d:Bool) (j:Nat) (hj:j∈[10,13,16,19,22,25,28,31,35,39,43,47,51,55,59,63,67,70,73,76,79,82]) (hi:j≤83):GoodP (ten j (!d)):=by have here:=singleton d j (by omega) have next:=singleton d (j+1) (by omega) have a:GoodP (first j (!d)):=by cases d <;> first | exact here | exact next have b:GoodP (second j (!d)):=by cases d <;> first | exact here | exact next exact app (hook j hj _) (app a (app (hook j hj _) (app b (hook j hj _)))) -- oddten:begin GOOD theorem group84_good (d:Bool):GoodP (group84 d):=by have ord {a b:Program} (x:GoodP a) (y:GoodP b):GoodP (ordered d a b):=by cases d <;> first | exact app x y | exact app y x have og (j n:Nat) (hi:j+n≤102):GoodP (ogroup d j n):= Finset.Subset.trans (WindowFieldCosts.ot_ogroup_sub d j n) (ordinary d j n hi) have ot (j:Nat) (hj:j∈[10,13,16,19,22,25,28,31,35,39,43,47,51,55,59,63,67,70,73,76,79,82]) (hi:j≤83):GoodP (oten j (!d)):= Finset.Subset.trans (WindowFieldCosts.ot_oten_sub j (!d)) (pair d j hj hi) have c43 := ord (ot 82 (by decide) (by decide)) (og 84 1 (by decide)) have c42 := ord (og 81 1 (by decide)) c43 have c41 := ord (ot 79 (by decide) (by decide)) c42 have c40 := ord (og 78 1 (by decide)) c41 have c39 := ord (ot 76 (by decide) (by decide)) c40 have c38 := ord (og 75 1 (by decide)) c39 have c37 := ord (ot 73 (by decide) (by decide)) c38 have c36 := ord (og 72 1 (by decide)) c37 have c35 := ord (ot 70 (by decide) (by decide)) c36 have c34 := ord (og 69 1 (by decide)) c35 have c33 := ord (ot 67 (by decide) (by decide)) c34 have c32 := ord (og 65 2 (by decide)) c33 have c31 := ord (ot 63 (by decide) (by decide)) c32 have c30 := ord (og 61 2 (by decide)) c31 have c29 := ord (ot 59 (by decide) (by decide)) c30 have c28 := ord (og 57 2 (by decide)) c29 have c27 := ord (ot 55 (by decide) (by decide)) c28 have c26 := ord (og 53 2 (by decide)) c27 have c25 := ord (ot 51 (by decide) (by decide)) c26 have c24 := ord (og 49 2 (by decide)) c25 have c23 := ord (ot 47 (by decide) (by decide)) c24 have c22 := ord (og 45 2 (by decide)) c23 have c21 := ord (ot 43 (by decide) (by decide)) c22 have c20 := ord (og 41 2 (by decide)) c21 have c19 := ord (ot 39 (by decide) (by decide)) c20 have c18 := ord (og 37 2 (by decide)) c19 have c17 := ord (ot 35 (by decide) (by decide)) c18 have c16 := ord (og 33 2 (by decide)) c17 have c15 := ord (ot 31 (by decide) (by decide)) c16 have c14 := ord (og 30 1 (by decide)) c15 have c13 := ord (ot 28 (by decide) (by decide)) c14 have c12 := ord (og 27 1 (by decide)) c13 have c11 := ord (ot 25 (by decide) (by decide)) c12 have c10 := ord (og 24 1 (by decide)) c11 have c9 := ord (ot 22 (by decide) (by decide)) c10 have c8 := ord (og 21 1 (by decide)) c9 have c7 := ord (ot 19 (by decide) (by decide)) c8 have c6 := ord (og 18 1 (by decide)) c7 have c5 := ord (ot 16 (by decide) (by decide)) c6 have c4 := ord (og 15 1 (by decide)) c5 have c3 := ord (ot 13 (by decide) (by decide)) c4 have c2 := ord (og 12 1 (by decide)) c3 have c1 := ord (ot 10 (by decide) (by decide)) c2 exact ord (og 1 9 (by decide)) c1 -- oddten:end GOOD theorem entryTailPrefix_ours : wires (WindowCallerCosts.entryTailPrefix StairConcreteAssembly.checkpointPrimitives) ⊆ callerDomain := by have oddDom (d f c : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (hfc : f + c ≤ 102) : wires (OddFullPass.P1LifeLoan.hostedGroup StairConcreteAssembly.hostPlan true d f c) ⊆ callerDomain := (OddFullPass.P1LifeLoan.hostedGroup_wires_sub _ true d f c hd h42).trans (hostedGroupV3_caller true d f c (by omega) hfc) unfold WindowCallerCosts.entryTailPrefix simp only [wires_append, Finset.union_subset_iff, and_assoc] exact ⟨group84_good true, fseg_caller 87 62 (by decide) (by decide) (by decide) (by decide), oddDom 13 85 5 (by decide) (by decide) (by decide), fseg_caller 62 47 (by decide) (by decide) (by decide) (by decide), oddDom 22 90 3 (by decide) (by decide) (by decide), fseg_caller 47 32 (by decide) (by decide) (by decide) (by decide), oddDom 30 93 3 (by decide) (by decide) (by decide), fseg_caller 32 22 (by decide) (by decide) (by decide) (by decide), oddDom 36 96 2 (by decide) (by decide) (by decide), fseg_caller 22 12 (by decide) (by decide) (by decide) (by decide), oddDom 41 98 2 (by decide) (by decide) (by decide), forwardLastV3_caller⟩ theorem exitHeadSuffix_ours : wires (WindowCallerCosts.exitHeadSuffix StairConcreteAssembly.checkpointPrimitives) ⊆ callerDomain := by have oddDom (d f c : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (hfc : f + c ≤ 102) : wires (OddFullPass.P1LifeLoan.hostedGroup StairConcreteAssembly.hostPlan false d f c) ⊆ callerDomain := (OddFullPass.P1LifeLoan.hostedGroup_wires_sub _ false d f c hd h42).trans (hostedGroupV3_caller false d f c (by omega) hfc) have cutDom (B N s f d first c : Nat) (hw : wires (PackCutOddExit.cutRowOddPk B N s f d first c) ⊆ wires (OddFullPass.P1LifeLoan.hostedGroup StairConcreteAssembly.hostPlan false d first (c + 1)) ∪ wires (StairSchedule.reverseSegment StairConcreteAssembly.checkpointPrimitives B N s f)) (h1 : wires (OddFullPass.P1LifeLoan.hostedGroup StairConcreteAssembly.hostPlan false d first (c + 1)) ⊆ callerDomain) (h2 : wires (StairSchedule.reverseSegment StairConcreteAssembly.checkpointPrimitives B N s f) ⊆ callerDomain) : wires (PackCutOddExit.cutRowOddPk B N s f d first c) ⊆ callerDomain := hw.trans (Finset.union_subset h1 h2) unfold WindowCallerCosts.exitHeadSuffix simp only [wires_append, Finset.union_subset_iff, and_assoc] exact ⟨reverseLastV3_caller, cutDom 22 12 490 500 41 98 1 PackCutOddExit.cutRow4_wires (oddDom 41 98 2 (by decide) (by decide) (by decide)) (rseg_caller 22 12 (by decide) (by decide) (by decide) (by decide) (by decide)), cutDom 32 22 480 490 36 96 1 PackCutOddExit.cutRow3_wires (oddDom 36 96 2 (by decide) (by decide) (by decide)) (rseg_caller 32 22 (by decide) (by decide) (by decide) (by decide) (by decide)), cutDom 47 32 465 480 30 93 2 PackCutOddExit.cutRow2_wires (oddDom 30 93 3 (by decide) (by decide) (by decide)) (rseg_caller 47 32 (by decide) (by decide) (by decide) (by decide) (by decide)), cutDom 62 47 450 465 22 90 2 PackCutOddExit.cutRow1_wires (oddDom 22 90 3 (by decide) (by decide) (by decide)) (rseg_caller 62 47 (by decide) (by decide) (by decide) (by decide) (by decide)), cutDom 87 62 425 450 13 85 4 PackCutOddExit.cutRow0_wires (oddDom 13 85 5 (by decide) (by decide) (by decide)) (rseg_caller 87 62 (by decide) (by decide) (by decide) (by decide) (by decide)), group84_good false⟩ private theorem hostedFirstPacketOdd_caller (divide : Bool) : wires (StairLoan.rebindMany StairSchedule.exclusiveRoles (StairConcreteAssembly.hostPlan.firstPacket divide) (JointOdd1588.placedFirstPacketOdd WindowCallerCosts.oddFirstHalf divide)) ⊆ callerDomain := by refine rebindMany_caller _ _ _ exclusive_caller (hostPlan_firstPacket_caller divide) ?_ intro q hq have hsup := StairWireCheck.allSites_sound StairWireCheck.fpSup _ (JointOdd1588.placedFirstPacketOdd_passSup WindowCallerCosts.oddFirstHalf divide (WindowCallerCosts.oddFirstHalf_support divide)) q hq rcases WindowCallerCosts.fpSup_bounds q hsup with ⟨hlo, hhi⟩ | rfl · have heq : base (q - 16) = q := Nat.sub_add_cancel hlo rw [← heq] exact base_mem_caller _ (Or.inl (Nat.sub_lt_left_of_lt_add hlo hhi)) · exact base_mem_caller 2409 (Or.inr (Or.inr (Or.inl rfl))) theorem entryLowPrefix_ours : wires (WindowCallerCosts.entryLowPrefix StairConcreteAssembly.checkpointPrimitives) ⊆ callerDomain := by unfold WindowCallerCosts.entryLowPrefix exact wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (hostedFirstPacketOdd_caller true) glue_own.2.2.1) (borrow_caller _ entryTailPrefix_ours)) glue_own.2.2.2 theorem exitLowSuffix_ours : wires (WindowCallerCosts.exitLowSuffix StairConcreteAssembly.checkpointPrimitives) ⊆ callerDomain := by unfold WindowCallerCosts.exitLowSuffix exact wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ glue_own.2.2.1 (borrow_caller _ exitHeadSuffix_ours)) glue_own.2.2.2) (hostedFirstPacketOdd_caller false) end ECDSAAdd.Entrant.StairPacket.ExteriorCaller end section namespace ECDSAAdd.Entrant.StairPacket.WindowKernelPrograms open Arithmetic MappedCompressed Baselines Stair44Placement Stair44PointMap Stair44WalkMap Stair44Kernel open Stair44Outer Rolling1588Lifetime Secp256k1 StairConcreteAssembly StairSemanticFinal set_option maxRecDepth 16000 set_option maxHeartbeats 2000000 def openWalk (d:Bool) (tail:Nat):Program:=Stair44Kernel.firstR++WindowWalkCosts.forward d tail def divBefore:Program:=renameProgram phaseHost (openWalk true 4++checkpointPrimitives.firstPack)++WindowParityCaller.entryFieldHostedCut def divAfter:Program:=Stair44Outer.reverseEnd++(WindowWalkCosts.backward false 85++renameProgram first (FrontierEntry1591NativeH.inverse base)) def division:Program:=divBefore++renameProgram phaseHost divAfter def mulBefore:Program:=(renameProgram phaseHost (openWalk false 84++Stair44Outer.forwardEnd)++WindowParityCaller.exitFieldHosted checkpointPrimitives)++renameProgram phaseHost checkpointPrimitives.firstUnpack def mulAfter (k:Nat):Program:=WindowWalkCosts.backward true 4++renameProgram rawX (ParityXExitInverse23Kernel.x1N k) def multiplication (k:Nat):Program:=mulBefore++renameProgram phaseHost (mulAfter k) theorem div_split : FrontierEntry1591Callers.entry division layout = Stair44Splits.tick ++ WindowParityCaller.divide := by change kernelPlace (divBefore++renameProgram phaseHost divAfter)=_ simp only [divBefore,divAfter,openWalk,WindowParityCaller.divide,kernelPlace,Six505.rename_append,List.append_assoc] change phasePlace Stair44Kernel.firstR ++ _=Stair44Splits.tick ++ _ rw [Stair44Splits.tick_eq] rfl theorem mul_split (k:Nat) : FrontierEntry1591Callers.exit (multiplication k) layout=Stair44Splits.tick ++ WindowParityCaller.multiply k := by change kernelPlace (multiplication k)=_ simp only [multiplication,mulBefore,mulAfter,openWalk,WindowParityCaller.multiply,kernelPlace,Six505.rename_append,List.append_assoc] change phasePlace Stair44Kernel.firstR ++ _=Stair44Splits.tick ++ _ rw [Stair44Splits.tick_eq] rw [show Stair44PointMap.switchX (phasePlace (ParityXExitInverse23Kernel.x1N k)) = phasePlace (renameProgram rawX (ParityXExitInverse23Kernel.x1N k)) from (Stair44Splits.placeMove rawX duringX (fun q => (maps q).2.1) _).symm] rfl structure Contracts:Prop where divSites:wires division⊆callerDomain mulSites:∀k,wires (multiplication k)⊆callerDomain enter:OddOuterBridge.EntryCorrectOdd division exit:∀k, k < p → OddOuterBridge.ExitMatchesOdd (renameProgram outMap.symm (multiplication k)) k end ECDSAAdd.Entrant.StairPacket.WindowKernelPrograms end section namespace ECDSAAdd.Entrant.Stair44PointSecond open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines ControlledPointLayout CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite FlagEntry FlagExit DirectSkywalk ParityUniform ParityEven ParityXExitInverse23Kernel ParityStageBothInverse23 A161Generic Stair44PointMap Stair44PlacedHead set_option maxHeartbeats 3000000 set_option maxRecDepth 20000 attribute [local irreducible] run measurementCount fastConstAdd theorem joinRecords (A B : Program) (a b : List Bool) (s : State) : run (A++B) (pfx (measurementCount A) a ++ b) s=run B b (run A a s) := by rw [run_append,List.take_append_of_le_length (by rw [pfx_length]),List.take_of_length_le (by rw [pfx_length]), List.drop_append_of_le_length (by rw [pfx_length]),List.drop_of_length_le (by rw [pfx_length]),run_pfx] rfl theorem tripleRun (A B C : Program) (m : List Bool) (s : State) : let a := m.take (measurementCount A) let tail := m.drop (measurementCount A) run ((A++B)++C) m s=run C (tail.drop (measurementCount B)) (run B (tail.take (measurementCount B)) (run A a s)) := by rw [List.append_assoc,run_append A,run_append B] theorem chosenRun (A B C : Program) (r y : List Bool) (s : State) : run ((A++B)++C) (pfx (measurementCount A) []++(pfx (measurementCount B) r++y)) s= run C y (run B r (run A [] s)) := by rw [List.append_assoc,run_pre A,joinRecords B] theorem runNil (A B : Program) (s : State) : run (A++B) [] s=run B [] (run A [] s) := by rw [run_append,List.take_nil,List.drop_nil] theorem stockCut (k X Y : Fp) (G : Bool) (origin : BasisState) (s w : State) (v : PointDialogValues layout X Y G origin s.basis) (ew : run (SquareCarryLoan719BF.program layout ++ fastConstAdd layout layout.point.x k) [] s=w) : run (squareEntry layout k) [] s=run (E1QubitPlacement.tickF layout) [] w := (squareEntry_base layout layout_widths layout_nodup k X Y G origin s [] [] v).trans ((runNil _ _ s).trans (congrArg (run (E1QubitPlacement.tickF layout) []) ew)) theorem squareCut (k X Y : Fp) (G : Bool) (origin : BasisState) (s w : State) (m : List Bool) (v : PointDialogValues layout X Y G origin s.basis) (ew : run (SquareCarryLoan719BF.program layout ++ fastConstAdd layout layout.point.x k) [] s=w) (x : Nat) (vx : regValue layout.point.x w.basis=x) (hx : x Stair44OuterX.tickZero w [] x vx hx hc q ((by decide +kernel : ∀i∈([4835,4837,4615,4616]:List Wire),i∈firstClean) q hq))) end ECDSAAdd.Entrant.Stair44PointSecond end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorCaller open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairSemanticFinal set_option maxRecDepth 25000 set_option maxHeartbeats 4000000 attribute [local irreducible] wires renameProgram private theorem localSite {q:Nat} (h:16 ≤ q ∧ q < 2330):q∈callerDomain:=by have e:base (q-16)=q:=by simp only [base,Wire];omega exact e ▸ base_mem_caller _ (Or.inl (by omega)) private theorem setup:GoodP WindowFieldParity.setup:=by apply wires_sub_of_parts _ _ glue_own.2.1 -- one decide per bank region (a single decide over the 16-region `correction` overflows the stack) have app:∀ P Q:Program,StairWireCheck.allSites (fun q=>decide (16 ≤ q ∧ q < 2330)) P=true → StairWireCheck.allSites (fun q=>decide (16 ≤ q ∧ q < 2330)) Q=true → StairWireCheck.allSites (fun q=>decide (16 ≤ q ∧ q < 2330)) (P++Q)=true:=by intro P Q a b simp only [StairWireCheck.allSites,List.all_append,Bool.and_eq_true] at a b ⊢ exact ⟨a,b⟩ have bk:∀ j∈[10, 13, 16, 19, 22, 25, 28, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 70, 73, 76, 79, 82],StairWireCheck.allSites (fun q=>decide (16 ≤ q ∧ q < 2330)) (WindowFieldParity.bankCorrection j)=true:=by intro j hj simp only [List.mem_cons,List.not_mem_nil,or_false] at hj rcases hj with rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl|rfl <;> decide +kernel have table:StairWireCheck.allSites (fun q=>decide (16 ≤ q ∧ q < 2330)) WindowFieldParity.correction=true:=by unfold WindowFieldParity.correction exact (app _ _ (bk 10 (by decide)) (app _ _ (bk 13 (by decide)) (app _ _ (bk 16 (by decide)) (app _ _ (bk 19 (by decide)) (app _ _ (bk 22 (by decide)) (app _ _ (bk 25 (by decide)) (app _ _ (bk 28 (by decide)) (app _ _ (bk 31 (by decide)) (app _ _ (bk 35 (by decide)) (app _ _ (bk 39 (by decide)) (app _ _ (bk 43 (by decide)) (app _ _ (bk 47 (by decide)) (app _ _ (bk 51 (by decide)) (app _ _ (bk 55 (by decide)) (app _ _ (bk 59 (by decide)) (app _ _ (bk 63 (by decide)) (app _ _ (bk 67 (by decide)) (app _ _ (bk 70 (by decide)) (app _ _ (bk 73 (by decide)) (app _ _ (bk 76 (by decide)) (app _ _ (bk 79 (by decide)) (bk 82 (by decide))))))))))))))))))))))) intro q h exact localSite (of_decide_eq_true (StairWireCheck.allSites_sound _ _ table q h)) theorem entryFieldHosted_corrected : wires (WindowParityCaller.entryFieldHosted StairConcreteAssembly.checkpointPrimitives) ⊆ callerDomain := by have hSuf : wires (OddFullPass.P1LifeLoan.entryLowSuffixOdd StairConcreteAssembly.hostPlan) ⊆ callerDomain := (OddFullPass.P1LifeLoan.entryLowSuffixOdd_wires_sub _).trans entryLowSuffixV3_caller unfold WindowParityCaller.entryFieldHosted exact wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (fieldRename_caller _ entryLowPrefix_ours) setup) glue_own.1) (fieldRename_caller _ hSuf)) glue_own.1) setup theorem entryFieldHostedCut_corrected : wires WindowParityCaller.entryFieldHostedCut ⊆ callerDomain := fun q hq => entryFieldHosted_corrected (PackCutSub.wires_sub WindowParityCaller.field_sublist q hq) theorem exitFieldHosted_corrected : wires (WindowParityCaller.exitFieldHosted StairConcreteAssembly.checkpointPrimitives) ⊆ callerDomain := by have hPre : wires (OddFullPass.P1LifeLoan.exitLowPrefixOdd StairConcreteAssembly.hostPlan) ⊆ callerDomain := (OddFullPass.P1LifeLoan.exitLowPrefixOdd_wires_sub _).trans exitLowPrefixV3_caller unfold WindowParityCaller.exitFieldHosted exact wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ (wires_sub_of_parts _ _ setup glue_own.1) (fieldRename_caller _ hPre)) setup) glue_own.1) (fieldRename_caller _ exitLowSuffix_ours) end ECDSAAdd.Entrant.StairPacket.ExteriorCaller end section namespace ECDSAAdd.Entrant.StairPacket.StockNativeCompare open Arithmetic MappedCompressed WideReference Secp256k1 attribute [local irreducible] run theorem common_phase (d:Bool) (x:Nat) (good:Bounds x p) (s:State) (stage:Rolling1588.Integer.Stage base d x p 45 s.basis) : (StockArchiveReference.common d s).phase=s.phase := Shadow20.MixedOrd.common_phase d x good s stage theorem normalized (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) : StockArchiveBanks.Same (run (Shadow20.MixedWindow.forwardMixedCut d) m (pullState (OB5.sig 44) raw)) (StockArchiveReference.common d raw) := by rw [(Shadow20.MixedWindow.mixedCut_run_eq d).1] exact Shadow20.MixedOrd.normalized d x good raw m stage end ECDSAAdd.Entrant.StairPacket.StockNativeCompare end section namespace ECDSAAdd.Entrant.StairPacket.StockWalkWindow open Arithmetic MappedCompressed Secp256k1 WideReference StockArchiveBanks StockWalkPrefix set_option maxRecDepth 9500 set_option maxHeartbeats 3000000 attribute [local irreducible] run Rolling1588TickGap.forward Rolling1588.Integer.regularForward measurementCount Shadow20.MixedWindow.forwardMixedCut def NewNormalized (d:Bool) (x:Nat):Prop:=∀(raw:State)(m:List Bool),Rolling1588.Integer.Stage base d x p 45 raw.basis → Same (run (Shadow20.MixedWindow.forwardMixedCut d) m (pullState (OB5.sig 44) raw)) (StockArchiveReference.common d raw) theorem steady (d:Bool) (x:Nat) (good:Bounds x p) (i n:Nat) (lo:0 < i) (hi:i+n≤512) (s:State) (u v:List Bool) (stage:Rolling1588.Integer.Stage base d x p i s.basis): run (Rolling1588TickGap.forward d i n) u (pullState (OB5.sig (i-1)) s)=run (Rolling1588TickGap.forward d i n) v (pullState (OB5.sig (i-1)) s):= (StockDelayed.window d x good.nonzero good.small i n lo hi s u stage).trans (StockDelayed.window d x good.nonzero good.small i n lo hi s v stage).symm theorem suffix_independent (d:Bool) (n x:Nat) (good:Bounds x p) (bound:421+n≤512) (s:State) (stage:Rolling1588.Integer.Stage base d x p 45 s.basis) (u v y z:List Bool): let t:=pullState (OB5.sig 44) s let old:=Rolling1588TickGap.forward d 45 376 let tail:=Rolling1588TickGap.forward d 421 n run tail u (run old v t)=run tail y (run old z t):=by let t:=pullState (OB5.sig 44) s let A:=Rolling1588TickGap.forward d 45 376 let B:=Rolling1588TickGap.forward d 421 n let mix (v u:List Bool):=FlagEntry.pfx (measurementCount A) v++u have eq:=steady d x good 45 (376+n) (by decide) (by omega) s (mix v u) (mix z y) stage rw [StairRestSupport.forward_append d 376 45 n] at eq exact (Stair44PointSecond.joinRecords A B v u t).symm.trans (eq.trans (Stair44PointSecond.joinRecords A B z y t)) theorem window (d:Bool) (n x:Nat) (good:Bounds x p) (bound:421+n≤512) (raw:State) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) (m stockTape:List Bool) (norm:NewNormalized d x): let s:=pullState (OB5.sig 44) raw Paired d x (run (forwardEnd d n) m s) (run (Rolling1588TickGap.forward d 45 (376+n)) stockTape s) (StockRowVector.rows x p):=by let s:=pullState (OB5.sig 44) raw have result:=StockStrongChain.result d x good raw m stage have old:=StockBaseline.comparison d x good raw _ m stage result.2.1 have new:=norm raw m stage have eq:Same _ _:=⟨new.1.trans old.1.symm,fun q off=>(new.2 q off).trans (old.2 q off).symm⟩ have h:=StockRowVector.binding d x good raw _ m stage result.2.1 eq have onward:=h.through (Rolling1588TickGap.forward d 421 n) (fun q h=>(safe d 421 n (by decide) bound q h).1) (m.drop (measurementCount (Shadow20.MixedWindow.forwardMixedCut d))) simp only [forwardEnd,StairRestSupport.forward_append d 376 45 n,run_append,run_take] rw [←suffix_independent d n x good bound raw stage (m.drop (measurementCount (Shadow20.MixedWindow.forwardMixedCut d))) m (stockTape.drop (measurementCount (Rolling1588TickGap.forward d 45 376))) stockTape] exact onward end ECDSAAdd.Entrant.StairPacket.StockWalkWindow end section namespace ECDSAAdd.Entrant.StairPacket.StockPlacedWindow open Arithmetic MappedCompressed Secp256k1 WideReference StockArchiveBanks StockWalkPrefix StockWalkWindow set_option maxRecDepth 12000 set_option maxHeartbeats 2500000 attribute [local irreducible] run Rolling1588TickGap.forward Rolling1588.Integer.regularForward measurementCount Shadow20.MixedWindow.forwardMixedCut theorem fixed:∀(b:Bank)(j:Fin 16),Stair44WalkMap.rest (siteAt b j)=siteAt b j:=by intro b j; rw [site_eq]; exact Shadow20.MixedGeo.fixed_rest b j theorem unplace {d x a s rows} (pair:Paired d x (pullState Stair44WalkMap.rest a) (pullState Stair44WalkMap.rest s) rows):Paired d x a s rows:=by refine ⟨⟨pair.equality.1,?_⟩,pair.labels,?_,?_⟩ · intro q off have safe:Stair44WalkMap.rest.symm q∉archives:=by intro hit obtain ⟨b,j,e⟩:=bank_rep _ hit apply off have same:=congrArg Stair44WalkMap.rest e rw [fixed,Equiv.apply_symm_apply] at same exact same ▸ (StockArchiveBanks.mem b j) simpa only [pullState,Equiv.apply_symm_apply] using pair.equality.2 _ safe · intro b j change a.basis (siteAt b j)=_ rw [←fixed b j] exact pair.custom b j · intro b j rw [←fixed b j] exact pair.stock b j theorem old_split (d:Bool) (n:Nat):Stair44WalkRun.forward d (405+n)= first d++renameProgram Stair44WalkMap.rest (Rolling1588TickGap.forward d 45 (376+n)):=by have e:=StairRestSupport.forward_append d 29 16 (376+n) change Rolling1588TickGap.forward d 16 (29+(376+n))=Rolling1588TickGap.forward d 16 29++Rolling1588TickGap.forward d 45 (376+n) at e rw [show 405+n=29+(376+n) by omega] simp only [Stair44WalkRun.forward,first,e,renameProgram,List.map_append,List.append_assoc] theorem forward (d:Bool) (n x:Nat) (good:Bounds x p) (bound:421+n≤512) (s a:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 1 s.basis) (input:pullState Stair44WalkMap.first a=s) (norm:NewNormalized d x): Paired d x (run (WindowWalkCosts.forward d n) m a) (run (Stair44WalkRun.forward d (405+n)) m a) (StockRowVector.rows x p):=by let t:=m.drop (measurementCount (first d)) have rel:=window d n x good bound (regular d s m) (cut120 d x good s a m stage input).1 t t norm apply unplace rw [placed d n x good s a m stage input,old_split,run_append,run_take,run_rename _ Stair44WalkMap.rest.injective,(cut120 d x good s a m stage input).2] exact rel end ECDSAAdd.Entrant.StairPacket.StockPlacedWindow end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StockArchiveBanks StairArchiveRelease WindowFieldMask set_option maxRecDepth 30000 set_option maxHeartbeats 3500000 /-- Field bank of the ship's bank `b` (22 mixed 15/20-tick archive banks). -/ def groupId (b:Bank):Nat:=Shadow20.MixedGeo.groupId b def parityPort (b:Bank) (i:Fin 16):Wire:=OB5.sig 511 (NewHistory5.payloadWire base (8*groupId b+i.val)) theorem native_ports:∀(b:Bank)(i:Fin 16),parityPort b i=siteAt b i:=by intro b i; rw [site_eq]; exact Shadow20.MixedGeo.parity_ports b i theorem host_ports:∀(b:Bank)(i:Fin 16),Rolling1588Lifetime.phaseHost (siteAt b i)=siteAt b i:=by intro b i; rw [site_eq]; exact Shadow20.MixedGeo.fixed_phaseHost b i theorem field_ports:∀(b:Bank)(i:Fin 16),fieldPort (groupId b) i.val=siteAt b i:=by intro b i; rw [site_eq]; exact Shadow20.MixedGeo.field_ports b i theorem whole_iff (q:Wire):q∈allBanks ↔ q∈archives := by have hb : bankIds = Shadow20.MixedGeo.bankIds := rfl simp only [allBanks, archives, hb] exact Shadow20.MixedGeo.whole_iff q end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.StockInverseReplay open Arithmetic MappedCompressed Secp256k1 WideReference StockArchiveBanks StockWalkWindow StockPlacedWindow set_option maxRecDepth 11000 set_option maxHeartbeats 3000000 attribute [local irreducible] run measurementCount Rolling1588TickGap.forward Rolling1588.reverse Rolling1588.Integer.regularForward Rolling1588.Integer.regularReverse Shadow20.MixedWindow.forwardMixedCut TickCut.Mixed.reverse abbrev pool := (skywalkPoolWires base).toFinset def poolEq (a b:State):Prop:=∀q∈pool,a.basis q=b.basis q theorem reverse_forward (d:Bool) (x:Nat) (good:Bounds x p) (i n:Nat) (lo:1 ≤ i) (hi:i+n≤512) (raw:State) (m r:List Bool) (st:Rolling1588.Integer.Stage base d x p i raw.basis): let start:=pullState (OB5.sig (i-1)) raw run (Rolling1588.reverse d i n) r (run (Rolling1588TickGap.forward d i n) m start)=start:=by dsimp only let v:=run (Rolling1588.Integer.regularForward base d i n) m raw obtain ⟨hp0,odd,cap,cop⟩:=StackOB5.prime_facts x good.nonzero good.small have one:=Rolling1588TickGap.forward_gen d x good.nonzero good.small n i lo hi raw m st have two:=(Rolling1588.Integer.reverse_gen d x good.nonzero good.small n i lo hi raw m v r st (fun _ _=>rfl)).1 rw [Rolling1588.Integer.reverse_eq_packets] at two have undo:=Rolling1588.Integer.regularReverse_roundtrip base d base_pool_nodup StackOB5.historyAbove x p hp0 good.nonzero odd cap (by norm_num [p]) good.small cop n i hi raw m r st exact (congrArg (run (Rolling1588.reverse d i n) r) one).trans (two.trans (congrArg (pullState (OB5.sig (i-1))) undo)) theorem paired_pool {d x rows a ref b old} (actual:Paired d x a ref rows) (ghost:Paired d x b old rows) (agree:poolEq ref old):poolEq a b:=by intro q hq by_cases h:q∈archives · obtain ⟨k,j,rfl⟩:=bank_rep q h exact (actual.custom k j).trans (ghost.custom k j).symm · exact (actual.equality.2 q h).trans ((agree q hq).trans (ghost.equality.2 q h).symm) theorem replay (P Q:Program) (m:List Bool) (a ref b old origin:State) (A:wires P⊆pool) (B:wires Q⊆pool) (outside:∀q∉pool,a.basis q=ref.basis q) (phase:a.phase=ref.phase) (gp:b.phase=old.phase) (h1:poolEq a b) (h2:poolEq ref old) (one:run P m b=origin) (two:run Q m old=origin): run P m a=run Q m ref:=by have frame (h:poolEq a b):∀q∈wires P,a.basis q=b.basis q:=fun q hq=>h q (A hq) have left:=run_local_increment P a b m (frame h1) have right:=run_local_increment Q ref old m (fun q hq=>h2 q (B hq)) rw [one] at left rw [two] at right apply State.extensionality · have h:=(left.1.trans (congrArg (fun v:Bool=>origin.phase ^^ v) gp)).trans right.1.symm rw [phase] at h cases ref.phase <;> simpa using h · funext q by_cases u:q∈pool · have output (C:Program) (ac gh:State) (g:poolEq ac gh) (h:run C m gh=origin) (eq:∀q∈wires C,(run C m ac).basis q=origin.basis q): (run C m ac).basis q=origin.basis q:=by by_cases use:q∈wires C · exact eq q use · rw [←h,run_preserves_outside C m ac q use,run_preserves_outside C m gh q use] exact g q u exact (output P a b h1 one left.2).trans (output Q ref old h2 two right.2).symm · rw [run_preserves_outside P m a q (fun hit=>u (A hit)),run_preserves_outside Q m ref q (fun hit=>u (B hit))] exact outside q u theorem archives_pool (q:Wire) (hit:q∈archives):q∈pool:=by obtain ⟨b,j,rfl⟩:=bank_rep q hit have good:∀(b:Bank)(j:Fin 16),16≤siteAt b j ∧ siteAt b j≤1812:=by decide +kernel exact List.mem_toFinset.mpr (PartialSites.range_pool _ (good b j).1 (good b j).2) end ECDSAAdd.Entrant.StairPacket.StockInverseReplay end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StockArchiveBanks StairArchiveRelease WindowFieldMask CodecBitSliceVerify ArchivePortAction set_option maxRecDepth 30000 set_option maxHeartbeats 3000000 def fieldRows (r:Bank→Nat) (j:Nat):Nat:=Shadow20.MixedGeo.fieldRows r j theorem rowsAt (r:Bank→Nat) (b:Bank):fieldRows r (groupId b)=r b:= Shadow20.MixedGeo.rowsAt r b theorem idAt : ∀j∈bankIds,∃b:Bank,groupId b=j:=Shadow20.MixedGeo.idAt theorem enterCode (d:Bool) (j:Nat): (code d).take 16=(WindowFieldJourney.initialCode d j).take 16:=by cases d · simpa only [code,List.take_take,Nat.min_self] using StairArchiveHandoff.archive_edges.2.1 · simpa only [code,List.take_take,Nat.min_self] using StairArchiveHandoff.archive_edges.1 theorem fits {d x a s rows} (pair:Paired d x a s rows): Fits (fieldRows rows) (WindowFieldJourney.initialCode d) a s := by refine ⟨pair.equality.1,fun q h=>pair.equality.2 q (fun hit=>h ((whole_iff q).mpr hit)),?_⟩ intro j hj q hq obtain ⟨b,rfl⟩:=idAt j hj let i:Fin 16:=⟨q,Finset.mem_range.mp hq⟩ rw [rowsAt] have h:=pair.custom b i rw [show fieldPort (groupId b) q=siteAt b i from field_ports b i] exact h.trans (StairArchiveHandoff.wires_eq _ _ 16 (enterCode d _) q _ i.isLt) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.StockBackWindow open Arithmetic MappedCompressed Secp256k1 WideReference StockArchiveBanks StockWalkWindow StockInverseReplay set_option maxRecDepth 10000 set_option maxHeartbeats 3000000 attribute [local irreducible] run measurementCount Rolling1588TickGap.forward Rolling1588.reverse Rolling1588.Integer.regularForward Shadow20.MixedWindow.forwardMixedCut TickCut.Mixed.reverse def real (d:Bool) (raw:State):State:=run (Shadow20.MixedWindow.forwardMixedCut d) [] (pullState (OB5.sig 44) raw) def stock (d:Bool) (raw:State):State:=run (Rolling1588TickGap.forward d 45 376) [] (pullState (OB5.sig 44) raw) theorem shadow (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) (norm:NewNormalized d x): Paired d x (real d raw) (stock d raw) (StockRowVector.rows x p):=by have e:=norm raw [] stage have res:=StockStrongChain.result d x good raw [] stage have cmp:=StockBaseline.comparison d x good raw _ [] stage res.2.1 exact StockRowVector.binding d x good raw _ [] stage res.2.1 ⟨e.1.trans cmp.1.symm,fun q off=>(e.2 q off).trans (cmp.2 q off).symm⟩ theorem candidate_undo (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis): run (TickCut.Mixed.reverse d) m (real d raw)=pullState (OB5.sig 44) raw:= (StockStrongChain.result d x good raw [] stage).2.2 m theorem stock_undo (d:Bool) (x:Nat) (good:Bounds x p) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis): run (Rolling1588.reverse d 45 376) m (stock d raw)=pullState (OB5.sig 44) raw:= reverse_forward d x good 45 376 (by decide) (by decide) raw [] m stage attribute [local irreducible] real stock poolEq theorem inner (d:Bool) (x:Nat) (good:Bounds x p) (raw a ref:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) (norm:NewNormalized d x) (pair:Paired d x a ref (StockRowVector.rows x p)) (agree:poolEq ref (stock d raw)): run (TickCut.Mixed.reverse d) m a=run (Rolling1588.reverse d 45 376) m ref:=by have ghost:=shadow d x good raw stage norm exact replay _ _ m a ref (real d raw) (stock d raw) _ (PartialSites.pool_partial d) (PartialSites.pool_old d 45 376 (by decide) (by decide)) (fun q off=>pair.equality.2 q (fun h=>off (archives_pool q h))) pair.equality.1 ghost.equality.1 (paired_pool pair ghost agree) agree (candidate_undo d x good raw m stage) (stock_undo d x good raw m stage) theorem pool_run {C:Program} (cover:wires C⊆pool) {a b} (h:poolEq a b) (m:List Bool):poolEq (run C m a) (run C m b):=by unfold poolEq at h ⊢ have use:=run_local_increment C a b m (fun q hq=>h q (cover hq)) intro q hq by_cases hit:q∈wires C · exact use.2 q hit · rw [run_preserves_outside C m a q hit,run_preserves_outside C m b q hit] exact h q hq private theorem transport (F R:Program) (m:List Bool) (a b:State) (eq:a=b) (inv:run R m (run F [] b)=b): run R m (run F [] a)=a:=eq ▸ inv theorem stageAt (d:Bool) (x:Nat) (good:Bounds x p) (i n:Nat) (hi:i+n≤512) (raw:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p i raw.basis): Rolling1588.Integer.Stage base d x p (i+n) (run (Rolling1588.Integer.regularForward base d i n) m raw).basis:=by obtain ⟨hp0,odd,cap,cop⟩:=StackOB5.prime_facts x good.nonzero good.small exact (Rolling1588.Integer.regularForward_spec base d base_pool_nodup StackOB5.historyAbove x p i n hp0 good.nonzero odd cap (by norm_num [p]) good.small cop hi raw m stage).2 theorem tail_cancel (d:Bool) (x i h n:Nat) (good:Bounds x p) (lo:1 ≤ i) (bound:i+h+n≤512) (raw:State) (stage:Rolling1588.Integer.Stage base d x p i raw.basis) (m:List Bool): let s:=pullState (OB5.sig (i-1)) raw let old:=run (Rolling1588TickGap.forward d i h) [] s run (Rolling1588.reverse d (i+h) n) m (run (Rolling1588TickGap.forward d (i+h) n) [] old)=old:=by let t:=run (Rolling1588.Integer.regularForward base d i h) [] raw have cut:i+h≤512:=by omega have st:=stageAt d x good i h cut raw [] stage have eq:=Rolling1588TickGap.forward_gen d x good.nonzero good.small h i lo cut raw [] stage exact transport _ _ _ _ _ eq (reverse_forward d x good (i+h) n (by omega) bound t [] m st) def backwards (d:Bool) (n:Nat):Program:=Rolling1588.reverse d 421 n++TickCut.Mixed.reverse d theorem result (d:Bool) (n x:Nat) (good:Bounds x p) (bound:421+n≤512) (raw a ref:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) (norm:NewNormalized d x) (pair:Paired d x a ref (StockRowVector.rows x p)) (agree:poolEq ref (run (Rolling1588TickGap.forward d 45 (376+n)) [] (pullState (OB5.sig 44) raw))): run (backwards d n) m a=run (Rolling1588.reverse d 45 (376+n)) m ref:=by have h:=pair.through (Rolling1588.reverse d 421 n) (fun q hq=>(safe d 421 n (by decide) bound q hq).2) m have pools:=pool_run (PartialSites.pool_old d 421 n (by decide) bound) agree m simp only [StairRestSupport.forward_append d 376 45 n,run_append,run_take,List.drop_nil] at pools rw [tail_cancel d x 45 376 n good (by decide) bound raw stage m] at pools simp only [backwards,StairRestSupport.reverse_append d 376 45 n,run_append,run_take] apply inner d x good raw _ _ _ stage norm h unfold stock exact pools end ECDSAAdd.Entrant.StairPacket.StockBackWindow end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StockArchiveBanks StairArchiveRelease WindowFieldMask CodecBitSliceVerify ArchivePortAction WindowFieldJourney set_option maxRecDepth 25000 set_option maxHeartbeats 3200000 def Fixed (f:Wire→Wire):Prop:=∀b i,f (siteAt b i)=siteAt b i theorem archive_pre {f:Wire→Wire} (inj:Function.Injective f) (fix:Fixed f) (q:Wire) (off:q∉archives):f q∉archives:=by intro hit obtain ⟨b,i,e⟩:=StockArchiveBanks.bank_rep _ hit have eq:=inj ((fix b i).trans e) exact off (eq ▸ (StockArchiveBanks.mem b i)) theorem pairPull (f:Wire→Wire) (inj:Function.Injective f) (fix:Fixed f) {d x rows a r} (pair:Paired d x a r rows):Paired d x (pullState f a) (pullState f r) rows:=by refine ⟨⟨pair.equality.1,fun q h=>pair.equality.2 _ (archive_pre inj fix q h)⟩,pair.labels,?_,?_⟩ · intro b i change a.basis (f (siteAt b i))=_ rw [fix];exact pair.custom b i · intro b i change r.basis (f (siteAt b i))=_ rw [fix];exact pair.stock b i theorem fitsPull (f:Wire→Wire) (inj:Function.Injective f) (fix:Fixed f) {rows cs a r} (ff:Fits rows cs a r):Fits rows cs (pullState f a) (pullState f r):=by refine ⟨ff.phase,?_,?_⟩ · intro q off exact ff.outside _ (fun hit=>archive_pre inj fix q (fun h=>off ((whole_iff q).mpr h)) ((whole_iff _).mp hit)) · intro j hj q hq obtain ⟨b,rfl⟩:=idAt _ hj let i:Fin 16:=⟨q,Finset.mem_range.mp hq⟩ have fx:f (fieldPort (groupId b) q)=fieldPort (groupId b) q:=by change f (fieldPort (groupId b) i.val)=_;rw [field_ports,fix] change a.basis (f (fieldPort (groupId b) q))=_ rw [fx];exact ff.bytes _ hj _ hq theorem completeCode (d:Bool) (b:Bank): (finalCode d (plan d) (initialCode d) (groupId b)).take 16=(code (!d)).take 16:=by have toward:∀(d:Bool)(b:Bank),(finalCode d (plan d) (initialCode d) (groupId b)).take 16= (outputCols (StairArchiveNativeCut.leave (!d))).take 16:=by decide +kernel rw [toward] cases d · exact StairArchiveHandoff.archive_edges.2.2.2.2.2.2.2.trans ((enterCode true (groupId b)).symm) · exact StairArchiveHandoff.archive_edges.2.2.2.2.2.2.1.trans ((enterCode false (groupId b)).symm) theorem pairFinished {d x rows a r} (ff:Fits (fieldRows rows) (finalCode d (plan d) (initialCode d)) a r) (labels:∀b,rows b<63145 ∧ ArchiveStockRows.Chronology (tick b) x p (rows b)) (old:∀b,nativeAt (!d) b (rows b) r):Paired (!d) x a r rows:=by refine ⟨⟨ff.phase,fun q h=>ff.outside q (fun hit=>h ((whole_iff q).mp hit))⟩,labels,?_,old⟩ intro b i have pick:∀b:Bank,groupId b∈bankIds:=by decide +kernel have v:=ff.bytes _ (pick b) i.val (Finset.mem_range.mpr i.isLt) rw [field_ports b i,rowsAt] at v exact v.trans (StairArchiveHandoff.wires_eq _ _ 16 (completeCode d b) i.val _ i.isLt) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.StockPlacedBack open Arithmetic MappedCompressed Secp256k1 WideReference StockArchiveBanks StockWalkWindow StockInverseReplay FlagEntry set_option maxRecDepth 12000 set_option maxHeartbeats 3000000 attribute [local irreducible] run measurementCount Rolling1588TickGap.forward Rolling1588.reverse TickCut.Mixed.reverse theorem pull {d x a s rows} (h:Paired d x a s rows): Paired d x (pullState Stair44WalkMap.rest a) (pullState Stair44WalkMap.rest s) rows:=by refine ⟨⟨h.equality.1,?_⟩,h.labels,?_,?_⟩ · intro q off apply h.equality.2 intro hit obtain ⟨b,j,atSite⟩:=StockArchiveBanks.bank_rep _ hit have eq:siteAt b j=q:=Stair44WalkMap.rest.injective ((StockPlacedWindow.fixed b j).trans atSite) exact off (eq ▸ (StockArchiveBanks.mem b j)) · intro b j change a.basis (Stair44WalkMap.rest (siteAt b j))=_ rw [StockPlacedWindow.fixed] exact h.custom b j · intro b j change s.basis (Stair44WalkMap.rest (siteAt b j))=_ rw [StockPlacedWindow.fixed] exact h.stock b j def R (P:Program):Program:=renameProgram Stair44WalkMap.rest P def remaining (d:Bool):Program:=R (Rolling1588.reverse d 16 29)++renameProgram Stair44WalkMap.first (Rolling1588.reverse d 1 15) theorem split (d:Bool) (n:Nat):WindowWalkCosts.backward d n=R (StockBackWindow.backwards d n)++remaining d:=by simp only [WindowWalkCosts.backward,StockBackWindow.backwards,R,remaining,renameProgram,List.map_append,List.append_assoc] theorem old_split (d:Bool) (n:Nat):Stair44WalkRun.backward d (405+n)=R (Rolling1588.reverse d 45 (376+n))++remaining d:=by have e:=StairRestSupport.reverse_append d 29 16 (376+n) change Rolling1588.reverse d 16 (29+(376+n))=Rolling1588.reverse d 45 (376+n)++Rolling1588.reverse d 16 29 at e rw [show 405+n=29+(376+n) by omega] simp only [remaining,Stair44WalkRun.backward,e,R,renameProgram,List.map_append,List.append_assoc] theorem backward (d:Bool) (n x:Nat) (good:Bounds x p) (bound:421+n≤512) (raw a ref:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 45 raw.basis) (norm:NewNormalized d x) (pair:Paired d x a ref (StockRowVector.rows x p)) (agree:poolEq (pullState Stair44WalkMap.rest ref) (run (Rolling1588TickGap.forward d 45 (376+n)) [] (pullState (OB5.sig 44) raw))): ∃old,run (WindowWalkCosts.backward d n) m a=run (Stair44WalkRun.backward d (405+n)) old ref:=by let A:=R (StockBackWindow.backwards d n) let B:=R (Rolling1588.reverse d 45 (376+n)) let tail:=m.drop (measurementCount A) have eq:run A m a=run B m ref:=by apply MappedCompressed.pullState_perm_injective Stair44WalkMap.rest simp only [A,B,R,run_rename _ Stair44WalkMap.rest.injective] exact StockBackWindow.result d n x good bound raw _ _ m stage norm (pull pair) agree refine ⟨pfx (measurementCount B) m++tail,?_⟩ rw [split,old_split,Stair44PointSecond.joinRecords] rw [run_append,run_take] exact congrArg (run (remaining d) tail) eq end ECDSAAdd.Entrant.StairPacket.StockPlacedBack end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StockArchiveBanks WindowFieldMask CodecBitSliceVerify open StairOuterPlacement StairField2V3Seg set_option maxRecDepth 25000 set_option maxHeartbeats 1800000 attribute [local irreducible] run def fieldEquiv:Equiv.Perm Wire:=⟨fieldPlace,fieldPlaceInv,inv_fieldPlace,fieldPlace_inv⟩ theorem fieldFix:Fixed fieldEquiv:=by unfold Fixed; decide +kernel theorem phaseFix:Fixed Rolling1588Lifetime.phaseHost:=host_ports theorem inverseFix {f:Equiv.Perm Wire} (fixed:Fixed f):Fixed f.symm:=by intro b i exact f.injective (by rw [Equiv.apply_symm_apply,fixed b i]) theorem pairUnpull (f:Equiv.Perm Wire) (fix:Fixed f) {d x rows a r} (pair:Paired d x (pullState f a) (pullState f r) rows):Paired d x a r rows:=by have h:=pairPull f.symm f.symm.injective (inverseFix fix) pair rwa [Stair44PlacedHead.unpull,Stair44PlacedHead.unpull] at h theorem fitsUnpull (f:Equiv.Perm Wire) (fix:Fixed f) {rows cs a r} (ff:Fits rows cs (pullState f a) (pullState f r)):Fits rows cs a r:=by have h:=fitsPull f.symm f.symm.injective (inverseFix fix) ff rwa [Stair44PlacedHead.unpull,Stair44PlacedHead.unpull] at h theorem hosted {rows cs A B a r m n} (ff:Fits rows cs (run A m (pullState fieldEquiv a)) (run B n (pullState fieldEquiv r))): Fits rows cs (run (renameProgram fieldEquiv A) m a) (run (renameProgram fieldEquiv B) n r):=by apply fitsUnpull fieldEquiv fieldFix rwa [run_rename _ fieldEquiv.injective,run_rename _ fieldEquiv.injective] theorem placedShape (A:Program):StairSchedule.fieldRename (renameProgram Prefix1590.borrow A)=renameProgram fieldEquiv A:=by simp only [StairSchedule.fieldRename,StairSchedule.parityRename,renameProgram_comp] rfl end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.StockWalkEndpoints open Arithmetic MappedCompressed Secp256k1 WideReference StockArchiveBanks StockPlacedWindow StockInverseReplay StockWalkPrefix set_option maxRecDepth 14000 set_option maxHeartbeats 2500000 attribute [local irreducible] run measurementCount Rolling1588TickGap.forward Rolling1588.reverse Rolling1588.Integer.regularForward theorem bounds (x:Nat) (nz:0 < x) (lt:x first | exact h | exact List.mem_toFinset.mpr (OB5.base_pool _ (by decide)) theorem fixed_old (d:Bool) (n x:Nat) (good:Bounds x p) (atCut:421+n∈[425,505,506]) (s:State) (stage:Rolling1588.Integer.Stage base d x p 1 s.basis) (m:List Bool): let v:=run (Rolling1588TickGap.forward d 1 (420+n)) m s pullState Stair44WalkMap.rest v=v:=by let a:=pullState Stair44WalkMap.first.symm s have input:pullState Stair44WalkMap.first a=s:=Stair44PlacedHead.unpull Stair44WalkMap.first.symm s have num:15+(405+n)=420+n:=by omega have cut:1+(15+(405+n))∈[425,505,506]:=by simpa only [show 1+(15+(405+n))=421+n by omega] using atCut have one:=Stair44WalkRun.forward_run d (405+n) x good.nonzero good.small s a m stage input have two:=Stair44WalkCuts.forward_done d (405+n) x cut good.nonzero good.small s a m stage input rw [two,num] at one exact one theorem decompose (d:Bool) (x n:Nat) (good:Bounds x p) (s:State) (m:List Bool) (stage:Rolling1588.Integer.Stage base d x p 1 s.basis) (bound:421+n≤512): let raw:=regular d s [] run (Rolling1588TickGap.forward d 1 (420+n)) m s= run (Rolling1588TickGap.forward d 45 (376+n)) [] (pullState (OB5.sig 44) raw):=by have init:pullState (OB5.sig 0) s=s:=by apply State.extensionality _ s · rfl · funext q;exact congrArg s.basis (OB5.sig_zero q) have same:=StockWalkWindow.steady d x good 1 (420+n) (by decide) (by omega) s m [] stage rw [show 1-1=0 from rfl,init] at same have cut:=Rolling1588TickGap.forward_gen d x good.nonzero good.small 44 1 (by decide) (by decide) s [] stage rw [show 1-1=0 from rfl,init] at cut have shape:420+n=44+(376+n):=by omega rw [same,shape,StairRestSupport.forward_append d 44 1 (376+n),run_append,run_take,List.drop_nil,cut] rfl theorem move {f:Wire→Wire} (a b c:State) (mem:∀q∈pool,f q∈pool) (eq:poolEq a b) (fixed:pullState f b=b) (next:b=c):poolEq (pullState f a) c:=by intro q hq exact (eq _ (mem q hq)).trans ((congrArg (fun s:State=>s.basis q) fixed).trans (congrArg (fun s:State=>s.basis q) next)) theorem endpoint_stage (d:Bool) (x:Nat) (good:Bounds x p) (s:State) (stage:Rolling1588.Integer.Stage base d x p 1 s.basis): Rolling1588.Integer.Stage base d x p 45 (regular d s []).basis:=StockBackWindow.stageAt d x good 1 44 (by decide) s [] stage theorem endpoint_pool (d:Bool) (n x:Nat) (good:Bounds x p) (atCut:421+n∈[425,505,506]) (s ref:State) (enc:List Bool) (stage:Rolling1588.Integer.Stage base d x p 1 s.basis) (bound:421+n≤512) (agree:poolEq ref (run (Rolling1588TickGap.forward d 1 (420+n)) enc s)): poolEq (pullState Stair44WalkMap.rest ref) (run (Rolling1588TickGap.forward d 45 (376+n)) [] (pullState (OB5.sig 44) (regular d s []))):= move _ _ _ rest_pool agree (fixed_old d n x good atCut s stage enc) (decompose d x n good s enc stage bound) theorem closed (d:Bool) (n x:Nat) (nz:0 < x) (lt:xcongrArg (fun u:State=>u.basis q) eq⟩ private theorem transfer {v old target:State} (e:pullState phaseHost old=target) (h:v.phase=old.phase ∧ ∀q∈skywalkPoolWires base,v.basis q=old.basis q): (pullState phaseHost v).phase=target.phase ∧ ∀q∈skywalkPoolWires base,(pullState phaseHost v).basis q=target.basis q:=by subst target exact ⟨h.1,fun q hq=>h.2 _ (Stair44DivTerm.host_pool q hq)⟩ theorem div_pool {t:State} (F:EntryFrame t) (m:List Bool): let v:=run (divLead++fieldD) m t let want:=run (Rolling1588TickGap.firstPhase false) [] t (pullState phaseHost v).phase=want.phase ∧ ∀q∈skywalkPoolWires base,(pullState phaseHost v).basis q=want.basis q:=by dsimp only rw [beforeD F] have first:=StairLoanField7Values.first_phase_hosted false F.sharedNodup F.historyAbove F.x _ F.x_pos F.x_lt t [] (StairField13V3Clean.entryInput F) have before:=run_rename phaseHost phaseHost.injective (Rolling1588TickGap.firstPhase false) [] t change pullState phaseHost (run (renameProgram phaseHost (Rolling1588TickGap.firstPhase false)) [] t)=_ at before rw [first,StairField13V3Clean.pull_phaseHost_entry F] at before exact transfer before (Stair44DivisionCut.pool F m) theorem regular_endpoint (d:Bool) (x i:Nat) (nz:0 < x) (lt:xs.basis (siteAt b j)) same.symm).trans (pair.stock b j)) theorem div_native {s:State} (F:StairConcreteAssembly.EntryFrame s) (m:List Bool): Native false F.x (pullState phaseHost (run oldDivHead m s)):= ofEndpoint false 85 F.x F.x_pos F.x_lt (by decide) _ (div_endpoint F m) theorem mul_native (k:Nat) {s:State} (F:StairConcreteAssembly.ExitFrame k s) (m:List Bool): Native true F.x (pullState phaseHost (run oldMulHead m s)):= ofEndpoint true 4 F.x F.x_pos F.x_lt (by decide) _ (mul_endpoint k F m) end ECDSAAdd.Entrant.StairPacket.WindowEndBytes end section namespace ECDSAAdd.Entrant.StairPacket.WindowMiddlePieces open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly Rolling1588Lifetime FlagEntry StockArchiveBanks open WindowMiddleContract WindowStartStates set_option maxRecDepth 14000 set_option maxHeartbeats 2000000 attribute [local irreducible] run measurementCount renameProgram end ECDSAAdd.Entrant.StairPacket.WindowMiddlePieces end section namespace ECDSAAdd.Entrant.Stair44PointDivision open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines ControlledPointLayout CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite FlagEntry FlagExit DirectSkywalk ParityUniform ParityEven ParityXEntry FrontierEntry1591Callers Stair44PlacedHead set_option maxHeartbeats 3500000 set_option maxRecDepth 20000 attribute [local irreducible] run measurementCount fastConstAdd fusedY def reference (kx ky : Fp) := fastConstAdd layout layout.point.x kx ++ fusedY layout ky theorem standardHead (cx cy X Y : Fp) (G : Bool) (s : State) (m : List Bool) (v : PointDialogValues layout X Y G s.basis s.basis) : let e := if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val+(-cx).val) else false run (entryYAll layout (-cy) ++ entryXNew layout (pkW layout) (-cx)) m (put s (pkW layout) e) = run (E1QubitPlacement.tickF layout) [] (run (reference (-cx) (-cy)) [] s) := by intro e have a := (StairCallerEntry.head_pad_rest layout layout_widths layout_nodup cx cy X Y [] s v.x v.y v.clean (by decide +kernel)).run_eq m have b := StairCallerEntry.stageAll_eq_ref layout layout_widths layout_nodup X Y (-cx) (-cy) [] s (padE layout cy cx m) v.x v.y v.clean have c := E1QubitPlacement.entry1_eq layout layout_widths layout_nodup (-cx) (-cy) s X.val X.isLt Y G v.x v.y v.generic v.clean (padE layout cy cx m) [] simp only [List.append_nil] at a b rw [a,b,c,run_append,List.take_nil,List.drop_nil,reference] theorem prepClean (kx ky X Y : Fp) (G : Bool) (s : State) (v : PointDialogValues layout X Y G s.basis s.basis) : regValue layout.dialogPool (run (reference kx ky) [] s).basis=0 := by let P := fastConstAdd layout layout.point.x kx have u := fastStep_addX layout layout_widths layout_nodup X Y G s.basis kx s [] v have f := fusedY_correct layout layout_widths layout_nodup Y ky (run P [] s) [] u.2.y u.2.clean rw [reference,run_append,List.take_nil,List.drop_nil] exact (regValue_congr _ _ (run P [] s).basis (fun q hq => f.2.2 q (((E1QubitPlacement.lay layout layout_widths layout_nodup q).2.1 hq).2))).trans u.2.clean end ECDSAAdd.Entrant.Stair44PointDivision end section namespace ECDSAAdd.Entrant.StairPacket.PartialSites open Arithmetic MappedCompressed Partial set_option maxRecDepth 20000 attribute [local irreducible] wires domain theorem forward_domain (d : Bool) : ∀ q ∈ wires (Shadow20.MixedWindow.forwardMixedCut d), domain q = true := by intro q h rw [domain_eq] exact (Shadow20.MixedWindow.mixedCut_covered d).1 q h end ECDSAAdd.Entrant.StairPacket.PartialSites namespace ECDSAAdd.Entrant.StairPacket.WindowIntegerSites open Arithmetic MappedCompressed StairSemanticFinal Stair44WalkMap PartialSites WindowKernelPrograms open DirectSkywalk StairConcreteAssembly Stair44Kernel set_option maxRecDepth 12000 attribute [local irreducible] wires renameProgram private theorem swap (a b:Nat) (ha:a<2314) (hb:b<2314):PreservesCaller (Equiv.swap (base a) (base b)):= preserves_swap _ _ (base_mem_caller _ (Or.inl ha)) (base_mem_caller _ (Or.inl hb)) theorem firstOK:PreservesCaller Stair44WalkMap.first:=by unfold Stair44WalkMap.first Stair44WalkMap.shared repeat' apply preserves_perm_trans all_goals exact swap _ _ (by decide) (by decide) theorem restOK:PreservesCaller Stair44WalkMap.rest:=by unfold Stair44WalkMap.rest Stair44WalkMap.shared repeat' apply preserves_perm_trans all_goals exact swap _ _ (by decide) (by decide) theorem range_ok (q:Nat) (use:PartialSites.domain q=true):q∈callerDomain:=by have h:=PartialSites.inside q use have eq:base (q-16)=q:=by change q-16+16=q;exact Nat.sub_add_cancel h.1 exact eq ▸ base_mem_caller (q-16) (Or.inl (by omega)) theorem part (d:Bool):wires (Shadow20.MixedWindow.forwardMixedCut d)⊆callerDomain ∧ wires (TickCut.Mixed.reverse d)⊆callerDomain:= ⟨fun q h=>range_ok q (forward_domain d _ h),fun q h=>range_ok q (reverse_domain d _ h)⟩ theorem forward (d:Bool) (n:Nat) (bound:420+n≤504):wires (WindowWalkCosts.forward d n)⊆callerDomain:=by have stock:=forward_own d (420+n) bound have shape:420+n=15+(29+(376+n)):=by omega rw [shape,tickGap_forward_split d 15 1 (29+(376+n)),tickGap_forward_split d 29 16 (376+n),tickGap_forward_split d 376 45 n] at stock simp only [wires_append,Finset.union_subset_iff] at stock apply wires_sub_of_parts _ _ · exact rename_caller _ firstOK _ stock.1 · apply rename_caller _ restOK exact wires_sub_of_parts _ _ (wires_sub_of_parts _ _ stock.2.1 (part d).1) stock.2.2.2 theorem backward (d:Bool) (n:Nat) (bound:420+n≤505):wires (WindowWalkCosts.backward d n)⊆callerDomain:=by have stock:=reverse_own d (420+n) bound have shape:420+n=15+(29+(376+n)):=by omega rw [shape,reverse_split d 15 1 (29+(376+n)),reverse_split d 29 16 (376+n),reverse_split d 376 45 n] at stock simp only [wires_append,Finset.union_subset_iff] at stock apply wires_sub_of_parts _ _ · apply rename_caller _ restOK exact wires_sub_of_parts _ _ (wires_sub_of_parts _ _ stock.1.1.1 (part d).2) stock.1.2 · exact rename_caller _ firstOK _ stock.2 end ECDSAAdd.Entrant.StairPacket.WindowIntegerSites end end -- ==== begin OddTailPart1 ==== section section set_option autoImplicit false set_option maxRecDepth 20000 set_option maxHeartbeats 4000000 set_option linter.unusedSimpArgs false set_option linter.unusedVariables false namespace ECDSAAdd.Entrant.OddFullPassBridge open ECDSAAdd Arithmetic Challenge MappedCompressed Secp256k1 BalancedField BalancedCircuit open OddFullPass.P1LifeLoan private theorem run_zero_meas (P : Program) (h : measurementCount P = 0) (m n : List Bool) (s : State) : run P m s = run P n s := by induction P generalizing s m n with | nil => rfl | cons g gs ih => cases g with | measureX _ _ _ => simp [measurementCount] at h | X _ | CX _ _ | CCX _ _ _ => exact ih (by simpa [measurementCount] using h) m n _ private theorem meas_X (q : Wire) : measurementCount [.X q] = 0 := rfl attribute [local irreducible] run wires measurementCount OddFullPass.P1LifeLoan.rawAddLoan OddFullPass.P1LifeLoan.foldLoan OddFullPass.P1LifeLoan.unfoldLoan OddFullPass.P1LifeLoan.compareBlockLoan OddFullPass.P1LifeLoan.rawSubLoan OddFullPass.P1LifeLoan.shortConstAddLoan OddFullPass.P1LifeLoan.forwardLoan OddFullPass.P1LifeLoan.inverseLoan OddFullPass.P1LifeLoan.half760OddLoan P1Life.rawAdd P1Life.fold P1Life.unfoldStep P1Life.compare P1Life.rawSub P1Life.shortConstAdd P1Life.forward P1Life.inverse P1Life.half private abbrev L760 : BalancedCircuit.Layout := Q6EndpointCell.ports base (base 2409) private theorem mem_wireBlock_iff (w : Nat → Wire) (s n q : Nat) : q ∈ wireBlock w s n ↔ ∃ i, i < n ∧ q = w (s + i) := by simp only [wireBlock, List.mem_map, List.mem_range'_1] constructor · rintro ⟨k, ⟨h1, h2⟩, hkq⟩; exact ⟨k - s, by omega, by rw [← hkq]; congr 1; omega⟩ · rintro ⟨i, hi, rfl⟩; exact ⟨s + i, ⟨by omega, by omega⟩, rfl⟩ private theorem base_eq_add (k : Nat) : (base k : Nat) = k + 16 := rfl private theorem mem_L760_r_iff (q : Nat) : q ∈ L760.r ↔ 2072 ≤ q ∧ q < 2328 := by simp only [L760, BalancedCleanup.Layout.r, BalancedCleanup.Layout.low, Q6EndpointCell.ports, List.mem_cons, List.mem_append, List.not_mem_nil, or_false, mem_wireBlock_iff] simp only [base_eq_add] constructor · rintro ((rfl | ⟨i, hi, rfl⟩) | rfl) <;> omega · rintro ⟨hlo, hhi⟩ by_cases h0 : q = 2072 · exact Or.inl (Or.inl h0) · by_cases h1 : q = 2327 · exact Or.inr h1 · exact Or.inl (Or.inr ⟨q - 2073, by omega, by omega⟩) private theorem mem_L760_y_iff (q : Nat) : q ∈ L760.y ↔ 786 ≤ q ∧ q < 1042 := by simp only [L760, BalancedCleanup.Layout.y, Q6EndpointCell.ports, List.mem_append, List.mem_cons, List.not_mem_nil, or_false, mem_wireBlock_iff] simp only [base_eq_add] constructor · rintro (⟨i, hi, rfl⟩ | rfl) <;> omega · rintro ⟨hlo, hhi⟩ by_cases h1 : q = 1041 · exact Or.inr h1 · exact Or.inl ⟨q - 786, by omega, by omega⟩ private theorem mem_L760_carry_iff (q : Nat) : q ∈ L760.carry ↔ (528 ≤ q ∧ q < 781) ∨ q = 1556 ∨ q = 1557 ∨ q = 1042 := by simp only [L760, Q6EndpointCell.ports, List.mem_append, List.mem_cons, List.not_mem_nil, or_false, mem_wireBlock_iff] simp only [base_eq_add] constructor · rintro (⟨i, hi, rfl⟩ | h) · exact Or.inl ⟨by omega, by omega⟩ · exact Or.inr h · rintro (⟨h1, h2⟩ | h) · exact Or.inl ⟨q - 528, by omega, by omega⟩ · exact Or.inr h private theorem mem_L760_carry254_iff (q : Nat) : q ∈ L760.carry.take 254 ↔ (528 ≤ q ∧ q < 781) ∨ q = 1556 := by have htake : L760.carry.take 254 = wireBlock base 512 253 ++ [base 1540] := by have hlen : (wireBlock base 512 253).length = 253 := wireBlock_length base 512 253 simp only [L760, Q6EndpointCell.ports, List.take_append, hlen] rfl rw [htake] simp only [List.mem_append, List.mem_cons, List.not_mem_nil, or_false, mem_wireBlock_iff] simp only [base_eq_add] constructor · rintro (⟨i, hi, rfl⟩ | rfl) <;> omega · rintro (⟨h1, h2⟩ | rfl) · exact Or.inl ⟨q - 528, by omega, by omega⟩ · exact Or.inr rfl private theorem L760_carry_away (q : Nat) (hq : q ∈ L760.carry) : q ≠ L760.lower ∧ q ∉ L760.r ∧ q ∉ L760.y := by rw [mem_L760_carry_iff] at hq rw [mem_L760_r_iff, mem_L760_y_iff] have hlo : (L760.lower : Nat) = 1813 := rfl rw [hlo] omega private theorem mem_q6Carry255_drop1_iff (q : Nat) : q ∈ ((Q6Structural.q6Carry L760).take 255).drop 1 ↔ (529 ≤ q ∧ q < 781) ∨ q = 1556 ∨ q = 1813 := by have hshape : ((Q6Structural.q6Carry L760).take 255).drop 1 = wireBlock base 513 252 ++ [base 1540, base 1797] := by have h1 : L760.carry.take 254 = wireBlock base 512 253 ++ [base 1540] := by have hlen : (wireBlock base 512 253).length = 253 := wireBlock_length base 512 253 simp only [L760, Q6EndpointCell.ports, List.take_append, hlen]; rfl have hlen254 : (L760.carry.take 254).length = 254 := by rw [h1]; simp [wireBlock_length] have h2 : (Q6Structural.q6Carry L760).take 255 = L760.carry.take 254 ++ [L760.lower] := by rw [Q6Structural.q6Carry, List.append_assoc, List.take_append, hlen254] rw [List.take_of_length_le (by rw [hlen254]; omega)] rfl rw [h2, h1] simp only [List.append_assoc, List.cons_append, List.nil_append] change (base 512 :: (wireBlock base 513 252 ++ [base 1540, base 1797])).drop 1 = _ rfl rw [hshape] simp only [List.mem_append, List.mem_cons, List.not_mem_nil, or_false, mem_wireBlock_iff] simp only [base_eq_add] constructor · rintro (⟨i, hi, rfl⟩ | h) · exact Or.inl ⟨by omega, by omega⟩ · exact Or.inr h · rintro (⟨h1, h2⟩ | h) · exact Or.inl ⟨q - 529, by omega, by omega⟩ · exact Or.inr h private theorem not_mem_L760_r_of_eq {q : Wire} (n : Nat) (heq : n = q) (hn : ¬(2072 ≤ n ∧ n < 2328)) : q ∉ L760.r := by rw [← heq, mem_L760_r_iff]; exact hn private theorem not_mem_L760_y_of_eq {q : Wire} (n : Nat) (heq : n = q) (hn : ¬(786 ≤ n ∧ n < 1042)) : q ∉ L760.y := by rw [← heq, mem_L760_y_iff]; exact hn private theorem not_mem_L760_carry254_of_eq {q : Wire} (n : Nat) (heq : n = q) (hn : ¬((528 ≤ n ∧ n < 781) ∨ n = 1556)) : q ∉ L760.carry.take 254 := by rw [← heq, mem_L760_carry254_iff]; exact hn private theorem p1Seed_eq : p1Seed L760 = P1Life.p1Seed L760 := rfl private theorem prepareCompare_eq : prepareCompare L760 = P1Life.prepareCompare L760 := rfl private theorem exposure_eq : exposure L760 = P1Life.exposure L760 := rfl private theorem orMajor_eq (a b c : Wire) : orMajor a b c = P1Life.orMajor a b c := rfl private theorem orErase_eq (a b c : Wire) : orErase a b c = P1Life.orErase a b c := rfl private theorem oddEncoding_norm (x : Int) : DirectPass.oddEncoding.normalized x = encodeWord 255 (P1Life.oddNormalized x) := rfl private theorem regValue_singleton_false (w : Wire) (b : BasisState) (h : b w = false) : regValue [w] b = 0 := by simp [regValue, h] private theorem L760_sign_ne_parity : L760.sign ≠ L760.parity := by decide +kernel private theorem L760_sign_ne_lower : L760.sign ≠ L760.lower := by decide +kernel private theorem L760_sign_ne_one : L760.sign ≠ L760.one := by decide +kernel private theorem L760_one_ne_lower : L760.one ≠ L760.lower := by decide +kernel private theorem L760_parity_ne_lower : L760.parity ≠ L760.lower := by decide +kernel private theorem mem_mappedWires_read (ws : List Wire) (q : Wire) (hq : q ∈ mappedWires (mappedRead ws false)) : q ∈ ws := by induction ws with | nil => simp [mappedWires, mappedRead] at hq | cons w ws ih => simp only [mappedRead, mappedWires, List.map_cons, List.flatMap_cons, List.mem_append, Option.toList_some, List.mem_singleton] at hq rcases hq with rfl | hrest · exact List.mem_cons_self .. · exact List.mem_cons_of_mem _ (ih hrest) private theorem hw760 : L760.Widths := Q6EndpointCell.ports_widths base (base 2409) private theorem hn760 : L760.wires.Nodup := Rolling1588Lifetime.half_ports_nodup760 private theorem mem760 : base 760 ∈ (L760.carry.take 254).drop 1 := R2Life760.member760 private theorem pull_swap_invol (a b : Wire) (s : State) : pullState (Equiv.swap a b) (pullState (Equiv.swap a b) s) = s := by apply State.extensionality · rfl · funext q; simp [pullState] private theorem move_run_eq (a b : Wire) (P Q : Program) (s : State) (m n : List Bool) (h : run P m (pullState (Equiv.swap a b) s) = run Q n (pullState (Equiv.swap a b) s)) : run (Q6LifetimeResearch.move a b P) m s = run (Q6LifetimeResearch.move a b Q) n s := by have hp := run_rename (Equiv.swap a b) (Equiv.swap a b).injective P m s have hq := run_rename (Equiv.swap a b) (Equiv.swap a b).injective Q n s have heq : pullState (Equiv.swap a b) (run (Q6LifetimeResearch.move a b P) m s) = pullState (Equiv.swap a b) (run (Q6LifetimeResearch.move a b Q) n s) := hp.trans (h.trans hq.symm) simpa only [pull_swap_invol] using congrArg (pullState (Equiv.swap a b)) heq private theorem replace_mid (A P Q B : Program) (s : State) (m : List Bool) (h : ∀ x, ∃ y, run P x (run A (m.take (measurementCount A)) s) = run Q y (run A (m.take (measurementCount A)) s)) : ∃ n, run (A ++ (P ++ B)) m s = run (A ++ (Q ++ B)) n s := by let t1 := m.take (measurementCount A) let rest := m.drop (measurementCount A) let t2 := rest.take (measurementCount P) let t3 := rest.drop (measurementCount P) obtain ⟨y, hy⟩ := h t2 refine ⟨StairPacket.WindowFieldJourney.joinTapes A t1 (StairPacket.WindowFieldJourney.joinTapes Q y t3), ?_⟩ rw [run_append A (P ++ B), run_append P B, StairPacket.WindowFieldJourney.joined, StairPacket.WindowFieldJourney.joined] exact congrArg (run B t3) hy private theorem replace_last (A P Q : Program) (s : State) (m : List Bool) (h : ∀ x, ∃ y, run P x (run A (m.take (measurementCount A)) s) = run Q y (run A (m.take (measurementCount A)) s)) : ∃ n, run (A ++ P) m s = run (A ++ Q) n s := by simpa only [List.append_nil] using replace_mid A P Q [] s m h private theorem carry_all_zero_of_outside (origin : BasisState) (horig : ∀ q ∈ L760.carry, origin q = false) (b : BasisState) (hclean : DirectPass.CleanExcept (L760.carry.take 254) (base 760) b) (hframe : DirectPass.HalfOutside L760 origin b) (h760 : b (base 760) = false) : ∀ q ∈ L760.carry, b q = false := by intro q hq by_cases htake : q ∈ L760.carry.take 254 · by_cases hq760 : q = base 760 · exact hq760 ▸ h760 · exact hclean q htake hq760 · have hq2 : q = base 1541 ∨ q = base 1026 := by rcases (mem_L760_carry_iff q).mp hq with h1 | h2 | h3 | h4 · exact absurd ((mem_L760_carry254_iff q).mpr (Or.inl h1)) htake · exact absurd ((mem_L760_carry254_iff q).mpr (Or.inr h2)) htake · exact Or.inl h3 · exact Or.inr h4 rcases hq2 with rfl | rfl · exact (hframe _ (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel)).trans (horig _ hq) · exact (hframe _ (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel)).trans (horig _ hq) private theorem rawAddLoan_760_run_eq (d : Nat) (hd : d ≤ 43) (s : State) (m : List Bool) (hready : P1Life.OddRawReady L760 s.basis) (hlow : s.basis L760.lower = false) (hcar : ∀ q ∈ L760.carry, s.basis q = false) : ∃ n, run (rawAddLoan d L760) m s = run (P1Life.rawAdd (base 760) L760) n s := by let a := L760.ylow.getD 0 0 let b := L760.low.getD 0 0 let cs := (Q6Structural.q6Carry L760).take 255 let c := cs.getD 0 0 let clear : Program := [.CX L760.parity b, .CX a b, .X b] let Pre := signComplement L760.sign L760.y ++ orMajor a b c ++ clear let Post := clear.reverse ++ orErase a b c ++ [.CX a b, .X b] ++ signComplement L760.sign L760.y let MidP := Q6LifetimeResearch.move (base 760) b (StairLoan.addPrefixLoan d StairLoan.retiredRoles (L760.ylow.drop 1) (L760.low.drop 1) (cs.drop 1) L760.ymsb L760.rmsb L760.one c) let MidQ := Q6LifetimeResearch.move (base 760) b (StairLoan.addPrefixLoan 0 StairLoan.retiredRoles (L760.ylow.drop 1) (L760.low.drop 1) (cs.drop 1) L760.ymsb L760.rmsb L760.one c) have hshapeP : rawAddLoan d L760 = Pre ++ (MidP ++ Post) := by delta rawAddLoan; simp only [Pre, MidP, Post, a, b, cs, c, clear, List.append_assoc] have hshapeQ : P1Life.rawAdd (base 760) L760 = Pre ++ (MidQ ++ Post) := by delta P1Life.rawAdd; dsimp only rw [show CoherentTail.addPrefix (L760.ylow.drop 1) (L760.low.drop 1) (cs.drop 1) L760.ymsb L760.rmsb L760.one c = StairLoan.addPrefixLoan 0 StairLoan.retiredRoles (L760.ylow.drop 1) (L760.low.drop 1) (cs.drop 1) L760.ymsb L760.rmsb L760.one c from (StairLoan.addPrefixLoan_zero _ _ _ _ _ _ _ _).symm] simp only [Pre, MidQ, Post, a, b, cs, c, clear, orMajor, orErase, P1Life.orMajor, P1Life.orErase, List.append_assoc] rw [hshapeP, hshapeQ] apply replace_mid Pre MidP MidQ Post s m intro x refine ⟨[], ?_⟩ let u := run Pre (m.take (measurementCount Pre)) s have hPreM : measurementCount Pre = 0 := by have hsc : measurementCount (signComplement L760.sign L760.y) = 0 := (signComplement_counts _ _).2 have hom : measurementCount (orMajor a b c) = 0 := by decide +kernel have hcl : measurementCount clear = 0 := by decide +kernel simp only [Pre, measurementCount_append, hsc, hom, hcl] have huEq : u = run clear [] (run (orMajor a b c) [] (run (signComplement L760.sign L760.y) [] s)) := by dsimp only [u] rw [run_zero_meas Pre hPreM _ [], show Pre = signComplement L760.sign L760.y ++ orMajor a b c ++ clear from rfl, run_append, run_append] simp [List.take_nil, List.drop_nil] have hyND : L760.y.Nodup := PeakNodup.nodup_of_mask _ (by decide +kernel) have hsignY : L760.sign ∉ L760.y := by decide +kernel let s1 := run (signComplement L760.sign L760.y) [] s have hs1 (q : Wire) : s1.basis q = if q ∈ L760.y then s.basis q ^^ s.basis L760.sign else s.basis q := GuardCompression.complement_bit L760.sign L760.y hyND hsignY s [] q have hnotY : ∀ (q : Nat), q ∈ [L760.one, L760.rmsb, L760.parity, L760.lower, b] ++ L760.carry → s1.basis q = s.basis q := by intro q hq have hny : q ∉ L760.y := by rw [mem_L760_y_iff] simp only [List.mem_append, List.mem_cons, List.not_mem_nil, or_false, mem_L760_carry_iff] at hq rcases hq with (rfl | rfl | rfl | rfl | rfl) | hc · decide · decide · decide · decide · decide · omega rw [hs1, if_neg hny] have haY : a ∈ L760.y := by decide +kernel have hs1a : s1.basis a = (s.basis a ^^ s.basis L760.sign) := by rw [hs1, if_pos haY] have habc_away : ∀ q, q ≠ c → (run (orMajor a b c) [] s1).basis q = s1.basis q := by intro q hqc have hab : a ≠ b := by decide +kernel have hac : a ≠ c := by decide +kernel have hbc : b ≠ c := by decide +kernel by_cases hqa : q = a · subst hqa; simp [orMajor, run, writeBit, hab, hac, hbc, Ne.symm hab, Ne.symm hac, Ne.symm hbc] · by_cases hqb : q = b · subst hqb; simp [orMajor, run, writeBit, hab, hac, hbc, Ne.symm hab, Ne.symm hac, Ne.symm hbc] · simp [orMajor, run, writeBit, hqa, hqb, hqc] have hclear_away : ∀ q, q ≠ b → (run clear [] (run (orMajor a b c) [] s1)).basis q = (run (orMajor a b c) [] s1).basis q := by intro q hqb simp [clear, run, writeBit, hqb] have hu_b : u.basis b = false := by rw [huEq] have hpb : L760.parity ≠ b := by decide +kernel have hab : a ≠ b := by decide +kernel have hpc : L760.parity ≠ c := by decide +kernel have hac : a ≠ c := by decide +kernel have hbc : b ≠ c := by decide +kernel have h1 : (run clear [] (run (orMajor a b c) [] s1)).basis b = !(((run (orMajor a b c) [] s1).basis b ^^ (run (orMajor a b c) [] s1).basis L760.parity) ^^ (run (orMajor a b c) [] s1).basis a) := by simp [clear, run, writeBit, hpb, hab] rw [h1, habc_away b hbc, habc_away L760.parity hpc, habc_away a hac, hnotY b (by simp), hnotY L760.parity (by simp), hs1a] have hpar : s.basis L760.parity = (s.basis b ^^ s.basis a ^^ (s.basis L760.sign ^^ true)) := hready.2 rw [hpar] cases s.basis b <;> cases s.basis a <;> cases s.basis L760.sign <;> rfl have hu_keep : ∀ q ∈ [L760.one, L760.rmsb, L760.lower] ++ L760.carry.drop 1, u.basis q = s.basis q := by have hchk : ([L760.one, L760.rmsb, L760.lower] ++ L760.carry.drop 1).all (fun q => decide (q ≠ b ∧ q ≠ c)) = true := by decide +kernel intro q hq have hne := of_decide_eq_true (List.all_eq_true.mp hchk q hq) rw [huEq, hclear_away q hne.1, habc_away q hne.2] apply hnotY q simp only [List.mem_append, List.mem_cons, List.not_mem_nil, or_false] at hq ⊢ rcases hq with (rfl | rfl | rfl) | hc' · exact Or.inl (Or.inl rfl) · exact Or.inl (Or.inr (Or.inl rfl)) · exact Or.inl (Or.inr (Or.inr (Or.inr (Or.inl rfl)))) · exact Or.inr (List.mem_of_mem_drop hc') apply move_run_eq (base 760) b _ _ u x [] apply addPrefixLoan_760_run_eq d (by omega) (pullState (Equiv.swap (base 760) b) u) x [] · simp only [pullState, Equiv.swap_apply_of_ne_of_ne (by decide : L760.one ≠ base 760) (by decide : L760.one ≠ b), Equiv.swap_apply_of_ne_of_ne (by decide : L760.rmsb ≠ base 760) (by decide : L760.rmsb ≠ b)] rw [hu_keep L760.one (by simp), hu_keep L760.rmsb (by simp)] exact hready.1 · intro q hq by_cases hq760 : q = base 760 · subst hq760; simp only [pullState, Equiv.swap_apply_left]; exact hu_b · have hqb : q ≠ b := by have hchk : (cs.drop 1 ++ [L760.carry.getD 255 0]).all (fun z => decide (z ≠ b)) = true := by decide +kernel exact of_decide_eq_true (List.all_eq_true.mp hchk q hq) simp only [pullState, Equiv.swap_apply_of_ne_of_ne hq760 hqb] have hmem : q = L760.lower ∨ q ∈ L760.carry.drop 1 := by have hchk : (cs.drop 1 ++ [L760.carry.getD 255 0]).all (fun z => decide (z = L760.lower ∨ z ∈ L760.carry.drop 1)) = true := by decide +kernel exact of_decide_eq_true (List.all_eq_true.mp hchk q hq) rcases hmem with rfl | hcd · rw [hu_keep L760.lower (by simp)]; exact hlow · rw [hu_keep q (List.mem_append_right _ hcd)]; exact hcar q (List.mem_of_mem_drop hcd) private theorem foldLoan_760_run_eq (d : Nat) (hd : d ≤ 43) (s : State) (m : List Bool) (hlow : s.basis L760.lower = s.basis L760.rmsb) (hcar : ∀ q ∈ L760.carry, s.basis q = false) : ∃ n, run (foldLoan d L760) m s = run (P1Life.fold (base 760) L760) n s := by let Pre : Program := [.CCX L760.parity L760.lower L760.one, .CX L760.lower L760.rmsb] let Post : Program := [.CX L760.lower L760.rmsb, .CX L760.parity L760.rmsb, .X L760.rmsb, .CX L760.parity L760.lower, .CX L760.rmsb L760.lower, .X L760.lower, .measureX L760.one [] [.CZ L760.parity L760.rmsb]] let MidP := Q6LifetimeResearch.move (base 760) L760.rmsb (FoldTop.foldAdd d L760) let MidQ := Q6LifetimeResearch.move (base 760) L760.rmsb (StairLoan.mappedAddLoan 0 StairLoan.retiredRoles (ShortBiasedFold.lowBits L760) L760.low (L760.carry.take 254) L760.one) have hP : foldLoan d L760 = Pre ++ (MidP ++ Post) := by delta foldLoan; simp only [Pre, MidP, Post, List.append_assoc] have hQ : P1Life.fold (base 760) L760 = Pre ++ (MidQ ++ Post) := by delta P1Life.fold rw [show mappedAdd (ShortBiasedFold.lowBits L760) L760.low (L760.carry.take 254) L760.one = StairLoan.mappedAddLoan 0 StairLoan.retiredRoles (ShortBiasedFold.lowBits L760) L760.low (L760.carry.take 254) L760.one from (StairLoan.mappedAddLoan_zero _ _ _ _ _).symm] simp only [Pre, MidQ, Post, List.append_assoc] rw [hP, hQ] apply replace_mid Pre MidP MidQ Post s m intro x refine ⟨[], ?_⟩ let u := run Pre (m.take (measurementCount Pre)) s have huEq : u = run Pre [] s := run_zero_meas Pre (by decide +kernel) _ [] s have hurmsb : u.basis L760.rmsb = false := by rw [huEq] have h1 : L760.lower ≠ L760.one := by decide +kernel have h2 : L760.rmsb ≠ L760.one := by decide +kernel simp [Pre, run, writeBit, h1, h2, hlow] apply move_run_eq (base 760) L760.rmsb _ _ u x [] apply FoldTop.foldAdd_760_run_eq d hd (pullState (Equiv.swap (base 760) L760.rmsb) u) x [] intro q hq by_cases hq760 : q = base 760 · subst hq760; simp only [pullState, Equiv.swap_apply_left]; exact hurmsb · have hqAway : q ≠ L760.rmsb ∧ q ≠ L760.one := by have hchk : (L760.carry.take 254).all (fun z => decide (z ≠ L760.rmsb ∧ z ≠ L760.one)) = true := by decide +kernel exact of_decide_eq_true (List.all_eq_true.mp hchk q hq) simp only [pullState, Equiv.swap_apply_of_ne_of_ne hq760 hqAway.1] rw [huEq] simp only [Pre, run, writeBit, Function.update_of_ne hqAway.1, Function.update_of_ne hqAway.2] exact hcar q (List.mem_of_mem_take hq) private theorem unfoldLoan_760_run_eq (d : Nat) (hd : d ≤ 43) (s : State) (m : List Bool) (hlow : s.basis L760.lower = false) (hcar : ∀ q ∈ L760.carry, s.basis q = false) : ∃ n, run (unfoldLoan d L760) m s = run (P1Life.unfoldStep (base 760) L760) n s := by let Pre : Program := [.CX L760.parity L760.lower, .CX L760.rmsb L760.lower, .X L760.lower, .CCX L760.parity L760.lower L760.one, .CX L760.lower L760.rmsb, .CX L760.parity L760.rmsb, .X L760.rmsb] let Post : Program := [.CX L760.lower L760.rmsb, .CX L760.rmsb L760.lower, .measureX L760.one [] [.CZ L760.parity L760.rmsb]] let MidP := Q6LifetimeResearch.move (base 760) L760.rmsb (FoldTop.unfoldSub d L760) let MidQ := Q6LifetimeResearch.move (base 760) L760.rmsb (StairLoan.mappedSubLoan 0 StairLoan.retiredRoles (ShortBiasedFold.lowBits L760) L760.low (L760.carry.take 254) L760.one) have hP : unfoldLoan d L760 = Pre ++ (MidP ++ Post) := by delta unfoldLoan; simp only [Pre, MidP, Post, List.append_assoc] have hQ : P1Life.unfoldStep (base 760) L760 = Pre ++ (MidQ ++ Post) := by delta P1Life.unfoldStep rw [show mappedSub (ShortBiasedFold.lowBits L760) L760.low (L760.carry.take 254) L760.one = StairLoan.mappedSubLoan 0 StairLoan.retiredRoles (ShortBiasedFold.lowBits L760) L760.low (L760.carry.take 254) L760.one from (StairLoan.mappedSubLoan_zero _ _ _ _ _).symm] simp only [Pre, MidQ, Post, List.append_assoc] rw [hP, hQ] apply replace_mid Pre MidP MidQ Post s m intro x refine ⟨[], ?_⟩ let u := run Pre (m.take (measurementCount Pre)) s have huEq : u = run Pre [] s := run_zero_meas Pre (by decide +kernel) _ [] s have hurmsb : u.basis L760.rmsb = false := by rw [huEq] have h1 : L760.parity ≠ L760.lower := by decide +kernel have h2 : L760.parity ≠ L760.one := by decide +kernel have h3 : L760.parity ≠ L760.rmsb := by decide +kernel have h4 : L760.rmsb ≠ L760.lower := by decide +kernel have h5 : L760.rmsb ≠ L760.one := by decide +kernel have h6 : L760.lower ≠ L760.one := by decide +kernel simp only [Pre, run, writeBit, Function.update_self, Function.update_of_ne h1, Function.update_of_ne h2, Function.update_of_ne h3, Function.update_of_ne h4, Function.update_of_ne h5, Function.update_of_ne h6, Function.update_of_ne h1.symm, Function.update_of_ne h2.symm, Function.update_of_ne h3.symm, Function.update_of_ne h4.symm, Function.update_of_ne h5.symm, Function.update_of_ne h6.symm, hlow] cases s.basis L760.parity <;> cases s.basis L760.rmsb <;> rfl apply move_run_eq (base 760) L760.rmsb _ _ u x [] apply FoldTop.unfoldSub_760_run_eq d hd (pullState (Equiv.swap (base 760) L760.rmsb) u) x [] intro q hq by_cases hq760 : q = base 760 · subst hq760; simp only [pullState, Equiv.swap_apply_left]; exact hurmsb · have hqAway : q ≠ L760.rmsb ∧ q ≠ L760.one ∧ q ≠ L760.lower := by have hchk : (L760.carry.take 254).all (fun z => decide (z ≠ L760.rmsb ∧ z ≠ L760.one ∧ z ≠ L760.lower)) = true := by decide +kernel exact of_decide_eq_true (List.all_eq_true.mp hchk q hq) simp only [pullState, Equiv.swap_apply_of_ne_of_ne hq760 hqAway.1] rw [huEq] simp only [Pre, run, writeBit, Function.update_of_ne hqAway.1, Function.update_of_ne hqAway.2.1, Function.update_of_ne hqAway.2.2] exact hcar q (List.mem_of_mem_take hq) private theorem shortConstAddLoan_760_move_run_eq (d : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (k : Nat) (hk : k / 8 < 2 ^ 252) (s : State) (m : List Bool) (hrmsb : s.basis L760.rmsb = false) (hone : s.basis L760.one = false) (hpar : s.basis L760.parity = false) (hcar : ∀ q ∈ L760.carry, s.basis q = false) : ∃ n, run (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 k)) m s = run (Q6LifetimeResearch.move (base 760) L760.rmsb (P1Life.shortConstAdd L760 k)) n s := by refine ⟨[], ?_⟩ have h0 : P1Life.shortConstAdd L760 k = shortConstAddLoan 0 L760 k := by rw [short_zero] delta P1Life.shortConstAdd previousShort simp [StairLoan.literalConstAddLoan] rw [h0] apply move_run_eq (base 760) L760.rmsb _ _ s m [] apply shortConstAddLoan_run_eq d hd h42 k hk (pullState (Equiv.swap (base 760) L760.rmsb) s) m [] · intro q hq by_cases hq760 : q = base 760 · subst hq760; simp only [pullState, Equiv.swap_apply_left]; exact hrmsb · have hqne : q ≠ L760.rmsb := by have hchk : L760.carry.all (fun z => decide (z ≠ L760.rmsb)) = true := by decide +kernel exact of_decide_eq_true (List.all_eq_true.mp hchk q hq) simp only [pullState, Equiv.swap_apply_of_ne_of_ne hq760 hqne] exact hcar q hq · simp only [pullState, Equiv.swap_apply_of_ne_of_ne (by decide : L760.one ≠ base 760) (by decide : L760.one ≠ L760.rmsb)]; exact hone · simp only [pullState, Equiv.swap_apply_of_ne_of_ne (by decide : L760.parity ≠ base 760) (by decide : L760.parity ≠ L760.rmsb)]; exact hpar private theorem compareBlockLoan_760_eq_p1 (d : Nat) (hd : d ≤ 43) (fwd : Bool) (s : State) (m : List Bool) (oneZero : s.basis L760.one = false) (carryZero : ∀ q ∈ L760.carry, s.basis q = false) (lowerZero : s.basis L760.lower = false) (flag : fwd = true → s.basis L760.parity = decide (regValue L760.r s.basis < regValue L760.y s.basis)) : ∃ n, run (compareBlockLoan d fwd L760) m s = run (P1Life.compare (base 760) fwd L760) n s := by refine ⟨[], ?_⟩ have h0 : P1Life.compare (base 760) fwd L760 = compareBlockLoan 0 fwd L760 := by delta P1Life.compare compareBlockLoan; dsimp only rw [StairLoan.compareLoan_zero] rw [h0] exact compareBlockLoan_760_run_eq d (by omega) fwd s m [] oneZero carryZero lowerZero flag private theorem rawSubLoan_760_run_eq (d : Nat) (hd : d ≤ 43) (origin : BasisState) (B : Bool) (R Y : Int) (hr : P1Life.OddDomain R) (hy : P1Life.OddDomain Y) (hsign : origin L760.sign = B) (s : State) (m : List Bool) (hraw : DirectPass.AfterRaw DirectPass.standardEncoding L760 (base 760) origin (P1Life.oddSum B R Y) Y s.basis) (hcar : ∀ q ∈ L760.carry, s.basis q = false) : ∃ n, run (rawSubLoan d L760) m s = run (P1Life.rawSub (base 760) L760) n s := by let xs := GuardCompression.source L760 let ys := BalancedCircuit.rawTarget L760 let cs := (Q6Structural.q6Carry L760).take 255 let a := xs.getD 0 0 let b := ys.getD 0 0 let c := cs.getD 0 0 let Pre := signComplement L760.sign L760.y ++ notRegister ys ++ orMajor a b c ++ [.X b, .CX L760.parity b] let Post := [.CX L760.parity b, .X b] ++ orErase a b c ++ [.CX a b, .X b] ++ notRegister ys ++ signComplement L760.sign L760.y ++ [.CX b L760.parity, .CX (L760.ylow.getD 0 0) L760.parity, .CX L760.sign L760.parity, .X L760.parity, .CX L760.rmsb L760.one] let MidP := Q6LifetimeResearch.move (base 760) b (StairLoan.addTopLoan d StairLoan.retiredRoles (xs.drop 1) (ys.drop 1) (cs.drop 1) c) let MidQ := Q6LifetimeResearch.move (base 760) b (StairLoan.addTopLoan 0 StairLoan.retiredRoles (xs.drop 1) (ys.drop 1) (cs.drop 1) c) have hP : rawSubLoan d L760 = Pre ++ (MidP ++ Post) := by delta rawSubLoan; simp only [Pre, MidP, Post, xs, ys, cs, a, b, c, List.append_assoc] have hQ : P1Life.rawSub (base 760) L760 = Pre ++ (MidQ ++ Post) := by delta P1Life.rawSub; dsimp only rw [show Q6LifetimeResearch.addTop (xs.drop 1) (ys.drop 1) (cs.drop 1) c = StairLoan.addTopLoan 0 StairLoan.retiredRoles (xs.drop 1) (ys.drop 1) (cs.drop 1) c from (StairLoan.addTopLoan_zero _ _ _ _ _).symm] simp only [Pre, MidQ, Post, xs, ys, cs, a, b, c, orMajor, orErase, P1Life.orMajor, P1Life.orErase, List.append_assoc] rw [hP, hQ] apply replace_mid Pre MidP MidQ Post s m intro x refine ⟨[], ?_⟩ let u := run Pre (m.take (measurementCount Pre)) s have hPreM : measurementCount Pre = 0 := by have h1 := (signComplement_counts L760.sign L760.y).2 have h2 := (notRegister_counts ys).2 have h3 : measurementCount (orMajor a b c) = 0 := by decide +kernel have h4 : measurementCount [.X b, .CX L760.parity b] = 0 := by decide +kernel simp only [Pre, measurementCount_append, h1, h2, h3, h4] have huEq : u = run [.X b, .CX L760.parity b] [] (run (orMajor a b c) [] (run (notRegister ys) [] (run (signComplement L760.sign L760.y) [] s))) := by dsimp only [u] rw [run_zero_meas Pre hPreM _ [], show Pre = signComplement L760.sign L760.y ++ notRegister ys ++ orMajor a b c ++ [.X b, .CX L760.parity b] from rfl, run_append, run_append, run_append] simp [List.take_nil, List.drop_nil] have hyND : L760.y.Nodup := PeakNodup.nodup_of_mask _ (by decide +kernel) have hysND : ys.Nodup := PeakNodup.nodup_of_mask _ (by decide +kernel) have hsignY : L760.sign ∉ L760.y := by decide +kernel let st1 := run (signComplement L760.sign L760.y) [] s let st2 := run (notRegister ys) [] st1 let st3 := run (orMajor a b c) [] st2 have hst1 (q : Wire) : st1.basis q = if q ∈ L760.y then s.basis q ^^ s.basis L760.sign else s.basis q := GuardCompression.complement_bit L760.sign L760.y hyND hsignY s [] q have hst2 (q : Wire) : st2.basis q = if q ∈ ys then !st1.basis q else st1.basis q := congrFun (congrArg State.basis (notRegister_correct ys hysND st1 [])) q have hst3_away (q : Wire) (hqc : q ≠ c) : st3.basis q = st2.basis q := by have hab : a ≠ b := by decide +kernel have hac : a ≠ c := by decide +kernel have hbc : b ≠ c := by decide +kernel by_cases hqa : q = a · subst hqa; simp [st3, orMajor, run, writeBit, hab, hac, hbc, Ne.symm hab, Ne.symm hac, Ne.symm hbc] · by_cases hqb : q = b · subst hqb; simp [st3, orMajor, run, writeBit, hab, hac, hbc, Ne.symm hab, Ne.symm hac, Ne.symm hbc] · simp [st3, orMajor, run, writeBit, hqa, hqb, hqc] have hu_away (q : Wire) (hqb : q ≠ b) : u.basis q = st3.basis q := by rw [huEq]; simp [st3, st2, st1, run, writeBit, hqb] have hpar_eq_b : s.basis L760.parity = s.basis b := by have tlen : ys.length = 257 := by decide +kernel have htd : signedRegValue ys s.basis = P1Life.oddSum B R Y := by unfold signedRegValue; rw [tlen, hraw.1] have ht := P1Life.oddSum_signed B R Y hr hy exact decode_encodeWord 257 (by decide) _ ht have hbit : s.basis L760.r0 = originalParity (P1Life.oddSum B R Y) := by apply word_parity L760.r0 (L760.rtail ++ [L760.rmsb, L760.one]) s.basis _ simpa only [ys, BalancedCircuit.rawTarget, BalancedCleanup.Layout.r, BalancedCleanup.Layout.low, List.cons_append, List.append_assoc, List.singleton_append] using htd exact hraw.2.2.1.trans hbit.symm have hu_b : u.basis b = false := by rw [huEq] have hpb : L760.parity ≠ b := by decide +kernel have hpc : L760.parity ≠ c := by decide +kernel have hbc : b ≠ c := by decide +kernel have hbYs : b ∈ ys := by decide +kernel have hpYs : L760.parity ∉ ys := by decide +kernel have hbY : b ∉ L760.y := by decide +kernel have hpY : L760.parity ∉ L760.y := by decide +kernel change (run [.X b, .CX L760.parity b] [] st3).basis b = false simp only [run, writeBit, Function.update_self, Function.update_of_ne hpb] rw [hst3_away b hbc, hst3_away L760.parity hpc, hst2 b, hst2 L760.parity, if_pos hbYs, if_neg hpYs, hst1 b, hst1 L760.parity, if_neg hbY, if_neg hpY, hpar_eq_b] cases s.basis b <;> rfl have hclean_u : ∀ (q : Nat), q ∈ cs.drop 1 ++ [L760.carry.getD 255 0] → (pullState (Equiv.swap (base 760) b) u).basis q = false := by intro q hq have hlast : (L760.carry.getD 255 0 : Nat) = 1042 := by decide +kernel have hq_rng : (529 ≤ q ∧ q < 781) ∨ q = 1556 ∨ q = 1813 ∨ q = 1042 := by simp only [List.mem_append, List.mem_singleton, hlast] at hq rcases hq with h1 | rfl · have h1' := (mem_q6Carry255_drop1_iff q).mp h1 rcases h1' with a | b | c' · exact Or.inl a · exact Or.inr (Or.inl b) · exact Or.inr (Or.inr (Or.inl c')) · exact Or.inr (Or.inr (Or.inr rfl)) by_cases hq760 : q = base 760 · subst hq760; simp only [pullState, Equiv.swap_apply_left]; exact hu_b · have hb_val : (b : Nat) = 2072 := rfl have hc_val : (c : Nat) = 528 := by decide +kernel have hqb : q ≠ b := by rw [hb_val]; omega have hqc : q ≠ c := by rw [hc_val]; omega have hqy : q ∉ L760.y := by rw [mem_L760_y_iff]; omega have hqys : q ∉ ys := by simp only [ys, BalancedCircuit.rawTarget, List.mem_append, List.mem_singleton, mem_L760_r_iff] have ho_val : (L760.one : Nat) = 1043 := rfl rw [ho_val]; omega simp only [pullState, Equiv.swap_apply_of_ne_of_ne hq760 hqb] rw [hu_away q hqb, hst3_away q hqc, hst2 q, if_neg hqys, hst1 q, if_neg hqy] by_cases hlo : q = L760.lower · rw [hlo]; exact hraw.2.2.2.1 · have hlo_val : (L760.lower : Nat) = 1813 := rfl rw [hlo_val] at hlo exact hcar q ((mem_L760_carry_iff q).mpr (by omega)) apply move_run_eq (base 760) b _ _ u x [] apply addTopLoan_760_run_eq d (by omega) (pullState (Equiv.swap (base 760) b) u) x [] hclean_u -- Post-condition: after `addInPlace` on `v0 = pullState (swap (base 760) b) u`, `L760.one = L760.rmsb`. let v0 := pullState (Equiv.swap (base 760) b) u have hmv : ∀ (ws : List Wire) (bs : BasisState), mappedValue (mappedRead ws false) bs = regValue ws bs := by intro ws bs; induction ws with | nil => rfl | cons w ws ih => have hstep : mappedValue (mappedRead (w :: ws) false) bs = (bs w).toNat + 2 * mappedValue (mappedRead ws false) bs := by simp [mappedRead, mappedValue, MappedBit.value] have hreg : regValue (w :: ws) bs = (if bs w = true then 1 else 0) + 2 * regValue ws bs := rfl rw [hstep, hreg, ih]; cases bs w <;> simp have hadd_eq : ∀ (bs as cs : List Wire) (cin : Wire), as.length = bs.length → cs.length + 1 = bs.length → addInPlace as bs cs cin = mappedAdd (mappedRead as false) bs cs cin := by intro bs induction bs with | nil => intro as cs cin _ hc; simp at hc | cons b bs ih => intro as cs cin ha hc cases as with | nil => simp at ha | cons a as => cases bs with | nil => cases as with | cons _ _ => simp at ha | nil => cases cs with | cons _ _ => simp at hc | nil => rfl | cons b2 bs2 => cases as with | nil => simp at ha | cons a2 as2 => cases cs with | nil => simp at hc | cons c cs => simp only [addInPlace, mappedAdd, mappedRead, List.map_cons, mappedMajority, mappedEraseCarry, mappedSum] rw [ih (a2 :: as2) cs c (by simpa using ha) (by simpa using hc)] rfl have hnd_add : (c :: ((L760.low.drop 1 ++ [L760.rmsb, L760.one]) ++ (cs.drop 1 ++ [L760.carry.getD 255 0]))).Nodup := PeakNodup.nodup_of_mask _ (by decide +kernel) have haway_add : ∀ (q : Nat), q ∈ mappedWires (mappedRead (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]) false) → q ∉ c :: ((L760.low.drop 1 ++ [L760.rmsb, L760.one]) ++ (cs.drop 1 ++ [L760.carry.getD 255 0])) := by intro q hq have hw := mem_mappedWires_read _ q hq have hqy_rng : 786 ≤ q ∧ q < 1042 := by simp only [List.mem_append, List.mem_cons, List.not_mem_nil, or_false] at hw rcases hw with hdrop | rfl | rfl · exact (mem_L760_y_iff q).mp (List.mem_append_left _ (List.mem_of_mem_drop hdrop)) · have hy_val : (L760.ymsb : Nat) = 1041 := rfl; rw [hy_val]; omega · have hy_val : (L760.ymsb : Nat) = 1041 := rfl; rw [hy_val]; omega have hlast : (L760.carry.getD 255 0 : Nat) = 1042 := by decide +kernel have hc_val : (c : Nat) = 528 := by decide +kernel have hrm_val : (L760.rmsb : Nat) = 2327 := rfl have ho_val : (L760.one : Nat) = 1043 := rfl rw [hlast] simp only [List.mem_cons, List.mem_append, List.not_mem_nil, or_false] rintro (rfl | ((hlow | rfl | rfl) | (hcar | rfl))) · rw [hc_val] at hqy_rng; omega · have hrr := (mem_L760_r_iff q).mp (List.mem_append_left _ (List.mem_of_mem_drop hlow)); omega · rw [hrm_val] at hqy_rng; omega · rw [ho_val] at hqy_rng; omega · have hcar' := (mem_q6Carry255_drop1_iff q).mp hcar; omega · omega have hmc := mappedAdd_correct (mappedRead (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]) false) (L760.low.drop 1 ++ [L760.rmsb, L760.one]) (cs.drop 1 ++ [L760.carry.getD 255 0]) c hnd_add haway_add (by decide +kernel) (by decide +kernel) v0 [] hclean_u rw [hadd_eq _ _ _ _ (by decide +kernel) (by decide +kernel)] have hrv : regValue (L760.low.drop 1 ++ [L760.rmsb, L760.one]) (run (mappedAdd (mappedRead (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]) false) (L760.low.drop 1 ++ [L760.rmsb, L760.one]) (cs.drop 1 ++ [L760.carry.getD 255 0]) c) [] v0).basis = (regValue (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]) v0.basis + regValue (L760.low.drop 1 ++ [L760.rmsb, L760.one]) v0.basis + (v0.basis c).toNat) % 2 ^ 256 := by rw [hmc.2.2, hmv]; rfl apply DirectPass.extended_bits (L760.low.drop 1) L760.rmsb L760.one _ rw [show (L760.low.drop 1).length = 254 by decide +kernel, hrv] -- Relate v0 on xs.drop 1, ys.drop 1, c back to st2 have hv0_xs : regValue (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]) v0.basis = regValue (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]) st2.basis := by apply regValue_congr; intro q hq have hchk : (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]).all (fun z => decide (z ≠ base 760 ∧ z ≠ b ∧ z ≠ c)) = true := by decide +kernel have hf := of_decide_eq_true (List.all_eq_true.mp hchk q hq) simp only [v0, pullState, Equiv.swap_apply_of_ne_of_ne hf.1 hf.2.1] rw [hu_away q hf.2.1, hst3_away q hf.2.2] have hv0_ys : regValue (L760.low.drop 1 ++ [L760.rmsb, L760.one]) v0.basis = regValue (L760.low.drop 1 ++ [L760.rmsb, L760.one]) st2.basis := by apply regValue_congr; intro q hq have hchk : (L760.low.drop 1 ++ [L760.rmsb, L760.one]).all (fun z => decide (z ≠ base 760 ∧ z ≠ b ∧ z ≠ c)) = true := by decide +kernel have hf := of_decide_eq_true (List.all_eq_true.mp hchk q hq) simp only [v0, pullState, Equiv.swap_apply_of_ne_of_ne hf.1 hf.2.1] rw [hu_away q hf.2.1, hst3_away q hf.2.2] have hv0_c : v0.basis c = carryBit (st2.basis a) (st2.basis b) true := by have hcb : c ≠ b := by decide +kernel have hc760 : c ≠ base 760 := by decide +kernel have hcYs : c ∉ ys := by decide +kernel have hcY : c ∉ L760.y := by decide +kernel have hc0 : st2.basis c = false := by rw [hst2 c, if_neg hcYs, hst1 c, if_neg hcY] exact hcar c (by decide +kernel) simp only [v0, pullState, Equiv.swap_apply_of_ne_of_ne hc760 hcb] rw [hu_away c hcb] have hab : a ≠ b := by decide +kernel have hac : a ≠ c := by decide +kernel have hbc : b ≠ c := by decide +kernel change (run (orMajor a b c) [] st2).basis c = _ have hc_run : (run (orMajor a b c) [] st2).basis c = !((st2.basis c) ^^ ((!st2.basis a) && (!st2.basis b))) := by simp [orMajor, run, writeBit, hab, hac, hbc, Ne.symm hab, Ne.symm hac, Ne.symm hbc] rw [hc_run, hc0] cases st2.basis a <;> cases st2.basis b <;> rfl rw [hv0_xs, hv0_ys, hv0_c] have hxs_split : xs = a :: (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]) := by decide +kernel have hys_split : ys = b :: (L760.low.drop 1 ++ [L760.rmsb, L760.one]) := by decide +kernel have hsum_st2 : (regValue xs st2.basis + regValue ys st2.basis + 1) % 2 ^ 257 = 2 ^ 257 - 1 - encodeWord 257 R := by have hsign_s : s.basis L760.sign = B := by have haway : L760.sign ∉ ys ∧ L760.sign ≠ L760.parity ∧ L760.sign ≠ L760.lower ∧ L760.sign ≠ L760.one := by decide +kernel have hnr : L760.sign ∉ L760.r := by decide +kernel exact (hraw.2.2.2.2.2 L760.sign hnr haway.2.1 haway.2.2.1 haway.2.2.2).trans hsign have hgen : ∀ (ws : List Wire) (b1 b2 : BasisState), (∀ q ∈ ws, b1 q = !b2 q) → regValue ws b1 = 2 ^ ws.length - 1 - regValue ws b2 := by intro ws b1 b2 hf induction ws with | nil => simp [regValue] | cons w ws ih => have hlt := regValue_lt ws b2 have ih' := ih (fun q hq => hf q (List.mem_cons_of_mem w hq)) have hw0 := hf w (List.mem_cons_self ..) change (if b1 w = true then 1 else 0) + 2 * regValue ws b1 = 2 ^ (ws.length + 1) - 1 - ((if b2 w = true then 1 else 0) + 2 * regValue ws b2) rw [ih', hw0, Nat.pow_succ] cases b2 w <;> simp <;> omega have hst2_ys : regValue ys st2.basis = 2 ^ 257 - 1 - encodeWord 257 (P1Life.oddSum B R Y) := by have hst1_ys : regValue ys st1.basis = regValue ys s.basis := by apply regValue_congr; intro (q : Nat) hq have hny : q ∉ L760.y := by simp only [ys, BalancedCircuit.rawTarget, List.mem_append, List.mem_singleton, mem_L760_r_iff] at hq rw [mem_L760_y_iff] rcases hq with hr | rfl · omega · have ho_val : (L760.one : Nat) = 1043 := rfl; rw [ho_val]; omega rw [hst1 q, if_neg hny] have hflip := hgen ys st2.basis st1.basis (fun q hq => by rw [hst2 q, if_pos hq]) have hlen_ys : ys.length = 257 := by decide +kernel rw [hflip, hlen_ys, hst1_ys, hraw.1]; rfl have hst2_xs : regValue xs st2.basis = if B then 2 ^ 257 - 1 - encodeWord 257 Y else encodeWord 257 Y := by have hxs_in_y : ∀ (q : Nat), q ∈ xs → q ∈ L760.y := by intro q hq have hxs_def : xs = L760.y ++ [L760.ymsb] := rfl rw [hxs_def, List.mem_append, List.mem_singleton] at hq rcases hq with hqy | hlast · exact hqy · rw [hlast, mem_L760_y_iff]; have hy_val : (L760.ymsb : Nat) = 1041 := rfl; rw [hy_val]; omega have hst2_eq_st1 : regValue xs st2.basis = regValue xs st1.basis := by apply regValue_congr; intro (q : Nat) hq have hnys : q ∉ ys := by have hy := (mem_L760_y_iff q).mp (hxs_in_y q hq) simp only [ys, BalancedCircuit.rawTarget, List.mem_append, List.mem_singleton, mem_L760_r_iff] rintro (hr | rfl) · omega · have ho_val : (L760.one : Nat) = 1043 := rfl; rw [ho_val] at hy; omega rw [hst2 q, if_neg hnys] rw [hst2_eq_st1] have hsrc_s : regValue xs s.basis = encodeWord 257 Y := by have widths := BalancedCleanup.widths L760.toLayout hw760 have yd : signedRegValue L760.y s.basis = Y := by unfold signedRegValue; rw [widths.2.2.1, hraw.2.1] exact decode_encodeWord 256 (by decide) Y (P1Life.oddDomain_signed Y hy) have sd : signedRegValue xs s.basis = Y := (signed_extension L760.ylow L760.ymsb L760.ymsb s.basis rfl).trans yd exact word_encoding xs 257 (by decide +kernel) s.basis Y sd cases hB : B · rw [if_neg Bool.false_ne_true, ← hsrc_s] apply regValue_congr; intro q hq rw [hst1 q, hsign_s, hB]; split_ifs <;> simp · rw [if_pos rfl, ← hsrc_s] have hcomp : ∀ q ∈ xs, st1.basis q = !s.basis q := by intro q hq rw [hst1 q, if_pos (hxs_in_y q hq), hsign_s, hB] simp simpa only [show xs.length = 257 by decide +kernel] using hgen xs st1.basis s.basis hcomp have hadd := P1Life.oddSum_encoded 257 B R Y have hltR : encodeWord 257 R < 2 ^ 257 := encodeWord_bound 257 R have hltT : encodeWord 257 (P1Life.oddSum B R Y) < 2 ^ 257 := encodeWord_bound 257 _ have hltY : encodeWord 257 Y < 2 ^ 257 := encodeWord_bound 257 Y rw [hst2_xs, hst2_ys] cases B <;> simp only [Bool.false_eq_true, if_false, if_true] at hadd ⊢ <;> omega have hext_comp : DirectPass.Extended 255 (2 ^ 257 - 1 - encodeWord 257 R) := by have heR := DirectPass.encoded_extended 255 R (P1Life.oddDomain_signed R hr) have hltR := encodeWord_bound 257 R rw [show (255 : Nat) + 2 = 257 from rfl] at heR unfold DirectPass.Extended at heR ⊢ omega apply DirectPass.extended_tail (st2.basis a) (st2.basis b) true (regValue (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]) st2.basis) (regValue (L760.low.drop 1 ++ [L760.rmsb, L760.one]) st2.basis) 254 have hxs_val : regValue xs st2.basis = (st2.basis a).toNat + 2 * regValue (L760.ylow.drop 1 ++ [L760.ymsb, L760.ymsb]) st2.basis := by rw [hxs_split]; simp [regValue, Bool.toNat] have hys_val : regValue ys st2.basis = (st2.basis b).toNat + 2 * regValue (L760.low.drop 1 ++ [L760.rmsb, L760.one]) st2.basis := by rw [hys_split]; simp [regValue, Bool.toNat] simpa only [← hxs_val, ← hys_val, Bool.toNat_true, hsum_st2] using hext_comp private theorem carry_all_zero_of_afterHalf (origin : BasisState) (horig : ∀ q ∈ L760.carry, origin q = false) (b : BasisState) (hclean : DirectPass.CleanExcept (L760.carry.take 254) (base 760) b) (hframe : DirectPass.HalfOutside L760 origin b) : ∀ q ∈ L760.carry, b q = false := carry_all_zero_of_outside origin horig b hclean hframe ((hframe (base 760) (by decide +kernel) (by decide +kernel) (by decide +kernel) (by decide +kernel)).trans (horig (base 760) (by decide +kernel))) private theorem compare_after_prepare_run_eq (d : Nat) (hd : d ≤ 43) (fwd : Bool) (U Y : Int) (B Neg : Bool) (hu_b : -((2 ^ 254 : Nat) : Int) ≤ U ∧ U < ((2 ^ 254 : Nat) : Int)) (hy_b : -((2 ^ 255 : Nat) : Int) ≤ Y ∧ Y < ((2 ^ 255 : Nat) : Int)) (u0 : State) (m x : List Bool) (hrv : regValue L760.r u0.basis = encodeWord 255 U) (hyu : regValue L760.y u0.basis = encodeWord 256 Y) (hsign : u0.basis L760.sign = B) (hlower : u0.basis L760.lower = Neg) (hone : u0.basis L760.one = false) (hcar0 : ∀ q ∈ L760.carry, u0.basis q = false) (hpar : fwd = true → u0.basis L760.parity = DirectPass.comparisonPredicate true B Neg U Y) : ∃ y, run (compareBlockLoan d fwd L760) x (run (P1Life.prepareCompare L760 ++ P1Life.exposure L760) m u0) = run (P1Life.compare (base 760) fwd L760) y (run (P1Life.prepareCompare L760 ++ P1Life.exposure L760) m u0) := by let n0 : L760.toLayout.wires.Nodup := (List.nodup_append'.mp hn760).2.1 have hpc_eq : P1Life.prepareCompare L760 = DirectPass.comparePrepareMode true L760.toLayout := rfl have hex_eq : P1Life.exposure L760 = DirectPass.compareExposeMode true L760 := rfl have hp0 : measurementCount (P1Life.prepareCompare L760) = 0 := properProgram_measurementCount _ (DirectPass.prepare_compare_proper_mode true L760.toLayout n0) have he0 : measurementCount (P1Life.exposure L760) = 0 := by decide +kernel rw [run_append, run_zero_meas (P1Life.prepareCompare L760) hp0 _ [], run_zero_meas (P1Life.exposure L760) he0 _ []] have hvals := DirectPass.prepare_compare_value_mode true L760.toLayout hw760 n0 U Y B Neg hu_b hy_b u0 [] hrv hyu hsign hlower have hrel := DirectPass.prepare_compare_low_mode true L760.toLayout hw760 n0 U Y B Neg hu_b hy_b u0 [] hrv hyu hsign hlower rw [← hpc_eq] at hvals hrel generalize hu1_def : run (P1Life.prepareCompare L760) [] u0 = u1 rw [hu1_def] at hvals hrel have hu1_sign : u1.basis L760.sign = B := (hvals.2.2 L760.sign (not_mem_L760_r_of_eq 2425 rfl (by omega)) (not_mem_L760_y_of_eq 2425 rfl (by omega))).trans hsign have hu1_low : u1.basis L760.lower = Neg := (hvals.2.2 L760.lower (not_mem_L760_r_of_eq 1813 rfl (by omega)) (not_mem_L760_y_of_eq 1813 rfl (by omega))).trans hlower have hexp := DirectPass.expose_correct_mode true L760 (by decide +kernel) (by decide +kernel) u1 [] B Neg hu1_sign hu1_low hrel rw [← hex_eq] at hexp generalize hu2_def : run (P1Life.exposure L760) [] u1 = u2 rw [hu2_def] at hexp have hu2_one : u2.basis L760.one = false := (hexp.2.2 L760.one L760_one_ne_lower).trans ((hvals.2.2 L760.one (not_mem_L760_r_of_eq 1043 rfl (by omega)) (not_mem_L760_y_of_eq 1043 rfl (by omega))).trans hone) have hu2_car : ∀ q ∈ L760.carry, u2.basis q = false := by intro q hq have hf := L760_carry_away q hq exact (hexp.2.2 q hf.1).trans ((hvals.2.2 q hf.2.1 hf.2.2).trans (hcar0 q hq)) refine compareBlockLoan_760_eq_p1 d hd fwd u2 x hu2_one hu2_car hexp.2.1 ?_ intro hfwd have hp_keep : u2.basis L760.parity = DirectPass.comparisonPredicate true B Neg U Y := (hexp.2.2 L760.parity L760_parity_ne_lower).trans ((hvals.2.2 L760.parity (not_mem_L760_r_of_eq 784 rfl (by omega)) (not_mem_L760_y_of_eq 784 rfl (by omega))).trans (hpar hfwd)) have hvr : (regValue L760.r u2.basis : Int) = DirectPass.compareLeftValue true B Neg U + ((2 ^ 255 : Nat) : Int) := by rw [regValue_congr L760.r u2.basis u1.basis (fun q hq => hexp.2.2 q (fun heq => by have h := (mem_L760_r_iff q).mp hq have hl : (L760.lower : Nat) = 1813 := rfl rw [heq, hl] at h; omega))] exact hvals.1 have hvy : (regValue L760.y u2.basis : Int) = DirectPass.compareViewedValue B Neg Y + ((2 ^ 255 : Nat) : Int) := by rw [regValue_congr L760.y u2.basis u1.basis (fun q hq => hexp.2.2 q (fun heq => by have h := (mem_L760_y_iff q).mp hq have hl : (L760.lower : Nat) = 1813 := rfl rw [heq, hl] at h; omega))] exact hvals.2.1 have hiff : regValue L760.r u2.basis < regValue L760.y u2.basis ↔ DirectPass.compareLeftValue true B Neg U < DirectPass.compareViewedValue B Neg Y := by rw [← Int.ofNat_lt, hvr, hvy] exact Int.add_lt_add_iff_right _ rw [hp_keep] simp only [DirectPass.comparisonPredicate, if_true] exact (decide_eq_decide.mpr hiff).symm theorem forwardLoan_760_run_eq (d : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (origin : BasisState) (horig : ∀ q ∈ L760.carry, origin q = false) (R Y : Int) (hr : P1Life.OddDomain R) (hy : P1Life.OddDomain Y) (s : State) (m : List Bool) (hs : DirectPass.AfterHalf L760 (base 760) origin R Y s.basis) : ∃ n, run (forwardLoan d L760) m s = run (P1Life.forward (base 760) L760) n s := by let T := P1Life.oddSum (origin L760.sign) R Y have ht := P1Life.oddSum_bounds (origin L760.sign) R Y hr hy have hf := P1Life.oddFold_bounds T ht have mt : base 760 ∈ L760.carry.take 254 := List.mem_of_mem_drop mem760 have hshapeP : forwardLoan d L760 = P1Life.p1Seed L760 ++ (rawAddLoan d L760 ++ (OneReuse.newPrepare L760 ++ rotateRight (BalancedCircuit.rawTarget L760) ++ (foldLoan d L760 ++ (BalancedCleanup.prepareSign L760.toLayout ++ BiasedCircuit.flipBias L760 ++ P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ (compareBlockLoan d true L760 ++ ((P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 h.toNat) ++ (BalancedCleanup.prepareSign L760.toLayout).reverse))))))) := by delta forwardLoan; simp only [p1Seed_eq, prepareCompare_eq, exposure_eq, List.append_assoc] rw [hshapeP] -- Step 1: replace `rawAddLoan d L760` with `P1Life.rawAdd (base 760) L760` have h1 : ∃ n1, run (P1Life.p1Seed L760 ++ (rawAddLoan d L760 ++ (OneReuse.newPrepare L760 ++ rotateRight (BalancedCircuit.rawTarget L760) ++ (foldLoan d L760 ++ (BalancedCleanup.prepareSign L760.toLayout ++ BiasedCircuit.flipBias L760 ++ P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ (compareBlockLoan d true L760 ++ ((P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 h.toNat) ++ (BalancedCleanup.prepareSign L760.toLayout).reverse)))))))) m s = run (P1Life.p1Seed L760 ++ (P1Life.rawAdd (base 760) L760 ++ (OneReuse.newPrepare L760 ++ rotateRight (BalancedCircuit.rawTarget L760) ++ (foldLoan d L760 ++ (BalancedCleanup.prepareSign L760.toLayout ++ BiasedCircuit.flipBias L760 ++ P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ (compareBlockLoan d true L760 ++ ((P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 h.toNat) ++ (BalancedCleanup.prepareSign L760.toLayout).reverse)))))))) n1 s := by apply replace_mid intro x have hsp := DirectPass.seed_prepare true (base 760) L760 hw760 hn760 mem760 origin R Y (P1Life.oddDomain_signed R hr) (P1Life.oddDomain_signed Y hy) s (m.take (measurementCount (P1Life.p1Seed L760))) hs rcases hsp with ⟨_, htop, hpv, _, _, _, _, hcleanQ, hframe⟩ have hlow : (run (P1Life.p1Seed L760) (m.take (measurementCount (P1Life.p1Seed L760))) s).basis L760.lower = false := hcleanQ L760.lower (by decide +kernel) (by decide +kernel) have hclean254 : DirectPass.CleanExcept (L760.carry.take 254) (base 760) (run (P1Life.p1Seed L760) (m.take (measurementCount (P1Life.p1Seed L760))) s).basis := by intro q hq hne exact hcleanQ q (by rw [DirectPass.active_carry_shape L760 hw760]; exact List.mem_append_left _ hq) hne have hcar := carry_all_zero_of_afterHalf origin horig _ hclean254 hframe exact rawAddLoan_760_run_eq d hd _ x ⟨htop, hpv⟩ hlow hcar obtain ⟨n1, hn1⟩ := h1; rw [hn1] -- Step 2: replace `foldLoan d L760` with `P1Life.fold (base 760) L760` let A2 := (P1Life.p1Seed L760 ++ P1Life.rawAdd (base 760) L760) ++ (OneReuse.newPrepare L760 ++ rotateRight (BalancedCircuit.rawTarget L760)) let B2 := BalancedCleanup.prepareSign L760.toLayout ++ BiasedCircuit.flipBias L760 ++ P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ (compareBlockLoan d true L760 ++ ((P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 h.toNat) ++ (BalancedCleanup.prepareSign L760.toLayout).reverse))) have h2re : P1Life.p1Seed L760 ++ (P1Life.rawAdd (base 760) L760 ++ (OneReuse.newPrepare L760 ++ rotateRight (BalancedCircuit.rawTarget L760) ++ (foldLoan d L760 ++ B2))) = A2 ++ (foldLoan d L760 ++ B2) := by simp only [A2, List.append_assoc] rw [h2re] have htr2 : Triple (DirectPass.AfterHalf L760 (base 760) origin R Y) A2 (DirectPass.AfterShift L760 (base 760) origin T Y) := by have hrng : -((2 ^ 256 : Nat) : Int) ≤ T ∧ T < ((2 ^ 256 : Nat) : Int) := by have hp_lt : (p : Int) < ((2 ^ 256 : Nat) : Int) := by decide omega exact Triple.seq (P1Life.seed_to_raw (base 760) L760 hw760 hn760 mem760 origin R Y hr hy) (DirectPass.shift_boundary_full (base 760) L760 hw760 hn760 origin T Y hrng) have h2 : ∃ n2, run (A2 ++ (foldLoan d L760 ++ B2)) n1 s = run (A2 ++ (P1Life.fold (base 760) L760 ++ B2)) n2 s := by apply replace_mid intro x have hsh := (htr2 s (n1.take (measurementCount A2)) hs).2 rcases hsh with ⟨_, _, ⟨_, hlow, _⟩, hrmsb, hclean, hframe⟩ exact foldLoan_760_run_eq d hd _ x (hlow.trans hrmsb.symm) (carry_all_zero_of_afterHalf origin horig _ hclean hframe) obtain ⟨n2, hn2⟩ := h2; rw [hn2] -- Step 3: replace `compareBlockLoan d true L760` with `P1Life.compare (base 760) true L760` let A3f := (P1Life.p1Seed L760 ++ P1Life.rawAdd (base 760) L760) ++ (OneReuse.newPrepare L760 ++ rotateRight (BalancedCircuit.rawTarget L760) ++ P1Life.fold (base 760) L760) ++ (BalancedCleanup.prepareSign L760.toLayout ++ BiasedCircuit.flipBias L760) let Front3 := P1Life.prepareCompare L760 ++ P1Life.exposure L760 let A3 := A3f ++ Front3 let B3 := (P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 h.toNat) ++ (BalancedCleanup.prepareSign L760.toLayout).reverse) have h3re : A2 ++ (P1Life.fold (base 760) L760 ++ B2) = A3 ++ (compareBlockLoan d true L760 ++ B3) := by simp only [A2, B2, A3, A3f, Front3, B3, List.append_assoc] rw [h3re] have htr3f : Triple (DirectPass.AfterHalf L760 (base 760) origin R Y) A3f (DirectPass.InverseComparison DirectPass.oddEncoding L760 (base 760) origin T (P1Life.oddFold T) Y) := Triple.seq (Triple.seq (P1Life.seed_to_raw (base 760) L760 hw760 hn760 mem760 origin R Y hr hy) (P1Life.raw_to_fold (base 760) L760 hw760 hn760 mt origin T Y ht)) (P1Life.fold_view (base 760) L760 hw760 hn760 origin T (P1Life.oddFold T) Y hf) have h3 : ∃ n3, run (A3 ++ (compareBlockLoan d true L760 ++ B3)) n2 s = run (A3 ++ (P1Life.compare (base 760) true L760 ++ B3)) n3 s := by apply replace_mid intro x rw [show A3 = A3f ++ (P1Life.prepareCompare L760 ++ P1Life.exposure L760) from rfl, run_append] have hinv := (htr3f s ((n2.take (measurementCount A3)).take (measurementCount A3f)) hs).2 generalize hu0_def : run A3f ((n2.take (measurementCount A3)).take (measurementCount A3f)) s = u0 rw [hu0_def] at hinv rcases hinv with ⟨hlow, hrmsb, hyu, ⟨hpar, hlower, hone⟩, hclean, hframe⟩ have hrv : regValue L760.r u0.basis = encodeWord 255 (P1Life.oddNormalized (P1Life.oddFold T)) := by change regValue (L760.low ++ [L760.rmsb]) u0.basis = _ rw [regValue_append, hlow, oddEncoding_norm, regValue_singleton_false _ _ hrmsb, Nat.mul_zero, Nat.add_zero] have hsign : u0.basis L760.sign = origin L760.sign := hframe L760.sign (not_mem_L760_r_of_eq 2425 rfl (by omega)) L760_sign_ne_parity L760_sign_ne_lower L760_sign_ne_one have hu_b : -((2 ^ 254 : Nat) : Int) ≤ P1Life.oddNormalized (P1Life.oddFold T) ∧ P1Life.oddNormalized (P1Life.oddFold T) < ((2 ^ 254 : Nat) : Int) := by have hb := P1Life.oddNormalized_bounds (P1Life.oddFold T) hf have hc := constants; omega have hpar_eq : true = true → u0.basis L760.parity = DirectPass.comparisonPredicate true (origin L760.sign) (negative (P1Life.oddFold T)) (P1Life.oddNormalized (P1Life.oddFold T)) Y := fun _ => by rw [hpar, P1Life.odd_comparison_predicate] exact P1Life.oddComparison_parity (origin L760.sign) R Y hr hy exact compare_after_prepare_run_eq d hd true (P1Life.oddNormalized (P1Life.oddFold T)) Y (origin L760.sign) (negative (P1Life.oddFold T)) hu_b (P1Life.oddDomain_signed Y hy) u0 _ x hrv hyu hsign hlower hone (carry_all_zero_of_afterHalf origin horig u0.basis hclean hframe) hpar_eq obtain ⟨n3, hn3⟩ := h3; rw [hn3] -- Step 4: replace `shortConstAddLoan d L760 h.toNat` with `P1Life.shortConstAdd L760 h.toNat` let A4 := (P1Life.p1Seed L760 ++ P1Life.rawAdd (base 760) L760) ++ (OneReuse.newPrepare L760 ++ rotateRight (BalancedCircuit.rawTarget L760) ++ P1Life.fold (base 760) L760) ++ (BalancedCleanup.prepareSign L760.toLayout ++ BiasedCircuit.flipBias L760 ++ P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ P1Life.compare (base 760) true L760 ++ (P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse) let B4 := (BalancedCleanup.prepareSign L760.toLayout).reverse have h4re : A3 ++ (P1Life.compare (base 760) true L760 ++ B3) = A4 ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 h.toNat) ++ B4) := by simp only [A3, A3f, Front3, B3, A4, B4, List.append_assoc] rw [h4re] have htr4 : Triple (DirectPass.AfterHalf L760 (base 760) origin R Y) A4 (DirectPass.AfterComparison DirectPass.oddEncoding L760 (base 760) origin (P1Life.oddFold T) Y) := Triple.seq (Triple.seq (P1Life.seed_to_raw (base 760) L760 hw760 hn760 mem760 origin R Y hr hy) (P1Life.raw_to_fold (base 760) L760 hw760 hn760 mt origin T Y ht)) (P1Life.fold_to_comparison (base 760) L760 hw760 hn760 mem760 origin R Y hr hy) have h4 : ∃ n4, run (A4 ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 h.toNat) ++ B4)) n3 s = run (A4 ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (P1Life.shortConstAdd L760 h.toNat) ++ B4)) n4 s := by apply replace_mid intro x have hc := (htr4 s (n3.take (measurementCount A4)) hs).2 rcases hc with ⟨_, hrmsb, _, ⟨hpar, _, hone⟩, hclean, hframe⟩ exact shortConstAddLoan_760_move_run_eq d hd h42 h.toNat (by decide +kernel) _ x hrmsb hone hpar (carry_all_zero_of_afterHalf origin horig _ hclean hframe) obtain ⟨n4, hn4⟩ := h4 refine ⟨n4, hn4.trans ?_⟩ have hQ : A4 ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (P1Life.shortConstAdd L760 h.toNat) ++ B4) = P1Life.forward (base 760) L760 := by rw [P1Life.forward_chunks]; simp only [A4, B4, List.append_assoc] rw [hQ] theorem inverseLoan_760_run_eq (d : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (origin : BasisState) (horig : ∀ q ∈ L760.carry, origin q = false) (F Y : Int) (hf : P1Life.OddDomain F) (hy : P1Life.OddDomain Y) (s : State) (m : List Bool) (hs : DirectPass.AfterHalf L760 (base 760) origin F Y s.basis) : ∃ n, run (inverseLoan d L760) m s = run (P1Life.inverse (base 760) L760) n s := by let B := origin L760.sign let R := P1Life.oddInverse B F Y let T := P1Life.oddSum B R Y have hr : P1Life.OddDomain R := P1Life.oddRep_bounds _ have ht := P1Life.oddSum_bounds B R Y hr hy have hres : P1Life.oddFold T = F := P1Life.oddForward_inverse B F Y hf hy have hival : originalParity T = decide (P1Life.oddComparisonLeft F < P1Life.oddComparisonY B F Y) := by have h0 := P1Life.oddComparison_parity B R Y hr hy rwa [hres] at h0 have mt : base 760 ∈ L760.carry.take 254 := List.mem_of_mem_drop mem760 have hshapeP : inverseLoan d L760 = BalancedCleanup.prepareSign L760.toLayout ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 (encodeWord 255 (-h))) ++ (P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ (compareBlockLoan d false L760 ++ ((P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ BiasedInverse.unbiasView L760 ++ (unfoldLoan d L760 ++ (rotateLeft (BalancedCircuit.rawTarget L760) ++ [.CX L760.parity L760.r0] ++ rawSubLoan d L760)))))) := by delta inverseLoan; simp only [prepareCompare_eq, exposure_eq, List.append_assoc] rw [hshapeP] -- Step 1: shortConstAddLoan have h1 : ∃ n1, run (BalancedCleanup.prepareSign L760.toLayout ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (shortConstAddLoan d L760 (encodeWord 255 (-h))) ++ (P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ (compareBlockLoan d false L760 ++ ((P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ BiasedInverse.unbiasView L760 ++ (unfoldLoan d L760 ++ (rotateLeft (BalancedCircuit.rawTarget L760) ++ [.CX L760.parity L760.r0] ++ rawSubLoan d L760))))))) m s = run (BalancedCleanup.prepareSign L760.toLayout ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (P1Life.shortConstAdd L760 (encodeWord 255 (-h))) ++ (P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ (compareBlockLoan d false L760 ++ ((P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ BiasedInverse.unbiasView L760 ++ (unfoldLoan d L760 ++ (rotateLeft (BalancedCircuit.rawTarget L760) ++ [.CX L760.parity L760.r0] ++ rawSubLoan d L760))))))) n1 s := by apply replace_mid intro x have hu := (P1Life.prepare_sign_odd (base 760) L760 hw760 hn760 origin F Y hf s (m.take (measurementCount (BalancedCleanup.prepareSign L760.toLayout))) hs).2 rcases hu with ⟨_, hrmsb, _, ⟨hpar, _, hone⟩, hclean, hframe⟩ exact shortConstAddLoan_760_move_run_eq d hd h42 (encodeWord 255 (-h)) (by decide +kernel) _ x hrmsb hone hpar (carry_all_zero_of_afterHalf origin horig _ hclean hframe) obtain ⟨n1, hn1⟩ := h1; rw [hn1] -- Step 2: compareBlockLoan d false L760 let A2f := BalancedCleanup.prepareSign L760.toLayout ++ Q6LifetimeResearch.move (base 760) L760.rmsb (P1Life.shortConstAdd L760 (encodeWord 255 (-h))) let A2 := A2f ++ (P1Life.prepareCompare L760 ++ P1Life.exposure L760) let B2 := (P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ BiasedInverse.unbiasView L760 ++ (unfoldLoan d L760 ++ (rotateLeft (BalancedCircuit.rawTarget L760) ++ [.CX L760.parity L760.r0] ++ rawSubLoan d L760)) have h2re : BalancedCleanup.prepareSign L760.toLayout ++ (Q6LifetimeResearch.move (base 760) L760.rmsb (P1Life.shortConstAdd L760 (encodeWord 255 (-h))) ++ (P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ (compareBlockLoan d false L760 ++ B2))) = A2 ++ (compareBlockLoan d false L760 ++ B2) := by simp only [A2, A2f, List.append_assoc] rw [h2re] have htr2f : Triple (DirectPass.AfterHalf L760 (base 760) origin F Y) A2f (DirectPass.AfterComparison DirectPass.oddEncoding L760 (base 760) origin F Y) := Triple.seq (P1Life.prepare_sign_odd (base 760) L760 hw760 hn760 origin F Y hf) (P1Life.normalize_boundary (base 760) L760 hw760 hn760 mem760 origin F Y) have h2 : ∃ n2, run (A2 ++ (compareBlockLoan d false L760 ++ B2)) n1 s = run (A2 ++ (P1Life.compare (base 760) false L760 ++ B2)) n2 s := by apply replace_mid intro x rw [show A2 = A2f ++ (P1Life.prepareCompare L760 ++ P1Life.exposure L760) from rfl, run_append] have hcomp := (htr2f s ((n1.take (measurementCount A2)).take (measurementCount A2f)) hs).2 generalize hu0_def : run A2f ((n1.take (measurementCount A2)).take (measurementCount A2f)) s = u0 rw [hu0_def] at hcomp rcases hcomp with ⟨hlow, hrmsb, hyu, ⟨_, hlower, hone⟩, hclean, hframe⟩ have hrv : regValue L760.r u0.basis = encodeWord 255 (P1Life.oddNormalized F) := by change regValue (L760.low ++ [L760.rmsb]) u0.basis = _ rw [regValue_append, hlow, oddEncoding_norm, regValue_singleton_false _ _ hrmsb, Nat.mul_zero, Nat.add_zero] have hsign : u0.basis L760.sign = B := hframe L760.sign (not_mem_L760_r_of_eq 2425 rfl (by omega)) L760_sign_ne_parity L760_sign_ne_lower L760_sign_ne_one have hu_b : -((2 ^ 254 : Nat) : Int) ≤ P1Life.oddNormalized F ∧ P1Life.oddNormalized F < ((2 ^ 254 : Nat) : Int) := by have hb := P1Life.oddNormalized_bounds F hf; have hc := constants; omega exact compare_after_prepare_run_eq d hd false (P1Life.oddNormalized F) Y B (negative F) hu_b (P1Life.oddDomain_signed Y hy) u0 _ x hrv hyu hsign hlower hone (carry_all_zero_of_afterHalf origin horig u0.basis hclean hframe) (fun e => absurd e Bool.false_ne_true) obtain ⟨n2, hn2⟩ := h2; rw [hn2] -- Step 3: unfoldLoan let A3 := A2f ++ (P1Life.prepareCompare L760 ++ P1Life.exposure L760 ++ P1Life.compare (base 760) false L760 ++ (P1Life.exposure L760).reverse ++ (P1Life.prepareCompare L760).reverse ++ BiasedInverse.unbiasView L760) let B3 := rotateLeft (BalancedCircuit.rawTarget L760) ++ [.CX L760.parity L760.r0] ++ rawSubLoan d L760 have h3re : A2 ++ (P1Life.compare (base 760) false L760 ++ B2) = A3 ++ (unfoldLoan d L760 ++ B3) := by simp only [A2, B2, A3, B3, List.append_assoc] rw [h3re] have htr3 : Triple (DirectPass.AfterHalf L760 (base 760) origin F Y) A3 (DirectPass.AfterFold DirectPass.oddEncoding L760 (base 760) origin T F Y) := Triple.seq htr2f (P1Life.comparison_to_fold (base 760) L760 hw760 hn760 mem760 origin T F Y hf hy hival) have h3 : ∃ n3, run (A3 ++ (unfoldLoan d L760 ++ B3)) n2 s = run (A3 ++ (P1Life.unfoldStep (base 760) L760 ++ B3)) n3 s := by apply replace_mid intro x have haf := (htr3 s (n2.take (measurementCount A3)) hs).2 rcases haf with ⟨_, _, ⟨_, hlow, _⟩, hclean, hframe⟩ exact unfoldLoan_760_run_eq d hd _ x hlow (carry_all_zero_of_afterHalf origin horig _ hclean hframe) obtain ⟨n3, hn3⟩ := h3; rw [hn3] -- Step 4: rawSubLoan let A4 := A3 ++ (P1Life.unfoldStep (base 760) L760 ++ rotateLeft (BalancedCircuit.rawTarget L760) ++ [.CX L760.parity L760.r0]) have h4re : A3 ++ (P1Life.unfoldStep (base 760) L760 ++ B3) = A4 ++ rawSubLoan d L760 := by simp only [A4, B3, List.append_assoc] rw [h4re] have htr4 : Triple (DirectPass.AfterHalf L760 (base 760) origin F Y) A4 (DirectPass.AfterRaw DirectPass.standardEncoding L760 (base 760) origin T Y) := by have hfr := P1Life.fold_to_raw (base 760) L760 hw760 hn760 mt origin T Y ht rw [hres] at hfr exact Triple.seq htr3 hfr have h4 : ∃ n4, run (A4 ++ rawSubLoan d L760) n3 s = run (A4 ++ P1Life.rawSub (base 760) L760) n4 s := by apply replace_last intro x have hraw := (htr4 s (n3.take (measurementCount A4)) hs).2 have hcar := carry_all_zero_of_afterHalf origin horig _ hraw.2.2.2.2.1 hraw.2.2.2.2.2 exact rawSubLoan_760_run_eq d hd origin B R Y hr hy rfl _ x hraw hcar obtain ⟨n4, hn4⟩ := h4 refine ⟨n4, hn4.trans ?_⟩ have hQ : A4 ++ P1Life.rawSub (base 760) L760 = P1Life.inverse (base 760) L760 := by rw [P1Life.inverse_chunks]; simp only [A4, A3, A2f, List.append_assoc] rw [hQ] theorem half760OddLoan_law (d : Nat) (divide : Bool) (hd : d ≤ 43) (h42 : d ≠ 42) : RouteA.Rolling1588.HalfLaw (half760OddLoan d divide) divide P1Life.oddWord P1Life.oddWord := by intro origin clean X Y s m input let bodyP := if divide then forwardLoan d L760 else inverseLoan d L760 let bodyQ := if divide then P1Life.forward (base 760) L760 else P1Life.inverse (base 760) L760 have hP : half760OddLoan d divide = [.X (base 2409)] ++ (bodyP ++ [.X (base 2409)]) := by delta half760OddLoan; cases divide <;> simp [bodyP, L760, List.append_assoc] have hQ : P1Life.half (base 760) divide base (base 2409) = [.X (base 2409)] ++ (bodyQ ++ [.X (base 2409)]) := by delta P1Life.half; cases divide <;> simp [bodyQ, L760, List.append_assoc] have horig : ∀ q ∈ L760.carry, origin q = false := by intro q hq exact Q6EndpointCell.clean_work base (base 2409) origin clean q (by simp [BalancedCircuit.work, hq]) have hstep : ∃ n, run (half760OddLoan d divide) m s = run (P1Life.half (base 760) divide base (base 2409)) n s := by rw [hP, hQ] apply replace_mid intro x let u := run [.X (base 2409)] (m.take (measurementCount [.X (base 2409)])) s have hcl := Q6EndpointCell.clean_work base (base 2409) origin clean have hsr : base 2409 ∉ L760.r := by decide +kernel have hsy : base 2409 ∉ L760.y := by decide +kernel have hu_eq : u = run [.X (base 2409)] [] s := run_zero_meas [.X (base 2409)] (meas_X (base 2409)) _ [] s have huf : ∀ q, q ≠ base 2409 → u.basis q = s.basis q := fun q hq => by simp [hu_eq, run, writeBit, hq] have huc : ∀ q ∈ BalancedCircuit.work L760, u.basis q = false := by intro q hq have ha := DirectPass.work_outside L760 hn760 q hq exact (huf q ha.2.2).trans ((input.2.2 q ha.1 ha.2.1).trans (hcl q hq)) have hah : DirectPass.AfterHalf L760 (base 760) u.basis (P1Life.oddRep X) (P1Life.oddRep Y) u.basis := by refine ⟨?_, ?_, ⟨huc _ (by simp [BalancedCircuit.work]), huc _ (by simp [BalancedCircuit.work]), huc _ (by simp [BalancedCircuit.work])⟩, ?_, fun _ _ _ _ _ => rfl⟩ · exact (regValue_congr _ _ _ (fun q hq => huf q (fun e => hsr (e ▸ hq)))).trans input.1 · exact (regValue_congr _ _ _ (fun q hq => huf q (fun e => hsy (e ▸ hq)))).trans input.2.1 · intro q hq _; exact huc q (by simp [BalancedCircuit.work, List.mem_of_mem_take hq]) have hu_car : ∀ q ∈ L760.carry, u.basis q = false := fun q hq => huc q (by simp [BalancedCircuit.work, hq]) cases divide · exact inverseLoan_760_run_eq d hd h42 u.basis hu_car (P1Life.oddRep X) (P1Life.oddRep Y) (P1Life.oddRep_bounds X) (P1Life.oddRep_bounds Y) u x hah · exact forwardLoan_760_run_eq d hd h42 u.basis hu_car (P1Life.oddRep X) (P1Life.oddRep Y) (P1Life.oddRep_bounds X) (P1Life.oddRep_bounds Y) u x hah obtain ⟨n, hn⟩ := hstep rw [hn] exact P1Life.half_frame (base 760) divide base (base 2409) hn760 mem760 origin clean X Y s n input private theorem mem_jp760_iff (q : Nat) : q ∈ P1Life.junctionFootprint L760 ↔ q = 2425 ∨ q = 784 ∨ q = 1813 ∨ q = 1043 ∨ (2072 ≤ q ∧ q < 2328) ∨ (786 ≤ q ∧ q < 1042) ∨ (528 ≤ q ∧ q < 781) ∨ q = 1556 := by unfold P1Life.junctionFootprint rw [List.mem_toFinset] simp only [List.mem_cons, List.mem_append, mem_L760_r_iff, mem_L760_y_iff, mem_L760_carry254_iff] have hs : (L760.sign : Nat) = 2425 := rfl have hp : (L760.parity : Nat) = 784 := rfl have hl : (L760.lower : Nat) = 1813 := rfl have ho : (L760.one : Nat) = 1043 := rfl rw [hs, hp, hl, ho] tauto private theorem retiredRoles_in_jp (q : Nat) (hq : q ∈ StairLoan.retiredRoles) : q ∈ P1Life.junctionFootprint L760 := by have hchk : StairLoan.retiredRoleIndices.all (fun i => decide (512 ≤ i ∧ i < 765)) = true := by decide +kernel simp only [StairLoan.retiredRoles, List.mem_map, base_eq_add] at hq rcases hq with ⟨i, hi, rfl⟩ have hb := of_decide_eq_true (List.all_eq_true.mp hchk i hi) rw [mem_jp760_iff]; omega private theorem shortFreeHosts_in_jp (d : Nat) (q : Nat) (hq : q ∈ OddFullPass.P1LifeLoan.shortFreeHosts d) : q ∈ P1Life.junctionFootprint L760 := by rw [mem_jp760_iff] unfold OddFullPass.P1LifeLoan.shortFreeHosts at hq split_ifs at hq <;> (simp only [List.mem_cons, List.not_mem_nil, or_false, base_eq_add] at hq; omega) private theorem mem_jp760_of_eq {q : Wire} (n : Nat) (heq : n = q) (hn : n = 2425 ∨ n = 784 ∨ n = 1813 ∨ n = 1043 ∨ (2072 ≤ n ∧ n < 2328) ∨ (786 ≤ n ∧ n < 1042) ∨ (528 ≤ n ∧ n < 781) ∨ n = 1556) : q ∈ P1Life.junctionFootprint L760 := by rw [← heq, mem_jp760_iff]; exact hn private theorem mem_jp760_of_r (q : Nat) (hq : q ∈ L760.r) : q ∈ P1Life.junctionFootprint L760 := by rw [mem_jp760_iff]; have hr := (mem_L760_r_iff q).mp hq; omega private theorem jp_swap760 {host q : Wire} (hh : host ∈ P1Life.junctionFootprint L760) (hq : q ∈ P1Life.junctionFootprint L760) : Equiv.swap (base 760) host q ∈ P1Life.junctionFootprint L760 := by have h760 : base 760 ∈ P1Life.junctionFootprint L760 := mem_jp760_of_eq 776 rfl (by omega) by_cases h1 : q = base 760 · rw [h1, Equiv.swap_apply_left]; exact hh · by_cases h2 : q = host · rw [h2, Equiv.swap_apply_right]; exact h760 · rw [Equiv.swap_apply_of_ne_of_ne h1 h2]; exact hq private theorem move_in_jp {host : Wire} {P : Program} (hh : host ∈ P1Life.junctionFootprint L760) (hP : wires P ⊆ P1Life.junctionFootprint L760) : wires (Q6LifetimeResearch.move (base 760) host P) ⊆ P1Life.junctionFootprint L760 := by intro q hq rw [Q6LifetimeResearch.move, renameProgram_support, Finset.mem_image] at hq rcases hq with ⟨v, hv, rfl⟩ exact jp_swap760 hh (hP hv) private theorem layerHosts_take_in_jp {ls : List StairLoan.CarryLayer} {d : Nat} (hls : ∀ l ∈ ls, l.host ∈ P1Life.junctionFootprint L760) : (StairLoan.layerHosts (ls.take d)).toFinset ⊆ P1Life.junctionFootprint L760 := by intro q hq rw [List.mem_toFinset] at hq simp only [StairLoan.layerHosts, List.mem_map] at hq rcases hq with ⟨l, hl, rfl⟩ exact hls l (List.mem_of_mem_take hl) private theorem mappedLayers_hosts (bits : List MappedBit) (ys cs : List Wire) (cin : Wire) (hcs : ∀ q ∈ cs, q ∈ P1Life.junctionFootprint L760) : ∀ l ∈ StairLoan.mappedLayers bits ys cs cin, l.host ∈ P1Life.junctionFootprint L760 := by induction bits generalizing ys cs cin with | nil => intro l hl; simp [StairLoan.mappedLayers] at hl | cons b bs ih => cases bs with | nil => intro l hl; simp [StairLoan.mappedLayers] at hl | cons b2 bs2 => cases ys with | nil => intro l hl; simp [StairLoan.mappedLayers] at hl | cons y ys => cases ys with | nil => intro l hl; simp [StairLoan.mappedLayers] at hl | cons y2 ys2 => cases cs with | nil => intro l hl; simp [StairLoan.mappedLayers] at hl | cons c cs => intro l hl simp only [StairLoan.mappedLayers, List.mem_cons] at hl rcases hl with rfl | hrest · exact hcs c (List.mem_cons_self ..) · exact ih (y2 :: ys2) cs c (fun q hq => hcs q (List.mem_cons_of_mem _ hq)) l hrest private theorem compareLayers_hosts (fwd : Bool) (as bs cs : List Wire) (cin tgt : Wire) (hcs : ∀ q ∈ cs, q ∈ P1Life.junctionFootprint L760) : ∀ l ∈ StairLoan.compareLayers fwd as bs cs cin tgt, l.host ∈ P1Life.junctionFootprint L760 := by induction as generalizing bs cs cin with | nil => intro l hl; simp [StairLoan.compareLayers] at hl | cons a as ih => cases bs with | nil => intro l hl; simp [StairLoan.compareLayers] at hl | cons b bs => cases as with | nil => intro l hl; simp [StairLoan.compareLayers] at hl | cons a2 as2 => cases bs with | nil => intro l hl; simp [StairLoan.compareLayers] at hl | cons b2 bs2 => cases cs with | nil => intro l hl; simp [StairLoan.compareLayers] at hl | cons c cs => intro l hl simp only [StairLoan.compareLayers, List.mem_cons] at hl rcases hl with rfl | hrest · exact hcs c (List.mem_cons_self ..) · exact ih (b2 :: bs2) cs c (fun q hq => hcs q (List.mem_cons_of_mem _ hq)) l hrest private theorem prefixLayers_hosts (xs ys cs : List Wire) (a t z cin : Wire) (hcs : ∀ q ∈ cs, q ∈ P1Life.junctionFootprint L760) : ∀ l ∈ StairLoan.prefixLayers xs ys cs a t z cin, l.host ∈ P1Life.junctionFootprint L760 := by induction xs generalizing ys cs cin with | nil => intro l hl; simp [StairLoan.prefixLayers] at hl | cons x xs ih => cases ys with | nil => intro l hl; simp [StairLoan.prefixLayers] at hl | cons y ys => cases cs with | nil => intro l hl; simp [StairLoan.prefixLayers] at hl | cons c cs => intro l hl simp only [StairLoan.prefixLayers, List.mem_cons] at hl rcases hl with rfl | hrest · exact hcs c (List.mem_cons_self ..) · exact ih ys cs c (fun q hq => hcs q (List.mem_cons_of_mem _ hq)) l hrest private theorem addTopLayers_hosts (as bs cs : List Wire) (cin : Wire) (hcs : ∀ q ∈ cs, q ∈ P1Life.junctionFootprint L760) : ∀ l ∈ StairLoan.addTopLayers as bs cs cin, l.host ∈ P1Life.junctionFootprint L760 := by match as, bs, cs with | [_, _], [_, _], _ => intro l hl; simp [StairLoan.addTopLayers] at hl | a :: a' :: as', b :: b' :: bs', c :: cs' => cases as' with | nil => cases bs' with | nil => intro l hl; simp [StairLoan.addTopLayers] at hl | cons b2 bs2 => intro l hl have hstep : StairLoan.addTopLayers [a, a'] (b :: b' :: b2 :: bs2) (c :: cs') cin = { host := c, up := majority a b cin c, erase := eraseCarry a b cin c, finish := [.CX a b, .CX cin b] } :: StairLoan.addTopLayers [a'] (b' :: b2 :: bs2) cs' c := rfl rw [hstep, List.mem_cons] at hl rcases hl with rfl | hrest · exact hcs c (List.mem_cons_self ..) · exact addTopLayers_hosts [a'] (b' :: b2 :: bs2) cs' c (fun q hq => hcs q (List.mem_cons_of_mem _ hq)) l hrest | cons a2 as2 => intro l hl have hstep : StairLoan.addTopLayers (a :: a' :: a2 :: as2) (b :: b' :: bs') (c :: cs') cin = { host := c, up := majority a b cin c, erase := eraseCarry a b cin c, finish := [.CX a b, .CX cin b] } :: StairLoan.addTopLayers (a' :: a2 :: as2) (b' :: bs') cs' c := rfl rw [hstep, List.mem_cons] at hl rcases hl with rfl | hrest · exact hcs c (List.mem_cons_self ..) · exact addTopLayers_hosts (a' :: a2 :: as2) (b' :: bs') cs' c (fun q hq => hcs q (List.mem_cons_of_mem _ hq)) l hrest | [], _, _ => intro l hl; simp [StairLoan.addTopLayers] at hl | [_], _, _ => intro l hl; simp [StairLoan.addTopLayers] at hl | _, [], _ => intro l hl; simp [StairLoan.addTopLayers] at hl | _, [_], _ => intro l hl; simp [StairLoan.addTopLayers] at hl | a', b', [] => intro l hl rcases a' with _ | ⟨_, _ | ⟨_, _ | ⟨_, _⟩⟩⟩ <;> rcases b' with _ | ⟨_, _ | ⟨_, _ | ⟨_, _⟩⟩⟩ <;> simp [StairLoan.addTopLayers] at hl private theorem wires_append_sub {A B : Program} {S : Finset Wire} (hA : wires A ⊆ S) (hB : wires B ⊆ S) : wires (A ++ B) ⊆ S := by rw [wires_append]; exact Finset.union_subset hA hB private theorem wires_append_un {A B : Program} {S : Finset Wire} (h : wires (A ++ B) ⊆ S) : wires A ⊆ S ∧ wires B ⊆ S := by rw [wires_append] at h; exact Finset.union_subset_iff.mp h private theorem wires_X_sub {a : Wire} {S : Finset Wire} (ha : a ∈ S) : wires ([Instr.X a] : Program) ⊆ S := by intro q hq have hqa : q = a := by simp [wires, Instr.wires] at hq; exact hq exact hqa ▸ ha private theorem emitLoan_in_jp (d : Nat) (ls : List StairLoan.CarryLayer) (top : Program) (hsw : wires (StairLoan.emitSweep ls top) ⊆ P1Life.junctionFootprint L760) (hls : ∀ l ∈ ls, l.host ∈ P1Life.junctionFootprint L760) : wires (StairLoan.emitLoan d StairLoan.retiredRoles ls top) ⊆ P1Life.junctionFootprint L760 := by have h1 := StairLoanSupport.emitLoan_support_envelope d StairLoan.retiredRoles ls top refine h1.trans (Finset.union_subset (Finset.union_subset hsw ?_) (layerHosts_take_in_jp hls)) intro q hq exact retiredRoles_in_jp q (List.mem_of_mem_take (List.mem_toFinset.mp hq)) private theorem q6Tail_in_jp : ∀ q ∈ ((Q6Structural.q6Carry L760).take 255).drop 1, q ∈ P1Life.junctionFootprint L760 := by intro q hq; rw [mem_q6Carry255_drop1_iff] at hq; rw [mem_jp760_iff]; omega private theorem carry254_in_jp : ∀ q ∈ L760.carry.take 254, q ∈ P1Life.junctionFootprint L760 := by intro q hq; rw [mem_L760_carry254_iff] at hq; rw [mem_jp760_iff]; omega private theorem carry251_in_jp : ∀ q ∈ L760.carry.take 251, q ∈ P1Life.junctionFootprint L760 := by intro q hq have h254 : q ∈ L760.carry.take 254 := by have ht : L760.carry.take 251 = (L760.carry.take 254).take 251 := by rw [List.take_take]; rfl rw [ht] at hq; exact List.mem_of_mem_take hq rw [mem_L760_carry254_iff] at h254; rw [mem_jp760_iff]; omega private theorem jp_of_p1half (divide : Bool) : wires (P1Life.half (base 760) divide base (base 2409)) ⊆ P1Life.junctionFootprint L760 := (RouteA.Rolling1588.half_support divide).trans (Finset.erase_subset _ _) private theorem previousShort_in_jp (d k : Nat) (h0 : wires (P1Life.shortConstAdd L760 k) ⊆ P1Life.junctionFootprint L760) : wires (previousShort d L760 k) ⊆ P1Life.junctionFootprint L760 := by have hx2 : L760.low.getD 2 0 ∈ P1Life.junctionFootprint L760 := mem_jp760_of_eq 2074 rfl (by omega) have hlit : ∀ d', wires (StairLoan.literalConstAddLoan d' StairLoan.retiredRoles (L760.low.drop 3) (L760.carry.take 251) (L760.low.getD 2 0) L760.one (k / 8)) ⊆ P1Life.junctionFootprint L760 := by intro d' have h0lit : wires (literalConstAdd (L760.low.drop 3) (L760.carry.take 251) (L760.low.getD 2 0) L760.one (k / 8)) ⊆ P1Life.junctionFootprint L760 := by delta P1Life.shortConstAdd at h0 exact (wires_append_un h0).1 cases d' with | zero => simpa [StairLoan.literalConstAddLoan] using h0lit | succ d' => simp only [StairLoan.literalConstAddLoan, Nat.succ_ne_zero, if_false, StairLoan.mappedAddLoan] apply emitLoan_in_jp · rw [← StairLoan.mappedAdd_as_sweep] intro q hq have maw := mappedAdd_wires_subset _ _ _ _ hq simp only [List.mem_toFinset, List.mem_append, List.mem_cons, List.not_mem_nil, or_false] at maw rcases maw with ((h1 | h2) | h3) | rfl · exact absurd (mappedConstant_wires none _ _ q h1) (by simp) · exact mem_jp760_of_r q (List.mem_append_left _ (List.mem_of_mem_drop h2)) · exact carry251_in_jp q h3 · exact hx2 · exact mappedLayers_hosts _ _ _ _ carry251_in_jp unfold previousShort split_ifs · exact wires_append_sub (hlit d) (wires_X_sub hx2) · refine wires_append_sub ?_ (wires_X_sub hx2) refine (OddFullPass.rebindMany_wires_sub _ _ _).trans (Finset.union_subset (Finset.union_subset (hlit _) ?_) ?_) · intro q hq exact retiredRoles_in_jp q (List.mem_of_mem_take (List.mem_of_mem_drop (List.mem_toFinset.mp hq))) · intro q hq exact shortFreeHosts_in_jp d q (List.mem_toFinset.mp hq) private theorem shortConstAddLoan_in_jp (d k : Nat) (h0 : wires (P1Life.shortConstAdd L760 k) ⊆ P1Life.junctionFootprint L760) : wires (shortConstAddLoan d L760 k) ⊆ P1Life.junctionFootprint L760 := by apply short_cases d L760 k (fun p => wires p ⊆ P1Life.junctionFootprint L760) (previousShort_in_jp d k h0) intro dir _ lo hi omit42 q hit rcases LiteralTop.support d lo hi omit42 dir q hit with hl | ho | hp | hc · exact mem_jp760_of_r q (List.mem_append_left _ hl) · rw [ho]; exact mem_jp760_of_eq 1043 rfl (by omega) · rw [hp]; exact mem_jp760_of_eq 784 rfl (by omega) · exact carry254_in_jp q hc.1 private theorem half760OddLoan_in_jp (d : Nat) (divide : Bool) : wires (half760OddLoan d divide) ⊆ P1Life.junctionFootprint L760 := by have hp1 := jp_of_p1half divide have h2409 : base 2409 ∈ P1Life.junctionFootprint L760 := mem_jp760_of_eq 2425 rfl (by omega) have hrmsb : L760.rmsb ∈ P1Life.junctionFootprint L760 := mem_jp760_of_eq 2327 rfl (by omega) have hr0 : L760.r0 ∈ P1Life.junctionFootprint L760 := mem_jp760_of_eq 2072 rfl (by omega) have hone : L760.one ∈ P1Life.junctionFootprint L760 := mem_jp760_of_eq 1043 rfl (by omega) have hmove_in_jp : ∀ {host : Wire} {P : Program} (Q : Program), host ∈ P1Life.junctionFootprint L760 → wires (Q6LifetimeResearch.move (base 760) host Q) ⊆ P1Life.junctionFootprint L760 → (∀ q ∈ wires P, q ∈ wires Q ∨ q ∈ P1Life.junctionFootprint L760) → wires (Q6LifetimeResearch.move (base 760) host P) ⊆ P1Life.junctionFootprint L760 := by intro host P Q hh hQ hPQ q hq rw [Q6LifetimeResearch.move, renameProgram_support, Finset.mem_image] at hq rcases hq with ⟨v, hv, rfl⟩ rcases hPQ v hv with hvQ | hvJ · exact hQ (by rw [Q6LifetimeResearch.move, renameProgram_support]; exact Finset.mem_image.mpr ⟨v, hvQ, rfl⟩) · exact jp_swap760 hh hvJ have hmove_un : ∀ {host : Wire} {P : Program}, host ∈ P1Life.junctionFootprint L760 → wires (Q6LifetimeResearch.move (base 760) host P) ⊆ P1Life.junctionFootprint L760 → wires P ⊆ P1Life.junctionFootprint L760 := by intro host P hh hM w hw have hm := hM (by rw [Q6LifetimeResearch.move, renameProgram_support]; exact Finset.mem_image.mpr ⟨w, hw, rfl⟩) simpa [Equiv.swap_apply_self] using jp_swap760 hh hm have hcomp_in : ∀ (fwd : Bool), wires (P1Life.compare (base 760) fwd L760) ⊆ P1Life.junctionFootprint L760 → wires (compareBlockLoan d fwd L760) ⊆ P1Life.junctionFootprint L760 := by intro fwd hP1 delta compareBlockLoan; delta P1Life.compare at hP1 dsimp only at hP1 ⊢ rcases wires_append_un hP1 with ⟨hP1, h7⟩ rcases wires_append_un hP1 with ⟨hP1, h6⟩ rcases wires_append_un hP1 with ⟨hP1, h5⟩ rcases wires_append_un hP1 with ⟨hP1, h4⟩ rcases wires_append_un hP1 with ⟨hP1, h3⟩ rcases wires_append_un hP1 with ⟨h1, h2⟩ refine wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub h1 h2) h3) ?_) h5) h6) h7 refine hmove_in_jp (Q6LifetimeResearch.compareChain fwd (L760.r.drop 1) (L760.y.drop 1) (((Q6Structural.q6Carry L760).take 255).drop 1) (((Q6Structural.q6Carry L760).take 255).getD 0 0) L760.parity) hone h4 ?_ intro w hw have he := StairLoanSupport.emitLoan_support_envelope d StairLoan.retiredRoles (StairLoan.compareLayers fwd (L760.r.drop 1) (L760.y.drop 1) (((Q6Structural.q6Carry L760).take 255).drop 1) (((Q6Structural.q6Carry L760).take 255).getD 0 0) L760.parity) (StairLoan.compareTop fwd (L760.r.drop 1) (L760.y.drop 1) (((Q6Structural.q6Carry L760).take 255).drop 1) (((Q6Structural.q6Carry L760).take 255).getD 0 0) L760.parity) hw rw [← StairLoan.compareChain_as_sweep] at he simp only [Finset.mem_union] at he rcases he with (hsw | hret) | hlay · exact Or.inl hsw · exact Or.inr (retiredRoles_in_jp w (List.mem_of_mem_take (List.mem_toFinset.mp hret))) · exact Or.inr (layerHosts_take_in_jp (compareLayers_hosts _ _ _ _ _ _ q6Tail_in_jp) hlay) cases divide · -- inverse (divide = false) have hp1' : wires (P1Life.inverse (base 760) L760) ⊆ P1Life.junctionFootprint L760 := by delta P1Life.half at hp1; dsimp only at hp1; simp only [Bool.false_eq_true, if_false] at hp1 exact (wires_append_un (wires_append_un hp1).1).2 delta half760OddLoan; dsimp only; simp only [Bool.false_eq_true, if_false] refine wires_append_sub (wires_append_sub (wires_X_sub h2409) ?_) (wires_X_sub h2409) delta inverseLoan; delta P1Life.inverse at hp1' rw [prepareCompare_eq, exposure_eq] rcases wires_append_un hp1' with ⟨hp1', h12⟩ rcases wires_append_un hp1' with ⟨hp1', h11⟩ rcases wires_append_un hp1' with ⟨hp1', h10⟩ rcases wires_append_un hp1' with ⟨hp1', h9⟩ rcases wires_append_un hp1' with ⟨hp1', h8⟩ rcases wires_append_un hp1' with ⟨hp1', h7⟩ rcases wires_append_un hp1' with ⟨hp1', h6⟩ rcases wires_append_un hp1' with ⟨hp1', h5⟩ rcases wires_append_un hp1' with ⟨hp1', h4⟩ rcases wires_append_un hp1' with ⟨hp1', h3⟩ rcases wires_append_un hp1' with ⟨h1, h2⟩ refine wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub h1 (move_in_jp hrmsb (shortConstAddLoan_in_jp d _ (hmove_un hrmsb h2)))) h3) h4) (hcomp_in false h5)) h6) h7) h8) ?_) h10) h11) ?_ · -- unfoldLoan delta unfoldLoan; delta P1Life.unfoldStep at h9 rcases wires_append_un h9 with ⟨h9, hu3⟩ rcases wires_append_un h9 with ⟨hu1, hu2⟩ refine wires_append_sub (wires_append_sub hu1 ?_) hu3 refine hmove_in_jp (mappedSub (ShortBiasedFold.lowBits L760) L760.low (L760.carry.take 254) L760.one) hrmsb hu2 ?_ intro w hw simp only [FoldTop.unfoldSub, wires_append, Finset.mem_union] at hw rcases hw with (hn | hm) | hn · exact Or.inl (by simp only [mappedSub, wires_append, Finset.mem_union, hn, true_or, or_true]) · rcases FoldTop.foldAdd_wires_envelope d w hm with hsw | hret | hcs · exact Or.inl (by simp only [mappedSub, wires_append, Finset.mem_union, hsw, true_or, or_true]) · exact Or.inr (retiredRoles_in_jp w (List.mem_of_mem_take hret)) · exact Or.inr (carry254_in_jp w hcs) · exact Or.inl (by simp only [mappedSub, wires_append, Finset.mem_union, hn, true_or, or_true]) · -- rawSubLoan delta rawSubLoan; delta P1Life.rawSub at h12 dsimp only at h12 ⊢ rw [orMajor_eq, orErase_eq] rcases wires_append_un h12 with ⟨h12, r11⟩ rcases wires_append_un h12 with ⟨h12, r10⟩ rcases wires_append_un h12 with ⟨h12, r9⟩ rcases wires_append_un h12 with ⟨h12, r8⟩ rcases wires_append_un h12 with ⟨h12, r7⟩ rcases wires_append_un h12 with ⟨h12, r6⟩ rcases wires_append_un h12 with ⟨h12, r5⟩ rcases wires_append_un h12 with ⟨h12, r4⟩ rcases wires_append_un h12 with ⟨h12, r3⟩ rcases wires_append_un h12 with ⟨r1, r2⟩ refine wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub r1 r2) r3) r4) ?_) r6) r7) r8) r9) r10) r11 refine hmove_in_jp (Q6LifetimeResearch.addTop ((GuardCompression.source L760).drop 1) ((BalancedCircuit.rawTarget L760).drop 1) (((Q6Structural.q6Carry L760).take 255).drop 1) (((Q6Structural.q6Carry L760).take 255).getD 0 0)) hr0 r5 ?_ intro w hw have he := StairLoanSupport.emitLoan_support_envelope d StairLoan.retiredRoles (StairLoan.addTopLayers ((GuardCompression.source L760).drop 1) ((BalancedCircuit.rawTarget L760).drop 1) (((Q6Structural.q6Carry L760).take 255).drop 1) (((Q6Structural.q6Carry L760).take 255).getD 0 0)) (StairLoan.addTopTop ((GuardCompression.source L760).drop 1) ((BalancedCircuit.rawTarget L760).drop 1) (((Q6Structural.q6Carry L760).take 255).drop 1) (((Q6Structural.q6Carry L760).take 255).getD 0 0)) hw rw [← StairLoan.addTop_as_sweep] at he simp only [Finset.mem_union] at he rcases he with (hsw | hret) | hlay · exact Or.inl hsw · exact Or.inr (retiredRoles_in_jp w (List.mem_of_mem_take (List.mem_toFinset.mp hret))) · exact Or.inr (layerHosts_take_in_jp (addTopLayers_hosts _ _ _ _ q6Tail_in_jp) hlay) · -- forward (divide = true) have hp1' : wires (P1Life.forward (base 760) L760) ⊆ P1Life.junctionFootprint L760 := by delta P1Life.half at hp1; dsimp only at hp1; simp only [if_true] at hp1 exact (wires_append_un (wires_append_un hp1).1).2 delta half760OddLoan; dsimp only; simp only [if_true] refine wires_append_sub (wires_append_sub (wires_X_sub h2409) ?_) (wires_X_sub h2409) delta forwardLoan; delta P1Life.forward at hp1' rw [p1Seed_eq, prepareCompare_eq, exposure_eq] rcases wires_append_un hp1' with ⟨hp1', h14⟩ rcases wires_append_un hp1' with ⟨hp1', h13⟩ rcases wires_append_un hp1' with ⟨hp1', h12⟩ rcases wires_append_un hp1' with ⟨hp1', h11⟩ rcases wires_append_un hp1' with ⟨hp1', h10⟩ rcases wires_append_un hp1' with ⟨hp1', h9⟩ rcases wires_append_un hp1' with ⟨hp1', h8⟩ rcases wires_append_un hp1' with ⟨hp1', h7⟩ rcases wires_append_un hp1' with ⟨hp1', h6⟩ rcases wires_append_un hp1' with ⟨hp1', h5⟩ rcases wires_append_un hp1' with ⟨hp1', h4⟩ rcases wires_append_un hp1' with ⟨hp1', h3⟩ rcases wires_append_un hp1' with ⟨h1, h2⟩ refine wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub h1 ?_) h3) h4) ?_) h6) h7) h8) h9) (hcomp_in true h10)) h11) h12) (move_in_jp hrmsb (shortConstAddLoan_in_jp d _ (hmove_un hrmsb h13)))) h14 · -- rawAddLoan delta rawAddLoan; delta P1Life.rawAdd at h2 dsimp only at h2 ⊢ rw [orMajor_eq, orErase_eq] rcases wires_append_un h2 with ⟨h2, r8⟩ rcases wires_append_un h2 with ⟨h2, r7⟩ rcases wires_append_un h2 with ⟨h2, r6⟩ rcases wires_append_un h2 with ⟨h2, r5⟩ rcases wires_append_un h2 with ⟨h2, r4⟩ rcases wires_append_un h2 with ⟨h2, r3⟩ rcases wires_append_un h2 with ⟨r1, r2⟩ refine wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub (wires_append_sub r1 r2) r3) ?_) r5) r6) r7) r8 refine hmove_in_jp (CoherentTail.addPrefix (L760.ylow.drop 1) (L760.low.drop 1) (((Q6Structural.q6Carry L760).take 255).drop 1) L760.ymsb L760.rmsb L760.one (((Q6Structural.q6Carry L760).take 255).getD 0 0)) hr0 r4 ?_ intro w hw have he := StairLoanSupport.emitLoan_support_envelope d StairLoan.retiredRoles (StairLoan.prefixLayers (L760.ylow.drop 1) (L760.low.drop 1) (((Q6Structural.q6Carry L760).take 255).drop 1) L760.ymsb L760.rmsb L760.one (((Q6Structural.q6Carry L760).take 255).getD 0 0)) (StairLoan.prefixTop (L760.ylow.drop 1) (L760.low.drop 1) (((Q6Structural.q6Carry L760).take 255).drop 1) L760.ymsb L760.rmsb L760.one (((Q6Structural.q6Carry L760).take 255).getD 0 0)) hw rw [← StairLoan.addPrefix_as_sweep] at he simp only [Finset.mem_union] at he rcases he with (hsw | hret) | hlay · exact Or.inl hsw · exact Or.inr (retiredRoles_in_jp w (List.mem_of_mem_take (List.mem_toFinset.mp hret))) · exact Or.inr (layerHosts_take_in_jp (prefixLayers_hosts _ _ _ _ _ _ _ q6Tail_in_jp) hlay) · -- foldLoan delta foldLoan; delta P1Life.fold at h5 rcases wires_append_un h5 with ⟨h5, f3⟩ rcases wires_append_un h5 with ⟨f1, f2⟩ refine wires_append_sub (wires_append_sub f1 ?_) f3 refine hmove_in_jp (mappedAdd (ShortBiasedFold.lowBits L760) L760.low (L760.carry.take 254) L760.one) hrmsb f2 ?_ intro w hw rcases FoldTop.foldAdd_wires_envelope d w hw with hsw | hret | hcs · exact Or.inl hsw · exact Or.inr (retiredRoles_in_jp w (List.mem_of_mem_take hret)) · exact Or.inr (carry254_in_jp w hcs) theorem half760OddLoan_support (d : Nat) (divide : Bool) (hd : d ≤ 43) (h42 : d ≠ 42) : RouteA.Rolling1588.HalfSupport (half760OddLoan d divide) := by have h1 := OddFullPass.P1LifeLoan.half760OddLoan_wires_sub d divide hd h42 have h2 := StairLoanSupport.half760Loan_support760 d divide (by omega) have hnot760 : base 760 ∉ wires (half760OddLoan d divide) := by intro hmem have hs := (Finset.sdiff_subset (h2 (h1 hmem))) rw [StairLoan.half760Loan_zero] at hs exact R2Life760.half760_free divide hs intro q hq exact Finset.mem_erase.mpr ⟨fun e => hnot760 (e ▸ hq), half760OddLoan_in_jp d divide hq⟩ private def basePacketWith (divide : Bool) (P : Program) (j : Nat) : Program := ECDSAAdd.Entrant.Rolling1588.onPacket j (ECDSAAdd.Entrant.Rolling1588.dp ++ ParityCodec5New.untwist) ++ (if divide then RouteA.Rolling1588.cellWith true P j 3 2 ++ RouteA.Rolling1588.cellWith true P j 4 2 ++ ECDSAAdd.Entrant.Rolling1588.onPacket j ECDSAAdd.Entrant.Rolling1588.bridge7 ++ RouteA.Rolling1588.cellWith true P j 4 2 ++ RouteA.Rolling1588.cellWith true P j 3 2 ++ ECDSAAdd.Entrant.Rolling1588.onPacket j ECDSAAdd.Entrant.Rolling1588.bridge5 ++ RouteA.Rolling1588.cellWith true P j 4 2 else RouteA.Rolling1588.cellWith false P j 4 2 ++ ECDSAAdd.Entrant.Rolling1588.onPacket j ECDSAAdd.Entrant.Rolling1588.bridge5 ++ RouteA.Rolling1588.cellWith false P j 3 2 ++ RouteA.Rolling1588.cellWith false P j 4 2 ++ ECDSAAdd.Entrant.Rolling1588.onPacket j ECDSAAdd.Entrant.Rolling1588.bridge7inv ++ RouteA.Rolling1588.cellWith false P j 4 2 ++ RouteA.Rolling1588.cellWith false P j 3 2) ++ ECDSAAdd.Entrant.Rolling1588.onPacket j (ParityCodec5New.twist ++ ECDSAAdd.Entrant.Rolling1588.ep) private theorem cell_eq_cellWith (divide : Bool) (d j active hole : Nat) : OddFullPass.P1LifeLoan.cell divide d j active hole = RouteA.Rolling1588.cellWith divide (half760OddLoan d divide) j active hole := by unfold OddFullPass.P1LifeLoan.cell OddFullPass.P1LifeLoan.halfWindow RouteA.Rolling1588.cellWith RouteA.Rolling1588.halfWindowWith cases divide <;> rfl private theorem basePacket_eq_with (divide : Bool) (d k : Nat) : OddFullPass.P1LifeLoan.basePacket divide d k = basePacketWith divide (half760OddLoan d divide) k := by unfold OddFullPass.P1LifeLoan.basePacket basePacketWith cases divide <;> simp only [if_true, if_false, Bool.false_eq_true, cell_eq_cellWith] private theorem packet_with_cut_frame (P : Program) (divide : Bool) (hlaw : RouteA.Rolling1588.HalfLaw P divide P1Life.oddWord P1Life.oddWord) (hsup : RouteA.Rolling1588.HalfSupport P) (k : Nat) (lo : 1 ≤ k) (hi : k < 102) (hsub : wires (basePacketWith divide P k) ⊆ wires (ECDSAAdd.Entrant.Rolling1588.basePacket divide k)) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400) = true) (X Y : Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if divide then k else k + 1) origin X Y) (renameProgram (shifted (Placement5.pi k)) (basePacketWith divide P k)) (fun state => let V := CompressedFieldSupport.directionalPayload (!divide) (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (X, Y) RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if divide then k + 1 else k) origin V.1 V.2 state) := by intro state records input have hk0 : k ≠ 0 := by omega have hkk : k ≤ k := le_rfl have hk1 : ¬ (k + 1 ≤ k) := by omega let Vout := CompressedFieldSupport.directionalPayload (!divide) (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (X, Y) have raw := RouteA.Rolling1588.cut_window_frame P1Life.oddWord P1Life.oddWord P1Life.oddWord P1Life.oddWord (if divide then k else k + 1) (if divide then k + 1 else k) k hi origin X Y Vout.1 Vout.2 (basePacketWith divide P k) (by cases divide · exact (ECDSAAdd.Entrant.Rolling1588.otherEncodeCut_step base k 102).symm · exact ECDSAAdd.Entrant.Rolling1588.otherEncodeCut_step base k 102) (ECDSAAdd.Entrant.Rolling1588.otherEncodeCut_body_disjoint (if divide then k else k + 1) k hi origin ctx _ (hsub.trans (ECDSAAdd.Entrant.Rolling1588.basePacket_read_support divide k hi))) (fun current tape frame => by have normalized : RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (ECDSAAdd.Entrant.Rolling1588.codeEncodeAt divide (History5.historyMap base (5 * k))) origin X Y current := by cases divide <;> simpa only [ECDSAAdd.Entrant.Rolling1588.encodeGroup, ECDSAAdd.Entrant.Rolling1588.encodeAt, hk0, hkk, hk1, Bool.false_eq_true, if_true, if_false, decide_true, decide_false] using frame let Frame (sIdx : Nat) (V : Fp × Fp) := RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (ECDSAAdd.Entrant.Rolling1588.stageCodeAt divide sIdx (History5.historyMap base (5 * k))) origin V.1 V.2 have opening (V : Fp × Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (ECDSAAdd.Entrant.Rolling1588.codeEncodeAt divide (History5.historyMap base (5 * k))) origin V.1 V.2) (ECDSAAdd.Entrant.Rolling1588.onPacket k ECDSAAdd.Entrant.Rolling1588.stageOpen) (Frame 0 V) := fun s r h => RouteA.Rolling1588.regular_open_frame P1Life.oddWord P1Life.oddWord divide k hi origin ctx V.1 V.2 s r h have step (sIdx lIdx pIdx : Nat) (hs : sIdx < 3) (hl : (lIdx, pIdx) ∈ ECDSAAdd.Entrant.Rolling1588.activeSlots divide sIdx) (V : Fp × Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (Frame sIdx V) (RouteA.Rolling1588.cellWith divide P k pIdx 2) (Frame sIdx (ECDSAAdd.Entrant.Rolling1588.regularStep divide k origin lIdx V)) := fun s r h => RouteA.Rolling1588.regular_cellWith_frame P divide P1Life.oddWord P1Life.oddWord hlaw hsup k sIdx lIdx pIdx hi hs hl origin ctx enabled V.1 V.2 s r h have transfer (sIdx : Nat) (hs : sIdx < 2) (V : Fp × Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (Frame sIdx V) (ECDSAAdd.Entrant.Rolling1588.onPacket k (ECDSAAdd.Entrant.Rolling1588.stageTransition divide sIdx)) (Frame (sIdx + 1) V) := fun s r h => RouteA.Rolling1588.regular_transition_frame P1Life.oddWord P1Life.oddWord divide k sIdx hi hs origin ctx V.1 V.2 s r h have closing (V : Fp × Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (Frame 2 V) (ECDSAAdd.Entrant.Rolling1588.onPacket k ECDSAAdd.Entrant.Rolling1588.stageClose) (RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (ECDSAAdd.Entrant.Rolling1588.codeEncodeAt (!divide) (History5.historyMap base (5 * k))) origin V.1 V.2) := fun s r h => RouteA.Rolling1588.regular_close_frame P1Life.oddWord P1Life.oddWord divide k hi origin ctx V.1 V.2 s r h have h10 : (1 : Nat) ≠ 0 := by decide cases divide · let V1 := ECDSAAdd.Entrant.Rolling1588.regularStep false k origin 4 (X, Y) let V2 := ECDSAAdd.Entrant.Rolling1588.regularStep false k origin 3 V1 let V3 := ECDSAAdd.Entrant.Rolling1588.regularStep false k origin 2 V2 let V4 := ECDSAAdd.Entrant.Rolling1588.regularStep false k origin 1 V3 let V5 := ECDSAAdd.Entrant.Rolling1588.regularStep false k origin 0 V4 have hres := (opening (X, Y)).seq ((step 0 4 4 (by decide) (by decide) (X, Y)).seq ((transfer 0 (by decide) V1).seq ((step 1 3 3 (by decide) (by decide) V1).seq ((step 1 2 4 (by decide) (by decide) V2).seq ((transfer 1 (by decide) V3).seq ((step 2 1 4 (by decide) (by decide) V3).seq ((step 2 0 3 (by decide) (by decide) V4).seq (closing V5)))))))) have hstep := hres current tape normalized rw [show V5 = ECDSAAdd.Entrant.Rolling1588.regularPayload false k origin (X, Y) from by simp only [V5, V4, V3, V2, V1, ECDSAAdd.Entrant.Rolling1588.regularPayload, Bool.false_eq_true, if_false], ECDSAAdd.Entrant.Rolling1588.regularPayload_eq false k hi origin enabled] at hstep simpa only [basePacketWith, Vout, ECDSAAdd.Entrant.Rolling1588.stageOpen, ECDSAAdd.Entrant.Rolling1588.stageClose, ECDSAAdd.Entrant.Rolling1588.stageTransition, ECDSAAdd.Entrant.Rolling1588.encodeGroup, ECDSAAdd.Entrant.Rolling1588.encodeAt, hk0, hkk, hk1, h10, Bool.false_eq_true, Bool.not_false, if_true, if_false, decide_true, decide_false, List.append_assoc] using hstep · let V1 := ECDSAAdd.Entrant.Rolling1588.regularStep true k origin 0 (X, Y) let V2 := ECDSAAdd.Entrant.Rolling1588.regularStep true k origin 1 V1 let V3 := ECDSAAdd.Entrant.Rolling1588.regularStep true k origin 2 V2 let V4 := ECDSAAdd.Entrant.Rolling1588.regularStep true k origin 3 V3 let V5 := ECDSAAdd.Entrant.Rolling1588.regularStep true k origin 4 V4 have hres := (opening (X, Y)).seq ((step 0 0 3 (by decide) (by decide) (X, Y)).seq ((step 0 1 4 (by decide) (by decide) V1).seq ((transfer 0 (by decide) V2).seq ((step 1 2 4 (by decide) (by decide) V2).seq ((step 1 3 3 (by decide) (by decide) V3).seq ((transfer 1 (by decide) V4).seq ((step 2 4 4 (by decide) (by decide) V4).seq (closing V5)))))))) have hstep := hres current tape normalized rw [show V5 = ECDSAAdd.Entrant.Rolling1588.regularPayload true k origin (X, Y) from by simp only [V5, V4, V3, V2, V1, ECDSAAdd.Entrant.Rolling1588.regularPayload, if_true], ECDSAAdd.Entrant.Rolling1588.regularPayload_eq true k hi origin enabled] at hstep simpa only [basePacketWith, Vout, ECDSAAdd.Entrant.Rolling1588.stageOpen, ECDSAAdd.Entrant.Rolling1588.stageClose, ECDSAAdd.Entrant.Rolling1588.stageTransition, ECDSAAdd.Entrant.Rolling1588.encodeGroup, ECDSAAdd.Entrant.Rolling1588.encodeAt, hk0, hkk, hk1, h10, Bool.false_eq_true, Bool.not_true, if_true, if_false, decide_true, decide_false, List.append_assoc] using hstep) state records input have same := Replay5.placed_eq (Placement5.pi k) (basePacketWith divide P k) (fun q hq => Placement5.pi_outside k q hi hq) state records (RouteA.Rolling1588.cutFrame_zero_region P1Life.oddWord P1Life.oddWord _ origin ctx X Y state input) (RouteA.Rolling1588.cutFrame_zero_region P1Life.oddWord P1Life.oddWord _ origin ctx _ _ _ raw.2) rw [same]; exact raw theorem packet_oddLoan_cut_frame (d : Nat) (divide : Bool) (hd : d ≤ 43) (h42 : d ≠ 42) (k : Nat) (lo : 1 ≤ k) (hi : k < 102) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400) = true) (X Y : Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if divide then k else k + 1) origin X Y) (OddFullPass.P1LifeLoan.packet divide d k) (fun state => let V := CompressedFieldSupport.directionalPayload (!divide) (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) (X, Y) RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if divide then k + 1 else k) origin V.1 V.2 state) := by have hsub : wires (OddFullPass.P1LifeLoan.basePacket divide d k) ⊆ wires (ECDSAAdd.Entrant.Rolling1588.basePacket divide k) := by have hp := OddFullPass.P1LifeLoan.packet_wires_sub divide d k hd h42 have hps := StairLoanGroupSupport.packet_sub divide d k (by omega) have hcomb := hp.trans hps rw [OddFullPass.P1LifeLoan.packet, StairGroups.packet_zero, ECDSAAdd.Entrant.Rolling1588.packet, renameProgram_support, renameProgram_support] at hcomb intro q hq obtain ⟨v, hv, eq⟩ := Finset.mem_image.mp (hcomb (Finset.mem_image.mpr ⟨q, hq, rfl⟩)) exact (Equiv.injective _ eq) ▸ hv have hpeq : OddFullPass.P1LifeLoan.packet divide d k = renameProgram (shifted (Placement5.pi k)) (basePacketWith divide (half760OddLoan d divide) k) := by rw [OddFullPass.P1LifeLoan.packet, basePacket_eq_with] rw [hpeq] exact packet_with_cut_frame (half760OddLoan d divide) divide (half760OddLoan_law d divide hd h42) (half760OddLoan_support d divide hd h42) k lo hi (basePacket_eq_with divide d k ▸ hsub) origin ctx enabled X Y theorem groups_oddLoan_cut_frame (d : Nat) (divide : Bool) (hd : d ≤ 43) (h42 : d ≠ 42) (j n : Nat) (lo : 1 ≤ j) (hi : j + n ≤ 102) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400) = true) (X Y : Fp) : ECDSAAdd.Entrant.Rolling1588.StateTriple (RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if divide then j else j + n) origin X Y) (OddFullPass.P1LifeLoan.groups divide d j n) (fun state => let V := Replay5.groupsPayload divide origin j n (X, Y) RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if divide then j + n else j) origin V.1 V.2 state) := RouteA.Rolling1588.route_cut_sequence_frame divide (OddFullPass.P1LifeLoan.packet divide d) (fun k V => CompressedFieldSupport.directionalPayload (!divide) (mixedTranscriptControls origin (base 2400) (Replay5.letters k)) V) (fun k (V : Fp × Fp) => RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord k origin V.1 V.2) 102 (fun k hk kb V => packet_oddLoan_cut_frame d divide hd h42 k hk kb origin ctx enabled V.1 V.2) j n lo hi (X, Y) theorem oddFirstHalf_law (divide : Bool) : JointOdd1588.OddHalfLaw (StairPacket.WindowCallerCosts.oddFirstHalf divide) divide := fun origin clean X Y => P1Life.half_frame (base 760) divide base (base 2409) hn760 mem760 origin clean X Y end ECDSAAdd.Entrant.OddFullPassBridge end end -- ==== end OddTailPart1 ==== -- ==== begin OddLockstepBase ==== section /-! # Odd-word stock lockstep bridge (Division + Multiplication) Couples the stock odd-word kernel heads (`stockOddDivHead`, `stockOddMulHead`, using `WindowFieldCosts.ogroup`, `OddFullPass.P1LifeLoan.hostedGroup`, `JointOdd1588.hostedFirstPacketOdd`, `OddFullPass.CompareDecoderOdd`, `OddFullPass.InverseTailCOdd`, and `OddFullPass.HalfConvertOdd`) directly against the existing stock heads (`oldDivHead`, `oldMulHead`) step by step along `StairField13V3Clean`'s 25-piece decomposition. Produces the four clean deliverables consumed by the window replay tail: 1. `stockOddDiv_cut3`: cut-3 `OCut 1` + `Loan` + `AgreeRY` against `ExteriorEntryCut.stockPrefix`. 2. `stockOddDivHead_eq_oldDivHead`: exact state equality `run stockOddDivHead m tOdd = run oldDivHead n tStd`. 3. `stockOddMul_cut21`: cut-21 `OCut 85` + `Loan` + `AgreeRY` against `WindowExitFrame.stockPrefix k`. 4. `stockOddMulHead_agree_oldMulHead`: `AgreeOutsideR` + `regValue fieldR = oddWord (Y * x / 2)` against `oldMulHead`, plus `mulRawTail_disjoint_fieldR` and `outMap_fix_fieldR`. -/ set_option autoImplicit false section namespace ECDSAAdd.Entrant.OddStockLockstep open ECDSAAdd Arithmetic RecordedQuantum Challenge MappedCompressed Secp256k1 BalancedField open StairConcreteAssembly StairHostsSchedule StairField2V3Seg StairField2V3Replay open StairField2V3Delta StairField2V3Couple StairField2V3Entry StairField2V3RecScratch StairField2V3ExitRec open StairField2V3LastRecX StairField2V3EntryPlanR StairField2V3ExitPlanR open StairField13V3 StairField13V3Clean StairOuterPlacement StairPhysicalLayout open StairLoanExitReachX StairPacket set_option maxRecDepth 30000 set_option maxHeartbeats 2000000 set_option linter.unusedSimpArgs false set_option linter.unusedVariables false attribute [local irreducible] run measurementCount wires renameProgram /-! ## Section 1: Wire regions, `AgreeRY`, `AgreeOutsideR`, `OddRel`, fixed-point lemmas -/ abbrev fieldR : List Wire := wireBlock base 2056 256 abbrev fieldY : List Wire := wireBlock base 770 256 abbrev ryWires : List Wire := fieldR ++ fieldY theorem ryWires_eq : ryWires = fieldR ++ fieldY := rfl theorem mem_ryWires_iff (q : Wire) : q ∈ ryWires ↔ q ∈ fieldR ∨ q ∈ fieldY := by rw [ryWires_eq, List.mem_append] private theorem mem_fieldR_iff (q : Wire) : q ∈ fieldR ↔ 2072 ≤ q ∧ q < 2328 := by simp only [fieldR, wireBlock, List.mem_map, List.mem_range'_1] constructor · rintro ⟨i, ⟨h1, h2⟩, rfl⟩; change 2072 ≤ i + 16 ∧ i + 16 < 2328; omega · rintro ⟨h1, h2⟩ have h16 : 16 ≤ q := Nat.le_trans (by decide) h1 exact ⟨q - 16, ⟨Nat.le_sub_of_add_le h1, Nat.sub_lt_left_of_lt_add h16 h2⟩, Nat.sub_add_cancel h16⟩ private theorem mem_fieldY_iff (q : Wire) : q ∈ fieldY ↔ 786 ≤ q ∧ q < 1042 := by simp only [fieldY, wireBlock, List.mem_map, List.mem_range'_1] constructor · rintro ⟨i, ⟨h1, h2⟩, rfl⟩; change 786 ≤ i + 16 ∧ i + 16 < 1042; omega · rintro ⟨h1, h2⟩ have h16 : 16 ≤ q := Nat.le_trans (by decide) h1 exact ⟨q - 16, ⟨Nat.le_sub_of_add_le h1, Nat.sub_lt_left_of_lt_add h16 h2⟩, Nat.sub_add_cancel h16⟩ def notFieldR (q : Wire) : Bool := !(decide (2072 ≤ q ∧ q < 2328)) def notRY (q : Wire) : Bool := notFieldR q && !(decide (786 ≤ q ∧ q < 1042)) theorem notFieldR_iff (q : Wire) : notFieldR q = true ↔ q ∉ fieldR := by simp only [notFieldR, Bool.not_eq_true', decide_eq_false_iff_not, mem_fieldR_iff] theorem notRY_iff (q : Wire) : notRY q = true ↔ q ∉ ryWires := by simp only [notRY, Bool.and_eq_true, notFieldR_iff, Bool.not_eq_true', decide_eq_false_iff_not, mem_ryWires_iff, mem_fieldY_iff, not_or] /-- Two states agree on phase and on every wire outside `ryWires = fieldR ++ fieldY`. -/ def AgreeRY (a b : State) : Prop := a.phase = b.phase ∧ ∀ q, q ∉ ryWires → a.basis q = b.basis q /-- Two states agree on phase and on every wire outside `fieldR`. -/ def AgreeOutsideR (a b : State) : Prop := a.phase = b.phase ∧ ∀ q, q ∉ fieldR → a.basis q = b.basis q /-- Binary state relation carrying the odd-word vs center-word register correspondence without threading explicit `(X, Y)` parameters across disjoint segments. -/ def OddRel (wR wY : Fp → Nat) (a b : State) : Prop := AgreeRY a b ∧ (∀ X : Fp, regValue fieldR b.basis = centerWord X → regValue fieldR a.basis = wR X) ∧ (∀ Y : Fp, regValue fieldY b.basis = centerWord Y → regValue fieldY a.basis = wY Y) theorem agreeRY_refl (a : State) : AgreeRY a a := ⟨rfl, fun _ _ => rfl⟩ theorem agreeRY_symm {a b : State} (h : AgreeRY a b) : AgreeRY b a := ⟨h.1.symm, fun q hq => (h.2 q hq).symm⟩ theorem agreeRY_trans {a b c : State} (h1 : AgreeRY a b) (h2 : AgreeRY b c) : AgreeRY a c := ⟨h1.1.trans h2.1, fun q hq => (h1.2 q hq).trans (h2.2 q hq)⟩ theorem agreeOutsideR_refl (a : State) : AgreeOutsideR a a := ⟨rfl, fun _ _ => rfl⟩ theorem agreeOutsideR_symm {a b : State} (h : AgreeOutsideR a b) : AgreeOutsideR b a := ⟨h.1.symm, fun q hq => (h.2 q hq).symm⟩ theorem agreeOutsideR_trans {a b c : State} (h1 : AgreeOutsideR a b) (h2 : AgreeOutsideR b c) : AgreeOutsideR a c := ⟨h1.1.trans h2.1, fun q hq => (h1.2 q hq).trans (h2.2 q hq)⟩ theorem agreeRY_of_agreeOutsideR {a b : State} (h : AgreeOutsideR a b) : AgreeRY a b := ⟨h.1, fun q hq => h.2 q (fun hr => hq ((mem_ryWires_iff q).mpr (Or.inl hr)))⟩ theorem agreeOutsideR_of_agreeRY {a b : State} (h : AgreeRY a b) (hy : ∀ q ∈ fieldY, a.basis q = b.basis q) : AgreeOutsideR a b := by refine ⟨h.1, fun q hq => ?_⟩ by_cases hfy : q ∈ fieldY · exact hy q hfy · exact h.2 q (fun hry => ((mem_ryWires_iff q).mp hry).elim hq hfy) theorem basis_eq_of_regValue_eq (r : List Wire) (a b : BasisState) (h : regValue r a = regValue r b) : ∀ q ∈ r, a q = b q := by intro q hq obtain ⟨i, hi, rfl⟩ := List.mem_iff_getElem.mp hq have hb : (a (r.getD i 0)).toNat = (b (r.getD i 0)).toNat := by rw [Arithmetic.regValue_bit r i 0 a hi, Arithmetic.regValue_bit r i 0 b hi, h] rw [List.getD_eq_getElem _ _ hi] at hb cases h1 : a r[i] <;> cases h2 : b r[i] <;> simp_all theorem state_eq_of_agreeOutsideR {a b : State} (h : AgreeOutsideR a b) (hr : regValue fieldR a.basis = regValue fieldR b.basis) : a = b := by apply State.extensionality _ _ h.1 funext q by_cases hfr : q ∈ fieldR · exact basis_eq_of_regValue_eq fieldR a.basis b.basis hr q hfr · exact h.2 q hfr theorem centerWord_injective {x y : Fp} (h : centerWord x = centerWord y) : x = y := by have hd : centerFp x = centerFp y := by rw [← BalancedField.centerWord_decode x, ← BalancedField.centerWord_decode y, h] have hx := BalancedField.centerFp_cast x have hy := BalancedField.centerFp_cast y rw [← hx, ← hy, hd] theorem oddRel_of_agreeRY_values {wR wY : Fp → Nat} {a b : State} (X Y : Fp) (hag : AgreeRY a b) (hRb : regValue fieldR b.basis = centerWord X) (hYb : regValue fieldY b.basis = centerWord Y) (hRa : regValue fieldR a.basis = wR X) (hYa : regValue fieldY a.basis = wY Y) : OddRel wR wY a b := by refine ⟨hag, ?_, ?_⟩ · intro X' hX' have eq := centerWord_injective (hRb.symm.trans hX') subst eq; exact hRa · intro Y' hY' have eq := centerWord_injective (hYb.symm.trans hY') subst eq; exact hYa theorem agreeRY_disjoint (P : Program) (hP : ∀ q ∈ wires P, q ∉ ryWires) {a b : State} (h : AgreeRY a b) (m : List Bool) : AgreeRY (run P m a) (run P m b) := by have inc := Arithmetic.run_local_increment P a b m (fun q hq => h.2 q (hP q hq)) have hp : (run P m a).phase = (run P m b).phase := by have h1 := inc.1; rw [h.1] at h1 revert h1 generalize (run P m a).phase = x generalize (run P m b).phase = y generalize b.phase = z cases x <;> cases y <;> cases z <;> decide refine ⟨hp, fun q hq => ?_⟩ by_cases hp' : q ∈ wires P · exact inc.2 q hp' · rw [run_preserves_outside P m a q hp', run_preserves_outside P m b q hp'] exact h.2 q hq theorem oddRel_disjoint {wR wY : Fp → Nat} (P : Program) (hP : ∀ q ∈ wires P, q ∉ ryWires) {a b : State} (h : OddRel wR wY a b) (m : List Bool) : OddRel wR wY (run P m a) (run P m b) := by have keepR (s : State) : regValue fieldR (run P m s).basis = regValue fieldR s.basis := regValue_congr _ _ _ (fun q hq => run_preserves_outside P m s q (fun hw => hP q hw ((mem_ryWires_iff q).mpr (Or.inl hq)))) have keepY (s : State) : regValue fieldY (run P m s).basis = regValue fieldY s.basis := regValue_congr _ _ _ (fun q hq => run_preserves_outside P m s q (fun hw => hP q hw ((mem_ryWires_iff q).mpr (Or.inr hq)))) refine ⟨agreeRY_disjoint P hP h.1 m, ?_, ?_⟩ · intro X hX; rw [keepR a]; exact h.2.1 X (by rwa [keepR b] at hX) · intro Y hY; rw [keepY a]; exact h.2.2 Y (by rwa [keepY b] at hY) theorem agreeOutsideR_disjoint (P : Program) (hP : ∀ q ∈ wires P, q ∉ fieldR) {a b : State} (h : AgreeOutsideR a b) (m : List Bool) : AgreeOutsideR (run P m a) (run P m b) := by have inc := Arithmetic.run_local_increment P a b m (fun q hq => h.2 q (hP q hq)) have hp : (run P m a).phase = (run P m b).phase := by have h1 := inc.1; rw [h.1] at h1 revert h1 generalize (run P m a).phase = x generalize (run P m b).phase = y generalize b.phase = z cases x <;> cases y <;> cases z <;> decide refine ⟨hp, fun q hq => ?_⟩ by_cases hp' : q ∈ wires P · exact inc.2 q hp' · rw [run_preserves_outside P m a q hp', run_preserves_outside P m b q hp'] exact h.2 q hq theorem regValue_fieldR_disjoint (P : Program) (hP : ∀ q ∈ wires P, q ∉ fieldR) (a : State) (m : List Bool) : regValue fieldR (run P m a).basis = regValue fieldR a.basis := regValue_congr _ _ _ (fun q hq => run_preserves_outside P m a q (fun hw => hP q hw hq)) /-! ### Fixed-point & disjointness checks (`decide +kernel`) -/ theorem fieldPlace_fix_ryWires : ∀ q ∈ ryWires, fieldPlace q = q := by have h : ryWires.all (fun q => decide (fieldPlace q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) theorem fieldPlaceInv_fix_ryWires : ∀ q ∈ ryWires, fieldPlaceInv q = q := by intro q hq have h := congrArg fieldPlaceInv (fieldPlace_fix_ryWires q hq) rw [inv_fieldPlace] at h exact h.symm theorem fieldMap_fix_ryWires : ∀ q ∈ ryWires, fieldMap q = q := by have h : ryWires.all (fun q => decide (fieldMap q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) theorem lowMap_fix_ryWires : ∀ q ∈ ryWires, lowMap q = q := by have h : ryWires.all (fun q => decide (lowMap q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) theorem sig511_fix_ryWires : ∀ q ∈ ryWires, OB5.sig 511 q = q := by have h : ryWires.all (fun q => decide (OB5.sig 511 q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) theorem borrow_fix_ryWires : ∀ q ∈ ryWires, Prefix1590.borrow q = q := by have h : ryWires.all (fun q => decide (Prefix1590.borrow q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) theorem phaseHost_fix_fieldR : ∀ q ∈ fieldR, Rolling1588Lifetime.phaseHost q = q := by have h : fieldR.all (fun q => decide (Rolling1588Lifetime.phaseHost q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) theorem outMap_fix_fieldR : ∀ q ∈ fieldR, Stair44Kernel.outMap q = q := by have h : fieldR.all (fun q => decide (Stair44Kernel.outMap q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) theorem fieldR_disjoint_pool : ∀ q ∈ skywalkPoolWires base, q ∉ fieldR := by have h : (skywalkPoolWires base).all notFieldR = true := by decide +kernel intro q hq; exact (notFieldR_iff q).mp (List.all_eq_true.mp h q hq) theorem ryWires_off : ∀ q ∈ ryWires, Off q := by have h : ryWires.all (fun q => decide (q ∉ EP)) = true := by decide +kernel intro q hq exact off_of_not_EP q (of_decide_eq_true (List.all_eq_true.mp h q hq)) theorem futurePayload_not_ryWires : ∀ B ∈ budgets, ∀ q ∈ futurePayload B, q ∉ ryWires := by have h : budgets.all (fun B => (futurePayload B).all notRY) = true := by decide +kernel intro B hB q hq exact (notRY_iff q).mp (List.all_eq_true.mp (List.all_eq_true.mp h B hB) q hq) theorem exclusiveRoles_not_ryWires : ∀ q ∈ StairSchedule.exclusiveRoles, q ∉ ryWires := by have h : StairSchedule.exclusiveRoles.all notRY = true := by decide +kernel intro q hq; exact (notRY_iff q).mp (List.all_eq_true.mp h q hq) theorem hosts_not_ryWires : ∀ B ∈ budgets, ∀ q ∈ hosts B, q ∉ ryWires := by have h : budgets.all (fun B => (hosts B).all notRY) = true := by decide +kernel intro B hB q hq exact (notRY_iff q).mp (List.all_eq_true.mp (List.all_eq_true.mp h B hB) q hq) theorem poolHosts_not_ryWires : ∀ q ∈ StairV3Primitives.poolHosts, q ∉ ryWires := by have h : StairV3Primitives.poolHosts.all notRY = true := by decide +kernel intro q hq; exact (notRY_iff q).mp (List.all_eq_true.mp h q hq) theorem archives_not_fieldR : ∀ (b : StockArchiveBanks.Bank) (i : Fin 16), StockArchiveBanks.siteAt b i ∉ fieldR := by have h : ∀ (b : StockArchiveBanks.Bank) (i : Fin 16), notFieldR (StockArchiveBanks.siteAt b i) = true := by decide +kernel intro b i; exact (notFieldR_iff _).mp (h b i) theorem fieldR_disjoint_fieldY : ∀ q ∈ fieldR, q ∉ fieldY := by have h : fieldR.all (fun q => decide (q ∉ fieldY)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) theorem pullIn_agreeRY {a b : State} (h : AgreeRY a b) : AgreeRY (pullIn a) (pullIn b) := by refine ⟨h.1, fun q hq => ?_⟩ change a.basis (fieldPlace q) = b.basis (fieldPlace q) apply h.2 intro hmem have eq := fieldPlaceInv_fix_ryWires _ hmem rw [inv_fieldPlace] at eq exact hq (eq ▸ hmem) theorem pullOut_agreeRY {a b : State} (h : AgreeRY a b) : AgreeRY (pullOut a) (pullOut b) := by refine ⟨h.1, fun q hq => ?_⟩ change a.basis (fieldPlaceInv q) = b.basis (fieldPlaceInv q) apply h.2 intro hmem have eq := fieldPlace_fix_ryWires _ hmem rw [fieldPlace_inv] at eq exact hq (eq ▸ hmem) theorem pullIn_regValue_R (a : State) : regValue fieldR (pullIn a).basis = regValue fieldR a.basis := regValue_congr _ _ _ (fun q hq => by change a.basis (fieldPlace q) = a.basis q rw [fieldPlace_fix_ryWires q ((mem_ryWires_iff q).mpr (Or.inl hq))]) theorem pullIn_regValue_Y (a : State) : regValue fieldY (pullIn a).basis = regValue fieldY a.basis := regValue_congr _ _ _ (fun q hq => by change a.basis (fieldPlace q) = a.basis q rw [fieldPlace_fix_ryWires q ((mem_ryWires_iff q).mpr (Or.inr hq))]) theorem pullIn_oddRel {wR wY : Fp → Nat} {a b : State} (h : OddRel wR wY a b) : OddRel wR wY (pullIn a) (pullIn b) := by refine ⟨pullIn_agreeRY h.1, ?_, ?_⟩ · intro X hX; rw [pullIn_regValue_R]; exact h.2.1 X (by rwa [pullIn_regValue_R] at hX) · intro Y hY; rw [pullIn_regValue_Y]; exact h.2.2 Y (by rwa [pullIn_regValue_Y] at hY) theorem pullOut_oddRel {wR wY : Fp → Nat} {a b : State} (h : OddRel wR wY a b) : OddRel wR wY (pullOut a) (pullOut b) := by have rEq (s : State) : regValue fieldR (pullOut s).basis = regValue fieldR s.basis := regValue_congr _ _ _ (fun q hq => by change s.basis (fieldPlaceInv q) = s.basis q rw [fieldPlaceInv_fix_ryWires q ((mem_ryWires_iff q).mpr (Or.inl hq))]) have yEq (s : State) : regValue fieldY (pullOut s).basis = regValue fieldY s.basis := regValue_congr _ _ _ (fun q hq => by change s.basis (fieldPlaceInv q) = s.basis q rw [fieldPlaceInv_fix_ryWires q ((mem_ryWires_iff q).mpr (Or.inr hq))]) refine ⟨pullOut_agreeRY h.1, ?_, ?_⟩ · intro X hX; rw [rEq]; exact h.2.1 X (by rwa [rEq] at hX) · intro Y hY; rw [yEq]; exact h.2.2 Y (by rwa [yEq] at hY) theorem pullState_sig511_agreeRY {a b : State} (h : AgreeRY a b) : AgreeRY (pullState (OB5.sig 511) a) (pullState (OB5.sig 511) b) := by refine ⟨h.1, fun q hq => ?_⟩ change a.basis (OB5.sig 511 q) = b.basis (OB5.sig 511 q) apply h.2 intro hmem have eq := sig511_fix_ryWires _ hmem rw [OB5.sig_invol 511 (by decide)] at eq exact hq (eq ▸ hmem) theorem pullState_sig511_regValue_R (a : State) : regValue fieldR (pullState (OB5.sig 511) a).basis = regValue fieldR a.basis := regValue_congr _ _ _ (fun q hq => by change a.basis (OB5.sig 511 q) = a.basis q rw [sig511_fix_ryWires q ((mem_ryWires_iff q).mpr (Or.inl hq))]) theorem pullState_sig511_regValue_Y (a : State) : regValue fieldY (pullState (OB5.sig 511) a).basis = regValue fieldY a.basis := regValue_congr _ _ _ (fun q hq => by change a.basis (OB5.sig 511 q) = a.basis q rw [sig511_fix_ryWires q ((mem_ryWires_iff q).mpr (Or.inr hq))]) theorem pullState_fieldMap_agreeRY {a b : State} (h : AgreeRY a b) : AgreeRY (pullState fieldMap a) (pullState fieldMap b) := by refine ⟨h.1, fun q hq => ?_⟩ change a.basis (fieldMap q) = b.basis (fieldMap q) apply h.2 intro hmem have eq := fieldMap_fix_ryWires _ hmem have qeq : fieldMap q = fieldMap (fieldMap q) := eq.symm exact hq ((fieldMap_injective qeq).symm ▸ hmem) theorem pullState_fieldMap_regValue_R (a : State) : regValue fieldR (pullState fieldMap a).basis = regValue fieldR a.basis := regValue_congr _ _ _ (fun q hq => by change a.basis (fieldMap q) = a.basis q rw [fieldMap_fix_ryWires q ((mem_ryWires_iff q).mpr (Or.inl hq))]) theorem pullState_fieldMap_regValue_Y (a : State) : regValue fieldY (pullState fieldMap a).basis = regValue fieldY a.basis := regValue_congr _ _ _ (fun q hq => by change a.basis (fieldMap q) = a.basis q rw [fieldMap_fix_ryWires q ((mem_ryWires_iff q).mpr (Or.inr hq))]) /-! ### `ryWires`-disjointness of all shared / segment / glue programs -/ theorem disjoint_ryWires_of_allSites {P : Program} (h : StairWireCheck.allSites notRY P = true) : ∀ q ∈ wires P, q ∉ ryWires := fun q hq => (notRY_iff q).mp (StairWireCheck.allSites_sound notRY P h q hq) theorem disjoint_ryWires_append {A B : Program} (hA : ∀ q ∈ wires A, q ∉ ryWires) (hB : ∀ q ∈ wires B, q ∉ ryWires) : ∀ q ∈ wires (A ++ B), q ∉ ryWires := by intro q hq rw [wires_append, Finset.mem_union] at hq exact hq.elim (hA q) (hB q) theorem disjoint_ryWires_rename {f : Wire → Wire} (inj : Function.Injective f) (fix : ∀ q ∈ ryWires, f q = q) {P : Program} (hP : ∀ q ∈ wires P, q ∉ ryWires) : ∀ q ∈ wires (renameProgram f P), q ∉ ryWires := by intro q hq hmem rw [renameProgram_support] at hq obtain ⟨r, hr, rfl⟩ := Finset.mem_image.mp hq have eq : f (f r) = f r := fix (f r) hmem exact hP r hr ((inj eq) ▸ hmem) theorem disjoint_ryWires_liftF {P : Program} (hP : ∀ q ∈ wires P, q ∉ ryWires) : ∀ q ∈ wires (liftF P), q ∉ ryWires := by rw [show liftF P = renameProgram ExteriorPorts.fieldEquiv P from ExteriorPorts.placedShape P] exact disjoint_ryWires_rename ExteriorPorts.fieldEquiv.injective fieldPlace_fix_ryWires hP theorem disjoint_ryWires_fieldRename {P : Program} (hP : ∀ q ∈ wires P, q ∉ ryWires) : ∀ q ∈ wires (StairSchedule.fieldRename P), q ∉ ryWires := by rw [fieldRename_eq] exact disjoint_ryWires_rename fieldMap_injective fieldMap_fix_ryWires hP private theorem rowSitesL_notRY (B : Nat) (hB : B ∈ budgets) : ∀ q ∈ StairPhysicalPrimitives.rowSitesL B, q ∉ ryWires := by have ok : budgets.all (fun B => (StairPhysicalPrimitives.rowSitesL B).all notRY) = true := by decide +kernel intro q hq exact (notRY_iff q).mp (List.all_eq_true.mp (List.all_eq_true.mp ok B hB) q hq) private theorem of_rowSitesL {B : Nat} (hB : B ∈ budgets) {P : Program} (sub : ∀ q ∈ wires P, q ∈ StairPhysicalPrimitives.rowSitesL B) : ∀ q ∈ wires P, q ∉ ryWires := fun q hq => rowSitesL_notRY B hB q (sub q hq) theorem clearProgram_notRY : ∀ q ∈ wires FourScratchWindow.clearProgram, q ∉ ryWires := disjoint_ryWires_of_allSites (by decide +kernel) theorem unprefix_notRY : ∀ q ∈ wires FourScratchWindow.unprefix, q ∉ ryWires := disjoint_ryWires_of_allSites (by decide +kernel) theorem paritySetup_notRY : ∀ q ∈ wires StairSchedule.paritySetup, q ∉ ryWires := disjoint_ryWires_of_allSites (by decide +kernel) theorem hostedX_notRY : ∀ q ∈ wires StairSchedule.hostedX, q ∉ ryWires := disjoint_ryWires_of_allSites (by decide +kernel) private theorem forwardSites_notRY : ∀ q ∈ StairTerminalV3.forwardSites, q ∉ ryWires := by have h : StairTerminalV3.forwardSites.all notRY = true := by decide +kernel intro q hq; exact (notRY_iff q).mp (List.all_eq_true.mp h q hq) private theorem reverseSites_notRY : ∀ q ∈ StairTerminalV3.reverseSites, q ∉ ryWires := by have h : StairTerminalV3.reverseSites.all notRY = true := by decide +kernel intro q hq; exact (notRY_iff q).mp (List.all_eq_true.mp h q hq) theorem forwardSeg_notRY (B B' a b : Nat) (hB : B ∈ budgets) (hB' : B' ∈ budgets) (ha : a = startFor B) (hb : b = endFor B) (ho : ∀ q ∈ wires (checkpointPrimitives.orient b), q ∉ ryWires) (hp : ∀ q ∈ wires (renameProgram (OB5.sig b) (Rolling1588.Integer.packFirst base true b)), q ∉ ryWires) : ∀ q ∈ wires (StairSchedule.forwardSegment checkpointPrimitives B B' a b), q ∉ ryWires := by subst ha; subst hb exact disjoint_ryWires_append (disjoint_ryWires_append (disjoint_ryWires_append (disjoint_ryWires_append (disjoint_ryWires_append (of_rowSitesL hB (StairPhysicalPrimitives.unpack_rows B hB)) (of_rowSitesL hB (StairPhysicalPrimitives.tickForward_rows B hB))) (of_rowSitesL hB (StairPhysicalPrimitives.middleForward_rows B hB))) ho) hp) (of_rowSitesL hB' (StairPhysicalPrimitives.pack_rows B' hB')) theorem reverseSeg_notRY (B B' a b : Nat) (hB : B ∈ budgets) (hB' : B' ∈ budgets) (ha : a = startFor B) (hb : b = endFor B) (hrev : StairPhysicalPrimitivesFix505.reverseEnd B = b) (ho : ∀ q ∈ wires (checkpointPrimitives.orientR b), q ∉ ryWires) (hu : ∀ q ∈ wires (renameProgram (OB5.sig b) (Rolling1588.unpackAtTick true b)), q ∉ ryWires) : ∀ q ∈ wires (StairSchedule.reverseSegment checkpointPrimitives B B' a b), q ∉ ryWires := by subst ha; subst hb exact disjoint_ryWires_append (disjoint_ryWires_append (disjoint_ryWires_append (disjoint_ryWires_append (disjoint_ryWires_append (of_rowSitesL hB' (StairPhysicalPrimitives.unpack_rows B' hB')) hu) ho) (of_rowSitesL hB (hrev ▸ StairPhysicalPrimitivesFix505.middleReverseFix_rows B hB))) (of_rowSitesL hB (StairPhysicalPrimitives.tickReverse_rows B hB))) (of_rowSitesL hB (StairPhysicalPrimitives.pack_rows B hB)) theorem forward425_notRY : ∀ q ∈ wires (StairSchedule.forwardSegment cp 87 62 425 450), q ∉ ryWires := forwardSeg_notRY 87 62 425 450 (by decide) (by decide) rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem forward450_notRY : ∀ q ∈ wires (StairSchedule.forwardSegment cp 62 47 450 465), q ∉ ryWires := forwardSeg_notRY 62 47 450 465 (by decide) (by decide) rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem forward465_notRY : ∀ q ∈ wires (StairSchedule.forwardSegment cp 47 32 465 480), q ∉ ryWires := forwardSeg_notRY 47 32 465 480 (by decide) (by decide) rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem forward480_notRY : ∀ q ∈ wires (StairSchedule.forwardSegment cp 32 22 480 490), q ∉ ryWires := forwardSeg_notRY 32 22 480 490 (by decide) (by decide) rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem forward490_notRY : ∀ q ∈ wires (StairSchedule.forwardSegment cp 22 12 490 500), q ∉ ryWires := forwardSeg_notRY 22 12 490 500 (by decide) (by decide) rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem reverse425_notRY : ∀ q ∈ wires (StairSchedule.reverseSegment cp 87 62 425 450), q ∉ ryWires := reverseSeg_notRY 87 62 425 450 (by decide) (by decide) rfl rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem reverse450_notRY : ∀ q ∈ wires (StairSchedule.reverseSegment cp 62 47 450 465), q ∉ ryWires := reverseSeg_notRY 62 47 450 465 (by decide) (by decide) rfl rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem reverse465_notRY : ∀ q ∈ wires (StairSchedule.reverseSegment cp 47 32 465 480), q ∉ ryWires := reverseSeg_notRY 47 32 465 480 (by decide) (by decide) rfl rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem reverse480_notRY : ∀ q ∈ wires (StairSchedule.reverseSegment cp 32 22 480 490), q ∉ ryWires := reverseSeg_notRY 32 22 480 490 (by decide) (by decide) rfl rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem reverse490_notRY : ∀ q ∈ wires (StairSchedule.reverseSegment cp 22 12 490 500), q ∉ ryWires := reverseSeg_notRY 22 12 490 500 (by decide) (by decide) rfl rfl rfl (disjoint_ryWires_of_allSites (by decide +kernel)) (disjoint_ryWires_of_allSites (by decide +kernel)) theorem forwardLast_notRY : ∀ q ∈ wires (StairSchedule.forwardLast cp), q ∉ ryWires := by have term : ∀ q ∈ wires cp.forwardTerminal, q ∉ ryWires := fun q hq => forwardSites_notRY q (List.mem_toFinset.mp (StairTerminalV3.forwardTerminalV3_wires hq)) exact disjoint_ryWires_append (disjoint_ryWires_append (disjoint_ryWires_append (of_rowSitesL (B := 12) (by decide) (StairPhysicalPrimitives.unpack_rows 12 (by decide))) (of_rowSitesL (B := 12) (by decide) (StairPhysicalPrimitives.tickForward_rows 12 (by decide)))) (of_rowSitesL (B := 12) (by decide) (StairPhysicalPrimitives.middleForward_rows 12 (by decide)))) term theorem reverseLast_notRY : ∀ q ∈ wires (StairSchedule.reverseLast cp), q ∉ ryWires := by have term : ∀ q ∈ wires cp.reverseTerminal, q ∉ ryWires := fun q hq => reverseSites_notRY q (List.mem_toFinset.mp (StairTerminalV3.reverseTerminalV3_wires hq)) exact disjoint_ryWires_append (disjoint_ryWires_append (disjoint_ryWires_append term (of_rowSitesL (B := 12) (by decide) (StairPhysicalPrimitivesFix505.middleReverseFix_rows 12 (by decide)))) (of_rowSitesL (B := 12) (by decide) (StairPhysicalPrimitives.tickReverse_rows 12 (by decide)))) (of_rowSitesL (B := 12) (by decide) (StairPhysicalPrimitives.pack_rows 12 (by decide))) theorem firstUnpack_notFieldR : ∀ q ∈ wires (renameProgram Rolling1588Lifetime.phaseHost cp.firstUnpack), q ∉ fieldR := by have raw : ∀ q ∈ wires cp.firstUnpack, q ∉ fieldR := by have h4 : (StairPhysicalPrimitives.rowSitesL 87).all (fun q => notFieldR (phaseRelabel q)) = true := by decide +kernel have hrows : ∀ q ∈ wires (renameProgram phaseRelabel (StairPhysicalPrimitives.unpack 87)), q ∉ fieldR := by intro q hq rw [renameProgram_support] at hq obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp hq exact (notFieldR_iff _).mp (List.all_eq_true.mp h4 w (StairPhysicalPrimitives.unpack_rows 87 (by decide) w hw)) have hrest : ∀ q ∈ wires StairPhysicalPhase.phaseBReturn, q ∉ fieldR := by have h : StairWireCheck.allSites notFieldR StairPhysicalPhase.phaseBReturn = true := by decide +kernel exact fun q hq => (notFieldR_iff q).mp (StairWireCheck.allSites_sound notFieldR _ h q hq) have hunp : ∀ q ∈ wires (renameProgram (OB5.sig 425) (Rolling1588.unpackAtTick true 425)), q ∉ fieldR := by have h : StairWireCheck.allSites notFieldR (renameProgram (OB5.sig 425) (Rolling1588.unpackAtTick true 425)) = true := by decide +kernel exact fun q hq => (notFieldR_iff q).mp (StairWireCheck.allSites_sound notFieldR _ h q hq) have hori : ∀ q ∈ wires (renameProgram StairV3Primitives.xRelabel (StairV3Primitives.orient 425)), q ∉ fieldR := by have h : StairWireCheck.allSites notFieldR (renameProgram StairV3Primitives.xRelabel (StairV3Primitives.orient 425)) = true := by decide +kernel exact fun q hq => (notFieldR_iff q).mp (StairWireCheck.allSites_sound notFieldR _ h q hq) intro q hq simp only [cp, checkpointPrimitives, StairV3Primitives.primitives, StairV3Primitives.firstUnpack, wires_append, Finset.mem_union] at hq rcases hq with ((h | h) | h) | h · exact hrows q h · exact hrest q h · exact hunp q h · exact hori q h intro q hq hfr rw [renameProgram_support] at hq obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp hq have eq : Rolling1588Lifetime.phaseHost (Rolling1588Lifetime.phaseHost w) = Rolling1588Lifetime.phaseHost w := phaseHost_fix_fieldR _ hfr exact raw w hw ((Rolling1588Lifetime.phaseHost.injective eq) ▸ hfr) theorem reverse_notFieldR (d : Bool) (n i : Nat) (lo : 1 ≤ i) (hi : i + n ≤ 506) (q : Wire) (hq : q ∈ wires (Rolling1588.reverse d i n)) : q ∉ fieldR := fieldR_disjoint_pool q (List.mem_toFinset.mp (StairPacket.PartialSites.pool_old d i n lo (by omega) hq)) theorem mulRawTail_notFieldR (k : Nat) : ∀ q ∈ wires (renameProgram Rolling1588Lifetime.phaseHost (Stair44Kernel.mulRawTail k)), q ∉ fieldR := by have first_fix : ∀ q ∈ fieldR, Stair44WalkMap.first q = q := by have h : fieldR.all (fun q => decide (Stair44WalkMap.first q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) have rest_fix : ∀ q ∈ fieldR, Stair44WalkMap.rest q = q := by have h : fieldR.all (fun q => decide (Stair44WalkMap.rest q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) have rawX_x1N : ∀ q ∈ wires (renameProgram Stair44Kernel.rawX (ParityXExitInverse23Kernel.x1N k)), q ∉ fieldR := by have pi_fix : ∀ q ∈ fieldR, ParityXExitInverse23Kernel.pi q = q := fun q hq => ParityXExitInverse23Kernel.pi_out q (fun hp => fieldR_disjoint_pool q hp hq) have rawX_fix : ∀ q ∈ fieldR, Stair44Kernel.rawX q = q := by have h : fieldR.all (fun q => decide (Stair44Kernel.rawX q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) have tSites_notR : ∀ w ∈ StairSiteEasy.tSites base (base 2400), w ∉ fieldR := by have h : (StairSiteEasy.tSites base (base 2400)).all notFieldR = true := by decide +kernel intro w hw; exact (notFieldR_iff w).mp (List.all_eq_true.mp h w hw) intro q hq hfr rw [renameProgram_support] at hq obtain ⟨v, hv, rfl⟩ := Finset.mem_image.mp hq have hv_fr : v ∈ fieldR := (Stair44Kernel.rawX.injective (rawX_fix _ hfr)) ▸ hfr have hv1 := ParityXExitInverse23Kernel.x1N_sub k hv rw [ParityXExitInverse23Kernel.x1, renameProgram_support] at hv1 obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp hv1 have hw_fr : w ∈ fieldR := (ParityXExitInverse23Kernel.pi.injective (pi_fix _ hv_fr)) ▸ hv_fr have hw1 := StairSiteEasy.exitMerge_tight base (base 2400) k (ParityXExit.programAll_wires base (base 2400) k hw) exact tSites_notR w (List.mem_toFinset.mp hw1) hw_fr have bwd : ∀ q ∈ wires (Stair44WalkRun.backward true 409), q ∉ fieldR := by intro q hq hfr unfold Stair44WalkRun.backward at hq rw [wires_append, Finset.mem_union] at hq rcases hq with h1 | h2 · rw [renameProgram_support] at h1 obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp h1 have eq := rest_fix _ hfr exact reverse_notFieldR true 409 16 (by decide) (by decide) w hw ((Stair44WalkMap.rest.injective eq) ▸ hfr) · rw [renameProgram_support] at h2 obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp h2 have eq := first_fix _ hfr exact reverse_notFieldR true 15 1 (by decide) (by decide) w hw ((Stair44WalkMap.first.injective eq) ▸ hfr) intro q hq hfr rw [renameProgram_support] at hq obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp hq have hw_fr : w ∈ fieldR := (Rolling1588Lifetime.phaseHost.injective (phaseHost_fix_fieldR _ hfr)) ▸ hfr unfold Stair44Kernel.mulRawTail at hw rw [wires_append, Finset.mem_union] at hw exact hw.elim (fun h => bwd w h hw_fr) (fun h => rawX_x1N w h hw_fr) /-! ## Section 2: `spliceRY`, `CutFrame`, `EncodedFieldFrame`, and boundary helpers -/ /-- Replace `s`'s bits on `ryWires = fieldR ++ fieldY` with `a`'s bits (keeping `s`'s phase and outside bits). -/ def spliceRY (a s : State) : State := ⟨s.phase, fun q => if q ∈ ryWires then a.basis q else s.basis q⟩ theorem spliceRY_agreeRY (a s : State) (hph : a.phase = s.phase) : AgreeRY (spliceRY a s) s := ⟨rfl, fun q hq => by simp only [spliceRY, hq, if_false]⟩ theorem spliceRY_regValue_R (a s : State) : regValue fieldR (spliceRY a s).basis = regValue fieldR a.basis := regValue_congr _ _ _ (fun q hq => by simp only [spliceRY, (mem_ryWires_iff q).mpr (Or.inl hq), if_true]) theorem spliceRY_regValue_Y (a s : State) : regValue fieldY (spliceRY a s).basis = regValue fieldY a.basis := regValue_congr _ _ _ (fun q hq => by simp only [spliceRY, (mem_ryWires_iff q).mpr (Or.inr hq), if_true]) theorem pullState_sig511_spliceRY (a s : State) : pullState (OB5.sig 511) (spliceRY a s) = spliceRY (pullState (OB5.sig 511) a) (pullState (OB5.sig 511) s) := by apply State.extensionality · rfl funext q change (if OB5.sig 511 q ∈ ryWires then a.basis (OB5.sig 511 q) else s.basis (OB5.sig 511 q)) = (if q ∈ ryWires then a.basis (OB5.sig 511 q) else s.basis (OB5.sig 511 q)) by_cases hq : q ∈ ryWires · rw [if_pos hq, sig511_fix_ryWires q hq, if_pos hq] · have hq' : OB5.sig 511 q ∉ ryWires := fun hm => by have eq := sig511_fix_ryWires _ hm rw [OB5.sig_invol 511 (by decide)] at eq exact hq (eq ▸ hm) rw [if_neg hq, if_neg hq'] theorem allEncode_notRY (isA : Bool) : ∀ q ∈ wires (Rolling1588.allEncode base isA 102), q ∉ ryWires := by have h : (wireBlock base 0 512 ++ wireBlock base 1028 512).all notRY = true := by decide +kernel intro q hq have hm := List.mem_toFinset.mp (Rolling1588.allEncode_history_support base isA 102 (by decide) hq) exact (notRY_iff q).mp (List.all_eq_true.mp h q hm) theorem allEncodeCut_notRY (c : Nat) : ∀ q ∈ wires (Rolling1588.allEncodeCut base c 102), q ∉ ryWires := by intro q hq rw [Rolling1588.allEncodeCut_support_eq, ← Rolling1588.allEncode_support_eq base true 102] at hq exact allEncode_notRY true q hq theorem run_disjoint_spliceRY (P : Program) (hP : ∀ q ∈ wires P, q ∉ ryWires) (a s : State) (m : List Bool) : run P m (spliceRY a s) = spliceRY a (run P m s) := by have inc := Arithmetic.run_local_increment P (spliceRY a s) s m (fun q hq => by simp only [spliceRY, hP q hq, if_false]) have hph : (run P m (spliceRY a s)).phase = (spliceRY a (run P m s)).phase := by have h1 := inc.1 change ((run P m (spliceRY a s)).phase ^^ s.phase) = ((run P m s).phase ^^ s.phase) at h1 change (run P m (spliceRY a s)).phase = (run P m s).phase revert h1 generalize (run P m (spliceRY a s)).phase = x generalize (run P m s).phase = y generalize s.phase = z cases x <;> cases y <;> cases z <;> decide apply State.extensionality _ _ hph funext q by_cases hmem : q ∈ ryWires · have hnot : q ∉ wires P := fun hw => hP q hw hmem rw [run_preserves_outside P m (spliceRY a s) q hnot] simp only [spliceRY, hmem, if_true] · change (run P m (spliceRY a s)).basis q = (if q ∈ ryWires then a.basis q else (run P m s).basis q) rw [if_neg hmem] by_cases hp : q ∈ wires P · exact inc.2 q hp · rw [run_preserves_outside P m (spliceRY a s) q hp, run_preserves_outside P m s q hp] simp only [spliceRY, hmem, if_false] theorem cutFrame_spliceRY (wR wY : Fp → Nat) (c : Nat) (origin : BasisState) (X Y : Fp) (a s : State) (hcut : Rolling1588.CutFrame c origin X Y (pullState (OB5.sig 511) s)) (hRa : regValue fieldR a.basis = wR X) (hYa : regValue fieldY a.basis = wY Y) : RouteA.Rolling1588.CutFrame wR wY c origin X Y (pullState (OB5.sig 511) (spliceRY a s)) := by obtain ⟨raw, hph, hpair, henc⟩ := hcut refine ⟨spliceRY (pullState (OB5.sig 511) a) raw, hph, ?_, ?_⟩ · refine ⟨?_, ?_, ?_⟩ · change regValue fieldR (spliceRY (pullState (OB5.sig 511) a) raw).basis = wR X rw [spliceRY_regValue_R, pullState_sig511_regValue_R]; exact hRa · change regValue fieldY (spliceRY (pullState (OB5.sig 511) a) raw).basis = wY Y rw [spliceRY_regValue_Y, pullState_sig511_regValue_Y]; exact hYa · intro q hnr hny have hnot : q ∉ ryWires := fun hm => ((mem_ryWires_iff q).mp hm).elim hnr hny simp only [spliceRY, hnot, if_false] exact hpair.2.2 q hnr hny · rw [pullState_sig511_spliceRY, henc, run_disjoint_spliceRY _ (allEncodeCut_notRY c)] theorem cutFrame_values (wR wY : Fp → Nat) (c : Nat) (origin : BasisState) (X Y : Fp) (t : State) (hcut : RouteA.Rolling1588.CutFrame wR wY c origin X Y t) : regValue fieldR t.basis = wR X ∧ regValue fieldY t.basis = wY Y := by obtain ⟨raw, _, hpair, henc⟩ := hcut rw [henc] constructor · exact (regValue_congr _ _ _ (fun q hq => run_preserves_outside _ [] raw q (fun hw => allEncodeCut_notRY c q hw ((mem_ryWires_iff q).mpr (Or.inl hq))))).trans hpair.1 · exact (regValue_congr _ _ _ (fun q hq => run_preserves_outside _ [] raw q (fun hw => allEncodeCut_notRY c q hw ((mem_ryWires_iff q).mpr (Or.inr hq))))).trans hpair.2.1 theorem cutFrame_std_values (c : Nat) (origin : BasisState) (X Y : Fp) (t : State) (hcut : Rolling1588.CutFrame c origin X Y t) : regValue fieldR t.basis = centerWord X ∧ regValue fieldY t.basis = centerWord Y := cutFrame_values centerWord centerWord c origin X Y t hcut theorem cutFrame_agreeRY (wR wY : Fp → Nat) (c : Nat) (origin : BasisState) (X1 Y1 X2 Y2 : Fp) (t1 t2 : State) (hph : t1.phase = t2.phase) (h1 : RouteA.Rolling1588.CutFrame wR wY c origin X1 Y1 t1) (h2 : Rolling1588.CutFrame c origin X2 Y2 t2) : AgreeRY t1 t2 := by obtain ⟨raw1, hp1, hf1, he1⟩ := h1 obtain ⟨raw2, hp2, hf2, he2⟩ := h2 have hraw : AgreeRY raw1 raw2 := by refine ⟨hp1.trans (hph.trans hp2.symm), fun q hq => ?_⟩ have hnr : q ∉ fieldR := fun h => hq ((mem_ryWires_iff q).mpr (Or.inl h)) have hny : q ∉ fieldY := fun h => hq ((mem_ryWires_iff q).mpr (Or.inr h)) exact (hf1.2.2 q hnr hny).trans (hf2.2.2 q hnr hny).symm rw [he1, he2] exact agreeRY_disjoint _ (allEncodeCut_notRY c) hraw [] theorem encodedFieldFrame_spliceRY (wR wY : Fp → Nat) (isA : Bool) (origin : BasisState) (X Y : Fp) (a s : State) (hin : Rolling1588Frame.EncodedFieldFrame isA origin X Y s) (hRa : regValue fieldR a.basis = wR X) (hYa : regValue fieldY a.basis = wY Y) : JointOdd1588.EncodedFieldFrameOdd wR wY isA origin X Y (spliceRY a s) := by obtain ⟨raw, hph, hpair, henc⟩ := hin refine ⟨spliceRY (pullState (OB5.sig 511) a) raw, hph, ?_, ?_⟩ · refine ⟨?_, ?_, ?_⟩ · change regValue fieldR (spliceRY (pullState (OB5.sig 511) a) raw).basis = wR X rw [spliceRY_regValue_R, pullState_sig511_regValue_R]; exact hRa · change regValue fieldY (spliceRY (pullState (OB5.sig 511) a) raw).basis = wY Y rw [spliceRY_regValue_Y, pullState_sig511_regValue_Y]; exact hYa · intro q hnr hny have hnot : q ∉ ryWires := fun hm => ((mem_ryWires_iff q).mp hm).elim hnr hny simp only [spliceRY, hnot, if_false] exact hpair.2.2 q hnr hny · rw [pullState_sig511_spliceRY, henc, run_disjoint_spliceRY _ (allEncode_notRY isA)] theorem encodedFieldFrameOdd_values (wR wY : Fp → Nat) (isA : Bool) (origin : BasisState) (X Y : Fp) (s : State) (h : JointOdd1588.EncodedFieldFrameOdd wR wY isA origin X Y s) : regValue fieldR s.basis = wR X ∧ regValue fieldY s.basis = wY Y := by obtain ⟨raw, _, hpair, henc⟩ := h constructor · rw [← pullState_sig511_regValue_R, henc] exact (regValue_congr _ _ _ (fun q hq => run_preserves_outside _ [] raw q (fun hw => allEncode_notRY isA q hw ((mem_ryWires_iff q).mpr (Or.inl hq))))).trans hpair.1 · rw [← pullState_sig511_regValue_Y, henc] exact (regValue_congr _ _ _ (fun q hq => run_preserves_outside _ [] raw q (fun hw => allEncode_notRY isA q hw ((mem_ryWires_iff q).mpr (Or.inr hq))))).trans hpair.2.1 theorem encodedFieldFrame_values (isA : Bool) (origin : BasisState) (X Y : Fp) (s : State) (h : Rolling1588Frame.EncodedFieldFrame isA origin X Y s) : regValue fieldR s.basis = centerWord X ∧ regValue fieldY s.basis = centerWord Y := encodedFieldFrameOdd_values centerWord centerWord isA origin X Y s h theorem encodedFieldFrame_agreeRY (wR wY : Fp → Nat) (isA : Bool) (origin : BasisState) (X1 Y1 X2 Y2 : Fp) (s1 s2 : State) (hph : s1.phase = s2.phase) (h1 : JointOdd1588.EncodedFieldFrameOdd wR wY isA origin X1 Y1 s1) (h2 : Rolling1588Frame.EncodedFieldFrame isA origin X2 Y2 s2) : AgreeRY s1 s2 := by obtain ⟨raw1, hp1, hf1, he1⟩ := h1 obtain ⟨raw2, hp2, hf2, he2⟩ := h2 have hraw : AgreeRY raw1 raw2 := by refine ⟨hp1.trans (hph.trans hp2.symm), fun q hq => ?_⟩ have hnr : q ∉ fieldR := fun h => hq ((mem_ryWires_iff q).mpr (Or.inl h)) have hny : q ∉ fieldY := fun h => hq ((mem_ryWires_iff q).mpr (Or.inr h)) exact (hf1.2.2 q hnr hny).trans (hf2.2.2 q hnr hny).symm have hp : AgreeRY (pullState (OB5.sig 511) s1) (pullState (OB5.sig 511) s2) := by rw [he1, he2] exact agreeRY_disjoint _ (allEncode_notRY isA) hraw [] have hu := pullState_sig511_agreeRY hp rwa [StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide)), StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide))] at hu end ECDSAAdd.Entrant.OddStockLockstep end end -- ==== end OddLockstepBase ==== -- ==== begin OddLockstepSteps ==== section set_option autoImplicit false section namespace ECDSAAdd.Entrant.OddStockLockstep open ECDSAAdd Arithmetic RecordedQuantum Challenge MappedCompressed Secp256k1 BalancedField open StairConcreteAssembly StairHostsSchedule StairField2V3Seg StairField2V3Replay open StairField2V3Delta StairField2V3Couple StairField2V3Entry StairField2V3RecScratch StairField2V3ExitRec open StairField2V3LastRecX StairField2V3EntryPlanR StairField2V3ExitPlanR open StairField13V3 StairField13V3Clean StairOuterPlacement StairPhysicalLayout open StairLoanExitReachX StairPacket set_option maxRecDepth 30000 set_option maxHeartbeats 2000000 set_option linter.unusedSimpArgs false set_option linter.unusedVariables false attribute [local irreducible] run measurementCount wires renameProgram private theorem phase_eq_of_xor {a b c d e f : Bool} (h1 : (a ^^ c) = (e ^^ f)) (h2 : (b ^^ d) = (e ^^ f)) (h3 : c = d) : a = b := by subst h3 cases a <;> cases b <;> cases c <;> cases e <;> cases f <;> simp_all private theorem phase_eq_of_xor2 {a b c d e1 e2 f1 f2 : Bool} (h1 : (a ^^ c) = (e1 ^^ f1)) (h2 : (b ^^ d) = (e2 ^^ f2)) (he : e1 = f1) (hf : e2 = f2) (hcd : c = d) : a = b := by subst he; subst hf; subst hcd cases a <;> cases b <;> cases c <;> cases e1 <;> cases e2 <;> simp_all private theorem base_not_ryWires_of_zeroRegion (q : Nat) (hq : Placement5.zeroRegion q) : base q ∉ ryWires := by apply (notRY_iff _).mp simp only [notRY, notFieldR, Bool.and_eq_true, Bool.not_eq_true', decide_eq_false_iff_not] change ¬ (2072 ≤ q + 16 ∧ q + 16 < 2328) ∧ ¬ (786 ≤ q + 16 ∧ q + 16 < 1042) rcases hq with ⟨h1, h2⟩ | ⟨h1, h2, _⟩ <;> omega /-! ## Section 3: Uniform hosted group step & `from_record_odd` -/ theorem from_record_odd (c : Nat) (hc1 : 1 ≤ c) (hc2 : c ≤ 85) (origin : BasisState) (X Y : Fp) (r s : State) (cut : RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord c origin X Y (pullState (OB5.sig 511) s)) (tag : r.basis (base 720) = false) (hosted : ∀ q, r.basis (StairArchiveInactive.host q) = r.basis q) (agrees : ∀ q, Off q → q ∉ futurePayload 87 → r.basis q = s.basis q) : WindowFieldView.OCut c origin r := by let b := pullState StairArchiveInactive.host.symm s have back : pullState WindowFieldView.wire b = pullState (OB5.sig 511) s := by have hgen : ∀ (e : Equiv.Perm Wire) (f : Wire → Wire), pullState (fun q => e (f q)) (pullState e.symm s) = pullState f s := fun e f => by apply State.extensionality · rfl · funext q; change s.basis (e.symm (e (f q))) = s.basis (f q); rw [e.symm_apply_apply] exact hgen StairArchiveInactive.host (OB5.sig 511) refine ⟨tag, X, Y, b, ?_, ?_⟩ · rw [WindowFieldView.oddCutWord_odd hc1 hc2, back]; exact cut · intro q hq ntag have ready := WindowFieldView.reliable hq ntag have fixed := hosted (StairArchiveInactive.host.symm q) rw [Equiv.apply_symm_apply] at fixed exact fixed.trans (agrees _ ready.1 ready.2) /-- Uniform lockstep across ANY hosted group `(d, def_, start, len)` on `OddFullPass.P1LifeLoan.hostedGroup` versus the logical stock group `liftF (renameProgram (OB5.sig 511) (StairGroups.groups d def_ start len))`. -/ theorem odd_hostedGroup_step (d : Bool) (def_ start len B x : Nat) (hdef : def_ ≤ 43) (h42 : def_ ≠ 42) (hlo : 1 ≤ start) (hhi : start + len ≤ 102) (hB_mem : B = 0 ∨ B ∈ budgets) (havoid_payload : B ≠ 0 → ∀ q ∈ futurePayload B, q ∉ wires (renameProgram (OB5.sig 511) (Rolling1588.groups d start len))) (a b record : State) (m : List Bool) (hrel : OddRel P1Life.oddWord P1Life.oddWord a b) (hframe : FrameAt x (if d then start else start + len) record) (hagree : if B = 0 then b = record else AgreeOutside (Δv B) b record) (hcleanIn : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group d def_ start len).map lowMap, b.basis q = false) (hcleanOut : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_).map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups d def_ start len))) m b).basis q = false) (hhosts_notRY : ∀ q ∈ hostPlan.group d def_ start len, q ∉ ryWires) (hfresh : ∀ q ∈ hostPlan.group d def_ start len, q ∉ wires (renameProgram (OB5.sig 511) (OddFullPass.P1LifeLoan.groups d def_ start len))) : OddRel P1Life.oddWord P1Life.oddWord (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan d def_ start len)) m a) (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups d def_ start len))) m b) := by let P_odd := renameProgram (OB5.sig 511) (OddFullPass.P1LifeLoan.groups d def_ start len) let P_std := renameProgram (OB5.sig 511) (StairGroups.groups d def_ start len) let P_rec := renameProgram (OB5.sig 511) (Rolling1588.groups d start len) have hsub_odd : wires P_odd ⊆ wires P_rec := by have h1 : wires (OddFullPass.P1LifeLoan.groups d def_ start len) ⊆ wires (StairGroups.groups d def_ start len) := StairLoanGroupSupport.sequence_sub _ _ _ (fun k => OddFullPass.P1LifeLoan.packet_wires_sub d def_ k hdef h42) _ _ have h2 := StairLoanGroupSupport.groups_sub d def_ (by omega) start len rw [show P_odd = renameProgram (OB5.sig 511) _ from rfl, show P_rec = renameProgram (OB5.sig 511) _ from rfl, renameProgram_support, renameProgram_support] exact Finset.image_subset_image (h1.trans h2) have hsub_std : wires P_std ⊆ wires P_rec := by rw [show P_std = renameProgram (OB5.sig 511) _ from rfl, show P_rec = renameProgram (OB5.sig 511) _ from rfl, renameProgram_support, renameProgram_support] exact Finset.image_subset_image (StairLoanGroupSupport.groups_sub d def_ (by omega) start len) have hrec_off : ∀ q ∈ wires P_rec, Off q := by cases d · exact StairField2V3ExitRec.groupsF_off start len hlo hhi · exact groups_off start len hlo hhi obtain ⟨origin, X, Y, s_rec, ctx, en, tr, cut_rec, agree_rec⟩ := hframe -- Agreement between `pullIn b` and `s_rec` on `Off` outside `futurePayload B` have hpb_rec : ∀ q, Off q → (B ≠ 0 → q ∉ futurePayload B) → (pullIn b).basis q = s_rec.basis q := by intro q hq hnp have hbr : (pullIn b).basis q = (pullIn record).basis q := by by_cases hB0 : B = 0 · simp only [hB0, if_true] at hagree; rw [hagree] · simp only [hB0, if_false] at hagree change b.basis (fieldPlace q) = record.basis (fieldPlace q) apply hagree.2 intro hmem simp only [Δv, List.mem_toFinset, List.mem_map] at hmem obtain ⟨r, hr, heq⟩ := hmem have qr : r = q := by have := congrArg fieldPlaceInv heq rwa [inv_fieldPlace, inv_fieldPlace] at this exact hnp hB0 (qr ▸ hr) exact hbr.trans (agree_rec q hq) -- Extract `(centerWord X, centerWord Y)` on `b` have hb_vals : regValue fieldR b.basis = centerWord X ∧ regValue fieldY b.basis = centerWord Y := by have hrec_vals := cutFrame_std_values _ origin X Y _ cut_rec rw [pullState_sig511_regValue_R, pullState_sig511_regValue_Y] at hrec_vals have hEq_ry : ∀ q ∈ ryWires, (pullIn b).basis q = s_rec.basis q := by intro q hq apply hpb_rec q (ryWires_off q hq) intro hB0 hfp rcases hB_mem with rfl | hBm · exact hB0 rfl · exact futurePayload_not_ryWires B hBm q hfp hq constructor · rw [← pullIn_regValue_R] exact (regValue_congr _ _ _ (fun q hq => hEq_ry q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hrec_vals.1 · rw [← pullIn_regValue_Y] exact (regValue_congr _ _ _ (fun q hq => hEq_ry q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hrec_vals.2 have ha_vals : regValue fieldR a.basis = P1Life.oddWord X ∧ regValue fieldY a.basis = P1Life.oddWord Y := ⟨hrel.2.1 X hb_vals.1, hrel.2.2 Y hb_vals.2⟩ -- Splice `pullIn a` onto `s_rec` let s_odd : State := spliceRY (pullIn a) s_rec have hcut_odd : RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if d then start else start + len) origin X Y (pullState (OB5.sig 511) s_odd) := cutFrame_spliceRY P1Life.oddWord P1Life.oddWord _ origin X Y (pullIn a) s_rec cut_rec (by rw [pullIn_regValue_R]; exact ha_vals.1) (by rw [pullIn_regValue_Y]; exact ha_vals.2) -- Run `groups_oddLoan_cut_frame` on `s_odd` and `StairLoanReplay.groups_cut_frame` on `s_rec` have hrun_odd := OddFullPassBridge.groups_oddLoan_cut_frame def_ d hdef h42 start len hlo hhi origin ctx en X Y (pullState (OB5.sig 511) s_odd) m hcut_odd have hrun_std := StairLoanReplay.groups_cut_frame StairOpenWiring.half760 d def_ start len (by omega) hlo hhi origin ctx en X Y (pullState (OB5.sig 511) s_rec) m cut_rec have hconj (P : Program) (u : State) : pullState (OB5.sig 511) (run (renameProgram (OB5.sig 511) P) m u) = run P m (pullState (OB5.sig 511) u) := by rw [run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide))] -- Transfer `run P_odd m (pullIn a)` to `run P_odd m s_odd` via `run_local_increment` have hpa_sodd : ∀ q ∈ wires P_odd, (pullIn a).basis q = s_odd.basis q := by intro q hq by_cases hry : q ∈ ryWires · simp only [s_odd, spliceRY, hry, if_true] · simp only [s_odd, spliceRY, hry, if_false] have h1 := (pullIn_agreeRY hrel.1).2 q hry have h2 := hpb_rec q (hrec_off q (hsub_odd hq)) (fun hB0 hfp => havoid_payload hB0 q hfp (hsub_odd hq)) exact h1.trans h2 have hpb_srec : ∀ q ∈ wires P_std, (pullIn b).basis q = s_rec.basis q := fun q hq => hpb_rec q (hrec_off q (hsub_std hq)) (fun hB0 hfp => havoid_payload hB0 q hfp (hsub_std hq)) have hinc_odd := Arithmetic.run_local_increment P_odd (pullIn a) s_odd m hpa_sodd have hinc_std := Arithmetic.run_local_increment P_std (pullIn b) s_rec m hpb_srec -- Outputs of `P_odd` on `s_odd` and `P_std` on `s_rec` satisfy `AgreeRY` and have oddWord / centerWord of `V` have hout_s_ag : AgreeRY (run P_odd m s_odd) (run P_std m s_rec) := by have hph : (pullState (OB5.sig 511) (run P_odd m s_odd)).phase = (pullState (OB5.sig 511) (run P_std m s_rec)).phase := by rw [hconj, hconj, hrun_odd.1, hrun_std.1]; rfl have h1 := cutFrame_agreeRY P1Life.oddWord P1Life.oddWord _ origin _ _ _ _ _ _ hph (by rw [hconj]; exact hrun_odd.2) (by rw [hconj]; exact hrun_std.2) have h2 := pullState_sig511_agreeRY h1 rwa [StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide)), StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide))] at h2 -- Hence `run P_odd m (pullIn a)` and `run P_std m (pullIn b)` satisfy `AgreeRY`! have hout_ag : AgreeRY (run P_odd m (pullIn a)) (run P_std m (pullIn b)) := by have hph : (run P_odd m (pullIn a)).phase = (run P_std m (pullIn b)).phase := by have hp1 : (run P_odd m s_odd).phase = s_odd.phase := by have := hrun_odd.1; rw [← hconj] at this; exact this have hp2 : (run P_std m s_rec).phase = s_rec.phase := by have := hrun_std.1; rw [← hconj] at this; exact this exact phase_eq_of_xor2 hinc_odd.1 hinc_std.1 hp1 hp2 hrel.1.1 refine ⟨hph, fun q hq => ?_⟩ by_cases h1 : q ∈ wires P_odd · by_cases h2 : q ∈ wires P_std · rw [hinc_odd.2 q h1, hinc_std.2 q h2]; exact hout_s_ag.2 q hq · rw [hinc_odd.2 q h1, run_preserves_outside P_std m (pullIn b) q h2] have h3 := hout_s_ag.2 q hq rw [run_preserves_outside P_std m s_rec q h2] at h3 exact h3.trans (hpb_rec q (hrec_off q (hsub_odd h1)) (fun hB0 hfp => havoid_payload hB0 q hfp (hsub_odd h1))).symm · rw [run_preserves_outside P_odd m (pullIn a) q h1] by_cases h2 : q ∈ wires P_std · rw [hinc_std.2 q h2] have h3 := hout_s_ag.2 q hq rw [run_preserves_outside P_odd m s_odd q h1] at h3 have h4 : (pullIn a).basis q = s_odd.basis q := by simp only [s_odd, spliceRY, hq, if_false] exact ((pullIn_agreeRY hrel.1).2 q hq).trans (hpb_rec q (hrec_off q (hsub_std h2)) (fun hB0 hfp => havoid_payload hB0 q hfp (hsub_std h2))) exact h4.trans h3 · rw [run_preserves_outside P_std m (pullIn b) q h2] exact (pullIn_agreeRY hrel.1).2 q hq -- Drop `rebindMany` on `pullIn a`! have hclean_a_in : ∀ q ∈ StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group d def_ start len, (pullIn a).basis q = false := by intro q hq have hnot : q ∉ ryWires := by rcases List.mem_append.mp hq with hr | hh · exact exclusiveRoles_not_ryWires q (List.mem_of_mem_drop hr) · exact hhosts_notRY q hh have h1 := (pullIn_agreeRY hrel.1).2 q hnot have h2 : (pullIn b).basis q = false := hcleanIn (lowMap q) (List.mem_map.mpr ⟨q, hq, rfl⟩) exact h1.trans h2 have hclean_a_out : ∀ q ∈ StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group d def_ start len, (run P_odd m (pullIn a)).basis q = false := by intro q hq rcases List.mem_append.mp hq with hr | hh · have hnot : q ∉ ryWires := exclusiveRoles_not_ryWires q (List.mem_of_mem_drop hr) have h1 := hout_ag.2 q hnot have h2 := hcleanOut (lowMap q) (List.mem_map.mpr ⟨q, hr, rfl⟩) have h3 : (pullIn (run (liftF P_std) m b)).basis q = false := h2 rw [pullIn_liftF] at h3 exact h1.trans h3 · rw [run_preserves_outside P_odd m (pullIn a) q (hfresh q hh)] exact hclean_a_in q (List.mem_append_right _ hh) have hrebind : run (OddFullPass.P1LifeLoan.hostedGroup hostPlan d def_ start len) m (pullIn a) = run P_odd m (pullIn a) := StairLoan.rebindMany_run _ _ P_odd (pullIn a) m hclean_a_in hclean_a_out -- Values of `V = Replay5.groupsPayload d origin start len (X, Y)` on outputs let V := Replay5.groupsPayload d origin start len (X, Y) have hv_odd : regValue fieldR (run P_odd m (pullIn a)).basis = P1Life.oddWord V.1 ∧ regValue fieldY (run P_odd m (pullIn a)).basis = P1Life.oddWord V.2 := by have hvs := cutFrame_values P1Life.oddWord P1Life.oddWord _ origin V.1 V.2 (pullState (OB5.sig 511) (run P_odd m s_odd)) (by rw [hconj]; exact hrun_odd.2) rw [pullState_sig511_regValue_R, pullState_sig511_regValue_Y] at hvs have hEq (q : Wire) (hq : q ∈ ryWires) : (run P_odd m (pullIn a)).basis q = (run P_odd m s_odd).basis q := by by_cases hw : q ∈ wires P_odd · exact hinc_odd.2 q hw · rw [run_preserves_outside P_odd m (pullIn a) q hw, run_preserves_outside P_odd m s_odd q hw] simp only [s_odd, spliceRY, hq, if_true] exact ⟨(regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hvs.1, (regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hvs.2⟩ have hv_std : regValue fieldR (run P_std m (pullIn b)).basis = centerWord V.1 ∧ regValue fieldY (run P_std m (pullIn b)).basis = centerWord V.2 := by have hvs := cutFrame_std_values _ origin V.1 V.2 (pullState (OB5.sig 511) (run P_std m s_rec)) (by rw [hconj]; exact hrun_std.2) rw [pullState_sig511_regValue_R, pullState_sig511_regValue_Y] at hvs have hEq (q : Wire) (hq : q ∈ ryWires) : (run P_std m (pullIn b)).basis q = (run P_std m s_rec).basis q := by by_cases hw : q ∈ wires P_std · exact hinc_std.2 q hw · rw [run_preserves_outside P_std m (pullIn b) q hw, run_preserves_outside P_std m s_rec q hw] apply hpb_rec q (ryWires_off q hq) intro hB0 hfp rcases hB_mem with rfl | hBm · exact hB0 rfl · exact futurePayload_not_ryWires B hBm q hfp hq exact ⟨(regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hvs.1, (regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hvs.2⟩ have hout_rel : OddRel P1Life.oddWord P1Life.oddWord (run P_odd m (pullIn a)) (run P_std m (pullIn b)) := oddRel_of_agreeRY_values V.1 V.2 hout_ag hv_std.1 hv_std.2 hv_odd.1 hv_odd.2 rw [show renameProgram ExteriorPorts.fieldEquiv _ = liftF _ from (ExteriorPorts.placedShape _).symm, StairField2V3Seg.liftF_run, StairField2V3Seg.liftF_run, hrebind] exact pullOut_oddRel hout_rel theorem rebindMany_append (roles hosts : List Wire) (A B : Program) : StairLoan.rebindMany roles hosts (A ++ B) = StairLoan.rebindMany roles hosts A ++ StairLoan.rebindMany roles hosts B := by induction roles generalizing hosts with | nil => rfl | cons r rs ih => cases hosts with | nil => rfl | cons h hs => simp only [StairLoan.rebindMany, ih hs, Six505.rename_append] theorem ogroup_eq_rebindMany (d : Bool) : ∀ n j, WindowFieldCosts.ogroup d j n = StairLoan.rebindMany StairSchedule.exclusiveRoles (hosts 87) (renameProgram (OB5.sig 511) (PacketSequence.program d (WindowFieldCosts.oddPk d) j n)) | 0, j => by have hnil (rs hs : List Wire) : StairLoan.rebindMany rs hs [] = [] := by induction rs generalizing hs with | nil => rfl | cons _ rs ih => cases hs <;> simp [StairLoan.rebindMany, ih, renameProgram] simp [WindowFieldCosts.ogroup, PacketSequence.program, renameProgram, hnil] | n + 1, j => by have ih := ogroup_eq_rebindMany d n (j + 1) cases d <;> simp only [WindowFieldCosts.ogroup, WindowFieldCosts.opk, PacketSequence.program, Bool.false_eq_true, if_true, if_false, Six505.rename_append, rebindMany_append] at ih ⊢ <;> rw [ih] /-- `oddPk d` wires are contained in `Rolling1588.packet d` for `1 ≤ k ≤ 84`. -/ theorem oddPk_wires_sub (d : Bool) (k : Nat) (_h1 : 1 ≤ k) (_h2 : k ≤ 84) : wires (WindowFieldCosts.oddPk d k) ⊆ wires (Rolling1588.packet d k) := WindowFieldCosts.oddPk_sub d k theorem oddPk_seq_wires_sub (d : Bool) : ∀ n j, 1 ≤ j → j + n ≤ 85 → wires (PacketSequence.program d (WindowFieldCosts.oddPk d) j n) ⊆ wires (Rolling1588.groups d j n) | 0, j, _, _ => by simp [PacketSequence.program, Rolling1588.groups, wires] | n + 1, j, h1, h2 => by have hp := oddPk_wires_sub d j h1 (by omega) have hr := oddPk_seq_wires_sub d n (j + 1) (by omega) (by omega) cases d <;> simp only [Rolling1588.groups, PacketSequence.program, Bool.false_eq_true, if_true, if_false, wires_append] <;> exact Finset.union_subset_union (by assumption) (by assumption) /-- Lockstep across the 84-packet odd group (`WindowFieldCosts.ogroup d 1 84`) vs stock `liftF (renameProgram (OB5.sig 511) (StairGroups.groups d 0 1 84))`. -/ theorem odd_ogroup84_step (d : Bool) (x : Nat) (a b record : State) (m : List Bool) (hrel : OddRel P1Life.oddWord P1Life.oddWord a b) (hframe : FrameAt x (if d then 1 else 85) record) (hagree : AgreeOutside (Δv 87) b record) (hcleanIn : ∀ q ∈ (StairSchedule.exclusiveRoles ++ hostPlan.group d 0 1 84).map lowMap, b.basis q = false) (hcleanOut : ∀ q ∈ StairSchedule.exclusiveRoles.map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups d 0 1 84))) m b).basis q = false) : OddRel P1Life.oddWord P1Life.oddWord (run (renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup d 1 84)) m a) (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups d 0 1 84))) m b) := by let P_odd := renameProgram (OB5.sig 511) (PacketSequence.program d (WindowFieldCosts.oddPk d) 1 84) let P_std := renameProgram (OB5.sig 511) (StairGroups.groups d 0 1 84) let P_rec := renameProgram (OB5.sig 511) (Rolling1588.groups d 1 84) have hsub_odd : wires P_odd ⊆ wires P_rec := by rw [show P_odd = renameProgram (OB5.sig 511) _ from rfl, show P_rec = renameProgram (OB5.sig 511) _ from rfl, renameProgram_support, renameProgram_support] exact Finset.image_subset_image (oddPk_seq_wires_sub d 84 1 (by decide) (by decide)) have hsub_std : wires P_std ⊆ wires P_rec := by rw [show P_std = renameProgram (OB5.sig 511) _ from rfl, show P_rec = renameProgram (OB5.sig 511) _ from rfl, renameProgram_support, renameProgram_support] exact Finset.image_subset_image (StairLoanGroupSupport.groups_sub d 0 (by decide) 1 84) have hrec_off : ∀ q ∈ wires P_rec, Off q := by cases d · exact StairField2V3ExitRec.groupsF_off 1 84 (by decide) (by decide) · exact groups_off 1 84 (by decide) (by decide) have havoid : ∀ q ∈ futurePayload 87, q ∉ wires P_rec := StairField2V3Groups.groups_avoid_payload d 87 (by decide) 84 1 (by decide) obtain ⟨origin, X, Y, s_rec, ctx, en, tr, cut_rec, agree_rec⟩ := hframe have hpb_rec : ∀ q, Off q → q ∉ futurePayload 87 → (pullIn b).basis q = s_rec.basis q := by intro q hq hnp have hbr : (pullIn b).basis q = (pullIn record).basis q := by change b.basis (fieldPlace q) = record.basis (fieldPlace q) apply hagree.2 intro hmem simp only [Δv, List.mem_toFinset, List.mem_map] at hmem obtain ⟨r, hr, heq⟩ := hmem have qr : r = q := by have := congrArg fieldPlaceInv heq rwa [inv_fieldPlace, inv_fieldPlace] at this exact hnp (qr ▸ hr) exact hbr.trans (agree_rec q hq) have hb_vals : regValue fieldR b.basis = centerWord X ∧ regValue fieldY b.basis = centerWord Y := by have hrec_vals := cutFrame_std_values _ origin X Y _ cut_rec rw [pullState_sig511_regValue_R, pullState_sig511_regValue_Y] at hrec_vals have hEq_ry : ∀ q ∈ ryWires, (pullIn b).basis q = s_rec.basis q := fun q hq => hpb_rec q (ryWires_off q hq) (futurePayload_not_ryWires 87 (by decide) q · hq) constructor · rw [← pullIn_regValue_R] exact (regValue_congr _ _ _ (fun q hq => hEq_ry q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hrec_vals.1 · rw [← pullIn_regValue_Y] exact (regValue_congr _ _ _ (fun q hq => hEq_ry q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hrec_vals.2 have ha_vals : regValue fieldR a.basis = P1Life.oddWord X ∧ regValue fieldY a.basis = P1Life.oddWord Y := ⟨hrel.2.1 X hb_vals.1, hrel.2.2 Y hb_vals.2⟩ let s_odd : State := spliceRY (pullIn a) s_rec have hcut_odd : RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if d then 1 else 85) origin X Y (pullState (OB5.sig 511) s_odd) := cutFrame_spliceRY P1Life.oddWord P1Life.oddWord _ origin X Y (pullIn a) s_rec cut_rec (by rw [pullIn_regValue_R]; exact ha_vals.1) (by rw [pullIn_regValue_Y]; exact ha_vals.2) have hrun_odd := WindowFieldView.ofield_cut_frame_odd d origin ctx en X Y (pullState (OB5.sig 511) s_odd) m hcut_odd have hrun_std := StairLoanReplay.groups_cut_frame StairOpenWiring.half760 d 0 1 84 (by decide) (by decide) (by decide) origin ctx en X Y (pullState (OB5.sig 511) s_rec) m cut_rec have hconj (P : Program) (u : State) : pullState (OB5.sig 511) (run (renameProgram (OB5.sig 511) P) m u) = run P m (pullState (OB5.sig 511) u) := by rw [run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide))] have hpa_sodd : ∀ q ∈ wires P_odd, (pullIn a).basis q = s_odd.basis q := by intro q hq by_cases hry : q ∈ ryWires · simp only [s_odd, spliceRY, hry, if_true] · simp only [s_odd, spliceRY, hry, if_false] exact ((pullIn_agreeRY hrel.1).2 q hry).trans (hpb_rec q (hrec_off q (hsub_odd hq)) (fun hfp => havoid q hfp (hsub_odd hq))) have hpb_srec : ∀ q ∈ wires P_std, (pullIn b).basis q = s_rec.basis q := fun q hq => hpb_rec q (hrec_off q (hsub_std hq)) (fun hfp => havoid q hfp (hsub_std hq)) have hinc_odd := Arithmetic.run_local_increment P_odd (pullIn a) s_odd m hpa_sodd have hinc_std := Arithmetic.run_local_increment P_std (pullIn b) s_rec m hpb_srec have hout_s_ag : AgreeRY (run P_odd m s_odd) (run P_std m s_rec) := by have hph : (pullState (OB5.sig 511) (run P_odd m s_odd)).phase = (pullState (OB5.sig 511) (run P_std m s_rec)).phase := by rw [hconj, hconj, hrun_odd.1, hrun_std.1]; rfl have h1 := cutFrame_agreeRY P1Life.oddWord P1Life.oddWord _ origin _ _ _ _ _ _ hph (by rw [hconj]; exact hrun_odd.2) (by rw [hconj]; exact hrun_std.2) have h2 := pullState_sig511_agreeRY h1 rwa [StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide)), StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide))] at h2 have hout_ag : AgreeRY (run P_odd m (pullIn a)) (run P_std m (pullIn b)) := by have hph : (run P_odd m (pullIn a)).phase = (run P_std m (pullIn b)).phase := by have hp1 : (run P_odd m s_odd).phase = s_odd.phase := by have := hrun_odd.1; rw [← hconj] at this; exact this have hp2 : (run P_std m s_rec).phase = s_rec.phase := by have := hrun_std.1; rw [← hconj] at this; exact this exact phase_eq_of_xor2 hinc_odd.1 hinc_std.1 hp1 hp2 hrel.1.1 refine ⟨hph, fun q hq => ?_⟩ by_cases h1 : q ∈ wires P_odd · by_cases h2 : q ∈ wires P_std · rw [hinc_odd.2 q h1, hinc_std.2 q h2]; exact hout_s_ag.2 q hq · rw [hinc_odd.2 q h1, run_preserves_outside P_std m (pullIn b) q h2] have h3 := hout_s_ag.2 q hq rw [run_preserves_outside P_std m s_rec q h2] at h3 exact h3.trans (hpb_rec q (hrec_off q (hsub_odd h1)) (fun hfp => havoid q hfp (hsub_odd h1))).symm · rw [run_preserves_outside P_odd m (pullIn a) q h1] by_cases h2 : q ∈ wires P_std · rw [hinc_std.2 q h2] have h3 := hout_s_ag.2 q hq rw [run_preserves_outside P_odd m s_odd q h1] at h3 have h4 : (pullIn a).basis q = s_odd.basis q := by simp only [s_odd, spliceRY, hq, if_false] exact ((pullIn_agreeRY hrel.1).2 q hq).trans (hpb_rec q (hrec_off q (hsub_std h2)) (fun hfp => havoid q hfp (hsub_std h2))) exact h4.trans h3 · rw [run_preserves_outside P_std m (pullIn b) q h2] exact (pullIn_agreeRY hrel.1).2 q hq have hhost_eq : hostPlan.group d 0 1 84 = hosts 87 := hp_group d 0 1 84 (by decide) have hfresh : ∀ q ∈ hosts 87, q ∉ wires P_odd := by intro q hq hw have hfr := StairField13V3Fresh.hostPlan_group_fresh d 0 1 84 (by simp) q (hhost_eq.symm ▸ hq) have hst : StairSchedule.placedGroups StairConcrete.bestLoans d 0 1 84 = P_rec := by simp only [StairSchedule.placedGroups, StairConcrete.bestLoans, StairGroups.groups_zero, P_rec] rw [hst] at hfr exact hfr (hsub_odd hw) have hclean_a_in : ∀ q ∈ StairSchedule.exclusiveRoles ++ hosts 87, (pullIn a).basis q = false := by intro q hq have hnot : q ∉ ryWires := by rcases List.mem_append.mp hq with hr | hh · exact exclusiveRoles_not_ryWires q hr · exact hosts_not_ryWires 87 (by decide) q hh have h1 := (pullIn_agreeRY hrel.1).2 q hnot have h2 : (pullIn b).basis q = false := hcleanIn (lowMap q) (List.mem_map.mpr ⟨q, by rw [hhost_eq]; exact hq, rfl⟩) exact h1.trans h2 have hclean_a_out : ∀ q ∈ StairSchedule.exclusiveRoles ++ hosts 87, (run P_odd m (pullIn a)).basis q = false := by intro q hq rcases List.mem_append.mp hq with hr | hh · have hnot : q ∉ ryWires := exclusiveRoles_not_ryWires q hr have h1 := hout_ag.2 q hnot have h2 := hcleanOut (lowMap q) (List.mem_map.mpr ⟨q, hr, rfl⟩) have h3 : (pullIn (run (liftF P_std) m b)).basis q = false := h2 rw [pullIn_liftF] at h3 exact h1.trans h3 · rw [run_preserves_outside P_odd m (pullIn a) q (hfresh q hh)] exact hclean_a_in q (List.mem_append_right _ hh) have hrebind : run (WindowFieldCosts.ogroup d 1 84) m (pullIn a) = run P_odd m (pullIn a) := by rw [ogroup_eq_rebindMany] exact StairLoan.rebindMany_run _ _ P_odd (pullIn a) m hclean_a_in hclean_a_out let V := Replay5.groupsPayload d origin 1 84 (X, Y) have hv_odd : regValue fieldR (run P_odd m (pullIn a)).basis = P1Life.oddWord V.1 ∧ regValue fieldY (run P_odd m (pullIn a)).basis = P1Life.oddWord V.2 := by have hvs := cutFrame_values P1Life.oddWord P1Life.oddWord _ origin V.1 V.2 (pullState (OB5.sig 511) (run P_odd m s_odd)) (by rw [hconj]; exact hrun_odd.2) rw [pullState_sig511_regValue_R, pullState_sig511_regValue_Y] at hvs have hEq (q : Wire) (hq : q ∈ ryWires) : (run P_odd m (pullIn a)).basis q = (run P_odd m s_odd).basis q := by by_cases hw : q ∈ wires P_odd · exact hinc_odd.2 q hw · rw [run_preserves_outside P_odd m (pullIn a) q hw, run_preserves_outside P_odd m s_odd q hw] simp only [s_odd, spliceRY, hq, if_true] exact ⟨(regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hvs.1, (regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hvs.2⟩ have hv_std : regValue fieldR (run P_std m (pullIn b)).basis = centerWord V.1 ∧ regValue fieldY (run P_std m (pullIn b)).basis = centerWord V.2 := by have hvs := cutFrame_std_values _ origin V.1 V.2 (pullState (OB5.sig 511) (run P_std m s_rec)) (by rw [hconj]; exact hrun_std.2) rw [pullState_sig511_regValue_R, pullState_sig511_regValue_Y] at hvs have hEq (q : Wire) (hq : q ∈ ryWires) : (run P_std m (pullIn b)).basis q = (run P_std m s_rec).basis q := by by_cases hw : q ∈ wires P_std · exact hinc_std.2 q hw · rw [run_preserves_outside P_std m (pullIn b) q hw, run_preserves_outside P_std m s_rec q hw] exact hpb_rec q (ryWires_off q hq) (futurePayload_not_ryWires 87 (by decide) q · hq) exact ⟨(regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hvs.1, (regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hvs.2⟩ have hout_rel := oddRel_of_agreeRY_values V.1 V.2 hout_ag hv_std.1 hv_std.2 hv_odd.1 hv_odd.2 rw [show renameProgram ExteriorPorts.fieldEquiv _ = liftF _ from (ExteriorPorts.placedShape _).symm, StairField2V3Seg.liftF_run, StairField2V3Seg.liftF_run, hrebind] exact pullOut_oddRel hout_rel /-- Extract `OCut c origin (pullIn a)` from `OddRel` + `FrameAt x c record` + `AgreeOutside (Δv 87)` + `Loan`. -/ theorem odd_cut_ocut (c : Nat) (hc1 : 1 ≤ c) (hc2 : c ≤ 85) (x : Nat) (a b record : State) (hrel : OddRel P1Life.oddWord P1Life.oddWord a b) (hframe : FrameAt x c record) (hagree : AgreeOutside (Δv 87) b record) (hloan : ∀ q ∈ StairSchedule.exclusiveRoles ++ hosts 87, b.basis (fieldPlace q) = false) : ∃ (origin : BasisState), FrontierReplay1591.Context origin ∧ origin (base 2400) = true ∧ TraceOK x origin ∧ WindowFieldView.OCut c origin (pullIn a) := by obtain ⟨origin, X, Y, s_rec, ctx, en, tr, cut_rec, agree_rec⟩ := hframe have hpb_rec : ∀ q, Off q → q ∉ futurePayload 87 → (pullIn b).basis q = s_rec.basis q := by intro q hq hnp have hbr : (pullIn b).basis q = (pullIn record).basis q := by change b.basis (fieldPlace q) = record.basis (fieldPlace q) apply hagree.2 intro hmem simp only [Δv, List.mem_toFinset, List.mem_map] at hmem obtain ⟨r, hr, heq⟩ := hmem have qr : r = q := by have := congrArg fieldPlaceInv heq rwa [inv_fieldPlace, inv_fieldPlace] at this exact hnp (qr ▸ hr) exact hbr.trans (agree_rec q hq) have hb_vals : regValue fieldR b.basis = centerWord X ∧ regValue fieldY b.basis = centerWord Y := by have hrec_vals := cutFrame_std_values _ origin X Y _ cut_rec rw [pullState_sig511_regValue_R, pullState_sig511_regValue_Y] at hrec_vals have hEq_ry : ∀ q ∈ ryWires, (pullIn b).basis q = s_rec.basis q := fun q hq => hpb_rec q (ryWires_off q hq) (futurePayload_not_ryWires 87 (by decide) q · hq) constructor · rw [← pullIn_regValue_R] exact (regValue_congr _ _ _ (fun q hq => hEq_ry q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hrec_vals.1 · rw [← pullIn_regValue_Y] exact (regValue_congr _ _ _ (fun q hq => hEq_ry q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hrec_vals.2 let s_odd : State := spliceRY (pullIn a) s_rec have hcut_odd := cutFrame_spliceRY P1Life.oddWord P1Life.oddWord c origin X Y (pullIn a) s_rec cut_rec (by rw [pullIn_regValue_R]; exact hrel.2.1 X hb_vals.1) (by rw [pullIn_regValue_Y]; exact hrel.2.2 Y hb_vals.2) have hloan_a : ∀ q ∈ StairSchedule.exclusiveRoles ++ hosts 87, (pullIn a).basis q = false := by intro q hq have hnot : q ∉ ryWires := by rcases List.mem_append.mp hq with hr | hh · exact exclusiveRoles_not_ryWires q hr · exact hosts_not_ryWires 87 (by decide) q hh exact ((pullIn_agreeRY hrel.1).2 q hnot).trans (hloan q hq) refine ⟨origin, ctx, en, tr, from_record_odd c hc1 hc2 origin X Y (pullIn a) s_odd hcut_odd (hloan_a (base 720) (by decide +kernel)) (WindowFieldView.host_fixed (pullIn a) hloan_a) ?_⟩ intro q hq hnp by_cases hry : q ∈ ryWires · simp only [s_odd, spliceRY, hry, if_true] · simp only [s_odd, spliceRY, hry, if_false] exact ((pullIn_agreeRY hrel.1).2 q hry).trans (hpb_rec q hq hnp) /-! ### Boundary helpers: `Q6EndpointCell.Clean`, `convWork`, `copyN`, `firstPacketOdd`, `divEndTail`, `mulHeadCore` -/ private theorem q6Clean_of_encoded5 {isA : Bool} (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (X Y : Fp) (s : State) (hin : Rolling1588.EncodedFieldFrame5 base (base 2409) isA origin X Y s) : Q6EndpointCell.Clean base s.basis := by obtain ⟨raw, _, hpair, henc⟩ := hin have hclean := Q6EndpointCell.clean_of_env base origin ctx.env ctx.parity have hnot_ry : (Q6EndpointCell.workIds.map base).all notRY = true := by decide +kernel have hnot_hist : (Q6EndpointCell.workIds.map base).all (fun q => !(decide (16 ≤ q ∧ q < 528)) && !(decide (1044 ≤ q ∧ q < 1556))) = true := by decide +kernel intro q hq have hnr : q ∉ ryWires := (notRY_iff q).mp (List.all_eq_true.mp hnot_ry q hq) have hnh : q ∉ wireBlock base 0 512 ++ wireBlock base 1028 512 := by have hb := List.all_eq_true.mp hnot_hist q hq simp only [Bool.and_eq_true, Bool.not_eq_true', decide_eq_false_iff_not] at hb intro hm rcases List.mem_append.mp hm with h1 | h2 · obtain ⟨i, hi, rfl⟩ := List.mem_map.mp h1 simp only [List.mem_range'_1] at hi exact hb.1 ⟨by change 16 ≤ i + 16; omega, by change i + 16 < 528; omega⟩ · obtain ⟨i, hi, rfl⟩ := List.mem_map.mp h2 simp only [List.mem_range'_1] at hi exact hb.2 ⟨by change 1044 ≤ i + 16; omega, by change i + 16 < 1556; omega⟩ have hne : q ∉ wires (Rolling1588.allEncode base isA 102) := fun hw => hnh (List.mem_toFinset.mp (Rolling1588.allEncode_history_support base isA 102 (by decide) hw)) rw [henc, run_preserves_outside _ [] raw q hne] exact (hpair.2.2 q (fun h => hnr ((mem_ryWires_iff q).mpr (Or.inl h))) (fun h => hnr ((mem_ryWires_iff q).mpr (Or.inr h)))).trans (hclean q hq) private theorem q6Clean_of_agreeRY {a b : State} (h : AgreeRY a b) (hb : Q6EndpointCell.Clean base b.basis) : Q6EndpointCell.Clean base a.basis := by have hnot_ry : (Q6EndpointCell.workIds.map base).all notRY = true := by decide +kernel intro q hq exact (h.2 q ((notRY_iff q).mp (List.all_eq_true.mp hnot_ry q hq))).trans (hb q hq) private theorem convWork_not_fieldR : ∀ q ∈ OddFullPass.HalfConvertOdd.convWork StairBoundaryLoan.converterLayout760, q ∉ fieldR := by have h : (OddFullPass.HalfConvertOdd.convWork StairBoundaryLoan.converterLayout760).all notFieldR = true := by decide +kernel intro q hq; exact (notFieldR_iff q).mp (List.all_eq_true.mp h q hq) private theorem yHosts43_sub_fieldY : ∀ q ∈ OddFullPass.HalfConvertOdd.yHosts43, q ∈ fieldY := by have h : OddFullPass.HalfConvertOdd.yHosts43.all (fun q => decide (q ∈ fieldY)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) private theorem bcWork_extra_pulled : ([StairBoundaryLoan.converterLayout760.flag, StairBoundaryLoan.converterLayout760.cin, StairBoundaryLoan.converterLayout760.one] ++ StairBoundaryLoan.converterLayout760.carry.drop 254).all (fun q => decide (StairBoundaryLoan.PulledClass (OB5.sig 511 q))) = true := by decide +kernel private theorem bcWork_clean_of_encodedField {isA : Bool} (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (X : Fp) (s : State) (hin : Rolling1588Frame.EncodedFieldFrame isA origin X 0 s) : ∀ q ∈ BalancedConvert.work StairBoundaryLoan.converterLayout760, s.basis q = false := by have hcar := StairBoundaryLoan.canon_ladder_clean origin ctx X s hin intro q hq simp only [BalancedConvert.work, BalancedConvert.scratch, List.mem_cons, List.mem_append] at hq have hpull (hm : q ∈ [StairBoundaryLoan.converterLayout760.flag, StairBoundaryLoan.converterLayout760.cin, StairBoundaryLoan.converterLayout760.one] ++ StairBoundaryLoan.converterLayout760.carry.drop 254) : s.basis q = false := by have hpc := of_decide_eq_true (List.all_eq_true.mp bcWork_extra_pulled q hm) have h := StairBoundaryLoan.field_pulled_zero origin ctx X (pullState (OB5.sig 511) s) hin _ hpc change s.basis (OB5.sig 511 (OB5.sig 511 q)) = false at h; rwa [StairBoundaryLoan.sig511_invol] at h rcases hq with rfl | (rfl | rfl | _) | hc · exact hpull (by simp) · exact hpull (by simp) · exact hpull (by simp) · simp at * · rw [← List.take_append_drop 254 StairBoundaryLoan.converterLayout760.carry, List.mem_append] at hc rcases hc with h1 | h2 · exact hcar q h1 · exact hpull (List.mem_append_right _ h2) private theorem convWork_clean_of_encodedField {isA : Bool} (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (X : Fp) (s : State) (hin : Rolling1588Frame.EncodedFieldFrame isA origin X 0 s) : ∀ q ∈ OddFullPass.HalfConvertOdd.convWork StairBoundaryLoan.converterLayout760, s.basis q = false := by intro q hq apply bcWork_clean_of_encodedField origin ctx X s hin q simp only [OddFullPass.HalfConvertOdd.convWork, BalancedConvert.work, BalancedConvert.scratch, List.mem_cons, List.mem_append] at hq ⊢ rcases hq with rfl | rfl | hc · exact Or.inl rfl · exact Or.inr (Or.inl (Or.inl rfl)) · exact Or.inr (Or.inr (List.mem_of_mem_take hc)) private theorem allEncode_510_free (isA : Bool) : base 510 ∉ wires (Rolling1588.allEncode base isA 102) := by have hgen : ∀ n, 5 * n ≤ 510 → base 510 ∉ wires (Rolling1588.allEncode base isA n) := by intro n induction n with | zero => intro _; simp [Rolling1588.allEncode, wires] | succ n ih => intro hn hw rw [Rolling1588.allEncode, wires_append, Finset.mem_union] at hw rcases hw with h1 | h2 · exact ih (by omega) h1 · rw [Rolling1588.encodeGroup_support_eq, NewHistory5.encode_support_eq] at h2 obtain ⟨j, hj⟩ := History5.history_gate_mem base (5 * n) _ (Or.inl rfl) (base 510) h2 have eq : 510 = History5.historyId (5 * n) j := by have := congrArg (· - 16) hj simpa [base] using this unfold History5.historyId at eq have jlt := j.isLt split_ifs at eq <;> omega exact hgen 102 (by decide) private theorem bcWork_clean_of_encodedCanonical {isA : Bool} (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (ha : regValue (skywalkSharedField base).a origin = 0) (X : Fp) (s : State) (hin : Rolling1588Frame.EncodedCanonicalFrame isA origin X 0 s) : ∀ q ∈ BalancedConvert.work StairBoundaryLoan.converterLayout760, s.basis q = false := by have hcar := StairBoundaryLoan.center_ladder_clean origin ctx ha X s hin intro q hq simp only [BalancedConvert.work, BalancedConvert.scratch, List.mem_cons, List.mem_append] at hq have hpull (hm : q ∈ [StairBoundaryLoan.converterLayout760.flag, StairBoundaryLoan.converterLayout760.cin, StairBoundaryLoan.converterLayout760.one] ++ StairBoundaryLoan.converterLayout760.carry.drop 254) : s.basis q = false := by have hpc := of_decide_eq_true (List.all_eq_true.mp bcWork_extra_pulled q hm) have h := StairBoundaryLoan.canonical_pulled_zero origin ctx ha X (pullState (OB5.sig 511) s) hin _ hpc change s.basis (OB5.sig 511 (OB5.sig 511 q)) = false at h; rwa [StairBoundaryLoan.sig511_invol] at h rcases hq with rfl | (rfl | rfl | _) | hc · exact hpull (by simp) · exact hpull (by simp) · exact hpull (by simp) · simp at * · rw [← List.take_append_drop 254 StairBoundaryLoan.converterLayout760.carry, List.mem_append] at hc rcases hc with h1 | h2 · exact hcar q h1 · exact hpull (List.mem_append_right _ h2) private theorem convWork_clean_of_encodedCanonical {isA : Bool} (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (ha : regValue (skywalkSharedField base).a origin = 0) (X : Fp) (s : State) (hin : Rolling1588Frame.EncodedCanonicalFrame isA origin X 0 s) : ∀ q ∈ OddFullPass.HalfConvertOdd.convWork StairBoundaryLoan.converterLayout760, s.basis q = false := by intro q hq apply bcWork_clean_of_encodedCanonical origin ctx ha X s hin q simp only [OddFullPass.HalfConvertOdd.convWork, BalancedConvert.work, BalancedConvert.scratch, List.mem_cons, List.mem_append] at hq ⊢ rcases hq with rfl | rfl | hc · exact Or.inl rfl · exact Or.inr (Or.inl (Or.inl rfl)) · exact Or.inr (Or.inr (List.mem_of_mem_take hc)) /-- `HalfFieldOB5.copyN` preserves phase and everything outside `fieldY`, and XORs `fieldR` into `fieldY`. -/ theorem copyN_step (hn : (skywalkSharedWires base).Nodup) (s : State) (m : List Bool) : (run HalfFieldOB5.copyN m s).phase = s.phase ∧ (∀ q, q ∉ fieldY → (run HalfFieldOB5.copyN m s).basis q = s.basis q) ∧ regValue fieldY (run HalfFieldOB5.copyN m s).basis = regValue fieldY s.basis ^^^ regValue fieldR s.basis := by have len : (balancedSharedPorts base (base 2409)).r.length = (balancedSharedPorts base (base 2409)).y.length := by rw [balancedSharedPorts_r, balancedSharedPorts_y]; simp [wireBlock_length] obtain ⟨hph, hkeep, hval⟩ := copyRegister_correct none (balancedSharedPorts base (base 2409)).r (balancedSharedPorts base (base 2409)).y len (balancedSharedLayout_pairND base (base 2409) hn) (by simp) s m refine ⟨hph, ?_, ?_⟩ · intro q hq exact hkeep q (by rw [balancedSharedPorts_y]; exact hq) · simpa only [copyValue, balancedSharedPorts_r, balancedSharedPorts_y] using hval /-- Lockstep for `firstPacketOdd` (both `divide = true` at cut 1 and `divide = false` at cut 23). -/ theorem firstPacketOdd_step (divide isA : Bool) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400) = true) (x : Nat) (hx : x < p) (trace : skywalkTapeControls origin (skywalkSharedTape base) = SkywalkTrace.trace 512 (SkywalkRails.encode false false (x : Int) (p : Int))) (X Y : Fp) (hz : FirstZero.FirstHyp divide origin X Y) (a b s_rec : State) (m : List Bool) (hag : AgreeRY a b) (hrec : Rolling1588Frame.EncodedFieldFrame isA origin X Y s_rec) (hpb_fp : ∀ q, StairWireCheck.fpSup q = true → (pullState fieldMap b).basis q = s_rec.basis q) (hpb_ry : ∀ q ∈ ryWires, (pullState fieldMap b).basis q = s_rec.basis q) (hRa : regValue fieldR a.basis = P1Life.oddWord X) (hYa : regValue fieldY a.basis = JointOdd1588.firstYIn divide Y) (hcleanIn : ∀ q ∈ (StairSchedule.exclusiveRoles ++ hostPlan.firstPacket divide).map fieldMap, b.basis q = false) (hcleanOut : ∀ q ∈ StairSchedule.exclusiveRoles.map fieldMap, (run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket divide)) m b).basis q = false) : let V := Replay5.firstPayload divide origin (X, Y) let a' := run (StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf divide)) m a let b' := run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket divide)) m b AgreeRY a' b' ∧ regValue fieldR a'.basis = P1Life.oddWord V.1 ∧ regValue fieldY a'.basis = JointOdd1588.firstYOut divide V.2 ∧ regValue fieldR b'.basis = centerWord V.1 ∧ regValue fieldY b'.basis = centerWord V.2 := by let P_odd := JointOdd1588.placedFirstPacketOdd WindowCallerCosts.oddFirstHalf divide let P_std := Rolling1588.placedFirstPacket divide have hfp_odd : ∀ q ∈ wires P_odd, StairWireCheck.fpSup q = true := StairWireCheck.allSites_sound StairWireCheck.fpSup P_odd (JointOdd1588.placedFirstPacketOdd_passSup WindowCallerCosts.oddFirstHalf divide (WindowCallerCosts.oddFirstHalf_support divide)) have hfp_std : ∀ q ∈ wires P_std, StairWireCheck.fpSup q = true := StairWireCheck.allSites_sound StairWireCheck.fpSup P_std (by cases divide; exact StairFirstPacketKernel.passSup_false; exact StairFirstPacketKernel.passSup_true) let s_odd : State := spliceRY (pullState fieldMap a) s_rec have hframe_odd : JointOdd1588.EncodedFieldFrameOdd P1Life.oddWord (JointOdd1588.firstYIn divide) isA origin X Y s_odd := encodedFieldFrame_spliceRY P1Life.oddWord (JointOdd1588.firstYIn divide) isA origin X Y (pullState fieldMap a) s_rec hrec (by rw [pullState_fieldMap_regValue_R]; exact hRa) (by rw [pullState_fieldMap_regValue_Y]; exact hYa) have hrun_odd := JointOdd1588.placedFirstPacketOdd_frame WindowCallerCosts.oddFirstHalf divide isA (OddFullPassBridge.oddFirstHalf_law divide) (WindowCallerCosts.oddFirstHalf_support divide) origin ctx en x hx trace X Y hz s_odd m hframe_odd have hrun_std := Rolling1588.placedFirstPacket_frame divide isA origin ctx en x hx trace X Y hz s_rec m hrec have hpa_sodd : ∀ q ∈ wires P_odd, (pullState fieldMap a).basis q = s_odd.basis q := by intro q hq by_cases hry : q ∈ ryWires · simp only [s_odd, spliceRY, hry, if_true] · simp only [s_odd, spliceRY, hry, if_false] exact ((pullState_fieldMap_agreeRY hag).2 q hry).trans (hpb_fp q (hfp_odd q hq)) have hpb_srec : ∀ q ∈ wires P_std, (pullState fieldMap b).basis q = s_rec.basis q := fun q hq => hpb_fp q (hfp_std q hq) have hinc_odd := Arithmetic.run_local_increment P_odd (pullState fieldMap a) s_odd m hpa_sodd have hinc_std := Arithmetic.run_local_increment P_std (pullState fieldMap b) s_rec m hpb_srec have hout_s_ag : AgreeRY (run P_odd m s_odd) (run P_std m s_rec) := encodedFieldFrame_agreeRY P1Life.oddWord (JointOdd1588.firstYOut divide) isA origin _ _ _ _ _ _ (by rw [hrun_odd.1, hrun_std.1]; rfl) hrun_odd.2 hrun_std.2 have hout_ag : AgreeRY (run P_odd m (pullState fieldMap a)) (run P_std m (pullState fieldMap b)) := by have hph : (run P_odd m (pullState fieldMap a)).phase = (run P_std m (pullState fieldMap b)).phase := phase_eq_of_xor2 hinc_odd.1 hinc_std.1 hrun_odd.1 hrun_std.1 hag.1 refine ⟨hph, fun q hq => ?_⟩ by_cases h1 : q ∈ wires P_odd · by_cases h2 : q ∈ wires P_std · rw [hinc_odd.2 q h1, hinc_std.2 q h2]; exact hout_s_ag.2 q hq · rw [hinc_odd.2 q h1, run_preserves_outside P_std m (pullState fieldMap b) q h2] have h3 := hout_s_ag.2 q hq rw [run_preserves_outside P_std m s_rec q h2] at h3 exact h3.trans (hpb_fp q (hfp_odd q h1)).symm · rw [run_preserves_outside P_odd m (pullState fieldMap a) q h1] by_cases h2 : q ∈ wires P_std · rw [hinc_std.2 q h2] have h3 := hout_s_ag.2 q hq rw [run_preserves_outside P_odd m s_odd q h1] at h3 have h4 : (pullState fieldMap a).basis q = s_odd.basis q := by simp only [s_odd, spliceRY, hq, if_false] exact ((pullState_fieldMap_agreeRY hag).2 q hq).trans (hpb_fp q (hfp_std q h2)) exact h4.trans h3 · rw [run_preserves_outside P_std m (pullState fieldMap b) q h2] exact (pullState_fieldMap_agreeRY hag).2 q hq -- Drop `rebindMany` on `pullState fieldMap a` have hroles_in : ∀ q ∈ StairSchedule.exclusiveRoles, (pullState fieldMap a).basis q = false := by intro q hq exact ((pullState_fieldMap_agreeRY hag).2 q (exclusiveRoles_not_ryWires q hq)).trans (hcleanIn (fieldMap q) (List.mem_map.mpr ⟨q, List.mem_append_left _ hq, rfl⟩)) have hhosts_in : ∀ q ∈ hostPlan.firstPacket divide, (pullState fieldMap a).basis q = false := by intro q hq have hnot : q ∉ ryWires := hosts_not_ryWires 87 (by decide) q (by simpa [StairV3Primitives.hostPlan] using hq) exact ((pullState_fieldMap_agreeRY hag).2 q hnot).trans (hcleanIn (fieldMap q) (List.mem_map.mpr ⟨q, List.mem_append_right _ hq, rfl⟩)) have hroles_out : ∀ q ∈ StairSchedule.exclusiveRoles, (run P_odd m (pullState fieldMap a)).basis q = false := by intro q hq have h1 := hout_ag.2 q (exclusiveRoles_not_ryWires q hq) have h2 := hcleanOut (fieldMap q) (List.mem_map.mpr ⟨q, hq, rfl⟩) rw [fieldRename_eq] at h2 have h3 : (pullState fieldMap (run (renameProgram fieldMap P_std) m b)).basis q = false := h2 rw [run_rename fieldMap fieldMap_injective] at h3 exact h1.trans h3 have hrebind := JointOdd1588.hostedFirstPacketOdd_run_eq WindowCallerCosts.oddFirstHalf divide (WindowCallerCosts.oddFirstHalf_support divide) m (pullState fieldMap a) hroles_in hhosts_in hroles_out -- Values of `V` on `run P_odd m (pullState fieldMap a)` and `run P_std m (pullState fieldMap b)` let V := Replay5.firstPayload divide origin (X, Y) have hvo := encodedFieldFrameOdd_values P1Life.oddWord (JointOdd1588.firstYOut divide) isA origin V.1 V.2 _ hrun_odd.2 have hvs := encodedFieldFrame_values isA origin V.1 V.2 _ hrun_std.2 have hEq_odd (q : Wire) (hq : q ∈ ryWires) : (run P_odd m (pullState fieldMap a)).basis q = (run P_odd m s_odd).basis q := by by_cases hw : q ∈ wires P_odd · exact hinc_odd.2 q hw · rw [run_preserves_outside P_odd m (pullState fieldMap a) q hw, run_preserves_outside P_odd m s_odd q hw] simp only [s_odd, spliceRY, hq, if_true] have hEq_std (q : Wire) (hq : q ∈ ryWires) : (run P_std m (pullState fieldMap b)).basis q = (run P_std m s_rec).basis q := by by_cases hw : q ∈ wires P_std · exact hinc_std.2 q hw · rw [run_preserves_outside P_std m (pullState fieldMap b) q hw, run_preserves_outside P_std m s_rec q hw] exact hpb_ry q hq -- Lift back through `fieldRename = renameProgram fieldMap` using `fieldMapEquiv` let fmInv : Wire → Wire := fun q => HostOB5.hostSwap (Equiv.swap FrontierEntry1591Field.work FrontierEntry1591Field.host q) let fmEq : Equiv.Perm Wire := ⟨fieldMap, fmInv, fun q => by simp only [fieldMap, fmInv, Equiv.swap_apply_self, HostOB5.hostSwap_invol], fun q => by simp only [fieldMap, fmInv, HostOB5.hostSwap_invol, Equiv.swap_apply_self]⟩ have hfmInv_fix : ∀ q ∈ ryWires, fmInv q = q := fun q hq => by have h1 := fieldMap_fix_ryWires q hq have h2 := congrArg fmInv h1 exact (fmEq.left_inv q).symm.trans h2 |>.symm have hconj_fm (P : Program) (u : State) : run (StairSchedule.fieldRename P) m u = pullState fmInv (run P m (pullState fieldMap u)) := by rw [fieldRename_eq] have hr := run_rename fieldMap fieldMap_injective P m u apply State.extensionality · change (pullState fieldMap (run (renameProgram fieldMap P) m u)).phase = (run P m (pullState fieldMap u)).phase exact congrArg State.phase hr · funext q have h1 := congrFun (congrArg State.basis hr) (fmInv q) change (run (renameProgram fieldMap P) m u).basis (fieldMap (fmInv q)) = _ at h1 have hfr : fieldMap (fmInv q) = q := by simp only [fieldMap, fmInv, HostOB5.hostSwap_invol, Equiv.swap_apply_self] rw [hfr] at h1 exact h1 have hpullInv_ag : ∀ {u v : State}, AgreeRY u v → AgreeRY (pullState fmInv u) (pullState fmInv v) := by intro u v huv refine ⟨huv.1, fun q hq => ?_⟩ change u.basis (fmInv q) = v.basis (fmInv q) apply huv.2 intro hm have h1 := fieldMap_fix_ryWires (fmInv q) hm have h2 : fieldMap (fmInv q) = q := by simp only [fieldMap, fmInv, HostOB5.hostSwap_invol, Equiv.swap_apply_self] rw [h2] at h1 exact hq (h1 ▸ hm) have hpullInv_R (u : State) : regValue fieldR (pullState fmInv u).basis = regValue fieldR u.basis := regValue_congr _ _ _ (fun q hq => by change u.basis (fmInv q) = u.basis q rw [hfmInv_fix q ((mem_ryWires_iff q).mpr (Or.inl hq))]) have hpullInv_Y (u : State) : regValue fieldY (pullState fmInv u).basis = regValue fieldY u.basis := regValue_congr _ _ _ (fun q hq => by change u.basis (fmInv q) = u.basis q rw [hfmInv_fix q ((mem_ryWires_iff q).mpr (Or.inr hq))]) dsimp only rw [hconj_fm, hconj_fm, hrebind] refine ⟨hpullInv_ag hout_ag, ?_, ?_, ?_, ?_⟩ · rw [hpullInv_R] exact (regValue_congr _ _ _ (fun q hq => hEq_odd q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hvo.1 · rw [hpullInv_Y] exact (regValue_congr _ _ _ (fun q hq => hEq_odd q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hvo.2 · rw [hpullInv_R] exact (regValue_congr _ _ _ (fun q hq => hEq_std q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hvs.1 · rw [hpullInv_Y] exact (regValue_congr _ _ _ (fun q hq => hEq_std q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hvs.2 private theorem skywalkSharedField_z_eq_fieldR : (skywalkSharedField base).z = fieldR ++ [base 2312] := by decide +kernel private theorem skywalkSharedField_a_eq_fieldY : (skywalkSharedField base).a = fieldY ++ [base 1026] := by decide +kernel private theorem pullState_phase (f : Wire → Wire) (s : State) : (pullState f s).phase = s.phase := rfl private theorem fixedLayout_r_eq : DecoderBiasReuse.fixedLayout.r = fieldR := by decide +kernel private theorem fixedLayout_y_eq : DecoderBiasReuse.fixedLayout.y = fieldY := by decide +kernel private theorem endpointL_r_eq : (Q6EndpointCell.ports base (base 2409)).r = fieldR := by decide +kernel private theorem endpointL_y_eq : (Q6EndpointCell.ports base (base 2409)).y = fieldY := by decide +kernel private theorem converterLayout760_word_eq_fieldR : StairBoundaryLoan.converterLayout760.word = fieldR := by decide +kernel private theorem converterLayout760_wires_nodup : StairBoundaryLoan.converterLayout760.wires.Nodup := by have heq : StairBoundaryLoan.converterLayout760.wires = HalfField.tgt.wires.map StairBoundaryLoan.converterRename := by simp only [BalancedConvert.Layout.wires, StairBoundaryLoan.converterLayout760, BalancedConvert.Layout.word, List.map_append, List.map_cons, List.map_nil] rw [heq] exact List.Nodup.map StairBoundaryLoan.converterRename_injective_k4a (PeakNodup.nodup_of_mask _ (by decide +kernel)) /-- Pieces 18–20 of Division: `endPacket760DivOddLoan ++ copyN ++ canon760OddLoan` vs `divEndpoint ++ copyN ++ canon` produce **EXACT STATE EQUALITY**! -/ theorem divEndTail_eq (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400) = true) (X Y : Fp) (hend : (Replay5.endPayload true origin (X, Y)).1 = Y) (a b s_rec : State) (m : List Bool) (hrel : OddRel P1Life.oddWord P1Life.oddWord a b) (hframe : Rolling1588Frame.EncodedFieldFrame false origin X Y s_rec) (hpb_rec : ∀ q, Off q → (pullIn b).basis q = s_rec.basis q) : run (liftF (renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan ++ HalfFieldOB5.copyN ++ OddFullPass.HalfConvertOdd.canon760OddLoan)) m a = run (liftF (renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint ++ HalfFieldOB5.copyN ++ StairConcrete.bestLoans.canon)) m b := by let P1o := renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan let P1s := renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint let P_odd := (P1o ++ HalfFieldOB5.copyN) ++ OddFullPass.HalfConvertOdd.canon760OddLoan let P_std := (P1s ++ HalfFieldOB5.copyN) ++ StairConcrete.bestLoans.canon have hdiv_off : ∀ q ∈ wires P1s, Off q := by have hnotz : EP.all (fun e => let v := Equiv.swap (base 760) (base 717) (OB5.sig 511 e) decide (16 ≤ v) && !(decide (Placement5.workRegion (v - 16))) && !(decide (Placement5.holeRegion (v - 16)))) = true := by decide +kernel have hpi0_fix_ep : ∀ e ∈ EP, shifted Placement5.pi0 (Equiv.swap (base 760) (base 717) (OB5.sig 511 e)) = Equiv.swap (base 760) (base 717) (OB5.sig 511 e) := by intro e he set v := Equiv.swap (base 760) (base 717) (OB5.sig 511 e) have hb := List.all_eq_true.mp hnotz e he simp only [Bool.and_eq_true, decide_eq_true_eq, Bool.not_eq_true', decide_eq_false_iff_not] at hb have hsub : base (v - 16) = v := Nat.sub_add_cancel hb.1.1 rw [← hsub, shifted_base, Placement5.pi0_outside (v - 16) (fun hz => hz.elim hb.1.2 hb.2)] have hok : DecoderBiasReuse.fixedLayout.wires.all (fun w => !(decide (OB5.sig 511 (Equiv.swap (base 760) (base 717) (Equiv.swap (base 719) (base 510) w)) ∈ EP))) = true := by decide +kernel have hok_ep : ∀ w, OB5.sig 511 (Equiv.swap (base 760) (base 717) (shifted Placement5.pi0 w)) ∈ EP → OB5.sig 511 (Equiv.swap (base 760) (base 717) w) ∈ EP := by intro w hm have hfix := hpi0_fix_ep _ hm rw [OB5.sig_invol 511 (by decide), Equiv.swap_apply_self] at hfix have hweq : w = shifted Placement5.pi0 w := ((shifted Placement5.pi0).injective hfix).symm rwa [← hweq] at hm intro q hq rw [show P1s = renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint from rfl, renameProgram_support, StairConcrete.bestLoans_divEndpoint] at hq obtain ⟨y, hy, rfl⟩ := Finset.mem_image.mp hq unfold CompareDecoder.BoundaryLoan.endPacket760DivLoan at hy rw [renameProgram_support] at hy; obtain ⟨u1, hu1, rfl⟩ := Finset.mem_image.mp hy rw [renameProgram_support] at hu1; obtain ⟨u2, hu2, rfl⟩ := Finset.mem_image.mp hu1 apply off_of_not_EP intro hmem have hm' := hok_ep u2 hmem rcases Finset.mem_union.mp (ControlLoan1589.loanWindow_support _ _ _ _ hu2) with h | h · rw [Finset.mem_insert, Finset.mem_singleton] at h rcases h with rfl | rfl <;> exact absurd hm' (by decide +kernel) · obtain ⟨z, hz, rfl⟩ := Finset.mem_image.mp h rw [wires_append, Finset.mem_union] at hz rcases hz with hz | hz · have h1 := List.all_eq_true.mp hok z (List.mem_toFinset.mp (CompareDecoder.support (CompareDecoder.BoundaryLoan.Inclusion.cellDecoderLoan_sub hz))) simp [hm'] at h1 · have hc := (InverseEndpointWires.pad_facts 507 (base 512)).2.2.2.1 hz rw [Finset.mem_singleton] at hc; rw [hc] at hm'; exact absurd hm' (by decide +kernel) have hcopy_off : ∀ q ∈ wires HalfFieldOB5.copyN, Off q := by have hok : StairWireCheck.allSites (fun q => !(decide (q ∈ EP))) HalfFieldOB5.copyN = true := by decide +kernel intro q hq exact off_of_not_EP q (by simpa using StairWireCheck.allSites_sound _ _ hok q hq) have hcanon_off : ∀ q ∈ wires StairConcrete.bestLoans.canon, Off q := by have hok1 : EP.all (fun e => !(decide (StairBoundaryLoan.converterPerm_k4a.symm e ∈ HalfField.tgt.wires))) = true := by decide +kernel have hok2 : StairBoundaryLoan.converterHosts.all (fun q => !(decide (q ∈ EP))) = true := by decide +kernel have hlt_eq : StairBoundaryLoan.converterLayout760.wires = HalfField.tgt.wires.map StairBoundaryLoan.converterRename := by simp only [BalancedConvert.Layout.wires, StairBoundaryLoan.converterLayout760, BalancedConvert.Layout.word, List.map_append, List.map_cons, List.map_nil] intro q hq apply off_of_not_EP intro hmem rcases Finset.mem_union.mp (StairBoundaryLoan.canon760Loan_envelope hq) with h1 | h2 · rw [StairBoundaryLoan.canon760_eq] at h1 have hm := List.mem_toFinset.mp ((HalfConvert.support _ StairBoundaryLoan.converterLayout760_facts.widths).2 h1) rw [hlt_eq] at hm obtain ⟨w, hw, rfl⟩ := List.mem_map.mp hm have hbad := List.all_eq_true.mp hok1 _ hmem rw [StairBoundaryLoan.converterRename_apply_k4a, Equiv.symm_apply_apply] at hbad simp [hw] at hbad · have hbad := List.all_eq_true.mp hok2 q (List.mem_toFinset.mp h2) simp [hmem] at hbad have hstd_off : ∀ q ∈ wires P_std, Off q := by intro q hq simp only [P_std, wires_append, Finset.mem_union] at hq rcases hq with (h | h) | h · exact hdiv_off q h · exact hcopy_off q h · exact hcanon_off q h have hodd_sub_std : wires P_odd ⊆ wires P_std := by have h1 : wires P1o ⊆ wires P1s := by simp only [P1o, P1s, renameProgram_support, StairConcrete.bestLoans_divEndpoint] exact Finset.image_subset_image OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan_wires_sub have h2 := OddFullPass.HalfConvertOdd.canon760OddLoan_wires_sub intro q hq simp only [P_odd, P_std, wires_append, Finset.mem_union] at hq ⊢ rcases hq with (ha | hb) | hc · exact Or.inl (Or.inl (h1 ha)) · exact Or.inl (Or.inr hb) · rcases Finset.mem_union.mp (h2 hc) with hca | hcb · exact Or.inr hca · exact Or.inl (Or.inr hcb) have hry_sub_std : ∀ q ∈ ryWires, q ∈ wires P_std := by have hcopy_mem : ∀ (a b : List Wire), a.length = b.length → ∀ q ∈ a ++ b, q ∈ wires (copyRegister none a b) := by intro a induction a with | nil => intro b hb q hq; cases b <;> simp_all | cons x xs ih => intro b hb q hq cases b with | nil => simp at hb | cons y ys => simp only [copyRegister, copyGate, wires_append, wires, Instr.wires, Finset.mem_union, Finset.mem_insert, Finset.mem_singleton, Finset.notMem_empty, or_false] simp only [List.mem_append, List.mem_cons] at hq rcases hq with (rfl | hx) | (rfl | hy) · exact Or.inl (Or.inl rfl) · exact Or.inr (ih ys (by simpa using hb) q (List.mem_append_left _ hx)) · exact Or.inl (Or.inr rfl) · exact Or.inr (ih ys (by simpa using hb) q (List.mem_append_right _ hy)) have hlen : fieldR.length = fieldY.length := by simp [fieldR, fieldY, wireBlock_length] intro q hq simp only [P_std, wires_append, Finset.mem_union] exact Or.inl (Or.inr (hcopy_mem fieldR fieldY hlen q hq)) -- First prove exact equality on `s_odd := spliceRY (pullIn a) s_rec` vs `s_rec`! let a0 := spliceRY (pullIn a) s_rec let b0 := s_rec have hrel0 : OddRel P1Life.oddWord P1Life.oddWord a0 b0 := by have hb_vals_rec := encodedFieldFrame_values false origin X Y s_rec hframe have hb_vals : regValue fieldR b.basis = centerWord X ∧ regValue fieldY b.basis = centerWord Y := by constructor · rw [← pullIn_regValue_R] exact (regValue_congr _ _ _ (fun q hq => hpb_rec q (ryWires_off q ((mem_ryWires_iff q).mpr (Or.inl hq))))).trans hb_vals_rec.1 · rw [← pullIn_regValue_Y] exact (regValue_congr _ _ _ (fun q hq => hpb_rec q (ryWires_off q ((mem_ryWires_iff q).mpr (Or.inr hq))))).trans hb_vals_rec.2 have ha_vals : regValue fieldR a0.basis = P1Life.oddWord X ∧ regValue fieldY a0.basis = P1Life.oddWord Y := by constructor · rw [show regValue fieldR a0.basis = regValue fieldR (pullIn a).basis from regValue_congr _ _ _ (fun q hq => by simp only [a0, spliceRY, (mem_ryWires_iff q).mpr (Or.inl hq), if_true]), pullIn_regValue_R] exact hrel.2.1 X hb_vals.1 · rw [show regValue fieldY a0.basis = regValue fieldY (pullIn a).basis from regValue_congr _ _ _ (fun q hq => by simp only [a0, spliceRY, (mem_ryWires_iff q).mpr (Or.inr hq), if_true]), pullIn_regValue_Y] exact hrel.2.2 Y hb_vals.2 exact oddRel_of_agreeRY_values X Y ⟨rfl, fun q hq => by simp only [a0, b0, spliceRY, hq, if_false]⟩ hb_vals_rec.1 hb_vals_rec.2 ha_vals.1 ha_vals.2 have hb0_vals := encodedFieldFrame_values false origin X Y b0 hframe have ha0_vals : regValue fieldR a0.basis = P1Life.oddWord X ∧ regValue fieldY a0.basis = P1Life.oddWord Y := ⟨hrel0.2.1 X hb0_vals.1, hrel0.2.2 Y hb0_vals.2⟩ -- Split tape into 3 parts: endPacket, copyN, canon let m12o := m.take (measurementCount (P1o ++ HalfFieldOB5.copyN)) let m1o := m12o.take (measurementCount P1o) let m2o := m12o.drop (measurementCount P1o) let m3o := m.drop (measurementCount (P1o ++ HalfFieldOB5.copyN)) let m12s := m.take (measurementCount (P1s ++ HalfFieldOB5.copyN)) let m1s := m12s.take (measurementCount P1s) let m2s := m12s.drop (measurementCount P1s) let m3s := m.drop (measurementCount (P1s ++ HalfFieldOB5.copyN)) -- Step 1: endPacketDiv let a1 := run P1o m1o a0 let b1 := run P1s m1s b0 have hsig_a0 : AgreeRY (pullState (OB5.sig 511) a0) (pullState (OB5.sig 511) b0) := pullState_sig511_agreeRY hrel0.1 have h510_notRY : base 510 ∉ ryWires := by decide +kernel have h2409_notRY : base 2409 ∉ ryWires := by decide +kernel have h760_notRY : base 760 ∉ ryWires := by decide +kernel have h717_notRY : base 717 ∉ ryWires := by decide +kernel have hzero_b0 := Rolling1588.encoded_zero_region base (base 2409) false ctx.hn (ctx.hp _ (by simp)) origin ctx.env ctx.legal X Y _ hframe have hzero_a0 : ∀ q, Placement5.zeroRegion q → (pullState (OB5.sig 511) a0).basis (base q) = false := fun q hq => (hsig_a0.2 (base q) (base_not_ryWires_of_zeroRegion q hq)).trans (hzero_b0 q hq) have hXeq : X = (if (pullState (OB5.sig 511) a0).basis (base 510) then 1 else 3) * Y := by obtain ⟨raw, _, hpair, henc⟩ := hframe have hout510 : raw.basis (base 510) = origin (base 510) := hpair.2.2 (base 510) (by decide +kernel) (by decide +kernel) have h510_b : (pullState (OB5.sig 511) b0).basis (base 510) = origin (base 510) := by rw [henc] have h510_ne : base 510 ∉ wires (Rolling1588.allEncode base false 102) := fun hw => allEncode_510_free false hw rw [run_preserves_outside _ [] raw _ h510_ne, hout510] have h510_a : (pullState (OB5.sig 511) a0).basis (base 510) = origin (base 510) := (hsig_a0.2 (base 510) h510_notRY).trans h510_b rw [h510_a] have hd : (X + (if origin (base 510) then Y else -Y)) / 2 = Y := by simpa only [Replay5.endPayload, mixedTranscriptBit, en, if_true] using hend have h2 : (2 : Fp) ≠ 0 := by decide have hmul : X + (if origin (base 510) then Y else -Y) = 2 * Y := by have h1 : ((X + (if origin (base 510) then Y else -Y)) / 2) * 2 = Y * 2 := congrArg (· * 2) hd rw [div_mul_cancel₀ _ h2] at h1 exact h1.trans (mul_comm Y 2) cases h : origin (base 510) <;> simp only [h, Bool.false_eq_true, if_true, if_false] at hmul ⊢ <;> linear_combination hmul have hflag_b0 : (pullState (OB5.sig 511) b0).basis (base 2409) = false := by obtain ⟨raw, _, hpair, henc⟩ := hframe have hne : base 2409 ∉ wires (Rolling1588.allEncode base false 102) := fun hw => absurd (List.mem_toFinset.mp (Rolling1588.allEncode_history_support base false 102 (by decide) hw)) (by decide +kernel) rw [henc, run_preserves_outside _ [] raw _ hne] exact (hpair.2.2 (base 2409) (by decide +kernel) (by decide +kernel)).trans ctx.hg0 have ha1_spec := OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan_frame Y (pullState (OB5.sig 511) a0) m1o (q6Clean_of_agreeRY hsig_a0 (q6Clean_of_encoded5 origin ctx X Y _ hframe)) ((hsig_a0.2 (base 2409) h2409_notRY).trans hflag_b0) (by rw [fixedLayout_y_eq, pullState_sig511_regValue_Y]; exact ha0_vals.2) (by rw [fixedLayout_r_eq, pullState_sig511_regValue_R, ← hXeq]; exact ha0_vals.1) (Placement5.shifted_zero_boundary Placement5.pi0 Placement5.pi0_outside _ hzero_a0) ((hsig_a0.2 (base 760) h760_notRY).trans (R2SqEp760.encoded5_760 origin ctx X Y _ hframe)) ((hsig_a0.2 (base 717) h717_notRY).trans (R2SqEp760.encoded5_717 origin ctx X Y _ hframe)) rw [fixedLayout_r_eq] at ha1_spec have hb1_eq : run StairConcrete.bestLoans.divEndpoint m1s (pullState (OB5.sig 511) b0) = run (R2SqEp760.endPacket760 true) m1s (pullState (OB5.sig 511) b0) := by rw [StairConcrete.bestLoans_divEndpoint] exact CompareDecoder.BoundaryLoan.endPacket760DivLoan_run_eq false origin ctx en X Y hend _ m1s m1s hframe have hb1_spec := R2SqEp760.endPacket760_frame false true origin ctx en X Y (fun _ => hend) (fun h => absurd h (by decide)) (pullState (OB5.sig 511) b0) m1s hframe have hb1_frame : Rolling1588Frame.EncodedFieldFrame false origin Y Y b1 := by have hconj := run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)) StairConcrete.bestLoans.divEndpoint m1s b0 change Rolling1588.EncodedFieldFrame5 base (base 2409) false origin Y Y (pullState (OB5.sig 511) b1) rw [show pullState (OB5.sig 511) b1 = run StairConcrete.bestLoans.divEndpoint m1s (pullState (OB5.sig 511) b0) from hconj, hb1_eq] have hs2 := hb1_spec.2 rw [hend] at hs2 exact hs2 have ha1_ag : AgreeRY a1 b1 := by have hconj_a := run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan m1o a0 have hconj_b := run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)) StairConcrete.bestLoans.divEndpoint m1s b0 have ha1p : a1.phase = a0.phase := (pullState_phase _ a1).symm.trans ((congrArg State.phase hconj_a).trans (ha1_spec.1.trans (pullState_phase _ a0))) have hb1p : b1.phase = b0.phase := (pullState_phase _ b1).symm.trans ((congrArg State.phase hconj_b).trans (((congrArg State.phase hb1_eq).trans hb1_spec.1).trans (pullState_phase _ b0))) have hph : a1.phase = b1.phase := ha1p.trans (hrel0.1.1.trans hb1p.symm) have ha1_out : ∀ q, q ∉ ryWires → (pullState (OB5.sig 511) a1).basis q = (pullState (OB5.sig 511) a0).basis q := by intro q hq rw [hconj_a] exact ha1_spec.2.2 q (fun hr => hq ((mem_ryWires_iff q).mpr (Or.inl hr))) have hb1_out : ∀ q, q ∉ ryWires → (pullState (OB5.sig 511) b1).basis q = (pullState (OB5.sig 511) b0).basis q := by intro q hq have h1 := encodedFieldFrame_agreeRY centerWord centerWord false origin Y Y X Y b1 b0 hb1p hb1_frame hframe exact (pullState_sig511_agreeRY h1).2 q hq have hp : AgreeRY (pullState (OB5.sig 511) a1) (pullState (OB5.sig 511) b1) := ⟨(pullState_phase _ a1).trans (hph.trans (pullState_phase _ b1).symm), fun q hq => (ha1_out q hq).trans ((hsig_a0.2 q hq).trans (hb1_out q hq).symm)⟩ have hu := pullState_sig511_agreeRY hp rwa [StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide)), StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide))] at hu have ha1_vals : regValue fieldR a1.basis = P1Life.oddWord Y ∧ regValue fieldY a1.basis = P1Life.oddWord Y := by have hconj_a := run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan m1o a0 constructor · rw [← pullState_sig511_regValue_R, hconj_a]; exact ha1_spec.2.1 · rw [← pullState_sig511_regValue_Y, hconj_a] exact (regValue_congr _ _ _ (fun q hq => ha1_spec.2.2 q (fun hr => fieldR_disjoint_fieldY q hr hq))).trans (by rw [pullState_sig511_regValue_Y]; exact ha0_vals.2) -- Step 2: HalfFieldOB5.copyN let a2 := run HalfFieldOB5.copyN m2o a1 let b2 := run HalfFieldOB5.copyN m2s b1 have hc_a := copyN_step ctx.hn a1 m2o have hc_b := copyN_step ctx.hn b1 m2s have hb2_frame : Rolling1588Frame.EncodedFieldFrame false origin Y 0 b2 := (Rolling1588HalfFieldOB5.copy_clear ctx.hn origin Y b1 m2s hb1_frame).2 have ha2_R : regValue fieldR a2.basis = P1Life.oddWord Y := (regValue_congr _ _ _ (fun q hq => hc_a.2.1 q (fieldR_disjoint_fieldY q hq))).trans ha1_vals.1 have ha2_Y0 : regValue fieldY a2.basis = 0 := by rw [hc_a.2.2, ha1_vals.1, ha1_vals.2, Nat.xor_self] have hb2_vals := encodedFieldFrame_values false origin Y 0 b2 hb2_frame have hb2_Y0 : regValue fieldY b2.basis = 0 := by rw [hb2_vals.2, HalfField.centerWord_zero] have ha2_agR : AgreeOutsideR a2 b2 := by apply agreeOutsideR_of_agreeRY · refine ⟨hc_a.1.trans (ha1_ag.1.trans hc_b.1.symm), fun q hq => ?_⟩ have hny : q ∉ fieldY := fun h => hq ((mem_ryWires_iff q).mpr (Or.inr h)) rw [hc_a.2.1 q hny, hc_b.2.1 q hny] exact ha1_ag.2 q hq · exact basis_eq_of_regValue_eq fieldY a2.basis b2.basis (ha2_Y0.trans hb2_Y0.symm) -- Step 3: canon760OddLoan vs canon760Loan let a3 := run OddFullPass.HalfConvertOdd.canon760OddLoan m3o a2 let b3 := run StairConcrete.bestLoans.canon m3s b2 have hcw_b2 := convWork_clean_of_encodedField origin ctx Y b2 hb2_frame have hcw_a2 : ∀ q ∈ OddFullPass.HalfConvertOdd.convWork StairBoundaryLoan.converterLayout760, a2.basis q = false := fun q hq => (ha2_agR.2 q (convWork_not_fieldR q hq)).trans (hcw_b2 q hq) have hy43_a2 : ∀ q ∈ OddFullPass.HalfConvertOdd.yHosts43, a2.basis q = false := fun q hq => (regValue_zero fieldY a2.basis).mp ha2_Y0 q (yHosts43_sub_fieldY q hq) have ha3_eq := OddFullPass.HalfConvertOdd.canon760OddLoan_run_eq_canonicalOdd Y a2 m3o (by rw [converterLayout760_word_eq_fieldR]; exact ha2_R) hcw_a2 hy43_a2 have ha3_corr := OddFullPass.HalfConvertOdd.canonicalOdd_correct StairBoundaryLoan.converterLayout760 StairBoundaryLoan.converterLayout760_facts.widths converterLayout760_wires_nodup Y a2 m3o (by rw [converterLayout760_word_eq_fieldR]; exact ha2_R) hcw_a2 rw [converterLayout760_word_eq_fieldR] at ha3_corr have hb3_eq : b3 = run R2SqEp760.canon760 m3s b2 := StairBoundaryLoan.canon760Loan_run_eq origin ctx Y b2 m3s m3s hb2_frame have hb3_corr : b3.phase = b2.phase ∧ regValue fieldR b3.basis = (2 * Y).val ∧ ∀ q, q ∉ fieldR → b3.basis q = b2.basis q := by rw [hb3_eq, StairBoundaryLoan.canon760_eq] have hc := HalfConvert.canonical_correct StairBoundaryLoan.converterLayout760 StairBoundaryLoan.converterLayout760_facts.widths converterLayout760_wires_nodup Y b2 m3s (by rw [converterLayout760_word_eq_fieldR]; exact hb2_vals.1) (bcWork_clean_of_encodedField origin ctx Y b2 hb2_frame) rw [converterLayout760_word_eq_fieldR] at hc exact ⟨hc.1, hc.2.1, hc.2.2.2⟩ have ha3_eq_b3 : run P_odd m a0 = run P_std m b0 := by have h1 : run P_odd m a0 = a3 := by simp only [P_odd, run_append, a3, a2, a1, m1o, m2o, m3o, m12o] have h2 : run P_std m b0 = b3 := by simp only [P_std, run_append, b3, b2, b1, m1s, m2s, m3s, m12s] rw [h1, h2] have ha3p : a3.phase = a2.phase := by change (run _ m3o a2).phase = _; rw [ha3_eq]; exact ha3_corr.1 have ha3out : ∀ q, q ∉ fieldR → a3.basis q = a2.basis q := fun q hq => by change (run _ m3o a2).basis q = _; rw [ha3_eq]; exact ha3_corr.2.2.2 q hq have ha3R : regValue fieldR a3.basis = (2 * Y).val := by change regValue fieldR (run _ m3o a2).basis = _; rw [ha3_eq]; exact ha3_corr.2.1 apply state_eq_of_agreeOutsideR · refine ⟨ha3p.trans (ha2_agR.1.trans hb3_corr.1.symm), fun q hq => ?_⟩ rw [ha3out q hq, hb3_corr.2.2 q hq] exact ha2_agR.2 q hq · rw [ha3R, hb3_corr.2.1] -- Transfer from `(a0, b0)` to `(pullIn a, pullIn b)` via `run_local_increment`! have hpa_a0 : ∀ q ∈ wires P_odd, (pullIn a).basis q = a0.basis q := by intro q hq by_cases hry : q ∈ ryWires · simp only [a0, spliceRY, hry, if_true] · simp only [a0, spliceRY, hry, if_false] exact ((pullIn_agreeRY hrel.1).2 q hry).trans (hpb_rec q (hstd_off q (hodd_sub_std hq))) have hpb_b0 : ∀ q ∈ wires P_std, (pullIn b).basis q = b0.basis q := fun q hq => hpb_rec q (hstd_off q hq) have hinc_odd := Arithmetic.run_local_increment P_odd (pullIn a) a0 m hpa_a0 have hinc_std := Arithmetic.run_local_increment P_std (pullIn b) b0 m hpb_b0 have hfull : run P_odd m (pullIn a) = run P_std m (pullIn b) := by apply State.extensionality · have hpeq : (run P_odd m a0).phase = (run P_std m b0).phase := congrArg State.phase ha3_eq_b3 have hinc2 : ((run P_std m (pullIn b)).phase ^^ (pullIn b).phase) = ((run P_odd m a0).phase ^^ a0.phase) := by rw [hpeq]; exact hinc_std.1 exact phase_eq_of_xor hinc_odd.1 hinc2 hrel.1.1 · funext q by_cases h1 : q ∈ wires P_odd · rw [hinc_odd.2 q h1, hinc_std.2 q (hodd_sub_std h1), ha3_eq_b3] · rw [run_preserves_outside P_odd m (pullIn a) q h1] by_cases h2 : q ∈ wires P_std · rw [hinc_std.2 q h2, ← ha3_eq_b3, run_preserves_outside P_odd m a0 q h1] by_cases hry : q ∈ ryWires · simp only [a0, spliceRY, hry, if_true] · simp only [a0, spliceRY, hry, if_false] exact ((pullIn_agreeRY hrel.1).2 q hry).trans (hpb_rec q (hstd_off q h2)) · rw [run_preserves_outside P_std m (pullIn b) q h2] exact (pullIn_agreeRY hrel.1).2 q (fun hry => h2 (hry_sub_std q hry)) rw [StairField2V3Seg.liftF_run, StairField2V3Seg.liftF_run] exact congrArg pullOut hfull /-- Pieces 4–6 of Multiplication (`center760OddLoan ++ copyN ++ endPacket760OddLoan44` vs `center ++ copyN ++ placedEndPacket bestLoans false 68`) starting from identical `b` (`pullIn b` agrees on `Off` with `s_rec` which carries `EncodedCanonicalFrame false origin Y 0`). -/ theorem mulHeadCore_step (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (ha : regValue (skywalkSharedField base).a origin = 0) (en : origin (base 2400) = true) (Y : Fp) (b s_rec : State) (m : List Bool) (hrec : Rolling1588Frame.EncodedCanonicalFrame false origin Y 0 s_rec) (hpb_rec : ∀ q, Off q → (pullIn b).basis q = s_rec.basis q) : OddRel P1Life.oddWord P1Life.oddWord (run (liftF (OddFullPass.HalfConvertOdd.center760OddLoan ++ HalfFieldOB5.copyN ++ renameProgram (OB5.sig 511) OddFullPass.InverseTailCOdd.endPacket760OddLoan44)) m b) (run (liftF (StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN ++ StairSchedule.placedEndPacket StairConcrete.bestLoans false 68)) m b) := by let P_odd := OddFullPass.HalfConvertOdd.center760OddLoan ++ HalfFieldOB5.copyN ++ renameProgram (OB5.sig 511) OddFullPass.InverseTailCOdd.endPacket760OddLoan44 let P_std := StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN ++ StairSchedule.placedEndPacket StairConcrete.bestLoans false 68 have hstd_off : ∀ q ∈ wires P_std, Off q := by have hsub_hc : wires P_std ⊆ wires headCore := by have h1 := StairLoanConverterSupport.center760Loan_sub have h2 : wires (StairSchedule.placedEndPacket StairConcrete.bestLoans false 68) ⊆ wires (renameProgram (OB5.sig 511) (R2SqEp760.endPacket760 false)) := by have he : StairConcrete.bestLoans.endPacket false 68 = StairEndpointLoan44.endPacket760Loan44 false := by simp only [StairConcrete.bestLoans, StairConcrete.endPacket, Bool.false_eq_true, if_false, if_true] rw [StairSchedule.placedEndPacket, he, renameProgram_support, renameProgram_support] exact Finset.image_subset_image StairEndpointLoan44.endPacket760Loan44_support simp only [P_std, headCore, wires_append] exact Finset.union_subset_union (Finset.union_subset_union h1 (Finset.Subset.refl _)) h2 exact fun q hq => headCore_off q (hsub_hc hq) have hodd_sub_std : wires P_odd ⊆ wires P_std := by have h1 := OddFullPass.HalfConvertOdd.center760OddLoan_wires_sub have h2 : wires (renameProgram (OB5.sig 511) OddFullPass.InverseTailCOdd.endPacket760OddLoan44) ⊆ wires (StairSchedule.placedEndPacket StairConcrete.bestLoans false 68) := by have he : StairConcrete.bestLoans.endPacket false 68 = StairEndpointLoan44.endPacket760Loan44 false := by simp only [StairConcrete.bestLoans, StairConcrete.endPacket, Bool.false_eq_true, if_false, if_true] rw [StairSchedule.placedEndPacket, he, renameProgram_support, renameProgram_support] exact Finset.image_subset_image OddFullPass.InverseTailCOdd.endPacket760OddLoan44_wires_sub intro q hq simp only [P_odd, P_std, wires_append, Finset.mem_union] at hq ⊢ rcases hq with (ha | hb) | hc · rcases Finset.mem_union.mp (h1 ha) with hca | hcb · exact Or.inl (Or.inl hca) · exact Or.inl (Or.inr hcb) · exact Or.inl (Or.inr hb) · exact Or.inr (h2 hc) have hodd_off : ∀ q ∈ wires P_odd, Off q := fun q hq => hstd_off q (hodd_sub_std hq) -- Run `P_odd` vs `P_std` on `s_rec` first, then transfer to `pullIn b` via `run_local_increment`! let m12o := m.take (measurementCount (OddFullPass.HalfConvertOdd.center760OddLoan ++ HalfFieldOB5.copyN)) let m1o := m12o.take (measurementCount OddFullPass.HalfConvertOdd.center760OddLoan) let m2o := m12o.drop (measurementCount OddFullPass.HalfConvertOdd.center760OddLoan) let m3o := m.drop (measurementCount (OddFullPass.HalfConvertOdd.center760OddLoan ++ HalfFieldOB5.copyN)) let m12s := m.take (measurementCount (StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN)) let m1s := m12s.take (measurementCount StairConcrete.bestLoans.center) let m2s := m12s.drop (measurementCount StairConcrete.bestLoans.center) let m3s := m.drop (measurementCount (StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN)) -- Step 1: center760OddLoan vs center760Loan on `s_rec` have hs_vals : regValue fieldR s_rec.basis = Y.val ∧ regValue fieldY s_rec.basis = 0 := by obtain ⟨raw, _, hpair, henc⟩ := hrec have hpR : regValue fieldR raw.basis = Y.val := by have h1 := hpair.1 rw [skywalkSharedField_z_eq_fieldR, Arithmetic.regValue_append] at h1 have hlen : fieldR.length = 256 := by simp [fieldR, wireBlock_length] have hlt : Y.val < 2 ^ 256 := lt_trans Y.val_lt (by decide) rw [hlen] at h1 have hbit0 : regValue [base 2312] raw.basis = 0 := by by_contra hne have hge : 2 ^ 256 ≤ 2 ^ 256 * regValue [base 2312] raw.basis := Nat.le_mul_of_pos_right _ (Nat.pos_of_ne_zero hne) omega rw [hbit0, Nat.mul_zero, Nat.add_zero] at h1 exact h1 have hpY : regValue fieldY raw.basis = 0 := by have h1 := hpair.2.1 rw [skywalkSharedField_a_eq_fieldY, Arithmetic.regValue_append, ZMod.val_zero] at h1 omega constructor · rw [← pullState_sig511_regValue_R, henc] exact (regValue_congr _ _ _ (fun q hq => run_preserves_outside _ [] raw q (fun hw => allEncode_notRY false q hw ((mem_ryWires_iff q).mpr (Or.inl hq))))).trans hpR · rw [← pullState_sig511_regValue_Y, henc] exact (regValue_congr _ _ _ (fun q hq => run_preserves_outside _ [] raw q (fun hw => allEncode_notRY false q hw ((mem_ryWires_iff q).mpr (Or.inr hq))))).trans hpY have hcw_s := convWork_clean_of_encodedCanonical origin ctx ha Y s_rec hrec have hy43_s : ∀ q ∈ OddFullPass.HalfConvertOdd.yHosts43, s_rec.basis q = false := fun q hq => (regValue_zero fieldY s_rec.basis).mp hs_vals.2 q (yHosts43_sub_fieldY q hq) let a1 := run OddFullPass.HalfConvertOdd.center760OddLoan m1o s_rec let b1 := run StairConcrete.bestLoans.center m1s s_rec have ha1_eq := OddFullPass.HalfConvertOdd.center760OddLoan_run_eq_centerOdd Y s_rec m1o (by rw [converterLayout760_word_eq_fieldR]; exact hs_vals.1) hcw_s hy43_s have ha1_corr := OddFullPass.HalfConvertOdd.centerOdd_correct StairBoundaryLoan.converterLayout760 StairBoundaryLoan.converterLayout760_facts.widths converterLayout760_wires_nodup Y s_rec m1o (by rw [converterLayout760_word_eq_fieldR]; exact hs_vals.1) hcw_s rw [converterLayout760_word_eq_fieldR] at ha1_corr have hb1_eq : b1 = run R2SqEp760.center760 m1s s_rec := StairBoundaryLoan.center760Loan_run_eq origin ctx ha Y s_rec m1s m1s hrec have hb1_frame : Rolling1588Frame.EncodedFieldFrame false origin (Y / 2) 0 b1 := by rw [hb1_eq]; exact (R2SqEp760.center760_frame origin ctx ha Y s_rec m1s hrec).2 have hb1_corr : b1.phase = s_rec.phase ∧ regValue fieldR b1.basis = centerWord (Y / 2) ∧ ∀ q, q ∉ fieldR → b1.basis q = s_rec.basis q := by rw [hb1_eq, StairBoundaryLoan.center760_eq] have hc := HalfConvert.center_correct StairBoundaryLoan.converterLayout760 StairBoundaryLoan.converterLayout760_facts.widths converterLayout760_wires_nodup Y s_rec m1s (by rw [converterLayout760_word_eq_fieldR]; exact hs_vals.1) (bcWork_clean_of_encodedCanonical origin ctx ha Y s_rec hrec) rw [converterLayout760_word_eq_fieldR] at hc exact ⟨hc.1, hc.2.1, hc.2.2.2⟩ have ha1p : a1.phase = s_rec.phase := by change (run _ m1o s_rec).phase = _; rw [ha1_eq]; exact ha1_corr.1 have ha1out : ∀ q, q ∉ fieldR → a1.basis q = s_rec.basis q := fun q hq => by change (run _ m1o s_rec).basis q = _; rw [ha1_eq]; exact ha1_corr.2.2.2 q hq have ha1_agR : AgreeOutsideR a1 b1 := ⟨ha1p.trans hb1_corr.1.symm, fun q hq => (ha1out q hq).trans (hb1_corr.2.2 q hq).symm⟩ -- Step 2: HalfFieldOB5.copyN let a2 := run HalfFieldOB5.copyN m2o a1 let b2 := run HalfFieldOB5.copyN m2s b1 have hc_a := copyN_step ctx.hn a1 m2o have hc_b := copyN_step ctx.hn b1 m2s have hb2_frame : Rolling1588Frame.EncodedFieldFrame false origin (Y / 2) (Y / 2) b2 := (Rolling1588HalfFieldOB5.copy_fill ctx.hn origin (Y / 2) b1 m2s hb1_frame).2 have ha1_R : regValue fieldR a1.basis = P1Life.oddWord (Y / 2) := by change regValue fieldR (run _ m1o s_rec).basis = _; rw [ha1_eq]; exact ha1_corr.2.1 have ha1_Y0 : regValue fieldY a1.basis = 0 := (regValue_congr _ _ _ (fun q hq => ha1out q (fun hr => fieldR_disjoint_fieldY q hr hq))).trans hs_vals.2 have ha2_R : regValue fieldR a2.basis = P1Life.oddWord (Y / 2) := (regValue_congr _ _ _ (fun q hq => hc_a.2.1 q (fieldR_disjoint_fieldY q hq))).trans ha1_R have ha2_Y : regValue fieldY a2.basis = P1Life.oddWord (Y / 2) := by rw [hc_a.2.2, ha1_Y0, ha1_R, Nat.zero_xor] have ha2_ag : AgreeRY a2 b2 := ⟨hc_a.1.trans (ha1_agR.1.trans hc_b.1.symm), fun q hq => by have hny : q ∉ fieldY := fun h => hq ((mem_ryWires_iff q).mpr (Or.inr h)) have hnr : q ∉ fieldR := fun h => hq ((mem_ryWires_iff q).mpr (Or.inl h)) rw [hc_a.2.1 q hny, hc_b.2.1 q hny] exact ha1_agR.2 q hnr⟩ -- Step 3: endPacket760OddLoan44 vs placedEndPacket bestLoans false 68 let a3 := run (renameProgram (OB5.sig 511) OddFullPass.InverseTailCOdd.endPacket760OddLoan44) m3o a2 let b3 := run (StairSchedule.placedEndPacket StairConcrete.bestLoans false 68) m3s b2 have hsig_a2 := pullState_sig511_agreeRY ha2_ag have hzero_b2 := Rolling1588.encoded_zero_region base (base 2409) false ctx.hn (ctx.hp _ (by simp)) origin ctx.env ctx.legal (Y / 2) (Y / 2) _ hb2_frame have hzero_a2 : ∀ q, Placement5.zeroRegion q → (pullState (OB5.sig 511) a2).basis (base q) = false := fun q hq => (hsig_a2.2 (base q) (base_not_ryWires_of_zeroRegion q hq)).trans (hzero_b2 q hq) have hflag_b2 : (pullState (OB5.sig 511) b2).basis (base 2409) = false := by obtain ⟨raw, _, hpair, henc⟩ := hb2_frame have hne : base 2409 ∉ wires (Rolling1588.allEncode base false 102) := fun hw => absurd (List.mem_toFinset.mp (Rolling1588.allEncode_history_support base false 102 (by decide) hw)) (by decide +kernel) rw [henc, run_preserves_outside _ [] raw _ hne] exact (hpair.2.2 (base 2409) (by decide +kernel) (by decide +kernel)).trans ctx.hg0 have ha3_spec := OddFullPass.InverseTailCOdd.endPacket760OddLoan44_frame (Y / 2) (pullState (OB5.sig 511) a2) m3o (q6Clean_of_agreeRY hsig_a2 (q6Clean_of_encoded5 origin ctx (Y / 2) (Y / 2) _ hb2_frame)) ((hsig_a2.2 (base 2409) (by decide +kernel)).trans hflag_b2) (by rw [endpointL_r_eq, pullState_sig511_regValue_R]; exact ha2_R) (by rw [endpointL_y_eq, pullState_sig511_regValue_Y]; exact ha2_Y) (Placement5.shifted_zero_boundary Placement5.pi0 Placement5.pi0_outside _ hzero_a2) ((hsig_a2.2 (base 760) (by decide +kernel)).trans (R2SqEp760.encoded5_760 origin ctx _ _ _ hb2_frame)) ((hsig_a2.2 (base 717) (by decide +kernel)).trans (R2SqEp760.encoded5_717 origin ctx _ _ _ hb2_frame)) rw [endpointL_r_eq] at ha3_spec have hb3_eq : run (StairConcrete.bestLoans.endPacket false 68) m3s (pullState (OB5.sig 511) b2) = run (R2SqEp760.endPacket760 false) m3s (pullState (OB5.sig 511) b2) := by have he : StairConcrete.bestLoans.endPacket false 68 = StairEndpointLoan44.endPacket760Loan44 false := by simp only [StairConcrete.bestLoans, StairConcrete.endPacket, Bool.false_eq_true, if_false, if_true] rw [he] exact StairEndpointLoan44.endPacket760Loan44_run_eq false origin ctx en (Y / 2) (Y / 2) rfl _ m3s m3s hb2_frame have hb3_spec := R2SqEp760.endPacket760_frame false false origin ctx en (Y / 2) (Y / 2) (fun h => absurd h (by decide)) (fun _ => rfl) (pullState (OB5.sig 511) b2) m3s hb2_frame have hb3_frame : Rolling1588Frame.EncodedFieldFrame false origin (Replay5.endPayload false origin (Y / 2, Y / 2)).1 (Replay5.endPayload false origin (Y / 2, Y / 2)).2 b3 := by have hconj := run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)) (StairConcrete.bestLoans.endPacket false 68) m3s b2 change Rolling1588.EncodedFieldFrame5 base (base 2409) false origin _ _ (pullState (OB5.sig 511) b3) rw [show pullState (OB5.sig 511) b3 = run (StairConcrete.bestLoans.endPacket false 68) m3s (pullState (OB5.sig 511) b2) from hconj, hb3_eq] exact hb3_spec.2 have h510_eq : (pullState (OB5.sig 511) a2).basis (base 510) = origin (base 510) := by refine (hsig_a2.2 (base 510) (by decide +kernel)).trans ?_ obtain ⟨raw, _, hpair, henc⟩ := hb2_frame rw [henc, run_preserves_outside _ [] raw _ (allEncode_510_free false)] exact hpair.2.2 (base 510) (by decide +kernel) (by decide +kernel) have hV1_eq : (Replay5.endPayload false origin (Y / 2, Y / 2)).1 = (if (pullState (OB5.sig 511) a2).basis (base 510) then 1 else 3) * (Y / 2) := by rw [h510_eq]; simp only [Replay5.endPayload, mixedTranscriptBit, en, if_true] cases origin (base 510) <;> simp <;> ring have hV2_eq : (Replay5.endPayload false origin (Y / 2, Y / 2)).2 = Y / 2 := rfl have ha3_ag : AgreeRY a3 b3 := by have hconj_a := run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)) OddFullPass.InverseTailCOdd.endPacket760OddLoan44 m3o a2 have hconj_b := run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)) (StairConcrete.bestLoans.endPacket false 68) m3s b2 have ha3p : a3.phase = a2.phase := (pullState_phase _ a3).symm.trans ((congrArg State.phase hconj_a).trans (ha3_spec.1.trans (pullState_phase _ a2))) have hb3p : b3.phase = b2.phase := (pullState_phase _ b3).symm.trans ((congrArg State.phase hconj_b).trans (((congrArg State.phase hb3_eq).trans hb3_spec.1).trans (pullState_phase _ b2))) have hph : a3.phase = b3.phase := ha3p.trans (ha2_ag.1.trans hb3p.symm) have hb3_out := encodedFieldFrame_agreeRY centerWord centerWord false origin _ _ _ _ b3 b2 hb3p hb3_frame hb2_frame have hp : AgreeRY (pullState (OB5.sig 511) a3) (pullState (OB5.sig 511) b3) := ⟨(pullState_phase _ a3).trans (hph.trans (pullState_phase _ b3).symm), fun q hq => by rw [hconj_a, ha3_spec.2.2 q (fun hr => hq ((mem_ryWires_iff q).mpr (Or.inl hr)))] exact (hsig_a2.2 q hq).trans ((pullState_sig511_agreeRY hb3_out).2 q hq).symm⟩ have hu := pullState_sig511_agreeRY hp rwa [StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide)), StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide))] at hu have ha3_vals : regValue fieldR a3.basis = P1Life.oddWord (Replay5.endPayload false origin (Y / 2, Y / 2)).1 ∧ regValue fieldY a3.basis = P1Life.oddWord (Replay5.endPayload false origin (Y / 2, Y / 2)).2 := by have hconj_a := run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)) OddFullPass.InverseTailCOdd.endPacket760OddLoan44 m3o a2 constructor · rw [← pullState_sig511_regValue_R, hconj_a, hV1_eq]; exact ha3_spec.2.1 · rw [← pullState_sig511_regValue_Y, hconj_a, hV2_eq] exact (regValue_congr _ _ _ (fun q hq => ha3_spec.2.2 q (fun hr => fieldR_disjoint_fieldY q hr hq))).trans (by rw [pullState_sig511_regValue_Y]; exact ha2_Y) have hb3_vals := encodedFieldFrame_values false origin _ _ b3 hb3_frame -- Now transfer `P_odd` and `P_std` from `s_rec` to `pullIn b` via `run_local_increment`! have hs_rel : OddRel P1Life.oddWord P1Life.oddWord (run P_odd m s_rec) (run P_std m s_rec) := by have h1 : run P_odd m s_rec = a3 := by simp only [P_odd, run_append, a3, a2, a1, m1o, m2o, m3o, m12o] have h2 : run P_std m s_rec = b3 := by simp only [P_std, run_append, b3, b2, b1, m1s, m2s, m3s, m12s] rw [h1, h2] exact oddRel_of_agreeRY_values _ _ ha3_ag hb3_vals.1 hb3_vals.2 ha3_vals.1 ha3_vals.2 have hinc_odd := Arithmetic.run_local_increment P_odd (pullIn b) s_rec m (fun q hq => hpb_rec q (hodd_off q hq)) have hinc_std := Arithmetic.run_local_increment P_std (pullIn b) s_rec m (fun q hq => hpb_rec q (hstd_off q hq)) have hout_ag : AgreeRY (run P_odd m (pullIn b)) (run P_std m (pullIn b)) := by have hph : (run P_odd m (pullIn b)).phase = (run P_std m (pullIn b)).phase := phase_eq_of_xor hinc_odd.1 (hs_rel.1.1 ▸ hinc_std.1) rfl refine ⟨hph, fun q hq => ?_⟩ by_cases h1 : q ∈ wires P_odd · rw [hinc_odd.2 q h1, hinc_std.2 q (hodd_sub_std h1)]; exact hs_rel.1.2 q hq · rw [run_preserves_outside P_odd m (pullIn b) q h1] by_cases h2 : q ∈ wires P_std · rw [hinc_std.2 q h2] have h3 := hs_rel.1.2 q hq rw [run_preserves_outside P_odd m s_rec q h1] at h3 exact (hpb_rec q (hstd_off q h2)).trans h3 · rw [run_preserves_outside P_std m (pullIn b) q h2] have hout_vals_odd : regValue fieldR (run P_odd m (pullIn b)).basis = regValue fieldR (run P_odd m s_rec).basis ∧ regValue fieldY (run P_odd m (pullIn b)).basis = regValue fieldY (run P_odd m s_rec).basis := by have hEq (q : Wire) (hq : q ∈ ryWires) : (run P_odd m (pullIn b)).basis q = (run P_odd m s_rec).basis q := by by_cases hw : q ∈ wires P_odd · exact hinc_odd.2 q hw · rw [run_preserves_outside P_odd m (pullIn b) q hw, run_preserves_outside P_odd m s_rec q hw] exact hpb_rec q (ryWires_off q hq) exact ⟨regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inl hq))), regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inr hq)))⟩ have hout_vals_std : regValue fieldR (run P_std m (pullIn b)).basis = regValue fieldR (run P_std m s_rec).basis ∧ regValue fieldY (run P_std m (pullIn b)).basis = regValue fieldY (run P_std m s_rec).basis := by have hEq (q : Wire) (hq : q ∈ ryWires) : (run P_std m (pullIn b)).basis q = (run P_std m s_rec).basis q := by by_cases hw : q ∈ wires P_std · exact hinc_std.2 q hw · rw [run_preserves_outside P_std m (pullIn b) q hw, run_preserves_outside P_std m s_rec q hw] exact hpb_rec q (ryWires_off q hq) exact ⟨regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inl hq))), regValue_congr _ _ _ (fun q hq => hEq q ((mem_ryWires_iff q).mpr (Or.inr hq)))⟩ have hout_rel : OddRel P1Life.oddWord P1Life.oddWord (run P_odd m (pullIn b)) (run P_std m (pullIn b)) := by refine ⟨hout_ag, ?_, ?_⟩ · intro X hX; rw [hout_vals_odd.1]; exact hs_rel.2.1 X (by rwa [← hout_vals_std.1]) · intro Y' hY'; rw [hout_vals_odd.2]; exact hs_rel.2.2 Y' (by rwa [← hout_vals_std.2]) rw [StairField2V3Seg.liftF_run, StairField2V3Seg.liftF_run] exact pullOut_oddRel hout_rel end ECDSAAdd.Entrant.OddStockLockstep end end -- ==== end OddLockstepSteps ==== -- ==== begin OddLockstepDiv ==== section set_option autoImplicit false section namespace ECDSAAdd.Entrant.OddStockLockstep open ECDSAAdd Arithmetic RecordedQuantum Challenge MappedCompressed Secp256k1 BalancedField open StairConcreteAssembly StairHostsSchedule StairField2V3Seg StairField2V3Replay open StairField2V3Delta StairField2V3Couple StairField2V3Entry StairField2V3RecScratch StairField2V3ExitRec open StairField2V3LastRecX StairField2V3EntryPlanR StairField2V3ExitPlanR open StairField13V3 StairField13V3Clean StairOuterPlacement StairPhysicalLayout open StairLoanExitReachX StairLoanField7Transport StairPacket set_option maxRecDepth 30000 set_option maxHeartbeats 2000000 set_option linter.unusedSimpArgs false set_option linter.unusedVariables false attribute [local irreducible] run measurementCount wires renameProgram cut Rolling1588TickGap.forward theorem pullState_sig511_injective {a b : State} (h : pullState (OB5.sig 511) a = pullState (OB5.sig 511) b) : a = b := by have h2 := congrArg (pullState (OB5.sig 511)) h rwa [StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide)), StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide))] at h2 theorem local_eq_of_sub (P Q : Program) (hsub : wires P ⊆ wires Q) (a b : State) (m : List Bool) (hag : ∀ q ∈ wires Q, a.basis q = b.basis q) (heq : run P m b = run Q m b) : run P m a = run Q m a := by have hp := Arithmetic.run_local_increment P a b m (fun q hq => hag q (hsub hq)) have hq := Arithmetic.run_local_increment Q a b m hag apply State.extensionality · have hpeq : (run P m b).phase = (run Q m b).phase := congrArg State.phase heq have h1 : ((run P m a).phase ^^ a.phase) = ((run P m b).phase ^^ b.phase) := hp.1 have h2 : ((run Q m a).phase ^^ a.phase) = ((run P m b).phase ^^ b.phase) := by rw [hpeq]; exact hq.1 revert h1 h2 cases (run P m a).phase <;> cases (run Q m a).phase <;> cases a.phase <;> cases (run P m b).phase <;> cases b.phase <;> decide · funext w by_cases h1 : w ∈ wires P · rw [hp.2 w h1, hq.2 w (hsub h1), heq] · rw [run_preserves_outside P m a w h1] by_cases h2 : w ∈ wires Q · rw [hq.2 w h2, ← heq, run_preserves_outside P m b w h1]; exact hag w h2 · rw [run_preserves_outside Q m a w h2] theorem pullState_fieldMap_basis (s : State) (q : Wire) : (pullState fieldMap s).basis q = (pullState HostOB5.hostSwap (pullState (Equiv.swap FrontierEntry1591Field.work FrontierEntry1591Field.host) s)).basis q := rfl private theorem sig511_511 : OB5.sig 511 (base 511) = base 511 := by decide +kernel private theorem regValue_run_disjoint_R (P : Program) (h : ∀ q ∈ wires P, q ∉ fieldR) (m : List Bool) (s : State) : regValue fieldR (run P m s).basis = regValue fieldR s.basis := regValue_congr fieldR (run P m s).basis s.basis (fun q hq => run_preserves_outside P m s q (fun hw => h q hw hq)) private theorem R0_eq : R0 = renameProgram Rolling1588Lifetime.phaseHost (Rolling1588TickGap.firstPhase true) ++ (StairSchedule.paritySetup ++ StairSchedule.hostedX) := List.append_inj_left' R0_shape rfl private def fmInv (q : Wire) : Wire := HostOB5.hostSwap (Equiv.swap FrontierEntry1591Field.work FrontierEntry1591Field.host q) private theorem fmInv_fieldMap (q : Wire) : fmInv (fieldMap q) = q := by simp only [fmInv, fieldMap, Equiv.swap_apply_self, HostOB5.hostSwap_invol] theorem hostPlan_group_fresh_odd (d : Bool) (def_ start len : Nat) (hd : def_ ≤ 43) (h42 : def_ ≠ 42) (h1 : 1 ≤ start) (hb : start + len ≤ 102) (hsched : def_ = 43 ∨ (def_, start, len) ∈ [(0, 1, 84), (13, 85, 5), (22, 90, 3), (30, 93, 3), (36, 96, 2), (41, 98, 2)]) : ∀ q ∈ hostPlan.group d def_ start len, q ∉ wires (renameProgram (OB5.sig 511) (OddFullPass.P1LifeLoan.groups d def_ start len)) := by have hsub : wires (renameProgram (OB5.sig 511) (OddFullPass.P1LifeLoan.groups d def_ start len)) ⊆ wires (StairSchedule.placedGroups StairConcrete.bestLoans d def_ start len) := by simp only [StairSchedule.placedGroups, StairConcrete.bestLoans, OddFullPass.P1LifeLoan.groups, StairGroups.groups] exact StairLoanGroupSupport.rename_sub _ _ _ (StairLoanGroupSupport.sequence_sub _ _ _ (fun k => OddFullPass.P1LifeLoan.packet_wires_sub d def_ k hd h42) _ _) intro q hq hw rcases hsched with rfl | hs · exact StairField13V3Fresh.hostPlan_group43_fresh d start len h1 hb q hq (hsub hw) · exact StairField13V3Fresh.hostPlan_group_fresh d def_ start len hs q hq (hsub hw) theorem hostPlan_group_notRY (d : Bool) (def_ start len : Nat) (hd : def_ ≠ 44) : ∀ q ∈ hostPlan.group d def_ start len, q ∉ ryWires := by rw [hp_group d def_ start len hd] intro q hq unfold StairV3Primitives.groupHosts at hq split_ifs at hq · exact hosts_not_ryWires 87 (by decide) q hq · exact poolHosts_not_ryWires q hq · rcases List.mem_append.mp hq with h1 | h2 · have hb : StairV3Primitives.budgetOfDeficit def_ ∈ budgets := by unfold StairV3Primitives.budgetOfDeficit; split_ifs <;> decide exact hosts_not_ryWires _ hb q h1 · exact poolHosts_not_ryWires q h2 private theorem lowMap_eq_fieldPlace (w : Wire) : lowMap w = fieldPlace w := rfl private theorem grpL_eq (def_ start len : Nat) : grpL StairConcrete.bestLoans def_ start len = liftF (renameProgram (OB5.sig 511) (StairGroups.groups true def_ start len)) := rfl private theorem grp_eq (start len : Nat) : grp start len = liftF (renameProgram (OB5.sig 511) (Rolling1588.groups true start len)) := rfl private theorem cutLoan_helper {P : Program} {pre : State → Prop} {d : Bool} (clean : CutClean pre P ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group d 0 1 84).map lowMap)) (s : State) (h : pre s) (m : List Bool) : ∀ q ∈ StairSchedule.exclusiveRoles ++ hosts 87, (run P m s).basis (fieldPlace q) = false := by intro q hq exact clean s h m _ (by rw [hp_group d 0 1 84 (by decide)]; exact List.mem_map.mpr ⟨q, hq, rfl⟩) theorem cleanCut_after {pre : State → Prop} {P1 P2 P12 : Program} {sites : List Wire} (h : CutClean pre P12 sites) (hcat : P12 = P1 ++ P2) (s : State) (hs : pre s) (m1 m2 : List Bool) : ∀ q ∈ sites, (run P2 m2 (run P1 m1 s)).basis q = false := by intro q hq have h2 := h s hs (WindowFieldJourney.joinTapes P1 m1 m2) q hq rwa [hcat, WindowFieldJourney.joined] at h2 private theorem fullEntryCut3Clean (parts : StairField13V3Fresh.EntryClean) : CutClean EntryPre (cut eps 3) ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group true 0 1 84).map lowMap) := parts.groupsBefore (3, 0, 1, 84) (List.Mem.head _) theorem entryCut3_pin_loan {s : State} (F : EntryFrame s) (m : List Bool) : (∃ record, FrameAt F.x 1 record ∧ AgreeOutside (Δv 87) (run (cut eps 3) m s) record) ∧ (∀ q ∈ StairSchedule.exclusiveRoles ++ hosts 87, (run (cut eps 3) m s).basis (fieldPlace q) = false) := by constructor · obtain ⟨Q, step⟩ := ern3 F.x (StairOpenWiring.entryPlans F.x) obtain ⟨n, hrel, root, tape, ⟨F0, fx⟩, hreach⟩ := step s s ⟨⟨F, rfl⟩, rfl⟩ m have pinned := g_first root F0 tape rw [fx] at pinned rw [ecut3] exact ⟨_, hreach.symm ▸ pinned.1, hrel.1⟩ · exact cutLoan_helper (d := true) (fullEntryCut3Clean (entryClean_of_planR StairOpenWiring.entryPlans StairOpenWiring.half760)) s ⟨F⟩ m /-! ## Section 4: Division stock lockstep (`stockOddDivPrefix3`, `stockOddDivHead`) -/ def stockOddDivBeforeGroup : Program := StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf true ++ FourScratchWindow.clearProgram) def stockOddDivPrefix3 : Program := renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp) ++ stockOddDivBeforeGroup def stockOddDivRawTail : Program := StairSchedule.forwardSegment cp 87 62 425 450 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 5 ++ StairSchedule.forwardSegment cp 62 47 450 465 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 3 ++ StairSchedule.forwardSegment cp 47 32 465 480 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 3 ++ StairSchedule.forwardSegment cp 32 22 480 490 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 2 ++ StairSchedule.forwardSegment cp 22 12 490 500 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 2 ++ StairSchedule.forwardLast cp def stockOddDivPre : Program := renameProgram ExteriorPorts.fieldEquiv stockOddDivRawTail ++ StairSchedule.fieldRename FourScratchWindow.unprefix def stockOddDivBetween : Program := StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.entryLowSuffixOdd hostPlan) ++ StairSchedule.hostedX def stockOddDivPost : Program := renameProgram Rolling1588Lifetime.phaseHost Stair44Outer.reverseEnd def stockOddDivHead : Program := ((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) ++ ((((stockOddDivPre ++ StairSchedule.paritySetup) ++ stockOddDivBetween) ++ StairSchedule.paritySetup) ++ stockOddDivPost) /-- Construct the matching standard-encoded division input state `tStd` from an odd-word input `tOdd`. -/ def stdOfOdd (tOdd : State) (Y : Fp) : State := ⟨tOdd.phase, fun q => if h : q ∈ fieldR then (centerWord (Y / 2)).testBit (q - 2072) else tOdd.basis q⟩ def stdOfOdd_spec (hn : (skywalkSharedWires base).Nodup) (hlo : History5.HistoryAbove base) (ho : ∀ q ∈ [base 2400, base 2409, base 2410], q ∉ skywalkSharedWires base) (hf : MixedTranscriptReplayLayout base (base 2400) (base 2409) (base 2410) (mixedTranscriptTape base)) (x : Nat) (Y : Fp) (hx0 : 0 < x) (hx : x < p) (s tOdd : State) (hin : SkywalkArithmeticInput base x Y.val s.basis) (hg0 : s.basis (base 2409) = false) (hs0 : s.basis (base 2410) = false) (hph : tOdd.phase = s.phase) (hsame : ∀ q, q ∉ fieldR → tOdd.basis q = s.basis q) (hval : regValue fieldR tOdd.basis = P1Life.oddWord (Y / 2)) : PProd (EntryFrame (stdOfOdd tOdd Y)) (AgreeOutsideR tOdd (stdOfOdd tOdd Y)) := by let tStd := stdOfOdd tOdd Y have hval_std : regValue fieldR tStd.basis = centerWord (Y / 2) := by have hlt : centerWord (Y / 2) < 2 ^ 256 := (BalancedField.centerWord_valid (Y / 2)).1 apply Nat.eq_of_testBit_eq intro i by_cases hi : i < 256 · have hlen : fieldR.length = 256 := by simp [fieldR, wireBlock_length] have hbit := Arithmetic.regValue_bit fieldR i 0 tStd.basis (by omega) have hget : fieldR.getD i 0 = base (2056 + i) := by rw [List.getD_eq_getElem _ _ (by omega)] simp [fieldR, wireBlock] rw [hget] at hbit have hmem : base (2056 + i) ∈ fieldR := List.mem_map.mpr ⟨2056 + i, by simp only [List.mem_range'_1]; omega, rfl⟩ have hsub : base (2056 + i) - 2072 = i := by change (2056 + i) + 16 - 2072 = i; omega have htb : tStd.basis (base (2056 + i)) = (centerWord (Y / 2)).testBit i := by simp only [tStd, stdOfOdd, dif_pos hmem, hsub] rw [htb] at hbit rw [Nat.testBit_eq_decide_div_mod_eq, ← hbit] cases (centerWord (Y / 2)).testBit i <;> decide · have hlen : fieldR.length = 256 := by simp [fieldR, wireBlock_length] have hlt1 : regValue fieldR tStd.basis < 2 ^ 256 := hlen ▸ Arithmetic.regValue_lt fieldR tStd.basis rw [Nat.testBit_lt_two_pow (lt_of_lt_of_le hlt1 (Nat.pow_le_pow_right (by decide) (by omega))), Nat.testBit_lt_two_pow (lt_of_lt_of_le hlt (Nat.pow_le_pow_right (by decide) (by omega)))] have hag : AgreeOutsideR tOdd tStd := ⟨rfl, fun q hq => by simp only [tStd, stdOfOdd, dif_neg hq]⟩ refine ⟨⟨hn, hlo, ho, hf, x, Y, hx0, hx, s, hin, hg0, hs0, hph, fun q hq => (hag.2 q hq).symm.trans (hsame q hq), hval_std⟩, hag⟩ /-! ### Section 4b: Division cut-3 and full-head lockstep -/ private theorem openS_notFieldR : ∀ q ∈ wires (Stair44Kernel.openS true 409), q ∉ fieldR := by have hsub_fwd (n k : Nat) : wires (Rolling1588.Integer.forward true 1 n) ⊆ wires (Rolling1588.Integer.forward true 1 (n + k)) := by induction k with | zero => exact Finset.Subset.refl _ | succ k ih => rw [show n + (k + 1) = (n + k) + 1 by omega, Rolling1588.Integer.forward_snoc, wires_append] exact ih.trans Finset.subset_union_left have h424_508 : wires (Rolling1588TickGap.forward true 1 424) ⊆ wires (Rolling1588.forward true 1 508) := by have h1 := Rolling1588TickGap.forward_support true 1 424 (by decide) rw [← Rolling1588.Integer.forward_eq_packets] at h1 have h2 := h1.trans (hsub_fwd 424 84) rwa [Rolling1588.Integer.forward_eq_packets] at h2 have hsub_stack : wires (Rolling1588.forward true 1 508) ⊆ wires (Rolling1588.stackForward true) := by simp only [Rolling1588.stackForward, wires_append] exact Finset.subset_union_left.trans Finset.subset_union_left intro q hq have hp : q ∈ skywalkPoolWires base := by apply List.mem_toFinset.mp apply ParityXExitInverse23Kernel.first_pool true simp only [Rolling1588.firstPhase, wires_append, Finset.mem_union] simp only [Stair44Kernel.openS, wires_append, Finset.mem_union] at hq rcases hq with h1 | h2 · exact Or.inl (Or.inl h1) · exact Or.inl (Or.inr (hsub_stack (h424_508 h2))) exact FrontierEntry1591Kernel.pool_away_numerator q hp private theorem firstPack_notFieldR : ∀ q ∈ wires checkpointPrimitives.firstPack, q ∉ fieldR := by have h1 : StairWireCheck.allSites notFieldR (renameProgram StairV3Primitives.xRelabel (StairV3Primitives.orient 425)) = true := by decide +kernel have h2 : StairWireCheck.allSites notFieldR (renameProgram (OB5.sig 425) (Rolling1588.Integer.packFirst base true 425)) = true := by decide +kernel have h3 : StairWireCheck.allSites notFieldR StairPhysicalLayout.phaseBMove = true := by decide +kernel have h4 : (StairPhysicalPrimitives.rowSitesL 87).all (fun q => notFieldR (phaseRelabel q)) = true := by decide +kernel intro q hq simp only [checkpointPrimitives, StairV3Primitives.primitives, StairV3Primitives.firstPack, wires_append, Finset.mem_union] at hq rcases hq with ((ha | hb) | hc) | hd · exact (notFieldR_iff q).mp (StairWireCheck.allSites_sound notFieldR _ h1 q ha) · exact (notFieldR_iff q).mp (StairWireCheck.allSites_sound notFieldR _ h2 q hb) · exact (notFieldR_iff q).mp (StairWireCheck.allSites_sound notFieldR _ h3 q hc) · rw [renameProgram_support] at hd obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp hd exact (notFieldR_iff _).mp (List.all_eq_true.mp h4 w (StairPhysicalPrimitives.pack_rows 87 (by decide) w hw)) theorem firstPhase_cp_notFieldR : ∀ q ∈ wires (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)), q ∉ fieldR := by intro q hq rw [renameProgram_support] at hq obtain ⟨w, hw, rfl⟩ := Finset.mem_image.mp hq rw [WindowStockHead.shapeD, wires_append, Finset.mem_union] at hw have hnw : w ∉ fieldR := hw.elim (openS_notFieldR w) (firstPack_notFieldR w) intro hmem have hfix := phaseHost_fix_fieldR (Rolling1588Lifetime.phaseHost w) hmem exact hnw (Rolling1588Lifetime.phaseHost.injective hfix ▸ hmem) theorem divLead_eq_firstPhase_odd {tOdd tStd : State} (F : EntryFrame tStd) (hag : AgreeOutsideR tOdd tStd) (m : List Bool) : run Stair44Kernel.divLead m tOdd = run (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)) m tOdd := by have hin_std := StairField13V3Clean.entryInput F have hin_odd : SkywalkArithmeticInput base F.x (regValue fieldR tOdd.basis) tOdd.basis := FrontierEntry1591Kernel.paired_input F.x (centerWord (F.Y / 2)) tStd tOdd hin_std hag.2 have hpull_odd : pullState Rolling1588Lifetime.phaseHost tOdd = tOdd := by have hpull_std := StairField13V3Clean.pull_phaseHost_entry F apply State.extensionality · rfl · funext q by_cases hr : q ∈ fieldR · change tOdd.basis (Rolling1588Lifetime.phaseHost q) = tOdd.basis q rw [phaseHost_fix_fieldR q hr] · have hnr : Rolling1588Lifetime.phaseHost q ∉ fieldR := by intro hmem have hf := phaseHost_fix_fieldR (Rolling1588Lifetime.phaseHost q) hmem exact hr (Rolling1588Lifetime.phaseHost.injective hf ▸ hmem) change tOdd.basis (Rolling1588Lifetime.phaseHost q) = tOdd.basis q rw [hag.2 _ hnr, hag.2 _ hr] exact congrFun (congrArg State.basis hpull_std) q apply MappedCompressed.pullState_perm_injective Rolling1588Lifetime.phaseHost rw [run_rename _ Rolling1588Lifetime.phaseHost.injective, run_rename _ Rolling1588Lifetime.phaseHost.injective, hpull_odd, WindowStockHead.shapeD] exact Stair44Kernel.with_tail true 409 F.x _ (by decide) F.x_pos F.x_lt F.sharedNodup tOdd hin_odd _ m theorem fpSup_not_E : ∀ q, StairWireCheck.fpSup q = true → q ∉ E := by have h : E.all (fun q => !StairWireCheck.fpSup q) = true := by decide +kernel intro q hq hmem have := List.all_eq_true.mp h q hmem simp [hq] at this theorem ryWires_not_E : ∀ q ∈ ryWires, q ∉ E := by have h : E.all notRY = true := by decide +kernel intro q hq hmem exact (notRY_iff q).mp (List.all_eq_true.mp h q hmem) hq theorem fpSup_not_delta87 : ∀ q, StairWireCheck.fpSup q = true → fieldMap q ∉ Δv 87 := by have h : (futurePayload 87).all (fun r => !StairWireCheck.fpSup (fmInv (fieldPlace r))) = true := by decide +kernel intro q hq hmem simp only [Δv, List.mem_toFinset, List.mem_map] at hmem obtain ⟨r, hr, heq⟩ := hmem have hfm : fmInv (fieldPlace r) = q := by rw [heq, fmInv_fieldMap] have h1 := List.all_eq_true.mp h r hr rw [hfm, hq] at h1; exact Bool.noConfusion h1 theorem ryWires_not_delta87 : ∀ q ∈ ryWires, fieldMap q ∉ Δv 87 := by have h : (futurePayload 87).all (fun r => notRY (fmInv (fieldPlace r))) = true := by decide +kernel intro q hq hmem simp only [Δv, List.mem_toFinset, List.mem_map] at hmem obtain ⟨r, hr, heq⟩ := hmem have hfm : fmInv (fieldPlace r) = q := by rw [heq, fmInv_fieldMap] exact (notRY_iff q).mp (hfm ▸ List.all_eq_true.mp h r hr) hq private theorem entryClean_v3_inst : StairField13V3Fresh.EntryClean := entryClean_of_planR StairOpenWiring.entryPlans StairOpenWiring.half760 theorem exitClean_v3_inst (k : Nat) : StairField13V3Fresh.ExitClean k := exitClean_of_planR StairOpenWiring.exitPlans StairOpenWiring.half760 k private theorem firstBefore_eps : CutClean EntryPre (cut eps 1) ((StairSchedule.exclusiveRoles ++ hostPlan.firstPacket true).map fieldMap) := entryClean_v3_inst.firstBefore private theorem firstRolesAfter_eps : CutClean EntryPre (cut eps 2) (StairSchedule.exclusiveRoles.map fieldMap) := entryClean_v3_inst.firstRolesAfter private theorem groupsBefore_eps (j def_ start len : Nat) (h : (j, def_, start, len) ∈ [(3, 0, 1, 84), (5, 13, 85, 5), (7, 22, 90, 3), (9, 30, 93, 3), (11, 36, 96, 2), (13, 41, 98, 2), (17, 43, 100, 2)]) : CutClean EntryPre (cut eps j) ((StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group true def_ start len).map lowMap) := entryClean_v3_inst.groupsBefore (j, def_, start, len) h private theorem groupsRolesAfter_eps (j def_ start len : Nat) (h : (j, def_, start, len) ∈ [(3, 0, 1, 84), (5, 13, 85, 5), (7, 22, 90, 3), (9, 30, 93, 3), (11, 36, 96, 2), (13, 41, 98, 2), (17, 43, 100, 2)]) : CutClean EntryPre (cut eps (j + 1)) ((StairSchedule.exclusiveRoles.drop def_).map lowMap) := entryClean_v3_inst.groupsRolesAfter (j, def_, start, len) h private theorem div_piece1_rel {tOdd tStd : State} (F : EntryFrame tStd) (hag0 : AgreeOutsideR tOdd tStd) (hR0 : regValue fieldR tOdd.basis = P1Life.oddWord (F.Y / 2)) (m0 m1 : List Bool) : OddRel P1Life.oddWord P1Life.oddWord (run (StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf true)) m1 (run (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)) m0 tOdd)) (run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket true)) m1 (run (cut eps 1) m0 tStd)) := by have he1 : cut eps 1 = renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp) := by rw [cut_succ eps 0 (eL 0 (by decide)), cut_zero, e0_L, List.nil_append] have hag1_raw : AgreeOutsideR (run (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)) m0 tOdd) (run (cut eps 1) m0 tStd) := by rw [he1] exact agreeOutsideR_disjoint (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)) firstPhase_cp_notFieldR hag0 m0 have hR1_raw : regValue fieldR (run (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)) m0 tOdd).basis = P1Life.oddWord (F.Y / 2) := (regValue_run_disjoint_R _ firstPhase_cp_notFieldR m0 tOdd).trans hR0 have hb1_R_raw : regValue fieldR (run (cut eps 1) m0 tStd).basis = centerWord (F.Y / 2) := by rw [he1] exact (regValue_run_disjoint_R _ firstPhase_cp_notFieldR m0 tStd).trans F.numerator have hcleanIn_raw : ∀ q ∈ (StairSchedule.exclusiveRoles ++ hostPlan.firstPacket true).map fieldMap, (run (cut eps 1) m0 tStd).basis q = false := firstBefore_eps tStd ⟨F⟩ m0 have hcleanOut_raw : ∀ q ∈ StairSchedule.exclusiveRoles.map fieldMap, (run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket true)) m1 (run (cut eps 1) m0 tStd)).basis q = false := cleanCut_after firstRolesAfter_eps (by rw [cut_succ eps 1 (eL 1 (by decide)), e1_L]) tStd ⟨F⟩ m0 m1 -- Abstract `a1` and `b1` as opaque `State` variables so the kernel never unfolds `run`! obtain ⟨a1, ha1⟩ : ∃ s, run (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)) m0 tOdd = s := ⟨_, rfl⟩ obtain ⟨b1, hb1⟩ : ∃ s, run (cut eps 1) m0 tStd = s := ⟨_, rfl⟩ rw [ha1] at hag1_raw hR1_raw ⊢ rw [hb1] at hag1_raw hb1_R_raw hcleanIn_raw hcleanOut_raw ⊢ -- Relate `b1` to `run R0 mpR root` via `ern1` obtain ⟨Q1, hstep1⟩ := ern1 F.x (StairOpenWiring.entryPlans F.x) obtain ⟨n0, hrel1, root, mpR, ⟨Froot, fx⟩, hreach1⟩ := hstep1 tStd tStd ⟨⟨F, rfl⟩, rfl⟩ m0 obtain ⟨r0, hr0⟩ : ∃ s, run R0 mpR root = s := ⟨_, rfl⟩ have hrel1_b1 : AgreeOutside (Δv 87) b1 r0 := by have h1 := hrel1.1 rw [← ecut1, hb1, hreach1, hr0] at h1 exact h1 have actual_r := FrontierEntry1591Kernel.paired_input Froot.x Froot.Y.val Froot.source root Froot.input Froot.outsideNumerator let mp := mpR.take (measurementCount (renameProgram Rolling1588Lifetime.phaseHost (Rolling1588TickGap.firstPhase true))) let mS := mpR.drop (measurementCount (renameProgram Rolling1588Lifetime.phaseHost (Rolling1588TickGap.firstPhase true))) obtain ⟨orig_r, facts_r, legal_r, frames_r⟩ := Rolling1588Lifetime.entry_first_prepared Froot.sharedNodup Froot.historyAbove Froot.selectorsAway Froot.x Froot.Y Froot.x_pos Froot.x_lt Froot.source root mp Froot.input Froot.phase Froot.outsideNumerator Froot.numerator have ctx_r := Rolling1588Lifetime.prepared_context Froot.sharedNodup Froot.selectorsAway Froot.transcript Froot.x Froot.Y Froot.source orig_r facts_r legal_r Froot.selectorG_zero Froot.selectorS_zero have frameA_r := frames_r true have bits := Rolling1588Lifetime.first_clean true Froot.sharedNodup Froot.historyAbove Froot.x _ Froot.x_pos Froot.x_lt root mp actual_r have work := Rolling1588Lifetime.first_work_zero true Froot.sharedNodup Froot.x _ root mp actual_r have parity := Rolling1588Lifetime.first_parity true Froot.sharedNodup Froot.historyAbove Froot.x _ Froot.x_pos Froot.x_lt root mp actual_r rw [lf_eq] at frameA_r bits work parity obtain ⟨v, hv⟩ : ∃ v : State, run (Rolling1588.firstPhase true) mp root = v := ⟨_, rfl⟩ rw [hv] at frameA_r bits work parity have hR0_eq : r0 = run (StairSchedule.paritySetup ++ StairSchedule.hostedX) mS v := by rw [← hr0, R0_eq, run_append, first_phase_hosted true Froot.sharedNodup Froot.historyAbove Froot.x _ Froot.x_pos Froot.x_lt root mp actual_r, hv] have code := Rolling1588Frame.field_special_at orig_r.basis (Froot.Y / 2) 0 v 511 (by simp) frameA_r have in511 : v.basis (base 511) = true := (by rw [sig511_511] at code; exact code : v.basis (base 511) = orig_r.basis (base 511)).trans (trace_last Froot.x Froot.x_pos Froot.x_lt orig_r.basis facts_r.trace) have in1542 : v.basis (base 1542) = false := bits _ (by simp [FrontierEntry1591Native.workSites]) have flags := field_flags orig_r.basis ctx_r (Froot.Y / 2) 0 v frameA_r have hag_fv := hosted_agree_force v flags.1 in511 flags.2 in1542 work parity mS let origin' := writeBit orig_r.basis (base 2400) true have ctx' := FrontierEntry1591.context_control_set orig_r.basis ctx_r true have trace' : skywalkTapeControls origin' (skywalkSharedTape base) = SkywalkTrace.trace 512 (SkywalkRails.encode false false (Froot.x : Int) (p : Int)) := by rw [FrontierEntry1591.trace_control_set]; exact facts_r.trace have input' := Rolling1588.frame_control_set orig_r.basis (Froot.Y / 2) 0 v true frameA_r have en' : origin' (base 2400) = true := by simp [origin', writeBit] have hpb_fp : ∀ q, StairWireCheck.fpSup q = true → (pullState fieldMap b1).basis q = (force v).basis q := by intro q hq have h1 := hrel1_b1.2 (fieldMap q) (fpSup_not_delta87 q hq) have h2 : (pullState fieldMap r0).basis q = (force v).basis q := by rw [hR0_eq, pullState_fieldMap_basis]; exact hag_fv q (fpSup_not_E q hq) exact h1.trans h2 have hpb_ry : ∀ q ∈ ryWires, (pullState fieldMap b1).basis q = (force v).basis q := by intro q hq have h1 := hrel1_b1.2 (fieldMap q) (ryWires_not_delta87 q hq) have h2 : (pullState fieldMap r0).basis q = (force v).basis q := by rw [hR0_eq, pullState_fieldMap_basis]; exact hag_fv q (ryWires_not_E q hq) exact h1.trans h2 have hv_vals := encodedFieldFrame_values true origin' (Froot.Y / 2) 0 (force v) input' have hYeq : Froot.Y / 2 = F.Y / 2 := by have hb1_R_fv : regValue fieldR b1.basis = centerWord (Froot.Y / 2) := by rw [← pullState_fieldMap_regValue_R] exact (regValue_congr _ _ _ (fun q hq => hpb_ry q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hv_vals.1 exact centerWord_injective (hb1_R_fv.symm.trans hb1_R_raw) have ha1_Y0 : regValue fieldY a1.basis = 0 := by have hb1_Y0 : regValue fieldY b1.basis = 0 := by rw [← pullState_fieldMap_regValue_Y] have hvy := hv_vals.2 rw [HalfField.centerWord_zero] at hvy exact (regValue_congr _ _ _ (fun q hq => hpb_ry q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hvy exact (regValue_congr _ _ _ (fun q hq => hag1_raw.2 q (fun hr => fieldR_disjoint_fieldY q hr hq))).trans hb1_Y0 have hfp := firstPacketOdd_step true true origin' ctx' en' Froot.x Froot.x_lt trace' (Froot.Y / 2) 0 ⟨fun h => absurd h (by decide), fun _ => rfl⟩ a1 b1 (force v) m1 (agreeRY_of_agreeOutsideR hag1_raw) input' hpb_fp hpb_ry (by rw [hYeq]; exact hR1_raw) (by simp [JointOdd1588.firstYIn, HalfField.centerWord_zero, ha1_Y0]) hcleanIn_raw hcleanOut_raw exact oddRel_of_agreeRY_values _ _ hfp.1 hfp.2.2.2.1 hfp.2.2.2.2 hfp.2.1 hfp.2.2.1 /-- Cut-3 deliverable for Division: relates `stockOddDivPrefix3` (pieces 0–2) against `ExteriorEntryCut.stockPrefix` (cut 3 of `entryPieces`) with `OddRel`, `OCut 1`, and `Loan`. -/ theorem stockOddDiv_cut3 {tOdd tStd : State} (F : EntryFrame tStd) (hag0 : AgreeOutsideR tOdd tStd) (hR0 : regValue fieldR tOdd.basis = P1Life.oddWord (F.Y / 2)) (m : List Bool) : let a3 := run stockOddDivPrefix3 m tOdd (∃ n, OddRel P1Life.oddWord P1Life.oddWord a3 (run (cut eps 3) n tStd)) ∧ (∃ origin, FrontierReplay1591.Context origin ∧ origin (base 2400) = true ∧ TraceOK F.x origin ∧ WindowFieldView.OCut 1 origin (pullIn a3)) := by intro a3 let m0 := m.take (measurementCount (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp))) let mRest := m.drop (measurementCount (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp))) let m1 := mRest.take (measurementCount (StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf true))) let m2 := mRest.drop (measurementCount (StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf true))) have ha3_eq : a3 = run (StairSchedule.fieldRename FourScratchWindow.clearProgram) m2 (run (StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf true)) m1 (run (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)) m0 tOdd)) := by simp only [a3, stockOddDivPrefix3, stockOddDivBeforeGroup, fieldRename_append, run_append, m0, mRest, m1, m2] let n2 := WindowFieldJourney.joinTapes (cut eps 1) m0 m1 let n3 := WindowFieldJourney.joinTapes (cut eps 2) n2 m2 have hb3_eq : run (cut eps 3) n3 tStd = run (StairSchedule.fieldRename FourScratchWindow.clearProgram) m2 (run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket true)) m1 (run (cut eps 1) m0 tStd)) := by have hc2 : cut eps 2 = cut eps 1 ++ StairSchedule.fieldRename (Rolling1588.placedFirstPacket true) := by rw [cut_succ eps 1 (eL 1 (by decide)), e1_L] have hc3 : cut eps 3 = cut eps 2 ++ StairSchedule.fieldRename FourScratchWindow.clearProgram := by rw [cut_succ eps 2 (eL 2 (by decide)), e2_L] rw [hc3, WindowFieldJourney.joined, hc2, WindowFieldJourney.joined] have hrel2 := div_piece1_rel F hag0 hR0 m0 m1 have hrel3 : OddRel P1Life.oddWord P1Life.oddWord a3 (run (cut eps 3) n3 tStd) := by rw [ha3_eq, hb3_eq] exact oddRel_disjoint _ (disjoint_ryWires_fieldRename clearProgram_notRY) hrel2 m2 obtain ⟨⟨record, hframe, hagree⟩, hloan⟩ := entryCut3_pin_loan F n3 exact ⟨⟨n3, hrel3⟩, odd_cut_ocut 1 (by decide) (by decide) F.x a3 (run (cut eps 3) n3 tStd) record hrel3 hframe hagree hloan⟩ private theorem groupsPayload_add_true (origin : BasisState) (j a b : Nat) (V : Fp × Fp) : Replay5.groupsPayload true origin (j + a) b (Replay5.groupsPayload true origin j a V) = Replay5.groupsPayload true origin j (a + b) V := by induction a generalizing j V with | zero => simp [Replay5.groupsPayload, PacketSequence.payload] | succ a ih => simp only [Replay5.groupsPayload, PacketSequence.payload, if_true] at ih ⊢ have := ih (j + 1) (CompressedFieldSupport.directionalPayload false (mixedTranscriptControls origin (base 2400) (Replay5.letters j)) V) rw [show j + (a + 1) = j + 1 + a by omega, show (a + 1) + b = (a + b) + 1 by omega] simpa only [PacketSequence.payload, if_true] using this private def CutPay (origin : BasisState) (V0 : Fp × Fp) (c : Nat) (t : State) : Prop := ∃ s : State, Rolling1588.CutFrame c origin (Replay5.groupsPayload true origin 1 (c - 1) V0).1 (Replay5.groupsPayload true origin 1 (c - 1) V0).2 (pullState (OB5.sig 511) s) ∧ ∀ q, Off q → (pullIn t).basis q = s.basis q private theorem cutPay_step (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400) = true) (V0 : Fp × Fp) (j n j' : Nat) (hj : 1 ≤ j) (hb : j + n ≤ 102) (hj' : j + n = j') (t : State) (h : CutPay origin V0 j t) (m : List Bool) : CutPay origin V0 j' (run (grp j n) m t) := by subst hj' obtain ⟨s, hcut, hag⟩ := h have tri := Rolling1588.groups_cut_frame true j n hj hb origin ctx en _ _ (pullState (OB5.sig 511) s) m hcut have hpay : Replay5.groupsPayload true origin j n (Replay5.groupsPayload true origin 1 (j - 1) V0) = Replay5.groupsPayload true origin 1 (j + n - 1) V0 := by have h1 : 1 + (j - 1) = j := by omega have h2 : (j - 1) + n = j + n - 1 := by omega rw [← h2, ← groupsPayload_add_true origin 1 (j - 1) n V0, h1] refine ⟨run (renameProgram (OB5.sig 511) (Rolling1588.groups true j n)) m s, ?_, ?_⟩ · rw [StairField2V3Packet.sig_conj, StairReplay.pullState_involutive (OB5.sig 511) (OB5.sig_invol 511 (by decide)), ← hpay] exact tri.2 · intro q hq unfold grp; rw [pullIn_liftF] exact run_agree_offP _ (groups_off j n hj hb) _ _ m hag q hq /-- Explicit frame at division cut 18 (`run (R6 ++ grp 100 2) m tStd`) with exact `endPayload.1 = Y`! -/ private theorem div_cut18_frame_inner {tStd : State} (F : EntryFrame tStd) (mp mS mF mTail : List Bool) : ∃ (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400) = true) (X Y : Fp) (s102 : State), (Replay5.endPayload true origin (X, Y)).1 = Y ∧ Rolling1588Frame.EncodedFieldFrame false origin X Y s102 ∧ (∀ q, Off q → (pullIn (run ((((((grp 1 84 ++ grp 85 5) ++ grp 90 3) ++ grp 93 3) ++ grp 96 2) ++ grp 98 2) ++ grp 100 2) mTail (run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket true ++ FourScratchWindow.clearProgram)) mF (run (StairSchedule.paritySetup ++ StairSchedule.hostedX) mS (run (Rolling1588.firstPhase true) mp tStd))))).basis q = s102.basis q) := by have actual := FrontierEntry1591Kernel.paired_input F.x F.Y.val F.source tStd F.input F.outsideNumerator obtain ⟨orig, facts, legal, frames⟩ := Rolling1588Lifetime.entry_first_prepared F.sharedNodup F.historyAbove F.selectorsAway F.x F.Y F.x_pos F.x_lt F.source tStd mp F.input F.phase F.outsideNumerator F.numerator have ctx := Rolling1588Lifetime.prepared_context F.sharedNodup F.selectorsAway F.transcript F.x F.Y F.source orig facts legal F.selectorG_zero F.selectorS_zero have bits := Rolling1588Lifetime.first_clean true F.sharedNodup F.historyAbove F.x _ F.x_pos F.x_lt tStd mp actual have work := Rolling1588Lifetime.first_work_zero true F.sharedNodup F.x _ tStd mp actual have parity := Rolling1588Lifetime.first_parity true F.sharedNodup F.historyAbove F.x _ F.x_pos F.x_lt tStd mp actual have frameA := frames true rw [lf_eq] at frameA bits work parity obtain ⟨v, hv⟩ : ∃ v : State, run (Rolling1588.firstPhase true) mp tStd = v := ⟨_, rfl⟩ rw [hv] at frameA bits work parity ⊢ have code := Rolling1588Frame.field_special_at orig.basis (F.Y / 2) 0 v 511 (by simp) frameA have in511 : v.basis (base 511) = true := (by rw [sig511_511] at code; exact code : v.basis (base 511) = orig.basis (base 511)).trans (trace_last F.x F.x_pos F.x_lt orig.basis facts.trace) have in1542 : v.basis (base 1542) = false := bits _ (by simp [FrontierEntry1591Native.workSites]) have flags := field_flags orig.basis ctx (F.Y / 2) 0 v frameA let origin' := writeBit orig.basis (base 2400) true have ctx' := FrontierEntry1591.context_control_set orig.basis ctx true have trace' : skywalkTapeControls origin' (skywalkSharedTape base) = SkywalkTrace.trace 512 (SkywalkRails.encode false false (F.x : Int) (p : Int)) := by rw [FrontierEntry1591.trace_control_set]; exact facts.trace have input' := Rolling1588.frame_control_set orig.basis (F.Y / 2) 0 v true frameA have en' : origin' (base 2400) = true := by simp [origin', writeBit] have first := Rolling1588.placedFirstPacket_frame true true origin' ctx' en' F.x F.x_lt trace' (F.Y / 2) 0 ⟨fun h => absurd h (by decide), fun _ => rfl⟩ (force v) (mF.take (measurementCount (Rolling1588.placedFirstPacket true))) input' have agreeY := run_agree_off _ firstPacket_avoidE _ (force v) (mF.take (measurementCount (Rolling1588.placedFirstPacket true))) (hosted_agree_force v flags.1 in511 flags.2 in1542 work parity mS) obtain ⟨s1, hs1⟩ : ∃ s1 : State, run (Rolling1588.placedFirstPacket true) (mF.take (measurementCount (Rolling1588.placedFirstPacket true))) (force v) = s1 := ⟨_, rfl⟩ rw [hs1] at first agreeY have codes := Rolling1588.field_prefix_codes origin' ctx' _ _ s1 first.2 F.x F.x_pos F.x_lt trace' have clean := FourScratchWindow.field_clean origin' ctx' _ _ s1 first.2 codes.1 codes.2.1 have z768 := Rolling1588.field_768_zero origin' ctx' _ _ s1 first.2 have hag_s1 : ∀ q, Off q → (pullIn (run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket true ++ FourScratchWindow.clearProgram)) mF (run (StairSchedule.paritySetup ++ StairSchedule.hostedX) mS v))).basis q = s1.basis q := by intro q hq rw [field_pullIn, run_append (Rolling1588.placedFirstPacket true)] exact window_agree _ s1 _ agreeY clean codes.2.2 z768 q hq.1 hq.2 obtain ⟨V0, hV0⟩ : ∃ V0 : Fp × Fp, Replay5.firstPayload true origin' (F.Y / 2, 0) = V0 := ⟨_, rfl⟩ have hfirst_v0 : Rolling1588Frame.EncodedFieldFrame true origin' V0.1 V0.2 s1 := by rw [← hV0]; exact first.2 have hcp1 : CutPay origin' V0 1 (run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket true ++ FourScratchWindow.clearProgram)) mF (run (StairSchedule.paritySetup ++ StairSchedule.hostedX) mS v)) := ⟨s1, (Rolling1588.cutFrame_one origin' V0.1 V0.2 (pullState (OB5.sig 511) s1)).mpr hfirst_v0, hag_s1⟩ have hcp_chain (u1 : State) (m1 m2 m3 m4 m5 m6 m7 : List Bool) (h1 : CutPay origin' V0 1 u1) : CutPay origin' V0 102 (run (grp 100 2) m7 (run (grp 98 2) m6 (run (grp 96 2) m5 (run (grp 93 3) m4 (run (grp 90 3) m3 (run (grp 85 5) m2 (run (grp 1 84) m1 u1))))))) := by have h2 := cutPay_step origin' ctx' en' V0 1 84 85 (by decide) (by decide) rfl u1 h1 m1 have h3 := cutPay_step origin' ctx' en' V0 85 5 90 (by decide) (by decide) rfl _ h2 m2 have h4 := cutPay_step origin' ctx' en' V0 90 3 93 (by decide) (by decide) rfl _ h3 m3 have h5 := cutPay_step origin' ctx' en' V0 93 3 96 (by decide) (by decide) rfl _ h4 m4 have h6 := cutPay_step origin' ctx' en' V0 96 2 98 (by decide) (by decide) rfl _ h5 m5 have h7 := cutPay_step origin' ctx' en' V0 98 2 100 (by decide) (by decide) rfl _ h6 m6 exact cutPay_step origin' ctx' en' V0 100 2 102 (by decide) (by decide) rfl _ h7 m7 rw [run_append, run_append, run_append, run_append, run_append, run_append] obtain ⟨s8, hc8, ha8⟩ := hcp_chain _ _ _ _ _ _ _ _ hcp1 have hpay := Replay5.forward_payload origin' F.x (F.Y / 2) F.x_pos F.x_lt trace' rw [hV0] at hpay obtain ⟨V, hV⟩ : ∃ V : Fp × Fp, Replay5.groupsPayload true origin' 1 101 V0 = V := ⟨_, rfl⟩ rw [show (102 - 1 : Nat) = 101 from rfl, hV] at hc8 rw [hV] at hpay have hend : (Replay5.endPayload true origin' V).1 = V.2 := by have h1 := congrArg Prod.fst hpay have h2 := congrArg Prod.snd hpay have hsnd : (Replay5.endPayload true origin' V).2 = V.2 := by simp [Replay5.endPayload] exact h1.trans (h2.symm.trans hsnd) exact ⟨origin', ctx', en', V.1, V.2, s8, hend, (Rolling1588.cutFrame_end origin' V.1 V.2 (pullState (OB5.sig 511) s8)).mp hc8, ha8⟩ private theorem div_cut18_frame {tStd : State} (F : EntryFrame tStd) (m : List Bool) : ∃ (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400) = true) (X Y : Fp) (s102 : State), (Replay5.endPayload true origin (X, Y)).1 = Y ∧ Rolling1588Frame.EncodedFieldFrame false origin X Y s102 ∧ (∀ q, Off q → (pullIn (run (R6 ++ grp 100 2) m tStd)).basis q = s102.basis q) := by have hshape : R6 ++ grp 100 2 = ((renameProgram Rolling1588Lifetime.phaseHost (Rolling1588TickGap.firstPhase true) ++ (StairSchedule.paritySetup ++ StairSchedule.hostedX)) ++ StairSchedule.fieldRename (Rolling1588.placedFirstPacket true ++ FourScratchWindow.clearProgram)) ++ ((((((grp 1 84 ++ grp 85 5) ++ grp 90 3) ++ grp 93 3) ++ grp 96 2) ++ grp 98 2) ++ grp 100 2) := by simp only [R6, R5, R4, R3, R2, R1, R0_shape, List.append_assoc] rw [hshape, run_append ((renameProgram Rolling1588Lifetime.phaseHost (Rolling1588TickGap.firstPhase true) ++ (StairSchedule.paritySetup ++ StairSchedule.hostedX)) ++ StairSchedule.fieldRename (Rolling1588.placedFirstPacket true ++ FourScratchWindow.clearProgram)), run_append (renameProgram Rolling1588Lifetime.phaseHost (Rolling1588TickGap.firstPhase true) ++ (StairSchedule.paritySetup ++ StairSchedule.hostedX)), run_append (renameProgram Rolling1588Lifetime.phaseHost (Rolling1588TickGap.firstPhase true)), first_phase_hosted true F.sharedNodup F.historyAbove F.x _ F.x_pos F.x_lt tStd _ (FrontierEntry1591Kernel.paired_input F.x F.Y.val F.source tStd F.input F.outsideNumerator)] exact div_cut18_frame_inner F _ _ _ _ /-- Full division head lockstep: **`run stockOddDivHead m tOdd = run oldDivHead n tStd`**! -/ theorem stockOddDivHead_eq_oldDivHead {tOdd tStd : State} (F : EntryFrame tStd) (hag0 : AgreeOutsideR tOdd tStd) (hR0 : regValue fieldR tOdd.basis = P1Life.oddWord (F.Y / 2)) (m : List Bool) : ∃ n, run stockOddDivHead m tOdd = run WindowMiddleContract.oldDivHead n tStd := by -- Both `stockOddDivHead` and `oldDivHead` end with `post := renameProgram phaseHost reverseEnd`. -- Strip `post` and `divLead` first, then run the 24-piece lockstep! have hmc_divLead : measurementCount Stair44Kernel.divLead = measurementCount (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)) := by rw [WindowStockHead.shapeD, (renameProgram_counts _ _).2, (renameProgram_counts _ _).2, measurementCount_append, measurementCount_append, Stair44Kernel.open_count] let mPre := m.take (measurementCount ((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84) ++ ((((stockOddDivPre ++ StairSchedule.paritySetup) ++ stockOddDivBetween) ++ StairSchedule.paritySetup)))) let mPost := m.drop (measurementCount ((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84) ++ ((((stockOddDivPre ++ StairSchedule.paritySetup) ++ stockOddDivBetween) ++ StairSchedule.paritySetup)))) -- Step-by-step piece relation `DivCut j a b := (∃ u, b = run (cut eps j) u tStd) ∧ OddRel oddWord oddWord a b` let DivCut (j : Nat) (a b : State) : Prop := (∃ u, b = run (cut eps j) u tStd) ∧ OddRel P1Life.oddWord P1Life.oddWord a b have step_disj (j : Nat) (hj : j < 25) (P : Program) (hP : (eps[j]'(eL j hj)).L = P) (hnot : ∀ q ∈ wires P, q ∉ ryWires) : ∀ a b m', DivCut j a b → DivCut (j + 1) (run P m' a) (run P m' b) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ refine ⟨⟨WindowFieldJourney.joinTapes (cut eps j) u m', ?_⟩, oddRel_disjoint P hnot hrel m'⟩ rw [cut_succ eps j (eL j hj), hP, WindowFieldJourney.joined] have step_grp (j B def_ start len : Nat) (hj : j < 25) (hL : (eps[j]'(eL j hj)).L = grpL StairConcrete.bestLoans def_ start len) (hB : B ∈ budgets) (hstartB : start + len ≤ startFor B / 5) (hd : def_ ≤ 43) (h42 : def_ ≠ 42) (h1 : 1 ≤ start) (hb : start + len ≤ 102) (hmem : (j, def_, start, len) ∈ [(3, 0, 1, 84), (5, 13, 85, 5), (7, 22, 90, 3), (9, 30, 93, 3), (11, 36, 96, 2), (13, 41, 98, 2), (17, 43, 100, 2)]) (hsched : def_ = 43 ∨ (def_, start, len) ∈ [(0, 1, 84), (13, 85, 5), (22, 90, 3), (30, 93, 3), (36, 96, 2), (41, 98, 2)]) (hpin : ∀ u, ∃ rec, FrameAt F.x start rec ∧ AgreeOutside (Δv B) (run (cut eps j) u tStd) rec) : ∀ a b m', DivCut j a b → DivCut (j + 1) (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true def_ start len)) m' a) (run (grpL StairConcrete.bestLoans def_ start len) m' b) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨rec, hframe, hagree⟩ := hpin u have hclIn : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group true def_ start len).map lowMap, (run (cut eps j) u tStd).basis q = false := groupsBefore_eps j def_ start len hmem tStd ⟨F⟩ u have hclOut : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_).map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups true def_ start len))) m' (run (cut eps j) u tStd)).basis q = false := cleanCut_after (groupsRolesAfter_eps j def_ start len hmem) (by rw [cut_succ eps j (eL j hj), hL, grpL_eq]) tStd ⟨F⟩ u m' have hBne : B ≠ 0 := by rcases (by simpa [budgets] using hB : B = 87 ∨ B = 62 ∨ B = 47 ∨ B = 32 ∨ B = 22 ∨ B = 12) with rfl | rfl | rfl | rfl | rfl | rfl <;> decide have havoid : B ≠ 0 → ∀ q ∈ futurePayload B, q ∉ wires (renameProgram (OB5.sig 511) (Rolling1588.groups true start len)) := fun _ => StairField2V3Groups.groups_avoid_payload true B hB len start (by omega) have hstep := odd_hostedGroup_step true def_ start len B F.x hd h42 h1 hb (Or.inr hB) havoid a (run (cut eps j) u tStd) rec m' hrel hframe (by simp only [hBne, if_false]; exact hagree) hclIn hclOut (hostPlan_group_notRY true def_ start len (by omega)) (hostPlan_group_fresh_odd true def_ start len hd h42 h1 hb hsched) rw [← grpL_eq] at hstep refine ⟨⟨WindowFieldJourney.joinTapes (cut eps j) u m', ?_⟩, hstep⟩ rw [cut_succ eps j (eL j hj), hL, WindowFieldJourney.joined] -- Helper to extract `FrameAt` + `AgreeOutside (Δv B)` from `ern*` + `g_R*` have V := StairLoanField7RR.entryReachTransportR_best StairOpenWiring.half760 F.x have pin_of {j B : Nat} {Z R : Program} (hecut : cut eps j = Z) (hern : ∃ Q, CRel (EPreX F.x) (RowRelEn F.x B R) Z Q) (hg : ∀ t, ReachEn F.x R t → FrameAt F.x (if B = 62 then 85 else if B = 47 then 90 else if B = 32 then 93 else if B = 22 then 96 else 98) t) : ∀ u, ∃ rec, FrameAt F.x (if B = 62 then 85 else if B = 47 then 90 else if B = 32 then 93 else if B = 22 then 96 else 98) rec ∧ AgreeOutside (Δv B) (run (cut eps j) u tStd) rec := by intro u obtain ⟨Q, hcr⟩ := hern obtain ⟨_, hrr⟩ := hcr tStd tStd ⟨⟨F, rfl⟩, rfl⟩ u rw [hecut] exact ⟨_, hg _ hrr.2, hrr.1.1⟩ have pin5 := pin_of ecut5 (ern5 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r1 t ht; rw [← fx]; exact (g_R1 s0 F0 m0).1) have pin7 := pin_of ecut7 (ern7 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r2 t ht; rw [← fx]; exact (g_R2 s0 F0 m0).1) have pin9 := pin_of ecut9 (ern9 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r3 t ht; rw [← fx]; exact (g_R3 s0 F0 m0).1) have pin11 := pin_of ecut11 (ern11 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r4 t ht; rw [← fx]; exact (g_R4 s0 F0 m0).1) have pin13 := pin_of ecut13 (ern13 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r5 t ht; rw [← fx]; exact (g_R5 s0 F0 m0).1) -- Cut 3: `stockOddDivPrefix3` vs `cut eps 3` have hcut3 (m3 : List Bool) : ∃ b3, DivCut 3 (run (Stair44Kernel.divLead ++ stockOddDivBeforeGroup) m3 tOdd) b3 := by have hlead : run (Stair44Kernel.divLead ++ stockOddDivBeforeGroup) m3 tOdd = run stockOddDivPrefix3 m3 tOdd := by rw [stockOddDivPrefix3, run_append, run_append, divLead_eq_firstPhase_odd F hag0, hmc_divLead] rw [hlead] obtain ⟨⟨n3, hrel3⟩, _⟩ := stockOddDiv_cut3 F hag0 hR0 m3 exact ⟨run (cut eps 3) n3 tStd, ⟨n3, rfl⟩, hrel3⟩ -- Piece 3: `ogroup true 1 84` vs `grpL bestLoans 0 1 84` have step3 : ∀ a b m', DivCut 3 a b → DivCut 4 (run (renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) m' a) (run (grpL StairConcrete.bestLoans 0 1 84) m' b) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨⟨rec, hframe, hagree⟩, hloan⟩ := entryCut3_pin_loan F u have hclIn : ∀ q ∈ (StairSchedule.exclusiveRoles ++ hostPlan.group true 0 1 84).map lowMap, (run (cut eps 3) u tStd).basis q = false := by intro q hq obtain ⟨w, hw, rfl⟩ := List.mem_map.mp hq rw [hp_group true 0 1 84 (by decide)] at hw rw [lowMap_eq_fieldPlace] exact hloan w hw have hclOut' : ∀ q ∈ (StairSchedule.exclusiveRoles.drop 0).map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups true 0 1 84))) m' (run (cut eps 3) u tStd)).basis q = false := cleanCut_after (groupsRolesAfter_eps 3 0 1 84 (List.Mem.head _)) (by rw [cut_succ eps 3 (eL 3 (by decide)), e3_L, grpL_eq]) tStd ⟨F⟩ u m' have hclOut : ∀ q ∈ StairSchedule.exclusiveRoles.map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups true 0 1 84))) m' (run (cut eps 3) u tStd)).basis q = false := fun q hq => hclOut' q (by simpa only [List.drop_zero] using hq) have hstep := odd_ogroup84_step true F.x a (run (cut eps 3) u tStd) rec m' hrel hframe hagree hclIn hclOut rw [← grpL_eq] at hstep refine ⟨⟨WindowFieldJourney.joinTapes (cut eps 3) u m', ?_⟩, hstep⟩ rw [cut_succ eps 3 (eL 3 (by decide)), e3_L, WindowFieldJourney.joined] -- Pieces 4..16 have step4 := step_disj 4 (by decide) _ e4_L (disjoint_ryWires_liftF forward425_notRY) have step5 := step_grp 5 62 13 85 5 (by decide) e5_L (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin5 have step6 := step_disj 6 (by decide) _ e6_L (disjoint_ryWires_liftF forward450_notRY) have step7 := step_grp 7 47 22 90 3 (by decide) e7_L (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin7 have step8 := step_disj 8 (by decide) _ e8_L (disjoint_ryWires_liftF forward465_notRY) have step9 := step_grp 9 32 30 93 3 (by decide) e9_L (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin9 have step10 := step_disj 10 (by decide) _ e10_L (disjoint_ryWires_liftF forward480_notRY) have step11 := step_grp 11 22 36 96 2 (by decide) e11_L (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin11 have step12 := step_disj 12 (by decide) _ e12_L (disjoint_ryWires_liftF forward490_notRY) have step13 := step_grp 13 12 41 98 2 (by decide) (show (eps[13]'(eL 13 (by decide))).L = grpL StairConcrete.bestLoans 41 98 2 from rfl) (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin13 have step14 := step_disj 14 (by decide) (liftF (StairSchedule.forwardLast cp)) (by rfl) (disjoint_ryWires_liftF forwardLast_notRY) have step15 := step_disj 15 (by decide) (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup) (by rfl) (disjoint_ryWires_append (disjoint_ryWires_fieldRename unprefix_notRY) paritySetup_notRY) have step16 := step_disj 16 (by decide) (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram) (by rfl) (disjoint_ryWires_append hostedX_notRY (disjoint_ryWires_fieldRename clearProgram_notRY)) -- Cut 17 → Exact `b17 = run R6 nR6 s0` via `EntryPlanR.lastStep`, then piece 17 (`grpL bestLoans 43 100 2`) + pieces 18–20 (`divEndTail_eq`)! have h17_eq_R6 : ∀ u, ∃ (s0 : State) (F0 : EntryFrame s0) (nR6 : List Bool), F0.x = F.x ∧ run (cut eps 17) u tStd = run R6 nR6 s0 := by intro u obtain ⟨Q13, h13⟩ := ern13 F.x (StairOpenWiring.entryPlans F.x) V have h14 := crel_append h13 (sharedEn F.x 12 (grpL StairConcrete.bestLoans 41 98 2) (R5L StairConcrete.bestLoans) (away_of_sub _ _ _ entryGroupSub_best.2.2.2.2.2 (grp_away 12 (by decide) 98 2 (by decide)))) have hcut17 : cut eps 17 = (ES13 ++ grpL StairConcrete.bestLoans 41 98 2) ++ lastSeg cp := by rw [cut_succ eps 16 (eL 16 (by decide)), cut_succ eps 15 (eL 15 (by decide)), cut_succ eps 14 (eL 14 (by decide)), cut_succ eps 13 (eL 13 (by decide)), ecut13, show (eps[13]'(eL 13 (by decide))).L = grpL StairConcrete.bestLoans 41 98 2 from rfl, show (eps[14]'(eL 14 (by decide))).L = liftF (StairSchedule.forwardLast cp) from rfl, show (eps[15]'(eL 15 (by decide))).L = StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup from rfl, show (eps[16]'(eL 16 (by decide))).L = StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram from rfl] simp only [lastSeg, List.append_assoc] obtain ⟨n14, hrr14⟩ := h14 tStd tStd ⟨⟨F, rfl⟩, rfl⟩ (u.take (measurementCount (ES13 ++ grpL StairConcrete.bestLoans 41 98 2))) obtain ⟨nL, heqL⟩ := (StairOpenWiring.entryPlans F.x).lastStep _ _ ⟨hrr14.1, V.r6 _ hrr14.2⟩ (u.drop (measurementCount (ES13 ++ grpL StairConcrete.bestLoans 41 98 2))) obtain ⟨s0, nR6, ⟨F0, fx⟩, hs0⟩ := V.r6 _ hrr14.2 refine ⟨s0, F0, nR6, fx, ?_⟩ rw [hcut17, run_append, heqL] exact (by simp [run] : run [] nL _ = _).trans hs0 -- Step 17 (`grpL bestLoans 43 100 2`): exact `b17 = run R6 nR6 s0` gives `FrameAt F.x 100 b17` + `AgreeOutside (Δv 0) b17 b17`! have step17 : ∀ a b m', DivCut 17 a b → DivCut 18 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)) m' a) (run (grpL StairConcrete.bestLoans 43 100 2) m' b) ∧ (∃ (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400) = true) (X Y : Fp) (s102 : State), (Replay5.endPayload true origin (X, Y)).1 = Y ∧ Rolling1588Frame.EncodedFieldFrame false origin X Y s102 ∧ (∀ q, Off q → (pullIn (run (grpL StairConcrete.bestLoans 43 100 2) m' b)).basis q = s102.basis q)) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨s0, F0, nR6, fx, heq17⟩ := h17_eq_R6 u have hframe17 : FrameAt F.x 100 (run (cut eps 17) u tStd) := by rw [heq17, ← fx]; exact (g_R6 s0 F0 nR6).1 have hagree17 : AgreeOutside (Δv 0) (run (cut eps 17) u tStd) (run (cut eps 17) u tStd) := ⟨rfl, fun _ _ => rfl⟩ have hclIn : ∀ q ∈ (StairSchedule.exclusiveRoles.drop 43 ++ hostPlan.group true 43 100 2).map lowMap, (run (cut eps 17) u tStd).basis q = false := groupsBefore_eps 17 43 100 2 (by simp) tStd ⟨F⟩ u have hclOut : ∀ q ∈ (StairSchedule.exclusiveRoles.drop 43).map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups true 43 100 2))) m' (run (cut eps 17) u tStd)).basis q = false := cleanCut_after (groupsRolesAfter_eps 17 43 100 2 (by simp)) (by rw [cut_succ eps 17 (eL 17 (by decide)), show (eps[17]'(eL 17 (by decide))).L = grpL StairConcrete.bestLoans 43 100 2 from rfl, grpL_eq]) tStd ⟨F⟩ u m' have hstep := odd_hostedGroup_step true 43 100 2 0 F.x (by decide) (by decide) (by decide) (by decide) (Or.inl rfl) (fun h => absurd rfl h) a (run (cut eps 17) u tStd) (run (cut eps 17) u tStd) m' hrel hframe17 (by simp only [if_true]) hclIn hclOut (hostPlan_group_notRY true 43 100 2 (by decide)) (hostPlan_group_fresh_odd true 43 100 2 (by decide) (by decide) (by decide) (by decide) (Or.inl rfl)) rw [← grpL_eq] at hstep -- Also show `run (grpL bestLoans 43 100 2) m' (run R6 nR6 s0) = run (R6 ++ grp 100 2) (joinTapes R6 nR6 m') s0`! -- Wait: `StairGroups.groups true 43 100 2` agrees with `Rolling1588.groups true 100 2` on `s7` via `StairGroups.groups_cut_frame` -- AND `div_cut18_frame F0` gives `EncodedFieldFrame false origin X Y s102` + `AgreeOff`! -- Specifically, `run (grpL bestLoans 43 100 2) m' (run R6 nR6 s0) = run (grp 100 2) m' (run R6 nR6 s0)`: have hgrp_eq : run (grpL StairConcrete.bestLoans 43 100 2) m' (run R6 nR6 s0) = run (grp 100 2) m' (run R6 nR6 s0) := by have hg6 := (g_R6 s0 F0 nR6).1 obtain ⟨orig, X, Y, s_rec, ctx, en, _, hcut, hagree_rec⟩ := hg6 have hsub : wires (renameProgram (OB5.sig 511) (StairGroups.groups true 43 100 2)) ⊆ wires (renameProgram (OB5.sig 511) (Rolling1588.groups true 100 2)) := by rw [renameProgram_support, renameProgram_support] exact Finset.image_subset_image (StairLoanGroupSupport.groups_sub true 43 (by decide) 100 2) have hoff : ∀ q ∈ wires (renameProgram (OB5.sig 511) (Rolling1588.groups true 100 2)), Off q := groups_off 100 2 (by decide) (by decide) have hrun_eq : run (renameProgram (OB5.sig 511) (StairGroups.groups true 43 100 2)) m' s_rec = run (renameProgram (OB5.sig 511) (Rolling1588.groups true 100 2)) m' s_rec := by apply pullState_sig511_injective rw [run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)), run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide))] exact StairLoanReplay.groups_run_eq StairOpenWiring.half760 true 43 100 2 (by decide) (by decide) (by decide) orig ctx en X Y (pullState (OB5.sig 511) s_rec) m' m' hcut rw [grpL_eq, grp_eq, StairField2V3Seg.liftF_run, StairField2V3Seg.liftF_run] apply congrArg pullOut exact local_eq_of_sub _ _ hsub (pullIn (run R6 nR6 s0)) s_rec m' (fun q hq => hagree_rec q (hoff q hq)) hrun_eq refine ⟨⟨⟨WindowFieldJourney.joinTapes (cut eps 17) u m', ?_⟩, hstep⟩, ?_⟩ · rw [cut_succ eps 17 (eL 17 (by decide)), show (eps[17]'(eL 17 (by decide))).L = grpL StairConcrete.bestLoans 43 100 2 from rfl, WindowFieldJourney.joined] · rw [heq17, hgrp_eq, ← WindowFieldJourney.joined R6 (grp 100 2) nR6 m' s0] exact div_cut18_frame F0 (WindowFieldJourney.joinTapes R6 nR6 m') -- Assemble the full 24-piece run equality: `run odd24 mPre tOdd = run (cut eps 24) n24 tStd`! let odd24 : Program := ((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) ++ ((((stockOddDivPre ++ StairSchedule.paritySetup) ++ stockOddDivBetween) ++ StairSchedule.paritySetup)) have hodd24_shape : odd24 = ((((((((((((((((((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) ++ liftF (StairSchedule.forwardSegment cp 87 62 425 450)) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 5)) ++ liftF (StairSchedule.forwardSegment cp 62 47 450 465)) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 3)) ++ liftF (StairSchedule.forwardSegment cp 47 32 465 480)) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 3)) ++ liftF (StairSchedule.forwardSegment cp 32 22 480 490)) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 2)) ++ liftF (StairSchedule.forwardSegment cp 22 12 490 500)) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 2)) ++ liftF (StairSchedule.forwardLast cp)) ++ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup)) ++ (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram)) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)) ++ liftF (renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan ++ HalfFieldOB5.copyN ++ OddFullPass.HalfConvertOdd.canon760OddLoan)) ++ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup)) := by have hlt_eq (P : Program) : liftF P = renameProgram ExteriorPorts.fieldEquiv P := ExteriorPorts.placedShape P have hraw : renameProgram ExteriorPorts.fieldEquiv stockOddDivRawTail = liftF (StairSchedule.forwardSegment cp 87 62 425 450) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 5) ++ liftF (StairSchedule.forwardSegment cp 62 47 450 465) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 3) ++ liftF (StairSchedule.forwardSegment cp 47 32 465 480) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 3) ++ liftF (StairSchedule.forwardSegment cp 32 22 480 490) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 2) ++ liftF (StairSchedule.forwardSegment cp 22 12 490 500) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 2) ++ liftF (StairSchedule.forwardLast cp) := by simp only [stockOddDivRawTail, Six505.rename_append, hlt_eq, List.append_assoc] have hbet : stockOddDivBetween = StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2) ++ liftF (renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan ++ HalfFieldOB5.copyN ++ OddFullPass.HalfConvertOdd.canon760OddLoan) ++ StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX := by simp only [stockOddDivBetween, OddFullPass.P1LifeLoan.entryLowSuffixOdd, OddFullPass.P1LifeLoan.entryTailSuffixOdd, fieldRename_append, Six505.rename_append, liftF, List.append_assoc] rw [← ExteriorPorts.placedShape (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)] simp only [odd24, stockOddDivPre, hraw, hbet, List.append_assoc] have hchain (s3 : State) (m3 m4 m5 m6 m7 m8 m9 m10 m11 m12 m13 m14 m15 m16 m17 m1820 m2123 : List Bool) (h3 : ∃ b3, DivCut 3 s3 b3) : ∃ n24, run (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup) m2123 (run (liftF (renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan ++ HalfFieldOB5.copyN ++ OddFullPass.HalfConvertOdd.canon760OddLoan)) m1820 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)) m17 (run (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram) m16 (run (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup) m15 (run (liftF (StairSchedule.forwardLast cp)) m14 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 2)) m13 (run (liftF (StairSchedule.forwardSegment cp 22 12 490 500)) m12 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 2)) m11 (run (liftF (StairSchedule.forwardSegment cp 32 22 480 490)) m10 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 3)) m9 (run (liftF (StairSchedule.forwardSegment cp 47 32 465 480)) m8 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 3)) m7 (run (liftF (StairSchedule.forwardSegment cp 62 47 450 465)) m6 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 5)) m5 (run (liftF (StairSchedule.forwardSegment cp 87 62 425 450)) m4 (run (renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) m3 s3)))))))))))))))) = run (cut eps 24) n24 tStd := by obtain ⟨b3, d3⟩ := h3 have d4 := step3 _ _ m3 d3 have d5 := step4 _ _ m4 d4 have d6 := step5 _ _ m5 d5 have d7 := step6 _ _ m6 d6 have d8 := step7 _ _ m7 d7 have d9 := step8 _ _ m8 d8 have d10 := step9 _ _ m9 d9 have d11 := step10 _ _ m10 d10 have d12 := step11 _ _ m11 d11 have d13 := step12 _ _ m12 d12 have d14 := step13 _ _ m13 d13 have d15 := step14 _ _ m14 d14 have d16 := step15 _ _ m15 d15 have d17 := step16 _ _ m16 d16 obtain ⟨⟨⟨u18, hb18⟩, hrel18⟩, origin, ctx, en, X, Y, s102, hend, hfr102, hag102⟩ := step17 _ _ m17 d17 rw [hb18] at hrel18 hag102 have htail_eq := divEndTail_eq origin ctx en X Y hend _ _ s102 m1820 hrel18 hfr102 hag102 let mTail := WindowFieldJourney.joinTapes (liftF (renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint ++ HalfFieldOB5.copyN ++ StairConcrete.bestLoans.canon)) m1820 m2123 refine ⟨WindowFieldJourney.joinTapes (cut eps 18) u18 mTail, ?_⟩ have hc24 : cut eps 24 = cut eps 18 ++ (liftF (renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint ++ HalfFieldOB5.copyN ++ StairConcrete.bestLoans.canon) ++ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup)) := by rw [cut_succ eps 23 (eL 23 (by decide)), cut_succ eps 22 (eL 22 (by decide)), cut_succ eps 21 (eL 21 (by decide)), cut_succ eps 20 (eL 20 (by decide)), cut_succ eps 19 (eL 19 (by decide)), cut_succ eps 18 (eL 18 (by decide)), show (eps[18]'(eL 18 (by decide))).L = liftF (renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint) from rfl, show (eps[19]'(eL 19 (by decide))).L = liftF HalfFieldOB5.copyN from rfl, show (eps[20]'(eL 20 (by decide))).L = liftF StairConcrete.bestLoans.canon from rfl, show (eps[21]'(eL 21 (by decide))).L = StairSchedule.fieldRename FourScratchWindow.unprefix from rfl, show (eps[22]'(eL 22 (by decide))).L = StairSchedule.hostedX from rfl, show (eps[23]'(eL 23 (by decide))).L = StairSchedule.paritySetup from rfl] simp only [liftF_append, List.append_assoc] rw [hc24, WindowFieldJourney.joined, WindowFieldJourney.joined] exact congrArg (run (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup) m2123) htail_eq have h24 : ∃ n24, run odd24 mPre tOdd = run (cut eps 24) n24 tStd := by rw [hodd24_shape, run_append _ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup), run_append _ (liftF (renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan ++ HalfFieldOB5.copyN ++ OddFullPass.HalfConvertOdd.canon760OddLoan)), run_append _ (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)), run_append _ (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram), run_append _ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup), run_append _ (liftF (StairSchedule.forwardLast cp)), run_append _ (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 2)), run_append _ (liftF (StairSchedule.forwardSegment cp 22 12 490 500)), run_append _ (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 2)), run_append _ (liftF (StairSchedule.forwardSegment cp 32 22 480 490)), run_append _ (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 3)), run_append _ (liftF (StairSchedule.forwardSegment cp 47 32 465 480)), run_append _ (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 3)), run_append _ (liftF (StairSchedule.forwardSegment cp 62 47 450 465)), run_append _ (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 5)), run_append _ (liftF (StairSchedule.forwardSegment cp 87 62 425 450)), run_append _ (renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84))] exact hchain _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (hcut3 _) obtain ⟨n24, hn24⟩ := h24 have hold24 : run (Stair44Kernel.divLead ++ Stair44Kernel.fieldD) n24 tStd = run (cut eps 24) n24 tStd := by rw [WindowStockHead.beforeD F, ← Stair44DivisionCut.selected cp hostPlan] unfold cut exact Stair44HostedCut.entry 24 tStd ⟨F⟩ n24 refine ⟨WindowFieldJourney.joinTapes (Stair44Kernel.divLead ++ Stair44Kernel.fieldD) n24 mPost, ?_⟩ have hsh : stockOddDivHead = odd24 ++ stockOddDivPost := by simp only [stockOddDivHead, odd24, stockOddDivPost, List.append_assoc] have hpost : stockOddDivPost = renameProgram Rolling1588Lifetime.phaseHost Stair44Outer.reverseEnd := rfl have hmPre : m.take (measurementCount odd24) = mPre := rfl have hmPost : m.drop (measurementCount odd24) = mPost := rfl rw [hsh, run_append, hmPre, hmPost, hpost, WindowMiddleContract.oldDivHead, WindowFieldJourney.joined, hold24, ← hn24] /-! ## Packet-cut rows on the odd division head -/ /-- The unlifted run of `P` on `pullIn s` reads a wire `q` where the lifted run reads `fieldPlace q`. -/ theorem run_pullIn_basis (P : Program) (m : List Bool) (s : State) (q : Wire) : (run P m (pullIn s)).basis q = (run (liftF P) m s).basis (fieldPlace q) := by rw [liftF_run] show _ = (run P m (pullIn s)).basis (fieldPlaceInv (fieldPlace q)) rw [inv_fieldPlace] /-- States that agree outside `ryWires` still agree, after a program whose lift avoids `ryWires`, on every wire that lifts outside `ryWires`. -/ theorem pullIn_agree {a b : State} (h : AgreeRY a b) (P : Program) (hP : ∀ q ∈ wires (liftF P), q ∉ ryWires) (m : List Bool) (q : Wire) (hq : fieldPlace q ∉ ryWires) : (run P m (pullIn a)).basis q = (run P m (pullIn b)).basis q := by rw [run_pullIn_basis, run_pullIn_basis] exact (agreeRY_disjoint (liftF P) hP h m).2 _ hq theorem oddRowCut1 {tStd : State} (F : EntryFrame tStd) (u : List Bool) (a : State) (hag : AgreeRY a (run (cut eps 4) u tStd)) (m : List Bool) : ∃ m', run (liftF (PackCutOdd.cutRowOdd 87 62 425 450 13 85 4)) m a = run (liftF (StairSchedule.forwardSegment cp 87 62 425 450 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 (4 + 1))) m' a := by have hH : run ((((entryPieces checkpointPrimitives hostPlan).take 4).map Piece.H).flatten) u tStd = run (cut eps 4) u tStd := by unfold cut exact Stair44HostedCut.entry 4 tStd ⟨F⟩ u have hseg : StairSchedule.forwardSegment cp 87 62 425 450 = (StairConcreteAssembly.checkpointPrimitives.unpack 87 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 425 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (425 + 1) (5 * 85 + 5 - (425 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (5 * 85 + 5)) ++ (renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (5 * 85))) PackCutTrip.E138 ++ renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (5 * 85))) Rolling1588.ep ++ (StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (5 * 85 + 5 + 1) (450 - (5 * 85 + 5) - 1) ++ checkpointPrimitives.orient 450 ++ renameProgram (OB5.sig 450) (Rolling1588.Integer.packFirst base true 450) ++ checkpointPrimitives.pack 62)) := by rw [PackCutShape.forwardSegment_row 87 62 425 450 85 (by decide) (by decide) (by decide) (by decide) (by decide)] simp only [List.append_assoc] have hP : ∀ q ∈ wires (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 87 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 425 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (425 + 1) (5 * 85 + 5 - (425 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (5 * 85 + 5))), q ∉ ryWires := by have hsub : (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 87 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 425 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (425 + 1) (5 * 85 + 5 - (425 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (5 * 85 + 5))).Sublist (liftF (StairSchedule.forwardSegment cp 87 62 425 450)) := by rw [hseg] exact PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (List.sublist_append_left _ _))) intro q hq exact disjoint_ryWires_liftF forward425_notRY q (PackCutSub.wires_sub hsub q hq) have hq : ∀ jj : Fin 10, fieldPlace ((History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (425 + 1))) (5 * 85)) jj) ∉ ryWires := by intro jj exact (notRY_iff _).mp (by revert jj; decide) obtain ⟨m', h⟩ := PackCutEntryChain.rowCutOdd1 F.x (StairOpenWiring.entryPlans F.x) (StairLoanField7RR.entryReachTransportR_best StairOpenWiring.half760 F.x) StairLoanField7Transport.entryGroupSub_best (StairField13V3.entrySlotsClean_of _ _ _ (StairField13V3.entrySlots_of_v3 (StairField13V3.entrySlotsV3_of_parts (StairField13V3Fresh.entryParts_of_clean (StairField13V3Clean.entryClean_of_planR StairOpenWiring.entryPlans StairOpenWiring.half760))))) tStd ⟨F, rfl⟩ u a (fun t1 jj => by rw [hH]; exact pullIn_agree hag _ hP t1 _ (hq jj)) m exact ⟨m', by rw [liftF_run, liftF_run, h]⟩ theorem oddRowCut2 {tStd : State} (F : EntryFrame tStd) (u : List Bool) (a : State) (hag : AgreeRY a (run (cut eps 6) u tStd)) (m : List Bool) : ∃ m', run (liftF (PackCutOdd.cutRowOdd 62 47 450 465 22 90 2)) m a = run (liftF (StairSchedule.forwardSegment cp 62 47 450 465 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 (2 + 1))) m' a := by have hH : run ((((entryPieces checkpointPrimitives hostPlan).take 6).map Piece.H).flatten) u tStd = run (cut eps 6) u tStd := by unfold cut exact Stair44HostedCut.entry 6 tStd ⟨F⟩ u have hseg : StairSchedule.forwardSegment cp 62 47 450 465 = (StairConcreteAssembly.checkpointPrimitives.unpack 62 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 450 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (450 + 1) (5 * 90 + 5 - (450 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (5 * 90 + 5)) ++ (renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (5 * 90))) PackCutTrip.E138 ++ renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (5 * 90))) Rolling1588.ep ++ (StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (5 * 90 + 5 + 1) (465 - (5 * 90 + 5) - 1) ++ checkpointPrimitives.orient 465 ++ renameProgram (OB5.sig 465) (Rolling1588.Integer.packFirst base true 465) ++ checkpointPrimitives.pack 47)) := by rw [PackCutShape.forwardSegment_row 62 47 450 465 90 (by decide) (by decide) (by decide) (by decide) (by decide)] simp only [List.append_assoc] have hP : ∀ q ∈ wires (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 62 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 450 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (450 + 1) (5 * 90 + 5 - (450 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (5 * 90 + 5))), q ∉ ryWires := by have hsub : (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 62 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 450 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (450 + 1) (5 * 90 + 5 - (450 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (5 * 90 + 5))).Sublist (liftF (StairSchedule.forwardSegment cp 62 47 450 465)) := by rw [hseg] exact PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (List.sublist_append_left _ _))) intro q hq exact disjoint_ryWires_liftF forward450_notRY q (PackCutSub.wires_sub hsub q hq) have hq : ∀ jj : Fin 10, fieldPlace ((History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (450 + 1))) (5 * 90)) jj) ∉ ryWires := by intro jj exact (notRY_iff _).mp (by revert jj; decide) obtain ⟨m', h⟩ := PackCutEntryChain.rowCutOdd2 F.x (StairOpenWiring.entryPlans F.x) (StairLoanField7RR.entryReachTransportR_best StairOpenWiring.half760 F.x) StairLoanField7Transport.entryGroupSub_best (StairField13V3.entrySlotsClean_of _ _ _ (StairField13V3.entrySlots_of_v3 (StairField13V3.entrySlotsV3_of_parts (StairField13V3Fresh.entryParts_of_clean (StairField13V3Clean.entryClean_of_planR StairOpenWiring.entryPlans StairOpenWiring.half760))))) tStd ⟨F, rfl⟩ u a (fun t1 jj => by rw [hH]; exact pullIn_agree hag _ hP t1 _ (hq jj)) m exact ⟨m', by rw [liftF_run, liftF_run, h]⟩ theorem oddRowCut3 {tStd : State} (F : EntryFrame tStd) (u : List Bool) (a : State) (hag : AgreeRY a (run (cut eps 8) u tStd)) (m : List Bool) : ∃ m', run (liftF (PackCutOdd.cutRowOdd 47 32 465 480 30 93 2)) m a = run (liftF (StairSchedule.forwardSegment cp 47 32 465 480 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 (2 + 1))) m' a := by have hH : run ((((entryPieces checkpointPrimitives hostPlan).take 8).map Piece.H).flatten) u tStd = run (cut eps 8) u tStd := by unfold cut exact Stair44HostedCut.entry 8 tStd ⟨F⟩ u have hseg : StairSchedule.forwardSegment cp 47 32 465 480 = (StairConcreteAssembly.checkpointPrimitives.unpack 47 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 465 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (465 + 1) (5 * 93 + 5 - (465 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (5 * 93 + 5)) ++ (renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (5 * 93))) PackCutTrip.E138 ++ renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (5 * 93))) Rolling1588.ep ++ (StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (5 * 93 + 5 + 1) (480 - (5 * 93 + 5) - 1) ++ checkpointPrimitives.orient 480 ++ renameProgram (OB5.sig 480) (Rolling1588.Integer.packFirst base true 480) ++ checkpointPrimitives.pack 32)) := by rw [PackCutShape.forwardSegment_row 47 32 465 480 93 (by decide) (by decide) (by decide) (by decide) (by decide)] simp only [List.append_assoc] have hP : ∀ q ∈ wires (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 47 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 465 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (465 + 1) (5 * 93 + 5 - (465 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (5 * 93 + 5))), q ∉ ryWires := by have hsub : (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 47 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 465 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (465 + 1) (5 * 93 + 5 - (465 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (5 * 93 + 5))).Sublist (liftF (StairSchedule.forwardSegment cp 47 32 465 480)) := by rw [hseg] exact PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (List.sublist_append_left _ _))) intro q hq exact disjoint_ryWires_liftF forward465_notRY q (PackCutSub.wires_sub hsub q hq) have hq : ∀ jj : Fin 10, fieldPlace ((History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (465 + 1))) (5 * 93)) jj) ∉ ryWires := by intro jj exact (notRY_iff _).mp (by revert jj; decide) obtain ⟨m', h⟩ := PackCutEntryChain.rowCutOdd3 F.x (StairOpenWiring.entryPlans F.x) (StairLoanField7RR.entryReachTransportR_best StairOpenWiring.half760 F.x) StairLoanField7Transport.entryGroupSub_best (StairField13V3.entrySlotsClean_of _ _ _ (StairField13V3.entrySlots_of_v3 (StairField13V3.entrySlotsV3_of_parts (StairField13V3Fresh.entryParts_of_clean (StairField13V3Clean.entryClean_of_planR StairOpenWiring.entryPlans StairOpenWiring.half760))))) tStd ⟨F, rfl⟩ u a (fun t1 jj => by rw [hH]; exact pullIn_agree hag _ hP t1 _ (hq jj)) m exact ⟨m', by rw [liftF_run, liftF_run, h]⟩ theorem oddRowCut4 {tStd : State} (F : EntryFrame tStd) (u : List Bool) (a : State) (hag : AgreeRY a (run (cut eps 10) u tStd)) (m : List Bool) : ∃ m', run (liftF (PackCutOdd.cutRowOdd 32 22 480 490 36 96 1)) m a = run (liftF (StairSchedule.forwardSegment cp 32 22 480 490 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 (1 + 1))) m' a := by have hH : run ((((entryPieces checkpointPrimitives hostPlan).take 10).map Piece.H).flatten) u tStd = run (cut eps 10) u tStd := by unfold cut exact Stair44HostedCut.entry 10 tStd ⟨F⟩ u have hseg : StairSchedule.forwardSegment cp 32 22 480 490 = (StairConcreteAssembly.checkpointPrimitives.unpack 32 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 480 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (480 + 1) (5 * 96 + 5 - (480 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (5 * 96 + 5)) ++ (renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (5 * 96))) PackCutTrip.E138 ++ renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (5 * 96))) Rolling1588.ep ++ (StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (5 * 96 + 5 + 1) (490 - (5 * 96 + 5) - 1) ++ checkpointPrimitives.orient 490 ++ renameProgram (OB5.sig 490) (Rolling1588.Integer.packFirst base true 490) ++ checkpointPrimitives.pack 22)) := by rw [PackCutShape.forwardSegment_row 32 22 480 490 96 (by decide) (by decide) (by decide) (by decide) (by decide)] simp only [List.append_assoc] have hP : ∀ q ∈ wires (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 32 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 480 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (480 + 1) (5 * 96 + 5 - (480 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (5 * 96 + 5))), q ∉ ryWires := by have hsub : (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 32 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 480 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (480 + 1) (5 * 96 + 5 - (480 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (5 * 96 + 5))).Sublist (liftF (StairSchedule.forwardSegment cp 32 22 480 490)) := by rw [hseg] exact PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (List.sublist_append_left _ _))) intro q hq exact disjoint_ryWires_liftF forward480_notRY q (PackCutSub.wires_sub hsub q hq) have hq : ∀ jj : Fin 10, fieldPlace ((History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (480 + 1))) (5 * 96)) jj) ∉ ryWires := by intro jj exact (notRY_iff _).mp (by revert jj; decide) obtain ⟨m', h⟩ := PackCutEntryChain.rowCutOdd4 F.x (StairOpenWiring.entryPlans F.x) (StairLoanField7RR.entryReachTransportR_best StairOpenWiring.half760 F.x) StairLoanField7Transport.entryGroupSub_best (StairField13V3.entrySlotsClean_of _ _ _ (StairField13V3.entrySlots_of_v3 (StairField13V3.entrySlotsV3_of_parts (StairField13V3Fresh.entryParts_of_clean (StairField13V3Clean.entryClean_of_planR StairOpenWiring.entryPlans StairOpenWiring.half760))))) tStd ⟨F, rfl⟩ u a (fun t1 jj => by rw [hH]; exact pullIn_agree hag _ hP t1 _ (hq jj)) m exact ⟨m', by rw [liftF_run, liftF_run, h]⟩ theorem oddRowCut5 {tStd : State} (F : EntryFrame tStd) (u : List Bool) (a : State) (hag : AgreeRY a (run (cut eps 12) u tStd)) (m : List Bool) : ∃ m', run (liftF (PackCutOdd.cutRowOdd 22 12 490 500 41 98 1)) m a = run (liftF (StairSchedule.forwardSegment cp 22 12 490 500 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 (1 + 1))) m' a := by have hH : run ((((entryPieces checkpointPrimitives hostPlan).take 12).map Piece.H).flatten) u tStd = run (cut eps 12) u tStd := by unfold cut exact Stair44HostedCut.entry 12 tStd ⟨F⟩ u have hseg : StairSchedule.forwardSegment cp 22 12 490 500 = (StairConcreteAssembly.checkpointPrimitives.unpack 22 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 490 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (490 + 1) (5 * 98 + 5 - (490 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (5 * 98 + 5)) ++ (renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (5 * 98))) PackCutTrip.E138 ++ renameProgram (MeasuredCodec5.label (History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (5 * 98))) Rolling1588.ep ++ (StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (5 * 98 + 5 + 1) (500 - (5 * 98 + 5) - 1) ++ checkpointPrimitives.orient 500 ++ renameProgram (OB5.sig 500) (Rolling1588.Integer.packFirst base true 500) ++ checkpointPrimitives.pack 12)) := by rw [PackCutShape.forwardSegment_row 22 12 490 500 98 (by decide) (by decide) (by decide) (by decide) (by decide)] simp only [List.append_assoc] have hP : ∀ q ∈ wires (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 22 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 490 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (490 + 1) (5 * 98 + 5 - (490 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (5 * 98 + 5))), q ∉ ryWires := by have hsub : (liftF (StairConcreteAssembly.checkpointPrimitives.unpack 22 ++ StairConcreteAssembly.checkpointPrimitives.tickForward 490 ++ StairReplay.movedForward (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (490 + 1) (5 * 98 + 5 - (490 + 1)) ++ TickRanges.tick (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (5 * 98 + 5))).Sublist (liftF (StairSchedule.forwardSegment cp 22 12 490 500)) := by rw [hseg] exact PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (PackCutSub.rename_sub _ (List.sublist_append_left _ _))) intro q hq exact disjoint_ryWires_liftF forward490_notRY q (PackCutSub.wires_sub hsub q hq) have hq : ∀ jj : Fin 10, fieldPlace ((History5.historyMap (StairPhysicalPrimitives.midSegmentMap (StairPhysicalPrimitives.segmentOf (490 + 1))) (5 * 98)) jj) ∉ ryWires := by intro jj exact (notRY_iff _).mp (by revert jj; decide) obtain ⟨m', h⟩ := PackCutEntryChain.rowCutOdd5 F.x (StairOpenWiring.entryPlans F.x) (StairLoanField7RR.entryReachTransportR_best StairOpenWiring.half760 F.x) StairLoanField7Transport.entryGroupSub_best (StairField13V3.entrySlotsClean_of _ _ _ (StairField13V3.entrySlots_of_v3 (StairField13V3.entrySlotsV3_of_parts (StairField13V3Fresh.entryParts_of_clean (StairField13V3Clean.entryClean_of_planR StairOpenWiring.entryPlans StairOpenWiring.half760))))) tStd ⟨F, rfl⟩ u a (fun t1 jj => by rw [hH]; exact pullIn_agree hag _ hP t1 _ (hq jj)) m exact ⟨m', by rw [liftF_run, liftF_run, h]⟩ /-- The odd division field's rows with the five packet-cut rows. -/ def stockOddDivRawTailCut : Program := PackCutOdd.cutRowOdd 87 62 425 450 13 85 4 ++ (PackCutOdd.cutRowOdd 62 47 450 465 22 90 2 ++ (PackCutOdd.cutRowOdd 47 32 465 480 30 93 2 ++ (PackCutOdd.cutRowOdd 32 22 480 490 36 96 1 ++ (PackCutOdd.cutRowOdd 22 12 490 500 41 98 1 ++ StairSchedule.forwardLast cp)))) def stockOddDivPreCut : Program := renameProgram ExteriorPorts.fieldEquiv stockOddDivRawTailCut ++ StairSchedule.fieldRename FourScratchWindow.unprefix def stockOddDivHeadCut : Program := ((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) ++ ((((stockOddDivPreCut ++ StairSchedule.paritySetup) ++ stockOddDivBetween) ++ StairSchedule.paritySetup) ++ stockOddDivPost) /-- The division head with the five packet-cut rows runs like the stock division head. -/ theorem stockOddDivHeadCut_eq_oldDivHead {tOdd tStd : State} (F : EntryFrame tStd) (hag0 : AgreeOutsideR tOdd tStd) (hR0 : regValue fieldR tOdd.basis = P1Life.oddWord (F.Y / 2)) (m : List Bool) : ∃ n, run stockOddDivHeadCut m tOdd = run WindowMiddleContract.oldDivHead n tStd := by -- Both `stockOddDivHead` and `oldDivHead` end with `post := renameProgram phaseHost reverseEnd`. -- Strip `post` and `divLead` first, then run the 24-piece lockstep! have hmc_divLead : measurementCount Stair44Kernel.divLead = measurementCount (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase cp)) := by rw [WindowStockHead.shapeD, (renameProgram_counts _ _).2, (renameProgram_counts _ _).2, measurementCount_append, measurementCount_append, Stair44Kernel.open_count] let mPre := m.take (measurementCount ((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84) ++ ((((stockOddDivPreCut ++ StairSchedule.paritySetup) ++ stockOddDivBetween) ++ StairSchedule.paritySetup)))) let mPost := m.drop (measurementCount ((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84) ++ ((((stockOddDivPreCut ++ StairSchedule.paritySetup) ++ stockOddDivBetween) ++ StairSchedule.paritySetup)))) -- Step-by-step piece relation `DivCut j a b := (∃ u, b = run (cut eps j) u tStd) ∧ OddRel oddWord oddWord a b` let DivCut (j : Nat) (a b : State) : Prop := (∃ u, b = run (cut eps j) u tStd) ∧ OddRel P1Life.oddWord P1Life.oddWord a b have step_disj (j : Nat) (hj : j < 25) (P : Program) (hP : (eps[j]'(eL j hj)).L = P) (hnot : ∀ q ∈ wires P, q ∉ ryWires) : ∀ a b m', DivCut j a b → DivCut (j + 1) (run P m' a) (run P m' b) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ refine ⟨⟨WindowFieldJourney.joinTapes (cut eps j) u m', ?_⟩, oddRel_disjoint P hnot hrel m'⟩ rw [cut_succ eps j (eL j hj), hP, WindowFieldJourney.joined] have step_grp (j B def_ start len : Nat) (hj : j < 25) (hL : (eps[j]'(eL j hj)).L = grpL StairConcrete.bestLoans def_ start len) (hB : B ∈ budgets) (hstartB : start + len ≤ startFor B / 5) (hd : def_ ≤ 43) (h42 : def_ ≠ 42) (h1 : 1 ≤ start) (hb : start + len ≤ 102) (hmem : (j, def_, start, len) ∈ [(3, 0, 1, 84), (5, 13, 85, 5), (7, 22, 90, 3), (9, 30, 93, 3), (11, 36, 96, 2), (13, 41, 98, 2), (17, 43, 100, 2)]) (hsched : def_ = 43 ∨ (def_, start, len) ∈ [(0, 1, 84), (13, 85, 5), (22, 90, 3), (30, 93, 3), (36, 96, 2), (41, 98, 2)]) (hpin : ∀ u, ∃ rec, FrameAt F.x start rec ∧ AgreeOutside (Δv B) (run (cut eps j) u tStd) rec) : ∀ a b m', DivCut j a b → DivCut (j + 1) (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true def_ start len)) m' a) (run (grpL StairConcrete.bestLoans def_ start len) m' b) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨rec, hframe, hagree⟩ := hpin u have hclIn : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group true def_ start len).map lowMap, (run (cut eps j) u tStd).basis q = false := groupsBefore_eps j def_ start len hmem tStd ⟨F⟩ u have hclOut : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_).map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups true def_ start len))) m' (run (cut eps j) u tStd)).basis q = false := cleanCut_after (groupsRolesAfter_eps j def_ start len hmem) (by rw [cut_succ eps j (eL j hj), hL, grpL_eq]) tStd ⟨F⟩ u m' have hBne : B ≠ 0 := by rcases (by simpa [budgets] using hB : B = 87 ∨ B = 62 ∨ B = 47 ∨ B = 32 ∨ B = 22 ∨ B = 12) with rfl | rfl | rfl | rfl | rfl | rfl <;> decide have havoid : B ≠ 0 → ∀ q ∈ futurePayload B, q ∉ wires (renameProgram (OB5.sig 511) (Rolling1588.groups true start len)) := fun _ => StairField2V3Groups.groups_avoid_payload true B hB len start (by omega) have hstep := odd_hostedGroup_step true def_ start len B F.x hd h42 h1 hb (Or.inr hB) havoid a (run (cut eps j) u tStd) rec m' hrel hframe (by simp only [hBne, if_false]; exact hagree) hclIn hclOut (hostPlan_group_notRY true def_ start len (by omega)) (hostPlan_group_fresh_odd true def_ start len hd h42 h1 hb hsched) rw [← grpL_eq] at hstep refine ⟨⟨WindowFieldJourney.joinTapes (cut eps j) u m', ?_⟩, hstep⟩ rw [cut_succ eps j (eL j hj), hL, WindowFieldJourney.joined] -- Helper to extract `FrameAt` + `AgreeOutside (Δv B)` from `ern*` + `g_R*` have V := StairLoanField7RR.entryReachTransportR_best StairOpenWiring.half760 F.x have pin_of {j B : Nat} {Z R : Program} (hecut : cut eps j = Z) (hern : ∃ Q, CRel (EPreX F.x) (RowRelEn F.x B R) Z Q) (hg : ∀ t, ReachEn F.x R t → FrameAt F.x (if B = 62 then 85 else if B = 47 then 90 else if B = 32 then 93 else if B = 22 then 96 else 98) t) : ∀ u, ∃ rec, FrameAt F.x (if B = 62 then 85 else if B = 47 then 90 else if B = 32 then 93 else if B = 22 then 96 else 98) rec ∧ AgreeOutside (Δv B) (run (cut eps j) u tStd) rec := by intro u obtain ⟨Q, hcr⟩ := hern obtain ⟨_, hrr⟩ := hcr tStd tStd ⟨⟨F, rfl⟩, rfl⟩ u rw [hecut] exact ⟨_, hg _ hrr.2, hrr.1.1⟩ have pin5 := pin_of ecut5 (ern5 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r1 t ht; rw [← fx]; exact (g_R1 s0 F0 m0).1) have pin7 := pin_of ecut7 (ern7 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r2 t ht; rw [← fx]; exact (g_R2 s0 F0 m0).1) have pin9 := pin_of ecut9 (ern9 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r3 t ht; rw [← fx]; exact (g_R3 s0 F0 m0).1) have pin11 := pin_of ecut11 (ern11 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r4 t ht; rw [← fx]; exact (g_R4 s0 F0 m0).1) have pin13 := pin_of ecut13 (ern13 F.x (StairOpenWiring.entryPlans F.x) V) (fun t ht => by obtain ⟨s0, m0, ⟨F0, fx⟩, rfl⟩ := V.r5 t ht; rw [← fx]; exact (g_R5 s0 F0 m0).1) -- Cut 3: `stockOddDivPrefix3` vs `cut eps 3` have hcut3 (m3 : List Bool) : ∃ b3, DivCut 3 (run (Stair44Kernel.divLead ++ stockOddDivBeforeGroup) m3 tOdd) b3 := by have hlead : run (Stair44Kernel.divLead ++ stockOddDivBeforeGroup) m3 tOdd = run stockOddDivPrefix3 m3 tOdd := by rw [stockOddDivPrefix3, run_append, run_append, divLead_eq_firstPhase_odd F hag0, hmc_divLead] rw [hlead] obtain ⟨⟨n3, hrel3⟩, _⟩ := stockOddDiv_cut3 F hag0 hR0 m3 exact ⟨run (cut eps 3) n3 tStd, ⟨n3, rfl⟩, hrel3⟩ -- Piece 3: `ogroup true 1 84` vs `grpL bestLoans 0 1 84` have step3 : ∀ a b m', DivCut 3 a b → DivCut 4 (run (renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) m' a) (run (grpL StairConcrete.bestLoans 0 1 84) m' b) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨⟨rec, hframe, hagree⟩, hloan⟩ := entryCut3_pin_loan F u have hclIn : ∀ q ∈ (StairSchedule.exclusiveRoles ++ hostPlan.group true 0 1 84).map lowMap, (run (cut eps 3) u tStd).basis q = false := by intro q hq obtain ⟨w, hw, rfl⟩ := List.mem_map.mp hq rw [hp_group true 0 1 84 (by decide)] at hw rw [lowMap_eq_fieldPlace] exact hloan w hw have hclOut' : ∀ q ∈ (StairSchedule.exclusiveRoles.drop 0).map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups true 0 1 84))) m' (run (cut eps 3) u tStd)).basis q = false := cleanCut_after (groupsRolesAfter_eps 3 0 1 84 (List.Mem.head _)) (by rw [cut_succ eps 3 (eL 3 (by decide)), e3_L, grpL_eq]) tStd ⟨F⟩ u m' have hclOut : ∀ q ∈ StairSchedule.exclusiveRoles.map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups true 0 1 84))) m' (run (cut eps 3) u tStd)).basis q = false := fun q hq => hclOut' q (by simpa only [List.drop_zero] using hq) have hstep := odd_ogroup84_step true F.x a (run (cut eps 3) u tStd) rec m' hrel hframe hagree hclIn hclOut rw [← grpL_eq] at hstep refine ⟨⟨WindowFieldJourney.joinTapes (cut eps 3) u m', ?_⟩, hstep⟩ rw [cut_succ eps 3 (eL 3 (by decide)), e3_L, WindowFieldJourney.joined] -- Pieces 4..16 have step4 := step_disj 4 (by decide) _ e4_L (disjoint_ryWires_liftF forward425_notRY) have step5 := step_grp 5 62 13 85 5 (by decide) e5_L (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin5 have step6 := step_disj 6 (by decide) _ e6_L (disjoint_ryWires_liftF forward450_notRY) have step7 := step_grp 7 47 22 90 3 (by decide) e7_L (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin7 have step8 := step_disj 8 (by decide) _ e8_L (disjoint_ryWires_liftF forward465_notRY) have step9 := step_grp 9 32 30 93 3 (by decide) e9_L (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin9 have step10 := step_disj 10 (by decide) _ e10_L (disjoint_ryWires_liftF forward480_notRY) have step11 := step_grp 11 22 36 96 2 (by decide) e11_L (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin11 have step12 := step_disj 12 (by decide) _ e12_L (disjoint_ryWires_liftF forward490_notRY) have step13 := step_grp 13 12 41 98 2 (by decide) (show (eps[13]'(eL 13 (by decide))).L = grpL StairConcrete.bestLoans 41 98 2 from rfl) (by decide) (by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin13 have stepCut1 : ∀ a b m', DivCut 4 a b → ∃ b', DivCut 6 (run (liftF (PackCutOdd.cutRowOdd 87 62 425 450 13 85 4)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨m2, h⟩ := oddRowCut1 F u a hrel.1 m' have dA := step4 _ _ (m2.take (measurementCount (liftF (StairSchedule.forwardSegment cp 87 62 425 450)))) ⟨⟨u, rfl⟩, hrel⟩ have dB := step5 _ _ (m2.drop (measurementCount (liftF (StairSchedule.forwardSegment cp 87 62 425 450)))) dA have e : liftF (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 (4 + 1)) = renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 5) := ExteriorPorts.placedShape _ rw [h, liftF_append, run_append, e] exact ⟨_, dB⟩ have stepCut2 : ∀ a b m', DivCut 6 a b → ∃ b', DivCut 8 (run (liftF (PackCutOdd.cutRowOdd 62 47 450 465 22 90 2)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨m2, h⟩ := oddRowCut2 F u a hrel.1 m' have dA := step6 _ _ (m2.take (measurementCount (liftF (StairSchedule.forwardSegment cp 62 47 450 465)))) ⟨⟨u, rfl⟩, hrel⟩ have dB := step7 _ _ (m2.drop (measurementCount (liftF (StairSchedule.forwardSegment cp 62 47 450 465)))) dA have e : liftF (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 (2 + 1)) = renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 3) := ExteriorPorts.placedShape _ rw [h, liftF_append, run_append, e] exact ⟨_, dB⟩ have stepCut3 : ∀ a b m', DivCut 8 a b → ∃ b', DivCut 10 (run (liftF (PackCutOdd.cutRowOdd 47 32 465 480 30 93 2)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨m2, h⟩ := oddRowCut3 F u a hrel.1 m' have dA := step8 _ _ (m2.take (measurementCount (liftF (StairSchedule.forwardSegment cp 47 32 465 480)))) ⟨⟨u, rfl⟩, hrel⟩ have dB := step9 _ _ (m2.drop (measurementCount (liftF (StairSchedule.forwardSegment cp 47 32 465 480)))) dA have e : liftF (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 (2 + 1)) = renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 3) := ExteriorPorts.placedShape _ rw [h, liftF_append, run_append, e] exact ⟨_, dB⟩ have stepCut4 : ∀ a b m', DivCut 10 a b → ∃ b', DivCut 12 (run (liftF (PackCutOdd.cutRowOdd 32 22 480 490 36 96 1)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨m2, h⟩ := oddRowCut4 F u a hrel.1 m' have dA := step10 _ _ (m2.take (measurementCount (liftF (StairSchedule.forwardSegment cp 32 22 480 490)))) ⟨⟨u, rfl⟩, hrel⟩ have dB := step11 _ _ (m2.drop (measurementCount (liftF (StairSchedule.forwardSegment cp 32 22 480 490)))) dA have e : liftF (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 (1 + 1)) = renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 2) := ExteriorPorts.placedShape _ rw [h, liftF_append, run_append, e] exact ⟨_, dB⟩ have stepCut5 : ∀ a b m', DivCut 12 a b → ∃ b', DivCut 14 (run (liftF (PackCutOdd.cutRowOdd 22 12 490 500 41 98 1)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨m2, h⟩ := oddRowCut5 F u a hrel.1 m' have dA := step12 _ _ (m2.take (measurementCount (liftF (StairSchedule.forwardSegment cp 22 12 490 500)))) ⟨⟨u, rfl⟩, hrel⟩ have dB := step13 _ _ (m2.drop (measurementCount (liftF (StairSchedule.forwardSegment cp 22 12 490 500)))) dA have e : liftF (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 (1 + 1)) = renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 2) := ExteriorPorts.placedShape _ rw [h, liftF_append, run_append, e] exact ⟨_, dB⟩ have step14 := step_disj 14 (by decide) (liftF (StairSchedule.forwardLast cp)) (by rfl) (disjoint_ryWires_liftF forwardLast_notRY) have step15 := step_disj 15 (by decide) (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup) (by rfl) (disjoint_ryWires_append (disjoint_ryWires_fieldRename unprefix_notRY) paritySetup_notRY) have step16 := step_disj 16 (by decide) (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram) (by rfl) (disjoint_ryWires_append hostedX_notRY (disjoint_ryWires_fieldRename clearProgram_notRY)) -- Cut 17 → Exact `b17 = run R6 nR6 s0` via `EntryPlanR.lastStep`, then piece 17 (`grpL bestLoans 43 100 2`) + pieces 18–20 (`divEndTail_eq`)! have h17_eq_R6 : ∀ u, ∃ (s0 : State) (F0 : EntryFrame s0) (nR6 : List Bool), F0.x = F.x ∧ run (cut eps 17) u tStd = run R6 nR6 s0 := by intro u obtain ⟨Q13, h13⟩ := ern13 F.x (StairOpenWiring.entryPlans F.x) V have h14 := crel_append h13 (sharedEn F.x 12 (grpL StairConcrete.bestLoans 41 98 2) (R5L StairConcrete.bestLoans) (away_of_sub _ _ _ entryGroupSub_best.2.2.2.2.2 (grp_away 12 (by decide) 98 2 (by decide)))) have hcut17 : cut eps 17 = (ES13 ++ grpL StairConcrete.bestLoans 41 98 2) ++ lastSeg cp := by rw [cut_succ eps 16 (eL 16 (by decide)), cut_succ eps 15 (eL 15 (by decide)), cut_succ eps 14 (eL 14 (by decide)), cut_succ eps 13 (eL 13 (by decide)), ecut13, show (eps[13]'(eL 13 (by decide))).L = grpL StairConcrete.bestLoans 41 98 2 from rfl, show (eps[14]'(eL 14 (by decide))).L = liftF (StairSchedule.forwardLast cp) from rfl, show (eps[15]'(eL 15 (by decide))).L = StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup from rfl, show (eps[16]'(eL 16 (by decide))).L = StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram from rfl] simp only [lastSeg, List.append_assoc] obtain ⟨n14, hrr14⟩ := h14 tStd tStd ⟨⟨F, rfl⟩, rfl⟩ (u.take (measurementCount (ES13 ++ grpL StairConcrete.bestLoans 41 98 2))) obtain ⟨nL, heqL⟩ := (StairOpenWiring.entryPlans F.x).lastStep _ _ ⟨hrr14.1, V.r6 _ hrr14.2⟩ (u.drop (measurementCount (ES13 ++ grpL StairConcrete.bestLoans 41 98 2))) obtain ⟨s0, nR6, ⟨F0, fx⟩, hs0⟩ := V.r6 _ hrr14.2 refine ⟨s0, F0, nR6, fx, ?_⟩ rw [hcut17, run_append, heqL] exact (by simp [run] : run [] nL _ = _).trans hs0 -- Step 17 (`grpL bestLoans 43 100 2`): exact `b17 = run R6 nR6 s0` gives `FrameAt F.x 100 b17` + `AgreeOutside (Δv 0) b17 b17`! have step17 : ∀ a b m', DivCut 17 a b → DivCut 18 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)) m' a) (run (grpL StairConcrete.bestLoans 43 100 2) m' b) ∧ (∃ (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400) = true) (X Y : Fp) (s102 : State), (Replay5.endPayload true origin (X, Y)).1 = Y ∧ Rolling1588Frame.EncodedFieldFrame false origin X Y s102 ∧ (∀ q, Off q → (pullIn (run (grpL StairConcrete.bestLoans 43 100 2) m' b)).basis q = s102.basis q)) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨s0, F0, nR6, fx, heq17⟩ := h17_eq_R6 u have hframe17 : FrameAt F.x 100 (run (cut eps 17) u tStd) := by rw [heq17, ← fx]; exact (g_R6 s0 F0 nR6).1 have hagree17 : AgreeOutside (Δv 0) (run (cut eps 17) u tStd) (run (cut eps 17) u tStd) := ⟨rfl, fun _ _ => rfl⟩ have hclIn : ∀ q ∈ (StairSchedule.exclusiveRoles.drop 43 ++ hostPlan.group true 43 100 2).map lowMap, (run (cut eps 17) u tStd).basis q = false := groupsBefore_eps 17 43 100 2 (by simp) tStd ⟨F⟩ u have hclOut : ∀ q ∈ (StairSchedule.exclusiveRoles.drop 43).map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups true 43 100 2))) m' (run (cut eps 17) u tStd)).basis q = false := cleanCut_after (groupsRolesAfter_eps 17 43 100 2 (by simp)) (by rw [cut_succ eps 17 (eL 17 (by decide)), show (eps[17]'(eL 17 (by decide))).L = grpL StairConcrete.bestLoans 43 100 2 from rfl, grpL_eq]) tStd ⟨F⟩ u m' have hstep := odd_hostedGroup_step true 43 100 2 0 F.x (by decide) (by decide) (by decide) (by decide) (Or.inl rfl) (fun h => absurd rfl h) a (run (cut eps 17) u tStd) (run (cut eps 17) u tStd) m' hrel hframe17 (by simp only [if_true]) hclIn hclOut (hostPlan_group_notRY true 43 100 2 (by decide)) (hostPlan_group_fresh_odd true 43 100 2 (by decide) (by decide) (by decide) (by decide) (Or.inl rfl)) rw [← grpL_eq] at hstep -- Also show `run (grpL bestLoans 43 100 2) m' (run R6 nR6 s0) = run (R6 ++ grp 100 2) (joinTapes R6 nR6 m') s0`! -- Wait: `StairGroups.groups true 43 100 2` agrees with `Rolling1588.groups true 100 2` on `s7` via `StairGroups.groups_cut_frame` -- AND `div_cut18_frame F0` gives `EncodedFieldFrame false origin X Y s102` + `AgreeOff`! -- Specifically, `run (grpL bestLoans 43 100 2) m' (run R6 nR6 s0) = run (grp 100 2) m' (run R6 nR6 s0)`: have hgrp_eq : run (grpL StairConcrete.bestLoans 43 100 2) m' (run R6 nR6 s0) = run (grp 100 2) m' (run R6 nR6 s0) := by have hg6 := (g_R6 s0 F0 nR6).1 obtain ⟨orig, X, Y, s_rec, ctx, en, _, hcut, hagree_rec⟩ := hg6 have hsub : wires (renameProgram (OB5.sig 511) (StairGroups.groups true 43 100 2)) ⊆ wires (renameProgram (OB5.sig 511) (Rolling1588.groups true 100 2)) := by rw [renameProgram_support, renameProgram_support] exact Finset.image_subset_image (StairLoanGroupSupport.groups_sub true 43 (by decide) 100 2) have hoff : ∀ q ∈ wires (renameProgram (OB5.sig 511) (Rolling1588.groups true 100 2)), Off q := groups_off 100 2 (by decide) (by decide) have hrun_eq : run (renameProgram (OB5.sig 511) (StairGroups.groups true 43 100 2)) m' s_rec = run (renameProgram (OB5.sig 511) (Rolling1588.groups true 100 2)) m' s_rec := by apply pullState_sig511_injective rw [run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)), run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide))] exact StairLoanReplay.groups_run_eq StairOpenWiring.half760 true 43 100 2 (by decide) (by decide) (by decide) orig ctx en X Y (pullState (OB5.sig 511) s_rec) m' m' hcut rw [grpL_eq, grp_eq, StairField2V3Seg.liftF_run, StairField2V3Seg.liftF_run] apply congrArg pullOut exact local_eq_of_sub _ _ hsub (pullIn (run R6 nR6 s0)) s_rec m' (fun q hq => hagree_rec q (hoff q hq)) hrun_eq refine ⟨⟨⟨WindowFieldJourney.joinTapes (cut eps 17) u m', ?_⟩, hstep⟩, ?_⟩ · rw [cut_succ eps 17 (eL 17 (by decide)), show (eps[17]'(eL 17 (by decide))).L = grpL StairConcrete.bestLoans 43 100 2 from rfl, WindowFieldJourney.joined] · rw [heq17, hgrp_eq, ← WindowFieldJourney.joined R6 (grp 100 2) nR6 m' s0] exact div_cut18_frame F0 (WindowFieldJourney.joinTapes R6 nR6 m') -- Assemble the full 24-piece run equality: `run odd24 mPre tOdd = run (cut eps 24) n24 tStd`! let odd24 : Program := ((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) ++ ((((stockOddDivPreCut ++ StairSchedule.paritySetup) ++ stockOddDivBetween) ++ StairSchedule.paritySetup)) have hodd24_shape : odd24 = (((((((((((((Stair44Kernel.divLead ++ stockOddDivBeforeGroup) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) ++ liftF (PackCutOdd.cutRowOdd 87 62 425 450 13 85 4)) ++ liftF (PackCutOdd.cutRowOdd 62 47 450 465 22 90 2)) ++ liftF (PackCutOdd.cutRowOdd 47 32 465 480 30 93 2)) ++ liftF (PackCutOdd.cutRowOdd 32 22 480 490 36 96 1)) ++ liftF (PackCutOdd.cutRowOdd 22 12 490 500 41 98 1)) ++ liftF (StairSchedule.forwardLast cp)) ++ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup)) ++ (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram)) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)) ++ liftF (renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan ++ HalfFieldOB5.copyN ++ OddFullPass.HalfConvertOdd.canon760OddLoan)) ++ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup)) := by have hlt_eq (P : Program) : liftF P = renameProgram ExteriorPorts.fieldEquiv P := ExteriorPorts.placedShape P have hraw : renameProgram ExteriorPorts.fieldEquiv stockOddDivRawTailCut = liftF (PackCutOdd.cutRowOdd 87 62 425 450 13 85 4) ++ liftF (PackCutOdd.cutRowOdd 62 47 450 465 22 90 2) ++ liftF (PackCutOdd.cutRowOdd 47 32 465 480 30 93 2) ++ liftF (PackCutOdd.cutRowOdd 32 22 480 490 36 96 1) ++ liftF (PackCutOdd.cutRowOdd 22 12 490 500 41 98 1) ++ liftF (StairSchedule.forwardLast cp) := by simp only [stockOddDivRawTailCut, Six505.rename_append, hlt_eq, List.append_assoc] have hbet : stockOddDivBetween = StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2) ++ liftF (renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan ++ HalfFieldOB5.copyN ++ OddFullPass.HalfConvertOdd.canon760OddLoan) ++ StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX := by simp only [stockOddDivBetween, OddFullPass.P1LifeLoan.entryLowSuffixOdd, OddFullPass.P1LifeLoan.entryTailSuffixOdd, fieldRename_append, Six505.rename_append, liftF, List.append_assoc] rw [← ExteriorPorts.placedShape (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)] simp only [odd24, stockOddDivPreCut, hraw, hbet, List.append_assoc] have hchain (s3 : State) (m3 m4 m6 m8 m10 m12 m14 m15 m16 m17 m1820 m2123 : List Bool) (h3 : ∃ b3, DivCut 3 s3 b3) : ∃ n24, run (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup) m2123 (run (liftF (renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan ++ HalfFieldOB5.copyN ++ OddFullPass.HalfConvertOdd.canon760OddLoan)) m1820 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)) m17 (run (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram) m16 (run (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup) m15 (run (liftF (StairSchedule.forwardLast cp)) m14 (run (liftF (PackCutOdd.cutRowOdd 22 12 490 500 41 98 1)) m12 (run (liftF (PackCutOdd.cutRowOdd 32 22 480 490 36 96 1)) m10 (run (liftF (PackCutOdd.cutRowOdd 47 32 465 480 30 93 2)) m8 (run (liftF (PackCutOdd.cutRowOdd 62 47 450 465 22 90 2)) m6 (run (liftF (PackCutOdd.cutRowOdd 87 62 425 450 13 85 4)) m4 (run (renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84)) m3 s3))))))))))) = run (cut eps 24) n24 tStd := by obtain ⟨b3, d3⟩ := h3 have d4 := step3 _ _ m3 d3 obtain ⟨b6, d6⟩ := stepCut1 _ _ m4 d4 obtain ⟨b8, d8⟩ := stepCut2 _ _ m6 d6 obtain ⟨b10, d10⟩ := stepCut3 _ _ m8 d8 obtain ⟨b12, d12⟩ := stepCut4 _ _ m10 d10 obtain ⟨b14, d14⟩ := stepCut5 _ _ m12 d12 have d15 := step14 _ _ m14 d14 have d16 := step15 _ _ m15 d15 have d17 := step16 _ _ m16 d16 obtain ⟨⟨⟨u18, hb18⟩, hrel18⟩, origin, ctx, en, X, Y, s102, hend, hfr102, hag102⟩ := step17 _ _ m17 d17 rw [hb18] at hrel18 hag102 have htail_eq := divEndTail_eq origin ctx en X Y hend _ _ s102 m1820 hrel18 hfr102 hag102 let mTail := WindowFieldJourney.joinTapes (liftF (renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint ++ HalfFieldOB5.copyN ++ StairConcrete.bestLoans.canon)) m1820 m2123 refine ⟨WindowFieldJourney.joinTapes (cut eps 18) u18 mTail, ?_⟩ have hc24 : cut eps 24 = cut eps 18 ++ (liftF (renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint ++ HalfFieldOB5.copyN ++ StairConcrete.bestLoans.canon) ++ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup)) := by rw [cut_succ eps 23 (eL 23 (by decide)), cut_succ eps 22 (eL 22 (by decide)), cut_succ eps 21 (eL 21 (by decide)), cut_succ eps 20 (eL 20 (by decide)), cut_succ eps 19 (eL 19 (by decide)), cut_succ eps 18 (eL 18 (by decide)), show (eps[18]'(eL 18 (by decide))).L = liftF (renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint) from rfl, show (eps[19]'(eL 19 (by decide))).L = liftF HalfFieldOB5.copyN from rfl, show (eps[20]'(eL 20 (by decide))).L = liftF StairConcrete.bestLoans.canon from rfl, show (eps[21]'(eL 21 (by decide))).L = StairSchedule.fieldRename FourScratchWindow.unprefix from rfl, show (eps[22]'(eL 22 (by decide))).L = StairSchedule.hostedX from rfl, show (eps[23]'(eL 23 (by decide))).L = StairSchedule.paritySetup from rfl] simp only [liftF_append, List.append_assoc] rw [hc24, WindowFieldJourney.joined, WindowFieldJourney.joined] exact congrArg (run (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup) m2123) htail_eq have h24 : ∃ n24, run odd24 mPre tOdd = run (cut eps 24) n24 tStd := by rw [hodd24_shape, run_append _ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.hostedX ++ StairSchedule.paritySetup), run_append _ (liftF (renameProgram (OB5.sig 511) OddFullPass.CompareDecoderOdd.endPacket760DivOddLoan ++ HalfFieldOB5.copyN ++ OddFullPass.HalfConvertOdd.canon760OddLoan)), run_append _ (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan true 43 100 2)), run_append _ (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram), run_append _ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup), run_append _ (liftF (StairSchedule.forwardLast cp)), run_append _ (liftF (PackCutOdd.cutRowOdd 22 12 490 500 41 98 1)), run_append _ (liftF (PackCutOdd.cutRowOdd 32 22 480 490 36 96 1)), run_append _ (liftF (PackCutOdd.cutRowOdd 47 32 465 480 30 93 2)), run_append _ (liftF (PackCutOdd.cutRowOdd 62 47 450 465 22 90 2)), run_append _ (liftF (PackCutOdd.cutRowOdd 87 62 425 450 13 85 4)), run_append _ (renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup true 1 84))] exact hchain _ _ _ _ _ _ _ _ _ _ _ _ _ (hcut3 _) obtain ⟨n24, hn24⟩ := h24 have hold24 : run (Stair44Kernel.divLead ++ Stair44Kernel.fieldD) n24 tStd = run (cut eps 24) n24 tStd := by rw [WindowStockHead.beforeD F, ← Stair44DivisionCut.selected cp hostPlan] unfold cut exact Stair44HostedCut.entry 24 tStd ⟨F⟩ n24 refine ⟨WindowFieldJourney.joinTapes (Stair44Kernel.divLead ++ Stair44Kernel.fieldD) n24 mPost, ?_⟩ have hsh : stockOddDivHeadCut = odd24 ++ stockOddDivPost := by simp only [stockOddDivHeadCut, odd24, stockOddDivPost, List.append_assoc] have hpost : stockOddDivPost = renameProgram Rolling1588Lifetime.phaseHost Stair44Outer.reverseEnd := rfl have hmPre : m.take (measurementCount odd24) = mPre := rfl have hmPost : m.drop (measurementCount odd24) = mPost := rfl rw [hsh, run_append, hmPre, hmPost, hpost, WindowMiddleContract.oldDivHead, WindowFieldJourney.joined, hold24, ← hn24] end ECDSAAdd.Entrant.OddStockLockstep end end /-! ## PACK-CUT odd exit: the last packet's letters before its closing `ep`, and the row cut (late) -/ section set_option autoImplicit false set_option maxRecDepth 20000 set_option maxHeartbeats 4000000 namespace ECDSAAdd.Entrant.PackCutOddExit open ECDSAAdd Arithmetic MappedCompressed Secp256k1 BalancedField /-- The odd exit packet head takes the packet's A-code frame to the stage-2 code frame followed by `twist`. -/ theorem oddHeadF_frame (d j : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (hj : j < 102) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400) = true) (X Y : Fp) : Rolling1588.StateTriple (RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (Rolling1588.codeEncodeAt false (History5.historyMap base (5 * j))) origin X Y) (oddHeadF d j) (fun state => ∃ X' Y' : Fp, RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (Rolling1588.stageCodeAt false 2 (History5.historyMap base (5 * j)) ++ Rolling1588.onPacket j ParityCodec5New.twist) origin X' Y' state) := by have hlaw := OddFullPassBridge.half760OddLoan_law d false hd h42 have hsup := OddFullPassBridge.half760OddLoan_support d false hd h42 let Frame (k : Nat) (V : Fp × Fp) := RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (Rolling1588.stageCodeAt false k (History5.historyMap base (5 * j))) origin V.1 V.2 have opening (V : Fp × Fp) : Rolling1588.StateTriple (RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (Rolling1588.codeEncodeAt false (History5.historyMap base (5 * j))) origin V.1 V.2) (Rolling1588.onPacket j Rolling1588.stageOpen) (Frame 0 V) := fun s r h => RouteA.Rolling1588.regular_open_frame P1Life.oddWord P1Life.oddWord false j hj origin ctx V.1 V.2 s r h have step (k logical physical : Nat) (hk : k < 3) (used : (logical, physical) ∈ Rolling1588.activeSlots false k) (V : Fp × Fp) : ∃ W : Fp × Fp, Rolling1588.StateTriple (Frame k V) (RouteA.Rolling1588.cellWith false (OddFullPass.P1LifeLoan.half760OddLoan d false) j physical 2) (Frame k W) := ⟨_, fun s r h => RouteA.Rolling1588.regular_cellWith_frame (OddFullPass.P1LifeLoan.half760OddLoan d false) false P1Life.oddWord P1Life.oddWord hlaw hsup j k logical physical hj hk used origin ctx enabled V.1 V.2 s r h⟩ have transfer (k : Nat) (hk : k < 2) (V : Fp × Fp) : Rolling1588.StateTriple (Frame k V) (Rolling1588.onPacket j (Rolling1588.stageTransition false k)) (Frame (k + 1) V) := fun s r h => RouteA.Rolling1588.regular_transition_frame P1Life.oddWord P1Life.oddWord false j k hj hk origin ctx V.1 V.2 s r h obtain ⟨V1, s1⟩ := step 0 4 4 (by decide) (by decide) (X, Y) obtain ⟨V2, s2⟩ := step 1 3 3 (by decide) (by decide) V1 obtain ⟨V3, s3⟩ := step 1 2 4 (by decide) (by decide) V2 obtain ⟨V4, s4⟩ := step 2 1 4 (by decide) (by decide) V3 obtain ⟨V5, s5⟩ := step 2 0 3 (by decide) (by decide) V4 have result := (opening (X, Y)).seq (s1.seq ((transfer 0 (by decide) V1).seq (s2.seq (s3.seq ((transfer 1 (by decide) V3).seq (s4.seq (s5.seq (twist_frame j _ origin V5.1 V5.2)))))))) have hprog : Rolling1588.onPacket j Rolling1588.stageOpen ++ (RouteA.Rolling1588.cellWith false (OddFullPass.P1LifeLoan.half760OddLoan d false) j 4 2 ++ (Rolling1588.onPacket j (Rolling1588.stageTransition false 0) ++ (RouteA.Rolling1588.cellWith false (OddFullPass.P1LifeLoan.half760OddLoan d false) j 3 2 ++ (RouteA.Rolling1588.cellWith false (OddFullPass.P1LifeLoan.half760OddLoan d false) j 4 2 ++ (Rolling1588.onPacket j (Rolling1588.stageTransition false 1) ++ (RouteA.Rolling1588.cellWith false (OddFullPass.P1LifeLoan.half760OddLoan d false) j 4 2 ++ (RouteA.Rolling1588.cellWith false (OddFullPass.P1LifeLoan.half760OddLoan d false) j 3 2 ++ Rolling1588.onPacket j ParityCodec5New.twist))))))) = oddHeadF d j := by simp only [oddHeadF, Rolling1588.stageOpen, Rolling1588.stageTransition, Rolling1588.onPacket, PackCutShape.rename_app, List.append_assoc, if_true, if_false, Bool.false_eq_true, show ¬(1 : Nat) = 0 from by decide] intro state records input have r := result state records input rw [hprog] at r exact ⟨r.1, V5.1, V5.2, r.2⟩ attribute [local irreducible] run measurementCount wires renameProgram theorem head_sub (d j : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) : wires (oddHeadF d j) ⊆ wires (Rolling1588.basePacket false j) := by have hfull : wires (OddFullPass.P1LifeLoan.basePacket false d j) ⊆ wires (Rolling1588.basePacket false j) := by have hp := OddFullPass.P1LifeLoan.packet_wires_sub false d j hd h42 have hps := StairLoanGroupSupport.packet_sub false d j (by omega) have hcomb := hp.trans hps rw [OddFullPass.P1LifeLoan.packet, StairGroups.packet_zero, Rolling1588.packet, renameProgram_support, renameProgram_support] at hcomb intro q hq obtain ⟨v, hv, eq⟩ := Finset.mem_image.mp (hcomb (Finset.mem_image.mpr ⟨q, hq, rfl⟩)) exact (Equiv.injective _ eq) ▸ hv rw [basePacket_false_tail, wires_append] at hfull exact Finset.subset_union_left.trans hfull theorem mem_single (w : Wire) : w ∈ wires [Instr.X w] := by simp [wires, Instr.wires] theorem single_sub (w : Wire) (S : Finset Wire) (h : w ∈ S) : wires [Instr.X w] ⊆ S := by intro q hq have : q = w := by simpa [wires, Instr.wires] using hq subst this exact h open MeasuredCodec5 PackCutExit PackCutExitCut in set_option maxRecDepth 20000 in /-- On an odd record cut frame at `j + 1`, after the odd head of packet `j` (all but its closing `ep`), the packet's ten letters are the shortened encode of a legal word. -/ theorem oddHeadF_cut_bits (d j : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (hj1 : 1 ≤ j) (hj : j < 102) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400) = true) (X Y : Fp) (hF : ∀ i : Fin 10, History5.historyMap base (5 * j) i ∈ NewHistory5.groupReadSites base (base 2400) (base 2409) (base 2410) (5 * j)) (state : State) (records : List Bool) (input : RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (j + 1) origin X Y state) : ∃ x, x < 1024 ∧ legalNat x = true ∧ ∀ i : Fin 10, (run (oddHeadF d j) records state).basis (History5.historyMap base (5 * j) i) = (bitRun E138x x).testBit i := by have nonzero : j ≠ 0 := by omega obtain ⟨raw, rawPhase, rawFrame, encoded⟩ := input let current := run (Rolling1588.encodeGroup base (decide (j + 1 ≤ j)) j) [] raw have currentPhase := Rolling1588.encodeGroup_zero_phase base (decide (j + 1 ≤ j)) base_pool_nodup j (by omega) raw have cf : RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (Rolling1588.encodeGroup base (decide (j + 1 ≤ j)) j) origin X Y current := ⟨raw, currentPhase.symm, rawFrame, rfl⟩ have normalized : RouteA.Rolling1588.CodeFrame P1Life.oddWord P1Life.oddWord (Rolling1588.codeEncodeAt false (History5.historyMap base (5 * j))) origin X Y current := by simpa [Rolling1588.encodeGroup, nonzero, show ¬j + 1 ≤ j from by omega] using cf have res := oddHeadF_frame d j hd h42 hj origin ctx enabled X Y current records normalized obtain ⟨X', Y', raw', _, pf', enc'⟩ := res.2 have legal' : MeasuredCodec5.legalAt (History5.historyMap base (5 * j)) raw'.basis := RouteA.Rolling1588.route_raw_current_legal P1Life.oddWord P1Life.oddWord j hj origin ctx X' Y' raw' pf' have hsup := (head_sub d j hd h42).trans (Rolling1588.basePacket_read_support false j hj) have disj := Rolling1588.otherEncodeCut_body_disjoint (j + 1) j hj origin ctx _ hsup have factor := Rolling1588.allEncodeCut_factor base (j + 1) base_pool_nodup 102 j (by decide) hj raw have actual : run (oddHeadF d j) records state = run (Rolling1588.otherEncodeCut base (j + 1) j 102) [] (run (oddHeadF d j) records current) := by rw [encoded, factor] exact (Arithmetic.run_disjoint_commute (Rolling1588.otherEncodeCut base (j + 1) j 102) (oddHeadF d j) disj [] records current).symm have hFo : ∀ i : Fin 10, History5.historyMap base (5 * j) i ∉ wires (Rolling1588.otherEncodeCut base (j + 1) j 102) := by intro i hi have body := Rolling1588.otherEncodeCut_body_disjoint (j + 1) j hj origin ctx [Instr.X (History5.historyMap base (5 * j) i)] (single_sub _ _ (Finset.mem_union_left _ (hF i))) exact Finset.disjoint_left.mp body hi (mem_single _) have inj := History5.historyMap_injective base base_pool_nodup (5 * j) (by omega) obtain ⟨x, hx, lx, hb⟩ := placed_E138x_bits (History5.historyMap base (5 * j)) inj raw' legal' refine ⟨x, hx, lx, fun i => ?_⟩ rw [actual, run_preserves_outside _ [] _ _ (hFo i), enc', stage_twist_eq] exact hb i theorem shifted_oddHead_bits (d j : Nat) (hj : j < 102) (s : State) (m : List Bool) (hz : ∀ q, Placement5.zeroRegion q → s.basis (base q) = false) (hfixF : ∀ i : Fin 10, Placement5.pi j (History5.historyId (5 * j) i) = History5.historyId (5 * j) i) (i : Fin 10) : (run (renameProgram (shifted (Placement5.pi j)) (oddHeadF d j)) m s).basis (History5.historyMap base (5 * j) i) = (run (oddHeadF d j) m s).basis (History5.historyMap base (5 * j) i) := by have h := run_rename (shifted (Placement5.pi j)) (shifted (Placement5.pi j)).injective (oddHeadF d j) m s rw [Placement5.shifted_zero_boundary (Placement5.pi j) (fun q hq => Placement5.pi_outside j q hj hq) s hz] at h have e := congrArg (fun st : State => st.basis (History5.historyMap base (5 * j) i)) h simp only [pullState] at e have hfix : shifted (Placement5.pi j) (History5.historyMap base (5 * j) i) = History5.historyMap base (5 * j) i := by show shifted (Placement5.pi j) (base (History5.historyId (5 * j) i)) = base (History5.historyId (5 * j) i) rw [shifted_base, hfixF i] rw [hfix] at e exact e open MeasuredCodec5 PackCutExit in set_option maxRecDepth 20000 in /-- The odd exit group of packets `first .. first + c` without its last closing `ep`, on the odd record cut frame at `first + c + 1`: the last packet's letters are the shortened encode of a legal word. -/ theorem oddGroup_head_bits (d first c : Nat) (hd : d ≤ 43) (h42 : d ≠ 42) (h1 : 1 ≤ first) (hb : first + c + 1 ≤ 102) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (enabled : origin (base 2400) = true) (X Y : Fp) (hF : ∀ i : Fin 10, History5.historyMap base (5 * first) i ∈ NewHistory5.groupReadSites base (base 2400) (base 2409) (base 2410) (5 * first)) (hfixF : ∀ i : Fin 10, Placement5.pi first (History5.historyId (5 * first) i) = History5.historyId (5 * first) i) (s : State) (m : List Bool) (input : RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (first + c + 1) origin X Y s) : ∃ x, x < 1024 ∧ legalNat x = true ∧ ∀ i : Fin 10, (run (OddFullPass.P1LifeLoan.groups false d (first + 1) c ++ renameProgram (shifted (Placement5.pi first)) (oddHeadF d first)) m s).basis (History5.historyMap base (5 * first) i) = (bitRun E138x x).testBit i := by have gf := OddFullPassBridge.groups_oddLoan_cut_frame d false hd h42 (first + 1) c (by omega) (by omega) origin ctx enabled X Y have inp : RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (if false = true then first + 1 else first + 1 + c) origin X Y s := by simpa [show first + 1 + c = first + c + 1 by omega] using input have r := gf s (m.take (measurementCount (OddFullPass.P1LifeLoan.groups false d (first + 1) c))) inp set s2 := run (OddFullPass.P1LifeLoan.groups false d (first + 1) c) (m.take (measurementCount (OddFullPass.P1LifeLoan.groups false d (first + 1) c))) s with hs2 have f2 : RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (first + 1) origin (Replay5.groupsPayload false origin (first + 1) c (X, Y)).1 (Replay5.groupsPayload false origin (first + 1) c (X, Y)).2 s2 := by have r2 := r.2 simp only [Bool.false_eq_true, if_false] at r2 exact r2 have hz := RouteA.Rolling1588.cutFrame_zero_region P1Life.oddWord P1Life.oddWord (first + 1) origin ctx _ _ s2 f2 obtain ⟨x, hx, lx, hbits⟩ := oddHeadF_cut_bits d first hd h42 h1 (by omega) origin ctx enabled (Replay5.groupsPayload false origin (first + 1) c (X, Y)).1 (Replay5.groupsPayload false origin (first + 1) c (X, Y)).2 hF s2 (m.drop (measurementCount (OddFullPass.P1LifeLoan.groups false d (first + 1) c))) f2 refine ⟨x, hx, lx, fun i => ?_⟩ rw [run_append, ← hs2, shifted_oddHead_bits d first (by omega) s2 _ hz hfixF i] exact hbits i end ECDSAAdd.Entrant.PackCutOddExit namespace ECDSAAdd.Entrant.PackCutOddExit open ECDSAAdd Arithmetic RecordedQuantum Challenge MappedCompressed Secp256k1 BalancedField open StairConcreteAssembly StairHostsSchedule StairField2V3Seg StairField2V3Replay open StairField2V3Delta StairField2V3Couple StairField2V3Entry StairField2V3RecScratch StairField2V3ExitRec open StairField2V3LastRecX StairField2V3EntryPlanR StairField2V3ExitPlanR open StairField13V3 StairField13V3Clean StairOuterPlacement StairPhysicalLayout open StairLoanExitReachX StairPacket OddStockLockstep attribute [local irreducible] run measurementCount wires renameProgram open MeasuredCodec5 PackCutExit in set_option maxRecDepth 30000 in /-- Odd exit row bits: on the odd lockstep relation at the group's start (the hypotheses of `odd_hostedGroup_step`), after the hosted odd group without its last closing `ep`, the last packet's ten letters (at `Fs`) are the shortened encode of a legal word. -/ theorem oddRow_bits (def_ first c B x : Nat) (hdef : def_ ≤ 43) (h42 : def_ ≠ 42) (h1 : 1 ≤ first) (hb : first + c + 1 ≤ 102) (hB_mem : B = 0 ∨ B ∈ budgets) (havoid_payload : B ≠ 0 → ∀ q ∈ futurePayload B, q ∉ wires (renameProgram (OB5.sig 511) (Rolling1588.groups false first (c + 1)))) (a b record : State) (m : List Bool) (hrel : OddRel P1Life.oddWord P1Life.oddWord a b) (hframe : FrameAt x (first + (c + 1)) record) (hagree : if B = 0 then b = record else AgreeOutside (Δv B) b record) (hcleanIn : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group false def_ first (c + 1)).map lowMap, b.basis q = false) (hhosts_notRY : ∀ q ∈ hostPlan.group false def_ first (c + 1), q ∉ ryWires) (Fs : Fin 10 → Wire) (hsig : ∀ i, OB5.sig 511 (History5.historyMap base (5 * first) i) = Fs i) (hRH : ∀ i, Fs i ∉ StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group false def_ first (c + 1)) (hOff : ∀ i, Off (Fs i)) (hfp : ∀ i, B ≠ 0 → Fs i ∉ futurePayload B) (hnRY : ∀ i, Fs i ∉ ryWires) (hF : ∀ i : Fin 10, History5.historyMap base (5 * first) i ∈ NewHistory5.groupReadSites base (base 2400) (base 2409) (base 2410) (5 * first)) (hfixF : ∀ i : Fin 10, Placement5.pi first (History5.historyId (5 * first) i) = History5.historyId (5 * first) i) : ∃ x', x' < 1024 ∧ legalNat x' = true ∧ ∀ i : Fin 10, (run (StairLoan.rebindMany (StairSchedule.exclusiveRoles.drop def_) (hostPlan.group false def_ first (c + 1)) (renameProgram (OB5.sig 511) (OddFullPass.P1LifeLoan.groups false def_ (first + 1) c ++ renameProgram (shifted (Placement5.pi first)) (oddHeadF def_ first)))) m (pullIn a)).basis (Fs i) = (bitRun E138x x').testBit i := by let G : Program := OddFullPass.P1LifeLoan.groups false def_ (first + 1) c ++ renameProgram (shifted (Placement5.pi first)) (oddHeadF def_ first) let PG := renameProgram (OB5.sig 511) G let P_odd := renameProgram (OB5.sig 511) (OddFullPass.P1LifeLoan.groups false def_ first (c + 1)) let P_rec := renameProgram (OB5.sig 511) (Rolling1588.groups false first (c + 1)) have hG_sub : wires PG ⊆ wires P_odd := by show wires (renameProgram (OB5.sig 511) G) ⊆ wires (renameProgram (OB5.sig 511) _) rw [oddPlaced_false_tail, wires_append] exact Finset.subset_union_left have hsub_odd : wires P_odd ⊆ wires P_rec := by have h1 : wires (OddFullPass.P1LifeLoan.groups false def_ first (c + 1)) ⊆ wires (StairGroups.groups false def_ first (c + 1)) := StairLoanGroupSupport.sequence_sub _ _ _ (fun k => OddFullPass.P1LifeLoan.packet_wires_sub false def_ k hdef h42) _ _ have h2 := StairLoanGroupSupport.groups_sub false def_ (by omega) first (c + 1) show wires (renameProgram (OB5.sig 511) _) ⊆ wires (renameProgram (OB5.sig 511) _) rw [renameProgram_support, renameProgram_support] exact Finset.image_subset_image (h1.trans h2) have hrec_off : ∀ q ∈ wires P_rec, Off q := StairField2V3ExitRec.groupsF_off first (c + 1) h1 (by omega) obtain ⟨origin, X, Y, s_rec, ctx, en, tr, cut_rec, agree_rec⟩ := hframe have hpb_rec : ∀ q, Off q → (B ≠ 0 → q ∉ futurePayload B) → (pullIn b).basis q = s_rec.basis q := by intro q hq hnp have hbr : (pullIn b).basis q = (pullIn record).basis q := by by_cases hB0 : B = 0 · simp only [hB0, if_true] at hagree; rw [hagree] · simp only [hB0, if_false] at hagree change b.basis (fieldPlace q) = record.basis (fieldPlace q) apply hagree.2 intro hmem simp only [Δv, List.mem_toFinset, List.mem_map] at hmem obtain ⟨r, hr, heq⟩ := hmem have qr : r = q := by have := congrArg fieldPlaceInv heq rwa [inv_fieldPlace, inv_fieldPlace] at this exact hnp hB0 (qr ▸ hr) exact hbr.trans (agree_rec q hq) have hb_vals : regValue fieldR b.basis = centerWord X ∧ regValue fieldY b.basis = centerWord Y := by have hrec_vals := cutFrame_std_values _ origin X Y _ cut_rec rw [pullState_sig511_regValue_R, pullState_sig511_regValue_Y] at hrec_vals have hEq_ry : ∀ q ∈ ryWires, (pullIn b).basis q = s_rec.basis q := by intro q hq apply hpb_rec q (ryWires_off q hq) intro hB0 hfp' rcases hB_mem with rfl | hBm · exact hB0 rfl · exact futurePayload_not_ryWires B hBm q hfp' hq constructor · rw [← pullIn_regValue_R] exact (regValue_congr _ _ _ (fun q hq => hEq_ry q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hrec_vals.1 · rw [← pullIn_regValue_Y] exact (regValue_congr _ _ _ (fun q hq => hEq_ry q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hrec_vals.2 have ha_vals : regValue fieldR a.basis = P1Life.oddWord X ∧ regValue fieldY a.basis = P1Life.oddWord Y := ⟨hrel.2.1 X hb_vals.1, hrel.2.2 Y hb_vals.2⟩ let s_odd : State := spliceRY (pullIn a) s_rec have hcut_odd : RouteA.Rolling1588.CutFrame P1Life.oddWord P1Life.oddWord (first + (c + 1)) origin X Y (pullState (OB5.sig 511) s_odd) := cutFrame_spliceRY P1Life.oddWord P1Life.oddWord _ origin X Y (pullIn a) s_rec cut_rec (by rw [pullIn_regValue_R]; exact ha_vals.1) (by rw [pullIn_regValue_Y]; exact ha_vals.2) have hpa_sodd : ∀ q ∈ wires PG, (pullIn a).basis q = s_odd.basis q := by intro q hq by_cases hry : q ∈ ryWires · simp only [s_odd, spliceRY, hry, if_true] · simp only [s_odd, spliceRY, hry, if_false] have hq' := hsub_odd (hG_sub hq) have h1' := (pullIn_agreeRY hrel.1).2 q hry have h2' := hpb_rec q (hrec_off q hq') (fun hB0 hfp' => havoid_payload hB0 q hfp' hq') exact h1'.trans h2' have hinc := Arithmetic.run_local_increment PG (pullIn a) s_odd m hpa_sodd -- the hosted roles / hosts are zero on `pullIn a` have hclean_a_in : ∀ q ∈ StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group false def_ first (c + 1), (pullIn a).basis q = false := by intro q hq have hnot : q ∉ ryWires := by rcases List.mem_append.mp hq with hr | hh · exact exclusiveRoles_not_ryWires q (List.mem_of_mem_drop hr) · exact hhosts_notRY q hh have h1' := (pullIn_agreeRY hrel.1).2 q hnot have h2' : (pullIn b).basis q = false := hcleanIn (lowMap q) (List.mem_map.mpr ⟨q, hq, rfl⟩) exact h1'.trans h2' -- the record-frame bits on the spliced state obtain ⟨x', hx', lx', hbits⟩ := oddGroup_head_bits def_ first c hdef h42 h1 hb origin ctx en X Y hF hfixF (pullState (OB5.sig 511) s_odd) m hcut_odd refine ⟨x', hx', lx', fun i => ?_⟩ rw [PackCutExitTransport.hosted_bits _ _ _ m (pullIn a) hclean_a_in (Fs i) (hRH i)] have step1 : (run PG m (pullIn a)).basis (Fs i) = (run PG m s_odd).basis (Fs i) := by by_cases hw : Fs i ∈ wires PG · exact hinc.2 _ hw · rw [run_preserves_outside _ m _ _ hw, run_preserves_outside _ m _ _ hw] simp only [s_odd, spliceRY, hnRY i, if_false] exact ((pullIn_agreeRY hrel.1).2 _ (hnRY i)).trans (hpb_rec _ (hOff i) (hfp i)) show (run PG m (pullIn a)).basis (Fs i) = _ rw [step1] have e := ECDSAAdd.run_rename (OB5.sig 511) (OB5.sig_injective 511 (le_refl _)) G m s_odd have e2 := congrArg (fun st : State => st.basis (History5.historyMap base (5 * first) i)) e simp only [pullState] at e2 rw [← hsig i, e2] exact hbits i end ECDSAAdd.Entrant.PackCutOddExit namespace ECDSAAdd.Entrant.PackCutOddExit open ECDSAAdd Arithmetic MappedCompressed open StairConcreteAssembly StairPhysicalLayout StairField2V3RecScratch OddStockLockstep attribute [local irreducible] run measurementCount wires renameProgram open MeasuredCodec5 PackCutExit in set_option maxRecDepth 30000 in /-- PACK-CUT odd exit row: the odd hosted group's last closing `ep` and the next segment's due-read `dp` cancel. -/ theorem oddExit_row_full (def_ first c B x : Nat) (hdef : def_ ≤ 43) (h42 : def_ ≠ 42) (h1 : 1 ≤ first) (hb : first + c + 1 ≤ 102) (hB_mem : B = 0 ∨ B ∈ budgets) (havoid_payload : B ≠ 0 → ∀ q ∈ futurePayload B, q ∉ wires (renameProgram (OB5.sig 511) (Rolling1588.groups false first (c + 1)))) (a b record : State) (hrel : OddRel P1Life.oddWord P1Life.oddWord a b) (hframe : StairField2V3LastRecX.FrameAt x (first + (c + 1)) record) (hagree : if B = 0 then b = record else StairField2V3Replay.AgreeOutside (StairField2V3Delta.Δv B) b record) (hcleanIn : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group false def_ first (c + 1)).map StairField13V3.lowMap, b.basis q = false) (hhosts_notRY : ∀ q ∈ hostPlan.group false def_ first (c + 1), q ∉ ryWires) (Fs : Fin 10 → Wire) (hFinj : Function.Injective Fs) (hsig : ∀ i, OB5.sig 511 (History5.historyMap base (5 * first) i) = Fs i) (hRH : ∀ i, Fs i ∉ StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group false def_ first (c + 1)) (hOff : ∀ i, Off (Fs i)) (hfp : ∀ i, B ≠ 0 → Fs i ∉ futurePayload B) (hnRY : ∀ i, Fs i ∉ ryWires) (hF : ∀ i : Fin 10, History5.historyMap base (5 * first) i ∈ NewHistory5.groupReadSites base (base 2400) (base 2409) (base 2410) (5 * first)) (hfixF : ∀ i : Fin 10, Placement5.pi first (History5.historyId (5 * first) i) = History5.historyId (5 * first) i) (SEG M Bx : Program) (hseg : SEG = M ++ renameProgram (label Fs) Rolling1588.dp ++ Bx) (hM : ∀ q ∈ (Finset.range 10).image (label Fs), q ∉ wires M) (hep : StairLoan.rebindMany (StairSchedule.exclusiveRoles.drop def_) (hostPlan.group false def_ first (c + 1)) (renameProgram (OB5.sig 511) (renameProgram (shifted (Placement5.pi first)) (Rolling1588.onPacket first Rolling1588.ep))) = renameProgram (label Fs) Rolling1588.ep) (m : List Bool) : ∃ m', run (AhOdd def_ first c ++ M ++ Bx) m (StairField2V3Seg.pullIn a) = run (OddFullPass.P1LifeLoan.hostedGroup hostPlan false def_ first (c + 1) ++ SEG) m' (StairField2V3Seg.pullIn a) := by obtain ⟨m', h⟩ := PackCutExitBits.exit_row_cut_bits (AhOdd def_ first c) M _ Bx Fs hFinj rfl hM (StairField2V3Seg.pullIn a) m (fun tA => oddRow_bits def_ first c B x hdef h42 h1 hb hB_mem havoid_payload a b record tA hrel hframe hagree hcleanIn hhosts_notRY Fs hsig hRH hOff hfp hnRY hF hfixF) refine ⟨m', ?_⟩ rw [h, oddHostedGroup_false_tail, hep, hseg] simp only [AhOdd, List.append_assoc] end ECDSAAdd.Entrant.PackCutOddExit namespace ECDSAAdd.Entrant.PackCutOddExit open ECDSAAdd Arithmetic MappedCompressed open StairConcreteAssembly StairPhysicalLayout StairField2V3RecScratch OddStockLockstep StairPacket attribute [local irreducible] run measurementCount wires renameProgram open MeasuredCodec5 PackCutExit in set_option maxRecDepth 30000 in /-- The odd exit row cut in physical (field-placed) coordinates, as the odd lockstep chain runs it. -/ theorem oddCutRow_runeq (def_ first c B x : Nat) (hdef : def_ ≤ 43) (h42 : def_ ≠ 42) (h1 : 1 ≤ first) (hb : first + c + 1 ≤ 102) (hB_mem : B = 0 ∨ B ∈ budgets) (havoid_payload : B ≠ 0 → ∀ q ∈ futurePayload B, q ∉ wires (renameProgram (OB5.sig 511) (Rolling1588.groups false first (c + 1)))) (a b record : State) (hrel : OddRel P1Life.oddWord P1Life.oddWord a b) (hframe : StairField2V3LastRecX.FrameAt x (first + (c + 1)) record) (hagree : if B = 0 then b = record else StairField2V3Replay.AgreeOutside (StairField2V3Delta.Δv B) b record) (hcleanIn : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group false def_ first (c + 1)).map StairField13V3.lowMap, b.basis q = false) (hhosts_notRY : ∀ q ∈ hostPlan.group false def_ first (c + 1), q ∉ ryWires) (Fs : Fin 10 → Wire) (hFinj : Function.Injective Fs) (hsig : ∀ i, OB5.sig 511 (History5.historyMap base (5 * first) i) = Fs i) (hRH : ∀ i, Fs i ∉ StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group false def_ first (c + 1)) (hOff : ∀ i, Off (Fs i)) (hfp : ∀ i, B ≠ 0 → Fs i ∉ futurePayload B) (hnRY : ∀ i, Fs i ∉ ryWires) (hF : ∀ i : Fin 10, History5.historyMap base (5 * first) i ∈ NewHistory5.groupReadSites base (base 2400) (base 2409) (base 2410) (5 * first)) (hfixF : ∀ i : Fin 10, Placement5.pi first (History5.historyId (5 * first) i) = History5.historyId (5 * first) i) (SEG M Bx : Program) (hseg : SEG = M ++ renameProgram (label Fs) Rolling1588.dp ++ Bx) (hM : ∀ q ∈ (Finset.range 10).image (label Fs), q ∉ wires M) (hep : StairLoan.rebindMany (StairSchedule.exclusiveRoles.drop def_) (hostPlan.group false def_ first (c + 1)) (renameProgram (OB5.sig 511) (renameProgram (shifted (Placement5.pi first)) (Rolling1588.onPacket first Rolling1588.ep))) = renameProgram (label Fs) Rolling1588.ep) (m : List Bool) : ∃ m', run (StairField2V3Entry.liftF (AhOdd def_ first c ++ M ++ Bx)) m a = run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan false def_ first (c + 1)) ++ StairField2V3Entry.liftF SEG) m' a := by obtain ⟨m', h⟩ := oddExit_row_full def_ first c B x hdef h42 h1 hb hB_mem havoid_payload a b record hrel hframe hagree hcleanIn hhosts_notRY Fs hFinj hsig hRH hOff hfp hnRY hF hfixF SEG M Bx hseg hM hep m refine ⟨m', ?_⟩ rw [show renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan false def_ first (c + 1)) = StairField2V3Entry.liftF (OddFullPass.P1LifeLoan.hostedGroup hostPlan false def_ first (c + 1)) from (ExteriorPorts.placedShape _).symm, ← StairField13V3Clean.liftF_append, StairField2V3Seg.liftF_run, StairField2V3Seg.liftF_run, h] end ECDSAAdd.Entrant.PackCutOddExit end -- ==== end OddLockstepDiv ==== -- ==== begin OddLockstepMul ==== section set_option autoImplicit false section namespace ECDSAAdd.Entrant.OddStockLockstep open ECDSAAdd Arithmetic RecordedQuantum Challenge MappedCompressed Secp256k1 BalancedField open StairConcreteAssembly StairHostsSchedule StairField2V3Seg StairField2V3Replay open StairField2V3Delta StairField2V3Couple StairField2V3Entry StairField2V3RecScratch StairField2V3ExitRec open StairField2V3LastRecX StairField2V3EntryPlanR StairField2V3ExitPlanR open StairField13V3 StairField13V3Clean StairOuterPlacement StairPhysicalLayout open StairLoanExitReachX StairLoanField7Transport StairPacket set_option maxRecDepth 30000 set_option maxHeartbeats 2000000 set_option linter.unusedSimpArgs false set_option linter.unusedVariables false attribute [local irreducible] run measurementCount wires renameProgram cut private theorem local_eq_of_sub₂ (P Q : Program) (hsub : wires P ⊆ wires Q) (a b : State) (m1 m2 : List Bool) (hag : ∀ q ∈ wires Q, a.basis q = b.basis q) (heq : run P m1 b = run Q m2 b) : run P m1 a = run Q m2 a := by have hp := Arithmetic.run_local_increment P a b m1 (fun q hq => hag q (hsub hq)) have hq := Arithmetic.run_local_increment Q a b m2 hag apply State.extensionality · have hpeq : (run P m1 b).phase = (run Q m2 b).phase := congrArg State.phase heq have h1 : ((run P m1 a).phase ^^ a.phase) = ((run P m1 b).phase ^^ b.phase) := hp.1 have h2 : ((run Q m2 a).phase ^^ a.phase) = ((run P m1 b).phase ^^ b.phase) := by rw [hpeq]; exact hq.1 revert h1 h2 cases (run P m1 a).phase <;> cases (run Q m2 a).phase <;> cases a.phase <;> cases (run P m1 b).phase <;> cases b.phase <;> decide · funext w by_cases h1 : w ∈ wires P · rw [hp.2 w h1, hq.2 w (hsub h1), heq] · rw [run_preserves_outside P m1 a w h1] by_cases h2 : w ∈ wires Q · rw [hq.2 w h2, ← heq, run_preserves_outside P m1 b w h1]; exact hag w h2 · rw [run_preserves_outside Q m2 a w h2] private theorem sig511_511_mul : OB5.sig 511 (base 511) = base 511 := by decide +kernel private theorem regValue_run_disjoint_R_mul (P : Program) (h : ∀ q ∈ wires P, q ∉ fieldR) (m : List Bool) (s : State) : regValue fieldR (run P m s).basis = regValue fieldR s.basis := regValue_congr fieldR (run P m s).basis s.basis (fun q hq => run_preserves_outside P m s q (fun hw => h q hw hq)) private theorem cutLoan_exit_helper {P : Program} {pre : State → Prop} (clean : CutClean pre P ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group false 0 1 84).map lowMap)) (s : State) (h : pre s) (m : List Bool) : ∀ q ∈ StairSchedule.exclusiveRoles ++ hosts 87, (run P m s).basis (fieldPlace q) = false := by intro q hq exact clean s h m _ (by rw [hp_group false 0 1 84 (by decide)]; exact List.mem_map.mpr ⟨q, hq, rfl⟩) private theorem exitFirstBefore_xps (k : Nat) : CutClean (ExitPre k) (cut (xps k) 23) ((StairSchedule.exclusiveRoles ++ hostPlan.firstPacket false).map fieldMap) := (exitClean_v3_inst k).firstBefore private theorem exitFirstRolesAfter_xps (k : Nat) : CutClean (ExitPre k) (cut (xps k) 24) (StairSchedule.exclusiveRoles.map fieldMap) := (exitClean_v3_inst k).firstRolesAfter private theorem exitGroupsBefore_xps (k j def_ start len : Nat) (h : (j, def_, start, len) ∈ [(7, 43, 100, 2), (11, 41, 98, 2), (13, 36, 96, 2), (15, 30, 93, 3), (17, 22, 90, 3), (19, 13, 85, 5), (21, 0, 1, 84)]) : CutClean (ExitPre k) (cut (xps k) j) ((StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group false def_ start len).map lowMap) := (exitClean_v3_inst k).groupsBefore (j, def_, start, len) h private theorem exitGroupsRolesAfter_xps (k j def_ start len : Nat) (h : (j, def_, start, len) ∈ [(7, 43, 100, 2), (11, 41, 98, 2), (13, 36, 96, 2), (15, 30, 93, 3), (17, 22, 90, 3), (19, 13, 85, 5), (21, 0, 1, 84)]) : CutClean (ExitPre k) (cut (xps k) (j + 1)) ((StairSchedule.exclusiveRoles.drop def_).map lowMap) := (exitClean_v3_inst k).groupsRolesAfter (j, def_, start, len) h private theorem fullExitCut21Clean (k : Nat) (parts : StairField13V3Fresh.ExitClean k) : CutClean (ExitPre k) (cut (xps k) 21) ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group false 0 1 84).map lowMap) := parts.groupsBefore (21, 0, 1, 84) (by simp) theorem exitCut21_pin_loan (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : (∃ record, FrameAt F.x 85 record ∧ AgreeOutside (Δv 87) (run (cut (xps k) 21) m s) record) ∧ (∀ q ∈ StairSchedule.exclusiveRoles ++ hosts 87, (run (cut (xps k) 21) m s).basis (fieldPlace q) = false) := by constructor · rw [xcut21, run_append] obtain ⟨Q, link⟩ := rch21 k F.x (StairOpenWiring.exitPlans k F.x) StairOpenWiring.half760 obtain ⟨old, rel, reachable⟩ := link _ _ ⟨⟨s, F, rfl, _, rfl⟩, rfl⟩ _ exact ⟨_, WindowFieldView.exitFrame 85 F.x _ (StairField2V3ExitRec.reach_YE k F.x _ (reachX_E StairOpenWiring.half760 k F.x _ reachable)), rel.1⟩ · exact cutLoan_exit_helper (fullExitCut21Clean k (exitClean_v3_inst k)) s ⟨F⟩ m theorem outMap_symm_fix_fieldR : ∀ q ∈ fieldR, Stair44Kernel.outMap.symm q = q := fun q hq => by have h := outMap_fix_fieldR q hq have h2 := congrArg Stair44Kernel.outMap.symm h rw [Equiv.symm_apply_apply] at h2 exact h2.symm private theorem regValue_pull_put_eq_R (f : Wire → Wire) (hfix : ∀ q ∈ fieldR, f q = q) (rk : State) (p : Wire) (hp : p ∉ fieldR) (b : Bool) : regValue fieldR (pullState f (ParityEven.put rk p b)).basis = regValue fieldR rk.basis := by apply regValue_congr fieldR _ rk.basis intro q hq change (ParityEven.put rk p b).basis (f q) = rk.basis q rw [hfix q hq] have hne : q ≠ p := fun e => hp (e ▸ hq) simp only [ParityEven.put, writeBit, Function.update_of_ne hne] /-! ## Section 5: Multiplication stock lockstep (`stockOddMulPrefix21`, `stockOddMulHead`) -/ def stockOddMulBeforeParity : Program := StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.exitLowPrefixOdd hostPlan) def stockOddMulBeforeGroup : Program := StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram ++ StairSchedule.fieldRename (renameProgram Prefix1590.borrow (StairSchedule.reverseLast cp ++ PackCutOddExit.cutRowOddPk 22 12 490 500 41 98 1 ++ PackCutOddExit.cutRowOddPk 32 22 480 490 36 96 1 ++ PackCutOddExit.cutRowOddPk 47 32 465 480 30 93 2 ++ PackCutOddExit.cutRowOddPk 62 47 450 465 22 90 2 ++ PackCutOddExit.cutRowOddPk 87 62 425 450 13 85 4)) def stockOddMulLeading : Program := StairSchedule.paritySetup ++ stockOddMulBeforeParity ++ StairSchedule.paritySetup ++ stockOddMulBeforeGroup def stockOddMulPrefix21 : Program := StairField2V3Replay.exitReferenceOpening ++ stockOddMulLeading def stockOddMulAfterGroup : Program := StairSchedule.fieldRename (FourScratchWindow.unprefix ++ JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf false) def stockOddMulHead : Program := (((Stair44Kernel.mulLead ++ stockOddMulLeading) ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup false 1 84)) ++ stockOddMulAfterGroup) ++ renameProgram Rolling1588Lifetime.phaseHost checkpointPrimitives.firstUnpack /-- Explicit cut-21 lockstep for Multiplication: `stockOddMulPrefix21` vs `cut (xps k) 21` with `OddRel` and `OCut 85`! -/ theorem stockOddMul_cut21 (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : let a21 := run stockOddMulPrefix21 m s (∃ n, OddRel P1Life.oddWord P1Life.oddWord a21 (run (cut (xps k) 21) n s)) ∧ (∃ origin, FrontierReplay1591.Context origin ∧ origin (base 2400) = true ∧ TraceOK F.x origin ∧ WindowFieldView.OCut 85 origin (pullIn a21)) := by intro a21 -- Define `MulCut j a b := (∃ u, b = run (cut (xps k) j) u s) ∧ OddRel oddWord oddWord a b` let MulCut (j : Nat) (a b : State) : Prop := (∃ u, b = run (cut (xps k) j) u s) ∧ OddRel P1Life.oddWord P1Life.oddWord a b have step_disj (j : Nat) (hj : j < 25) (P : Program) (hP : ((xps k)[j]'(xL k j hj)).L = P) (hnot : ∀ q ∈ wires P, q ∉ ryWires) : ∀ a b m', MulCut j a b → MulCut (j + 1) (run P m' a) (run P m' b) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ refine ⟨⟨WindowFieldJourney.joinTapes (cut (xps k) j) u m', ?_⟩, oddRel_disjoint P hnot hrel m'⟩ rw [cut_succ (xps k) j (xL k j hj), hP, WindowFieldJourney.joined] have step_grp (j B def_ start len : Nat) (hj : j < 25) (hL : ((xps k)[j]'(xL k j hj)).L = grpFL StairConcrete.bestLoans def_ start len) (hB : B = 0 ∨ B ∈ budgets) (hstartB : B ≠ 0 → start + len ≤ startFor B / 5) (hd : def_ ≤ 43) (h42 : def_ ≠ 42) (h1 : 1 ≤ start) (hb : start + len ≤ 102) (hmem : (j, def_, start, len) ∈ [(7, 43, 100, 2), (11, 41, 98, 2), (13, 36, 96, 2), (15, 30, 93, 3), (17, 22, 90, 3), (19, 13, 85, 5), (21, 0, 1, 84)]) (hsched : def_ = 43 ∨ (def_, start, len) ∈ [(0, 1, 84), (13, 85, 5), (22, 90, 3), (30, 93, 3), (36, 96, 2), (41, 98, 2)]) (hpin : ∀ u, ∃ rec, FrameAt F.x (start + len) rec ∧ (if B = 0 then run (cut (xps k) j) u s = rec else AgreeOutside (Δv B) (run (cut (xps k) j) u s) rec)) : ∀ a b m', MulCut j a b → MulCut (j + 1) (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan false def_ start len)) m' a) (run (grpFL StairConcrete.bestLoans def_ start len) m' b) := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨rec, hframe, hagree⟩ := hpin u have hclIn : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_ ++ hostPlan.group false def_ start len).map lowMap, (run (cut (xps k) j) u s).basis q = false := exitGroupsBefore_xps k j def_ start len hmem s ⟨F⟩ u have hclOut : ∀ q ∈ (StairSchedule.exclusiveRoles.drop def_).map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups false def_ start len))) m' (run (cut (xps k) j) u s)).basis q = false := cleanCut_after (exitGroupsRolesAfter_xps k j def_ start len hmem) (by rw [cut_succ (xps k) j (xL k j hj), hL]; rfl) s ⟨F⟩ u m' have havoid : B ≠ 0 → ∀ q ∈ futurePayload B, q ∉ wires (renameProgram (OB5.sig 511) (Rolling1588.groups false start len)) := by intro hne rcases hB with rfl | hBm · exact absurd rfl hne · exact StairField2V3Groups.groups_avoid_payload false B hBm len start (by have := hstartB hne; omega) have hstep := odd_hostedGroup_step false def_ start len B F.x hd h42 h1 hb hB havoid a (run (cut (xps k) j) u s) rec m' hrel hframe hagree hclIn hclOut (hostPlan_group_notRY false def_ start len (by omega)) (hostPlan_group_fresh_odd false def_ start len hd h42 h1 hb hsched) have hgrpFL_eq : grpFL StairConcrete.bestLoans def_ start len = liftF (renameProgram (OB5.sig 511) (StairGroups.groups false def_ start len)) := rfl rw [← hgrpFL_eq] at hstep refine ⟨⟨WindowFieldJourney.joinTapes (cut (xps k) j) u m', ?_⟩, hstep⟩ rw [cut_succ (xps k) j (xL k j hj), hL, WindowFieldJourney.joined] -- Pieces 0–6: pieces 0–3 identical on `s`, then pieces 4–6 via `mulHeadCore_step`! have hcut7 (m7 : List Bool) : let P03 := StairField2V3Replay.exitReferenceOpening ++ StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram let CoreOdd := liftF (OddFullPass.HalfConvertOdd.center760OddLoan ++ HalfFieldOB5.copyN ++ renameProgram (OB5.sig 511) OddFullPass.InverseTailCOdd.endPacket760OddLoan44) MulCut 7 (run (P03 ++ CoreOdd) m7 s) (run (cut (xps k) 7) m7 s) := by intro P03 CoreOdd have hcut4 : cut (xps k) 4 = P03 := by rw [cut_succ (xps k) 3 (xL k 3 (by decide)), cut_succ (xps k) 2 (xL k 2 (by decide)), cut_succ (xps k) 1 (xL k 1 (by decide)), cut_succ (xps k) 0 (xL k 0 (by decide)), cut_zero, x0_L, x1_L, x2_L, x3_L] simp only [P03, List.nil_append, List.append_assoc] have hcut7_eq : cut (xps k) 7 = P03 ++ liftF (StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN ++ StairSchedule.placedEndPacket StairConcrete.bestLoans false 68) := by rw [cut_succ (xps k) 6 (xL k 6 (by decide)), cut_succ (xps k) 5 (xL k 5 (by decide)), cut_succ (xps k) 4 (xL k 4 (by decide)), hcut4, x4_L, x5_L, x6_L] simp only [liftF_append, List.append_assoc] let m0 := m7.take (measurementCount P03) let m1 := m7.drop (measurementCount P03) let b4 := run P03 m0 s let mOpen := m0.take (measurementCount StairField2V3Replay.exitReferenceOpening) let mRest := m0.drop (measurementCount StairField2V3Replay.exitReferenceOpening) have hopen : run StairField2V3Replay.exitReferenceOpening mOpen s = run (Rolling1588.firstPhase false) mOpen s := first_phase_hosted false F.sharedNodup F.historyAbove F.x F.Y.val F.x_pos F.x_lt s mOpen F.input obtain ⟨orig, facts, legal, frames⟩ := Rolling1588Lifetime.first_prepared F.sharedNodup F.historyAbove F.selectorsAway F.x F.Y F.x_pos F.x_lt s mOpen F.input have ctx := Rolling1588Lifetime.prepared_context F.sharedNodup F.selectorsAway F.transcript F.x F.Y s orig facts legal F.selectorG_zero F.selectorS_zero have bits := Rolling1588Lifetime.first_clean false F.sharedNodup F.historyAbove F.x F.Y.val F.x_pos F.x_lt s mOpen F.input have work := Rolling1588Lifetime.first_work_zero false F.sharedNodup F.x F.Y.val s mOpen F.input have parity := Rolling1588Lifetime.first_parity false F.sharedNodup F.historyAbove F.x F.Y.val F.x_pos F.x_lt s mOpen F.input have input := frames false rw [lf_eq] at input bits work parity obtain ⟨v, hv⟩ : ∃ v : State, run (Rolling1588.firstPhase false) mOpen s = v := ⟨_, rfl⟩ rw [hv] at input bits work parity have code := Rolling1588Frame.canonical_special_at orig.basis F.Y 0 v 511 (by simp) input have in511 : v.basis (base 511) = true := (by rw [sig511_511_mul] at code; exact code : v.basis (base 511) = orig.basis (base 511)).trans (trace_last F.x F.x_pos F.x_lt orig.basis facts.trace) have in1542 : v.basis (base 1542) = false := bits _ (by simp [FrontierEntry1591Native.workSites]) have flags := canonical_flags orig.basis ctx F.Y 0 v input let origin' := writeBit orig.basis (base 2400) true have ctx' := FrontierEntry1591.context_control_set orig.basis ctx true have ha' := FrontierEntry1591.source_zero_control_set orig.basis true facts.sourceZero have trace' : skywalkTapeControls origin' (skywalkSharedTape base) = SkywalkTrace.trace 512 (SkywalkRails.encode false false (F.x : Int) (p : Int)) := by rw [FrontierEntry1591.trace_control_set]; exact facts.trace have input' := Rolling1588.canonical_control_set orig.basis F.Y 0 v true input have en' : origin' (base 2400) = true := by simp [origin', writeBit] have codes := Rolling1588.canonical_prefix_codes origin' ctx' F.Y 0 (force v) input' F.x F.x_pos F.x_lt trace' have clean := FourScratchWindow.canonical_clean origin' ctx' ha' F.Y (force v) input' codes.1 codes.2.1 have z768 := Rolling1588.canonical_768_zero origin' ctx' F.Y 0 (force v) input' have hpb_fv : ∀ q, Off q → (pullIn b4).basis q = (force v).basis q := by intro q hq have hb4_eq : b4 = run (StairSchedule.fieldRename FourScratchWindow.clearProgram) (mRest.drop (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX))) (run (StairSchedule.paritySetup ++ StairSchedule.hostedX) (mRest.take (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX))) v) := by have hsh : P03 = StairField2V3Replay.exitReferenceOpening ++ ((StairSchedule.paritySetup ++ StairSchedule.hostedX) ++ StairSchedule.fieldRename FourScratchWindow.clearProgram) := by simp only [P03, List.append_assoc] dsimp only [b4]; rw [hsh, run_append, run_append, hopen, hv] rw [hb4_eq, field_pullIn] exact window_agree _ (force v) _ (hosted_agree_force v flags.1 in511 flags.2 in1542 work parity _) clean codes.2.2 z768 q hq.1 hq.2 have hcore := mulHeadCore_step origin' ctx' ha' en' F.Y b4 (force v) m1 input' hpb_fv refine ⟨⟨m7, rfl⟩, ?_⟩ rw [hcut7_eq, run_append P03, run_append P03] exact hcore -- Pin helpers for pieces 7, 11, 13, 15, 17, 19 have pin7 : ∀ u, ∃ rec, FrameAt F.x 102 rec ∧ (if (0 : Nat) = 0 then run (cut (xps k) 7) u s = rec else AgreeOutside (Δv 0) (run (cut (xps k) 7) u s) rec) := by intro u have hcut4 : cut (xps k) 7 = StairField2V3Replay.exitReferenceOpening ++ ((StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram) ++ liftF (StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN ++ StairSchedule.placedEndPacket StairConcrete.bestLoans false 68)) := by rw [cut_succ (xps k) 6 (xL k 6 (by decide)), cut_succ (xps k) 5 (xL k 5 (by decide)), cut_succ (xps k) 4 (xL k 4 (by decide)), cut_succ (xps k) 3 (xL k 3 (by decide)), cut_succ (xps k) 2 (xL k 2 (by decide)), cut_succ (xps k) 1 (xL k 1 (by decide)), cut_succ (xps k) 0 (xL k 0 (by decide)), cut_zero, x0_L, x1_L, x2_L, x3_L, x4_L, x5_L, x6_L] simp only [liftF_append, List.nil_append, List.append_assoc] let mOpen := u.take (measurementCount StairField2V3Replay.exitReferenceOpening) let mTail := u.drop (measurementCount StairField2V3Replay.exitReferenceOpening) let mA := mTail.take (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram)) let mB := mTail.drop (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram)) have hopen : run StairField2V3Replay.exitReferenceOpening mOpen s = run (Rolling1588.firstPhase false) mOpen s := first_phase_hosted false F.sharedNodup F.historyAbove F.x F.Y.val F.x_pos F.x_lt s mOpen F.input obtain ⟨orig, facts, legal, frames⟩ := Rolling1588Lifetime.first_prepared F.sharedNodup F.historyAbove F.selectorsAway F.x F.Y F.x_pos F.x_lt s mOpen F.input have ctx := Rolling1588Lifetime.prepared_context F.sharedNodup F.selectorsAway F.transcript F.x F.Y s orig facts legal F.selectorG_zero F.selectorS_zero have bits := Rolling1588Lifetime.first_clean false F.sharedNodup F.historyAbove F.x F.Y.val F.x_pos F.x_lt s mOpen F.input have work := Rolling1588Lifetime.first_work_zero false F.sharedNodup F.x F.Y.val s mOpen F.input have parity := Rolling1588Lifetime.first_parity false F.sharedNodup F.historyAbove F.x F.Y.val F.x_pos F.x_lt s mOpen F.input have input := frames false rw [lf_eq] at input bits work parity obtain ⟨v, hv⟩ : ∃ v : State, run (Rolling1588.firstPhase false) mOpen s = v := ⟨_, rfl⟩ rw [hv] at input bits work parity have code := Rolling1588Frame.canonical_special_at orig.basis F.Y 0 v 511 (by simp) input have in511 : v.basis (base 511) = true := (by rw [sig511_511_mul] at code; exact code : v.basis (base 511) = orig.basis (base 511)).trans (trace_last F.x F.x_pos F.x_lt orig.basis facts.trace) have in1542 : v.basis (base 1542) = false := bits _ (by simp [FrontierEntry1591Native.workSites]) have flags := canonical_flags orig.basis ctx F.Y 0 v input let origin' := writeBit orig.basis (base 2400) true have ctx' := FrontierEntry1591.context_control_set orig.basis ctx true have ha' := FrontierEntry1591.source_zero_control_set orig.basis true facts.sourceZero have trace' : skywalkTapeControls origin' (skywalkSharedTape base) = SkywalkTrace.trace 512 (SkywalkRails.encode false false (F.x : Int) (p : Int)) := by rw [FrontierEntry1591.trace_control_set]; exact facts.trace have input' := Rolling1588.canonical_control_set orig.basis F.Y 0 v true input have en' : origin' (base 2400) = true := by simp [origin', writeBit] have codes := Rolling1588.canonical_prefix_codes origin' ctx' F.Y 0 (force v) input' F.x F.x_pos F.x_lt trace' have clean := FourScratchWindow.canonical_clean origin' ctx' ha' F.Y (force v) input' codes.1 codes.2.1 have z768 := Rolling1588.canonical_768_zero origin' ctx' F.Y 0 (force v) input' let mC := mB.take (measurementCount StairConcrete.bestLoans.center) let mRest := mB.drop (measurementCount StairConcrete.bestLoans.center) let mCopy := mRest.take (measurementCount HalfFieldOB5.copyN) let mEnd := mRest.drop (measurementCount HalfFieldOB5.copyN) let mB' := WindowFieldJourney.joinTapes (R2SqEp760.center760 ++ HalfFieldOB5.copyN) (WindowFieldJourney.joinTapes R2SqEp760.center760 [] mCopy) mEnd obtain ⟨X', Y', hcut102⟩ := headCore_frame origin' ctx' ha' en' F.Y (force v) input' mB' have hcore_eq : run (StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN ++ StairSchedule.placedEndPacket StairConcrete.bestLoans false 68) mB (force v) = run headCore mB' (force v) := by have hc_eq := StairBoundaryLoan.center760Loan_run_eq origin' ctx' ha' F.Y (force v) mC [] input' have hcopy_f := (Rolling1588HalfFieldOB5.copy_fill ctx'.hn origin' (F.Y / 2) (run R2SqEp760.center760 [] (force v)) mCopy (R2SqEp760.center760_frame origin' ctx' ha' F.Y (force v) [] input').2).2 have hcopyN_eq : Rolling1588HalfFieldOB5.copyN = HalfFieldOB5.copyN := rfl rw [hcopyN_eq] at hcopy_f have he_eq : StairConcrete.bestLoans.endPacket false 68 = StairEndpointLoan44.endPacket760Loan44 false := by simp only [StairConcrete.bestLoans, StairConcrete.endPacket, Bool.false_eq_true, if_false, if_true] have hctr_eq : StairConcrete.bestLoans.center = StairBoundaryLoan.center760Loan := rfl have hsplit_lhs : run (StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN ++ StairSchedule.placedEndPacket StairConcrete.bestLoans false 68) mB (force v) = run (StairSchedule.placedEndPacket StairConcrete.bestLoans false 68) mEnd (run HalfFieldOB5.copyN mCopy (run StairConcrete.bestLoans.center mC (force v))) := by rw [List.append_assoc, run_append StairConcrete.bestLoans.center, run_append HalfFieldOB5.copyN] have hsplit_rhs : run headCore mB' (force v) = run (renameProgram (OB5.sig 511) (R2SqEp760.endPacket760 false)) mEnd (run HalfFieldOB5.copyN mCopy (run R2SqEp760.center760 [] (force v))) := by simp only [headCore, mB', WindowFieldJourney.joined] rw [hsplit_lhs, hsplit_rhs, hctr_eq, hc_eq, StairSchedule.placedEndPacket, he_eq] obtain ⟨s_cp, hs_cp⟩ : ∃ st, run HalfFieldOB5.copyN mCopy (run R2SqEp760.center760 [] (force v)) = st := ⟨_, rfl⟩ rw [hs_cp] at hcopy_f ⊢ apply pullState_sig511_injective rw [run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide)), run_rename (OB5.sig 511) (OB5.sig_injective 511 (by decide))] exact StairEndpointLoan44.endPacket760Loan44_run_eq false origin' ctx' en' (F.Y / 2) (F.Y / 2) rfl _ mEnd mEnd hcopy_f have hsub_core : wires (StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN ++ StairSchedule.placedEndPacket StairConcrete.bestLoans false 68) ⊆ wires headCore := by have hctr_eq : StairConcrete.bestLoans.center = StairBoundaryLoan.center760Loan := rfl have h1 : wires StairConcrete.bestLoans.center ⊆ wires R2SqEp760.center760 := by rw [hctr_eq]; exact StairLoanConverterSupport.center760Loan_sub have h2 : wires (StairSchedule.placedEndPacket StairConcrete.bestLoans false 68) ⊆ wires (renameProgram (OB5.sig 511) (R2SqEp760.endPacket760 false)) := by have he_eq : StairConcrete.bestLoans.endPacket false 68 = StairEndpointLoan44.endPacket760Loan44 false := by simp only [StairConcrete.bestLoans, StairConcrete.endPacket, Bool.false_eq_true, if_false, if_true] rw [StairSchedule.placedEndPacket, he_eq, renameProgram_support, renameProgram_support] exact Finset.image_subset_image (fun q hq => StairEndpointLoan44.endPacket760Loan44_support hq) simp only [headCore, wires_append] exact Finset.union_subset_union (Finset.union_subset_union h1 (Finset.Subset.refl _)) h2 obtain ⟨sA, hsA⟩ : ∃ st, run (StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram) mA v = st := ⟨_, rfl⟩ have hrun7 : run (cut (xps k) 7) u s = run (liftF (StairConcrete.bestLoans.center ++ HalfFieldOB5.copyN ++ StairSchedule.placedEndPacket StairConcrete.bestLoans false 68)) mB sA := by have hmO : u.take (measurementCount StairField2V3Replay.exitReferenceOpening) = mOpen := rfl have hmT : u.drop (measurementCount StairField2V3Replay.exitReferenceOpening) = mTail := rfl have hmA_eq : mTail.take (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram)) = mA := rfl have hmB_eq : mTail.drop (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram)) = mB := rfl rw [hcut4, run_append StairField2V3Replay.exitReferenceOpening, hmO, hmT, hopen, hv, run_append (StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram), hmA_eq, hmB_eq, hsA] have hpre_ag : ∀ r, Off r → (pullIn sA).basis r = (force v).basis r := by intro r hr rw [← hsA, run_append (StairSchedule.paritySetup ++ StairSchedule.hostedX), field_pullIn] exact window_agree _ (force v) _ (hosted_agree_force v flags.1 in511 flags.2 in1542 work parity _) clean codes.2.2 z768 r hr.1 hr.2 have hloc := local_eq_of_sub₂ _ _ hsub_core (pullIn sA) (force v) mB mB' (fun r hr => hpre_ag r (headCore_off r hr)) hcore_eq refine ⟨run (cut (xps k) 7) u s, ?_, by simp only [if_true]⟩ refine ⟨origin', X', Y', run headCore mB' (force v), ctx', en', ⟨F.x_pos, F.x_lt, trace', ctx'.legal⟩, hcut102, ?_⟩ intro q hq rw [hrun7, pullIn_liftF, hloc] exact run_agree_offP _ headCore_off (pullIn sA) (force v) mB' hpre_ag q hq have pin_of_x {j B c : Nat} {Z YP : Program} (hBne : B ≠ 0) (hxcut : cut (xps k) j = StairField2V3Replay.exitReferenceOpening ++ Z) (hrch : ∃ Q, CRel (XPreX k F.x) (RowRelL k F.x B YP) Z Q) (hinv : ∀ t, ReachBy (ExitMiddleX k F.x) YP t → InvE F.x c t) : ∀ u, ∃ rec, FrameAt F.x c rec ∧ (if B = 0 then run (cut (xps k) j) u s = rec else AgreeOutside (Δv B) (run (cut (xps k) j) u s) rec) := by intro u rw [hxcut, run_append] obtain ⟨Q, hcr⟩ := hrch obtain ⟨_, hrel, hreach⟩ := hcr _ _ ⟨⟨s, F, rfl, _, rfl⟩, rfl⟩ _ exact ⟨_, WindowFieldView.exitFrame c F.x _ (hinv _ hreach), by simp only [hBne, if_false]; exact hrel.1⟩ have pin11 := pin_of_x (by decide) (xcut11 k) (rch11 k F.x (StairOpenWiring.exitPlans k F.x) StairOpenWiring.half760) (fun t ht => StairField2V3ExitRec.reach_head k F.x t (reachX_head StairOpenWiring.half760 k F.x t ht)) have pin13 := pin_of_x (by decide) (xcut13 k) (rch13 k F.x (StairOpenWiring.exitPlans k F.x) StairOpenWiring.half760) (fun t ht => StairField2V3ExitRec.reach_YA k F.x t (reachX_A StairOpenWiring.half760 k F.x t ht)) have pin15 := pin_of_x (by decide) (xcut15 k) (rch15 k F.x (StairOpenWiring.exitPlans k F.x) StairOpenWiring.half760) (fun t ht => StairField2V3ExitRec.reach_YB k F.x t (reachX_B StairOpenWiring.half760 k F.x t ht)) have pin17 := pin_of_x (by decide) (xcut17 k) (rch17 k F.x (StairOpenWiring.exitPlans k F.x) StairOpenWiring.half760) (fun t ht => StairField2V3ExitRec.reach_YC k F.x t (reachX_C StairOpenWiring.half760 k F.x t ht)) have pin19 := pin_of_x (by decide) (xcut19 k) (rch19 k F.x (StairOpenWiring.exitPlans k F.x) StairOpenWiring.half760) (fun t ht => StairField2V3ExitRec.reach_YD k F.x t (reachX_D StairOpenWiring.half760 k F.x t ht)) have s7 := step_grp 7 0 43 100 2 (by decide) (x7_L k) (Or.inl rfl) (fun h => absurd rfl h) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inl rfl) pin7 have s8 := step_disj 8 (by decide) _ (x8_L k) (disjoint_ryWires_append (disjoint_ryWires_fieldRename unprefix_notRY) paritySetup_notRY) have s9 := step_disj 9 (by decide) _ (x9_L k) (disjoint_ryWires_append hostedX_notRY (disjoint_ryWires_fieldRename clearProgram_notRY)) have s10 := step_disj 10 (by decide) _ (x10_L k) (disjoint_ryWires_liftF reverseLast_notRY) have s11 := step_grp 11 12 41 98 2 (by decide) (x11_L k) (Or.inr (by decide)) (fun _ => by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin11 have s12 := step_disj 12 (by decide) _ (x12_L k) (disjoint_ryWires_liftF reverse490_notRY) have s13 := step_grp 13 22 36 96 2 (by decide) (x13_L k) (Or.inr (by decide)) (fun _ => by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin13 have s14 := step_disj 14 (by decide) _ (x14_L k) (disjoint_ryWires_liftF reverse480_notRY) have s15 := step_grp 15 32 30 93 3 (by decide) (x15_L k) (Or.inr (by decide)) (fun _ => by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin15 have s16 := step_disj 16 (by decide) _ (x16_L k) (disjoint_ryWires_liftF reverse465_notRY) have s17 := step_grp 17 47 22 90 3 (by decide) (x17_L k) (Or.inr (by decide)) (fun _ => by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin17 have s18 := step_disj 18 (by decide) _ (x18_L k) (disjoint_ryWires_liftF reverse450_notRY) have s19 := step_grp 19 62 13 85 5 (by decide) (x19_L k) (Or.inr (by decide)) (fun _ => by decide) (by decide) (by decide) (by decide) (by decide) (by simp) (Or.inr (by simp)) pin19 have s20 := step_disj 20 (by decide) _ (x20_L k) (disjoint_ryWires_liftF reverse425_notRY) have c11 : ∀ (a b : State) (m' : List Bool), MulCut 11 a b → ∃ b', MulCut 13 (run (liftF (PackCutOddExit.cutRowOddPk 22 12 490 500 41 98 1)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨rec, hframe, hagree⟩ := pin11 u obtain ⟨m2, heq⟩ := PackCutOddExit.oddCutRow_runeq 41 98 1 12 F.x (by decide) (by decide) (by decide) (by decide) (Or.inr (by decide)) (fun _ => StairField2V3Groups.groups_avoid_payload false 12 (by decide) (1 + 1) 98 (by decide)) a (run (cut (xps k) 11) u s) rec hrel hframe hagree (exitGroupsBefore_xps k 11 41 98 (1 + 1) (by simp) s ⟨F⟩ u) (hostPlan_group_notRY false 41 98 (1 + 1) (by decide)) (History5.historyMap (PackCutExitRows.segW 490) (5 * 98)) PackCutExitRows.inj4 PackCutExitInst.sig4 PackCutExitInst.rh4 PackCutExitInst.off4 (fun i _ => PackCutExitInst.fp4 i) (by decide +kernel) PackCutExitInst.rs4 PackCutExitInst.fix4 _ _ _ PackCutExitRows.seg4 PackCutExitRows.mid4 PackCutExitRows.hep4 m' have hseg' : StairField2V3Entry.liftF (StairSchedule.reverseSegment StairConcreteAssembly.checkpointPrimitives 22 12 490 500) = StairField2V3ExitPlan.rseg cp 22 12 490 500 := rfl have heq' : run (liftF (PackCutOddExit.cutRowOddPk 22 12 490 500 41 98 1)) m' a = _ := heq rw [heq', hseg', run_append] exact ⟨_, s12 _ _ _ (s11 _ _ _ ⟨⟨u, rfl⟩, hrel⟩)⟩ have c13 : ∀ (a b : State) (m' : List Bool), MulCut 13 a b → ∃ b', MulCut 15 (run (liftF (PackCutOddExit.cutRowOddPk 32 22 480 490 36 96 1)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨rec, hframe, hagree⟩ := pin13 u obtain ⟨m2, heq⟩ := PackCutOddExit.oddCutRow_runeq 36 96 1 22 F.x (by decide) (by decide) (by decide) (by decide) (Or.inr (by decide)) (fun _ => StairField2V3Groups.groups_avoid_payload false 22 (by decide) (1 + 1) 96 (by decide)) a (run (cut (xps k) 13) u s) rec hrel hframe hagree (exitGroupsBefore_xps k 13 36 96 (1 + 1) (by simp) s ⟨F⟩ u) (hostPlan_group_notRY false 36 96 (1 + 1) (by decide)) (History5.historyMap (PackCutExitRows.segW 480) (5 * 96)) PackCutExitRows.inj3 PackCutExitInst.sig3 PackCutExitInst.rh3 PackCutExitInst.off3 (fun i _ => PackCutExitInst.fp3 i) (by decide +kernel) PackCutExitInst.rs3 PackCutExitInst.fix3 _ _ _ PackCutExitRows.seg3 PackCutExitRows.mid3 PackCutExitRows.hep3 m' have hseg' : StairField2V3Entry.liftF (StairSchedule.reverseSegment StairConcreteAssembly.checkpointPrimitives 32 22 480 490) = StairField2V3ExitPlan.rseg cp 32 22 480 490 := rfl have heq' : run (liftF (PackCutOddExit.cutRowOddPk 32 22 480 490 36 96 1)) m' a = _ := heq rw [heq', hseg', run_append] exact ⟨_, s14 _ _ _ (s13 _ _ _ ⟨⟨u, rfl⟩, hrel⟩)⟩ have c15 : ∀ (a b : State) (m' : List Bool), MulCut 15 a b → ∃ b', MulCut 17 (run (liftF (PackCutOddExit.cutRowOddPk 47 32 465 480 30 93 2)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨rec, hframe, hagree⟩ := pin15 u obtain ⟨m2, heq⟩ := PackCutOddExit.oddCutRow_runeq 30 93 2 32 F.x (by decide) (by decide) (by decide) (by decide) (Or.inr (by decide)) (fun _ => StairField2V3Groups.groups_avoid_payload false 32 (by decide) (2 + 1) 93 (by decide)) a (run (cut (xps k) 15) u s) rec hrel hframe hagree (exitGroupsBefore_xps k 15 30 93 (2 + 1) (by simp) s ⟨F⟩ u) (hostPlan_group_notRY false 30 93 (2 + 1) (by decide)) (History5.historyMap (PackCutExitRows.segW 465) (5 * 93)) PackCutExitRows.inj2 PackCutExitInst.sig2 PackCutExitInst.rh2 PackCutExitInst.off2 (fun i _ => PackCutExitInst.fp2 i) (by decide +kernel) PackCutExitInst.rs2 PackCutExitInst.fix2 _ _ _ PackCutExitRows.seg2 PackCutExitRows.mid2 PackCutExitRows.hep2 m' have hseg' : StairField2V3Entry.liftF (StairSchedule.reverseSegment StairConcreteAssembly.checkpointPrimitives 47 32 465 480) = StairField2V3ExitPlan.rseg cp 47 32 465 480 := rfl have heq' : run (liftF (PackCutOddExit.cutRowOddPk 47 32 465 480 30 93 2)) m' a = _ := heq rw [heq', hseg', run_append] exact ⟨_, s16 _ _ _ (s15 _ _ _ ⟨⟨u, rfl⟩, hrel⟩)⟩ have c17 : ∀ (a b : State) (m' : List Bool), MulCut 17 a b → ∃ b', MulCut 19 (run (liftF (PackCutOddExit.cutRowOddPk 62 47 450 465 22 90 2)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨rec, hframe, hagree⟩ := pin17 u obtain ⟨m2, heq⟩ := PackCutOddExit.oddCutRow_runeq 22 90 2 47 F.x (by decide) (by decide) (by decide) (by decide) (Or.inr (by decide)) (fun _ => StairField2V3Groups.groups_avoid_payload false 47 (by decide) (2 + 1) 90 (by decide)) a (run (cut (xps k) 17) u s) rec hrel hframe hagree (exitGroupsBefore_xps k 17 22 90 (2 + 1) (by simp) s ⟨F⟩ u) (hostPlan_group_notRY false 22 90 (2 + 1) (by decide)) (History5.historyMap (PackCutExitRows.segW 450) (5 * 90)) PackCutExitRows.inj1 PackCutExitInst.sig1 PackCutExitInst.rh1 PackCutExitInst.off1 (fun i _ => PackCutExitInst.fp1 i) (by decide +kernel) PackCutExitInst.rs1 PackCutExitInst.fix1 _ _ _ PackCutExitRows.seg1 PackCutExitRows.mid1 PackCutExitRows.hep1 m' have hseg' : StairField2V3Entry.liftF (StairSchedule.reverseSegment StairConcreteAssembly.checkpointPrimitives 62 47 450 465) = StairField2V3ExitPlan.rseg cp 62 47 450 465 := rfl have heq' : run (liftF (PackCutOddExit.cutRowOddPk 62 47 450 465 22 90 2)) m' a = _ := heq rw [heq', hseg', run_append] exact ⟨_, s18 _ _ _ (s17 _ _ _ ⟨⟨u, rfl⟩, hrel⟩)⟩ have c19 : ∀ (a b : State) (m' : List Bool), MulCut 19 a b → ∃ b', MulCut 21 (run (liftF (PackCutOddExit.cutRowOddPk 87 62 425 450 13 85 4)) m' a) b' := by rintro a b m' ⟨⟨u, rfl⟩, hrel⟩ obtain ⟨rec, hframe, hagree⟩ := pin19 u obtain ⟨m2, heq⟩ := PackCutOddExit.oddCutRow_runeq 13 85 4 62 F.x (by decide) (by decide) (by decide) (by decide) (Or.inr (by decide)) (fun _ => StairField2V3Groups.groups_avoid_payload false 62 (by decide) (4 + 1) 85 (by decide)) a (run (cut (xps k) 19) u s) rec hrel hframe hagree (exitGroupsBefore_xps k 19 13 85 (4 + 1) (by simp) s ⟨F⟩ u) (hostPlan_group_notRY false 13 85 (4 + 1) (by decide)) (History5.historyMap (PackCutExitRows.segW 425) (5 * 85)) PackCutExitRows.inj0 PackCutExitInst.sig0 PackCutExitInst.rh0 PackCutExitInst.off0 (fun i _ => PackCutExitInst.fp0 i) (by decide +kernel) PackCutExitInst.rs0 PackCutExitInst.fix0 _ _ _ PackCutExitRows.seg0 PackCutExitRows.mid0 PackCutExitRows.hep0 m' have hseg' : StairField2V3Entry.liftF (StairSchedule.reverseSegment StairConcreteAssembly.checkpointPrimitives 87 62 425 450) = StairField2V3ExitPlan.rseg cp 87 62 425 450 := rfl have heq' : run (liftF (PackCutOddExit.cutRowOddPk 87 62 425 450 13 85 4)) m' a = _ := heq rw [heq', hseg', run_append] exact ⟨_, s20 _ _ _ (s19 _ _ _ ⟨⟨u, rfl⟩, hrel⟩)⟩ have hshape21p : stockOddMulPrefix21 = ((((((((((StairField2V3Replay.exitReferenceOpening ++ StairSchedule.paritySetup ++ StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram) ++ liftF (OddFullPass.HalfConvertOdd.center760OddLoan ++ HalfFieldOB5.copyN ++ renameProgram (OB5.sig 511) OddFullPass.InverseTailCOdd.endPacket760OddLoan44)) ++ renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan false 43 100 2)) ++ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup)) ++ (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram)) ++ liftF (StairSchedule.reverseLast cp)) ++ liftF (PackCutOddExit.cutRowOddPk 22 12 490 500 41 98 1)) ++ liftF (PackCutOddExit.cutRowOddPk 32 22 480 490 36 96 1)) ++ liftF (PackCutOddExit.cutRowOddPk 47 32 465 480 30 93 2)) ++ liftF (PackCutOddExit.cutRowOddPk 62 47 450 465 22 90 2)) ++ liftF (PackCutOddExit.cutRowOddPk 87 62 425 450 13 85 4) := by have hfr_bor (P : Program) : StairSchedule.fieldRename (renameProgram Prefix1590.borrow P) = liftF P := rfl simp only [stockOddMulPrefix21, stockOddMulLeading, stockOddMulBeforeParity, stockOddMulBeforeGroup, OddFullPass.P1LifeLoan.exitLowPrefixOdd, OddFullPass.P1LifeLoan.exitHeadPrefixOdd, fieldRename_append, Six505.rename_append, hfr_bor, liftF_append, List.append_assoc] rw [← ExteriorPorts.placedShape (OddFullPass.P1LifeLoan.hostedGroup hostPlan false 43 100 2)] simp only [hfr_bor] have hchain21p (s7_ : State) (m7 m8 m9 m10 m11 m13 m15 m17 m19 : List Bool) (h7 : ∃ b7, MulCut 7 s7_ b7) : ∃ b21, MulCut 21 (run (liftF (PackCutOddExit.cutRowOddPk 87 62 425 450 13 85 4)) m19 (run (liftF (PackCutOddExit.cutRowOddPk 62 47 450 465 22 90 2)) m17 (run (liftF (PackCutOddExit.cutRowOddPk 47 32 465 480 30 93 2)) m15 (run (liftF (PackCutOddExit.cutRowOddPk 32 22 480 490 36 96 1)) m13 (run (liftF (PackCutOddExit.cutRowOddPk 22 12 490 500 41 98 1)) m11 (run (liftF (StairSchedule.reverseLast cp)) m10 (run (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram) m9 (run (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup) m8 (run (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan false 43 100 2)) m7 s7_))))))))) b21 := by obtain ⟨b7, d7⟩ := h7 have d8 := s7 _ _ m7 d7 have d9 := s8 _ _ m8 d8 have d10 := s9 _ _ m9 d9 have d11 := s10 _ _ m10 d10 obtain ⟨b13, d13⟩ := c11 _ _ m11 d11 obtain ⟨b15, d15⟩ := c13 _ _ m13 d13 obtain ⟨b17, d17⟩ := c15 _ _ m15 d15 obtain ⟨b19, d19⟩ := c17 _ _ m17 d17 exact c19 _ _ m19 d19 have hd21 : ∃ b21, MulCut 21 a21 b21 := by change ∃ b21, MulCut 21 (run stockOddMulPrefix21 m s) b21 rw [hshape21p, run_append _ (liftF (PackCutOddExit.cutRowOddPk 87 62 425 450 13 85 4)), run_append _ (liftF (PackCutOddExit.cutRowOddPk 62 47 450 465 22 90 2)), run_append _ (liftF (PackCutOddExit.cutRowOddPk 47 32 465 480 30 93 2)), run_append _ (liftF (PackCutOddExit.cutRowOddPk 32 22 480 490 36 96 1)), run_append _ (liftF (PackCutOddExit.cutRowOddPk 22 12 490 500 41 98 1)), run_append _ (liftF (StairSchedule.reverseLast cp)), run_append _ (StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram), run_append _ (StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.paritySetup), run_append _ (renameProgram ExteriorPorts.fieldEquiv (OddFullPass.P1LifeLoan.hostedGroup hostPlan false 43 100 2))] exact hchain21p _ _ _ _ _ _ _ _ _ _ ⟨_, hcut7 _⟩ obtain ⟨b21, ⟨u21, hb21⟩, hrel21⟩ := hd21 rw [hb21] at hrel21 obtain ⟨⟨rec, hframe, hagree⟩, hloan⟩ := exitCut21_pin_loan k F u21 exact ⟨⟨u21, hrel21⟩, odd_cut_ocut 85 (by decide) (by decide) F.x a21 (run (cut (xps k) 21) u21 s) rec hrel21 hframe hagree hloan⟩ /-- Explicit frame at multiplication cut 23 (`run (exitReferenceOpening ++ (YE ++ grpF 1 84) ++ fieldRename unprefix)`)! -/ private theorem mul_cut23_frame (k : Nat) {s : State} (F : ExitFrame k s) (mOpen mBody : List Bool) : ∃ (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400) = true) (tr : skywalkTapeControls origin (skywalkSharedTape base) = SkywalkTrace.trace 512 (SkywalkRails.encode false false (F.x : Int) (p : Int))) (s23 : State), Rolling1588Frame.EncodedFieldFrame true origin (Rolling1588.exitHeadPayload origin F.Y).1 (Rolling1588.exitHeadPayload origin F.Y).2 s23 ∧ (∀ q, q ∉ E → (pullState fieldMap (run ((YE ++ StairField2V3ExitPlan.grpF 1 84) ++ StairSchedule.fieldRename FourScratchWindow.unprefix) mBody (run StairField2V3Replay.exitReferenceOpening mOpen s))).basis q = s23.basis q) := by have hopen : run StairField2V3Replay.exitReferenceOpening mOpen s = run (Rolling1588.firstPhase false) mOpen s := first_phase_hosted false F.sharedNodup F.historyAbove F.x F.Y.val F.x_pos F.x_lt s mOpen F.input rw [hopen] obtain ⟨orig, facts, legal, frames⟩ := Rolling1588Lifetime.first_prepared F.sharedNodup F.historyAbove F.selectorsAway F.x F.Y F.x_pos F.x_lt s mOpen F.input have ctx := Rolling1588Lifetime.prepared_context F.sharedNodup F.selectorsAway F.transcript F.x F.Y s orig facts legal F.selectorG_zero F.selectorS_zero have bits := Rolling1588Lifetime.first_clean false F.sharedNodup F.historyAbove F.x F.Y.val F.x_pos F.x_lt s mOpen F.input have work := Rolling1588Lifetime.first_work_zero false F.sharedNodup F.x F.Y.val s mOpen F.input have parity := Rolling1588Lifetime.first_parity false F.sharedNodup F.historyAbove F.x F.Y.val F.x_pos F.x_lt s mOpen F.input have input := frames false rw [lf_eq] at input bits work parity obtain ⟨v, hv⟩ : ∃ v : State, run (Rolling1588.firstPhase false) mOpen s = v := ⟨_, rfl⟩ rw [hv] at input bits work parity ⊢ have code := Rolling1588Frame.canonical_special_at orig.basis F.Y 0 v 511 (by simp) input have in511 : v.basis (base 511) = true := (by rw [sig511_511_mul] at code; exact code : v.basis (base 511) = orig.basis (base 511)).trans (trace_last F.x F.x_pos F.x_lt orig.basis facts.trace) have in1542 : v.basis (base 1542) = false := bits _ (by simp [FrontierEntry1591Native.workSites]) have flags := canonical_flags orig.basis ctx F.Y 0 v input let origin' := writeBit orig.basis (base 2400) true have ctx' := FrontierEntry1591.context_control_set orig.basis ctx true have ha' := FrontierEntry1591.source_zero_control_set orig.basis true facts.sourceZero have trace' : skywalkTapeControls origin' (skywalkSharedTape base) = SkywalkTrace.trace 512 (SkywalkRails.encode false false (F.x : Int) (p : Int)) := by rw [FrontierEntry1591.trace_control_set]; exact facts.trace have input' := Rolling1588.canonical_control_set orig.basis F.Y 0 v true input have en' : origin' (base 2400) = true := by simp [origin', writeBit] -- Show `(YE ++ grpF 1 84) ++ fieldRename unprefix = (paritySetup ++ hostedX) ++ fieldRename (clearProgram ++ renameProgram borrow exitHead ++ unprefix)`! have hgrp_split (j a b : Nat) : Rolling1588.groups false (j + a) b ++ Rolling1588.groups false j a = Rolling1588.groups false j (a + b) := by induction a generalizing j with | zero => simp [Rolling1588.groups, PacketSequence.program] | succ a ih => have h1 : a + 1 + b = (a + b) + 1 := by omega rw [h1] simp only [Rolling1588.groups, PacketSequence.program, Bool.false_eq_true, if_false, ← List.append_assoc] have h2 := ih (j + 1) rw [show j + 1 + a = j + (a + 1) by omega] at h2 simp only [Rolling1588.groups] at h2 rw [h2] have h101 : Rolling1588.groups false 100 2 ++ Rolling1588.groups false 98 2 ++ Rolling1588.groups false 96 2 ++ Rolling1588.groups false 93 3 ++ Rolling1588.groups false 90 3 ++ Rolling1588.groups false 85 5 ++ Rolling1588.groups false 1 84 = Rolling1588.groups false 1 101 := by rw [hgrp_split 98 2 2, hgrp_split 96 2 4, hgrp_split 93 3 6, hgrp_split 90 3 9, hgrp_split 85 5 12, hgrp_split 1 84 17] let W := FourScratchWindow.clearProgram ++ (renameProgram Prefix1590.borrow Rolling1588.exitHead ++ FourScratchWindow.unprefix) let mS := mBody.take (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX)) let mW := mBody.drop (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX)) have hbody : (YE ++ StairField2V3ExitPlan.grpF 1 84) ++ StairSchedule.fieldRename FourScratchWindow.unprefix = (StairSchedule.paritySetup ++ StairSchedule.hostedX) ++ StairSchedule.fieldRename W := by have hYE : YE ++ StairField2V3ExitPlan.grpF 1 84 = (StairSchedule.paritySetup ++ StairSchedule.hostedX) ++ StairSchedule.fieldRename FourScratchWindow.clearProgram ++ liftF Rolling1588.exitHead := by rw [Rolling1588.exitHead, ← h101] simp only [YE, YD, YC, YB, YA, StairField2V3ExitPlan.headE, StairField2V3ExitPlan.grpF, liftF, headCore, fieldRename_append, Six505.rename_append, List.append_assoc] rw [hYE] simp only [W, liftF, fieldRename_append, List.append_assoc] have hmS : mBody.take (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX)) = mS := rfl have hmW : mBody.drop (measurementCount (StairSchedule.paritySetup ++ StairSchedule.hostedX)) = mW := rfl rw [hbody, run_append, hmS, hmW] have hW_avoidE : ∀ q ∈ E, q ∉ wires W := by have hcl_notE : StairWireCheck.allSites (fun q => !(decide (q ∈ E))) FourScratchWindow.clearProgram = true := by decide +kernel have hun_notE : StairWireCheck.allSites (fun q => !(decide (q ∈ E))) FourScratchWindow.unprefix = true := by decide +kernel have hbor_E : ∀ q ∈ E, Prefix1590.borrow q = q := by have h : E.all (fun q => decide (Prefix1590.borrow q = q)) = true := by decide +kernel intro q hq; exact of_decide_eq_true (List.all_eq_true.mp h q hq) intro q hE hq simp only [W, wires_append, Finset.mem_union] at hq rcases hq with h1 | h2 | h3 · have := StairWireCheck.allSites_sound _ _ hcl_notE q h1; simp [hE] at this · rw [renameProgram_support] at h2 obtain ⟨r, hr, heq⟩ := Finset.mem_image.mp h2 have hrq : r = q := Prefix1590.borrow.injective (heq.trans (hbor_E q hE).symm) exact (exitHead_avoid r hr).1 (hrq ▸ hE) · have := StairWireCheck.allSites_sound _ _ hun_notE q h3; simp [hE] at this have hrun_W : run W mW (force v) = run Rolling1588.exitHead (mW.drop 6) (force v) := by have hres := Rolling1588.exitHead_frame origin' ctx' ha' en' F.Y (force v) (mW.drop 6) input' have hbef := Rolling1588.canonical_prefix_codes origin' ctx' F.Y 0 (force v) input' F.x F.x_pos F.x_lt trace' have haft := Rolling1588.field_prefix_codes origin' ctx' _ _ _ hres.2 F.x F.x_pos F.x_lt trace' exact FourScratchWindow.window_run_eq Rolling1588.exitHead W rfl Rolling1588.exitHead_payload_free (force v) mW (FourScratchWindow.canonical_clean origin' ctx' ha' F.Y (force v) input' hbef.1 hbef.2.1) (FourScratchWindow.field_clean origin' ctx' _ _ _ hres.2 haft.1 haft.2.1) (Rolling1588.canonical_768_zero origin' ctx' F.Y 0 (force v) input') (Rolling1588.field_768_zero origin' ctx' _ _ _ hres.2) hbef.2.2 have hframe23 := (Rolling1588.exitHead_frame origin' ctx' ha' en' F.Y (force v) (mW.drop 6) input').2 obtain ⟨rS, hrS⟩ : ∃ st, run (StairSchedule.paritySetup ++ StairSchedule.hostedX) mS v = st := ⟨_, rfl⟩ have hS_ag : ∀ q, q ∉ E → (pullState fieldMap rS).basis q = (force v).basis q := fun q hq => by rw [pullState_fieldMap_basis] have h := hosted_agree_force v flags.1 in511 flags.2 in1542 work parity mS q hq rwa [hrS] at h refine ⟨origin', ctx', en', trace', run Rolling1588.exitHead (mW.drop 6) (force v), hframe23, ?_⟩ intro q hq rw [hrS, fieldRename_eq, run_rename fieldMap fieldMap_injective, ← hrun_W] exact run_agree_off W hW_avoidE (pullState fieldMap rS) (force v) mW hS_ag q hq /-- Full multiplication head lockstep: `AgreeOutsideR` + `regValue fieldR = oddWord (Y * x / 2)` between `stockOddMulHead` and `WindowMiddleContract.oldMulHead`! -/ theorem stockOddMulHead_agree_oldMulHead (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : ∃ n, AgreeOutsideR (run stockOddMulHead m s) (run WindowMiddleContract.oldMulHead n s) ∧ regValue fieldR (run stockOddMulHead m s).basis = P1Life.oddWord (F.Y * (F.x : Fp) / 2) := by -- Step 1: replace `mulLead` by `exitReferenceOpening` on `stockOddMulHead`! have hlead_eq : run stockOddMulHead m s = run ((((stockOddMulPrefix21 ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup false 1 84)) ++ StairSchedule.fieldRename FourScratchWindow.unprefix) ++ StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf false)) ++ renameProgram Rolling1588Lifetime.phaseHost checkpointPrimitives.firstUnpack) m s := by have h1 : stockOddMulHead = (Stair44Kernel.mulLead ++ (stockOddMulLeading ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup false 1 84) ++ StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf false) ++ renameProgram Rolling1588Lifetime.phaseHost checkpointPrimitives.firstUnpack)) := by simp only [stockOddMulHead, stockOddMulAfterGroup, fieldRename_append, List.append_assoc] have h2 : ((((stockOddMulPrefix21 ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup false 1 84)) ++ StairSchedule.fieldRename FourScratchWindow.unprefix) ++ StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf false)) ++ renameProgram Rolling1588Lifetime.phaseHost checkpointPrimitives.firstUnpack) = StairField2V3Replay.exitReferenceOpening ++ (stockOddMulLeading ++ renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup false 1 84) ++ StairSchedule.fieldRename FourScratchWindow.unprefix ++ StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf false) ++ renameProgram Rolling1588Lifetime.phaseHost checkpointPrimitives.firstUnpack) := by simp only [stockOddMulPrefix21, List.append_assoc] rw [h1, h2, run_append Stair44Kernel.mulLead, run_append StairField2V3Replay.exitReferenceOpening, WindowStockHead.leadM k F, WindowStockHead.countM] rw [hlead_eq] let P21 := stockOddMulPrefix21 let POg := renameProgram ExteriorPorts.fieldEquiv (WindowFieldCosts.ogroup false 1 84) let PUn := StairSchedule.fieldRename FourScratchWindow.unprefix let PFp := StairSchedule.fieldRename (JointOdd1588.hostedFirstPacketOdd WindowCallerCosts.oddFirstHalf false) let PFu := renameProgram Rolling1588Lifetime.phaseHost checkpointPrimitives.firstUnpack let m1234 := m.take (measurementCount (((P21 ++ POg) ++ PUn) ++ PFp)) let m25 := m.drop (measurementCount (((P21 ++ POg) ++ PUn) ++ PFp)) let m123 := m1234.take (measurementCount ((P21 ++ POg) ++ PUn)) let mFp := m1234.drop (measurementCount ((P21 ++ POg) ++ PUn)) let m12 := m123.take (measurementCount (P21 ++ POg)) let mUn := m123.drop (measurementCount (P21 ++ POg)) let m21 := m12.take (measurementCount P21) let mOg := m12.drop (measurementCount P21) have hsplit5 : run ((((P21 ++ POg) ++ PUn) ++ PFp) ++ PFu) m s = run PFu m25 (run PFp mFp (run PUn mUn (run POg mOg (run P21 m21 s)))) := by rw [run_append (((P21 ++ POg) ++ PUn) ++ PFp), run_append ((P21 ++ POg) ++ PUn), run_append (P21 ++ POg), run_append P21] rw [hsplit5] -- Cut 21: `stockOddMul_cut21` gives `u21` with `OddRel a21 (run (cut (xps k) 21) u21 s)`! obtain ⟨⟨u21, hrel21⟩, _⟩ := stockOddMul_cut21 k F m21 let a21 := run P21 m21 s let a22 := run POg mOg a21 let a23 := run PUn mUn a22 let a24 := run PFp mFp a23 -- Piece 21: `ogroup false 1 84` vs `grpFL bestLoans 0 1 84`! obtain ⟨⟨rec21, hframe21, hagree21⟩, hloan21⟩ := exitCut21_pin_loan k F u21 have hgrpFL0_eq : grpFL StairConcrete.bestLoans 0 1 84 = liftF (renameProgram (OB5.sig 511) (StairGroups.groups false 0 1 84)) := rfl have hclIn21 : ∀ q ∈ (StairSchedule.exclusiveRoles ++ hostPlan.group false 0 1 84).map lowMap, (run (cut (xps k) 21) u21 s).basis q = false := by intro q hq obtain ⟨w, hw, rfl⟩ := List.mem_map.mp hq rw [hp_group false 0 1 84 (by decide)] at hw rw [show lowMap w = fieldPlace w from rfl] exact hloan21 w hw have hclOut21' : ∀ q ∈ (StairSchedule.exclusiveRoles.drop 0).map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups false 0 1 84))) mOg (run (cut (xps k) 21) u21 s)).basis q = false := cleanCut_after (exitGroupsRolesAfter_xps k 21 0 1 84 (by simp)) (by rw [cut_succ (xps k) 21 (xL k 21 (by decide)), x21_L, hgrpFL0_eq]) s ⟨F⟩ u21 mOg have hclOut21 : ∀ q ∈ StairSchedule.exclusiveRoles.map lowMap, (run (liftF (renameProgram (OB5.sig 511) (StairGroups.groups false 0 1 84))) mOg (run (cut (xps k) 21) u21 s)).basis q = false := fun q hq => hclOut21' q (by simpa only [List.drop_zero] using hq) have hrel22 := odd_ogroup84_step false F.x a21 (run (cut (xps k) 21) u21 s) rec21 mOg hrel21 hframe21 hagree21 hclIn21 hclOut21 rw [← hgrpFL0_eq] at hrel22 let u22 := WindowFieldJourney.joinTapes (cut (xps k) 21) u21 mOg have hb22 : run (grpFL StairConcrete.bestLoans 0 1 84) mOg (run (cut (xps k) 21) u21 s) = run (cut (xps k) 22) u22 s := by rw [cut_succ (xps k) 21 (xL k 21 (by decide)), x21_L, WindowFieldJourney.joined] rw [hb22] at hrel22 -- Piece 22: `fieldRename FourScratchWindow.unprefix` (disjoint from `ryWires`)! have hrel23 := oddRel_disjoint PUn (disjoint_ryWires_fieldRename unprefix_notRY) hrel22 mUn let u23 := WindowFieldJourney.joinTapes (cut (xps k) 22) u22 mUn have hb23 : run PUn mUn (run (cut (xps k) 22) u22 s) = run (cut (xps k) 23) u23 s := by rw [cut_succ (xps k) 22 (xL k 22 (by decide)), x22_L, WindowFieldJourney.joined] rw [hb23] at hrel23 -- Piece 23: relate `b23 = run (cut (xps k) 23) u23 s` to `s23` (`EncodedFieldFrame true origin (exitHeadPayload origin F0.Y)`) via `rch21` + `mul_cut23_frame`! have h23_pin : ∃ (Y0 : Fp) (origin : BasisState) (ctx : FrontierReplay1591.Context origin) (en : origin (base 2400) = true) (tr : skywalkTapeControls origin (skywalkSharedTape base) = SkywalkTrace.trace 512 (SkywalkRails.encode false false (F.x : Int) (p : Int))) (s23 : State), Rolling1588Frame.EncodedFieldFrame true origin (Rolling1588.exitHeadPayload origin Y0).1 (Rolling1588.exitHeadPayload origin Y0).2 s23 ∧ (∀ q, StairWireCheck.fpSup q = true → (pullState fieldMap (run (cut (xps k) 23) u23 s)).basis q = s23.basis q) ∧ (∀ q ∈ ryWires, (pullState fieldMap (run (cut (xps k) 23) u23 s)).basis q = s23.basis q) := by obtain ⟨Q21, hcr21⟩ := rch21 k F.x (StairOpenWiring.exitPlans k F.x) StairOpenWiring.half760 have hcr23 : CRel (XPreX k F.x) (fun a b => AgreeOutside (Δv 87) a b ∧ ReachE k F.x ((YE ++ StairField2V3ExitPlan.grpF 1 84) ++ StairSchedule.fieldRename FourScratchWindow.unprefix) b) XS23 ((Q21 ++ grpFL StairConcrete.bestLoans 0 1 84) ++ StairSchedule.fieldRename FourScratchWindow.unprefix) := by have h21' : CRel (XPreX k F.x) (fun a b => RelX F.x 87 a b ∧ ReachE k F.x YE b) XS21 Q21 := crel_mono (fun _ _ w => w) (fun _ _ w => ⟨w.1, reachX_E StairOpenWiring.half760 k F.x _ w.2⟩) hcr21 -- Step 21 (`grpFL bestLoans 0 1 84` vs `grpF 1 84` on `YE`): -- Note: `grpFL bestLoans 0 1 84` and `grpF 1 84` act identically on `YE` (cut 85) via `StairGroups.groups_run_eq`! -- Even simpler: `grpFL StairConcrete.bestLoans 0 1 84 = grpF 1 84`? YES!! `def_ = 0`, `StairGroups.groups_zero`!! have hgrp0 : grpFL StairConcrete.bestLoans 0 1 84 = StairField2V3ExitPlan.grpF 1 84 := by simp only [grpFL, StairField2V3ExitPlan.grpF, StairSchedule.placedGroups, StairConcrete.bestLoans, StairGroups.groups_zero] have hstep21 : CRel (fun a b => RelX F.x 87 a b ∧ ReachE k F.x YE b) (fun a b => RelX F.x 87 a b ∧ ReachE k F.x (YE ++ StairField2V3ExitPlan.grpF 1 84) b) (grpFL StairConcrete.bestLoans 0 1 84) (grpFL StairConcrete.bestLoans 0 1 84) := by rintro a b ⟨hrel, ⟨s0, m0, hs0, rfl⟩⟩ m21 have hs := shared_step (Δv 87) (CvX F.x 87) (cvX_local F.x 87) (grpFL StairConcrete.bestLoans 0 1 84) (away_of_sub _ _ _ exitGroupSub_best.2.2.2.2.2 (StairField2V3Delta.grpF_away 87 (by decide) 1 84 (by decide))) a (run YE m0 s0) hrel m21 obtain ⟨n21, hn21⟩ := hs refine ⟨n21, hn21, s0, WindowFieldJourney.joinTapes YE m0 n21, hs0, ?_⟩ rw [hgrp0, WindowFieldJourney.joined] have hstep22 : CRel (fun a b => RelX F.x 87 a b ∧ ReachE k F.x (YE ++ StairField2V3ExitPlan.grpF 1 84) b) (fun a b => AgreeOutside (Δv 87) a b ∧ ReachE k F.x ((YE ++ StairField2V3ExitPlan.grpF 1 84) ++ StairSchedule.fieldRename FourScratchWindow.unprefix) b) (StairSchedule.fieldRename FourScratchWindow.unprefix) (StairSchedule.fieldRename FourScratchWindow.unprefix) := by rintro a b ⟨hrel, ⟨s0, m0, hs0, rfl⟩⟩ m22 have hs := shared_step (Δv 87) (CvX F.x 87) (cvX_local F.x 87) (StairSchedule.fieldRename FourScratchWindow.unprefix) (away_of_sub _ _ _ unprefix_sub StairField2V3ExitPlanR.low_away) a (run (YE ++ StairField2V3ExitPlan.grpF 1 84) m0 s0) hrel m22 obtain ⟨n22, hn22⟩ := hs refine ⟨n22, hn22.1, s0, WindowFieldJourney.joinTapes (YE ++ StairField2V3ExitPlan.grpF 1 84) m0 n22, hs0, ?_⟩ rw [WindowFieldJourney.joined] exact crel_append (crel_append h21' hstep21) hstep22 rw [xcut23 k, run_append] obtain ⟨_, hagree23, t0, mBody, ⟨s0, F0, fx0, mOpen, rfl⟩, hrec23⟩ := hcr23 _ _ ⟨⟨s, F, rfl, _, rfl⟩, rfl⟩ _ obtain ⟨origin, ctx, en, tr, s23, hfr23, hag23⟩ := mul_cut23_frame k F0 mOpen mBody obtain ⟨r23, hr23⟩ : ∃ st, run ((YE ++ StairField2V3ExitPlan.grpF 1 84) ++ StairSchedule.fieldRename FourScratchWindow.unprefix) mBody (run StairField2V3Replay.exitReferenceOpening mOpen s0) = st := ⟨_, rfl⟩ rw [hr23] at hrec23 hag23 obtain ⟨c23, hc23⟩ : ∃ st, run XS23 (u23.drop (measurementCount StairField2V3Replay.exitReferenceOpening)) (run StairField2V3Replay.exitReferenceOpening (u23.take (measurementCount StairField2V3Replay.exitReferenceOpening)) s) = st := ⟨_, rfl⟩ rw [hc23] at hagree23 ⊢ refine ⟨F0.Y, origin, ctx, en, by rw [← fx0]; exact tr, s23, hfr23, ?_, ?_⟩ · intro q hq have h1 := hagree23.2 (fieldMap q) (fpSup_not_delta87 q hq) have h2 := hag23 q (fpSup_not_E q hq) exact (h1.trans (congrArg (fun st : State => st.basis (fieldMap q)) hrec23)).trans h2 · intro q hq have h1 := hagree23.2 (fieldMap q) (ryWires_not_delta87 q hq) have h2 := hag23 q (ryWires_not_E q hq) exact (h1.trans (congrArg (fun st : State => st.basis (fieldMap q)) hrec23)).trans h2 obtain ⟨Y0, origin, ctx, en, tr, s23, hfr23, hpb_fp, hpb_ry⟩ := h23_pin obtain ⟨P23, hP23⟩ : ∃ P : Fp × Fp, Rolling1588.exitHeadPayload origin Y0 = P := ⟨_, rfl⟩ rw [hP23] at hfr23 have hcleanIn23 : ∀ q ∈ (StairSchedule.exclusiveRoles ++ hostPlan.firstPacket false).map fieldMap, (run (cut (xps k) 23) u23 s).basis q = false := exitFirstBefore_xps k s ⟨F⟩ u23 have hcleanOut23 : ∀ q ∈ StairSchedule.exclusiveRoles.map fieldMap, (run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket false)) mFp (run (cut (xps k) 23) u23 s)).basis q = false := cleanCut_after (exitFirstRolesAfter_xps k) (by rw [cut_succ (xps k) 23 (xL k 23 (by decide))]; rfl) s ⟨F⟩ u23 mFp have hb23_vals : regValue fieldR (run (cut (xps k) 23) u23 s).basis = centerWord P23.1 ∧ regValue fieldY (run (cut (xps k) 23) u23 s).basis = centerWord P23.2 := by have hvs := encodedFieldFrame_values true origin P23.1 P23.2 s23 hfr23 constructor · rw [← pullState_fieldMap_regValue_R] exact (regValue_congr _ _ _ (fun q hq => hpb_ry q ((mem_ryWires_iff q).mpr (Or.inl hq)))).trans hvs.1 · rw [← pullState_fieldMap_regValue_Y] exact (regValue_congr _ _ _ (fun q hq => hpb_ry q ((mem_ryWires_iff q).mpr (Or.inr hq)))).trans hvs.2 have hz23 : FirstZero.FirstHyp false origin P23.1 P23.2 := by refine ⟨fun _ => ?_, fun h => absurd h (by decide)⟩ rw [Prod.mk.eta, ← hP23] exact Rolling1588.exitHead_first_zero origin F.x Y0 F.x_pos F.x_lt tr have hfp23 := firstPacketOdd_step false true origin ctx en F.x F.x_lt tr P23.1 P23.2 hz23 a23 (run (cut (xps k) 23) u23 s) s23 mFp hrel23.1 hfr23 hpb_fp hpb_ry (hrel23.2.1 _ hb23_vals.1) (by simp [JointOdd1588.firstYIn]; exact hrel23.2.2 _ hb23_vals.2) hcleanIn23 hcleanOut23 have hpay_inv := Replay5.inverse_payload origin F.x (Y0 / 2) F.x_pos F.x_lt tr have hV_eq : Replay5.firstPayload false origin (P23.1, P23.2) = (Y0 / 2 * (F.x : Fp), 0) := by rw [Prod.mk.eta, ← hP23, Rolling1588.exitHeadPayload] simpa only [en, if_true] using hpay_inv have ha24_agR : AgreeOutsideR a24 (run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket false)) mFp (run (cut (xps k) 23) u23 s)) := by apply agreeOutsideR_of_agreeRY hfp23.1 apply basis_eq_of_regValue_eq have h1 := hfp23.2.2.1 have h2 := hfp23.2.2.2.2 rw [hV_eq] at h1 h2 simp only [JointOdd1588.firstYOut, HalfField.centerWord_zero] at h1 h2 exact h1.trans h2.symm -- Piece 24: `renameProgram phaseHost checkpointPrimitives.firstUnpack` (disjoint from `fieldR`!) let u24 := WindowFieldJourney.joinTapes (cut (xps k) 23) u23 mFp have hb24_eq : run (StairSchedule.fieldRename (Rolling1588.placedFirstPacket false)) mFp (run (cut (xps k) 23) u23 s) = run (cut (xps k) 24) u24 s := by have hc24 : cut (xps k) 24 = cut (xps k) 23 ++ StairSchedule.fieldRename (Rolling1588.placedFirstPacket false) := by rw [cut_succ (xps k) 23 (xL k 23 (by decide))]; rfl rw [hc24, WindowFieldJourney.joined] rw [hb24_eq] at ha24_agR have hag25 := agreeOutsideR_disjoint PFu firstUnpack_notFieldR ha24_agR m25 -- Relate `run (renameProgram phaseHost firstUnpack) m25 (run (cut (xps k) 24) u24 s)` to `run oldMulHead u25_H s`! let u25_H := WindowFieldJourney.joinTapes (Stair44MultiplyCut.beforeClose hostPlan) u24 m25 have hold25 : run WindowMiddleContract.oldMulHead u25_H s = run PFu m25 (run (cut (xps k) 24) u24 s) := by have hsh : WindowMiddleContract.oldMulHead = Stair44Kernel.beforeX := rfl rw [hsh, WindowStockHead.beforeM k F, Stair44Kernel.stockBeforeX, WindowFieldJourney.joined, ← Stair44MultiplyCut.selected k hostPlan] exact congrArg (run PFu m25) (by unfold cut; exact Stair44HostedCut.exit k 24 s ⟨F⟩ u24) -- Identify `Y0 / 2 * F.x = F.Y * F.x / 2` via `Stair44Kernel.mul_run` + `centerWord_injective`! have hY0_eq : Y0 / 2 * (F.x : Fp) = F.Y * (F.x : Fp) / 2 := by have hb24_R : regValue fieldR (run (cut (xps k) 24) u24 s).basis = centerWord (Y0 / 2 * (F.x : Fp)) := by rw [← hb24_eq] have h1 := hfp23.2.2.2.1 rw [hV_eq] at h1 exact h1 have hb25_R : regValue fieldR (run WindowMiddleContract.oldMulHead u25_H s).basis = centerWord (Y0 / 2 * (F.x : Fp)) := by rw [hold25, regValue_run_disjoint_R_mul PFu firstUnpack_notFieldR m25] exact hb24_R let mFull := WindowFieldJourney.joinTapes WindowMiddleContract.oldMulHead u25_H [] have hfull_R1 : regValue fieldR (run (Stair44Kernel.multiplication k) mFull s).basis = centerWord (Y0 / 2 * (F.x : Fp)) := by have hmt : Stair44WalkRun.backward true 409 ++ renameProgram Stair44Kernel.rawX (ParityXExitInverse23Kernel.x1N k) = Stair44Kernel.mulRawTail k := rfl rw [WindowMiddleContract.old_mul_head_split k, hmt, WindowFieldJourney.joined, regValue_run_disjoint_R_mul _ (mulRawTail_notFieldR k) []] exact hb25_R have hfull_R2 : regValue fieldR (run (Stair44Kernel.multiplication k) mFull s).basis = centerWord (F.Y * (F.x : Fp) / 2) := by have hpk_notR : ParityXExitInverse23Kernel.pkP ∉ fieldR := (notFieldR_iff _).mp (by decide) rw [Stair44Kernel.mul_run k F mFull, StairCallerReplay.hostedExit_pw Stair44Kernel.hostReplay k F.k_lt F.sharedNodup F.historyAbove F.selectorsAway F.transcript F.x F.Y F.x_pos F.x_lt s mFull F.input F.selectorG_zero F.selectorS_zero] have hkx := (ParityXExitInverse23Kernel.kernelX_correct k F.k_lt F.sharedNodup F.historyAbove F.selectorsAway F.transcript F.x F.Y F.x_pos F.x_lt s mFull F.input F.selectorG_zero F.selectorS_zero).2.1 have hnum_eq : skywalkArithmeticNumerator base = fieldR := rfl rw [hnum_eq] at hkx exact (regValue_pull_put_eq_R _ outMap_symm_fix_fieldR _ _ hpk_notR _).trans hkx exact centerWord_injective (hfull_R1.symm.trans hfull_R2) refine ⟨u25_H, by rw [hold25]; exact hag25, ?_⟩ have ha25_R : regValue fieldR (run PFu m25 a24).basis = P1Life.oddWord (Y0 / 2 * (F.x : Fp)) := by rw [regValue_run_disjoint_R_mul PFu firstUnpack_notFieldR m25 a24] have h1 := hfp23.2.1 rw [hV_eq] at h1 exact h1 rw [← hY0_eq]; exact ha25_R end ECDSAAdd.Entrant.OddStockLockstep end end -- ==== end OddLockstepMul ==== -- ==== begin MainTail ==== section section section namespace ECDSAAdd.Entrant.StairPacket.WindowKernelReplay open Arithmetic MappedCompressed Secp256k1 Rolling1588Lifetime FlagEntry StairConcreteAssembly StockArchiveBanks open WindowMiddleContract WindowStockHead set_option maxRecDepth 16000 set_option maxHeartbeats 3000000 set_option linter.unusedVariables false attribute [local irreducible] run measurementCount wires renameProgram theorem tail (d:Bool) (n x:Nat) (nz:0 < x) (lt:x decide · have hlen : OddStockLockstep.fieldR.length = 256 := by simp [OddStockLockstep.fieldR, wireBlock_length] have hlt1 : regValue OddStockLockstep.fieldR tStd.basis < 2 ^ 256 := hlen ▸ Arithmetic.regValue_lt OddStockLockstep.fieldR tStd.basis rw [Nat.testBit_lt_two_pow (lt_of_lt_of_le hlt1 (Nat.pow_le_pow_right (by decide) (by omega))), Nat.testBit_lt_two_pow (lt_of_lt_of_le hlt (Nat.pow_le_pow_right (by decide) (by omega)))] private theorem stdOfOdd_agree (tOdd : State) (Y : Fp) : OddStockLockstep.AgreeOutsideR tOdd (OddStockLockstep.stdOfOdd tOdd Y) := ⟨rfl, fun q hq => by simp only [OddStockLockstep.stdOfOdd, dif_neg hq]⟩ theorem division_odd (geometry : OddEntryContract) : OddOuterBridge.EntryCorrectOdd WindowKernelPrograms.division := by intro hn hl ho hf x Y hx0 hx s tOdd m input hg hs phase eq val let tStd := OddStockLockstep.stdOfOdd tOdd Y have hag := stdOfOdd_agree tOdd Y let FStd : EntryFrame tStd := ⟨hn, hl, ho, hf, x, Y, hx0, hx, s, input, hg, hs, phase, fun q hq => (hag.2 q hq).symm.trans (eq q hq), stdOfOdd_val tOdd Y⟩ obtain ⟨head, v⟩ := geometry hn hl ho hf x Y hx0 hx s tOdd m input hg hs phase eq val have hrun : ∃ old, run WindowKernelPrograms.division m tOdd = run Stair44Kernel.division old tStd := by rw [div_head_split, old_div_head_split] obtain ⟨post, close⟩ := tail false 85 x hx0 hx (by decide) (run divHead m tOdd) (run oldDivHead head tStd) (renameProgram Stair44WalkMap.first (FrontierEntry1591NativeH.inverse base)) (m.drop (measurementCount divHead)) v (div_endpoint FStd head) refine ⟨pfx (measurementCount oldDivHead) head ++ post, ?_⟩ rw [Stair44PointSecond.joinRecords, run_append divHead, run_take] exact close obtain ⟨old, hsame⟩ := hrun dsimp only rw [hsame] exact Stair44Kernel.division_correct hn hl ho hf x Y hx0 hx s tStd old input hg hs phase (fun q hq => (hag.2 q hq).symm.trans (eq q hq)) (stdOfOdd_val tOdd Y) private theorem outMap_clean_exit {k : Nat} {s : State} (F : ExitFrame k s) : pullState Stair44Kernel.outMap.symm s = s := by let pairs : List (Wire × Wire) := [(base 1542, base 500), (base 1026, base 501), (base 1541, base 502), (base 723, base 503), (base 724, base 504)] let ok (q : Wire) := phaseHost q ∈ skywalkSharedWires base ∧ phaseHost q ∉ wireBlock base 770 256 ∧ phaseHost q ∉ wireBlock base 2056 256 have small : ∀ ab ∈ pairs, ok ab.1 ∧ ok ab.2 := by unfold ok; decide +kernel have z (q : Wire) (hq : ok q) : (pullState phaseHost s).basis q = false := F.input.2.2 _ hq.1 hq.2.1 hq.2.2 have fixed : pullState Stair44Kernel.rawOut (pullState phaseHost s) = pullState phaseHost s := (Stair44PointMap.clean_chain pairs id _ _ (fun ab hab => ⟨z _ (small ab hab).1, z _ (small ab hab).2⟩)).mpr rfl have inv := congrArg (pullState Stair44Kernel.rawOut.symm) fixed rw [Stair44PlacedHead.unpull] at inv apply MappedCompressed.pullState_perm_injective phaseHost apply State.extensionality · rfl · funext q have hconj : ((phaseHost.symm.trans Stair44Kernel.rawOut).trans phaseHost).symm (phaseHost q) = phaseHost (Stair44Kernel.rawOut.symm q) := by simp only [Equiv.symm_trans_apply, Equiv.symm_symm, Equiv.symm_apply_apply] exact (congrArg s.basis hconj).trans (congrFun (congrArg State.basis inv.symm) q) private theorem regValue_pull_eq_R_tail (f : Wire → Wire) (hfix : ∀ q ∈ OddStockLockstep.fieldR, f q = q) (st : State) : regValue OddStockLockstep.fieldR (pullState f st).basis = regValue OddStockLockstep.fieldR st.basis := regValue_congr OddStockLockstep.fieldR (pullState f st).basis st.basis (fun q hq => by change st.basis (f q) = st.basis q; rw [hfix q hq]) private theorem regValue_run_disjoint_R_tail (P : Program) (h : ∀ q ∈ wires P, q ∉ OddStockLockstep.fieldR) (m : List Bool) (s : State) : regValue OddStockLockstep.fieldR (run P m s).basis = regValue OddStockLockstep.fieldR s.basis := regValue_congr OddStockLockstep.fieldR (run P m s).basis s.basis (fun q hq => run_preserves_outside P m s q (fun hw => h q hw hq)) private theorem pullState_basis_tail (f : Wire → Wire) (st : State) (q : Wire) : (pullState f st).basis q = st.basis (f q) := rfl private theorem pullState_phase_tail (f : Wire → Wire) (st : State) : (pullState f st).phase = st.phase := rfl private theorem unpull_symm (e : Equiv.Perm Wire) (s : State) : pullState e (pullState e.symm s) = s := by apply State.extensionality · rfl · funext q change s.basis (e.symm (e q)) = s.basis q rw [e.symm_apply_apply] theorem multiplication_odd (geometry : OddExitContract) : ∀ k, k < p → OddOuterBridge.ExitMatchesOdd (renameProgram Stair44Kernel.outMap.symm (WindowKernelPrograms.multiplication k)) k := by intro k hk hn hlo ho hf x Y hx0 hx s m input hg0 hs0 let F : ExitFrame k s := ⟨hk, hn, hlo, ho, hf, x, Y, hx0, hx, input, hg0, hs0⟩ obtain ⟨head, v⟩ := geometry k F (m.take (measurementCount mulHead)) obtain ⟨nOld, hAgHead, hValHead⟩ := OddStockLockstep.stockOddMulHead_agree_oldMulHead k F head have hEndOdd : Endpoint true x 424 (pullState phaseHost (run OddStockLockstep.stockOddMulHead head s)) := by obtain ⟨s0, enc, st, hpool⟩ := mul_endpoint k F nOld refine ⟨s0, enc, st, fun q hq => ?_⟩ have hq_notR : phaseHost q ∉ OddStockLockstep.fieldR := OddStockLockstep.fieldR_disjoint_pool (phaseHost q) (Stair44DivTerm.host_pool q (List.mem_toFinset.mp hq)) rw [pullState_basis_tail] have hhp := hpool q hq rw [pullState_basis_tail] at hhp exact (hAgHead.2 (phaseHost q) hq_notR).trans hhp obtain ⟨post, htail⟩ := tail true 4 x hx0 hx (by decide) (run mulHead (m.take (measurementCount mulHead)) s) (run OddStockLockstep.stockOddMulHead head s) (renameProgram Stair44Kernel.rawX (ParityXExitInverse23Kernel.x1N k)) (m.drop (measurementCount mulHead)) v hEndOdd have hmt : Stair44WalkRun.backward true 409 ++ renameProgram Stair44Kernel.rawX (ParityXExitInverse23Kernel.x1N k) = Stair44Kernel.mulRawTail k := rfl have hmul_eq : run (WindowKernelPrograms.multiplication k) m s = run (renameProgram phaseHost (Stair44Kernel.mulRawTail k)) post (run OddStockLockstep.stockOddMulHead head s) := by rw [mul_head_split k, run_append mulHead, ← hmt]; exact htail let mFull := WindowFieldJourney.joinTapes oldMulHead nOld post have hold_eq : run (Stair44Kernel.multiplication k) mFull s = run (renameProgram phaseHost (Stair44Kernel.mulRawTail k)) post (run oldMulHead nOld s) := by rw [old_mul_head_split k, hmt, WindowFieldJourney.joined] have hAgFull : OddStockLockstep.AgreeOutsideR (run (WindowKernelPrograms.multiplication k) m s) (run (Stair44Kernel.multiplication k) mFull s) := by rw [hmul_eq, hold_eq] exact OddStockLockstep.agreeOutsideR_disjoint _ (OddStockLockstep.mulRawTail_notFieldR k) hAgHead post have hValFull : regValue OddStockLockstep.fieldR (run (WindowKernelPrograms.multiplication k) m s).basis = P1Life.oddWord (Y * (x : Fp) / 2) := by rw [hmul_eq, regValue_run_disjoint_R_tail _ (OddStockLockstep.mulRawTail_notFieldR k) post] exact hValHead -- Conjugate by `outMap.symm` and relate `Stair44Kernel.multiplication k` to `put (run (kernelX k) m s) pkP flag`! have hren := run_rename Stair44Kernel.outMap.symm Stair44Kernel.outMap.symm.injective (WindowKernelPrograms.multiplication k) m s rw [outMap_clean_exit F] at hren have hout_eq : run (renameProgram Stair44Kernel.outMap.symm (WindowKernelPrograms.multiplication k)) m s = pullState Stair44Kernel.outMap (run (WindowKernelPrograms.multiplication k) m s) := by have h1 := congrArg (pullState Stair44Kernel.outMap) hren rwa [unpull_symm] at h1 have hold_eq_m : run (Stair44Kernel.multiplication k) mFull s = run (Stair44Kernel.multiplication k) m s := State.extensionality _ _ ((old_phase k F mFull).trans (old_phase k F m).symm) (Arithmetic.run_basis_records _ _ _ _ _ rfl) have href_eq : pullState Stair44Kernel.outMap (run (Stair44Kernel.multiplication k) mFull s) = ParityEven.put (run (ParityXExitInverse23Kernel.kernelX k) m s) ParityXExitInverse23Kernel.pkP (s.basis (base 2400) && decide (k < x)) := by rw [hold_eq_m, Stair44Kernel.mul_run k F m, unpull_symm] exact StairCallerReplay.hostedExit_pw Stair44Kernel.hostReplay k hk hn hlo ho hf x Y hx0 hx s m input hg0 hs0 dsimp only rw [hout_eq, ← href_eq] have hout_fix : ∀ q ∈ OddStockLockstep.fieldR, Stair44Kernel.outMap q = q := OddStockLockstep.outMap_fix_fieldR have hout_symm_fix : ∀ q ∈ OddStockLockstep.fieldR, Stair44Kernel.outMap.symm q = q := OddStockLockstep.outMap_symm_fix_fieldR refine ⟨by rw [pullState_phase_tail, pullState_phase_tail]; exact hAgFull.1, ?_, ?_⟩ · exact (regValue_pull_eq_R_tail (⇑Stair44Kernel.outMap) hout_fix _).trans hValFull · intro q hq have hnr : Stair44Kernel.outMap q ∉ OddStockLockstep.fieldR := by intro hmem have hfix := hout_symm_fix (Stair44Kernel.outMap q) hmem rw [Equiv.symm_apply_apply] at hfix exact hq (hfix.symm ▸ hmem) rw [pullState_basis_tail, pullState_basis_tail] exact hAgFull.2 (Stair44Kernel.outMap q) hnr end ECDSAAdd.Entrant.StairPacket.WindowKernelReplay end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldParity open Arithmetic MappedCompressed CodecBitSliceVerify WindowParityDirty set_option maxHeartbeats 2000000 set_option maxRecDepth 16000 set_option linter.unusedSimpArgs false def delta (d : Bool) (r : Nat) := ((parity (ArchivePortAction.code d)).testBit r) ^^ ((parity (StairArchiveNativeCut.canonical d d)).testBit r) def Active (j : Nat) := j=10 ∨ j=13 ∨ j=16 ∨ j=19 ∨ j=22 ∨ j=25 ∨ j=28 ∨ j=31 ∨ j=35 ∨ j=39 ∨ j=43 ∨ j=47 ∨ j=51 ∨ j=55 ∨ j=59 ∨ j=63 ∨ j=67 ∨ j=70 ∨ j=73 ∨ j=76 ∨ j=79 ∨ j=82 private theorem mesh : wires region⊆Finset.range 31 := ECDSAAdd.Entrant.WSlimMain.wires_subset_range_of_all (by decide +kernel) private theorem portDistinct : ∀ j∈([10,13,16,19,22,25,28,31,35,39,43,47,51,55,59,63,67,70,73,76,79,82]:List Nat), ((List.range 31).map (port j)).Nodup := by decide +kernel private theorem inj {j : Nat} (hj : Active j) : ∀a∈Finset.range 31,∀b∈Finset.range 31, port j a=port j b → a=b := by intro a ha b hb eq have mem : j∈([10,13,16,19,22,25,28,31,35,39,43,47,51,55,59,63,67,70,73,76,79,82]:List Nat) := by rcases hj with h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h <;> simp [h] have la := Finset.mem_range.mp ha have lb := Finset.mem_range.mp hb apply (List.Nodup.getElem_inj_iff (portDistinct j mem) (i:=a) (j:=b) (hi:=by simpa using la) (hj:=by simpa using lb)).mp simpa only [List.getElem_map,List.getElem_range] using eq private theorem center (j : Nat) : port j 16=FrontierEntry1591Field.host := by rfl theorem site_ne {j i : Nat} (hj : Active j) (hi : i<16) : site j i≠FrontierEntry1591Field.host := by intro bad have eq : port j i=port j 16 := by simpa only [port,if_pos hi,center] using bad have := inj hj i (Finset.mem_range.mpr (by omega)) 16 (by decide) eq omega def Data (s : State) (j : Nat) (d : Bool) (r : Nat) := ∀ i<16,s.basis (site j i)=(get (ArchivePortAction.code d) i).testBit r attribute [local irreducible] run region port site theorem bank_run (j : Nat) (hj : Active j) (d : Bool) (r : Nat) (hr : r<63145) (m : List Bool) (s : State) (h : Data s j d r) : run (bankCorrection j) m s = flip FrontierEntry1591Field.host (delta d r) s := by let loc := pullState (port j) s have dloc : ∀i<16,loc.basis i=(get (ArchivePortAction.code d) i).testBit r := by intro i hi; simpa only [loc,pullState,port,if_pos hi] using h i hi have hrun := run_rename_pool (port j) (Finset.range 31) (inj hj) region mesh m loc s rfl (fun _ _=>rfl) rw [region_run d r hr m loc dloc] at hrun apply State.extensionality · change (run (renameProgram (port j) region) m s).phase=s.phase exact hrun.1 funext q by_cases mem : q∈(Finset.range 31).image (port j) · obtain ⟨k,hk,rfl⟩ := Finset.mem_image.mp mem rw [show bankCorrection j=renameProgram (port j) region from rfl,hrun.2 k hk] by_cases e : k=16 · subst k; rw [center,at_flip,at_flip]; simp only [loc,pullState,center,delta] · have neq : port j k≠FrontierEntry1591Field.host := fun bad=>e (inj hj _ hk 16 (by decide) (bad.trans (center j).symm)) rw [at_other _ _ _ _ e,at_other _ _ _ _ neq]; rfl · have neq : q≠FrontierEntry1591Field.host := by intro bad; exact mem (Finset.mem_image.mpr ⟨16,by decide,(center j).trans bad.symm⟩) exact (run_rename_pool_outside _ _ _ mesh _ _ _ mem).trans (at_other _ _ _ _ neq).symm private theorem data_flip (s : State) (v : Bool) {j : Nat} (hj : Active j) {d r} (h : Data s j d r) : Data (flip FrontierEntry1591Field.host v s) j d r := by intro i hi; rw [at_other _ _ _ _ (site_ne hj hi)]; exact h i hi attribute [local irreducible] bankCorrection theorem correction_run (dirs : Nat→Bool) (rows : Nat→Nat) (m : List Bool) (s : State) (hr : ∀j, Active j → rows j<63145) (hd : ∀j, Active j→Data s j (dirs j) (rows j)) : run correction m s = flip FrontierEntry1591Field.host (((((((((((((((((((((delta (dirs 10) (rows 10) ^^ delta (dirs 13) (rows 13)) ^^ delta (dirs 16) (rows 16)) ^^ delta (dirs 19) (rows 19)) ^^ delta (dirs 22) (rows 22)) ^^ delta (dirs 25) (rows 25)) ^^ delta (dirs 28) (rows 28)) ^^ delta (dirs 31) (rows 31)) ^^ delta (dirs 35) (rows 35)) ^^ delta (dirs 39) (rows 39)) ^^ delta (dirs 43) (rows 43)) ^^ delta (dirs 47) (rows 47)) ^^ delta (dirs 51) (rows 51)) ^^ delta (dirs 55) (rows 55)) ^^ delta (dirs 59) (rows 59)) ^^ delta (dirs 63) (rows 63)) ^^ delta (dirs 67) (rows 67)) ^^ delta (dirs 70) (rows 70)) ^^ delta (dirs 73) (rows 73)) ^^ delta (dirs 76) (rows 76)) ^^ delta (dirs 79) (rows 79)) ^^ delta (dirs 82) (rows 82)) s := by have a0 : Active 10 := (Or.inl rfl) have a1 : Active 13 := (Or.inr (Or.inl rfl)) have a2 : Active 16 := (Or.inr (Or.inr (Or.inl rfl))) have a3 : Active 19 := (Or.inr (Or.inr (Or.inr (Or.inl rfl)))) have a4 : Active 22 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))) have a5 : Active 25 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))) have a6 : Active 28 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))) have a7 : Active 31 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))) have a8 : Active 35 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))) have a9 : Active 39 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))) have a10 : Active 43 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))))) have a11 : Active 47 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))))) have a12 : Active 51 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))))))) have a13 : Active 55 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))))))) have a14 : Active 59 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))))))))) have a15 : Active 63 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))))))))) have a16 : Active 67 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))))))))))) have a17 : Active 70 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))))))))))) have a18 : Active 73 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))))))))))))) have a19 : Active 76 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))))))))))))) have a20 : Active 79 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))))))))))))))) have a21 : Active 82 := (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (rfl)))))))))))))))))))))) simp only [correction,run_append,run_take] rw [ bank_run 10 a0 _ _ (hr _ a0) _ s (hd _ a0), bank_run 13 a1 _ _ (hr _ a1) _ _ (data_flip _ _ a1 (hd _ a1)), bank_run 16 a2 _ _ (hr _ a2) _ _ (data_flip _ _ a2 (data_flip _ _ a2 (hd _ a2))), bank_run 19 a3 _ _ (hr _ a3) _ _ (data_flip _ _ a3 (data_flip _ _ a3 (data_flip _ _ a3 (hd _ a3)))), bank_run 22 a4 _ _ (hr _ a4) _ _ (data_flip _ _ a4 (data_flip _ _ a4 (data_flip _ _ a4 (data_flip _ _ a4 (hd _ a4))))), bank_run 25 a5 _ _ (hr _ a5) _ _ (data_flip _ _ a5 (data_flip _ _ a5 (data_flip _ _ a5 (data_flip _ _ a5 (data_flip _ _ a5 (hd _ a5)))))), bank_run 28 a6 _ _ (hr _ a6) _ _ (data_flip _ _ a6 (data_flip _ _ a6 (data_flip _ _ a6 (data_flip _ _ a6 (data_flip _ _ a6 (data_flip _ _ a6 (hd _ a6))))))), bank_run 31 a7 _ _ (hr _ a7) _ _ (data_flip _ _ a7 (data_flip _ _ a7 (data_flip _ _ a7 (data_flip _ _ a7 (data_flip _ _ a7 (data_flip _ _ a7 (data_flip _ _ a7 (hd _ a7)))))))), bank_run 35 a8 _ _ (hr _ a8) _ _ (data_flip _ _ a8 (data_flip _ _ a8 (data_flip _ _ a8 (data_flip _ _ a8 (data_flip _ _ a8 (data_flip _ _ a8 (data_flip _ _ a8 (data_flip _ _ a8 (hd _ a8))))))))), bank_run 39 a9 _ _ (hr _ a9) _ _ (data_flip _ _ a9 (data_flip _ _ a9 (data_flip _ _ a9 (data_flip _ _ a9 (data_flip _ _ a9 (data_flip _ _ a9 (data_flip _ _ a9 (data_flip _ _ a9 (data_flip _ _ a9 (hd _ a9)))))))))), bank_run 43 a10 _ _ (hr _ a10) _ _ (data_flip _ _ a10 (data_flip _ _ a10 (data_flip _ _ a10 (data_flip _ _ a10 (data_flip _ _ a10 (data_flip _ _ a10 (data_flip _ _ a10 (data_flip _ _ a10 (data_flip _ _ a10 (data_flip _ _ a10 (hd _ a10))))))))))), bank_run 47 a11 _ _ (hr _ a11) _ _ (data_flip _ _ a11 (data_flip _ _ a11 (data_flip _ _ a11 (data_flip _ _ a11 (data_flip _ _ a11 (data_flip _ _ a11 (data_flip _ _ a11 (data_flip _ _ a11 (data_flip _ _ a11 (data_flip _ _ a11 (data_flip _ _ a11 (hd _ a11)))))))))))), bank_run 51 a12 _ _ (hr _ a12) _ _ (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (data_flip _ _ a12 (hd _ a12))))))))))))), bank_run 55 a13 _ _ (hr _ a13) _ _ (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (data_flip _ _ a13 (hd _ a13)))))))))))))), bank_run 59 a14 _ _ (hr _ a14) _ _ (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (data_flip _ _ a14 (hd _ a14))))))))))))))), bank_run 63 a15 _ _ (hr _ a15) _ _ (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (data_flip _ _ a15 (hd _ a15)))))))))))))))), bank_run 67 a16 _ _ (hr _ a16) _ _ (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (data_flip _ _ a16 (hd _ a16))))))))))))))))), bank_run 70 a17 _ _ (hr _ a17) _ _ (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (data_flip _ _ a17 (hd _ a17)))))))))))))))))), bank_run 73 a18 _ _ (hr _ a18) _ _ (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (data_flip _ _ a18 (hd _ a18))))))))))))))))))), bank_run 76 a19 _ _ (hr _ a19) _ _ (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (data_flip _ _ a19 (hd _ a19)))))))))))))))))))), bank_run 79 a20 _ _ (hr _ a20) _ _ (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (data_flip _ _ a20 (hd _ a20))))))))))))))))))))), bank_run 82 a21 _ _ (hr _ a21) _ _ (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (data_flip _ _ a21 (hd _ a21))))))))))))))))))))))] simp only [flip_twice,Bool.xor_assoc] end ECDSAAdd.Entrant.StairPacket.WindowFieldParity end section set_option maxRecDepth 30000 set_option linter.unusedVariables false namespace ECDSAAdd.Entrant.Window45Dialog open Arithmetic RecordedQuantum MeasuredCodec5 Baselines Secp256k1 ControlledPointLayout InputSentinel CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite ExitFusionResearch FrontierEntry1591Callers BalancedField Challenge ParityCarry FlagEntry ParityFinalBothInverse23Out ParityEven ParityUniform open FlagExit open ParityXExitInverse23Kernel ParityStageBothInverse23 A161Generic ParityXEntry open MappedCompressed Stair44PointMap set_option maxRecDepth 30000 set_option maxHeartbeats 8000000 attribute [local irreducible] run wires def logical (cx cy : Fp) := renameProgram outer.symm (StairPacket.WindowParityCaller.generic cx cy) def block (cx cy : Fp) := renameProgram (FlagTop.rho layout) (logical cx cy) def borrow (cx cy : Fp) := renameProgram (Equiv.swap layout.doubleSelect layout.control) (block cx cy) def middle (C : Point) (cx cy : Fp) := AboveFieldPointDevelop.encode C ++ AboveFieldPointDevelop.eraseB ++ borrow cx cy ++ AboveFieldPointDevelop.loadB ++ AboveFieldPointDevelop.decode C def finite (C : Point) (cx cy : Fp) := FlagTop.stageNew layout C (pkW layout) ++ middle C cx cy ++ ControlPointEncodingDevelop.borrowOut C def wrapper (C : Point) (cx cy : Fp) := renameProgram (Wrapper5.U layout) (finite C cx cy) def GenericReplay : Prop := ∀ (cx cy X Y : Fp) (G : Bool) (s : State) (e : Bool) (hv : PointDialogValues layout X Y G s.basis s.basis) (he : e = (if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val + (-cx).val) else false)) (hg : pkW layout ≠ layout.core.generic) (hx1 : X+(if G then -cx else 0)≠0) (hx2 : (X+(if G then -cx else 0))- (if G then ((Y+(if G then -cy else 0))/(X+(if G then -cx else 0)))* ((Y+(if G then -cy else 0))/(X+(if G then -cx else 0))) else 0)+ (if G then (SquareCarryLoan719BF.K:Fp) else 0)+ (if G then ReflectionE1.correction cx else 0)≠0) (m : List Bool), ∃ old, run (StairPacket.WindowParityCaller.generic cx cy) m (pullState outer.symm (put s (pkW layout) e)) = pullState outer.symm (run (genericN layout cx cy) old (put s (pkW layout) e)) theorem logicalReplay (H : GenericReplay) (cx cy X Y : Fp) (G : Bool) (s : State) (e : Bool) (hv : PointDialogValues layout X Y G s.basis s.basis) (he : e = (if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val + (-cx).val) else false)) (hg : pkW layout ≠ layout.core.generic) (hx1 : X+(if G then -cx else 0)≠0) (hx2 : (X+(if G then -cx else 0))- (if G then ((Y+(if G then -cy else 0))/(X+(if G then -cx else 0)))* ((Y+(if G then -cy else 0))/(X+(if G then -cx else 0))) else 0)+ (if G then (SquareCarryLoan719BF.K:Fp) else 0)+ (if G then ReflectionE1.correction cx else 0)≠0) (m : List Bool) : ∃ old, run (logical cx cy) m (put s (pkW layout) e) = run (genericN layout cx cy) old (put s (pkW layout) e) := by obtain ⟨old, eq⟩ := H cx cy X Y G s e hv he hg hx1 hx2 m refine ⟨old, MappedCompressed.pullState_perm_injective outer.symm ?_⟩ rw [logical,run_rename _ outer.symm.injective,eq] end ECDSAAdd.Entrant.Window45Dialog namespace ECDSAAdd.Entrant.StairSemanticFinal.Window45 section Generic open Arithmetic RecordedQuantum MeasuredCodec5 Baselines Secp256k1 ControlledPointLayout InputSentinel CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite ExitFusionResearch FrontierEntry1591Callers BalancedField Challenge ParityCarry FlagEntry ParityFinalBothInverse23Out ParityEven ParityUniform open FlagExit open ParityXExitInverse23Kernel ParityStageBothInverse23 A161Generic ParityXEntry set_option maxHeartbeats 8000000 in /-- Hosted counterpart of `FlagExit.generic_padp_true` (same hypotheses). -/ theorem routed_generic_eq_trueD (H : Window45Dialog.GenericReplay) (X Y cx cy : Fp) (s : State) (e : Bool) (hv : PointDialogValues layout X Y true s.basis s.basis) (he : e = (if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val + (-cx).val) else false)) (hXc : X≠cx) (hd : cx-genericX X Y cx cy≠0) (hg : pkW layout ≠ layout.core.generic) (m : List Bool) : ∃ m', run (Window45Dialog.logical cx cy) m (put s (pkW layout) e) = run (genericN layout cx cy) m' (put s (pkW layout) e) := by let a:=genericSlope X Y cx cy let d:=cx-genericX X Y cx cy have hvv:=generic_inplace_values X Y cx cy hXc have ha : (Y-cy)/(X-cx)=a:=rfl have hd4 : (X-cx)-a*a+(SquareCarryLoan719BF.K:Nat)+ReflectionE1.correction cx=d := by have e:=hvv.2.1 change (X-cx)-a*a+3*cx=d at e rw [←e] unfold ReflectionE1.correction ring apply Window45Dialog.logicalReplay H cx cy X Y true s e hv he hg · simpa only [if_true,←sub_eq_add_neg] using sub_ne_zero.mpr hXc · simp only [if_true,←sub_eq_add_neg,ha] rw [hd4] exact hd set_option maxHeartbeats 8000000 in /-- Hosted counterpart of `FlagExit.generic_padp_false` (same hypotheses). -/ theorem routed_generic_eq_falseD (H : Window45Dialog.GenericReplay) (X Y cx cy : Fp) (s : State) (e : Bool) (hv : PointDialogValues layout X Y false s.basis s.basis) (he : e = (if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val + (-cx).val) else false)) (hX0 : X≠0) (hg : pkW layout ≠ layout.core.generic) (m : List Bool) : ∃ m', run (Window45Dialog.logical cx cy) m (put s (pkW layout) e) = run (genericN layout cx cy) m' (put s (pkW layout) e) := by apply Window45Dialog.logicalReplay H cx cy X Y false s e hv he hg · simpa only [Bool.false_eq_true,if_false,add_zero] using hX0 · simpa only [Bool.false_eq_true,if_false,add_zero,sub_zero] using hX0 end Generic section Block open Arithmetic RecordedQuantum MeasuredCodec5 Baselines Secp256k1 ControlledPointLayout InputSentinel CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite ExitFusionResearch FrontierEntry1591Callers BalancedField Challenge ParityCarry FlagEntry ParityFinalBothInverse23Out FlagTop FlagExit OutFlag ParityEven ParityUniform FlagTop2 open ControlGenericPointDevelop open Classical in /-- Hosted counterpart of `ControlGenericPointDevelop.generic_pad_point`, as a run equality with the record block on the same states. -/ theorem routed_block_eq_pointD (H : Window45Dialog.GenericReplay) {cx cy : Fp} (hc : curve.toAffine.Nonsingular cx cy) (b : Bool) (R : Point) (t1 : State) (m2 : regValue layout.point.x t1.basis = codeX R) (t1y : regValue layout.point.y t1.basis = pointY R) (m3 : t1.basis layout.point.finite = false) (m4 : t1.basis layout.genericSelect = dialogOrdinary b R (.some hc)) (hE' : t1.basis layout.core.equalNegY = false) (hD : t1.basis layout.doubleSelect = false) (hclean : regValue layout.dialogPool t1.basis = 0) (m : List Bool) : ∃ m', run (renameProgram (rho layout) (Window45Dialog.logical cx cy)) m (put t1 (pkW layout) (dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < codeX R))) = run (renameProgram (rho layout) (genericN layout cx cy)) m' (put t1 (pkW layout) (dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < codeX R))) := by classical have hC : (.some hc : Point) ≠ 0 := WeierstrassCurve.Affine.Point.some_ne_zero hc have hgen : pkW layout ≠ layout.core.generic := pk_flag _ (by simp [ControlledPointLayout.inPlaceFlags]) have wrap : ∀ (X Y : Fp), X.val = codeX R → Y.val = pointY R → (PointDialogValues layout X Y (dialogOrdinary b R (.some hc)) (pullState (rho layout) t1).basis (pullState (rho layout) t1).basis → ∃ m', run (Window45Dialog.logical cx cy) m (put (pullState (rho layout) t1) (pkW layout) (if dialogOrdinary b R (.some hc) then decide (EntryFuseArithmetic.prime ≤ X.val + (-cx).val) else false)) = run (genericN layout cx cy) m' (put (pullState (rho layout) t1) (pkW layout) (if dialogOrdinary b R (.some hc) then decide (EntryFuseArithmetic.prime ≤ X.val + (-cx).val) else false))) → ∃ m', run (renameProgram (rho layout) (Window45Dialog.logical cx cy)) m (put t1 (pkW layout) (dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < codeX R))) = run (renameProgram (rho layout) (genericN layout cx cy)) m' (put t1 (pkW layout) (dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < codeX R))) := by intro X Y hXv hYv h have pvv := pulled_values t1 X Y (dialogOrdinary b R (.some hc)) (m2.trans hXv.symm) (t1y.trans hYv.symm) m3 m4 hE' hD hclean rw [flag_eq hc b R X hXv] obtain ⟨m', h'⟩ := h ⟨pvv.1, pvv.2.1, pvv.2.2.1, pvv.2.2.2, fun _ _ => rfl⟩ exact ⟨m', rename_put_eqD (rho layout) rho_injective (pkW layout) rho_pk _ _ t1 _ m m' h'⟩ by_cases hG : dialogOrdinary b R (.some hc) = true · obtain ⟨hb, h0, h1, h2, h3⟩ := (dialogOrdinary_true b R _ hC).mp hG cases R with | zero => exact absurd rfl h0 | @some x y hr => have den := dialog_denominators_ne_zero hr hc h1 h2 h3 apply wrap x y rfl rfl intro hv rw [hG] at hv exact routed_generic_eq_trueD H x y cx cy _ _ hv (by rw [hv.generic, hG]) den.1 den.2 hgen m · have hG' : dialogOrdinary b R (.some hc) = false := by simpa using hG cases R with | zero => apply wrap (FiniteFlagInterval.sentinel : Fp) 0 FiniteFlagInterval.sentinel_val rfl intro hv rw [hG'] at hv exact routed_generic_eq_falseD H _ 0 cx cy _ _ hv (by rw [hv.generic, hG']) FiniteFlagInterval.sentinel_ne_zero hgen m | @some x y hr => apply wrap x y rfl rfl intro hv rw [hG'] at hv exact routed_generic_eq_falseD H x y cx cy _ _ hv (by rw [hv.generic, hG']) (curve_x_ne_zero hr) hgen m set_option maxHeartbeats 8000000 in open Classical in /-- Hosted `generic_point_run`: the same complete output description. -/ theorem routed_hosted_generic_point_runD (H : Window45Dialog.GenericReplay) {cx cy : Fp} (hc : curve.toAffine.Nonsingular cx cy) (b : Bool) (R : Point) (s : State) (m : List Bool) (hx : regValue layout.point.x s.basis = codeX R) (hy : regValue layout.point.y s.basis = pointY R) (hf : s.basis layout.point.finite = false) (hg : s.basis layout.genericSelect = dialogOrdinary b R (.some hc)) (he : s.basis layout.core.equalNegY = false) (hd : s.basis layout.doubleSelect = false) (hz : regValue layout.dialogPool s.basis = 0) : let u:=put s (pkW layout) (dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < codeX R)) let t:=run (renameProgram (rho layout) (Window45Dialog.logical cx cy)) m u t.phase=s.phase ∧ regValue layout.point.x t.basis=codeX (if dialogOrdinary b R (.some hc) then R+.some hc else R) ∧ regValue layout.point.y t.basis=pointY (if dialogOrdinary b R (.some hc) then R+.some hc else R) ∧ t.basis (pkW layout)=vB hc b R ∧ ∀q,q∉layout.point.x++layout.point.y→q≠pkW layout→t.basis q=s.basis q := by obtain ⟨m', eq⟩ := routed_block_eq_pointD H hc b R s hx hy hf hg he hd hz m dsimp only rw [eq] exact generic_point_run hc b R s m' hx hy hf hg he hd hz set_option maxHeartbeats 8000000 in /-- Hosted `GenericFalseDevelop.mapped_false`: on a non-generic dialog state the hosted generic block is the identity. -/ theorem routed_hosted_mapped_falseD (H : Window45Dialog.GenericReplay) (X Y cx cy : Fp) (s : State) (m : List Bool) (hx : regValue layout.point.x s.basis=X.val) (hy : regValue layout.point.y s.basis=Y.val) (hf : s.basis layout.point.finite=false) (hg : s.basis layout.genericSelect=false) (he : s.basis layout.core.equalNegY=false) (hd : s.basis layout.doubleSelect=false) (hz : regValue layout.dialogPool s.basis=0) (hx0 : X≠0) : run (renameProgram (rho layout) (Window45Dialog.logical cx cy)) m s=s := by have pv:=pulled_values s X Y false hx hy hf hg he hd hz have hv:PointDialogValues layout X Y false (pullState (rho layout) s).basis (pullState (rho layout) s).basis:=⟨pv.1,pv.2.1,pv.2.2.1,pv.2.2.2,fun _ _=>rfl⟩ have hgen : pkW layout ≠ layout.core.generic := pk_flag _ (by simp [ControlledPointLayout.inPlaceFlags]) have hpk : s.basis (pkW layout) = false := (regValue_zero _ _).mp hz _ (pk_pool layout layout_widths) have hput : put s (pkW layout) false = s := by apply State.extensionality _ s · rfl funext q by_cases hp : q = pkW layout · subst q; simp [put, writeBit, hpk] · simp [put, writeBit, hp] have hgv : (pullState (rho layout) s).basis layout.core.generic = false := hv.generic obtain ⟨m', eq⟩ := routed_generic_eq_falseD H X Y cx cy (pullState (rho layout) s) false hv (by rw [hgv]; rfl) hx0 hgen m have lifted := rename_put_eqD (rho layout) rho_injective (pkW layout) rho_pk _ _ s false m m' eq rw [hput] at lifted rw [lifted] exact GenericFalseDevelop.mapped_false X Y cx cy s m' hx hy hf hg he hd hz hx0 end Block section Parked open Arithmetic RecordedQuantum MeasuredCodec5 Baselines Secp256k1 ControlledPointLayout InputSentinel CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite ExitFusionResearch FrontierEntry1591Callers BalancedField Challenge ParityCarry FlagEntry ParityFinalBothInverse23Out FlagTop FlagExit OutFlag ParityEven ParityUniform FlagTop2 open ControlGenericPointDevelop attribute [local irreducible] layout set_option maxHeartbeats 8000000 in open Classical in /-- Hosted `ControlGenericPointDevelop.generic_parked_run`. -/ theorem routed_hosted_parked_runD (H : Window45Dialog.GenericReplay) {cx cy : Fp} (hc : curve.toAffine.Nonsingular cx cy) (b : Bool) (R : Point) (s : State) (m : List Bool) (hx : regValue layout.point.x s.basis = codeX R) (hy : regValue layout.point.y s.basis = pointY R) (hf : s.basis layout.point.finite = false) (hg : s.basis layout.genericSelect = dialogOrdinary b R (.some hc)) (he : s.basis layout.core.equalNegY = false) (hd : s.basis layout.doubleSelect = false) (hz : ∀q∈layout.dialogPool,q≠pkW layout→s.basis q=false) (hpk:s.basis (pkW layout)=(dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < codeX R))) : let t:=run (Window45Dialog.block cx cy) m s t.phase=s.phase ∧ regValue layout.point.x t.basis=codeX (if dialogOrdinary b R (.some hc) then R+.some hc else R) ∧ regValue layout.point.y t.basis=pointY (if dialogOrdinary b R (.some hc) then R+.some hc else R) ∧ t.basis (pkW layout)=vB hc b R ∧ ∀q,q∉layout.point.x++layout.point.y→q≠pkW layout→t.basis q=s.basis q := by let a:=put s (pkW layout) false have ax:regValue layout.point.x a.basis=codeX R:= (put_reg _ _ _ _ (by decide +kernel)).trans hx have ay:regValue layout.point.y a.basis=pointY R:= (put_reg _ _ _ _ (by decide +kernel)).trans hy have af:a.basis layout.point.finite=false:=by simpa [a,put,writeBit,Function.update_apply, show layout.point.finite≠pkW layout by decide +kernel] using hf have ag:a.basis layout.genericSelect=dialogOrdinary b R (.some hc):=by simpa [a,put,writeBit,Function.update_apply, show layout.genericSelect≠pkW layout by decide +kernel] using hg have ae:a.basis layout.core.equalNegY=false:=by simpa [a,put,writeBit,Function.update_apply, show layout.core.equalNegY≠pkW layout by decide +kernel] using he have ad:a.basis layout.doubleSelect=false:=by simpa [a,put,writeBit,Function.update_apply, show layout.doubleSelect≠pkW layout by decide +kernel] using hd have az:regValue layout.dialogPool a.basis=0:=by apply (regValue_zero _ _).mpr intro q hq by_cases hp:q=pkW layout · simp [a,put,writeBit,hp] · simpa [a,put,writeBit,Function.update_apply,hp] using hz q hq hp have restore:put a (pkW layout) (dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < codeX R))=s:=by apply State.extensionality _ s · rfl funext q by_cases hp:q=pkW layout · subst q;simp [a,put,writeBit,←hpk] · simp [a,put,writeBit,hp] have h:=routed_hosted_generic_point_runD H hc b R a m ax ay af ag ae ad az dsimp only at h rw [restore] at h refine ⟨h.1,h.2.1,h.2.2.1,h.2.2.2.1,?_⟩ intro q hq hp exact (h.2.2.2.2 q hq hp).trans (by simp [a,put,writeBit,hp]) end Parked end ECDSAAdd.Entrant.StairSemanticFinal.Window45 namespace ECDSAAdd.Entrant.AboveFieldTagDevelop.LT11Final.Window45 open Arithmetic Challenge Secp256k1 Baselines ControlledPointLayout InputSentinel FlagTop FlagExit FlagTop2 ParityEven ControlGenericPointDevelop ControlPointEncodingDevelop open StairSemanticFinal StairSemanticFinal.Window45 attribute [local irreducible] layout run wires set_option maxHeartbeats 8000000 in open Classical in /-- Hosted `AboveFieldTagDevelop.generic_format_run`. -/ theorem routed_hosted_format_runD (H : Window45Dialog.GenericReplay) {cx cy : Fp} (hc : curve.toAffine.Nonsingular cx cy) (b : Bool) (R : Point) (s : State) (m : List Bool) (hx : regValue layout.point.x s.basis = formatX (.some hc) b (dialogOrdinary b R (.some hc)) R) (hy : regValue layout.point.y s.basis = formatY (.some hc) b (dialogOrdinary b R (.some hc)) R) (hf : s.basis layout.point.finite = false) (hg : s.basis layout.genericSelect = dialogOrdinary b R (.some hc)) (he : s.basis layout.core.equalNegY = false) (hd : s.basis layout.doubleSelect = false) (hz : ∀q∈layout.dialogPool,q≠FlagEntry.pkW layout→s.basis q=false) (hpk:s.basis (FlagEntry.pkW layout)=(dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < ControlSentinelDevelop.ordinaryX R))) : let G:=dialogOrdinary b R (.some hc) let O:=if G then R+.some hc else R let t:=run (Window45Dialog.block cx cy) m s t.phase=s.phase ∧ regValue layout.point.x t.basis=formatX (.some hc) b G O ∧ regValue layout.point.y t.basis=formatY (.some hc) b G O ∧ t.basis (FlagEntry.pkW layout)=vB hc b R ∧ ∀q,q∉layout.point.x++layout.point.y→q≠FlagEntry.pkW layout→t.basis q=s.basis q := by cases hG:dialogOrdinary b R (.some hc) · have hpk0:s.basis (FlagEntry.pkW layout)=false:=by simpa only [hG,Bool.false_and] using hpk have hclean:regValue layout.dialogPool s.basis=0:=by apply (regValue_zero _ _).mpr intro q hq by_cases hp:q=FlagEntry.pkW layout · simpa only [hp] using hpk0 · exact hz q hq hp let X: Fp:=formatX (.some hc) b false R let Y: Fp:=formatY (.some hc) b false R have hXv:X.val=formatX (.some hc) b false R:= ZMod.val_natCast_of_lt (format_bounds (.some hc) b false R).1 have hYv:Y.val=formatY (.some hc) b false R:= ZMod.val_natCast_of_lt (format_bounds (.some hc) b false R).2 have hid:=StairSemanticFinal.Window45.routed_hosted_mapped_falseD H X Y cx cy s m (by simpa only [hXv,hG] using hx) (by simpa only [hYv,hG] using hy) hf (hg.trans hG) he hd hclean (formatX_fp_ne_zero (.some hc) b false R) change run (Window45Dialog.block cx cy) m s=s at hid dsimp only rw [hid] simp only [Bool.false_eq_true,if_false] exact ⟨True.intro,by simpa only [hG] using hx,by simpa only [hG] using hy, by simpa only [vB,hG,Bool.false_and] using hpk0,fun _ _ _=>True.intro⟩ · have hx':regValue layout.point.x s.basis=codeX R:=by rw [codeX_ordinary] simpa only [formatX,hG,Bool.not_true,Bool.and_false,Bool.false_eq_true,if_false] using hx have hy':regValue layout.point.y s.basis=pointY R:=by simpa only [formatY,hG,Bool.not_true,Bool.and_false,Bool.false_eq_true,if_false] using hy have hpk':s.basis (FlagEntry.pkW layout)=(dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < codeX R)):=by simpa only [codeX_ordinary] using hpk have h:=routed_hosted_parked_runD H hc b R s m hx' hy' hf hg he hd hz hpk' dsimp only at h ⊢ simpa [hG,formatX,formatY,codeX_ordinary] using h end ECDSAAdd.Entrant.AboveFieldTagDevelop.LT11Final.Window45 namespace ECDSAAdd.Entrant.AboveFieldPointDevelop.LT11Final.Window45 open ControlPointEncodingDevelop open Arithmetic Challenge Secp256k1 Baselines ControlledPointLayout InputSentinel FlagTop FlagExit FlagTop2 ParityEven ControlGenericPointDevelop open StairSemanticFinal StairSemanticFinal.Window45 AboveFieldTagDevelop.LT11Final AboveFieldTagDevelop.LT11Final.Window45 attribute [local irreducible] layout run wires set_option maxHeartbeats 8000000 in open Classical in /-- The hosted middle block replays the record middle block on every state the record's `middle_sequence` starts from. -/ theorem routed_hostedMiddle_replayD (H : Window45Dialog.GenericReplay) {cx cy : Fp} (hc : curve.toAffine.Nonsingular cx cy) (b : Bool) (R : Point) (s : State) (hx : regValue layout.point.x s.basis = ControlSentinelDevelop.ordinaryX R) (hy : regValue layout.point.y s.basis = pointY R) (hb:s.basis layout.control=b) (hf : s.basis layout.point.finite = false) (hg : s.basis layout.genericSelect = dialogOrdinary b R (.some hc)) (he : s.basis layout.core.equalNegY = false) (hd : s.basis layout.doubleSelect = false) (hz : ∀q∈layout.dialogPool,q≠FlagEntry.pkW layout→s.basis q=false) (hpk:s.basis (FlagEntry.pkW layout)=(dialogOrdinary b R (.some hc) && decide ((triOf (.some hc)).A < ControlSentinelDevelop.ordinaryX R))) (m : List Bool) : ∃ m', run (Window45Dialog.middle (.some hc) cx cy) m s = run (middle (.some hc) cx cy) m' s := by let C:Point:=.some hc have eqH : Window45Dialog.middle C cx cy = (encode C ++ eraseB) ++ (Window45Dialog.borrow cx cy ++ (loadB ++ decode C)) := by simp only [Window45Dialog.middle, List.append_assoc] have eqR : middle C cx cy = (encode C ++ eraseB) ++ (borrowGeneric cx cy ++ (loadB ++ decode C)) := by simp only [middle, List.append_assoc] rw [eqH, eqR] apply StairCallerGeneric.mid_replay intro tape b' let G:=dialogOrdinary b R C have hG:G=ControlSentinelDevelop.generic C b R:= ControlSentinelDevelop.generic_agrees C R b (WeierstrassCurve.Affine.Point.some_ne_zero hc) have hcorner:(b && !G)=true→ControlSentinelDevelop.corner C R:=by rw [hG] cases b <;> by_cases hr:ControlSentinelDevelop.corner C R <;> simp [ControlSentinelDevelop.generic,hr] have hgb:G=true→b=true:=by rw [hG] cases b <;> simp [ControlSentinelDevelop.generic] let me := tape.take (measurementCount (encode C)) let ma := tape.drop (measurementCount (encode C)) have hsplit : run (encode C ++ eraseB) tape s = run eraseB ma (run (encode C) me s) := by rw [run_append] let a:=run (encode C) me s have hp:=encode_spec hc b G R s me hgb hcorner hx hy hb hg (fun i=>hz _ (work_pool i) (work_off_pk i)) have ha:XYResult s a (formatX C b G R) (formatY C b G R):=hp.1 have apool:∀q∈layout.dialogPool,q≠FlagEntry.pkW layout→a.basis q=false:=by intro q hq hpq exact (ha.rest q (pool_off_xy q hq)).trans (hz q hq hpq) have af:a.basis layout.point.finite=false:=(ha.rest _ finite_off_xy).trans hf have ag:a.basis layout.genericSelect=G:=(ha.rest _ generic_off_xy).trans hg have ab:a.basis layout.control=b:=(ha.rest _ control_off_xy).trans hb have ae:a.basis layout.core.equalNegY=false:=(ha.rest _ eneg_off_xy).trans he have ad:a.basis layout.doubleSelect=false:=(ha.rest _ double_off_xy).trans hd have apk:a.basis (FlagEntry.pkW layout)=(G && decide ((triOf C).A < ControlSentinelDevelop.ordinaryX R)):= (ha.rest _ (pool_off_xy _ (FlagEntry.pk_pool layout layout_widths))).trans hpk let u:=put a layout.control false have erase:run eraseB ma a=u:=by apply eraseB_run a ma (formatX C b G R) (formatY C b G R) ha.x ha.y af (fun q hq=>apool _ (marker_work_pool q hq) (marker_work_off_pk q hq)) rw [ag,format_recover C b G R hgb] exact ab have ux:regValue layout.point.x u.basis=formatX C b G R:= (put_reg _ _ _ _ (by decide +kernel)).trans ha.x have uy:regValue layout.point.y u.basis=formatY C b G R:= (put_reg _ _ _ _ (by decide +kernel)).trans ha.y have uf:u.basis layout.point.finite=false:=(put_away a _ _ false finite_off_control).trans af have ug:u.basis layout.genericSelect=G:=(put_away a _ _ false generic_off_control).trans ag have ue:u.basis layout.core.equalNegY=false:=(put_away a _ _ false eneg_off_control).trans ae have ud:u.basis layout.doubleSelect=false:=(put_away a _ _ false double_off_control).trans ad have ub:u.basis layout.control=false:=put_at _ _ _ have upool:∀q∈layout.dialogPool,q≠FlagEntry.pkW layout→u.basis q=false:=by intro q hq hpq exact (put_away a _ _ false (pool_off_control q hq)).trans (apool q hq hpq) have upk:u.basis (FlagEntry.pkW layout)=(G && decide ((triOf C).A < ControlSentinelDevelop.ordinaryX R)):= (put_away a _ _ false pk_off_control).trans apk rw [hsplit, erase] have gt:=generic_format_run hc b R u b' ux uy uf ug ue ud upool upk have ht:=routed_hosted_format_runD H hc b R u b' ux uy uf ug ue ud upool upk have gd:(run (genericBlock cx cy) b' u).basis layout.doubleSelect=false:= (gt.2.2.2.2 _ double_off_xy double_off_pk).trans ud have hd':(run (Window45Dialog.block cx cy) b' u).basis layout.doubleSelect=false:= (ht.2.2.2.2 _ double_off_xy double_off_pk).trans ud rw [borrowGeneric_run cx cy u b' ub ud gd] have hsw : run (Window45Dialog.borrow cx cy) b' u = run (Window45Dialog.block cx cy) b' u := by let perm := Equiv.swap layout.doubleSelect layout.control have pre : pullState perm u=u := FieldFrameOB5.pull_swap_zero _ _ u ud ub have postC := (ht.2.2.2.2 _ control_off_xy (by decide +kernel)).trans ub have post := FieldFrameOB5.pull_swap_zero _ _ _ hd' postC apply MappedCompressed.pullState_perm_injective perm rw [Window45Dialog.borrow,run_rename _ perm.injective,pre] exact post.symm rw [hsw] apply State.extensionality · exact ht.1.trans gt.1.symm · funext q by_cases hqx : q ∈ layout.point.x · exact (regValue_eq_iff _ _ _).mp (ht.2.1.trans gt.2.1.symm) q hqx by_cases hqy : q ∈ layout.point.y · exact (regValue_eq_iff _ _ _).mp (ht.2.2.1.trans gt.2.2.1.symm) q hqy by_cases hqp : q = FlagEntry.pkW layout · subst hqp exact ht.2.2.2.1.trans gt.2.2.2.1.symm · have hq : q ∉ layout.point.x ++ layout.point.y := by simp [hqx, hqy] exact (ht.2.2.2.2 q hq hqp).trans (gt.2.2.2.2 q hq hqp).symm theorem routed_finite (H : Window45Dialog.GenericReplay) {cx cy : Fp} (hc : curve.toAffine.Nonsingular cx cy) (b : Bool) (R : Point) (s : State) (fresh : List Bool) (hs : encodes b R s.basis) : ∃ old, run (Window45Dialog.wrapper (.some hc) cx cy) fresh s = run (AboveFieldPointDevelop.wrapperBorrow (.some hc) cx cy) old s := by let C : Point := .some hc let U : Equiv.Perm Wire := Wrapper5.U Baselines.layout have finiteReplay : ∀ t, Challenge.encodes b R t.basis → ∀ tape, ∃ old, run (Window45Dialog.finite C cx cy) tape t = run (AboveFieldPointDevelop.finiteBorrow C cx cy) old t := by intro t ht tape have hi := StairCallerMiddle.boundary_of_encodes b R t ht simpa only [Window45Dialog.finite, AboveFieldPointDevelop.finiteBorrow, List.append_assoc] using (append_replayD (FlagTop.stageNew Baselines.layout C (FlagEntry.pkW Baselines.layout)) (Window45Dialog.middle C cx cy) (AboveFieldPointDevelop.middle C cx cy) (ControlPointEncodingDevelop.borrowOut C) (fun st => Staged C R b st) (fun st hv records ↦ routed_hostedMiddle_replayD H hc b R st hv.x hv.y hv.control hv.finite hv.generic hv.eneg hv.double hv.clean hv.parked records) t tape (fun prefixTape ↦ stage_values hc b R t prefixTape hi)) have pulled_eq : pullState U s = s := by change pullState (Equiv.swap (Baselines.layout.core.poolWire 684) (Baselines.layout.core.poolWire 717)) s = s exact FieldFrameOB5.pull_swap_zero _ _ s (hs.2.2 _ (by decide +kernel)) (hs.2.2 _ (by decide +kernel)) have pulled_encoded : Challenge.encodes b R (pullState U s).basis := by rw [pulled_eq] exact hs obtain ⟨old, outer⟩ := rename_replayD U (Window45Dialog.finite C cx cy) (AboveFieldPointDevelop.finiteBorrow C cx cy) (fun t ↦ Challenge.encodes b R t.basis) finiteReplay s pulled_encoded fresh refine ⟨old, ?_⟩ simpa only [C, Window45Dialog.wrapper, AboveFieldPointDevelop.wrapperBorrow, U] using outer end ECDSAAdd.Entrant.AboveFieldPointDevelop.LT11Final.Window45 end section namespace ECDSAAdd.Entrant.StairPacket.WindowPointWord open Arithmetic MappedCompressed DirectSkywalk Secp256k1 Rolling1588Lifetime BalancedField ControlledPointLayout CompressedPointDialog ParityEven ParityXExitInverse23Kernel StairSemanticFinal Stair44Kernel Stair44PointMap Baselines StairConcreteAssembly set_option maxRecDepth 18000 set_option maxHeartbeats 2500000 attribute [local irreducible] run wires measurementCount def normalized (k : Nat) := renameProgram outMap.symm (WindowKernelPrograms.multiplication k) private theorem conjugate (p a : Equiv.Perm Wire) (q : Wire) : ((p.symm.trans a).trans p).symm (p q)=p (a.symm q) := by simp only [Equiv.symm_trans_apply,Equiv.symm_symm,Equiv.symm_apply_apply] private theorem conjugateInv (p a : Equiv.Perm Wire) (q : Wire) : ((p.symm.trans a).trans p).symm q=p (a.symm (p.symm q)) := by simp only [Equiv.symm_trans_apply,Equiv.symm_symm] private theorem clean {k : Nat} {s : State} (F : ExitFrame k s) : pullState outMap.symm s=s := by let pairs : List (Wire × Wire) := [(base 1542,base 500),(base 1026,base 501),(base 1541,base 502), (base 723,base 503),(base 724,base 504)] let ok (q : Wire) := phaseHost q∈skywalkSharedWires base ∧ phaseHost q∉wireBlock base 770 256 ∧ phaseHost q∉wireBlock base 2056 256 have small : ∀ab∈pairs,ok ab.1 ∧ ok ab.2 := by unfold ok; decide +kernel have z (q : Wire) (hq : ok q) : (pullState phaseHost s).basis q=false := F.input.2.2 _ hq.1 hq.2.1 hq.2.2 have fixed : pullState rawOut (pullState phaseHost s)=pullState phaseHost s := (clean_chain pairs id _ _ (fun ab hab => ⟨z _ (small ab hab).1,z _ (small ab hab).2⟩)).mpr rfl have inv := congrArg (pullState rawOut.symm) fixed rw [Stair44PlacedHead.unpull] at inv apply MappedCompressed.pullState_perm_injective phaseHost apply State.extensionality · rfl · funext q exact (congrArg s.basis (conjugate phaseHost rawOut q)).trans (congrFun (congrArg State.basis inv.symm) q) private theorem rawOutPreserves : PreservesCaller rawOut.symm := by unfold rawOut simp only [chain] repeat' apply preserves_symm_trans all_goals first | exact preserves_swap_symm _ _ (base_mem_caller _ (Or.inl (by decide))) (base_mem_caller _ (Or.inl (by decide))) | exact fun _ h => h private theorem keep : PreservesCaller outMap.symm := preserves_symm_trans _ _ (preserves_symm_trans _ _ preserves_phaseHost rawOutPreserves) preserves_phaseHost_symm private theorem normSupport (H:WindowKernelPrograms.Contracts) (k : Nat) : wires (normalized k)⊆callerDomain := rename_caller outMap.symm keep (WindowKernelPrograms.multiplication k) (H.mulSites k) -- `H.exit k` directly supplies `OddOuterBridge.ExitMatchesOdd (normalized k) k`. theorem physInv (q : Wire) : wireFn2 layout (outMap.symm q)=outer.symm (wireFn2 layout q) := by rw [show outMap.symm q=phaseHost (rawOut.symm (phaseHost.symm q)) from conjugateInv _ _ _] apply outer.injective rw [Equiv.apply_symm_apply] have e := (Stair44Placement.maps (rawOut.symm (phaseHost.symm q))).2.2.symm rw [Equiv.apply_symm_apply] at e simpa only [Stair44Placement.phys,Equiv.apply_symm_apply] using e theorem transport (f a b : Wire→Wire) (P : Program) (eq : ∀q,f (a q)=b (f q)) : renameProgram f (renameProgram a P)=renameProgram b (renameProgram f P) := (renameProgram_comp f a P).trans ((congrArg (fun g : Wire→Wire => renameProgram g P) (funext eq)).trans (renameProgram_comp b f P).symm) theorem fullWord (H:WindowKernelPrograms.Contracts) (k X Y : Nat) (hk : k H.exit k hk config.1 above config.2.1 config.2.2 X (Y:Fp) hp hx t records input hg hs) have place : renameProgram (wireFn2 layout) (normalized k)=renameProgram outer.symm C := transport (wireFn2 layout) outMap.symm outer.symm (WindowKernelPrograms.multiplication k) physInv have o : pullState outer.symm s=s := by have members : ∀ab∈earlyPairs,ab.1∈layout.dialogPool ∧ ab.2∈layout.dialogPool := by decide +kernel have f : pullState outer s=s := (clean_chain earlyPairs id s s (fun ab h => ⟨(regValue_zero _ _).mp sc _ (members ab h).1,(regValue_zero _ _).mp sc _ (members ab h).2⟩)).mpr rfl have u := congrArg (pullState outer.symm) f rw [Stair44PlacedHead.unpull] at u; exact u.symm rw [place] at W have e := run_rename outer.symm outer.symm.injective C m s rw [o] at e have e2 := congrArg (pullState outer) (e.symm) have unp : ∀ st, pullState outer (pullState outer.symm st) = st := fun st => State.extensionality _ _ rfl (funext fun q => by change st.basis (outer.symm (outer q)) = st.basis q rw [outer.symm_apply_apply]) rw [unp] at e2 simpa only [← e2] using W end ECDSAAdd.Entrant.StairPacket.WindowPointWord end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldParity open Arithmetic MappedCompressed CodecBitSliceVerify WindowParityDirty FrontierEntry1591Field set_option maxRecDepth 6000 set_option maxHeartbeats 1200000 set_option linter.unusedSimpArgs false private theorem stock_flip (m : List Bool) (s : State) : run StairSchedule.paritySetup m s=flip host (stockParity s) s := ParityHost5.setup_run controls host s m host_not_controls theorem setup_pair (rows : Nat→Nat) (dirs : Nat→Bool) (a b : State) (m : List Bool) (valid : ∀ j,Active j → rows j<63145) (rest : ∀i,Elsewhere i→a.basis (addr i)=b.basis (addr i)) (actual : ∀j,Active j→Data a j (dirs j) (rows j)) (stock : ∀j,Active j→∀i<16,b.basis (site j i)=(get (StairArchiveNativeCut.canonical (dirs j) (dirs j)) i).testBit (rows j)) : run setup m a=flip host (stockParity b) a := by have eq := fold_pair rows dirs a b rest actual stock have data : ∀ j, Active j→Data (flip host (stockParity a) a) j (dirs j) (rows j) := by intro j hj i hi; rw [at_other _ _ _ _ (site_ne hj hi)]; exact actual j hj i hi have cor := correction_run dirs rows (m.drop (measurementCount StairSchedule.paritySetup)) (flip host (stockParity a) a) valid data rw [setup,run_append,run_take,stock_flip,cor,flip_twice] change _=_ simp only [delta] at * rw [←eq,←Bool.xor_assoc,Bool.xor_self,Bool.false_xor] end ECDSAAdd.Entrant.StairPacket.WindowFieldParity end section namespace ECDSAAdd.Entrant.Window45Dialog open Arithmetic MappedCompressed Secp256k1 Baselines Challenge Stair44PointMap set_option maxRecDepth 30000 set_option maxHeartbeats 4000000 attribute [local irreducible] run wires private theorem swapComm (f : Wire → Wire) (inj : Function.Injective f) (a b : Wire) (fa : f a=a) (fb : f b=b) (q : Wire) : f (Equiv.swap a b q) = Equiv.swap a b (f q) := by by_cases ha : q=a · subst q; simp [fa,fb] by_cases hb : q=b · subst q; simp [fa,fb] have na : f q ≠ a := fun eq => ha (inj (eq.trans fa.symm)) have nb : f q ≠ b := fun eq => hb (inj (eq.trans fb.symm)) simp [Equiv.swap_apply_def,ha,hb,na,nb] private theorem chainComm (f : Wire → Wire) (inj : Function.Injective f) (ps : List (Wire × Wire)) (fixed : ∀ t ∈ ps, f t.1=t.1 ∧ f t.2=t.2) (q : Wire) : f (chain ps q) = chain ps (f q) := by induction ps generalizing q with | nil => rfl | cons t ts ih => obtain ⟨a,b⟩ := t have h := fixed (a,b) List.mem_cons_self change f (chain ts (Equiv.swap a b q)) = chain ts (Equiv.swap a b (f q)) rw [ih (fun z hz => fixed z (List.mem_cons_of_mem _ hz)),swapComm f inj a b h.1 h.2] private theorem placed (f : Wire → Wire) (inj : Function.Injective f) (fixed : ∀ t ∈ earlyPairs, f t.1=t.1 ∧ f t.2=t.2) (P : Program) : encode (renameProgram f P) = renameProgram f (encode P) := by simp only [encode,renameProgram_comp] congr 1 funext q exact (chainComm f inj earlyPairs fixed q).symm private theorem borrowPlaced (cx cy : Fp) : encode (borrow cx cy)=StairPacket.WindowParityCaller.borrowGeneric cx cy := by unfold borrow block rw [placed _ (Equiv.swap _ _).injective (by decide +kernel), placed _ FlagTop.rho_injective (by decide +kernel)] have undo (P : Program) : encode (renameProgram outer.symm P)=P := by rw [encode,renameProgram_comp] have idMap : (outer : Wire → Wire) ∘ outer.symm = id := funext outer.apply_symm_apply rw [idMap] exact StairField2V3Win.renameProgram_id' P rw [logical,undo] rfl private theorem app (P Q : Program) : encode (P++Q)=encode P++encode Q := by simp only [encode,renameProgram,List.map_append] private theorem wrapperPlaced (C : Point) (cx cy : Fp) : encode (wrapper C cx cy)=renameProgram (Wrapper5.U layout) (StairPacket.WindowParityCaller.finite C cx cy) := by rw [wrapper,placed _ (Wrapper5.U _).injective (by decide +kernel)] congr 1 simp only [finite,middle,StairPacket.WindowParityCaller.finite,app,borrowPlaced,List.append_assoc] private theorem outerClean {b : Bool} {R : Point} {s : State} (h : encodes b R s.basis) : pullState outer s=s := by have high : ∀ t ∈ earlyPairs, 514 ≤ t.1 ∧ 514 ≤ t.2 := by decide +kernel exact (clean_chain earlyPairs id s s (fun ab hab => ⟨h.2.2 _ (high ab hab).1,h.2.2 _ (high ab hab).2⟩)).mpr rfl private theorem transport (P : BasisState → Prop) (phase : Bool) (a b : State) (eq : a=b) (hb : b.phase=phase ∧ P b.basis) : a.phase=phase ∧ P a.basis := eq ▸ hb theorem correct (replay : GenericReplay) (C : Point) (b : Bool) (R : Point) : Triple (encodes b R) (StairPacket.WindowParityCaller.program C) (encodes b (if b then R+C else R)) := by intro s fresh hs cases C with | zero => exact AboveFieldPointDevelop.program_correct_Q .zero b R s fresh hs | @some cx cy hc => let C : Point := .some hc obtain ⟨old,eq⟩ := AboveFieldPointDevelop.LT11Final.Window45.routed_finite replay hc b R s fresh hs have spec := AboveFieldPointDevelop.program_correct_Q C b R s old hs let want := encodes b (if b then R+C else R) let reference := run (AboveFieldPointDevelop.wrapperBorrow C cx cy) old s change reference.phase=s.phase ∧ want reference.basis at spec have same := run_rename outer outer.injective (wrapper C cx cy) fresh s rw [outerClean hs,eq] at same change pullState outer (run (encode (wrapper C cx cy)) fresh s)=_ at same rw [wrapperPlaced] at same have strong := MappedCompressed.pullState_perm_injective outer (same.trans (outerClean spec.2).symm) let result := run (renameProgram (Wrapper5.U layout) (StairPacket.WindowParityCaller.finite C cx cy)) fresh s change result.phase=s.phase ∧ want result.basis exact transport want s.phase result reference strong spec end ECDSAAdd.Entrant.Window45Dialog namespace ECDSAAdd.Entrant.StairPacket.WindowPointCertificate theorem certificate (replay : Window45Dialog.GenericReplay): Challenge.Certificate WindowParityRelease.entry WindowParityRelease.bounds:= WindowParityRelease.certificateOfSemantics (Window45Dialog.correct replay) end ECDSAAdd.Entrant.StairPacket.WindowPointCertificate end section namespace ECDSAAdd.Entrant.StairPacket.WindowPointDivision open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines ControlledPointLayout CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite FlagEntry FlagExit DirectSkywalk ParityUniform ParityEven ParityXEntry FrontierEntry1591Callers Stair44PlacedHead set_option maxHeartbeats 3500000 set_option maxRecDepth 20000 attribute [local irreducible] run measurementCount fastConstAdd fusedY def part (cx cy : Fp) := Stair44PlacedHead.routed (-cx) (-cy) ++ WindowParityCaller.divide open Stair44PointDivision theorem stage (Klaw:WindowKernelPrograms.Contracts) (cx cy X Y : Fp) (G : Bool) (s : State) (m : List Bool) (v : PointDialogValues layout X Y G s.basis s.basis) (hx : X+(if G then -cx else 0)≠0) : let e := if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val+(-cx).val) else false let u := run (part cx cy) m (pullState Stair44PointMap.outer.symm (put s (pkW layout) e)) u.phase=s.phase ∧ PointDialogValues layout (X+(if G then -cx else 0)) ((Y+(if G then -cy else 0))/(X+(if G then -cx else 0))) G s.basis u.basis := by intro e u let P := fastConstAdd layout layout.point.x (-cx) ++ EntryFuseOdd.entryYAllOdd layout (-cy) let F := E1QubitPlacement.tickF layout let K := FrontierEntry1591Callers.entry WindowKernelPrograms.division layout let H := Stair44PlacedHead.routed (-cx) (-cy) let r := m.drop (measurementCount H) have config := MappedCompressed.LaneA.laneLogical_config have above : History5.HistoryAbove base := by intro j hj; simp [base] have add := fastStep_addX layout layout_widths layout_nodup X Y G s.basis (-cx) have div := OddOuterBridge.division_stepD_odd WindowKernelPrograms.division Klaw.divSites Klaw.enter layout layout_widths layout_nodup config.1 above config.2.1 config.2.2 (X+(if G then -cx else 0)) Y (-cy) G s.basis hx have joint := add.seq div have equiv : (fastConstAdd layout layout.point.x (-cx) ++ (EntryFuseOdd.entryYAllOdd layout (-cy) ++ K))=P++K := List.append_assoc _ _ _ |>.symm rw [equiv] at joint have ans := joint s (pfx (measurementCount P) [] ++ (pfx (measurementCount Stair44Splits.tick) [] ++ r)) v rw [run_pre,show K=Stair44Splits.tick++WindowParityCaller.divide from WindowKernelPrograms.div_split,run_pre, show Stair44Splits.tick=renameProgram Stair44PointMap.integerFirst F from rfl, encodedTick _ _ (OddOuterBridge.prepClean_odd layout layout_widths layout_nodup (-cx) (-cy) X Y G s v)] at ans have tr := encoded_head X Y (-cx) (-cy) s (m.take (measurementCount H)) v.x v.y v.clean dsimp only at tr rw [show plain (-cx) (-cy) = EntryFuseOdd.entryYAllOdd layout (-cy) ++ entryXNew layout (pkW layout) (-cx) from rfl, OddOuterBridge.head_eq_odd layout layout_widths layout_nodup cx cy X Y G s _ v.x v.y v.generic v.clean (by decide +kernel)] at tr have replay : u=run WindowParityCaller.divide r (pullState Stair44PointMap.integerFirst.symm (run F [] (run P [] s))) := by change run (H++WindowParityCaller.divide) m _=_ rw [run_append] exact congrArg (run WindowParityCaller.divide r) tr rw [replay] exact ans end ECDSAAdd.Entrant.StairPacket.WindowPointDivision end section namespace ECDSAAdd.Entrant.StairPacket.WindowPointSecond open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines ControlledPointLayout CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite FlagEntry FlagExit DirectSkywalk ParityUniform ParityEven ParityXExitInverse23Kernel ParityStageBothInverse23 A161Generic Stair44PointMap Stair44PlacedHead set_option maxHeartbeats 3000000 set_option maxRecDepth 20000 attribute [local irreducible] run measurementCount fastConstAdd open Stair44PointSecond def second (k cy cx : Fp) := Stair44Square.program k ++ WindowParityCaller.multiply cx.val ++ encodeY (EntryFuseOdd.exitYAllOdd layout cy) theorem productCut (H:WindowKernelPrograms.Contracts) (cx X Y : Fp) (G : Bool) (origin : BasisState) (w v : State) (rm : List Bool) (values : PointDialogValues layout X Y G origin w.basis) (hp : 0 pfx z [] ++ rm) (renameProgram_counts _ _).2.symm have hrun : run (FrontierEntry1591Callers.exit (WindowKernelPrograms.multiplication cx.val) layout) d w = run (WindowParityCaller.multiply cx.val) rm v := by rw [WindowKernelPrograms.mul_split, dt, run_pre, show run Stair44Splits.tick [] w = pullState integerFirst.symm (run F [] w) from encodedTick w [] values.clean, ← eq] have hY : ((Y.val : Nat) : Fp) = Y := ZMod.natCast_zmod_val Y have hX : ((X.val : Nat) : Fp) = X := ZMod.natCast_zmod_val X have hput_ph : ∀ (st : State) (q : Wire) (b : Bool), (put st q b).phase = st.phase := fun _ _ _ => rfl rcases ww with ⟨h1, h2, h3⟩ have ha_eq : a = run (FrontierEntry1591Callers.exit (kernelX cx.val) layout) d w := rfl have hout_eq : out = pullState outer (run (WindowParityCaller.multiply cx.val) rm v) := rfl rw [hrun, hput_ph, ← ha_eq, ← hout_eq] at h1 rw [hrun, hY, hX, ← hout_eq] at h2 rw [hrun, values.generic, pk_wire, ← ha_eq, ← hout_eq] at h3 exact ⟨h1, h2, h3⟩ theorem actual (H:WindowKernelPrograms.Contracts) (k cy cx X Y : Fp) (G : Bool) (origin : BasisState) (s : State) (v : PointDialogValues layout X Y G origin s.basis) (hx : X-(if G then Y*Y else 0)+(if G then (SquareCarryLoan719BF.K:Fp) else 0)+(if G then k else 0)≠0) (m : List Bool) : ∃ n,run (second k cy cx) m s=pullState outer.symm (run (secondStageN layout k cy cx) n s) := by let square := Stair44Square.program k let mul := WindowParityCaller.multiply cx.val let A := SquareCarryLoan719BF.program layout ++ fastConstAdd layout layout.point.x k let Z := X-(if G then Y*Y else 0)+(if G then (SquareCarryLoan719BF.K:Fp) else 0) let X' := Z+(if G then k else 0) obtain ⟨w,ew⟩ : ∃z : State, run A [] s=z := ⟨_,rfl⟩ let F := E1QubitPlacement.tickF layout let u := run F [] w let sm := m.take (measurementCount square) let tail := m.drop (measurementCount square) let rm := tail.take (measurementCount mul) let ym := tail.drop (measurementCount mul) let d := pfx (measurementCount F) [] ++ rm obtain ⟨plainOut,ep⟩ : ∃z : State,run (FrontierEntry1591Callers.exit (kernelX cx.val) layout) d w=z := ⟨_,rfl⟩ let flag := G && decide (cx.val hx ((ZMod.val_eq_zero X').mp eq)) have core : run oldSq [] s=u := stockCut k X Y G origin s w v ew have realSquare : run square sm s=pullState integerFirst.symm u := squareCut k X Y G origin s w sm v ew X'.val vw.x X'.isLt vw.clean have nw : (pullState outer (run mul rm (run square sm s))).phase = plainOut.phase ∧ regValue layout.point.y (pullState outer (run mul rm (run square sm s))).basis = EntryFuseOdd.oddWord (Y * X' / 2) ∧ ∀ q, q ∉ layout.point.y → (pullState outer (run mul rm (run square sm s))).basis q = (put plainOut (pkW layout) flag).basis q := by rw [←ep]; exact productCut H cx X' Y G origin w _ rm vw hp realSquare have o := exitX_correct layout layout_widths layout_nodup cx.val cx.isLt X'.val Y.val X'.isLt hp Y.isLt w d vw.x vw.y vw.clean rw [ep] at o have oc : regValue layout.dialogPool plainOut.basis=0 := (regValue_congr _ _ _ (fun q hq => o.2.2.2 q (((E1QubitPlacement.lay layout layout_widths layout_nodup q).2.1 hq).2) (((E1QubitPlacement.lay layout layout_widths layout_nodup q).2.1 hq).1))).trans vw.clean have oy : regValue layout.point.y plainOut.basis=centerWord ((Y*X')/2) := by simpa only [ZMod.natCast_zmod_val] using o.2.1 have stock := rest_pw layout layout_widths layout_nodup k cx X Y G origin s v hx [] rm have oldRest : run (restXX layout cx.val) rm (run oldSq [] s)=plainOut := by rw [←ep,exit_splitX,show d=pfx (measurementCount F) []++rm from rfl,run_pre,core] rw [oldRest] at stock let actual := run mul rm (run square sm s) have final := OddOuterBridge.pointSecond_rejoin_odd ((Y*X')/2) cy plainOut actual ym flag oy oc nw.1 nw.2.1 nw.2.2 refine ⟨pfx (measurementCount oldSq) [] ++ (pfx (measurementCount oldMul) rm ++ ym),?_⟩ change run ((square++mul)++_) m s=pullState outer.symm (run ((oldSq++oldMul)++_) _ s) rw [tripleRun square mul,chosenRun oldSq oldMul,stock] exact final end ECDSAAdd.Entrant.StairPacket.WindowPointSecond end section namespace ECDSAAdd.Entrant.StairPacket.WindowGeneric open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines ControlledPointLayout CompressedPointDialog CompressedAllocation CompressedFieldSupport EntryFuse EntryFuseFinite FlagEntry FlagExit DirectSkywalk ParityUniform ParityEven ParityXExitInverse23Kernel ParityStageBothInverse23 A161Generic Stair44PointMap Stair44PlacedHead set_option maxHeartbeats 2500000 set_option maxRecDepth 20000 attribute [local irreducible] run measurementCount theorem generic_eqD (K:WindowKernelPrograms.Contracts) (cx cy X Y : Fp) (G : Bool) (s : State) (e : Bool) (hv : PointDialogValues layout X Y G s.basis s.basis) (he : e=(if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val+(-cx).val) else false)) (hg : pkW layout≠layout.core.generic) (hx1 : X+(if G then -cx else 0)≠0) (hx2 : (X+(if G then -cx else 0))- (if G then ((Y+(if G then -cy else 0))/(X+(if G then -cx else 0)))* ((Y+(if G then -cy else 0))/(X+(if G then -cx else 0))) else 0)+ (if G then (SquareCarryLoan719BF.K:Fp) else 0)+(if G then ReflectionE1.correction cx else 0)≠0) (m : List Bool) : ∃ m',run (WindowParityCaller.generic cx cy) m (pullState outer.symm (put s (pkW layout) e))= pullState outer.symm (run (genericN layout cx cy) m' (put s (pkW layout) e)) := by subst e let H := WindowPointDivision.part cx cy let H0 := (entryYAll layout (-cy) ++ entryXNew layout (pkW layout) (-cx)) ++ restEntry layout let flag := if s.basis layout.core.generic then decide (EntryFuseArithmetic.prime ≤ X.val+(-cx).val) else false let s0 := put s (pkW layout) flag let s1 := run H0 [] s0 have hv0 := entryStageAll_step layout layout_widths layout_nodup X Y (-cx) (-cy) G s.basis hx1 s (padE layout cy cx []) hv rw [←(head_pad layout layout_widths layout_nodup cx cy X Y s hv.x hv.y hv.clean hg).run_eq []] at hv0 have hv1 := WindowPointDivision.stage K cx cy X Y G s (m.take (measurementCount H)) hv hx1 have eq : run H (m.take (measurementCount H)) (pullState outer.symm s0)=s1 := StairCallerEntry.state_eq_of_values hv1 hv0 obtain ⟨n,hn⟩ := WindowPointSecond.actual K (ReflectionE1.correction cx) cy cx _ _ G s.basis s1 hv0.2 hx2 (m.drop (measurementCount H)) refine ⟨pfx (measurementCount H0) []++n,?_⟩ have structureEq : WindowParityCaller.generic cx cy=H++WindowPointSecond.second (ReflectionE1.correction cx) cy cx := by simp only [H,WindowPointDivision.part,WindowPointSecond.second,WindowParityCaller.generic,Stair44PlacedHead.routed,OddOuterBridge.routedOdd,List.append_assoc] rw [structureEq,run_append,eq,genericN,run_pre] exact hn theorem certificate (K:WindowKernelPrograms.Contracts):Challenge.Certificate WindowParityRelease.entry WindowParityRelease.bounds:= WindowPointCertificate.certificate (generic_eqD K) end ECDSAAdd.Entrant.StairPacket.WindowGeneric end section namespace ECDSAAdd.Entrant.StairPacket.WindowFieldParity open Arithmetic MappedCompressed CodecBitSliceVerify WindowParityDirty FrontierEntry1591Field open StockArchiveBanks ExteriorPorts WindowFieldMask set_option maxRecDepth 12000 set_option maxHeartbeats 2000000 set_option linter.unusedSimpArgs false private theorem ids {j : Nat} (h : Active j) : j∈bankIds := by rcases h with h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h|h <;> simp [h,bankIds] private theorem alive (b : Bank) : Active (groupId b) := by revert b; unfold Active; decide +kernel private def offset (w : Wire) := let q := OB5.sig 511 w-16 let side := decide (1028 ≤ q) let v := if side then q-1028 else q let i := 2*(v%5)+side.toNat 8*(v/5)+(if i<5 then i else i-1) private theorem offset_all : ∀i:Fin 816, offset (addr i)=i.val := by decide +kernel private theorem addr_inj {a b : Nat} (ha : a<816) (hb : b<816) (eq : addr a=addr b) : a=b := (offset_all ⟨a,ha⟩).symm.trans ((congrArg offset eq).trans (offset_all ⟨b,hb⟩)) private theorem not_inside (i : Nat) (hi : Elsewhere i) : addr i∉archives := by intro h obtain ⟨b,q,e⟩ := StockArchiveBanks.bank_rep _ h have eq : addr (8*groupId b+q.val)=addr i := (native_ports b q).trans e have hlt : ∀ (v : Bank) (u : Fin 16), 8*groupId v+u.val < 816 := by decide +kernel have hno : ∀ (v : Bank) (u : Fin 16), ¬ Elsewhere (8*groupId v+u.val) := by intro v u; revert v u; unfold Elsewhere; decide +kernel have hi_lt : i < 816 := by unfold Elsewhere at hi; omega have k := addr_inj (a:=8*groupId b+q.val) (b:=i) (hlt b q) hi_lt eq exact hno b q (k ▸ hi) private theorem host_outside : host∉archives := by intro h obtain ⟨b,i,e⟩ := StockArchiveBanks.bank_rep _ h exact site_ne (alive b) i.isLt ((native_ports b i).trans e) theorem setup_through {d x a b rows} (pair : Paired d x a b rows) (m n : List Bool) : Paired d x (run setup m a) (run StairSchedule.paritySetup n b) rows := by let rr := fieldRows rows have rb (j : Nat) (hj : Active j) : rr j<63145 := by obtain ⟨v,rfl⟩ := idAt j (ids hj) rw [show rr (groupId v)=rows v from rowsAt rows v] exact (pair.labels _).1 have cs (j : Nat) (hj : Active j) : Data a j d (rr j) := by obtain ⟨v,rfl⟩ := idAt j (ids hj) intro i hi let t : Fin 16 := ⟨i,hi⟩ rw [show site (groupId v) i=siteAt v t from native_ports v t,show rr (groupId v)=rows v from rowsAt rows v] exact pair.custom v t have bs (j : Nat) (hj : Active j) : ∀i<16,b.basis (site j i)=(get (StairArchiveNativeCut.canonical d d) i).testBit (rr j) := by obtain ⟨v,rfl⟩ := idAt j (ids hj) intro i hi let t : Fin 16 := ⟨i,hi⟩ rw [show site (groupId v) i=siteAt v t from native_ports v t,show rr (groupId v)=rows v from rowsAt rows v] exact pair.stock v t have eff := setup_pair rr (fun _=>d) a b m rb (fun i hi=>pair.equality.2 _ (not_inside i hi)) cs bs rw [eff,show run StairSchedule.paritySetup n b=flip host (stockParity b) b from ParityHost5.setup_run controls host b n host_not_controls] refine ⟨⟨pair.equality.1,?_⟩,pair.labels,?_,?_⟩ · intro q h; by_cases e:q=host · subst q; simp only [at_flip,pair.equality.2 host host_outside] · rw [at_other _ _ _ _ e,at_other _ _ _ _ e]; exact pair.equality.2 q h · intro v i have ne : siteAt v i≠host := fun h=>site_ne (alive v) i.isLt ((native_ports v i).trans h) exact (at_other a (siteAt v i) host _ ne).trans (pair.custom v i) · intro v i have ne : siteAt v i≠host := fun h=>site_ne (alive v) i.isLt ((native_ports v i).trans h) exact (at_other b (siteAt v i) host _ ne).trans (pair.stock v i) end ECDSAAdd.Entrant.StairPacket.WindowFieldParity end section namespace ECDSAAdd.Entrant.StairPacket.WindowReleaseProof open Arithmetic MappedCompressed Secp256k1 StairSemanticFinal StairConcreteAssembly Rolling1588Lifetime set_option maxRecDepth 17000 set_option maxHeartbeats 3500000 set_option linter.unusedSimpArgs false attribute [local irreducible] wires renameProgram theorem division (g:wires WindowParityCaller.entryFieldHostedCut⊆callerDomain): wires WindowKernelPrograms.division⊆callerDomain:=by have original:=Stair44CallerSupport.division have f:=phaseHost_caller _ (WindowIntegerSites.forward true 4 (by decide)) have b:=phaseHost_caller _ (WindowIntegerSites.backward false 85 (by decide)) simp only [WindowKernelPrograms.division,WindowKernelPrograms.divBefore,WindowKernelPrograms.divAfter, WindowKernelPrograms.openWalk,Stair44Kernel.division,Stair44Kernel.divLead,Stair44Kernel.openR, Stair44DivTerm.routedClose,Stair44Outer.reverseEnd,Stair44DivTerm.head,Stair44DivTerm.P1, Six505.rename_append,wires_append,Finset.union_subset_iff] at original ⊢ tauto theorem multiplication (k:Nat) (g:wires (WindowParityCaller.exitFieldHosted checkpointPrimitives)⊆callerDomain): wires (WindowKernelPrograms.multiplication k)⊆callerDomain:=by have original:=Stair44CallerSupport.multiplication k have f:=phaseHost_caller _ (WindowIntegerSites.forward false 84 (by decide)) have b:=phaseHost_caller _ (WindowIntegerSites.backward true 4 (by decide)) simp only [WindowKernelPrograms.multiplication,WindowKernelPrograms.mulBefore,WindowKernelPrograms.mulAfter, WindowKernelPrograms.openWalk,Stair44Kernel.multiplication,Stair44Kernel.beforeX,Stair44Kernel.mulLead,Stair44Kernel.openR, Stair44Kernel.mulRawTail,Stair44Kernel.finishM,Stair44Outer.forwardEnd, Six505.rename_append,wires_append,Finset.union_subset_iff] at original ⊢ tauto theorem certificate (enter:WindowKernelReplay.OddEntryContract) (leave:WindowKernelReplay.OddExitContract): Challenge.Certificate WindowParityRelease.entry WindowParityRelease.bounds:= WindowGeneric.certificate ⟨division ExteriorCaller.entryFieldHostedCut_corrected,fun k=>multiplication k ExteriorCaller.exitFieldHosted_corrected, WindowKernelReplay.division_odd enter,WindowKernelReplay.multiplication_odd leave⟩ end ECDSAAdd.Entrant.StairPacket.WindowReleaseProof end end -- ==== end PrizeTail05e06b1e9 ==== -- ==== begin PrizeTaila22007f05 ==== section section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly Stair44Outer StockArchiveBanks StairV3Primitives StairPhysicalPhase def free (q:Wire):Bool:=!(205773114712187275122282265982765293605562563561189812287139891611589843445849597337103538494103336978362213714661966168451171851648096542974182730298938690363272409754698411001089266389078812285291449861766214794211333330842948986826888135717666812766266187006046759537055486313122308420383943763511987145123427459459516126487590571586904268547089117918011279036204763364901996160144223273307447875459693702879511493135943689368591511483737771298575471633784665705161978870541934630194604427888602806707054647786582470712223963572206094038073344:Nat).testBit q set_option maxRecDepth 30000 set_option maxHeartbeats 3000000 theorem occupied:∀(b:Bank)(i:Fin 16),free (siteAt b i)=false:=by decide +kernel def check (P:Program):Bool:=StairWireCheck.allSites free P theorem checked {P:Program} (h:check P=true):∀q∈archives,q∉wires P:=by intro q hq used obtain ⟨b,j,rfl⟩:=StockArchiveBanks.bank_rep q hq have safe:=StairWireCheck.allSites_sound free P h _ used rw [occupied] at safe contradiction end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.WindowExitFrame open Arithmetic MappedCompressed Secp256k1 StairField13V3 StairField13V3Clean open StairConcreteAssembly StairField2V3Replay StairField2V3Delta StairField2V3Couple open StairField2V3ExitPlanR StairField2V3LastRecX StairPhysicalLayout StairOuterPlacement open StairLoanExitReachX set_option maxRecDepth 12000 set_option maxHeartbeats 2000000 attribute [local irreducible] run wires renameProgram def stockPrefix (k : Nat) : Program := (((exitPieces cp hostPlan k).take 21).map Piece.H).flatten def Pinned (x : Nat) (ref : State) : Prop := ∃ record, FrameAt x 85 record ∧ AgreeOutside (Δv 87) ref record def Loan (ref : State) : Prop := ∀q ∈ StairSchedule.exclusiveRoles ++ hosts 87, ref.basis (fieldPlace q) = false private theorem ofMiddle (k x : Nat) (u : State) (hu : ExitMiddleX k x u) (m : List Bool) : Pinned x (run XS21 m u) := by obtain ⟨Q, link⟩ := rch21 k x (StairOpenWiring.exitPlans k x) StairOpenWiring.half760 obtain ⟨old,rel,reachable⟩ := link u u ⟨hu,rfl⟩ m exact ⟨_,WindowFieldView.exitFrame 85 x _ (StairField2V3ExitRec.reach_YE k x _ (reachX_E StairOpenWiring.half760 k x _ reachable)),rel.1⟩ private theorem logicalPinned (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : Pinned F.x (run (cut (xps k) 21) m s) := by rw [xcut21,run_append] exact ofMiddle k F.x _ ⟨s,F,rfl,_,rfl⟩ _ private theorem loanSite (q : Wire) (hq : q∈StairSchedule.exclusiveRoles ++ hosts 87) : fieldPlace q ∈ ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group false 0 1 84).map lowMap) := by rw [hp_group false 0 1 84 (by decide)] exact List.mem_map.mpr ⟨q,hq,rfl⟩ private theorem fullCutClean (k : Nat) (parts : StairField13V3Fresh.ExitClean k) : CutClean (ExitPre k) (cut (xps k) 21) ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group false 0 1 84).map lowMap) := parts.groupsBefore (21,0,1,84) (by simp) private theorem cutLoan {P : Program} {pre : State → Prop} (clean : CutClean pre P ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group false 0 1 84).map lowMap)) (s : State) (h : pre s) (m : List Bool) : Loan (run P m s) := by intro q hq exact clean s h m _ (loanSite q hq) private theorem logicalLoan (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : Loan (run (cut (xps k) 21) m s) := cutLoan (fullCutClean k (exitClean_of_planR StairOpenWiring.exitPlans StairOpenWiring.half760 k)) s ⟨F⟩ m theorem at_cut (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : Pinned F.x (run (stockPrefix k) m s) ∧ Loan (run (stockPrefix k) m s) := by have eq := Stair44HostedCut.exit k 21 s ⟨F⟩ m change run (stockPrefix k) m s = run (cut (xps k) 21) m s at eq rw [eq] exact ⟨logicalPinned k F m,logicalLoan k F m⟩ end ECDSAAdd.Entrant.StairPacket.WindowExitFrame end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly Stair44Outer StockArchiveBanks open StairV3Primitives StairPhysicalPhase StairPhysicalLayout set_option maxRecDepth 80000 set_option maxHeartbeats 6000000 attribute [local irreducible] wires def Clear (P:Program):Prop:=∀q∈archives,q∉wires P theorem both {A B:Program} (a:Clear A) (b:Clear B):Clear (A++B):=by intro q h rw [wires_append,Finset.mem_union] exact fun hit=>hit.elim (a q h) (b q h) private theorem rows87 {P:Program} (sub:∀q∈wires P,q∈StairPhysicalPrimitives.rowSitesL 87): Clear (renameProgram phaseRelabel P):=by have rowFree:∀q∈StairPhysicalPrimitives.rowSitesL 87,free (phaseRelabel q)=true:=by decide +kernel intro q h used obtain ⟨b,i,rfl⟩:=StockArchiveBanks.bank_rep _ h rw [renameProgram_support] at used obtain ⟨w,hw,eq⟩:=Finset.mem_image.mp used have ok:=rowFree w (sub w hw) rw [eq,occupied] at ok contradiction private theorem orientOK:Clear (renameProgram xRelabel (StairV3Primitives.orient 425)):=checked (by decide +kernel) private theorem packetOK:Clear (renameProgram (OB5.sig 425) (Rolling1588.Integer.packFirst base true 425)):=checked (by decide +kernel) private theorem unpacketOK:Clear (renameProgram (OB5.sig 425) (Rolling1588.unpackAtTick true 425)):=checked (by decide +kernel) private theorem moveOK:Clear (phaseBMove):=checked (by decide +kernel) private theorem restoreOK:Clear (phaseBReturn):=checked (by decide +kernel) theorem firstPack_free:Clear checkpointPrimitives.firstPack:=by exact both (both (both orientOK packetOK) moveOK) (rows87 (StairPhysicalPrimitives.pack_rows 87 (by decide))) theorem firstUnpack_free:Clear checkpointPrimitives.firstUnpack:=by exact both (both (both (rows87 (StairPhysicalPrimitives.unpack_rows 87 (by decide))) restoreOK) unpacketOK) orientOK end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.WindowExitPieces open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairField13V3 StairField13V3Clean open StairField2V3Replay StairHostsSchedule ExteriorPorts set_option maxRecDepth 12000 set_option maxHeartbeats 1800000 set_option linter.unusedSimpArgs false attribute [local irreducible] run wires def beforeParity := StairSchedule.hostedX ++ StairSchedule.fieldRename (exitLowPrefix hostPlan) def beforeParityOdd := StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.exitLowPrefixOdd hostPlan) def beforeGroup := StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram ++ StairSchedule.fieldRename (renameProgram Prefix1590.borrow (StairSchedule.reverseLast cp ++ hostedGroup hostPlan false 41 98 2 ++ StairSchedule.reverseSegment cp 22 12 490 500 ++ hostedGroup hostPlan false 36 96 2 ++ StairSchedule.reverseSegment cp 32 22 480 490 ++ hostedGroup hostPlan false 30 93 3 ++ StairSchedule.reverseSegment cp 47 32 465 480 ++ hostedGroup hostPlan false 22 90 3 ++ StairSchedule.reverseSegment cp 62 47 450 465 ++ hostedGroup hostPlan false 13 85 5 ++ StairSchedule.reverseSegment cp 87 62 425 450)) def beforeGroupOdd := StairSchedule.hostedX ++ StairSchedule.fieldRename FourScratchWindow.clearProgram ++ StairSchedule.fieldRename (renameProgram Prefix1590.borrow (StairSchedule.reverseLast cp ++ PackCutOddExit.cutRowOddPk 22 12 490 500 41 98 1 ++ PackCutOddExit.cutRowOddPk 32 22 480 490 36 96 1 ++ PackCutOddExit.cutRowOddPk 47 32 465 480 30 93 2 ++ PackCutOddExit.cutRowOddPk 62 47 450 465 22 90 2 ++ PackCutOddExit.cutRowOddPk 87 62 425 450 13 85 4)) def afterGroup := StairSchedule.fieldRename (FourScratchWindow.unprefix ++ StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket false) (Rolling1588.placedFirstPacket false)) def afterGroupOdd := StairSchedule.fieldRename (FourScratchWindow.unprefix ++ StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket false) (JointOdd1588.placedFirstPacketOdd WindowCallerCosts.oddFirstHalf false)) def leading (setup : Program) := setup ++ beforeParity ++ setup ++ beforeGroup def leadingOdd (setup : Program) := setup ++ beforeParityOdd ++ setup ++ beforeGroupOdd def field (setup group : Program) := leading setup ++ renameProgram fieldEquiv group ++ afterGroup def fieldOdd (setup group : Program) := leadingOdd setup ++ renameProgram fieldEquiv group ++ afterGroupOdd theorem ordinary : StairHostsSchedule.exitFieldHosted cp hostPlan = field StairSchedule.paritySetup (WindowFieldCosts.group false 1 84) := by simp only [field,leading,beforeParity,beforeGroup,afterGroup,StairHostsSchedule.exitFieldHosted, exitLowSuffix,exitHeadSuffix,WindowFieldCosts.group,←placedShape,fieldRename_append,rename_append,List.append_assoc] theorem corrected : WindowParityCaller.exitFieldHosted cp = fieldOdd WindowFieldParity.setup (WindowFieldCosts.group84 false) := by simp only [fieldOdd,leadingOdd,beforeParityOdd,beforeGroupOdd,afterGroupOdd,WindowParityCaller.exitFieldHosted, WindowCallerCosts.exitLowSuffix,WindowCallerCosts.exitHeadSuffix,←placedShape,fieldRename_append,rename_append,List.append_assoc] theorem prefix_shape (k : Nat) : WindowExitFrame.stockPrefix k = exitReferenceOpening ++ leading StairSchedule.paritySetup := by simp only [WindowExitFrame.stockPrefix,leading,beforeParity,beforeGroup,exitPieces,List.take_succ_cons, List.take_zero,groupSlot,lowCommon,common,List.map_cons,List.map_nil,List.flatten_cons, List.flatten_nil,List.append_nil,exitReferenceOpening,exitLowPrefix,exitHeadPrefix, hostedEndpoint,fieldRename_append,rename_append,List.append_assoc] theorem cutAfter (k : Nat) {s : State} (F : ExitFrame k s) (m n : List Bool) : let ref := run (leading StairSchedule.paritySetup) n (run exitReferenceOpening m s) WindowExitFrame.Pinned F.x ref ∧ WindowExitFrame.Loan ref := by have h := WindowExitFrame.at_cut k F (WindowFieldJourney.joinTapes exitReferenceOpening m n) rwa [prefix_shape,WindowFieldJourney.joined] at h end ECDSAAdd.Entrant.StairPacket.WindowExitPieces end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairHostsSchedule set_option maxHeartbeats 1800000 set_option maxRecDepth 35000 theorem clearSafe:Clear (FourScratchWindow.clearProgram):=checked (by decide +kernel) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairHostsSchedule set_option maxHeartbeats 1800000 set_option maxRecDepth 35000 theorem unprefixSafe:Clear (FourScratchWindow.unprefix):=checked (by decide +kernel) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines DirectSkywalk OB5 StairConcreteAssembly Stair44Outer set_option maxRecDepth 80000 set_option maxHeartbeats 6000000 private theorem wipeOK:Clear (skywalkArithmeticClear base):=checked (by decide +kernel) private theorem tickOK:Clear (renameProgram (sig 511) tickR):=checked (by decide +kernel) private theorem lastBackOK:Clear (renameProgram (sig 510) (Rolling1588.unpackAtTick false 510 ++ InverseFive23.candidate15)):=checked (by decide +kernel) private theorem mergedOK:Clear (Six505.merged6):=checked (by decide +kernel) private theorem packedOK:Clear (Six505.packP false):=checked (by decide +kernel) private theorem afterOK:Clear (ForwardSixPlacement.after false):=checked (by decide +kernel) theorem reverseEnd_free:Clear reverseEnd:=both (both wipeOK tickOK) lastBackOK theorem forwardEnd_free:Clear forwardEnd:=both (both (both mergedOK packedOK) afterOK) wipeOK end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StockArchiveBanks StairOuterPlacement theorem mapped {P:Program} (f:Wire→Wire) (inj:Function.Injective f) (fix:Fixed f) (clear:Clear P):Clear (renameProgram f P):=by intro q hit used rw [renameProgram_support] at used obtain ⟨v,use,eq⟩:=Finset.mem_image.mp used obtain ⟨b,i,rfl⟩:=StockArchiveBanks.bank_rep q hit have same:=inj (eq.trans (fix b i).symm) exact clear _ ((StockArchiveBanks.mem b i)) (same ▸ use) theorem fieldMapped {P:Program} (c:Clear P):Clear (renameProgram fieldEquiv P):=mapped _ fieldEquiv.injective fieldFix c def noBorrow:Equiv.Perm Wire:=⟨fun q=>Equiv.swap FrontierEntry1591Field.work FrontierEntry1591Field.host (HostOB5.hostSwap q), fun q=>HostOB5.hostSwap (Equiv.swap FrontierEntry1591Field.work FrontierEntry1591Field.host q), fun q=>by simp only [Equiv.swap_apply_self,HostOB5.hostSwap_invol],fun q=>by simp only [HostOB5.hostSwap_invol,Equiv.swap_apply_self]⟩ theorem noBorrowFixed:Fixed noBorrow:=by unfold Fixed;decide +kernel theorem fieldRename_free {P:Program} (c:Clear P):Clear (StairSchedule.fieldRename P):=by unfold StairSchedule.fieldRename StairSchedule.parityRename rw [renameProgram_comp] exact mapped _ noBorrow.injective noBorrowFixed c end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StockArchiveBanks StairPhysicalLayout StairPhysicalPrimitives set_option maxRecDepth 30000 set_option maxHeartbeats 3500000 theorem live_rows (B:Nat) (h:B∈budgets):∀q∈rowSitesL B,free q=true:=by have ok:budgets.all (fun b=>(rowSitesL b).all free)=true:=by decide +kernel exact List.all_eq_true.mp (List.all_eq_true.mp ok B h) theorem of_rows {B:Nat} (h:B∈budgets) {P:Program} (sub:∀q∈wires P,q∈rowSitesL B):Clear P:=by intro q hit used obtain ⟨b,i,rfl⟩:=StockArchiveBanks.bank_rep q hit have pass:=live_rows B h _ (sub _ used) rw [occupied] at pass contradiction theorem packFree (B:Nat) (h:B∈budgets):Clear (checkpointPrimitives.pack B):=of_rows h (pack_rows B h) theorem unpackFree (B:Nat) (h:B∈budgets):Clear (checkpointPrimitives.unpack B):=of_rows h (unpack_rows B h) theorem tfFree (B:Nat) (h:B∈budgets):Clear (checkpointPrimitives.tickForward (startFor B)):=of_rows h (tickForward_rows B h) theorem trFree (B:Nat) (h:B∈budgets):Clear (checkpointPrimitives.tickReverse (startFor B)):=of_rows h (tickReverse_rows B h) theorem mfFree (B:Nat) (h:B∈budgets):Clear (checkpointPrimitives.middleForward (startFor B+1) (endFor B-startFor B-1)):=of_rows h (middleForward_rows B h) theorem mrFree (B:Nat) (h:B∈budgets):Clear (checkpointPrimitives.middleReverse (startFor B+1) (StairPhysicalPrimitivesFix505.reverseEnd B-startFor B-1)):= of_rows h (StairPhysicalPrimitivesFix505.middleReverseFix_rows B h) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StockArchiveBanks StairArchiveInactive open StairConcreteAssembly StairHostsSchedule StairPhysicalLayout StairLoanGroupSupport set_option maxRecDepth 25000 set_option maxHeartbeats 3500000 attribute [local irreducible] wires renameProgram def src (j:Nat) (b:Bank) (i:Fin 16):Wire:=(shifted (Placement5.pi j)).symm (OB5.sig 511 (siteAt b i)) private def past (q:Wire):Bool:=(180939578497055528381340555886972105278508634386471692433344651056468842455492551968605753108720236510606156341375616254805889977801910117699643979599013346951331785567366854493054705746989936027101548883133753420750226259356410440051146502167827208772920478394656641415965145086803519272414845853530467261180647566909180489658681653141169362245534189956705224747886492356240073856782829434037665175587309741396045870269781290955637990096896:Nat).testBit q private theorem fixedSources:∀j∈List.range' 85 17,∀(b:Bank)(i:Fin 16),src j b i=src 85 b i:=by decide +kernel private theorem tagged:∀(b:Bank)(i:Fin 16),past (src 85 b i)=true:=by decide +kernel private theorem globals:∀q∈[base 2400,base 2409,base 2410]++Q6EndpointCell.ids.map base,past q=false:=by decide +kernel private theorem recent:∀j∈List.range' 85 17,∀i:Fin 10,past (History5.historyMap base (5*j) i)=false:=by decide +kernel private theorem miss (j:Nat) (hj:j∈List.range' 85 17) (b:Bank) (i:Fin 16):src j b i∉cover j:=by intro hit have yes:=tagged b i rw [←fixedSources j hj b i] at yes rcases List.mem_append.mp hit with g|hist · rw [globals _ g] at yes;contradiction · obtain ⟨k,_,eq⟩:=List.mem_map.mp hist rw [←eq,recent j hj k] at yes;contradiction private theorem packetFree (d:Bool) (j:Nat) (lo:85≤j) (hi:j<102):Clear (renameProgram (OB5.sig 511) (Rolling1588.packet d j)):=by intro q hit use obtain ⟨b,i,rfl⟩:=StockArchiveBanks.bank_rep q hit rw [renameProgram_support] at use obtain ⟨v,hv,eq⟩:=Finset.mem_image.mp use rw [Rolling1588.packet,renameProgram_support] at hv obtain ⟨w,hw,rfl⟩:=Finset.mem_image.mp hv have geom:src j b i=w:=by simp only [src,←eq,OB5.sig_invol 511 (by decide),Equiv.symm_apply_apply] apply miss j (List.mem_range'_1.mpr (by omega)) b i rw [geom] exact cover_read j (Rolling1588.basePacket_readSites_support d j hi hw) private theorem regular (d:Bool) (j n:Nat) (lo:85≤j) (hi:j+n≤102):Clear (renameProgram (OB5.sig 511) (Rolling1588.groups d j n)):=by induction n generalizing j with | zero=>intro q _;simp [Rolling1588.groups,PacketSequence.program,renameProgram,wires] | succ n ih=> have a:=packetFree d j lo (by omega) have b:=ih (j+1) (by omega) (by omega) cases d <;> simp only [Rolling1588.groups,PacketSequence.program,if_true,if_false,Bool.false_eq_true,Six505.rename_append] · exact both b a · exact both a b theorem groups (d:Bool) (k j n:Nat) (lo:85≤j) (hi:j+n≤102) (dk:k≤68) (safe:∀q∈hostPlan.group d k j n,free q=true):Clear (hostedGroup hostPlan d k j n):=by have roles:∀q∈StairSchedule.exclusiveRoles,free q=true:=by decide +kernel intro q hit used obtain ⟨b,i,rfl⟩:=StockArchiveBanks.bank_rep q hit obtain host|role|inner:=StairWireCheck.rebindMany_support _ _ _ _ used · have ok:=safe _ host;rw [occupied] at ok;contradiction · have ok:=roles _ (List.mem_of_mem_drop role);rw [occupied] at ok;contradiction · exact regular d j n lo hi _ ((StockArchiveBanks.mem b i)) (placedGroups_sub d k dk j n inner) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly set_option maxRecDepth 50000 set_option maxHeartbeats 3500000 private theorem segment425Ori:Clear (checkpointPrimitives.orient 450):=checked (by decide +kernel) private theorem segment425OriR:Clear (checkpointPrimitives.orientR 450):=checked (by decide +kernel) private theorem segment425P:Clear (renameProgram (OB5.sig 450) (Rolling1588.Integer.packFirst base true 450)):=checked (by decide +kernel) private theorem segment425U:Clear (renameProgram (OB5.sig 450) (Rolling1588.unpackAtTick true 450)):=checked (by decide +kernel) theorem forward425:Clear (StairSchedule.forwardSegment checkpointPrimitives 87 62 425 450):= both (both (both (both (both (unpackFree 87 (by decide)) (tfFree 87 (by decide))) (mfFree 87 (by decide))) segment425Ori) segment425P) (packFree 62 (by decide)) theorem reverse425:Clear (StairSchedule.reverseSegment checkpointPrimitives 87 62 425 450):= both (both (both (both (both (unpackFree 62 (by decide)) segment425U) segment425OriR) (mrFree 87 (by decide))) (trFree 87 (by decide))) (packFree 87 (by decide)) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly set_option maxRecDepth 50000 set_option maxHeartbeats 3500000 private theorem segment450Ori:Clear (checkpointPrimitives.orient 465):=checked (by decide +kernel) private theorem segment450OriR:Clear (checkpointPrimitives.orientR 465):=checked (by decide +kernel) private theorem segment450P:Clear (renameProgram (OB5.sig 465) (Rolling1588.Integer.packFirst base true 465)):=checked (by decide +kernel) private theorem segment450U:Clear (renameProgram (OB5.sig 465) (Rolling1588.unpackAtTick true 465)):=checked (by decide +kernel) theorem forward450:Clear (StairSchedule.forwardSegment checkpointPrimitives 62 47 450 465):= both (both (both (both (both (unpackFree 62 (by decide)) (tfFree 62 (by decide))) (mfFree 62 (by decide))) segment450Ori) segment450P) (packFree 47 (by decide)) theorem reverse450:Clear (StairSchedule.reverseSegment checkpointPrimitives 62 47 450 465):= both (both (both (both (both (unpackFree 47 (by decide)) segment450U) segment450OriR) (mrFree 62 (by decide))) (trFree 62 (by decide))) (packFree 62 (by decide)) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly set_option maxRecDepth 50000 set_option maxHeartbeats 3500000 private theorem segment465Ori:Clear (checkpointPrimitives.orient 480):=checked (by decide +kernel) private theorem segment465OriR:Clear (checkpointPrimitives.orientR 480):=checked (by decide +kernel) private theorem segment465P:Clear (renameProgram (OB5.sig 480) (Rolling1588.Integer.packFirst base true 480)):=checked (by decide +kernel) private theorem segment465U:Clear (renameProgram (OB5.sig 480) (Rolling1588.unpackAtTick true 480)):=checked (by decide +kernel) theorem forward465:Clear (StairSchedule.forwardSegment checkpointPrimitives 47 32 465 480):= both (both (both (both (both (unpackFree 47 (by decide)) (tfFree 47 (by decide))) (mfFree 47 (by decide))) segment465Ori) segment465P) (packFree 32 (by decide)) theorem reverse465:Clear (StairSchedule.reverseSegment checkpointPrimitives 47 32 465 480):= both (both (both (both (both (unpackFree 32 (by decide)) segment465U) segment465OriR) (mrFree 47 (by decide))) (trFree 47 (by decide))) (packFree 47 (by decide)) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly set_option maxRecDepth 50000 set_option maxHeartbeats 3500000 private theorem segment480Ori:Clear (checkpointPrimitives.orient 490):=checked (by decide +kernel) private theorem segment480OriR:Clear (checkpointPrimitives.orientR 490):=checked (by decide +kernel) private theorem segment480P:Clear (renameProgram (OB5.sig 490) (Rolling1588.Integer.packFirst base true 490)):=checked (by decide +kernel) private theorem segment480U:Clear (renameProgram (OB5.sig 490) (Rolling1588.unpackAtTick true 490)):=checked (by decide +kernel) theorem forward480:Clear (StairSchedule.forwardSegment checkpointPrimitives 32 22 480 490):= both (both (both (both (both (unpackFree 32 (by decide)) (tfFree 32 (by decide))) (mfFree 32 (by decide))) segment480Ori) segment480P) (packFree 22 (by decide)) theorem reverse480:Clear (StairSchedule.reverseSegment checkpointPrimitives 32 22 480 490):= both (both (both (both (both (unpackFree 22 (by decide)) segment480U) segment480OriR) (mrFree 32 (by decide))) (trFree 32 (by decide))) (packFree 32 (by decide)) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly set_option maxRecDepth 50000 set_option maxHeartbeats 3500000 private theorem segment490Ori:Clear (checkpointPrimitives.orient 500):=checked (by decide +kernel) private theorem segment490OriR:Clear (checkpointPrimitives.orientR 500):=checked (by decide +kernel) private theorem segment490P:Clear (renameProgram (OB5.sig 500) (Rolling1588.Integer.packFirst base true 500)):=checked (by decide +kernel) private theorem segment490U:Clear (renameProgram (OB5.sig 500) (Rolling1588.unpackAtTick true 500)):=checked (by decide +kernel) theorem forward490:Clear (StairSchedule.forwardSegment checkpointPrimitives 22 12 490 500):= both (both (both (both (both (unpackFree 22 (by decide)) (tfFree 22 (by decide))) (mfFree 22 (by decide))) segment490Ori) segment490P) (packFree 12 (by decide)) theorem reverse490:Clear (StairSchedule.reverseSegment checkpointPrimitives 22 12 490 500):= both (both (both (both (both (unpackFree 12 (by decide)) segment490U) segment490OriR) (mrFree 22 (by decide))) (trFree 22 (by decide))) (packFree 22 (by decide)) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorPorts open Arithmetic MappedCompressed Secp256k1 BalancedField Baselines DirectSkywalk OB5 StairConcreteAssembly Stair44Outer open StairPhysicalLayout StairTerminalV3 set_option maxRecDepth 80000 set_option maxHeartbeats 4800000 attribute [local irreducible] wires renameProgram theorem terminalFixed:Fixed terminalPerm:=by unfold Fixed;decide +kernel private theorem w:Clear (skywalkArithmeticClear base):=checked (by decide +kernel) private theorem f:Clear Six505.merged6:=checked (by decide +kernel) private theorem pk:Clear (Six505.packP true):=checked (by decide +kernel) private theorem a:Clear (ForwardSixPlacement.after true):=checked (by decide +kernel) private theorem t:Clear (renameProgram (sig 511) tickR):=checked (by decide +kernel) private theorem k:Clear (renameProgram (sig 510) (Rolling1588.unpackAtTick true 510 ++ InverseFive23.candidate15)):=checked (by decide +kernel) theorem forwardTerm:Clear checkpointPrimitives.forwardTerminal:= mapped _ terminalPerm.injective terminalFixed (both (both (both f pk) a) w) theorem reverseTerm:Clear checkpointPrimitives.reverseTerminal:= mapped _ terminalPerm.injective terminalFixed (both w (both t k)) theorem forwardLast:Clear (StairSchedule.forwardLast checkpointPrimitives):= both (both (both (unpackFree 12 (by decide)) (tfFree 12 (by decide))) (mfFree 12 (by decide))) forwardTerm theorem reverseLast:Clear (StairSchedule.reverseLast checkpointPrimitives):= both (both (both reverseTerm (mrFree 12 (by decide))) (trFree 12 (by decide))) (packFree 12 (by decide)) end ECDSAAdd.Entrant.StairPacket.ExteriorPorts end section namespace ECDSAAdd.Entrant.StairPacket.WindowExitStages open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly Rolling1588Lifetime open StockArchiveBanks WindowStartStates WindowMiddlePieces ExteriorPorts WindowExitPieces open WindowFieldMask WindowFieldJourney set_option maxHeartbeats 2000000 set_option maxRecDepth 15000 attribute [local irreducible] run measurementCount def endF := renameProgram phaseHost Stair44Outer.forwardEnd def unpack := renameProgram phaseHost checkpointPrimitives.firstUnpack def beginW := opening false 84 ++ endF def beginR := original false 84 ++ endF theorem refBegin : beginR = Stair44Kernel.mulLead := by simp only [beginR,original,endF,Stair44Kernel.mulLead,Stair44Kernel.finishM,Stair44Outer.forwardEnd,Six505.rename_append,List.append_assoc] theorem begin_pair (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : ∃n, Paired false F.x (run beginW m s) (run beginR n s) (StockRowVector.rows F.x p) := by let A := opening false 84 let B := original false 84 let t := m.drop (measurementCount A) refine ⟨joinTapes B m t,?_⟩ rw [beginW,beginR,joined,run_append,run_take] apply pairUnpull phaseHost phaseFix rw [endF,run_rename _ phaseHost.injective,run_rename _ phaseHost.injective] exact (WindowStartStates.multiplication k F m).through _ forwardEnd_free _ theorem begin_record (k : Nat) {s : State} (F : ExitFrame k s) (m : List Bool) : run beginR m s = run StairField2V3Replay.exitReferenceOpening m s := by rw [refBegin] exact WindowStockHead.leadM k F m def newP := (beginW ++ WindowParityCaller.exitFieldHosted checkpointPrimitives) ++ unpack def oldP := (beginR ++ StairHostsSchedule.exitFieldHosted checkpointPrimitives hostPlan) ++ unpack theorem newShape : WindowMiddleContract.mulHead = newP := by simp only [WindowMiddleContract.mulHead,WindowKernelPrograms.mulBefore,newP,beginW,opening,endF,unpack, Six505.rename_append,List.append_assoc] theorem oldShape : WindowMiddleContract.oldMulHead = oldP := by rw [oldP,refBegin] rfl end ECDSAAdd.Entrant.StairPacket.WindowExitStages end section namespace ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairHostsSchedule ExteriorPorts open StockArchiveBanks StairFirstPacketKernel set_option maxRecDepth 16000 set_option maxHeartbeats 1800000 attribute [local irreducible] wires theorem viaFree {P : Program} (touch : ∀q∈wires P,free q=true) : Clear P := by intro q h used obtain ⟨b,i,rfl⟩ := StockArchiveBanks.bank_rep q h exact Bool.noConfusion ((occupied b i).symm.trans (touch _ used)) end ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed end section namespace ECDSAAdd.Entrant.StairPacket.WindowExitReplay open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly Rolling1588Lifetime open StockArchiveBanks WindowStartStates WindowMiddlePieces ExteriorPorts WindowExitPieces open WindowFieldMask WindowFieldJourney WindowExitStages set_option maxRecDepth 14000 set_option maxHeartbeats 1800000 attribute [local irreducible] run measurementCount wires def leadingOK : Prop := ∀ (x : Nat) (rows : StockArchiveBanks.Bank → Nat) (a r : State) (m : List Bool), Paired false x a r rows → ∃n, Paired false x (run (leading WindowFieldParity.setup) m a) (run (leading StairSchedule.paritySetup) n r) rows abbrev C0 := initialCode false abbrev C1 := finalCode false (plan false) C0 def gW := renameProgram fieldEquiv (WindowFieldCosts.group84 false) def gR := renameProgram fieldEquiv (WindowFieldCosts.group false 1 84) def RStart (x : Nat) (rows : StockArchiveBanks.Bank → Nat) (s : State) (a r : State) : Prop := Paired false x a r rows ∧ ∃m, r = run StairField2V3Replay.exitReferenceOpening m s def RCut (x : Nat) (rows : StockArchiveBanks.Bank → Nat) (a r : State) : Prop := Paired false x a r rows ∧ WindowExitFrame.Pinned x r ∧ WindowExitFrame.Loan r private theorem beginRel (k : Nat) {s : State} (F : ExitFrame k s) : Relates beginW beginR (fun a r=>a=s ∧ r=s) (RStart F.x (StockRowVector.rows F.x p) s) := by rintro a r ⟨rfl,eq⟩ m subst r obtain ⟨n,rel⟩ := begin_pair k F m exact ⟨n,rel,n,begin_record k F n⟩ private theorem leadingRel (ok : leadingOK) (k : Nat) {s : State} (F : ExitFrame k s) (rows : StockArchiveBanks.Bank → Nat) : Relates (leading WindowFieldParity.setup) (leading StairSchedule.paritySetup) (RStart F.x rows s) (RCut F.x rows) := by rintro a r ⟨pair,u,rfl⟩ m obtain ⟨n,h⟩ := ok _ _ _ _ m pair exact ⟨n,h,cutAfter k F u n⟩ private theorem template (A P G T U : Program) : (A ++ ((P ++ G) ++ T)) ++ U = (((A ++ P) ++ G) ++ (T ++ U)) := by simp only [List.append_assoc] def leadingOddOK : Prop := ∀ (x : Nat) (rows : StockArchiveBanks.Bank → Nat) (a r : State) (m : List Bool), Paired false x a r rows → ∃ n, Paired false x (run (leadingOdd WindowFieldParity.setup) m a) (run (leadingOdd StairSchedule.paritySetup) n r) rows def gROdd := renameProgram fieldEquiv (WindowFieldCosts.ogroup false 1 84) def RCutOdd (x : Nat) (rows : StockArchiveBanks.Bank → Nat) (a r : State) : Prop := Paired false x a r rows ∧ ∃ origin, FrontierReplay1591.Context origin ∧ origin (base 2400) = true ∧ StairField2V3Seg.TraceOK x origin ∧ WindowFieldView.OCut 85 origin (StairField2V3Seg.pullIn r) private theorem leadingOddRel (ok : leadingOddOK) (k : Nat) {s : State} (F : ExitFrame k s) (rows : StockArchiveBanks.Bank → Nat) : Relates (leadingOdd WindowFieldParity.setup) (leadingOdd StairSchedule.paritySetup) (RStart F.x rows s) (RCutOdd F.x rows) := by rintro a r ⟨pair, u, rfl⟩ m obtain ⟨n, h⟩ := ok _ _ _ _ m pair have hsh : StairField2V3Replay.exitReferenceOpening ++ leadingOdd StairSchedule.paritySetup = OddStockLockstep.stockOddMulPrefix21 := by simp only [OddStockLockstep.stockOddMulPrefix21, OddStockLockstep.stockOddMulLeading, OddStockLockstep.stockOddMulBeforeParity, OddStockLockstep.stockOddMulBeforeGroup, leadingOdd, beforeParityOdd, beforeGroupOdd, List.append_assoc] have hcut := (OddStockLockstep.stockOddMul_cut21 k F (WindowFieldJourney.joinTapes StairField2V3Replay.exitReferenceOpening u n)).2 rw [← hsh, WindowFieldJourney.joined] at hcut exact ⟨n, h, hcut⟩ private theorem windowOddRel (x : Nat) (rows : StockArchiveBanks.Bank → Nat) : Relates gW gROdd (RCutOdd x rows) (Fits (fieldRows rows) C1) := by rintro a r ⟨pair, origin, ctx, en, tr, ocut⟩ m refine ⟨WindowFieldJourney.oreferenceTape false (plan false) m, ?_⟩ have ids : ∀ j ∈ bankIds, fieldRows rows j < 63145 := by intro j hj; obtain ⟨b, rfl⟩ := idAt j hj; rw [rowsAt]; exact (pair.labels b).1 have chronological : ∀ j ∈ bankIds, ArchiveStockRows.Chronology (5 * j - 5) x p (fieldRows rows j) := by intro j hj; obtain ⟨b, rfl⟩ := idAt j hj; rw [rowsAt] have times : ∀ k : StockArchiveBanks.Bank, 5 * groupId k - 5 = StockArchiveBanks.tick k := by decide +kernel rw [times]; exact (pair.labels b).2 apply hosted have hpull := fitsPull fieldEquiv fieldEquiv.injective fieldFix (fits pair) have hfe : pullState fieldEquiv r = StairField2V3Seg.pullIn r := rfl rw [hfe] at hpull ⊢ exact WindowFieldView.ocaller false x (fieldRows rows) ids chronological origin ctx en tr (pullState fieldEquiv a) r m hpull ocut private theorem newPathOdd : WindowMiddleContract.mulHead = (((beginW ++ leadingOdd WindowFieldParity.setup) ++ gW) ++ (afterGroupOdd ++ unpack)) := by rw [newShape, newP, corrected] exact template _ _ _ _ _ private theorem stockOddPath : OddStockLockstep.stockOddMulHead = (((beginR ++ leadingOdd StairSchedule.paritySetup) ++ gROdd) ++ (afterGroupOdd ++ unpack)) := by simp only [OddStockLockstep.stockOddMulHead, OddStockLockstep.stockOddMulLeading, OddStockLockstep.stockOddMulBeforeParity, OddStockLockstep.stockOddMulBeforeGroup, OddStockLockstep.stockOddMulAfterGroup, refBegin, leadingOdd, beforeParityOdd, beforeGroupOdd, gROdd, afterGroupOdd, unpack, JointOdd1588.hostedFirstPacketOdd, StairConcreteAssembly.hostPlan, List.append_assoc] private theorem pullState_basis_exit (f : Wire → Wire) (st : State) (q : Wire) : (pullState f st).basis q = st.basis (f q) := rfl theorem exitOdd (leadingLaw : leadingOddOK) (endClear : Clear (afterGroupOdd ++ unpack)) : WindowKernelReplay.OddExitContract := by intro k s F m have keep := pass (rows := fieldRows (StockRowVector.rows F.x p)) (cs := C1) (P := afterGroupOdd ++ unpack) (fun q h => endClear q ((whole_iff q).mp h)) have total := compose (compose (compose (beginRel k F) (leadingOddRel leadingLaw k F _)) (windowOddRel _ _)) keep obtain ⟨n, out⟩ := total s s ⟨rfl, rfl⟩ m rw [← newPathOdd, ← stockOddPath] at out have paired := fitsPull phaseHost phaseHost.injective phaseFix out obtain ⟨nOld, hAg, _⟩ := OddStockLockstep.stockOddMulHead_agree_oldMulHead k F n have nativeOld := WindowEndBytes.mul_native k F nOld have nativeOdd : ∀ b, nativeAt true b (StockRowVector.rows F.x p b) (pullState phaseHost (run OddStockLockstep.stockOddMulHead n s)) := by intro b i have hnotR : phaseHost (siteAt b i) ∉ OddStockLockstep.fieldR := OddStockLockstep.fieldR_disjoint_pool _ (Stair44DivTerm.host_pool _ (List.mem_toFinset.mp (StockInverseReplay.archives_pool _ (StockArchiveBanks.mem b i)))) have hb := nativeOld.bytes b i rw [pullState_basis_exit] at hb ⊢ exact (hAg.2 (phaseHost (siteAt b i)) hnotR).trans hb exact ⟨n, pairFinished paired nativeOld.ids nativeOdd⟩ end ECDSAAdd.Entrant.StairPacket.WindowExitReplay end section namespace ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairHostsSchedule ExteriorPorts open StockArchiveBanks StairFirstPacketKernel set_option maxRecDepth 16000 set_option maxHeartbeats 1800000 attribute [local irreducible] wires private theorem convert {P Q : Program} (env : wires P ⊆ wires Q ∪ StairBoundaryLoan.converterHosts.toFinset) (rec : wires Q ⊆ StairBoundaryLoan.converterLayout760.wires.toFinset) : Clear P := by have ok : (StairBoundaryLoan.converterLayout760.wires ++ StairBoundaryLoan.converterHosts).all free=true := by decide +kernel apply viaFree intro q hq apply List.all_eq_true.mp ok rcases Finset.mem_union.mp (env hq) with l|r · exact List.mem_append_left _ (List.mem_toFinset.mp (rec l)) · exact List.mem_append_right _ (List.mem_toFinset.mp r) theorem canon : Clear StairConcrete.bestLoans.canon := convert StairBoundaryLoan.canon760Loan_envelope (by rw [StairBoundaryLoan.canon760_eq] exact (HalfConvert.support _ StairBoundaryLoan.converterLayout760_facts.widths).2) theorem center : Clear StairConcrete.bestLoans.center := convert StairBoundaryLoan.center760Loan_envelope (by rw [StairBoundaryLoan.center760_eq] exact (HalfConvert.support _ StairBoundaryLoan.converterLayout760_facts.widths).1) theorem copy : Clear HalfFieldOB5.copyN := checked (by decide +kernel) end ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed end section namespace ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairHostsSchedule ExteriorPorts open StockArchiveBanks StairFirstPacketKernel set_option maxRecDepth 16000 set_option maxHeartbeats 1800000 attribute [local irreducible] wires theorem mulEndpoint : Clear (hostedEndpoint hostPlan false 68) := by have ok : StairSiteEasy.multEndL.all (fun q=>free (OB5.sig 511 q))=true := by decide +kernel apply viaFree intro q h have e : StairConcrete.bestLoans.endPacket false 68=StairEndpointLoan44.endPacket760Loan44 false := by simp only [StairConcrete.bestLoans,StairConcrete.endPacket,Bool.false_eq_true,if_false,if_true] rw [hostedEndpoint,StairSchedule.placedEndPacket,e,renameProgram_support] at h obtain ⟨q,hq,rfl⟩ := Finset.mem_image.mp h exact List.all_eq_true.mp ok q (StairSiteEasy.endPacket760_false_mem q (StairEndpointLoan44.endPacket760Loan44_support hq)) private def outward (q : Wire) := OB5.sig 511 (Equiv.swap (base 760) (base 717) (shifted Placement5.pi0 q)) private def inner (q : Wire) := Equiv.swap (base 719) (base 510) q theorem divEndpoint : Clear (renameProgram (OB5.sig 511) StairConcrete.bestLoans.divEndpoint) := by have ok : DecoderBiasReuse.fixedLayout.wires.all (fun q=>free (outward (inner q)))=true := by decide +kernel apply viaFree intro q h rw [renameProgram_support,StairConcrete.bestLoans_divEndpoint] at h obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp h unfold CompareDecoder.BoundaryLoan.endPacket760DivLoan at hy rw [renameProgram_support] at hy obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hy rw [renameProgram_support] at ha obtain ⟨b,hb,rfl⟩ := Finset.mem_image.mp ha rcases Finset.mem_union.mp (ControlLoan1589.loanWindow_support _ _ _ _ hb) with h|h · rw [Finset.mem_insert,Finset.mem_singleton] at h rcases h with rfl|rfl <;> decide +kernel · obtain ⟨z,hz,rfl⟩ := Finset.mem_image.mp h rw [wires_append,Finset.mem_union] at hz rcases hz with hz|hz · exact List.all_eq_true.mp ok z (List.mem_toFinset.mp (CompareDecoder.support (CompareDecoder.BoundaryLoan.Inclusion.cellDecoderLoan_sub hz))) · have hc := (InverseEndpointWires.pad_facts 507 (base 512)).2.2.2.1 hz rw [Finset.mem_singleton] at hc rw [hc] decide +kernel end ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed end section namespace ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairHostsSchedule ExteriorPorts open StockArchiveBanks StairFirstPacketKernel StairWireCheck set_option maxRecDepth 16000 set_option maxHeartbeats 1800000 attribute [local irreducible] wires theorem firstNo : ∀(b : Bank)(i : Fin 16), fpSup (siteAt b i)=false := by decide +kernel theorem noRole : ∀(b : Bank)(i : Fin 16), siteAt b i∉StairSchedule.exclusiveRoles := by decide +kernel theorem noHost : ∀(b : Bank)(i : Fin 16), siteAt b i∉StairPhysicalLayout.hosts 87 := by decide +kernel end ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed end section namespace ECDSAAdd.Entrant.StairPacket.WindowExitClear open Arithmetic MappedCompressed Secp256k1 Rolling1588Lifetime StairConcreteAssembly open StockArchiveBanks WindowExitPieces WindowExitStages ExteriorPorts StairField13V3 set_option maxRecDepth 12000 set_option maxHeartbeats 1200000 attribute [local irreducible] wires run measurementCount theorem renameClear (fn : Wire → Wire) (inj : Function.Injective fn) (fixed : Fixed fn) {P : Program} (clear : Clear P) : Clear (renameProgram fn P) := by intro q hq used rw [renameProgram_support] at used obtain ⟨r,hr,rfl⟩ := Finset.mem_image.mp used by_cases orig : r∈StockArchiveBanks.archives · exact clear r orig hr · exact archive_pre inj fixed r orig hq theorem fieldClear {P : Program} (clear : Clear P) : Clear (StairSchedule.fieldRename P) := by rw [fieldRename_eq] exact renameClear fieldMap fieldMap_injective (by unfold Fixed; decide +kernel) clear theorem after (f : Clear FourScratchWindow.unprefix) (g : Clear (StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket false) (Rolling1588.placedFirstPacket false))) : Clear (afterGroup ++ unpack) := both (fieldClear (both f g)) (renameClear phaseHost phaseHost.injective phaseFix firstUnpack_free) private theorem pass {d x rows P} (clear : Clear P) : Relates P P (fun a r=>Paired d x a r rows) (fun a r=>Paired d x a r rows) := by intro a r pair m exact ⟨m,pair.through P clear m⟩ private theorem parity {d x rows} : Relates WindowFieldParity.setup StairSchedule.paritySetup (fun a r=>Paired d x a r rows) (fun a r=>Paired d x a r rows) := by intro a r pair m exact ⟨m,WindowFieldParity.setup_through pair m m⟩ theorem leading (pre : Clear beforeParity) (next : Clear beforeGroup) : WindowExitReplay.leadingOK := by intro x rows a r m pair exact compose (compose (compose parity (pass pre)) parity) (pass next) a r pair m theorem leadingOdd (pre : Clear beforeParityOdd) (next : Clear beforeGroupOdd) : WindowExitReplay.leadingOddOK := by intro x rows a r m pair exact compose (compose (compose parity (pass pre)) parity) (pass next) a r pair m end ECDSAAdd.Entrant.StairPacket.WindowExitClear end section namespace ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairHostsSchedule ExteriorPorts open StockArchiveBanks StairFirstPacketKernel StairWireCheck set_option maxRecDepth 16000 set_option maxHeartbeats 1800000 attribute [local irreducible] wires private theorem table (d : Bool) : allSites fpSup (Rolling1588.placedFirstPacket d)=true := by cases d · exact passSup_false · exact passSup_true private theorem exclude (q : Wire) (h : q∈StockArchiveBanks.archives) : q∉StairPhysicalLayout.hosts 87 ∧ q∉StairSchedule.exclusiveRoles ∧ fpSup q=false := by obtain ⟨b,i,rfl⟩ := StockArchiveBanks.bank_rep q h exact ⟨noHost b i,noRole b i,firstNo b i⟩ private theorem rebind {P : Program} (hs : List Wire) (eq : hs=StairPhysicalLayout.hosts 87) (ok : allSites fpSup P=true) : Clear (StairLoan.rebindMany StairSchedule.exclusiveRoles hs P) := by intro q h used have neg := exclude q h rcases rebindMany_support StairSchedule.exclusiveRoles hs P q used with host | role | orig · exact neg.1 (eq ▸ host) · exact neg.2.1 role · exact Bool.noConfusion (neg.2.2.symm.trans (allSites_sound fpSup P ok q orig)) theorem first (d : Bool) : Clear (StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket d) (Rolling1588.placedFirstPacket d)) := rebind (hostPlan.firstPacket d) rfl (table d) theorem firstOdd (d : Bool) : Clear (StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket d) (JointOdd1588.placedFirstPacketOdd WindowCallerCosts.oddFirstHalf d)) := rebind (hostPlan.firstPacket d) rfl (JointOdd1588.placedFirstPacketOdd_passSup WindowCallerCosts.oddFirstHalf d (WindowCallerCosts.oddFirstHalf_support d)) end ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed end section namespace ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairHostsSchedule ExteriorPorts open StockArchiveBanks StairFirstPacketKernel set_option maxRecDepth 16000 set_option maxHeartbeats 1800000 attribute [local irreducible] wires theorem tail (other : Clear (hostedGroup hostPlan true 43 100 2)) : Clear (entryTailSuffix hostPlan) := both (both (both other divEndpoint) copy) canon theorem head (other : Clear (hostedGroup hostPlan false 43 100 2)) : Clear (exitHeadPrefix hostPlan) := both (both (both center copy) mulEndpoint) other end ECDSAAdd.Entrant.StairPacket.WindowExteriorFixed end section namespace ECDSAAdd.Entrant.StairPacket.WindowExitOuter open Arithmetic MappedCompressed StairConcreteAssembly StairHostsSchedule ExteriorPorts WindowExitPieces set_option maxRecDepth 12000 set_option maxHeartbeats 1600000 attribute [local irreducible] wires theorem hostedX : Clear StairSchedule.hostedX := checked (by decide +kernel) theorem ordinaryGroup (d : Bool) (k j n : Nat) (start : 85≤j) (bound : j+n≤102) (budget : k≤68) (tab : (hostPlan.group d k j n).all free=true) : Clear (hostedGroup hostPlan d k j n) := groups d k j n start bound budget (List.all_eq_true.mp tab) theorem other (d : Bool) : Clear (hostedGroup hostPlan d 43 100 2) := ordinaryGroup d 43 100 2 (by decide) (by decide) (by decide) (by cases d <;> decide +kernel) theorem pre : Clear beforeParity := by apply both hostedX apply fieldRename_free apply both _ unprefixSafe apply both clearSafe -- The outer field placement is applied once more by the caller. exact WindowExitClear.renameClear Prefix1590.borrow Prefix1590.borrow.injective (by unfold Fixed; decide +kernel) (WindowExteriorFixed.head (other false)) theorem preOdd : Clear beforeParityOdd := by have hsub : wires beforeParityOdd ⊆ wires beforeParity := by unfold beforeParityOdd beforeParity apply StairLoanGroupSupport.append_sub _ _ _ _ (Finset.Subset.refl _) unfold StairSchedule.fieldRename StairSchedule.parityRename exact StairLoanGroupSupport.rename_sub _ _ _ (StairLoanGroupSupport.rename_sub _ _ _ (OddFullPass.P1LifeLoan.exitLowPrefixOdd_wires_sub _)) exact fun q hq used => pre q hq (hsub used) theorem endPart : Clear (afterGroup ++ WindowExitStages.unpack) := WindowExitClear.after unprefixSafe (WindowExteriorFixed.first false) theorem endPartOdd : Clear (afterGroupOdd ++ WindowExitStages.unpack) := both (WindowExitClear.fieldClear (both unprefixSafe (WindowExteriorFixed.firstOdd false))) (WindowExitClear.renameClear Rolling1588Lifetime.phaseHost Rolling1588Lifetime.phaseHost.injective phaseFix firstUnpack_free) end ECDSAAdd.Entrant.StairPacket.WindowExitOuter end section namespace ECDSAAdd.Entrant.StairPacket.WindowExitReady open Arithmetic MappedCompressed StairConcreteAssembly StairHostsSchedule ExteriorPorts WindowExitPieces WindowExitOuter set_option maxRecDepth 14000 set_option maxHeartbeats 1800000 attribute [local irreducible] wires theorem before : Clear beforeGroup := by apply both (both hostedX (fieldRename_free clearSafe)) rw [placedShape] apply fieldMapped apply both _ reverse425 apply both _ (ordinaryGroup false 13 85 5 (by decide) (by decide) (by decide) (by decide +kernel)) apply both _ reverse450 apply both _ (ordinaryGroup false 22 90 3 (by decide) (by decide) (by decide) (by decide +kernel)) apply both _ reverse465 apply both _ (ordinaryGroup false 30 93 3 (by decide) (by decide) (by decide) (by decide +kernel)) apply both _ reverse480 apply both _ (ordinaryGroup false 36 96 2 (by decide) (by decide) (by decide) (by decide +kernel)) apply both _ reverse490 apply both _ (ordinaryGroup false 41 98 2 (by decide) (by decide) (by decide) (by decide +kernel)) exact reverseLast theorem beforeOdd : Clear beforeGroupOdd := by have hsub : wires beforeGroupOdd ⊆ wires beforeGroup := by unfold beforeGroupOdd beforeGroup apply StairLoanGroupSupport.append_sub _ _ _ _ (Finset.Subset.refl _) unfold StairSchedule.fieldRename StairSchedule.parityRename apply StairLoanGroupSupport.rename_sub apply StairLoanGroupSupport.rename_sub apply StairLoanGroupSupport.rename_sub exact PackCutOddExit.cutRows_sub exact fun q hq used => before q hq (hsub used) theorem exitOdd : WindowKernelReplay.OddExitContract := WindowExitReplay.exitOdd (WindowExitClear.leadingOdd preOdd beforeOdd) endPartOdd end ECDSAAdd.Entrant.StairPacket.WindowExitReady end end -- ==== end PrizeTaila22007f05 ==== -- ==== begin Main ==== section section namespace ECDSAAdd.Entrant.StairPacket.ExteriorEntryCut open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairField13V3 StairField13V3Clean open StairField2V3Replay StairField2V3Couple StairField2V3Entry StairField2V3Seg StairField2V3LastRecX StairField2V3Delta open StairField2V3EntryPlanR StairOpenWiring StairOuterPlacement StairPhysicalLayout set_option maxRecDepth 14000 set_option maxHeartbeats 1800000 attribute [local irreducible] run measurementCount private theorem pin (x:Nat) (r record:State) (h:RowRelEn x 87 (R0++firstPkt) r record): FrameAt x 1 record ∧ AgreeOutside (Δv 87) r record:=by obtain ⟨rel,root,tape,⟨F,fx⟩,reach⟩:=h have pinned:=g_first root F tape rw [fx] at pinned exact ⟨reach.symm ▸ pinned.1,rel.1⟩ def stockPrefix:Program:=(((entryPieces cp hostPlan).take 3).map Piece.H).flatten def Pinned (x:Nat) (ref:State):Prop:=∃record,FrameAt x 1 record ∧ AgreeOutside (Δv 87) ref record def Loan (ref : State) : Prop := ∀q ∈ StairSchedule.exclusiveRoles ++ hosts 87, ref.basis (fieldPlace q) = false private theorem loanSite (q : Wire) (hq : q∈StairSchedule.exclusiveRoles ++ hosts 87) : fieldPlace q ∈ ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group true 0 1 84).map lowMap) := by rw [hp_group true 0 1 84 (by decide)] exact List.mem_map.mpr ⟨q,hq,rfl⟩ private theorem fullCutClean (parts:StairField13V3Fresh.EntryClean): CutClean EntryPre (cut eps 3) ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group true 0 1 84).map lowMap):= parts.groupsBefore (3,0,1,84) (by simp) private theorem cutLoan {P : Program} {pre : State → Prop} (clean : CutClean pre P ((StairSchedule.exclusiveRoles.drop 0 ++ hp.group true 0 1 84).map lowMap)) (s : State) (h : pre s) (m : List Bool) : Loan (run P m s) := by intro q hq exact clean s h m _ (loanSite q hq) theorem at_cut {s:State} (F:EntryFrame s) (m:List Bool):Pinned F.x (run stockPrefix m s) ∧ Loan (run stockPrefix m s):=by have eq:=Stair44HostedCut.entry 3 s ⟨F⟩ m change run stockPrefix m s=run (cut eps 3) m s at eq rw [eq] refine ⟨?_,cutLoan (fullCutClean (entryClean_of_planR entryPlans half760)) s ⟨F⟩ m⟩ obtain ⟨Q,step⟩:=ern3 F.x (entryPlans F.x) obtain ⟨n,h⟩:=step s s ⟨⟨F,rfl⟩,rfl⟩ m rw [ecut3] exact ⟨_,pin _ _ _ h⟩ end ECDSAAdd.Entrant.StairPacket.ExteriorEntryCut end section namespace ECDSAAdd.Entrant.StairPacket.WindowReturningBytes open Arithmetic MappedCompressed Secp256k1 FrontierEntry1591Field StockArchiveBanks ExteriorPorts open WindowParityDirty WindowFieldParity set_option maxRecDepth 6000 attribute [local irreducible] run measurementCount wires def Keeps (P : Program) : Prop := ∀(s : State) (m : List Bool) (b : Bank) (i : Fin 16), (run P m s).basis (siteAt b i) = s.basis (siteAt b i) theorem untouched {P : Program} (clear : Clear P) : Keeps P := fun s m b i=>run_preserves_outside P m s _ (clear _ (StockArchiveBanks.mem b i)) theorem both {P Q : Program} (hp : Keeps P) (hq : Keeps Q) : Keeps (P ++ Q) := by intro s m b i rw [run_append] exact (hq _ _ _ _).trans (hp _ _ _ _) theorem parity : Keeps StairSchedule.paritySetup := by intro s m b i have outside : ∀(v : Bank)(j : Fin 16), siteAt v j≠host := by decide +kernel have eq : run StairSchedule.paritySetup m s = flip host (stockParity s) s := ParityHost5.setup_run controls host s m host_not_controls rw [eq] exact at_other _ _ _ _ (outside b i) theorem nativeBack {d : Bool} {rows : Bank → Nat} {r m P} (hp : Keeps P) (old : ∀b,nativeAt d b (rows b) (run P m r)) : ∀b,nativeAt d b (rows b) r := fun b i=>(hp r m b i).symm.trans (old b i) theorem nativeUnpull {d : Bool} {rows : Bank → Nat} {r} (old : ∀b,nativeAt d b (rows b) (pullState Rolling1588Lifetime.phaseHost r)) : ∀b,nativeAt d b (rows b) r := by intro b i have v := old b i change r.basis (Rolling1588Lifetime.phaseHost (siteAt b i))=_ at v rwa [host_ports] at v end ECDSAAdd.Entrant.StairPacket.WindowReturningBytes end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorEntryCut open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairField2V3Seg open WindowFieldMask WindowFieldJourney WindowFieldCosts ExteriorPorts StockArchiveBanks set_option maxRecDepth 16000 set_option maxHeartbeats 2200000 attribute [local irreducible] run measurementCount theorem history {x rows} (labels:∀b,rows b<63145 ∧ ArchiveStockRows.Chronology (tick b) x p (rows b)): (∀j∈bankIds,fieldRows rows j<63145) ∧ (∀j∈bankIds,ArchiveStockRows.Chronology (5*j-5) x p (fieldRows rows j)):=by have times:∀b:Bank,5*groupId b-5=tick b:=by decide +kernel constructor <;> intro j hj <;> obtain ⟨b,rfl⟩:=idAt _ hj <;> rw [rowsAt] · exact (labels b).1 · rw [times];exact (labels b).2 end ECDSAAdd.Entrant.StairPacket.ExteriorEntryCut end section namespace ECDSAAdd.Entrant.StairPacket.WindowReturningTail open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StockArchiveBanks open WindowReturningBytes WindowFieldMask WindowFieldJourney ExteriorPorts set_option maxRecDepth 12000 set_option maxHeartbeats 1000000 attribute [local irreducible] run measurementCount wires def program (pre between post setup : Program) := (((pre ++ setup) ++ between) ++ setup) ++ post private theorem keepTail {pre between post : Program} (hp : Clear pre) (hb : Clear between) (ht : Clear post) : Keeps (program pre between post StairSchedule.paritySetup) := WindowReturningBytes.both (WindowReturningBytes.both (WindowReturningBytes.both (WindowReturningBytes.both (untouched hp) WindowReturningBytes.parity) (untouched hb)) WindowReturningBytes.parity) (untouched ht) private theorem stable {d x rows P} (c : Clear P) : Relates P P (fun a r=>Paired d x a r rows) (fun a r=>Paired d x a r rows) := by intro a r pair m exact ⟨m,pair.through P c m⟩ private theorem switchParity {d x rows} : Relates WindowFieldParity.setup StairSchedule.paritySetup (fun a r=>Paired d x a r rows) (fun a r=>Paired d x a r rows) := by intro a r pair m exact ⟨m,WindowFieldParity.setup_through pair m m⟩ theorem carry {pre between post : Program} (hp : Clear pre) (hb : Clear between) (ht : Clear post) {d x rows} : Relates (program pre between post WindowFieldParity.setup) (program pre between post StairSchedule.paritySetup) (fun a r=>Paired d x a r rows) (fun a r=>Paired d x a r rows) := compose (compose (compose (compose (stable hp) switchParity) (stable hb)) switchParity) (stable ht) theorem runTail {pre between post oldPrefix : Program} {s : State} (F : EntryFrame s) (shape : WindowMiddleContract.oldDivHead=oldPrefix ++ program pre between post StairSchedule.paritySetup) (hp : Clear pre) (hb : Clear between) (ht : Clear post) (a : State) (old m : List Bool) (ff : Fits (fieldRows (StockRowVector.rows F.x p)) (finalCode true (plan true) (initialCode true)) a (run oldPrefix old s)) : ∃n, Paired false F.x (run (program pre between post WindowFieldParity.setup) m a) (run (program pre between post StairSchedule.paritySetup) n (run oldPrefix old s)) (StockRowVector.rows F.x p) := by let tape := joinTapes oldPrefix old [] have native := WindowEndBytes.div_native F tape have known := nativeUnpull native.bytes unfold tape at known rw [shape,joined] at known have here := nativeBack (keepTail hp hb ht) known have source : Paired false F.x a (run oldPrefix old s) (StockRowVector.rows F.x p) := pairFinished ff native.ids here exact carry hp hb ht _ _ source m theorem entryOfPrefix {pre between post newPrefix oldPrefix : Program} (newShape : WindowMiddleContract.divHead=newPrefix ++ program pre between post WindowFieldParity.setup) (oldShape : WindowMiddleContract.oldDivHead=oldPrefix ++ program pre between post StairSchedule.paritySetup) (hp : Clear pre) (hb : Clear between) (ht : Clear post) (starts : ∀ {s : State} (F : EntryFrame s) (m : List Bool), ∃old, Fits (fieldRows (StockRowVector.rows F.x p)) (finalCode true (plan true) (initialCode true)) (run newPrefix m s) (run oldPrefix old s)) : WindowMiddleContract.entry := by intro s F m obtain ⟨old,ff⟩ := starts F m obtain ⟨n,pair⟩ := runTail F oldShape hp hb ht _ old (m.drop (measurementCount newPrefix)) ff refine ⟨joinTapes oldPrefix old n,?_⟩ rw [newShape,oldShape,joined,run_append,run_take] exact pairPull Rolling1588Lifetime.phaseHost Rolling1588Lifetime.phaseHost.injective phaseFix pair end ECDSAAdd.Entrant.StairPacket.WindowReturningTail end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorDivPieces open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly StairField13V3 StairField13V3Clean open StairField2V3Replay StairHostsSchedule ExteriorPorts Rolling1588Lifetime set_option maxRecDepth 14000 set_option maxHeartbeats 1800000 set_option linter.unusedSimpArgs false attribute [local irreducible] run measurementCount wires def beforeGroup := StairSchedule.fieldRename (StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket true) (Rolling1588.placedFirstPacket true) ++ FourScratchWindow.clearProgram) def beforeGroupOdd := StairSchedule.fieldRename (StairLoan.rebindMany StairSchedule.exclusiveRoles (hostPlan.firstPacket true) (JointOdd1588.placedFirstPacketOdd WindowCallerCosts.oddFirstHalf true) ++ FourScratchWindow.clearProgram) def rawTail := StairSchedule.forwardSegment cp 87 62 425 450 ++ hostedGroup hostPlan true 13 85 5 ++ StairSchedule.forwardSegment cp 62 47 450 465 ++ hostedGroup hostPlan true 22 90 3 ++ StairSchedule.forwardSegment cp 47 32 465 480 ++ hostedGroup hostPlan true 30 93 3 ++ StairSchedule.forwardSegment cp 32 22 480 490 ++ hostedGroup hostPlan true 36 96 2 ++ StairSchedule.forwardSegment cp 22 12 490 500 ++ hostedGroup hostPlan true 41 98 2 ++ StairSchedule.forwardLast cp def rawTailOdd := StairSchedule.forwardSegment cp 87 62 425 450 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 5 ++ StairSchedule.forwardSegment cp 62 47 450 465 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 3 ++ StairSchedule.forwardSegment cp 47 32 465 480 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 3 ++ StairSchedule.forwardSegment cp 32 22 480 490 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 2 ++ StairSchedule.forwardSegment cp 22 12 490 500 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 2 ++ StairSchedule.forwardLast cp def pre := renameProgram fieldEquiv rawTail ++ StairSchedule.fieldRename FourScratchWindow.unprefix def preOdd := renameProgram fieldEquiv rawTailOdd ++ StairSchedule.fieldRename FourScratchWindow.unprefix def between := StairSchedule.hostedX ++ StairSchedule.fieldRename (entryLowSuffix hostPlan) ++ StairSchedule.hostedX def betweenOdd := StairSchedule.hostedX ++ StairSchedule.fieldRename (OddFullPass.P1LifeLoan.entryLowSuffixOdd hostPlan) ++ StairSchedule.hostedX def post := renameProgram phaseHost Stair44Outer.reverseEnd def field (S G : Program) := (((beforeGroup ++ renameProgram fieldEquiv G) ++ pre) ++ S) ++ between ++ S def fieldOdd (S G : Program) := (((beforeGroupOdd ++ renameProgram fieldEquiv G) ++ preOdd) ++ S) ++ betweenOdd ++ S theorem ordinary : StairHostsSchedule.entryFieldHosted cp hostPlan = field StairSchedule.paritySetup (WindowFieldCosts.group true 1 84) := by simp only [field,beforeGroup,pre,between,rawTail,StairHostsSchedule.entryFieldHosted, entryLowPrefix,entryTailPrefix,WindowFieldCosts.group,←placedShape,fieldRename_append,rename_append,List.append_assoc] theorem corrected : WindowParityCaller.entryFieldHosted cp = fieldOdd WindowFieldParity.setup (WindowFieldCosts.group84 true) := by simp only [fieldOdd,beforeGroupOdd,preOdd,betweenOdd,rawTailOdd,WindowParityCaller.entryFieldHosted, WindowCallerCosts.entryLowPrefix,WindowCallerCosts.entryTailPrefix,←placedShape,fieldRename_append,rename_append,List.append_assoc] /-- The odd field rows with the five packet-cut rows. -/ def rawTailOddCut := PackCutOdd.cutRowOdd 87 62 425 450 13 85 4 ++ (PackCutOdd.cutRowOdd 62 47 450 465 22 90 2 ++ (PackCutOdd.cutRowOdd 47 32 465 480 30 93 2 ++ (PackCutOdd.cutRowOdd 32 22 480 490 36 96 1 ++ (PackCutOdd.cutRowOdd 22 12 490 500 41 98 1 ++ StairSchedule.forwardLast cp)))) def preOddCut := renameProgram fieldEquiv rawTailOddCut ++ StairSchedule.fieldRename FourScratchWindow.unprefix def fieldOddCut (S G : Program) := (((beforeGroupOdd ++ renameProgram fieldEquiv G) ++ preOddCut) ++ S) ++ betweenOdd ++ S theorem correctedCut : WindowParityCaller.entryFieldHostedCut = fieldOddCut WindowFieldParity.setup (WindowFieldCosts.group84 true) := by simp only [fieldOddCut,beforeGroupOdd,preOddCut,betweenOdd,rawTailOddCut,WindowParityCaller.entryFieldHostedCut, WindowCallerCosts.entryLowPrefixCut,WindowCallerCosts.entryTailPrefixCut,←placedShape,fieldRename_append, rename_append,List.append_assoc] def stockBegin := renameProgram phaseHost (StairSchedule.firstPhase checkpointPrimitives) theorem cutShape : ExteriorEntryCut.stockPrefix = stockBegin ++ beforeGroup := by simp only [ExteriorEntryCut.stockPrefix,stockBegin,beforeGroup,entryPieces,List.take_succ_cons, List.take_zero,common,firstSlot,List.map_cons,List.map_nil,List.flatten_cons, List.flatten_nil,List.append_nil,fieldRename_append,List.append_assoc] end ECDSAAdd.Entrant.StairPacket.ExteriorDivPieces end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorDivPieces open Arithmetic MappedCompressed StairConcreteAssembly StairHostsSchedule ExteriorPorts Rolling1588Lifetime set_option maxRecDepth 14000 set_option maxHeartbeats 1800000 attribute [local irreducible] wires theorem beforeFree : Clear beforeGroup := fieldRename_free (both (WindowExteriorFixed.first true) clearSafe) theorem beforeOddFree : Clear beforeGroupOdd := fieldRename_free (both (WindowExteriorFixed.firstOdd true) clearSafe) theorem preFree : Clear pre := by apply both _ (fieldRename_free unprefixSafe) apply fieldMapped apply both _ forwardLast apply both _ (WindowExitOuter.ordinaryGroup true 41 98 2 (by decide) (by decide) (by decide) (by decide +kernel)) apply both _ forward490 apply both _ (WindowExitOuter.ordinaryGroup true 36 96 2 (by decide) (by decide) (by decide) (by decide +kernel)) apply both _ forward480 apply both _ (WindowExitOuter.ordinaryGroup true 30 93 3 (by decide) (by decide) (by decide) (by decide +kernel)) apply both _ forward465 apply both _ (WindowExitOuter.ordinaryGroup true 22 90 3 (by decide) (by decide) (by decide) (by decide +kernel)) apply both _ forward450 exact both forward425 (WindowExitOuter.ordinaryGroup true 13 85 5 (by decide) (by decide) (by decide) (by decide +kernel)) theorem betweenFree : Clear between := by apply both _ WindowExitOuter.hostedX apply both WindowExitOuter.hostedX apply fieldRename_free apply both _ unprefixSafe apply both clearSafe exact WindowExitClear.renameClear Prefix1590.borrow Prefix1590.borrow.injective (by unfold Fixed; decide +kernel) (WindowExteriorFixed.tail (WindowExitOuter.other true)) theorem preOddFree : Clear preOdd := by have hsub : wires preOdd ⊆ wires pre := by unfold preOdd pre rawTailOdd rawTail apply StairLoanGroupSupport.append_sub _ _ _ _ _ (Finset.Subset.refl _) apply StairLoanGroupSupport.rename_sub apply StairLoanGroupSupport.append_sub _ _ _ _ _ (Finset.Subset.refl _) apply StairLoanGroupSupport.append_sub _ _ _ _ _ (OddFullPass.P1LifeLoan.hostedGroup_wires_sub _ true _ _ _ (by decide) (by decide)) apply StairLoanGroupSupport.append_sub _ _ _ _ _ (Finset.Subset.refl _) apply StairLoanGroupSupport.append_sub _ _ _ _ _ (OddFullPass.P1LifeLoan.hostedGroup_wires_sub _ true _ _ _ (by decide) (by decide)) apply StairLoanGroupSupport.append_sub _ _ _ _ _ (Finset.Subset.refl _) apply StairLoanGroupSupport.append_sub _ _ _ _ _ (OddFullPass.P1LifeLoan.hostedGroup_wires_sub _ true _ _ _ (by decide) (by decide)) apply StairLoanGroupSupport.append_sub _ _ _ _ _ (Finset.Subset.refl _) apply StairLoanGroupSupport.append_sub _ _ _ _ _ (OddFullPass.P1LifeLoan.hostedGroup_wires_sub _ true _ _ _ (by decide) (by decide)) apply StairLoanGroupSupport.append_sub _ _ _ _ _ (Finset.Subset.refl _) exact StairLoanGroupSupport.append_sub _ _ _ _ (Finset.Subset.refl _) (OddFullPass.P1LifeLoan.hostedGroup_wires_sub _ true _ _ _ (by decide) (by decide)) exact fun q hq used => preFree q hq (hsub used) theorem preOddCut_sub : preOddCut.Sublist preOdd := by have e : rawTailOdd = (StairSchedule.forwardSegment StairField13V3Clean.cp 87 62 425 450 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 13 85 (4 + 1)) ++ ((StairSchedule.forwardSegment StairField13V3Clean.cp 62 47 450 465 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 22 90 (2 + 1)) ++ ((StairSchedule.forwardSegment StairField13V3Clean.cp 47 32 465 480 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 30 93 (2 + 1)) ++ ((StairSchedule.forwardSegment StairField13V3Clean.cp 32 22 480 490 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 36 96 (1 + 1)) ++ ((StairSchedule.forwardSegment StairField13V3Clean.cp 22 12 490 500 ++ OddFullPass.P1LifeLoan.hostedGroup hostPlan true 41 98 (1 + 1)) ++ StairSchedule.forwardLast StairField13V3Clean.cp)))) := by simp only [rawTailOdd, List.append_assoc] unfold preOddCut preOdd rw [e] exact (PackCutSub.rename_sub _ ((PackCutOdd.row_subOdd 87 62 425 450 13 85 4 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp1).append ((PackCutOdd.row_subOdd 62 47 450 465 22 90 2 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp2).append ((PackCutOdd.row_subOdd 47 32 465 480 30 93 2 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp3).append ((PackCutOdd.row_subOdd 32 22 480 490 36 96 1 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp4).append ((PackCutOdd.row_subOdd 22 12 490 500 41 98 1 (by decide) (by decide) (by decide) (by decide) (by decide) PackCutRows.hdp5).append (List.Sublist.refl _))))))).append (List.Sublist.refl _) theorem preOddCutFree : Clear preOddCut := fun q hq hw => preOddFree q hq (PackCutSub.wires_sub preOddCut_sub q hw) theorem betweenOddFree : Clear betweenOdd := by have hsub : wires betweenOdd ⊆ wires between := by unfold betweenOdd between apply StairLoanGroupSupport.append_sub _ _ _ _ _ (Finset.Subset.refl _) apply StairLoanGroupSupport.append_sub _ _ _ _ (Finset.Subset.refl _) unfold StairSchedule.fieldRename StairSchedule.parityRename exact StairLoanGroupSupport.rename_sub _ _ _ (StairLoanGroupSupport.rename_sub _ _ _ (OddFullPass.P1LifeLoan.entryLowSuffixOdd_wires_sub _)) exact fun q hq used => betweenFree q hq (hsub used) theorem postFree : Clear post := mapped _ phaseHost.injective phaseFix reverseEnd_free end ECDSAAdd.Entrant.StairPacket.ExteriorDivPieces end section namespace ECDSAAdd.Entrant.StairPacket.ExteriorDivReady open Arithmetic MappedCompressed Secp256k1 StairConcreteAssembly Rolling1588Lifetime open StockArchiveBanks WindowStartStates ExteriorPorts ExteriorDivPieces WindowFieldMask WindowFieldJourney set_option maxHeartbeats 2000000 set_option maxRecDepth 15000 attribute [local irreducible] run measurementCount wires def pack := renameProgram phaseHost checkpointPrimitives.firstPack def beginW := opening true 4 ++ pack def beginR := original true 4 ++ pack def prefixW := (beginW ++ beforeGroup) ++ renameProgram fieldEquiv (WindowFieldCosts.group84 true) def prefixR := (beginR ++ beforeGroup) ++ renameProgram fieldEquiv (WindowFieldCosts.group true 1 84) theorem refBegin : beginR = Stair44Kernel.divLead := by simp only [beginR,original,pack,Stair44Kernel.divLead,Six505.rename_append] theorem begin_pair {s : State} (F : EntryFrame s) (m : List Bool) : ∃n, Paired true F.x (run beginW m s) (run beginR n s) (StockRowVector.rows F.x p) := by let A := opening true 4 let B := original true 4 let t := m.drop (measurementCount A) refine ⟨joinTapes B m t,?_⟩ rw [beginW,beginR,joined,run_append,run_take] apply pairUnpull phaseHost phaseFix rw [pack,run_rename _ phaseHost.injective,run_rename _ phaseHost.injective] exact (WindowStartStates.division F m).through _ firstPack_free _ theorem cut {s : State} (F : EntryFrame s) (m : List Bool) : ∃old rec, Paired true F.x (run (beginW ++ beforeGroup) m s) (run (beginR ++ beforeGroup) old s) (StockRowVector.rows F.x p) ∧ run (beginR ++ beforeGroup) old s = run ExteriorEntryCut.stockPrefix rec s := by obtain ⟨n,pair⟩ := begin_pair F m let t := m.drop (measurementCount beginW) refine ⟨joinTapes beginR n t,joinTapes stockBegin n t,?_,?_⟩ · rw [joined,run_append,run_take] exact pair.through _ beforeFree _ · rw [cutShape,joined,joined,refBegin,WindowStockHead.leadD F] rfl def prefixWOdd := (beginW ++ beforeGroupOdd) ++ renameProgram fieldEquiv (WindowFieldCosts.group84 true) def prefixROdd := (beginR ++ beforeGroupOdd) ++ renameProgram fieldEquiv (WindowFieldCosts.ogroup true 1 84) theorem stockOddShapeCut : OddStockLockstep.stockOddDivHeadCut = prefixROdd ++ WindowReturningTail.program preOddCut betweenOdd post StairSchedule.paritySetup := by simp only [OddStockLockstep.stockOddDivHeadCut, OddStockLockstep.stockOddDivBeforeGroup, OddStockLockstep.stockOddDivPreCut, OddStockLockstep.stockOddDivRawTailCut, OddStockLockstep.stockOddDivBetween, OddStockLockstep.stockOddDivPost, prefixROdd, refBegin, beforeGroupOdd, preOddCut, rawTailOddCut, betweenOdd, post, JointOdd1588.hostedFirstPacketOdd, StairConcreteAssembly.hostPlan, WindowReturningTail.program, List.append_assoc] theorem newShapeOddCut : WindowMiddleContract.divHead = prefixWOdd ++ WindowReturningTail.program preOddCut betweenOdd post WindowFieldParity.setup := by simp only [WindowMiddleContract.divHead, WindowKernelPrograms.divBefore, correctedCut, fieldOddCut, prefixWOdd, beginW, opening, pack, post, WindowReturningTail.program, Six505.rename_append, List.append_assoc] theorem stockOddShape : OddStockLockstep.stockOddDivHead = prefixROdd ++ WindowReturningTail.program preOdd betweenOdd post StairSchedule.paritySetup := by simp only [OddStockLockstep.stockOddDivHead, OddStockLockstep.stockOddDivBeforeGroup, OddStockLockstep.stockOddDivPre, OddStockLockstep.stockOddDivRawTail, OddStockLockstep.stockOddDivBetween, OddStockLockstep.stockOddDivPost, prefixROdd, refBegin, beforeGroupOdd, preOdd, rawTailOdd, betweenOdd, post, JointOdd1588.hostedFirstPacketOdd, StairConcreteAssembly.hostPlan, WindowReturningTail.program, List.append_assoc] private theorem begin_pair_odd {tOdd tStd : State} (FStd : EntryFrame tStd) (hag : OddStockLockstep.AgreeOutsideR tOdd tStd) (m : List Bool) : ∃ n, Paired true FStd.x (run beginW m tOdd) (run beginR n tOdd) (StockRowVector.rows FStd.x p) := by let A := opening true 4 let B := original true 4 let t := m.drop (measurementCount A) have hnum : skywalkArithmeticNumerator base = OddStockLockstep.fieldR := rfl have hinOdd : SkywalkArithmeticInput base FStd.x (regValue OddStockLockstep.fieldR tOdd.basis) tOdd.basis := FrontierEntry1591Kernel.paired_input FStd.x (BalancedField.centerWord (FStd.Y / 2)) tStd tOdd (StairField13V3Clean.entryInput FStd) (fun q hq => hag.2 q (hnum ▸ hq)) have hpullOdd : pullState phaseHost tOdd = tOdd := by have hpullStd := StairField13V3Clean.pull_phaseHost_entry FStd apply State.extensionality · rfl · funext q by_cases hr : q ∈ OddStockLockstep.fieldR · change tOdd.basis (phaseHost q) = tOdd.basis q rw [OddStockLockstep.phaseHost_fix_fieldR q hr] · have hnr : phaseHost q ∉ OddStockLockstep.fieldR := by intro hmem have hf := OddStockLockstep.phaseHost_fix_fieldR (phaseHost q) hmem exact hr (phaseHost.injective hf ▸ hmem) change tOdd.basis (phaseHost q) = tOdd.basis q rw [hag.2 _ hnr, hag.2 _ hr] exact congrFun (congrArg State.basis hpullStd) q have hopen : Paired true FStd.x (pullState phaseHost (run A m tOdd)) (pullState phaseHost (run B m tOdd)) (StockRowVector.rows FStd.x p) := by dsimp only [A, B] rw [opening, original, run_rename _ phaseHost.injective, run_rename _ phaseHost.injective, hpullOdd] exact WindowStartStates.open_raw true 4 FStd.x _ FStd.x_pos FStd.x_lt (by decide) FStd.sharedNodup tOdd hinOdd _ refine ⟨joinTapes B m t, ?_⟩ rw [beginW, beginR, joined, run_append, run_take] apply pairUnpull phaseHost phaseFix rw [pack, run_rename _ phaseHost.injective, run_rename _ phaseHost.injective] exact hopen.through _ firstPack_free _ private theorem pull_fieldEquiv_eq_pullIn (st : State) : pullState ExteriorPorts.fieldEquiv st = StairField2V3Seg.pullIn st := rfl private theorem starts_odd {tOdd tStd : State} (FStd : EntryFrame tStd) (hag : OddStockLockstep.AgreeOutsideR tOdd tStd) (hval : regValue OddStockLockstep.fieldR tOdd.basis = P1Life.oddWord (FStd.Y / 2)) (m : List Bool) : ∃ old, Fits (fieldRows (StockRowVector.rows FStd.x p)) (finalCode true (plan true) (initialCode true)) (run prefixWOdd m tOdd) (run prefixROdd old tOdd) := by obtain ⟨n0, pair0⟩ := begin_pair_odd FStd hag m let tBef := m.drop (measurementCount beginW) let n1 := joinTapes beginR n0 tBef have pair1 : Paired true FStd.x (run (beginW ++ beforeGroupOdd) m tOdd) (run (beginR ++ beforeGroupOdd) n1 tOdd) (StockRowVector.rows FStd.x p) := by rw [run_append, run_take, joined] exact pair0.through _ beforeOddFree _ have heq3 : run (beginR ++ beforeGroupOdd) n1 tOdd = run OddStockLockstep.stockOddDivPrefix3 n1 tOdd := by have hcp : StairField13V3Clean.cp = checkpointPrimitives := rfl have h409 : (405 : Nat) + 4 = 409 := rfl have hmc : measurementCount beginR = measurementCount (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase StairField13V3Clean.cp)) := by rw [beginR, original, h409, pack, hcp, WindowStockHead.shapeD, measurementCount_append, (renameProgram_counts _ _).2, (renameProgram_counts _ _).2, (renameProgram_counts _ _).2, measurementCount_append, Stair44Kernel.open_count] have hbg : beforeGroupOdd = OddStockLockstep.stockOddDivBeforeGroup := by simp only [beforeGroupOdd, OddStockLockstep.stockOddDivBeforeGroup, JointOdd1588.hostedFirstPacketOdd, StairConcreteAssembly.hostPlan] have hlead := OddStockLockstep.divLead_eq_firstPhase_odd FStd hag (n1.take (measurementCount beginR)) rw [← refBegin] at hlead rw [OddStockLockstep.stockOddDivPrefix3, run_append beginR, run_append (renameProgram Rolling1588Lifetime.phaseHost (StairSchedule.firstPhase StairField13V3Clean.cp)), ← hmc, hbg, hlead] obtain ⟨_, origin, ctx, en, tr, ocut⟩ := OddStockLockstep.stockOddDiv_cut3 FStd hag hval n1 rw [← heq3] at ocut let tGrp := m.drop (measurementCount (beginW ++ beforeGroupOdd)) let tape := oreferenceTape true (plan true) tGrp refine ⟨joinTapes (beginR ++ beforeGroupOdd) n1 tape, ?_⟩ rw [prefixWOdd, prefixROdd, run_append, run_take, joined] obtain ⟨bound, trace⟩ := ExteriorEntryCut.history pair1.labels apply hosted obtain ⟨a1, ha1⟩ : ∃ st, run (beginW ++ beforeGroupOdd) m tOdd = st := ⟨_, rfl⟩ obtain ⟨r1, hr1⟩ : ∃ st, run (beginR ++ beforeGroupOdd) n1 tOdd = st := ⟨_, rfl⟩ rw [ha1, hr1] at pair1 ⊢ rw [hr1] at ocut have hpull := fitsPull fieldEquiv fieldEquiv.injective fieldFix (fits pair1) rw [pull_fieldEquiv_eq_pullIn] at hpull ⊢ exact WindowFieldView.ocaller true FStd.x (fieldRows (StockRowVector.rows FStd.x p)) bound trace origin ctx en tr (StairField2V3Seg.pullIn a1) r1 tGrp hpull ocut theorem entryOdd : WindowKernelReplay.OddEntryContract := by intro hn hl ho hf x Y hx0 hx s tOdd m input hg hs phase eq val let tStd := OddStockLockstep.stdOfOdd tOdd Y have hag : OddStockLockstep.AgreeOutsideR tOdd tStd := ⟨rfl, fun q hq => by simp only [tStd, OddStockLockstep.stdOfOdd, dif_neg hq]⟩ have hval_std : regValue OddStockLockstep.fieldR tStd.basis = BalancedField.centerWord (Y / 2) := by have hlt : BalancedField.centerWord (Y / 2) < 2 ^ 256 := (BalancedField.centerWord_valid (Y / 2)).1 apply Nat.eq_of_testBit_eq intro i by_cases hi : i < 256 · have hlen : OddStockLockstep.fieldR.length = 256 := by simp [OddStockLockstep.fieldR, wireBlock_length] have hbit := Arithmetic.regValue_bit OddStockLockstep.fieldR i 0 tStd.basis (by omega) have hget : OddStockLockstep.fieldR.getD i 0 = base (2056 + i) := by rw [List.getD_eq_getElem _ _ (by omega)] simp [OddStockLockstep.fieldR, wireBlock] rw [hget] at hbit have hmem : base (2056 + i) ∈ OddStockLockstep.fieldR := List.mem_map.mpr ⟨2056 + i, by simp only [List.mem_range'_1]; omega, rfl⟩ have hsub : base (2056 + i) - 2072 = i := by change (2056 + i) + 16 - 2072 = i; omega have htb : tStd.basis (base (2056 + i)) = (BalancedField.centerWord (Y / 2)).testBit i := by simp only [tStd, OddStockLockstep.stdOfOdd, dif_pos hmem, hsub] rw [htb] at hbit rw [Nat.testBit_eq_decide_div_mod_eq, ← hbit] cases (BalancedField.centerWord (Y / 2)).testBit i <;> decide · have hlen : OddStockLockstep.fieldR.length = 256 := by simp [OddStockLockstep.fieldR, wireBlock_length] have hlt1 : regValue OddStockLockstep.fieldR tStd.basis < 2 ^ 256 := hlen ▸ Arithmetic.regValue_lt OddStockLockstep.fieldR tStd.basis rw [Nat.testBit_lt_two_pow (lt_of_lt_of_le hlt1 (Nat.pow_le_pow_right (by decide) (by omega))), Nat.testBit_lt_two_pow (lt_of_lt_of_le hlt (Nat.pow_le_pow_right (by decide) (by omega)))] let FStd : EntryFrame tStd := ⟨hn, hl, ho, hf, x, Y, hx0, hx, s, input, hg, hs, phase, fun q hq => (hag.2 q hq).symm.trans (eq q hq), hval_std⟩ obtain ⟨old, ff⟩ := starts_odd FStd hag val m let mTail := m.drop (measurementCount prefixWOdd) let tape0 := joinTapes prefixROdd old [] obtain ⟨nOld0, heq0⟩ := OddStockLockstep.stockOddDivHeadCut_eq_oldDivHead FStd hag val tape0 have native0 := WindowEndBytes.div_native FStd nOld0 have known : ∀ b, nativeAt false b (StockRowVector.rows x p b) (run OddStockLockstep.stockOddDivHeadCut tape0 tOdd) := by rw [heq0]; exact WindowReturningBytes.nativeUnpull native0.bytes unfold tape0 at known rw [stockOddShapeCut, joined] at known have hkeep : WindowReturningBytes.Keeps (WindowReturningTail.program preOddCut betweenOdd post StairSchedule.paritySetup) := WindowReturningBytes.both (WindowReturningBytes.both (WindowReturningBytes.both (WindowReturningBytes.both (WindowReturningBytes.untouched preOddCutFree) WindowReturningBytes.parity) (WindowReturningBytes.untouched betweenOddFree)) WindowReturningBytes.parity) (WindowReturningBytes.untouched postFree) have here := WindowReturningBytes.nativeBack hkeep known have source : Paired false x (run prefixWOdd m tOdd) (run prefixROdd old tOdd) (StockRowVector.rows x p) := pairFinished ff native0.ids here obtain ⟨nTail, pairTail⟩ := WindowReturningTail.carry preOddCutFree betweenOddFree postFree _ _ source mTail let nFull := joinTapes prefixROdd old nTail obtain ⟨nOld, heqFull⟩ := OddStockLockstep.stockOddDivHeadCut_eq_oldDivHead FStd hag val nFull refine ⟨nOld, ?_⟩ rw [← heqFull, newShapeOddCut, stockOddShapeCut, run_append, run_take, joined] exact pairPull phaseHost phaseHost.injective phaseFix pairTail end ECDSAAdd.Entrant.StairPacket.ExteriorDivReady end section namespace ECDSAAdd.Entrant def entry : Challenge.Entry := StairPacket.WindowParityRelease.entry def bounds : Challenge.Bounds := StairPacket.WindowParityRelease.bounds theorem certificate : Challenge.Certificate entry bounds := StairPacket.WindowReleaseProof.certificate StairPacket.ExteriorDivReady.entryOdd StairPacket.WindowExitReady.exitOdd end ECDSAAdd.Entrant end end -- ==== end Main ==== end -- ==== end MainTail ====