Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 2c74921

Browse files
committed
feat(data/pfun): A new induction on pfun.fix (#12109)
A new lemma that lets you prove predicates given `b ∈ f.fix a` if `f` preserves the predicate, and it holds for values which `f` maps to `b`.
1 parent 9b333b2 commit 2c74921

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/data/pfun.lean

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,36 @@ end⟩
236236
/-- A recursion principle for `pfun.fix`. -/
237237
@[elab_as_eliminator] def fix_induction
238238
{f : α →. β ⊕ α} {b : β} {C : α → Sort*} {a : α} (h : b ∈ f.fix a)
239-
(H : ∀ a, b ∈ f.fix a →
240-
(∀ a', b ∈ f.fix a' → sum.inr a' ∈ f a → C a') → C a) : C a :=
239+
(H : ∀ a', b ∈ f.fix a'
240+
(∀ a'', b ∈ f.fix a'' → sum.inr a'' ∈ f a' → C a'') → C a') : C a :=
241241
begin
242242
replace h := part.mem_assert_iff.1 h,
243243
have := h.snd, revert this,
244244
induction h.fst with a ha IH, intro h₂,
245245
refine H a (part.mem_assert_iff.2 ⟨⟨_, ha⟩, h₂⟩)
246-
(λ a' ha' fa', _),
247-
have := (part.mem_assert_iff.1 ha').snd,
248-
exact IH _ fa' ⟨ha _ fa', thisthis
246+
(λ a'' ha'' fa'', _),
247+
have := (part.mem_assert_iff.1 ha'').snd,
248+
exact IH _ fa'' ⟨ha _ fa'', thisthis,
249+
end
250+
251+
/--
252+
Another induction lemma for `b ∈ f.fix a` which allows one to prove a predicate `P` holds for
253+
`a` given that `f a` inherits `P` from `a` and `P` holds for preimages of `b`.
254+
-/
255+
@[elab_as_eliminator]
256+
def fix_induction'
257+
(f : α →. β ⊕ α) (b : β) {C : α → Sort*} {a : α} (h : b ∈ f.fix a)
258+
(hbase : ∀ a_final : α, sum.inl b ∈ f a_final → C a_final)
259+
(hind : ∀ a₀ a₁ : α, b ∈ f.fix a₁ → sum.inr a₁ ∈ f a₀ → C a₁ → C a₀) : C a :=
260+
begin
261+
refine fix_induction h (λ a' h ih, _),
262+
cases e : (f a').get (dom_of_mem_fix h) with b' a''; replace e : _ ∈ f a' := ⟨_, e⟩,
263+
{ have : b' = b,
264+
{ obtain h'' | ⟨a, h'', _⟩ := mem_fix_iff.1 h; cases part.mem_unique e h'', refl },
265+
subst this, exact hbase _ e },
266+
{ have : b ∈ f.fix a'',
267+
{ obtain h'' | ⟨a, h'', e'⟩ := mem_fix_iff.1 h; cases part.mem_unique e h'', exact e' },
268+
refine hind _ _ this e (ih _ this e) },
249269
end
250270

251271
variables (f : α →. β)

0 commit comments

Comments
 (0)