Skip to content

Commit d1c6642

Browse files
author
Matthias Koeppe
committed
src/sage/sat/boolean_polynomials.py: Use file-level # optional/needs
1 parent 417429f commit d1c6642

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/sage/sat/boolean_polynomials.py

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# sage.doctest: needs sage.rings.polynomial.pbori
1+
# sage.doctest: optional - pycryptosat, needs sage.modules sage.rings.polynomial.pbori
22
"""
33
SAT Functions for Boolean Polynomials
44
@@ -72,8 +72,8 @@ def solve(F, converter=None, solver=None, n=1, target_variables=None, **kwds):
7272
7373
We construct a very small-scale AES system of equations::
7474
75-
sage: sr = mq.SR(1, 1, 1, 4, gf2=True, polybori=True) # needs sage.modules sage.rings.finite_rings
76-
sage: while True: # workaround (see :trac:`31891`) # needs sage.modules sage.rings.finite_rings
75+
sage: sr = mq.SR(1, 1, 1, 4, gf2=True, polybori=True)
76+
sage: while True: # workaround (see :trac:`31891`)
7777
....: try:
7878
....: F, s = sr.polynomial_system()
7979
....: break
@@ -83,57 +83,56 @@ def solve(F, converter=None, solver=None, n=1, target_variables=None, **kwds):
8383
and pass it to a SAT solver::
8484
8585
sage: from sage.sat.boolean_polynomials import solve as solve_sat
86-
sage: s = solve_sat(F) # optional - pycryptosat # needs sage.modules sage.rings.finite_rings
87-
sage: F.subs(s[0]) # optional - pycryptosat # needs sage.modules sage.rings.finite_rings
86+
sage: s = solve_sat(F)
87+
sage: F.subs(s[0])
8888
Polynomial Sequence with 36 Polynomials in 0 Variables
8989
9090
This time we pass a few options through to the converter and the solver::
9191
92-
sage: s = solve_sat(F, c_max_vars_sparse=4, c_cutting_number=8) # optional - pycryptosat, needs sage.modules sage.rings.finite_rings
93-
sage: F.subs(s[0]) # optional - pycryptosat # needs sage.modules sage.rings.finite_rings
92+
sage: s = solve_sat(F, c_max_vars_sparse=4, c_cutting_number=8)
93+
sage: F.subs(s[0])
9494
Polynomial Sequence with 36 Polynomials in 0 Variables
9595
9696
We construct a very simple system with three solutions
9797
and ask for a specific number of solutions::
9898
99-
sage: # optional - pycryptosat, needs sage.modules
10099
sage: B.<a,b> = BooleanPolynomialRing()
101100
sage: f = a*b
102101
sage: l = solve_sat([f],n=1)
103102
sage: len(l) == 1, f.subs(l[0])
104103
(True, 0)
105104
106-
sage: l = solve_sat([a*b],n=2) # optional - pycryptosat # needs sage.modules
107-
sage: len(l) == 2, f.subs(l[0]), f.subs(l[1]) # optional - pycryptosat # needs sage.modules
105+
sage: l = solve_sat([a*b],n=2)
106+
sage: len(l) == 2, f.subs(l[0]), f.subs(l[1])
108107
(True, 0, 0)
109108
110-
sage: sorted((d[a], d[b]) for d in solve_sat([a*b], n=3)) # optional - pycryptosat, needs sage.modules
109+
sage: sorted((d[a], d[b]) for d in solve_sat([a*b], n=3))
111110
[(0, 0), (0, 1), (1, 0)]
112-
sage: sorted((d[a], d[b]) for d in solve_sat([a*b], n=4)) # optional - pycryptosat, needs sage.modules
111+
sage: sorted((d[a], d[b]) for d in solve_sat([a*b], n=4))
113112
[(0, 0), (0, 1), (1, 0)]
114-
sage: sorted((d[a], d[b]) for d in solve_sat([a*b], n=infinity)) # optional - pycryptosat, needs sage.modules
113+
sage: sorted((d[a], d[b]) for d in solve_sat([a*b], n=infinity))
115114
[(0, 0), (0, 1), (1, 0)]
116115
117116
In the next example we see how the ``target_variables`` parameter works::
118117
119118
sage: from sage.sat.boolean_polynomials import solve as solve_sat
120-
sage: R.<a,b,c,d> = BooleanPolynomialRing() # optional - pycryptosat # needs sage.modules
121-
sage: F = [a + b, a + c + d] # optional - pycryptosat # needs sage.modules
119+
sage: R.<a,b,c,d> = BooleanPolynomialRing()
120+
sage: F = [a + b, a + c + d]
122121
123122
First the normal use case::
124123
125-
sage: sorted((D[a], D[b], D[c], D[d]) # optional - pycryptosat # needs sage.modules
124+
sage: sorted((D[a], D[b], D[c], D[d])
126125
....: for D in solve_sat(F, n=infinity))
127126
[(0, 0, 0, 0), (0, 0, 1, 1), (1, 1, 0, 1), (1, 1, 1, 0)]
128127
129128
Now we are only interested in the solutions of the variables a and b::
130129
131-
sage: solve_sat(F, n=infinity, target_variables=[a,b]) # optional - pycryptosat, needs sage.modules
130+
sage: solve_sat(F, n=infinity, target_variables=[a,b])
132131
[{b: 0, a: 0}, {b: 1, a: 1}]
133132
134133
Here, we generate and solve the cubic equations of the AES SBox (see :trac:`26676`)::
135134
136-
sage: # long time, optional - pycryptosat, needs sage.modules
135+
sage: # long time
137136
sage: from sage.rings.polynomial.multi_polynomial_sequence import PolynomialSequence
138137
sage: from sage.sat.boolean_polynomials import solve as solve_sat
139138
sage: sr = sage.crypto.mq.SR(1, 4, 4, 8,
@@ -145,7 +144,7 @@ def solve(F, converter=None, solver=None, n=1, target_variables=None, **kwds):
145144
sage: variables = ",".join(variables)
146145
sage: R = BooleanPolynomialRing(16, variables)
147146
sage: eqs = [R(eq) for eq in eqs]
148-
sage: sls_aes = solve_sat(eqs, n = infinity)
147+
sage: sls_aes = solve_sat(eqs, n=infinity)
149148
sage: len(sls_aes)
150149
256
151150
@@ -168,7 +167,7 @@ def solve(F, converter=None, solver=None, n=1, target_variables=None, **kwds):
168167
....: k9 + k28,
169168
....: k11 + k20]
170169
sage: from sage.sat.boolean_polynomials import solve as solve_sat
171-
sage: solve_sat(keqs, n=1, solver=SAT('cryptominisat')) # optional - pycryptosat
170+
sage: solve_sat(keqs, n=1, solver=SAT('cryptominisat'))
172171
[{k28: 0,
173172
k26: 1,
174173
k24: 0,
@@ -342,16 +341,16 @@ def learn(F, converter=None, solver=None, max_learnt_length=3, interreduction=Fa
342341
343342
EXAMPLES::
344343
345-
sage: from sage.sat.boolean_polynomials import learn as learn_sat # optional - pycryptosat
344+
sage: from sage.sat.boolean_polynomials import learn as learn_sat
346345
347346
We construct a simple system and solve it::
348347
349-
sage: set_random_seed(2300)
350-
sage: sr = mq.SR(1, 2, 2, 4, gf2=True, polybori=True) # optional - pycryptosat, needs sage.modules sage.rings.finite_rings
351-
sage: F,s = sr.polynomial_system() # optional - pycryptosat # needs sage.modules sage.rings.finite_rings
352-
sage: H = learn_sat(F) # optional - pycryptosat # needs sage.modules sage.rings.finite_rings
353-
sage: H[-1] # optional - pycryptosat # needs sage.modules sage.rings.finite_rings
354-
k033 + 1
348+
sage: set_random_seed(2300)
349+
sage: sr = mq.SR(1, 2, 2, 4, gf2=True, polybori=True)
350+
sage: F,s = sr.polynomial_system()
351+
sage: H = learn_sat(F)
352+
sage: H[-1]
353+
k033 + 1
355354
"""
356355
try:
357356
len(F)

0 commit comments

Comments
 (0)