Buckets:
| import OAI.Computability.DegreeRigidity.Computability.OracleCode | |
| import Mathlib.Computability.Primrec.List | |
| namespace OAI | |
| namespace TuringRigidity.PrefixComputability | |
| open Encodable | |
| variable {O : Set (ℕ →. ℕ)} | |
| theorem total_comp {f g : ℕ → ℕ} | |
| (hf : Nat.RecursiveIn O (fun n => Part.some (f n))) | |
| (hg : Nat.RecursiveIn O (fun n => Part.some (g n))) : | |
| Nat.RecursiveIn O (fun n => Part.some (f (g n))) := by | |
| simpa using Nat.RecursiveIn.comp hf hg | |
| theorem total_pair {f g : ℕ → ℕ} | |
| (hf : Nat.RecursiveIn O (fun n => Part.some (f n))) | |
| (hg : Nat.RecursiveIn O (fun n => Part.some (g n))) : | |
| Nat.RecursiveIn O (fun n => Part.some (Nat.pair (f n) (g n))) := by | |
| simpa [Seq.seq] using Nat.RecursiveIn.pair hf hg | |
| theorem total_primrec {f : ℕ → ℕ} (hf : Primrec f) : | |
| Nat.RecursiveIn O (fun n => Part.some (f n)) := | |
| RecursiveIn.iff_nat.mp hf.computableIn | |
| def oraclePrefix (g : ℕ → ℕ) (m : ℕ) : List ℕ := (List.range m).map g | |
| def appendEncoded (a b : ℕ) : ℕ := encode ((decode (α := List ℕ) a).getD [] ++ [b]) | |
| theorem appendEncoded_primrec : Primrec₂ appendEncoded := | |
| Primrec.encode.comp (Primrec.list_append.comp | |
| (Primrec.option_getD_default.comp (Primrec.decode.comp Primrec.fst)) | |
| (Primrec.list_cons.comp Primrec.snd (Primrec.const []))) | |
| theorem prefix_recursive (g : ℕ → ℕ) : | |
| Nat.RecursiveIn {fun n => Part.some (g n)} (fun m => Part.some (encode (oraclePrefix g m))) := by | |
| have hquery : Nat.RecursiveIn {fun n => Part.some (g n)} (fun n => Part.some (g n)) := | |
| .oracle _ (Set.mem_singleton _) | |
| have hy := (total_primrec (O := {fun n => Part.some (g n)})) (Primrec.fst.comp (Primrec.unpair.comp | |
| (Primrec.snd.comp Primrec.unpair))) | |
| have hi := (total_primrec (O := {fun n => Part.some (g n)})) (Primrec.snd.comp (Primrec.unpair.comp | |
| (Primrec.snd.comp Primrec.unpair))) | |
| have hs := total_comp ((total_primrec (O := {fun n => Part.some (g n)})) (appendEncoded_primrec.comp | |
| (Primrec.fst.comp Primrec.unpair) (Primrec.snd.comp Primrec.unpair))) | |
| (total_pair hi (total_comp hquery hy)) | |
| have hp := Nat.RecursiveIn.prec ((total_primrec (O := {fun n => Part.some (g n)})) (Primrec.const (encode ([] : List ℕ)))) hs | |
| have hh := Nat.RecursiveIn.comp hp | |
| (total_pair ((total_primrec (O := {fun n => Part.some (g n)})) (Primrec.const 0)) ((total_primrec (O := {fun n => Part.some (g n)})) Primrec.id)) | |
| apply hh.of_eq | |
| intro n | |
| change (Part.some (Nat.pair 0 n)).bind _ = _ | |
| rw [Part.bind_some] | |
| simp only [Nat.unpair_pair] | |
| induction n with | |
| | zero => rfl | |
| | succ n ih => | |
| simp only [ih] | |
| simp [appendEncoded, oraclePrefix, List.range_succ] | |
| private def flag (e : ℕ) : ℕ := | |
| if ((decode (α := Option ℕ) e).getD none).isSome then 0 else 1 | |
| private def answer (e : ℕ) : ℕ := ((decode (α := Option ℕ) e).getD none).getD 0 | |
| private theorem flag_primrec : Primrec flag := by | |
| apply (Primrec.cond (Primrec.option_isSome.comp (Primrec.option_getD_default.comp (Primrec.decode (α := Option ℕ)))) | |
| (Primrec.const 0) (Primrec.const 1)).of_eq | |
| intro n | |
| change (cond ((decode (α := Option ℕ) n).getD none).isSome 0 1) = _ | |
| cases hh : ((decode (α := Option ℕ) n).getD none).isSome <;> simp only [flag,hh] <;> rfl | |
| private theorem answer_primrec : Primrec answer := | |
| Primrec.option_getD_default.comp (Primrec.option_getD_default.comp Primrec.decode) | |
| theorem total_search {E : ℕ → ℕ → Option ℕ} | |
| (hE : Nat.RecursiveIn O (fun z => Part.some (encode (E (Nat.unpair z).1 (Nat.unpair z).2)))) | |
| (f : ℕ → ℕ) (hsound : ∀ n m a, a ∈ E n m → a = f n) | |
| (hcomplete : ∀ n, ∃ m a, a ∈ E n m) : | |
| Nat.RecursiveIn O (fun n => Part.some (f n)) := by | |
| have hflag := total_comp (total_primrec flag_primrec) hE | |
| have hfind := Nat.RecursiveIn.rfind hflag | |
| have hpair := Nat.RecursiveIn.pair (total_primrec Primrec.id) hfind | |
| have hrun := Nat.RecursiveIn.comp (total_primrec answer_primrec) | |
| (Nat.RecursiveIn.comp hE hpair) | |
| apply hrun.of_eq_tot | |
| intro n | |
| have hex : ∃ m, (E n m).isSome = true := by | |
| obtain ⟨m,a,ha⟩ := hcomplete n | |
| exact ⟨m, Option.isSome_iff_exists.mpr ⟨a,ha⟩⟩ | |
| let m := Nat.find hex | |
| have hm := Nat.find_spec hex | |
| obtain ⟨a,ha⟩ := Option.isSome_iff_exists.mp hm | |
| have hval : a = f n := hsound n m a ha | |
| have hmem : m ∈ Nat.rfind (fun k => | |
| (fun v : ℕ => decide (v=0)) <$> Part.some (flag (encode (E n k)))) := by | |
| apply Nat.mem_rfind.mpr | |
| constructor | |
| · simp [flag, m, hm] | |
| · intro k hk | |
| have hk' : (E n k).isSome = false := Bool.eq_false_iff.mpr (Nat.find_min hex hk) | |
| simp [flag, hk'] | |
| apply Part.mem_bind_iff.mpr | |
| refine ⟨encode (E n m), ?_, ?_⟩ | |
| · apply Part.mem_bind_iff.mpr | |
| refine ⟨Nat.pair n m, ?_, ?_⟩ | |
| · simp only [Seq.seq] | |
| apply Part.mem_bind_iff.mpr | |
| refine ⟨Nat.pair n, (Part.mem_map_iff _).mpr ⟨n,Part.mem_some _,rfl⟩, ?_⟩ | |
| exact (Part.mem_map_iff _).mpr ⟨m,by simpa only [Nat.unpair_pair] using hmem,rfl⟩ | |
| · simp | |
| · have hea : E n m = some a := Option.mem_def.mp ha | |
| apply Part.mem_some_iff.mpr | |
| rw [hea] | |
| simpa only [answer, Encodable.encodek, Option.getD_some] using hval.symm | |
| end TuringRigidity.PrefixComputability | |
| end OAI | |
Xet Storage Details
- Size:
- 5.26 kB
- Xet hash:
- c86ffbd00837c1cce4f6c52019469431dd03db026ffb42040df5072f004701d3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.