Quadratic roots, wide range

?

Percentage Accurate: 17.2% → 97.7%
Time: 8.6s
Precision: binary64
Cost: 53824

?

\[\left(\left(4.930380657631324 \cdot 10^{-32} < a \land a < 2.028240960365167 \cdot 10^{+31}\right) \land \left(4.930380657631324 \cdot 10^{-32} < b \land b < 2.028240960365167 \cdot 10^{+31}\right)\right) \land \left(4.930380657631324 \cdot 10^{-32} < c \land c < 2.028240960365167 \cdot 10^{+31}\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(c \cdot a\right)}^{4}\\ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, t_0, 4 \cdot t_0\right)}{a \cdot {b}^{7}}, \frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \end{array} \end{array} \]
(FPCore (a b c)
 :precision binary64
 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c)
 :precision binary64
 (let* ((t_0 (pow (* c a) 4.0)))
   (-
    (fma
     -0.25
     (/ (fma 16.0 t_0 (* 4.0 t_0)) (* a (pow b 7.0)))
     (- (/ (* (* a (* a -2.0)) (pow c 3.0)) (pow b 5.0)) (/ c b)))
    (/ (* c c) (/ (pow b 3.0) a)))))
double code(double a, double b, double c) {
	return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
double code(double a, double b, double c) {
	double t_0 = pow((c * a), 4.0);
	return fma(-0.25, (fma(16.0, t_0, (4.0 * t_0)) / (a * pow(b, 7.0))), ((((a * (a * -2.0)) * pow(c, 3.0)) / pow(b, 5.0)) - (c / b))) - ((c * c) / (pow(b, 3.0) / a));
}
function code(a, b, c)
	return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a))
end
function code(a, b, c)
	t_0 = Float64(c * a) ^ 4.0
	return Float64(fma(-0.25, Float64(fma(16.0, t_0, Float64(4.0 * t_0)) / Float64(a * (b ^ 7.0))), Float64(Float64(Float64(Float64(a * Float64(a * -2.0)) * (c ^ 3.0)) / (b ^ 5.0)) - Float64(c / b))) - Float64(Float64(c * c) / Float64((b ^ 3.0) / a)))
