feat: add getNondepPropHyps
This commit is contained in:
parent
dd8ead186f
commit
da8e5150c9
2 changed files with 35 additions and 0 deletions
|
|
@ -69,6 +69,10 @@ def value : LocalDecl → Expr
|
|||
| cdecl .. => panic! "let declaration expected"
|
||||
| ldecl (value := v) .. => v
|
||||
|
||||
def hasValue : LocalDecl → Bool
|
||||
| cdecl .. => false
|
||||
| ldecl .. => true
|
||||
|
||||
def setValue : LocalDecl → Expr → LocalDecl
|
||||
| ldecl idx id n t _ nd, v => ldecl idx id n t v nd
|
||||
| d, _ => d
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ Copyright (c) 2019 Microsoft Corporation. All rights reserved.
|
|||
Released under Apache 2.0 license as described in the file LICENSE.
|
||||
Authors: Leonardo de Moura
|
||||
-/
|
||||
import Lean.Util.ForEachExpr
|
||||
import Lean.Meta.Basic
|
||||
import Lean.Meta.AppBuilder
|
||||
import Lean.Meta.LevelDefEq
|
||||
|
|
@ -57,4 +58,34 @@ def admit (mvarId : MVarId) (synthetic := true) : MetaM Unit :=
|
|||
def headBetaMVarType (mvarId : MVarId) : MetaM Unit := do
|
||||
setMVarType mvarId (← getMVarType mvarId).headBeta
|
||||
|
||||
/-- Collect nondependent hypotheses. -/
|
||||
def getNondepPropHyps (mvarId : MVarId) : MetaM (Array FVarId) :=
|
||||
withMVarContext mvarId do
|
||||
let mut candidates : NameHashSet := {}
|
||||
for localDecl in (← getLCtx) do
|
||||
candidates ← removeDeps localDecl.type candidates
|
||||
match localDecl.value? with
|
||||
| none => pure ()
|
||||
| some value => candidates ← removeDeps value candidates
|
||||
if (← isProp localDecl.type) && !localDecl.hasValue then
|
||||
candidates := candidates.insert localDecl.fvarId
|
||||
candidates ← removeDeps (← getMVarType mvarId) candidates
|
||||
if candidates.isEmpty then
|
||||
return #[]
|
||||
else
|
||||
let mut result := #[]
|
||||
for localDecl in (← getLCtx) do
|
||||
if candidates.contains localDecl.fvarId then
|
||||
result := result.push localDecl.fvarId
|
||||
return result
|
||||
where
|
||||
removeDeps (e : Expr) (candidates : NameHashSet) : MetaM NameHashSet := do
|
||||
let e ← instantiateMVars e
|
||||
let visit : StateRefT NameHashSet MetaM NameHashSet := do
|
||||
e.forEach fun
|
||||
| Expr.fvar fvarId _ => modify fun s => s.erase fvarId
|
||||
| _ => pure ()
|
||||
get
|
||||
visit |>.run' candidates
|
||||
|
||||
end Lean.Meta
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue