def _select_sublist(lst, target):
    """
    Enumerate all possible selection of elements from a list.
    This function is used to generate all solutions to findall/3.
    An element must be selected if it is TRUE in the target formula.

    :param lst: list to select elements from
    :type lst: list of tuple
    :param target: data structure containing truth value of nodes
    :type target: LogicFormula
    :return: generator of sublists
    """
    ln = len(lst)
    choice_bits = [None] * ln
    x = 0
    for i in range(0, ln):
        if lst[i][1] not in (target.TRUE, target.FALSE):
            choice_bits[i] = x
            x += 1
    n = (1 << x) - 1
    while n >= 0:
        sublist = [lst[i] for i in range(0, ln) if choice_bits[i] is None and
            lst[i][1] == target.TRUE or choice_bits[i] is not None and n & 
            1 << choice_bits[i]]
        sublist_no = tuple([target.negate(lst[i][1]) for i in range(0, ln) if
            choice_bits[i] is None and lst[i][1] == target.FALSE or 
            choice_bits[i] is not None and not n & 1 << choice_bits[i]])
        if sublist:
            terms, nodes = zip(*sublist)
        else:
            terms, nodes = (), ()
        yield terms, nodes + sublist_no + (0,)
        n -= 1
