def unwrap_fcs()

in src/math_verify/grader.py [0:0]


def unwrap_fcs(expr: Basic | MatrixBase) -> Basic | MatrixBase:
    """Unwrap function calls to their arguments.

    For example, Function('f')(x) becomes Symbol('f_x')

    Args:
        expr: The expression to unwrap

    Returns:
        The unwrapped expression with functions replaced by concatenated symbols
    """
    # Base case - not a Basic type
    if not isinstance(expr, Basic):
        return expr

    # Handle function case
    if hasattr(expr, "func") and isinstance(expr.func, UndefinedFunction):
        # Get function name and arguments
        func_name = expr.func.__name__
        # Recursively unwrap arguments before converting to string
        unwrapped_args = [str(unwrap_fcs(arg)) for arg in expr.args]
        # Create new symbol by concatenating function name and args
        return Symbol(f"{func_name}_{'_'.join(unwrapped_args)}")

    # Recursively unwrap all arguments
    try:
        new_args = [unwrap_fcs(arg) for arg in expr.args]
        if new_args:
            return expr.func(*new_args)
    except Exception:
        pass

    return expr