ceexp 0.3.3__tar.gz → 0.3.5__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 (28) hide show
  1. {ceexp-0.3.3/src/ceexp.egg-info → ceexp-0.3.5}/PKG-INFO +30 -6
  2. {ceexp-0.3.3 → ceexp-0.3.5}/README.md +27 -5
  3. {ceexp-0.3.3 → ceexp-0.3.5}/pyproject.toml +3 -1
  4. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp/__init__.py +1 -1
  5. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp/benchmark.py +39 -20
  6. ceexp-0.3.5/src/ceexp/cli.py +124 -0
  7. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp/constant.py +5 -1
  8. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp/residue.py +6 -0
  9. {ceexp-0.3.3 → ceexp-0.3.5/src/ceexp.egg-info}/PKG-INFO +30 -6
  10. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp.egg-info/SOURCES.txt +2 -0
  11. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp.egg-info/entry_points.txt +1 -0
  12. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp.egg-info/requires.txt +3 -0
  13. ceexp-0.3.5/tests/test_cli.py +71 -0
  14. {ceexp-0.3.3 → ceexp-0.3.5}/tests/test_properties.py +18 -1
  15. {ceexp-0.3.3 → ceexp-0.3.5}/LICENSE +0 -0
  16. {ceexp-0.3.3 → ceexp-0.3.5}/LICENSE-docs.md +0 -0
  17. {ceexp-0.3.3 → ceexp-0.3.5}/setup.cfg +0 -0
  18. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp/expansions.py +0 -0
  19. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp/series.py +0 -0
  20. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp/verify.py +0 -0
  21. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp.egg-info/dependency_links.txt +0 -0
  22. {ceexp-0.3.3 → ceexp-0.3.5}/src/ceexp.egg-info/top_level.txt +0 -0
  23. {ceexp-0.3.3 → ceexp-0.3.5}/tests/test_benchmark.py +0 -0
  24. {ceexp-0.3.3 → ceexp-0.3.5}/tests/test_champernowne_comparison.py +0 -0
  25. {ceexp-0.3.3 → ceexp-0.3.5}/tests/test_expansions.py +0 -0
  26. {ceexp-0.3.3 → ceexp-0.3.5}/tests/test_reference.py +0 -0
  27. {ceexp-0.3.3 → ceexp-0.3.5}/tests/test_theorems.py +0 -0
  28. {ceexp-0.3.3 → ceexp-0.3.5}/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
