math / data /lean /OAI /Combinatorics /EditApproximation /Binary /BinaryBellmanReads.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
4.11 kB
import OAI.Combinatorics.EditApproximation.Binary.BinaryBellmanKernel
import OAI.Combinatorics.EditApproximation.Binary.BinaryReadComposition
import OAI.Combinatorics.EditApproximation.Definitions
namespace OAI
/-! Bellman action evaluation with literal finite-table reader calls.
Child words are gathered once, then Boolean arithmetic
operates on that stored list. Reader scans are part of the returned cost. -/
namespace EditApproximation
namespace BinaryFraction
theorem bellmanActionReadWithWork_eq {Parent Child : Type*} {M : β„•}
(distance : Parent β†’ Parent β†’ BinaryFraction Γ— β„•) (L : BinaryFraction)
(read : Child β†’ BinaryFraction Γ— β„•) (query : Parent)
(action : BinaryBellmanAction Parent Child M) :
(bellmanActionReadWithWork distance L read query action).1 =
(bellmanActionWithWork distance L (fun s => (read s).1) query action).1 := by
simp only [bellmanActionReadWithWork, arithmeticMapWithWork_value,
bellmanActionWithWork, List.ofFn_eq_map]
theorem bellmanActionReadWithWork_cost {Parent Child : Type*} {M : β„•}
(distance : Parent β†’ Parent β†’ BinaryFraction Γ— β„•) (L : BinaryFraction)
(read : Child β†’ BinaryFraction Γ— β„•) (query : Parent)
(action : BinaryBellmanAction Parent Child M) (R : β„•)
(hread : βˆ€ i, (read (action.childState i)).2 ≀ R) :
(bellmanActionReadWithWork distance L read query action).2 ≀
(bellmanActionWithWork distance L (fun s => (read s).1) query action).2 + M * (R + 3) := by
have h := arithmeticMapWithWork_cost (fun i => read (action.childState i))
(List.finRange M) R (fun i _ => hread i)
simp only [List.length_finRange] at h
simp only [bellmanActionReadWithWork, arithmeticMapWithWork_value,
bellmanActionWithWork, List.ofFn_eq_map]
omega
theorem bellmanReadWithWork_eq {Parent Child : Type*} {M : β„•}
(distance : Parent β†’ Parent β†’ BinaryFraction Γ— β„•) (L fallback : BinaryFraction)
(read : Child β†’ BinaryFraction Γ— β„•) (query : Parent)
(actions : List (BinaryBellmanAction Parent Child M)) :
(bellmanReadWithWork distance L fallback read query actions).1 =
(bellmanWithWork distance L fallback (fun s => (read s).1) query actions).1 := by
simp only [bellmanReadWithWork, bellmanWithWork, arithmeticMapWithWork_value,
bellmanActionReadWithWork_eq]
theorem bellmanReadWithWork_cost {Parent Child : Type*} {M : β„•}
(distance : Parent β†’ Parent β†’ BinaryFraction Γ— β„•) (L fallback : BinaryFraction)
(read : Child β†’ BinaryFraction Γ— β„•) (query : Parent)
(actions : List (BinaryBellmanAction Parent Child M)) (R : β„•)
(hread : βˆ€ action ∈ actions, βˆ€ i, (read (action.childState i)).2 ≀ R) :
(bellmanReadWithWork distance L fallback read query actions).2 ≀
(bellmanWithWork distance L fallback (fun s => (read s).1) query actions).2 +
actions.length * (M * (R + 3)) := by
have h := arithmeticMapWithWork_extra
(bellmanActionReadWithWork distance L read query)
(bellmanActionWithWork distance L (fun s => (read s).1) query)
(fun _ => M * (R + 3)) actions
(fun action _ => bellmanActionReadWithWork_eq distance L read query action)
(fun action ha => bellmanActionReadWithWork_cost distance L read query action R (hread action ha))
have hs : (actions.map (fun _ => M * (R + 3))).sum = actions.length * (M * (R + 3)) := by
simp only [List.map_const', List.sum_replicate, smul_eq_mul]
rw [hs] at h
unfold bellmanReadWithWork bellmanWithWork
dsimp only
rw [h.1]
omega
theorem bellmanWithWork_action_count {Parent Child : Type*} {M : β„•}
(distance : Parent β†’ Parent β†’ BinaryFraction Γ— β„•) (L fallback : BinaryFraction)
(child : Child β†’ BinaryFraction) (query : Parent)
(actions : List (BinaryBellmanAction Parent Child M)) :
actions.length ≀ (bellmanWithWork distance L fallback child query actions).2 := by
have h := arithmeticMapWithWork_length_le_cost
(bellmanActionWithWork distance L child query) actions
change actions.length ≀ _ + _ + 1
omega
end BinaryFraction
end EditApproximation
end OAI