Cubic critical, narrow range

?

Percentage Accurate: 55.2% → 90.9%
Time: 12.8s
Precision: binary64
Cost: 53504

?

\[\left(\left(1.0536712127723509 \cdot 10^{-8} < a \land a < 94906265.62425156\right) \land \left(1.0536712127723509 \cdot 10^{-8} < b \land b < 94906265.62425156\right)\right) \land \left(1.0536712127723509 \cdot 10^{-8} < c \land c < 94906265.62425156\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
\[\begin{array}{l} \\ \mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \mathsf{fma}\left(-0.16666666666666666, \frac{{\left(c \cdot a\right)}^{4} \cdot 6.328125}{a \cdot {b}^{7}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, -0.375 \cdot \frac{a}{\frac{{b}^{3}}{c \cdot c}}\right)\right)\right) \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))
(FPCore (a b c)
 :precision binary64
 (fma
  -0.5625
  (/ (pow c 3.0) (/ (pow b 5.0) (* a a)))
  (fma
   -0.16666666666666666
   (/ (* (pow (* c a) 4.0) 6.328125) (* a (pow b 7.0)))
   (fma -0.5 (/ c b) (* -0.375 (/ a (/ (pow b 3.0) (* c c))))))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((3.0 * a) * c)))) / (3.0 * a);
}
double code(double a, double b, double c) {
	return fma(-0.5625, (pow(c, 3.0) / (pow(b, 5.0) / (a * a))), fma(-0.16666666666666666, ((pow((c * a), 4.0) * 6.328125) / (a * pow(b, 7.0))), fma(-0.5, (c / b), (-0.375 * (a / (pow(b, 3.0) / (c * c)))))));
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(3.0 * a) * c)))) / Float64(3.0 * a))
end
function code(a, b, c)
	return fma(-0.5625, Float64((c ^ 3.0) / Float64((b ^ 5.0) / Float64(a * a))), fma(-0.16666666666666666, Float64(Float64((Float64(c * a) ^ 4.0) * 6.328125) / Float64(a * (b ^ 7.0))), fma(-0.5, Float64(c / b), Float64(-0.375 * Float64(a / Float64((b ^ 3.0) / Float64(c * c)))))))
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(3.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(3.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := N[(-0.5625 * N[(N[Power[c, 3.0], $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.16666666666666666 * N[(N[(N[Power[N[(c * a), $MachinePrecision], 4.0], $MachinePrecision] * 6.328125), $MachinePrecision] / N[(a * N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.5 * N[(c / b), $MachinePrecision] + N[(-0.375 * N[(a / N[(N[Power[b, 3.0], $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}
\begin{array}{l}

\\
\mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \mathsf{fma}\left(-0.16666666666666666, \frac{{\left(c \cdot a\right)}^{4} \cdot 6.328125}{a \cdot {b}^{7}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, -0.375 \cdot \frac{a}{\frac{{b}^{3}}{c \cdot c}}\right)\right)\right)
\end{array}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Herbie found 9 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Bogosity?

Bogosity

Derivation?

  1. Initial program 56.0%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]
  2. Simplified56.1%

    \[\leadsto \color{blue}{\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right) \cdot \frac{0.3333333333333333}{a}} \]
    Step-by-step derivation

    [Start]56.0%

    \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]

    neg-sub0 [=>]56.0%

    \[ \frac{\color{blue}{\left(0 - b\right)} + \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \]

    associate-+l- [=>]56.0%

    \[ \frac{\color{blue}{0 - \left(b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a} \]

    sub0-neg [=>]56.0%

    \[ \frac{\color{blue}{-\left(b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a} \]

    neg-mul-1 [=>]56.0%

    \[ \frac{\color{blue}{-1 \cdot \left(b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right)}}{3 \cdot a} \]

    associate-*r/ [<=]56.0%

    \[ \color{blue}{-1 \cdot \frac{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a}} \]

    *-commutative [=>]56.0%

    \[ \color{blue}{\frac{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot -1} \]

    metadata-eval [<=]56.0%

    \[ \frac{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \color{blue}{\frac{1}{-1}} \]

    metadata-eval [<=]56.0%

    \[ \frac{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{3 \cdot a} \cdot \frac{\color{blue}{--1}}{-1} \]

    times-frac [<=]56.0%

    \[ \color{blue}{\frac{\left(b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \left(--1\right)}{\left(3 \cdot a\right) \cdot -1}} \]

    *-commutative [<=]56.0%

    \[ \frac{\left(b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}\right) \cdot \left(--1\right)}{\color{blue}{-1 \cdot \left(3 \cdot a\right)}} \]

    times-frac [=>]56.0%

    \[ \color{blue}{\frac{b - \sqrt{b \cdot b - \left(3 \cdot a\right) \cdot c}}{-1} \cdot \frac{--1}{3 \cdot a}} \]
  3. Applied egg-rr56.1%

    \[\leadsto \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.3333333333333333}{a}\right)\right)} \]
    Step-by-step derivation

    [Start]56.1%

    \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right) \cdot \frac{0.3333333333333333}{a} \]

    expm1-log1p-u [=>]56.1%

    \[ \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right) \cdot \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.3333333333333333}{a}\right)\right)} \]
  4. Taylor expanded in b around inf 91.2%

    \[\leadsto \color{blue}{-0.5625 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + \left(-0.16666666666666666 \cdot \frac{{\left(-1.125 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 5.0625 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)\right)} \]
  5. Simplified91.2%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \mathsf{fma}\left(-0.16666666666666666, \frac{{\left(c \cdot a\right)}^{4} \cdot 6.328125}{a \cdot {b}^{7}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, -0.375 \cdot \frac{a}{\frac{{b}^{3}}{c \cdot c}}\right)\right)\right)} \]
    Step-by-step derivation

    [Start]91.2%

    \[ -0.5625 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}} + \left(-0.16666666666666666 \cdot \frac{{\left(-1.125 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 5.0625 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)\right) \]

    fma-def [=>]91.2%

    \[ \color{blue}{\mathsf{fma}\left(-0.5625, \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}, -0.16666666666666666 \cdot \frac{{\left(-1.125 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 5.0625 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-0.5 \cdot \frac{c}{b} + -0.375 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)\right)} \]
  6. Final simplification91.2%

    \[\leadsto \mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \mathsf{fma}\left(-0.16666666666666666, \frac{{\left(c \cdot a\right)}^{4} \cdot 6.328125}{a \cdot {b}^{7}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, -0.375 \cdot \frac{a}{\frac{{b}^{3}}{c \cdot c}}\right)\right)\right) \]

Alternatives

Alternative 1
Accuracy90.9%
Cost53504
\[\mathsf{fma}\left(-0.5625, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \mathsf{fma}\left(-0.16666666666666666, \frac{{\left(c \cdot a\right)}^{4} \cdot 6.328125}{a \cdot {b}^{7}}, \mathsf{fma}\left(-0.5, \frac{c}{b}, -0.375 \cdot \frac{a}{\frac{{b}^{3}}{c \cdot c}}\right)\right)\right) \]
Alternative 2
Accuracy89.6%
Cost41028
\[\begin{array}{l} t_0 := \mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)\\ \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -0.8:\\ \;\;\;\;\frac{t_0 - b \cdot b}{b + \sqrt{t_0}} \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\frac{0.3333333333333333}{a}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \frac{c}{b}, a \cdot \left(-0.375 \cdot \left(c \cdot \frac{c}{{b}^{3}}\right) + \frac{-0.5625}{{b}^{5}} \cdot \left({c}^{3} \cdot a\right)\right)\right)\\ \end{array} \]
Alternative 3
Accuracy89.5%
Cost34564
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -0.8:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right) \cdot e^{\log \left(\frac{0.3333333333333333}{a}\right)}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \frac{c}{b}, a \cdot \left(-0.375 \cdot \left(c \cdot \frac{c}{{b}^{3}}\right) + \frac{-0.5625}{{b}^{5}} \cdot \left({c}^{3} \cdot a\right)\right)\right)\\ \end{array} \]
Alternative 4
Accuracy84.9%
Cost21124
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -0.00045:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;\mathsf{fma}\left(-0.5, \frac{c}{b}, \frac{-0.375 \cdot \left(a \cdot \left(c \cdot c\right)\right)}{{b}^{3}}\right)\\ \end{array} \]
Alternative 5
Accuracy75.6%
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -2.7 \cdot 10^{-8}:\\ \;\;\;\;-0.3333333333333333 \cdot \frac{b - \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)}}{a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 6
Accuracy75.6%
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -2.7 \cdot 10^{-8}:\\ \;\;\;\;\frac{0.3333333333333333}{a} \cdot \left(\sqrt{\mathsf{fma}\left(b, b, a \cdot \left(c \cdot -3\right)\right)} - b\right)\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 7
Accuracy75.6%
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -2.7 \cdot 10^{-8}:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -3\right)\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 8
Accuracy75.6%
Cost14788
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(3 \cdot a\right)} - b}{3 \cdot a} \leq -2.7 \cdot 10^{-8}:\\ \;\;\;\;\frac{\sqrt{b \cdot b - 3 \cdot \left(c \cdot a\right)} - b}{3 \cdot a}\\ \mathbf{else}:\\ \;\;\;\;-0.5 \cdot \frac{c}{b}\\ \end{array} \]
Alternative 9
Accuracy64.5%
Cost320
\[-0.5 \cdot \frac{c}{b} \]

Reproduce?

herbie shell --seed 2023167 
(FPCore (a b c)
  :name "Cubic critical, narrow range"
  :precision binary64
  :pre (and (and (and (< 1.0536712127723509e-8 a) (< a 94906265.62425156)) (and (< 1.0536712127723509e-8 b) (< b 94906265.62425156))) (and (< 1.0536712127723509e-8 c) (< c 94906265.62425156)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 3.0 a) c)))) (* 3.0 a)))