import sympy
from sympy.logic.boolalg import Equivalent

def is_equivalent(expr1, expr2):
    """
    Checks if two logical expressions are mathematically equivalent.
    Returns True if their underlying truth tables match perfectly.
    """
    try:
        e1 = sympy.sympify(expr1)
        e2 = sympy.sympify(expr2)
        
        # Check equivalence and simplify
        result = sympy.simplify_logic(Equivalent(e1, e2))
        return result == sympy.true
        
    except Exception as e:
        raise ValueError(f"Swayam Error: Could not parse expressions. {e}")

def simplify_logic(expr):
    """
    Takes a messy logical expression and returns the cleanest, 
    shortest mathematically equivalent version of it.
    """
    return sympy.simplify_logic(sympy.sympify(expr))