-
Notifications
You must be signed in to change notification settings - Fork 446
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: FunInd: support structural recursion on reflexive types (#4327)
types like ``` inductive Many (α : Type u) where | none : Many α | more : α → (Unit → Many α) → Many α ``` have a `.brecOn` only supports motives producing `Type u`, but not `Sort u`, but our induction principles produce `Prop`. So the previous implementation of functional induction would fail for functions that structurally recurse over such types. We recognize this case now and, rather hazardously, replace `.brecOn` with `.binductionOn` (and thus `.below ` with `.ibelow` and `PProd` with `And`). This assumes that these definitions are highly analogous. This also improves the error message when realizing a reserved name fails with an exception, by prepending ``` Failed to realize constant {id}: ``` to the error message. Fixes #4320
- Loading branch information
Showing
3 changed files
with
91 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
inductive Many (α : Type u) where | ||
| none : Many α | ||
| more : α → (Unit → Many α) → Many α | ||
|
||
def many_map {α β : Type} (f : α → β) : Many α → Many β | ||
| .none => .none | ||
| .more x xs => Many.more (f x) (fun () => many_map f <| xs ()) | ||
|
||
/-- | ||
info: many_map.induct {α β : Type} (f : α → β) (motive : Many α → Prop) (case1 : motive Many.none) | ||
(case2 : ∀ (x : α) (xs : Unit → Many α), motive (xs ()) → motive (Many.more x xs)) : ∀ (a : Many α), motive a | ||
-/ | ||
#guard_msgs in | ||
#check many_map.induct | ||
|
||
-- Unrelated, but for fun, show that we get the identical theorem from well-founded recursion | ||
|
||
def many_map' {α β : Type} (f : α → β) : Many α → Many β | ||
| .none => .none | ||
| .more x xs => Many.more (f x) (fun () => many_map' f <| xs ()) | ||
termination_by m => m | ||
|
||
example : @many_map.induct = @many_map'.induct := rfl |