{"record":{"id":"1b80fd090007c9d6","repo":"TheAlgorithms/Python","slug":"the-final-value-of-x-must-be-greater-than-the-init","errorCode":null,"errorMessage":"The final value of x must be greater than the initial values of x.","messagePattern":"The final value of x must be greater than the initial values of x\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/numerical_analysis/adams_bashforth.py","lineNumber":54,"sourceCode":"    Traceback (most recent call last):\n        ...\n    ValueError: x-values must be equally spaced according to step size.\n\n    >>> AdamsBashforth(f,[0,0.2,0.4,0.6,0.8],[0,0,0.04,0.128,0.307],-0.2,1).step_5()\n    Traceback (most recent call last):\n        ...\n    ValueError: Step size must be positive.\n    \"\"\"\n\n    func: Callable[[float, float], float]\n    x_initials: list[float]\n    y_initials: list[float]\n    step_size: float\n    x_final: float\n\n    def __post_init__(self) -> None:\n        if self.x_initials[-1] >= self.x_final:\n            raise ValueError(\n                \"The final value of x must be greater than the initial values of x.\"\n            )\n\n        if self.step_size <= 0:\n            raise ValueError(\"Step size must be positive.\")\n\n        if not all(\n            round(x1 - x0, 10) == self.step_size\n            for x0, x1 in zip(self.x_initials, self.x_initials[1:])\n        ):\n            raise ValueError(\"x-values must be equally spaced according to step size.\")\n\n    def step_2(self) -> np.ndarray:\n        \"\"\"\n        >>> def f(x, y):\n        ...     return x\n        >>> AdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 1).step_2()\n        array([0.  , 0.  , 0.06, 0.16, 0.3 , 0.48])","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/numerical_analysis/adams_bashforth.py#L36-L72","documentation":"Raised by the AdamsBashforth dataclass __post_init__ in maths/numerical_analysis/adams_bashforth.py when the last initial x value is >= x_final. Adams-Bashforth is a multistep ODE solver that marches forward from the initial points to x_final; if the integration endpoint is not strictly beyond the last initial condition, there is nothing to integrate and the constructor rejects it.","triggerScenarios":"AdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 0.2) (x_final equals the last initial x), or any x_final <= x_initials[-1], or accidentally swapping the x_final and step_size arguments.","commonSituations":"Off-by-one in choosing the integration interval, reusing an example's x_final with different initial points, or argument-order confusion since both x_final and step_size are floats.","solutions":["Ensure x_final > x_initials[-1], e.g. x_final = 1 with initials [0, 0.2].","Check keyword-arg usage: AdamsBashforth(func=f, x_initials=..., y_initials=..., step_size=..., x_final=...) to avoid positional mix-ups.","Derive x_final from the initial grid plus n*step_size so ordering is guaranteed."],"exampleFix":"# before\nAdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 0.2)  # nothing to integrate\n\n# after\nAdamsBashforth(f, [0, 0.2], [0, 0], 0.2, 1.0)","handlingStrategy":"validation","validationCode":"if x_final <= x_initials[-1]:\n    raise ValueError(f'x_final ({x_final}) must exceed last initial x ({x_initials[-1]})')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass solver parameters by keyword to avoid positional swaps.","Derive x_final as x_initials[-1] + n * step_size with n >= 1."],"tags":["math","numerical-analysis","ode","valueerror","parameter-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}