roseking commited on
Commit
9dbc64e
·
verified ·
1 Parent(s): 8df23f4

Add lean source and binary files (part 60)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPersistenceDegreeModel.lean +72 -0
  2. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPrefixFamilies.lean +49 -0
  3. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPrefixForcing.lean +100 -0
  4. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPresentation.lean +50 -0
  5. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPresentationProperty.lean +98 -0
  6. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPrincipalIntersection.lean +52 -0
  7. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticProgramGraph.lean +43 -0
  8. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticRelations.lean +75 -0
  9. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticSetSyntax.lean +103 -0
  10. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticShuffleCertificate.lean +59 -0
  11. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticShuffleGraph.lean +77 -0
  12. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticSkolem.lean +165 -0
  13. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticSourceEquation.lean +31 -0
  14. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticSourceTruth.lean +48 -0
  15. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTables.lean +100 -0
  16. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTestApproximation.lean +155 -0
  17. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTreeDefinability.lean +110 -0
  18. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTreeDescent.lean +85 -0
  19. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTreeSequence.lean +87 -0
  20. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTruthRequirements.lean +133 -0
  21. lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticWitnessTree.lean +127 -0
  22. lean/OAI/Computability/DegreeRigidity/Computability/BinaryCut.lean +99 -0
  23. lean/OAI/Computability/DegreeRigidity/Computability/BinaryMachine.lean +110 -0
  24. lean/OAI/Computability/DegreeRigidity/Computability/BinaryRecovery.lean +131 -0
  25. lean/OAI/Computability/DegreeRigidity/Computability/BinarySeries.lean +91 -0
  26. lean/OAI/Computability/DegreeRigidity/Computability/BranchFrequency.lean +71 -0
  27. lean/OAI/Computability/DegreeRigidity/Computability/BranchMachine.lean +143 -0
  28. lean/OAI/Computability/DegreeRigidity/Computability/BranchRecovery.lean +156 -0
  29. lean/OAI/Computability/DegreeRigidity/Computability/CutAddition.lean +140 -0
  30. lean/OAI/Computability/DegreeRigidity/Computability/CutArithmetic.lean +82 -0
  31. lean/OAI/Computability/DegreeRigidity/Computability/CutTranscript.lean +102 -0
  32. lean/OAI/Computability/DegreeRigidity/Computability/Cuts.lean +63 -0
  33. lean/OAI/Computability/DegreeRigidity/Computability/DegreeCoverage.lean +52 -0
  34. lean/OAI/Computability/DegreeRigidity/Computability/EffectiveRecovery.lean +223 -0
  35. lean/OAI/Computability/DegreeRigidity/Computability/Introreducible.lean +159 -0
  36. lean/OAI/Computability/DegreeRigidity/Computability/Joins.lean +126 -0
  37. lean/OAI/Computability/DegreeRigidity/Computability/JumpIdeal.lean +55 -0
  38. lean/OAI/Computability/DegreeRigidity/Computability/JumpIdealPresentation.lean +88 -0
  39. lean/OAI/Computability/DegreeRigidity/Computability/JumpIterationFormula.lean +39 -0
  40. lean/OAI/Computability/DegreeRigidity/Computability/JumpProperties.lean +85 -0
  41. lean/OAI/Computability/DegreeRigidity/Computability/JumpSetFormula.lean +75 -0
  42. lean/OAI/Computability/DegreeRigidity/Computability/NormalizedRecovery.lean +48 -0
  43. lean/OAI/Computability/DegreeRigidity/Computability/OracleCode.lean +125 -0
  44. lean/OAI/Computability/DegreeRigidity/Computability/OracleEnumeration.lean +96 -0
  45. lean/OAI/Computability/DegreeRigidity/Computability/OracleJump.lean +90 -0
  46. lean/OAI/Computability/DegreeRigidity/Computability/RationalCoding.lean +157 -0
  47. lean/OAI/Computability/DegreeRigidity/Computability/RationalCut.lean +82 -0
  48. lean/OAI/Computability/DegreeRigidity/Computability/RealProjectionSyntax.lean +136 -0
  49. lean/OAI/Computability/DegreeRigidity/Computability/RecoverySetup.lean +95 -0
  50. lean/OAI/Computability/DegreeRigidity/Computability/ScalarCoding.lean +94 -0
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPersistenceDegreeModel.lean ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Constructibility.PersistenceExtensionAbsoluteness
2
+ import OAI.Computability.DegreeRigidity.Representation.SourceTModelBridge
3
+
4
+ namespace OAI
5
+
6
+
7
+ namespace TuringRigidity.BoundedSetTheory
8
+ open TransitiveNameModel EncodedForcing PersistentRestrictions PersistentPresentation OracleJump
9
+ open ArithmeticTree ArithmeticPersistence
10
+ universe u
11
+
12
+ theorem sourceT_arithmetic_persistent_graph (M : ZFSet.{u}) (hM : Transitive M) (hT : SourceT M)
13
+ (S : ZFSet.{u}) (hSM : S ∈ M)
14
+ (hS : ∀ A : Oracle, realCode A ∈ S ↔ A ∈ modelReals M)
15
+ (hSd : ∀ x ∈ S, ∃ A : Oracle, realCode A = x)
16
+ (A R : Oracle) (hA : A ∈ modelReals M) (hR : R ∈ modelReals M)
17
+ (hp : ∀ H ∈ modelReals M, Base A R ∧ Matrix (parameters A R H) 0) :
18
+ ∃ I : CountableIdeal, ∃ hAI : Presented I A, ∃ ρ : I ≃o I,
19
+ (∀ v, R v = true ↔ Graph ρ hAI v) ∧ Persistent I ρ ∧
20
+ presentationGraph S A R ∈ M ∧
21
+ (LevySigma.persistent 0 1 2 3 4).Realize M
22
+ (modelDegreeEnv S (presentationSet S A) (presentationGraph S A R)) := by
23
+ obtain ⟨I,hAI,hz,ρ,hgraph,hpers⟩ := (sourceT_persistence_presentation M hM hT A R hA hR).mp hp
24
+ have hc : ∀ n, realCode (columns A n) ∈ S :=
25
+ fun n => (hS _).mpr (sourceT_real_column M hM hT hA n)
26
+ have hbridge := sourceT_arbitrary_persistent_graph M hM hT S hSM hS hSd hAI hA ρ hpers hz
27
+ (presentationGraph S A R) (fun _ h => (ZFSet.mem_sep.mp h).1)
28
+ (presentationGraph_actual S hAI hc ρ hgraph)
29
+ exact ⟨I,hAI,ρ,hgraph,hpers,hbridge⟩
30
+
31
+ theorem sourceT_presentation_transfer (M N : ZFSet.{u})
32
+ (hM : Transitive M) (hN : Transitive N) (hTM : SourceT M) (hTN : SourceT N)
33
+ (A R : Oracle) (hAM : A ∈ modelReals M) (hRM : R ∈ modelReals M)
34
+ (hAN : A ∈ modelReals N) (hRN : R ∈ modelReals N)
35
+ (hp : ∀ H ∈ modelReals M, Base A R ∧ Matrix (parameters A R H) 0) :
36
+ ∃ S ∈ N, degreeUniverse S ∈ N ∧ degreeOrder S ∈ N ∧
37
+ presentationGraph S A R ∈ N ∧
38
+ (LevySigma.persistent 0 1 2 3 4).Realize N
39
+ (modelDegreeEnv S (presentationSet S A) (presentationGraph S A R)) := by
40
+ have hpN := (persistence_between_models M N hM hN hTM hTN A R hAM hRM hAN hRN).mp hp
41
+ obtain ⟨S,hSN,hS,hSd⟩ := internal_real_power N hN hTN
42
+ have hd : ∀ x ∈ S, ∃ B : Oracle, realCode B = x := by
43
+ intro x hx; obtain ⟨B,_,hB⟩ := hSd x hx; exact ⟨B,hB⟩
44
+ obtain ⟨_,_,_,_,_,hgraph,hpers⟩ := sourceT_arithmetic_persistent_graph N hN hTN S hSN hS hd A R hAN hRN hpN
45
+ exact ⟨S,hSN,internal_degreeUniverse N hN hTN S hSN hd,
46
+ internal_degreeOrder N hN hTN S hSN hd,hgraph,hpers⟩
47
+
48
+ theorem generic_extension_persistent_degree_model (M : ZFSet.{u}) (hM : Transitive M) (hT : SourceT M)
49
+ {c o : ZFSet.{u}} [Preorder (Conditions c)] [Top (Conditions c)] (hc : c ∈ M) (hoM : o ∈ M)
50
+ (ho : ∀ r s : Conditions c, ZFSet.pair (label c r) (label c s) ∈ o ↔ r ≤ s)
51
+ (G : CountableForcing.GenericFilter (Conditions c)) (hG : AtomicForcing.GroundGeneric M G)
52
+ (htop : ⊤ ∈ G.carrier) (A R : Oracle) (hA : A ∈ modelReals M) (hR : R ∈ modelReals M)
53
+ (hp : ∀ H ∈ modelReals M, Base A R ∧ Matrix (parameters A R H) 0) :
54
+ let E := genericExtensionSet M c G.carrier
55
+ ∃ S ∈ E, degreeUniverse S ∈ E ∧ degreeOrder S ∈ E ∧
56
+ presentationGraph S A R ∈ E ∧
57
+ (LevySigma.persistent 0 1 2 3 4).Realize E
58
+ (modelDegreeEnv S (presentationSet S A) (presentationGraph S A R)) := by
59
+ have hi := ground_inclusion_set M c hM hT.pairing hT.union hT.powerSet
60
+ hT.separation.finitePrefix.bounded hT.replacement.finitePrefix hT.infinity hc G.carrier htop
61
+ have hAE : A ∈ modelReals (genericExtensionSet M c G.carrier) := by
62
+ change realCode A ∈ genericExtensionSet M c G.carrier
63
+ exact hi hA
64
+ have hRE : R ∈ modelReals (genericExtensionSet M c G.carrier) := by
65
+ change realCode R ∈ genericExtensionSet M c G.carrier
66
+ exact hi hR
67
+ exact sourceT_presentation_transfer M _ hM (genericExtensionSet_transitive M c hM G.carrier)
68
+ hT (extension_sourceT M hM hT hc hoM ho G hG htop) A R hA hR hAE hRE hp
69
+
70
+ end TuringRigidity.BoundedSetTheory
71
+
72
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPrefixFamilies.lean ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticGenericTruth
2
+
3
+ namespace OAI
4
+
5
+
6
+ namespace TuringRigidity.ArithmeticPrefixFamilies
7
+ open UniformArithmetic ArithmeticPrefixForcing ShuffleRequirements FiniteShuffle
8
+
9
+ theorem prefix_comp {Q : PrefixPredicate} (hQ : ArithmeticPrefix Q)
10
+ {f : ℕ → ℕ} (hf : Primrec f) : ArithmeticPrefix (fun O v => Q O (f v)) :=
11
+ (hQ.comp _ (Primrec₂.natPair.comp (hf.comp left_primrec) right_primrec)).congr
12
+ (fun _ _ => by simp only [left,right,Nat.unpair_pair])
13
+
14
+ theorem prefix_exists {Q : PrefixPredicate} (hQ : ArithmeticPrefix Q) :
15
+ ArithmeticPrefix (fun O v s => ∃ n, Q O (Nat.pair v n) s) :=
16
+ ((hQ.comp _ (Primrec₂.natPair.comp
17
+ (Primrec₂.natPair.comp (left_primrec.comp left_primrec) right_primrec)
18
+ (right_primrec.comp left_primrec))).ex).congr
19
+ (fun _ _ => by simp only [left,right,Nat.unpair_pair])
20
+
21
+ theorem dense_and {D E : List Bool → Prop} (hD : DenseOpen D) (hE : DenseOpen E) :
22
+ DenseOpen (fun s => D s ∧ E s) := by
23
+ constructor
24
+ · intro s
25
+ obtain ⟨t,hst,ht⟩ := hD.1 s
26
+ obtain ⟨u,htu,hu⟩ := hE.1 t
27
+ exact ⟨u,hst.trans htu,hD.2 t u htu ht,hu⟩
28
+ · intro s t hst hs
29
+ exact ⟨hD.2 s t hst hs.1,hE.2 s t hst hs.2⟩
30
+
31
+ theorem dense_true : DenseOpen (fun _ : List Bool => True) :=
32
+ ⟨fun s => ⟨s,List.prefix_rfl,True.intro⟩,fun _ _ _ _ => True.intro⟩
33
+
34
+ theorem avoid_truth_of_decides (Q : List Bool → Prop) (hQ : Upward Q) (G : Oracle)
35
+ (hG : G ∈ OpenSet (Decides Q)) :
36
+ G ∈ OpenSet (Avoid Q) ↔ ¬ G ∈ OpenSet Q := by
37
+ constructor
38
+ · rintro ⟨s,hs,hGs⟩ ⟨t,ht,hGt⟩
39
+ obtain ⟨u,hsu,htu,_⟩ := realizes_common hGs hGt
40
+ exact hs u hsu (hQ t u htu ht)
41
+ · intro hn
42
+ obtain ⟨s,hs,hGs⟩ := hG
43
+ rcases hs with hs | hs
44
+ · exact False.elim (hn ⟨s,hs,hGs⟩)
45
+ · exact ⟨s,hs,hGs⟩
46
+
47
+ end TuringRigidity.ArithmeticPrefixFamilies
48
+
49
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPrefixForcing.lean ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticCommonRequirement
2
+ import OAI.Computability.DegreeRigidity.SetModels.ShuffleRequirements
3
+
4
+ namespace OAI
5
+
6
+
7
+ namespace TuringRigidity.ArithmeticPrefixForcing
8
+ open Encodable UniformArithmetic FiniteShuffle ShuffleRequirements
9
+ open EncodedForcing (word word_primrec)
10
+
11
+ abbrev PrefixPredicate := Oracles → ℕ → List Bool → Prop
12
+ abbrev ArithmeticPrefix (Q : PrefixPredicate) :=
13
+ Arith (fun O v => Q O (left v) (word (right v)))
14
+
15
+ def Upward (Q : List Bool → Prop) : Prop :=
16
+ ∀ s t, s <+: t → Q s → Q t
17
+
18
+ def Avoid (Q : List Bool → Prop) (s : List Bool) : Prop :=
19
+ ∀ t, s <+: t → ¬ Q t
20
+
21
+ def Decides (Q : List Bool → Prop) (s : List Bool) : Prop := Q s ∨ Avoid Q s
22
+
23
+ def Generic (O : Oracles) (G : Oracle) : Prop :=
24
+ ∀ D : Oracles → List Bool → Prop,
25
+ Arith (fun O n => D O (word n)) → DenseOpen (D O) →
26
+ ∃ s, D O s ∧ Realizes s G
27
+
28
+ theorem avoids_upward (Q : List Bool → Prop) : Upward (Avoid Q) :=
29
+ fun _ _ h hs u hu => hs u (h.trans hu)
30
+
31
+ theorem decides_dense (Q : List Bool → Prop) (hQ : Upward Q) :
32
+ DenseOpen (Decides Q) := by
33
+ classical
34
+ constructor
35
+ · intro s
36
+ by_cases h : ∃ t, s <+: t ∧ Q t
37
+ · obtain ⟨t,ht,hq⟩ := h
38
+ exact ⟨t,ht,Or.inl hq⟩
39
+ · exact ⟨s,List.prefix_rfl,Or.inr (fun t ht hq => h ⟨t,ht,hq⟩)⟩
40
+ · intro s t h
41
+ exact Or.imp (hQ s t h) (avoids_upward Q s t h)
42
+
43
+ theorem avoids_arith {Q : PrefixPredicate} (hQ : ArithmeticPrefix Q) :
44
+ ArithmeticPrefix (fun O v => Avoid (Q O v)) := by
45
+ have hp := ArithmeticCommonRequirement.prefix_arith
46
+ (right_primrec.comp left_primrec) right_primrec
47
+ have h := hQ.comp _ (Primrec₂.natPair.comp (left_primrec.comp left_primrec) right_primrec)
48
+ apply (hp.imp h.neg).all.congr
49
+ intro O v
50
+ simp only [left,right,Nat.unpair_pair]
51
+ constructor
52
+ · intro h t ht
53
+ have hh := h (encode t)
54
+ simpa only [word,Encodable.encodek,Option.getD_some] using hh (by
55
+ simpa only [word,Encodable.encodek,Option.getD_some] using ht)
56
+ · intro h t ht
57
+ exact h (word t) ht
58
+
59
+ theorem decides_arith {Q : PrefixPredicate} (hQ : ArithmeticPrefix Q) :
60
+ ArithmeticPrefix (fun O v => Decides (Q O v)) := hQ.or (avoids_arith hQ)
61
+
62
+ theorem realizes_common {s t : List Bool} {G : Oracle}
63
+ (hs : Realizes s G) (ht : Realizes t G) :
64
+ ∃ u, s <+: u ∧ t <+: u ∧ Realizes u G := by
65
+ refine ⟨initial G (max s.length t.length), ?_, ?_,
66
+ (realizes_initial _ _ _).mpr (fun _ _ => rfl)⟩
67
+ · rw [←prefix_default s]
68
+ exact initial_prefix (by simp) hs
69
+ · rw [←prefix_default t]
70
+ exact initial_prefix (by simp) ht
71
+
72
+ theorem open_and (Q R : List Bool → Prop) (hQ : Upward Q) (hR : Upward R) (G : Oracle) :
73
+ G ∈ OpenSet (fun s => Q s ∧ R s) ↔ G ∈ OpenSet Q ∧ G ∈ OpenSet R := by
74
+ constructor
75
+ · rintro ⟨s,⟨hq,hr⟩,hs⟩
76
+ exact ⟨⟨s,hq,hs⟩,⟨s,hr,hs⟩⟩
77
+ · rintro ⟨⟨s,hq,hs⟩,⟨t,hr,ht⟩⟩
78
+ obtain ⟨u,hsu,htu,hu⟩ := realizes_common hs ht
79
+ exact ⟨u,⟨hQ s u hsu hq,hR t u htu hr⟩,hu⟩
80
+
81
+ theorem open_avoid {Q : PrefixPredicate} (hQ : ArithmeticPrefix Q)
82
+ (hup : ∀ O v, Upward (Q O v)) (O : Oracles) (v : ℕ) (G : Oracle)
83
+ (hG : Generic O G) :
84
+ G ∈ OpenSet (Avoid (Q O v)) ↔ ¬ G ∈ OpenSet (Q O v) := by
85
+ constructor
86
+ · rintro ⟨s,hs,hGs⟩ ⟨t,ht,hGt⟩
87
+ obtain ⟨u,hsu,htu,_⟩ := realizes_common hGs hGt
88
+ exact hs u hsu (hup O v t u htu ht)
89
+ · intro hn
90
+ have hd : Arith (fun O n => Decides (Q O v) (word n)) :=
91
+ ((decides_arith hQ).comp _ (Primrec₂.natPair.comp (Primrec.const v) Primrec.id)).congr
92
+ (fun _ _ => by simp only [left,right,Nat.unpair_pair,id_eq])
93
+ obtain ⟨s,hs,hGs⟩ := hG (fun O s => Decides (Q O v) s) hd (decides_dense _ (hup O v))
94
+ rcases hs with hs | hs
95
+ · exact False.elim (hn ⟨s,hs,hGs⟩)
96
+ · exact ⟨s,hs,hGs⟩
97
+
98
+ end TuringRigidity.ArithmeticPrefixForcing
99
+
100
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPresentation.lean ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.SetModels.EnumerationTransport
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.ArithmeticPresentation
6
+ open OracleJump ArithmeticHierarchy EncodedForcing BoundedDecoding IdealInterpretation
7
+ open EnumerationDecoding EnumerationConstruction EnumerationTransport GlobalLocality
8
+ noncomputable section
9
+
10
+ theorem reduces_iterate (H : Oracle) (n : ℕ) : Reduces H (iterate H n) := by
11
+ induction n with
12
+ | zero => exact reduces_refl H
13
+ | succ n ih => exact reduces_trans ih (reduces_jump _)
14
+
15
+ def Graph (π : Degree ≃o Degree) (H : Oracle) (v : ℕ) : Prop :=
16
+ π (degree (columns H (Nat.unpair v).1)) = degree (columns H (Nat.unpair v).2)
17
+
18
+ theorem graph_arithmetic (π : Degree ≃o Degree) (H : Oracle)
19
+ (hz : Reduces (jump FixedArithmetic.zero) H)
20
+ (hpre : π.symm (degree (jump FixedArithmetic.zero)) ≤ degree H) :
21
+ Sigma (iterate H 6) 5 (Graph π H) ∧ RecursivePred (iterate H 11) (Graph π H) := by
22
+ obtain ⟨c,hout,hS,hP⟩ := enumeration_exists H hz
23
+ let d := mapEnumeration π c
24
+ obtain ⟨hdS,hdP⟩ := mapEnumeration_below π c (degree (jump H)) hS hP
25
+ have hb : π (degree (jump H)) ≤ degree (iterate H 6) := by
26
+ have hh := source_3_3_1 π (degree (jump H)) (hpre.trans (reduces_jump H))
27
+ rw [degreeIterate_degree] at hh
28
+ exact hh
29
+ have hg := graph_sigma (reduces_iterate H 6) d (hdS.mono hb) (hdP.mono hb)
30
+ have h : Sigma (iterate H 6) 5 (Graph π H) := hg.congr (fun v => by
31
+ simp only [d,mapEnumeration,hout,Graph])
32
+ have hr := form_recursive h
33
+ exact ⟨h,hr⟩
34
+
35
+ theorem source_3_3_5 (π : Degree ≃o Degree) (I : DegreeIdeal) (H : Oracle)
36
+ (hpres : ∀ x, x ∈ I.carrier ↔ ∃ k, degree (columns H k) = x)
37
+ (hz : degree (jump FixedArithmetic.zero) ∈ I.carrier)
38
+ (hinv : ∀ x, π x ∈ I.carrier ↔ x ∈ I.carrier) :
39
+ Sigma (iterate H 6) 5 (Graph π H) ∧ RecursivePred (iterate H 11) (Graph π H) := by
40
+ have hbound (x : Degree) (hx : x ∈ I.carrier) : x ≤ degree H := by
41
+ obtain ⟨k,rfl⟩ := (hpres x).mp hx
42
+ exact CodingExtraction.column_projection_reduces H k
43
+ have hp : π.symm (degree (jump FixedArithmetic.zero)) ∈ I.carrier :=
44
+ (hinv _).mp (by simpa only [π.apply_symm_apply] using hz)
45
+ exact graph_arithmetic π H (hbound _ hz) (hbound _ hp)
46
+
47
+ end
48
+ end TuringRigidity.ArithmeticPresentation
49
+
50
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPresentationProperty.lean ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticPersistence
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.ArithmeticPersistence
6
+ open EncodedForcing OracleJump UniformArithmetic PersistentRestrictions
7
+ open PersistentPresentation NumericalAutomorphism
8
+ noncomputable section
9
+
10
+ def IdealCode (A : Oracle) : Prop :=
11
+ (∀ n e, IndexPresentation.Dom (columns A n) e →
12
+ ∃ m, IndexPresentation.value (columns A n) e = degree (columns A m)) ∧
13
+ ∀ n m, ∃ k, degree (columns A n) ⊔ degree (columns A m) = degree (columns A k)
14
+
15
+ def idealOfCode (A : Oracle) (h : IdealCode A) : CountableIdeal where
16
+ carrier := Set.range (fun n => degree (columns A n))
17
+ nonempty := ⟨degree (columns A 0),0,rfl⟩
18
+ countable := Set.countable_range _
19
+ lower := by
20
+ intro a b hab hb
21
+ obtain ⟨n,rfl⟩ := hb
22
+ obtain ⟨e,he,hv⟩ := IndexPresentation.value_surjective (columns A n) a hab
23
+ obtain ⟨m,hm⟩ := h.1 n e he
24
+ exact ⟨m,hm.symm.trans hv⟩
25
+ join_mem := by
26
+ intro a b ha hb
27
+ obtain ⟨n,rfl⟩ := ha
28
+ obtain ⟨m,rfl⟩ := hb
29
+ obtain ⟨k,hk⟩ := h.2 n m
30
+ exact ⟨k,hk.symm⟩
31
+
32
+ theorem ideal_code {I : CountableIdeal} {A : Oracle} (hA : Presented I A) : IdealCode A := by
33
+ constructor
34
+ · intro n e _
35
+ obtain ⟨m,hm⟩ := (hA _).mp
36
+ (I.lower (IndexPresentation.value_below (columns A n) e) (entry hA n).property)
37
+ exact ⟨m,hm.symm⟩
38
+ · intro n m
39
+ obtain ⟨k,hk⟩ := (hA _).mp (I.join_mem (entry hA n).property (entry hA m).property)
40
+ exact ⟨k,hk.symm⟩
41
+
42
+ def Base (A R : Oracle) : Prop :=
43
+ IdealCode A ∧ (∃ n, degree (jump FixedArithmetic.zero) = degree (columns A n)) ∧
44
+ Action A (fun v => R v = true)
45
+
46
+ def Property (A R : Oracle) : Prop :=
47
+ ∃ I : CountableIdeal, ∃ hA : Presented I A,
48
+ degree (jump FixedArithmetic.zero) ∈ I.carrier ∧
49
+ ∃ ρ : I ≃o I, (∀ v, R v = true ↔ Graph ρ hA v) ∧ Persistent I ρ
50
+
51
+ theorem property_iff (A R : Oracle) : Property A R ↔ Base A R ∧ Criterion A R := by
52
+ constructor
53
+ · rintro ⟨I,hA,hz,ρ,hR,hp⟩
54
+ have ha : Action A (fun v => R v = true) :=
55
+ (PersistenceCriterion.action_congr hR).mpr (action_of_automorphism hA ρ)
56
+ obtain ⟨n,hn⟩ := (hA _).mp hz
57
+ exact ⟨⟨ideal_code hA,⟨n,hn.symm⟩,ha⟩,(persistent_iff hA ρ hz hR).mp hp⟩
58
+ · rintro ⟨⟨hi,⟨n,hn⟩,ha⟩,hc⟩
59
+ let I := idealOfCode A hi
60
+ have hA : Presented I A := fun _ => Iff.rfl
61
+ have hz : degree (jump FixedArithmetic.zero) ∈ I.carrier := (hA _).mpr ⟨n,hn.symm⟩
62
+ obtain ⟨ρ,hR⟩ := reconstruct hA ha
63
+ exact ⟨I,hA,hz,ρ,hR,(persistent_iff hA ρ hz hR).mpr hc⟩
64
+
65
+ theorem base_arith : Arith (fun O (_ : ℕ) => Base (O 0) (O 1)) := by
66
+ have hA := parameter_arith 0
67
+ have hR := parameter_arith 1
68
+ have hz : ArithmeticOracle (fun _ _ => FixedArithmetic.zero) := by
69
+ exact (equal (Primrec.const 0) (Primrec.const 1)).congr
70
+ (fun _ _ => by simp [FixedArithmetic.zero])
71
+ have hz' := (degree_equal_arith (jump_arith hz) (column_arith hA UniformArithmetic.right_primrec)).ex
72
+ have hi := (lower_arith hA).and (join_closed_arith hA)
73
+ exact (hi.and (hz'.and (action_arith hA hR))).congr
74
+ (fun _ _ => by simp only [Base,IdealCode,UniformArithmetic.right,Nat.unpair_pair])
75
+
76
+ def parameters (A R H : Oracle) : Oracles
77
+ | 0 => A
78
+ | 1 => R
79
+ | _ => H
80
+
81
+ def PiOneOne (P : Oracle → Oracle → Prop) : Prop :=
82
+ ∃ Q : Predicate, Arith Q ∧ ∀ A R, P A R ↔ ∀ H : Oracle, Q (parameters A R H) 0
83
+
84
+ theorem source_4_2_1 : PiOneOne Property := by
85
+ refine ⟨fun O v => Base (O 0) (O 1) ∧ Matrix O v,
86
+ base_arith.and matrix_arith,fun A R => ?_⟩
87
+ rw [property_iff]
88
+ change Base A R ∧ Criterion A R ↔ ∀ H, Base A R ∧
89
+ (NumericalIdeal.JumpCode H → NumericalIdeal.Includes A H →
90
+ ∃ e, NumericalAutomorphism.Action H (fun v => tableOracle (iterate H 11) e v = true) ∧
91
+ NumericalExtension.Compatible A H (fun v => R v = true)
92
+ (fun v => tableOracle (iterate H 11) e v = true))
93
+ exact ⟨fun h H => ⟨h.1,h.2 H⟩,fun h => ⟨(h FixedArithmetic.zero).1,fun H => (h H).2⟩⟩
94
+
95
+ end
96
+ end TuringRigidity.ArithmeticPersistence
97
+
98
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticPrincipalIntersection.lean ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticRelations
2
+ import OAI.Computability.DegreeRigidity.Representation.GenericIdentity
3
+
4
+ namespace OAI
5
+
6
+
7
+ namespace TuringRigidity.ArithmeticPrincipalIntersection
8
+ open Encodable UniformArithmetic TableIndices IndexMatrix
9
+
10
+ theorem principal_iff_tables (U L R : Oracle) :
11
+ GenericIdentity.PrincipalIntersection U L R ↔
12
+ Reduces U L ∧ Reduces U R ∧ ∀ e : ℕ, IndexPresentation.Dom L e →
13
+ Reduces (tableOracle L e) R → Reduces (tableOracle L e) U := by
14
+ constructor
15
+ · intro h
16
+ have hU := (h (degree U)).mp le_rfl
17
+ refine ⟨hU.1,hU.2,fun e he hR => ?_⟩
18
+ exact (h (degree (tableOracle L e))).mpr
19
+ ⟨represents_reduces ((valid_tableOracle L e).mp he),hR⟩
20
+ · rintro ⟨hL,hR,h⟩ b
21
+ obtain ⟨A,rfl⟩ := degree_surjective b
22
+ constructor
23
+ · intro hA
24
+ exact ⟨reduces_trans hA hL,reduces_trans hA hR⟩
25
+ · rintro ⟨haL,haR⟩
26
+ change Reduces A R at haR
27
+ change Reduces A U
28
+ obtain ⟨d,hd⟩ := (reduces_iff_represents A L).mp haL
29
+ have he : Represents L (machine (encode d)) A := by simpa using hd
30
+ have hvalid : IndexPresentation.Dom L (encode d) :=
31
+ (valid_iff_represents L _).mpr ⟨A,he⟩
32
+ have ht := tableOracle_eq he
33
+ have hh := h (encode d) hvalid (by simpa only [ht] using haR)
34
+ simpa only [ht] using hh
35
+
36
+ theorem principal_arith {U L R : OracleFamily}
37
+ (hU : ArithmeticOracle U) (hL : ArithmeticOracle L) (hR : ArithmeticOracle R) :
38
+ Arith (fun O v => GenericIdentity.PrincipalIntersection (U O v) (L O v) (R O v)) := by
39
+ have hleft := reduces_arith hU hL
40
+ have hright := reduces_arith hU hR
41
+ have hd := valid_arith (hL.comp left_primrec) right_primrec
42
+ have hout := tableOracle_arith (hL.comp left_primrec) right_primrec
43
+ have hr := reduces_arith hout (hR.comp left_primrec)
44
+ have hu := reduces_arith hout (hU.comp left_primrec)
45
+ apply (hleft.and (hright.and (hd.imp (hr.imp hu)).all)).congr
46
+ intro O v
47
+ simp only [left,right,Nat.unpair_pair]
48
+ exact (principal_iff_tables (U O v) (L O v) (R O v)).symm
49
+
50
+ end TuringRigidity.ArithmeticPrincipalIntersection
51
+
52
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticProgramGraph.lean ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Effective.UniformPartialGraph
2
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticRelations
3
+ import OAI.Computability.DegreeRigidity.Representation.GenericTotality
4
+
5
+ namespace OAI
6
+
7
+
8
+ namespace TuringRigidity.ArithmeticProgramGraph
9
+ open Encodable UniformArithmetic IndexMatrix GenericIdentity
10
+
11
+ theorem eval_arith (p : OracleCode) {B : OracleFamily} (hB : ArithmeticOracle B)
12
+ {c n a : ℕ → ℕ} (hc : Primrec c) (hn : Primrec n) (ha : Primrec a) :
13
+ Arith (fun O v => a v ∈ OracleCode.eval (oracleFunction (B O (c v))) p (n v)) := by
14
+ obtain ⟨d, hd⟩ := UniformPartialGraph.eval_iff_table p
15
+ have h := (run_arith hB (hc.comp left_primrec) (Primrec.const (encode d))
16
+ (hn.comp left_primrec) right_primrec (ha.comp left_primrec)).ex
17
+ exact h.congr (fun O v => by
18
+ simpa only [left, right, Nat.unpair_pair, machine_encode, Option.mem_def] using
19
+ (hd (B O (c v)) (n v) (a v)).symm)
20
+
21
+ theorem output_arith (p : OracleCode) {B : OracleFamily} (hB : ArithmeticOracle B) :
22
+ ArithmeticOracle (fun O v => programOutput p (B O v)) :=
23
+ (eval_arith p hB left_primrec right_primrec (Primrec.const 1)).congr
24
+ (fun _ _ => by simp [programOutput])
25
+
26
+ theorem value_arith (p : OracleCode) {P A : OracleFamily}
27
+ (hP : ArithmeticOracle P) (hA : ArithmeticOracle A) :
28
+ ArithmeticOracle (fun O v => value p (P O v) (A O v)) :=
29
+ output_arith p (join_arith hA hP)
30
+
31
+ theorem total_arith (p : OracleCode) {P A : OracleFamily}
32
+ (hP : ArithmeticOracle P) (hA : ArithmeticOracle A) :
33
+ Arith (fun O v => Total p (P O v) (A O v)) := by
34
+ have hB := join_arith hA hP
35
+ have h0 := eval_arith p hB left_primrec right_primrec (Primrec.const 0)
36
+ have h1 := eval_arith p hB left_primrec right_primrec (Primrec.const 1)
37
+ exact (h0.or h1).all.congr (fun O v => by
38
+ simpa only [left, right, Nat.unpair_pair, BinaryHalts] using
39
+ (total_iff_binaryHalts p (P O v) (A O v)).symm)
40
+
41
+ end TuringRigidity.ArithmeticProgramGraph
42
+
43
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticRelations.lean ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticOracles
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.UniformArithmetic
6
+ open Encodable CommonIdeal IndexMatrix TableIndices OracleJump
7
+ noncomputable section
8
+
9
+ theorem represents_arith {A B : OracleFamily} (hA : ArithmeticOracle A)
10
+ (hB : ArithmeticOracle B) {e : ℕ → ℕ} (he : Primrec e) :
11
+ Arith (fun O v => Represents (B O v) (machine (e v)) (A O v)) := by
12
+ let c := left_primrec.comp (left_primrec.comp left_primrec)
13
+ let n := right_primrec.comp (left_primrec.comp left_primrec)
14
+ let z := right_primrec.comp left_primrec
15
+ have hr := run_arith hB c (he.comp c) n z right_primrec
16
+ have hb := bit_equal hA c n right_primrec
17
+ have h := ((hr.imp hb).all.all.all).and ((hr.and hb).ex.ex.all)
18
+ apply h.congr
19
+ intro O v
20
+ simp only [left,right,Nat.unpair_pair]
21
+ constructor
22
+ · rintro ⟨hs,ht⟩
23
+ exact ⟨fun n z a ha => hs n z a (Option.mem_def.mp ha),
24
+ fun n => by obtain ⟨z,a,ha,_⟩ := ht n; exact ⟨z,a,Option.mem_def.mpr ha⟩⟩
25
+ · rintro ⟨hs,ht⟩
26
+ exact ⟨fun n z a ha => hs n z a (Option.mem_def.mpr ha),
27
+ fun n => by obtain ⟨z,a,ha⟩ := ht n; exact ⟨z,a,Option.mem_def.mp ha,hs n z a ha⟩⟩
28
+
29
+ theorem valid_tableOracle (B : Oracle) (e : ℕ) :
30
+ Valid B (machine e) ↔ Represents B (machine e) (tableOracle B e) := by
31
+ constructor
32
+ · intro hv
33
+ obtain ⟨A,hA⟩ := (valid_iff_represents B (machine e)).mp hv
34
+ rw [tableOracle_eq hA]
35
+ exact hA
36
+ · intro h
37
+ exact (valid_iff_represents B (machine e)).mpr ⟨_,h⟩
38
+
39
+ theorem valid_arith {B : OracleFamily} (hB : ArithmeticOracle B)
40
+ {e : ℕ → ℕ} (he : Primrec e) :
41
+ Arith (fun O v => IndexPresentation.Dom (B O v) (e v)) :=
42
+ (represents_arith (tableOracle_arith hB he) hB he).congr
43
+ (fun O v => (valid_tableOracle (B O v) (e v)).symm)
44
+
45
+ theorem reduces_arith {A B : OracleFamily} (hA : ArithmeticOracle A)
46
+ (hB : ArithmeticOracle B) : Arith (fun O v => Reduces (A O v) (B O v)) := by
47
+ have h := (represents_arith (hA.comp left_primrec) (hB.comp left_primrec) right_primrec).ex
48
+ apply h.congr
49
+ intro O v
50
+ simp only [left,right,Nat.unpair_pair]
51
+ rw [reduces_iff_represents]
52
+ constructor
53
+ · rintro ⟨e,he⟩
54
+ exact ⟨machine e,he⟩
55
+ · rintro ⟨e,he⟩
56
+ exact ⟨encode e,by simpa using he⟩
57
+
58
+ theorem degree_equal_arith {A B : OracleFamily} (hA : ArithmeticOracle A)
59
+ (hB : ArithmeticOracle B) : Arith (fun O v => degree (A O v) = degree (B O v)) :=
60
+ ((reduces_arith hA hB).and (reduces_arith hB hA)).congr
61
+ (fun O v => (degree_eq_iff (A O v) (B O v)).symm)
62
+
63
+ theorem join_arith {A B : OracleFamily} (hA : ArithmeticOracle A)
64
+ (hB : ArithmeticOracle B) : ArithmeticOracle (fun O v => join (A O v) (B O v)) := by
65
+ have ht : Arith (fun (_ : Oracles) v => (right v).bodd = true) :=
66
+ .pure _ (Primrec.eq.comp (Primrec.nat_bodd.comp right_primrec) (Primrec.const true))
67
+ have hd : Primrec (fun v => right v / 2) := Primrec.nat_div.comp right_primrec (Primrec.const 2)
68
+ exact ((ht.and (query_at hB left_primrec hd)).or
69
+ (ht.neg.and (query_at hA left_primrec hd))).congr (fun O v => by
70
+ cases h : (right v).bodd <;> simp [join,h])
71
+
72
+ end
73
+ end TuringRigidity.UniformArithmetic
74
+
75
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticSetSyntax.lean ADDED
@@ -0,0 +1,103 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Syntax.PrimitivePredicateFormula
2
+ import OAI.Computability.DegreeRigidity.SetModels.ModelReals
3
+ import OAI.Computability.DegreeRigidity.Computability.UniformArithmetic
4
+
5
+ namespace OAI
6
+
7
+
8
+ namespace TuringRigidity.BoundedSetTheory
9
+ open UniformArithmetic
10
+ universe u
11
+
12
+ noncomputable def arithmeticEnv (Q : ZFSet.{u}) (O : Oracles) (n : ℕ) : ℕ → ZFSet.{u} :=
13
+ cons (natSet n) (cons ZFSet.omega (cons Q (fun i => realCode (O i))))
14
+
15
+ def DefinesArithmetic (φ : Formula) (P : Predicate) : Prop :=
16
+ ∀ Q : ZFSet.{u}, (∀ f : ℕ → ℕ, ∀ k, finiteNaturalGraph f k ∈ Q) → ∀ O n,
17
+ (φ.Eval (arithmeticEnv Q O n) ↔ P O n)
18
+
19
+ namespace Formula
20
+ def arithmeticVars (k : ℕ) : ℕ → ℕ
21
+ | 0 => 0
22
+ | i+1 => i+k+1
23
+
24
+ theorem eval_arithmetic_shift_one (φ : Formula) (Q : ZFSet.{u}) (O : Oracles) (n m : ℕ) :
25
+ (φ.rename (arithmeticVars 1)).Eval (cons (natSet m) (arithmeticEnv Q O n)) ↔
26
+ φ.Eval (arithmeticEnv Q O m) := by
27
+ rw [eval_rename]
28
+ have he : (fun i => cons (natSet m) (arithmeticEnv Q O n) (arithmeticVars 1 i)) = arithmeticEnv Q O m := by
29
+ funext i; cases i <;> rfl
30
+ rw [he]
31
+
32
+ theorem eval_arithmetic_shift_two (φ : Formula) (Q : ZFSet.{u}) (O : Oracles) (n k m : ℕ) :
33
+ (φ.rename (arithmeticVars 2)).Eval (cons (natSet m) (cons (natSet k) (arithmeticEnv Q O n))) ↔
34
+ φ.Eval (arithmeticEnv Q O m) := by
35
+ rw [eval_rename]
36
+ have he : (fun i => cons (natSet m) (cons (natSet k) (arithmeticEnv Q O n)) (arithmeticVars 2 i)) =
37
+ arithmeticEnv Q O m := by
38
+ funext i; cases i <;> rfl
39
+ rw [he]
40
+
41
+ def arithmeticExists (φ : Formula) : Formula := .existsMem 1 (.existsMem 2
42
+ (.conj (naturalPair 3 4 2 1 0) (φ.rename (arithmeticVars 2))))
43
+
44
+ def arithmeticComp (φ ψ : Formula) : Formula := .existsMem 1
45
+ (.conj (unary ψ 2 3 1 0) (φ.rename (arithmeticVars 1)))
46
+ end Formula
47
+
48
+ theorem DefinesArithmetic.existsNat {φ : Formula} {P : Predicate} (hφ : DefinesArithmetic.{u} φ P) :
49
+ DefinesArithmetic.{u} φ.arithmeticExists (fun O n => ∃ k, P O (Nat.pair n k)) := by
50
+ intro Q hQ O n
51
+ have hp (k : ℕ) (w : ZFSet.{u}) := Formula.naturalPair_spec 3 4 2 1 0
52
+ (cons w (cons (natSet k) (arithmeticEnv Q O n))) rfl hQ n k rfl rfl
53
+ simp only [Formula.arithmeticExists,Formula.Eval,arithmeticEnv,cons_zero,cons_succ]
54
+ constructor
55
+ · rintro ⟨x,hx,w,_,hpair,h⟩
56
+ obtain ⟨k,rfl⟩ := (mem_omega x).mp hx
57
+ obtain rfl := (hp k w).mp hpair
58
+ exact ⟨k,(hφ Q hQ O _).mp ((Formula.eval_arithmetic_shift_two φ Q O n k _).mp h)⟩
59
+ · rintro ⟨k,h⟩
60
+ exact ⟨natSet k,(mem_omega _).mpr ⟨k,rfl⟩,natSet (Nat.pair n k),
61
+ (mem_omega _).mpr ⟨Nat.pair n k,rfl⟩,(hp k _).mpr rfl,
62
+ (Formula.eval_arithmetic_shift_two φ Q O n k _).mpr ((hφ Q hQ O _).mpr h)⟩
63
+
64
+ theorem DefinesArithmetic.comp {φ ψ : Formula} {P : Predicate} {f : ℕ → ℕ}
65
+ (hφ : DefinesArithmetic.{u} φ P) (hψ : DefinesNatural.{u} ψ f) :
66
+ DefinesArithmetic.{u} (φ.arithmeticComp ψ) (fun O n => P O (f n)) := by
67
+ intro Q hQ O n
68
+ have hf (w : ZFSet.{u}) := Formula.unary_spec hψ 2 3 1 0
69
+ (cons w (arithmeticEnv Q O n)) rfl hQ n rfl
70
+ simp only [Formula.arithmeticComp,Formula.Eval,arithmeticEnv,cons_zero,cons_succ]
71
+ constructor
72
+ · rintro ⟨w,_,hw,h⟩
73
+ obtain rfl := (hf w).mp hw
74
+ exact (hφ Q hQ O _).mp ((Formula.eval_arithmetic_shift_one φ Q O n _).mp h)
75
+ · intro h
76
+ exact ⟨natSet (f n),(mem_omega _).mpr ⟨f n,rfl⟩,(hf _).mpr rfl,
77
+ (Formula.eval_arithmetic_shift_one φ Q O n _).mpr ((hφ Q hQ O _).mpr h)⟩
78
+
79
+ theorem arithmetic_bounded_definition {P : Predicate} (hP : Arith P) :
80
+ ∃ φ : Formula, DefinesArithmetic.{u} φ P := by
81
+ induction hP with
82
+ | pure P hP =>
83
+ obtain ⟨φ,hφ⟩ := primitive_predicate_bounded.{u} hP
84
+ exact ⟨φ,fun Q hQ O n => hφ (arithmeticEnv Q O n) rfl hQ n rfl⟩
85
+ | query i =>
86
+ exact ⟨.member 0 (i+3),fun Q _ O n => natSet_mem_realCode (O i) n⟩
87
+ | neg h ih =>
88
+ obtain ⟨φ,hφ⟩ := ih
89
+ exact ⟨.neg φ,fun Q hQ O n => not_congr (hφ Q hQ O n)⟩
90
+ | and h k ih ik =>
91
+ obtain ⟨φ,hφ⟩ := ih; obtain ⟨ψ,hψ⟩ := ik
92
+ exact ⟨.conj φ ψ,fun Q hQ O n => and_congr (hφ Q hQ O n) (hψ Q hQ O n)⟩
93
+ | ex h ih =>
94
+ obtain ⟨φ,hφ⟩ := ih
95
+ exact ⟨φ.arithmeticExists,hφ.existsNat⟩
96
+ | comp f h hf ih =>
97
+ obtain ⟨φ,hφ⟩ := ih
98
+ obtain ⟨ψ,hψ⟩ := primitive_bounded_definition.{u} (Primrec.nat_iff.mp hf)
99
+ exact ⟨φ.arithmeticComp ψ,hφ.comp hψ⟩
100
+
101
+ end TuringRigidity.BoundedSetTheory
102
+
103
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticShuffleCertificate.lean ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Effective.FiniteShuffleComputation
2
+ import OAI.Computability.DegreeRigidity.Computability.UniformArithmetic
3
+
4
+ namespace OAI
5
+
6
+
7
+ namespace TuringRigidity.ArithmeticShuffleCertificate
8
+ open Encodable UniformArithmetic FiniteShuffleComputation FiniteShuffleCertificate
9
+ open EncodedForcing (word word_primrec)
10
+
11
+ theorem certificate_arith :
12
+ Arith (fun O n => Certificate (fun t => O 0 (encode t) = true) (word n)) := by
13
+ let L := left_primrec
14
+ let R := right_primrec
15
+
16
+ let hn := L.comp (L.comp L)
17
+ let hk := R.comp (L.comp L)
18
+ let hs := R.comp L
19
+ have hshuffle := finiteShuffleWord_primrec.comp
20
+ (Primrec₂.natPair.comp hs (Primrec₂.natPair.comp hn R))
21
+ have hquery := (Arith.query 0).comp _ hshuffle
22
+ have hbound := Arith.pure (fun v => right v ≤ right (left (left v)))
23
+ (Primrec.nat_le.comp R hk)
24
+ have hex := (hbound.and hquery).ex
25
+ have hlength := equal (Primrec.list_length.comp (word_primrec.comp R)) (R.comp L)
26
+ have hall := (hlength.imp hex).all
27
+ have hsize := Arith.pure (fun v => 2 * right v ≤ (word (left v)).length)
28
+ (Primrec.nat_le.comp (Primrec.nat_mul.comp (Primrec.const 2) R)
29
+ (Primrec.list_length.comp (word_primrec.comp L)))
30
+ apply (hsize.and hall).ex.congr
31
+ intro O n
32
+ simp only [left,right,Nat.unpair_pair,finiteShuffleWord]
33
+ constructor
34
+ · rintro ⟨k,hk,h⟩
35
+ refine ⟨k,hk,fun s hs => ?_⟩
36
+ have hlen : (word (encode s)).length = k := by simpa [word] using hs
37
+ simpa [word] using h (encode s) hlen
38
+ · rintro ⟨k,hk,h⟩
39
+ exact ⟨k,hk,fun s hs => h (word s) hs⟩
40
+
41
+ theorem open_arith : Arith (fun O n =>
42
+ ∃ r : List Bool, O 0 (encode r) = true ∧ r <+: word n) := by
43
+ have hp : Arith (fun (_ : Oracles) v => word (right v) <+: word (left v)) :=
44
+ (Arith.pure _ (Primrec.eq.comp (word_primrec.comp right_primrec)
45
+ (Primrec.list_take.comp (Primrec.list_length.comp (word_primrec.comp right_primrec))
46
+ (word_primrec.comp left_primrec)))).congr (fun _ _ => List.prefix_iff_eq_take.symm)
47
+ have hq := (Arith.query 0).comp _ (Primrec.encode.comp (word_primrec.comp right_primrec))
48
+ apply (hq.and hp).ex.congr
49
+ intro O n
50
+ simp only [left,right,Nat.unpair_pair]
51
+ constructor
52
+ · rintro ⟨r,hr,hp⟩
53
+ exact ⟨word r,hr,hp⟩
54
+ · rintro ⟨r,hr,hp⟩
55
+ exact ⟨encode r,by simpa [word] using hr,by simpa [word] using hp⟩
56
+
57
+ end TuringRigidity.ArithmeticShuffleCertificate
58
+
59
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticShuffleGraph.lean ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticOracles
2
+ import OAI.Computability.DegreeRigidity.Effective.FiniteShuffleComputation
3
+
4
+ namespace OAI
5
+
6
+
7
+ namespace TuringRigidity.ArithmeticShuffleGraph
8
+ open Encodable UniformArithmetic FiniteShuffle ShuffleRequirements GenericCoding
9
+ open EncodedForcing (word word_primrec)
10
+
11
+ theorem realizes_arith {B : OracleFamily} (hB : ArithmeticOracle B)
12
+ {c s : ℕ → ℕ} (hc : Primrec c) (hs : Primrec s) :
13
+ Arith (fun O v => Realizes (word (s v)) (B O (c v))) := by
14
+ have hb := Arith.pure (fun v => (word (s (left v))).getD (right v) false = true)
15
+ (Primrec.eq.comp ((Primrec.list_getD false).comp
16
+ (word_primrec.comp (hs.comp left_primrec)) right_primrec) (Primrec.const true))
17
+ have hq := query_at hB (hc.comp left_primrec) right_primrec
18
+ have hl := less right_primrec
19
+ (Primrec.list_length.comp (word_primrec.comp (hs.comp left_primrec)))
20
+ apply (hl.imp (hb.iff hq)).all.congr
21
+ intro O v
22
+ simp only [left, right, Nat.unpair_pair]
23
+ constructor
24
+ · intro h i hi
25
+ have hh := h i hi
26
+ cases hb : (word (s v)).getD i false <;> cases ho : B O (c v) i <;> simp_all
27
+ · intro h i hi
28
+ rw [show (word (s v)).getD i false = B O (c v) i from h i hi]
29
+
30
+ theorem code_bit_iff (Y L : Oracle) (n : ℕ) :
31
+ code Y L n = true ↔ ∃ s t : ℕ,
32
+ (word s).length = n + 1 ∧ (word t).length = 2 * (n + 1) ∧
33
+ Realizes (word s) Y ∧ Realizes (word t) L ∧
34
+ code (fun i => (word s).getD i false) (fun i => (word t).getD i false) n = true := by
35
+ constructor
36
+ · intro h
37
+ refine ⟨encode (initial Y (n + 1)), encode (initial L (2 * (n + 1))), ?_⟩
38
+ simp only [word, Encodable.encodek, Option.getD_some, prefix_length]
39
+ have hy : Realizes (initial Y (n + 1)) Y :=
40
+ (realizes_initial _ _ _).mpr (fun _ _ => rfl)
41
+ have hl : Realizes (initial L (2 * (n + 1))) L :=
42
+ (realizes_initial _ _ _).mpr (fun _ _ => rfl)
43
+ have he := code_agree (n := n + 1)
44
+ (show Agree (n + 1) (fun i => (initial Y (n+1)).getD i false) Y from
45
+ fun i hi => prefix_getD Y _ i hi)
46
+ (show Agree (2 * (n + 1)) (fun i => (initial L (2*(n+1))).getD i false) L from
47
+ fun i hi => prefix_getD L _ i hi)
48
+ exact ⟨True.intro, True.intro, hy, hl, (he n (by omega)).trans h⟩
49
+ · rintro ⟨s,t,hs,ht,hy,hl,h⟩
50
+ have hy' : Agree (n + 1) (fun i => (word s).getD i false) Y := by
51
+ simpa only [Realizes, hs] using hy
52
+ have hl' : Agree (2 * (n + 1)) (fun i => (word t).getD i false) L := by
53
+ simpa only [Realizes, ht] using hl
54
+ exact ((code_agree hy' hl') n (by omega)).symm.trans h
55
+
56
+ theorem code_arith {Y L : OracleFamily}
57
+ (hY : ArithmeticOracle Y) (hL : ArithmeticOracle L) :
58
+ ArithmeticOracle (fun O v => code (Y O v) (L O v)) := by
59
+ let base := left_primrec.comp (left_primrec.comp left_primrec)
60
+ let n := right_primrec.comp (left_primrec.comp left_primrec)
61
+ let s := right_primrec.comp left_primrec
62
+ let t := right_primrec
63
+ have hs := equal (Primrec.list_length.comp (word_primrec.comp s)) (Primrec.succ.comp n)
64
+ have ht := equal (Primrec.list_length.comp (word_primrec.comp t))
65
+ (Primrec.nat_mul.comp (Primrec.const 2) (Primrec.succ.comp n))
66
+ have hy := realizes_arith hY base s
67
+ have hl := realizes_arith hL base t
68
+ have hb := Arith.pure _ (Primrec.eq.comp
69
+ (FiniteShuffleComputation.wordShuffleBit_primrec.comp
70
+ ((word_primrec.comp s).pair ((word_primrec.comp t).pair n))) (Primrec.const true))
71
+ exact (hs.and (ht.and (hy.and (hl.and hb)))).ex.ex.congr (fun O v => by
72
+ simpa only [base,n,s,t,left,right,Nat.unpair_pair] using
73
+ (code_bit_iff (Y O (left v)) (L O (left v)) (right v)).symm)
74
+
75
+ end TuringRigidity.ArithmeticShuffleGraph
76
+
77
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticSkolem.lean ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticFiniteTest
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.ArithmeticTree
6
+ open UniformArithmetic
7
+ noncomputable section
8
+
9
+ def HasTest (P : Predicate) : Prop := ∃ t : Test, t.Presents P
10
+
11
+ namespace HasTest
12
+
13
+ private def col (k : ℕ) (t : Test) : Test :=
14
+ t.subst .input (fun s => .witness (.pair (.const k) s))
15
+
16
+ private theorem col_eval (k : ℕ) (t : Test) (O : Oracles) (f : ℕ → ℕ) (v : ℕ) :
17
+ (col k t).eval O f v ↔ t.eval O (fun n => f (Nat.pair k n)) v :=
18
+ t.eval_subst _ _ O f _ v (fun _ => rfl)
19
+
20
+ theorem pure (P : ℕ → Prop) (hP : PrimrecPred P) : HasTest (fun _ v => P v) := by
21
+ refine ⟨.pure P hP (.left .input),fun O v => ?_⟩
22
+ simp only [Test.eval,Term.eval,Term.left,UniformArithmetic.left,Nat.unpair_pair]
23
+ exact ⟨fun h => ⟨fun _ => 0,fun _ => h⟩,fun ⟨_,h⟩ => h 0⟩
24
+
25
+ theorem query (i : ℕ) : HasTest (fun O v => O i v = true) := by
26
+ refine ⟨.query i (.left .input),fun O v => ?_⟩
27
+ simp only [Test.eval,Term.eval,Term.left,UniformArithmetic.left,Nat.unpair_pair]
28
+ exact ⟨fun h => ⟨fun _ => 0,fun _ => h⟩,fun ⟨_,h⟩ => h 0⟩
29
+
30
+ theorem not_pure (P : ℕ → Prop) (hP : PrimrecPred P) : HasTest (fun _ v => ¬ P v) := by
31
+ refine ⟨.neg (.pure P hP (.left .input)),fun O v => ?_⟩
32
+ simp only [Test.eval,Term.eval,Term.left,UniformArithmetic.left,Nat.unpair_pair]
33
+ exact ⟨fun h => ⟨fun _ => 0,fun _ => h⟩,fun ⟨_,h⟩ => h 0⟩
34
+
35
+ theorem not_query (i : ℕ) : HasTest (fun O v => ¬ O i v = true) := by
36
+ refine ⟨.neg (.query i (.left .input)),fun O v => ?_⟩
37
+ simp only [Test.eval,Term.eval,Term.left,UniformArithmetic.left,Nat.unpair_pair]
38
+ exact ⟨fun h => ⟨fun _ => 0,fun _ => h⟩,fun ⟨_,h⟩ => h 0⟩
39
+
40
+ theorem and {P Q} (hP : HasTest P) (hQ : HasTest Q) :
41
+ HasTest (fun O v => P O v ∧ Q O v) := by
42
+ classical
43
+ obtain ⟨t,ht⟩ := hP
44
+ obtain ⟨s,hs⟩ := hQ
45
+ refine ⟨.and (col 0 t) (col 1 s),fun O v => ?_⟩
46
+ simp only [Test.eval,col_eval]
47
+ constructor
48
+ · rintro ⟨hp,hq⟩
49
+ obtain ⟨f,hf⟩ := (ht O v).mp hp
50
+ obtain ⟨g,hg⟩ := (hs O v).mp hq
51
+ refine ⟨fun k => if (Nat.unpair k).1 = 0 then f (Nat.unpair k).2 else g (Nat.unpair k).2,?_⟩
52
+ intro n
53
+ constructor
54
+ · simpa only [Nat.unpair_pair,ite_eq_left rfl,ite_true] using hf n
55
+ · simpa only [Nat.unpair_pair,ite_eq_right (Nat.one_ne_zero)] using hg n
56
+ · rintro ⟨f,hf⟩
57
+ exact ⟨(ht O v).mpr ⟨_,fun n => (hf n).1⟩,
58
+ (hs O v).mpr ⟨_,fun n => (hf n).2⟩⟩
59
+
60
+ private def tailTest (t : Test) : Test :=
61
+ t.subst .input (fun s => .witness (.prim Nat.succ Primrec.succ s))
62
+
63
+ private theorem tail_eval (t : Test) (O : Oracles) (f : ℕ → ℕ) (v : ℕ) :
64
+ (tailTest t).eval O f v ↔ t.eval O (fun n => f (n+1)) v :=
65
+ t.eval_subst _ _ O f _ v (fun _ => rfl)
66
+
67
+ private def zeroTag : Test :=
68
+ .pure (fun n => n = 0) (Primrec.eq.comp Primrec.id (Primrec.const 0))
69
+ (.witness (.const 0))
70
+
71
+ theorem or {P Q} (hP : HasTest P) (hQ : HasTest Q) :
72
+ HasTest (fun O v => P O v ∨ Q O v) := by
73
+ classical
74
+ obtain ⟨t,ht⟩ := hP
75
+ obtain ⟨s,hs⟩ := hQ
76
+ refine ⟨(Test.and zeroTag (tailTest t)).or (.and (.neg zeroTag) (tailTest s)),fun O v => ?_⟩
77
+ simp only [Test.eval_or,Test.eval,tail_eval,zeroTag,Term.eval]
78
+ constructor
79
+ · intro h
80
+ rcases h with hp | hq
81
+ · obtain ⟨f,hf⟩ := (ht O v).mp hp
82
+ exact ⟨(fun n => Nat.casesOn n 0 f),fun n => Or.inl ⟨rfl,hf n⟩⟩
83
+ · obtain ⟨g,hg⟩ := (hs O v).mp hq
84
+ exact ⟨(fun n => Nat.casesOn n 1 g),fun n => Or.inr ⟨by simp,hg n⟩⟩
85
+ · rintro ⟨f,hf⟩
86
+ by_cases hz : f 0 = 0
87
+ · exact Or.inl ((ht O v).mpr ⟨_,fun n => ((hf n).resolve_right (fun h => h.1 hz)).2⟩)
88
+ · exact Or.inr ((hs O v).mpr ⟨_,fun n => ((hf n).resolve_left (fun h => hz h.1)).2⟩)
89
+
90
+ theorem comp {P} (hP : HasTest P) (g : ℕ → ℕ) (hg : Primrec g) :
91
+ HasTest (fun O v => P O (g v)) := by
92
+ obtain ⟨t,ht⟩ := hP
93
+ let inputTerm : Term := .pair (.prim g hg (.left .input)) (.right .input)
94
+ refine ⟨t.subst inputTerm Term.witness,fun O v => ?_⟩
95
+ dsimp only
96
+ rw [ht]
97
+ apply exists_congr
98
+ intro f
99
+ apply forall_congr'
100
+ intro n
101
+ simpa only [inputTerm,Term.eval,Term.left,Term.right,UniformArithmetic.left,
102
+ UniformArithmetic.right,Nat.unpair_pair] using
103
+ (t.eval_subst inputTerm Term.witness O f f (Nat.pair v n) (fun _ => rfl)).symm
104
+
105
+ theorem ex {P} (hP : HasTest P) : HasTest (fun O v => ∃ k, P O (Nat.pair v k)) := by
106
+ obtain ⟨t,ht⟩ := hP
107
+ let inputTerm : Term := .pair (.pair (.left .input) (.witness (.const 0))) (.right .input)
108
+ let q : Term → Term := fun s => .witness (.prim Nat.succ Primrec.succ s)
109
+ have he O f v n : (t.subst inputTerm q).eval O f (Nat.pair v n) ↔
110
+ t.eval O (fun k => f (k+1)) (Nat.pair (Nat.pair v (f 0)) n) := by
111
+ simpa only [inputTerm,Term.eval,Term.left,Term.right,UniformArithmetic.left,
112
+ UniformArithmetic.right,Nat.unpair_pair] using
113
+ t.eval_subst inputTerm q O f (fun k => f (k+1)) (Nat.pair v n) (fun _ => rfl)
114
+ refine ⟨t.subst inputTerm q,fun O v => ?_⟩
115
+ constructor
116
+ · rintro ⟨k,hk⟩
117
+ obtain ⟨f,hf⟩ := (ht O (Nat.pair v k)).mp hk
118
+ exact ⟨(fun n => Nat.casesOn n k f),fun n => (he _ _ _ _).mpr (hf n)⟩
119
+ · rintro ⟨f,hf⟩
120
+ exact ⟨f 0,(ht O _).mpr ⟨_,fun n => (he _ _ _ _).mp (hf n)⟩⟩
121
+
122
+ theorem all {P} (hP : HasTest P) : HasTest (fun O v => ∀ k, P O (Nat.pair v k)) := by
123
+ classical
124
+ obtain ⟨t,ht⟩ := hP
125
+ let inputTerm : Term := .pair (.pair (.left .input) (.left (.right .input))) (.right (.right .input))
126
+ let q : Term → Term := fun s => .witness (.pair (.left (.right .input)) s)
127
+ have he O f v n : (t.subst inputTerm q).eval O f (Nat.pair v n) ↔
128
+ t.eval O (fun k => f (Nat.pair (Nat.unpair n).1 k))
129
+ (Nat.pair (Nat.pair v (Nat.unpair n).1) (Nat.unpair n).2) := by
130
+ simpa only [inputTerm,Term.eval,Term.left,Term.right,UniformArithmetic.left,
131
+ UniformArithmetic.right,Nat.unpair_pair] using
132
+ t.eval_subst inputTerm q O f (fun k => f (Nat.pair (Nat.unpair n).1 k))
133
+ (Nat.pair v n) (fun _ => by simp [q,Term.eval,Term.left,Term.right,
134
+ UniformArithmetic.left,UniformArithmetic.right])
135
+ refine ⟨t.subst inputTerm q,fun O v => ?_⟩
136
+ constructor
137
+ · intro h
138
+ have hh : ∀ k, ∃ f, ∀ n, t.eval O f (Nat.pair (Nat.pair v k) n) :=
139
+ fun k => (ht O _).mp (h k)
140
+ choose f hf using hh
141
+ refine ⟨fun n => f (Nat.unpair n).1 (Nat.unpair n).2,fun n => (he _ _ _ _).mpr ?_⟩
142
+ simpa only [Nat.unpair_pair] using hf (Nat.unpair n).1 (Nat.unpair n).2
143
+ · rintro ⟨f,hf⟩ k
144
+ refine (ht O _).mpr ⟨fun n => f (Nat.pair k n),fun n => ?_⟩
145
+ simpa only [Nat.unpair_pair] using (he _ _ _ _).mp (hf (Nat.pair k n))
146
+
147
+ theorem congr {P Q} (hP : HasTest P) (he : ∀ O v, P O v ↔ Q O v) : HasTest Q := by
148
+ obtain ⟨t,ht⟩ := hP
149
+ exact ⟨t,fun O v => (he O v).symm.trans (ht O v)⟩
150
+ end HasTest
151
+
152
+ theorem arithmetic_tests {P} (h : Arith P) : HasTest P ∧ HasTest (fun O v => ¬ P O v) := by
153
+ induction h with
154
+ | pure P hP => exact ⟨HasTest.pure P hP,HasTest.not_pure P hP⟩
155
+ | query i => exact ⟨HasTest.query i,HasTest.not_query i⟩
156
+ | neg h ih => exact ⟨ih.2,ih.1.congr (fun _ _ => not_not.symm)⟩
157
+ | and h k ih ik =>
158
+ exact ⟨ih.1.and ik.1,(ih.2.or ik.2).congr (fun _ _ => not_and_or.symm)⟩
159
+ | ex h ih => exact ⟨ih.1.ex,ih.2.all.congr (fun _ _ => not_exists.symm)⟩
160
+ | comp f h hf ih => exact ⟨ih.1.comp f hf,ih.2.comp f hf⟩
161
+
162
+ end
163
+ end TuringRigidity.ArithmeticTree
164
+
165
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticSourceEquation.lean ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticProgramGraph
2
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticShuffleGraph
3
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticPrincipalIntersection
4
+
5
+ namespace OAI
6
+
7
+
8
+ namespace TuringRigidity.ArithmeticSourceEquation
9
+ open UniformArithmetic ArithmeticProgramGraph ArithmeticShuffleGraph GenericIdentity
10
+
11
+ theorem equation_arith (p : OracleCode) {P Y L R : OracleFamily}
12
+ (hP : ArithmeticOracle P) (hY : ArithmeticOracle Y)
13
+ (hL : ArithmeticOracle L) (hR : ArithmeticOracle R) :
14
+ Arith (fun O v => SourceEquation p (P O v) (Y O v, L O v, R O v)) := by
15
+ have hYL := code_arith hY hL
16
+ have hYR := code_arith hY hR
17
+ have hi := ArithmeticPrincipalIntersection.principal_arith (value_arith p hP hY)
18
+ (join_arith (value_arith p hP hYL) (value_arith p hP hL))
19
+ (join_arith (value_arith p hP hYR) (value_arith p hP hR))
20
+ exact (total_arith p hP hY).and ((total_arith p hP hL).and
21
+ ((total_arith p hP hR).and ((total_arith p hP hYL).and
22
+ ((total_arith p hP hYR).and hi))))
23
+
24
+ theorem sourceEquation_arith (p : OracleCode) :
25
+ Arith (fun O _ => SourceEquation p (O 0) (O 1, O 2, O 3)) :=
26
+ equation_arith p (parameter_arith 0) (parameter_arith 1)
27
+ (parameter_arith 2) (parameter_arith 3)
28
+
29
+ end TuringRigidity.ArithmeticSourceEquation
30
+
31
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticSourceTruth.lean ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticSourceEquation
2
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticGenericDensity
3
+
4
+ namespace OAI
5
+
6
+
7
+ namespace TuringRigidity.ArithmeticSourceTruth
8
+ open UniformArithmetic ArithmeticPrefixForcing GenericIdentity GenericTruth ShuffleRequirements
9
+
10
+ theorem binary_column_arith {B : OracleFamily} (hB : ArithmeticOracle B) (b : Bool) :
11
+ ArithmeticOracle (fun O v => PairGenericSelection.column b (B O v)) := by
12
+ have he := Primrec.nat_mul.comp (Primrec.const 2) right_primrec
13
+ cases b with
14
+ | false => exact query_at hB left_primrec he
15
+ | true => exact query_at hB left_primrec (Primrec.succ.comp he)
16
+
17
+ theorem triple_equation_arith (p : OracleCode) :
18
+ Arith (fun O _ => SourceEquation p (O 1) (triple (O 0))) :=
19
+ ArithmeticSourceEquation.equation_arith p (parameter_arith 1)
20
+ (binary_column_arith (parameter_arith 0) false)
21
+ (binary_column_arith (binary_column_arith (parameter_arith 0) true) false)
22
+ (binary_column_arith (binary_column_arith (parameter_arith 0) true) true)
23
+
24
+ theorem source_equation_truth (p : OracleCode) :
25
+ ∃ Q : PrefixPredicate, ArithmeticPrefix Q ∧ (∀ O v, Upward (Q O v)) ∧
26
+ ∀ P G : Oracle, Generic (fun _ => P) G →
27
+ (SourceEquation p P (triple G) ↔
28
+ G ∈ OpenSet (Q (fun _ => P) 0)) := by
29
+ obtain ⟨Q,hQ,hup,ht⟩ := ArithmeticGenericTruth.arithmetic_generic_truth (triple_equation_arith p)
30
+ refine ⟨Q,hQ,hup,?_⟩
31
+ intro P G hG
32
+ simpa using ht (fun _ => P) 0 G hG
33
+
34
+ theorem source_equation_of_dense (p : OracleCode) (P : Oracle)
35
+ (hd : ∀ s : List Bool, ∃ H : Oracle,
36
+ Generic (fun _ => P) H ∧ Realizes s H ∧ SourceEquation p P (triple H)) :
37
+ ∀ G : Oracle, Generic (fun _ => P) G → SourceEquation p P (triple G) := by
38
+ have hden : ∀ s : List Bool, ∃ H : Oracle,
39
+ Generic (fun _ => P) H ∧ Realizes s H ∧
40
+ SourceEquation p ((Function.update (fun _ => P) 0 H) 1)
41
+ (triple ((Function.update (fun _ => P) 0 H) 0)) := by
42
+ simpa using hd
43
+ simpa using ArithmeticGenericDensity.truth_of_dense (triple_equation_arith p)
44
+ (fun _ => P) 0 hden
45
+
46
+ end TuringRigidity.ArithmeticSourceTruth
47
+
48
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTables.lean ADDED
@@ -0,0 +1,100 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.UniformArithmetic
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.UniformArithmetic
6
+ open Encodable UniformOracle CommonIdeal IndexMatrix
7
+
8
+ abbrev OracleFamily := Oracles → ℕ → Oracle
9
+ abbrev ArithmeticOracle (B : OracleFamily) :=
10
+ Arith (fun O v => B O (left v) (right v) = true)
11
+
12
+ theorem query_at {B : OracleFamily} (hB : ArithmeticOracle B)
13
+ {c n : ℕ → ℕ} (hc : Primrec c) (hn : Primrec n) :
14
+ Arith (fun O v => B O (c v) (n v) = true) :=
15
+ (hB.comp _ (Primrec₂.natPair.comp hc hn)).congr
16
+ (fun _ _ => by simp only [left,right,Nat.unpair_pair])
17
+
18
+ theorem bit_equal {B : OracleFamily} (hB : ArithmeticOracle B)
19
+ {c n a : ℕ → ℕ} (hc : Primrec c) (hn : Primrec n) (ha : Primrec a) :
20
+ Arith (fun O v => a v = bit (B O (c v) (n v))) := by
21
+ have h := query_at hB hc hn
22
+ exact ((h.and (equal ha (Primrec.const 1))).or
23
+ (h.neg.and (equal ha (Primrec.const 0)))).congr (fun O v => by
24
+ cases B O (c v) (n v) <;> simp [bit])
25
+
26
+ def table (c : ℕ) : List ℕ := (decode c).getD []
27
+ def item (c k : ℕ) : ℕ := (table c).getD k 0
28
+
29
+ theorem table_primrec : Primrec table :=
30
+ Primrec.option_getD.comp Primrec.decode (Primrec.const [])
31
+ theorem item_primrec : Primrec₂ item :=
32
+ (Primrec.list_getD 0).comp (table_primrec.comp Primrec.fst) Primrec.snd
33
+
34
+ def Prefix (B : Oracle) (m c : ℕ) : Prop :=
35
+ (table c).length = m ∧ ∀ k, k < m → item c k = bit (B k)
36
+
37
+ theorem prefix_iff (B : Oracle) (m c : ℕ) :
38
+ Prefix B m c ↔ table c = oraclePrefix (fun k => bit (B k)) m := by
39
+ constructor
40
+ · rintro ⟨hlen,he⟩
41
+ apply List.ext_getElem
42
+ · simpa [oraclePrefix] using hlen
43
+ · intro k hk hk'
44
+ have hkm : k < m := by simpa [oraclePrefix] using hk'
45
+ have hh := he k hkm
46
+ simpa [item,List.getD_eq_getElem?_getD,List.getElem?_eq_getElem hk,
47
+ oraclePrefix] using hh
48
+ · intro he
49
+ constructor
50
+ · simp [he,oraclePrefix]
51
+ · intro k hk
52
+ simp [item,he,oraclePrefix,List.getD_eq_getElem?_getD,List.getElem?_range hk]
53
+
54
+ theorem prefix_arith {B : OracleFamily} (hB : ArithmeticOracle B)
55
+ {c m l : ℕ → ℕ} (hc : Primrec c) (hm : Primrec m) (hl : Primrec l) :
56
+ Arith (fun O v => Prefix (B O (c v)) (m v) (l v)) := by
57
+ have hb := bit_equal hB (hc.comp left_primrec) right_primrec
58
+ (item_primrec.comp (hl.comp left_primrec) right_primrec)
59
+ have ht := ((less right_primrec (hm.comp left_primrec)).imp hb).all
60
+ exact ((equal (Primrec.list_length.comp (table_primrec.comp hl)) hm).and ht).congr
61
+ (fun _ _ => by simp only [Prefix,left,right,Nat.unpair_pair])
62
+
63
+ def trialTest (e n m t a : ℕ) : Prop :=
64
+ (machine e).evaln t (Nat.pair (encode (table m)) n) = some a
65
+
66
+ theorem trialTest_arith {e n m t a : ℕ → ℕ}
67
+ (he : Primrec e) (hn : Primrec n) (hm : Primrec m) (ht : Primrec t) (ha : Primrec a) :
68
+ Arith (fun _ v => trialTest (e v) (n v) (m v) (t v) (a v)) := by
69
+ apply Arith.pure
70
+ exact Primrec.eq.comp
71
+ (Nat.Partrec.Code.primrec_evaln.comp
72
+ ((ht.pair (machine_primrec.comp he)).pair
73
+ (Primrec₂.natPair.comp (Primrec.encode.comp (table_primrec.comp hm)) hn)))
74
+ (Primrec.option_some.comp ha)
75
+
76
+ theorem run_arith {B : OracleFamily} (hB : ArithmeticOracle B)
77
+ {c e n z a : ℕ → ℕ} (hc : Primrec c) (he : Primrec e) (hn : Primrec n)
78
+ (hz : Primrec z) (ha : Primrec a) :
79
+ Arith (fun O v => TableIndices.run (B O (c v)) (machine (e v)) (n v) (z v) = some (a v)) := by
80
+ have hp := prefix_arith hB (hc.comp left_primrec)
81
+ ((left_primrec.comp hz).comp left_primrec) right_primrec
82
+ have ht := trialTest_arith (he.comp left_primrec) (hn.comp left_primrec)
83
+ right_primrec ((right_primrec.comp hz).comp left_primrec) (ha.comp left_primrec)
84
+ apply (hp.and ht).ex.congr
85
+ intro O v
86
+ simp only [left,right,Nat.unpair_pair]
87
+ constructor
88
+ · rintro ⟨l,hp,ht⟩
89
+ rw [prefix_iff] at hp
90
+ simpa [trialTest,TableIndices.run,trial,hp] using ht
91
+ · intro ht
92
+ let L := oraclePrefix (fun k => bit (B O (c v) k)) (Nat.unpair (z v)).1
93
+ refine ⟨encode L,?_,?_⟩
94
+ · rw [prefix_iff]
95
+ simp [table,L]
96
+ · simpa [trialTest,table,L,TableIndices.run,trial] using ht
97
+
98
+ end TuringRigidity.UniformArithmetic
99
+
100
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTestApproximation.lean ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticFiniteTest
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.ArithmeticTree
6
+ open UniformArithmetic
7
+ noncomputable section
8
+ attribute [local instance] Classical.propDecidable
9
+
10
+ abbrev Approx := ℕ → Option ℕ
11
+
12
+ def Extends (s t : Approx) : Prop := ∀ i a, s i = some a → t i = some a
13
+
14
+ def Captures (s : Approx) (f : ℕ → ℕ) (N : ℕ) : Prop := ∀ i < N, s i = some (f i)
15
+
16
+ theorem Captures.mono {s f N K} (h : Captures s f N) (hK : K ≤ N) : Captures s f K :=
17
+ fun i hi => h i (lt_of_lt_of_le hi hK)
18
+
19
+ namespace Term
20
+
21
+ def approx (s : Approx) (v : ℕ) : Term → Option ℕ
22
+ | .input => some v
23
+ | .const n => some n
24
+ | .prim g _ t => (t.approx s v).bind (fun a => some (g a))
25
+ | .pair t u => (t.approx s v).bind (fun a => (u.approx s v).bind (fun b => some (Nat.pair a b)))
26
+ | .witness t => (t.approx s v).bind s
27
+
28
+ theorem approx_mono (t : Term) {s u : Approx} (h : Extends s u) (v a : ℕ)
29
+ (ha : t.approx s v = some a) : t.approx u v = some a := by
30
+ induction t generalizing a with
31
+ | input => exact ha
32
+ | const n => exact ha
33
+ | prim g hg t ih =>
34
+ simp only [approx,Option.bind_eq_some_iff] at ha ⊢
35
+ obtain ⟨b,hb,he⟩ := ha
36
+ exact ⟨b,ih b hb,he⟩
37
+ | pair t w ih ik =>
38
+ simp only [approx,Option.bind_eq_some_iff] at ha ⊢
39
+ obtain ⟨b,hb,c,hc,he⟩ := ha
40
+ exact ⟨b,ih b hb,c,ik c hc,he⟩
41
+ | witness t ih =>
42
+ simp only [approx,Option.bind_eq_some_iff] at ha ⊢
43
+ obtain ⟨b,hb,he⟩ := ha
44
+ exact ⟨b,ih b hb,h b a he⟩
45
+
46
+ @[simp] theorem approx_full (t : Term) (f : ℕ → ℕ) (v : ℕ) :
47
+ t.approx (fun i => some (f i)) v = some (t.eval f v) := by
48
+ induction t <;> simp_all [approx,eval]
49
+
50
+ theorem approx_sound (t : Term) {s : Approx} {f : ℕ → ℕ}
51
+ (h : Extends s (fun i => some (f i))) (v a : ℕ) (ha : t.approx s v = some a) :
52
+ t.eval f v = a := by
53
+ simpa only [approx_full,Option.some.injEq] using t.approx_mono h v a ha
54
+
55
+ theorem approx_complete (t : Term) (f : ℕ → ℕ) (v : ℕ) :
56
+ ∃ N, ∀ s : Approx, Captures s f N → t.approx s v = some (t.eval f v) := by
57
+ induction t with
58
+ | input => exact ⟨0,fun _ _ => rfl⟩
59
+ | const n => exact ⟨0,fun _ _ => rfl⟩
60
+ | prim g hg t ih =>
61
+ obtain ⟨N,hN⟩ := ih
62
+ exact ⟨N,fun s hs => by simp [approx,eval,hN s hs]⟩
63
+ | pair t u ih ik =>
64
+ obtain ⟨N,hN⟩ := ih
65
+ obtain ⟨K,hK⟩ := ik
66
+ exact ⟨max N K,fun s hs => by
67
+ simp [approx,eval,hN s (hs.mono (le_max_left _ _)),hK s (hs.mono (le_max_right _ _))]⟩
68
+ | witness t ih =>
69
+ obtain ⟨N,hN⟩ := ih
70
+ refine ⟨max N (t.eval f v + 1),fun s hs => ?_⟩
71
+ simp only [approx,hN s (hs.mono (le_max_left _ _)),Option.bind_some,eval]
72
+ exact hs _ (lt_of_lt_of_le (Nat.lt_succ_self _) (le_max_right _ _))
73
+ end Term
74
+
75
+ namespace Test
76
+
77
+ def approx (O : Oracles) (s : Approx) (v : ℕ) : Test → Option Bool
78
+ | .pure P _ t => (t.approx s v).bind (fun a => some (decide (P a)))
79
+ | .query i t => (t.approx s v).bind (fun a => some (O i a))
80
+ | .neg t => (t.approx O s v).bind (fun a => some (!a))
81
+ | .and t u => (t.approx O s v).bind (fun a => (u.approx O s v).bind (fun b => some (a && b)))
82
+
83
+ private theorem approx_mono (t : Test) (O : Oracles) {s u : Approx} (h : Extends s u)
84
+ (v : ℕ) (a : Bool) (ha : t.approx O s v = some a) : t.approx O u v = some a := by
85
+ induction t generalizing a with
86
+ | pure P hP t =>
87
+ simp only [approx,Option.bind_eq_some_iff] at ha ⊢
88
+ obtain ⟨b,hb,he⟩ := ha
89
+ exact ⟨b,t.approx_mono h v b hb,he⟩
90
+ | query i t =>
91
+ simp only [approx,Option.bind_eq_some_iff] at ha ⊢
92
+ obtain ⟨b,hb,he⟩ := ha
93
+ exact ⟨b,t.approx_mono h v b hb,he⟩
94
+ | neg t ih =>
95
+ simp only [approx,Option.bind_eq_some_iff] at ha ⊢
96
+ obtain ⟨b,hb,he⟩ := ha
97
+ exact ⟨b,ih b hb,he⟩
98
+ | and t w ih ik =>
99
+ simp only [approx,Option.bind_eq_some_iff] at ha ⊢
100
+ obtain ⟨b,hb,c,hc,he⟩ := ha
101
+ exact ⟨b,ih b hb,c,ik c hc,he⟩
102
+
103
+ @[simp] theorem approx_full (t : Test) (O : Oracles) (f : ℕ → ℕ) (v : ℕ) :
104
+ t.approx O (fun i => some (f i)) v = some (decide (t.eval O f v)) := by
105
+ induction t with
106
+ | pure P hP t =>
107
+ by_cases h : P (t.eval f v) <;> simp [approx,eval,h]
108
+ | query i t => cases h : O i (t.eval f v) <;> simp [approx,eval,h]
109
+ | neg t ih => by_cases h : t.eval O f v <;> simp [approx,eval,ih,h]
110
+ | and t w ih ik =>
111
+ by_cases ht : t.eval O f v <;> by_cases hw : w.eval O f v <;> simp [approx,eval,ih,ik,ht,hw]
112
+
113
+ theorem approx_sound (t : Test) (O : Oracles) {s : Approx} {f : ℕ → ℕ}
114
+ (h : Extends s (fun i => some (f i))) (v : ℕ) (a : Bool)
115
+ (ha : t.approx O s v = some a) : t.eval O f v ↔ a = true := by
116
+ have he : decide (t.eval O f v) = a := by
117
+ simpa only [approx_full,Option.some.injEq] using t.approx_mono O h v a ha
118
+ rw [← he]
119
+ simp
120
+
121
+ theorem approx_complete (t : Test) (O : Oracles) (f : ℕ → ℕ) (v : ℕ) :
122
+ ∃ N, ∀ s : Approx, Captures s f N →
123
+ t.approx O s v = some (decide (t.eval O f v)) := by
124
+ induction t with
125
+ | pure P hP t =>
126
+ obtain ⟨N,hN⟩ := t.approx_complete f v
127
+ refine ⟨N,fun s hs => ?_⟩
128
+ rw [← approx_full]
129
+ simp only [approx,hN s hs,Term.approx_full]
130
+ | query i t =>
131
+ obtain ⟨N,hN⟩ := t.approx_complete f v
132
+ refine ⟨N,fun s hs => ?_⟩
133
+ rw [← approx_full]
134
+ simp only [approx,hN s hs,Term.approx_full]
135
+ | neg t ih =>
136
+ obtain ⟨N,hN⟩ := ih
137
+ refine ⟨N,fun s hs => ?_⟩
138
+ rw [← approx_full]
139
+ simp only [approx,hN s hs,approx_full]
140
+ | and t u ih ik =>
141
+ obtain ⟨N,hN⟩ := ih
142
+ obtain ⟨K,hK⟩ := ik
143
+ refine ⟨max N K,fun s hs => ?_⟩
144
+ rw [← approx_full]
145
+ simp only [approx,hN s (hs.mono (le_max_left _ _)),hK s (hs.mono (le_max_right _ _)),approx_full]
146
+
147
+ theorem rejection_mono (t : Test) (O : Oracles) {s u : Approx} (h : Extends s u)
148
+ (v : ℕ) (ha : t.approx O s v = some false) : t.approx O u v = some false :=
149
+ t.approx_mono O h v false ha
150
+ end Test
151
+
152
+ end
153
+ end TuringRigidity.ArithmeticTree
154
+
155
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTreeDefinability.lean ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticWitnessTree
2
+ import Mathlib.Computability.Primrec.List
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity.ArithmeticTree
7
+ open UniformArithmetic Encodable
8
+ noncomputable section
9
+ attribute [local instance] Classical.propDecidable
10
+
11
+ theorem Term.approx_primrec (t : Term) :
12
+ Primrec (fun p : List ℕ × ℕ => t.approx (listApprox p.1) p.2) := by
13
+ induction t with
14
+ | input => exact Primrec.option_some.comp Primrec.snd
15
+ | const n => exact Primrec.const (some n)
16
+ | prim g hg t ih =>
17
+ exact Primrec.option_bind ih (Primrec.option_some.comp (hg.comp Primrec.snd))
18
+ | pair t u ih ik =>
19
+ exact Primrec.option_bind ih (Primrec.option_bind (ik.comp Primrec.fst)
20
+ (Primrec.option_some.comp (Primrec₂.natPair.comp (Primrec.snd.comp Primrec.fst) Primrec.snd)))
21
+ | witness t ih =>
22
+ exact Primrec.option_bind ih
23
+ (Primrec.list_getElem?.comp (Primrec.fst.comp Primrec.fst) Primrec.snd)
24
+
25
+ private theorem option_neg_iff (a : Option Bool) (b : Bool) :
26
+ (a.bind (fun c => some (!c)) = some b) ↔ a = some (!b) := by
27
+ cases a with
28
+ | none => simp
29
+ | some a => cases a <;> cases b <;> decide
30
+
31
+ private theorem option_and_true (a b : Option Bool) :
32
+ (a.bind (fun c => b.bind (fun d => some (c && d))) = some true) ↔
33
+ a = some true ∧ b = some true := by
34
+ cases a with
35
+ | none => simp
36
+ | some a => cases b with
37
+ | none => simp
38
+ | some b => cases a <;> cases b <;> decide
39
+
40
+ private theorem option_and_false (a b : Option Bool) :
41
+ (a.bind (fun c => b.bind (fun d => some (c && d))) = some false) ↔
42
+ (a = some false ∧ b = some false) ∨
43
+ (a = some false ∧ b = some true) ∨ (a = some true ∧ b = some false) := by
44
+ cases a with
45
+ | none => simp
46
+ | some a => cases b with
47
+ | none => simp
48
+ | some b => cases a <;> cases b <;> decide
49
+
50
+ theorem Test.approx_arith (t : Test) {s : ℕ → List ℕ} (hs : Primrec s)
51
+ {v : ℕ → ℕ} (hv : Primrec v) (b : Bool) :
52
+ Arith (fun O k => t.approx O (listApprox (s k)) (v k) = some b) := by
53
+ induction t generalizing s v b with
54
+ | pure P hP t =>
55
+ have hp : Primrec (fun k : ℕ => (t.approx (listApprox (s k)) (v k)).bind
56
+ (fun a => some (decide (P a)))) := Primrec.option_bind ((t.approx_primrec).comp (hs.pair hv))
57
+ (Primrec.option_some.comp (hP.decide.comp Primrec.snd))
58
+ exact .pure _ (Primrec.eq.comp hp (Primrec.const (some b)))
59
+ | query i t =>
60
+ have ht := (t.approx_primrec).comp ((hs.comp left_primrec).pair (hv.comp left_primrec))
61
+ have hh : Arith (fun _ k => t.approx (listApprox (s (left k))) (v (left k)) = some (right k)) :=
62
+ .pure _ (Primrec.eq.comp ht (Primrec.option_some.comp right_primrec))
63
+ have hq : Arith (fun O k => O i (right k) = b) := by
64
+ cases b with
65
+ | true => exact (Arith.query i).comp _ right_primrec
66
+ | false =>
67
+ exact ((Arith.query i).comp _ right_primrec).neg.congr
68
+ (fun O k => by cases O i (right k) <;> simp)
69
+ exact (hh.and hq).ex.congr (fun O k => by
70
+ simp only [left,right,Nat.unpair_pair,Test.approx,Option.bind_eq_some_iff,Option.some.injEq])
71
+ | neg t ih =>
72
+ exact (ih hs hv (!b)).congr (fun O k => (option_neg_iff _ b).symm)
73
+ | and t u ih ik =>
74
+ cases b with
75
+ | true =>
76
+ exact ((ih hs hv true).and (ik hs hv true)).congr
77
+ (fun O k => (option_and_true _ _).symm)
78
+ | false =>
79
+ exact (((ih hs hv false).and (ik hs hv false)).or
80
+ (((ih hs hv false).and (ik hs hv true)).or ((ih hs hv true).and (ik hs hv false)))).congr
81
+ (fun O k => (option_and_false _ _).symm)
82
+
83
+ theorem Test.accepts_arith (t : Test) {s : ℕ → List ℕ} (hs : Primrec s)
84
+ {v : ℕ → ℕ} (hv : Primrec v) : Arith (fun O k => t.accepts O (v k) (s k)) := by
85
+ have hlen : Arith (fun _ k => right k < (s (left k)).length) :=
86
+ .pure _ (Primrec.nat_lt.comp right_primrec (Primrec.list_length.comp (hs.comp left_primrec)))
87
+ have ht := t.approx_arith (hs.comp left_primrec)
88
+ (Primrec₂.natPair.comp (hv.comp left_primrec) right_primrec) false
89
+ exact (hlen.imp ht.neg).all.congr (fun O k => by
90
+ simp only [Test.accepts,left,right,Nat.unpair_pair])
91
+
92
+ def decodeNode (n : ℕ) : List ℕ := (decode (α := List ℕ) n).getD []
93
+
94
+ theorem decodeNode_primrec : Primrec decodeNode :=
95
+ Primrec.option_getD.comp Primrec.decode (Primrec.const [])
96
+
97
+ @[simp] theorem decodeNode_encode (s : List ℕ) : decodeNode (encode s) = s := by
98
+ simp [decodeNode]
99
+
100
+ def Test.nodeCode (t : Test) (O : Oracles) (v : ℕ) : Oracle :=
101
+ fun n => decide (t.accepts O v (decodeNode n))
102
+
103
+ theorem Test.nodeCode_arith (t : Test) (v : ℕ) :
104
+ Arith (fun O n => t.nodeCode O v n = true) :=
105
+ (t.accepts_arith decodeNode_primrec (Primrec.const v)).congr (fun _ _ => by simp [Test.nodeCode])
106
+
107
+ end
108
+ end TuringRigidity.ArithmeticTree
109
+
110
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTreeDescent.lean ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.SetModels.SetModelTreeRelations
2
+ import OAI.Computability.DegreeRigidity.Constructibility.PersistenceWitnessTree
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity.ArithmeticTree
7
+ open UniformArithmetic SetModelReals SetModelSyntax SetModelFunctions
8
+ universe u
9
+ noncomputable section
10
+ attribute [local instance] Classical.propDecidable
11
+
12
+ def unionRead (c : ℕ → ℕ) (i : ℕ) : ℕ := (decodeNode (c (i+1)))[i]?.getD 0
13
+
14
+ private theorem length_chain (c : ℕ → ℕ)
15
+ (hs : ∀ n, ∃ a, decodeNode (c (n+1)) = decodeNode (c n) ++ [a]) (n : ℕ) :
16
+ n ≤ (decodeNode (c n)).length := by
17
+ induction n with
18
+ | zero => omega
19
+ | succ n ih =>
20
+ obtain ⟨a,ha⟩ := hs n
21
+ simp only [ha,List.length_append,List.length_singleton]
22
+ omega
23
+
24
+ private theorem extends_chain (c : ℕ → ℕ)
25
+ (hs : ∀ n, ∃ a, decodeNode (c (n+1)) = decodeNode (c n) ++ [a])
26
+ {i j : ℕ} (hij : i ≤ j) : Extends (listApprox (decodeNode (c i))) (listApprox (decodeNode (c j))) := by
27
+ induction j, hij using Nat.le_induction with
28
+ | base => exact fun _ _ h => h
29
+ | succ j hj ih =>
30
+ obtain ⟨a,ha⟩ := hs j
31
+ intro k b hb
32
+ rw [ha]
33
+ exact listApprox_append _ _ k b (ih k b hb)
34
+
35
+ theorem unionRead_captures (c : ℕ → ℕ)
36
+ (hs : ∀ n, ∃ a, decodeNode (c (n+1)) = decodeNode (c n) ++ [a]) (n : ℕ) :
37
+ Captures (listApprox (decodeNode (c n))) (unionRead c) n := by
38
+ intro i hi
39
+ have hil : i < (decodeNode (c (i+1))).length :=
40
+ lt_of_lt_of_le (Nat.lt_succ_self _) (length_chain c hs _)
41
+ have he : (decodeNode (c (i+1)))[i]? = some ((decodeNode (c (i+1)))[i]) :=
42
+ List.getElem?_eq_some_iff.mpr ⟨hil,rfl⟩
43
+ have hv : unionRead c i = (decodeNode (c (i+1)))[i] := by simp [unionRead,he]
44
+ rw [hv]
45
+ exact extends_chain c hs (Nat.succ_le_of_lt hi) i _ he
46
+
47
+ theorem Test.eval_of_descent (t : Test) (O : Oracles) (v : ℕ) (c : ℕ → ℕ)
48
+ (hc : ∀ n, t.edgePredicate O v (c (n+1)) (c n)) :
49
+ ∀ n, t.eval O (unionRead c) (Nat.pair v n) := by
50
+ have hs : ∀ n, ∃ a, decodeNode (c (n+1)) = decodeNode (c n) ++ [a] := fun n => (hc n).2.2
51
+ intro n
52
+ obtain ⟨N,hN⟩ := t.approx_complete O (unionRead c) (Nat.pair v n)
53
+ let K := max N (n+1)
54
+ have he := hN (listApprox (decodeNode (c K))) ((unionRead_captures c hs K).mono (le_max_left _ _))
55
+ have hnK : n < (decodeNode (c K)).length :=
56
+ lt_of_lt_of_le (lt_of_lt_of_le (Nat.lt_succ_self _) (le_max_right _ _)) (length_chain c hs K)
57
+ have hh := (hc K).2.1.2 n hnK
58
+ by_contra hp
59
+ exact hh (he.trans (by simp [hp]))
60
+
61
+ private theorem read_primrec : Primrec (fun p : ℕ × ℕ => (decodeNode p.1)[p.2]?.getD 0) :=
62
+ Primrec.option_getD.comp (Primrec.list_getElem?.comp (decodeNode_primrec.comp Primrec.fst) Primrec.snd)
63
+ (Primrec.const 0)
64
+
65
+ theorem union_real_mem {M : ZFSet.{u}} (C : Context M) (G : Oracle) (hG : G ∈ reals M)
66
+ (c : ℕ → ℕ) (hc : ∀ n k, G (Nat.pair n k) = true ↔ k = c n) :
67
+ Test.realPart (unionRead c) ∈ reals M := by
68
+ let idx : ℕ → ℕ := fun n => Nat.pair 0 n
69
+ have hi : Primrec idx := Primrec₂.natPair.comp (Primrec.const 0) Primrec.id
70
+ have hq := (Arith.query 0).comp
71
+ (fun n => Nat.pair (idx (left n)+1) (right n))
72
+ (Primrec₂.natPair.comp (Primrec.succ.comp (hi.comp left_primrec)) right_primrec)
73
+ have hr : Arith (fun _ n => (decodeNode (right n))[idx (left n)]?.getD 0 = 1) :=
74
+ .pure _ (Primrec.eq.comp (read_primrec.comp (right_primrec.pair (hi.comp left_primrec))) (Primrec.const 1))
75
+ apply arithmetic_comprehension C (hq.and hr).ex (fun _ => G) (fun _ => hG) _
76
+ intro n
77
+ simp only [left,right,Nat.unpair_pair]
78
+ change (∃ k, G (Nat.pair (idx n + 1) k) = true ∧ (decodeNode k)[idx n]?.getD 0 = 1) ↔ _
79
+ simp only [hc,exists_eq_left,Test.realPart,unionRead,idx]
80
+ exact ⟨decide_eq_true,of_decide_eq_true⟩
81
+
82
+ end
83
+ end TuringRigidity.ArithmeticTree
84
+
85
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTreeSequence.lean ADDED
@@ -0,0 +1,87 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticTreeDefinability
2
+
3
+ namespace OAI
4
+
5
+
6
+ namespace TuringRigidity.ArithmeticTree
7
+ open UniformArithmetic Encodable
8
+ noncomputable section
9
+
10
+ def Test.codeChild (t : Test) (O : Oracles) (v x y : ℕ) : Prop :=
11
+ t.accepts O v (decodeNode x) ∧ t.accepts O v (decodeNode y) ∧
12
+ ∃ a, decodeNode x = decodeNode y ++ [a]
13
+
14
+ theorem Test.codeChild_arith (t : Test) (v : ℕ) :
15
+ Arith (fun O k => t.codeChild O v (left k) (right k)) := by
16
+ have hx := t.accepts_arith (decodeNode_primrec.comp left_primrec) (Primrec.const v)
17
+ have hy := t.accepts_arith (decodeNode_primrec.comp right_primrec) (Primrec.const v)
18
+ have he : Arith (fun _ k => decodeNode (left (left k)) = decodeNode (right (left k)) ++ [right k]) :=
19
+ .pure _ (Primrec.eq.comp (decodeNode_primrec.comp (left_primrec.comp left_primrec))
20
+ (Primrec.list_append.comp (decodeNode_primrec.comp (right_primrec.comp left_primrec))
21
+ (Primrec.list_cons.comp right_primrec (Primrec.const []))))
22
+ exact (hx.and (hy.and he.ex)).congr (fun _ _ => by
23
+ simp only [Test.codeChild,left,right,Nat.unpair_pair])
24
+
25
+ def chainValue (s : ℕ → ℕ) (i : ℕ) : ℕ := ((decodeNode (s (i+1)))[i]?).getD 0
26
+
27
+ theorem code_chain_extends (s : ℕ → ℕ)
28
+ (h : ∀ n, ∃ a, decodeNode (s (n+1)) = decodeNode (s n) ++ [a])
29
+ {i j : ℕ} (hij : i ≤ j) :
30
+ Extends (listApprox (decodeNode (s i))) (listApprox (decodeNode (s j))) := by
31
+ induction j, hij using Nat.le_induction with
32
+ | base => exact fun _ _ h => h
33
+ | succ j hj ih =>
34
+ obtain ⟨a,ha⟩ := h j
35
+ intro k b hb
36
+ rw [ha]
37
+ exact listApprox_append _ _ k b (ih k b hb)
38
+
39
+ theorem code_chain_length (s : ℕ → ℕ)
40
+ (h : ∀ n, ∃ a, decodeNode (s (n+1)) = decodeNode (s n) ++ [a]) (n : ℕ) :
41
+ n ≤ (decodeNode (s n)).length := by
42
+ induction n with
43
+ | zero => omega
44
+ | succ n ih =>
45
+ obtain ⟨a,ha⟩ := h n
46
+ simp only [ha,List.length_append,List.length_singleton]
47
+ omega
48
+
49
+ theorem code_chain_captures (s : ℕ → ℕ)
50
+ (h : ∀ n, ∃ a, decodeNode (s (n+1)) = decodeNode (s n) ++ [a]) (n : ℕ) :
51
+ Captures (listApprox (decodeNode (s n))) (chainValue s) n := by
52
+ intro i hi
53
+ have hil : i < (decodeNode (s (i+1))).length :=
54
+ lt_of_lt_of_le (Nat.lt_succ_self _) (code_chain_length s h _)
55
+ have he : (decodeNode (s (i+1)))[i]? = some (chainValue s i) := by
56
+ simp only [chainValue,List.getElem?_eq_getElem hil,Option.getD_some]
57
+ exact code_chain_extends s h (Nat.succ_le_of_lt hi) i _ he
58
+
59
+ theorem Test.code_chain_eval (t : Test) (O : Oracles) (v : ℕ) (s : ℕ → ℕ)
60
+ (h : ∀ n, t.codeChild O v (s (n+1)) (s n)) :
61
+ ∀ n, t.eval O (chainValue s) (Nat.pair v n) := by
62
+ intro n
63
+ have hstep := fun k => (h k).2.2
64
+ obtain ⟨N,hN⟩ := t.approx_complete O (chainValue s) (Nat.pair v n)
65
+ let K := max N (n+1)
66
+ have he := hN (listApprox (decodeNode (s K)))
67
+ ((code_chain_captures s hstep K).mono (le_max_left _ _))
68
+ have hn : n < (decodeNode (s K)).length :=
69
+ lt_of_lt_of_le (lt_of_lt_of_le (Nat.lt_succ_self _) (le_max_right _ _))
70
+ (code_chain_length s hstep K)
71
+ have hh := (h K).2.1 n hn
72
+ by_contra hp
73
+ exact hh (he.trans (by simp [hp]))
74
+
75
+ theorem Test.code_chain_exists (t : Test) (O : Oracles) (v : ℕ)
76
+ (h : ∃ f : ℕ → ℕ, ∀ n, t.eval O f (Nat.pair v n)) :
77
+ ∃ s : ℕ → ℕ, ∀ n, t.codeChild O v (s (n+1)) (s n) := by
78
+ obtain ⟨f,hf⟩ := h
79
+ refine ⟨fun n => encode (initialSegment f n),fun n => ?_⟩
80
+ simp only [Test.codeChild,decodeNode_encode]
81
+ exact ⟨(t.branch_iff O v f).mpr hf (n+1),(t.branch_iff O v f).mpr hf n,
82
+ f n,prefix_succ f n⟩
83
+
84
+ end
85
+ end TuringRigidity.ArithmeticTree
86
+
87
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticTruthRequirements.lean ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticPrefixFamilies
2
+
3
+ namespace OAI
4
+
5
+
6
+ namespace TuringRigidity.ArithmeticTruthRequirements
7
+ open UniformArithmetic ArithmeticPrefixForcing ArithmeticPrefixFamilies
8
+ open ArithmeticGenericTruth FiniteShuffle ShuffleRequirements
9
+ open EncodedForcing (word word_primrec)
10
+
11
+ theorem arithmetic_truth_requirements {P : Predicate} (hP : Arith P) :
12
+ ∃ Q D : PrefixPredicate, ArithmeticPrefix Q ∧ ArithmeticPrefix D ∧
13
+ (∀ O v, Upward (Q O v)) ∧
14
+ (∀ O v n, DenseOpen (D O (Nat.pair v n))) ∧
15
+ ∀ O v G, GenericFor (fun n => D O (Nat.pair v n)) G →
16
+ (P (Function.update O 0 G) v ↔ G ∈ OpenSet (Q O v)) := by
17
+ have htrue : ArithmeticPrefix (fun _ _ _ => True) :=
18
+ (equal (Primrec.const 0) (Primrec.const 0)).congr (fun _ _ => by simp)
19
+ induction hP with
20
+ | pure P hP =>
21
+ refine ⟨fun _ v _ => P v, fun _ _ _ => True, .pure _ (hP.comp left_primrec), htrue,
22
+ fun _ _ _ _ _ h => h, fun _ _ _ => dense_true, ?_⟩
23
+ intro O v G _
24
+ exact (open_constant _ _).symm
25
+ | query i =>
26
+ by_cases hi : i = 0
27
+ · subst i
28
+ let Q : PrefixPredicate := fun _ v s => v < s.length ∧ s.getD v false = true
29
+ have hQ : ArithmeticPrefix Q :=
30
+ (less left_primrec (Primrec.list_length.comp (word_primrec.comp right_primrec))).and
31
+ (.pure _ (Primrec.eq.comp ((Primrec.list_getD false).comp
32
+ (word_primrec.comp right_primrec) left_primrec) (Primrec.const true)))
33
+ refine ⟨Q,fun _ _ _ => True,hQ,htrue,?_,fun _ _ _ => dense_true,?_⟩
34
+ · intro O v s t hst hs
35
+ exact ⟨lt_of_lt_of_le hs.1 hst.length_le,
36
+ (getD_of_prefix hst v hs.1).symm.trans hs.2⟩
37
+ · intro O v G _
38
+ simp only [Function.update_self]
39
+ constructor
40
+ · intro hv
41
+ refine ⟨initial G (v+1),⟨?_,?_⟩,
42
+ (realizes_initial _ _ _).mpr (fun _ _ => rfl)⟩
43
+ · simp
44
+ · exact (prefix_getD G _ v (by omega)).trans hv
45
+ · rintro ⟨s,hs,hGs⟩
46
+ exact (hGs v hs.1).symm.trans hs.2
47
+ · refine ⟨fun O v _ => O i v = true, fun _ _ _ => True, (Arith.query i).comp _ left_primrec, htrue,
48
+ fun _ _ _ _ _ h => h, fun _ _ _ => dense_true, ?_⟩
49
+ intro O v G _
50
+ simpa only [Function.update_of_ne hi] using (open_constant (O i v = true) G).symm
51
+ | neg h ih =>
52
+ obtain ⟨Q,D,hQ,hD,hup,hden,ht⟩ := ih
53
+ let E : PrefixPredicate := fun O v s => D O v s ∧ Decides (Q O (left v)) s
54
+ have hE : ArithmeticPrefix E := hD.and (prefix_comp (decides_arith hQ) left_primrec)
55
+ refine ⟨fun O v => Avoid (Q O v),E,avoids_arith hQ,hE,
56
+ fun O v => avoids_upward _,?_,?_⟩
57
+ · intro O v n
58
+ simpa only [E,left,Nat.unpair_pair] using
59
+ dense_and (hden O v n) (decides_dense (Q O v) (hup O v))
60
+ · intro O v G hG
61
+ have hGD : GenericFor (fun n => D O (Nat.pair v n)) G := by
62
+ intro n
63
+ obtain ⟨s,hs,hGs⟩ := hG n
64
+ exact ⟨s,hs.1,hGs⟩
65
+ have hdec : G ∈ OpenSet (Decides (Q O v)) := by
66
+ obtain ⟨s,hs,hGs⟩ := hG 0
67
+ exact ⟨s,by simpa only [left,Nat.unpair_pair] using hs.2,hGs⟩
68
+ exact (not_congr (ht O v G hGD)).trans
69
+ (avoid_truth_of_decides (Q O v) (hup O v) G hdec).symm
70
+ | and h k ih ik =>
71
+ obtain ⟨Q,D,hQ,hD,hQu,hDd,hQt⟩ := ih
72
+ obtain ⟨R,E,hR,hE,hRu,hEd,hRt⟩ := ik
73
+ let F : PrefixPredicate := fun O v s =>
74
+ D O (Nat.pair (left v) (left (right v))) s ∧
75
+ E O (Nat.pair (left v) (right (right v))) s
76
+ have hF : ArithmeticPrefix F :=
77
+ (prefix_comp hD (Primrec₂.natPair.comp left_primrec (left_primrec.comp right_primrec))).and
78
+ (prefix_comp hE (Primrec₂.natPair.comp left_primrec (right_primrec.comp right_primrec)))
79
+ refine ⟨fun O v s => Q O v s ∧ R O v s,F,hQ.and hR,hF,
80
+ fun O v s t hst hs => ⟨hQu O v s t hst hs.1,hRu O v s t hst hs.2⟩,?_,?_⟩
81
+ · intro O v n
82
+ simpa only [F,left,right,Nat.unpair_pair] using
83
+ dense_and (hDd O v (left n)) (hEd O v (right n))
84
+ · intro O v G hG
85
+ have hGD : GenericFor (fun n => D O (Nat.pair v n)) G := by
86
+ intro n
87
+ obtain ⟨s,hs,hGs⟩ := hG (Nat.pair n 0)
88
+ exact ⟨s,by simpa only [left,right,Nat.unpair_pair] using hs.1,hGs⟩
89
+ have hGE : GenericFor (fun n => E O (Nat.pair v n)) G := by
90
+ intro n
91
+ obtain ⟨s,hs,hGs⟩ := hG (Nat.pair 0 n)
92
+ exact ⟨s,by simpa only [left,right,Nat.unpair_pair] using hs.2,hGs⟩
93
+ exact (and_congr (hQt O v G hGD) (hRt O v G hGE)).trans
94
+ (open_and (Q O v) (R O v) (hQu O v) (hRu O v) G).symm
95
+ | ex h ih =>
96
+ obtain ⟨Q,D,hQ,hD,hup,hden,ht⟩ := ih
97
+ let E : PrefixPredicate := fun O v =>
98
+ D O (Nat.pair (Nat.pair (left v) (left (right v))) (right (right v)))
99
+ have hE : ArithmeticPrefix E := prefix_comp hD
100
+ (Primrec₂.natPair.comp
101
+ (Primrec₂.natPair.comp left_primrec (left_primrec.comp right_primrec))
102
+ (right_primrec.comp right_primrec))
103
+ refine ⟨fun O v s => ∃ n, Q O (Nat.pair v n) s,E,prefix_exists hQ,hE,?_,?_,?_⟩
104
+ · rintro O v s t hst ⟨n,hn⟩
105
+ exact ⟨n,hup O _ s t hst hn⟩
106
+ · intro O v n
107
+ simpa only [E,left,right,Nat.unpair_pair] using
108
+ hden O (Nat.pair v (left n)) (right n)
109
+ · intro O v G hG
110
+ have hGD (n : ℕ) : GenericFor (fun k => D O (Nat.pair (Nat.pair v n) k)) G := by
111
+ intro k
112
+ simpa only [E,left,right,Nat.unpair_pair] using hG (Nat.pair n k)
113
+ constructor
114
+ · rintro ⟨n,hn⟩
115
+ obtain ⟨s,hs,hGs⟩ := (ht O _ G (hGD n)).mp hn
116
+ exact ⟨s,⟨n,hs⟩,hGs⟩
117
+ · rintro ⟨s,⟨n,hs⟩,hGs⟩
118
+ exact ⟨n,(ht O _ G (hGD n)).mpr ⟨s,hs,hGs⟩⟩
119
+ | comp f h hf ih =>
120
+ obtain ⟨Q,D,hQ,hD,hup,hden,ht⟩ := ih
121
+ let E : PrefixPredicate := fun O v => D O (Nat.pair (f (left v)) (right v))
122
+ refine ⟨fun O v => Q O (f v),E,prefix_comp hQ hf,
123
+ prefix_comp hD (Primrec₂.natPair.comp (hf.comp left_primrec) right_primrec),
124
+ fun O v => hup O (f v),?_,?_⟩
125
+ · intro O v n
126
+ simpa only [E,left,right,Nat.unpair_pair] using hden O (f v) n
127
+ · intro O v G hG
128
+ apply ht O (f v) G
129
+ simpa only [E,left,right,Nat.unpair_pair] using hG
130
+
131
+ end TuringRigidity.ArithmeticTruthRequirements
132
+
133
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ArithmeticWitnessTree.lean ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticTestApproximation
2
+ import Mathlib.SetTheory.Descriptive.Tree
3
+ import Mathlib.Order.WellFounded
4
+
5
+ namespace OAI
6
+
7
+ namespace TuringRigidity.ArithmeticTree
8
+ open UniformArithmetic
9
+ noncomputable section
10
+ attribute [local instance] Classical.propDecidable
11
+
12
+ abbrev listApprox (s : List ℕ) : Approx := fun i => s[i]?
13
+
14
+ theorem listApprox_append (s t : List ℕ) : Extends (listApprox s) (listApprox (s ++ t)) := by
15
+ intro i a ha
16
+ obtain ⟨hi,_⟩ := List.getElem?_eq_some_iff.mp ha
17
+ simpa only [listApprox,List.getElem?_append_left hi] using ha
18
+
19
+ def initialSegment (f : ℕ → ℕ) (n : ℕ) : List ℕ := List.ofFn (fun i : Fin n => f i.val)
20
+
21
+ @[simp] theorem prefix_length (f : ℕ → ℕ) (n : ℕ) : (initialSegment f n).length = n := by
22
+ simp [initialSegment]
23
+
24
+ theorem prefix_succ (f : ℕ → ℕ) (n : ℕ) : initialSegment f (n+1) = initialSegment f n ++ [f n] := by
25
+ unfold initialSegment
26
+ rw [List.ofFn_succ_last]
27
+ rfl
28
+
29
+ theorem prefix_captures (f : ℕ → ℕ) (n : ℕ) : Captures (listApprox (initialSegment f n)) f n := by
30
+ intro i hi
31
+ simp [listApprox,initialSegment,hi]
32
+
33
+ theorem prefix_extends (f : ℕ → ℕ) (n : ℕ) :
34
+ Extends (listApprox (initialSegment f n)) (fun i => some (f i)) := by
35
+ intro i a ha
36
+ obtain ⟨hi,he⟩ := List.getElem?_eq_some_iff.mp ha
37
+ simp only [prefix_length] at hi
38
+ have hb := prefix_captures f n i hi
39
+ exact hb.symm.trans ha
40
+
41
+ namespace Test
42
+
43
+ def accepts (t : Test) (O : Oracles) (v : ℕ) (s : List ℕ) : Prop :=
44
+ ∀ n < s.length, t.approx O (listApprox s) (Nat.pair v n) ≠ some false
45
+
46
+ def tree (t : Test) (O : Oracles) (v : ℕ) : Descriptive.tree ℕ :=
47
+ ⟨{s | t.accepts O v s},by
48
+ intro s a h n hn he
49
+ exact h n (by simp; omega) (t.rejection_mono O (listApprox_append s [a]) _ he)⟩
50
+
51
+ theorem branch_iff (t : Test) (O : Oracles) (v : ℕ) (f : ℕ → ℕ) :
52
+ (∀ N, initialSegment f N ∈ t.tree O v) ↔ ∀ n, t.eval O f (Nat.pair v n) := by
53
+ constructor
54
+ · intro h n
55
+ obtain ⟨N,hN⟩ := t.approx_complete O f (Nat.pair v n)
56
+ let K := max N (n+1)
57
+ have he := hN (listApprox (initialSegment f K)) ((prefix_captures f K).mono (le_max_left _ _))
58
+ have hn : n < (initialSegment f K).length := by simp [K]
59
+ have hh := h K n hn
60
+ by_contra hp
61
+ exact hh (he.trans (by simp [hp]))
62
+ · intro h N n hn he
63
+ have ha := (t.approx_sound O (prefix_extends f N) _ false he).mp (h n)
64
+ exact Bool.false_ne_true ha
65
+
66
+ def Child (t : Test) (O : Oracles) (v : ℕ) (s r : t.tree O v) : Prop :=
67
+ ∃ a, s.val = r.val ++ [a]
68
+
69
+ private theorem chain_extends (s : ℕ → List ℕ)
70
+ (h : ∀ n, ∃ a, s (n+1) = s n ++ [a]) {i j : ℕ} (hij : i ≤ j) :
71
+ Extends (listApprox (s i)) (listApprox (s j)) := by
72
+ induction j, hij using Nat.le_induction with
73
+ | base => exact fun _ _ h => h
74
+ | succ j hj ih =>
75
+ obtain ⟨a,ha⟩ := h j
76
+ intro k b hb
77
+ rw [ha]
78
+ exact listApprox_append _ _ k b (ih k b hb)
79
+
80
+ private theorem chain_length (s : ℕ → List ℕ)
81
+ (h : ∀ n, ∃ a, s (n+1) = s n ++ [a]) (n : ℕ) : n ≤ (s n).length := by
82
+ induction n with
83
+ | zero => omega
84
+ | succ n ih =>
85
+ obtain ⟨a,ha⟩ := h n
86
+ simp only [ha,List.length_append,List.length_singleton]
87
+ omega
88
+
89
+ private theorem chain_union (s : ℕ → List ℕ)
90
+ (h : ∀ n, ∃ a, s (n+1) = s n ++ [a]) :
91
+ ∃ f : ℕ → ℕ, ∀ n, Captures (listApprox (s n)) f n := by
92
+ have hex : ∀ i, ∃ a, (s (i+1))[i]? = some a := by
93
+ intro i
94
+ have hi : i < (s (i+1)).length := lt_of_lt_of_le (Nat.lt_succ_self _) (chain_length s h _)
95
+ exact ⟨(s (i+1))[i],List.getElem?_eq_some_iff.mpr ⟨hi,rfl⟩⟩
96
+ choose f hf using hex
97
+ refine ⟨f,fun n i hi => ?_⟩
98
+ exact chain_extends s h (Nat.succ_le_of_lt hi) i (f i) (hf i)
99
+
100
+ theorem wellFounded_iff (t : Test) (O : Oracles) (v : ℕ) :
101
+ WellFounded (t.Child O v) ↔ ¬ ∃ f : ℕ → ℕ, ∀ n, t.eval O f (Nat.pair v n) := by
102
+ rw [wellFounded_iff_isEmpty_descending_chain]
103
+ constructor
104
+ · intro hw ⟨f,hf⟩
105
+ let nodes : ℕ → t.tree O v := fun n => ⟨initialSegment f n,(t.branch_iff O v f).mpr hf n⟩
106
+ exact hw.false ⟨nodes,fun n => ⟨f n,prefix_succ f n⟩⟩
107
+ · intro h
108
+ refine ⟨fun ⟨nodes,hn⟩ => ?_⟩
109
+ let s : ℕ → List ℕ := fun n => (nodes n).val
110
+ have hs : ∀ n, ∃ a, s (n+1) = s n ++ [a] := hn
111
+ obtain ⟨f,hf⟩ := chain_union s hs
112
+ apply h
113
+ refine ⟨f,fun n => ?_⟩
114
+ obtain ⟨N,hN⟩ := t.approx_complete O f (Nat.pair v n)
115
+ let K := max N (n+1)
116
+ have he := hN (listApprox (s K)) ((hf K).mono (le_max_left _ _))
117
+ have hnK : n < (s K).length :=
118
+ lt_of_lt_of_le (lt_of_lt_of_le (Nat.lt_succ_self _) (le_max_right _ _)) (chain_length s hs K)
119
+ have hh := (nodes K).property n hnK
120
+ by_contra hp
121
+ exact hh (he.trans (by simp [hp]))
122
+ end Test
123
+
124
+ end
125
+ end TuringRigidity.ArithmeticTree
126
+
127
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/BinaryCut.lean ADDED
@@ -0,0 +1,99 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.BinaryMachine
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.BinarySeries
6
+ open UniformOracle RationalCoding Encodable Filter
7
+
8
+ def approxDecision (z : ℕ × ℕ × ℕ) : Option ℕ :=
9
+ if fracLeft (z.1,z.2.2,2^z.2.1) < fracRight (z.1,z.2.2,2^z.2.1) then some 1
10
+ else if fracRight (z.1,z.2.2+1,2^z.2.1) < fracLeft (z.1,z.2.2+1,2^z.2.1) then some 0
11
+ else none
12
+
13
+ theorem approxDecision_primrec : Primrec approxDecision := by
14
+ have hD : Primrec (fun z : ℕ × ℕ × ℕ => 2^z.2.1) := powTwo_primrec.comp (Primrec.fst.comp Primrec.snd)
15
+ have hlo := Primrec.fst.pair ((Primrec.snd.comp Primrec.snd).pair hD)
16
+ have hhi := Primrec.fst.pair ((Primrec.succ.comp (Primrec.snd.comp Primrec.snd)).pair hD)
17
+ exact Primrec.ite (Primrec.nat_lt.comp (fracLeft_primrec.comp hlo) (fracRight_primrec.comp hlo))
18
+ (Primrec.const (some 1))
19
+ (Primrec.ite (Primrec.nat_lt.comp (fracRight_primrec.comp hhi) (fracLeft_primrec.comp hhi))
20
+ (Primrec.const (some 0)) (Primrec.const none))
21
+
22
+ def approxTrial (B : Oracle) (q n : ℕ) : Option ℕ := approxDecision (q,n,numeral B n)
23
+
24
+ theorem approxTrial_recursive (B : Oracle) :
25
+ Nat.RecursiveIn {oracleFunction B}
26
+ (fun z => Part.some (encode (approxTrial B (Nat.unpair z).1 (Nat.unpair z).2))) := by
27
+ have hq := total_primrec (O := {oracleFunction B}) (Primrec.fst.comp Primrec.unpair)
28
+ have hn := total_primrec (O := {oracleFunction B}) (Primrec.snd.comp Primrec.unpair)
29
+ have hk := total_comp (numeral_recursive B) hn
30
+ have hdec := Primrec.encode.comp (approxDecision_primrec.comp
31
+ ((Primrec.fst.comp Primrec.unpair).pair (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair))))
32
+ exact (total_comp (total_primrec hdec) (total_pair hq (total_pair hn hk))).of_eq
33
+ (fun z => by simp [approxTrial])
34
+
35
+ theorem approxTrial_sound (B : Oracle) (q n a : ℕ) (ha : a ∈ approxTrial B q n) :
36
+ a = if cut (value B) q then 1 else 0 := by
37
+ have hb := bracket B n
38
+ unfold approxTrial approxDecision at ha
39
+ split at ha
40
+ · rename_i h
41
+ have hq := (frac_lt_iff q (numeral B n) (2^n) (by positivity)).mp h
42
+ have hc : cut (value B) q = true := (cut_eq_true _ _).mpr (lt_of_lt_of_le (by simpa using hq) hb.1)
43
+ simpa [hc] using (Option.mem_def.mp ha).symm
44
+ · split at ha
45
+ · rename_i h
46
+ have hq := (lt_frac_iff q (numeral B n+1) (2^n) (by positivity)).mp h
47
+ have hc : cut (value B) q = false := Bool.eq_false_iff.mpr (fun hc => by
48
+ have hh := (cut_eq_true _ _).mp hc
49
+ push_cast at hq
50
+ linarith)
51
+ simpa [hc] using (Option.mem_def.mp ha).symm
52
+ · simp at ha
53
+
54
+ theorem small_width (ε : ℝ) (hε : 0 < ε) : ∃ n : ℕ, (2^n : ℝ)⁻¹ < ε := by
55
+ have ht : Tendsto (fun n : ℕ => (2^n : ℝ)⁻¹) atTop (nhds 0) := by
56
+ simpa only [inv_pow] using
57
+ (tendsto_pow_atTop_nhds_zero_of_abs_lt_one (by norm_num : |(2:ℝ)⁻¹| < 1))
58
+ exact (ht.eventually (eventually_lt_nhds hε)).exists
59
+
60
+ theorem approxTrial_complete (B : Oracle) (hi : Irrational (value B)) (q : ℕ) :
61
+ ∃ n a, a ∈ approxTrial B q n := by
62
+ have hne : (rationalEnumeration q : ℝ) ≠ value B := fun h => hi ⟨_,h⟩
63
+ rcases lt_or_gt_of_ne hne with hq | hq
64
+ · obtain ⟨n,hn⟩ := small_width (value B - rationalEnumeration q) (by linarith)
65
+ have hb := bracket B n
66
+ have hl : (rationalEnumeration q : ℝ) < (numeral B n : ℝ)/(2^n : ℕ) := by
67
+ push_cast
68
+ rw [add_div] at hb
69
+ simp only [one_div] at hb
70
+ linarith
71
+ have hd := (frac_lt_iff q (numeral B n) (2^n) (by positivity)).mpr hl
72
+ exact ⟨n,1,by simp [approxTrial,approxDecision,hd]⟩
73
+ · obtain ⟨n,hn⟩ := small_width (rationalEnumeration q - value B) (by linarith)
74
+ have hb := bracket B n
75
+ have hu : ((numeral B n+1 : ℕ) : ℝ)/(2^n : ℕ) < rationalEnumeration q := by
76
+ push_cast
77
+ rw [add_div]
78
+ simp only [one_div]
79
+ linarith
80
+ have hd := (lt_frac_iff q (numeral B n+1) (2^n) (by positivity)).mpr hu
81
+ have hl : ¬ fracLeft (q,numeral B n,2^n) < fracRight (q,numeral B n,2^n) := by
82
+ intro hh
83
+ have hh' := (frac_lt_iff q (numeral B n) (2^n) (by positivity)).mp hh
84
+ push_cast at hh'
85
+ linarith [hb.1]
86
+ exact ⟨n,0,by simp [approxTrial,approxDecision,hl,hd]⟩
87
+
88
+ theorem cut_reduces (B : Oracle) (hi : Irrational (value B)) : Reduces (cut (value B)) B := by
89
+ apply RecursiveIn.iff_nat.mpr
90
+ exact total_search (approxTrial_recursive B) _ (approxTrial_sound B) (approxTrial_complete B hi)
91
+
92
+ theorem cut_single_program (B : Oracle) (hi : Irrational (value B)) :
93
+ ∃ p : OracleCode, ∀ q, OracleCode.eval (oracleFunction B) p q = oracleFunction (cut (value B)) q := by
94
+ obtain ⟨p,hp⟩ := (OracleCode.turingReducible_iff_exists_code _ _).mp (cut_reduces B hi)
95
+ exact ⟨p,fun q => congrFun hp q⟩
96
+
97
+ end TuringRigidity.BinarySeries
98
+
99
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/BinaryMachine.lean ADDED
@@ -0,0 +1,110 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.BinarySeries
2
+ import OAI.Computability.DegreeRigidity.Computability.RationalCut
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity.BinarySeries
7
+ open UniformOracle RationalCoding Encodable
8
+
9
+ theorem eventually_constant_reduces (B A : Oracle) (b : Bool) (N : ℕ)
10
+ (h : ∀ n, N ≤ n → B n = b) : Reduces B A := by
11
+ let L := (List.range N).map (bit B)
12
+ let d : ℕ := if b then 1 else 0
13
+ have hp : Primrec (fun n => L.getD n d) := (Primrec.list_getD d).comp (Primrec.const L) Primrec.id
14
+ have he (n : ℕ) : L.getD n d = bit B n := by
15
+ by_cases hn : n < N
16
+ · simp [L, List.getD, List.getElem?_map, List.getElem?_range hn]
17
+ · have hb := h n (by omega)
18
+ have hz : (List.range N)[n]? = none := List.getElem?_eq_none (by simp; omega)
19
+ simp [L, List.getD, hz, bit, hb, d]
20
+ apply RecursiveIn.iff_nat.mpr
21
+ exact total_primrec (hp.of_eq he)
22
+
23
+ theorem mixed_of_noncomputable (B : Oracle) (h : ¬ Reduces B (fun _ => false)) : Mixed B := by
24
+ intro N
25
+ constructor
26
+ · by_contra hn
27
+ push Not at hn
28
+ apply h
29
+ exact eventually_constant_reduces B _ false N (fun n hN => Bool.eq_false_iff.mpr (hn n hN))
30
+ · by_contra hn
31
+ push Not at hn
32
+ apply h
33
+ exact eventually_constant_reduces B _ true N (fun n hN => Bool.eq_true_of_not_eq_false (hn n hN))
34
+
35
+ def foldNumeral (L : List ℕ) : ℕ := L.foldl (fun a b => 2*a+b) 0
36
+
37
+ theorem foldNumeral_primrec : Primrec foldNumeral :=
38
+ Primrec.list_foldl Primrec.id (Primrec.const 0)
39
+ ((Primrec.nat_add.comp (Primrec.nat_mul.comp (Primrec.const 2) Primrec.fst) Primrec.snd).comp Primrec.snd).to₂
40
+
41
+ theorem foldNumeral_prefix (B : Oracle) (n : ℕ) :
42
+ foldNumeral (oraclePrefix (bit B) n) = numeral B n := by
43
+ induction n with
44
+ | zero => rfl
45
+ | succ n ih =>
46
+ simpa [foldNumeral, oraclePrefix, List.range_succ, List.foldl_append, numeral] using
47
+ congrArg (fun a => 2*a+bit B n) ih
48
+
49
+ theorem numeral_recursive (B : Oracle) :
50
+ Nat.RecursiveIn {oracleFunction B} (fun n => Part.some (numeral B n)) := by
51
+ have hf := total_comp (total_primrec (foldNumeral_primrec.comp
52
+ (Primrec.option_getD_default.comp Primrec.decode))) (prefix_recursive (bit B))
53
+ exact hf.of_eq (fun n => by simp only [encodek, Option.getD_some, foldNumeral_prefix])
54
+
55
+ theorem powTwo_primrec : Primrec (fun n : ℕ => 2^n) := by
56
+ have hp : Primrec (fun n : ℕ => (List.range n).foldl (fun a _ => 2*a) 1) :=
57
+ Primrec.list_foldl Primrec.list_range (Primrec.const 1)
58
+ ((Primrec.nat_mul.comp (Primrec.const 2) Primrec.fst).comp Primrec.snd).to₂
59
+ apply hp.of_eq
60
+ intro n
61
+ induction n with
62
+ | zero => simp
63
+ | succ n ih =>
64
+ simp only [List.range_succ, List.foldl_append, List.foldl_cons, List.foldl_nil]
65
+ rw [ih, pow_succ, Nat.mul_comm]
66
+
67
+ def fracLeft (z : ℕ × ℕ × ℕ) : ℕ := positiveNumerator z.1 * z.2.2
68
+ def fracRight (z : ℕ × ℕ × ℕ) : ℕ := z.2.1 * denominator z.1 + negativeNumerator z.1 * z.2.2
69
+
70
+ theorem fracLeft_primrec : Primrec fracLeft := Primrec.nat_mul.comp
71
+ (positiveNumerator_primrec.comp Primrec.fst) (Primrec.snd.comp Primrec.snd)
72
+ theorem fracRight_primrec : Primrec fracRight := Primrec.nat_add.comp
73
+ (Primrec.nat_mul.comp (Primrec.fst.comp Primrec.snd) (denominator_primrec.comp Primrec.fst))
74
+ (Primrec.nat_mul.comp (negativeNumerator_primrec.comp Primrec.fst) (Primrec.snd.comp Primrec.snd))
75
+
76
+ theorem frac_lt_iff (q k D : ℕ) (hD : 0 < D) :
77
+ fracLeft (q,k,D) < fracRight (q,k,D) ↔ (rationalEnumeration q : ℝ) < (k : ℝ)/D := by
78
+ rw [signed_query_value, div_lt_div_iff₀ (by exact_mod_cast denominator_pos q) (by exact_mod_cast hD)]
79
+ unfold fracLeft fracRight
80
+ constructor <;> intro h
81
+ · have hh : (positiveNumerator q : ℝ)*D < k*denominator q + negativeNumerator q*D := by exact_mod_cast h
82
+ nlinarith
83
+ · have hh : (positiveNumerator q : ℝ)*D < k*denominator q + negativeNumerator q*D := by nlinarith
84
+ exact_mod_cast hh
85
+
86
+ theorem lt_frac_iff (q k D : ℕ) (hD : 0 < D) :
87
+ fracRight (q,k,D) < fracLeft (q,k,D) ↔ (k : ℝ)/D < (rationalEnumeration q : ℝ) := by
88
+ rw [signed_query_value, div_lt_div_iff₀ (by exact_mod_cast hD) (by exact_mod_cast denominator_pos q)]
89
+ unfold fracLeft fracRight
90
+ constructor <;> intro h
91
+ · have hh : k* (denominator q : ℝ) + negativeNumerator q*D < positiveNumerator q*D := by exact_mod_cast h
92
+ nlinarith
93
+ · have hh : k* (denominator q : ℝ) + negativeNumerator q*D < positiveNumerator q*D := by nlinarith
94
+ exact_mod_cast hh
95
+
96
+ theorem frac_eq_iff (q k D : ℕ) (hD : 0 < D) :
97
+ fracLeft (q,k,D) = fracRight (q,k,D) ↔ (rationalEnumeration q : ℝ) = (k : ℝ)/D := by
98
+ constructor
99
+ · intro he
100
+ apply le_antisymm
101
+ · exact le_of_not_gt (fun h => by have := (lt_frac_iff q k D hD).mpr h; omega)
102
+ · exact le_of_not_gt (fun h => by have := (frac_lt_iff q k D hD).mpr h; omega)
103
+ · intro he
104
+ apply Nat.le_antisymm
105
+ · exact Nat.le_of_not_gt (fun h => by have := (lt_frac_iff q k D hD).mp h; linarith)
106
+ · exact Nat.le_of_not_gt (fun h => by have := (frac_lt_iff q k D hD).mp h; linarith)
107
+
108
+ end TuringRigidity.BinarySeries
109
+
110
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/BinaryRecovery.lean ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.BinaryMachine
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.BinarySeries
6
+ open UniformOracle RationalCoding Encodable
7
+
8
+ def recoverGuard (z : ℕ × ℕ × ℕ × ℕ) : Prop :=
9
+ fracLeft (z.2.2.1,z.2.1,2^(z.1+1)) = fracRight (z.2.2.1,z.2.1,2^(z.1+1)) ∧
10
+ fracLeft (z.2.2.2,z.2.1+1,2^(z.1+1)) = fracRight (z.2.2.2,z.2.1+1,2^(z.1+1))
11
+ instance (z : ℕ × ℕ × ℕ × ℕ) : Decidable (recoverGuard z) := inferInstanceAs (Decidable (_ ∧ _))
12
+
13
+ theorem recoverGuard_primrec : PrimrecPred recoverGuard := by
14
+ have hn : Primrec (fun z : ℕ × ℕ × ℕ × ℕ => 2^(z.1+1)) :=
15
+ powTwo_primrec.comp (Primrec.succ.comp Primrec.fst)
16
+ have hk : Primrec (fun z : ℕ × ℕ × ℕ × ℕ => z.2.1) := Primrec.fst.comp Primrec.snd
17
+ have hi : Primrec (fun z : ℕ × ℕ × ℕ × ℕ => z.2.2.1) := Primrec.fst.comp (Primrec.snd.comp Primrec.snd)
18
+ have hj : Primrec (fun z : ℕ × ℕ × ℕ × ℕ => z.2.2.2) := Primrec.snd.comp (Primrec.snd.comp Primrec.snd)
19
+ exact (Primrec.eq.comp (fracLeft_primrec.comp (hi.pair (hk.pair hn)))
20
+ (fracRight_primrec.comp (hi.pair (hk.pair hn)))).and
21
+ (Primrec.eq.comp (fracLeft_primrec.comp (hj.pair ((Primrec.succ.comp hk).pair hn)))
22
+ (fracRight_primrec.comp (hj.pair ((Primrec.succ.comp hk).pair hn))))
23
+
24
+ def recoverDecision (z : (ℕ × ℕ × ℕ × ℕ) × (ℕ × ℕ)) : Option ℕ :=
25
+ if recoverGuard z.1 ∧ z.2.1=1 ∧ z.2.2=0 then some (z.1.2.1%2) else none
26
+
27
+ theorem recoverDecision_primrec : Primrec recoverDecision :=
28
+ Primrec.ite ((recoverGuard_primrec.comp Primrec.fst).and
29
+ ((Primrec.eq.comp (Primrec.fst.comp Primrec.snd) (Primrec.const 1)).and
30
+ (Primrec.eq.comp (Primrec.snd.comp Primrec.snd) (Primrec.const 0))))
31
+ (Primrec.option_some.comp (Primrec.nat_mod.comp
32
+ (Primrec.fst.comp (Primrec.snd.comp Primrec.fst)) (Primrec.const 2))) (Primrec.const none)
33
+
34
+ noncomputable def recoverTrial (B : Oracle) (n m : ℕ) : Option ℕ :=
35
+ let k := (Nat.unpair m).1
36
+ let i := (Nat.unpair (Nat.unpair m).2).1
37
+ let j := (Nat.unpair (Nat.unpair m).2).2
38
+ recoverDecision ((n,k,i,j),(bit (cut (value B)) i,bit (cut (value B)) j))
39
+
40
+ theorem recoverTrial_recursive (B : Oracle) :
41
+ Nat.RecursiveIn {oracleFunction (cut (value B))}
42
+ (fun z => Part.some (encode (recoverTrial B (Nat.unpair z).1 (Nat.unpair z).2))) := by
43
+ let O : Set (ℕ →. ℕ) := {oracleFunction (cut (value B))}
44
+ have hn := total_primrec (O := O) (Primrec.fst.comp Primrec.unpair)
45
+ have hm := total_primrec (O := O) (Primrec.snd.comp Primrec.unpair)
46
+ have hk := total_comp (total_primrec (Primrec.fst.comp Primrec.unpair)) hm
47
+ have hi := total_comp (total_primrec (Primrec.fst.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))) hm
48
+ have hj := total_comp (total_primrec (Primrec.snd.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))) hm
49
+ have hg : Nat.RecursiveIn O (oracleFunction (cut (value B))) := .oracle _ (Set.mem_singleton _)
50
+ have hmeta := total_pair hn (total_pair hk (total_pair hi hj))
51
+ have hbits := total_pair (total_comp hg hi) (total_comp hg hj)
52
+ have hdecode : Primrec (fun z : ℕ =>
53
+ (((Nat.unpair (Nat.unpair z).1).1,
54
+ (Nat.unpair (Nat.unpair (Nat.unpair z).1).2).1,
55
+ Nat.unpair (Nat.unpair (Nat.unpair (Nat.unpair z).1).2).2),Nat.unpair (Nat.unpair z).2)) := by
56
+ exact (((Primrec.fst.comp Primrec.unpair).pair
57
+ (((Primrec.fst.comp Primrec.unpair).pair (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair))).comp
58
+ (Primrec.snd.comp Primrec.unpair))).comp (Primrec.fst.comp Primrec.unpair)).pair
59
+ (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair))
60
+ exact (total_comp (total_primrec (Primrec.encode.comp (recoverDecision_primrec.comp hdecode)))
61
+ (total_pair hmeta hbits)).of_eq (fun z => by simp [recoverTrial,bit])
62
+
63
+ theorem recoverTrial_sound (B : Oracle) (hB : Mixed B) (n m a : ℕ)
64
+ (ha : a ∈ recoverTrial B n m) : a = bit B n := by
65
+ let k := (Nat.unpair m).1
66
+ let i := (Nat.unpair (Nat.unpair m).2).1
67
+ let j := (Nat.unpair (Nat.unpair m).2).2
68
+ change a ∈ recoverDecision ((n,k,i,j),(bit (cut (value B)) i,bit (cut (value B)) j)) at ha
69
+ unfold recoverDecision at ha
70
+ split at ha
71
+ · rename_i h
72
+ have hai : a=k%2 := by simpa using (Option.mem_def.mp ha).symm
73
+ have hi := (frac_eq_iff i k (2^(n+1)) (by positivity)).mp h.1.1
74
+ have hj := (frac_eq_iff j (k+1) (2^(n+1)) (by positivity)).mp h.1.2
75
+ have hci : cut (value B) i=true := by cases hh : cut (value B) i <;> simp_all [bit]
76
+ have hcj : cut (value B) j=false := by cases hh : cut (value B) j <;> simp_all [bit]
77
+ have hlo := (cut_eq_true _ _).mp hci
78
+ have hup : value B ≤ (rationalEnumeration j : ℝ) := le_of_not_gt (fun hh => by
79
+ have := (cut_eq_true _ _).mpr hh; simp_all)
80
+ rw [hi] at hlo
81
+ rw [hj] at hup
82
+ have hb := strict_bracket B hB (n+1)
83
+ have hD : (0 : ℝ) < (2^(n+1) : ℝ) := by positivity
84
+ have hk1 : (k : ℝ) < numeral B (n+1)+1 := by
85
+ have hh := lt_trans hlo hb.2
86
+ push_cast at hh
87
+ exact (div_lt_div_iff_of_pos_right hD).mp hh
88
+ have hk2 : (numeral B (n+1) : ℝ) < k+1 := by
89
+ have hh := lt_of_lt_of_le hb.1 hup
90
+ push_cast at hh
91
+ exact (div_lt_div_iff_of_pos_right hD).mp hh
92
+ have hk : k = numeral B (n+1) := by
93
+ have h1 : k < numeral B (n+1)+1 := by exact_mod_cast hk1
94
+ have h2 : numeral B (n+1) < k+1 := by exact_mod_cast hk2
95
+ omega
96
+ rw [hai,hk,numeral]
97
+ unfold bit
98
+ split <;> omega
99
+ · simp at ha
100
+
101
+ theorem recoverTrial_complete (B : Oracle) (hB : Mixed B) (n : ℕ) :
102
+ ∃ m a, a ∈ recoverTrial B n m := by
103
+ let k := numeral B (n+1)
104
+ let i := encode ((k : ℚ)/2^(n+1))
105
+ let j := encode (((k+1 : ℕ) : ℚ)/2^(n+1))
106
+ have hi : (rationalEnumeration i : ℝ) = (k : ℝ)/(2^(n+1) : ℕ) := by simp [i,rationalEnumeration]
107
+ have hj : (rationalEnumeration j : ℝ) = ((k+1 : ℕ) : ℝ)/(2^(n+1) : ℕ) := by simp [j,rationalEnumeration]
108
+ have hg : recoverGuard (n,k,i,j) := ⟨(frac_eq_iff _ _ _ (by positivity)).mpr hi,
109
+ (frac_eq_iff _ _ _ (by positivity)).mpr hj⟩
110
+ have hb := strict_bracket B hB (n+1)
111
+ have hci : cut (value B) i=true := (cut_eq_true _ _).mpr (by simpa [hi,k] using hb.1)
112
+ have hcj : cut (value B) j=false := Bool.eq_false_iff.mpr (fun hh => by
113
+ have hh' := (cut_eq_true _ _).mp hh
114
+ rw [hj] at hh'
115
+ push_cast at hh'
116
+ dsimp only [k] at hh'
117
+ linarith [hb.2])
118
+ exact ⟨Nat.pair k (Nat.pair i j),k%2,by simp [recoverTrial,recoverDecision,bit,hci,hcj,hg]⟩
119
+
120
+ theorem set_reduces_cut (B : Oracle) (hB : Mixed B) : Reduces B (cut (value B)) := by
121
+ apply RecursiveIn.iff_nat.mpr
122
+ exact total_search (recoverTrial_recursive B) _ (recoverTrial_sound B hB) (recoverTrial_complete B hB)
123
+
124
+ theorem set_single_program (B : Oracle) (hB : Mixed B) :
125
+ ∃ p : OracleCode, ∀ n, OracleCode.eval (oracleFunction (cut (value B))) p n = oracleFunction B n := by
126
+ obtain ⟨p,hp⟩ := (OracleCode.turingReducible_iff_exists_code _ _).mp (set_reduces_cut B hB)
127
+ exact ⟨p,fun n => congrFun hp n⟩
128
+
129
+ end TuringRigidity.BinarySeries
130
+
131
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/BinarySeries.lean ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.Cuts
2
+ import Mathlib.Analysis.Real.OfDigits
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity.BinarySeries
7
+
8
+ def bit (B : Oracle) (n : ℕ) : ℕ := if B n then 1 else 0
9
+
10
+ def digits (B : Oracle) (n : ℕ) : Fin 2 := ⟨bit B n, by unfold bit; split <;> omega⟩
11
+
12
+ noncomputable def value (B : Oracle) : ℝ := Real.ofDigits (digits B)
13
+
14
+ def numeral (B : Oracle) : ℕ → ℕ
15
+ | 0 => 0
16
+ | n+1 => 2 * numeral B n + bit B n
17
+
18
+ theorem numeral_sum (B : Oracle) (n : ℕ) :
19
+ (∑ i ∈ Finset.range n, Real.ofDigitsTerm (digits B) i) =
20
+ (numeral B n : ℝ) / 2^n := by
21
+ induction n with
22
+ | zero => simp [numeral]
23
+ | succ n ih =>
24
+ rw [Finset.sum_range_succ, ih]
25
+ simp only [numeral, Nat.cast_add, Nat.cast_mul, Nat.cast_ofNat,
26
+ Real.ofDigitsTerm, digits, pow_succ]
27
+ field_simp
28
+
29
+ theorem split_value (B : Oracle) (n : ℕ) :
30
+ value B = (numeral B n : ℝ)/2^n + (2^n : ℝ)⁻¹ * value (fun i => B (i+n)) := by
31
+ exact (Real.ofDigits_eq_sum_add_ofDigits (digits B) n).trans (by rw [numeral_sum]; rfl)
32
+
33
+ theorem nonneg (B : Oracle) : 0 ≤ value B := Real.ofDigits_nonneg _
34
+ theorem le_one (B : Oracle) : value B ≤ 1 := Real.ofDigits_le_one _
35
+
36
+ theorem positive (B : Oracle) (h : ∃ n, B n = true) : 0 < value B := by
37
+ obtain ⟨n, hn⟩ := h
38
+ have ht : 0 < Real.ofDigitsTerm (digits B) n := by
39
+ simp [Real.ofDigitsTerm, digits, bit, hn]
40
+ exact lt_of_lt_of_le ht (Summable.le_tsum Real.summable_ofDigitsTerm n
41
+ (fun _ _ => Real.ofDigitsTerm_nonneg))
42
+
43
+ theorem complement (B : Oracle) : value B + value (fun n => !(B n)) = 1 := by
44
+ rw [value, value, Real.ofDigits, Real.ofDigits, ← Summable.tsum_add
45
+ Real.summable_ofDigitsTerm Real.summable_ofDigitsTerm]
46
+ have he : (fun n => Real.ofDigitsTerm (digits B) n +
47
+ Real.ofDigitsTerm (digits (fun n => !(B n))) n) =
48
+ Real.ofDigitsTerm (fun _ => (⟨1, by omega⟩ : Fin 2)) := by
49
+ funext n
50
+ cases h : B n <;> simp [Real.ofDigitsTerm, digits, bit, h]
51
+ rw [he]
52
+ exact Real.ofDigits_const_last_eq_one' (by omega : 1 < 2)
53
+
54
+ theorem lt_one (B : Oracle) (h : ∃ n, B n = false) : value B < 1 := by
55
+ have hp := positive (fun n => !(B n)) (by obtain ⟨n, hn⟩ := h; exact ⟨n, by simp [hn]⟩)
56
+ have hc := complement B
57
+ linarith
58
+
59
+ def Mixed (B : Oracle) : Prop := ∀ N, (∃ n, N ≤ n ∧ B n = true) ∧ (∃ n, N ≤ n ∧ B n = false)
60
+
61
+ theorem strict_bracket (B : Oracle) (h : Mixed B) (n : ℕ) :
62
+ (numeral B n : ℝ)/2^n < value B ∧ value B < (numeral B n + 1 : ℝ)/2^n := by
63
+ have hp : 0 < value (fun i => B (i+n)) := by
64
+ apply positive
65
+ obtain ⟨k,hk,hb⟩ := (h n).1
66
+ exact ⟨k-n, by simpa [Nat.sub_add_cancel hk] using hb⟩
67
+ have hu : value (fun i => B (i+n)) < 1 := by
68
+ apply lt_one
69
+ obtain ⟨k,hk,hb⟩ := (h n).2
70
+ exact ⟨k-n, by simpa [Nat.sub_add_cancel hk] using hb⟩
71
+ rw [split_value B n]
72
+ have hd : (0 : ℝ) < (2^n : ℝ)⁻¹ := by positivity
73
+ constructor
74
+ · nlinarith
75
+ · rw [add_div]
76
+ simp only [one_div]
77
+ nlinarith
78
+
79
+ theorem bracket (B : Oracle) (n : ℕ) :
80
+ (numeral B n : ℝ)/2^n ≤ value B ∧ value B ≤ (numeral B n + 1 : ℝ)/2^n := by
81
+ rw [split_value B n]
82
+ have hp := nonneg (fun i => B (i+n))
83
+ have hu := le_one (fun i => B (i+n))
84
+ have hd : (0 : ℝ) < (2^n : ℝ)⁻¹ := by positivity
85
+ constructor
86
+ · nlinarith
87
+ · rw [add_div]; simp only [one_div]; nlinarith
88
+
89
+ end TuringRigidity.BinarySeries
90
+
91
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/BranchFrequency.lean ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.BranchRecovery
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity
6
+
7
+ namespace UniformOracle
8
+
9
+ def runningSum (f : ℕ → ℕ) : ℕ → ℕ
10
+ | 0 => 0
11
+ | n+1 => runningSum f n + f n
12
+
13
+ theorem runningSum_recursive {O : Set (ℕ →. ℕ)} {f : ℕ → ℕ}
14
+ (hf : Nat.RecursiveIn O (fun n => Part.some (f n))) :
15
+ Nat.RecursiveIn O (fun n => Part.some (runningSum f n)) := by
16
+ have hy := total_primrec (O := O) (Primrec.fst.comp (Primrec.unpair.comp
17
+ (Primrec.snd.comp Primrec.unpair)))
18
+ have hi := total_primrec (O := O) (Primrec.snd.comp (Primrec.unpair.comp
19
+ (Primrec.snd.comp Primrec.unpair)))
20
+ have hs := total_comp (total_primrec (Primrec.nat_add.comp
21
+ (Primrec.fst.comp Primrec.unpair) (Primrec.snd.comp Primrec.unpair)))
22
+ (total_pair hi (total_comp hf hy))
23
+ have hp := Nat.RecursiveIn.prec (total_primrec (Primrec.const 0)) hs
24
+ have hh := Nat.RecursiveIn.comp hp
25
+ (total_pair (total_primrec (Primrec.const 0)) (total_primrec Primrec.id))
26
+ apply hh.of_eq
27
+ intro n
28
+ change (Part.some (Nat.pair 0 n)).bind _ = _
29
+ rw [Part.bind_some]
30
+ simp only [Nat.unpair_pair]
31
+ induction n with
32
+ | zero => rfl
33
+ | succ n ih =>
34
+ simp only [ih]
35
+ change (Part.some (runningSum f n)).bind _ = _
36
+ rw [Part.bind_some]
37
+ rfl
38
+ end UniformOracle
39
+
40
+ namespace RecoveryData
41
+ variable {F : ℝ → Oracle} {t u v : ℝ}
42
+
43
+ def count (d : RecoveryData F t u v) : ℕ → ℕ :=
44
+ UniformOracle.runningSum (fun n => if d.branchOracle n then 1 else 0)
45
+
46
+ theorem count_eq_sum (d : RecoveryData F t u v) (n : ℕ) :
47
+ (d.count n : ℝ) = ∑ k ∈ Finset.range n, branch d.test (d.delta : ℝ) t k := by
48
+ induction n with
49
+ | zero => simp [count,UniformOracle.runningSum]
50
+ | succ n ih =>
51
+ simp only [count,UniformOracle.runningSum,Finset.sum_range_succ,Nat.cast_add]
52
+ rw [show (UniformOracle.runningSum (fun n => if d.branchOracle n then 1 else 0) n : ℝ) =
53
+ ∑ k ∈ Finset.range n, branch d.test (d.delta : ℝ) t k from ih]
54
+ congr 1
55
+ cases hb : d.branchOracle n <;> simp [branch,choiceBit,branchOracle] at hb ⊢ <;> simp [hb]
56
+
57
+ theorem count_recursive (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1) :
58
+ Nat.RecursiveIn {oracleFunction (fourTuple F t u v d.delta)}
59
+ (fun n => Part.some (d.count n)) := by
60
+ exact UniformOracle.runningSum_recursive (RecursiveIn.iff_nat.mp (d.branch_reduces ht0 ht1))
61
+
62
+ theorem count_frequency_bound (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1)
63
+ (n : ℕ) (hn : 0 < n) :
64
+ |t - (d.count n : ℝ)/(n : ℝ)| < 1/((n : ℝ)*(d.delta : ℝ)) := by
65
+ rw [count_eq_sum]
66
+ exact d.frequency_bound ht0 ht1 n hn
67
+
68
+ end RecoveryData
69
+ end TuringRigidity
70
+
71
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/BranchMachine.lean ADDED
@@ -0,0 +1,143 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Effective.PartialComputability
2
+ import OAI.Computability.DegreeRigidity.SetModels.ParametricEval
3
+ import OAI.Computability.DegreeRigidity.Effective.FiniteApproximation
4
+
5
+ namespace OAI
6
+
7
+ namespace TuringRigidity
8
+ open Computable
9
+
10
+ def partialJoin (f g : ℕ →. ℕ) (k : ℕ) : Part ℕ :=
11
+ if k.bodd then g (k/2) else f (k/2)
12
+
13
+ namespace BranchMachine
14
+
15
+ def initial (g : ℕ →. ℕ) (k : ℕ) : Part ℕ := g (8*k)
16
+ def anchor (g : ℕ →. ℕ) (k : ℕ) : Part ℕ := g (8*k+4)
17
+ def increment (g : ℕ →. ℕ) (h b k : ℕ) : Part ℕ :=
18
+ g (if b = h then 2*k+1 else 4*k+2)
19
+
20
+ def step (p q : OracleCode) (j h : ℕ) (g old : ℕ →. ℕ) (k : ℕ) : Part ℕ :=
21
+ old j >>= fun b =>
22
+ OracleCode.eval
23
+ (partialJoin (OracleCode.eval (partialJoin old (increment g h b)) p) (anchor g)) q k
24
+
25
+ def stage (p q : OracleCode) (j h : ℕ) (g : ℕ →. ℕ) : ℕ → ℕ →. ℕ
26
+ | 0 => initial g
27
+ | n+1 => step p q j h g (stage p q j h g n)
28
+
29
+ theorem partialJoin_approximates {f g : ℕ →. ℕ} {fs gs : ℕ → ℕ →. ℕ}
30
+ (hf : ∀ k, Approximates (f k) (fun m => fs m k))
31
+ (hg : ∀ k, Approximates (g k) (fun m => gs m k)) (k : ℕ) :
32
+ Approximates (partialJoin f g k) (fun m => partialJoin (fs m) (gs m) k) := by
33
+ simp only [partialJoin]
34
+ split
35
+ · exact hg _
36
+ · exact hf _
37
+
38
+ theorem stage_approximates (p q : OracleCode) (j h : ℕ)
39
+ {g : ℕ →. ℕ} {gs : ℕ → ℕ →. ℕ}
40
+ (hg : ∀ k, Approximates (g k) (fun m => gs m k)) :
41
+ ∀ n k, Approximates (stage p q j h g n k)
42
+ (fun m => stage p q j h (gs m) n k) := by
43
+ intro n
44
+ induction n with
45
+ | zero => intro k; exact hg _
46
+ | succ n ih =>
47
+ intro k
48
+ apply (ih j).bind
49
+ intro b
50
+ apply OracleCode.eval_approximates _ q k
51
+ intro x
52
+ apply partialJoin_approximates
53
+ · exact OracleCode.eval_approximates
54
+ (fun x => partialJoin_approximates ih (fun k => hg _) x) p
55
+ · intro x; exact hg _
56
+
57
+ variable {α : Type*} [Primcodable α]
58
+
59
+ theorem partialJoin_partrec {f g : α → ℕ →. ℕ} (hf : Partrec₂ f) (hg : Partrec₂ g) :
60
+ Partrec₂ (fun a k => partialJoin (f a) (g a) k) := by
61
+ apply partrec_cond (Computable.nat_bodd.comp snd)
62
+ · exact hg.comp fst ((Primrec.nat_div.comp Primrec.id (Primrec.const 2)).to_comp.comp snd)
63
+ · exact hf.comp fst ((Primrec.nat_div.comp Primrec.id (Primrec.const 2)).to_comp.comp snd)
64
+
65
+ theorem increment_index_computable (h : ℕ) :
66
+ Computable₂ (fun b k : ℕ => if b = h then 2*k+1 else 4*k+2) := by
67
+ apply (Computable.cond ((Primrec.beq.comp Primrec.fst (Primrec.const h)).to_comp)
68
+ ((Primrec.nat_add.comp (Primrec.nat_mul.comp (Primrec.const 2) Primrec.snd)
69
+ (Primrec.const 1)).to_comp)
70
+ ((Primrec.nat_add.comp (Primrec.nat_mul.comp (Primrec.const 4) Primrec.snd)
71
+ (Primrec.const 2)).to_comp)).of_eq
72
+ intro z
73
+ by_cases hh : z.1 = h
74
+ · simp [hh]
75
+ · have he : (z.1 == h) = false := Bool.eq_false_iff.mpr (fun he => hh (beq_iff_eq.mp he))
76
+ simp [hh,he]
77
+
78
+ theorem step_partrec (p q : OracleCode) (j h : ℕ)
79
+ {g old : α → ℕ →. ℕ} (hg : Partrec₂ g) (ho : Partrec₂ old) :
80
+ Partrec₂ (fun a k => step p q j h (g a) (old a) k) := by
81
+ change Partrec (fun z : α × ℕ => (old z.1 j).bind _)
82
+ apply Partrec.bind (ho.comp fst (Computable.const j))
83
+ let β := (α × ℕ) × ℕ
84
+ have hleft : Partrec₂ (fun z : β => old z.1.1) :=
85
+ ho.comp (fst.comp (fst.comp fst)) snd
86
+ have hinc : Partrec₂ (fun z : β => increment (g z.1.1) h z.2) :=
87
+ hg.comp (fst.comp (fst.comp fst))
88
+ ((increment_index_computable h).comp (snd.comp fst) snd)
89
+ have hforward := OracleCode.eval_partrec (partialJoin_partrec hleft hinc) p
90
+ have hanchor : Partrec₂ (fun z : β => anchor (g z.1.1)) :=
91
+ hg.comp (fst.comp (fst.comp fst))
92
+ ((Primrec.nat_add.comp (Primrec.nat_mul.comp (Primrec.const 8) Primrec.snd)
93
+ (Primrec.const 4)).to_comp)
94
+ exact (OracleCode.eval_partrec (partialJoin_partrec hforward hanchor) q).comp
95
+ Computable.id (snd.comp fst)
96
+
97
+ def lookup (L : List ℕ) (k : ℕ) : Part ℕ := (L[k]? : Part ℕ)
98
+
99
+ theorem lookup_partrec : Partrec₂ lookup :=
100
+ Computable.ofOption Primrec.list_getElem?.to_comp
101
+
102
+ theorem stage_finite_partrec (p q : OracleCode) (j h : ℕ) :
103
+ Partrec (fun z : List ℕ × ℕ × ℕ => stage p q j h (lookup z.1) z.2.1 z.2.2) := by
104
+ let α := List ℕ × ℕ × ℕ
105
+ let body (c : Nat.Partrec.Code) (z : α) : Part ℕ :=
106
+ if z.2.1 == 0 then initial (lookup z.1) z.2.2 else
107
+ step p q j h (lookup z.1)
108
+ (fun k => c.eval (Encodable.encode (z.1, z.2.1-1, k))) z.2.2
109
+ have hb : Partrec₂ body := by
110
+ apply partrec_cond ((Primrec.beq.comp
111
+ (Primrec.fst.comp (Primrec.snd.comp Primrec.snd)) (Primrec.const 0)).to_comp)
112
+ · exact lookup_partrec.comp (fst.comp snd)
113
+ ((Primrec.nat_mul.comp (Primrec.const 8)
114
+ (Primrec.snd.comp (Primrec.snd.comp Primrec.snd))).to_comp)
115
+ · have hg : Partrec₂ (fun z : Nat.Partrec.Code × α => lookup z.2.1) :=
116
+ lookup_partrec.comp (fst.comp (snd.comp fst)) snd
117
+ have ho : Partrec₂ (fun z : Nat.Partrec.Code × α =>
118
+ fun k => z.1.eval (Encodable.encode (z.2.1,z.2.2.1-1,k))) :=
119
+ Nat.Partrec.Code.eval_part.comp (fst.comp fst)
120
+ ((Computable.encode (α := List ℕ × ℕ × ℕ)).comp ((fst.comp (snd.comp fst)).pair
121
+ ((Computable.pred.comp (fst.comp (snd.comp (snd.comp fst)))).pair snd)))
122
+ exact (step_partrec p q j h hg ho).comp Computable.id (snd.comp (snd.comp snd))
123
+ obtain ⟨c,hc⟩ := partrec_fixed_point hb
124
+ have heq : ∀ n L k, c.eval (Encodable.encode (L,n,k)) = stage p q j h (lookup L) n k := by
125
+ intro n
126
+ induction n with
127
+ | zero => intro L k; rw [hc]; rfl
128
+ | succ n ih =>
129
+ intro L k
130
+ rw [hc]
131
+ have hn0 : (n+1 == 0) = false := rfl
132
+ simp only [body, hn0,
133
+ Bool.false_eq_true, ↓reduceIte, Nat.add_sub_cancel, stage]
134
+ congr 1
135
+ funext i
136
+ exact ih L i
137
+ exact (Nat.Partrec.Code.eval_part.comp (Computable.const c) Computable.encode).of_eq
138
+ (fun z => heq z.2.1 z.1 z.2.2)
139
+
140
+ end BranchMachine
141
+ end TuringRigidity
142
+
143
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/BranchRecovery.lean ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Effective.UniformOracle
2
+ import OAI.Computability.DegreeRigidity.Computability.RecoverySetup
3
+ import OAI.Computability.DegreeRigidity.Representation.Assembly
4
+
5
+ namespace OAI
6
+
7
+ namespace TuringRigidity
8
+
9
+ @[simp] theorem partialJoin_oracle (A B : Oracle) :
10
+ partialJoin (oracleFunction A) (oracleFunction B) = oracleFunction (join A B) := by
11
+ funext k
12
+ cases hk : k.bodd <;> simp [partialJoin, oracleFunction, join, hk]
13
+
14
+ namespace RecoveryData
15
+ variable {F : ℝ → Oracle} {t u v : ℝ}
16
+
17
+ def highBit (d : RecoveryData F t u v) : ℕ := if F (u+d.hi) d.bit then 1 else 0
18
+
19
+ def branchOracle (d : RecoveryData F t u v) : Oracle :=
20
+ fun n => d.test (state d.test (d.delta : ℝ) t n)
21
+
22
+ private theorem tuple_initial (d : RecoveryData F t u v) :
23
+ BranchMachine.initial (oracleFunction (fourTuple F t u v d.delta)) = oracleFunction (F u) := by
24
+ funext k
25
+ change oracleFunction (fourTuple F t u v d.delta) (8*k) = _
26
+ rw [show 8*k = 2*(2*(2*k)) by omega]
27
+ simp [oracleFunction, fourTuple]
28
+
29
+ private theorem tuple_anchor (d : RecoveryData F t u v) :
30
+ BranchMachine.anchor (oracleFunction (fourTuple F t u v d.delta)) = oracleFunction (F (u-v)) := by
31
+ funext k
32
+ change oracleFunction (fourTuple F t u v d.delta) (8*k+4) = _
33
+ rw [show 8*k+4 = 2*(2*(2*k+1)) by omega]
34
+ simp [oracleFunction, fourTuple]
35
+
36
+ private theorem tuple_increment (d : RecoveryData F t u v) (s : ℝ) :
37
+ BranchMachine.increment (oracleFunction (fourTuple F t u v d.delta)) d.highBit
38
+ (if F (u+s) d.bit then 1 else 0) =
39
+ oracleFunction (F (v-u+(d.delta : ℝ)*(t-choiceBit d.test s))) := by
40
+ funext k
41
+ have h3 : oracleFunction (fourTuple F t u v d.delta) (4*k+2) =
42
+ oracleFunction (F (v-u+(d.delta : ℝ)*t)) k := by
43
+ rw [show 4*k+2 = 2*(2*k+1) by omega]
44
+ simp [oracleFunction, fourTuple]
45
+ have h4 : oracleFunction (fourTuple F t u v d.delta) (2*k+1) =
46
+ oracleFunction (F (v-u+(d.delta : ℝ)*(t-1))) k := by
47
+ simp [oracleFunction, fourTuple]
48
+ cases hb : F (u+s) d.bit <;> cases hh : F (u+d.hi) d.bit <;>
49
+ simp [BranchMachine.increment, highBit, choiceBit, test, hb, hh, h3, h4]
50
+
51
+ private theorem increment_span (d : RecoveryData F t u v) (s : ℝ) :
52
+ (d.delta : ℝ)*(t-choiceBit d.test s) ∈ rationalSpan t := by
53
+ cases hb : d.test s
54
+ · exact ⟨0,d.delta,by simp [choiceBit,hb]⟩
55
+ · refine ⟨-d.delta,d.delta,?_⟩
56
+ simp only [choiceBit,hb,↓reduceIte,Rat.cast_neg]
57
+ ring
58
+
59
+ private theorem increment_abs (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1)
60
+ (s : ℝ) : |(d.delta : ℝ)*(t-choiceBit d.test s)| < d.radius := by
61
+ have hd : (0 : ℝ) < d.delta := by exact_mod_cast d.delta_pos
62
+ have hδ := d.delta_lt
63
+ apply abs_lt.mpr
64
+ cases hb : d.test s <;> simp only [choiceBit,hb,Bool.false_eq_true,↓reduceIte,sub_zero] <;>
65
+ constructor <;> nlinarith
66
+
67
+ theorem stage_correct (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1) :
68
+ ∀ n, BranchMachine.stage (codeEnumeration d.forward) (codeEnumeration d.backward)
69
+ d.bit d.highBit (oracleFunction (fourTuple F t u v d.delta)) n =
70
+ oracleFunction (F (u+state d.test (d.delta : ℝ) t n)) := by
71
+ intro n
72
+ induction n with
73
+ | zero =>
74
+ funext input
75
+ simpa [BranchMachine.stage,state] using congrFun (tuple_initial d) input
76
+ | succ n ih =>
77
+ let s := state d.test (d.delta : ℝ) t n
78
+ let a := (d.delta : ℝ)*(t-choiceBit d.test s)
79
+ have hsa : s+a = state d.test (d.delta : ℝ) t (n+1) := rfl
80
+ have hp := d.forward_correct s (state_mem_rationalSpan d.test d.delta t n)
81
+ a (increment_span d s) (d.abs_state_lt ht0 ht1 n) (increment_abs d ht0 ht1 s)
82
+ have hq := d.backward_correct (s+a) (by rw [hsa]; exact state_mem_rationalSpan _ _ _ _)
83
+ (by rw [hsa]; exact d.abs_state_lt ht0 ht1 (n+1))
84
+ funext k
85
+ simp only [BranchMachine.stage,BranchMachine.step,ih,oracleFunction]
86
+ change (Part.some _).bind _ = _
87
+ rw [Part.bind_some]
88
+ change OracleCode.eval
89
+ (partialJoin (OracleCode.eval
90
+ (partialJoin (oracleFunction (F (u+s)))
91
+ (BranchMachine.increment (oracleFunction (fourTuple F t u v d.delta)) d.highBit
92
+ (if F (u+s) d.bit then 1 else 0))) (codeEnumeration d.forward))
93
+ (BranchMachine.anchor (oracleFunction (fourTuple F t u v d.delta))))
94
+ (codeEnumeration d.backward) k = _
95
+ rw [tuple_increment,tuple_anchor,partialJoin_oracle,hp]
96
+ rw [show v+s+a = v+(s+a) by ring,partialJoin_oracle,hq]
97
+ rfl
98
+
99
+ theorem stage_single_program (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1) :
100
+ ∃ c : OracleCode, ∀ n k,
101
+ OracleCode.eval (oracleFunction (fourTuple F t u v d.delta)) c (Nat.pair n k) =
102
+ oracleFunction (F (u+state d.test (d.delta : ℝ) t n)) k := by
103
+ let T := fourTuple F t u v d.delta
104
+ let g : ℕ → ℕ := fun k => if T k then 1 else 0
105
+ let f : ℕ → ℕ := fun z => if F (u+state d.test (d.delta : ℝ) t (Nat.unpair z).1)
106
+ (Nat.unpair z).2 then 1 else 0
107
+ have hg : (fun x => Part.some (g x)) = oracleFunction (fourTuple F t u v d.delta) := rfl
108
+ have hf := UniformOracle.stage_recursive (codeEnumeration d.forward) (codeEnumeration d.backward)
109
+ d.bit d.highBit g f (by
110
+ intro n k
111
+ rw [hg]
112
+ have hs := congrFun (d.stage_correct ht0 ht1 n) k
113
+ apply hs.trans
114
+ simp only [f,Nat.unpair_pair]
115
+ rfl)
116
+ obtain ⟨c,hc⟩ := OracleCode.exists_code hf
117
+ rw [hg] at hc
118
+ refine ⟨c,fun n k => (congrFun hc (Nat.pair n k)).trans ?_⟩
119
+ simp only [f,Nat.unpair_pair]
120
+ rfl
121
+
122
+ theorem branch_reduces (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1) :
123
+ Reduces d.branchOracle (fourTuple F t u v d.delta) := by
124
+ obtain ⟨c,hc⟩ := d.stage_single_program ht0 ht1
125
+ have he := OracleCode.eval_recursiveIn (oracleFunction (fourTuple F t u v d.delta)) c
126
+ have hp := UniformOracle.total_primrec (O := {oracleFunction (fourTuple F t u v d.delta)})
127
+ (Primrec₂.natPair.comp Primrec.id (Primrec.const d.bit))
128
+ have hbits : Nat.RecursiveIn {oracleFunction (fourTuple F t u v d.delta)}
129
+ (fun input => oracleFunction (F (u+state d.test (d.delta : ℝ) t input)) d.bit) :=
130
+ (Nat.RecursiveIn.comp he hp).of_eq (fun n => by
131
+ change (Part.some (Nat.pair n d.bit)).bind
132
+ (fun input => OracleCode.eval (oracleFunction (fourTuple F t u v d.delta)) c input) = _
133
+ rw [Part.bind_some,hc])
134
+ have hcmp : Primrec (fun b : ℕ => if b = d.highBit then 1 else 0) :=
135
+ Primrec.ite (Primrec.eq.comp Primrec.id (Primrec.const d.highBit))
136
+ (Primrec.const 1) (Primrec.const 0)
137
+ apply RecursiveIn.iff_nat.mpr
138
+ apply (Nat.RecursiveIn.comp (UniformOracle.total_primrec hcmp) hbits).of_eq
139
+ intro n
140
+ simp only [oracleFunction]
141
+ change (Part.some _).bind _ = _
142
+ rw [Part.bind_some]
143
+ cases hb : F (u+state d.test (d.delta : ℝ) t n) d.bit <;>
144
+ cases hh : F (u+d.hi) d.bit <;>
145
+ simp [branchOracle,test,highBit,hb,hh]
146
+
147
+ theorem branch_single_program (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1) :
148
+ ∃ c : OracleCode,
149
+ OracleCode.eval (oracleFunction (fourTuple F t u v d.delta)) c =
150
+ oracleFunction d.branchOracle :=
151
+ (OracleCode.turingReducible_iff_exists_code _ _).mp (d.branch_reduces ht0 ht1)
152
+
153
+ end RecoveryData
154
+ end TuringRigidity
155
+
156
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/CutAddition.lean ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.OrdinalCodes.SumComparison
2
+ import OAI.Computability.DegreeRigidity.Computability.Joins
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity
7
+ namespace CutAddition
8
+ open RationalCoding UniformOracle
9
+
10
+ def decision (z : ℕ × (ℕ × ℕ) × (ℕ × ℕ)) : Option ℕ :=
11
+ if z.2.2.1=1 ∧ z.2.2.2=1 ∧ sumLeft (z.1,z.2.1.1,z.2.1.2)<sumRight (z.1,z.2.1.1,z.2.1.2)
12
+ then some 1 else
13
+ if z.2.2.1=0 ∧ z.2.2.2=0 ∧ sumRight (z.1,z.2.1.1,z.2.1.2)<sumLeft (z.1,z.2.1.1,z.2.1.2)
14
+ then some 0 else none
15
+
16
+ theorem decision_primrec : Primrec decision := by
17
+ let hargs := Primrec.fst.pair (Primrec.fst.comp Primrec.snd)
18
+ (α := ℕ × (ℕ × ℕ) × (ℕ × ℕ))
19
+ let hfirst := Primrec.fst.comp (Primrec.snd.comp Primrec.snd)
20
+ (α := ℕ × (ℕ × ℕ) × (ℕ × ℕ))
21
+ let hsecond := Primrec.snd.comp (Primrec.snd.comp Primrec.snd)
22
+ (α := ℕ × (ℕ × ℕ) × (ℕ × ℕ))
23
+ exact Primrec.ite ((Primrec.eq.comp hfirst (Primrec.const 1)).and
24
+ ((Primrec.eq.comp hsecond (Primrec.const 1)).and
25
+ (Primrec.nat_lt.comp (sumLeft_primrec.comp hargs) (sumRight_primrec.comp hargs))))
26
+ (Primrec.const (some 1))
27
+ (Primrec.ite ((Primrec.eq.comp hfirst (Primrec.const 0)).and
28
+ ((Primrec.eq.comp hsecond (Primrec.const 0)).and
29
+ (Primrec.nat_lt.comp (sumRight_primrec.comp hargs) (sumLeft_primrec.comp hargs))))
30
+ (Primrec.const (some 0)) (Primrec.const none))
31
+
32
+ noncomputable def trial (x y : ℝ) (n m : ℕ) : Option ℕ :=
33
+ decision (n,Nat.unpair m,
34
+ (if cut x (Nat.unpair m).1 then 1 else 0,if cut y (Nat.unpair m).2 then 1 else 0))
35
+
36
+ theorem trial_recursive (x y : ℝ) :
37
+ Nat.RecursiveIn {oracleFunction (join (cut x) (cut y))}
38
+ (fun z => Part.some (Encodable.encode (trial x y (Nat.unpair z).1 (Nat.unpair z).2))) := by
39
+ let O : Set (ℕ →. ℕ) := {oracleFunction (join (cut x) (cut y))}
40
+ have hq := total_primrec (O := O) (Primrec.fst.comp Primrec.unpair)
41
+ have hi := total_primrec (O := O) (Primrec.fst.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))
42
+ have hj := total_primrec (O := O) (Primrec.snd.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))
43
+ have hg : Nat.RecursiveIn O (oracleFunction (join (cut x) (cut y))) := .oracle _ (Set.mem_singleton _)
44
+ have hbi := total_comp hg (total_comp
45
+ (total_primrec (Primrec.nat_mul.comp (Primrec.const 2) Primrec.id)) hi)
46
+ have hbj := total_comp hg (total_comp
47
+ (total_primrec (Primrec.nat_add.comp (Primrec.nat_mul.comp (Primrec.const 2) Primrec.id)
48
+ (Primrec.const 1))) hj)
49
+ have hdec : Primrec (fun z : ℕ => Encodable.encode (decision
50
+ ((Nat.unpair z).1,Nat.unpair (Nat.unpair (Nat.unpair z).2).1,
51
+ Nat.unpair (Nat.unpair (Nat.unpair z).2).2))) :=
52
+ Primrec.encode.comp (decision_primrec.comp
53
+ ((Primrec.fst.comp Primrec.unpair).pair
54
+ ((Primrec.unpair.comp (Primrec.fst.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))).pair
55
+ (Primrec.unpair.comp (Primrec.snd.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))))))
56
+ exact (total_comp (total_primrec hdec)
57
+ (total_pair hq (total_pair (total_pair hi hj) (total_pair hbi hbj)))).of_eq
58
+ (fun z => by simp [trial])
59
+
60
+ private theorem bit_one (b : Bool) (h : (if b then (1 : ℕ) else 0)=1) : b=true := by
61
+ cases b <;> simp_all
62
+ private theorem bit_zero (b : Bool) (h : (if b then (1 : ℕ) else 0)=0) : b=false := by
63
+ cases b <;> simp_all
64
+
65
+ theorem trial_sound (x y : ℝ) (n m r : ℕ) (hr : r ∈ trial x y n m) :
66
+ r = if cut (x+y) n then 1 else 0 := by
67
+ let i := (Nat.unpair m).1
68
+ let j := (Nat.unpair m).2
69
+ change r ∈ decision (n,(i,j),(if cut x i then 1 else 0,if cut y j then 1 else 0)) at hr
70
+ generalize hbi : (if cut x i then (1 : ℕ) else 0) = bi at hr
71
+ generalize hbj : (if cut y j then (1 : ℕ) else 0) = bj at hr
72
+ unfold decision at hr
73
+ split at hr
74
+ · rename_i h
75
+ have hr' : r=1 := by symm; simpa using hr
76
+ subst r
77
+ have hx := (cut_eq_true x i).mp (bit_one _ (hbi.trans h.1))
78
+ have hy := (cut_eq_true y j).mp (bit_one _ (hbj.trans h.2.1))
79
+ have hq := (lt_sum_iff n i j).mp h.2.2
80
+ have hc : cut (x+y) n=true := (cut_eq_true _ _).mpr (by linarith)
81
+ simp [hc]
82
+ · split at hr
83
+ · rename_i h
84
+ have hr' : r=0 := by symm; simpa using hr
85
+ subst r
86
+ have hx : x ≤ (rationalEnumeration i : ℝ) := le_of_not_gt
87
+ (fun hx => Bool.noConfusion ((bit_zero _ (hbi.trans h.1)).symm.trans ((cut_eq_true x i).mpr hx)))
88
+ have hy : y ≤ (rationalEnumeration j : ℝ) := le_of_not_gt
89
+ (fun hy => Bool.noConfusion ((bit_zero _ (hbj.trans h.2.1)).symm.trans ((cut_eq_true y j).mpr hy)))
90
+ have hq := (sum_lt_iff n i j).mp h.2.2
91
+ have hnot : ¬(rationalEnumeration n : ℝ)<x+y := by linarith
92
+ have hc : cut (x+y) n=false := Bool.eq_false_iff.mpr
93
+ (fun hc => hnot ((cut_eq_true _ _).mp hc))
94
+ simp [hc]
95
+ · simp at hr
96
+
97
+ theorem trial_complete (x y : ℝ) (hxy : Irrational (x+y)) (n : ℕ) :
98
+ ∃ m r, r ∈ trial x y n m := by
99
+ have hne : (rationalEnumeration n : ℝ) ≠ x+y := fun h => hxy ⟨rationalEnumeration n,h⟩
100
+ rcases lt_or_gt_of_ne hne with h | h
101
+ · obtain ⟨a,ha,hax⟩ := exists_rat_btwn (show (rationalEnumeration n : ℝ)-y<x by linarith)
102
+ obtain ⟨b,hb,hby⟩ := exists_rat_btwn (show (rationalEnumeration n : ℝ)-(a : ℝ)<y by linarith)
103
+ obtain ⟨i,hi⟩ := rationalEnumeration_surjective a
104
+ obtain ⟨j,hj⟩ := rationalEnumeration_surjective b
105
+ have hci : cut x i=true := (cut_eq_true x i).mpr (by simpa only [hi] using hax)
106
+ have hcj : cut y j=true := (cut_eq_true y j).mpr (by simpa only [hj] using hby)
107
+ have hl : sumLeft (n,i,j)<sumRight (n,i,j) := (lt_sum_iff n i j).mpr (by rw [hi,hj]; linarith)
108
+ exact ⟨Nat.pair i j,1,by simp [trial,decision,hci,hcj,hl]⟩
109
+ · obtain ⟨a,hxa,ha⟩ := exists_rat_btwn (show x<(rationalEnumeration n : ℝ)-y by linarith)
110
+ obtain ⟨b,hyb,hb⟩ := exists_rat_btwn (show y<(rationalEnumeration n : ℝ)-(a : ℝ) by linarith)
111
+ obtain ⟨i,hi⟩ := rationalEnumeration_surjective a
112
+ obtain ⟨j,hj⟩ := rationalEnumeration_surjective b
113
+ have hci : cut x i=false := Bool.eq_false_iff.mpr (fun hc => by
114
+ have hh := (cut_eq_true x i).mp hc
115
+ rw [hi] at hh
116
+ linarith)
117
+ have hcj : cut y j=false := Bool.eq_false_iff.mpr (fun hc => by
118
+ have hh := (cut_eq_true y j).mp hc
119
+ rw [hj] at hh
120
+ linarith)
121
+ have hu : sumRight (n,i,j)<sumLeft (n,i,j) := (sum_lt_iff n i j).mpr (by rw [hi,hj]; linarith)
122
+ exact ⟨Nat.pair i j,0,by simp [trial,decision,hci,hcj,hu]⟩
123
+
124
+ theorem irrational_add_reduces (x y : ℝ) (hxy : Irrational (x+y)) :
125
+ Reduces (cut (x+y)) (join (cut x) (cut y)) := by
126
+ apply RecursiveIn.iff_nat.mpr
127
+ exact total_search (trial_recursive x y) (fun n => if cut (x+y) n then 1 else 0)
128
+ (trial_sound x y) (trial_complete x y hxy)
129
+ end CutAddition
130
+
131
+ theorem cut_add_reduces (x y : ℝ) : Reduces (cut (x+y)) (join (cut x) (cut y)) := by
132
+ by_cases hxy : Irrational (x+y)
133
+ · exact CutAddition.irrational_add_reduces x y hxy
134
+ · obtain ⟨q,hq⟩ := not_not.mp hxy
135
+ rw [←hq]
136
+ exact rational_cut_reduces q _
137
+
138
+ end TuringRigidity
139
+
140
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/CutArithmetic.lean ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.CutAddition
2
+ import OAI.Computability.DegreeRigidity.Computability.ScalarCoding
3
+ import OAI.Computability.DegreeRigidity.Representation.Assembly
4
+
5
+ namespace OAI
6
+
7
+ namespace TuringRigidity
8
+ open RationalCoding UniformOracle
9
+
10
+ theorem cut_smul_reduces (r : ℚ) (x : ℝ) : Reduces (cut ((r : ℝ)*x)) (cut x) := by
11
+ by_cases hr : r=0
12
+ · subst r
13
+ simpa using rational_cut_reduces (0 : ℚ) (cut x)
14
+ by_cases ht : Irrational ((r : ℝ)*x)
15
+ swap
16
+ · obtain ⟨q,hq⟩ := not_not.mp ht
17
+ rw [←hq]
18
+ exact rational_cut_reduces q _
19
+ have hq : Nat.RecursiveIn {oracleFunction (cut x)} (oracleFunction (cut x)) :=
20
+ .oracle _ (Set.mem_singleton _)
21
+ have hread := Nat.RecursiveIn.comp hq (divideIndex_recursive (O := {oracleFunction (cut x)}) r hr)
22
+ apply RecursiveIn.iff_nat.mpr
23
+ by_cases hpos : 0<r
24
+ · have hpos' : (0 : ℝ)<r := by exact_mod_cast hpos
25
+ apply hread.of_eq
26
+ intro n
27
+ change (Part.some (divideIndex r n)).bind
28
+ (fun input => Part.some (if cut x input then 1 else 0)) =
29
+ oracleFunction (cut ((r : ℝ)*x)) n
30
+ rw [Part.bind_some]
31
+ have hiff : cut x (divideIndex r n)=true ↔ cut ((r : ℝ)*x) n=true := by
32
+ rw [cut_eq_true,cut_eq_true,divideIndex_value,Rat.cast_div]
33
+ simpa only [mul_comm] using (div_lt_iff₀ hpos' :
34
+ (rationalEnumeration n : ℝ)/(r : ℝ)<x ↔ (rationalEnumeration n : ℝ)<x*(r : ℝ))
35
+ have heq : cut x (divideIndex r n)=cut ((r : ℝ)*x) n := Bool.eq_iff_iff.mpr hiff
36
+ simp only [oracleFunction,heq]
37
+ · have hneg : r<0 := (lt_or_gt_of_ne hr).resolve_right hpos
38
+ have hneg' : (r : ℝ)<0 := by exact_mod_cast hneg
39
+ have hc : Primrec (fun b : ℕ => if b=0 then 1 else 0) :=
40
+ Primrec.ite (Primrec.eq.comp Primrec.id (Primrec.const 0)) (Primrec.const 1) (Primrec.const 0)
41
+ apply (Nat.RecursiveIn.comp (total_primrec hc) hread).of_eq
42
+ intro n
43
+ change ((Part.some (divideIndex r n)).bind
44
+ (fun input => Part.some (if cut x input then 1 else 0))).bind
45
+ (fun value => Part.some (if value = 0 then 1 else 0)) =
46
+ oracleFunction (cut ((r : ℝ)*x)) n
47
+ simp only [Part.bind_some]
48
+ have hiff : cut x (divideIndex r n)=true ↔ (r : ℝ)*x<(rationalEnumeration n : ℝ) := by
49
+ rw [cut_eq_true,divideIndex_value,Rat.cast_div]
50
+ simpa only [mul_comm] using (div_lt_iff_of_neg hneg' :
51
+ (rationalEnumeration n : ℝ)/(r : ℝ)<x ↔ x*(r : ℝ)<(rationalEnumeration n : ℝ))
52
+ have hneq : (rationalEnumeration n : ℝ) ≠ (r : ℝ)*x :=
53
+ fun h => ht ⟨rationalEnumeration n,h⟩
54
+ by_cases hin : cut x (divideIndex r n)=true
55
+ · have hout : cut ((r : ℝ)*x) n=false := Bool.eq_false_iff.mpr
56
+ (fun h => (not_lt_of_gt (hiff.mp hin)) ((cut_eq_true _ _).mp h))
57
+ simp [hin,hout,oracleFunction]
58
+ · have hle : (rationalEnumeration n : ℝ) ≤ (r : ℝ)*x :=
59
+ le_of_not_gt (fun h => hin (hiff.mpr h))
60
+ have hout : cut ((r : ℝ)*x) n=true := (cut_eq_true _ _).mpr
61
+ ((lt_or_eq_of_le hle).resolve_right hneq)
62
+ have hin' := Bool.eq_false_iff.mpr hin
63
+ simp [hin',hout,oracleFunction]
64
+
65
+ theorem cut_sub_reduces (x y : ℝ) : Reduces (cut (x-y)) (join (cut x) (cut y)) := by
66
+ have hy : Reduces (cut (-y)) (cut y) := by simpa using cut_smul_reduces (-1 : ℚ) y
67
+ have h := reduces_trans (cut_add_reduces x (-y)) (join_mono (reduces_refl (cut x)) hy)
68
+ simpa only [sub_eq_add_neg] using h
69
+
70
+ theorem cut_translate_reduces (x : ℝ) (q : ℚ) : Reduces (cut (x+(q : ℝ))) (cut x) :=
71
+ reduces_trans (cut_add_reduces x q)
72
+ (join_reduces (reduces_refl (cut x)) (rational_cut_reduces q (cut x)))
73
+
74
+ theorem cut_arithmetic : CutArithmetic where
75
+ add := cut_add_reduces
76
+ sub := cut_sub_reduces
77
+ smul := cut_smul_reduces
78
+ translate := cut_translate_reduces
79
+
80
+ end TuringRigidity
81
+
82
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/CutTranscript.lean ADDED
@@ -0,0 +1,102 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Effective.FiniteTranscript
2
+ import OAI.Computability.DegreeRigidity.Computability.Cuts
3
+ import OAI.Computability.DegreeRigidity.Computability.Joins
4
+
5
+ namespace OAI
6
+
7
+ open Set
8
+ namespace TuringRigidity
9
+
10
+ theorem cut_prefix_left (x : ℝ) (m : ℕ) :
11
+ ∃ l : ℝ, l < x ∧ ∀ y, l < y → y ≤ x → ∀ k, k < m → cut y k = cut x k := by
12
+ induction m with
13
+ | zero => exact ⟨x-1, by linarith, by simp⟩
14
+ | succ m ih =>
15
+ obtain ⟨l,hl,he⟩ := ih
16
+ by_cases hq : (rationalEnumeration m : ℝ) < x
17
+ · refine ⟨max l (rationalEnumeration m), max_lt hl hq, ?_⟩
18
+ intro y hy hyx k hk
19
+ rcases Nat.lt_succ_iff_lt_or_eq.mp hk with hk | hk
20
+ · exact he y ((le_max_left _ _).trans_lt hy) hyx k hk
21
+ · subst k
22
+ have hqy := (le_max_right l (rationalEnumeration m : ℝ)).trans_lt hy
23
+ simp [cut, hq, hqy]
24
+ · refine ⟨l,hl,?_⟩
25
+ intro y hy hyx k hk
26
+ rcases Nat.lt_succ_iff_lt_or_eq.mp hk with hk | hk
27
+ · exact he y hy hyx k hk
28
+ · subst k
29
+ have hqy : ¬ (rationalEnumeration m : ℝ) < y :=
30
+ not_lt.mpr (hyx.trans (not_lt.mp hq))
31
+ simp [cut,hq,hqy]
32
+
33
+ namespace CategorySearch
34
+
35
+ noncomputable def pairOracle (A : Oracle) (p : ℝ × ℝ) : Oracle := join (join A (cut p.1)) (cut p.2)
36
+ noncomputable def value (A : Oracle) (p : ℝ × ℝ) (k : ℕ) : ℕ := if pairOracle A p k then 1 else 0
37
+
38
+ theorem value_prefix (A : Oracle) (p q : ℝ × ℝ) (m : ℕ)
39
+ (h1 : ∀ k, k < m → cut q.1 k = cut p.1 k)
40
+ (h2 : ∀ k, k < m → cut q.2 k = cut p.2 k) :
41
+ ∀ k, k < m → value A q k = value A p k := by
42
+ intro k hk
43
+ apply congrArg (fun b : Bool => if b then (1 : ℕ) else 0)
44
+ have hk2 : k/2 < m := by omega
45
+ have hk4 : k/2/2 < m := by omega
46
+ simp only [pairOracle,join,h1 _ hk4,h2 _ hk2]
47
+
48
+ theorem halting_left (A : Oracle) (c : OracleCode) (p : ℝ × ℝ) (n a : ℕ)
49
+ (ha : a ∈ OracleCode.eval (oracleFunction (pairOracle A p)) c n) :
50
+ ∃ l : ℝ × ℝ, l.1 < p.1 ∧ l.2 < p.2 ∧
51
+ ∀ q : ℝ × ℝ, l.1 < q.1 → q.1 ≤ p.1 → l.2 < q.2 → q.2 ≤ p.2 →
52
+ a ∈ OracleCode.eval (oracleFunction (pairOracle A q)) c n := by
53
+ obtain ⟨m,hm⟩ := OracleCode.eval_total_stable (value A p) c n a ha
54
+ obtain ⟨l1,h1,he1⟩ := cut_prefix_left p.1 m
55
+ obtain ⟨l2,h2,he2⟩ := cut_prefix_left p.2 m
56
+ refine ⟨(l1,l2),h1,h2,?_⟩
57
+ intro q hq1 hq1' hq2 hq2'
58
+ exact hm (value A q) (value_prefix A p q m (he1 _ hq1 hq1') (he2 _ hq2 hq2'))
59
+
60
+ def rectangle (l r : ℚ × ℚ) : Set (ℝ × ℝ) :=
61
+ Ioo (l.1 : ℝ) (r.1 : ℝ) ×ˢ Ioo (l.2 : ℝ) (r.2 : ℝ)
62
+
63
+ def success (A Y : Oracle) (c : OracleCode) : Set (ℝ × ℝ) :=
64
+ {p | OracleCode.eval (oracleFunction (pairOracle A p)) c = oracleFunction Y}
65
+
66
+ theorem dense_sound (A Y : Oracle) (c : OracleCode) (l r : ℚ × ℚ)
67
+ (hd : rectangle l r ⊆ closure (success A Y c)) (p : ℝ × ℝ)
68
+ (hp : p ∈ rectangle l r) (n a : ℕ)
69
+ (ha : a ∈ OracleCode.eval (oracleFunction (pairOracle A p)) c n) :
70
+ a = if Y n then 1 else 0 := by
71
+ obtain ⟨b,hb1,hb2,he⟩ := halting_left A c p n a ha
72
+ let U : Set (ℝ × ℝ) := Ioo (max b.1 (l.1 : ℝ)) p.1 ×ˢ Ioo (max b.2 (l.2 : ℝ)) p.2
73
+ have hU : IsOpen U := isOpen_Ioo.prod isOpen_Ioo
74
+ have hne : U.Nonempty :=
75
+ (nonempty_Ioo.mpr (max_lt hb1 hp.1.1)).prod (nonempty_Ioo.mpr (max_lt hb2 hp.2.1))
76
+ have hsub : U ⊆ rectangle l r := by
77
+ intro q hq
78
+ exact ⟨⟨(le_max_right _ _).trans_lt hq.1.1,hq.1.2.trans hp.1.2⟩,
79
+ ⟨(le_max_right _ _).trans_lt hq.2.1,hq.2.2.trans hp.2.2⟩⟩
80
+ obtain ⟨q,hq⟩ := hne
81
+ obtain ⟨z,hzU,hzS⟩ := mem_closure_iff.mp (hd (hsub hq)) U hU hq
82
+ have hz := he z ((le_max_left _ _).trans_lt hzU.1.1) hzU.1.2.le
83
+ ((le_max_left _ _).trans_lt hzU.2.1) hzU.2.2.le
84
+ rw [hzS] at hz
85
+ exact Part.mem_some_iff.mp hz
86
+
87
+ theorem rational_halting (A : Oracle) (c : OracleCode) (l r : ℚ × ℚ)
88
+ (p : ℝ × ℝ) (hp : p ∈ rectangle l r) (n a : ℕ)
89
+ (ha : a ∈ OracleCode.eval (oracleFunction (pairOracle A p)) c n) :
90
+ ∃ q : ℚ × ℚ, ((q.1 : ℝ),(q.2 : ℝ)) ∈ rectangle l r ∧
91
+ a ∈ OracleCode.eval (oracleFunction (pairOracle A ((q.1 : ℝ),(q.2 : ℝ)))) c n := by
92
+ obtain ⟨b,hb1,hb2,he⟩ := halting_left A c p n a ha
93
+ obtain ⟨u,hu1,hu2⟩ := exists_rat_btwn (max_lt hb1 hp.1.1)
94
+ obtain ⟨v,hv1,hv2⟩ := exists_rat_btwn (max_lt hb2 hp.2.1)
95
+ exact ⟨(u,v),⟨⟨(le_max_right _ _).trans_lt hu1,hu2.trans hp.1.2⟩,
96
+ ⟨(le_max_right _ _).trans_lt hv1,hv2.trans hp.2.2⟩⟩,
97
+ he _ ((le_max_left _ _).trans_lt hu1) hu2.le ((le_max_left _ _).trans_lt hv1) hv2.le⟩
98
+
99
+ end CategorySearch
100
+ end TuringRigidity
101
+
102
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/Cuts.lean ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.OracleCode
2
+ import OAI.Computability.DegreeRigidity.Representation.Category
3
+ import Mathlib.MeasureTheory.Constructions.BorelSpace.Real
4
+
5
+ namespace OAI
6
+
7
+ open Set Filter Topology
8
+ namespace TuringRigidity
9
+
10
+ def rationalEnumeration (n : ℕ) : ℚ := (Encodable.decode (α := ℚ) n).getD 0
11
+
12
+ theorem rationalEnumeration_surjective : Function.Surjective rationalEnumeration := by
13
+ intro q
14
+ refine ⟨Encodable.encode q, ?_⟩
15
+ simp [rationalEnumeration]
16
+
17
+ noncomputable def cut (x : ℝ) : Oracle := fun n => decide ((rationalEnumeration n : ℝ) < x)
18
+
19
+ @[simp] theorem cut_eq_true (x : ℝ) (n : ℕ) :
20
+ cut x n = true ↔ (rationalEnumeration n : ℝ) < x := by simp [cut]
21
+
22
+ theorem cut_injective : Function.Injective cut := by
23
+ intro x y hxy
24
+ apply le_antisymm
25
+ · by_contra h
26
+ have hyx : y < x := lt_of_not_ge h
27
+ obtain ⟨q, hyq, hqx⟩ := exists_rat_btwn hyx
28
+ obtain ⟨n, hn⟩ := rationalEnumeration_surjective q
29
+ have hc : cut x n = true := (cut_eq_true x n).mpr (by simpa [hn] using hqx)
30
+ rw [hxy] at hc
31
+ have hqy := (cut_eq_true y n).mp hc
32
+ rw [hn] at hqy
33
+ exact (not_lt_of_gt hyq) hqy
34
+ · by_contra h
35
+ have hxy' : x < y := lt_of_not_ge h
36
+ obtain ⟨q, hxq, hqy⟩ := exists_rat_btwn hxy'
37
+ obtain ⟨n, hn⟩ := rationalEnumeration_surjective q
38
+ have hc : cut y n = true := (cut_eq_true y n).mpr (by simpa [hn] using hqy)
39
+ rw [← hxy] at hc
40
+ have hqx := (cut_eq_true x n).mp hc
41
+ rw [hn] at hqx
42
+ exact (not_lt_of_gt hxq) hqx
43
+
44
+ theorem cut_measurable : Measurable cut := by
45
+ apply Measurable.of_eval
46
+ intro n
47
+ have h : MeasurableSet {x : ℝ | (rationalEnumeration n : ℝ) < x} := measurableSet_Ioi
48
+ have hm : Measurable (fun x : ℝ => if (rationalEnumeration n : ℝ) < x then true else false) :=
49
+ Measurable.ite h measurable_const measurable_const
50
+ convert hm using 1
51
+ funext x
52
+ by_cases hq : (rationalEnumeration n : ℝ) < x <;> simp [cut, hq]
53
+
54
+ noncomputable def realDegree (x : ℝ) : Degree := degree (cut x)
55
+
56
+ theorem represented_real_map_countable_fibers (π : Degree ≃o Degree) (F : ℝ → Oracle)
57
+ (hF : ∀ x, degree (F x) = π (realDegree x)) :
58
+ ∀ B : Oracle, {x : ℝ | F x = B}.Countable := by
59
+ exact countable_lift_fiber cut cut_injective π π.injective F hF
60
+
61
+ end TuringRigidity
62
+
63
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/DegreeCoverage.lean ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.BinaryCut
2
+ import OAI.Computability.DegreeRigidity.Computability.BinaryRecovery
3
+ import OAI.Computability.DegreeRigidity.Representation.Assembly
4
+
5
+ namespace OAI
6
+
7
+ namespace TuringRigidity
8
+ namespace BinarySeries
9
+
10
+ theorem value_eq_series (B : Oracle) :
11
+ value B = ∑' n, (bit B n : ℝ) * (2^(n+1) : ℝ)⁻¹ := rfl
12
+
13
+ theorem irrational_of_noncomputable (B : Oracle) (h : ¬ Reduces B (fun _ => false)) :
14
+ Irrational (value B) := by
15
+ intro ⟨q,hq⟩
16
+ apply h
17
+ have hr := set_reduces_cut B (mixed_of_noncomputable B h)
18
+ rw [←hq] at hr
19
+ exact reduces_trans hr (rational_cut_reduces q _)
20
+
21
+ theorem rational_series_reduces (B A : Oracle) (q : ℚ) (hq : (q : ℝ) = value B) :
22
+ Reduces B A := by
23
+ by_contra h
24
+ have hn : ¬ Reduces B (fun _ => false) := by
25
+ intro hh
26
+ exact h (reduces_trans hh (eventually_constant_reduces (fun _ => false) A false 0 (by simp)))
27
+ exact irrational_of_noncomputable B hn ⟨q,hq⟩
28
+
29
+ theorem noncomputable_series (B : Oracle) (h : ¬ Reduces B (fun _ => false)) :
30
+ Irrational (value B) ∧ 0 < value B ∧ value B < 1 ∧
31
+ Reduces (cut (value B)) B ∧ Reduces B (cut (value B)) := by
32
+ have hm := mixed_of_noncomputable B h
33
+ have hi := irrational_of_noncomputable B h
34
+ refine ⟨hi,positive B ?_,lt_one B ?_,cut_reduces B hi,set_reduces_cut B hm⟩
35
+ · obtain ⟨n,_,hn⟩ := (hm 0).1
36
+ exact ⟨n,hn⟩
37
+ · obtain ⟨n,_,hn⟩ := (hm 0).2
38
+ exact ⟨n,hn⟩
39
+ end BinarySeries
40
+
41
+ theorem irrational_degree_coverage : IrrationalDegreeCoverage := by
42
+ intro a ha
43
+ obtain ⟨B,rfl⟩ := degree_surjective a
44
+ have hn : ¬ Reduces B (fun _ => false) := by
45
+ intro h
46
+ exact ha (le_antisymm h bot_le)
47
+ obtain ⟨hi,h0,h1,hforward,hback⟩ := BinarySeries.noncomputable_series B hn
48
+ exact ⟨BinarySeries.value B,hi,h0,h1,(degree_eq_iff _ _).mpr ⟨hforward,hback⟩⟩
49
+
50
+ end TuringRigidity
51
+
52
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/EffectiveRecovery.lean ADDED
@@ -0,0 +1,223 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.RationalCoding
2
+ import OAI.Computability.DegreeRigidity.Computability.BranchFrequency
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity
7
+
8
+ namespace EffectiveRecovery
9
+ open RationalCoding
10
+
11
+ def window (A B : ℕ) (z : Bool × (ℕ × ℕ) × (ℕ × ℕ)) : Option ℕ :=
12
+ if z.1 then some 1 else
13
+ if z.2.1.1*z.2.2.1*A + z.2.1.2*B < z.2.1.2*z.2.2.2*A then some 1 else
14
+ if z.2.1.2*(z.2.2.2*A+B) < z.2.1.1*z.2.2.1*A then some 0 else none
15
+
16
+ theorem window_primrec (A B : ℕ) : Primrec (window A B) := by
17
+ let Q := Primrec.fst.comp (Primrec.fst.comp Primrec.snd) (α := Bool × (ℕ × ℕ) × (ℕ × ℕ))
18
+ let D := Primrec.snd.comp (Primrec.fst.comp Primrec.snd) (α := Bool × (ℕ × ℕ) × (ℕ × ℕ))
19
+ let N := Primrec.fst.comp (Primrec.snd.comp Primrec.snd) (α := Bool × (ℕ × ℕ) × (ℕ × ℕ))
20
+ let S := Primrec.snd.comp (Primrec.snd.comp Primrec.snd) (α := Bool × (ℕ × ℕ) × (ℕ × ℕ))
21
+ exact Primrec.ite (Primrec.eq.comp Primrec.fst (Primrec.const true)) (Primrec.const (some 1))
22
+ (Primrec.ite (Primrec.nat_lt.comp
23
+ (Primrec.nat_add.comp (Primrec.nat_mul.comp (Primrec.nat_mul.comp Q N) (Primrec.const A))
24
+ (Primrec.nat_mul.comp D (Primrec.const B)))
25
+ (Primrec.nat_mul.comp (Primrec.nat_mul.comp D S) (Primrec.const A)))
26
+ (Primrec.const (some 1))
27
+ (Primrec.ite (Primrec.nat_lt.comp
28
+ (Primrec.nat_mul.comp D (Primrec.nat_add.comp
29
+ (Primrec.nat_mul.comp S (Primrec.const A)) (Primrec.const B)))
30
+ (Primrec.nat_mul.comp (Primrec.nat_mul.comp Q N) (Primrec.const A)))
31
+ (Primrec.const (some 0)) (Primrec.const none)))
32
+
33
+ theorem lower_iff (Q D N S A B : ℕ) (hD : 0 < D) (hN : 0 < N) (hA : 0 < A) :
34
+ (Q : ℝ)/D < (S : ℝ)/N - (B : ℝ)/(N*A) ↔ Q*N*A+D*B < D*S*A := by
35
+ have hd : (0 : ℝ) < D := by exact_mod_cast hD
36
+ have hn : (0 : ℝ) < N := by exact_mod_cast hN
37
+ have ha : (0 : ℝ) < A := by exact_mod_cast hA
38
+ have hden : (0 : ℝ) < D*N*A := mul_pos (mul_pos hd hn) ha
39
+ have he : ((S : ℝ)/N - (B : ℝ)/(N*A) - (Q : ℝ)/D) * (D*N*A) =
40
+ (D : ℝ)*S*A - ((Q : ℝ)*N*A+D*B) := by
41
+ field_simp
42
+ ring
43
+ constructor
44
+ · intro h
45
+ have hp := mul_pos (sub_pos.mpr h) hden
46
+ rw [he] at hp
47
+ exact_mod_cast sub_pos.mp hp
48
+ · intro h
49
+ have hr : (Q : ℝ)*N*A+D*B < (D : ℝ)*S*A := by exact_mod_cast h
50
+ have hp : 0 < ((S : ℝ)/N - (B : ℝ)/(N*A) - (Q : ℝ)/D) * (D*N*A) := by
51
+ rw [he]; linarith
52
+ exact sub_pos.mp ((mul_pos_iff_of_pos_right hden).mp hp)
53
+
54
+ theorem upper_iff (Q D N S A B : ℕ) (hD : 0 < D) (hN : 0 < N) (hA : 0 < A) :
55
+ (S : ℝ)/N + (B : ℝ)/(N*A) < (Q : ℝ)/D ↔ D*(S*A+B) < Q*N*A := by
56
+ have hd : (0 : ℝ) < D := by exact_mod_cast hD
57
+ have hn : (0 : ℝ) < N := by exact_mod_cast hN
58
+ have ha : (0 : ℝ) < A := by exact_mod_cast hA
59
+ have hden : (0 : ℝ) < D*N*A := mul_pos (mul_pos hd hn) ha
60
+ have he : ((Q : ℝ)/D - ((S : ℝ)/N + (B : ℝ)/(N*A))) * (D*N*A) =
61
+ (Q : ℝ)*N*A - (D : ℝ)*(S*A+B) := by
62
+ field_simp
63
+ constructor
64
+ · intro h
65
+ have hp := mul_pos (sub_pos.mpr h) hden
66
+ rw [he] at hp
67
+ exact_mod_cast sub_pos.mp hp
68
+ · intro h
69
+ have hr : (D : ℝ)*(S*A+B) < (Q : ℝ)*N*A := by exact_mod_cast h
70
+ have hp : 0 < ((Q : ℝ)/D - ((S : ℝ)/N + (B : ℝ)/(N*A))) * (D*N*A) := by
71
+ rw [he]; linarith
72
+ exact sub_pos.mp ((mul_pos_iff_of_pos_right hden).mp hp)
73
+ end EffectiveRecovery
74
+
75
+ namespace RecoveryData
76
+ open RationalCoding EffectiveRecovery
77
+ variable {F : ℝ → Oracle} {t u v : ℝ}
78
+
79
+ theorem delta_numerator_pos (d : RecoveryData F t u v) : 0 < d.delta.num.natAbs := by
80
+ have hn : 0 < d.delta.num := Rat.num_pos.mpr d.delta_pos
81
+ have he : (d.delta.num.natAbs : ℤ) = d.delta.num := by
82
+ rw [Int.natCast_natAbs,abs_of_pos hn]
83
+ rw [←he] at hn
84
+ exact_mod_cast hn
85
+
86
+ theorem delta_fraction (d : RecoveryData F t u v) :
87
+ (d.delta : ℝ) = (d.delta.num.natAbs : ℝ)/(d.delta.den : ℝ) := by
88
+ have hn : 0 < d.delta.num := Rat.num_pos.mpr d.delta_pos
89
+ have he : (d.delta.num.natAbs : ℤ) = d.delta.num := by
90
+ rw [Int.natCast_natAbs,abs_of_pos hn]
91
+ have he' : (d.delta.num.natAbs : ℝ) = (d.delta.num : ℝ) := by
92
+ simpa only [Int.cast_natCast] using congrArg (fun z : ℤ => (z : ℝ)) he
93
+ rw [Rat.cast_def,he']
94
+
95
+ theorem radius_fraction (d : RecoveryData F t u v) (N : ℕ) (hN : 0 < N) :
96
+ 1/((N : ℝ)*(d.delta : ℝ)) = (d.delta.den : ℝ)/((N : ℝ)*d.delta.num.natAbs) := by
97
+ have hn : (0 : ℝ) < N := by exact_mod_cast hN
98
+ have ha : (0 : ℝ) < d.delta.num.natAbs := by exact_mod_cast d.delta_numerator_pos
99
+ have hb : (0 : ℝ) < d.delta.den := by exact_mod_cast d.delta.den_pos
100
+ rw [d.delta_fraction]
101
+ field_simp
102
+
103
+ def cutTrial (d : RecoveryData F t u v) (i m : ℕ) : Option ℕ :=
104
+ window d.delta.num.natAbs d.delta.den
105
+ (negative i,(numeratorMagnitude i,denominator i),(m+1,d.count (m+1)))
106
+
107
+ theorem cutTrial_recursive (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1) :
108
+ Nat.RecursiveIn {oracleFunction (fourTuple F t u v d.delta)}
109
+ (fun z => Part.some (Encodable.encode (d.cutTrial (Nat.unpair z).1 (Nat.unpair z).2))) := by
110
+ let O : Set (ℕ →. ℕ) := {oracleFunction (fourTuple F t u v d.delta)}
111
+ have hq := UniformOracle.total_primrec (O := O) (Primrec.fst.comp Primrec.unpair)
112
+ have hN := UniformOracle.total_primrec (O := O) (Primrec.succ.comp (Primrec.snd.comp Primrec.unpair))
113
+ have hS := UniformOracle.total_comp (d.count_recursive ht0 ht1) hN
114
+ have hwindow : Primrec (fun z : ℕ => Encodable.encode
115
+ (window d.delta.num.natAbs d.delta.den
116
+ (negative (Nat.unpair z).1,
117
+ (numeratorMagnitude (Nat.unpair z).1,denominator (Nat.unpair z).1),
118
+ ((Nat.unpair (Nat.unpair z).2).1,(Nat.unpair (Nat.unpair z).2).2)))) :=
119
+ Primrec.encode.comp ((window_primrec _ _).comp
120
+ ((negative_primrec.comp (Primrec.fst.comp Primrec.unpair)).pair
121
+ (((numeratorMagnitude_primrec.comp (Primrec.fst.comp Primrec.unpair)).pair
122
+ (denominator_primrec.comp (Primrec.fst.comp Primrec.unpair))).pair
123
+ (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))))
124
+ exact (UniformOracle.total_comp (UniformOracle.total_primrec hwindow)
125
+ (UniformOracle.total_pair hq (UniformOracle.total_pair hN hS))).of_eq
126
+ (fun z => by simp [cutTrial])
127
+
128
+ theorem cutTrial_sound (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1)
129
+ (i m r : ℕ) (hr : r ∈ d.cutTrial i m) : r = if cut t i then 1 else 0 := by
130
+ have hn : 0 < m+1 := Nat.succ_pos m
131
+ have he := d.count_frequency_bound ht0 ht1 (m+1) hn
132
+ rw [d.radius_fraction (m+1) hn] at he
133
+ unfold cutTrial window at hr
134
+ split at hr
135
+ · rename_i hneg
136
+ have hr' : r=1 := by symm; simpa using hr
137
+ subst r
138
+ have hq : (rationalEnumeration i : ℝ) ≤ 0 := by
139
+ rw [query_value,ite_eq_left hneg]
140
+ exact div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (Nat.cast_nonneg _)) (Nat.cast_nonneg _)
141
+ have hc : cut t i = true := (cut_eq_true t i).mpr (hq.trans_lt ht0)
142
+ simp [hc]
143
+ · rename_i hneg
144
+ have hq : (rationalEnumeration i : ℝ) = (numeratorMagnitude i : ℝ)/(denominator i : ℝ) := by
145
+ rw [query_value,ite_eq_right hneg]
146
+ split at hr
147
+ · rename_i hl
148
+ have hr' : r=1 := by symm; simpa using hr
149
+ subst r
150
+ have hl' := (lower_iff (numeratorMagnitude i) (denominator i) (m+1) (d.count (m+1))
151
+ d.delta.num.natAbs d.delta.den (denominator_pos i) hn d.delta_numerator_pos).mpr hl
152
+ rw [←hq] at hl'
153
+ have hh := (abs_lt.mp he).1
154
+ have hc : cut t i = true := (cut_eq_true t i).mpr (by linarith)
155
+ simp [hc]
156
+ · split at hr
157
+ · rename_i hu
158
+ have hr' : r=0 := by symm; simpa using hr
159
+ subst r
160
+ have hu' := (upper_iff (numeratorMagnitude i) (denominator i) (m+1) (d.count (m+1))
161
+ d.delta.num.natAbs d.delta.den (denominator_pos i) hn d.delta_numerator_pos).mpr hu
162
+ rw [←hq] at hu'
163
+ have hh := (abs_lt.mp he).2
164
+ have htq : t < (rationalEnumeration i : ℝ) := by linarith
165
+ have hc : cut t i = false := Bool.eq_false_iff.mpr
166
+ (fun h => (not_lt_of_gt htq) ((cut_eq_true t i).mp h))
167
+ simp [hc]
168
+ · simp at hr
169
+
170
+ theorem cutTrial_complete (d : RecoveryData F t u v) (ht : Irrational t)
171
+ (ht0 : 0 < t) (ht1 : t < 1) (i : ℕ) : ∃ m r, r ∈ d.cutTrial i m := by
172
+ by_cases hneg : negative i = true
173
+ · exact ⟨0,1,by simp [cutTrial,window,hneg]⟩
174
+ · have hq : (rationalEnumeration i : ℝ) = (numeratorMagnitude i : ℝ)/(denominator i : ℝ) := by
175
+ rw [query_value,ite_eq_right hneg]
176
+ have hne : (rationalEnumeration i : ℝ) ≠ t := fun h => ht ⟨rationalEnumeration i,h⟩
177
+ obtain ⟨⟨N,hN,hs⟩,_⟩ := comparison_search t (d.delta : ℝ)
178
+ (fun n => (d.count n : ℝ)/(n : ℝ)) (by exact_mod_cast d.delta_pos)
179
+ (fun n hn => d.count_frequency_bound ht0 ht1 n hn) (rationalEnumeration i) hne
180
+ rw [d.radius_fraction N hN,hq] at hs
181
+ have hm : N-1+1=N := by omega
182
+ rcases hs with hl | hu
183
+ · have hl' := (lower_iff (numeratorMagnitude i) (denominator i) N (d.count N)
184
+ d.delta.num.natAbs d.delta.den (denominator_pos i) hN d.delta_numerator_pos).mp hl
185
+ exact ⟨N-1,1,by simp [cutTrial,hm,window,hneg,hl']⟩
186
+ · have hu' := (upper_iff (numeratorMagnitude i) (denominator i) N (d.count N)
187
+ d.delta.num.natAbs d.delta.den (denominator_pos i) hN d.delta_numerator_pos).mp hu
188
+ by_cases hl' : numeratorMagnitude i*N*d.delta.num.natAbs+denominator i*d.delta.den <
189
+ denominator i*d.count N*d.delta.num.natAbs
190
+ · exact ⟨N-1,1,by simp [cutTrial,hm,window,hneg,hl']⟩
191
+ · exact ⟨N-1,0,by simp [cutTrial,hm,window,hneg,hl',hu']⟩
192
+
193
+ theorem cut_reduces (d : RecoveryData F t u v) (ht : Irrational t)
194
+ (ht0 : 0 < t) (ht1 : t < 1) : Reduces (cut t) (fourTuple F t u v d.delta) := by
195
+ apply RecursiveIn.iff_nat.mpr
196
+ exact UniformOracle.total_search (d.cutTrial_recursive ht0 ht1)
197
+ (fun i => if cut t i then 1 else 0) (d.cutTrial_sound ht0 ht1)
198
+ (d.cutTrial_complete ht ht0 ht1)
199
+
200
+ theorem cut_single_program (d : RecoveryData F t u v) (ht : Irrational t)
201
+ (ht0 : 0 < t) (ht1 : t < 1) :
202
+ ∃ c : OracleCode, OracleCode.eval (oracleFunction (fourTuple F t u v d.delta)) c =
203
+ oracleFunction (cut t) :=
204
+ (OracleCode.turingReducible_iff_exists_code _ _).mp (d.cut_reduces ht ht0 ht1)
205
+
206
+ end RecoveryData
207
+
208
+ theorem four_value_recovery : FourValueRecovery := by
209
+ intro F hF hfiber hadd t ht ht0 ht1
210
+ obtain ⟨G,hG,hdata⟩ := recovery_data_exists F hF hfiber hadd t
211
+ refine ⟨G,hG,?_⟩
212
+ intro p hp
213
+ obtain ⟨d⟩ := hdata p hp
214
+ refine ⟨d.delta,d.delta_pos,?_,d.cut_reduces ht ht0 ht1⟩
215
+ exact_mod_cast d.delta_lt.trans d.radius_lt_one
216
+
217
+ theorem main_of_remaining_obligations (hrep : BorelRepresentation) (harith : CutArithmetic)
218
+ (hcover : IrrationalDegreeCoverage) (havoid : CategoryAvoidance) : MainTheorem :=
219
+ main_of_obligations hrep harith hcover four_value_recovery havoid
220
+
221
+ end TuringRigidity
222
+
223
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/Introreducible.lean ADDED
@@ -0,0 +1,159 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Effective.PrefixComputability
2
+ import Mathlib.Data.Set.Finite.Range
3
+ import Lean.Elab.Tactic.Omega
4
+
5
+ namespace OAI
6
+
7
+ namespace TuringRigidity
8
+ namespace Introreducible
9
+ open Encodable PrefixComputability
10
+
11
+ def bit (X : Oracle) (n : ℕ) : ℕ := if X n then 1 else 0
12
+
13
+ def prefixCode (X : Oracle) (n : ℕ) : ℕ := encode (oraclePrefix (bit X) n)
14
+
15
+ def codeList (c : ℕ) : List ℕ := (decode (α := List ℕ) c).getD []
16
+ def codeLength (c : ℕ) : ℕ := (codeList c).length
17
+
18
+ def prefixSet (X : Oracle) (c : ℕ) : Bool := decide (prefixCode X (codeLength c) = c)
19
+
20
+ @[simp] theorem codeList_prefix (X : Oracle) (n : ℕ) :
21
+ codeList (prefixCode X n) = oraclePrefix (bit X) n := by
22
+ simp [codeList, prefixCode]
23
+
24
+ @[simp] theorem codeLength_prefix (X : Oracle) (n : ℕ) :
25
+ codeLength (prefixCode X n) = n := by
26
+ simp [codeLength, oraclePrefix]
27
+
28
+ @[simp] theorem prefixSet_prefix (X : Oracle) (n : ℕ) :
29
+ prefixSet X (prefixCode X n) = true := by
30
+ simp [prefixSet]
31
+
32
+ theorem prefixCode_injective (X : Oracle) : Function.Injective (prefixCode X) := by
33
+ intro n m h
34
+ simpa using congrArg codeLength h
35
+
36
+ theorem prefixSet_infinite (X : Oracle) : {c | prefixSet X c = true}.Infinite := by
37
+ apply (Set.infinite_range_of_injective (prefixCode_injective X)).mono
38
+ rintro _ ⟨n, rfl⟩
39
+ exact prefixSet_prefix X n
40
+
41
+ theorem subset_unbounded {X Z : Oracle}
42
+ (hsub : ∀ c, Z c = true → prefixSet X c = true)
43
+ (hinf : {c | Z c = true}.Infinite) (n : ℕ) :
44
+ ∃ c, Z c = true ∧ n < codeLength c := by
45
+ by_contra h
46
+ have hb : ∀ c, Z c = true → codeLength c ≤ n := by
47
+ intro c hc
48
+ by_contra hn
49
+ exact h ⟨c, hc, Nat.lt_of_not_ge hn⟩
50
+ apply hinf
51
+ apply ((Set.finite_le_nat n).image (prefixCode X)).subset
52
+ intro c hc
53
+ have he := of_decide_eq_true (hsub c hc)
54
+ exact ⟨codeLength c, hb c hc, he⟩
55
+
56
+ theorem codeList_primrec : Primrec codeList :=
57
+ Primrec.option_getD_default.comp Primrec.decode
58
+
59
+ theorem codeLength_primrec : Primrec codeLength :=
60
+ Primrec.list_length.comp codeList_primrec
61
+
62
+ private def equalBit (c : ℕ) : ℕ :=
63
+ if (Nat.unpair c).1 = (Nat.unpair c).2 then 1 else 0
64
+
65
+ private theorem equalBit_primrec : Primrec equalBit := by
66
+ apply (Primrec.ite (Primrec.eq.comp (Primrec.fst.comp Primrec.unpair)
67
+ (Primrec.snd.comp Primrec.unpair)) (Primrec.const 1) (Primrec.const 0)).of_eq
68
+ intro n
69
+ simp [equalBit]
70
+
71
+ theorem prefixSet_reduces (X : Oracle) : Reduces (prefixSet X) X := by
72
+ apply RecursiveIn.iff_nat.mpr
73
+ have hp := total_comp (prefix_recursive (bit X)) (total_primrec codeLength_primrec)
74
+ have he := total_comp (total_primrec equalBit_primrec)
75
+ (total_pair hp (total_primrec Primrec.id))
76
+ apply he.of_eq
77
+ intro n
78
+ by_cases h : encode (oraclePrefix (bit X) (codeLength n)) = n
79
+ · simp [oracleFunction, prefixSet, equalBit, prefixCode, h]
80
+ · simp [oracleFunction, prefixSet, equalBit, prefixCode, h]
81
+
82
+ def codeBit (n c : ℕ) : ℕ := (codeList c).getD n 0
83
+
84
+ @[simp] theorem codeBit_prefix (X : Oracle) (n m : ℕ) (h : n < m) :
85
+ codeBit n (prefixCode X m) = bit X n := by
86
+ simp [codeBit, oraclePrefix, List.getD_eq_getElem?_getD, List.getElem?_range h]
87
+
88
+ theorem codeBit_primrec : Primrec₂ codeBit :=
89
+ (Primrec.list_getD 0).comp (codeList_primrec.comp Primrec.snd) Primrec.fst
90
+
91
+ def trial (Z : Oracle) (n c : ℕ) : Option ℕ :=
92
+ if Z c = true ∧ n < codeLength c then some (codeBit n c) else none
93
+
94
+ private def trialStep (p : ℕ) : ℕ :=
95
+ let n := (Nat.unpair p).1
96
+ let c := (Nat.unpair (Nat.unpair p).2).1
97
+ let b := (Nat.unpair (Nat.unpair p).2).2
98
+ encode (if b = 1 ∧ n < codeLength c then some (codeBit n c) else none)
99
+
100
+ private theorem trialStep_primrec : Primrec trialStep := by
101
+ let hn := Primrec.fst.comp Primrec.unpair
102
+ let hc := Primrec.fst.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair))
103
+ let hb := Primrec.snd.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair))
104
+ apply (Primrec.encode.comp (Primrec.ite
105
+ ((Primrec.eq.comp hb (Primrec.const 1)).and
106
+ (Primrec.nat_lt.comp hn (codeLength_primrec.comp hc)))
107
+ (Primrec.option_some.comp (codeBit_primrec.comp hn hc)) (Primrec.const none))).of_eq
108
+ intro p
109
+ simp [trialStep]
110
+
111
+ theorem trial_recursive (Z : Oracle) :
112
+ Nat.RecursiveIn {oracleFunction Z}
113
+ (fun p => Part.some (encode (trial Z (Nat.unpair p).1 (Nat.unpair p).2))) := by
114
+ have hq : Nat.RecursiveIn {oracleFunction Z} (oracleFunction Z) :=
115
+ .oracle _ (Set.mem_singleton _)
116
+ have hn := total_primrec (O := {oracleFunction Z}) (Primrec.fst.comp Primrec.unpair)
117
+ have hc := total_primrec (O := {oracleFunction Z}) (Primrec.snd.comp Primrec.unpair)
118
+ have ht := total_comp (total_primrec trialStep_primrec)
119
+ (total_pair hn (total_pair hc (total_comp hq hc)))
120
+ apply ht.of_eq
121
+ intro p
122
+ cases hz : Z (Nat.unpair p).2 <;> simp [trialStep, trial, hz]
123
+
124
+ theorem reduces_of_infinite_subset {X Z : Oracle}
125
+ (hsub : ∀ c, Z c = true → prefixSet X c = true)
126
+ (hinf : {c | Z c = true}.Infinite) : Reduces X Z := by
127
+ apply RecursiveIn.iff_nat.mpr
128
+ change Nat.RecursiveIn {oracleFunction Z} (fun n => Part.some (bit X n))
129
+ apply total_search (trial_recursive Z) (bit X)
130
+ · intro n c a ha
131
+ simp only [trial] at ha
132
+ split at ha
133
+ next h =>
134
+ have he : prefixCode X (codeLength c) = c := of_decide_eq_true (hsub c h.1)
135
+ have ha' : a = codeBit n c := (Option.mem_some_iff.mp ha).symm
136
+ rw [ha', ← he]
137
+ exact codeBit_prefix X n (codeLength c) h.2
138
+ next h => simp at ha
139
+ · intro n
140
+ obtain ⟨c, hc, hn⟩ := subset_unbounded hsub hinf n
141
+ exact ⟨c, codeBit n c, by simp [trial, hc, hn]⟩
142
+
143
+ theorem prefixSet_degree (X : Oracle) : degree (prefixSet X) = degree X := by
144
+ apply (degree_eq_iff _ _).mpr
145
+ exact ⟨prefixSet_reduces X, reduces_of_infinite_subset (fun _ h => h)
146
+ (prefixSet_infinite X)⟩
147
+
148
+ theorem introreducible_representative (X : Oracle) :
149
+ ∃ Y : Oracle, degree Y = degree X ∧ {n | Y n = true}.Infinite ∧
150
+ ∀ Z : Oracle, (∀ n, Z n = true → Y n = true) →
151
+ {n | Z n = true}.Infinite → Reduces Y Z := by
152
+ refine ⟨prefixSet X, prefixSet_degree X, prefixSet_infinite X, ?_⟩
153
+ intro Z hsub hinf
154
+ exact reduces_trans (prefixSet_reduces X) (reduces_of_infinite_subset hsub hinf)
155
+
156
+ end Introreducible
157
+ end TuringRigidity
158
+
159
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/Joins.lean ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.OracleCode
2
+ import Lean.Elab.Tactic.Omega
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity
7
+
8
+ def join (A B : Oracle) (n : ℕ) : Bool := if n.bodd then B (n / 2) else A (n / 2)
9
+
10
+ private theorem total_comp {O : Set (ℕ →. ℕ)} {f g : ℕ → ℕ}
11
+ (hf : Nat.RecursiveIn O (fun n => Part.some (f n)))
12
+ (hg : Nat.RecursiveIn O (fun n => Part.some (g n))) :
13
+ Nat.RecursiveIn O (fun n => Part.some (f (g n))) := by
14
+ simpa using Nat.RecursiveIn.comp hf hg
15
+
16
+ private theorem total_pair {O : Set (ℕ →. ℕ)} {f g : ℕ → ℕ}
17
+ (hf : Nat.RecursiveIn O (fun n => Part.some (f n)))
18
+ (hg : Nat.RecursiveIn O (fun n => Part.some (g n))) :
19
+ Nat.RecursiveIn O (fun n => Part.some (Nat.pair (f n) (g n))) := by
20
+ simpa [Seq.seq] using Nat.RecursiveIn.pair hf hg
21
+
22
+ private theorem total_primrec {O : Set (ℕ →. ℕ)} {f : ℕ → ℕ}
23
+ (hf : Primrec f) : Nat.RecursiveIn O (fun n => Part.some (f n)) :=
24
+ RecursiveIn.iff_nat.mp hf.computableIn
25
+
26
+ @[simp] theorem join_even (A B : Oracle) (n : ℕ) : join A B (2*n) = A n := by
27
+ simp [join, Nat.bodd_mul]
28
+
29
+ @[simp] theorem join_odd (A B : Oracle) (n : ℕ) : join A B (2*n+1) = B n := by
30
+ simp [join, Nat.bodd_mul]
31
+ congr 1
32
+ omega
33
+
34
+ theorem reduces_join_left (A B : Oracle) : Reduces A (join A B) := by
35
+ apply RecursiveIn.iff_nat.mpr
36
+ have horacle : Nat.RecursiveIn {oracleFunction (join A B)} (oracleFunction (join A B)) :=
37
+ .oracle _ (Set.mem_singleton _)
38
+ have h := total_comp horacle (total_primrec (Primrec.nat_mul.comp (Primrec.const 2) Primrec.id))
39
+ change Nat.RecursiveIn {oracleFunction (join A B)} (fun n => Part.some (if A n then 1 else 0))
40
+ simpa [oracleFunction] using h
41
+
42
+ theorem reduces_join_right (A B : Oracle) : Reduces B (join A B) := by
43
+ apply RecursiveIn.iff_nat.mpr
44
+ have horacle : Nat.RecursiveIn {oracleFunction (join A B)} (oracleFunction (join A B)) :=
45
+ .oracle _ (Set.mem_singleton _)
46
+ have h := total_comp horacle (total_primrec
47
+ (Primrec.nat_add.comp (Primrec.nat_mul.comp (Primrec.const 2) Primrec.id) (Primrec.const 1)))
48
+ change Nat.RecursiveIn {oracleFunction (join A B)} (fun n => Part.some (if B n then 1 else 0))
49
+ simpa [oracleFunction] using h
50
+
51
+ private def selectPair (k : ℕ) : ℕ :=
52
+ if (Nat.unpair k).1.bodd then (Nat.unpair (Nat.unpair k).2).2
53
+ else (Nat.unpair (Nat.unpair k).2).1
54
+
55
+ private theorem selectPair_primrec : Primrec selectPair := by
56
+ apply (Primrec.cond (Primrec.nat_bodd.comp (Primrec.fst.comp Primrec.unpair))
57
+ (Primrec.snd.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))
58
+ (Primrec.fst.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))).of_eq
59
+ intro n
60
+ cases hb : (Nat.unpair n).1.bodd <;> simp [selectPair, hb]
61
+
62
+ theorem join_reduces {A B C : Oracle} (hA : Reduces A C) (hB : Reduces B C) :
63
+ Reduces (join A B) C := by
64
+ apply RecursiveIn.iff_nat.mpr
65
+ have hA' := RecursiveIn.iff_nat.mp hA
66
+ have hB' := RecursiveIn.iff_nat.mp hB
67
+ have hdiv : Nat.RecursiveIn {oracleFunction C} (fun n => Part.some (n / 2)) :=
68
+ total_primrec (Primrec.nat_div.comp Primrec.id (Primrec.const 2))
69
+ have hp := total_pair (total_primrec Primrec.id)
70
+ (total_pair (total_comp hA' hdiv) (total_comp hB' hdiv))
71
+ have h := total_comp (total_primrec selectPair_primrec) hp
72
+ apply Nat.RecursiveIn.of_eq h
73
+ intro n
74
+ simp only [selectPair, Nat.unpair_pair, oracleFunction, join, id_eq]
75
+ by_cases hb : n.bodd = true <;> simp [hb]
76
+
77
+ theorem join_reduces_iff (A B C : Oracle) :
78
+ Reduces (join A B) C ↔ Reduces A C ∧ Reduces B C :=
79
+ ⟨fun h => ⟨reduces_trans (reduces_join_left A B) h,
80
+ reduces_trans (reduces_join_right A B) h⟩, fun h => join_reduces h.1 h.2⟩
81
+
82
+ theorem join_mono {A B C D : Oracle} (hA : Reduces A C) (hB : Reduces B D) :
83
+ Reduces (join A B) (join C D) :=
84
+ join_reduces (reduces_trans hA (reduces_join_left C D))
85
+ (reduces_trans hB (reduces_join_right C D))
86
+
87
+ def degreeJoin (a b : Degree) : Degree :=
88
+ Quotient.liftOn₂ a b (fun A B => degree (join A B))
89
+ (fun _ _ _ _ hA hB => (degree_eq_iff _ _).mpr
90
+ ⟨join_mono hA.1 hB.1, join_mono hA.2 hB.2⟩)
91
+
92
+ @[simp] theorem degree_join (A B : Oracle) :
93
+ degreeJoin (degree A) (degree B) = degree (join A B) := rfl
94
+
95
+ instance : SemilatticeSup Degree where
96
+ sup := degreeJoin
97
+ le_sup_left a b := by
98
+ obtain ⟨A, rfl⟩ := degree_surjective a
99
+ obtain ⟨B, rfl⟩ := degree_surjective b
100
+ exact reduces_join_left A B
101
+ le_sup_right a b := by
102
+ obtain ⟨A, rfl⟩ := degree_surjective a
103
+ obtain ⟨B, rfl⟩ := degree_surjective b
104
+ exact reduces_join_right A B
105
+ sup_le a b c := by
106
+ obtain ⟨A, rfl⟩ := degree_surjective a
107
+ obtain ⟨B, rfl⟩ := degree_surjective b
108
+ obtain ⟨C, rfl⟩ := degree_surjective c
109
+ exact join_reduces
110
+
111
+ instance : OrderBot Degree where
112
+ bot := degree (fun _ => false)
113
+ bot_le a := by
114
+ obtain ⟨A, rfl⟩ := degree_surjective a
115
+ apply RecursiveIn.iff_nat.mpr
116
+ change Nat.RecursiveIn {oracleFunction A} (fun _ => Part.some 0)
117
+ exact .zero
118
+
119
+ theorem automorphism_preserves_join (π : Degree ≃o Degree) (a b : Degree) :
120
+ π (a ⊔ b) = π a ⊔ π b := π.map_sup a b
121
+
122
+ theorem automorphism_fixes_zero (π : Degree ≃o Degree) : π ⊥ = ⊥ := π.map_bot
123
+
124
+ end TuringRigidity
125
+
126
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/JumpIdeal.lean ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Constructibility.PersistentLocality
2
+ import OAI.Computability.DegreeRigidity.Representation.GlobalLocality
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity.JumpIdeal
7
+ open OracleJump IdealInterpretation IdealLocality PersistentRestrictions PersistentLocality GlobalLocality
8
+ noncomputable section
9
+
10
+ theorem iterate_monotone (x : Degree) : Monotone (degreeIterate x) := by
11
+ apply monotone_nat_of_le_succ
12
+ intro n
13
+ exact degree_le_jump _
14
+
15
+ def generated (x : Degree) : CountableIdeal where
16
+ carrier := {y | ∃ n, y ≤ degreeIterate x n}
17
+ nonempty := ⟨x,0,le_rfl⟩
18
+ countable := by
19
+ have he : {y | ∃ n, y ≤ degreeIterate x n} = ⋃ n, Set.Iic (degreeIterate x n) := by
20
+ ext y
21
+ simp only [Set.mem_ofPred_eq,Set.mem_iUnion,Set.mem_Iic]
22
+ rw [he]
23
+ exact Set.countable_iUnion (fun n => countable_principal_lower _)
24
+ lower := by
25
+ intro a b hab hb
26
+ obtain ⟨n,hn⟩ := hb
27
+ exact ⟨n,hab.trans hn⟩
28
+ join_mem := by
29
+ intro a b ha hb
30
+ obtain ⟨m,hm⟩ := ha
31
+ obtain ⟨n,hn⟩ := hb
32
+ exact ⟨max m n,sup_le (hm.trans (iterate_monotone x (le_max_left m n)))
33
+ (hn.trans (iterate_monotone x (le_max_right m n)))⟩
34
+
35
+ theorem includes (x : Degree) : x ∈ (generated x).carrier := ⟨0,le_rfl⟩
36
+
37
+ theorem closed (x : Degree) : JumpClosed (ideal (generated x)) := by
38
+ intro y hy
39
+ obtain ⟨n,hn⟩ := hy
40
+ exact ⟨n+1,degreeJump_mono hn⟩
41
+
42
+ theorem least (x : Degree) (J : DegreeIdeal) (hx : x ∈ J.carrier)
43
+ (hj : JumpClosed J) : (generated x).carrier ⊆ J.carrier := by
44
+ have hi (n : ℕ) : degreeIterate x n ∈ J.carrier := by
45
+ induction n with
46
+ | zero => exact hx
47
+ | succ n ih => exact hj _ ih
48
+ intro y hy
49
+ obtain ⟨n,hn⟩ := hy
50
+ exact J.lower hn (hi n)
51
+
52
+ end
53
+ end TuringRigidity.JumpIdeal
54
+
55
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/JumpIdealPresentation.lean ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticJumpBound
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.JumpIdealPresentation
6
+ open Encodable EncodedForcing OracleJump ArithmeticHierarchy IndexMatrix TableIndices
7
+ open PersistentRestrictions PersistentPresentation UniformArithmetic
8
+ noncomputable section
9
+
10
+ def omegaJump (X : Oracle) : Oracle := fun v => iterate X (Nat.unpair v).1 (Nat.unpair v).2
11
+
12
+ @[simp] theorem omegaJump_column (X : Oracle) (n : ℕ) :
13
+ columns (omegaJump X) n = iterate X n := by
14
+ funext k
15
+ simp [columns,omegaJump]
16
+
17
+ def presentation (X : Oracle) : Oracle := fun v =>
18
+ tableOracle (iterate X (Nat.unpair (Nat.unpair v).1).1)
19
+ (Nat.unpair (Nat.unpair v).1).2 (Nat.unpair v).2
20
+
21
+ @[simp] theorem presentation_column (X : Oracle) (n e : ℕ) :
22
+ columns (presentation X) (Nat.pair n e) = tableOracle (iterate X n) e := by
23
+ funext k
24
+ simp [columns,presentation]
25
+
26
+ theorem graph_sigma (Y : Oracle) (e : ℕ) : Sigma Y 1 (tableGraph Y e) := by
27
+ classical
28
+ have hr := IndexMatrix.run_uniform_recursive Y
29
+ have hf := UniformOracle.total_comp hr (UniformOracle.total_primrec
30
+ (Primrec₂.natPair.comp (Primrec.const e)
31
+ (Primrec₂.natPair.comp UniformArithmetic.left_primrec UniformArithmetic.right_primrec)))
32
+ have hcheck : Primrec (fun q : ℕ => if q = encode (some (1 : ℕ)) then 1 else 0) :=
33
+ Primrec.ite (Primrec.eq.comp Primrec.id (Primrec.const _)) (Primrec.const 1) (Primrec.const 0)
34
+ have h : RecursivePred Y (fun v => run Y (machine e) (Nat.unpair v).1 (Nat.unpair v).2 = some 1) := by
35
+ exact (UniformOracle.total_comp (UniformOracle.total_primrec hcheck) hf).of_eq
36
+ (fun v => by simp only [Nat.unpair_pair,Encodable.encode_injective.eq_iff,UniformArithmetic.left,UniformArithmetic.right]; split <;> simp_all)
37
+ exact (exists_form (n := 0) h).congr
38
+ (fun _ => by simp only [Nat.unpair_pair,tableGraph])
39
+
40
+ theorem tableOracle_reduces_jump (Y : Oracle) (e : ℕ) :
41
+ Reduces (tableOracle Y e) (jump Y) := by
42
+ apply RecursiveIn.iff_nat.mpr
43
+ exact (form_recursive (graph_sigma Y e)).of_eq
44
+ (fun v => by
45
+ classical
46
+ simp [oracleFunction,tableOracle])
47
+
48
+ theorem presents (X : Oracle) : Presented (JumpIdeal.generated (degree X)) (presentation X) := by
49
+ intro x
50
+ constructor
51
+ · rintro ⟨n,hn⟩
52
+ have hx : x ≤ degree (iterate X n) := by simpa only [GlobalLocality.degreeIterate_degree] using hn
53
+ obtain ⟨A,rfl⟩ := degree_surjective x
54
+ obtain ⟨d,hd⟩ := reduces_represents hx
55
+ have hd' : Represents (iterate X n) (machine (encode d)) A := by simpa using hd
56
+ refine ⟨Nat.pair n (encode d),?_⟩
57
+ rw [presentation_column,tableOracle_eq hd']
58
+ · rintro ⟨k,rfl⟩
59
+ obtain ⟨⟨n,e⟩,rfl⟩ := Nat.pairEquiv.surjective k
60
+ change degree (columns (presentation X) (Nat.pair n e)) ∈ _
61
+ rw [presentation_column]
62
+ refine ⟨n+1,?_⟩
63
+ simpa only [GlobalLocality.degreeIterate_degree,iterate,degree_le_iff] using tableOracle_reduces_jump (iterate X n) e
64
+
65
+ theorem presentation_arith : Arith (fun O v =>
66
+ tableOracle (columns (O 0) (Nat.unpair (Nat.unpair v).1).1)
67
+ (Nat.unpair (Nat.unpair v).1).2 (Nat.unpair v).2 = true) := by
68
+ have hB := column_arith (parameter_arith 0) UniformArithmetic.left_primrec
69
+ have h := tableOracle_arith hB UniformArithmetic.right_primrec
70
+ exact h
71
+
72
+ theorem presentation_bounded (X : Oracle) :
73
+ ∃ k, Reduces (presentation X) (iterate (omegaJump X) k) := by
74
+ obtain ⟨k,hk⟩ := presentation_arith.jump_bound
75
+ refine ⟨k,RecursiveIn.iff_nat.mpr ?_⟩
76
+ have h := hk (fun _ => omegaJump X) (omegaJump X) (fun _ => reduces_refl _)
77
+ exact h.of_eq (fun v => by
78
+ simp only [omegaJump_column]
79
+ by_cases value : presentation X v = true
80
+ · simp [oracleFunction,presentation] at value ⊢
81
+ simp [value]
82
+ · simp [oracleFunction,presentation] at value ⊢
83
+ simp [value])
84
+
85
+ end
86
+ end TuringRigidity.JumpIdealPresentation
87
+
88
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/JumpIterationFormula.lean ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.JumpSetFormula
2
+ import OAI.Computability.DegreeRigidity.SetModels.ModelIterationFormula
3
+
4
+ namespace OAI
5
+
6
+
7
+ namespace TuringRigidity.BoundedSetTheory
8
+ open UniformArithmetic OracleJump
9
+ universe u
10
+
11
+ def JumpFormula (φ : Formula) : Prop := ∀ o Q x y : ℕ, ∀ e : ℕ → ZFSet.{u},
12
+ e o = ZFSet.omega → (∀ f : ℕ → ℕ, ∀ k, finiteNaturalGraph f k ∈ e Q) →
13
+ ∀ A B : Oracle, e x = realCode A → e y = realCode B →
14
+ ((Formula.oracleGraph φ o Q x y).Eval e ↔ B = jump A)
15
+
16
+ namespace Formula
17
+ def jumpIteration (φ : Formula) (o R Qf Qn n A B : ℕ) : Formula :=
18
+ modelIteration o R Qf n A B (oracleGraph φ (o+3) (Qn+3) 1 0)
19
+
20
+ theorem jumpIteration_spec {φ : Formula} (hφ : JumpFormula.{u} φ)
21
+ (o R Qf Qn n x y : ℕ) (e : ℕ → ZFSet.{u}) (ho : e o = ZFSet.omega)
22
+ (hQn : ∀ f : ℕ → ℕ, ∀ k, finiteNaturalGraph f k ∈ e Qn)
23
+ (hQf : ∀ a : ℕ → ZFSet.{u}, (∀ i, a i ∈ e R) → ∀ k, finiteModelGraph a k ∈ e Qf)
24
+ (hR : ∀ w ∈ e R, ∃ B : Oracle, realCode B = w)
25
+ (A : Oracle) (hA : ∀ i, realCode (iterate A i) ∈ e R)
26
+ (hx : e x = realCode A) (N : ℕ) (hn : e n = natSet N) :
27
+ (jumpIteration φ o R Qf Qn n x y).Eval e ↔ e y = realCode (iterate A N) := by
28
+ apply modelIteration_spec o R Qf n x y _ e ho hQf N hn
29
+ (fun i => realCode (iterate A i)) hA hx
30
+ intro i w hw
31
+ obtain ⟨B,rfl⟩ := hR w hw
32
+ rw [hφ (o+3) (Qn+3) 1 0 (cons (realCode B) (cons (realCode (iterate A i)) (cons (natSet i) e)))
33
+ ho hQn (iterate A i) B rfl rfl]
34
+ exact ⟨fun h => congrArg realCode h,fun h => realCode_injective h⟩
35
+ end Formula
36
+
37
+ end TuringRigidity.BoundedSetTheory
38
+
39
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/JumpProperties.lean ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.OracleJump
2
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticAtoms
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity.OracleJump
7
+ open Encodable UniformOracle CommonIdeal TableIndices IndexMatrix ArithmeticHierarchy
8
+
9
+ theorem recursive_transfer {Y Z : Oracle} {P : ℕ → Prop}
10
+ (h : RecursivePred Y P) (hYZ : Reduces Y Z) : RecursivePred Z P :=
11
+ RecursiveIn.iff_nat.mp (TuringReducible.trans (RecursiveIn.iff_nat.mpr h) hYZ)
12
+
13
+ theorem recursive_lift {Y : Oracle} {P : ℕ → Prop} (h : RecursivePred Y P) :
14
+ RecursivePred (jump Y) P := by
15
+ have hh := exists_recursive_jump (recursive_comp h (Primrec.fst.comp Primrec.unpair))
16
+ exact Form.congr (n := 0) (s := true) hh (fun x => by simp)
17
+
18
+ theorem reduces_jump (Y : Oracle) : Reduces Y (jump Y) := by
19
+ have h : RecursivePred Y (fun x => Y x = true) := by
20
+ classical
21
+ have hq : Nat.RecursiveIn {oracleFunction Y} (oracleFunction Y) :=
22
+ .oracle _ (Set.mem_singleton _)
23
+ exact hq.of_eq (fun x => by cases hy : Y x <;> simp [oracleFunction,hy])
24
+ apply RecursiveIn.iff_nat.mpr
25
+ exact (recursive_lift h).of_eq (fun x => by cases hy : Y x <;> simp [oracleFunction,hy])
26
+
27
+ theorem halts_sigma (Y : Oracle) :
28
+ Sigma Y 1 (fun v => Halts Y (Nat.unpair v).1 (Nat.unpair v).2) := by
29
+ classical
30
+ let f := Primrec.fst.comp Primrec.unpair
31
+ let s := Primrec.snd.comp Primrec.unpair
32
+ have ht := total_comp (run_uniform_recursive Y) (total_primrec
33
+ (Primrec₂.natPair.comp (f.comp f) (Primrec₂.natPair.comp (s.comp f) s)))
34
+ have hcheck : Primrec (fun v : ℕ => bit ((decode (α := Option ℕ) v).getD none).isSome) :=
35
+ bit_primrec.comp (Primrec.option_isSome.comp
36
+ (Primrec.option_getD.comp Primrec.decode (Primrec.const none)))
37
+ have h : RecursivePred Y (fun v =>
38
+ (TableIndices.run Y (machine (Nat.unpair (Nat.unpair v).1).1)
39
+ (Nat.unpair (Nat.unpair v).1).2 (Nat.unpair v).2).isSome = true) := by
40
+ exact (total_comp (total_primrec hcheck) ht).of_eq (fun v => by
41
+ simp only [Nat.unpair_pair, encodek, Option.getD_some, bit]
42
+ congr 1
43
+ split <;> rfl)
44
+ apply (exists_form (n := 0) h).congr
45
+ intro v
46
+ simp only [Nat.unpair_pair, Halts]
47
+ apply exists_congr
48
+ intro z
49
+ cases TableIndices.run Y (machine (Nat.unpair v).1) (Nat.unpair v).2 z <;> simp
50
+
51
+ theorem jump_mono {Y Z : Oracle} (hYZ : Reduces Y Z) : Reduces (jump Y) (jump Z) := by
52
+ obtain ⟨Q,hQ,he⟩ := halts_sigma Y
53
+ have h := exists_recursive_jump (recursive_transfer hQ hYZ)
54
+ have h' : RecursivePred (jump Z) (fun v => Halts Y (Nat.unpair v).1 (Nat.unpair v).2) :=
55
+ Form.congr (n := 0) (s := true) h (fun v => (he v).symm)
56
+ apply RecursiveIn.iff_nat.mpr
57
+ exact h'.of_eq (fun v => by
58
+ classical
59
+ by_cases h : Halts Y (Nat.unpair v).1 (Nat.unpair v).2 <;> simp [oracleFunction, jump, h])
60
+
61
+ theorem iterate_mono {Y Z : Oracle} (hYZ : Reduces Y Z) (n : ℕ) :
62
+ Reduces (iterate Y n) (iterate Z n) := by
63
+ induction n with
64
+ | zero => exact hYZ
65
+ | succ n ih => exact jump_mono ih
66
+
67
+ noncomputable def degreeJump (x : Degree) : Degree :=
68
+ Quotient.liftOn x (fun Y => degree (jump Y)) (fun Y Z h =>
69
+ (degree_eq_iff (jump Y) (jump Z)).mpr ⟨jump_mono h.1, jump_mono h.2⟩)
70
+
71
+ @[simp] theorem degreeJump_degree (Y : Oracle) : degreeJump (degree Y) = degree (jump Y) := rfl
72
+
73
+ theorem degree_le_jump (x : Degree) : x ≤ degreeJump x := by
74
+ obtain ⟨Y,rfl⟩ := degree_surjective x
75
+ exact reduces_jump Y
76
+
77
+ theorem degreeJump_mono : Monotone degreeJump := by
78
+ intro x y h
79
+ obtain ⟨Y,rfl⟩ := degree_surjective x
80
+ obtain ⟨Z,rfl⟩ := degree_surjective y
81
+ exact jump_mono h
82
+
83
+ end TuringRigidity.OracleJump
84
+
85
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/JumpSetFormula.lean ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.SetModels.ModelRealOperations
2
+
3
+ namespace OAI
4
+
5
+
6
+ namespace TuringRigidity.BoundedSetTheory
7
+ open UniformArithmetic OracleJump
8
+ universe u
9
+
10
+ namespace Formula
11
+ def singleOracleVars (o Q A n : ℕ) : ℕ → ℕ
12
+ | 0 => n
13
+ | 1 => o
14
+ | 2 => Q
15
+ | _+3 => A
16
+
17
+ def singleOracle (φ : Formula) (o Q A n : ℕ) : Formula := φ.rename (singleOracleVars o Q A n)
18
+
19
+ theorem singleOracle_spec {φ : Formula} {P : Predicate} (hφ : DefinesArithmetic.{u} φ P)
20
+ (o Q A n : ℕ) (e : ℕ → ZFSet.{u}) (ho : e o = ZFSet.omega)
21
+ (hQ : ∀ f : ℕ → ℕ, ∀ k, finiteNaturalGraph f k ∈ e Q)
22
+ (B : Oracle) (hA : e A = realCode B) (N : ℕ) (hn : e n = natSet N) :
23
+ (singleOracle φ o Q A n).Eval e ↔ P (fun _ => B) N := by
24
+ rw [singleOracle,eval_rename]
25
+ have he : (fun i => e (singleOracleVars o Q A n i)) = arithmeticEnv (e Q) (fun _ => B) N := by
26
+ funext i
27
+ rcases i with _|i; exact hn
28
+ rcases i with _|i; exact ho
29
+ rcases i with _|i; rfl
30
+ exact hA
31
+ rw [he]
32
+ exact hφ _ hQ _ _
33
+
34
+ def oracleGraph (φ : Formula) (o Q A B : ℕ) : Formula :=
35
+ allMem o (iff (.member 0 (B+1)) (singleOracle φ (o+1) (Q+1) (A+1) 0))
36
+
37
+ theorem oracleGraph_spec {φ : Formula} {P : Predicate} (hφ : DefinesArithmetic.{u} φ P)
38
+ (o Q x y : ℕ) (e : ℕ → ZFSet.{u}) (ho : e o = ZFSet.omega)
39
+ (hQ : ∀ f : ℕ → ℕ, ∀ k, finiteNaturalGraph f k ∈ e Q)
40
+ (A B : Oracle) (hx : e x = realCode A) (hy : e y = realCode B) :
41
+ (oracleGraph φ o Q x y).Eval e ↔ ∀ n, B n = true ↔ P (fun _ => A) n := by
42
+ simp only [oracleGraph,eval_allMem,eval_iff,Formula.Eval,cons_zero,cons_succ]
43
+ rw [ho]
44
+ constructor
45
+ · intro h n
46
+ have hn := h (natSet n) ((mem_omega _).mpr ⟨n,rfl⟩)
47
+ rw [hy,natSet_mem_realCode] at hn
48
+ exact hn.trans (singleOracle_spec hφ (o+1) (Q+1) (x+1) 0 (cons (natSet n) e) ho hQ A hx n rfl)
49
+ · intro h z hz
50
+ obtain ⟨n,rfl⟩ := (mem_omega z).mp hz
51
+ rw [hy,natSet_mem_realCode]
52
+ exact (h n).trans (singleOracle_spec hφ (o+1) (Q+1) (x+1) 0 (cons (natSet n) e) ho hQ A hx n rfl).symm
53
+ end Formula
54
+
55
+ theorem jump_bounded_relation : ∃ φ : Formula, ∀ o Q x y : ℕ, ∀ e : ℕ → ZFSet.{u},
56
+ e o = ZFSet.omega → (∀ f : ℕ → ℕ, ∀ k, finiteNaturalGraph f k ∈ e Q) →
57
+ ∀ A B : Oracle, e x = realCode A → e y = realCode B →
58
+ ((Formula.oracleGraph φ o Q x y).Eval e ↔ B = jump A) := by
59
+ have h := Arith.comp (fun n => Nat.pair 0 n) (jump_arith (parameter_arith 0))
60
+ (Primrec₂.natPair.comp (Primrec.const 0) Primrec.id)
61
+ have hp : Arith (fun O n => jump (O 0) n = true) := h.congr (fun _ _ => by simp only [right,Nat.unpair_pair])
62
+ obtain ⟨φ,hφ⟩ := arithmetic_bounded_definition.{u} hp
63
+ refine ⟨φ,?_⟩
64
+ intro o Q x y e ho hQ A B hx hy
65
+ rw [Formula.oracleGraph_spec hφ o Q x y e ho hQ A B hx hy]
66
+ constructor
67
+ · intro hb
68
+ funext n
69
+ have hn := hb n
70
+ cases ha : B n <;> cases hj : jump A n <;> simp_all
71
+ · intro hb; subst B; exact fun _ => Iff.rfl
72
+
73
+ end TuringRigidity.BoundedSetTheory
74
+
75
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/NormalizedRecovery.lean ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Effective.StageNormalization
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity.NormalizedRecovery
6
+ open EncodedForcing Encodable UniformOracle Introreducible StageNormalization
7
+
8
+ def trial (B : Oracle) (n c : ℕ) : Option ℕ :=
9
+ if B (Nat.pair (Nat.unpair n).1 c) = true ∧ (Nat.unpair n).2 < codeLength c
10
+ then some (codeBit (Nat.unpair n).2 c) else none
11
+
12
+ theorem trial_recursive (B : Oracle) :
13
+ Nat.RecursiveIn {oracleFunction B} (fun v => Part.some (encode (trial B (Nat.unpair v).1 (Nat.unpair v).2))) := by
14
+ let f := Primrec.fst.comp Primrec.unpair
15
+ let r := Primrec.snd.comp Primrec.unpair
16
+ have hq : Nat.RecursiveIn {oracleFunction B} (oracleFunction B) := .oracle _ (Set.mem_singleton _)
17
+ have hb := total_comp hq (total_primrec (Primrec₂.natPair.comp (f.comp f) r))
18
+ let n := r.comp (f.comp f)
19
+ let c := r.comp f
20
+ have hpost := Primrec.encode.comp (Primrec.ite
21
+ ((Primrec.eq.comp r (Primrec.const 1)).and (Primrec.nat_lt.comp n (codeLength_primrec.comp c)))
22
+ (Primrec.option_some.comp (codeBit_primrec.comp n c)) (Primrec.const none))
23
+ exact (total_comp (total_primrec hpost) (total_pair (total_primrec Primrec.id) hb)).of_eq
24
+ (fun v => by cases h : B (Nat.pair (Nat.unpair (Nat.unpair v).1).1 (Nat.unpair v).2) <;>
25
+ simp [trial,h])
26
+
27
+ theorem normalized_inverse (A : Oracle) : Reduces A (normalized A) := by
28
+ apply RecursiveIn.iff_nat.mpr
29
+ change Nat.RecursiveIn {oracleFunction (normalized A)} (fun n => Part.some (bit A n))
30
+ apply total_search (trial_recursive (normalized A)) (bit A)
31
+ · intro n c a ha
32
+ simp only [trial] at ha
33
+ split at ha
34
+ next h =>
35
+ have he : prefixCode (columns A (Nat.unpair n).1) (codeLength c) = c := by
36
+ simpa [normalized,prefixSet] using h.1
37
+ have ha' : a = codeBit (Nat.unpair n).2 c := (Option.mem_some_iff.mp ha).symm
38
+ rw [ha',← he,codeBit_prefix _ _ _ h.2]
39
+ simp [bit,columns,Nat.pair_unpair]
40
+ next h => simp at ha
41
+ · intro n
42
+ let c := prefixCode (columns A (Nat.unpair n).1) ((Nat.unpair n).2+1)
43
+ refine ⟨c,codeBit (Nat.unpair n).2 c,?_⟩
44
+ simp [trial,normalized,c]
45
+
46
+ end TuringRigidity.NormalizedRecovery
47
+
48
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/OracleCode.lean ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.SetModels.Degrees
2
+ import Mathlib.Tactic.DeriveEncodable
3
+ import Mathlib.Data.Set.Countable
4
+
5
+ namespace OAI
6
+
7
+ namespace TuringRigidity
8
+
9
+ inductive OracleCode where
10
+ | zero | succ | left | right | query
11
+ | pair : OracleCode → OracleCode → OracleCode
12
+ | comp : OracleCode → OracleCode → OracleCode
13
+ | prec : OracleCode → OracleCode → OracleCode
14
+ | find : OracleCode → OracleCode
15
+ deriving Encodable
16
+
17
+ namespace OracleCode
18
+
19
+ def eval (g : ℕ →. ℕ) : OracleCode → ℕ →. ℕ
20
+ | .zero => fun _ => 0
21
+ | .succ => Nat.succ
22
+ | .left => fun n => (Nat.unpair n).1
23
+ | .right => fun n => (Nat.unpair n).2
24
+ | .query => g
25
+ | .pair c d => fun n => Nat.pair <$> eval g c n <*> eval g d n
26
+ | .comp c d => fun n => eval g d n >>= eval g c
27
+ | .prec c d => fun p =>
28
+ let (a, n) := Nat.unpair p
29
+ n.rec (eval g c a) fun y ih => do
30
+ let i ← ih
31
+ eval g d (Nat.pair a (Nat.pair y i))
32
+ | .find c => fun a =>
33
+ Nat.rfind fun n => (fun m => m = 0) <$> eval g c (Nat.pair a n)
34
+
35
+ theorem eval_recursiveIn (g : ℕ →. ℕ) (c : OracleCode) :
36
+ Nat.RecursiveIn {g} (eval g c) := by
37
+ induction c with
38
+ | zero => exact .zero
39
+ | succ => exact .succ
40
+ | left => exact .left
41
+ | right => exact .right
42
+ | query => exact .oracle g (Set.mem_singleton g)
43
+ | pair c d hc hd => exact .pair hc hd
44
+ | comp c d hc hd => exact .comp hc hd
45
+ | prec c d hc hd => exact .prec hc hd
46
+ | find c hc => exact .rfind hc
47
+
48
+ theorem exists_code {g f : ℕ →. ℕ} (hf : Nat.RecursiveIn {g} f) :
49
+ ∃ c : OracleCode, eval g c = f := by
50
+ induction hf with
51
+ | zero => exact ⟨.zero, rfl⟩
52
+ | succ => exact ⟨.succ, rfl⟩
53
+ | left => exact ⟨.left, rfl⟩
54
+ | right => exact ⟨.right, rfl⟩
55
+ | oracle f hf =>
56
+ have hfg : f = g := Set.mem_singleton_iff.mp hf
57
+ subst f
58
+ exact ⟨.query, rfl⟩
59
+ | pair _ _ hc hd =>
60
+ obtain ⟨c, rfl⟩ := hc
61
+ obtain ⟨d, rfl⟩ := hd
62
+ exact ⟨.pair c d, rfl⟩
63
+ | comp _ _ hc hd =>
64
+ obtain ⟨c, rfl⟩ := hc
65
+ obtain ⟨d, rfl⟩ := hd
66
+ exact ⟨.comp c d, rfl⟩
67
+ | prec _ _ hc hd =>
68
+ obtain ⟨c, rfl⟩ := hc
69
+ obtain ⟨d, rfl⟩ := hd
70
+ exact ⟨.prec c d, rfl⟩
71
+ | rfind _ hc =>
72
+ obtain ⟨c, rfl⟩ := hc
73
+ exact ⟨.find c, rfl⟩
74
+
75
+ theorem turingReducible_iff_exists_code (f g : ℕ →. ℕ) :
76
+ TuringReducible f g ↔ ∃ c : OracleCode, eval g c = f := by
77
+ change RecursiveIn {g} f ↔ _
78
+ rw [RecursiveIn.iff_nat]
79
+ exact ⟨exists_code, fun ⟨c, hc⟩ => hc ▸ eval_recursiveIn g c⟩
80
+
81
+ theorem countable_reducible (g : ℕ →. ℕ) :
82
+ {f : ℕ →. ℕ | TuringReducible f g}.Countable := by
83
+ have heq : {f : ℕ →. ℕ | TuringReducible f g} = Set.range (eval g) := by
84
+ ext f
85
+ exact turingReducible_iff_exists_code f g
86
+ rw [heq]
87
+ exact Set.countable_range _
88
+
89
+ end OracleCode
90
+
91
+ theorem oracleFunction_injective : Function.Injective oracleFunction := by
92
+ intro A B hab
93
+ funext n
94
+ have h := congrFun hab n
95
+ cases ha : A n <;> cases hb : B n <;> simp [oracleFunction, ha, hb] at h ⊢
96
+
97
+ theorem countable_reduces (B : Oracle) : {A : Oracle | Reduces A B}.Countable := by
98
+ exact (OracleCode.countable_reducible (oracleFunction B)).preimage oracleFunction_injective
99
+
100
+ theorem countable_degree_fiber (a : Degree) : {A : Oracle | degree A = a}.Countable := by
101
+ obtain ⟨B, rfl⟩ := degree_surjective a
102
+ apply (countable_reduces B).mono
103
+ intro A hA
104
+ exact ((degree_eq_iff A B).mp hA).1
105
+
106
+ theorem countable_lift_fiber {X : Type*} (C : X → Oracle) (hC : Function.Injective C)
107
+ (π : Degree → Degree) (hπ : Function.Injective π)
108
+ (F : X → Oracle) (hF : ∀ x, degree (F x) = π (degree (C x))) (B : Oracle) :
109
+ {x : X | F x = B}.Countable := by
110
+ by_cases hne : ∃ x, F x = B
111
+ · obtain ⟨x₀, hx₀⟩ := hne
112
+ apply ((countable_degree_fiber (degree (C x₀))).preimage hC).mono
113
+ intro x hx
114
+ apply hπ
115
+ rw [← hF x, ← hF x₀, hx, hx₀]
116
+ · have hempty : {x : X | F x = B} = ∅ := by
117
+ ext x
118
+ simp only [Set.mem_ofPred_eq, Set.mem_empty_iff_false, iff_false]
119
+ exact fun h => hne ⟨x,h⟩
120
+ rw [hempty]
121
+ exact Set.countable_empty
122
+
123
+ end TuringRigidity
124
+
125
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/OracleEnumeration.lean ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Effective.PrefixComputability
2
+ import Mathlib.Data.Set.Finite.Range
3
+ import Lean.Elab.Tactic.Omega
4
+
5
+ namespace OAI
6
+
7
+ namespace TuringRigidity.OracleEnumeration
8
+ open PrefixComputability
9
+
10
+ theorem exists_ge {A : Oracle} (hA : {n | A n = true}.Infinite) (n : ℕ) :
11
+ ∃ m, n ≤ m ∧ A m = true := by
12
+ by_contra h
13
+ apply hA
14
+ apply (Set.finite_le_nat n).subset
15
+ intro m hm
16
+ exact Nat.le_of_lt (Nat.lt_of_not_ge (fun hnm => h ⟨m, hnm, hm⟩))
17
+
18
+ noncomputable def next (A : Oracle) (hA : {n | A n = true}.Infinite) (n : ℕ) : ℕ :=
19
+ Nat.find (exists_ge hA n)
20
+
21
+ theorem next_spec (A : Oracle) (hA : {n | A n = true}.Infinite) (n : ℕ) :
22
+ n ≤ next A hA n ∧ A (next A hA n) = true := Nat.find_spec (exists_ge hA n)
23
+
24
+ theorem next_min (A : Oracle) (hA : {n | A n = true}.Infinite) (n m : ℕ)
25
+ (hm : n ≤ m) (hAm : A m = true) : next A hA n ≤ m :=
26
+ Nat.find_min' (exists_ge hA n) ⟨hm, hAm⟩
27
+
28
+ private def searchFlag (p : ℕ) : ℕ :=
29
+ if (Nat.unpair p).1 ≤ (Nat.unpair (Nat.unpair p).2).1 ∧
30
+ (Nat.unpair (Nat.unpair p).2).2 = 1 then 0 else 1
31
+
32
+ private theorem searchFlag_primrec : Primrec searchFlag := by
33
+ exact Primrec.ite ((Primrec.nat_le.comp (Primrec.fst.comp Primrec.unpair)
34
+ (Primrec.fst.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))).and
35
+ (Primrec.eq.comp (Primrec.snd.comp (Primrec.unpair.comp (Primrec.snd.comp Primrec.unpair)))
36
+ (Primrec.const 1))) (Primrec.const 0) (Primrec.const 1)
37
+
38
+ theorem next_recursive (A : Oracle) (hA : {n | A n = true}.Infinite) :
39
+ Nat.RecursiveIn {oracleFunction A} (fun n => Part.some (next A hA n)) := by
40
+ have hq : Nat.RecursiveIn {oracleFunction A} (oracleFunction A) :=
41
+ .oracle _ (Set.mem_singleton _)
42
+ have hn := total_primrec (O := {oracleFunction A}) (Primrec.fst.comp Primrec.unpair)
43
+ have hm := total_primrec (O := {oracleFunction A}) (Primrec.snd.comp Primrec.unpair)
44
+ have hf := total_comp (total_primrec searchFlag_primrec)
45
+ (total_pair hn (total_pair hm (total_comp hq hm)))
46
+ apply (Nat.RecursiveIn.rfind hf).of_eq_tot
47
+ intro n
48
+ apply Nat.mem_rfind.mpr
49
+ constructor
50
+ · have hs := next_spec A hA n
51
+ simp [searchFlag, hs.1, hs.2]
52
+ · intro m hm'
53
+ have hh : ¬(n ≤ m ∧ A m = true) := Nat.find_min (exists_ge hA n) hm'
54
+ cases ha : A m <;> simp_all [searchFlag]
55
+
56
+ noncomputable def enumerate (A : Oracle) (hA : {n | A n = true}.Infinite) : ℕ → ℕ
57
+ | 0 => next A hA 0
58
+ | n+1 => next A hA (enumerate A hA n + 1)
59
+
60
+ theorem enumerate_mem (A : Oracle) (hA : {n | A n = true}.Infinite) (n : ℕ) :
61
+ A (enumerate A hA n) = true := by
62
+ cases n <;> exact (next_spec A hA _).2
63
+
64
+ theorem enumerate_strictMono (A : Oracle) (hA : {n | A n = true}.Infinite) :
65
+ StrictMono (enumerate A hA) := by
66
+ apply strictMono_nat_of_lt_succ
67
+ intro n
68
+ exact (Nat.lt_succ_self _).trans_le (next_spec A hA _).1
69
+
70
+ theorem le_enumerate (A : Oracle) (hA : {n | A n = true}.Infinite) (n : ℕ) :
71
+ n ≤ enumerate A hA n := (enumerate_strictMono A hA).id_le n
72
+
73
+ theorem enumerate_recursive (A : Oracle) (hA : {n | A n = true}.Infinite) :
74
+ Nat.RecursiveIn {oracleFunction A} (fun n => Part.some (enumerate A hA n)) := by
75
+ have hnext := next_recursive A hA
76
+ have hbase := total_comp hnext (total_primrec (Primrec.const 0))
77
+ have hstep := total_comp hnext (total_primrec
78
+ (Primrec.succ.comp (Primrec.snd.comp (Primrec.unpair.comp
79
+ (Primrec.snd.comp Primrec.unpair)))))
80
+ have hrec := Nat.RecursiveIn.prec hbase hstep
81
+ have hr := Nat.RecursiveIn.comp hrec
82
+ (total_pair (total_primrec (Primrec.const 0)) (total_primrec Primrec.id))
83
+ apply hr.of_eq
84
+ intro n
85
+ change (Part.some (Nat.pair 0 n)).bind _ = _
86
+ rw [Part.bind_some]
87
+ simp only [Nat.unpair_pair]
88
+ induction n with
89
+ | zero => rfl
90
+ | succ n ih =>
91
+ simp only [ih]
92
+ simp [enumerate]
93
+
94
+ end TuringRigidity.OracleEnumeration
95
+
96
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/OracleJump.lean ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.ArithmeticHierarchy
2
+ import OAI.Computability.DegreeRigidity.OrdinalCodes.IndexMatrix
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity.OracleJump
7
+ open Encodable UniformOracle CommonIdeal TableIndices IndexMatrix ArithmeticHierarchy
8
+
9
+ def Halts (Y : Oracle) (e n : ℕ) : Prop := ∃ z a, a ∈ TableIndices.run Y (machine e) n z
10
+
11
+ noncomputable def jump (Y : Oracle) : Oracle := by
12
+ classical
13
+ exact fun v => decide (Halts Y (Nat.unpair v).1 (Nat.unpair v).2)
14
+
15
+ theorem partial_table {Y : Oracle} {f : ℕ →. ℕ}
16
+ (hf : Nat.RecursiveIn {oracleFunction Y} f) :
17
+ ∃ e, ∀ n, Halts Y e n ↔ (f n).Dom := by
18
+ obtain ⟨c, hc⟩ := OracleCode.exists_code hf
19
+ have hh : Partrec₂ (fun L : List ℕ => fun n => OracleCode.eval (BranchMachine.lookup L) c n) :=
20
+ OracleCode.eval_partrec BranchMachine.lookup_partrec c
21
+ obtain ⟨d, hd⟩ := partrec_code hh
22
+ have hd' : ∀ L n, d.eval (Nat.pair (encode L) n) = OracleCode.eval (BranchMachine.lookup L) c n :=
23
+ fun L n => hd (L,n)
24
+ have ha (n : ℕ) : Approximates (f n)
25
+ (fun m => d.eval (Nat.pair (encode (oraclePrefix (fun k => bit (Y k)) m)) n)) := by
26
+ simp only [hd', ← hc]
27
+ exact OracleCode.eval_approximates (prefix_approximates (fun k => bit (Y k))) c n
28
+ refine ⟨encode d, fun n => ?_⟩
29
+ constructor
30
+ · rintro ⟨z,a,ha'⟩
31
+ simp only [machine_encode] at ha'
32
+ exact ((ha n).1 (Nat.unpair z).1 a (Nat.Partrec.Code.evaln_sound ha')).1
33
+ · intro hf'
34
+ obtain ⟨m,hm⟩ := (ha n).2 ((f n).get hf') ⟨hf',rfl⟩
35
+ obtain ⟨t,ht⟩ := Nat.Partrec.Code.evaln_complete.mp (hm m le_rfl)
36
+ exact ⟨Nat.pair m t, (f n).get hf', by simpa [TableIndices.run, trial] using ht⟩
37
+
38
+ theorem domain_recursive_jump {Y : Oracle} {f : ℕ →. ℕ}
39
+ (hf : Nat.RecursiveIn {oracleFunction Y} f) :
40
+ RecursivePred (jump Y) (fun n => (f n).Dom) := by
41
+ classical
42
+ obtain ⟨e,he⟩ := partial_table hf
43
+ have hq : Nat.RecursiveIn {oracleFunction (jump Y)} (oracleFunction (jump Y)) :=
44
+ .oracle _ (Set.mem_singleton _)
45
+ have h := Nat.RecursiveIn.comp hq (total_primrec (Primrec₂.natPair.comp (Primrec.const e) Primrec.id))
46
+ exact h.of_eq (fun n => by
47
+ change (Part.some (Nat.pair e n)).bind
48
+ (fun input => Part.some (if jump Y input then 1 else 0)) = _
49
+ rw [Part.bind_some]
50
+ simp [jump, he])
51
+
52
+ theorem exists_recursive_jump {Y : Oracle} {P : ℕ → Prop} (hP : RecursivePred Y P) :
53
+ RecursivePred (jump Y) (fun x => ∃ a, P (Nat.pair x a)) := by
54
+ classical
55
+ have hN := recursive_not hP
56
+ have hs := Nat.RecursiveIn.rfind hN
57
+ have hd := domain_recursive_jump hs
58
+ apply Form.congr (n := 0) (s := true) hd
59
+ intro x
60
+ erw [Nat.rfind_dom]
61
+ simp
62
+
63
+ theorem forall_recursive_jump {Y : Oracle} {P : ℕ → Prop} (hP : RecursivePred Y P) :
64
+ RecursivePred (jump Y) (fun x => ∀ a, P (Nat.pair x a)) := by
65
+ have h := recursive_not (exists_recursive_jump (recursive_not hP))
66
+ simpa only [not_exists, not_not] using h
67
+
68
+ noncomputable def iterate (Y : Oracle) : ℕ → Oracle
69
+ | 0 => Y
70
+ | n+1 => jump (iterate Y n)
71
+
72
+ theorem form_recursive {Y n s P} (h : Form Y n s P) : RecursivePred (iterate Y n) P := by
73
+ induction n generalizing s P with
74
+ | zero => exact h
75
+ | succ n ih =>
76
+ obtain ⟨Q,hQ,he⟩ := h
77
+ have hr := ih hQ
78
+ cases s with
79
+ | false =>
80
+ have hh := forall_recursive_jump hr
81
+ have he' : (fun x => ∀ a, Q (Nat.pair x a)) = P := funext (fun x => propext (he x).symm)
82
+ exact he' ▸ hh
83
+ | true =>
84
+ have hh := exists_recursive_jump hr
85
+ have he' : (fun x => ∃ a, Q (Nat.pair x a)) = P := funext (fun x => propext (he x).symm)
86
+ exact he' ▸ hh
87
+
88
+ end TuringRigidity.OracleJump
89
+
90
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/RationalCoding.lean ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.Cuts
2
+ import Mathlib.Computability.Primrec.List
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity
7
+ open Encodable
8
+
9
+ namespace RationalCoding
10
+
11
+ def magnitude (n : ℕ) : ℕ := n/2+n%2
12
+
13
+ theorem magnitude_primrec : Primrec magnitude :=
14
+ Primrec.nat_add.comp (Primrec.nat_div.comp Primrec.id (Primrec.const 2))
15
+ (Primrec.nat_mod.comp Primrec.id (Primrec.const 2))
16
+
17
+ theorem encode_int_nonneg (n : ℕ) : encode (Int.ofNat n) = 2*n := by
18
+ change Nat.bit false n = 2*n
19
+ simp [Nat.bit]
20
+
21
+ theorem encode_int_neg (n : ℕ) : encode (Int.negSucc n) = 2*n+1 := by
22
+ change Nat.bit true n = 2*n+1
23
+ simp [Nat.bit]
24
+
25
+ theorem magnitude_encode_int (z : ℤ) : magnitude (encode z) = z.natAbs := by
26
+ cases z with
27
+ | ofNat n =>
28
+ change magnitude (encode (Int.ofNat n)) = n
29
+ rw [encode_int_nonneg]
30
+ simp [magnitude]
31
+ | negSucc n => simp [encode_int_neg,magnitude]; omega
32
+
33
+ theorem encode_rat (q : ℚ) : encode q = Nat.pair (encode q.num) q.den := rfl
34
+
35
+ def valid (n : ℕ) : Prop :=
36
+ 0 < (Nat.unpair n).2 ∧ (magnitude (Nat.unpair n).1).Coprime (Nat.unpair n).2
37
+
38
+ instance (n : ℕ) : Decidable (valid n) := inferInstanceAs (Decidable (_ ∧ _))
39
+
40
+ theorem valid_iff (n : ℕ) : valid n ↔ ∃ q : ℚ, encode q = n := by
41
+ constructor
42
+ · rintro ⟨hd,hcop⟩
43
+ let z := Equiv.intEquivNat.symm (Nat.unpair n).1
44
+ have hz : encode z = (Nat.unpair n).1 := Equiv.intEquivNat.apply_symm_apply _
45
+ have hm : z.natAbs = magnitude (Nat.unpair n).1 := by rw [←hz,magnitude_encode_int]
46
+ let q : ℚ := ⟨z,(Nat.unpair n).2,Nat.ne_of_gt hd,hm.symm ▸ hcop⟩
47
+ refine ⟨q,?_⟩
48
+ rw [encode_rat]
49
+ change Nat.pair (encode z) (Nat.unpair n).2 = n
50
+ rw [hz,Nat.pair_unpair]
51
+ · rintro ⟨q,rfl⟩
52
+ simp only [valid,encode_rat,Nat.unpair_pair,magnitude_encode_int]
53
+ exact ⟨q.den_pos,q.reduced⟩
54
+
55
+ theorem coprime_bounded (a b : ℕ) :
56
+ (0 < b ∧ a.Coprime b) ↔
57
+ (0 < b ∧ ∀ k ∈ List.range (b+1), a%k ≠ 0 ∨ b%k ≠ 0 ∨ k=1) := by
58
+ constructor
59
+ · rintro ⟨hb,hc⟩
60
+ refine ⟨hb,fun k _hk => ?_⟩
61
+ by_cases ha : a%k = 0
62
+ · by_cases hb' : b%k = 0
63
+ · exact Or.inr (Or.inr (Nat.dvd_one.mp (by
64
+ rw [←hc]
65
+ exact Nat.dvd_gcd (Nat.dvd_of_mod_eq_zero ha) (Nat.dvd_of_mod_eq_zero hb'))))
66
+ · exact Or.inr (Or.inl hb')
67
+ · exact Or.inl ha
68
+ · rintro ⟨hb,h⟩
69
+ refine ⟨hb,?_⟩
70
+ have hg : a.gcd b ∈ List.range (b+1) := by
71
+ simp only [List.mem_range,Nat.lt_succ_iff]
72
+ exact Nat.gcd_le_right a hb
73
+ have hh := h (a.gcd b) hg
74
+ simpa [Nat.mod_eq_zero_of_dvd (Nat.gcd_dvd_left a b),
75
+ Nat.mod_eq_zero_of_dvd (Nat.gcd_dvd_right a b)] using hh
76
+
77
+ theorem coprime_positive_primrec : PrimrecPred (fun p : ℕ × ℕ => 0 < p.2 ∧ p.1.Coprime p.2) := by
78
+ have hr : PrimrecRel (fun k (p : ℕ × ℕ) => p.1%k ≠ 0 ∨ p.2%k ≠ 0 ∨ k=1) :=
79
+ ((Primrec.eq.comp (Primrec.nat_mod.comp (Primrec.fst.comp Primrec.snd) Primrec.fst)
80
+ (Primrec.const 0)).not).or
81
+ (((Primrec.eq.comp (Primrec.nat_mod.comp (Primrec.snd.comp Primrec.snd) Primrec.fst)
82
+ (Primrec.const 0)).not).or (Primrec.eq.comp Primrec.fst (Primrec.const 1)))
83
+ have hh := (Primrec.nat_lt.comp (Primrec.const 0) Primrec.snd).and
84
+ (hr.forall_mem_list.comp (Primrec.list_range.comp (Primrec.succ.comp Primrec.snd)) Primrec.id)
85
+ exact hh.of_eq (fun p => (coprime_bounded p.1 p.2).symm)
86
+
87
+ theorem valid_primrec : PrimrecPred valid :=
88
+ coprime_positive_primrec.comp ((magnitude_primrec.comp (Primrec.fst.comp Primrec.unpair)).pair
89
+ (Primrec.snd.comp Primrec.unpair))
90
+
91
+ def canonicalCode (n : ℕ) : ℕ := if valid n then n else encode (0 : ℚ)
92
+
93
+ theorem canonicalCode_primrec : Primrec canonicalCode :=
94
+ Primrec.ite valid_primrec Primrec.id (Primrec.const (encode (0 : ℚ)))
95
+
96
+ theorem decode_invalid (n : ℕ) (hv : ¬valid n) : decode (α := ℚ) n = none := by
97
+ let z := Equiv.intEquivNat.symm (Nat.unpair n).1
98
+ have hz : decode (α := ℤ) (Nat.unpair n).1 = some z := rfl
99
+ have henc : encode z = (Nat.unpair n).1 := Equiv.intEquivNat.apply_symm_apply _
100
+ have hbad : ¬(0 < (Nat.unpair n).2 ∧ z.natAbs.Coprime (Nat.unpair n).2) := by
101
+ simpa only [valid, ←henc, magnitude_encode_int] using hv
102
+ have hsub : decode (α := { b : ℕ // 0 < b ∧ z.natAbs.Coprime b }) (Nat.unpair n).2 = none := by
103
+ change Encodable.decodeSubtype (P := fun b => 0 < b ∧ z.natAbs.Coprime b) _ = none
104
+ simp [Encodable.decodeSubtype,hbad]
105
+ have hsigma : decode (α := Σ z : ℤ, { b : ℕ // 0 < b ∧ z.natAbs.Coprime b }) n = none := by
106
+ change Encodable.decodeSigma (γ := fun z : ℤ => { b : ℕ // 0 < b ∧ z.natAbs.Coprime b }) n = none
107
+ simp only [Encodable.decodeSigma]
108
+ rw [hz]
109
+ simp only [Option.bind_some]
110
+ rw [hsub]
111
+ rfl
112
+ simp only [Encodable.decode_ofEquiv,hsigma,Option.map_none]
113
+
114
+ theorem canonicalCode_eq (n : ℕ) : canonicalCode n = encode (rationalEnumeration n) := by
115
+ by_cases hv : valid n
116
+ · obtain ⟨q,rfl⟩ := (valid_iff n).mp hv
117
+ simp only [canonicalCode,ite_eq_left hv,rationalEnumeration,encodek,Option.getD_some]
118
+ · have hn := decode_invalid n hv
119
+ simp only [canonicalCode,ite_eq_right hv,rationalEnumeration,hn,Option.getD_none]
120
+
121
+ def numeratorCode (n : ℕ) : ℕ := (Nat.unpair (canonicalCode n)).1
122
+ def numeratorMagnitude (n : ℕ) : ℕ := magnitude (numeratorCode n)
123
+ def denominator (n : ℕ) : ℕ := (Nat.unpair (canonicalCode n)).2
124
+ def negative (n : ℕ) : Bool := (numeratorCode n).bodd
125
+
126
+ theorem numeratorCode_primrec : Primrec numeratorCode :=
127
+ (Primrec.fst.comp Primrec.unpair).comp canonicalCode_primrec
128
+ theorem numeratorMagnitude_primrec : Primrec numeratorMagnitude :=
129
+ magnitude_primrec.comp numeratorCode_primrec
130
+ theorem denominator_primrec : Primrec denominator :=
131
+ (Primrec.snd.comp Primrec.unpair).comp canonicalCode_primrec
132
+ theorem negative_primrec : Primrec negative := Primrec.nat_bodd.comp numeratorCode_primrec
133
+
134
+ theorem numeratorCode_eq (n : ℕ) : numeratorCode n = encode (rationalEnumeration n).num := by
135
+ rw [numeratorCode,canonicalCode_eq,encode_rat,Nat.unpair_pair]
136
+ theorem numeratorMagnitude_eq (n : ℕ) : numeratorMagnitude n = (rationalEnumeration n).num.natAbs := by
137
+ rw [numeratorMagnitude,numeratorCode_eq,magnitude_encode_int]
138
+ theorem denominator_eq (n : ℕ) : denominator n = (rationalEnumeration n).den := by
139
+ rw [denominator,canonicalCode_eq,encode_rat,Nat.unpair_pair]
140
+ theorem denominator_pos (n : ℕ) : 0 < denominator n := by
141
+ rw [denominator_eq]
142
+ exact (rationalEnumeration n).den_pos
143
+
144
+ theorem query_value (n : ℕ) : (rationalEnumeration n : ℝ) =
145
+ if negative n then -(numeratorMagnitude n : ℝ)/(denominator n : ℝ)
146
+ else (numeratorMagnitude n : ℝ)/(denominator n : ℝ) := by
147
+ rw [negative,numeratorCode_eq,numeratorMagnitude_eq,denominator_eq,Rat.cast_def]
148
+ cases hz : (rationalEnumeration n).num with
149
+ | ofNat k =>
150
+ rw [encode_int_nonneg]
151
+ simp [Nat.bodd_mul]
152
+ | negSucc k => simp [encode_int_neg,Nat.bodd_mul]
153
+
154
+ end RationalCoding
155
+ end TuringRigidity
156
+
157
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/RationalCut.lean ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.RationalCoding
2
+ import OAI.Computability.DegreeRigidity.Effective.UniformOracle
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity
7
+ namespace RationalCoding
8
+
9
+ def positiveNumerator (n : ℕ) : ℕ := if negative n then 0 else numeratorMagnitude n
10
+ def negativeNumerator (n : ℕ) : ℕ := if negative n then numeratorMagnitude n else 0
11
+
12
+ theorem positiveNumerator_primrec : Primrec positiveNumerator :=
13
+ Primrec.ite (Primrec.eq.comp negative_primrec (Primrec.const true)) (Primrec.const 0)
14
+ numeratorMagnitude_primrec
15
+
16
+ theorem negativeNumerator_primrec : Primrec negativeNumerator :=
17
+ Primrec.ite (Primrec.eq.comp negative_primrec (Primrec.const true)) numeratorMagnitude_primrec
18
+ (Primrec.const 0)
19
+
20
+ theorem signed_query_value (n : ℕ) : (rationalEnumeration n : ℝ) =
21
+ ((positiveNumerator n : ℝ)-(negativeNumerator n : ℝ))/(denominator n : ℝ) := by
22
+ rw [query_value]
23
+ cases hn : negative n <;> simp [positiveNumerator,negativeNumerator,hn]
24
+
25
+ def ltCode (i j : ℕ) : Prop :=
26
+ positiveNumerator i*denominator j + negativeNumerator j*denominator i <
27
+ positiveNumerator j*denominator i + negativeNumerator i*denominator j
28
+
29
+ instance (i j : ℕ) : Decidable (ltCode i j) := inferInstanceAs (Decidable (_ < _))
30
+
31
+ theorem ltCode_primrec : PrimrecRel ltCode :=
32
+ Primrec.nat_lt.comp
33
+ (Primrec.nat_add.comp
34
+ (Primrec.nat_mul.comp (positiveNumerator_primrec.comp Primrec.fst)
35
+ (denominator_primrec.comp Primrec.snd))
36
+ (Primrec.nat_mul.comp (negativeNumerator_primrec.comp Primrec.snd)
37
+ (denominator_primrec.comp Primrec.fst)))
38
+ (Primrec.nat_add.comp
39
+ (Primrec.nat_mul.comp (positiveNumerator_primrec.comp Primrec.snd)
40
+ (denominator_primrec.comp Primrec.fst))
41
+ (Primrec.nat_mul.comp (negativeNumerator_primrec.comp Primrec.fst)
42
+ (denominator_primrec.comp Primrec.snd)))
43
+
44
+ theorem ltCode_iff (i j : ℕ) :
45
+ ltCode i j ↔ (rationalEnumeration i : ℝ) < (rationalEnumeration j : ℝ) := by
46
+ have hi : (0 : ℝ) < denominator i := by exact_mod_cast denominator_pos i
47
+ have hj : (0 : ℝ) < denominator j := by exact_mod_cast denominator_pos j
48
+ rw [signed_query_value,signed_query_value,div_lt_div_iff₀ hi hj]
49
+ constructor
50
+ · intro h
51
+ have hh : (positiveNumerator i : ℝ)*denominator j + negativeNumerator j*denominator i <
52
+ (positiveNumerator j : ℝ)*denominator i + negativeNumerator i*denominator j := by
53
+ exact_mod_cast h
54
+ nlinarith
55
+ · intro h
56
+ change positiveNumerator i*denominator j + negativeNumerator j*denominator i <
57
+ positiveNumerator j*denominator i + negativeNumerator i*denominator j
58
+ have hh : (positiveNumerator i : ℝ)*denominator j + negativeNumerator j*denominator i <
59
+ (positiveNumerator j : ℝ)*denominator i + negativeNumerator i*denominator j := by nlinarith
60
+ exact_mod_cast hh
61
+ end RationalCoding
62
+
63
+ theorem rational_cut_computable (q : ℚ) :
64
+ Primrec (fun n => if cut (q : ℝ) n then (1 : ℕ) else 0) := by
65
+ have hp := Primrec.ite
66
+ (RationalCoding.ltCode_primrec.comp Primrec.id (Primrec.const (Encodable.encode q)))
67
+ (Primrec.const 1) (Primrec.const 0)
68
+ apply hp.of_eq
69
+ intro n
70
+ have hq : rationalEnumeration (Encodable.encode q) = q := by simp [rationalEnumeration]
71
+ have he : RationalCoding.ltCode n (Encodable.encode q) ↔ (rationalEnumeration n : ℝ) < q := by
72
+ rw [RationalCoding.ltCode_iff,hq]
73
+ by_cases h : (rationalEnumeration n : ℝ) < q
74
+ · simp [he,h,cut]
75
+ · simp [he,h,cut]
76
+
77
+ theorem rational_cut_reduces (q : ℚ) (A : Oracle) : Reduces (cut (q : ℝ)) A := by
78
+ exact RecursiveIn.iff_nat.mpr (UniformOracle.total_primrec (rational_cut_computable q))
79
+
80
+ end TuringRigidity
81
+
82
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/RealProjectionSyntax.lean ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Constructibility.ConstructionInputData
2
+ import OAI.Computability.DegreeRigidity.SetModels.SetModelJoin
3
+
4
+ namespace OAI
5
+
6
+ namespace TuringRigidity.RelativeConstructible
7
+ open ElementaryModel BoundedSetTheory TransitiveNameModel SetModelArithmetic SetModelReals
8
+ universe u
9
+
10
+ def bitIndex : List Bool → ℕ → ℕ
11
+ | [], n => n
12
+ | b::bs, n => 2 * bitIndex bs n + if b then 1 else 0
13
+
14
+ def partBits : ℕ → List Bool
15
+ | 0 => [false]
16
+ | i+1 => true :: partBits i
17
+
18
+ def pathBits : List ℕ → List Bool
19
+ | [] => []
20
+ | i::is => partBits i ++ pathBits is
21
+
22
+ theorem bitIndex_append (a b : List Bool) (n : ℕ) :
23
+ bitIndex (a++b) n = bitIndex a (bitIndex b n) := by
24
+ induction a with
25
+ | nil => rfl
26
+ | cons c a ih => simp only [List.cons_append,bitIndex,ih]
27
+
28
+ theorem realPart_bits (P : Oracle) (i n : ℕ) :
29
+ realPart P i n = P (bitIndex (partBits i) n) := by
30
+ induction i generalizing P with
31
+ | zero => simp [realPart,partBits,bitIndex]
32
+ | succ i ih => exact ih (fun k => P (2*k+1))
33
+
34
+ theorem pathReal_bits (P : Oracle) (path : List ℕ) (n : ℕ) :
35
+ pathReal P path n = P (bitIndex (pathBits path) n) := by
36
+ induction path generalizing P with
37
+ | nil => rfl
38
+ | cons i is ih => rw [pathReal,ih,realPart_bits,pathBits,bitIndex_append]
39
+
40
+ def bitStep (b : Bool) (w a d x y : ℕ) : Formula :=
41
+ if b then .existsMem w (.conj (tripleFormula (x+1) (x+1) 0 (a+1) (d+1))
42
+ (.successor (y+1) 0)) else tripleFormula x x y a d
43
+
44
+ theorem bitStep_spec (b : Bool) (w a d x y : ℕ) (e : ℕ → ZFSet.{u})
45
+ (hw : e w = ZFSet.omega) (ha : e a = additionSet) (hd : e d = pairNumbers)
46
+ (n m : ℕ) (hx : e x = natSet n) (hy : e y = natSet m) :
47
+ (bitStep b w a d x y).Eval e ↔ m = 2*n + if b then 1 else 0 := by
48
+ cases b
49
+ · simp [bitStep,eval_tripleFormula,hx,hy,ha,hd,addition_code,two_mul]
50
+ · simp only [bitStep,ite_true,Formula.Eval,eval_tripleFormula,Formula.eval_successor,
51
+ cons_zero,cons_succ,hw,hx,hy,ha,hd]
52
+ rw [omega_exists]
53
+ simp only [natPair_mem,true_and,addition_code,natSet_successor_eq]
54
+ constructor
55
+ · rintro ⟨k,hk,hm⟩; omega
56
+ · intro hm; exact ⟨n+n,rfl,by omega⟩
57
+
58
+ def bitIndexFormula : List Bool → ℕ → ℕ → ℕ → ℕ → ℕ → Formula
59
+ | [], _, _, _, x, y => .equal y x
60
+ | b::bs, w, a, d, x, y => .existsMem w
61
+ (.conj (bitIndexFormula bs (w+1) (a+1) (d+1) (x+1) 0)
62
+ (bitStep b (w+1) (a+1) (d+1) 0 (y+1)))
63
+
64
+ theorem bitIndexFormula_spec (bs : List Bool) (w a d x y : ℕ) (e : ℕ → ZFSet.{u})
65
+ (hw : e w = ZFSet.omega) (ha : e a = additionSet) (hd : e d = pairNumbers)
66
+ (n m : ℕ) (hx : e x = natSet n) (hy : e y = natSet m) :
67
+ (bitIndexFormula bs w a d x y).Eval e ↔ m = bitIndex bs n := by
68
+ induction bs generalizing w a d x y e m with
69
+ | nil => simp [bitIndexFormula,Formula.Eval,hx,hy,bitIndex,natSet_injective.eq_iff]
70
+ | cons b bs ih =>
71
+ simp only [bitIndexFormula,Formula.Eval,hw]
72
+ rw [omega_exists]
73
+ have hb (k : ℕ) := bitStep_spec b (w+1) (a+1) (d+1) 0 (y+1)
74
+ (cons (natSet k) e) hw ha hd k m rfl hy
75
+ have hi (k : ℕ) := ih (w+1) (a+1) (d+1) (x+1) 0 (cons (natSet k) e)
76
+ hw ha hd k hx rfl
77
+ simp only [hi,hb,exists_eq_left,bitIndex]
78
+
79
+ def projectionMember (bs : List Bool) (w a d P x : ℕ) : Formula :=
80
+ .conj (.member x w) (.existsMem w
81
+ (.conj (bitIndexFormula bs (w+1) (a+1) (d+1) (x+1) 0) (.member 0 (P+1))))
82
+
83
+ theorem projectionMember_spec (bs : List Bool) (w a d P x : ℕ)
84
+ (e : ℕ → ZFSet.{u}) (hw : e w = ZFSet.omega) (ha : e a = additionSet)
85
+ (hd : e d = pairNumbers) (Q : Oracle) (hP : e P = realCode Q) :
86
+ (projectionMember bs w a d P x).Eval e ↔ e x ∈ realCode (fun n => Q (bitIndex bs n)) := by
87
+ simp only [projectionMember,Formula.Eval,hw,cons_zero,cons_succ,hP]
88
+ constructor
89
+ · rintro ⟨hx,k,hk,hrel,hQ⟩
90
+ obtain ⟨n,hn⟩ := (mem_omega (e x)).mp hx
91
+ obtain ⟨m,rfl⟩ := (mem_omega k).mp hk
92
+ have hm := (bitIndexFormula_spec bs (w+1) (a+1) (d+1) (x+1) 0
93
+ (cons (natSet m) e) hw ha hd n m hn rfl).mp hrel
94
+ rw [hn,natSet_mem_realCode]
95
+ simpa [hm] using (natSet_mem_realCode Q m).mp hQ
96
+ · intro hx
97
+ obtain ⟨n,hn⟩ := (mem_omega (e x)).mp (realCode_subset _ hx)
98
+ have hnQ : Q (bitIndex bs n) = true := (natSet_mem_realCode _ n).mp (hn ▸ hx)
99
+ refine ⟨hn.symm ▸ (mem_omega _).mpr ⟨n,rfl⟩,natSet (bitIndex bs n),
100
+ (mem_omega _).mpr ⟨_,rfl⟩,?_,(natSet_mem_realCode Q _).mpr hnQ⟩
101
+ exact (bitIndexFormula_spec bs (w+1) (a+1) (d+1) (x+1) 0
102
+ (cons (natSet (bitIndex bs n)) e) hw ha hd n _ hn rfl).mpr rfl
103
+
104
+ noncomputable def projectionFormula (bs : List Bool) (out w a d P : ℕ) : SentenceForm :=
105
+ SentenceForm.all (SentenceForm.iff (.member 0 (out+1))
106
+ (fromBounded (projectionMember bs (w+1) (a+1) (d+1) (P+1) 0)))
107
+
108
+ theorem projectionFormula_spec (M : ZFSet.{u}) (hM : Transitive M)
109
+ (bs : List Bool) (out w a d P : ℕ) (e : ℕ → ZFSet.{u}) (he : ∀ i, e i ∈ M)
110
+ (hw : e w = ZFSet.omega) (ha : e a = additionSet) (hd : e d = pairNumbers)
111
+ (Q : Oracle) (hP : e P = realCode Q) :
112
+ (projectionFormula bs out w a d P).Sat (M : Set ZFSet) e ↔
113
+ e out = realCode (fun n => Q (bitIndex bs n)) := by
114
+ have hs (x : ZFSet.{u}) (hx : x ∈ M) :
115
+ (fromBounded (projectionMember bs (w+1) (a+1) (d+1) (P+1) 0)).Sat
116
+ (M : Set ZFSet) (cons x e) ↔ x ∈ realCode (fun n => Q (bitIndex bs n)) := by
117
+ rw [bounded_sat,Formula.absolute _ M hM _
118
+ (by intro i; cases i; exact hx; exact he _)]
119
+ exact projectionMember_spec bs (w+1) (a+1) (d+1) (P+1) 0 (cons x e) hw ha hd Q hP
120
+ simp only [projectionFormula,SentenceForm.sat_all,SentenceForm.sat_iff,
121
+ SentenceForm.Sat,cons_zero,cons_succ]
122
+ constructor
123
+ · intro h
124
+ apply ZFSet.ext; intro x
125
+ constructor
126
+ · intro hx
127
+ have hxM := hM _ (he out) _ hx
128
+ exact (hs x hxM).mp ((h x hxM).mp hx)
129
+ · intro hx
130
+ have hxM := hM _ (hw ▸ he w) _ (realCode_subset _ hx)
131
+ exact (h x hxM).mpr ((hs x hxM).mpr hx)
132
+ · intro h x hx; rw [h]; exact (hs x hx).symm
133
+
134
+ end TuringRigidity.RelativeConstructible
135
+
136
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/RecoverySetup.lean ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Representation.Endpoints
2
+
3
+ namespace OAI
4
+
5
+ open Set Filter Topology
6
+ namespace TuringRigidity
7
+
8
+ structure RecoveryData (F : ℝ → Oracle) (t u v : ℝ) where
9
+ radius : ℝ
10
+ radius_pos : 0 < radius
11
+ radius_lt_one : radius < 1
12
+ lo : ℝ
13
+ hi : ℝ
14
+ lo_gt : -radius < lo
15
+ lo_neg : lo < 0
16
+ hi_pos : 0 < hi
17
+ hi_lt : hi < radius
18
+ delta : ℚ
19
+ delta_pos : 0 < delta
20
+ delta_lt : (delta : ℝ) < radius
21
+ delta_gap : 3*(delta : ℝ) < hi-lo
22
+ bit : ℕ
23
+ forward : ℕ
24
+ backward : ℕ
25
+ left : ∀ s ∈ rationalSpan t, s ∈ Icc lo (lo+(delta : ℝ)) →
26
+ F (u+s) bit ≠ F (u+hi) bit
27
+ right : ∀ s ∈ rationalSpan t, s ∈ Icc (hi-(delta : ℝ)) hi →
28
+ F (u+s) bit = F (u+hi) bit
29
+ forward_correct : ∀ s ∈ rationalSpan t, ∀ a ∈ rationalSpan t,
30
+ |s| < radius → |a| < radius →
31
+ OracleCode.eval (oracleFunction (join (F (u+s)) (F (v-u+a))))
32
+ (codeEnumeration forward) = oracleFunction (F (v+s+a))
33
+ backward_correct : ∀ s ∈ rationalSpan t, |s| < radius →
34
+ OracleCode.eval (oracleFunction (join (F (v+s)) (F (u-v))))
35
+ (codeEnumeration backward) = oracleFunction (F (u+s))
36
+
37
+ theorem recovery_data_exists (F : ℝ → Oracle) (hF : Measurable F)
38
+ (hfiber : ∀ B, {x | F x = B}.Countable)
39
+ (hadd : ∀ x y, Reduces (F (x+y)) (join (F x) (F y))) (t : ℝ) :
40
+ ∃ G : Set (ℝ × ℝ), G ∈ residual (ℝ × ℝ) ∧
41
+ ∀ p ∈ G, Nonempty (RecoveryData F t p.1 p.2) := by
42
+ obtain ⟨D,hD,hFD⟩ := measurable_continuousOn_residual F hF
43
+ obtain ⟨e,E,hE,he,hspec⟩ := addition_program_continuous_restriction F hF hadd
44
+ refine ⟨goodPairs t D E,goodPairs_residual t D E hD hE,?_⟩
45
+ rintro ⟨u,v⟩ hgood
46
+ obtain ⟨p,q,ρ,hρ,hρ1,hp,hq⟩ := fixed_local_programs F t u v D E e he hgood hspec
47
+ obtain ⟨lo,hi,j,δ,hloρ,hlo,hhi,hhiρ,hδ,hδρ,hgap,hleft,hright⟩ :=
48
+ exists_endpoint_bands F hfiber D hD hFD t u ρ hρ (fun s hs => (hgood s hs).1)
49
+ exact ⟨{
50
+ radius := ρ, radius_pos := hρ, radius_lt_one := hρ1,
51
+ lo := lo, hi := hi, lo_gt := hloρ, lo_neg := hlo, hi_pos := hhi, hi_lt := hhiρ,
52
+ delta := δ, delta_pos := hδ, delta_lt := hδρ, delta_gap := hgap,
53
+ bit := j, forward := p, backward := q,
54
+ left := hleft, right := hright, forward_correct := hp, backward_correct := hq }⟩
55
+
56
+ namespace RecoveryData
57
+ variable {F : ℝ → Oracle} {t u v : ℝ}
58
+
59
+ def test (d : RecoveryData F t u v) (s : ℝ) : Bool :=
60
+ decide (F (u+s) d.bit = F (u+d.hi) d.bit)
61
+
62
+ theorem bounded (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1) (n : ℕ) :
63
+ state d.test (d.delta : ℝ) t n ∈ Icc d.lo d.hi := by
64
+ apply state_mem_Icc_on_span d.test d.delta t d.lo d.hi
65
+ (by exact_mod_cast d.delta_pos) ht0 ht1 d.lo_neg.le d.hi_pos.le
66
+ · intro s hs hb
67
+ simp [test, d.left s hs hb]
68
+ · intro s hs hb
69
+ simp [test, d.right s hs hb]
70
+
71
+ theorem abs_state_lt (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1) (n : ℕ) :
72
+ |state d.test (d.delta : ℝ) t n| < d.radius := by
73
+ obtain ⟨hl,hu⟩ := d.bounded ht0 ht1 n
74
+ exact abs_lt.mpr ⟨d.lo_gt.trans_le hl, hu.trans_lt d.hi_lt⟩
75
+
76
+ theorem frequency_bound (d : RecoveryData F t u v) (ht0 : 0 < t) (ht1 : t < 1)
77
+ (n : ℕ) (hn : 0 < n) :
78
+ |t - (∑ k ∈ Finset.range n, branch d.test (d.delta : ℝ) t k) / (n : ℝ)| <
79
+ 1 / ((n : ℝ) * (d.delta : ℝ)) := by
80
+ exact frequency_error d.test (d.delta : ℝ) t n
81
+ (by exact_mod_cast d.delta_pos) hn ((d.abs_state_lt ht0 ht1 n).trans d.radius_lt_one)
82
+
83
+ theorem cut_search (d : RecoveryData F t u v) (ht : Irrational t) (ht0 : 0 < t)
84
+ (ht1 : t < 1) (q : ℚ) :
85
+ (q : ℝ) < t ↔ ∃ n : ℕ, 0 < n ∧ (q : ℝ) <
86
+ (∑ k ∈ Finset.range n, branch d.test (d.delta : ℝ) t k) / (n : ℝ) -
87
+ 1 / ((n : ℝ) * (d.delta : ℝ)) := by
88
+ exact irrational_cut_iff_search t (d.delta : ℝ)
89
+ (fun n => (∑ k ∈ Finset.range n, branch d.test (d.delta : ℝ) t k) / (n : ℝ))
90
+ ht (by exact_mod_cast d.delta_pos) (fun n hn => d.frequency_bound ht0 ht1 n hn) q
91
+ end RecoveryData
92
+
93
+ end TuringRigidity
94
+
95
+ end OAI
lean/OAI/Computability/DegreeRigidity/Computability/ScalarCoding.lean ADDED
@@ -0,0 +1,94 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import OAI.Computability.DegreeRigidity.Computability.RationalCut
2
+
3
+ namespace OAI
4
+
5
+ namespace TuringRigidity
6
+ namespace RationalCoding
7
+
8
+ def scalarLeft (r : ℕ) (z : ℕ × ℕ) : ℕ :=
9
+ (positiveNumerator r*positiveNumerator z.2 + negativeNumerator r*negativeNumerator z.2)*denominator z.1 +
10
+ negativeNumerator z.1*denominator r*denominator z.2
11
+
12
+ def scalarRight (r : ℕ) (z : ℕ × ℕ) : ℕ :=
13
+ (positiveNumerator r*negativeNumerator z.2 + negativeNumerator r*positiveNumerator z.2)*denominator z.1 +
14
+ positiveNumerator z.1*denominator r*denominator z.2
15
+
16
+ private theorem scalarPolynomial_primrec (a b D : ℕ) {p q c : ℕ → ℕ}
17
+ (hp : Primrec p) (hq : Primrec q) (hc : Primrec c) :
18
+ Primrec (fun z : ℕ × ℕ => (a*p z.2+b*q z.2)*denominator z.1+c z.1*D*denominator z.2) :=
19
+ Primrec.nat_add.comp
20
+ (Primrec.nat_mul.comp
21
+ (Primrec.nat_add.comp (Primrec.nat_mul.comp (Primrec.const a) (hp.comp Primrec.snd))
22
+ (Primrec.nat_mul.comp (Primrec.const b) (hq.comp Primrec.snd)))
23
+ (denominator_primrec.comp Primrec.fst))
24
+ (Primrec.nat_mul.comp (Primrec.nat_mul.comp (hc.comp Primrec.fst) (Primrec.const D))
25
+ (denominator_primrec.comp Primrec.snd))
26
+
27
+ theorem scalarLeft_primrec (r : ℕ) : Primrec (scalarLeft r) :=
28
+ scalarPolynomial_primrec _ _ _ positiveNumerator_primrec negativeNumerator_primrec negativeNumerator_primrec
29
+
30
+ theorem scalarRight_primrec (r : ℕ) : Primrec (scalarRight r) :=
31
+ scalarPolynomial_primrec _ _ _ negativeNumerator_primrec positiveNumerator_primrec positiveNumerator_primrec
32
+
33
+ theorem scalar_eq_iff (r i j : ℕ) : scalarLeft r (i,j)=scalarRight r (i,j) ↔
34
+ (rationalEnumeration r : ℝ)*(rationalEnumeration j : ℝ)=(rationalEnumeration i : ℝ) := by
35
+ have hr : (denominator r : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt (denominator_pos r))
36
+ have hi : (denominator i : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt (denominator_pos i))
37
+ have hj : (denominator j : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_of_gt (denominator_pos j))
38
+ rw [signed_query_value,signed_query_value,signed_query_value]
39
+ have he : ((positiveNumerator r : ℝ)-negativeNumerator r)/denominator r *
40
+ (((positiveNumerator j : ℝ)-negativeNumerator j)/denominator j) =
41
+ ((positiveNumerator i : ℝ)-negativeNumerator i)/denominator i ↔
42
+ (scalarLeft r (i,j) : ℝ)=(scalarRight r (i,j) : ℝ) := by
43
+ simp only [scalarLeft,scalarRight,Nat.cast_add,Nat.cast_mul]
44
+ field_simp
45
+ constructor <;> intro h <;> nlinarith
46
+ rw [he]
47
+ exact Nat.cast_inj.symm
48
+
49
+ def divideIndex (r : ℚ) (i : ℕ) : ℕ := Encodable.encode (rationalEnumeration i/r)
50
+
51
+ theorem divideIndex_value (r : ℚ) (i : ℕ) :
52
+ rationalEnumeration (divideIndex r i) = rationalEnumeration i/r := by
53
+ simp only [divideIndex,rationalEnumeration,Encodable.encodek,Option.getD_some]
54
+
55
+ theorem divideIndex_recursive {O : Set (ℕ →. ℕ)} (r : ℚ) (hr : r ≠ 0) :
56
+ Nat.RecursiveIn O (fun i => Part.some (divideIndex r i)) := by
57
+ let ridx := Encodable.encode r
58
+ let E : ℕ → ℕ → Option ℕ := fun i j =>
59
+ if valid j ∧ scalarLeft ridx (i,j)=scalarRight ridx (i,j) then some j else none
60
+ have hE : Primrec (fun z : ℕ => Encodable.encode (E (Nat.unpair z).1 (Nat.unpair z).2)) :=
61
+ Primrec.encode.comp ((Primrec.ite ((valid_primrec.comp Primrec.snd).and
62
+ (Primrec.eq.comp (scalarLeft_primrec ridx) (scalarRight_primrec ridx)))
63
+ (Primrec.option_some.comp Primrec.snd) (Primrec.const none)).comp Primrec.unpair)
64
+ have hridx : rationalEnumeration ridx = r := by simp [ridx,rationalEnumeration]
65
+ apply UniformOracle.total_search (UniformOracle.total_primrec hE) (divideIndex r)
66
+ · intro i j a ha
67
+ dsimp only [E] at ha
68
+ split at ha
69
+ · rename_i h
70
+ have haj : a=j := by symm; simpa using ha
71
+ subst a
72
+ have he := (scalar_eq_iff ridx i j).mp h.2
73
+ rw [hridx] at he
74
+ have heq : r*rationalEnumeration j=rationalEnumeration i := by exact_mod_cast he
75
+ have hval : rationalEnumeration j=rationalEnumeration i/r :=
76
+ (eq_div_iff hr).mpr (by simpa [mul_comm] using heq)
77
+ have hj : canonicalCode j=j := ite_eq_left h.1
78
+ rw [canonicalCode_eq,hval] at hj
79
+ exact hj.symm
80
+ · simp at ha
81
+ · intro i
82
+ let j := divideIndex r i
83
+ have hv : valid j := (valid_iff j).mpr ⟨rationalEnumeration i/r,rfl⟩
84
+ have he : scalarLeft ridx (i,j)=scalarRight ridx (i,j) := by
85
+ apply (scalar_eq_iff ridx i j).mpr
86
+ rw [hridx,show rationalEnumeration j=rationalEnumeration i/r from divideIndex_value r i]
87
+ push_cast
88
+ field_simp
89
+ exact ⟨j,j,by simp [E,hv,he]⟩
90
+
91
+ end RationalCoding
92
+ end TuringRigidity
93
+
94
+ end OAI