-
Notifications
You must be signed in to change notification settings - Fork 345
/
Delta.lean
51 lines (43 loc) · 1.91 KB
/
Delta.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/-
Copyright (c) 2020 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import Lean.Meta.Transform
import Lean.Meta.Tactic.Replace
namespace Lean.Meta
def delta? (e : Expr) (p : Name → Bool := fun _ => true) : CoreM (Option Expr) :=
matchConst e.getAppFn (fun _ => return none) fun fInfo fLvls => do
if p fInfo.name && fInfo.hasValue && fInfo.levelParams.length == fLvls.length then
let f ← instantiateValueLevelParams fInfo fLvls
return some (f.betaRev e.getAppRevArgs (useZeta := true))
else
return none
/-- Low-level delta expansion. It is used to implement equation lemmas and elimination principles for recursive definitions. -/
def deltaExpand (e : Expr) (p : Name → Bool) : CoreM Expr :=
Core.transform e fun e => do
match (← delta? e p) with
| some e' => return .visit e'
| none => return .continue
/--
Delta expand declarations that satisfy `p` at `mvarId` type.
-/
def _root_.Lean.MVarId.deltaTarget (mvarId : MVarId) (p : Name → Bool) : MetaM MVarId :=
mvarId.withContext do
mvarId.checkNotAssigned `delta
mvarId.change (← deltaExpand (← mvarId.getType) p) (checkDefEq := false)
@[deprecated MVarId.deltaTarget (since := "2022-07-15")]
def deltaTarget (mvarId : MVarId) (p : Name → Bool) : MetaM MVarId :=
mvarId.deltaTarget p
/--
Delta expand declarations that satisfy `p` at `fvarId` type.
-/
def _root_.Lean.MVarId.deltaLocalDecl (mvarId : MVarId) (fvarId : FVarId) (p : Name → Bool) : MetaM MVarId :=
mvarId.withContext do
mvarId.checkNotAssigned `delta
mvarId.changeLocalDecl fvarId (← deltaExpand (← mvarId.getType) p) (checkDefEq := false)
@[deprecated MVarId.deltaLocalDecl (since := "2022-07-15")]
def deltaLocalDecl (mvarId : MVarId) (fvarId : FVarId) (p : Name → Bool) : MetaM MVarId :=
mvarId.deltaLocalDecl fvarId p
end Lean.Meta