156 lines
12 KiB
Python
156 lines
12 KiB
Python
"""The frame of article/sim_numerics.md brought to the method it now proposes (A', Section 8):
|
||
abstract, introduction, a note in Section 3, the close of 7.4, new negative results 12-16,
|
||
conclusion, future work, references 8-12. Whole paragraphs are replaced by their unique
|
||
opening words; insertions go after a unique anchor. Nothing is written unless every anchor
|
||
matches exactly once.
|
||
|
||
python -u apply_article_frame.py
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
PATH = "article/sim_numerics.md"
|
||
|
||
ABSTRACT_2 = (
|
||
"The derivation fixes a *base rule* before any benchmark is consulted: a similarity whose "
|
||
"approach to 1 is linear, the finest available data-derived scale, and a safeguard that "
|
||
"projects the step onto the admissible interval rather than replacing it. It is, explicitly, a "
|
||
"Newton step with a three-point divided-difference derivative, clipped to the bracket and "
|
||
"projected onto the bisection budget; the similarity function is scaffolding of the derivation "
|
||
"and does not appear in the final rule. It carries a proven worst case of twice bisection plus "
|
||
"one step and exactly one free constant, which we declare rather than argue away: the "
|
||
"multiplier of that budget. On the 154 problems of Alefeld, Potra and Shi it needs 2806 "
|
||
"evaluations of $f$ against 2820 for TOMS 748, 2889 for Brent and 2787 for Chandrupatla's "
|
||
"method — level in total — and beats Chandrupatla problem by problem 87 to 42 (exact sign test "
|
||
"$p=9\\cdot10^{-5}$). On the 45 wide-bracket problems of Chandrupatla it beats Brent and TOMS 748 "
|
||
"and loses to ITP and to Chandrupatla (3220 against 2896 and 2441). For every data-derived "
|
||
"scale, the ranking of the nine similarity functions matches the derived law without exception."
|
||
)
|
||
|
||
ABSTRACT_3 = (
|
||
"The wide-bracket gap turns out to be not the order of the model but a decision — when to give "
|
||
"the model up — and the decision is a similarity after all, of an unfamiliar kind: the similarity "
|
||
"of a run to its own past. A pure power is self-similar under zoom, so the dimensionless "
|
||
"configuration of the last three points recurs, while at a simple root it tends to the linear "
|
||
"prototype; the analogous pair yields the local order, $m=\\ln L_f/\\ln L_x$, and an exponential, "
|
||
"self-similar by translation, is its limit $m=\\infty$. Entering a halving regime when that "
|
||
"analogy holds with $m\\ge2$ — the condition under which a tangent step loses to a halving — "
|
||
"splitting at the point the order predicts, and leaving when the split looks linear, together "
|
||
"with four smaller readings of the same kind and one borrowed element, gives the method proposed "
|
||
"here, A′. On the two sets it needs 2438 and 2005 evaluations against Chandrupatla's 2787 and "
|
||
"2441 and beats him problem by problem on both, 103 to 30 and 29 to 7. The chain of decisions "
|
||
"that produced it was selected on those sets; tested once, after its code was frozen, on 240 "
|
||
"problems from six new families, it needs 3656 evaluations against Chandrupatla's 5717 and wins "
|
||
"177 problems to 28. 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; against "
|
||
"Chandrupatla it is ahead in total on five corpora and level on the sixth. The lead is large on "
|
||
"multiple, fractional and nearly flat roots and a matter of per cent on simple ones."
|
||
)
|
||
|
||
INTRO_ADD = (
|
||
"\n\nThe paper proceeds in two stages. Sections 2–7 derive a base rule from the similarity alone, "
|
||
"measure it, and locate what it lacks: not a better model but a decision, when to stop trusting "
|
||
"the model it has. Section 8 supplies that decision with a similarity of the run to its own "
|
||
"past, and Section 9 tests the resulting method on four corpora it was not developed on, one of "
|
||
"them fixed after the method's code was frozen."
|
||
)
|
||
|
||
SEC3_ADD = (
|
||
" We call it the **base rule**; the method this paper proposes builds on it in Section 8."
|
||
)
|
||
|
||
SEC74_ADD = (
|
||
" Section 8 shows that the decision is reachable without a new model: by a similarity of the "
|
||
"run to its own past."
|
||
)
|
||
|
||
NEG_ADD = """
|
||
|
||
12. **Reading the unkept promise one step at a time does not pay.** The flag of §8.1 sees the flat regime, but a halving in place of each flagged step takes the canonical set from 2806 to 3029 and the wide-bracket set only from 3220 to 3198: a simple root far from convergence breaks its promises too. Requiring the promise to fail twice in a row keeps the canonical set (2803) but fires one step late, before the crossing, and replaces the most useful step of the cycle (wide brackets 3341); requiring a creep in one direction as well gives 2878 and 3354.
|
||
|
||
13. **A halving that sticks once begun wins the flat families and loses everything else.** Without an exit the flat families fall to 1057 — pure bisection's level — and the canonical set rises to 6897, because a false entry now lasts to the end of the run. Splitting at the order read from the failed promise, $(1-1/m)^m=r$, changes nothing: that order is $m=\\infty$ in 163 of 174 entries (6781).
|
||
|
||
14. **The model's own point cannot tell a flat root from a simple one.** Judging the evaluated point against the line through the bracket ends and against 0 — the exit judgment of §8.2 — also at *entry* gives 3009 and 2486 against 3125 and 2503 for the exit alone: the model aims at the root, so $f$ is small there by construction and looks flat at a simple root as readily as at a power. The same judgment works at a split, which the model did not choose.
|
||
|
||
15. **The decision reading "defect" does not transfer.** Combined with the regime it was the best configuration on the two development sets (§7.2's canonical record 2523 with the flat families of §8), and it passed every pre-registered criterion there. On new corpus 1 it did not: per problem 95/33/78 against Chandrupatla ($p=0.22$), losing the class of exponential flanks 9 to 26. It is therefore not part of A′.
|
||
|
||
16. **A component rejected alone can pay in combination.** Remembering the analogy for the run was rejected by its own pre-registration (canonical set 2814 against 2806 without the regime), and with the split of §8.3 it is the better form (with the step pattern, wide brackets 2117 against 2221 for the analogy read in one state). Composition was measured, not assumed, throughout — which is also why §7's readings (2) and (3), each an improvement, are not combined."""
|
||
|
||
CONCL_2 = (
|
||
"The base rule has one declared constant and carries a worst case of twice bisection plus one "
|
||
"step. On the canonical Alefeld–Potra–Shi set it is level with TOMS 748 and with Chandrupatla's "
|
||
"method in total and ahead of both problem by problem; on the wide-bracket set Chandrupatla is "
|
||
"genuinely stronger (2441 against 3220). §7.4 locates the cause: not the order of the model but "
|
||
"the decision to give it up, which Chandrupatla takes by halving and which no reading of a single "
|
||
"state takes correctly for our step.\n\n"
|
||
"That decision is a similarity too — of the run to its own past. A pure power repeats its "
|
||
"configuration under zoom, an exponential under translation, a simple root tends to the line; "
|
||
"the analogous pair reads the local order, the order decides between the model and a halving by "
|
||
"bisection's own $\\tfrac12$, and it says where to split. The method built on it, A′, is ahead of "
|
||
"Chandrupatla on both canonical sets in total and problem by problem, and on a corpus fixed after "
|
||
"its code was frozen it needs 36% fewer evaluations and wins 177 problems to 28. The claim the "
|
||
"measurements support is a lead over Brent and TOMS 748 everywhere, with the guarantee they do "
|
||
"not keep, and over Chandrupatla a lead that is large where roots are multiple, fractional or "
|
||
"nearly flat and small where they are simple — not superiority by the same margin everywhere. "
|
||
"`fun9`, near-cancelling terms and smooth applied equations are where it is behind or level."
|
||
)
|
||
|
||
FUTURE = (
|
||
"Three questions remain, all narrower than the one this section used to pose.\n\n"
|
||
"The first is the steep flank. Where the loss remains — `fun9`, the near-cancelling class, "
|
||
"4 − tan x at its pole — the base step approaches along a flank far steeper than its model, and "
|
||
"the half contradiction of §8.4 removes only part of the cost. The second is the one geometric "
|
||
"choice of §8.2, the Euclidean metric of the $(\\xi,\\varphi)$ plane: a metric derived from the "
|
||
"configuration's own sensitivity would remove it. 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."
|
||
)
|
||
|
||
REFS = """
|
||
8. G. Pólya, *How to Solve It*. Princeton, NJ: Princeton University Press, 1945.
|
||
9. T. J. Dekker, "Finding a zero by means of successive linear interpolation," in B. Dejon and P. Henrici (eds.), *Constructive Aspects of the Fundamental Theorem of Algebra*. London: Wiley-Interscience, 1969, pp. 37–51.
|
||
10. N. Ganchovski and A. Traykov, "Modified Anderson-Björck's method for solving non-linear equations in structural mechanics," *IOP Conf. Ser.: Mater. Sci. Eng.*, vol. 1276, 012010, 2023.
|
||
11. M. Galassi et al., *GNU Scientific Library Reference Manual*, 3rd ed. Network Theory, 2009; root-finding test suite `roots/test.c`.
|
||
12. J. Verzani et al., *Roots.jl*, Julia package; bracketing benchmark `test/benchmark-bracketing-methods.jl`, commit cf1d256, 2026."""
|
||
|
||
|
||
def replace_paragraph(text, opening, new):
|
||
lines = text.split("\n")
|
||
idx = [i for i, ln in enumerate(lines) if ln.startswith(opening)]
|
||
if len(idx) != 1:
|
||
raise SystemExit(f"paragraph opening found {len(idx)}x: {opening[:60]}")
|
||
lines[idx[0]] = new
|
||
return "\n".join(lines)
|
||
|
||
|
||
def insert_after(text, anchor, add):
|
||
if text.count(anchor) != 1:
|
||
raise SystemExit(f"anchor found {text.count(anchor)}x: {anchor[:60]}")
|
||
return text.replace(anchor, anchor + add)
|
||
|
||
|
||
def main():
|
||
with open(PATH, encoding="utf8") as fh:
|
||
text = fh.read()
|
||
text = replace_paragraph(text, "The derivation fixes the method before any benchmark is consulted:",
|
||
ABSTRACT_2)
|
||
text = replace_paragraph(text, "Reading the same similarity in one more place — which three points",
|
||
ABSTRACT_3)
|
||
text = insert_after(text, "The answer is sharp in both directions, and the negative half is as "
|
||
"informative as the positive half.", INTRO_ADD)
|
||
text = insert_after(text, "(iii) the negative results of §10; (iv) the measurements.", SEC3_ADD)
|
||
text = insert_after(text, "which is inverse quadratic interpolation — a different method rather "
|
||
"than another reading of this one.", SEC74_ADD)
|
||
text = insert_after(text, "on the flat families the right move is to halve, not to march.", NEG_ADD)
|
||
text = replace_paragraph(text, "The resulting rule has one declared constant", CONCL_2)
|
||
text = replace_paragraph(text, "The diagnosis of §7.4 leaves one question", FUTURE)
|
||
text = replace_paragraph(text, "What is open is a decision, not a model.", "")
|
||
text = insert_after(text, "*BIT*, vol. 11, pp. 168–174, 1971.", REFS)
|
||
with open(PATH, "w", encoding="utf8") as fh:
|
||
fh.write(text)
|
||
print("frame updated")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|