Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Computability): define oracle computability and Turing degrees #20219

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

tannerduve
Copy link

@tannerduve tannerduve commented Dec 24, 2024

Some initial definitions introducing a model of oracle computability via partial recursive functions, define Turing reducibility and equivalence, and prove that Turing equivalence is an equivalence relation. Define the type of Turing degrees as equivalence classes under Turing equivalence. This PR includes:

  • RecursiveIn g f: An inductive definition representing that a partial function f is recursive in oracle g.
  • turing_reducible: A relation defining Turing reducibility between partial functions.
  • turing_equivalent: A relation defining Turing equivalence between partial functions.
  • TuringDegree: The type of Turing degrees, defined as equivalence classes under turing_equivalent.
  • A proof that TuringDegree is a partial order when reducibility is lifted to degrees

Implementation Notes

The type RecursiveIn g f is inductively defined to include basic functions such as zero, succ, projections, and the oracle g, and is closed under pairing, composition, primitive recursion, and μ-recursion. The join operation combines two partial functions by mapping even and odd numbers to the respective functions.

Notation

  • f ≤ᵀ g: f is Turing reducible to g.
  • f ≡ᵀ g: f is Turing equivalent to g.
  • f ⊔ g: The join of partial functions f and g.

In Progress

The work here is just the basic definitions for the theory being developed. Some current in-progress work involves proving the upper-semilattice structure of Turing degrees, proving the existence of a relativized universal partial recursive function, and proving properties of the jump operator.

References

  • [Carneiro2018] Carneiro, Mario. Formalizing Computability Theory via Partial Recursive Functions. arXiv preprint arXiv:1810.08380, 2018.
  • [Odifreddi1989] Odifreddi, Piergiorgio. Classical Recursion Theory: The Theory of Functions and Sets of Natural Numbers, Vol. I. Springer-Verlag, 1989.
  • [Soare1987] Soare, Robert I. Recursively Enumerable Sets and Degrees. Springer-Verlag, 1987.
  • [Gu2015] Gu, Yi-Zhi. Turing Degrees. Institute for Advanced Study, 2015.

Tags

Computability, Oracle, Turing Degrees, Reducibility, Equivalence Relation

@tannerduve tannerduve changed the title feat(oracle_computability): define oracle computability and Turing degrees feat(Computability): define oracle computability and Turing degrees Dec 24, 2024
A partial function `f` is partial recursive if and only if
it is recursive in the constant zero function.
-/
lemma partrec_iff_partrec_in_zero
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the definition of Nat.Partrec should be changed to this, otherwise there's unnecessary duplication.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going to add an alternative definition, Partrec_0, defined in this way

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not a good solution, it would just mean we have two duplicate definitions

Copy link
Author

@tannerduve tannerduve Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it best to just remove these equivalence lemmas then? I don't want to mess too much with the existing computability set up. These lemmas end up being useful for some proofs I'm currently working on.

Mathlib/Computability/TuringDegrees.lean Outdated Show resolved Hide resolved
Mathlib/Computability/TuringDegrees.lean Outdated Show resolved Hide resolved
Mathlib/Computability/TuringDegrees.lean Outdated Show resolved Hide resolved
Mathlib/Computability/TuringDegrees.lean Outdated Show resolved Hide resolved
Mathlib/Computability/TuringDegrees.lean Outdated Show resolved Hide resolved
Mathlib/Computability/TuringDegrees.lean Outdated Show resolved Hide resolved
Mathlib/Computability/TuringDegrees.lean Outdated Show resolved Hide resolved
@Command-Master Command-Master added the awaiting-author A reviewer has asked the author a question or requested changes label Dec 24, 2024
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
Comment on lines +102 to +105
lemma partrec_implies_recursive_in_everything
(f : ℕ →. ℕ) : Nat.Partrec f → (∀ g, RecursiveIn f g) := by
intro pF
intro g
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be renamed to allow for dot-notation

