// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Incoprea
// Estimate slope by symmetric samples
// Not compiled or tested in-world
// Setup: Place in a spare owned prim. Set X and positive H for the supplied cubic function. Touch to run; output is private to the owner.
// Stop / restore: Disable/remove. No scene changes or external calls.
// Notes: An extremely small step amplifies rounding error; a large step adds approximation error.
// License: see LICENSE in this distribution.
// Original Incoprea. MIT.
float X=2.0;
float H=0.01;
float f(float x)
{
    return x*x*x-2.0*x;
}
default
{
    touch_start(integer detectedCount)
    {
        if(llDetectedKey(0)!=llGetOwner())return;
        if(H<=0.0)
        {
            llOwnerSay("Positive step required.");
            return;
        }
        float slope=(f(X+H)-f(X-H))/(2.0*H);
        llOwnerSay("Approximate slope="+(string)slope+" exact="+(string)(3.0*X*X-2.0));
    }
}
