Quadratic roots, wide range

?

Percentage Accurate: 18.2% → 97.5%
Time: 9.4s
Precision: binary64
Cost: 47040

?

\[\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} \]
\[\mathsf{fma}\left(-0.25, \frac{{\left(c \cdot a\right)}^{4} \cdot 20}{a \cdot {b}^{7}}, \mathsf{fma}\left(-2, \frac{c \cdot {\left(c \cdot a\right)}^{2}}{{b}^{5}}, \frac{-c}{b}\right)\right) - \frac{a}{\frac{{b}^{3}}{c \cdot c}} \]
(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
   (/ (* (pow (* c a) 4.0) 20.0) (* a (pow b 7.0)))
   (fma -2.0 (/ (* c (pow (* c a) 2.0)) (pow b 5.0)) (/ (- c) b)))
  (/ a (/ (pow b 3.0) (* c c)))))
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, ((pow((c * a), 4.0) * 20.0) / (a * pow(b, 7.0))), fma(-2.0, ((c * pow((c * a), 2.0)) / pow(b, 5.0)), (-c / b))) - (a / (pow(b, 3.0) / (c * c)));
}
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(fma(-0.25, Float64(Float64((Float64(c * a) ^ 4.0) * 20.0) / Float64(a * (b ^ 7.0))), fma(-2.0, Float64(Float64(c * (Float64(c * a) ^ 2.0)) / (b ^ 5.0)), Float64(Float64(-c) / b))) - 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[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := N[(N[(-0.25 * N[(N[(N[Power[N[(c * a), $MachinePrecision], 4.0], $MachinePrecision] * 20.0), $MachinePrecision] / N[(a * N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-2.0 * N[(N[(c * N[Power[N[(c * a), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision] + N[((-c) / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[(N[Power[b, 3.0], $MachinePrecision] / N[(c * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\mathsf{fma}\left(-0.25, \frac{{\left(c \cdot a\right)}^{4} \cdot 20}{a \cdot {b}^{7}}, \mathsf{fma}\left(-2, \frac{c \cdot {\left(c \cdot a\right)}^{2}}{{b}^{5}}, \frac{-c}{b}\right)\right) - \frac{a}{\frac{{b}^{3}}{c \cdot c}}

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.0%

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

    \[\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.0%

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

    /-rgt-identity [<=]16.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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.0%

    \[ \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. Applied egg-rr16.0%

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

    [Start]16.0%

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

    fma-udef [=>]16.0%

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

    *-commutative [=>]16.0%

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

    metadata-eval [<=]16.0%

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

    cancel-sign-sub-inv [<=]16.0%

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

    associate-*l* [<=]16.0%

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

    *-un-lft-identity [=>]16.0%

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

    prod-diff [=>]16.0%

    \[ \left(\sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(\left(4 \cdot a\right) \cdot c\right) \cdot 1\right) + \mathsf{fma}\left(-\left(4 \cdot a\right) \cdot c, 1, \left(\left(4 \cdot a\right) \cdot c\right) \cdot 1\right)}} - b\right) \cdot \frac{0.5}{a} \]
  4. Simplified16.0%

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

    [Start]16.0%

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

    *-rgt-identity [=>]16.0%

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

    fma-neg [<=]15.9%

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

    fma-udef [=>]15.9%

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

    *-rgt-identity [=>]15.9%

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

    *-rgt-identity [=>]15.9%

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

    associate--r- [<=]16.0%

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

    associate--r+ [=>]16.0%

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

    +-inverses [=>]16.0%

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

    neg-sub0 [<=]16.0%

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

    associate-*r* [=>]16.0%

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

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

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

    metadata-eval [=>]16.0%

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

    *-commutative [=>]16.0%

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

    associate-*r* [<=]16.0%

    \[ \left(\sqrt{b \cdot b - \color{blue}{c \cdot \left(a \cdot 4\right)}} - b\right) \cdot \frac{0.5}{a} \]
  5. Taylor expanded in b around inf 97.5%

    \[\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)} \]
  6. Simplified97.5%

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

    [Start]97.5%

    \[ -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 [=>]97.5%

    \[ \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}}} \]

    mul-1-neg [=>]97.5%

    \[ \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) + \color{blue}{\left(-\frac{{c}^{2} \cdot a}{{b}^{3}}\right)} \]

    unsub-neg [=>]97.5%

    \[ \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) - \frac{{c}^{2} \cdot a}{{b}^{3}}} \]
  7. Final simplification97.5%

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

Alternatives

Alternative 1
Accuracy97.5%
Cost47040
\[\mathsf{fma}\left(-0.25, \frac{{\left(c \cdot a\right)}^{4} \cdot 20}{a \cdot {b}^{7}}, \mathsf{fma}\left(-2, \frac{c \cdot {\left(c \cdot a\right)}^{2}}{{b}^{5}}, \frac{-c}{b}\right)\right) - \frac{a}{\frac{{b}^{3}}{c \cdot c}} \]
Alternative 2
Accuracy96.7%
Cost27072
\[\mathsf{fma}\left(-2, \frac{{c}^{3}}{\frac{{b}^{5}}{a \cdot a}}, \frac{-c}{b}\right) - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
Alternative 3
Accuracy95.1%
Cost7232
\[\frac{-c}{b} - \frac{c \cdot c}{\frac{{b}^{3}}{a}} \]
Alternative 4
Accuracy94.8%
Cost1344
\[\frac{\frac{\left(c \cdot a\right) \cdot -4}{b + \left(b + -2 \cdot \frac{c}{\frac{b}{a}}\right)}}{a \cdot 2} \]
Alternative 5
Accuracy90.1%
Cost256
\[\frac{-c}{b} \]

Reproduce?

herbie shell --seed 2023165 
(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)))