Skip to content

Commit 64c3c49

Browse files
committed
Variant
1 parent 32f6654 commit 64c3c49

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/Lean/Meta/Match/SimpH.lean

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,12 @@ end SimpH
122122

123123

124124
/--
125-
Auxiliary method for simplifying equational theorem hypotheses.
126-
127-
Recall that each equation contains additional hypotheses to ensure the associated case was not taken by previous cases.
128-
We have one hypothesis for each previous case.
125+
Like `simpH?`, but works directly on a goal corresponding to the unsimplified equational theorem
126+
hypothesis, and either closes it or returns a residual goal whose type is the simplified equational
127+
theorem hypothesis.
129128
-/
130-
public partial def simpHWithProof? (h : Expr) (numEqs : Nat) : MetaM (Option Expr × Expr) := withDefault do
131-
let numVars ← forallTelescope h fun ys _ => pure (ys.size - numEqs)
132-
let prf ← mkFreshExprSyntheticOpaqueMVar h
133-
let mvarId := prf.mvarId!
129+
public partial def simpH (mvarId : MVarId) (numEqs : Nat) : MetaM (Option MVarId) := withDefault do
130+
let numVars ← forallTelescope (← mvarId.getType) fun ys _ => pure (ys.size - numEqs)
134131
let mvarId ← mvarId.tryClearMany (← getLCtx).getFVarIds
135132
let (xs, mvarId) ← mvarId.introN numVars
136133
let (eqs, mvarId) ← mvarId.introN numEqs
@@ -145,16 +142,19 @@ public partial def simpHWithProof? (h : Expr) (numEqs : Nat) : MetaM (Option Exp
145142
mvarId'.withContext do
146143
let xs ← s.xs.toArray.reverse.filterM (dependsOn r ·)
147144
let mvarId' := (← mvarId'.revert xs).2
148-
let r ← mvarId'.getType
149-
trace[Meta.Match.matchEqs] "simplified hypothesis{indentExpr r}"
150-
let prf ← instantiateMVars prf
151-
let prf ← mkLambdaFVars (binderInfoForMVars := .default) #[mkMVar mvarId'] prf
152-
return (some r, prf)
145+
return (some mvarId')
153146
else
154-
let prf ← instantiateMVars prf
155-
if prf.hasMVar then
156-
throwError "simpH failed, but proof is incomplete:{indentExpr prf}"
157-
return (none, prf)
147+
return none
158148

149+
/--
150+
Auxiliary method for simplifying equational theorem hypotheses.
151+
152+
Recall that each equation contains additional hypotheses to ensure the associated case was not taken by previous cases.
153+
We have one hypothesis for each previous case.
154+
-/
159155
public def simpH? (h : Expr) (numEqs : Nat) : MetaM (Option Expr) := do
160-
return (← simpHWithProof? h numEqs).1
156+
let prf ← mkFreshExprSyntheticOpaqueMVar h
157+
match (← simpH prf.mvarId! numEqs) with
158+
| none => return none
159+
| some mvarId' =>
160+
return some (← mvarId'.getType)

0 commit comments

Comments
 (0)