Suggested change
lemma partrec_implies_recursive_in_everything
(f : ℕ →. ℕ) : Nat.Partrec f → (∀ g, RecursiveIn f g) := by
intro pF
intro g
lemma Nat.Partrec.recursiveIn (f : ℕ →. ℕ) (pF : Nat.Partrec f) (g : ℕ →. ℕ) : RecursiveIn f g := by

Comment on lines +128 to +130
lemma partrec_in_zero_implies_partrec
(f : ℕ →. ℕ) : RecursiveIn f (fun _ => Part.some 0) → Nat.Partrec f := by
intro fRecInZero
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be renamed to allow for dot-notation

Suggested change
lemma partrec_in_zero_implies_partrec
(f : ℕ →. ℕ) : RecursiveIn f (fun _ => Part.some 0) → Nat.Partrec f := by
intro fRecInZero
lemma RecursiveIn.partrec_of_zero (f : ℕ →. ℕ) (fRecInZero : RecursiveIn f fun _ => Part.some 0) :
Nat.Partrec f := by

Comment on lines +171 to +178
theorem partrec_iff_partrec_in_everything
(f : ℕ →. ℕ) : Nat.Partrec f ↔ (∀ g, RecursiveIn f g) := by
constructor
· exact partrec_implies_recursive_in_everything f
· intro H
have lem : RecursiveIn f (fun _ => Part.some 0) := H (fun _ => Part.some 0)
have lem : Nat.Partrec f := partrec_in_zero_implies_partrec f lem
exact lem
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly stylistic, but this can be golfed to

Suggested change
theorem partrec_iff_partrec_in_everything
(f : ℕ →. ℕ) : Nat.Partrec f ↔ (∀ g, RecursiveIn f g) := by
constructor
· exact partrec_implies_recursive_in_everything f
· intro H
have lem : RecursiveIn f (fun _ => Part.some 0) := H (fun _ => Part.some 0)
have lem : Nat.Partrec f := partrec_in_zero_implies_partrec f lem
exact lem
theorem partrec_iff_partrec_in_everything (f : ℕ →. ℕ) : Nat.Partrec f ↔ ∀ g, RecursiveIn f g :=
⟨(·.recursiveIn), (· _ |>.partrec_of_zero)⟩

Comment on lines +190 to +191
theorem TuringEquivalent.refl (f : ℕ →. ℕ) : f ≡ᵀ f :=
⟨RecursiveIn.refl f, RecursiveIn.refl f⟩
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you provide an IsRefl instance for RecursiveIn this can be antisymmRel_refl

Comment on lines +196 to +198
@[symm]
theorem TuringEquivalent.symm {f g : ℕ →. ℕ} (h : f ≡ᵀ g) : g ≡ᵀ f :=
⟨h.2, h.1⟩
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be AntisymmRel.symm

Comment on lines +294 to +355
/--
For any partial functions `a`, `b₁`, and `b₂`, if `b₁` is Turing equivalent to `b₂`,
then `a` is Turing reducible to `b₁` if and only if `a` is Turing reducible to `b₂`.
-/
lemma reduce_lifts₁ : ∀ (a b₁ b₂ : ℕ →. ℕ), b₁≡ᵀb₂ → (RecursiveIn a b₁) = (RecursiveIn a b₂) := by
intros a b₁ b₂ bEqb
apply propext
constructor
· intro aRedb₁
apply RecursiveIn.trans aRedb₁ bEqb.1
· intro aRedb₂
apply RecursiveIn.trans aRedb₂ bEqb.2

/--
For any partial functions `f`, `g`, and `h`, if `f` is Turing equivalent to `g`,
then `f` is Turing reducible to `h` if and only if `g` is Turing reducible to `h`.
-/
lemma reduce_lifts₂ : ∀ (f g h : ℕ →. ℕ),
f ≡ᵀ g → (RecursiveIn f h = RecursiveIn g h) := by
intros f g h fEqg
apply propext
constructor
· intro fRedh
apply RecursiveIn.trans fEqg.2 fRedh
· intro gRedh
apply RecursiveIn.trans fEqg.1 gRedh

