"""Find slopes matching a secant of f(x) = x³ − 3x."""
import argparse
import math


def matches(a, b):
    # Factoring the cubic difference gives the secant slope without cancellation.
    secant = a * a + a * b + b * b - 3
    root = math.sqrt((secant + 3) / 3)
    return secant, [x for x in (-root, root) if a < x < b]


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("a", type=int)
    parser.add_argument("b", type=int)
    args = parser.parse_args()
    if not -6 <= args.a < args.b <= 6:
        parser.error("Use ordered integer endpoints between -6 and 6.")
    slope, points = matches(args.a, args.b)
    print(f"Secant slope: {slope:.6f}")
    for point in points:
        print(f"Matching x: {point:.6f}")


if __name__ == "__main__":
    main()
