[SCM] polybori: Polynomials over Boolean Rings branch, upstream-hg, updated. b4a5cffaa908c53e1d958a42110f8c4dad853aa3

Alexander Dreyer adreyer at gmx.de
Fri Mar 23 08:02:21 UTC 2012


The following commit has been merged in the upstream-hg branch:
commit 7d96e37dea6cf1226b71b958edb67621dc44cbce
Author: Alexander Dreyer <adreyer at gmx.de>
Date:   Mon Mar 12 12:38:23 2012 +0100

    FIX: more idependence from actual interface implementation

diff --git a/pyroot/polybori/addition.py b/pyroot/polybori/addition.py
index 109e7e8..41fecd6 100644
--- a/pyroot/polybori/addition.py
+++ b/pyroot/polybori/addition.py
@@ -113,9 +113,9 @@ def multiply_by_addition(word_a, word_b):
     word_b=list(word_b)
     summands=[]
     if word_a:
-        zero = word_a[0] * 0
+        zero = word_a[0].ring().zero()
     elif word_b:
-        zero = word_b[0] * 0
+        zero = word_b[0].ring().zero()
     else:
         zero = BooleConstant(0)
 
diff --git a/pyroot/polybori/cnf.py b/pyroot/polybori/cnf.py
index 007a3eb..4b8650a 100644
--- a/pyroot/polybori/cnf.py
+++ b/pyroot/polybori/cnf.py
@@ -59,6 +59,7 @@ class CNFEncoder(object):
                     return 1
                 return 0
             block_dict = dict([(v, get_val(v)) for v in variables])
+
             l = l.set()
             self.random_generator.shuffle(variables)
             for v in variables:
@@ -69,15 +70,21 @@ class CNFEncoder(object):
             rest = rest.diff(l)
             res.append(block_dict)
         return res
+
     def clauses(self, f):
         """
         >>> from polybori import *
         >>> r = declare_ring(["x", "y", "z"], dict())
         >>> e = CNFEncoder(r)
-        >>> e.clauses(r.variable(0)*r.variable(1)*r.variable(2))
-        [{x: 0, y: 0, z: 0}]
-        >>> e.clauses(r.variable(1)+r.variable(0))
-        [{x: 1, y: 0}, {y: 1, x: 0}]
+        >>> e.clauses(r.variable(0)*r.variable(1)*r.variable(2)) # doctest:+ELLIPSIS
+        [{...x: 0...}]
+        >>> e.clauses(r.variable(1)+r.variable(0)) # doctest:+ELLIPSIS
+        [{...x: 1...}, {...y: 1...}]
+
+        >>> [sorted(c.iteritems()) for c in e.clauses(r.variable(0)*r.variable(1)*r.variable(2))]
+        [[(z, 0), (y, 0), (x, 0)]]
+        >>> [sorted(c.iteritems()) for c in e.clauses(r.variable(1)+r.variable(0))]
+        [[(y, 1), (x, 0)], [(y, 0), (x, 1)]]
         """
         f_plus_one = f+1
         blocks = self.zero_blocks(f+1)
@@ -116,11 +123,13 @@ class CNFEncoder(object):
             if value == 1: 
                 return 1
             return -1
+            
+        items = sorted(c.iteritems(), reverse=True)
         return " ".join(
         [str(v) for v in 
             [
             get_sign(value)*self.to_dimacs_index(variable) 
-            for (variable, value) in c.iteritems()]+[0]])
+            for (variable, value) in items]+[0]])
             
     def dimacs_encode_polynomial(self, p):
         """
@@ -129,7 +138,7 @@ class CNFEncoder(object):
          >>> r = declare_ring(["x", "y", "z"], d)
          >>> e = CNFEncoder(r)
          >>> e.dimacs_encode_polynomial(d["x"]+d["y"]+d["z"])
-         ['1 2 -3 0', '3 1 -2 0', '-2 -3 -1 0', '3 -1 2 0']
+         ['1 2 -3 0', '1 -2 3 0', '-1 -2 -3 0', '-1 2 3 0']
             """
         clauses = self.clauses(p)
         res=[]
