post-canonical 2.0.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.
Files changed (50) hide show
  1. post_canonical-2.0.0/.github/workflows/ci.yml +65 -0
  2. post_canonical-2.0.0/.github/workflows/publish.yml +46 -0
  3. post_canonical-2.0.0/.gitignore +194 -0
  4. post_canonical-2.0.0/.python-version +1 -0
  5. post_canonical-2.0.0/CHANGELOG.md +59 -0
  6. post_canonical-2.0.0/LICENSE +21 -0
  7. post_canonical-2.0.0/PKG-INFO +329 -0
  8. post_canonical-2.0.0/README.md +311 -0
  9. post_canonical-2.0.0/docs/ARCHITECTURE.md +295 -0
  10. post_canonical-2.0.0/example.py +371 -0
  11. post_canonical-2.0.0/pyproject.toml +51 -0
  12. post_canonical-2.0.0/src/post_canonical/__init__.py +105 -0
  13. post_canonical-2.0.0/src/post_canonical/builder.py +285 -0
  14. post_canonical-2.0.0/src/post_canonical/cli.py +570 -0
  15. post_canonical-2.0.0/src/post_canonical/core/__init__.py +14 -0
  16. post_canonical-2.0.0/src/post_canonical/core/alphabet.py +55 -0
  17. post_canonical-2.0.0/src/post_canonical/core/errors.py +42 -0
  18. post_canonical-2.0.0/src/post_canonical/core/pattern.py +163 -0
  19. post_canonical-2.0.0/src/post_canonical/core/rule.py +74 -0
  20. post_canonical-2.0.0/src/post_canonical/core/variable.py +75 -0
  21. post_canonical-2.0.0/src/post_canonical/matching/__init__.py +11 -0
  22. post_canonical-2.0.0/src/post_canonical/matching/binding.py +74 -0
  23. post_canonical-2.0.0/src/post_canonical/matching/matcher.py +159 -0
  24. post_canonical-2.0.0/src/post_canonical/matching/unifier.py +95 -0
  25. post_canonical-2.0.0/src/post_canonical/presets/__init__.py +27 -0
  26. post_canonical-2.0.0/src/post_canonical/presets/alphabets.py +20 -0
  27. post_canonical-2.0.0/src/post_canonical/presets/examples.py +125 -0
  28. post_canonical-2.0.0/src/post_canonical/py.typed +0 -0
  29. post_canonical-2.0.0/src/post_canonical/query/__init__.py +9 -0
  30. post_canonical-2.0.0/src/post_canonical/query/reachability.py +125 -0
  31. post_canonical-2.0.0/src/post_canonical/serialization/__init__.py +7 -0
  32. post_canonical-2.0.0/src/post_canonical/serialization/json_codec.py +145 -0
  33. post_canonical-2.0.0/src/post_canonical/system/__init__.py +15 -0
  34. post_canonical-2.0.0/src/post_canonical/system/derivation.py +125 -0
  35. post_canonical-2.0.0/src/post_canonical/system/executor.py +206 -0
  36. post_canonical-2.0.0/src/post_canonical/system/pcs.py +183 -0
  37. post_canonical-2.0.0/src/post_canonical/visualization.py +219 -0
  38. post_canonical-2.0.0/tests/conftest.py +110 -0
  39. post_canonical-2.0.0/tests/test_alphabet.py +169 -0
  40. post_canonical-2.0.0/tests/test_binding.py +253 -0
  41. post_canonical-2.0.0/tests/test_derivation.py +369 -0
  42. post_canonical-2.0.0/tests/test_executor.py +438 -0
  43. post_canonical-2.0.0/tests/test_matcher.py +333 -0
  44. post_canonical-2.0.0/tests/test_pattern.py +285 -0
  45. post_canonical-2.0.0/tests/test_pcs.py +423 -0
  46. post_canonical-2.0.0/tests/test_reachability.py +340 -0
  47. post_canonical-2.0.0/tests/test_rule.py +263 -0
  48. post_canonical-2.0.0/tests/test_serialization.py +539 -0
  49. post_canonical-2.0.0/tests/test_variable.py +197 -0
  50. post_canonical-2.0.0/uv.lock +163 -0
