Lean4
/-- Given a proposition `ty` that is an `Eq`, `Iff`, or `HEq`, returns `(tyLhs, lhs, tyRhs, rhs)`,
where `lhs : tyLhs` and `rhs : tyRhs`,
and where `lhs` is related to `rhs` by the respective relation.
See also `Lean.Expr.iff?`, `Lean.Expr.eq?`, and `Lean.Expr.heq?`. -/
def sides? (ty : Expr) : Option (Expr × Expr × Expr × Expr) :=
if let some (lhs, rhs) := ty.iff? then some (.sort .zero, lhs, .sort .zero, rhs)
else if let some (ty, lhs, rhs) := ty.eq? then some (ty, lhs, ty, rhs) else ty.heq?