Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit d0bc786

Browse files
committed
transform python test into sage tests - step one.
1 parent 2226097 commit d0bc786

File tree

16 files changed

+257
-257
lines changed

16 files changed

+257
-257
lines changed

src/sage/rings/polynomial/pbori/PyPolyBoRi.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,57 @@
88
99
Examples:
1010
11-
>>> from sage.rings.polynomial.pbori.brial.frontend import *
12-
>>> r=declare_ring(["x0","x1","x2","y0","y1","y2"], globals())
13-
>>> x0>x1
11+
sage: from sage.rings.polynomial.pbori.brial.frontend import *
12+
sage: r=declare_ring(["x0","x1","x2","y0","y1","y2"], globals())
13+
sage: x0>x1
1414
True
15-
>>> x0>x1*x2
15+
sage: x0>x1*x2
1616
True
17-
>>> y0>y1
17+
sage: y0>y1
1818
True
19-
>>> y0>y1*y2
19+
sage: y0>y1*y2
2020
True
2121
22-
>>> r = r.clone(ordering=dlex)
23-
>>> r(x0) > r(x1)
22+
sage: r = r.clone(ordering=dlex)
23+
sage: r(x0) > r(x1)
2424
True
25-
>>> r(x0) > r(x1*x2)
25+
sage: r(x0) > r(x1*x2)
2626
False
2727
28-
>>> r = r.clone(ordering=dp_asc)
29-
>>> r(x0) > r(x1)
28+
sage: r = r.clone(ordering=dp_asc)
29+
sage: r(x0) > r(x1)
3030
False
31-
>>> r(x0) > r(x1*x2)
31+
sage: r(x0) > r(x1*x2)
3232
False
3333
34-
>>> r = r.clone(ordering=block_dlex, blocks=[3])
35-
>>> r(x0) > r(x1)
34+
sage: r = r.clone(ordering=block_dlex, blocks=[3])
35+
sage: r(x0) > r(x1)
3636
True
37-
>>> r(x0) > r(x1*x2)
37+
sage: r(x0) > r(x1*x2)
3838
False
39-
>>> r(x0) > r(y0*y1*y2)
39+
sage: r(x0) > r(y0*y1*y2)
4040
True
4141
42-
>>> r = r.clone(ordering=block_dp_asc)
43-
>>> r(x0) > r(x1)
42+
sage: r = r.clone(ordering=block_dp_asc)
43+
sage: r(x0) > r(x1)
4444
False
45-
>>> r(x0) > r(y0)
45+
sage: r(x0) > r(y0)
4646
False
47-
>>> r(x0) > r(x1*x2)
47+
sage: r(x0) > r(x1*x2)
4848
False
4949
50-
>>> r = r.clone(ordering=block_dp_asc, blocks=[3])
51-
>>> r(x0) > r(y0)
50+
sage: r = r.clone(ordering=block_dp_asc, blocks=[3])
51+
sage: r(x0) > r(y0)
5252
True
5353
54-
>>> r(x0) > r(y0*y1)
54+
sage: r(x0) > r(y0*y1)
5555
True
5656
57-
>>> r = r.clone(names=["z17", "z7"])
58-
>>> [r.variable(idx) for idx in xrange(3)]
57+
sage: r = r.clone(names=["z17", "z7"])
58+
sage: [r.variable(idx) for idx in xrange(3)]
5959
[z17, z7, x2]
60-
>>> r = r.clone(names="abcde")
61-
>>> [r.variable(idx) for idx in xrange(6)]
60+
sage: r = r.clone(names="abcde")
61+
sage: [r.variable(idx) for idx in xrange(6)]
6262
[a, b, c, d, e, y2]
6363
6464
"""

src/sage/rings/polynomial/pbori/addition.py

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
def add_bits_old(bits):
88
"""Adds n bits
9-
>>> from sage.rings.polynomial.pbori.brial import *
10-
>>> r=Ring(10)
11-
>>> add_bits_old([r.variable(i) for i in xrange(3)])
9+
sage: from sage.rings.polynomial.pbori.brial import *
10+
sage: r=Ring(10)
11+
sage: add_bits_old([r.variable(i) for i in xrange(3)])
1212
[x(0) + x(1) + x(2), x(0)*x(1) + x(0)*x(2) + x(1)*x(2)]
13-
>>> add_bits_old([r.variable(i) for i in xrange(4)])
13+
sage: add_bits_old([r.variable(i) for i in xrange(4)])
1414
[x(0) + x(1) + x(2) + x(3), x(0)*x(1) + x(0)*x(2) + x(0)*x(3) + x(1)*x(2) + x(1)*x(3) + x(2)*x(3)]
1515
"""
1616
bits = list(bits)
@@ -33,13 +33,13 @@ def add_bits_old(bits):
3333

3434
def add_bits(bits):
3535
"""Adds n bit variables, by Lucas theorem
36-
>>> from sage.rings.polynomial.pbori.brial import *
37-
>>> r=Ring(10)
38-
>>> add_bits([r.variable(i) for i in xrange(3)])
36+
sage: from sage.rings.polynomial.pbori.brial import *
37+
sage: r=Ring(10)
38+
sage: add_bits([r.variable(i) for i in xrange(3)])
3939
[x(0) + x(1) + x(2), x(0)*x(1) + x(0)*x(2) + x(1)*x(2)]
40-
>>> add_bits([r.variable(i) for i in xrange(4)])
40+
sage: add_bits([r.variable(i) for i in xrange(4)])
4141
[x(0) + x(1) + x(2) + x(3), x(0)*x(1) + x(0)*x(2) + x(0)*x(3) + x(1)*x(2) + x(1)*x(3) + x(2)*x(3), x(0)*x(1)*x(2)*x(3)]
42-
>>> add_bits([r.variable(0)])
42+
sage: add_bits([r.variable(0)])
4343
[x(0)]
4444
"""
4545
bits = list(bits)
@@ -59,15 +59,15 @@ def add_bits(bits):
5959
def add_bit_expressions(bit_expressions):
6060
"""Adds n bits, which can be arbitrary expressions, the first n variables of the ring are reversed for usage in this function.
6161
62-
>>> from sage.rings.polynomial.pbori.brial import *
63-
>>> r=Ring(20)
64-
>>> add_bit_expressions([r.variable(i) for i in xrange(10,13)])
62+
sage: from sage.rings.polynomial.pbori.brial import *
63+
sage: r=Ring(20)
64+
sage: add_bit_expressions([r.variable(i) for i in xrange(10,13)])
6565
[x(10) + x(11) + x(12), x(10)*x(11) + x(10)*x(12) + x(11)*x(12)]
66-
>>> add_bit_expressions([r.variable(i) for i in xrange(10,13)])
66+
sage: add_bit_expressions([r.variable(i) for i in xrange(10,13)])
6767
[x(10) + x(11) + x(12), x(10)*x(11) + x(10)*x(12) + x(11)*x(12)]
68-
>>> add_bit_expressions([r.variable(11), r.variable(11)])
68+
sage: add_bit_expressions([r.variable(11), r.variable(11)])
6969
[0, x(11)]
70-
>>> add_bit_expressions([r.variable(11),r.variable(12),r.variable(13)])
70+
sage: add_bit_expressions([r.variable(11),r.variable(12),r.variable(13)])
7171
[x(11) + x(12) + x(13), x(11)*x(12) + x(11)*x(13) + x(12)*x(13)]
7272
"""
7373

@@ -85,16 +85,16 @@ def add_bit_expressions(bit_expressions):
8585

8686
def add_words(words):
8787
"""def adds n words, this words are supposed to consists of list of their bits.
88-
>>> from sage.rings.polynomial.pbori.brial import *
89-
>>> r=Ring(1000)
90-
>>> add_words([[r.variable(100+i*3+j) for i in xrange(2)] for j in xrange(3)])
88+
sage: from sage.rings.polynomial.pbori.brial import *
89+
sage: r=Ring(1000)
90+
sage: add_words([[r.variable(100+i*3+j) for i in xrange(2)] for j in xrange(3)])
9191
[x(100) + x(101) + x(102), x(100)*x(101) + x(100)*x(102) + x(101)*x(102) + x(103) + x(104) + x(105), x(100)*x(101)*x(103) + x(100)*x(101)*x(104) + x(100)*x(101)*x(105) + x(100)*x(102)*x(103) + x(100)*x(102)*x(104) + x(100)*x(102)*x(105) + x(101)*x(102)*x(103) + x(101)*x(102)*x(104) + x(101)*x(102)*x(105) + x(103)*x(104) + x(103)*x(105) + x(104)*x(105), x(100)*x(101)*x(103)*x(104)*x(105) + x(100)*x(102)*x(103)*x(104)*x(105) + x(101)*x(102)*x(103)*x(104)*x(105)]
92-
>>> res=add_words([[r.variable(100+i*9+j) for i in xrange(4)] for j in xrange(9)])
93-
>>> [len(p) for p in res]
92+
sage: res=add_words([[r.variable(100+i*9+j) for i in xrange(4)] for j in xrange(9)])
93+
sage: [len(p) for p in res]
9494
[9, 45, 495, 12870, 735462, 70285482, 1891358892, 6435]
95-
>>> [p.deg() for p in res]
95+
sage: [p.deg() for p in res]
9696
[1, 2, 4, 8, 12, 18, 25, 33]
97-
>>> [p.n_nodes() for p in res]
97+
sage: [p.n_nodes() for p in res]
9898
[9, 25, 54, 100, 153, 211, 249, 100]
9999
"""
100100

@@ -112,12 +112,12 @@ def add_words(words):
112112

113113
def multiply_by_addition(word_a, word_b):
114114
"""Multiply two words
115-
>>> from sage.rings.polynomial.pbori.brial import Ring
116-
>>> r=Ring(1000)
117-
>>> x = r.variable
118-
>>> n=7
119-
>>> res=multiply_by_addition([x(200+2*i) for i in xrange(n)], [x(200+2*i+1) for i in xrange(n)])
120-
>>> [p.n_nodes() for p in res]
115+
sage: from sage.rings.polynomial.pbori.brial import Ring
116+
sage: r=Ring(1000)
117+
sage: x = r.variable
118+
sage: n=7
119+
sage: res=multiply_by_addition([x(200+2*i) for i in xrange(n)], [x(200+2*i+1) for i in xrange(n)])
120+
sage: [p.n_nodes() for p in res]
121121
[2, 4, 7, 17, 38, 85, 222, 630, 1358, 1702, 1713, 1430, 875, 214, 0]
122122
"""
123123
word_a = list(word_a)

src/sage/rings/polynomial/pbori/cnf.py

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ def __init__(self, r, random_seed=16):
1414

1515
def zero_blocks(self, f):
1616
"""divides the zero set of f into blocks
17-
>>> from sage.rings.polynomial.pbori.brial import *
18-
>>> r = declare_ring(["x", "y", "z"], dict())
19-
>>> e = CNFEncoder(r)
20-
>>> e.zero_blocks(r.variable(0)*r.variable(1)*r.variable(2))
17+
sage: from sage.rings.polynomial.pbori.brial import *
18+
sage: r = declare_ring(["x", "y", "z"], dict())
19+
sage: e = CNFEncoder(r)
20+
sage: e.zero_blocks(r.variable(0)*r.variable(1)*r.variable(2))
2121
[{y: 0}, {z: 0}, {x: 0}]
2222
"""
2323
f = Polynomial(f)
@@ -78,17 +78,17 @@ def get_val(var):
7878

7979
def clauses(self, f):
8080
"""
81-
>>> from sage.rings.polynomial.pbori.brial import *
82-
>>> r = declare_ring(["x", "y", "z"], dict())
83-
>>> e = CNFEncoder(r)
84-
>>> e.clauses(r.variable(0)*r.variable(1)*r.variable(2)) # doctest:+ELLIPSIS
81+
sage: from sage.rings.polynomial.pbori.brial import *
82+
sage: r = declare_ring(["x", "y", "z"], dict())
83+
sage: e = CNFEncoder(r)
84+
sage: e.clauses(r.variable(0)*r.variable(1)*r.variable(2)) # doctest:+ELLIPSIS
8585
[{...x: 0...}]
86-
>>> e.clauses(r.variable(1)+r.variable(0)) # doctest:+ELLIPSIS
86+
sage: e.clauses(r.variable(1)+r.variable(0)) # doctest:+ELLIPSIS
8787
[{...x: 1...}, {...y: 1...}]
8888
89-
>>> [sorted(c.iteritems()) for c in e.clauses(r.variable(0)*r.variable(1)*r.variable(2))]
89+
sage: [sorted(c.iteritems()) for c in e.clauses(r.variable(0)*r.variable(1)*r.variable(2))]
9090
[[(z, 0), (y, 0), (x, 0)]]
91-
>>> [sorted(c.iteritems()) for c in e.clauses(r.variable(1)+r.variable(0))]
91+
sage: [sorted(c.iteritems()) for c in e.clauses(r.variable(1)+r.variable(0))]
9292
[[(y, 1), (x, 0)], [(y, 0), (x, 1)]]
9393
"""
9494
f_plus_one = f + 1
@@ -102,14 +102,14 @@ def clauses(self, f):
102102

103103
def polynomial_clauses(self, f):
104104
"""
105-
>>> from sage.rings.polynomial.pbori.brial import *
106-
>>> r = declare_ring(["x", "y", "z"], dict())
107-
>>> e = CNFEncoder(r)
108-
>>> e.polynomial_clauses(r.variable(0)*r.variable(1)*r.variable(2))
105+
sage: from sage.rings.polynomial.pbori.brial import *
106+
sage: r = declare_ring(["x", "y", "z"], dict())
107+
sage: e = CNFEncoder(r)
108+
sage: e.polynomial_clauses(r.variable(0)*r.variable(1)*r.variable(2))
109109
[x*y*z]
110-
>>> v = r.variable
111-
>>> p = v(1)*v(2)+v(2)*v(0)+1
112-
>>> groebner_basis([p], heuristic = False)==groebner_basis(e.polynomial_clauses(p), heuristic = False)
110+
sage: v = r.variable
111+
sage: p = v(1)*v(2)+v(2)*v(0)+1
112+
sage: groebner_basis([p], heuristic = False)==groebner_basis(e.polynomial_clauses(p), heuristic = False)
113113
True
114114
"""
115115

@@ -141,11 +141,11 @@ def get_sign(val):
141141

142142
def dimacs_encode_polynomial(self, p):
143143
"""
144-
>>> from sage.rings.polynomial.pbori.brial import *
145-
>>> d=dict()
146-
>>> r = declare_ring(["x", "y", "z"], d)
147-
>>> e = CNFEncoder(r)
148-
>>> e.dimacs_encode_polynomial(d["x"]+d["y"]+d["z"])
144+
sage: from sage.rings.polynomial.pbori.brial import *
145+
sage: d=dict()
146+
sage: r = declare_ring(["x", "y", "z"], d)
147+
sage: e = CNFEncoder(r)
148+
sage: e.dimacs_encode_polynomial(d["x"]+d["y"]+d["z"])
149149
['1 2 -3 0', '1 -2 3 0', '-1 -2 -3 0', '-1 2 3 0']
150150
"""
151151
clauses = self.clauses(p)
@@ -156,14 +156,14 @@ def dimacs_encode_polynomial(self, p):
156156

157157
def dimacs_cnf(self, polynomial_system):
158158
r"""
159-
>>> from sage.rings.polynomial.pbori.brial import *
160-
>>> r = declare_ring(["x", "y", "z"], dict())
161-
>>> e = CNFEncoder(r)
162-
>>> e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2)])
159+
sage: from sage.rings.polynomial.pbori.brial import *
160+
sage: r = declare_ring(["x", "y", "z"], dict())
161+
sage: e = CNFEncoder(r)
162+
sage: e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2)])
163163
'c cnf generated by PolyBoRi\np cnf 3 1\n-1 -2 -3 0'
164-
>>> e.dimacs_cnf([r.variable(1)+r.variable(0)])
164+
sage: e.dimacs_cnf([r.variable(1)+r.variable(0)])
165165
'c cnf generated by PolyBoRi\np cnf 3 2\n1 -2 0\n-1 2 0'
166-
>>> e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2), r.variable(1)+r.variable(0)])
166+
sage: e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2), r.variable(1)+r.variable(0)])
167167
'c cnf generated by PolyBoRi\np cnf 3 3\n-1 -2 -3 0\n-1 2 0\n1 -2 0'
168168
"""
169169
clauses_list = [c for p in polynomial_system for c in self.
@@ -182,18 +182,18 @@ class CryptoMiniSatEncoder(CNFEncoder):
182182

183183
def dimacs_encode_polynomial(self, p):
184184
r"""
185-
>>> from sage.rings.polynomial.pbori.brial import *
186-
>>> d=dict()
187-
>>> r = declare_ring(["x", "y", "z"], d)
188-
>>> e = CryptoMiniSatEncoder(r)
189-
>>> p = d["x"]+d["y"]+d["z"]
190-
>>> p.deg()
185+
sage: from sage.rings.polynomial.pbori.brial import *
186+
sage: d=dict()
187+
sage: r = declare_ring(["x", "y", "z"], d)
188+
sage: e = CryptoMiniSatEncoder(r)
189+
sage: p = d["x"]+d["y"]+d["z"]
190+
sage: p.deg()
191191
1
192-
>>> len(p)
192+
sage: len(p)
193193
3
194-
>>> e.dimacs_encode_polynomial(p)
194+
sage: e.dimacs_encode_polynomial(p)
195195
['x1 2 3 0\nc g 1 x + y + z']
196-
>>> e.dimacs_encode_polynomial(p+1)
196+
sage: e.dimacs_encode_polynomial(p+1)
197197
['x1 2 -3 0\nc g 2 x + y + z + 1']
198198
"""
199199
if p.deg() != 1 or len(p) <= 1:
@@ -216,14 +216,14 @@ def dimacs_encode_polynomial(self, p):
216216

217217
def dimacs_cnf(self, polynomial_system):
218218
r"""
219-
>>> from sage.rings.polynomial.pbori.brial import *
220-
>>> r = declare_ring(["x", "y", "z"], dict())
221-
>>> e = CryptoMiniSatEncoder(r)
222-
>>> e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2)])
219+
sage: from sage.rings.polynomial.pbori.brial import *
220+
sage: r = declare_ring(["x", "y", "z"], dict())
221+
sage: e = CryptoMiniSatEncoder(r)
222+
sage: e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2)])
223223
'c cnf generated by PolyBoRi\np cnf 3 1\n-1 -2 -3 0\nc g 1 x*y*z\nc v 1 x\nc v 2 y\nc v 3 z'
224-
>>> e.dimacs_cnf([r.variable(1)+r.variable(0)])
224+
sage: e.dimacs_cnf([r.variable(1)+r.variable(0)])
225225
'c cnf generated by PolyBoRi\np cnf 3 1\nx1 2 0\nc g 2 x + y\nc v 1 x\nc v 2 y'
226-
>>> e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2), r.variable(1)+r.variable(0)])
226+
sage: e.dimacs_cnf([r.variable(0)*r.variable(1)*r.variable(2), r.variable(1)+r.variable(0)])
227227
'c cnf generated by PolyBoRi\np cnf 3 2\n-1 -2 -3 0\nc g 3 x*y*z\nx1 2 0\nc g 4 x + y\nc v 1 x\nc v 2 y\nc v 3 z'
228228
"""
229229
uv = list(used_vars_set(polynomial_system).variables())

src/sage/rings/polynomial/pbori/context.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
def _exists():
88
"""PolyBoRi convention: checking optional components for prerequisites here
99
10-
>>> _exists()
10+
sage: _exists()
1111
True
1212
"""
1313
from distutils.sysconfig import get_python_version
@@ -24,13 +24,13 @@ class FactoryContext(object):
2424
callable object. It is useful together with the with statement.
2525
2626
Example:
27-
>>> r = Ring(1000)
28-
>>> from sage.rings.polynomial.pbori.brial import Variable
29-
>>> def var(idx): return Variable(idx, r)
30-
>>> with FactoryContext(Variable, var):
27+
sage: r = Ring(1000)
28+
sage: from sage.rings.polynomial.pbori.brial import Variable
29+
sage: def var(idx): return Variable(idx, r)
30+
sage: with FactoryContext(Variable, var):
3131
... print Variable(17)
3232
x(17)
33-
>>> try:
33+
sage: try:
3434
... print Variable(17)
3535
... except:
3636
... print "caught expected exception"
@@ -64,14 +64,14 @@ class RingContext(object):
6464
the with statement.
6565
6666
Example:
67-
>>> r = Ring(1000)
68-
>>> from sage.rings.polynomial.pbori.brial import Variable
69-
>>> print Variable(17, r)
67+
sage: r = Ring(1000)
68+
sage: from sage.rings.polynomial.pbori.brial import Variable
69+
sage: print Variable(17, r)
7070
x(17)
71-
>>> with RingContext(r):
71+
sage: with RingContext(r):
7272
... print Variable(17), Monomial(), Polynomial(0), BooleSet()
7373
x(17) 1 0 {}
74-
>>> try:
74+
sage: try:
7575
... print Variable(17)
7676
... except:
7777
... print "caught expected exception"

0 commit comments

Comments
 (0)