-
Notifications
You must be signed in to change notification settings - Fork 453
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: functional induction #3432
Conversation
Mathlib CI status (docs):
|
PR #3432 will introduce more operations on `MatcherApp`, including somet that have more dependencies. This change prepares by introducing `Lean.Meta.Match.MatcherApp.Basic` for the basic definition, and `Lean.Meta.MatcherApp.Transform` for the transformations, currently `addArg` and `refineThrough`, but more to come.
PR #3432 will introduce more operations on `MatcherApp`, including somet that have more dependencies. This change prepares by introducing `Lean.Meta.Match.MatcherApp.Basic` for the basic definition, and `Lean.Meta.MatcherApp.Transform` for the transformations, currently `addArg` and `refineThrough`, but more to come.
PR #3432 will introduce more operations on `MatcherApp`, including somet that have more dependencies. This change prepares by introducing `Lean.Meta.Match.MatcherApp.Basic` for the basic definition, and `Lean.Meta.MatcherApp.Transform` for the transformations, currently `addArg` and `refineThrough`, but more to come.
98452f1
to
9daaadb
Compare
fec130b
to
4c65206
Compare
Removes `fvarId` from the local context, and replaces occurrences of it with `e`. | ||
It is the responsibility of the caller to ensure that `e` is well-typed in the context | ||
of any occurrence of `fvarId`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This operation sounds like "substitution" to me, but you're not using that terminology. Why not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No deep reason, just out of consistency with existing function names and doc strings: https://leanprover-community.github.io/mathlib4_docs/Lean/Expr.html#Lean.Expr.replaceFVar
/-- | ||
Performs a possibly type-changing transformation to a `MatcherApp`. | ||
|
||
* `onParams` is run on each parameter and discrimitant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know the term "discrimitant", and my dictionary doesn't either. Is this specialized technical vocabulary, or should it be "scrutinee"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Scrurtinee seems to be mostly GHC lingo, and discrs
is used in the lean code base. 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `onParams` is run on each parameter and discrimitant | |
* `onParams` is run on each parameter and discriminant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency is good here!
"Scrutinee" is also what we called it in Idris 1, but there were plenty of GHC-isms in that code as well, like "zonk".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though "-ant" is "a person or thing performing or causing the stated action". But the thing we're talking about here is not that which is causing discrimination to occur, it's that which is being subject to discrimination. "Discriminee" isn't in any English dictionaries that I could find, but it follows the regular pattern of "-ee" pointing at the object of a verb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed googling shows up Coq docs that (occasionally? rarely?) use of discriminee
, but never discriminant.
But yet:
~/build/lean/lean4 $ git grep discriminant|wc -l
84
~/build/lean/lean4 $ git grep discriminee|wc -l
0
I don’t mind changing that, but if we do, then everywhere separate of this PR.
Do we need a little “glossary and nomenclature” document somewhere where we can keep track of such decisions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"scrutinee" is also used in the Rust reference: https://doc.rust-lang.org/reference/expressions/match-expr.html#match-expressions
2cb8009
to
d9f9e2c
Compare
This adds the concept of **functional induction** to lean. Derived from the definition of a (possibly mutually) recursive function, a **functional induction principle** is tailored to proofs about that function. For example from: ``` def ackermann : Nat → Nat → Nat | 0, m => m + 1 | n+1, 0 => ackermann n 1 | n+1, m+1 => ackermann n (ackermann (n + 1) m) derive_functional_induction ackermann ``` we get ``` ackermann.induct (motive : Nat → Nat → Prop) (case1 : ∀ (m : Nat), motive 0 m) (case2 : ∀ (n : Nat), motive n 1 → motive (Nat.succ n) 0) (case3 : ∀ (n m : Nat), motive (n + 1) m → motive n (ackermann (n + 1) m) → motive (Nat.succ n) (Nat.succ m)) (x x : Nat) : motive x x ``` At the moment, the user has to ask for the functional induction principle explicitly using ``` derive_functional_induction ackermann ``` The module docstring of `Lean/Meta/Tactic/FunInd.lean` contains more details on the design and implementation of this command. More convenience around this (e.g. a `functional induction` tactic) will follow eventually. This PR includes a bunch of `PSum`/`PSigma` related functions in the `Lean.Tactic.FunInd` namespace. I plan to move these to `PackArgs`/`PackMutual` afterwards, and do some cleaning up as I do that. --------- Co-authored-by: David Thrane Christiansen <[email protected]> Co-authored-by: Leonardo de Moura <[email protected]>
This adds the concept of **functional induction** to lean. Derived from the definition of a (possibly mutually) recursive function, a **functional induction principle** is tailored to proofs about that function. For example from: ``` def ackermann : Nat → Nat → Nat | 0, m => m + 1 | n+1, 0 => ackermann n 1 | n+1, m+1 => ackermann n (ackermann (n + 1) m) derive_functional_induction ackermann ``` we get ``` ackermann.induct (motive : Nat → Nat → Prop) (case1 : ∀ (m : Nat), motive 0 m) (case2 : ∀ (n : Nat), motive n 1 → motive (Nat.succ n) 0) (case3 : ∀ (n m : Nat), motive (n + 1) m → motive n (ackermann (n + 1) m) → motive (Nat.succ n) (Nat.succ m)) (x x : Nat) : motive x x ``` At the moment, the user has to ask for the functional induction principle explicitly using ``` derive_functional_induction ackermann ``` The module docstring of `Lean/Meta/Tactic/FunInd.lean` contains more details on the design and implementation of this command. More convenience around this (e.g. a `functional induction` tactic) will follow eventually. This PR includes a bunch of `PSum`/`PSigma` related functions in the `Lean.Tactic.FunInd` namespace. I plan to move these to `PackArgs`/`PackMutual` afterwards, and do some cleaning up as I do that. --------- Co-authored-by: David Thrane Christiansen <[email protected]> Co-authored-by: Leonardo de Moura <[email protected]>
This adds the concept of functional induction to lean.
Derived from the definition of a (possibly mutually) recursive function, a functional
induction principle is tailored to proofs about that function. For example from:
we get
At the moment, the user has to ask for the functional induction principle explicitly using
The module docstring of
Lean/Meta/Tactic/FunInd.lean
contains more details on thedesign and implementation of this command.
More convenience around this (e.g. a
functional induction
tactic) will follow eventually.This PR includes a bunch of
PSum
/PSigma
related functions in theLean.Tactic.FunInd
namespace. I plan to move these to
PackArgs
/PackMutual
afterwards, and do some cleaningup as I do that.