def SOPform(variables, minterms, dontcares=None):
 variables = [sympify(v) for v in variables]
 if (minterms == []):
  return false
 minterms = [list(i) for i in minterms]
 dontcares = [list(i) for i in (dontcares or [])]
 for d in dontcares:
  if (d in minterms):
   raise ValueError(('%s in minterms is also in dontcares' % d))
 old = None
 new = (minterms + dontcares)
 while (new != old):
  old = new
  new = _simplified_pairs(old)
 essential = _rem_redundancy(new, minterms)
 return Or(*[_convert_to_varsSOP(x, variables) for x in essential])

def SOPform ( variables , minterms , dontcares = None ) : variables = [ sympify ( v ) for v in variables ] if ( minterms == [ ] ) : return false minterms = [ list ( i ) for i in minterms ] dontcares = [ list ( i ) for i in ( dontcares or [ ] ) ] for d in dontcares : if ( d in minterms ) : raise ValueError ( ( '%s in minterms is also in dontcares' % d ) ) old = None new = ( minterms + dontcares ) while ( new != old ) : old = new new = _simplified_pairs ( old ) essential = _rem_redundancy ( new , minterms ) return Or ( * [ _convert_to_varsSOP ( x , variables ) for x in essential ] )
the sopform function uses simplified_pairs and a redundant group- eliminating algorithm to convert the list of all input combos that generate 1 into the smallest sum of products form .