@@ -145,9 +154,9 @@ class CNFEncoder(object):
         >>> e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2)])
         'c cnf generated by PolyBoRi\np cnf 3 1\n-1 -2 -3 0'
         >>> e.dimacs_cnf([r.variable(1)+r.variable(0)])
-        'c cnf generated by PolyBoRi\np cnf 3 2\n1 -2 0\n2 -1 0'
+        'c cnf generated by PolyBoRi\np cnf 3 2\n1 -2 0\n-1 2 0'
         >>> e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2), r.variable(1)+r.variable(0)])
-        'c cnf generated by PolyBoRi\np cnf 3 3\n-1 -2 -3 0\n-1 2 0\n-2 1 0'
+        'c cnf generated by PolyBoRi\np cnf 3 3\n-1 -2 -3 0\n-1 2 0\n1 -2 0'
         """
         clauses_list = [c for p in polynomial_system for c in self.dimacs_encode_polynomial(p)]
         res = ["c cnf generated by PolyBoRi"]
diff --git a/pyroot/polybori/fglm.py b/pyroot/polybori/fglm.py
index 3cc8528..433158e 100644
--- a/pyroot/polybori/fglm.py
+++ b/pyroot/polybori/fglm.py
@@ -63,7 +63,7 @@ def m_k_plus_one(completed_elements, variables):
     >>> m_k_plus_one(s,variables)
     x(2)*x(3)
     >>> r2 = r.clone(ordering=dp_asc)
-    >>> m_k_plus_one(r2.coerce(s).set(),r2.coerce(variables).set())
+    >>> m_k_plus_one(r2(s).set(),r2(variables).set())
     x(1)*x(3)
     """
     return sorted(completed_elements.cartesian_product(variables).diff(completed_elements))[0]
diff --git a/pyroot/polybori/gbcore.py b/pyroot/polybori/gbcore.py
index 3fd1bc8..03325a4 100644
--- a/pyroot/polybori/gbcore.py
+++ b/pyroot/polybori/gbcore.py
@@ -359,13 +359,13 @@ def other_ordering_pre(I,option_set,kwds):
         kwds=dict((k,options[k]) for k in options if not (k in ("other_ordering_first","switch_to","I")))
         kwds["redsb"]=True
         I_orig=I
-        I=groebner_basis([new_ring.coerce(poly) for poly in I],**kwds)
+        I=groebner_basis([new_ring(poly) for poly in I],**kwds)
         variety_size=variety_size_from_gb(I)
         if variety_size<50000:
             main_kwds["convert_with_fglm_from_ring"]=new_ring
             main_kwds["convert_with_fglm_to_ring"]=old_ring        
         else:
-            I = [old_ring.coerce(poly) for poly in I]
+            I = [old_ring(poly) for poly in I]
     finally:
         pass
 
diff --git a/pyroot/polybori/intpolys.py b/pyroot/polybori/intpolys.py
index 255c9da..3c4ec18 100644
--- a/pyroot/polybori/intpolys.py
+++ b/pyroot/polybori/intpolys.py
@@ -23,16 +23,14 @@ class IntegerPolynomial(object):
                 if and_:
                     res.append(i)
             return (self, IntegerPolynomial(dict([(i, BooleConstant(1)) for i in res])))
-        if isinstance(other,  VariableType) or isinstance(other, Monomial):
+        if not isinstance(other,  IntegerPolynomial):
             other=Polynomial(other)
-        if isinstance(other, Polynomial):
-            return (self, IntegerPolynomial(dict([(0, other)])))
-        return None
+        return (self, IntegerPolynomial(dict([(0, other)])))
+
     def __add__(self, other):
         """
         >>> from polybori import *
-        >>> declare_ring([Block("x",1000)], globals()) # doctest: +ELLIPSIS
-        <...>
+        >>> r= declare_ring([Block("x",1000)], globals()) # doctest: +ELLIPSIS
         >>> p=IntegerPolynomial(x(1))
         >>> p
         {0: x(1)}

-- 
polybori: Polynomials over Boolean Rings



More information about the debian-science-commits mailing list