thousandproblems 0.1.0__tar.gz → 0.2.0__tar.gz
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.
- thousandproblems-0.2.0/CHANGELOG.md +12 -0
- {thousandproblems-0.1.0/src/thousandproblems.egg-info → thousandproblems-0.2.0}/PKG-INFO +42 -6
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/README.md +41 -5
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/pyproject.toml +1 -1
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems/__init__.py +15 -3
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems/_cparser.c +371 -24
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems/_pyparser.py +98 -12
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems/library.py +3 -2
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems/nodes.py +45 -1
- {thousandproblems-0.1.0 → thousandproblems-0.2.0/src/thousandproblems.egg-info}/PKG-INFO +42 -6
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/tests/test_tptp.py +198 -0
- thousandproblems-0.1.0/CHANGELOG.md +0 -8
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/LICENSE +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/MANIFEST.in +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/benchmarks/bench.py +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/setup.cfg +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/setup.py +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems/_cparser.pyi +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems/py.typed +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems.egg-info/SOURCES.txt +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems.egg-info/dependency_links.txt +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/src/thousandproblems.egg-info/top_level.txt +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/tests/corpus.py +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/tests/test_backends.py +0 -0
- {thousandproblems-0.1.0 → thousandproblems-0.2.0}/tests/test_library.py +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
- `Variable.index` and `TypedVariable.index`: the distinct variables of a formula are numbered
|
|
6
|
+
1, 2, 3 ... in order of first appearance (scoped by quantifier; 0 outside a formula).
|
|
7
|
+
- `TPTPFile.symbols` and `AnnotatedFormula.symbols`: the symbol table, a tuple of
|
|
8
|
+
`Symbol(name, arity)` in order of first appearance, without `$` and `$$` symbols.
|
|
9
|
+
- First release: parser and printer for every TPTP language (`thf`, `tff`, `tcf`, `fof`,
|
|
10
|
+
`cnf`, `tpi`), with a C extension and a pure-Python fallback that build identical trees.
|
|
11
|
+
- `fetch_problem` / `open_library`: read problems, and expand their includes, from a TPTP
|
|
12
|
+
folder, a tarball or the TPTP website.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: thousandproblems
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Fast parser and printer for the TPTP problem and solution syntax (thf, tff, tcf, fof, cnf, tpi).
|
|
5
5
|
Author-email: Ontology Portal <pypi@ontologyportal.org>
|
|
6
6
|
License: GNU GENERAL PUBLIC LICENSE
|
|
@@ -731,11 +731,47 @@ Import it as `thousandproblems`; the examples below alias it to `tptp`.
|
|
|
731
731
|
>>> ax.language, ax.name, ax.role
|
|
732
732
|
('fof', 'ax1', 'axiom')
|
|
733
733
|
>>> ax.formula.quantifier, ax.formula.variables
|
|
734
|
-
('!', (Variable(name='X'),))
|
|
734
|
+
('!', (Variable(name='X', index=1),))
|
|
735
735
|
>>> print(ax)
|
|
736
736
|
fof(ax1,axiom,! [X] : (p(X) => q(X))).
|
|
737
737
|
```
|
|
738
738
|
|
|
739
|
+
## Variable indexes and the symbol table
|
|
740
|
+
|
|
741
|
+
Each `Variable` has an `index`: the distinct variables of one formula are numbered 1, 2, 3 ... in
|
|
742
|
+
order of first appearance.
|
|
743
|
+
|
|
744
|
+
```python
|
|
745
|
+
>>> clause = tptp.parse("cnf(c, axiom, f(X) | f(Y) | g(X, f(Y))).").formulae[0]
|
|
746
|
+
>>> [(v.name, v.index) for v in tptp.walk(clause.formula) if isinstance(v, tptp.Variable)]
|
|
747
|
+
[('X', 1), ('Y', 2), ('X', 1), ('Y', 2)]
|
|
748
|
+
```
|
|
749
|
+
|
|
750
|
+
A quantifier counts as the first appearance of the variables it binds, and every binding is its
|
|
751
|
+
own variable, so `! [Y,X] : p(X,Y)` numbers Y 1 and X 2, and `(! [X] : p(X)) & (! [X] : q(X))`
|
|
752
|
+
gives its two `X` the indexes 1 and 2. Numbering restarts for each formula, and a variable that
|
|
753
|
+
is not part of a formula (in an annotation, or built by hand) has index 0. `index` is not
|
|
754
|
+
compared, so `Variable("X") == Variable("X", 1)`.
|
|
755
|
+
|
|
756
|
+
`problem.symbols` is the symbol table: a tuple of `Symbol(name, arity)`, one for each distinct
|
|
757
|
+
function, constant or predicate the formulae use, in order of first appearance. `f/1` and `f/2`
|
|
758
|
+
are different symbols, and a constant has arity 0.
|
|
759
|
+
|
|
760
|
+
```python
|
|
761
|
+
>>> problem = tptp.parse("cnf(a, axiom, p(f(a), X) | ~ q(f(a,b))). cnf(b, axiom, p(c, Y)).")
|
|
762
|
+
>>> [str(s) for s in problem.symbols]
|
|
763
|
+
['p/2', 'f/1', 'a/0', 'q/1', 'f/2', 'b/0', 'c/0']
|
|
764
|
+
>>> problem.formulae[1].symbols
|
|
765
|
+
(Symbol(name='p', arity=2), Symbol(name='c', arity=0))
|
|
766
|
+
```
|
|
767
|
+
|
|
768
|
+
Variables, equality, numbers, distinct objects, `$` and `$$` symbols (`$true`, `$less` ...),
|
|
769
|
+
type declarations and annotations are not symbols. In THF, `f @ a` uses the symbols `f/0` and
|
|
770
|
+
`a/0`. Each formula has its own `symbols`, and the file's table is rebuilt when
|
|
771
|
+
`expand_includes` brings other files in, so it only covers formulae that are really there.
|
|
772
|
+
|
|
773
|
+
## Functions
|
|
774
|
+
|
|
739
775
|
| Function | |
|
|
740
776
|
| --- | --- |
|
|
741
777
|
| `parse(text, filename=None)` | Parse the text of a file. |
|
|
@@ -821,10 +857,10 @@ Measured on an Apple M-series laptop, Python 3.14, on generated problems of 0.4
|
|
|
821
857
|
|
|
822
858
|
| | pure Python | C | speedup |
|
|
823
859
|
| --- | --- | --- | --- |
|
|
824
|
-
| cnf | 0.
|
|
825
|
-
| fof | 0.
|
|
826
|
-
| tff | 0.
|
|
827
|
-
| thf | 0.
|
|
860
|
+
| cnf | 0.274 s | 0.026 s | 10.5x |
|
|
861
|
+
| fof | 0.269 s | 0.027 s | 10.0x |
|
|
862
|
+
| tff | 0.221 s | 0.020 s | 10.9x |
|
|
863
|
+
| thf | 0.160 s | 0.013 s | 12.4x |
|
|
828
864
|
|
|
829
865
|
Run `python benchmarks/bench.py` to measure on your machine.
|
|
830
866
|
|
|
@@ -29,11 +29,47 @@ Import it as `thousandproblems`; the examples below alias it to `tptp`.
|
|
|
29
29
|
>>> ax.language, ax.name, ax.role
|
|
30
30
|
('fof', 'ax1', 'axiom')
|
|
31
31
|
>>> ax.formula.quantifier, ax.formula.variables
|
|
32
|
-
('!', (Variable(name='X'),))
|
|
32
|
+
('!', (Variable(name='X', index=1),))
|
|
33
33
|
>>> print(ax)
|
|
34
34
|
fof(ax1,axiom,! [X] : (p(X) => q(X))).
|
|
35
35
|
```
|
|
36
36
|
|
|
37
|
+
## Variable indexes and the symbol table
|
|
38
|
+
|
|
39
|
+
Each `Variable` has an `index`: the distinct variables of one formula are numbered 1, 2, 3 ... in
|
|
40
|
+
order of first appearance.
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
>>> clause = tptp.parse("cnf(c, axiom, f(X) | f(Y) | g(X, f(Y))).").formulae[0]
|
|
44
|
+
>>> [(v.name, v.index) for v in tptp.walk(clause.formula) if isinstance(v, tptp.Variable)]
|
|
45
|
+
[('X', 1), ('Y', 2), ('X', 1), ('Y', 2)]
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
A quantifier counts as the first appearance of the variables it binds, and every binding is its
|
|
49
|
+
own variable, so `! [Y,X] : p(X,Y)` numbers Y 1 and X 2, and `(! [X] : p(X)) & (! [X] : q(X))`
|
|
50
|
+
gives its two `X` the indexes 1 and 2. Numbering restarts for each formula, and a variable that
|
|
51
|
+
is not part of a formula (in an annotation, or built by hand) has index 0. `index` is not
|
|
52
|
+
compared, so `Variable("X") == Variable("X", 1)`.
|
|
53
|
+
|
|
54
|
+
`problem.symbols` is the symbol table: a tuple of `Symbol(name, arity)`, one for each distinct
|
|
55
|
+
function, constant or predicate the formulae use, in order of first appearance. `f/1` and `f/2`
|
|
56
|
+
are different symbols, and a constant has arity 0.
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
>>> problem = tptp.parse("cnf(a, axiom, p(f(a), X) | ~ q(f(a,b))). cnf(b, axiom, p(c, Y)).")
|
|
60
|
+
>>> [str(s) for s in problem.symbols]
|
|
61
|
+
['p/2', 'f/1', 'a/0', 'q/1', 'f/2', 'b/0', 'c/0']
|
|
62
|
+
>>> problem.formulae[1].symbols
|
|
63
|
+
(Symbol(name='p', arity=2), Symbol(name='c', arity=0))
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Variables, equality, numbers, distinct objects, `$` and `$$` symbols (`$true`, `$less` ...),
|
|
67
|
+
type declarations and annotations are not symbols. In THF, `f @ a` uses the symbols `f/0` and
|
|
68
|
+
`a/0`. Each formula has its own `symbols`, and the file's table is rebuilt when
|
|
69
|
+
`expand_includes` brings other files in, so it only covers formulae that are really there.
|
|
70
|
+
|
|
71
|
+
## Functions
|
|
72
|
+
|
|
37
73
|
| Function | |
|
|
38
74
|
| --- | --- |
|
|
39
75
|
| `parse(text, filename=None)` | Parse the text of a file. |
|
|
@@ -119,10 +155,10 @@ Measured on an Apple M-series laptop, Python 3.14, on generated problems of 0.4
|
|
|
119
155
|
|
|
120
156
|
| | pure Python | C | speedup |
|
|
121
157
|
| --- | --- | --- | --- |
|
|
122
|
-
| cnf | 0.
|
|
123
|
-
| fof | 0.
|
|
124
|
-
| tff | 0.
|
|
125
|
-
| thf | 0.
|
|
158
|
+
| cnf | 0.274 s | 0.026 s | 10.5x |
|
|
159
|
+
| fof | 0.269 s | 0.027 s | 10.0x |
|
|
160
|
+
| tff | 0.221 s | 0.020 s | 10.9x |
|
|
161
|
+
| thf | 0.160 s | 0.013 s | 12.4x |
|
|
126
162
|
|
|
127
163
|
Run `python benchmarks/bench.py` to measure on your machine.
|
|
128
164
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "thousandproblems"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "Fast parser and printer for the TPTP problem and solution syntax (thf, tff, tcf, fof, cnf, tpi)."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -10,7 +10,7 @@ directives, and annotations (sources, inference records, useful info).
|
|
|
10
10
|
>>> ax.language, ax.name, ax.role
|
|
11
11
|
('fof', 'ax1', 'axiom')
|
|
12
12
|
>>> ax.formula.quantifier, ax.formula.variables
|
|
13
|
-
('!', (Variable(name='X'),))
|
|
13
|
+
('!', (Variable(name='X', index=1),))
|
|
14
14
|
>>> print(ax)
|
|
15
15
|
fof(ax1,axiom,! [X] : (p(X) => q(X))).
|
|
16
16
|
|
|
@@ -27,6 +27,18 @@ The AST is the same for all languages:
|
|
|
27
27
|
:class:`Binary`. ``>`` is right-associative.
|
|
28
28
|
* Constants are :class:`Function` with no arguments. Defined and system symbols keep
|
|
29
29
|
their prefix, as in ``Function('$true')``.
|
|
30
|
+
* ``Variable.index`` numbers the distinct variables of a formula 1, 2, 3 ... in order of
|
|
31
|
+
first appearance, so in ``f(X) | f(Y) | g(X, f(Y))`` every ``X`` has index 1 and every
|
|
32
|
+
``Y`` index 2. A quantifier counts as the appearance of the variables it binds, and each
|
|
33
|
+
binding is its own variable: the two ``X`` of ``(! [X] : p(X)) & (! [X] : q(X))`` get
|
|
34
|
+
indexes 1 and 2. Numbering starts again for each formula; a variable outside a formula (in
|
|
35
|
+
an annotation, or built by hand) has index 0.
|
|
36
|
+
* ``TPTPFile.symbols`` is the symbol table: a tuple of :class:`Symbol` ``(name, arity)``,
|
|
37
|
+
one for each distinct function, constant or predicate the formulae use, in order of first
|
|
38
|
+
appearance, so ``f/1`` and ``f/2`` are different symbols. Variables, equality, numbers,
|
|
39
|
+
distinct objects, ``$`` and ``$$`` symbols, type declarations and annotations are not
|
|
40
|
+
symbols. Each ``AnnotatedFormula`` has its own ``symbols`` too, and the file's table follows
|
|
41
|
+
``expand_includes``.
|
|
30
42
|
* Quotes are removed from a word when the result is still a valid lower-case word,
|
|
31
43
|
so ``'cat'`` and ``cat`` compare equal, as the specification requires. Any other
|
|
32
44
|
quoted word keeps its quotes; use :func:`unquote` to get the raw text.
|
|
@@ -59,7 +71,7 @@ from typing import Optional, Union
|
|
|
59
71
|
|
|
60
72
|
from . import _pyparser
|
|
61
73
|
from .nodes import * # noqa: F403
|
|
62
|
-
from .nodes import _error_at, __all__ as _node_names
|
|
74
|
+
from .nodes import _error_at, _symbol_table, __all__ as _node_names
|
|
63
75
|
|
|
64
76
|
_LIBRARY_NAMES = ("DirectoryLibrary", "Library", "LibraryError", "OnlineLibrary", "ProblemNotFound",
|
|
65
77
|
"RateLimited", "TarballLibrary", "fetch_problem", "open_library")
|
|
@@ -158,4 +170,4 @@ def _load(path: Path, root: Optional[Path], expand: bool, stack: tuple[Path, ...
|
|
|
158
170
|
raise fail(f"{item.path!r} has no formulae named {sorted(missing)}")
|
|
159
171
|
formulae = tuple(selected)
|
|
160
172
|
inputs.extend(formulae)
|
|
161
|
-
return TPTPFile(tuple(inputs), parsed.comments, parsed.filename)
|
|
173
|
+
return TPTPFile(tuple(inputs), parsed.comments, parsed.filename, _symbol_table(i for i in inputs if isinstance(i, AnnotatedFormula)))
|