@@ -127,7 +127,7 @@ end SimpH
127127 Recall that each equation contains additional hypotheses to ensure the associated case was not taken by previous cases.
128128 We have one hypothesis for each previous case.
129129-/
130- public partial def simpH ? (h : Expr) (numEqs : Nat) : MetaM (Option Expr) := withDefault do
130+ public partial def simpHWithProof ? (h : Expr) (numEqs : Nat) : MetaM (Option Expr × Expr) := withDefault do
131131 let numVars ← forallTelescope h fun ys _ => pure (ys.size - numEqs)
132132 let prf ← mkFreshExprSyntheticOpaqueMVar h
133133 let mvarId := prf.mvarId!
@@ -138,18 +138,23 @@ public partial def simpH? (h : Expr) (numEqs : Nat) : MetaM (Option Expr) := wit
138138 if r then
139139 s.mvarId.withContext do
140140 let eqs := s.eqsNew.reverse.toArray
141- let mvarId := s.mvarId
142- let mvarId := (← mvarId.revert eqs).2
141+ let mvarId' := s.mvarId
142+ let mvarId' := (← mvarId' .revert eqs).2
143143 /- We only include variables in `xs` if there is a dependency. -/
144- let r ← mvarId.getType
145- mvarId.withContext do
144+ let r ← mvarId' .getType
145+ mvarId' .withContext do
146146 let xs ← s.xs.toArray.reverse.filterM (dependsOn r ·)
147- let mvarId := (← mvarId.revert xs).2
148- let r ← mvarId.getType
147+ let mvarId' := (← mvarId' .revert xs).2
148+ let r ← mvarId' .getType
149149 trace[Meta.Match.matchEqs] "simplified hypothesis{indentExpr r}"
150- return some r
150+ let prf ← instantiateMVars prf
151+ let prf ← mkLambdaFVars (binderInfoForMVars := .default) #[mkMVar mvarId'] prf
152+ return (some r, prf)
151153 else
152154 let prf ← instantiateMVars prf
153155 if prf.hasMVar then
154156 throwError "simpH failed, but proof is incomplete:{indentExpr prf}"
155- return none
157+ return (none, prf)
158+
159+ public def simpH? (h : Expr) (numEqs : Nat) : MetaM (Option Expr) := do
160+ return (← simpHWithProof? h numEqs).1
0 commit comments