File size: 7,964 Bytes
9dbc64e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | import OAI.Computability.DegreeRigidity.Computability.BinaryMachine
import OAI.Computability.DegreeRigidity.Computability.BranchFrequency
import OAI.Computability.DegreeRigidity.Effective.ProgramSelection
import Mathlib.Order.Interval.Finset.Basic
namespace OAI
namespace TuringRigidity.GenericCoding
open UniformOracle BinarySeries Encodable
def count (G : Oracle) : ℕ → ℕ := runningSum (fun n => bit G (2*n+1))
def code (A G : Oracle) (n : ℕ) : Bool :=
if G (2*n+1) then A (count G n) else G (2*(n-count G n))
theorem count_le (G : Oracle) (n : ℕ) : count G n ≤ n := by
induction n with
| zero => rfl
| succ n ih =>
change count G n + bit G (2*n+1) ≤ n+1
unfold bit
split <;> omega
theorem count_mono (G : Oracle) : Monotone (count G) := by
apply monotone_nat_of_le_succ
intro n
change count G n ≤ count G n + bit G (2*n+1)
omega
def InfiniteOdd (G : Oracle) : Prop := ∀ N, ∃ n, N ≤ n ∧ G (2*n+1) = true
theorem infiniteOdd_iff (G : Oracle) : InfiniteOdd G ↔ {n | G (2*n+1) = true}.Infinite := by
constructor
· intro h
apply Set.infinite_of_forall_exists_gt
intro N
obtain ⟨n,hn,hb⟩ := h (N+1)
exact ⟨n,hb,by omega⟩
· intro h N
obtain ⟨n,hb,hn⟩ := h.exists_gt N
exact ⟨n,by omega,hb⟩
theorem count_unbounded (G : Oracle) (hG : InfiniteOdd G) (k : ℕ) :
∃ n, k ≤ count G n := by
induction k with
| zero => exact ⟨0,by simp [count,runningSum]⟩
| succ k ih =>
obtain ⟨n,hn⟩ := ih
obtain ⟨m,hm,hb⟩ := hG n
have hc := count_mono G hm
refine ⟨m+1,?_⟩
change k+1 ≤ count G m + bit G (2*m+1)
simp only [bit,hb,↓reduceIte]
omega
theorem exists_insertion (G : Oracle) (hG : InfiniteOdd G) (k : ℕ) :
∃ n, count G n = k ∧ G (2*n+1) = true := by
have hi : ∀ m, k < count G m → ∃ n, count G n = k ∧ G (2*n+1) = true := by
intro m
induction m with
| zero => simp [count,runningSum]
| succ m ih =>
intro hm
by_cases hk : k < count G m
· exact ih hk
· change k < count G m + bit G (2*m+1) at hm
cases hb : G (2*m+1) with
| false => simp [bit,hb] at hm; omega
| true => exact ⟨m,by simp [bit,hb] at hm; omega,hb⟩
obtain ⟨m,hm⟩ := count_unbounded G hG (k+1)
exact hi m (by omega)
theorem count_recursive {O : Set (ℕ →. ℕ)} (G : Oracle)
(hG : Nat.RecursiveIn O (oracleFunction G)) :
Nat.RecursiveIn O (fun n => Part.some (count G n)) :=
runningSum_recursive (total_comp hG (total_primrec
(Primrec.succ.comp (Primrec.nat_mul.comp (Primrec.const 2) Primrec.id))))
theorem code_recursive {O : Set (ℕ →. ℕ)} (A G : Oracle)
(hA : Nat.RecursiveIn O (oracleFunction A)) (hG : Nat.RecursiveIn O (oracleFunction G)) :
Nat.RecursiveIn O (oracleFunction (code A G)) := by
have hc := count_recursive G hG
have ho := total_comp hG (total_primrec
(Primrec.succ.comp (Primrec.nat_mul.comp (Primrec.const 2) Primrec.id)))
have ha := total_comp hA hc
have hi := total_comp (total_primrec (Primrec.nat_mul.comp (Primrec.const 2)
(Primrec.nat_sub.comp (Primrec.fst.comp Primrec.unpair) (Primrec.snd.comp Primrec.unpair))))
(total_pair (total_primrec Primrec.id) hc)
have he := total_comp hG hi
have hd : Primrec (fun z : ℕ => if (Nat.unpair z).1=1 then
(Nat.unpair (Nat.unpair z).2).1 else (Nat.unpair (Nat.unpair z).2).2) :=
Primrec.ite (Primrec.eq.comp (Primrec.fst.comp Primrec.unpair) (Primrec.const 1))
(Primrec.fst.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))
(Primrec.snd.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))
exact (total_comp (total_primrec hd) (total_pair ho (total_pair ha he))).of_eq (fun n => by
cases hh : G (2*n+1) <;> simp [code,oracleFunction,hh])
theorem code_reduces (A G : Oracle) : Reduces (code A G) (join A G) := by
apply RecursiveIn.iff_nat.mpr
exact code_recursive A G (RecursiveIn.iff_nat.mp (reduces_join_left A G))
(RecursiveIn.iff_nat.mp (reduces_join_right A G))
def recoverDecision (z : ℕ × ℕ × ℕ × ℕ) : Option ℕ :=
if z.1=z.2.1 ∧ z.2.2.1=1 then some z.2.2.2 else none
theorem recoverDecision_primrec : Primrec recoverDecision :=
Primrec.ite ((Primrec.eq.comp Primrec.fst (Primrec.fst.comp Primrec.snd)).and
(Primrec.eq.comp (Primrec.fst.comp (Primrec.snd.comp Primrec.snd)) (Primrec.const 1)))
(Primrec.option_some.comp (Primrec.snd.comp (Primrec.snd.comp Primrec.snd))) (Primrec.const none)
def recoverTrial (A G : Oracle) (k n : ℕ) : Option ℕ :=
recoverDecision (k,count G n,bit G (2*n+1),bit (code A G) n)
theorem recoverTrial_recursive (A G : Oracle) :
Nat.RecursiveIn {oracleFunction (join (code A G) G)}
(fun z => Part.some (encode (recoverTrial A G (Nat.unpair z).1 (Nat.unpair z).2))) := by
let O : Set (ℕ →. ℕ) := {oracleFunction (join (code A G) G)}
have hg : Nat.RecursiveIn O (oracleFunction G) := RecursiveIn.iff_nat.mp (reduces_join_right (code A G) G)
have ha : Nat.RecursiveIn O (oracleFunction (code A G)) := RecursiveIn.iff_nat.mp (reduces_join_left (code A G) G)
have hk := total_primrec (O := O) (Primrec.fst.comp Primrec.unpair)
have hn := total_primrec (O := O) (Primrec.snd.comp Primrec.unpair)
have hc := total_comp (count_recursive G hg) hn
have ho := total_comp hg (total_primrec (Primrec.succ.comp
(Primrec.nat_mul.comp (Primrec.const 2) (Primrec.snd.comp Primrec.unpair))))
have ha' := total_comp ha hn
have hd := (Primrec.fst.comp Primrec.unpair).pair
(((Primrec.fst.comp Primrec.unpair).pair
(Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair))).comp (Primrec.snd.comp Primrec.unpair))
exact (total_comp (total_primrec (Primrec.encode.comp (recoverDecision_primrec.comp hd)))
(total_pair hk (total_pair hc (total_pair ho ha')))).of_eq (fun z => by simp [recoverTrial,bit])
theorem recoverTrial_sound (A G : Oracle) (k n a : ℕ) (ha : a ∈ recoverTrial A G k n) :
a = bit A k := by
unfold recoverTrial recoverDecision at ha
split at ha
· rename_i h
have hg : G (2*n+1) = true := by cases hh : G (2*n+1) <;> simp_all [bit]
have hk : k = count G n := h.1
simpa [bit,code,hg,←hk] using (Option.mem_def.mp ha).symm
· simp at ha
theorem recoverTrial_complete (A G : Oracle) (hG : InfiniteOdd G) (k : ℕ) :
∃ n a, a ∈ recoverTrial A G k n := by
obtain ⟨n,hn,hg⟩ := exists_insertion G hG k
exact ⟨n,bit A k,by simp [recoverTrial,recoverDecision,hn,hg,bit,code]⟩
theorem set_reduces_code_join (A G : Oracle) (hG : InfiniteOdd G) :
Reduces A (join (code A G) G) := by
apply RecursiveIn.iff_nat.mpr
exact total_search (recoverTrial_recursive A G) (bit A) (recoverTrial_sound A G)
(recoverTrial_complete A G hG)
theorem join_degree_eq (A G : Oracle) (hG : InfiniteOdd G) :
degree (join (code A G) G) = degree (join A G) := by
apply (degree_eq_iff _ _).mpr
exact ⟨join_reduces (code_reduces A G) (reduces_join_right A G),
join_reduces (set_reduces_code_join A G hG) (reduces_join_right (code A G) G)⟩
theorem source_join_degree_eq (A G : Oracle) (hG : {n | G (2*n+1) = true}.Infinite) :
degree (join (code A G) G) = degree (join A G) :=
join_degree_eq A G ((infiniteOdd_iff G).mpr hG)
theorem forward_single_program (A G : Oracle) :
∃ p : OracleCode, ∀ n, OracleCode.eval (oracleFunction (join A G)) p n = oracleFunction (code A G) n := by
obtain ⟨p,hp⟩ := (OracleCode.turingReducible_iff_exists_code _ _).mp (code_reduces A G)
exact ⟨p,fun n => congrFun hp n⟩
theorem inverse_single_program (A G : Oracle) (hG : InfiniteOdd G) :
∃ p : OracleCode, ∀ n, OracleCode.eval (oracleFunction (join (code A G) G)) p n = oracleFunction A n := by
obtain ⟨p,hp⟩ := (OracleCode.turingReducible_iff_exists_code _ _).mp (set_reduces_code_join A G hG)
exact ⟨p,fun n => congrFun hp n⟩
end TuringRigidity.GenericCoding
end OAI
|