Lean4
/-- Triggers on goals of the form `∃ a, body` and checks whether `body` has the
form `... ∧ a = a' ∧ ...` or `... ∧ a' = a ∧ ...` for some `a'` that is independent of `a`.
If so, it replaces all occurrences of `a` with `a'` and removes the quantifier. -/
def existsAndEq : Lean.Meta.Simp.Simproc := fun e => do
match e.getAppFnArgs with
| (``Exists, #[_, p]) =>
let some ⟨res, pf⟩ ← existsAndEq.findImpEqProof p |
return .continue
return .visit { expr := mkApp p res, proof? := pf }
| _ =>
return .continue