@@ -0,0 +1,65 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+ branches: [main]
8
+
9
+ jobs:
10
+ lint:
11
+ name: Lint
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+
16
+ - name: Install uv
17
+ uses: astral-sh/setup-uv@v4
18
+
19
+ - name: Set up Python
20
+ run: uv python install 3.12
21
+
22
+ - name: Install dependencies
23
+ run: uv sync --dev
24
+
25
+ - name: Run ruff check
26
+ run: uv run ruff check .
27
+
28
+ - name: Run ruff format check
29
+ run: uv run ruff format --check .
30
+
31
+ type-check:
32
+ name: Type Check
33
+ runs-on: ubuntu-latest
34
+ steps:
35
+ - uses: actions/checkout@v4
36
+
37
+ - name: Install uv
38
+ uses: astral-sh/setup-uv@v4
39
+
40
+ - name: Set up Python
41
+ run: uv python install 3.12
42
+
43
+ - name: Install dependencies
44
+ run: uv sync --dev
45
+
46
+ - name: Run mypy
47
+ run: uv run mypy src/
48
+
49
+ test:
50
+ name: Test
51
+ runs-on: ubuntu-latest
52
+ steps:
53
+ - uses: actions/checkout@v4
54
+
55
+ - name: Install uv
56
+ uses: astral-sh/setup-uv@v4
57
+
58
+ - name: Set up Python
59
+ run: uv python install 3.12
60
+
61
+ - name: Install dependencies
62
+ run: uv sync --dev
63
+
64
+ - name: Run pytest
65
+ run: uv run pytest tests/ -v
@@ -0,0 +1,46 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ build:
9
+ name: Build distribution
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+
14
+ - name: Install uv
15
+ uses: astral-sh/setup-uv@v4
16
+
17
+ - name: Set up Python
18
+ run: uv python install 3.12
19
+
20
+ - name: Build package
21
+ run: uv build
22
+
23
+ - name: Store distribution packages
24
+ uses: actions/upload-artifact@v4
25
+ with:
26
+ name: python-package-distributions
27
+ path: dist/
28
+
29
+ publish:
30
+ name: Publish to PyPI
31
+ needs: build
32
+ runs-on: ubuntu-latest
33
+ environment:
34
+ name: pypi
35
+ url: https://pypi.org/p/post-canonical
36
+ permissions:
37
+ id-token: write
38
+ steps:
39
+ - name: Download distribution packages
40
+ uses: actions/download-artifact@v4
41
+ with:
42
+ name: python-package-distributions
43
+ path: dist/
44
+
45
+ - name: Publish to PyPI
46
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,194 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Abstra
171
+ # Abstra is an AI-powered process automation framework.
172
+ # Ignore directories containing user credentials, local state, and settings.
173
+ # Learn more at https://abstra.io/docs
174
+ .abstra/
175
+
176
+ # Visual Studio Code
177
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
178
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
179
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
180
+ # you could uncomment the following to ignore the enitre vscode folder
181
+ # .vscode/
182
+
183
+ # Ruff stuff:
184
+ .ruff_cache/
185
+
186
+ # PyPI configuration file
187
+ .pypirc
188
+
189
+ # Cursor
190
+ # Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
191
+ # exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
192
+ # refer to https://docs.cursor.com/context/ignore-files
193
+ .cursorignore
194
+ .cursorindexingignore
@@ -0,0 +1 @@
1
+ 3.12
@@ -0,0 +1,59 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [2.0.0] - 2025-01-24
9
+
10
+ Complete rewrite of the Post Canonical Systems library with a modern, ergonomic API.
11
+
12
+ ### Added
13
+
14
+ - **SystemBuilder**: Fluent DSL for constructing systems without manual object creation.
15
+ Supports `$name` and `${name}` variable syntax with method chaining.
16
+ - **Interactive CLI (REPL)**: New `pcs` command provides an interactive shell for
17
+ building and exploring systems without writing Python code.
18
+ - **Visualization exports**: Export derivation proofs in multiple formats:
19
+ - GraphViz DOT for directed graphs
20
+ - LaTeX with `align*` environment and `\xrightarrow` annotations
21
+ - Mermaid for Markdown-compatible diagrams
22
+ - ASCII trees for terminal display
23
+ - **Derivation tracking**: Full provenance tracking with `Derivation`, `DerivationStep`,
24
+ and `DerivedWord` types to trace how words are generated.
25
+ - **Reachability queries**: `ReachabilityQuery` class to check if target words are
26
+ derivable from axioms, with configurable search limits.
27
+ - **Execution modes**: `ExecutionConfig` with `BFS` and `DFS` execution strategies.
28
+ - **Preset alphabets**: Built-in alphabets for common use cases (`BINARY`, `DECIMAL`,
29
+ `HEXADECIMAL`, `ENGLISH_LOWERCASE`, `ENGLISH_UPPERCASE`, `ENGLISH_LETTERS`, `MIU`).
30
+ - **Example systems**: Ready-to-use systems including `create_mu_puzzle()`,
31
+ `create_binary_doubler()`, and `create_palindrome_generator()`.
32
+ - **JSON serialization**: `PCSJsonCodec` for saving and loading system definitions.
33
+ - **Type annotations**: Full type hints throughout with PEP 561 `py.typed` marker.
34
+
35
+ ### Changed
36
+
37
+ - **Pattern matching**: Redesigned pattern system with explicit `Pattern` and `Variable`
38
+ types. Variables now have kinds (`ANY`, `NON_EMPTY`, `SINGLE`) for finer control.
39
+ - **Production rules**: Rules now support multiple antecedents for more expressive
40
+ pattern matching. Rule syntax uses `->` separator.
41
+ - **API structure**: Modular package structure with clear separation between core types,
42
+ system execution, queries, and serialization.
43
+
44
+ ### Fixed
45
+
46
+ - Multi-antecedent rules now correctly match multiple input words and bind variables
47
+ consistently across all antecedent patterns.
48
+ - Pattern matching handles edge cases with empty strings and single-character variables.
49
+ - Variable binding respects variable kind constraints during matching.
50
+
51
+ ## [1.0.0] - 2024-01-01
52
+
53
+ Initial implementation of Post Canonical Systems.
54
+
55
+ ### Added
56
+
57
+ - Basic `PostCanonicalSystem` class
58
+ - Simple production rules with single-character variables
59
+ - Word generation with step limits
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 niarenaw
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.