| Alternative 1 | |
|---|---|
| Error | 10.3 |
| Cost | 13896 |
(FPCore (a b c) :precision binary64 (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(FPCore (a b c)
:precision binary64
(if (<= b -3e-90)
(/ (- c) b)
(if (<= b 8.5e+105)
(/
(-
(- b)
(sqrt
(+
(fma b b (* c (* a -4.0)))
(* 4.0 (fma (- c) (* a 4.0) (* c (* a 4.0)))))))
(* a 2.0))
(- (/ b 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 tmp;
if (b <= -3e-90) {
tmp = -c / b;
} else if (b <= 8.5e+105) {
tmp = (-b - sqrt((fma(b, b, (c * (a * -4.0))) + (4.0 * fma(-c, (a * 4.0), (c * (a * 4.0))))))) / (a * 2.0);
} else {
tmp = -(b / a);
}
return tmp;
}
function code(a, b, c) return Float64(Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c))))) / Float64(2.0 * a)) end
function code(a, b, c) tmp = 0.0 if (b <= -3e-90) tmp = Float64(Float64(-c) / b); elseif (b <= 8.5e+105) tmp = Float64(Float64(Float64(-b) - sqrt(Float64(fma(b, b, Float64(c * Float64(a * -4.0))) + Float64(4.0 * fma(Float64(-c), Float64(a * 4.0), Float64(c * Float64(a * 4.0))))))) / Float64(a * 2.0)); else tmp = Float64(-Float64(b / a)); end return tmp end
code[a_, b_, c_] := N[(N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
code[a_, b_, c_] := If[LessEqual[b, -3e-90], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 8.5e+105], N[(N[((-b) - N[Sqrt[N[(N[(b * b + N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(4.0 * N[((-c) * N[(a * 4.0), $MachinePrecision] + N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], (-N[(b / a), $MachinePrecision])]]
\frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-90}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{+105}:\\
\;\;\;\;\frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \mathsf{fma}\left(-c, a \cdot 4, c \cdot \left(a \cdot 4\right)\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;-\frac{b}{a}\\
\end{array}
| Original | 34.2 |
|---|---|
| Target | 20.9 |
| Herbie | 10.3 |
if b < -3.0000000000000002e-90Initial program 52.3
Simplified52.3
[Start]52.3 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
*-lft-identity [<=]52.3 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}
\] |
metadata-eval [<=]52.3 | \[ \color{blue}{\left(--1\right)} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
associate-*r/ [=>]52.3 | \[ \color{blue}{\frac{\left(--1\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{2 \cdot a}}
\] |
associate-*l/ [<=]52.3 | \[ \color{blue}{\frac{--1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}
\] |
distribute-neg-frac [<=]52.3 | \[ \color{blue}{\left(-\frac{-1}{2 \cdot a}\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)
\] |
distribute-lft-neg-in [<=]52.3 | \[ \color{blue}{-\frac{-1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}
\] |
distribute-rgt-neg-out [<=]52.3 | \[ \color{blue}{\frac{-1}{2 \cdot a} \cdot \left(-\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)}
\] |
associate-/r* [=>]52.3 | \[ \color{blue}{\frac{\frac{-1}{2}}{a}} \cdot \left(-\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)
\] |
metadata-eval [=>]52.3 | \[ \frac{\color{blue}{-0.5}}{a} \cdot \left(-\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)
\] |
sub-neg [=>]52.3 | \[ \frac{-0.5}{a} \cdot \left(-\color{blue}{\left(\left(-b\right) + \left(-\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)}\right)
\] |
distribute-neg-out [=>]52.3 | \[ \frac{-0.5}{a} \cdot \left(-\color{blue}{\left(-\left(b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)}\right)
\] |
remove-double-neg [=>]52.3 | \[ \frac{-0.5}{a} \cdot \color{blue}{\left(b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}
\] |
sub-neg [=>]52.3 | \[ \frac{-0.5}{a} \cdot \left(b + \sqrt{\color{blue}{b \cdot b + \left(-4 \cdot \left(a \cdot c\right)\right)}}\right)
\] |
+-commutative [=>]52.3 | \[ \frac{-0.5}{a} \cdot \left(b + \sqrt{\color{blue}{\left(-4 \cdot \left(a \cdot c\right)\right) + b \cdot b}}\right)
\] |
Taylor expanded in b around -inf 10.3
Simplified10.3
[Start]10.3 | \[ -1 \cdot \frac{c}{b}
\] |
|---|---|
mul-1-neg [=>]10.3 | \[ \color{blue}{-\frac{c}{b}}
\] |
distribute-neg-frac [=>]10.3 | \[ \color{blue}{\frac{-c}{b}}
\] |
if -3.0000000000000002e-90 < b < 8.49999999999999986e105Initial program 12.6
Applied egg-rr12.6
Simplified12.7
[Start]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right) + \left(\left(\mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right) + \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)\right) + \left(\mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right) + \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)\right)\right)}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot a\right)} \cdot -4\right) + \left(\left(\mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right) + \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)\right) + \left(\mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right) + \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)\right)\right)}}{2 \cdot a}
\] |
associate-*l* [=>]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, \color{blue}{c \cdot \left(a \cdot -4\right)}\right) + \left(\left(\mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right) + \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)\right) + \left(\mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right) + \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)\right)\right)}}{2 \cdot a}
\] |
count-2 [=>]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \color{blue}{2 \cdot \left(\mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right) + \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)\right)}}}{2 \cdot a}
\] |
count-2 [=>]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 2 \cdot \color{blue}{\left(2 \cdot \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)\right)}}}{2 \cdot a}
\] |
associate-*r* [=>]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \color{blue}{\left(2 \cdot 2\right) \cdot \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)}}}{2 \cdot a}
\] |
metadata-eval [=>]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + \color{blue}{4} \cdot \mathsf{fma}\left(a \cdot \left(-c\right), 4, 4 \cdot \left(a \cdot c\right)\right)}}{2 \cdot a}
\] |
fma-udef [=>]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \color{blue}{\left(\left(a \cdot \left(-c\right)\right) \cdot 4 + 4 \cdot \left(a \cdot c\right)\right)}}}{2 \cdot a}
\] |
*-commutative [=>]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \left(\color{blue}{\left(\left(-c\right) \cdot a\right)} \cdot 4 + 4 \cdot \left(a \cdot c\right)\right)}}{2 \cdot a}
\] |
associate-*r* [<=]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \left(\color{blue}{\left(-c\right) \cdot \left(a \cdot 4\right)} + 4 \cdot \left(a \cdot c\right)\right)}}{2 \cdot a}
\] |
*-commutative [<=]12.6 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \left(\left(-c\right) \cdot \color{blue}{\left(4 \cdot a\right)} + 4 \cdot \left(a \cdot c\right)\right)}}{2 \cdot a}
\] |
fma-udef [<=]12.7 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \color{blue}{\mathsf{fma}\left(-c, 4 \cdot a, 4 \cdot \left(a \cdot c\right)\right)}}}{2 \cdot a}
\] |
*-commutative [=>]12.7 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \mathsf{fma}\left(-c, \color{blue}{a \cdot 4}, 4 \cdot \left(a \cdot c\right)\right)}}{2 \cdot a}
\] |
associate-*r* [=>]12.7 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \mathsf{fma}\left(-c, a \cdot 4, \color{blue}{\left(4 \cdot a\right) \cdot c}\right)}}{2 \cdot a}
\] |
*-commutative [=>]12.7 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \mathsf{fma}\left(-c, a \cdot 4, \color{blue}{c \cdot \left(4 \cdot a\right)}\right)}}{2 \cdot a}
\] |
*-commutative [=>]12.7 | \[ \frac{\left(-b\right) - \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right) + 4 \cdot \mathsf{fma}\left(-c, a \cdot 4, c \cdot \color{blue}{\left(a \cdot 4\right)}\right)}}{2 \cdot a}
\] |
if 8.49999999999999986e105 < b Initial program 46.5
Simplified46.6
[Start]46.5 | \[ \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
|---|---|
*-lft-identity [<=]46.5 | \[ \color{blue}{1 \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}}
\] |
metadata-eval [<=]46.5 | \[ \color{blue}{\left(--1\right)} \cdot \frac{\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\] |
associate-*r/ [=>]46.5 | \[ \color{blue}{\frac{\left(--1\right) \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}{2 \cdot a}}
\] |
associate-*l/ [<=]46.6 | \[ \color{blue}{\frac{--1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}
\] |
distribute-neg-frac [<=]46.6 | \[ \color{blue}{\left(-\frac{-1}{2 \cdot a}\right)} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)
\] |
distribute-lft-neg-in [<=]46.6 | \[ \color{blue}{-\frac{-1}{2 \cdot a} \cdot \left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}
\] |
distribute-rgt-neg-out [<=]46.6 | \[ \color{blue}{\frac{-1}{2 \cdot a} \cdot \left(-\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)}
\] |
associate-/r* [=>]46.6 | \[ \color{blue}{\frac{\frac{-1}{2}}{a}} \cdot \left(-\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)
\] |
metadata-eval [=>]46.6 | \[ \frac{\color{blue}{-0.5}}{a} \cdot \left(-\left(\left(-b\right) - \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)
\] |
sub-neg [=>]46.6 | \[ \frac{-0.5}{a} \cdot \left(-\color{blue}{\left(\left(-b\right) + \left(-\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)}\right)
\] |
distribute-neg-out [=>]46.6 | \[ \frac{-0.5}{a} \cdot \left(-\color{blue}{\left(-\left(b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)\right)}\right)
\] |
remove-double-neg [=>]46.6 | \[ \frac{-0.5}{a} \cdot \color{blue}{\left(b + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\right)}
\] |
sub-neg [=>]46.6 | \[ \frac{-0.5}{a} \cdot \left(b + \sqrt{\color{blue}{b \cdot b + \left(-4 \cdot \left(a \cdot c\right)\right)}}\right)
\] |
+-commutative [=>]46.6 | \[ \frac{-0.5}{a} \cdot \left(b + \sqrt{\color{blue}{\left(-4 \cdot \left(a \cdot c\right)\right) + b \cdot b}}\right)
\] |
Taylor expanded in a around 0 3.3
Simplified3.3
[Start]3.3 | \[ -1 \cdot \frac{b}{a}
\] |
|---|---|
associate-*r/ [=>]3.3 | \[ \color{blue}{\frac{-1 \cdot b}{a}}
\] |
mul-1-neg [=>]3.3 | \[ \frac{\color{blue}{-b}}{a}
\] |
Final simplification10.3
| Alternative 1 | |
|---|---|
| Error | 10.3 |
| Cost | 13896 |
| Alternative 2 | |
|---|---|
| Error | 10.2 |
| Cost | 7688 |
| Alternative 3 | |
|---|---|
| Error | 13.6 |
| Cost | 7432 |
| Alternative 4 | |
|---|---|
| Error | 39.5 |
| Cost | 388 |
| Alternative 5 | |
|---|---|
| Error | 22.5 |
| Cost | 388 |
| Alternative 6 | |
|---|---|
| Error | 62.4 |
| Cost | 192 |
| Alternative 7 | |
|---|---|
| Error | 56.5 |
| Cost | 192 |
herbie shell --seed 2023187
(FPCore (a b c)
:name "quadm (p42, negative)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ c (* a (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))) (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))
(/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))