certsf 0.1.0a1__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 (61) hide show
  1. certsf-0.1.0a1/.gitattributes +1 -0
  2. certsf-0.1.0a1/.github/workflows/release-checks.yml +43 -0
  3. certsf-0.1.0a1/.github/workflows/tests.yml +70 -0
  4. certsf-0.1.0a1/.gitignore +20 -0
  5. certsf-0.1.0a1/CHANGELOG.md +8 -0
  6. certsf-0.1.0a1/CITATION.cff +10 -0
  7. certsf-0.1.0a1/LICENSE +21 -0
  8. certsf-0.1.0a1/PKG-INFO +286 -0
  9. certsf-0.1.0a1/README.md +249 -0
  10. certsf-0.1.0a1/benchmarks/_common.py +36 -0
  11. certsf-0.1.0a1/benchmarks/bench_airy.py +17 -0
  12. certsf-0.1.0a1/benchmarks/bench_bessel.py +17 -0
  13. certsf-0.1.0a1/benchmarks/bench_gamma.py +17 -0
  14. certsf-0.1.0a1/benchmarks/bench_pcf.py +18 -0
  15. certsf-0.1.0a1/docs/audit/airy.md +42 -0
  16. certsf-0.1.0a1/docs/audit/bessel.md +45 -0
  17. certsf-0.1.0a1/docs/audit/gamma.md +46 -0
  18. certsf-0.1.0a1/docs/audit/parabolic_cylinder.md +53 -0
  19. certsf-0.1.0a1/docs/certification.md +195 -0
  20. certsf-0.1.0a1/docs/certification_audit.md +75 -0
  21. certsf-0.1.0a1/docs/certified_scope_0_1_0.md +62 -0
  22. certsf-0.1.0a1/docs/formula_audit.md +349 -0
  23. certsf-0.1.0a1/docs/release-0.1.0.md +88 -0
  24. certsf-0.1.0a1/docs/release_checklist.md +62 -0
  25. certsf-0.1.0a1/examples/airy_components.py +18 -0
  26. certsf-0.1.0a1/examples/basic_usage.py +24 -0
  27. certsf-0.1.0a1/examples/bessel_complex.py +21 -0
  28. certsf-0.1.0a1/examples/certified_vs_high_precision.py +75 -0
  29. certsf-0.1.0a1/examples/gamma_certified.py +18 -0
  30. certsf-0.1.0a1/examples/mcp_payload.py +18 -0
  31. certsf-0.1.0a1/examples/pcf_experimental.py +20 -0
  32. certsf-0.1.0a1/pyproject.toml +78 -0
  33. certsf-0.1.0a1/src/certsf/__init__.py +28 -0
  34. certsf-0.1.0a1/src/certsf/backends/__init__.py +1 -0
  35. certsf-0.1.0a1/src/certsf/backends/_common.py +83 -0
  36. certsf-0.1.0a1/src/certsf/backends/arb_backend.py +652 -0
  37. certsf-0.1.0a1/src/certsf/backends/mpmath_backend.py +233 -0
  38. certsf-0.1.0a1/src/certsf/backends/scipy_backend.py +204 -0
  39. certsf-0.1.0a1/src/certsf/dispatcher.py +465 -0
  40. certsf-0.1.0a1/src/certsf/functions/__init__.py +26 -0
  41. certsf-0.1.0a1/src/certsf/functions/airy.py +25 -0
  42. certsf-0.1.0a1/src/certsf/functions/bessel.py +21 -0
  43. certsf-0.1.0a1/src/certsf/functions/gamma.py +17 -0
  44. certsf-0.1.0a1/src/certsf/functions/parabolic_cylinder.py +25 -0
  45. certsf-0.1.0a1/src/certsf/mcp_server.py +105 -0
  46. certsf-0.1.0a1/src/certsf/result.py +134 -0
  47. certsf-0.1.0a1/tests/test_airy.py +123 -0
  48. certsf-0.1.0a1/tests/test_bessel.py +172 -0
  49. certsf-0.1.0a1/tests/test_branch_singularity.py +51 -0
  50. certsf-0.1.0a1/tests/test_certification_audit.py +129 -0
  51. certsf-0.1.0a1/tests/test_certification_contract.py +92 -0
  52. certsf-0.1.0a1/tests/test_certified_identities.py +225 -0
  53. certsf-0.1.0a1/tests/test_dispatcher.py +65 -0
  54. certsf-0.1.0a1/tests/test_gamma.py +124 -0
  55. certsf-0.1.0a1/tests/test_identity_residuals.py +204 -0
  56. certsf-0.1.0a1/tests/test_mcp_schema.py +72 -0
  57. certsf-0.1.0a1/tests/test_pbdv.py +167 -0
  58. certsf-0.1.0a1/tests/test_public_contract.py +174 -0
  59. certsf-0.1.0a1/tests/test_release_artifacts.py +36 -0
  60. certsf-0.1.0a1/tests/test_release_scope.py +86 -0
  61. certsf-0.1.0a1/tests/test_result.py +87 -0
