| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13632 |
\[\frac{-2}{\frac{b + \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot -4\right) \cdot a\right)}}{c}}
\]
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
(FPCore (a b c) :precision binary64 (* 0.5 (/ (* c -4.0) (+ b (sqrt (fma b b (* (* c -4.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) {
return 0.5 * ((c * -4.0) / (b + sqrt(fma(b, b, ((c * -4.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) return Float64(0.5 * Float64(Float64(c * -4.0) / Float64(b + sqrt(fma(b, b, Float64(Float64(c * -4.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_] := N[(0.5 * N[(N[(c * -4.0), $MachinePrecision] / N[(b + N[Sqrt[N[(b * b + N[(N[(c * -4.0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
0.5 \cdot \frac{c \cdot -4}{b + \sqrt{\mathsf{fma}\left(b, b, \left(c \cdot -4\right) \cdot a\right)}}
Initial program 28.4
Simplified28.4
[Start]28.4 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]28.4 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr29.0
Applied egg-rr15.0
Simplified15.0
[Start]15.0 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{\frac{1}{\frac{c \cdot \left(a \cdot -4\right)}{-\left(b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}}}}{a \cdot 2}
\] |
|---|---|
associate-/l* [=>]15.0 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{\frac{1}{\color{blue}{\frac{c}{\frac{-\left(b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\right)}{a \cdot -4}}}}}}{a \cdot 2}
\] |
*-commutative [=>]15.0 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{\frac{1}{\frac{c}{\frac{-\left(b + \sqrt{b \cdot b - \color{blue}{\left(a \cdot 4\right)} \cdot c}\right)}{a \cdot -4}}}}}{a \cdot 2}
\] |
associate-*r* [<=]15.0 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{\frac{1}{\frac{c}{\frac{-\left(b + \sqrt{b \cdot b - \color{blue}{a \cdot \left(4 \cdot c\right)}}\right)}{a \cdot -4}}}}}{a \cdot 2}
\] |
fma-neg [=>]15.0 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{\frac{1}{\frac{c}{\frac{-\left(b + \sqrt{\color{blue}{\mathsf{fma}\left(b, b, -a \cdot \left(4 \cdot c\right)\right)}}\right)}{a \cdot -4}}}}}{a \cdot 2}
\] |
*-commutative [=>]15.0 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{\frac{1}{\frac{c}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(b, b, -a \cdot \color{blue}{\left(c \cdot 4\right)}\right)}\right)}{a \cdot -4}}}}}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]15.0 | \[ \frac{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{\frac{1}{\frac{c}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(b, b, \color{blue}{a \cdot \left(-c \cdot 4\right)}\right)}\right)}{a \cdot -4}}}}}{a \cdot 2}
\] |
Applied egg-rr15.0
Simplified0.4
[Start]15.0 | \[ \frac{\left(b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)\right) \cdot \left(\frac{1}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)} \cdot \frac{c}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-c \cdot 4\right)\right)}\right)}{a \cdot -4}}\right)}{a \cdot 2}
\] |
|---|---|
associate-*l/ [=>]15.0 | \[ \frac{\left(b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)\right) \cdot \color{blue}{\frac{1 \cdot \frac{c}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-c \cdot 4\right)\right)}\right)}{a \cdot -4}}}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}}{a \cdot 2}
\] |
*-lft-identity [=>]15.0 | \[ \frac{\left(b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)\right) \cdot \frac{\color{blue}{\frac{c}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-c \cdot 4\right)\right)}\right)}{a \cdot -4}}}}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}{a \cdot 2}
\] |
associate-*r/ [=>]15.0 | \[ \frac{\color{blue}{\frac{\left(b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)\right) \cdot \frac{c}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-c \cdot 4\right)\right)}\right)}{a \cdot -4}}}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)}}}{a \cdot 2}
\] |
associate-*l/ [<=]14.9 | \[ \frac{\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)} \cdot \frac{c}{\frac{-\left(b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-c \cdot 4\right)\right)}\right)}{a \cdot -4}}}}{a \cdot 2}
\] |
associate-/r/ [=>]14.9 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}{b \cdot b - \left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)} \cdot \color{blue}{\left(\frac{c}{-\left(b + \sqrt{\mathsf{fma}\left(b, b, a \cdot \left(-c \cdot 4\right)\right)}\right)} \cdot \left(a \cdot -4\right)\right)}}{a \cdot 2}
\] |
Applied egg-rr24.8
Simplified0.3
[Start]24.8 | \[ e^{\mathsf{log1p}\left(\frac{-4 \cdot \left(a \cdot \frac{\frac{c \cdot \left(-4 \cdot \left(c \cdot a\right)\right)}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}\right)}{a \cdot 2}\right)} - 1
\] |
|---|---|
expm1-def [=>]10.5 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{-4 \cdot \left(a \cdot \frac{\frac{c \cdot \left(-4 \cdot \left(c \cdot a\right)\right)}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}\right)}{a \cdot 2}\right)\right)}
\] |
expm1-log1p [=>]0.4 | \[ \color{blue}{\frac{-4 \cdot \left(a \cdot \frac{\frac{c \cdot \left(-4 \cdot \left(c \cdot a\right)\right)}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}\right)}{a \cdot 2}}
\] |
*-commutative [=>]0.4 | \[ \frac{-4 \cdot \left(a \cdot \frac{\frac{c \cdot \left(-4 \cdot \left(c \cdot a\right)\right)}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}\right)}{\color{blue}{2 \cdot a}}
\] |
associate-/r* [=>]0.4 | \[ \color{blue}{\frac{\frac{-4 \cdot \left(a \cdot \frac{\frac{c \cdot \left(-4 \cdot \left(c \cdot a\right)\right)}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}\right)}{2}}{a}}
\] |
associate-/l* [=>]0.5 | \[ \frac{\color{blue}{\frac{-4}{\frac{2}{a \cdot \frac{\frac{c \cdot \left(-4 \cdot \left(c \cdot a\right)\right)}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}}}}}{a}
\] |
associate-/r/ [=>]0.4 | \[ \frac{\color{blue}{\frac{-4}{2} \cdot \left(a \cdot \frac{\frac{c \cdot \left(-4 \cdot \left(c \cdot a\right)\right)}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}\right)}}{a}
\] |
metadata-eval [=>]0.4 | \[ \frac{\color{blue}{-2} \cdot \left(a \cdot \frac{\frac{c \cdot \left(-4 \cdot \left(c \cdot a\right)\right)}{-4 \cdot \left(c \cdot a\right)}}{b + \sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}\right)}{a}
\] |
Final simplification0.3
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 13632 |
| Alternative 2 | |
|---|---|
| Error | 7.0 |
| Cost | 8964 |
| Alternative 3 | |
|---|---|
| Error | 9.1 |
| Cost | 8388 |
| Alternative 4 | |
|---|---|
| Error | 9.1 |
| Cost | 8388 |
| Alternative 5 | |
|---|---|
| Error | 9.1 |
| Cost | 8388 |
| Alternative 6 | |
|---|---|
| Error | 9.4 |
| Cost | 7748 |
| Alternative 7 | |
|---|---|
| Error | 9.4 |
| Cost | 7748 |
| Alternative 8 | |
|---|---|
| Error | 9.4 |
| Cost | 7620 |
| Alternative 9 | |
|---|---|
| Error | 9.4 |
| Cost | 7492 |
| Alternative 10 | |
|---|---|
| Error | 9.4 |
| Cost | 7492 |
| Alternative 11 | |
|---|---|
| Error | 11.6 |
| Cost | 1344 |
| Alternative 12 | |
|---|---|
| Error | 22.9 |
| Cost | 256 |
herbie shell --seed 2023011
(FPCore (a b c)
:name "Quadratic roots, 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) (* (* 4.0 a) c)))) (* 2.0 a)))