# /// script
# requires-python = ">=3.11"
# dependencies = []
# ///
"""Print the ABM43 fixed-history cases."""

import json
from math import exp
from pathlib import Path
import sys

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


def build():
    output = {
        "format": 1, "method": "adams-bashforth-moulton-4", "version": "0.1.0",
        "interface": ("step(f,t,y,h,history) returns [corrected y, corrected endpoint slope, signed Milne estimate]. "
                      "history has four slopes at t, t-h, t-2h, t-3h, newest first."),
        "problems": {
            "time-polynomial": "f(t,y)=[5*t^4].",
            "coupled": "f(t,y)=[t-y[0]*y[1],y[0]-y[1]+t^2].",
            "exponential": "f(t,y)=[y[0]].",
        },
        "cases": [],
    }
    inputs = [
        ("time-polynomial",0.7,(0.7**5,),0.13,[(5*(0.7-i*0.13)**4,) for i in range(4)]),
        ("coupled",1.2,(0.31,-0.52),0.17,[(1,-0.1),(0.8,-0.2),(0.5,0.1),(0.1,0.2)]),
        ("exponential",0,(1,),0.24,[(exp(-i*0.24),) for i in range(4)]),
        ("exponential",0,(1,),-0.14,[(exp(i*0.14),) for i in range(4)]),
    ]
    for problem,t,y,h,history in inputs:
        case = {"problem":problem,"t":t,"y":y,"h":h,"history":history,"tol":3e-12}
        case["expected"] = result(step, case)
        output["cases"].append(case)
    return output


if __name__ == "__main__":
    print(json.dumps(build(),indent=2))
