(s)
return And(*clauses)
Loads a boolean expression from a string.

    Examples
    ========

    >>> from sympy.logic.utilities.dimacs import load
    >>> load('1')
    cnf_1
    >>> load('1 2')
    Or(cnf_1, cnf_2)
    >>> load('1 \\n 2')
    And(cnf_1, cnf_2)
    >>> load('1 2 \\n 3')
    And(Or(cnf_1, cnf_2), cnf_3)
Loads a boolean expression from a string.
Loads a boolean expression from a string .
def load(s):
    """Loads a boolean expression from a string.

    Examples
    ========

    >>> from sympy.logic.utilities.dimacs import load
    >>> load('1')
    cnf_1
    >>> load('1 2')
    Or(cnf_1, cnf_2)
    >>> load('1 \\n 2')
    And(cnf_1, cnf_2)
    >>> load('1 2 \\n 3')
    And(Or(cnf_1, cnf_2), cnf_3)
    """
    clauses = []

    lines = s.split('\n')

    pComment = re.compile('c.*')
    pStats = re.compile('p\s*cnf\s*(\d*)\s*(\d*)')

    while len(lines) > 0:
        line = lines.pop(0)

        # Only deal with lines that aren't comments
        if not pComment.match(line):
            m = pStats.match(line)

            if not m:
                nums = line.rstrip('\n').split(' ')
                list = []
                for lit in nums:
                    if lit != '':
                        if int(lit) == 0:
                            continue
                        num = abs(int(lit))
                        sign = True
                        if int(lit) < 0:
                            sign = False

                        if sign:
                            list.append(Symbol("cnf_%s" % num))
                        else:
                            list.append(~Symbol("cnf_%s" % num))

                if len(list) > 0:
                    clauses.append(Or(*list))

    return And(*clauses)
def load ( s ) : clauses = [ ] lines = s . split ( '\n' ) pComment = re . compile ( 'c.*' ) pStats = re . compile ( 'p\s*cnf\s*(\d*)\s*(\d*)' ) while len ( lines ) > 0 : line = lines . pop ( 0 ) # Only deal with lines that aren't comments if not pComment . match ( line ) : m = pStats . match ( line ) if not m : nums = line . rstrip ( '\n' ) . split ( ' ' ) list = [ ] for lit in nums : if lit != '' : if int ( lit ) == 0 : continue num = abs ( int ( lit ) ) sign = True if int ( lit ) < 0 : sign = False if sign : list . append ( Symbol ( "cnf_%s" % num ) ) else : list . append ( ~ Symbol ( "cnf_%s" % num ) ) if len ( list ) > 0 : clauses . append ( Or ( * list ) ) return And ( * clauses )