Files
sim-numerics/apply_article_modab.py

104 lines
6.6 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""ModAB in article/sim_numerics.md (PREREG_modab outcome, sweep_modab.json): Table 8 and
Table 10 rows, the protocol note, the evidence paragraph of section 9, the precursor of the
exit judgment in 8.6, the abstract, the conclusion, future work, the introduction and
reference 20. Exact anchors, each found exactly once, or nothing is written.
python -u apply_article_modab.py
"""
from __future__ import annotations
PATH = "article/sim_numerics.md"
REPL = [
# introduction
("an interpolate–truncate–project cycle in ITP [4].",
"an interpolate–truncate–project cycle in ITP [4], an Anderson–Björck step behind a linearity "
"check in ModAB [10, 20]."),
# Table 8
("| ITP, per-problem oracle | 3260 | 2647 | 5907 | A′ 126/7/20 | A′ 35/1/4 |",
"| ITP, per-problem oracle | 3260 | 2647 | 5907 | A′ 126/7/20 | A′ 35/1/4 |\n"
"| ModAB [10, 20] | 2914 | 2436 | 5350 | A′ 118/11/25 | A′ 32/9/4 |"),
# section 9: how ModAB is run
("Where roots are not known in closed form, and for uniformity on all six corpora,",
"ModAB, the most recent bracketing method we know of, is run from its authors' package "
"(`pymodab` 1.0.9, a wrapper of their C code) with the stopping rule of every other method — a "
"bracket no wider than $\\varepsilon_x$, the relative term at machine precision, no stopping on "
"$|f|$ — and counted by the same wrapper around $f$, whose count agrees with the package's own. "
"Where roots are not known in closed form, and for uniformity on all six corpora,"),
# Table 10
("| corpus | A′ | Chandrupatla | Brent | TOMS 748 | A′ vs Chandrupatla |\n|---|---|---|---|---|---|",
"| corpus | A′ | Chandrupatla | ModAB | Brent | TOMS 748 | A′ vs Chandrupatla | A′ vs ModAB |\n"
"|---|---|---|---|---|---|---|---|"),
("| APS (154) | **2259** (0) | 2595 (0) | 2707 (0) | 2636 (0) | 103/20/31, $p=3\\cdot10^{-10}$ |",
"| APS (154) | **2259** (0) | 2595 (0) | 2726 (0) | 2707 (0) | 2636 (0) | 103/20/31, $p=3\\cdot10^{-10}$ | 118/10/26 |"),
("| Chandrupatla (45) | **1074** (0) | 1505 (0) | 3238 (18) | 3088 (15) | 31/4/10, $p=0.001$ |",
"| Chandrupatla (45) | **1074** (0) | 1505 (0) | 1681 (0) | 3238 (18) | 3088 (15) | 31/4/10, $p=0.001$ | 34/4/7 |"),
("| new corpus 1 (206) | **3290** (0) | 3716 (0) | 6395 (38) | 5746 (22) | 108/33/65, $p=0.001$ |",
"| new corpus 1 (206) | **3290** (0) | 3716 (0) | 3809 (1) | 6395 (38) | 5746 (22) | 108/33/65, $p=0.001$ | 125/26/55 |"),
("| Roots.jl (78) | **1371** (0) | 1566 (0) | 2455 (11) | 2339 (9) | 44/14/20, $p=0.004$ |",
"| Roots.jl (78) | **1371** (0) | 1566 (0) | 1446 (0) | 2455 (11) | 2339 (9) | 44/14/20, $p=0.004$ | 47/11/20 |"),
("| applied + GSL (132) | 1382 (0) | 1382 (0) | 1503 (1) | 1756 (1) | 48/52/32, $p=0.09$ |",
"| applied + GSL (132) | 1382 (0) | 1382 (0) | 1460 (0) | 1503 (1) | 1756 (1) | 48/52/32, $p=0.09$ | 76/35/21 |"),
("| **corpus 4 (240), the one test** | **3656** (0) | 5717 (0) | 8267 (50) | 8084 (37) | **177/35/28, $p=10^{-27}$** |",
"| **corpus 4 (240), the one test** | **3656** (0) | 5717 (0) | 5535 (8) | 8267 (50) | 8084 (37) | **177/35/28, $p=10^{-27}$** | **183/23/34** |"),
("| all 855 | **13032** | 16481 | 24565 | 23649 | |",
"| all 855 | **13032** | 16481 | 16657 | 24565 | 23649 | | |"),
# the evidence paragraph
("**What the evidence supports, and what it does not.** Against Brent and TOMS 748 A′ is ahead on "
"every corpus, by 8% to 67% in total, and it keeps its bound on all 855 problems, which Brent breaks "
"on 118 and TOMS 748 on 84.",
"**What the evidence supports, and what it does not.** Against Brent and TOMS 748 A′ is ahead on "
"every corpus, by 8% to 67% in total, and it keeps its bound on all 855 problems, which Brent breaks "
"on 118 and TOMS 748 on 84. Against ModAB it is ahead on every corpus, in total and problem by "
"problem ($p\\le0.0013$), on the one test of corpus 4 by 3656 to 5535 and 183 problems to 34 "
"($p=7\\cdot10^{-26}$), and on ModAB's own benchmark as well — all 91 problems of it, 1507 against "
"1588, 56/13/22 ($p=1.5\\cdot10^{-4}$); ModAB breaks the bound on 9 problems."),
# 8.6 table: the exit judgment's precursor
("| the tolerance step | Dekker [9], Brent [2] — borrowed and named as such |",
"| the tolerance step | Dekker [9], Brent [2] — borrowed and named as such |\n"
"| the exit judgment of §8.2 (the value at a split against the line) | ModAB's linearity check at "
"the midpoint [10, 20], $|y_m-y_3|<k\\,(|y_3|+|y_m|)$ with $k$ from a symmetry factor; ours compares "
"two predictions, the line and 0, without a factor |"),
# abstract
("Over 855 problems in six corpora it is ahead of Brent and TOMS 748 everywhere and keeps its bound "
"where they break theirs on 118 and 84 problems;",
"Over 855 problems in six corpora it is ahead of Brent, TOMS 748 and the recent ModAB everywhere "
"and keeps its bound where they break theirs on 118, 84 and 9 problems;"),
# conclusion
("The claim the measurements support is a lead over Brent and TOMS 748 everywhere, with the "
"guarantee they do not keep,",
"The claim the measurements support is a lead over Brent, TOMS 748 and ModAB everywhere, with the "
"guarantee they do not keep,"),
# future work
("Three questions remain, all narrower than the one this section used to pose.",
"Two questions remain, both narrower than the one this section used to pose."),
(" The third is a comparison this paper does not make: the modified Anderson–Björck method of [10], "
"the most recent bracketing method we know of, is not among the rivals; its own benchmark is corpus "
"2 here, so the comparison is ready to be run under the rule every other one followed — "
"pre-registered, on a corpus not yet seen.",
""),
# reference 20
("*Appl. Math. Comput.*, vol. 190, pp. 686–698, 2007.",
"*Appl. Math. Comput.*, vol. 190, pp. 686–698, 2007.\n"
"20. N. Ganchovski, O. Smith, C. Rackauckas, L. Tomov and A. Traykov, \"Improvements to the "
"Modified Anderson–Björck (modAB) root-finding algorithm,\" *Algorithms*, vol. 19, 332, 2026; "
"package `pymodab` 1.0.9."),
]
def main():
with open(PATH, encoding="utf8") as fh:
text = fh.read()
for old, _new in REPL:
if text.count(old) != 1:
raise SystemExit(f"found {text.count(old)}x: {old[:90]}")
for old, new in REPL:
text = text.replace(old, new)
with open(PATH, "w", encoding="utf8") as fh:
fh.write(text)
print(f"ModAB written ({len(REPL)} edits)")
if __name__ == "__main__":
main()