def POSform(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))
 maxterms = []
 for t in product([0, 1], repeat=len(variables)):
  t = list(t)
  if ((t not in minterms) and (t not in dontcares)):
   maxterms.append(t)
 old = None
 new = (maxterms + dontcares)
 while (new != old):
  old = new
  new = _simplified_pairs(old)
 essential = _rem_redundancy(new, maxterms)
 return And(*[_convert_to_varsPOS(x, variables) for x in essential])

def POSform ( 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 ) ) maxterms = [ ] for t in product ( [ 0 , 1 ] , repeat = len ( variables ) ) : t = list ( t ) if ( ( t not in minterms ) and ( t not in dontcares ) ) : maxterms . append ( t ) old = None new = ( maxterms + dontcares ) while ( new != old ) : old = new new = _simplified_pairs ( old ) essential = _rem_redundancy ( new , maxterms ) return And ( * [ _convert_to_varsPOS ( x , variables ) for x in essential ] )
the posform function uses simplified_pairs and a redundant-group eliminating algorithm to convert the list of all input combinations that generate 1 into the smallest product of sums form .