Lean4
/-- `applyContrLemma` inspects the target to see if it can be moved to a hypothesis by negation.
For example, a goal `⊢ a ≤ b` can become `b < a ⊢ false`.
If this is the case, it applies the appropriate lemma and introduces the new hypothesis.
It returns the type of the terms in the comparison (e.g. the type of `a` and `b` above) and the
newly introduced local constant.
Otherwise returns `none`.
-/
def applyContrLemma (g : MVarId) : MetaM (Option (Expr × Expr) × MVarId) := do
try
let (nm, tp) ← getContrLemma (← withReducible g.getType')
let [g] ← g.apply (← mkConst' nm) |
failure
let (f, g) ← g.intro1P
return (some (tp, .fvar f), g)
catch _ =>
return (none, g)