Skip to content

Commit 825c937

Browse files
committed
refactor: don't require DecidablePred to state PrimrecPred (#27076)
```lean def PrimrecPred {α} [Primcodable α] (p : α → Prop) [DecidablePred p] := Primrec fun a => decide (p a) ``` Currently, `DecidablePred` is required to **state** `PrimrecPred`, so this PR changes the definition and adds convenient APIs for this new definition: ```lean def PrimrecPred {α} [Primcodable α] (p : α → Prop) := ∃ (_ : DecidablePred p), Primrec fun a => decide (p a) ```
1 parent 14af323 commit 825c937

File tree

3 files changed

+122
-69
lines changed

3 files changed

+122
-69
lines changed

Mathlib/Computability/Halting.lean

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,30 @@ end Partrec
134134

135135
/-- A computable predicate is one whose indicator function is computable. -/
136136
def ComputablePred {α} [Primcodable α] (p : α → Prop) :=
137-
∃ _ : DecidablePred p, Computable fun a => decide (p a)
137+
∃ (_ : DecidablePred p), Computable fun a => decide (p a)
138+
139+
section decide
140+
141+
variable {α} [Primcodable α]
142+
143+
protected lemma ComputablePred.decide {p : α → Prop} [DecidablePred p] (hp : ComputablePred p) :
144+
Computable (fun a => decide (p a)) := by
145+
convert hp.choose_spec
146+
147+
lemma Computable.computablePred {p : α → Prop} [DecidablePred p]
148+
(hp : Computable (fun a => decide (p a))) : ComputablePred p :=
149+
⟨inferInstance, hp⟩
150+
151+
lemma computablePred_iff_computable_decide {p : α → Prop} [DecidablePred p] :
152+
ComputablePred p ↔ Computable (fun a => decide (p a)) where
153+
mp := ComputablePred.decide
154+
mpr := Computable.computablePred
155+
156+
lemma PrimrecPred.computablePred {α} [Primcodable α] {p : α → Prop} :
157+
(hp : PrimrecPred p) → ComputablePred p
158+
| ⟨_, hp⟩ => hp.to_comp.computablePred
159+
160+
end decide
138161

139162
/-- A recursively enumerable predicate is one which is the domain of a computable partial function.
140163
-/
@@ -170,22 +193,16 @@ theorem computable_iff {p : α → Prop} :
170193
fun ⟨_, h⟩ => ⟨_, h, funext fun _ => propext (Bool.decide_iff _).symm⟩, by
171194
rintro ⟨f, h, rfl⟩; exact ⟨by infer_instance, by simpa using h⟩⟩
172195

173-
protected theorem not {p : α → Prop} (hp : ComputablePred p) : ComputablePred fun a => ¬p a := by
174-
obtain ⟨f, hf, rfl⟩ := computable_iff.1 hp
175-
exact
176-
by infer_instance,
177-
(cond hf (const false) (const true)).of_eq fun n => by
178-
simp only [Bool.not_eq_true]
179-
cases f n <;> rfl⟩
196+
protected theorem not {p : α → Prop} :
197+
(hp : ComputablePred p) → ComputablePred fun a => ¬p a
198+
| ⟨_, hp⟩ => Computable.computablePred <| Primrec.not.to_comp.comp hp |>.of_eq <| by simp
180199

181200
/-- The computable functions are closed under if-then-else definitions
182201
with computable predicates. -/
183202
theorem ite {f₁ f₂ : ℕ → ℕ} (hf₁ : Computable f₁) (hf₂ : Computable f₂)
184203
{c : ℕ → Prop} [DecidablePred c] (hc : ComputablePred c) :
185204
Computable fun k ↦ if c k then f₁ k else f₂ k := by
186-
simp_rw [← Bool.cond_decide]
187-
obtain ⟨inst, hc⟩ := hc
188-
convert hc.cond hf₁ hf₂
205+
simpa [Bool.cond_decide] using hc.decide.cond hf₁ hf₂
189206

