ceexp 0.3.3__tar.gz → 0.3.4__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.
- {ceexp-0.3.3/src/ceexp.egg-info → ceexp-0.3.4}/PKG-INFO +30 -6
- {ceexp-0.3.3 → ceexp-0.3.4}/README.md +27 -5
- {ceexp-0.3.3 → ceexp-0.3.4}/pyproject.toml +3 -1
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp/__init__.py +1 -1
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp/benchmark.py +16 -13
- ceexp-0.3.4/src/ceexp/cli.py +121 -0
- {ceexp-0.3.3 → ceexp-0.3.4/src/ceexp.egg-info}/PKG-INFO +30 -6
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp.egg-info/SOURCES.txt +2 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp.egg-info/entry_points.txt +1 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp.egg-info/requires.txt +3 -0
- ceexp-0.3.4/tests/test_cli.py +59 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/LICENSE +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/LICENSE-docs.md +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/setup.cfg +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp/constant.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp/expansions.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp/residue.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp/series.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp/verify.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp.egg-info/dependency_links.txt +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/src/ceexp.egg-info/top_level.txt +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/tests/test_benchmark.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/tests/test_champernowne_comparison.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/tests/test_expansions.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/tests/test_properties.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/tests/test_reference.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/tests/test_theorems.py +0 -0
- {ceexp-0.3.3 → ceexp-0.3.4}/tests/test_variants_and_arithmetic.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ceexp
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Interval-certified Engel, Pierce, Luroth, and continued-fraction expansions and precision benchmarks
|
|
5
5
|
Author-email: Nicolás León Parra <leonparranicolas@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -17,17 +17,41 @@ Requires-Dist: numpy>=1.26; extra == "experiments"
|
|
|
17
17
|
Requires-Dist: scipy>=1.11; extra == "experiments"
|
|
18
18
|
Provides-Extra: benchmark
|
|
19
19
|
Requires-Dist: mpmath>=1.2; extra == "benchmark"
|
|
20
|
+
Provides-Extra: fast
|
|
21
|
+
Requires-Dist: gmpy2>=2.1; extra == "fast"
|
|
20
22
|
Dynamic: license-file
|
|
21
23
|
|
|
22
|
-
# Expansions and residues of the Copeland–Erdős constant
|
|
24
|
+
# Expansions and residues of the Copeland–Erdős constant (`ceexp`)
|
|
23
25
|
|
|
26
|
+
[](https://github.com/Nicolas11Leon/copeland-erdos-expansions/actions/workflows/ci.yml)
|
|
27
|
+
[](https://pypi.org/project/ceexp/)
|
|
28
|
+
[](https://pypi.org/project/ceexp/)
|
|
29
|
+
[](LICENSE)
|
|
24
30
|
[](https://doi.org/10.5281/zenodo.24693622)
|
|
25
31
|
|
|
26
|
-
Certified computations, proofs and reproducible experiments on
|
|
27
|
-
**
|
|
28
|
-
|
|
32
|
+
Certified computations, proofs and reproducible experiments on classical unit-fraction expansions
|
|
33
|
+
(**Engel, Pierce, Lüroth, greedy Egyptian, and continued fractions**) of the **Copeland–Erdős
|
|
34
|
+
constant** `C = 0.235711131719232931374143…` (OEIS [A033308](https://oeis.org/A033308)) and
|
|
35
|
+
base-$b$ Champernowne constants.
|
|
29
36
|
|
|
30
|
-
**Author:** Nicolás León Parra · **
|
|
37
|
+
**Author:** Nicolás León Parra · **Version:** v0.3.4 · **Code:** MIT · **Text and data:** CC BY 4.0
|
|
38
|
+
|
|
39
|
+
## Quickstart
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install ceexp # zero required dependencies
|
|
43
|
+
pip install "ceexp[fast]" # optional gmpy2 acceleration
|
|
44
|
+
pip install "ceexp[benchmark]" # optional mpmath comparison
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ceexp certify --expansion engel --digits 10000 --limit 10
|
|
49
|
+
ceexp certify --expansion luroth --digits-file my_constant.txt --digits 5000
|
|
50
|
+
ceexp bench 50000
|
|
51
|
+
ceexp order 10 100000000000031
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
See [docs/api.md](docs/api.md) for the full Python API reference.
|
|
31
55
|
|
|
32
56
|
## What is in this repository
|
|
33
57
|
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
# Expansions and residues of the Copeland–Erdős constant
|
|
1
|
+
# Expansions and residues of the Copeland–Erdős constant (`ceexp`)
|
|
2
2
|
|
|
3
|
+
[](https://github.com/Nicolas11Leon/copeland-erdos-expansions/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/ceexp/)
|
|
5
|
+
[](https://pypi.org/project/ceexp/)
|
|
6
|
+
[](LICENSE)
|
|
3
7
|
[](https://doi.org/10.5281/zenodo.24693622)
|
|
4
8
|
|
|
5
|
-
Certified computations, proofs and reproducible experiments on
|
|
6
|
-
**
|
|
7
|
-
|
|
9
|
+
Certified computations, proofs and reproducible experiments on classical unit-fraction expansions
|
|
10
|
+
(**Engel, Pierce, Lüroth, greedy Egyptian, and continued fractions**) of the **Copeland–Erdős
|
|
11
|
+
constant** `C = 0.235711131719232931374143…` (OEIS [A033308](https://oeis.org/A033308)) and
|
|
12
|
+
base-$b$ Champernowne constants.
|
|
8
13
|
|
|
9
|
-
**Author:** Nicolás León Parra · **
|
|
14
|
+
**Author:** Nicolás León Parra · **Version:** v0.3.4 · **Code:** MIT · **Text and data:** CC BY 4.0
|
|
15
|
+
|
|
16
|
+
## Quickstart
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install ceexp # zero required dependencies
|
|
20
|
+
pip install "ceexp[fast]" # optional gmpy2 acceleration
|
|
21
|
+
pip install "ceexp[benchmark]" # optional mpmath comparison
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
ceexp certify --expansion engel --digits 10000 --limit 10
|
|
26
|
+
ceexp certify --expansion luroth --digits-file my_constant.txt --digits 5000
|
|
27
|
+
ceexp bench 50000
|
|
28
|
+
ceexp order 10 100000000000031
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
See [docs/api.md](docs/api.md) for the full Python API reference.
|
|
10
32
|
|
|
11
33
|
## What is in this repository
|
|
12
34
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "ceexp"
|
|
7
|
-
version = "0.3.
|
|
7
|
+
version = "0.3.4"
|
|
8
8
|
description = "Interval-certified Engel, Pierce, Luroth, and continued-fraction expansions and precision benchmarks"
|
|
9
9
|
authors = [{ name = "Nicolás León Parra", email = "leonparranicolas@gmail.com" }]
|
|
10
10
|
license = { text = "MIT" }
|
|
@@ -25,11 +25,13 @@ Repository = "https://github.com/Nicolas11Leon/copeland-erdos-expansions"
|
|
|
25
25
|
Issues = "https://github.com/Nicolas11Leon/copeland-erdos-expansions/issues"
|
|
26
26
|
|
|
27
27
|
[project.scripts]
|
|
28
|
+
ceexp = "ceexp.cli:main"
|
|
28
29
|
ceexp-bench = "ceexp.benchmark:main"
|
|
29
30
|
|
|
30
31
|
[project.optional-dependencies]
|
|
31
32
|
experiments = ["numpy>=1.26", "scipy>=1.11"]
|
|
32
33
|
benchmark = ["mpmath>=1.2"]
|
|
34
|
+
fast = ["gmpy2>=2.1"]
|
|
33
35
|
|
|
34
36
|
[tool.setuptools.packages.find]
|
|
35
37
|
where = ["src"]
|
|
@@ -15,8 +15,9 @@ import math
|
|
|
15
15
|
import sys
|
|
16
16
|
import time
|
|
17
17
|
import tracemalloc
|
|
18
|
+
from functools import partial
|
|
18
19
|
from pathlib import Path
|
|
19
|
-
from typing import Callable
|
|
20
|
+
from typing import Any, Callable
|
|
20
21
|
|
|
21
22
|
try:
|
|
22
23
|
import mpmath
|
|
@@ -28,6 +29,7 @@ from .expansions import (
|
|
|
28
29
|
certified_interval,
|
|
29
30
|
continued_fraction,
|
|
30
31
|
engel,
|
|
32
|
+
gmpy2 as _gmpy2,
|
|
31
33
|
luroth,
|
|
32
34
|
pierce,
|
|
33
35
|
)
|
|
@@ -219,13 +221,15 @@ def run_benchmark(
|
|
|
219
221
|
trunc_digits: tuple[int, ...] = (500, 2000),
|
|
220
222
|
modes: tuple[str, ...] = ("engel", "pierce", "luroth", "continued_fraction"),
|
|
221
223
|
measure_memory: bool = False,
|
|
222
|
-
) -> dict[str,
|
|
224
|
+
) -> dict[str, Any]:
|
|
223
225
|
"""Benchmark uncertified engines against interval-certified ground truth."""
|
|
224
226
|
constants = build_benchmark_constants(n_digits)
|
|
225
|
-
|
|
227
|
+
cases: dict[str, Any] = {}
|
|
228
|
+
report: dict[str, Any] = {
|
|
226
229
|
"n_digits": n_digits,
|
|
230
|
+
"backend": "gmpy2" if _gmpy2 is not None else "python-int",
|
|
227
231
|
"mpmath_version": getattr(mpmath, "__version__", None),
|
|
228
|
-
"cases":
|
|
232
|
+
"cases": cases,
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
for name, digits in constants.items():
|
|
@@ -253,27 +257,25 @@ def run_benchmark(
|
|
|
253
257
|
entry["engine_term"] = str(cand[div_k - 1])[:24]
|
|
254
258
|
engines[label] = entry
|
|
255
259
|
|
|
256
|
-
record("float64",
|
|
260
|
+
record("float64", partial(run_float64, digits, mode, max_terms))
|
|
257
261
|
for prec in decimal_precs:
|
|
258
262
|
record(
|
|
259
263
|
f"decimal_{prec}",
|
|
260
|
-
|
|
264
|
+
partial(run_decimal, digits, mode, prec, max_terms),
|
|
261
265
|
)
|
|
262
266
|
if mpmath is not None:
|
|
263
267
|
record(
|
|
264
268
|
f"mpmath_{prec}",
|
|
265
|
-
|
|
269
|
+
partial(run_mpmath, digits, mode, prec, max_terms),
|
|
266
270
|
)
|
|
267
271
|
for td in trunc_digits:
|
|
268
272
|
if td < n_digits:
|
|
269
273
|
record(
|
|
270
274
|
f"trunc_{td}",
|
|
271
|
-
|
|
272
|
-
digits, exp_fn, d, max_terms
|
|
273
|
-
),
|
|
275
|
+
partial(run_uncertified_truncation, digits, exp_fn, td, max_terms),
|
|
274
276
|
)
|
|
275
277
|
|
|
276
|
-
entry_mode: dict[str,
|
|
278
|
+
entry_mode: dict[str, Any] = {
|
|
277
279
|
"certified_terms": max_terms,
|
|
278
280
|
"certified_elapsed_ms": cert_ms,
|
|
279
281
|
"engines": engines,
|
|
@@ -281,7 +283,7 @@ def run_benchmark(
|
|
|
281
283
|
if cert_kb is not None:
|
|
282
284
|
entry_mode["certified_peak_kb"] = cert_kb
|
|
283
285
|
case_entry[mode] = entry_mode
|
|
284
|
-
|
|
286
|
+
cases[name] = case_entry
|
|
285
287
|
return report
|
|
286
288
|
|
|
287
289
|
|
|
@@ -300,7 +302,8 @@ def main() -> None:
|
|
|
300
302
|
out_path.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
|
|
301
303
|
|
|
302
304
|
print(
|
|
303
|
-
f"Precision-failure benchmark (N={n_digits:,} digits,
|
|
305
|
+
f"Precision-failure benchmark (N={n_digits:,} digits, "
|
|
306
|
+
f"backend={report['backend']}, mpmath={report['mpmath_version']})"
|
|
304
307
|
)
|
|
305
308
|
for name, modes in report["cases"].items():
|
|
306
309
|
for mode, data in modes.items():
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Command-line interface for ceexp."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import re
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Sequence
|
|
10
|
+
|
|
11
|
+
from . import __version__
|
|
12
|
+
from .benchmark import EXPANSIONS, _champernowne_digits, main as bench_main
|
|
13
|
+
from .constant import copeland_erdos_digits
|
|
14
|
+
from .expansions import certified_interval, greedy_egyptian
|
|
15
|
+
from .residue import multiplicative_order
|
|
16
|
+
|
|
17
|
+
CLI_EXPANSIONS = {**EXPANSIONS, "greedy": greedy_egyptian}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _load_digits_file(path: Path, limit: int | None) -> str:
|
|
21
|
+
raw = path.read_text(encoding="utf-8").strip()
|
|
22
|
+
if "." in raw:
|
|
23
|
+
raw = raw.split(".", 1)[1]
|
|
24
|
+
digits = re.sub(r"\D", "", raw)
|
|
25
|
+
if not digits:
|
|
26
|
+
raise ValueError(f"No decimal digits found in {path}")
|
|
27
|
+
return digits[:limit] if limit is not None else digits
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _cmd_certify(args: argparse.Namespace) -> int:
|
|
31
|
+
if args.digits_file:
|
|
32
|
+
digits = _load_digits_file(Path(args.digits_file), args.digits)
|
|
33
|
+
elif args.constant == "champernowne-10":
|
|
34
|
+
digits = "".join(str(d) for d in _champernowne_digits(args.digits, 10))
|
|
35
|
+
else:
|
|
36
|
+
digits = copeland_erdos_digits(args.digits)
|
|
37
|
+
|
|
38
|
+
exp_fn = CLI_EXPANSIONS[args.expansion]
|
|
39
|
+
terms = certified_interval(exp_fn, digits)
|
|
40
|
+
shown = terms[: args.limit] if args.limit else terms
|
|
41
|
+
print(f"Certified {len(terms)} terms ({args.expansion}, N={len(digits)} digits):")
|
|
42
|
+
print(", ".join(str(t) for t in shown))
|
|
43
|
+
return 0
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _cmd_order(args: argparse.Namespace) -> int:
|
|
47
|
+
val = multiplicative_order(args.a, args.p)
|
|
48
|
+
print(f"ord_{args.p}({args.a}) = {val}")
|
|
49
|
+
return 0
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
53
|
+
parser = argparse.ArgumentParser(
|
|
54
|
+
prog="ceexp",
|
|
55
|
+
description="Interval-certified expansions and precision benchmarks.",
|
|
56
|
+
)
|
|
57
|
+
parser.add_argument("--version", action="version", version=f"ceexp {__version__}")
|
|
58
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
59
|
+
|
|
60
|
+
p_cert = sub.add_parser("certify", help="Interval-certify an expansion of a constant.")
|
|
61
|
+
p_cert.add_argument(
|
|
62
|
+
"--expansion",
|
|
63
|
+
choices=sorted(CLI_EXPANSIONS.keys()),
|
|
64
|
+
default="engel",
|
|
65
|
+
help="Expansion type (default: engel).",
|
|
66
|
+
)
|
|
67
|
+
p_cert.add_argument(
|
|
68
|
+
"--constant",
|
|
69
|
+
choices=("copeland-erdos", "champernowne-10"),
|
|
70
|
+
default="copeland-erdos",
|
|
71
|
+
help="Built-in constant when --digits-file is omitted.",
|
|
72
|
+
)
|
|
73
|
+
p_cert.add_argument(
|
|
74
|
+
"--digits-file",
|
|
75
|
+
help="Path to a text file containing fractional digits (0.xxxx or xxxx).",
|
|
76
|
+
)
|
|
77
|
+
p_cert.add_argument(
|
|
78
|
+
"--digits",
|
|
79
|
+
type=int,
|
|
80
|
+
default=5000,
|
|
81
|
+
help="Number of decimal digits to use (default: 5000).",
|
|
82
|
+
)
|
|
83
|
+
p_cert.add_argument(
|
|
84
|
+
"--limit",
|
|
85
|
+
type=int,
|
|
86
|
+
default=20,
|
|
87
|
+
help="Maximum number of certified terms to print (0 = all, default: 20).",
|
|
88
|
+
)
|
|
89
|
+
p_cert.set_defaults(func=_cmd_certify)
|
|
90
|
+
|
|
91
|
+
p_bench = sub.add_parser("bench", help="Run the precision-failure benchmark.")
|
|
92
|
+
p_bench.add_argument("n_digits", nargs="?", type=int, default=50_000)
|
|
93
|
+
p_bench.add_argument("--memory", action="store_true", help="Measure peak KB separately.")
|
|
94
|
+
|
|
95
|
+
p_ord = sub.add_parser("order", help="Compute multiplicative order of a mod prime p.")
|
|
96
|
+
p_ord.add_argument("a", type=int)
|
|
97
|
+
p_ord.add_argument("p", type=int)
|
|
98
|
+
p_ord.set_defaults(func=_cmd_order)
|
|
99
|
+
|
|
100
|
+
return parser
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
104
|
+
parser = build_parser()
|
|
105
|
+
args = parser.parse_args(list(argv) if argv is not None else None)
|
|
106
|
+
if args.command == "bench":
|
|
107
|
+
bench_argv = ["ceexp-bench", str(args.n_digits)]
|
|
108
|
+
if args.memory:
|
|
109
|
+
bench_argv.append("--memory")
|
|
110
|
+
old_argv = sys.argv
|
|
111
|
+
try:
|
|
112
|
+
sys.argv = bench_argv
|
|
113
|
+
bench_main()
|
|
114
|
+
finally:
|
|
115
|
+
sys.argv = old_argv
|
|
116
|
+
return 0
|
|
117
|
+
return int(args.func(args))
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
if __name__ == "__main__":
|
|
121
|
+
raise SystemExit(main())
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ceexp
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Interval-certified Engel, Pierce, Luroth, and continued-fraction expansions and precision benchmarks
|
|
5
5
|
Author-email: Nicolás León Parra <leonparranicolas@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -17,17 +17,41 @@ Requires-Dist: numpy>=1.26; extra == "experiments"
|
|
|
17
17
|
Requires-Dist: scipy>=1.11; extra == "experiments"
|
|
18
18
|
Provides-Extra: benchmark
|
|
19
19
|
Requires-Dist: mpmath>=1.2; extra == "benchmark"
|
|
20
|
+
Provides-Extra: fast
|
|
21
|
+
Requires-Dist: gmpy2>=2.1; extra == "fast"
|
|
20
22
|
Dynamic: license-file
|
|
21
23
|
|
|
22
|
-
# Expansions and residues of the Copeland–Erdős constant
|
|
24
|
+
# Expansions and residues of the Copeland–Erdős constant (`ceexp`)
|
|
23
25
|
|
|
26
|
+
[](https://github.com/Nicolas11Leon/copeland-erdos-expansions/actions/workflows/ci.yml)
|
|
27
|
+
[](https://pypi.org/project/ceexp/)
|
|
28
|
+
[](https://pypi.org/project/ceexp/)
|
|
29
|
+
[](LICENSE)
|
|
24
30
|
[](https://doi.org/10.5281/zenodo.24693622)
|
|
25
31
|
|
|
26
|
-
Certified computations, proofs and reproducible experiments on
|
|
27
|
-
**
|
|
28
|
-
|
|
32
|
+
Certified computations, proofs and reproducible experiments on classical unit-fraction expansions
|
|
33
|
+
(**Engel, Pierce, Lüroth, greedy Egyptian, and continued fractions**) of the **Copeland–Erdős
|
|
34
|
+
constant** `C = 0.235711131719232931374143…` (OEIS [A033308](https://oeis.org/A033308)) and
|
|
35
|
+
base-$b$ Champernowne constants.
|
|
29
36
|
|
|
30
|
-
**Author:** Nicolás León Parra · **
|
|
37
|
+
**Author:** Nicolás León Parra · **Version:** v0.3.4 · **Code:** MIT · **Text and data:** CC BY 4.0
|
|
38
|
+
|
|
39
|
+
## Quickstart
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pip install ceexp # zero required dependencies
|
|
43
|
+
pip install "ceexp[fast]" # optional gmpy2 acceleration
|
|
44
|
+
pip install "ceexp[benchmark]" # optional mpmath comparison
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
ceexp certify --expansion engel --digits 10000 --limit 10
|
|
49
|
+
ceexp certify --expansion luroth --digits-file my_constant.txt --digits 5000
|
|
50
|
+
ceexp bench 50000
|
|
51
|
+
ceexp order 10 100000000000031
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
See [docs/api.md](docs/api.md) for the full Python API reference.
|
|
31
55
|
|
|
32
56
|
## What is in this repository
|
|
33
57
|
|
|
@@ -4,6 +4,7 @@ README.md
|
|
|
4
4
|
pyproject.toml
|
|
5
5
|
src/ceexp/__init__.py
|
|
6
6
|
src/ceexp/benchmark.py
|
|
7
|
+
src/ceexp/cli.py
|
|
7
8
|
src/ceexp/constant.py
|
|
8
9
|
src/ceexp/expansions.py
|
|
9
10
|
src/ceexp/residue.py
|
|
@@ -17,6 +18,7 @@ src/ceexp.egg-info/requires.txt
|
|
|
17
18
|
src/ceexp.egg-info/top_level.txt
|
|
18
19
|
tests/test_benchmark.py
|
|
19
20
|
tests/test_champernowne_comparison.py
|
|
21
|
+
tests/test_cli.py
|
|
20
22
|
tests/test_expansions.py
|
|
21
23
|
tests/test_properties.py
|
|
22
24
|
tests/test_reference.py
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"""Tests for the ceexp command-line interface."""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import sys
|
|
5
|
+
import tempfile
|
|
6
|
+
import unittest
|
|
7
|
+
from contextlib import redirect_stdout
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
ROOT = Path(__file__).resolve().parent.parent
|
|
11
|
+
sys.path.insert(0, str(ROOT / "src"))
|
|
12
|
+
|
|
13
|
+
from ceexp import cli # noqa: E402
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TestCLI(unittest.TestCase):
|
|
17
|
+
def test_certify_copeland_erdos_engel(self) -> None:
|
|
18
|
+
buf = io.StringIO()
|
|
19
|
+
with redirect_stdout(buf):
|
|
20
|
+
rc = cli.main(
|
|
21
|
+
["certify", "--expansion", "engel", "--digits", "1000", "--limit", "6"]
|
|
22
|
+
)
|
|
23
|
+
self.assertEqual(rc, 0)
|
|
24
|
+
out = buf.getvalue()
|
|
25
|
+
self.assertIn("5, 6, 15, 15, 20, 360", out)
|
|
26
|
+
|
|
27
|
+
def test_certify_custom_digits_file(self) -> None:
|
|
28
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
29
|
+
p = Path(tmp) / "custom.txt"
|
|
30
|
+
# 2/5 = 0.4000... -> Luroth [3, 3, 3, ...]
|
|
31
|
+
p.write_text("0.4" + "0" * 199 + "\n", encoding="utf-8")
|
|
32
|
+
buf = io.StringIO()
|
|
33
|
+
with redirect_stdout(buf):
|
|
34
|
+
rc = cli.main(
|
|
35
|
+
[
|
|
36
|
+
"certify",
|
|
37
|
+
"--expansion",
|
|
38
|
+
"luroth",
|
|
39
|
+
"--digits-file",
|
|
40
|
+
str(p),
|
|
41
|
+
"--digits",
|
|
42
|
+
"200",
|
|
43
|
+
"--limit",
|
|
44
|
+
"5",
|
|
45
|
+
]
|
|
46
|
+
)
|
|
47
|
+
self.assertEqual(rc, 0)
|
|
48
|
+
self.assertIn("3, 3, 3, 3, 3", buf.getvalue())
|
|
49
|
+
|
|
50
|
+
def test_order_subcommand(self) -> None:
|
|
51
|
+
buf = io.StringIO()
|
|
52
|
+
with redirect_stdout(buf):
|
|
53
|
+
rc = cli.main(["order", "10", "100000000000031"])
|
|
54
|
+
self.assertEqual(rc, 0)
|
|
55
|
+
self.assertIn("ord_100000000000031(10) = 50000000000015", buf.getvalue())
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if __name__ == "__main__":
|
|
59
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|