feat: unfold namedPattern applications at equation theorems

This commit is contained in:
Leonardo de Moura 2022-01-18 15:03:20 -08:00
parent 1e21815e41
commit 873a2ba8a6
2 changed files with 10 additions and 0 deletions

View file

@ -88,6 +88,7 @@ private def saveEqn (mvarId : MVarId) : StateRefT (Array Expr) MetaM Unit := wit
if missing?.isNone then
fvarIds := fvarIds.push decl.fvarId
let type ← mkForallFVars (fvarIds.map mkFVar) target
let type ← Match.unfoldNamedPattern type
modify (·.push type)
partial def mkEqnTypes (declNames : Array Name) (mvarId : MVarId) : MetaM (Array Expr) := do

View file

@ -273,6 +273,14 @@ where
let mvarId ← tryClearMany mvarId (alts.map (·.fvarId!))
proveSubgoalLoop mvarId
def unfoldNamedPattern (e : Expr) : MetaM Expr := do
let visit (e : Expr) : MetaM TransformStep := do
if e.isAppOfArity ``namedPattern 4 then
if let some eNew ← unfoldDefinition? e then
return TransformStep.visit eNew
return TransformStep.visit e
Meta.transform e (pre := visit)
/--
Create conditional equations and splitter for the given match auxiliary declaration. -/
private partial def mkEquationsFor (matchDeclName : Name) : MetaM MatchEqns :=
@ -316,6 +324,7 @@ private partial def mkEquationsFor (matchDeclName : Name) : MetaM MatchEqns :=
let thmType ← mkEq lhs rhs
let thmType ← hs.foldrM (init := thmType) mkArrow
let thmType ← mkForallFVars (params ++ #[motive] ++ alts ++ ys) thmType
let thmType ← unfoldNamedPattern thmType
let thmVal ← proveCondEqThm matchDeclName thmType
addDecl <| Declaration.thmDecl {
name := thmName