# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
"""Use ABM43 on a smooth, repeatedly evaluated rate function."""

from math import cos, sin
from pathlib import Path
import sys

sys.path.insert(0,str(Path(__file__).resolve().parents[1]/"reference"))
from adams_bashforth_moulton_4 import integrate

calls = 0


def f(t,y):
    global calls
    calls += 1
    return (cos(t)+sin(t)-y[0],)


for t,y,e in integrate(f,0,(0,),0.025,80):
    pass
print(f"At t={t:.0f}, measured error against sin(t): {abs(y[0]-sin(t)):.3e}")
print(f"Total RHS calls: {calls} (RK4 throughout would use 320)")
print(f"Last signed local estimate: {e[0]:.3e}")
