You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: extract functionality from Match.MatchEqs (#11236)
This PR extracts two modules from `Match.MatchEqs`, in preparation of
#11220
and to use the module system to draw clear boundaries between concerns
here.
match (← injections mvarId (forbidden := forbidden)) with
276
-
| .solved => returntrue-- closed goal
277
-
| .subgoal mvarId' _ forbidden =>
278
-
if mvarId' == mvarId then
279
-
contradiction mvarId
280
-
else
281
-
trySubstVarsAndContradiction mvarId' forbidden
282
-
283
-
privatedefprocessNextEq : M Bool := do
284
-
let s ← get
285
-
s.mvarId.withContext do
286
-
iflet eq :: eqs := s.eqs then
287
-
modify fun s => { s with eqs }
288
-
let eqType ← inferType (mkFVar eq)
289
-
-- See `substRHS`. Recall that if `rhs` is a variable then if must be in `s.xs`
290
-
iflet some (_, lhs, rhs) ← matchEq? eqType then
291
-
-- Common case: Different constructors
292
-
match (← isConstructorApp? lhs), (← isConstructorApp? rhs) with
293
-
| some lhsCtor, some rhsCtor =>
294
-
if lhsCtor.name != rhsCtor.name then
295
-
returnfalse-- If the constructors are different, we can discard the hypothesis even if it a heterogeneous equality
296
-
| _,_ => pure ()
297
-
if (← isDefEq lhs rhs) then
298
-
returntrue
299
-
if rhs.isFVar && s.xs.contains rhs.fvarId! then
300
-
substRHS eq rhs.fvarId!
301
-
returntrue
302
-
iflet some (α, lhs, β, rhs) ← matchHEq? eqType then
303
-
-- Try to convert `HEq` into `Eq`
304
-
if (← isDefEq α β) then
305
-
let (eqNew, mvarId) ← heqToEq s.mvarId eq (tryToClear := true)
306
-
modify fun s => { s with mvarId, eqs := eqNew :: s.eqs }
307
-
returntrue
308
-
-- If it is not possible, we try to show the hypothesis is redundant by substituting even variables that are not at `s.xs`, and then use contradiction.
309
-
else
310
-
match (← isConstructorApp? lhs), (← isConstructorApp? rhs) with
311
-
| some lhsCtor, some rhsCtor =>
312
-
if lhsCtor.name != rhsCtor.name then
313
-
returnfalse-- If the constructors are different, we can discard the hypothesis even if it a heterogeneous equality
314
-
elseif (← trySubstVarsAndContradiction s.mvarId) then
315
-
returnfalse
316
-
| _, _ =>
317
-
if (← trySubstVarsAndContradiction s.mvarId) then
318
-
returnfalse
319
-
try
320
-
-- Try to simplify equation using `injection` tactic.
321
-
match (← injection s.mvarId eq) with
322
-
| InjectionResult.solved => returnfalse
323
-
| InjectionResult.subgoal mvarId eqNews .. =>
324
-
modify fun s => { s with mvarId, eqs := eqNews.toList ++ s.eqs }
325
-
catch _ =>
326
-
modify fun s => { s with eqsNew := eq :: s.eqsNew }
327
-
returntrue
328
-
329
-
partialdefgo : M Bool := do
330
-
if (← isDone) then
331
-
returntrue
332
-
elseif (← processNextEq) then
333
-
go
334
-
else
335
-
returnfalse
336
-
337
-
end SimpH
338
-
339
-
/--
340
-
Auxiliary method for simplifying equational theorem hypotheses.
341
-
342
-
Recall that each equation contains additional hypotheses to ensure the associated case was not taken by previous cases.
0 commit comments