-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add let_intros for better experience with levels about functions
- Loading branch information
1 parent
6cdbfbd
commit 9bc0a3d
Showing
6 changed files
with
123 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,3 +117,5 @@ $$ | |
\\end{CD} | ||
$$ | ||
``` | ||
|
||
See https://www.jmilne.org/not/Mamscd.pdf |
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,65 @@ | ||
import Lean.Elab.Binders | ||
import Lean.Elab.Tactic.Basic | ||
import Lean.Meta.Tactic.Intro | ||
|
||
/-! | ||
# `let_intros` Tactic | ||
`let_intros` is a weaker form of `intros` aimed to only introduce `let` statements, | ||
but not for example `∀`-binders. | ||
-/ | ||
|
||
namespace GameServer | ||
|
||
open Lean Meta Elab Parser Tactic | ||
|
||
/-- | ||
Copied from `Lean.Meta.getIntrosSize`. | ||
-/ | ||
private partial def getLetIntrosSize : Expr → Nat | ||
-- | .forallE _ _ b _ => getLetIntrosSize b + 1 | ||
| .letE _ _ _ b _ => getLetIntrosSize b + 1 | ||
| .mdata _ b => getLetIntrosSize b | ||
| e => | ||
if let some (_, _, _, b) := e.letFun? then | ||
getLetIntrosSize b + 1 | ||
else | ||
0 | ||
|
||
/-- | ||
Copied and from `Lean.MVarId.intros`. | ||
-/ | ||
def _root_.Lean.MVarId.letIntros (mvarId : MVarId) : MetaM (Array FVarId × MVarId) := do | ||
let type ← mvarId.getType | ||
let type ← instantiateMVars type | ||
let n := getLetIntrosSize type | ||
if n == 0 then | ||
return (#[], mvarId) | ||
else | ||
-- `introNP` preserves the binder names | ||
mvarId.introNP n | ||
|
||
/-- | ||
`let_intros` introduces all `let` statements that are preceeding the proof. Concretely | ||
it does a subset of what `intros` does. | ||
If names are provided, it will introduce as many `let` statements as there are names. | ||
-/ | ||
syntax (name := letIntros) "let_intros" : tactic | ||
-- (ppSpace colGt (ident <|> hole))* | ||
|
||
#check letIntros | ||
|
||
@[tactic letIntros] def evalLetIntros : Tactic := fun stx => do | ||
match stx with | ||
| `(tactic| let_intros) => liftMetaTactic fun mvarId => do | ||
let (_, mvarId) ← mvarId.letIntros | ||
return [mvarId] | ||
-- | `(tactic| let_intros $ids*) => do | ||
-- let fvars ← liftMetaTacticAux fun mvarId => do | ||
-- let (fvars, mvarId) ← mvarId.introN ids.size (ids.map getNameOfIdent').toList | ||
-- return (fvars, [mvarId]) | ||
-- withMainContext do | ||
-- for stx in ids, fvar in fvars do | ||
-- Term.addLocalVarInfo stx (mkFVar fvar) | ||
| _ => throwUnsupportedSyntax |
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,17 @@ | ||
import GameServer.Tactic.LetIntros | ||
|
||
set_option linter.unusedVariables false in | ||
|
||
example (f : Nat) : | ||
let f := fun x ↦ x + 1 | ||
let g : Nat → Nat := fun y ↦ y | ||
∀ x : Nat, x ≤ f x := by | ||
let_intros | ||
/- | ||
f✝ : Nat | ||
f : Nat → Nat := fun x => x + 1 | ||
g : Nat → Nat := fun y => y | ||
⊢ ∀ (x : Nat), x ≤ f x | ||
-/ | ||
intro x | ||
exact Nat.le_succ x |