fact
stringlengths
6
3.84k
type
stringclasses
11 values
library
stringclasses
32 values
imports
listlengths
1
14
filename
stringlengths
20
95
symbolic_name
stringlengths
1
90
docstring
stringlengths
7
20k
listFilter (hf : PrimrecPred p) : Primrec fun L ↦ List.filter (p ·) L := by rw [← List.filterMap_eq_filter] apply listFilterMap .id simp only [Primrec₂, Option.guard, decide_eq_true_eq] exact ite (hf.comp snd) (option_some_iff.mpr snd) (const none)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
listFilter
Filtering a list for elements that satisfy a decidable predicate is primitive recursive.
list_findIdx {f : α → List β} {p : α → β → Bool} (hf : Primrec f) (hp : Primrec₂ p) : Primrec fun a => (f a).findIdx (p a) := (list_foldr hf (const 0) <| to₂ <| cond (hp.comp fst <| fst.comp snd) (const 0) (succ.comp <| snd.comp snd)).of_eq fun a => by dsimp; induction f a <;> simp [List.findIdx_cons, *]
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
list_findIdx
null
list_idxOf [DecidableEq α] : Primrec₂ (@List.idxOf α _) := to₂ <| list_findIdx snd <| Primrec.beq.comp₂ snd.to₂ (fst.comp fst).to₂
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
list_idxOf
null
nat_strong_rec (f : α → ℕ → σ) {g : α → List σ → Option σ} (hg : Primrec₂ g) (H : ∀ a n, g a ((List.range n).map (f a)) = some (f a n)) : Primrec₂ f := suffices Primrec₂ fun a n => (List.range n).map (f a) from Primrec₂.option_some_iff.1 <| (list_getElem?.comp (this.comp fst (succ.comp snd)) snd).to₂.of_eq fun a n => by simp Primrec₂.option_some_iff.1 <| (nat_rec (const (some [])) (to₂ <| option_bind (snd.comp snd) <| to₂ <| option_map (hg.comp (fst.comp fst) snd) (to₂ <| list_concat.comp (snd.comp fst) snd))).of_eq fun a n => by induction n with | zero => rfl | succ n IH => simp [IH, H, List.range_succ]
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
nat_strong_rec
null
listLookup [DecidableEq α] : Primrec₂ (List.lookup : α → List (α × β) → Option β) := (to₂ <| list_rec snd (const none) <| to₂ <| cond (Primrec.beq.comp (fst.comp fst) (fst.comp <| fst.comp snd)) (option_some.comp <| snd.comp <| fst.comp snd) (snd.comp <| snd.comp snd)).of_eq fun a ps => by induction ps with simp [List.lookup, *] | cons p ps ih => cases ha : a == p.1 <;> simp
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
listLookup
null
nat_omega_rec' (f : β → σ) {m : β → ℕ} {l : β → List β} {g : β → List σ → Option σ} (hm : Primrec m) (hl : Primrec l) (hg : Primrec₂ g) (Ord : ∀ b, ∀ b' ∈ l b, m b' < m b) (H : ∀ b, g b ((l b).map f) = some (f b)) : Primrec f := by haveI : DecidableEq β := Encodable.decidableEqOfEncodable β let mapGraph (M : List (β × σ)) (bs : List β) : List σ := bs.flatMap (Option.toList <| M.lookup ·) let bindList (b : β) : ℕ → List β := fun n ↦ n.rec [b] fun _ bs ↦ bs.flatMap l let graph (b : β) : ℕ → List (β × σ) := fun i ↦ i.rec [] fun i ih ↦ (bindList b (m b - i)).filterMap fun b' ↦ (g b' <| mapGraph ih (l b')).map (b', ·) have mapGraph_primrec : Primrec₂ mapGraph := to₂ <| list_flatMap snd <| optionToList.comp₂ <| listLookup.comp₂ .right (fst.comp₂ .left) have bindList_primrec : Primrec₂ (bindList) := nat_rec' snd (list_cons.comp fst (const [])) (to₂ <| list_flatMap (snd.comp snd) (hl.comp₂ .right)) have graph_primrec : Primrec₂ (graph) := to₂ <| nat_rec' snd (const []) <| to₂ <| listFilterMap (bindList_primrec.comp (fst.comp fst) (nat_sub.comp (hm.comp <| fst.comp fst) (fst.comp snd))) <| to₂ <| option_map (hg.comp snd (mapGraph_primrec.comp (snd.comp <| snd.comp fst) (hl.comp snd))) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right) have : Primrec (fun b => (graph b (m b + 1))[0]?.map Prod.snd) := option_map (list_getElem?.comp (graph_primrec.comp Primrec.id (succ.comp hm)) (const 0)) (snd.comp₂ Primrec₂.right) exact option_some_iff.mp <| this.of_eq <| fun b ↦ by have graph_eq_map_bindList (i : ℕ) (hi : i ≤ m b + 1) : graph b i = (bindList b (m b + 1 - i)).map fun x ↦ (x, f x) := by have bindList_eq_nil : bindList b (m b + 1) = [] := have bindList_m_lt (k : ℕ) : ∀ b' ∈ bindList b k, m b' < m b + 1 - k := by induction k with simp [bindList] | succ k ih => grind List.eq_nil_iff_forall_not_mem.mpr (by intro b' ha'; by_contra; simpa using bindList_m_lt (m b + 1) b' ha') have mapGraph_graph {bs bs' : List β} (has : bs' ⊆ bs) : mapGraph (bs.map <| fun x => (x, f x)) bs' = bs'.map f := by induction bs' with simp [mapGraph] | cons b bs' ih => have : b ∈ bs ∧ bs' ⊆ bs := by simpa using has rcases this with ⟨ha, has'⟩ simpa [List.lookup_graph f ha] using ih has' have graph_succ : ∀ i, graph b (i + 1) = (bindList b (m b - i)).filterMap fun b' => (g b' <| mapGraph (graph b i) (l b')).map (b', ·) := fun _ => rfl have bindList_succ : ∀ i, bindList b (i + 1) = (bindList b i).flatMap l := fun _ => rfl induction i with | zero => symm; simpa [graph] using bindList_eq_nil | succ i ih => ...
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
nat_omega_rec'
null
nat_omega_rec (f : α → β → σ) {m : α → β → ℕ} {l : α → β → List β} {g : α → β × List σ → Option σ} (hm : Primrec₂ m) (hl : Primrec₂ l) (hg : Primrec₂ g) (Ord : ∀ a b, ∀ b' ∈ l a b, m a b' < m a b) (H : ∀ a b, g a (b, (l a b).map (f a)) = some (f a b)) : Primrec₂ f := Primrec₂.uncurry.mp <| nat_omega_rec' (Function.uncurry f) (Primrec₂.uncurry.mpr hm) (list_map (hl.comp fst snd) (Primrec₂.pair.comp₂ (fst.comp₂ .left) .right)) (hg.comp₂ (fst.comp₂ .left) (Primrec₂.pair.comp₂ (snd.comp₂ .left) .right)) (by simpa using Ord) (by simpa [Function.comp] using H)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
nat_omega_rec
null
exists_mem_list : (hf : PrimrecPred p) → PrimrecPred fun L : List α ↦ ∃ a ∈ L, p a | ⟨_, hf⟩ => .of_eq (.not <| Primrec.eq.comp (list_length.comp <| listFilter hf.primrecPred) (const 0)) <| by simp
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
exists_mem_list
Checking if any element of a list satisfies a decidable predicate is primitive recursive.
forall_mem_list : (hf : PrimrecPred p) → PrimrecPred fun L : List α ↦ ∀ a ∈ L, p a | ⟨_, hf⟩ => .of_eq (Primrec.eq.comp (list_length.comp <| listFilter hf.primrecPred) (list_length)) <| by simp variable {p : ℕ → Prop}
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
forall_mem_list
Checking if every element of a list satisfies a decidable predicate is primitive recursive.
exists_lt (hf : PrimrecPred p) : PrimrecPred fun n ↦ ∃ x < n, p x := of_eq (hf.exists_mem_list.comp list_range) (by simp)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
exists_lt
Bounded existential quantifiers are primitive recursive.
forall_lt (hf : PrimrecPred p) : PrimrecPred fun n ↦ ∀ x < n, p x := of_eq (hf.forall_mem_list.comp list_range) (by simp)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
forall_lt
Bounded universal quantifiers are primitive recursive.
listFilter_listRange {R : ℕ → ℕ → Prop} (s : ℕ) [DecidableRel R] (hf : PrimrecRel R) : Primrec fun n ↦ (range s).filter (fun y ↦ R y n) := by simp only [← filterMap_eq_filter] refine listFilterMap (.const (range s)) ?_ refine ite (Primrec.eq.comp ?_ (const true)) (option_some_iff.mpr snd) (.const Option.none) exact hf.decide.comp snd fst
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
listFilter_listRange
A helper lemma for proofs about bounded quantifiers on decidable relations.
protected not (hf : PrimrecRel R) : PrimrecRel fun a b ↦ ¬ R a b := PrimrecPred.not hf
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
not
null
listFilter (hf : PrimrecRel R) [DecidableRel R] : Primrec₂ fun (L : List α) b ↦ L.filter (fun a ↦ R a b) := by simp only [← List.filterMap_eq_filter] refine listFilterMap fst (Primrec.ite ?_ ?_ (Primrec.const Option.none)) · exact Primrec.eq.comp (hf.decide.comp snd (snd.comp fst)) (.const true) · exact (option_some).comp snd
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
listFilter
If `R a b` is decidable, then given `L : List α` and `b : β`, it is primitive recursive to filter `L` for elements `a` with `R a b`
exists_mem_list (hf : PrimrecRel R) : PrimrecRel fun (L : List α) b ↦ ∃ a ∈ L, R a b := by classical have h (L) (b) : (List.filter (R · b) L).length ≠ 0 ↔ ∃ a ∈ L, R a b := by simp refine .of_eq (.not ?_) h exact Primrec.eq.comp (list_length.comp hf.listFilter) (const 0)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
exists_mem_list
If `R a b` is decidable, then given `L : List α` and `b : β`, `g L b ↔ ∃ a L, R a b` is a primitive recursive relation.
forall_mem_list (hf : PrimrecRel R) : PrimrecRel fun (L : List α) b ↦ ∀ a ∈ L, R a b := by classical have h (L) (b) : (List.filter (R · b) L).length = L.length ↔ ∀ a ∈ L, R a b := by simp apply PrimrecRel.of_eq ?_ h exact (Primrec.eq.comp (list_length.comp <| PrimrecRel.listFilter hf) (.comp list_length fst)) variable {R : ℕ → ℕ → Prop}
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
forall_mem_list
If `R a b` is decidable, then given `L : List α` and `b : β`, `g L b ↔ ∀ a L, R a b` is a primitive recursive relation.
exists_lt (hf : PrimrecRel R) : PrimrecRel fun n y ↦ ∃ x < n, R x y := (hf.exists_mem_list.comp (list_range.comp fst) snd).of_eq (by simp)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
exists_lt
If `R a b` is decidable, then for any fixed `n` and `y`, `g n y ↔ ∃ x < n, R x y` is a primitive recursive relation.
forall_lt (hf : PrimrecRel R) : PrimrecRel fun n y ↦ ∀ x < n, R x y := (hf.forall_mem_list.comp (list_range.comp fst) snd).of_eq (by simp)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
forall_lt
If `R a b` is decidable, then for any fixed `n` and `y`, `g n y ↔ ∀ x < n, R x y` is a primitive recursive relation.
subtype {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : Primcodable (Subtype p) := ⟨have : Primrec fun n => (@decode α _ n).bind fun a => Option.guard p a := option_bind .decode (option_guard (hp.comp snd).primrecRel snd) nat_iff.1 <| (encode_iff.2 this).of_eq fun n => show _ = encode ((@decode α _ n).bind fun _ => _) by rcases @decode α _ n with - | a; · rfl dsimp [Option.guard] by_cases h : p a <;> simp [h]; rfl⟩
def
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
subtype
A subtype of a primitive recursive predicate is `Primcodable`.
fin {n} : Primcodable (Fin n) := @ofEquiv _ _ (subtype <| nat_lt.comp .id (const n)) Fin.equivSubtype
instance
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
fin
null
vector {n} : Primcodable (List.Vector α n) := subtype ((@Primrec.eq ℕ _).comp list_length (const _))
instance
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector
null
finArrow {n} : Primcodable (Fin n → α) := ofEquiv _ (Equiv.vectorEquivFin _ _).symm
instance
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
finArrow
null
mem_range_encode : PrimrecPred (fun n => n ∈ Set.range (encode : α → ℕ)) := have : PrimrecPred fun n => Encodable.decode₂ α n ≠ none := .not (Primrec.eq.comp (.option_bind .decode (.ite (by simpa using Primrec.eq.comp (Primrec.encode.comp .snd) .fst) (Primrec.option_some.comp .snd) (.const _))) (.const _)) this.of_eq fun _ => decode₂_ne_none_iff
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
mem_range_encode
null
ulower : Primcodable (ULower α) := Primcodable.subtype mem_range_encode
instance
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
ulower
null
subtype_val {p : α → Prop} [DecidablePred p] {hp : PrimrecPred p} : haveI := Primcodable.subtype hp Primrec (@Subtype.val α p) := by letI := Primcodable.subtype hp refine (Primcodable.prim (Subtype p)).of_eq fun n => ?_ rcases @decode (Subtype p) _ n with (_ | ⟨a, h⟩) <;> rfl
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
subtype_val
null
subtype_val_iff {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → Subtype p} : haveI := Primcodable.subtype hp (Primrec fun a => (f a).1) ↔ Primrec f := by letI := Primcodable.subtype hp refine ⟨fun h => ?_, fun hf => subtype_val.comp hf⟩ refine Nat.Primrec.of_eq h fun n => ?_ rcases @decode α _ n with - | a; · rfl simp; rfl
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
subtype_val_iff
null
subtype_mk {p : β → Prop} [DecidablePred p] {hp : PrimrecPred p} {f : α → β} {h : ∀ a, p (f a)} (hf : Primrec f) : haveI := Primcodable.subtype hp Primrec fun a => @Subtype.mk β p (f a) (h a) := subtype_val_iff.1 hf
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
subtype_mk
null
option_get {f : α → Option β} {h : ∀ a, (f a).isSome} : Primrec f → Primrec fun a => (f a).get (h a) := by intro hf refine (Nat.Primrec.pred.comp hf).of_eq fun n => ?_ generalize hx : @decode α _ n = x cases x <;> simp
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
option_get
null
ulower_down : Primrec (ULower.down : α → ULower α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ subtype_mk .encode
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
ulower_down
null
ulower_up : Primrec (ULower.up : ULower α → α) := letI : ∀ a, Decidable (a ∈ Set.range (encode : α → ℕ)) := decidableRangeEncode _ option_get (Primrec.decode₂.comp subtype_val)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
ulower_up
null
fin_val_iff {n} {f : α → Fin n} : (Primrec fun a => (f a).1) ↔ Primrec f := by letI : Primcodable { a // id a < n } := Primcodable.subtype (nat_lt.comp .id (const _)) exact (Iff.trans (by rfl) subtype_val_iff).trans (of_equiv_iff _)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
fin_val_iff
null
fin_val {n} : Primrec (fun (i : Fin n) => (i : ℕ)) := fin_val_iff.2 .id
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
fin_val
null
fin_succ {n} : Primrec (@Fin.succ n) := fin_val_iff.1 <| by simp [succ.comp fin_val]
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
fin_succ
null
vector_toList {n} : Primrec (@List.Vector.toList α n) := subtype_val
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_toList
null
vector_toList_iff {n} {f : α → List.Vector β n} : (Primrec fun a => (f a).toList) ↔ Primrec f := subtype_val_iff
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_toList_iff
null
vector_cons {n} : Primrec₂ (@List.Vector.cons α n) := vector_toList_iff.1 <| by simpa using list_cons.comp fst (vector_toList_iff.2 snd)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_cons
null
vector_length {n} : Primrec (@List.Vector.length α n) := const _
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_length
null
vector_head {n} : Primrec (@List.Vector.head α n) := option_some_iff.1 <| (list_head?.comp vector_toList).of_eq fun ⟨_ :: _, _⟩ => rfl
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_head
null
vector_tail {n} : Primrec (@List.Vector.tail α n) := vector_toList_iff.1 <| (list_tail.comp vector_toList).of_eq fun ⟨l, h⟩ => by cases l <;> rfl
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_tail
null
vector_get {n} : Primrec₂ (@List.Vector.get α n) := option_some_iff.1 <| (list_getElem?.comp (vector_toList.comp fst) (fin_val.comp snd)).of_eq fun a => by simp [Vector.get_eq_get_toList]
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_get
null
list_ofFn : ∀ {n} {f : Fin n → α → σ}, (∀ i, Primrec (f i)) → Primrec fun a => List.ofFn fun i => f i a | 0, _, _ => by simp only [List.ofFn_zero]; exact const [] | n + 1, f, hf => by simpa using list_cons.comp (hf 0) (list_ofFn fun i => hf i.succ)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
list_ofFn
null
vector_ofFn {n} {f : Fin n → α → σ} (hf : ∀ i, Primrec (f i)) : Primrec fun a => List.Vector.ofFn fun i => f i a := vector_toList_iff.1 <| by simp [list_ofFn hf]
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_ofFn
null
vector_get' {n} : Primrec (@List.Vector.get α n) := of_equiv_symm
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_get'
null
vector_ofFn' {n} : Primrec (@List.Vector.ofFn α n) := of_equiv
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vector_ofFn'
null
fin_app {n} : Primrec₂ (@id (Fin n → σ)) := (vector_get.comp (vector_ofFn'.comp fst) snd).of_eq fun ⟨v, i⟩ => by simp
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
fin_app
null
fin_curry₁ {n} {f : Fin n → α → σ} : Primrec₂ f ↔ ∀ i, Primrec (f i) := ⟨fun h i => h.comp (const i) .id, fun h => (vector_get.comp ((vector_ofFn h).comp snd) fst).of_eq fun a => by simp⟩
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
fin_curry₁
null
fin_curry {n} {f : α → Fin n → σ} : Primrec f ↔ Primrec₂ f := ⟨fun h => fin_app.comp (h.comp fst) snd, fun h => (vector_get'.comp (vector_ofFn fun i => show Primrec fun a => f a i from h.comp .id (const i))).of_eq fun a => by funext i; simp⟩
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
fin_curry
null
Primrec' : ∀ {n}, (List.Vector ℕ n → ℕ) → Prop | zero : @Primrec' 0 fun _ => 0 | succ : @Primrec' 1 fun v => succ v.head | get {n} (i : Fin n) : Primrec' fun v => v.get i | comp {m n f} (g : Fin n → List.Vector ℕ m → ℕ) : Primrec' f → (∀ i, Primrec' (g i)) → Primrec' fun a => f (List.Vector.ofFn fun i => g i a) | prec {n f g} : @Primrec' n f → @Primrec' (n + 2) g → Primrec' fun v : List.Vector ℕ (n + 1) => v.head.rec (f v.tail) fun y IH => g (y ::ᵥ IH ::ᵥ v.tail)
inductive
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
Primrec'
An alternative inductive definition of `Primrec` which does not use the pairing function on ℕ, and so has to work with n-ary functions on ℕ instead of unary functions. We prove that this is equivalent to the regular notion in `to_prim` and `of_prim`.
to_prim {n f} (pf : @Nat.Primrec' n f) : Primrec f := by induction pf with | zero => exact .const 0 | succ => exact _root_.Primrec.succ.comp .vector_head | get i => exact Primrec.vector_get.comp .id (.const i) | comp _ _ _ hf hg => exact hf.comp (.vector_ofFn fun i => hg i) | @prec n f g _ _ hf hg => exact .nat_rec' .vector_head (hf.comp Primrec.vector_tail) (hg.comp <| Primrec.vector_cons.comp (Primrec.fst.comp .snd) <| Primrec.vector_cons.comp (Primrec.snd.comp .snd) <| (@Primrec.vector_tail _ _ (n + 1)).comp .fst).to₂
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
to_prim
null
of_eq {n} {f g : List.Vector ℕ n → ℕ} (hf : Primrec' f) (H : ∀ i, f i = g i) : Primrec' g := (funext H : f = g) ▸ hf
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
of_eq
null
const {n} : ∀ m, @Primrec' n fun _ => m | 0 => zero.comp Fin.elim0 fun i => i.elim0 | m + 1 => succ.comp _ fun _ => const m
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
const
null
head {n : ℕ} : @Primrec' n.succ head := (get 0).of_eq fun v => by simp [get_zero]
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
head
null
tail {n f} (hf : @Primrec' n f) : @Primrec' n.succ fun v => f v.tail := (hf.comp _ fun i => @get _ i.succ).of_eq fun v => by rw [← ofFn_get v.tail]; congr; funext i; simp
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
tail
null
Vec {n m} (f : List.Vector ℕ n → List.Vector ℕ m) : Prop := ∀ i, Primrec' fun v => (f v).get i
def
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
Vec
A function from vectors to vectors is primitive recursive when all of its projections are.
protected nil {n} : @Vec n 0 fun _ => nil := fun i => i.elim0
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
nil
null
protected cons {n m f g} (hf : @Primrec' n f) (hg : @Vec n m g) : Vec fun v => f v ::ᵥ g v := fun i => Fin.cases (by simp [*]) (fun i => by simp [hg i]) i
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
cons
null
idv {n} : @Vec n n id := get
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
idv
null
comp' {n m f g} (hf : @Primrec' m f) (hg : @Vec n m g) : Primrec' fun v => f (g v) := (hf.comp _ hg).of_eq fun v => by simp
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
comp'
null
comp₁ (f : ℕ → ℕ) (hf : @Primrec' 1 fun v => f v.head) {n g} (hg : @Primrec' n g) : Primrec' fun v => f (g v) := hf.comp _ fun _ => hg
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
comp₁
null
comp₂ (f : ℕ → ℕ → ℕ) (hf : @Primrec' 2 fun v => f v.head v.tail.head) {n g h} (hg : @Primrec' n g) (hh : @Primrec' n h) : Primrec' fun v => f (g v) (h v) := by simpa using hf.comp' (hg.cons <| hh.cons Primrec'.nil)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
comp₂
null
prec' {n f g h} (hf : @Primrec' n f) (hg : @Primrec' n g) (hh : @Primrec' (n + 2) h) : @Primrec' n fun v => (f v).rec (g v) fun y IH : ℕ => h (y ::ᵥ IH ::ᵥ v) := by simpa using comp' (prec hg hh) (hf.cons idv)
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
prec'
null
pred : @Primrec' 1 fun v => v.head.pred := (prec' head (const 0) head).of_eq fun v => by simp; cases v.head <;> rfl
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
pred
null
add : @Primrec' 2 fun v => v.head + v.tail.head := (prec head (succ.comp₁ _ (tail head))).of_eq fun v => by simp; induction v.head <;> simp [*, Nat.succ_add]
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
add
null
sub : @Primrec' 2 fun v => v.head - v.tail.head := by have : @Primrec' 2 fun v ↦ (fun a b ↦ b - a) v.head v.tail.head := by refine (prec head (pred.comp₁ _ (tail head))).of_eq fun v => ?_ simp; induction v.head <;> simp [*, Nat.sub_add_eq] simpa using comp₂ (fun a b => b - a) this (tail head) head
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
sub
null
mul : @Primrec' 2 fun v => v.head * v.tail.head := (prec (const 0) (tail (add.comp₂ _ (tail head) head))).of_eq fun v => by simp; induction v.head <;> simp [*, Nat.succ_mul]; rw [add_comm]
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
mul
null
if_lt {n a b f g} (ha : @Primrec' n a) (hb : @Primrec' n b) (hf : @Primrec' n f) (hg : @Primrec' n g) : @Primrec' n fun v => if a v < b v then f v else g v := (prec' (sub.comp₂ _ hb ha) hg (tail <| tail hf)).of_eq fun v => by cases e : b v - a v · simp [not_lt.2 (Nat.sub_eq_zero_iff_le.mp e)] · simp [Nat.lt_of_sub_eq_succ e]
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
if_lt
null
natPair : @Primrec' 2 fun v => v.head.pair v.tail.head := if_lt head (tail head) (add.comp₂ _ (tail <| mul.comp₂ _ head head) head) (add.comp₂ _ (add.comp₂ _ (mul.comp₂ _ head head) head) (tail head))
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
natPair
null
protected encode : ∀ {n}, @Primrec' n encode | 0 => (const 0).of_eq fun v => by rw [v.eq_nil]; rfl | _ + 1 => (succ.comp₁ _ (natPair.comp₂ _ head (tail Primrec'.encode))).of_eq fun ⟨_ :: _, _⟩ => rfl
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
encode
null
sqrt : @Primrec' 1 fun v => v.head.sqrt := by suffices H : ∀ n : ℕ, n.sqrt = n.rec 0 fun x y => if x.succ < y.succ * y.succ then y else y.succ by simp only [H, succ_eq_add_one] have := @prec' 1 _ _ (fun v => by have x := v.head; have y := v.tail.head exact if x.succ < y.succ * y.succ then y else y.succ) head (const 0) ?_ · exact this have x1 : @Primrec' 3 fun v => v.head.succ := succ.comp₁ _ head have y1 : @Primrec' 3 fun v => v.tail.head.succ := succ.comp₁ _ (tail head) exact if_lt x1 (mul.comp₂ _ y1 y1) (tail head) y1 introv; symm induction n with | zero => simp | succ n IH => dsimp; rw [IH]; split_ifs with h · exact le_antisymm (Nat.sqrt_le_sqrt (Nat.le_succ _)) (Nat.lt_succ_iff.1 <| Nat.sqrt_lt.2 h) · exact Nat.eq_sqrt.2 ⟨not_lt.1 h, Nat.sqrt_lt.1 <| Nat.lt_succ_iff.2 <| Nat.sqrt_succ_le_succ_sqrt _⟩
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
sqrt
null
unpair₁ {n f} (hf : @Primrec' n f) : @Primrec' n fun v => (f v).unpair.1 := by have s := sqrt.comp₁ _ hf have fss := sub.comp₂ _ hf (mul.comp₂ _ s s) refine (if_lt fss s fss s).of_eq fun v => ?_ simp [Nat.unpair]; split_ifs <;> rfl
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
unpair₁
null
unpair₂ {n f} (hf : @Primrec' n f) : @Primrec' n fun v => (f v).unpair.2 := by have s := sqrt.comp₁ _ hf have fss := sub.comp₂ _ hf (mul.comp₂ _ s s) refine (if_lt fss s s (sub.comp₂ _ fss s)).of_eq fun v => ?_ simp [Nat.unpair]; split_ifs <;> rfl
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
unpair₂
null
of_prim {n f} : Primrec f → @Primrec' n f := suffices ∀ f, Nat.Primrec f → @Primrec' 1 fun v => f v.head from fun hf => (pred.comp₁ _ <| (this _ hf).comp₁ (fun m => Encodable.encode <| (@decode (List.Vector ℕ n) _ m).map f) Primrec'.encode).of_eq fun i => by simp [encodek] fun f hf => by induction hf with | zero => exact const 0 | succ => exact succ | left => exact unpair₁ head | right => exact unpair₂ head | pair _ _ hf hg => exact natPair.comp₂ _ hf hg | comp _ _ hf hg => exact hf.comp₁ _ hg | prec _ _ hf hg => simpa using prec' (unpair₂ head) (hf.comp₁ _ (unpair₁ head)) (hg.comp₁ _ <| natPair.comp₂ _ (unpair₁ <| tail <| tail head) (natPair.comp₂ _ head (tail head)))
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
of_prim
null
prim_iff {n f} : @Primrec' n f ↔ Primrec f := ⟨to_prim, of_prim⟩
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
prim_iff
null
prim_iff₁ {f : ℕ → ℕ} : (@Primrec' 1 fun v => f v.head) ↔ Primrec f := prim_iff.trans ⟨fun h => (h.comp <| .vector_ofFn fun _ => .id).of_eq fun v => by simp, fun h => h.comp .vector_head⟩
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
prim_iff₁
null
prim_iff₂ {f : ℕ → ℕ → ℕ} : (@Primrec' 2 fun v => f v.head v.tail.head) ↔ Primrec₂ f := prim_iff.trans ⟨fun h => (h.comp <| Primrec.vector_cons.comp .fst <| Primrec.vector_cons.comp .snd (.const nil)).of_eq fun v => by simp, fun h => h.comp .vector_head (Primrec.vector_head.comp .vector_tail)⟩
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
prim_iff₂
null
vec_iff {m n f} : @Vec m n f ↔ Primrec f := ⟨fun h => by simpa using Primrec.vector_ofFn fun i => to_prim (h i), fun h i => of_prim <| Primrec.vector_get.comp h (.const i)⟩
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
vec_iff
null
Primrec.nat_sqrt : Primrec Nat.sqrt := Nat.Primrec'.prim_iff₁.1 Nat.Primrec'.sqrt set_option linter.style.longFile 1700
theorem
Computability
[ "Mathlib.Algebra.Order.Ring.Nat", "Mathlib.Logic.Encodable.Pi", "Mathlib.Logic.Function.Iterate" ]
Mathlib/Computability/Primrec.lean
Primrec.nat_sqrt
null
ManyOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := ∃ f, Computable f ∧ ∀ a, p a ↔ q (f a) @[inherit_doc ManyOneReducible] infixl:1000 " ≤₀ " => ManyOneReducible
def
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
ManyOneReducible
`p` is many-one reducible to `q` if there is a computable function translating questions about `p` to questions about `q`.
ManyOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop) (h : Computable f) : (fun a => q (f a)) ≤₀ q := ⟨f, h, fun _ => Iff.rfl⟩ @[refl]
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
ManyOneReducible.mk
null
manyOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₀ p := ⟨id, Computable.id, by simp⟩ @[trans]
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
manyOneReducible_refl
null
ManyOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₀ q → q ≤₀ r → p ≤₀ r | ⟨f, c₁, h₁⟩, ⟨g, c₂, h₂⟩ => ⟨g ∘ f, c₂.comp c₁, fun a => ⟨fun h => by rw [comp_apply, ← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
ManyOneReducible.trans
null
reflexive_manyOneReducible {α} [Primcodable α] : Reflexive (@ManyOneReducible α α _ _) := manyOneReducible_refl
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
reflexive_manyOneReducible
null
transitive_manyOneReducible {α} [Primcodable α] : Transitive (@ManyOneReducible α α _ _) := fun _ _ _ => ManyOneReducible.trans
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
transitive_manyOneReducible
null
OneOneReducible {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := ∃ f, Computable f ∧ Injective f ∧ ∀ a, p a ↔ q (f a) @[inherit_doc OneOneReducible] infixl:1000 " ≤₁ " => OneOneReducible
def
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
OneOneReducible
`p` is one-one reducible to `q` if there is an injective computable function translating questions about `p` to questions about `q`.
OneOneReducible.mk {α β} [Primcodable α] [Primcodable β] {f : α → β} (q : β → Prop) (h : Computable f) (i : Injective f) : (fun a => q (f a)) ≤₁ q := ⟨f, h, i, fun _ => Iff.rfl⟩ @[refl]
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
OneOneReducible.mk
null
oneOneReducible_refl {α} [Primcodable α] (p : α → Prop) : p ≤₁ p := ⟨id, Computable.id, injective_id, by simp⟩ @[trans]
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
oneOneReducible_refl
null
OneOneReducible.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : p ≤₁ q → q ≤₁ r → p ≤₁ r | ⟨f, c₁, i₁, h₁⟩, ⟨g, c₂, i₂, h₂⟩ => ⟨g ∘ f, c₂.comp c₁, i₂.comp i₁, fun a => ⟨fun h => by rw [comp_apply, ← h₂, ← h₁]; assumption, fun h => by rwa [h₁, h₂]⟩⟩
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
OneOneReducible.trans
null
OneOneReducible.to_many_one {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : p ≤₁ q → p ≤₀ q | ⟨f, c, _, h⟩ => ⟨f, c, h⟩
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
OneOneReducible.to_many_one
null
OneOneReducible.of_equiv {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (q : β → Prop) (h : Computable e) : (q ∘ e) ≤₁ q := OneOneReducible.mk _ h e.injective
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
OneOneReducible.of_equiv
null
OneOneReducible.of_equiv_symm {α β} [Primcodable α] [Primcodable β] {e : α ≃ β} (q : β → Prop) (h : Computable e.symm) : q ≤₁ (q ∘ e) := by convert OneOneReducible.of_equiv _ h; funext; simp
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
OneOneReducible.of_equiv_symm
null
reflexive_oneOneReducible {α} [Primcodable α] : Reflexive (@OneOneReducible α α _ _) := oneOneReducible_refl
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
reflexive_oneOneReducible
null
transitive_oneOneReducible {α} [Primcodable α] : Transitive (@OneOneReducible α α _ _) := fun _ _ _ => OneOneReducible.trans
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
transitive_oneOneReducible
null
computable_of_manyOneReducible {p : α → Prop} {q : β → Prop} (h₁ : p ≤₀ q) (h₂ : ComputablePred q) : ComputablePred p := by rcases h₁ with ⟨f, c, hf⟩ rw [show p = fun a => q (f a) from Set.ext hf] rcases computable_iff.1 h₂ with ⟨g, hg, rfl⟩ exact ⟨by infer_instance, by simpa using hg.comp c⟩
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
computable_of_manyOneReducible
null
computable_of_oneOneReducible {p : α → Prop} {q : β → Prop} (h : p ≤₁ q) : ComputablePred q → ComputablePred p := computable_of_manyOneReducible h.to_many_one
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
computable_of_oneOneReducible
null
ManyOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := p ≤₀ q ∧ q ≤₀ p
def
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
ManyOneEquiv
`p` and `q` are many-one equivalent if each one is many-one reducible to the other.
OneOneEquiv {α β} [Primcodable α] [Primcodable β] (p : α → Prop) (q : β → Prop) := p ≤₁ q ∧ q ≤₁ p @[refl]
def
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
OneOneEquiv
`p` and `q` are one-one equivalent if each one is one-one reducible to the other.
manyOneEquiv_refl {α} [Primcodable α] (p : α → Prop) : ManyOneEquiv p p := ⟨manyOneReducible_refl _, manyOneReducible_refl _⟩ @[symm]
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
manyOneEquiv_refl
null
ManyOneEquiv.symm {α β} [Primcodable α] [Primcodable β] {p : α → Prop} {q : β → Prop} : ManyOneEquiv p q → ManyOneEquiv q p := And.symm @[trans]
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
ManyOneEquiv.symm
null
ManyOneEquiv.trans {α β γ} [Primcodable α] [Primcodable β] [Primcodable γ] {p : α → Prop} {q : β → Prop} {r : γ → Prop} : ManyOneEquiv p q → ManyOneEquiv q r → ManyOneEquiv p r | ⟨pq, qp⟩, ⟨qr, rq⟩ => ⟨pq.trans qr, rq.trans qp⟩
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
ManyOneEquiv.trans
null
equivalence_of_manyOneEquiv {α} [Primcodable α] : Equivalence (@ManyOneEquiv α α _ _) := ⟨manyOneEquiv_refl, fun {_ _} => ManyOneEquiv.symm, fun {_ _ _} => ManyOneEquiv.trans⟩ @[refl]
theorem
Computability
[ "Mathlib.Computability.Halting" ]
Mathlib/Computability/Reduce.lean
equivalence_of_manyOneEquiv
null