Quadratic roots, medium range

?

Percentage Accurate: 31.8% → 95.0%
Time: 12.5s
Precision: binary64
Cost: 47040

?

\[\left(\left(1.1102230246251565 \cdot 10^{-16} < a \land a < 9007199254740992\right) \land \left(1.1102230246251565 \cdot 10^{-16} < b \land b < 9007199254740992\right)\right) \land \left(1.1102230246251565 \cdot 10^{-16} < c \land c < 9007199254740992\right)\]
\[\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a} \]
\[\begin{array}{l} \\ \left(\mathsf{fma}\left(-0.25, 20 \cdot \frac{{c}^{4}}{\frac{{b}^{7}}{{a}^{3}}}, -2 \cdot \frac{a \cdot a}{\frac{{b}^{5}}{{c}^{3}}}\right) - \frac{c}{b}\right) - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}} \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
 (-
  (-
   (fma
    -0.25
    (* 20.0 (/ (pow c 4.0) (/ (pow b 7.0) (pow a 3.0))))
    (* -2.0 (/ (* a a) (/ (pow b 5.0) (pow c 3.0)))))
   (/ c b))
  (/ (* c (* c a)) (pow b 3.0))))
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) {
	return (fma(-0.25, (20.0 * (pow(c, 4.0) / (pow(b, 7.0) / pow(a, 3.0)))), (-2.0 * ((a * a) / (pow(b, 5.0) / pow(c, 3.0))))) - (c / b)) - ((c * (c * a)) / pow(b, 3.0));
}
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)
	return Float64(Float64(fma(-0.25, Float64(20.0 * Float64((c ^ 4.0) / Float64((b ^ 7.0) / (a ^ 3.0)))), Float64(-2.0 * Float64(Float64(a * a) / Float64((b ^ 5.0) / (c ^ 3.0))))) - Float64(c / b)) - Float64(Float64(c * Float64(c * a)) / (b ^ 3.0)))
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_] := N[(N[(N[(-0.25 * N[(20.0 * N[(N[Power[c, 4.0], $MachinePrecision] / N[(N[Power[b, 7.0], $MachinePrecision] / N[Power[a, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[(a * a), $MachinePrecision] / N[(N[Power[b, 5.0], $MachinePrecision] / N[Power[c, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(c / b), $MachinePrecision]), $MachinePrecision] - N[(N[(c * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}

\\
\left(\mathsf{fma}\left(-0.25, 20 \cdot \frac{{c}^{4}}{\frac{{b}^{7}}{{a}^{3}}}, -2 \cdot \frac{a \cdot a}{\frac{{b}^{5}}{{c}^{3}}}\right) - \frac{c}{b}\right) - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}}
\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 10 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 35.1%

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

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

    [Start]35.1%

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

    neg-sub0 [=>]35.1%

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

    associate-+l- [=>]35.1%

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

    sub0-neg [=>]35.1%

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

    neg-mul-1 [=>]35.1%

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

    associate-*l/ [<=]35.1%

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

    *-commutative [=>]35.1%

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

    associate-/r* [=>]35.1%

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

    /-rgt-identity [<=]35.1%

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

    metadata-eval [<=]35.1%

    \[ \frac{b - \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{--1}} \cdot \frac{\frac{-1}{2}}{a} \]
  3. Taylor expanded in a around 0 94.4%

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

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

    [Start]94.4%

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

    +-commutative [=>]94.4%

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

    mul-1-neg [=>]94.4%

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

    unsub-neg [=>]94.4%

    \[ \color{blue}{\left(-1 \cdot \frac{c}{b} + \left(-0.25 \cdot \frac{\left({\left(-2 \cdot \frac{{c}^{2}}{{b}^{3}}\right)}^{2} + 16 \cdot \frac{{c}^{4}}{{b}^{6}}\right) \cdot {a}^{3}}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right) - \frac{{c}^{2} \cdot a}{{b}^{3}}} \]
  5. Taylor expanded in c around 0 94.4%

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

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

    [Start]94.4%

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

    associate-/l* [=>]94.4%

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

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

Alternatives

Alternative 1
Accuracy95.0%
Cost47040
\[\left(\mathsf{fma}\left(-0.25, 20 \cdot \frac{{c}^{4}}{\frac{{b}^{7}}{{a}^{3}}}, -2 \cdot \frac{a \cdot a}{\frac{{b}^{5}}{{c}^{3}}}\right) - \frac{c}{b}\right) - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}} \]
Alternative 2
Accuracy95.0%
Cost40704
\[\mathsf{fma}\left(-0.25, \frac{{\left(c \cdot a\right)}^{4}}{a} \cdot \frac{20}{{b}^{7}}, \left(a \cdot \frac{a}{{b}^{5}}\right) \cdot \left(-2 \cdot {c}^{3}\right) - \frac{c}{b}\right) - c \cdot \frac{c \cdot a}{{b}^{3}} \]
Alternative 3
Accuracy89.6%
Cost22148
\[\begin{array}{l} t_0 := c \cdot \left(4 \cdot a\right)\\ t_1 := \sqrt{b \cdot b - t_0}\\ \mathbf{if}\;\frac{t_1 - b}{a \cdot 2} \leq -0.0007:\\ \;\;\;\;\frac{\frac{{\left(-b\right)}^{2} + \left(t_0 - b \cdot b\right)}{\left(-b\right) - t_1}}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{c}{b}\right) - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}}\\ \end{array} \]
Alternative 4
Accuracy89.3%
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.001:\\ \;\;\;\;\left(b - \sqrt{\mathsf{fma}\left(a, c \cdot -4, b \cdot b\right)}\right) \cdot \frac{-0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{c}{b}\right) - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}}\\ \end{array} \]
Alternative 5
Accuracy89.3%
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.001:\\ \;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{c}{b}\right) - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}}\\ \end{array} \]
Alternative 6
Accuracy89.3%
Cost21060
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.001:\\ \;\;\;\;\frac{\sqrt{\mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot -4\right)} - b}{a \cdot 2}\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{c}{b}\right) - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}}\\ \end{array} \]
Alternative 7
Accuracy93.5%
Cost20736
\[\left(\left(a \cdot \frac{a}{{b}^{5}}\right) \cdot \left(-2 \cdot {c}^{3}\right) - \frac{c}{b}\right) - c \cdot \frac{c \cdot a}{{b}^{3}} \]
Alternative 8
Accuracy89.3%
Cost14788
\[\begin{array}{l} \mathbf{if}\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{a \cdot 2} \leq -0.001:\\ \;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b + \left(c \cdot a\right) \cdot -4} - b\right)\\ \mathbf{else}:\\ \;\;\;\;\left(-\frac{c}{b}\right) - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}}\\ \end{array} \]
Alternative 9
Accuracy90.3%
Cost7232
\[\left(-\frac{c}{b}\right) - \frac{c \cdot \left(c \cdot a\right)}{{b}^{3}} \]
Alternative 10
Accuracy80.9%
Cost256
\[-\frac{c}{b} \]

Reproduce?

herbie shell --seed 2023167 
(FPCore (a b c)
  :name "Quadratic roots, medium range"
  :precision binary64
  :pre (and (and (and (< 1.1102230246251565e-16 a) (< a 9007199254740992.0)) (and (< 1.1102230246251565e-16 b) (< b 9007199254740992.0))) (and (< 1.1102230246251565e-16 c) (< c 9007199254740992.0)))
  (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))