/--
Here we show how to lift the Turing reducibility relation from
partial functions to their Turing degrees, using the above lemmas.
-/
def TuringDegree.turing_red (d₁ d₂ : TuringDegree) : Prop :=
@Quot.lift₂ _ _ Prop (TuringEquivalent)
(TuringEquivalent) (RecursiveIn) (reduce_lifts₁) (reduce_lifts₂) d₁ d₂

/--
Instance declaring that `TuringDegree.turing_red` is a partial order.
-/
instance : PartialOrder TuringDegree where
le := TuringDegree.turing_red
le_refl := by
apply Quot.ind
intro a
apply RecursiveIn.refl
le_trans := by
apply Quot.ind
intro a
apply Quot.ind
intro b
apply Quot.ind
intro c
exact RecursiveIn.trans
le_antisymm := by
apply Quot.ind
intro a
apply Quot.ind
intro b
intros aRedb bReda
apply Quot.sound
constructor
· exact aRedb
· exact bReda
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this can be rewritten to use existing Antisymmetrization stuff, like

instance : PartialOrder TuringDegree :=
  @instPartialOrderAntisymmetrization (ℕ →. ℕ)
    {le := RecursiveIn, le_refl := .refl, le_trans _ _ _ := RecursiveIn.trans}

Comment on lines +207 to +239
induction hg
case zero =>
apply RecursiveIn.zero
case succ =>
apply RecursiveIn.succ
case left =>
apply RecursiveIn.left
case right =>
apply RecursiveIn.right
case oracle =>
exact hh
case pair f' h' _ _ hf_ih hh_ih =>
apply RecursiveIn.pair
· apply hf_ih
apply hh
· apply hh_ih
apply hh
case comp f' h' _ _ hf_ih hh_ih =>
apply RecursiveIn.comp
· apply hf_ih
apply hh
· apply hh_ih
apply hh
case prec f' h' _ _ hf_ih hh_ih =>
apply RecursiveIn.prec
· apply hf_ih
apply hh
· apply hh_ih
apply hh
case rfind f' _ hf_ih =>
apply RecursiveIn.rfind
· apply hf_ih
apply hh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentation of this is incorrect, it should be indented by two spaces

Comment on lines +203 to +206
@[trans]
theorem RecursiveIn.trans {f g h : ℕ →. ℕ} :
RecursiveIn f g → RecursiveIn g h → RecursiveIn f h := by
intro hg hh
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general instead of writing function types and then using intro you can introduce values directly as arguments - often this is cleaner.

Suggested change
@[trans]
theorem RecursiveIn.trans {f g h : ℕ →. ℕ} :
RecursiveIn f g → RecursiveIn g h → RecursiveIn f h := by
intro hg hh
@[trans]
theorem RecursiveIn.trans {f g h : ℕ →. ℕ} (hg : RecursiveIn f g) (hh : RecursiveIn g h) :
RecursiveIn f h := by

Comment on lines +244 to +247
theorem TuringEquivalent.trans :
Transitive TuringEquivalent :=
fun _ _ _ ⟨fg₁, fg₂⟩ ⟨gh₁, gh₂⟩ =>
⟨RecursiveIn.trans fg₁ gh₁, RecursiveIn.trans gh₂ fg₂⟩
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you provide an IsTrans instance for RecursiveIn this can be AntisymmRel.trans

Comment on lines +252 to +257
instance : Equivalence TuringEquivalent :=
{
refl := TuringEquivalent.refl,
symm := TuringEquivalent.symm,
trans := @TuringEquivalent.trans
}
Copy link
Collaborator

@Command-Master Command-Master Dec 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you provide an IsPreorder instance for RecursiveIn this can be (AntisymmRel.setoid _ _).iseqv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting-author A reviewer has asked the author a question or requested changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants