certsf 0.1.0__py3-none-any.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.
- certsf/__init__.py +28 -0
- certsf/backends/__init__.py +1 -0
- certsf/backends/_common.py +83 -0
- certsf/backends/arb_backend.py +652 -0
- certsf/backends/mpmath_backend.py +233 -0
- certsf/backends/scipy_backend.py +204 -0
- certsf/dispatcher.py +465 -0
- certsf/functions/__init__.py +26 -0
- certsf/functions/airy.py +25 -0
- certsf/functions/bessel.py +21 -0
- certsf/functions/gamma.py +17 -0
- certsf/functions/parabolic_cylinder.py +25 -0
- certsf/mcp_server.py +105 -0
- certsf/result.py +134 -0
- certsf-0.1.0.dist-info/METADATA +317 -0
- certsf-0.1.0.dist-info/RECORD +18 -0
- certsf-0.1.0.dist-info/WHEEL +4 -0
- certsf-0.1.0.dist-info/licenses/LICENSE +21 -0
certsf/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""Certified special-function wrappers."""
|
|
2
|
+
|
|
3
|
+
from .functions.airy import ai, airyai, airy, airybi, bi
|
|
4
|
+
from .functions.bessel import besseli, besselj, besselk, bessely
|
|
5
|
+
from .functions.gamma import gamma, loggamma, rgamma
|
|
6
|
+
from .functions.parabolic_cylinder import pbdv, pcfd, pcfu, pcfv, pcfw
|
|
7
|
+
from .result import SFResult
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"SFResult",
|
|
11
|
+
"ai",
|
|
12
|
+
"airyai",
|
|
13
|
+
"airy",
|
|
14
|
+
"airybi",
|
|
15
|
+
"bi",
|
|
16
|
+
"besseli",
|
|
17
|
+
"besselj",
|
|
18
|
+
"besselk",
|
|
19
|
+
"bessely",
|
|
20
|
+
"gamma",
|
|
21
|
+
"loggamma",
|
|
22
|
+
"rgamma",
|
|
23
|
+
"pbdv",
|
|
24
|
+
"pcfd",
|
|
25
|
+
"pcfu",
|
|
26
|
+
"pcfv",
|
|
27
|
+
"pcfw",
|
|
28
|
+
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Backend implementations for certsf."""
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"""Shared helpers for backend wrappers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from certsf.result import SFResult
|
|
9
|
+
|
|
10
|
+
UNCERTIFIED_WARNING = "High precision numerical value, but no rigorous error enclosure."
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def ensure_dps(dps: int) -> int:
|
|
14
|
+
requested = int(dps)
|
|
15
|
+
if requested <= 0:
|
|
16
|
+
raise ValueError("dps must be a positive integer")
|
|
17
|
+
return requested
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def scipy_number(value: Any) -> Any:
|
|
21
|
+
if isinstance(value, str):
|
|
22
|
+
text = value.strip().replace("i", "j")
|
|
23
|
+
return complex(text) if "j" in text.lower() else float(text)
|
|
24
|
+
return value
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def scipy_real(value: Any) -> float:
|
|
28
|
+
if isinstance(value, str):
|
|
29
|
+
return float(value.strip())
|
|
30
|
+
return float(value)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def float_digits(dps: int) -> int:
|
|
34
|
+
return 17
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def number_to_string(value: Any, *, digits: int = 17) -> str:
|
|
38
|
+
if hasattr(value, "item"):
|
|
39
|
+
try:
|
|
40
|
+
value = value.item()
|
|
41
|
+
except ValueError:
|
|
42
|
+
pass
|
|
43
|
+
if isinstance(value, complex):
|
|
44
|
+
real = format(float(value.real), f".{digits}g")
|
|
45
|
+
imag_abs = format(abs(float(value.imag)), f".{digits}g")
|
|
46
|
+
sign = "+" if value.imag >= 0 else "-"
|
|
47
|
+
return f"{real}{sign}{imag_abs}j"
|
|
48
|
+
if isinstance(value, float):
|
|
49
|
+
return format(value, f".{digits}g")
|
|
50
|
+
return str(value)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def json_string(mapping: dict[str, str]) -> str:
|
|
54
|
+
return json.dumps(mapping, sort_keys=True)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def make_result(
|
|
58
|
+
*,
|
|
59
|
+
function: str,
|
|
60
|
+
value: str,
|
|
61
|
+
requested_dps: int,
|
|
62
|
+
working_dps: int,
|
|
63
|
+
method: str,
|
|
64
|
+
backend: str,
|
|
65
|
+
certified: bool,
|
|
66
|
+
abs_error_bound: str | None = None,
|
|
67
|
+
rel_error_bound: str | None = None,
|
|
68
|
+
terms_used: int | None = None,
|
|
69
|
+
diagnostics: dict[str, Any] | None = None,
|
|
70
|
+
) -> SFResult:
|
|
71
|
+
return SFResult(
|
|
72
|
+
value=value,
|
|
73
|
+
abs_error_bound=abs_error_bound,
|
|
74
|
+
rel_error_bound=rel_error_bound,
|
|
75
|
+
certified=certified,
|
|
76
|
+
function=function,
|
|
77
|
+
method=method,
|
|
78
|
+
backend=backend,
|
|
79
|
+
requested_dps=requested_dps,
|
|
80
|
+
working_dps=working_dps,
|
|
81
|
+
terms_used=terms_used,
|
|
82
|
+
diagnostics={} if diagnostics is None else diagnostics,
|
|
83
|
+
)
|