190207
theorem to_re {p : α → Prop} (hp : ComputablePred p) : REPred p := by
191208
obtain ⟨f, hf, rfl⟩ := computable_iff.1 hp
@@ -296,7 +313,7 @@ theorem to_part {n f} (pf : @Partrec' n f) : _root_.Partrec f := by
296313
| rfind _ hf =>
297314
have := hf.comp (vector_cons.comp snd fst)
298315
have :=
299-
((Primrec.eq.comp _root_.Primrec.id (_root_.Primrec.const 0)).to_comp.comp
316+
((Primrec.eq.decide.comp _root_.Primrec.id (_root_.Primrec.const 0)).to_comp.comp
300317
this).to₂.partrec₂
301318
exact _root_.Partrec.rfind this
302319

Mathlib/Computability/Partrec.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ theorem prec' {f g h} (hf : Partrec f) (hg : Partrec g) (hh : Partrec h) :
204204
theorem ppred : Partrec fun n => ppred n :=
205205
have : Primrec₂ fun n m => if n = Nat.succ m then 0 else 1 :=
206206
(Primrec.ite
207-
(@PrimrecRel.comp _ _ _ _ _ _ _ _ _ _
207+
(@PrimrecRel.comp _ _ _ _ _ _ _ _ _
208208
Primrec.eq Primrec.fst (_root_.Primrec.succ.comp Primrec.snd))
209209
(_root_.Primrec.const 0) (_root_.Primrec.const 1)).to₂
210210
(of_primrec (Primrec₂.unpaired'.2 this)).rfind.of_eq fun n => by

Mathlib/Computability/Primrec.lean

Lines changed: 92 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -330,18 +330,17 @@ end Primrec
330330
def Primrec₂ {α β σ} [Primcodable α] [Primcodable β] [Primcodable σ] (f : α → β → σ) :=
331331
Primrec fun p : α × β => f p.1 p.2
332332

333-
/-- `PrimrecPred p` means `p : α → Prop` is a (decidable)
333+
/-- `PrimrecPred p` means `p : α → Prop` is a
334334
primitive recursive predicate, which is to say that
335335
`decide ∘ p : α → Bool` is primitive recursive. -/
336-
def PrimrecPred {α} [Primcodable α] (p : α → Prop) [DecidablePred p] :=
337-
Primrec fun a => decide (p a)
336+
def PrimrecPred {α} [Primcodable α] (p : α → Prop) :=
337+
∃ (_ : DecidablePred p), Primrec fun a => decide (p a)
338338

339-
/-- `PrimrecRel p` means `p : α → β → Prop` is a (decidable)
339+
/-- `PrimrecRel p` means `p : α → β → Prop` is a
340340
primitive recursive relation, which is to say that
341341
`decide ∘ p : α → β → Bool` is primitive recursive. -/
342-
def PrimrecRel {α β} [Primcodable α] [Primcodable β] (s : α → β → Prop)
343-
[∀ a b, Decidable (s a b)] :=
344-
Primrec₂ fun a b => decide (s a b)
342+
def PrimrecRel {α β} [Primcodable α] [Primcodable β] (s : α → β → Prop) :=
343+
PrimrecPred fun p : α × β => s p.1 p.2
345344

346345
namespace Primrec₂
347346

@@ -408,29 +407,53 @@ theorem Primrec₂.comp₂ {f : γ → δ → σ} {g : α → β → γ} {h : α
408407
(hg : Primrec₂ g) (hh : Primrec₂ h) : Primrec₂ fun a b => f (g a b) (h a b) :=
409408
hf.comp hg hh
410409

411-
theorem PrimrecPred.comp {p : βProp} [DecidablePred p] {f : α → β} :
412-
PrimrecPred p → Primrec f → PrimrecPred fun a => p (f a) :=
413-
Primrec.comp
410+
protected lemma PrimrecPred.decide {p : αProp} [DecidablePred p] (hp : PrimrecPred p) :
411+
Primrec (fun a => decide (p a)) := by
412+
convert hp.choose_spec
414413

415-
theorem PrimrecRel.comp {R : βγ → Prop} [∀ a b, Decidable (R a b)] {f : α → β} {g : α → γ} :
416-
PrimrecRel R → Primrec f → Primrec g → PrimrecPred fun a => R (f a) (g a) :=
417-
Primrec₂.comp
414+
lemma Primrec.primrecPred {p : αProp} [DecidablePred p]
415+
(hp : Primrec (fun a => decide (p a))) : PrimrecPred p :=
416+
⟨inferInstance, hp⟩
418417

419-
theorem PrimrecRel.comp₂ {R : γ → δ → Prop} [∀ a b, Decidable (R a b)] {f : α → β → γ}
420-
{g : α → β → δ} :
418+
lemma primrecPred_iff_primrec_decide {p : α → Prop} [DecidablePred p] :
419+
PrimrecPred p ↔ Primrec (fun a => decide (p a)) where
420+
mp := PrimrecPred.decide
421+
mpr := Primrec.primrecPred
422+
423+
theorem PrimrecPred.comp {p : β → Prop} {f : α → β} :
424+
(hp : PrimrecPred p) → (hf : Primrec f) → PrimrecPred fun a => p (f a)
425+
| ⟨_i, hp⟩, hf => hp.comp hf |>.primrecPred
426+
427+
protected lemma PrimrecRel.decide {R : α → β → Prop} [DecidableRel R] (hR : PrimrecRel R) :
428+
Primrec₂ (fun a b => decide (R a b)) :=
429+
PrimrecPred.decide hR
430+
431+
lemma Primrec₂.primrecRel {R : α → β → Prop} [DecidableRel R]
432+
(hp : Primrec₂ (fun a b => decide (R a b))) : PrimrecRel R :=
433+
Primrec.primrecPred hp
434+
435+
lemma primrecRel_iff_primrec_decide {R : α → β → Prop} [DecidableRel R] :
436+
PrimrecRel R ↔ Primrec₂ (fun a b => decide (R a b)) where
437+
mp := PrimrecRel.decide
438+
mpr := Primrec₂.primrecRel
439+
440+
theorem PrimrecRel.comp {R : β → γ → Prop} {f : α → β} {g : α → γ}
441+
(hR : PrimrecRel R) (hf : Primrec f) (hg : Primrec g) : PrimrecPred fun a => R (f a) (g a) :=
442+
PrimrecPred.comp hR (hf.pair hg)
443+
444+
theorem PrimrecRel.comp₂ {R : γ → δ → Prop} {f : α → β → γ} {g : α → β → δ} :
421445
PrimrecRel R → Primrec₂ f → Primrec₂ g → PrimrecRel fun a b => R (f a b) (g a b) :=
422446
PrimrecRel.comp
423447

424448
end Comp
425449

426-
theorem PrimrecPred.of_eq {α} [Primcodable α] {p q : α → Prop} [DecidablePred p] [DecidablePred q]
450+
theorem PrimrecPred.of_eq {α} [Primcodable α] {p q : α → Prop}
427451
(hp : PrimrecPred p) (H : ∀ a, p a ↔ q a) : PrimrecPred q :=
428-
Primrec.of_eq hp fun a => Bool.decide_congr (H a)
452+
funext (fun a => propext (H a)) ▸ hp
429453

430454
theorem PrimrecRel.of_eq {α β} [Primcodable α] [Primcodable β] {r s : α → β → Prop}
431-
[∀ a b, Decidable (r a b)] [∀ a b, Decidable (s a b)] (hr : PrimrecRel r)
432-
(H : ∀ a b, r a b ↔ s a b) : PrimrecRel s :=
433-
Primrec₂.of_eq hr fun a b => Bool.decide_congr (H a b)
455+
(hr : PrimrecRel r) (H : ∀ a b, r a b ↔ s a b) : PrimrecRel s :=
456+
funext₂ (fun a b => propext (H a b)) ▸ hr
434457

435458
namespace Primrec₂
436459

@@ -439,7 +462,11 @@ variable [Primcodable α] [Primcodable β] [Primcodable σ]
439462

440463
open Nat.Primrec
441464

442-
theorem swap {f : α → β → σ} (h : Primrec₂ f) : Primrec₂ (swap f) :=
465+
protected theorem swap {f : α → β → σ} (h : Primrec₂ f) : Primrec₂ (swap f) :=
466+
h.comp₂ Primrec₂.right Primrec₂.left
467+
468+
protected theorem _root_.PrimrecRel.swap {r : α → β → Prop} (h : PrimrecRel r) :
469+
PrimrecRel (swap r) :=
443470
h.comp₂ Primrec₂.right Primrec₂.left
444471

445472
theorem nat_iff {f : α → β → σ} : Primrec₂ f ↔ Nat.Primrec
@@ -465,7 +492,11 @@ variable {α : Type*} {β : Type*} {σ : Type*}
465492
variable [Primcodable α] [Primcodable β] [Primcodable σ]
466493

467494
theorem to₂ {f : α × β → σ} (hf : Primrec f) : Primrec₂ fun a b => f (a, b) :=
468-
hf.of_eq fun _ => rfl
495+
hf
496+
497+
lemma _root_.PrimrecPred.primrecRel {p : α × β → Prop} (hp : PrimrecPred p) :
498+
PrimrecRel fun a b => p (a, b) :=
499+
hp
469500

470501
theorem nat_rec {f : α → β} {g : α → ℕ × β → β} (hf : Primrec f) (hg : Primrec₂ g) :
471502
Primrec₂ fun a (n : ℕ) => n.rec (motive := fun _ => β) (f a) fun n IH => g a (n, IH) :=
@@ -571,14 +602,14 @@ theorem cond {c : α → Bool} {f : α → σ} {g : α → σ} (hc : Primrec c)
571602

572603
theorem ite {c : α → Prop} [DecidablePred c] {f : α → σ} {g : α → σ} (hc : PrimrecPred c)
573604
(hf : Primrec f) (hg : Primrec g) : Primrec fun a => if c a then f a else g a := by
574-
simpa [Bool.cond_decide] using cond hc hf hg
605+
simpa [Bool.cond_decide] using cond hc.decide hf hg
575606

576607
theorem nat_le : PrimrecRel ((· ≤ ·) : ℕ → ℕ → Prop) :=
577-
(nat_casesOn nat_sub (const true) (const false).to₂).of_eq fun p => by
608+
Primrec₂.primrecRel ((nat_casesOn nat_sub (const true) (const false).to₂).of_eq fun p => by
578609
dsimp [swap]
579610
rcases e : p.1 - p.2 with - | n
580611
· simp [Nat.sub_eq_zero_iff_le.1 e]
581-
· simp [not_le.2 (Nat.lt_of_sub_eq_succ e)]
612+
· simp [not_le.2 (Nat.lt_of_sub_eq_succ e)])
582613

583614
theorem nat_min : Primrec₂ (@min ℕ _) :=
584615
ite nat_le fst snd
@@ -602,30 +633,31 @@ protected theorem and : Primrec₂ and :=
602633
protected theorem or : Primrec₂ or :=
603634
dom_bool₂ _
604635

605-
theorem _root_.PrimrecPred.not {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) :
606-
PrimrecPred fun a => ¬p a :=
607-
(Primrec.not.comp hp).of_eq fun n => by simp
636+
protected theorem _root_.PrimrecPred.not {p : α → Prop} :
637+
(hp : PrimrecPred p) → PrimrecPred fun a => ¬p a
638+
| ⟨_, hp⟩ => Primrec.primrecPred <| Primrec.not.comp hp |>.of_eq <| by simp
608639

609-
theorem _root_.PrimrecPred.and {p q : α → Prop} [DecidablePred p] [DecidablePred q]
610-
(hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∧ q a :=
611-
(Primrec.and.comp hp hq).of_eq fun n => by simp
640+
protected theorem _root_.PrimrecPred.and {p q : α → Prop} :
641+
(hp : PrimrecPred p) (hq : PrimrecPred q) PrimrecPred fun a => p a ∧ q a
642+
| ⟨_, hp⟩, ⟨_, hq⟩ => Primrec.primrecPred <| Primrec.and.comp hp hq |>.of_eq <| by simp
612643

613-
theorem _root_.PrimrecPred.or {p q : α → Prop} [DecidablePred p] [DecidablePred q]
614-
(hp : PrimrecPred p) (hq : PrimrecPred q) : PrimrecPred fun a => p a ∨ q a :=
615-
(Primrec.or.comp hp hq).of_eq fun n => by simp
644+
protected theorem _root_.PrimrecPred.or {p q : α → Prop} :
645+
(hp : PrimrecPred p) (hq : PrimrecPred q) PrimrecPred fun a => p a ∨ q a
646+
| ⟨_, hp⟩, ⟨_, hq⟩ => Primrec.primrecPred <| Primrec.or.comp hp hq |>.of_eq <| by simp
616647

617-
protected theorem beq [DecidableEq α] : Primrec₂ (@BEq.beq α _) :=
648+
protected theorem eq : PrimrecRel (@Eq α) :=
618649
have : PrimrecRel fun a b : ℕ => a = b :=
619650
(PrimrecPred.and nat_le nat_le.swap).of_eq fun a => by simp [le_antisymm_iff]
620-
(this.comp₂ (Primrec.encode.comp₂ Primrec₂.left) (Primrec.encode.comp₂ Primrec₂.right)).of_eq
651+
(this.decide.comp₂ (Primrec.encode.comp₂ Primrec₂.left)
652+
(Primrec.encode.comp₂ Primrec₂.right)).primrecRel.of_eq
621653
fun _ _ => encode_injective.eq_iff
622654

623-
protected theorem eq [DecidableEq α] : PrimrecRel (@Eq α) := Primrec.beq
655+
protected theorem beq [DecidableEq α] : Primrec₂ (@BEq.beq α _) := Primrec.eq.decide
624656

625657
theorem nat_lt : PrimrecRel ((· < ·) : ℕ → ℕ → Prop) :=
626658
(nat_le.comp snd fst).not.of_eq fun p => by simp
627659

628-
theorem option_guard {p : α → β → Prop} [∀ a b, Decidable (p a b)] (hp : PrimrecRel p) {f : α → β}
660+
theorem option_guard {p : α → β → Prop} [DecidableRel p] (hp : PrimrecRel p) {f : α → β}
629661
(hf : Primrec f) : Primrec fun a => Option.guard (p a) (f a) :=
630662
ite (by simpa using hp.comp Primrec.id hf) (option_some_iff.2 hf) (const none)
631663

@@ -634,7 +666,7 @@ theorem option_orElse : Primrec₂ ((· <|> ·) : Option α → Option α → Op
634666

635667
protected theorem decode₂ : Primrec (decode₂ α) :=
636668
option_bind .decode <|
637-
option_guard (Primrec.beq.comp₂ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd
669+
option_guard (Primrec.eq.comp₂ (by exact encode_iff.mpr snd) (by exact fst.comp fst)) snd
638670

639671
theorem list_findIdx₁ {p : α → β → Bool} (hp : Primrec₂ p) :
640672
∀ l : List β, Primrec fun a => l.findIdx (p a)
@@ -659,7 +691,7 @@ theorem dom_fintype [Finite α] (f : α → σ) : Primrec f :=
659691
def PrimrecBounded (f : α → β) : Prop :=
660692
∃ g : α → ℕ, Primrec g ∧ ∀ x, encode (f x) ≤ g x
661693

662-
theorem nat_findGreatest {f : α → ℕ} {p : α → ℕ → Prop} [∀ x n, Decidable (p x n)]
694+
theorem nat_findGreatest {f : α → ℕ} {p : α → ℕ → Prop} [DecidableRel p]
663695
(hf : Primrec f) (hp : PrimrecRel p) : Primrec fun x => (f x).findGreatest (p x) :=
664696
(nat_rec' (h := fun x nih => if p x (nih.1 + 1) then nih.1 + 1 else nih.2)
665697
hf (const 0) (ite (hp.comp fst (snd |> fst.comp |> succ.comp))
@@ -1091,19 +1123,21 @@ namespace PrimrecPred
10911123

10921124
open List Primrec
10931125

1094-
variable {α β : Type*} {p : α → Prop} [DecidablePred p] {L : List α} {b : β}
1126+
variable {α β : Type*} {p : α → Prop} {L : List α} {b : β}
10951127

10961128
variable [Primcodable α] [Primcodable β]
10971129

10981130
/-- Checking if any element of a list satisfies a decidable predicate is primitive recursive. -/
1099-
theorem exists_mem_list (hf : PrimrecPred p) : PrimrecPred fun L : List α ↦ ∃ a ∈ L, p a :=
1100-
.of_eq (.not <| PrimrecRel.comp .eq (list_length.comp <| listFilter hf) (const 0)) <| by simp
1131+
theorem exists_mem_list : (hf : PrimrecPred p) → PrimrecPred fun L : List α ↦ ∃ a ∈ L, p a
1132+
| ⟨_, hf⟩ => .of_eq
1133+
(.not <| Primrec.eq.comp (list_length.comp <| listFilter hf.primrecPred) (const 0)) <| by simp
11011134

11021135
/-- Checking if every element of a list satisfies a decidable predicate is primitive recursive. -/
1103-
theorem forall_mem_list (hf : PrimrecPred p) : PrimrecPred fun L : List α ↦ ∀ a ∈ L, p a :=
1104-
.of_eq (PrimrecRel.comp .eq (list_length.comp <| listFilter hf) (list_length)) <| by simp
1136+
theorem forall_mem_list : (hf : PrimrecPred p) → PrimrecPred fun L : List α ↦ ∀ a ∈ L, p a
1137+
| ⟨_, hf⟩ => .of_eq
1138+
(Primrec.eq.comp (list_length.comp <| listFilter hf.primrecPred) (list_length)) <| by simp
11051139

1106-
variable {p : ℕ → Prop} [DecidablePred p]
1140+
variable {p : ℕ → Prop}
11071141

11081142
/-- Bounded existential quantifiers are primitive recursive. -/
11091143
theorem exists_lt (hf : PrimrecPred p) : PrimrecPred fun n ↦ ∃ x < n, p x :=
@@ -1118,45 +1152,47 @@ theorem listFilter_listRange {R : ℕ → ℕ → Prop} (s : ℕ) [DecidableRel
11181152
Primrec fun n ↦ (range s).filter (fun y ↦ R y n) := by
11191153
simp only [← filterMap_eq_filter]
11201154
refine listFilterMap (.const (range s)) ?_
1121-
refine ite (PrimrecRel.comp .eq ?_ (const true)) (option_some_iff.mpr snd) (.const Option.none)
1122-
exact hf.comp snd fst
1155+
refine ite (Primrec.eq.comp ?_ (const true)) (option_some_iff.mpr snd) (.const Option.none)
1156+
exact hf.decide.comp snd fst
11231157

11241158
end PrimrecPred
11251159

11261160
namespace PrimrecRel
11271161

11281162
open Primrec List PrimrecPred
11291163

1130-
variable {α β : Type*} {R : α → β → Prop} [DecidableRel R] {L : List α} {b : β}
1164+
variable {α β : Type*} {R : α → β → Prop} {L : List α} {b : β}
11311165

11321166
variable [Primcodable α] [Primcodable β]
11331167

11341168
protected theorem not (hf : PrimrecRel R) : PrimrecRel fun a b ↦ ¬ R a b := PrimrecPred.not hf
11351169

11361170
/-- If `R a b` is decidable, then given `L : List α` and `b : β`, it is primitive recurisve
11371171
to filter `L` for elements `a` with `R a b` -/
1138-
theorem listFilter (hf : PrimrecRel R) :
1172+
theorem listFilter (hf : PrimrecRel R) [DecidableRel R] :
11391173
Primrec₂ fun (L : List α) b ↦ L.filter (fun a ↦ R a b) := by
11401174
simp only [← List.filterMap_eq_filter]
11411175
refine listFilterMap fst (Primrec.ite ?_ ?_ (Primrec.const Option.none))
1142-
· exact PrimrecRel.comp .eq (hf.comp snd (snd.comp fst)) (.const true)
1176+
· exact Primrec.eq.comp (hf.decide.comp snd (snd.comp fst)) (.const true)
11431177
· exact (option_some).comp snd
11441178

11451179
/-- If `R a b` is decidable, then given `L : List α` and `b : β`, `g L b ↔ ∃ a L, R a b`
11461180
is a primitive recursive relation. -/
11471181
theorem exists_mem_list (hf : PrimrecRel R) : PrimrecRel fun (L : List α) b ↦ ∃ a ∈ L, R a b := by
1182+
classical
11481183
have h (L) (b) : (List.filter (R · b) L).length ≠ 0 ↔ ∃ a ∈ L, R a b := by simp
11491184
refine .of_eq (.not ?_) h
1150-
exact .comp .eq (list_length.comp hf.listFilter) (const 0)
1185+
exact Primrec.eq.comp (list_length.comp hf.listFilter) (const 0)
11511186

11521187
/-- If `R a b` is decidable, then given `L : List α` and `b : β`, `g L b ↔ ∀ a L, R a b`
11531188
is a primitive recursive relation. -/
11541189
theorem forall_mem_list (hf : PrimrecRel R) : PrimrecRel fun (L : List α) b ↦ ∀ a ∈ L, R a b := by
1190+
classical
11551191
have h (L) (b) : (List.filter (R · b) L).length = L.length ↔ ∀ a ∈ L, R a b := by simp
11561192
apply PrimrecRel.of_eq ?_ h
1157-
exact (.comp .eq (list_length.comp <| PrimrecRel.listFilter hf) (.comp list_length fst))
1193+
exact (Primrec.eq.comp (list_length.comp <| PrimrecRel.listFilter hf) (.comp list_length fst))
11581194

1159-
variable {R : ℕ → ℕ → Prop} [DecidableRel R]
1195+
variable {R : ℕ → ℕ → Prop}
11601196

11611197
/-- If `R a b` is decidable, then for any fixed `n` and `y`, `g n y ↔ ∃ x < n, R x y` is a
11621198
primitive recursive relation. -/
@@ -1179,7 +1215,7 @@ open Primrec
11791215
/-- A subtype of a primitive recursive predicate is `Primcodable`. -/
11801216
def subtype {p : α → Prop} [DecidablePred p] (hp : PrimrecPred p) : Primcodable (Subtype p) :=
11811217
have : Primrec fun n => (@decode α _ n).bind fun a => Option.guard p a :=
1182-
option_bind .decode (option_guard (hp.comp snd).to₂ snd)
1218+
option_bind .decode (option_guard (hp.comp snd).primrecRel snd)
11831219
nat_iff.1 <| (encode_iff.2 this).of_eq fun n =>
11841220
show _ = encode ((@decode α _ n).bind fun _ => _) by
11851221
rcases @decode α _ n with - | a; · rfl
@@ -1190,7 +1226,7 @@ instance fin {n} : Primcodable (Fin n) :=
11901226
@ofEquiv _ _ (subtype <| nat_lt.comp .id (const n)) Fin.equivSubtype
11911227

11921228
instance vector {n} : Primcodable (List.Vector α n) :=
1193-
subtype ((@Primrec.eq ℕ _ _).comp list_length (const _))
1229+
subtype ((@Primrec.eq ℕ _).comp list_length (const _))
11941230

11951231
instance finArrow {n} : Primcodable (Fin n → α) :=
11961232
ofEquiv _ (Equiv.vectorEquivFin _ _).symm

0 commit comments

Comments
 (0)