Download data/lean/OAI/Algorithms/SubexponentialSAT/SqrtLogSpace/AttainedSignatureRescan.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 54.4 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Algorithms/SubexponentialSAT/SqrtLogSpace/AttainedSignatureRescan.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Algorithms/SubexponentialSAT/SqrtLogSpace/AttainedSignatureRescan.lean
-
curl -L -o AttainedSignatureRescan.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Algorithms/SubexponentialSAT/SqrtLogSpace/AttainedSignatureRescan.lean
54.4 kB
Lean 4 Β· 46
declarations fullstatements
| import OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.AttainedSignatureProgram | |
| import OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.CounterLoops | |
| /-! Actual bounded-word predecessor rescan and its uniform source-prefix storage. -/ | |
| namespace OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.AttainedSignatureProgram | |
| open OAI.Algorithms.SubexponentialSAT.BitProgram OAI.Algorithms.SubexponentialSAT.StructuredCalls OAI.Algorithms.SubexponentialSAT.Subexp.MatrixProgramSupport | |
| open OAI.Algorithms.SubexponentialSAT.SqrtLog.BucketProgram | |
| namespace Rescan | |
| theorem workState_fuel_update (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (candidate saved predecessor fuel newFuel : List Bool) | |
| (fresh : Bool) : | |
| (workState regs W rows candidate saved predecessor newFuel fresh [] []).stacks = | |
| Function.update (workState regs W rows candidate saved predecessor fuel fresh [] []).stacks | |
| 19 newFuel := by | |
| funext i | |
| fin_cases i <;> simp [workState] | |
| theorem nextState_workState (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (candidate saved predecessor fuel : List Bool) | |
| (fresh : Bool) : | |
| CounterForPrograms.nextState countdownPorts | |
| (workState regs W rows candidate saved predecessor fuel fresh [] []) = | |
| workState (CounterForPrograms.nextState countdownPorts | |
| (workState regs W rows candidate saved predecessor fuel fresh [] [])).regs | |
| W rows candidate saved predecessor (CounterPrograms.ripple false fuel) fresh [] [] := by | |
| let a := workState regs W rows candidate saved predecessor fuel fresh [] [] | |
| have hs : (CounterForPrograms.nextState countdownPorts a).stacks = | |
| Function.update a.stacks 19 (CounterPrograms.ripple false fuel) := by | |
| funext i | |
| by_cases hc : i = 19 | |
| Β· subst i | |
| rw [Function.update_self] | |
| exact CounterForPrograms.nextState_counter countdownPorts a | |
| rw [Function.update_of_ne hc] | |
| by_cases he : i = 20 | |
| Β· subst i | |
| exact CounterForPrograms.nextState_scratch countdownPorts a | |
| exact (CounterForPrograms.nextState_outside countdownPorts a i hc he).symm | |
| apply congrArg (StructuredProgram.State.mk _) | |
| exact hs.trans (workState_fuel_update _ W rows candidate saved predecessor fuel _ fresh).symm | |
| theorem body_scan_eval (W : List Bool) (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) (i : β) (hi : i < candidate.val) | |
| (fuel : List Bool) (regs : Fin 16 β Bool) : | |
| β nb β€ bodyBound W (naturalKey W rows h candidate) rows h B, β rb, | |
| Eval body nb | |
| (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h i) fuel | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate i)) [] []) | |
| (workState rb W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h (i + 1)) fuel | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate (i + 1))) [] []) := by | |
| have hil : i < 2 ^ h := hi.trans candidate.isLt | |
| have hinext : i + 1 < 2 ^ h := by have := candidate.isLt; omega | |
| let current := ExecCNFTupleEnumeration.fixedBits h i | |
| let saved := naturalKey W rows h candidate | |
| let fresh := !(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate i) | |
| obtain β¨nb, hnb, rb, hbβ© := body_eval regs W rows | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) saved current fuel fresh | |
| (by simpa [current] using hlen) | |
| have hbound : nb β€ bodyBound W saved rows h B := | |
| hnb.trans (bodyCost_le W current saved rows h B (by simp [current]) hlen hwidth) | |
| have hword : CounterPrograms.ripple true current = | |
| ExecCNFTupleEnumeration.fixedBits h (i + 1) := | |
| Counters.increment_word (β¨i, hilβ© : Fin (2 ^ h)) hinext | |
| have hfresh : (fresh && !decide (signatureValue W current rows = saved)) = | |
| !(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate (i + 1)) := by | |
| simp [AttainedSignatures.duplicateScan, fresh, saved, current, naturalKey, Bool.not_or] | |
| rfl | |
| rw [hword, hfresh] at hb | |
| exact β¨nb, hbound, rb, hbβ© | |
| inductive ScanInvariant (W : List Bool) (rows : List (List (List Bool))) (h : β) | |
| (candidate : Fin (2 ^ h)) (i : β) (a : Data) : Prop where | |
| | intro (fuel : List Bool) (hlen : fuel.length = h) | |
| (hvalue : i + CounterPrograms.value fuel = candidate.val) | |
| (he : a = workState a.regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h i) fuel | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate i)) [] []) : | |
| ScanInvariant W rows h candidate i a | |
| theorem scan_spec (W : List Bool) (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) (candidate : Fin (2 ^ h)) : | |
| β i a, ScanInvariant W rows h candidate i a β a.stacks countdownPorts.scratch = [] β | |
| 0 < CounterPrograms.value (a.stacks countdownPorts.counter) β | |
| β nb e, nb β€ bodyBound W (naturalKey W rows h candidate) rows h B β§ Eval body nb a e β§ | |
| e.stacks countdownPorts.counter = a.stacks countdownPorts.counter β§ | |
| e.stacks countdownPorts.scratch = [] β§ | |
| ScanInvariant W rows h candidate (i + 1) (CounterForPrograms.nextState countdownPorts e) := by | |
| intro i a hI _ hp | |
| obtain β¨fuel, hl, hv, heβ© := hI | |
| have hcounter : a.stacks countdownPorts.counter = fuel := | |
| congrArg (fun d : Data => d.stacks countdownPorts.counter) he | |
| have hp' : 0 < CounterPrograms.value fuel := by simpa only [hcounter] using hp | |
| have hi : i < candidate.val := by omega | |
| obtain β¨nb, hnb, rb, hbβ© := body_scan_eval W rows h B hlen hwidth candidate i hi fuel a.regs | |
| let e := workState rb W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h (i + 1)) fuel | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate (i + 1))) [] [] | |
| refine β¨nb, e, hnb, ?_, ?_, rfl, ?_β© | |
| Β· exact Eq.mpr (congrArg (fun d : Data => Eval body nb d e) he) hb | |
| Β· exact hcounter.symm | |
| Β· refine β¨CounterPrograms.ripple false fuel, | |
| (CounterPrograms.decrement_length hp').trans hl, ?_, ?_β© | |
| Β· have hd := CounterPrograms.value_decrement hp' | |
| omega | |
| Β· exact nextState_workState rb W rows _ _ _ fuel _ | |
| theorem visits_exists (W : List Bool) (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) (remaining : β) | |
| (i : β) (fuel : List Bool) (regs : Fin 16 β Bool) | |
| (htotal : i + remaining = candidate.val) (hl : fuel.length = h) | |
| (hv : CounterPrograms.value fuel = remaining) | |
| (hf : regs 15 = !(CounterPrograms.isZero fuel)) : | |
| β costs n out, | |
| CounterForPrograms.Visits countdownPorts body costs n | |
| (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h i) fuel | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate i)) [] []) | |
| (workState out W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (List.replicate h false) | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) [] []) β§ | |
| costs.sum β€ remaining * bodyBound W (naturalKey W rows h candidate) rows h B := by | |
| let a := workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h i) fuel | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate i)) [] [] | |
| have hI : ScanInvariant W rows h candidate i a := β¨fuel, hl, by omega, rflβ© | |
| obtain β¨costs, n, e, hrun, hIe, _, hcostβ© := CounterLoops.visits_exists_next | |
| countdownPorts body (ScanInvariant W rows h candidate) | |
| (fun _ => bodyBound W (naturalKey W rows h candidate) rows h B) | |
| (scan_spec W rows h B hlen hwidth candidate) remaining i a hv rfl hf hI | |
| obtain β¨finalFuel, hfl, hfv, heβ© := hIe | |
| have hzero : CounterPrograms.value finalFuel = 0 := by omega | |
| have hz : finalFuel = List.replicate h false := | |
| ExecCNFTupleEnumeration.word_eq_of_length_value (by simpa using hfl) (by simpa using hzero) | |
| rw [htotal, hz] at he | |
| rw [he] at hrun | |
| rw [CounterForPrograms.budgetSum_const] at hcost | |
| exact β¨costs, n, e.regs, hrun, hcostβ© | |
| theorem for_eval (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) : | |
| β n β€ candidate.val * | |
| (bodyBound W (naturalKey W rows h candidate) rows h B + 16 * h + 16) + 8 * h + 8, | |
| β out, Eval (CounterForPrograms.forCmd countdownPorts body) n | |
| (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) true [] []) | |
| (workState out W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (List.replicate h false) | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) [] []) := by | |
| let a := workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) true [] [] | |
| let t := CounterForPrograms.testResult countdownPorts a | |
| have ht : t = workState t.regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) true [] [] := by | |
| apply congrArg (StructuredProgram.State.mk t.regs) | |
| exact CounterForPrograms.testResult_stacks countdownPorts a rfl | |
| have hf : t.regs 15 = !(CounterPrograms.isZero (ExecCNFTupleEnumeration.fixedBits h candidate)) := | |
| CounterForPrograms.testResult_flag countdownPorts a | |
| obtain β¨costs, ns, out, hv, hcβ© := visits_exists W rows h B hlen hwidth candidate candidate.val | |
| 0 (ExecCNFTupleEnumeration.fixedBits h candidate) t.regs (by omega) (by simp) | |
| (ExecCNFTupleEnumeration.fixedBits_value h candidate candidate.isLt) hf | |
| simp only [AttainedSignatures.duplicateScan, Bool.not_false] at hv | |
| rw [β ht] at hv | |
| have htest := CounterForPrograms.test_eval countdownPorts a (by rfl) | |
| have hrun := htest.seq hv.eval | |
| obtain β¨hcount, _, _, htimeβ© := hv.bounds | |
| have hlen' : (t.stacks countdownPorts.counter).length = h := by | |
| rw [ht] | |
| simp [workState, countdownPorts] | |
| have hval : CounterPrograms.value (t.stacks countdownPorts.counter) = candidate.val := by | |
| rw [ht] | |
| exact ExecCNFTupleEnumeration.fixedBits_value h candidate candidate.isLt | |
| rw [hval] at hcount | |
| rw [hlen', hcount] at htime | |
| refine β¨_, ?_, out, hrunβ© | |
| change 8 * (ExecCNFTupleEnumeration.fixedBits h candidate).length + 7 + ns β€ _ | |
| rw [ExecCNFTupleEnumeration.fixedBits_length] | |
| nlinarith | |
| /-- All live arrays and all four retained words are included. -/ | |
| theorem workState_stackBits (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (candidate saved predecessor fuel : List Bool) | |
| (fresh : Bool) : | |
| stackBits (workState regs W rows candidate saved predecessor fuel fresh [] []).stacks = | |
| W.length + (words (rows.map words)).length + candidate.length + saved.length + | |
| predecessor.length + fuel.length + 1 := by | |
| simp [stackBits, workState, Fin.sum_univ_succ, Nat.add_assoc] | |
| def boundaryBound (W saved : List Bool) (rows : List (List (List Bool))) (h : β) : β := | |
| W.length + (words (rows.map words)).length + saved.length + 3 * h + 1 | |
| theorem boundary_stackBits (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (h c i : β) (fuel : List Bool) | |
| (hf : fuel.length = h) (fresh : Bool) : | |
| stackBits (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h c) | |
| (naturalKey W rows h c) (ExecCNFTupleEnumeration.fixedBits h i) fuel fresh [] []).stacks = | |
| boundaryBound W (naturalKey W rows h c) rows h := by | |
| rw [workState_stackBits] | |
| simp only [ExecCNFTupleEnumeration.fixedBits_length, hf, boundaryBound] | |
| omega | |
| inductive Boundary (W : List Bool) (rows : List (List (List Bool))) (h c phase : β) | |
| (a : Data) : Prop where | |
| | intro (i : β) (fuel : List Bool) (fresh : Bool) (hi : i β€ c) | |
| (hv : i + CounterPrograms.value fuel = c + phase) (hl : fuel.length = h) | |
| (he : a = workState a.regs W rows (ExecCNFTupleEnumeration.fixedBits h c) | |
| (naturalKey W rows h c) (ExecCNFTupleEnumeration.fixedBits h i) fuel fresh [] []) : | |
| Boundary W rows h c phase a | |
| theorem Boundary.stackBits {W : List Bool} {rows : List (List (List Bool))} | |
| {h c phase : β} {a : Data} (ha : Boundary W rows h c phase a) : | |
| stackBits a.stacks = boundaryBound W (naturalKey W rows h c) rows h := by | |
| obtain β¨i, fuel, fresh, _, _, hf, heβ© := ha | |
| rw [he] | |
| exact boundary_stackBits a.regs W rows h c i fuel hf fresh | |
| theorem boundary_after_body (W : List Bool) (rows : List (List (List Bool))) | |
| (h B : β) (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) (candidate : Fin (2 ^ h)) | |
| {a b : Data} {n : β} (hb : Eval body n a b) | |
| (ha : Boundary W rows h candidate 0 a) | |
| (hp : 0 < CounterPrograms.value (a.stacks countdownPorts.counter)) : | |
| Boundary W rows h candidate 1 b β§ | |
| n β€ bodyBound W (naturalKey W rows h candidate) rows h B := by | |
| obtain β¨i, fuel, fresh, hi, hv, hl, heβ© := ha | |
| have hp' : 0 < CounterPrograms.value fuel := by | |
| rw [he] at hp | |
| exact hp | |
| have hil : i < 2 ^ h := lt_of_le_of_lt hi candidate.isLt | |
| have hn : i + 1 < 2 ^ h := by have := candidate.isLt; omega | |
| obtain β¨nb, hnb, rb, hb'β© := body_eval a.regs W rows | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) (naturalKey W rows h candidate) | |
| (ExecCNFTupleEnumeration.fixedBits h i) fuel fresh (by simpa using hlen) | |
| have hb0 := hb | |
| rw [he] at hb0 | |
| have hn' := StreamResources.eval_steps_eq 0 0 hb0 hb' | |
| have hf := hb0.final_unique 0 hb' | |
| have hw := Counters.increment_word (β¨i, hilβ© : Fin (2 ^ h)) hn | |
| constructor | |
| Β· refine β¨i + 1, fuel, | |
| fresh && !decide (naturalKey W rows h i = naturalKey W rows h candidate), | |
| by omega, by omega, hl, ?_β© | |
| rw [hf] | |
| exact congrArg (fun w => workState rb W rows | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) (naturalKey W rows h candidate) | |
| w fuel (fresh && !decide (naturalKey W rows h i = naturalKey W rows h candidate)) [] []) hw | |
| Β· rw [hn'] | |
| exact hnb.trans (bodyCost_le W _ _ rows h B (by simp) hlen hwidth) | |
| theorem boundary_next (W : List Bool) (rows : List (List (List Bool))) | |
| (h c : β) {a : Data} (ha : Boundary W rows h c 1 a) | |
| (hp : 0 < CounterPrograms.value (a.stacks countdownPorts.counter)) : | |
| Boundary W rows h c 0 (CounterForPrograms.nextState countdownPorts a) := by | |
| obtain β¨i, fuel, fresh, hi, hv, hl, heβ© := ha | |
| have hp' : 0 < CounterPrograms.value fuel := by | |
| rw [he] at hp | |
| exact hp | |
| have hd := CounterPrograms.value_decrement hp' | |
| refine β¨i, CounterPrograms.ripple false fuel, fresh, hi, by omega, | |
| (CounterPrograms.decrement_length hp').trans hl, ?_β© | |
| rw [he] | |
| exact nextState_workState a.regs W rows _ _ _ fuel fresh | |
| /-- The exponential count of visits does not occur in this all-prefix bound. -/ | |
| theorem visits_stack_bound (W : List Bool) (rows : List (List (List Bool))) | |
| (h B : β) (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) (candidate : Fin (2 ^ h)) | |
| {costs : List β} {n : β} {a b : Data} | |
| (hv : CounterForPrograms.Visits countdownPorts body costs n a b) | |
| (ha : Boundary W rows h candidate 0 a) : | |
| β prefixSteps intermediate, prefixSteps β€ n β | |
| Trace (compiled (CounterForPrograms.loopCmd countdownPorts body) 19 19) | |
| prefixSteps (a.withPC (some (compiled | |
| (CounterForPrograms.loopCmd countdownPorts body) 19 19).entry)) intermediate β | |
| β i, (intermediate.stacks i).length β€ | |
| max (boundaryBound W (naturalKey W rows h candidate) rows h + | |
| bodyBound W (naturalKey W rows h candidate) rows h B) | |
| (40 * boundaryBound W (naturalKey W rows h candidate) rows h + 16) := by | |
| let base := boundaryBound W (naturalKey W rows h candidate) rows h | |
| let callbackBudget := bodyBound W (naturalKey W rows h candidate) rows h B | |
| have hbound (phase : β) (a : Data) (ha : Boundary W rows h candidate phase a) | |
| (i : Fin 24) : (a.stacks i).length β€ base := by | |
| have hs := Finset.single_le_sum (fun j _ => Nat.zero_le ((a.stacks j).length)) | |
| (Finset.mem_univ i) | |
| change (a.stacks i).length β€ stackBits a.stacks at hs | |
| rw [ha.stackBits] at hs | |
| exact hs | |
| have hcallback : β a b nb, Eval body nb a b β Boundary W rows h candidate 0 a β | |
| a.regs (countdownPorts.register 2) = true β | |
| 0 < CounterPrograms.value (a.stacks countdownPorts.counter) β | |
| Boundary W rows h candidate 1 b β§ | |
| β prefixSteps intermediate, prefixSteps β€ nb β | |
| Trace (compiled body 19 19) prefixSteps | |
| (a.withPC (some (compiled body 19 19).entry)) intermediate β | |
| β i, (intermediate.stacks i).length β€ base + callbackBudget := by | |
| intro a b nb hb ha _ hp | |
| obtain β¨hfinal, htimeβ© := boundary_after_body W rows h B hlen hwidth candidate hb ha hp | |
| refine β¨hfinal, ?_β© | |
| intro prefixSteps intermediate hle ht i | |
| apply StructuredSpace.local_stack_bound (compiled body 19 19) | |
| (steps := callbackBudget) (initialBound := base) _ prefixSteps intermediate | |
| (hle.trans htime) ht i | |
| exact le_of_eq ha.stackBits | |
| have ht := Enumerators.countdown_visits_stack_bound countdownPorts body | |
| (Boundary W rows h candidate 0) (Boundary W rows h candidate 1) | |
| base (base + callbackBudget) (hbound 0) (hbound 1) hcallback | |
| (fun a ha hp => boundary_next W rows h candidate ha hp) hv ha | |
| intro prefixSteps intermediate hle htrace i | |
| have hi := ht prefixSteps intermediate hle htrace i | |
| exact hi.trans (by dsimp [base, callbackBudget]; omega) | |
| def loopSpace (W : List Bool) (rows : List (List (List Bool))) (h B c : β) : β := | |
| max (boundaryBound W (naturalKey W rows h c) rows h + | |
| bodyBound W (naturalKey W rows h c) rows h B) | |
| (40 * boundaryBound W (naturalKey W rows h c) rows h + 16) | |
| /-- Every prefix of the actual counted rescan, including test and halt. -/ | |
| theorem for_stack_bound (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) {n : β} {finish : Data} | |
| (heval : Eval (CounterForPrograms.forCmd countdownPorts body) n | |
| (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) true [] []) finish) : | |
| β prefixSteps intermediate, prefixSteps β€ n + 1 β | |
| Trace (compiled (CounterForPrograms.forCmd countdownPorts body) 19 19) | |
| prefixSteps ((workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) true [] []).withPC | |
| (some (compiled (CounterForPrograms.forCmd countdownPorts body) 19 19).entry)) | |
| intermediate β β i, (intermediate.stacks i).length β€ loopSpace W rows h B candidate := by | |
| let a := workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) true [] [] | |
| let t := CounterForPrograms.testResult countdownPorts a | |
| have ht : t = workState t.regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) true [] [] := by | |
| apply congrArg (StructuredProgram.State.mk t.regs) | |
| exact CounterForPrograms.testResult_stacks countdownPorts a rfl | |
| have hf : t.regs 15 = !(CounterPrograms.isZero (ExecCNFTupleEnumeration.fixedBits h candidate)) := | |
| CounterForPrograms.testResult_flag countdownPorts a | |
| obtain β¨costs, ns, out, hv, _β© := visits_exists W rows h B hlen hwidth candidate candidate.val | |
| 0 (ExecCNFTupleEnumeration.fixedBits h candidate) t.regs (by omega) (by simp) | |
| (ExecCNFTupleEnumeration.fixedBits_value h candidate candidate.isLt) hf | |
| simp only [AttainedSignatures.duplicateScan, Bool.not_false] at hv | |
| rw [β ht] at hv | |
| have hI : Boundary W rows h candidate 0 t := by | |
| refine β¨0, ExecCNFTupleEnumeration.fixedBits h candidate, true, by omega, ?_, by simp, htβ© | |
| rw [ExecCNFTupleEnumeration.fixedBits_value h candidate candidate.isLt] | |
| omega | |
| have hloop := visits_stack_bound W rows h B hlen hwidth candidate hv hI | |
| have hinitial : β i, (a.stacks i).length β€ | |
| boundaryBound W (naturalKey W rows h candidate) rows h := by | |
| intro i | |
| have hs := Finset.single_le_sum (fun j _ => Nat.zero_le ((a.stacks j).length)) | |
| (Finset.mem_univ i) | |
| change (a.stacks i).length β€ stackBits a.stacks at hs | |
| have hb := boundary_stackBits regs W rows h candidate 0 | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) (by simp) true | |
| rw [hb] at hs | |
| exact hs | |
| have hb := Enumerators.countdown_for_stack_bound countdownPorts body (by rfl) | |
| hinitial hv hloop | |
| have htest := CounterForPrograms.test_eval countdownPorts a (by rfl) | |
| have hsame := StreamResources.eval_steps_eq 19 19 heval (htest.seq hv.eval) | |
| intro prefixSteps intermediate hle htrace i | |
| have hle' : prefixSteps β€ 8 * (a.stacks countdownPorts.counter).length + 7 + ns + 1 := by | |
| rw [hsame] at hle | |
| exact hle | |
| have hi := hb prefixSteps intermediate hle' htrace i | |
| exact hi.trans (by unfold loopSpace; omega) | |
| def setup : Code := .seq (copy 16 19) (storeFresh true) | |
| def cleanup : Code := .seq (clear 18) (.call (StackRoutines.transferProgram 19 18 0 1)) | |
| /-- The candidate word supplies the binary predecessor count. Its width is h; | |
| the final zero countdown word resets the predecessor without a family table. -/ | |
| def command : Code := .seq setup | |
| (.seq (CounterForPrograms.forCmd countdownPorts body) cleanup) | |
| theorem setup_eval (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (candidate saved predecessor : List Bool) (fresh : Bool) : | |
| β out, Eval setup (7 * candidate.length + 12) | |
| (workState regs W rows candidate saved predecessor [] fresh [] []) | |
| (workState out W rows candidate saved predecessor candidate true [] []) := by | |
| let a := workState regs W rows candidate saved predecessor [] fresh [] [] | |
| let rβ := readRegs regs 0 1 none | |
| have hcopy : Eval (copy 16 19) (7 * candidate.length + 5) a | |
| (workState rβ W rows candidate saved predecessor candidate fresh [] []) := by | |
| have ht := copy_eval 16 19 a (by decide) (by decide) (by decide) rfl | |
| have he : (β¨readRegs a.regs 0 1 none, StackRoutines.copyStacks 16 19 a.stacksβ© : Data) = | |
| workState rβ W rows candidate saved predecessor candidate fresh [] [] := by | |
| apply congrArg (StructuredProgram.State.mk rβ) | |
| funext i | |
| fin_cases i <;> simp [a, workState, StackRoutines.copyStacks] | |
| rw [he] at ht | |
| exact ht | |
| obtain β¨rβ, hfβ© := storeFresh_eval true rβ W rows candidate saved predecessor candidate fresh [] [] | |
| exact β¨rβ, by simpa only [setup] using hcopy.seq hfβ© | |
| theorem cleanup_eval (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (candidate saved : List Bool) (h : β) (answer : Bool) : | |
| β out, Eval cleanup (2 * candidate.length + 3 * h + 6) | |
| (workState regs W rows candidate saved candidate (List.replicate h false) answer [] []) | |
| (workState out W rows candidate saved (List.replicate h false) [] answer [] []) := by | |
| let rβ := readRegs regs 0 1 none | |
| have hclear : Eval (clear 18) (2 * candidate.length + 3) | |
| (workState regs W rows candidate saved candidate (List.replicate h false) answer [] []) | |
| (workState rβ W rows candidate saved [] (List.replicate h false) answer [] []) := by | |
| have ht := clear_eval 18 | |
| (workState regs W rows candidate saved candidate (List.replicate h false) answer [] []) | |
| have he : StackRoutines.clearStacks 18 | |
| (workState regs W rows candidate saved candidate (List.replicate h false) answer [] []).stacks = | |
| (workState rβ W rows candidate saved [] (List.replicate h false) answer [] []).stacks := by | |
| funext i | |
| fin_cases i <;> simp [workState, StackRoutines.clearStacks] | |
| rw [he] at ht | |
| exact ht | |
| let b := workState rβ W rows candidate saved [] (List.replicate h false) answer [] [] | |
| let rβ := readRegs rβ 0 1 none | |
| have htransfer : Eval (.call (StackRoutines.transferProgram 19 18 0 1)) (3 * h + 3) b | |
| (workState rβ W rows candidate saved (List.replicate h false) [] answer [] []) := by | |
| have ht : Eval (.call (StackRoutines.transferProgram 19 18 0 1)) | |
| (3 * (b.stacks 19).length + 3) b | |
| β¨readRegs b.regs 0 1 none, StackRoutines.transferStacks 19 18 b.stacksβ© := | |
| .call _ (ListRegisterProgram.transfer_run (19 : Fin 24) 18 | |
| (0 : Fin 16) 1 (by decide) (by decide) b.regs b.stacks) | |
| have he : StackRoutines.transferStacks 19 18 b.stacks = | |
| (workState rβ W rows candidate saved (List.replicate h false) [] answer [] []).stacks := by | |
| funext i | |
| fin_cases i <;> simp [b, workState, StackRoutines.transferStacks] | |
| rw [he] at ht | |
| have htarget : | |
| (β¨readRegs b.regs 0 1 none, | |
| (workState rβ W rows candidate saved (List.replicate h false) [] answer [] []).stacksβ© : | |
| Data) = | |
| workState rβ W rows candidate saved (List.replicate h false) [] answer [] [] := by | |
| apply congrArgβ StructuredProgram.State.mk <;> rfl | |
| rw [htarget] at ht | |
| change Eval (.call (StackRoutines.transferProgram 19 18 0 1)) | |
| (3 * (List.replicate h false).length + 3) b _ at ht | |
| simpa only [List.length_replicate] using ht | |
| refine β¨rβ, ?_β© | |
| convert hclear.seq htransfer using 1 | |
| Β· rfl | |
| Β· omega | |
| theorem command_eval (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) (fresh : Bool) : | |
| β n β€ candidate.val * | |
| (bodyBound W (naturalKey W rows h candidate) rows h B + 16 * h + 16) + 20 * h + 26, | |
| β out, Eval command n | |
| (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| [] fresh [] []) | |
| (workState out W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (List.replicate h false) [] | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) [] []) := by | |
| obtain β¨rβ, hsβ© := setup_eval regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) fresh | |
| obtain β¨nf, hnf, rf, hfβ© := for_eval rβ W rows h B hlen hwidth candidate | |
| obtain β¨rβ, hcβ© := cleanup_eval rf W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) h | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) | |
| refine β¨_, ?_, rβ, hs.seq (hf.seq hc)β© | |
| simp only [ExecCNFTupleEnumeration.fixedBits_length] | |
| omega | |
| theorem sequence_stack_bound {first second : Code} {n m bound : β} {a b c : Data} | |
| (hf : Eval first n a b) (hs : Eval second m b c) | |
| (hfirst : β p q, p β€ n β Trace (compiled first 19 19) p | |
| (a.withPC (some (compiled first 19 19).entry)) q β β i, (q.stacks i).length β€ bound) | |
| (hsecond : β p q, p β€ m β Trace (compiled second 19 19) p | |
| (b.withPC (some (compiled second 19 19).entry)) q β β i, (q.stacks i).length β€ bound) : | |
| β p q, p β€ n + m β Trace (compiled (.seq first second) 19 19) p | |
| (a.withPC (some (compiled (.seq first second) 19 19).entry)) q β | |
| β i, (q.stacks i).length β€ bound := | |
| StructuredSpace.sequence_stack_bound hf hs 19 19 hfirst hsecond | |
| (compiled (.seq first second) 19 19) (siteAddress _) (exitAddress _) | |
| (compiled_site _ 19 19) | |
| theorem control_space_le (W : List Bool) (rows : List (List (List Bool))) (h B c t : β) | |
| (ht : t β€ 7 * h + 12) : | |
| boundaryBound W (naturalKey W rows h c) rows h + t β€ loopSpace W rows h B c := by | |
| unfold loopSpace boundaryBound | |
| omega | |
| theorem command_stack_bound (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) (fresh : Bool) {n : β} {finish : Data} | |
| (heval : Eval command n | |
| (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| [] fresh [] []) finish) : | |
| β p q, p β€ n + 1 β Trace (compiled command 19 19) p | |
| ((workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| [] fresh [] []).withPC (some (compiled command 19 19).entry)) q β | |
| β i, (q.stacks i).length β€ loopSpace W rows h B candidate := by | |
| obtain β¨rβ, hsβ© := setup_eval regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) fresh | |
| obtain β¨nf, _, rf, hfβ© := for_eval rβ W rows h B hlen hwidth candidate | |
| obtain β¨rβ, hcβ© := cleanup_eval rf W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) h | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) | |
| simp only [ExecCNFTupleEnumeration.fixedBits_length] at hs hc | |
| let base := boundaryBound W (naturalKey W rows h candidate) rows h | |
| have hsetup : β p q, p β€ 7 * h + 12 β Trace (compiled setup 19 19) p | |
| ((workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| [] fresh [] []).withPC (some (compiled setup 19 19).entry)) q β | |
| β i, (q.stacks i).length β€ loopSpace W rows h B candidate := by | |
| intro p q hp hq i | |
| have hb : stackBits (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| [] fresh [] []).stacks β€ base := by | |
| rw [workState_stackBits] | |
| simp only [ExecCNFTupleEnumeration.fixedBits_length, List.length_nil] | |
| dsimp [base, boundaryBound] | |
| omega | |
| have hh := StructuredSpace.local_stack_bound (compiled setup 19 19) | |
| (a := (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| [] fresh [] []).withPC (some (compiled setup 19 19).entry)) | |
| (steps := 7 * h + 12) hb p q hp hq i | |
| exact hh.trans (control_space_le W rows h B candidate _ le_rfl) | |
| have hcleanup : β p q, p β€ 5 * h + 6 β Trace (compiled cleanup 19 19) p | |
| ((workState rf W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (List.replicate h false) | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) [] []).withPC | |
| (some (compiled cleanup 19 19).entry)) q β | |
| β i, (q.stacks i).length β€ loopSpace W rows h B candidate := by | |
| intro p q hp hq i | |
| have hb := boundary_stackBits rf W rows h candidate candidate | |
| (List.replicate h false) (by simp) | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) | |
| have hh := StructuredSpace.local_stack_bound (compiled cleanup 19 19) | |
| (a := (workState rf W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (List.replicate h false) | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) [] []).withPC | |
| (some (compiled cleanup 19 19).entry)) | |
| (steps := 5 * h + 6) (le_of_eq hb) p q hp hq i | |
| exact hh.trans (control_space_le W rows h B candidate _ (by omega)) | |
| have hloop := for_stack_bound rβ W rows h B hlen hwidth candidate hf | |
| have hcleanupCost : 2 * h + 3 * h + 6 = 5 * h + 6 := by omega | |
| rw [hcleanupCost] at hc | |
| have htail := sequence_stack_bound hf hc | |
| (fun p q hp hq i => hloop p q (by omega) hq i) hcleanup | |
| have hwhole := sequence_stack_bound hs (hf.seq hc) hsetup htail | |
| have hhalt := StructuredSpace.compiled_halt_stack_bound (hs.seq (hf.seq hc)) 19 19 hwhole | |
| have htime := StreamResources.eval_steps_eq 19 19 heval (hs.seq (hf.seq hc)) | |
| intro p q hp hq i | |
| rw [htime] at hp | |
| exact hhalt p q hp hq i | |
| /-- Compute the candidate's whole key once and retain it through the rescan. -/ | |
| def prepareKey : Code := .seq (copy 16 12) (.seq keyCall | |
| (.seq (copy 14 17) (.seq (clear 12) (clear 14)))) | |
| theorem prepareKey_eval (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (candidate predecessor : List Bool) (fresh : Bool) | |
| (hlen : β row β rows, row.length = candidate.length) : | |
| β n β€ cost W candidate rows + 9 * candidate.length + | |
| 9 * (signatureValue W candidate rows).length + 17, β out, | |
| Eval prepareKey n (workState regs W rows candidate [] predecessor [] fresh [] []) | |
| (workState out W rows candidate (signatureValue W candidate rows) | |
| predecessor [] fresh [] []) := by | |
| let a := workState regs W rows candidate [] predecessor [] fresh [] [] | |
| let rβ := readRegs regs 0 1 none | |
| have hcopy : Eval (copy 16 12) (7 * candidate.length + 5) a | |
| (workState rβ W rows candidate [] predecessor [] fresh candidate []) := by | |
| have ht := copy_eval 16 12 a (by decide) (by decide) (by decide) rfl | |
| have he : (β¨readRegs a.regs 0 1 none, StackRoutines.copyStacks 16 12 a.stacksβ© : Data) = | |
| workState rβ W rows candidate [] predecessor [] fresh candidate [] := by | |
| apply congrArg (StructuredProgram.State.mk rβ) | |
| funext i | |
| fin_cases i <;> simp [a, workState, StackRoutines.copyStacks] | |
| rw [he] at ht | |
| exact ht | |
| obtain β¨nk, hnk, rk, hkβ© := keyCall_eval rβ W rows candidate [] predecessor [] | |
| fresh candidate [] hlen | |
| simp only [List.append_nil] at hk | |
| let key := signatureValue W candidate rows | |
| let rβ := readRegs rk 0 1 none | |
| have hsave : Eval (copy 14 17) (7 * key.length + 5) | |
| (workState rk W rows candidate [] predecessor [] fresh candidate key) | |
| (workState rβ W rows candidate key predecessor [] fresh candidate key) := by | |
| have ht := copy_eval 14 17 | |
| (workState rk W rows candidate [] predecessor [] fresh candidate key) | |
| (by decide) (by decide) (by decide) rfl | |
| have he : StackRoutines.copyStacks 14 17 | |
| (workState rk W rows candidate [] predecessor [] fresh candidate key).stacks = | |
| (workState rβ W rows candidate key predecessor [] fresh candidate key).stacks := by | |
| funext i | |
| fin_cases i <;> simp [workState, StackRoutines.copyStacks] | |
| rw [he] at ht | |
| exact ht | |
| let rβ := readRegs rβ 0 1 none | |
| have hbits : Eval (clear 12) (2 * candidate.length + 3) | |
| (workState rβ W rows candidate key predecessor [] fresh candidate key) | |
| (workState rβ W rows candidate key predecessor [] fresh [] key) := by | |
| have ht := clear_eval 12 (workState rβ W rows candidate key predecessor [] fresh candidate key) | |
| have he : StackRoutines.clearStacks 12 | |
| (workState rβ W rows candidate key predecessor [] fresh candidate key).stacks = | |
| (workState rβ W rows candidate key predecessor [] fresh [] key).stacks := by | |
| funext i | |
| fin_cases i <;> simp [workState, StackRoutines.clearStacks] | |
| rw [he] at ht | |
| exact ht | |
| let rβ := readRegs rβ 0 1 none | |
| have hkey : Eval (clear 14) (2 * key.length + 3) | |
| (workState rβ W rows candidate key predecessor [] fresh [] key) | |
| (workState rβ W rows candidate key predecessor [] fresh [] []) := by | |
| have ht := clear_eval 14 (workState rβ W rows candidate key predecessor [] fresh [] key) | |
| have he : StackRoutines.clearStacks 14 | |
| (workState rβ W rows candidate key predecessor [] fresh [] key).stacks = | |
| (workState rβ W rows candidate key predecessor [] fresh [] []).stacks := by | |
| funext i | |
| fin_cases i <;> simp [workState, StackRoutines.clearStacks] | |
| rw [he] at ht | |
| exact ht | |
| refine β¨_, ?_, rβ, hcopy.seq (hk.seq (hsave.seq (hbits.seq hkey)))β© | |
| dsimp [key] at * | |
| omega | |
| def candidateCommand : Code := .seq prepareKey command | |
| theorem candidateCommand_eval (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) (fresh : Bool) : | |
| β n β€ cost W (ExecCNFTupleEnumeration.fixedBits h candidate) rows + | |
| 9 * (naturalKey W rows h candidate).length + | |
| candidate.val * (bodyBound W (naturalKey W rows h candidate) rows h B + 16 * h + 16) + | |
| 29 * h + 43, β out, | |
| Eval candidateCommand n | |
| (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) [] | |
| (ExecCNFTupleEnumeration.fixedBits h 0) [] fresh [] []) | |
| (workState out W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (List.replicate h false) [] | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) [] []) := by | |
| obtain β¨np, hnp, rp, hpβ© := prepareKey_eval regs W rows | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| fresh (by simpa using hlen) | |
| obtain β¨nc, hnc, rc, hcβ© := command_eval rp W rows h B hlen hwidth candidate fresh | |
| refine β¨np + nc, ?_, rc, hp.seq hcβ© | |
| simp only [ExecCNFTupleEnumeration.fixedBits_length] at hnp | |
| change np β€ cost W (ExecCNFTupleEnumeration.fixedBits h candidate) rows + | |
| 9 * h + 9 * (naturalKey W rows h candidate).length + 17 at hnp | |
| omega | |
| def candidateProgram := compiled candidateCommand 16 22 | |
| theorem candidate_stack_bound (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) (fresh : Bool) {n : β} {finish : Data} | |
| (heval : Eval candidateCommand n | |
| (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) [] | |
| (ExecCNFTupleEnumeration.fixedBits h 0) [] fresh [] []) finish) : | |
| β p q, p β€ n + 1 β Trace candidateProgram p | |
| ((workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) [] | |
| (ExecCNFTupleEnumeration.fixedBits h 0) [] fresh [] []).withPC | |
| (some candidateProgram.entry)) q β | |
| β i, (q.stacks i).length β€ loopSpace W rows h B candidate := by | |
| obtain β¨np, hnp, rp, hpβ© := prepareKey_eval regs W rows | |
| (ExecCNFTupleEnumeration.fixedBits h candidate) (ExecCNFTupleEnumeration.fixedBits h 0) | |
| fresh (by simpa using hlen) | |
| obtain β¨nc, _, rc, hcβ© := command_eval rp W rows h B hlen hwidth candidate fresh | |
| let base := boundaryBound W (naturalKey W rows h candidate) rows h | |
| have htime : np β€ bodyBound W (naturalKey W rows h candidate) rows h B := by | |
| have hs := cost_le W (ExecCNFTupleEnumeration.fixedBits h candidate) rows B | |
| (by simpa using hlen) hwidth | |
| simp only [ExecCNFTupleEnumeration.fixedBits_length] at hs hnp | |
| unfold bodyBound naturalKey | |
| omega | |
| have hprepare : β p q, p β€ np β Trace (compiled prepareKey 19 19) p | |
| ((workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) [] | |
| (ExecCNFTupleEnumeration.fixedBits h 0) [] fresh [] []).withPC | |
| (some (compiled prepareKey 19 19).entry)) q β | |
| β i, (q.stacks i).length β€ loopSpace W rows h B candidate := by | |
| intro p q hp' hq i | |
| have hb : stackBits (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) [] | |
| (ExecCNFTupleEnumeration.fixedBits h 0) [] fresh [] []).stacks β€ base := by | |
| rw [workState_stackBits] | |
| simp only [ExecCNFTupleEnumeration.fixedBits_length, List.length_nil] | |
| dsimp [base, boundaryBound] | |
| omega | |
| have hh := StructuredSpace.local_stack_bound (compiled prepareKey 19 19) | |
| (a := (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) [] | |
| (ExecCNFTupleEnumeration.fixedBits h 0) [] fresh [] []).withPC | |
| (some (compiled prepareKey 19 19).entry)) | |
| (steps := bodyBound W (naturalKey W rows h candidate) rows h B) | |
| hb p q (hp'.trans htime) hq i | |
| exact hh.trans (Nat.le_max_left _ _) | |
| have hscan := command_stack_bound rp W rows h B hlen hwidth candidate fresh hc | |
| have hwhole := sequence_stack_bound hp hc hprepare | |
| (fun p q hp' hq i => hscan p q (by omega) hq i) | |
| have hconverted := StructuredSpace.command_stack_bound (hp.seq hc) 19 19 hwhole | |
| candidateProgram (siteAddress candidateCommand) (exitAddress candidateCommand) | |
| (compiled_site candidateCommand 16 22) | |
| have hhalt := StructuredSpace.compiled_halt_stack_bound (hp.seq hc) 16 22 hconverted | |
| have hn := StreamResources.eval_steps_eq 16 22 heval (hp.seq hc) | |
| intro p q hp' hq i | |
| rw [hn] at hp' | |
| exact hhalt p q hp' hq i | |
| theorem naturalKey_eq_iff {h d : β} (W : List Bool) | |
| (c : Fin d β Fin h β List Bool) (A : Fin d β Fin h β β€) | |
| (hc : β j i, (BinaryArithmetic.toNat (c j i) : β€) = | |
| (BinaryArithmetic.toNat W : β€) + A j i) (i j : Fin (2 ^ h)) : | |
| naturalKey W (List.ofFn (fun row => List.ofFn (c row))) h i = | |
| naturalKey W (List.ofFn (fun row => List.ofFn (c row))) h j β | |
| AttainedSignatures.integerKey A i = AttainedSignatures.integerKey A j := by | |
| unfold naturalKey | |
| rw [β AttainedSignatures.assignment_word h i, β AttainedSignatures.assignment_word h j] | |
| exact key_eq_iff W c A _ _ hc | |
| /-- Lexicographic comparison with coordinate priority hβ1,...,0: compare | |
| higher coordinates first, and use the low bit only when their tails agree. -/ | |
| inductive ReverseLex : List Bool β List Bool β Prop where | |
| | higher {a b : Bool} {xs ys : List Bool} (h : ReverseLex xs ys) : | |
| ReverseLex (a :: xs) (b :: ys) | |
| | low (xs : List Bool) : ReverseLex (false :: xs) (true :: xs) | |
| theorem reverseLex_iff_value_lt (xs ys : List Bool) (hlen : xs.length = ys.length) : | |
| ReverseLex xs ys β CounterPrograms.value xs < CounterPrograms.value ys := by | |
| induction xs generalizing ys with | |
| | nil => | |
| cases ys with | |
| | nil => constructor <;> intro h <;> cases h | |
| | cons b ys => simp at hlen | |
| | cons a xs ih => | |
| cases ys with | |
| | nil => simp at hlen | |
| | cons b ys => | |
| have hl : xs.length = ys.length := by simpa using hlen | |
| constructor | |
| Β· intro h | |
| cases h with | |
| | higher h => | |
| have hv := (ih ys hl).mp h | |
| cases a <;> cases b <;> simp only [CounterPrograms.value, Bool.toNat_false, Bool.toNat_true] <;> omega | |
| | low => simp [CounterPrograms.value] | |
| Β· intro hv | |
| by_cases ht : CounterPrograms.value xs < CounterPrograms.value ys | |
| Β· exact .higher ((ih ys hl).mpr ht) | |
| have he : CounterPrograms.value xs = CounterPrograms.value ys := by | |
| cases a <;> cases b <;> simp only [CounterPrograms.value, Bool.toNat_false, Bool.toNat_true] at hv <;> omega | |
| have hw := ExecCNFTupleEnumeration.word_eq_of_length_value hl he | |
| subst ys | |
| cases a <;> cases b | |
| Β· simp [CounterPrograms.value] at hv | |
| Β· exact .low xs | |
| Β· simp [CounterPrograms.value] at hv | |
| Β· simp [CounterPrograms.value] at hv | |
| theorem fixedBits_lex_iff (h : β) (i j : Fin (2 ^ h)) : | |
| ReverseLex (ExecCNFTupleEnumeration.fixedBits h i) | |
| (ExecCNFTupleEnumeration.fixedBits h j) β i < j := by | |
| rw [reverseLex_iff_value_lt _ _ (by simp), | |
| ExecCNFTupleEnumeration.fixedBits_value h i i.isLt, | |
| ExecCNFTupleEnumeration.fixedBits_value h j j.isLt] | |
| rfl | |
| theorem actual_increment_lex (h : β) (i : Fin (2 ^ h)) (hi : i.val + 1 < 2 ^ h) : | |
| ReverseLex (ExecCNFTupleEnumeration.fixedBits h i) | |
| (CounterPrograms.ripple true (ExecCNFTupleEnumeration.fixedBits h i)) := by | |
| have hw : CounterPrograms.ripple true (ExecCNFTupleEnumeration.fixedBits h i) = | |
| ExecCNFTupleEnumeration.fixedBits h (i.val + 1) := Counters.increment_word i hi | |
| rw [hw] | |
| exact (fixedBits_lex_iff h i β¨i.val + 1, hiβ©).mpr (show i.val < i.val + 1 from Nat.lt_succ_self _) | |
| /-- A uniform polynomial local budget, before the exponential scan counts. -/ | |
| def polynomialBudget (W : List Bool) (rows : List (List (List Bool))) (h B : β) : β := | |
| 14 * (words (rows.map words)).length + | |
| 2 * (rows.length * (signatureRowBound W h B + 2)) + | |
| 38 * keyBound W h rows.length B + 62 * h + 129 | |
| theorem naturalKey_length_le (W : List Bool) (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) (c : β) : | |
| (naturalKey W rows h c).length β€ keyBound W h rows.length B := by | |
| have ht := signatureValue_length_bound W (ExecCNFTupleEnumeration.fixedBits h c) rows B | |
| (by simpa using hlen) hwidth | |
| simpa only [naturalKey, keyBound, | |
| ExecCNFTupleEnumeration.fixedBits_length] using ht | |
| theorem candidate_time_uniform (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) (fresh : Bool) : | |
| β n β€ (candidate.val + 1) * polynomialBudget W rows h B, β out, | |
| Eval candidateCommand n | |
| (workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) [] | |
| (ExecCNFTupleEnumeration.fixedBits h 0) [] fresh [] []) | |
| (workState out W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (List.replicate h false) [] | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) [] []) := by | |
| obtain β¨n, hn, out, htβ© := candidateCommand_eval regs W rows h B hlen hwidth candidate fresh | |
| have hs := cost_le W (ExecCNFTupleEnumeration.fixedBits h candidate) rows B | |
| (by simpa using hlen) hwidth | |
| simp only [ExecCNFTupleEnumeration.fixedBits_length] at hs | |
| have hk := naturalKey_length_le W rows h B hlen hwidth candidate | |
| have hbody : bodyBound W (naturalKey W rows h candidate) rows h B + 16 * h + 16 β€ | |
| polynomialBudget W rows h B := by unfold bodyBound polynomialBudget; omega | |
| have hsetup : cost W (ExecCNFTupleEnumeration.fixedBits h candidate) rows + | |
| 9 * (naturalKey W rows h candidate).length + 29 * h + 43 β€ | |
| polynomialBudget W rows h B := by unfold polynomialBudget; omega | |
| refine β¨n, ?_, out, htβ© | |
| calc | |
| n β€ candidate.val * polynomialBudget W rows h B + polynomialBudget W rows h B := by | |
| have hm := Nat.mul_le_mul_left candidate.val hbody | |
| omega | |
| _ = (candidate.val + 1) * polynomialBudget W rows h B := by rw [Nat.add_mul, one_mul] | |
| theorem complete_candidate_budget (W : List Bool) (rows : List (List (List Bool))) (h B : β) : | |
| (β candidate : Fin (2 ^ h), | |
| (candidate.val + 1) * polynomialBudget W rows h B) β€ | |
| polynomialBudget W rows h B * 4 ^ h := by | |
| calc | |
| _ β€ β _candidate : Fin (2 ^ h), (2 ^ h) * polynomialBudget W rows h B := by | |
| exact Finset.sum_le_sum (fun candidate _ => Nat.mul_le_mul_right _ (by omega)) | |
| _ = polynomialBudget W rows h B * 4 ^ h := by | |
| simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] | |
| rw [β Nat.mul_assoc, β mul_pow] | |
| ring | |
| def spaceBudget (W : List Bool) (rows : List (List (List Bool))) (h B : β) : β := | |
| 40 * (W.length + (words (rows.map words)).length + keyBound W h rows.length B + 3 * h + 1) + | |
| polynomialBudget W rows h B + 16 | |
| theorem loopSpace_le (W : List Bool) (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) (c : β) : | |
| loopSpace W rows h B c β€ spaceBudget W rows h B := by | |
| have hk := naturalKey_length_le W rows h B hlen hwidth c | |
| have hb : bodyBound W (naturalKey W rows h c) rows h B β€ polynomialBudget W rows h B := by | |
| unfold bodyBound polynomialBudget | |
| omega | |
| unfold loopSpace spaceBudget boundaryBound | |
| omega | |
| /-- One fixed actual candidate machine returns the canonical full key and | |
| freshness bit, with time and every-prefix storage bounds on that same run. -/ | |
| theorem candidate_run (regs : Fin 16 β Bool) (W : List Bool) | |
| (rows : List (List (List Bool))) (h B : β) | |
| (hlen : β row β rows, row.length = h) | |
| (hwidth : β row β rows, β x β row, x.length β€ B) | |
| (candidate : Fin (2 ^ h)) (fresh : Bool) : | |
| β n β€ (candidate.val + 1) * polynomialBudget W rows h B + 1, β out, | |
| Trace candidateProgram n | |
| ((workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) [] | |
| (ExecCNFTupleEnumeration.fixedBits h 0) [] fresh [] []).withPC | |
| (some candidateProgram.entry)) | |
| ((workState out W rows (ExecCNFTupleEnumeration.fixedBits h candidate) | |
| (naturalKey W rows h candidate) (List.replicate h false) [] | |
| (!(AttainedSignatures.duplicateScan (naturalKey W rows h) candidate candidate)) [] []).withPC none) β§ | |
| β prefixSteps intermediate, prefixSteps β€ n β | |
| Trace candidateProgram prefixSteps | |
| ((workState regs W rows (ExecCNFTupleEnumeration.fixedBits h candidate) [] | |
| (ExecCNFTupleEnumeration.fixedBits h 0) [] fresh [] []).withPC | |
| (some candidateProgram.entry)) intermediate β | |
| β i, (intermediate.stacks i).length β€ spaceBudget W rows h B := by | |
| obtain β¨steps, hsteps, out, heβ© := candidate_time_uniform regs W rows h B hlen hwidth candidate fresh | |
| refine β¨steps + 1, Nat.add_le_add_right hsteps 1, out, compiled_halt_trace he 16 22, ?_β© | |
| intro prefixSteps intermediate hle ht i | |
| exact (candidate_stack_bound regs W rows h B hlen hwidth candidate fresh he | |
| prefixSteps intermediate hle ht i).trans (loopSpace_le W rows h B hlen hwidth candidate) | |
| /-- Include each concrete compiled invocation's halt in the full generator | |
| charge; no emitted-key count multiplies the raw candidate scan. -/ | |
| theorem complete_candidate_run_budget (W : List Bool) (rows : List (List (List Bool))) | |
| (h B : β) : | |
| (β candidate : Fin (2 ^ h), | |
| ((candidate.val + 1) * polynomialBudget W rows h B + 1)) β€ | |
| (polynomialBudget W rows h B + 1) * 4 ^ h := by | |
| calc | |
| _ β€ β _candidate : Fin (2 ^ h), (2 ^ h) * (polynomialBudget W rows h B + 1) := by | |
| apply Finset.sum_le_sum | |
| intro candidate _ | |
| have hi : candidate.val + 1 β€ 2 ^ h := by have := candidate.isLt; omega | |
| have hm := Nat.mul_le_mul_right (polynomialBudget W rows h B) hi | |
| have hp : 1 β€ 2 ^ h := Nat.one_le_pow' h 1 | |
| nlinarith | |
| _ = _ := by | |
| simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] | |
| rw [β Nat.mul_assoc, β mul_pow] | |
| ring | |
| /-- Both concrete resource expressions have one fixed degree, independent of | |
| head width, matrix dimensions, coefficient values and the candidate cursor. -/ | |
| theorem budgets_le_monomial (W : List Bool) (rows : List (List (List Bool))) (h B S : β) | |
| (hS : 1 β€ S) (hW : W.length β€ S) (hd : rows.length β€ S) (hh : h β€ S) | |
| (hB : B β€ S) (hM : (words (rows.map words)).length β€ S) : | |
| polynomialBudget W rows h B β€ 100000 * S ^ 6 β§ | |
| spaceBudget W rows h B β€ 100000 * S ^ 6 := by | |
| let width := 1 + S * (S + 1 + S) | |
| let row := (S + 1) * (200 * (width + 2) ^ 2 + 34) + 9 * width + 22 | |
| let signature := 9 * (S * (2 * S + 1)) + 7 + (7 * S + 5) + 2 + | |
| (row + 1) + 8 * (width + 1) + 8 | |
| let key := S * (2 * (width + 1) + 1) | |
| let total := 14 * S + 2 * (S * (signature + 2)) + 38 * key + 62 * S + 129 | |
| have hp : polynomialBudget W rows h B β€ total := by | |
| dsimp [polynomialBudget, keyBound, signatureRowBound, rowCostBound, widthBound, | |
| total, signature, row, key, width] | |
| gcongr | |
| have hk : keyBound W h rows.length B β€ key := by | |
| dsimp [keyBound, widthBound, key, width] | |
| gcongr | |
| have hs : spaceBudget W rows h B β€ 40 * (S + S + key + 3 * S + 1) + total + 16 := by | |
| unfold spaceBudget | |
| gcongr | |
| have h0 : 1 β€ S ^ 6 := one_le_powβ hS | |
| have h1 : S β€ S ^ 6 := Nat.le_self_pow (by decide) _ | |
| have h2 : S ^ 2 β€ S ^ 6 := Nat.pow_le_pow_right hS (by decide) | |
| have h3 : S ^ 3 β€ S ^ 6 := Nat.pow_le_pow_right hS (by decide) | |
| have h4 : S ^ 4 β€ S ^ 6 := Nat.pow_le_pow_right hS (by decide) | |
| have h5 : S ^ 5 β€ S ^ 6 := Nat.pow_le_pow_right hS (by decide) | |
| dsimp [total, signature, row, key, width] at hp hs | |
| constructor <;> nlinarith | |
| end Rescan | |
| end OAI.Algorithms.SubexponentialSAT.SqrtLogSpace.AttainedSignatureProgram | |
Outline
- theorem
workState_fuel_update13 - theorem
nextState_workState22 - theorem
body_scan_eval46 - inductive
ScanInvariant79 - theorem
scan_spec88 - theorem
visits_exists116 - theorem
for_eval151 - theorem
workState_stackBits199 - def
boundaryBound207 - theorem
boundary_stackBits210 - inductive
Boundary220 - theorem
Boundary.stackBits228 - theorem
boundary_after_body235 - theorem
boundary_next268 - theorem
visits_stack_bound283 - def
loopSpace330 - theorem
for_stack_bound336 - def
setup394 - def
cleanup396 - def
command400 - theorem
setup_eval403 - theorem
cleanup_eval423 - theorem
command_eval470 - theorem
sequence_stack_bound494 - theorem
control_space_le507 - theorem
command_stack_bound513 - def
prepareKey586 - theorem
prepareKey_eval589 - def
candidateCommand655 - theorem
candidateCommand_eval657 - def
candidateProgram682 - theorem
candidate_stack_bound684 - theorem
naturalKey_eq_iff739 - inductive
ReverseLex752 - theorem
reverseLex_iff_value_lt757 - theorem
fixedBits_lex_iff789 - theorem
actual_increment_lex797 - def
polynomialBudget806 - theorem
naturalKey_length_le811 - theorem
candidate_time_uniform820 - theorem
complete_candidate_budget849 - def
spaceBudget861 - theorem
loopSpace_le865 - theorem
candidate_run878 - theorem
complete_candidate_run_budget905 - theorem
budgets_le_monomial925