math / data /lean /OAI /Algorithms /SubexponentialSAT /SqrtLog /BucketProgramBounds.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
5.22 kB
import OAI.Algorithms.SubexponentialSAT.LeanCompat
import OAI.Algorithms.SubexponentialSAT.SqrtLog.BucketProgramSignature
namespace OAI.Algorithms
/-! Explicit polynomial bounds for the physical integer-signature scan. -/
namespace SubexponentialSAT.SqrtLog.BucketProgram
open SubexponentialSAT.Subexp.MatrixProgramSupport
theorem words_length_bound (xs : List (List Bool)) (B : ℕ)
(hb : ∀ x∈xs,x.length ≤ B) : (words xs).length ≤ xs.length*(2*B+1) := by
induction xs with
| nil => simp [words]
| cons x xs ih =>
have hx := hb x (by simp)
have ht := ih (fun y hy => hb y (by simp [hy]))
simp only [words,List.length_append,Encoding.length_frame,List.length_cons]
nlinarith
theorem sum_lengths_bound (xs : List (List Bool)) (B : ℕ)
(hb : ∀ x∈xs,x.length ≤ B) : (xs.map List.length).sum ≤ xs.length*B := by
induction xs with
| nil => simp
| cons x xs ih =>
have hx := hb x (by simp)
have ht := ih (fun y hy => hb y (by simp [hy]))
simp only [List.map_cons,List.sum_cons,List.length_cons]
nlinarith
def widthBound (W : List Bool) (h B : ℕ) : ℕ := 1+h*(W.length+1+B)
theorem rowWidth_bound (W : List Bool) (xs : List (List Bool)) (B : ℕ)
(hb : ∀ x∈xs,x.length ≤ B) : rowWidth W xs [true] ≤ widthBound W xs.length B := by
have hs := sum_lengths_bound xs B hb
simp only [rowWidth,List.length_singleton,widthBound]
nlinarith
theorem rowKey_length_bound (W bits : List Bool) (row : List (List Bool))
(hl : row.length=bits.length) :
(rowKey W bits row).length ≤ rowWidth W row [true]+1 := by
obtain ⟨t,ht,rf,out,he,hv,hlen⟩ := rowCommand_eval (fun _ => false) W row bits [true] hl
have hv' : SubexponentialSAT.BinaryArithmetic.toNat out = 1+rowValue W row bits := by
simpa [SubexponentialSAT.BinaryArithmetic.toNat] using hv
have hp : 0 < SubexponentialSAT.CounterPrograms.value out := by
rw [SubexponentialSAT.CounterPrograms.value_eq_toNat,hv']; omega
have hn := SubexponentialSAT.CounterNormalizeProgram.normalized_eq_fixedBits out hp
have htrim := SubexponentialSAT.SubexpParameterProgram.trimTail_length_le out.reverse
have heq : rowKey W bits row = SubexponentialSAT.CounterNormalizeProgram.normalized out := by
rw [hn]
simp only [rowKey,canonical,SubexponentialSAT.CounterPrograms.value_eq_toNat,hv']
rw [heq]
simp only [SubexponentialSAT.CounterNormalizeProgram.normalized,List.length_reverse,List.length_cons]
simp only [List.length_reverse] at htrim
omega
def rowCostBound (W : List Bool) (h B : ℕ) : ℕ :=
(h+1)*(200*(widthBound W h B+2)^2+34)+9*widthBound W h B+22
theorem canonicalRowBudget_bound (W : List Bool) (row : List (List Bool)) (B : ℕ)
(hb : ∀ x∈row,x.length ≤ B) : canonicalRowBudget W row ≤ rowCostBound W row.length B := by
have hw := rowWidth_bound W row B hb
unfold canonicalRowBudget rowBudget rowCostBound
gcongr
def signatureRowBound (W : List Bool) (h B : ℕ) : ℕ :=
9*(h*(2*B+1))+7+(7*h+5)+2+(rowCostBound W h B+1)+8*(widthBound W h B+1)+8
theorem signatureStepCost_bound (W bits : List Bool) (row : List (List Bool)) (B : ℕ)
(hl : row.length=bits.length) (hb : ∀ x∈row,x.length ≤ B) :
signatureStepCost W bits row ≤ signatureRowBound W bits.length B := by
have hw := rowWidth_bound W row B hb
have hk := (rowKey_length_bound W bits row hl).trans (Nat.add_le_add_right hw 1)
have hr := canonicalRowBudget_bound W row B hb
have he := words_length_bound row B hb
rw [hl] at hk hr he
unfold signatureStepCost signatureRowBound
omega
theorem signatureCost_bound (W bits : List Bool) (rows : List (List (List Bool))) (B : ℕ)
(hl : ∀ row∈rows,row.length=bits.length)
(hb : ∀ row∈rows,∀ x∈row,x.length ≤ B) :
signatureCost W bits rows ≤ rows.length*(signatureRowBound W bits.length B+2)+1 := by
unfold signatureCost
suffices hs : (List.map (fun row => signatureStepCost W bits row+2) rows).sum ≤
rows.length*(signatureRowBound W bits.length B+2) by omega
induction rows with
| nil => simp
| cons row rows ih =>
have hx := signatureStepCost_bound W bits row B (hl row (by simp)) (hb row (by simp))
have ht := ih (fun r hr => hl r (by simp [hr])) (fun r hr => hb r (by simp [hr]))
simp only [List.map_cons,List.sum_cons,List.length_cons]
nlinarith
theorem signatureValue_length_bound (W bits : List Bool) (rows : List (List (List Bool))) (B : ℕ)
(hl : ∀ row∈rows,row.length=bits.length)
(hb : ∀ row∈rows,∀ x∈row,x.length ≤ B) :
(signatureValue W bits rows).length ≤ rows.length*(2*(widthBound W bits.length B+1)+1) := by
have hs : ∀ x∈(rows.map (rowKey W bits)).reverse, x.length ≤ widthBound W bits.length B+1 := by
intro x hx
obtain ⟨row,hr,rfl⟩ := List.mem_map.mp (List.mem_reverse.mp hx)
have hrw := rowWidth_bound W row B (hb row hr)
rw [hl row hr] at hrw
exact (rowKey_length_bound W bits row (hl row hr)).trans (Nat.add_le_add_right hrw 1)
simpa [signatureValue] using words_length_bound (rows.map (rowKey W bits)).reverse
(widthBound W bits.length B+1) hs
end SubexponentialSAT.SqrtLog.BucketProgram
end OAI.Algorithms