def goalexpand(goalt):
    """ Expand a goal tuple until it can no longer be expanded

    >>> from logpy.core import var, membero, goalexpand
    >>> from logpy.util import pprint
    >>> x = var('x')
    >>> goal = (membero, x, (1, 2, 3))
    >>> print(pprint(goalexpand(goal)))
    (lany, (eq, ~x, 1), (eq, ~x, 2), (eq, ~x, 3))
    """
    tmp = goalt
    while isinstance(tmp, tuple) and len(tmp) >= 1 and not callable(tmp):
        goalt = tmp
        tmp = goalt[0](*goalt[1:])
    return goalt