passagemath-standard-no-symbolics 10.6.45__cp313-cp313-macosx_13_0_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- passagemath_standard_no_symbolics/__init__.py +1 -0
- passagemath_standard_no_symbolics-10.6.45.data/scripts/sage-grep +5 -0
- passagemath_standard_no_symbolics-10.6.45.data/scripts/sage-grepdoc +5 -0
- passagemath_standard_no_symbolics-10.6.45.data/scripts/sage-list-packages +103 -0
- passagemath_standard_no_symbolics-10.6.45.dist-info/METADATA +150 -0
- passagemath_standard_no_symbolics-10.6.45.dist-info/RECORD +83 -0
- passagemath_standard_no_symbolics-10.6.45.dist-info/WHEEL +6 -0
- passagemath_standard_no_symbolics-10.6.45.dist-info/top_level.txt +2 -0
- sage/all.py +207 -0
- sage/all_cmdline.py +36 -0
- sage/cli/__init__.py +61 -0
- sage/cli/__main__.py +5 -0
- sage/cli/eval_cmd.py +45 -0
- sage/cli/eval_cmd_test.py +25 -0
- sage/cli/interactive_shell_cmd.py +28 -0
- sage/cli/notebook_cmd.py +51 -0
- sage/cli/notebook_cmd_test.py +39 -0
- sage/cli/options.py +26 -0
- sage/cli/run_file_cmd.py +50 -0
- sage/cli/version_cmd.py +26 -0
- sage/databases/all.py +83 -0
- sage/databases/cubic_hecke_db.py +1527 -0
- sage/dynamics/all.py +31 -0
- sage/dynamics/surface_dynamics_deprecation.py +32 -0
- sage/ext_data/kenzo/CP2.txt +45 -0
- sage/ext_data/kenzo/CP3.txt +349 -0
- sage/ext_data/kenzo/CP4.txt +4774 -0
- sage/ext_data/kenzo/README.txt +49 -0
- sage/ext_data/kenzo/S4.txt +20 -0
- sage/ext_data/mwrank/PRIMES +1 -0
- sage/ext_data/nbconvert/postprocess.py +48 -0
- sage/ext_data/nbconvert/rst_sage.tpl +99 -0
- sage/ext_data/nodoctest +0 -0
- sage/ext_data/notebook-ipython/kernel.json.in +11 -0
- sage/ext_data/notebook-ipython/logo-64x64.png +0 -0
- sage/ext_data/notebook-ipython/logo.svg +352 -0
- sage/ext_data/valgrind/pyalloc.supp +58 -0
- sage/ext_data/valgrind/sage-additional.supp +417 -0
- sage/ext_data/valgrind/sage.supp +43 -0
- sage/ext_data/valgrind/valgrind-python.supp +480 -0
- sage/geometry/all.py +12 -0
- sage/groups/matrix_gps/pickling_overrides.py +110 -0
- sage/homology/tests.py +66 -0
- sage/interacts/algebra.py +20 -0
- sage/interacts/all.py +25 -0
- sage/interacts/calculus.py +24 -0
- sage/interacts/fractals.py +18 -0
- sage/interacts/geometry.py +19 -0
- sage/interacts/library.py +1950 -0
- sage/interacts/library_cython.cpython-313-darwin.so +0 -0
- sage/interacts/statistics.py +19 -0
- sage/interfaces/axiom.py +1002 -0
- sage/interfaces/kash.py +834 -0
- sage/interfaces/lie.py +950 -0
- sage/interfaces/matlab.py +413 -0
- sage/interfaces/mupad.py +686 -0
- sage/interfaces/octave.py +858 -0
- sage/interfaces/phc.py +943 -0
- sage/interfaces/psage.py +189 -0
- sage/interfaces/qsieve.py +4 -0
- sage/interfaces/r.py +2096 -0
- sage/interfaces/read_data.py +46 -0
- sage/interfaces/scilab.py +576 -0
- sage/interfaces/tests.py +81 -0
- sage/libs/all.py +11 -0
- sage/libs/cremona/__init__.py +0 -0
- sage/libs/mwrank/__init__.py +0 -0
- sage/logic/all.py +3 -0
- sage/logic/booleval.py +160 -0
- sage/logic/boolformula.py +1490 -0
- sage/logic/logic.py +856 -0
- sage/logic/logicparser.py +696 -0
- sage/logic/logictable.py +272 -0
- sage/logic/propcalc.py +311 -0
- sage/misc/all.py +28 -0
- sage/misc/lazy_attribute.pyi +11 -0
- sage/rings/all.py +48 -0
- sage/rings/commutative_algebra.py +38 -0
- sage/rings/finite_rings/all.py +21 -0
- sage/rings/numbers_abc.py +58 -0
- sage/rings/polynomial/all.py +22 -0
- sage/rings/polynomial/convolution.py +421 -0
- sage/symbolic/all__sagemath_standard_no_symbolics.py +0 -0
sage/logic/logictable.py
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
r"""
|
|
2
|
+
Logic Tables
|
|
3
|
+
|
|
4
|
+
A logic table is essentially a 2-D array that is created by the statement class
|
|
5
|
+
and stored in the private global variable table, along with a list containing
|
|
6
|
+
the variable names to be used, in order.
|
|
7
|
+
|
|
8
|
+
The order in which the table is listed essentially amounts to counting in
|
|
9
|
+
binary. For instance, with the variables `A`, `B`, and `C` the truth table
|
|
10
|
+
looks like::
|
|
11
|
+
|
|
12
|
+
A B C value
|
|
13
|
+
False False False ?
|
|
14
|
+
False False True ?
|
|
15
|
+
False True False ?
|
|
16
|
+
False True True ?
|
|
17
|
+
True False False ?
|
|
18
|
+
True False True ?
|
|
19
|
+
True True False ?
|
|
20
|
+
True True True ?
|
|
21
|
+
|
|
22
|
+
This is equivalent to counting in binary, where a table would appear thus;
|
|
23
|
+
|
|
24
|
+
::
|
|
25
|
+
|
|
26
|
+
2^2 2^1 2^0 value
|
|
27
|
+
0 0 0 0
|
|
28
|
+
0 0 1 1
|
|
29
|
+
0 1 0 2
|
|
30
|
+
0 1 1 3
|
|
31
|
+
1 0 0 4
|
|
32
|
+
1 0 1 5
|
|
33
|
+
1 1 0 6
|
|
34
|
+
1 1 1 7
|
|
35
|
+
|
|
36
|
+
Given that a table can be created corresponding to any range of acceptable
|
|
37
|
+
values for a given statement, it is easy to find the value of a statement
|
|
38
|
+
for arbitrary values of its variables.
|
|
39
|
+
|
|
40
|
+
AUTHORS:
|
|
41
|
+
|
|
42
|
+
- William Stein (2006): initial version
|
|
43
|
+
|
|
44
|
+
- Chris Gorecki (2006): initial version
|
|
45
|
+
|
|
46
|
+
- Paul Scurek (2013-08-03): updated docstring formatting
|
|
47
|
+
|
|
48
|
+
EXAMPLES:
|
|
49
|
+
|
|
50
|
+
Create a truth table of a boolean formula::
|
|
51
|
+
|
|
52
|
+
sage: import sage.logic.propcalc as propcalc
|
|
53
|
+
sage: s = propcalc.formula("a&b|~(c|a)")
|
|
54
|
+
sage: s.truthtable()
|
|
55
|
+
a b c value
|
|
56
|
+
False False False True
|
|
57
|
+
False False True False
|
|
58
|
+
False True False True
|
|
59
|
+
False True True False
|
|
60
|
+
True False False False
|
|
61
|
+
True False True False
|
|
62
|
+
True True False True
|
|
63
|
+
True True True True
|
|
64
|
+
|
|
65
|
+
Get the LaTeX code for a truth table::
|
|
66
|
+
|
|
67
|
+
sage: latex(s.truthtable(5,11))
|
|
68
|
+
\\\begin{tabular}{llll}c & b & a & value \\\hline True & False & True & False \\True & True & False & True \\True & True & True & True\end{tabular}
|
|
69
|
+
|
|
70
|
+
It is not an error to use nonsensical numeric inputs::
|
|
71
|
+
|
|
72
|
+
sage: s = propcalc.formula("a&b|~(c|a)")
|
|
73
|
+
sage: s.truthtable(5, 9)
|
|
74
|
+
a b c value
|
|
75
|
+
True False True False
|
|
76
|
+
True True False True
|
|
77
|
+
True True True True
|
|
78
|
+
|
|
79
|
+
sage: s.truthtable(9, 5)
|
|
80
|
+
a b c value
|
|
81
|
+
|
|
82
|
+
If one argument is provided, truthtable defaults to the end::
|
|
83
|
+
|
|
84
|
+
sage: s.truthtable(-1)
|
|
85
|
+
a b c value
|
|
86
|
+
False False False True
|
|
87
|
+
False False True False
|
|
88
|
+
False True False True
|
|
89
|
+
False True True False
|
|
90
|
+
True False False False
|
|
91
|
+
True False True False
|
|
92
|
+
True True False True
|
|
93
|
+
True True True True
|
|
94
|
+
|
|
95
|
+
If the second argument is negative, truthtable defaults to the end::
|
|
96
|
+
|
|
97
|
+
sage: s.truthtable(4, -2)
|
|
98
|
+
a b c value
|
|
99
|
+
True False False False
|
|
100
|
+
True False True False
|
|
101
|
+
True True False True
|
|
102
|
+
True True True True
|
|
103
|
+
|
|
104
|
+
.. NOTE::
|
|
105
|
+
|
|
106
|
+
For statements that contain a variable list that when printed is longer
|
|
107
|
+
than the latex page, the columns of the table will run off the screen.
|
|
108
|
+
"""
|
|
109
|
+
# ****************************************************************************
|
|
110
|
+
# Copyright (C) 2006 William Stein <wstein@gmail.com>
|
|
111
|
+
# Copyright (C) 2006 Chris Gorecki <chris.k.gorecki@gmail.com>
|
|
112
|
+
# Copyright (C) 2013 Paul Scurek <scurek86@gmail.com>
|
|
113
|
+
#
|
|
114
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
115
|
+
# as published by the Free Software Foundation; either version 2 of
|
|
116
|
+
# the License, or (at your option) any later version.
|
|
117
|
+
# https://www.gnu.org/licenses/
|
|
118
|
+
# ****************************************************************************
|
|
119
|
+
|
|
120
|
+
# Global variables
|
|
121
|
+
__table = []
|
|
122
|
+
__vars_order = []
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class Truthtable:
|
|
126
|
+
"""
|
|
127
|
+
A truth table.
|
|
128
|
+
|
|
129
|
+
INPUT:
|
|
130
|
+
|
|
131
|
+
- ``t`` -- a 2-D array containing the table values
|
|
132
|
+
|
|
133
|
+
- ``vo`` -- list of the variables in the expression in order,
|
|
134
|
+
with each variable occurring only once
|
|
135
|
+
"""
|
|
136
|
+
def __init__(self, t, vo):
|
|
137
|
+
r"""
|
|
138
|
+
Initialize the data fields.
|
|
139
|
+
|
|
140
|
+
EXAMPLES:
|
|
141
|
+
|
|
142
|
+
This example illustrates the creation of a table
|
|
143
|
+
|
|
144
|
+
::
|
|
145
|
+
|
|
146
|
+
sage: import sage.logic.propcalc as propcalc
|
|
147
|
+
sage: s = propcalc.formula("a&b|~(c|a)")
|
|
148
|
+
sage: s.truthtable()
|
|
149
|
+
a b c value
|
|
150
|
+
False False False True
|
|
151
|
+
False False True False
|
|
152
|
+
False True False True
|
|
153
|
+
False True True False
|
|
154
|
+
True False False False
|
|
155
|
+
True False True False
|
|
156
|
+
True True False True
|
|
157
|
+
True True True True
|
|
158
|
+
"""
|
|
159
|
+
self.__table = t
|
|
160
|
+
self.__vars_order = vo
|
|
161
|
+
|
|
162
|
+
def _latex_(self):
|
|
163
|
+
r"""
|
|
164
|
+
Return a latex representation of the calling table object.
|
|
165
|
+
|
|
166
|
+
OUTPUT: the latex representation of the table
|
|
167
|
+
|
|
168
|
+
EXAMPLES:
|
|
169
|
+
|
|
170
|
+
This example illustrates how to get the latex representation of
|
|
171
|
+
the table::
|
|
172
|
+
|
|
173
|
+
sage: import sage.logic.propcalc as propcalc
|
|
174
|
+
sage: s = propcalc.formula("man->monkey&human")
|
|
175
|
+
sage: latex(s.truthtable())
|
|
176
|
+
\\\begin{tabular}{llll}human & monkey & man & value \\\hline False & False & False & True \\False & False & True & True \\False & True & False & True \\False & True & True & True \\True & False & False & False \\True & False & True & False \\True & True & False & False \\True & True & True & True\end{tabular}
|
|
177
|
+
|
|
178
|
+
Now, we show that strange parameters can lead to a table header
|
|
179
|
+
with no body::
|
|
180
|
+
|
|
181
|
+
sage: latex(s.truthtable(2, 1))
|
|
182
|
+
\\\begin{tabular}{llll}human & monkey & man & value \\\hli\end{tabular}
|
|
183
|
+
"""
|
|
184
|
+
rt = s = ""
|
|
185
|
+
self.__vars_order.reverse()
|
|
186
|
+
s = r'\\\begin{tabular}{'
|
|
187
|
+
s += 'l' * (len(self.__vars_order) + 1) + '}'
|
|
188
|
+
for var in self.__vars_order:
|
|
189
|
+
s += var + ' & '
|
|
190
|
+
rt += s + r'value \\' + r'\hline '
|
|
191
|
+
for row in self.__table:
|
|
192
|
+
s = ""
|
|
193
|
+
for i in row:
|
|
194
|
+
s += str(i) + ' & '
|
|
195
|
+
rt += s[:-3] + r' \\'
|
|
196
|
+
rt = rt[:-3] + r'\end{tabular}'
|
|
197
|
+
self.__vars_order.reverse()
|
|
198
|
+
return rt
|
|
199
|
+
|
|
200
|
+
def __repr__(self):
|
|
201
|
+
r"""
|
|
202
|
+
Return a string representation of the calling table object.
|
|
203
|
+
|
|
204
|
+
OUTPUT: the table as a 2-D string array
|
|
205
|
+
|
|
206
|
+
EXAMPLES:
|
|
207
|
+
|
|
208
|
+
This example illustrates how to display the truth table of a
|
|
209
|
+
boolean formula::
|
|
210
|
+
|
|
211
|
+
sage: import sage.logic.propcalc as propcalc
|
|
212
|
+
sage: s = propcalc.formula("man->monkey&human")
|
|
213
|
+
sage: s.truthtable()
|
|
214
|
+
man monkey human value
|
|
215
|
+
False False False True
|
|
216
|
+
False False True True
|
|
217
|
+
False True False True
|
|
218
|
+
False True True True
|
|
219
|
+
True False False False
|
|
220
|
+
True False True False
|
|
221
|
+
True True False False
|
|
222
|
+
True True True True
|
|
223
|
+
|
|
224
|
+
We now show that strange parameters can lead to the table
|
|
225
|
+
header with no body::
|
|
226
|
+
|
|
227
|
+
sage: s.truthtable(2, 1)
|
|
228
|
+
man monkey human value
|
|
229
|
+
"""
|
|
230
|
+
vars_len = []
|
|
231
|
+
line = rt = s = ""
|
|
232
|
+
for var in self.__vars_order:
|
|
233
|
+
vars_len.append(len(var))
|
|
234
|
+
s = var + ' '
|
|
235
|
+
while len(s) < len('False '):
|
|
236
|
+
s += ' '
|
|
237
|
+
s += ' '
|
|
238
|
+
line += s
|
|
239
|
+
rt += line + 'value\n'
|
|
240
|
+
for row in self.__table:
|
|
241
|
+
line = s = ""
|
|
242
|
+
i = 0
|
|
243
|
+
for e in row:
|
|
244
|
+
j = 2 if e else 1
|
|
245
|
+
s = str(e) + ' ' * j
|
|
246
|
+
if i < len(vars_len):
|
|
247
|
+
while len(s) <= vars_len[i]:
|
|
248
|
+
s += ' '
|
|
249
|
+
s += ' '
|
|
250
|
+
line += s
|
|
251
|
+
i += 1
|
|
252
|
+
rt += line + '\n'
|
|
253
|
+
return rt
|
|
254
|
+
|
|
255
|
+
def get_table_list(self):
|
|
256
|
+
r"""
|
|
257
|
+
Return a list representation of the calling table object.
|
|
258
|
+
|
|
259
|
+
OUTPUT: list representation of the table
|
|
260
|
+
|
|
261
|
+
EXAMPLES:
|
|
262
|
+
|
|
263
|
+
This example illustrates how to show the table as a list::
|
|
264
|
+
|
|
265
|
+
sage: import sage.logic.propcalc as propcalc
|
|
266
|
+
sage: s = propcalc.formula("man->monkey&human")
|
|
267
|
+
sage: s.truthtable().get_table_list()
|
|
268
|
+
[['man', 'monkey', 'human'], [False, False, False, True], [False, False, True, True], [False, True, False, True], [False, True, True, True], [True, False, False, False], [True, False, True, False], [True, True, False, False], [True, True, True, True]]
|
|
269
|
+
"""
|
|
270
|
+
t = self.__table[:]
|
|
271
|
+
t.insert(0, self.__vars_order)
|
|
272
|
+
return t
|
sage/logic/propcalc.py
ADDED
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
r"""
|
|
2
|
+
Propositional Calculus
|
|
3
|
+
|
|
4
|
+
Formulas consist of the following operators:
|
|
5
|
+
|
|
6
|
+
* ``&`` -- and
|
|
7
|
+
* ``|`` -- or
|
|
8
|
+
* ``~`` -- not
|
|
9
|
+
* ``^`` -- xor
|
|
10
|
+
* ``->`` -- if-then
|
|
11
|
+
* ``<->`` -- if and only if
|
|
12
|
+
|
|
13
|
+
Operators can be applied to variables that consist of a leading letter and
|
|
14
|
+
trailing underscores and alphanumerics. Parentheses may be used to explicitly
|
|
15
|
+
show order of operation.
|
|
16
|
+
|
|
17
|
+
AUTHORS:
|
|
18
|
+
|
|
19
|
+
- Chris Gorecki (2006): initial version, propcalc, boolformula,
|
|
20
|
+
logictable, logicparser, booleval
|
|
21
|
+
|
|
22
|
+
- Michael Greenberg -- boolopt
|
|
23
|
+
|
|
24
|
+
- Paul Scurek (2013-08-05): updated docstring formatting
|
|
25
|
+
|
|
26
|
+
- Paul Scurek (2013-08-12): added :func:`~sage.logic.propcalc.get_formulas()`,
|
|
27
|
+
:func:`~sage.logic.propcalc.consistent()`,
|
|
28
|
+
:func:`~sage.logic.propcalc.valid_consequence()`
|
|
29
|
+
|
|
30
|
+
EXAMPLES:
|
|
31
|
+
|
|
32
|
+
We can create boolean formulas in different ways::
|
|
33
|
+
|
|
34
|
+
sage: f = propcalc.formula("a&((b|c)^a->c)<->b")
|
|
35
|
+
sage: g = propcalc.formula("boolean<->algebra")
|
|
36
|
+
sage: (f&~g).ifthen(f)
|
|
37
|
+
((a&((b|c)^a->c)<->b)&(~(boolean<->algebra)))->(a&((b|c)^a->c)<->b)
|
|
38
|
+
|
|
39
|
+
We can create a truth table from a formula::
|
|
40
|
+
|
|
41
|
+
sage: f.truthtable()
|
|
42
|
+
a b c value
|
|
43
|
+
False False False True
|
|
44
|
+
False False True True
|
|
45
|
+
False True False False
|
|
46
|
+
False True True False
|
|
47
|
+
True False False True
|
|
48
|
+
True False True False
|
|
49
|
+
True True False True
|
|
50
|
+
True True True True
|
|
51
|
+
sage: f.truthtable(end=3)
|
|
52
|
+
a b c value
|
|
53
|
+
False False False True
|
|
54
|
+
False False True True
|
|
55
|
+
False True False False
|
|
56
|
+
sage: f.truthtable(start=4)
|
|
57
|
+
a b c value
|
|
58
|
+
True False False True
|
|
59
|
+
True False True False
|
|
60
|
+
True True False True
|
|
61
|
+
True True True True
|
|
62
|
+
sage: propcalc.formula("a").truthtable()
|
|
63
|
+
a value
|
|
64
|
+
False False
|
|
65
|
+
True True
|
|
66
|
+
|
|
67
|
+
Now we can evaluate the formula for a given set of input::
|
|
68
|
+
|
|
69
|
+
sage: f.evaluate({'a':True, 'b':False, 'c':True})
|
|
70
|
+
False
|
|
71
|
+
sage: f.evaluate({'a':False, 'b':False, 'c':True})
|
|
72
|
+
True
|
|
73
|
+
|
|
74
|
+
And we can convert a boolean formula to conjunctive normal form::
|
|
75
|
+
|
|
76
|
+
sage: f.convert_cnf_table()
|
|
77
|
+
sage: f
|
|
78
|
+
(a|~b|c)&(a|~b|~c)&(~a|b|~c)
|
|
79
|
+
sage: f.convert_cnf_recur()
|
|
80
|
+
sage: f
|
|
81
|
+
(a|~b|c)&(a|~b|~c)&(~a|b|~c)
|
|
82
|
+
|
|
83
|
+
Or determine if an expression is satisfiable, a contradiction, or a tautology::
|
|
84
|
+
|
|
85
|
+
sage: f = propcalc.formula("a|b")
|
|
86
|
+
sage: f.is_satisfiable()
|
|
87
|
+
True
|
|
88
|
+
sage: f = f & ~f
|
|
89
|
+
sage: f.is_satisfiable()
|
|
90
|
+
False
|
|
91
|
+
sage: f.is_contradiction()
|
|
92
|
+
True
|
|
93
|
+
sage: f = f | ~f
|
|
94
|
+
sage: f.is_tautology()
|
|
95
|
+
True
|
|
96
|
+
|
|
97
|
+
The equality operator compares semantic equivalence::
|
|
98
|
+
|
|
99
|
+
sage: f = propcalc.formula("(a|b)&c")
|
|
100
|
+
sage: g = propcalc.formula("c&(b|a)")
|
|
101
|
+
sage: f == g
|
|
102
|
+
True
|
|
103
|
+
sage: g = propcalc.formula("a|b&c")
|
|
104
|
+
sage: f == g
|
|
105
|
+
False
|
|
106
|
+
|
|
107
|
+
It is an error to create a formula with bad syntax::
|
|
108
|
+
|
|
109
|
+
sage: propcalc.formula("")
|
|
110
|
+
Traceback (most recent call last):
|
|
111
|
+
...
|
|
112
|
+
SyntaxError: malformed statement
|
|
113
|
+
sage: propcalc.formula("a&b~(c|(d)")
|
|
114
|
+
Traceback (most recent call last):
|
|
115
|
+
...
|
|
116
|
+
SyntaxError: malformed statement
|
|
117
|
+
sage: propcalc.formula("a&&b")
|
|
118
|
+
Traceback (most recent call last):
|
|
119
|
+
...
|
|
120
|
+
SyntaxError: malformed statement
|
|
121
|
+
sage: propcalc.formula("a&b a")
|
|
122
|
+
Traceback (most recent call last):
|
|
123
|
+
...
|
|
124
|
+
SyntaxError: malformed statement
|
|
125
|
+
|
|
126
|
+
It is also an error to not abide by the naming conventions.
|
|
127
|
+
sage: propcalc.formula("~a&9b")
|
|
128
|
+
Traceback (most recent call last):
|
|
129
|
+
...
|
|
130
|
+
NameError: invalid variable name 9b: identifiers must begin with a letter and contain only alphanumerics and underscores
|
|
131
|
+
"""
|
|
132
|
+
# *****************************************************************************
|
|
133
|
+
# Copyright (C) 2006 William Stein <wstein@gmail.com>
|
|
134
|
+
# Copyright (C) 2006 Chris Gorecki <chris.k.gorecki@gmail.com>
|
|
135
|
+
# Copyright (C) 2013 Paul Scurek <scurek86@gmail.com>
|
|
136
|
+
#
|
|
137
|
+
# Distributed under the terms of the GNU General Public License (GPL)
|
|
138
|
+
# as published by the Free Software Foundation; either version 2 of
|
|
139
|
+
# the License, or (at your option) any later version.
|
|
140
|
+
# https://www.gnu.org/licenses/
|
|
141
|
+
# *****************************************************************************
|
|
142
|
+
|
|
143
|
+
# TODO:
|
|
144
|
+
# converts (cnf) returns w/o change
|
|
145
|
+
|
|
146
|
+
from . import boolformula
|
|
147
|
+
from . import logicparser
|
|
148
|
+
from sage.misc.superseded import deprecated_function_alias
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def formula(s):
|
|
152
|
+
r"""
|
|
153
|
+
Return an instance of :class:`BooleanFormula`.
|
|
154
|
+
|
|
155
|
+
INPUT:
|
|
156
|
+
|
|
157
|
+
- ``s`` -- string that contains a logical expression
|
|
158
|
+
|
|
159
|
+
OUTPUT: an instance of :class:`BooleanFormula`
|
|
160
|
+
|
|
161
|
+
EXAMPLES:
|
|
162
|
+
|
|
163
|
+
This example illustrates ways to create a boolean formula::
|
|
164
|
+
|
|
165
|
+
sage: f = propcalc.formula("a&~b|c")
|
|
166
|
+
sage: g = propcalc.formula("a^c<->b")
|
|
167
|
+
sage: f&g|f
|
|
168
|
+
((a&~b|c)&(a^c<->b))|(a&~b|c)
|
|
169
|
+
|
|
170
|
+
We now demonstrate some possible errors::
|
|
171
|
+
|
|
172
|
+
sage: propcalc.formula("((a&b)")
|
|
173
|
+
Traceback (most recent call last):
|
|
174
|
+
...
|
|
175
|
+
SyntaxError: malformed statement
|
|
176
|
+
sage: propcalc.formula("_a&b")
|
|
177
|
+
Traceback (most recent call last):
|
|
178
|
+
...
|
|
179
|
+
NameError: invalid variable name _a: identifiers must begin with a letter and contain only alphanumerics and underscores
|
|
180
|
+
"""
|
|
181
|
+
try:
|
|
182
|
+
parse_tree, vars_order = logicparser.parse(s)
|
|
183
|
+
f = boolformula.BooleanFormula(s, parse_tree, vars_order)
|
|
184
|
+
f.truthtable(0, 1)
|
|
185
|
+
except (KeyError, RuntimeError, IndexError, SyntaxError):
|
|
186
|
+
msg = "malformed statement"
|
|
187
|
+
raise SyntaxError(msg)
|
|
188
|
+
return f
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def get_formulas(*statements):
|
|
192
|
+
r"""
|
|
193
|
+
Convert statements and parse trees into instances of
|
|
194
|
+
:class:`BooleanFormula`.
|
|
195
|
+
|
|
196
|
+
INPUT:
|
|
197
|
+
|
|
198
|
+
- ``*statements`` -- strings or lists; a list must be a
|
|
199
|
+
full syntax parse tree of a formula, and a string must
|
|
200
|
+
be a string representation of a formula
|
|
201
|
+
|
|
202
|
+
OUTPUT: the converted formulas in a list
|
|
203
|
+
|
|
204
|
+
EXAMPLES:
|
|
205
|
+
|
|
206
|
+
This example illustrates converting strings into boolean formulas.
|
|
207
|
+
|
|
208
|
+
::
|
|
209
|
+
|
|
210
|
+
sage: f = "a&(~c<->d)"
|
|
211
|
+
sage: g = "d|~~b"
|
|
212
|
+
sage: h = "~(a->c)<->(d|~c)"
|
|
213
|
+
sage: propcalc.get_formulas(f, g, h)
|
|
214
|
+
[a&(~c<->d), d|~~b, ~(a->c)<->(d|~c)]
|
|
215
|
+
|
|
216
|
+
::
|
|
217
|
+
|
|
218
|
+
sage: A, B, C = propcalc.get_formulas("(a&b)->~c", "c", "~(a&b)")
|
|
219
|
+
sage: A
|
|
220
|
+
(a&b)->~c
|
|
221
|
+
sage: B
|
|
222
|
+
c
|
|
223
|
+
sage: C
|
|
224
|
+
~(a&b)
|
|
225
|
+
|
|
226
|
+
We can also convert parse trees into formulas.
|
|
227
|
+
|
|
228
|
+
::
|
|
229
|
+
|
|
230
|
+
sage: t = ['a']
|
|
231
|
+
sage: u = ['~', ['|', ['&', 'a', 'b'], ['~', 'c']]]
|
|
232
|
+
sage: v = "b->(~c<->d)"
|
|
233
|
+
sage: formulas= propcalc.get_formulas(t, u, v)
|
|
234
|
+
sage: formulas[0]
|
|
235
|
+
a
|
|
236
|
+
sage: formulas[1]
|
|
237
|
+
~((a&b)|~c)
|
|
238
|
+
sage: formulas[2]
|
|
239
|
+
b->(~c<->d)
|
|
240
|
+
|
|
241
|
+
AUTHORS:
|
|
242
|
+
|
|
243
|
+
- Paul Scurek (2013-08-12)
|
|
244
|
+
"""
|
|
245
|
+
formulas = []
|
|
246
|
+
|
|
247
|
+
for statement in statements:
|
|
248
|
+
try:
|
|
249
|
+
if isinstance(statement, str):
|
|
250
|
+
formulas.append(formula(statement))
|
|
251
|
+
elif isinstance(statement, list):
|
|
252
|
+
formulas.append(formula(logicparser.recover_formula(statement)))
|
|
253
|
+
else:
|
|
254
|
+
raise TypeError
|
|
255
|
+
except (SyntaxError, NameError):
|
|
256
|
+
raise SyntaxError("malformed statement")
|
|
257
|
+
except TypeError:
|
|
258
|
+
raise TypeError
|
|
259
|
+
return formulas
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def consistent(*formulas):
|
|
263
|
+
r"""
|
|
264
|
+
Determine if the formulas are logically consistent.
|
|
265
|
+
|
|
266
|
+
INPUT:
|
|
267
|
+
|
|
268
|
+
- ``*formulas`` -- instances of :class:`BooleanFormula`
|
|
269
|
+
|
|
270
|
+
OUTPUT: a boolean value to be determined as follows:
|
|
271
|
+
|
|
272
|
+
- ``True`` -- if the formulas are logically consistent
|
|
273
|
+
|
|
274
|
+
- ``False`` -- if the formulas are not logically consistent
|
|
275
|
+
|
|
276
|
+
EXAMPLES:
|
|
277
|
+
|
|
278
|
+
This example illustrates determining if formulas are logically consistent.
|
|
279
|
+
|
|
280
|
+
::
|
|
281
|
+
|
|
282
|
+
sage: f, g, h, i = propcalc.get_formulas("a<->b", "~b->~c", "d|g", "c&a")
|
|
283
|
+
sage: propcalc.consistent(f, g, h, i)
|
|
284
|
+
True
|
|
285
|
+
|
|
286
|
+
::
|
|
287
|
+
|
|
288
|
+
sage: j, k, l, m = propcalc.get_formulas("a<->b", "~b->~c", "d|g", "c&~a")
|
|
289
|
+
sage: propcalc.consistent(j, k ,l, m)
|
|
290
|
+
False
|
|
291
|
+
|
|
292
|
+
AUTHORS:
|
|
293
|
+
|
|
294
|
+
- Paul Scurek (2013-08-12)
|
|
295
|
+
"""
|
|
296
|
+
# make sure only instances of :class:`BooleanFormula` were passed as arguments
|
|
297
|
+
for formula in formulas[1:]:
|
|
298
|
+
if not isinstance(formula, boolformula.BooleanFormula):
|
|
299
|
+
raise TypeError("consistent() takes BooleanFormula() class instances as arguments")
|
|
300
|
+
|
|
301
|
+
# conjoin all of the formulas with &
|
|
302
|
+
conjunction = formulas[0]
|
|
303
|
+
for formula in formulas[1:]:
|
|
304
|
+
conjunction = conjunction & formula
|
|
305
|
+
|
|
306
|
+
# if conjunction is a contradiction, the formulas are inconsistent
|
|
307
|
+
return not conjunction.is_contradiction()
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
# define function ``valid_consequence`` for backward compatibility
|
|
311
|
+
valid_consequence = deprecated_function_alias(28052, boolformula.is_consequence)
|
sage/misc/all.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# from sage.misc.all__sagemath_objects import *
|
|
2
|
+
from sage.misc.all__sagemath_environment import *
|
|
3
|
+
from sage.misc.all__sagemath_modules import *
|
|
4
|
+
from sage.misc.all__sagemath_repl import *
|
|
5
|
+
|
|
6
|
+
from sage.misc.misc import (BackslashOperator,
|
|
7
|
+
exists, forall, is_iterator,
|
|
8
|
+
random_sublist,
|
|
9
|
+
pad_zeros,
|
|
10
|
+
newton_method_sizes, compose,
|
|
11
|
+
nest)
|
|
12
|
+
|
|
13
|
+
lazy_import('sage.misc.banner', 'banner', deprecation=34259)
|
|
14
|
+
lazy_import('sage.misc.edit_module', 'set_edit_template', deprecation=34259)
|
|
15
|
+
lazy_import('sage.misc.profiler', 'Profiler', deprecation=34259)
|
|
16
|
+
lazy_import('sage.misc.trace', 'trace', deprecation=34259)
|
|
17
|
+
lazy_import('sage.misc.package', ('installed_packages', 'is_package_installed',
|
|
18
|
+
'package_versions'),
|
|
19
|
+
deprecation=34259)
|
|
20
|
+
lazy_import('sage.misc.benchmark', 'benchmark', deprecation=34259)
|
|
21
|
+
lazy_import('sage.repl.interpreter', 'logstr', deprecation=34259)
|
|
22
|
+
|
|
23
|
+
# Following will go to all__sagemath_objects.py in #36566
|
|
24
|
+
from sage.misc.randstate import seed, set_random_seed, initial_seed, current_randstate
|
|
25
|
+
from sage.misc.prandom import *
|
|
26
|
+
from sage.misc.sage_timeit_class import timeit
|
|
27
|
+
from sage.misc.session import load_session, save_session, show_identifiers
|
|
28
|
+
from sage.misc.reset import reset, restore
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# sage_setup: distribution = sagemath-objects
|
|
2
|
+
|
|
3
|
+
# This type-stub file helps pyright understand the decorator @lazy_attribute.
|
|
4
|
+
|
|
5
|
+
# Adapted from https://github.com/python/typeshed/blob/b9640005eb586afdbe0a57bac2b88a7a12465069/stdlib/builtins.pyi#L1237-L1254
|
|
6
|
+
class lazy_attribute:
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
f: Callable[[Any], Any] | None = ...
|
|
10
|
+
) -> None: ...
|
|
11
|
+
def __get__(self, a: Any, cls: type) -> Any: ...
|
sage/rings/all.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Rings
|
|
3
|
+
"""
|
|
4
|
+
# ****************************************************************************
|
|
5
|
+
# Copyright (C) 2005 William Stein <wstein@gmail.com>
|
|
6
|
+
#
|
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU General Public License as published by
|
|
9
|
+
# the Free Software Foundation, either version 2 of the License, or
|
|
10
|
+
# (at your option) any later version.
|
|
11
|
+
# https://www.gnu.org/licenses/
|
|
12
|
+
# ****************************************************************************
|
|
13
|
+
from sage.misc.lazy_import import lazy_import
|
|
14
|
+
|
|
15
|
+
from sage.rings.all__sagemath_categories import *
|
|
16
|
+
|
|
17
|
+
# Finite fields
|
|
18
|
+
from sage.rings.finite_rings.all import *
|
|
19
|
+
|
|
20
|
+
from sage.rings.all__sagemath_combinat import *
|
|
21
|
+
from sage.rings.all__sagemath_flint import *
|
|
22
|
+
from sage.rings.all__sagemath_gap import *
|
|
23
|
+
from sage.rings.all__sagemath_modules import *
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
from sage.rings.all__sagemath_symbolics import *
|
|
27
|
+
except ImportError:
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
# Function field
|
|
31
|
+
from sage.rings.function_field.all import *
|
|
32
|
+
|
|
33
|
+
# Semirings
|
|
34
|
+
from sage.rings.semirings.all import *
|
|
35
|
+
|
|
36
|
+
# Double precision floating point numbers
|
|
37
|
+
from sage.rings.real_double import RealDoubleField, RDF, RealDoubleElement
|
|
38
|
+
|
|
39
|
+
# Polynomial Rings and Polynomial Quotient Rings
|
|
40
|
+
from sage.rings.polynomial.all import *
|
|
41
|
+
|
|
42
|
+
# Following will go to all__sagemath_categories.py in #36566
|
|
43
|
+
|
|
44
|
+
from sage.rings.fast_arith import prime_range
|
|
45
|
+
|
|
46
|
+
# Register classes in numbers abc
|
|
47
|
+
from sage.rings import numbers_abc
|
|
48
|
+
del lazy_import
|