Buckets:
| import OAI.Combinatorics.EditApproximation.Geometry.MemoizedOracle | |
| import OAI.Combinatorics.EditApproximation.Definitions | |
| namespace OAI | |
| /-! Well-founded recursive memo evaluation. A local query program may | |
| choose later requests from earlier answers. Each recursive request carries | |
| its strict rank decrease; no complete table is evaluated in advance. -/ | |
| namespace EditApproximation | |
| namespace FiniteQuery | |
| def value {ι : Type*} (oracle : ι → ℚ) : FiniteQuery ι → ℚ | |
| | .done result => result | |
| | .read key next => value oracle (next (oracle key)) | |
| theorem run_sound {ι κ : Type*} (bits : ℕ) (encode : κ → ℕ) | |
| (expected : κ → ℚ) (answer : ι → ℚ) | |
| (ask : ι → BinaryMemo ℚ → RecursiveMemoResult κ) | |
| (hask : ∀ key memory, memoSound bits encode expected memory → | |
| (ask key memory).value = answer key ∧ | |
| memoSound bits encode expected (ask key memory).memory) | |
| (program : FiniteQuery ι) (memory : BinaryMemo ℚ) | |
| (hsound : memoSound bits encode expected memory) : | |
| (run ask program memory).value = program.value answer ∧ | |
| memoSound bits encode expected (run ask program memory).memory := by | |
| induction program generalizing memory with | |
| | done result => exact ⟨rfl, hsound⟩ | |
| | read key next ih => | |
| have hfirst := hask key memory hsound | |
| have hrest := ih (ask key memory).value (ask key memory).memory hfirst.2 | |
| refine ⟨?_, hrest.2⟩ | |
| simpa only [run, value, hfirst.1] using hrest.1 | |
| /-- Gather a finite list before running the dependent local continuation. -/ | |
| def gather {ι : Type*} : List ι → (List ℚ → FiniteQuery ι) → FiniteQuery ι | |
| | [], next => next [] | |
| | key :: keys, next => .read key (fun result => gather keys (fun results => next (result :: results))) | |
| theorem gather_value {ι : Type*} (oracle : ι → ℚ) (keys : List ι) | |
| (next : List ℚ → FiniteQuery ι) : | |
| (gather keys next).value oracle = (next (keys.map oracle)).value oracle := by | |
| induction keys generalizing next with | |
| | nil => rfl | |
| | cons key keys ih => exact ih (fun results => next (oracle key :: results)) | |
| end FiniteQuery | |
| def rankedProgramValue {κ : Type*} (rank : κ → ℕ) | |
| (program : (key : κ) → FiniteQuery {child : κ // rank child < rank key}) (key : κ) : ℚ := | |
| (program key).value (fun child => rankedProgramValue rank program child.val) | |
| termination_by rank key | |
| decreasing_by exact child.property | |
| theorem memoSound_insert {κ : Type*} (bits : ℕ) (encode : κ → ℕ) | |
| (hinjective : Function.Injective encode) (hbounded : ∀ key, encode key < 2 ^ bits) | |
| (expected : κ → ℚ) (memory : BinaryMemo ℚ) | |
| (hsound : memoSound bits encode expected memory) (key : κ) : | |
| memoSound bits encode expected | |
| (memory.insert (binaryMemoKey bits (encode key)) (expected key)) := by | |
| intro other result hresult | |
| rw [binaryMemo_lookup_insert _ bits (encode key) (encode other) | |
| (hbounded key) (hbounded other)] at hresult | |
| split_ifs at hresult with heq | |
| · have hkey : other = key := hinjective heq | |
| subst other | |
| exact Option.some.inj hresult.symm | |
| · exact hsound other result hresult | |
| theorem rankedMemoEvaluate_sound {κ : Type*} (rank : κ → ℕ) | |
| (program : (key : κ) → FiniteQuery {child : κ // rank child < rank key}) | |
| (bits : ℕ) (encode : κ → ℕ) (hinjective : Function.Injective encode) | |
| (hbounded : ∀ key, encode key < 2 ^ bits) (key : κ) (memory : BinaryMemo ℚ) | |
| (hsound : memoSound bits encode (rankedProgramValue rank program) memory) : | |
| (rankedMemoEvaluate rank program bits encode key memory).value = rankedProgramValue rank program key ∧ | |
| memoSound bits encode (rankedProgramValue rank program) | |
| (rankedMemoEvaluate rank program bits encode key memory).memory := by | |
| have hall : ∀ level key, rank key = level → ∀ memory, | |
| memoSound bits encode (rankedProgramValue rank program) memory → | |
| (rankedMemoEvaluate rank program bits encode key memory).value = rankedProgramValue rank program key ∧ | |
| memoSound bits encode (rankedProgramValue rank program) | |
| (rankedMemoEvaluate rank program bits encode key memory).memory := by | |
| intro level | |
| induction level using Nat.strong_induction_on with | |
| | h level ih => | |
| intro key hlevel memory hmemory | |
| rw [rankedMemoEvaluate] | |
| simp only [BinaryMemo.lookupCosted_spec] | |
| split | |
| · rename_i result hresult | |
| exact ⟨hmemory key result hresult, hmemory⟩ | |
| · have hchildren : ∀ (child : {child : κ // rank child < rank key}) previous, | |
| memoSound bits encode (rankedProgramValue rank program) previous → | |
| (rankedMemoEvaluate rank program bits encode child.val previous).value = | |
| rankedProgramValue rank program child.val ∧ | |
| memoSound bits encode (rankedProgramValue rank program) | |
| (rankedMemoEvaluate rank program bits encode child.val previous).memory := by | |
| intro child previous hprevious | |
| exact ih (rank child.val) (hlevel ▸ child.property) child.val rfl previous hprevious | |
| have hrun := FiniteQuery.run_sound bits encode (rankedProgramValue rank program) | |
| (fun child : {child : κ // rank child < rank key} => rankedProgramValue rank program child.val) | |
| (fun child previous => rankedMemoEvaluate rank program bits encode child.val previous) | |
| hchildren (program key) memory hmemory | |
| have hvalue : (FiniteQuery.run | |
| (fun child previous => rankedMemoEvaluate rank program bits encode child.val previous) | |
| (program key) memory).value = rankedProgramValue rank program key := by | |
| rw [rankedProgramValue] | |
| exact hrun.1 | |
| simp only [BinaryMemo.insertCosted_spec] | |
| refine ⟨hvalue, ?_⟩ | |
| rw [hvalue] | |
| exact memoSound_insert bits encode hinjective hbounded _ _ hrun.2 key | |
| exact hall (rank key) key rfl memory hsound | |
| theorem rankedMemoEvaluate_empty {κ : Type*} (rank : κ → ℕ) | |
| (program : (key : κ) → FiniteQuery {child : κ // rank child < rank key}) | |
| (bits : ℕ) (encode : κ → ℕ) (hinjective : Function.Injective encode) | |
| (hbounded : ∀ key, encode key < 2 ^ bits) (key : κ) : | |
| (rankedMemoEvaluate rank program bits encode key .empty).value = rankedProgramValue rank program key := | |
| (rankedMemoEvaluate_sound rank program bits encode hinjective hbounded key .empty | |
| (memoSound_empty bits encode _)).1 | |
| end EditApproximation | |
| end OAI | |
Xet Storage Details
- Size:
- 6.5 kB
- Xet hash:
- 410e644b17bd2c735dc02bf669cfdffc5d2b16ecaaa307af194ea0263a7ff375
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.