@@ -0,0 +1 @@
1
+ * text=auto eol=lf
@@ -0,0 +1,43 @@
1
+ name: release-checks
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ package:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-python@v5
13
+ with:
14
+ python-version: "3.12"
15
+ - name: Install build tooling
16
+ run: |
17
+ python -m pip install --upgrade pip
18
+ python -m pip install build twine
19
+ - name: Build sdist and wheel
20
+ run: python -m build
21
+ - name: Check package metadata
22
+ run: python -m twine check dist/*
23
+ - name: Install built wheel
24
+ run: python -m pip install dist/*.whl
25
+ - name: Import installed package
26
+ run: python -c "import certsf; print(certsf.__all__)"
27
+
28
+ lint-type:
29
+ runs-on: ubuntu-latest
30
+ steps:
31
+ - uses: actions/checkout@v4
32
+ - uses: actions/setup-python@v5
33
+ with:
34
+ python-version: "3.12"
35
+ - name: Install static-analysis tooling
36
+ run: |
37
+ python -m pip install --upgrade pip
38
+ python -m pip install -e ".[dev]"
39
+ python -m pip install pyright
40
+ - name: Run ruff
41
+ run: ruff check .
42
+ - name: Run pyright
43
+ run: pyright src --pythonpath "$(which python)"
@@ -0,0 +1,70 @@
1
+ name: tests
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+
7
+ jobs:
8
+ package-build:
9
+ runs-on: ubuntu-latest
10
+ steps:
11
+ - uses: actions/checkout@v4
12
+ - uses: actions/setup-python@v5
13
+ with:
14
+ python-version: "3.12"
15
+ - name: Install build backend
16
+ run: |
17
+ python -m pip install --upgrade pip
18
+ python -m pip install build
19
+ - name: Build sdist and wheel
20
+ run: python -m build
21
+
22
+ lint-type:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v4
26
+ - uses: actions/setup-python@v5
27
+ with:
28
+ python-version: "3.12"
29
+ - name: Install package and dev dependencies
30
+ run: |
31
+ python -m pip install --upgrade pip
32
+ python -m pip install -e ".[dev]"
33
+ - name: Run ruff
34
+ run: python -m ruff check src tests examples
35
+ - name: Run mypy
36
+ run: python -m mypy
37
+
38
+ pytest-certified:
39
+ runs-on: ubuntu-latest
40
+ strategy:
41
+ matrix:
42
+ python-version: ["3.10", "3.11", "3.12"]
43
+ steps:
44
+ - uses: actions/checkout@v4
45
+ - uses: actions/setup-python@v5
46
+ with:
47
+ python-version: ${{ matrix.python-version }}
48
+ - name: Install package and test dependencies
49
+ run: |
50
+ python -m pip install --upgrade pip
51
+ python -m pip install -e ".[test,certified]"
52
+ - name: Run tests
53
+ run: python -m pytest
54
+
55
+ pytest-base:
56
+ runs-on: ubuntu-latest
57
+ strategy:
58
+ matrix:
59
+ python-version: ["3.10", "3.11", "3.12"]
60
+ steps:
61
+ - uses: actions/checkout@v4
62
+ - uses: actions/setup-python@v5
63
+ with:
64
+ python-version: ${{ matrix.python-version }}
65
+ - name: Install package and test dependencies
66
+ run: |
67
+ python -m pip install --upgrade pip
68
+ python -m pip install -e ".[test]"
69
+ - name: Run tests
70
+ run: python -m pytest
@@ -0,0 +1,20 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *$py.class
4
+
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ .mypy_cache/
8
+ .coverage
9
+ htmlcov/
10
+
11
+ .venv/
12
+ venv/
13
+ env/
14
+
15
+ build/
16
+ dist/
17
+ *.egg-info/
18
+
19
+ .DS_Store
20
+ Thumbs.db
@@ -0,0 +1,8 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0-alpha.1 - 2026-05-07
4
+
5
+ - Added special-function wrappers for gamma, Airy, Bessel, and parabolic-cylinder families.
6
+ - Added SciPy fast mode, mpmath high-precision mode, and optional python-flint certified mode.
7
+ - Added structured `SFResult` diagnostics, MCP wrappers, CI, and certification documentation.
8
+ - Hardened dispatcher v2 with an explicit backend method registry and API/MCP coverage checks.
@@ -0,0 +1,10 @@
1
+ cff-version: 1.2.0
2
+ message: "If you use certsf in research, please cite it using this metadata."
3
+ title: "certsf: Certified special-function wrappers with explicit diagnostics"
4
+ version: 0.1.0-alpha.1
5
+ date-released: 2026-05-07
6
+ authors:
7
+ - family-names: Lee
8
+ given-names: Yutian
9
+ repository-code: "https://github.com/yutianlee/certsf"
10
+ license: MIT
certsf-0.1.0a1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yutian Lee
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.
@@ -0,0 +1,286 @@
1
+ Metadata-Version: 2.4
2
+ Name: certsf
3
+ Version: 0.1.0a1
4
+ Summary: Certified special-function wrappers with explicit diagnostics.
5
+ Project-URL: Homepage, https://github.com/yutianlee/certsf
6
+ Project-URL: Repository, https://github.com/yutianlee/certsf
7
+ Project-URL: Issues, https://github.com/yutianlee/certsf/issues
8
+ Author: Yutian Lee
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: arb,interval-arithmetic,mpmath,scientific-computing,special-functions,validated-numerics
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: mpmath>=1.3
22
+ Requires-Dist: scipy>=1.10
23
+ Provides-Extra: certified
24
+ Requires-Dist: python-flint>=0.6; extra == 'certified'
25
+ Provides-Extra: dev
26
+ Requires-Dist: build>=1.2; extra == 'dev'
27
+ Requires-Dist: mcp>=1.0; extra == 'dev'
28
+ Requires-Dist: mypy>=1.10; extra == 'dev'
29
+ Requires-Dist: pytest>=8; extra == 'dev'
30
+ Requires-Dist: python-flint>=0.6; extra == 'dev'
31
+ Requires-Dist: ruff>=0.6; extra == 'dev'
32
+ Provides-Extra: mcp
33
+ Requires-Dist: mcp>=1.0; extra == 'mcp'
34
+ Provides-Extra: test
35
+ Requires-Dist: pytest>=8; extra == 'test'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # certsf
39
+
40
+ `certsf` provides special-function wrappers with explicit diagnostics and, where
41
+ available, rigorous Arb ball enclosures through `python-flint`.
42
+
43
+ The public API is intentionally small: every function returns an `SFResult`
44
+ object with the computed value, backend metadata, certification status, optional
45
+ error bounds, and diagnostics explaining how the result was produced.
46
+
47
+ The certification scope lives in [`docs/certification.md`](docs/certification.md);
48
+ the scope-by-scope audit lives in
49
+ [`docs/certification_audit.md`](docs/certification_audit.md);
50
+ the 0.1.0 certified support matrix lives in
51
+ [`docs/certified_scope_0_1_0.md`](docs/certified_scope_0_1_0.md), and the formula
52
+ audit trail lives in [`docs/formula_audit.md`](docs/formula_audit.md).
53
+
54
+ ## Installation
55
+
56
+ For local development:
57
+
58
+ ```powershell
59
+ python -m pip install -e ".[dev]"
60
+ ```
61
+
62
+ For runtime use without optional MCP tooling:
63
+
64
+ ```powershell
65
+ python -m pip install -e ".[certified]"
66
+ ```
67
+
68
+ The base package depends on `scipy` and `mpmath`. Certified mode additionally
69
+ requires `python-flint`.
70
+
71
+ ## Quick Start
72
+
73
+ ```python
74
+ from certsf import gamma, besselj, pcfu
75
+
76
+ g = gamma("3.2", dps=50, mode="certified")
77
+ j = besselj("2.5", "4.0+1.25j", dps=60, mode="certified")
78
+ u = pcfu("2.5", "1.25", dps=60, mode="certified")
79
+
80
+ print(g.value)
81
+ print(g.abs_error_bound)
82
+ print(g.certified)
83
+ print(g.backend)
84
+ print(g.diagnostics)
85
+ ```
86
+
87
+ For a plain numerical value, use `mode="fast"` or `mode="high_precision"`:
88
+
89
+ ```python
90
+ from certsf import airy
91
+
92
+ result = airy("1.0", dps=80, mode="high_precision")
93
+ print(result.value)
94
+ ```
95
+
96
+ ## Result Object
97
+
98
+ Every wrapper returns an `SFResult` with these fields:
99
+
100
+ - `value`: string value, or a JSON string for multi-component results.
101
+ - `abs_error_bound`: rigorous absolute error bound when certified.
102
+ - `rel_error_bound`: rigorous relative error bound when available.
103
+ - `certified`: `True` only when a rigorous enclosure was produced.
104
+ - `function`: canonical function name.
105
+ - `method`: implementation method, such as `scipy.special`, `mpmath`, or
106
+ `arb_ball`.
107
+ - `backend`: backend package name.
108
+ - `requested_dps`: requested decimal precision.
109
+ - `working_dps`: internal decimal precision estimate.
110
+ - `diagnostics`: structured details about mode, domain, formula, and scope.
111
+
112
+ Unsupported certified domains return a clean non-certified result with
113
+ `value=""`, `certified=False`, and an explanatory diagnostics error. They do not
114
+ silently fall back to mpmath and call the value certified.
115
+
116
+ Certified successes also expose `diagnostics["certificate_level"]`,
117
+ `diagnostics["audit_status"]`, and `diagnostics["certification_claim"]`, so
118
+ callers can distinguish direct Arb primitive wrappers from formula-backed
119
+ experimental claims.
120
+
121
+ ## Choosing a Mode
122
+
123
+ - `mode="fast"` uses `scipy.special`; it is quick and non-certified.
124
+ - `mode="high_precision"` uses `mpmath`; it supports higher precision and
125
+ complex arguments, but is still non-certified.
126
+ - `mode="certified"` uses `python-flint` / Arb when a validated enclosure path
127
+ exists.
128
+ - `mode="auto"` chooses certified mode when `certify=True`, otherwise fast mode
129
+ for `dps <= 15` and high-precision mode for larger `dps` requests.
130
+
131
+ Fast mode is double precision. If you request more than 15 digits while forcing
132
+ `mode="fast"`, the result reports `working_dps=16` and includes a diagnostic
133
+ warning that the requested digits are not guaranteed.
134
+
135
+ Use `mode="certified"` when the error bound matters. Use `high_precision` when
136
+ you need more digits but not a rigorous certificate.
137
+
138
+ The dispatcher uses an explicit `MethodSpec` registry for every concrete mode.
139
+ Each registered method records its backend, callable, certification intent,
140
+ domain note, and certificate scope. Adding a public wrapper requires registering
141
+ its SciPy, mpmath, and Arb methods together; tests verify the registry, public
142
+ API, and MCP tool list stay in sync.
143
+
144
+ ## Supported Functions
145
+
146
+ The 0.1.0 alpha public certified surface is frozen. No additional public
147
+ special-function wrappers are planned before 0.1.0; the release work is focused
148
+ on audit, validation, packaging, and documentation.
149
+
150
+ | Area | Release status |
151
+ | --- | --- |
152
+ | `gamma`, `loggamma`, `rgamma` | alpha-certified, direct Arb primitive |
153
+ | `airy`, `ai`, `bi` | alpha-certified, direct Arb primitive |
154
+ | `besselj`, `bessely`, `besseli`, `besselk` | alpha-certified where direct Arb primitive works; real-valued order only |
155
+ | `pcfd`, `pcfu`, `pcfv`, `pcfw`, `pbdv` | experimental certified formula layer |
156
+ | MCP server | experimental tool interface |
157
+ | Custom Taylor/asymptotic methods | not yet |
158
+
159
+ ```python
160
+ from certsf import (
161
+ gamma,
162
+ loggamma,
163
+ rgamma,
164
+ airy,
165
+ ai,
166
+ bi,
167
+ besselj,
168
+ bessely,
169
+ besseli,
170
+ besselk,
171
+ pbdv,
172
+ pcfd,
173
+ pcfu,
174
+ pcfv,
175
+ pcfw,
176
+ )
177
+ ```
178
+
179
+ ### Gamma Family
180
+
181
+ - `gamma(z)`
182
+ - `loggamma(z)`, using the principal branch
183
+ - `rgamma(z) = 1 / gamma(z)`
184
+
185
+ `rgamma` is the safest wrapper near non-positive integer gamma poles. In
186
+ certified mode, `rgamma` returns a rigorous zero at poles, while `gamma` and
187
+ `loggamma` return clean non-certified failures when the requested value is not
188
+ finite.
189
+
190
+ ### Airy Family
191
+
192
+ - `airy(z)` returns Ai, Ai', Bi, and Bi' in one JSON payload.
193
+ - `ai(z, derivative=0)` and `ai(z, derivative=1)`.
194
+ - `bi(z, derivative=0)` and `bi(z, derivative=1)`.
195
+
196
+ Certified Airy wrappers use Arb ball arithmetic and report component-level
197
+ absolute and relative error bounds.
198
+
199
+ ### Bessel Family
200
+
201
+ - `besselj(v, z)` for \(J_v(z)\)
202
+ - `bessely(v, z)` for \(Y_v(z)\)
203
+ - `besseli(v, z)` for \(I_v(z)\)
204
+ - `besselk(v, z)` for \(K_v(z)\)
205
+
206
+ Certified Bessel wrappers support real-valued order and real or complex
207
+ arguments. Complex order is outside the certified scope and returns a clean
208
+ non-certified failure.
209
+
210
+ ### Parabolic-Cylinder Family
211
+
212
+ - `pbdv(v, x)` returns \(D_v(x)\) and \(D_v'(x)\) in one JSON payload.
213
+ - `pcfd(v, z)` returns \(D_v(z)\).
214
+ - `pcfu(a, z)` returns \(U(a,z)\).
215
+ - `pcfv(a, z)` returns \(V(a,z)\).
216
+ - `pcfw(a, x)` returns \(W(a,x)\).
217
+
218
+ Certified `pcfu`, `pcfd`, `pbdv`, and `pcfv` support real parameters and real
219
+ or complex arguments. Certified `pcfw` currently supports real parameters and
220
+ real arguments; complex arguments return a clean non-certified failure until a
221
+ validated complex-domain target is selected.
222
+
223
+ The parabolic-cylinder family is an experimental certified formula layer: Arb
224
+ encloses the implemented documented formula, while formula/domain audit remains
225
+ visible before broadening the claim.
226
+
227
+ ## Multi-Component Values
228
+
229
+ Functions such as `airy` and `pbdv` keep backward-compatible JSON strings in
230
+ `SFResult.value`, and provide helpers for Python callers:
231
+
232
+ ```python
233
+ from certsf import pbdv
234
+
235
+ result = pbdv("2.5", "1.25", dps=60, mode="certified")
236
+ values = result.value_as_dict()
237
+ bounds = result.abs_error_bound_as_dict()
238
+
239
+ print(values["value"])
240
+ print(values["derivative"])
241
+ print(bounds["value"])
242
+ print(bounds["derivative"])
243
+ print(result.component("value"))
244
+ ```
245
+
246
+ ## MCP Wrapper
247
+
248
+ `certsf.mcp_server` exposes thin MCP-facing wrappers around the same public API.
249
+ MCP payloads decode multi-component values and bounds as nested JSON objects
250
+ instead of JSON-encoded strings.
251
+ Install the optional MCP dependency before running the server:
252
+
253
+ ```powershell
254
+ python -m pip install -e ".[mcp,certified]"
255
+ python -m certsf.mcp_server
256
+ ```
257
+
258
+ ## Development
259
+
260
+ Run the test suite with:
261
+
262
+ ```powershell
263
+ python -m pytest
264
+ ```
265
+
266
+ The tests exercise the SciPy, mpmath, and Arb-backed paths when the optional
267
+ dependencies are installed.
268
+
269
+ The repository also includes:
270
+
271
+ - `docs/release_checklist.md` for prerelease/release verification.
272
+ - `docs/certification_audit.md` for scope-level certification evidence and
273
+ remaining audit gates.
274
+ - `docs/audit/` for family-level certification checklists.
275
+ - `docs/certified_scope_0_1_0.md` for the frozen 0.1.0 certified support
276
+ matrix.
277
+ - `docs/release-0.1.0.md` for alpha release notes and example commands.
278
+ - `examples/basic_usage.py` for a short end-to-end usage example.
279
+ - `examples/certified_vs_high_precision.py` for a compact comparison of
280
+ high-precision and certified result diagnostics.
281
+ - `examples/gamma_certified.py`, `examples/airy_components.py`,
282
+ `examples/bessel_complex.py`, `examples/pcf_experimental.py`, and
283
+ `examples/mcp_payload.py` for payload-first release examples.
284
+ - `benchmarks/bench_gamma.py`, `benchmarks/bench_airy.py`,
285
+ `benchmarks/bench_bessel.py`, and `benchmarks/bench_pcf.py` for lightweight
286
+ JSON-lines timing smoke benchmarks.