3
+ Version: 0.3.5
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
+ [![CI](https://github.com/Nicolas11Leon/copeland-erdos-expansions/actions/workflows/ci.yml/badge.svg)](https://github.com/Nicolas11Leon/copeland-erdos-expansions/actions/workflows/ci.yml)
27
+ [![PyPI](https://img.shields.io/pypi/v/ceexp.svg)](https://pypi.org/project/ceexp/)
28
+ [![Python](https://img.shields.io/pypi/pyversions/ceexp.svg)](https://pypi.org/project/ceexp/)
29
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
24
30
  [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24693622.svg)](https://doi.org/10.5281/zenodo.24693622)
25
31
 
26
- Certified computations, proofs and reproducible experiments on integer sequences derived from the
27
- **Copeland–Erdős constant** `C = 0.235711131719232931374143…`, the number obtained by writing the
28
- primes one after another in base 10 (OEIS [A033308](https://oeis.org/A033308)).
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 · **Status:** pre-publication (v0.2.0) · **Code:** MIT · **Text and data:** CC BY 4.0
37
+ **Author:** Nicolás León Parra · **Version:** v0.3.5 · **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
+ [![CI](https://github.com/Nicolas11Leon/copeland-erdos-expansions/actions/workflows/ci.yml/badge.svg)](https://github.com/Nicolas11Leon/copeland-erdos-expansions/actions/workflows/ci.yml)
4
+ [![PyPI](https://img.shields.io/pypi/v/ceexp.svg)](https://pypi.org/project/ceexp/)
5
+ [![Python](https://img.shields.io/pypi/pyversions/ceexp.svg)](https://pypi.org/project/ceexp/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
3
7
  [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24693622.svg)](https://doi.org/10.5281/zenodo.24693622)
4
8
 
5
- Certified computations, proofs and reproducible experiments on integer sequences derived from the
6
- **Copeland–Erdős constant** `C = 0.235711131719232931374143…`, the number obtained by writing the
7
- primes one after another in base 10 (OEIS [A033308](https://oeis.org/A033308)).
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 · **Status:** pre-publication (v0.2.0) · **Code:** MIT · **Text and data:** CC BY 4.0
14
+ **Author:** Nicolás León Parra · **Version:** v0.3.5 · **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.3"
7
+ version = "0.3.5"
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"]
@@ -13,4 +13,4 @@ from .series import (BLOCK_RULES, CARRY_MODES, blocks, blockwise_series, nico_le
13
13
  try:
14
14
  __version__ = _pkg_version("ceexp")
15
15
  except PackageNotFoundError: # pragma: no cover - editable / uninstalled checkout
16
- __version__ = "0.3.3"
16
+ __version__ = "0.3.5"
@@ -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, object]:
224
+ ) -> dict[str, Any]:
223
225
  """Benchmark uncertified engines against interval-certified ground truth."""
224
226
  constants = build_benchmark_constants(n_digits)
225
- report: dict[str, object] = {
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", lambda: run_float64(digits, mode, max_terms))
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
- lambda p=prec: run_decimal(digits, mode, p, max_terms),
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
- lambda p=prec: run_mpmath(digits, mode, p, max_terms),
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
- lambda d=td: run_uncertified_truncation(
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, object] = {
278
+ entry_mode: dict[str, Any] = {
277
279
  "certified_terms": max_terms,
278
280
  "certified_elapsed_ms": cert_ms,
279
281
  "engines": engines,
@@ -281,26 +283,43 @@ 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
- report["cases"][name] = case_entry
286
+ cases[name] = case_entry
285
287
  return report
286
288
 
287
289
 
288
290
  def main() -> None:
289
- args = [a for a in sys.argv[1:] if a != "--memory"]
290
- measure_memory = "--memory" in sys.argv[1:]
291
- n_digits = int(args[0]) if args else 50_000
291
+ raw_args = list(sys.argv[1:])
292
+ measure_memory = "--memory" in raw_args
293
+ out_override: str | None = None
294
+ pos_args: list[str] = []
295
+ i = 0
296
+ while i < len(raw_args):
297
+ if raw_args[i] == "--memory":
298
+ i += 1
299
+ elif raw_args[i] == "--output" and i + 1 < len(raw_args):
300
+ out_override = raw_args[i + 1]
301
+ i += 2
302
+ else:
303
+ pos_args.append(raw_args[i])
304
+ i += 1
305
+
306
+ n_digits = int(pos_args[0]) if pos_args else 50_000
292
307
  report = run_benchmark(n_digits=n_digits, measure_memory=measure_memory)
293
308
 
294
- repo_root = Path(__file__).resolve().parent.parent.parent
295
- if (repo_root / "pyproject.toml").exists():
296
- out_path = repo_root / "experiments" / "results" / "precision_benchmark.json"
309
+ if out_override is not None:
310
+ out_path = Path(out_override)
297
311
  else:
298
- out_path = Path.cwd() / "precision_benchmark.json"
312
+ repo_root = Path(__file__).resolve().parent.parent.parent
313
+ if (repo_root / "pyproject.toml").exists():
314
+ out_path = repo_root / "experiments" / "results" / "precision_benchmark.json"
315
+ else:
316
+ out_path = Path.cwd() / "precision_benchmark.json"
299
317
  out_path.parent.mkdir(parents=True, exist_ok=True)
300
318
  out_path.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
301
319
 
302
320
  print(
303
- f"Precision-failure benchmark (N={n_digits:,} digits, mpmath={report['mpmath_version']})"
321
+ f"Precision-failure benchmark (N={n_digits:,} digits, "
322
+ f"backend={report['backend']}, mpmath={report['mpmath_version']})"
304
323
  )
305
324
  for name, modes in report["cases"].items():
306
325
  for mode, data in modes.items():
@@ -0,0 +1,124 @@
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
+ p_bench.add_argument("--output", help="Optional path to save the JSON report.")
95
+
96
+ p_ord = sub.add_parser("order", help="Compute multiplicative order of a mod prime p.")
97
+ p_ord.add_argument("a", type=int)
98
+ p_ord.add_argument("p", type=int)
99
+ p_ord.set_defaults(func=_cmd_order)
100
+
101
+ return parser
102
+
103
+
104
+ def main(argv: Sequence[str] | None = None) -> int:
105
+ parser = build_parser()
106
+ args = parser.parse_args(list(argv) if argv is not None else None)
107
+ if args.command == "bench":
108
+ bench_argv = ["ceexp-bench", str(args.n_digits)]
109
+ if args.memory:
110
+ bench_argv.append("--memory")
111
+ if args.output:
112
+ bench_argv.extend(["--output", args.output])
113
+ old_argv = sys.argv
114
+ try:
115
+ sys.argv = bench_argv
116
+ bench_main()
117
+ finally:
118
+ sys.argv = old_argv
119
+ return 0
120
+ return int(args.func(args))
121
+
122
+
123
+ if __name__ == "__main__":
124
+ raise SystemExit(main())
@@ -105,7 +105,11 @@ def first_primes(count: int) -> list[int]:
105
105
 
106
106
 
107
107
  def digits_in_base(n: int, base: int = 10) -> list[int]:
108
- """Digits of n >= 1 in the given base, most significant first."""
108
+ """Digits of n >= 1 in the given base (>= 2), most significant first."""
109
+ if base < 2:
110
+ raise ValueError(f"base must be >= 2, got {base}")
111
+ if n < 1:
112
+ raise ValueError(f"n must be >= 1, got {n}")
109
113
  out = []
110
114
  while n:
111
115
  n, r = divmod(n, base)
@@ -21,6 +21,8 @@ def residues(n_terms: int, base: int = 10) -> tuple[list[int], list[int], list[i
21
21
 
22
22
  def legendre(a: int, p: int) -> int:
23
23
  """Legendre symbol (a/p) for an odd prime p, by Euler's criterion."""
24
+ if p < 3 or p % 2 == 0 or not _is_prime_mr(p):
25
+ raise ValueError(f"p must be an odd prime, got {p}")
24
26
  t = pow(a % p, (p - 1) // 2, p)
25
27
  return -1 if t == p - 1 else t
26
28
 
@@ -107,6 +109,10 @@ def _prime_factors(n: int) -> set[int]:
107
109
 
108
110
  def multiplicative_order(a: int, p: int) -> int:
109
111
  """Order of a modulo the prime p (a not divisible by p), using Pollard's rho."""
112
+ if p < 2 or not _is_prime_mr(p):
113
+ raise ValueError(f"p must be prime, got {p}")
114
+ if a % p == 0:
115
+ raise ValueError(f"a={a} is divisible by p={p}")
110
116
  m = p - 1
111
117
  for f in _prime_factors(m):
112
118
  while m % f == 0 and pow(a, m // f, p) == 1:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ceexp
3
- Version: 0.3.3
3
+ Version: 0.3.5
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
+ [![CI](https://github.com/Nicolas11Leon/copeland-erdos-expansions/actions/workflows/ci.yml/badge.svg)](https://github.com/Nicolas11Leon/copeland-erdos-expansions/actions/workflows/ci.yml)
27
+ [![PyPI](https://img.shields.io/pypi/v/ceexp.svg)](https://pypi.org/project/ceexp/)
28
+ [![Python](https://img.shields.io/pypi/pyversions/ceexp.svg)](https://pypi.org/project/ceexp/)
29
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
24
30
  [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24693622.svg)](https://doi.org/10.5281/zenodo.24693622)
25
31
 
26
- Certified computations, proofs and reproducible experiments on integer sequences derived from the
27
- **Copeland–Erdős constant** `C = 0.235711131719232931374143…`, the number obtained by writing the
28
- primes one after another in base 10 (OEIS [A033308](https://oeis.org/A033308)).
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 · **Status:** pre-publication (v0.2.0) · **Code:** MIT · **Text and data:** CC BY 4.0
37
+ **Author:** Nicolás León Parra · **Version:** v0.3.5 · **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
@@ -1,2 +1,3 @@
1
1
  [console_scripts]
2
+ ceexp = ceexp.cli:main
2
3
  ceexp-bench = ceexp.benchmark:main
@@ -5,3 +5,6 @@ mpmath>=1.2
5
5
  [experiments]
6
6
  numpy>=1.26
7
7
  scipy>=1.11
8
+
9
+ [fast]
10
+ gmpy2>=2.1
@@ -0,0 +1,71 @@
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
+ def test_bench_subcommand_with_memory_flag(self) -> None:
58
+ with tempfile.TemporaryDirectory() as tmp:
59
+ out_json = Path(tmp) / "bench.json"
60
+ buf = io.StringIO()
61
+ with redirect_stdout(buf):
62
+ rc = cli.main(["bench", "1000", "--memory", "--output", str(out_json)])
63
+ self.assertEqual(rc, 0)
64
+ self.assertTrue(out_json.exists())
65
+ out = buf.getvalue()
66
+ self.assertIn("backend=", out)
67
+ self.assertIn("KB)", out)
68
+
69
+
70
+ if __name__ == "__main__":
71
+ unittest.main()
@@ -98,13 +98,30 @@ class TestProperties(unittest.TestCase):
98
98
  self.assertAlmostEqual(float(term.u_exact), term.u, places=8)
99
99
 
100
100
  def test_multiplicative_order_large_primes_exact_minimality(self) -> None:
101
- for p in (1_000_000_000_039, 100_000_000_000_031):
101
+ # 60_013_200_343 - 1 = 2 * 3 * 100003 * 100019 (forces Pollard's rho split).
102
+ for p in (60_013_200_343, 1_000_000_000_039, 100_000_000_000_031):
102
103
  ord_10 = ceexp.multiplicative_order(10, p)
103
104
  self.assertEqual((p - 1) % ord_10, 0)
104
105
  self.assertEqual(pow(10, ord_10, p), 1)
105
106
  for q in _prime_factors(ord_10):
106
107
  self.assertNotEqual(pow(10, ord_10 // q, p), 1)
107
108
 
109
+ def test_input_validation_rejects_invalid_domains(self) -> None:
110
+ with self.assertRaises(ValueError):
111
+ ceexp.digits_in_base(5, base=1)
112
+ with self.assertRaises(ValueError):
113
+ ceexp.digits_in_base(0, base=10)
114
+ with self.assertRaises(ValueError):
115
+ ceexp.prime_blockwise_series(5, base=1)
116
+ with self.assertRaises(ValueError):
117
+ ceexp.multiplicative_order(10, 10)
118
+ with self.assertRaises(ValueError):
119
+ ceexp.multiplicative_order(2, 15)
120
+ with self.assertRaises(ValueError):
121
+ ceexp.legendre(10, 2)
122
+ with self.assertRaises(ValueError):
123
+ ceexp.legendre(10, 15)
124
+
108
125
 
109
126
  if __name__ == "__main__":
110
127
  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