end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := Block[{t$95$0 = N[Power[N[(c * a), $MachinePrecision], 4.0], $MachinePrecision]}, N[(N[(-0.25 * N[(N[(16.0 * t$95$0 + N[(4.0 * t$95$0), $MachinePrecision]), $MachinePrecision] / N[(a * N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N[(a * N[(a * -2.0), $MachinePrecision]), $MachinePrecision] * N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(c * c), $MachinePrecision] / N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\left(c \cdot a\right)}^{4}\\
\mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, t_0, 4 \cdot t_0\right)}{a \cdot {b}^{7}}, \frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}}
\end{array}
\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 5 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 16.8%

    \[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
  2. Simplified16.9%

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

    [Start]16.8%

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

    /-rgt-identity [<=]16.8%

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

    metadata-eval [<=]16.8%

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

    associate-/l* [<=]16.8%

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

    associate-*r/ [<=]16.8%

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

    +-commutative [=>]16.8%

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

    unsub-neg [=>]16.8%

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

    fma-neg [=>]16.9%

    \[ \left(\sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} - b\right) \cdot \frac{--1}{2 \cdot a} \]

    associate-*l* [=>]16.9%

    \[ \left(\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{4 \cdot \left(a \cdot c\right)}\right)} - b\right) \cdot \frac{--1}{2 \cdot a} \]

    *-commutative [=>]16.9%

    \[ \left(\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{\left(a \cdot c\right) \cdot 4}\right)} - b\right) \cdot \frac{--1}{2 \cdot a} \]

    distribute-rgt-neg-in [=>]16.9%

    \[ \left(\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}\right)} - b\right) \cdot \frac{--1}{2 \cdot a} \]

    metadata-eval [=>]16.9%

    \[ \left(\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot \color{blue}{-4}\right)} - b\right) \cdot \frac{--1}{2 \cdot a} \]

    associate-/r* [=>]16.9%

    \[ \left(\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - b\right) \cdot \color{blue}{\frac{\frac{--1}{2}}{a}} \]

    metadata-eval [=>]16.9%

    \[ \left(\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - b\right) \cdot \frac{\frac{\color{blue}{1}}{2}}{a} \]

    metadata-eval [=>]16.9%

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

    \[\leadsto \color{blue}{-1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)} \]
  4. Simplified98.3%

    \[\leadsto \color{blue}{\mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {c}^{4} \cdot {a}^{4}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}}} \]
    Step-by-step derivation

    [Start]98.3%

    \[ -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right) \]

    +-commutative [=>]98.3%

    \[ \color{blue}{\left(-0.25 \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{a \cdot {b}^{7}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right) + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}} \]
  5. Applied egg-rr98.3%

    \[\leadsto \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, \color{blue}{{\left({\left(c \cdot a\right)}^{4}\right)}^{1}}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
    Step-by-step derivation

    [Start]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {c}^{4} \cdot {a}^{4}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]

    pow1 [=>]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, \color{blue}{{\left({c}^{4} \cdot {a}^{4}\right)}^{1}}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]

    pow-prod-down [=>]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {\color{blue}{\left({\left(c \cdot a\right)}^{4}\right)}}^{1}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
  6. Simplified98.3%

    \[\leadsto \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, \color{blue}{{\left(c \cdot a\right)}^{4}}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
    Step-by-step derivation

    [Start]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {\left({\left(c \cdot a\right)}^{4}\right)}^{1}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]

    unpow1 [=>]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, \color{blue}{{\left(c \cdot a\right)}^{4}}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
  7. Applied egg-rr98.3%

    \[\leadsto \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {\left(c \cdot a\right)}^{4}, 4 \cdot \color{blue}{{\left({\left(c \cdot a\right)}^{4}\right)}^{1}}\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
    Step-by-step derivation

    [Start]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {c}^{4} \cdot {a}^{4}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]

    pow1 [=>]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, \color{blue}{{\left({c}^{4} \cdot {a}^{4}\right)}^{1}}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]

    pow-prod-down [=>]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {\color{blue}{\left({\left(c \cdot a\right)}^{4}\right)}}^{1}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
  8. Simplified98.3%

    \[\leadsto \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {\left(c \cdot a\right)}^{4}, 4 \cdot \color{blue}{{\left(c \cdot a\right)}^{4}}\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
    Step-by-step derivation

    [Start]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {\left({\left(c \cdot a\right)}^{4}\right)}^{1}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]

    unpow1 [=>]98.3%

    \[ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, \color{blue}{{\left(c \cdot a\right)}^{4}}, 4 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}, \frac{\left(\left(a \cdot -2\right) \cdot a\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
  9. Final simplification98.3%

    \[\leadsto \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, {\left(c \cdot a\right)}^{4}, 4 \cdot {\left(c \cdot a\right)}^{4}\right)}{a \cdot {b}^{7}}, \frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]

Alternatives

Alternative 1
Accuracy97.7%
Cost53824
\[\begin{array}{l} t_0 := {\left(c \cdot a\right)}^{4}\\ \mathsf{fma}\left(-0.25, \frac{\mathsf{fma}\left(16, t_0, 4 \cdot t_0\right)}{a \cdot {b}^{7}}, \frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \end{array} \]
Alternative 2
Accuracy97.0%
Cost34816
\[\begin{array}{l} t_0 := c \cdot -8 - c \cdot -4\\ 0.25 \cdot \frac{t_0}{b} + \left(-0.0625 \cdot \frac{a \cdot {t_0}^{2}}{{b}^{3}} + 0.03125 \cdot \frac{{t_0}^{3} \cdot {a}^{2}}{{b}^{5}}\right) \end{array} \]
Alternative 3
Accuracy96.9%
Cost20736
\[\left(\frac{\left(a \cdot \left(a \cdot -2\right)\right) \cdot {c}^{3}}{{b}^{5}} - \frac{c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
Alternative 4
Accuracy95.5%
Cost7232
\[\frac{-c}{b} - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
Alternative 5
Accuracy90.8%
Cost256
\[\frac{-c}{b} \]

Reproduce?

herbie shell --seed 2023167 
(FPCore (a b c)
  :name "Quadratic roots, wide range"
  :precision binary64
  :pre (and (and (and (< 4.930380657631324e-32 a) (< a 2.028240960365167e+31)) (and (< 4.930380657631324e-32 b) (< b 2.028240960365167e+31))) (and (< 4.930380657631324e-32 c) (< c 2.028240960365167e+31)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))