Lean4
/-- Apply symmetry to `H`, which is an `Eq` or a `HEq`.
* If `heqProofs` is true, ensure the result is a `HEq` (otherwise it is assumed to be `Eq`).
* If `flipped` is true, apply `symm`, otherwise keep the same direction. -/
def flipProofCore (H : Expr) (flipped heqProofs : Bool) : CCM Expr := do
let mut newH := H
if ← liftM <| pure heqProofs <&&> Expr.isEq <$> (inferType H >>= whnf) then
newH ← mkAppM ``heq_of_eq #[H]
if !flipped then
return newH
else if heqProofs then
mkHEqSymm newH
else
mkEqSymm newH