| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 7488 |
(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 32.0%
Simplified32.0%
[Start]32.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]32.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
Applied egg-rr32.7%
[Start]32.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{a \cdot 2}
\] |
|---|---|
+-commutative [=>]32.0 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{a \cdot 2}
\] |
flip-+ [=>]32.0 | \[ \frac{\color{blue}{\frac{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} \cdot \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}}{a \cdot 2}
\] |
add-sqr-sqrt [<=]32.9 | \[ \frac{\frac{\color{blue}{\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right)} - \left(-b\right) \cdot \left(-b\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
sqr-neg [=>]32.9 | \[ \frac{\frac{\left(b \cdot b - \left(4 \cdot a\right) \cdot c\right) - \color{blue}{b \cdot b}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
associate--l- [=>]32.9 | \[ \frac{\frac{\color{blue}{b \cdot b - \left(\left(4 \cdot a\right) \cdot c + b \cdot b\right)}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
+-commutative [<=]32.9 | \[ \frac{\frac{b \cdot b - \color{blue}{\left(b \cdot b + \left(4 \cdot a\right) \cdot c\right)}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
fma-def [=>]32.7 | \[ \frac{\frac{b \cdot b - \color{blue}{\mathsf{fma}\left(b, b, \left(4 \cdot a\right) \cdot c\right)}}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
associate-*l* [=>]32.7 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{4 \cdot \left(a \cdot c\right)}\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \left(-b\right)}}{a \cdot 2}
\] |
add-sqr-sqrt [=>]0.0 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{\sqrt{-b} \cdot \sqrt{-b}}}}{a \cdot 2}
\] |
sqrt-unprod [=>]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{\sqrt{\left(-b\right) \cdot \left(-b\right)}}}}{a \cdot 2}
\] |
sqr-neg [=>]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \sqrt{\color{blue}{b \cdot b}}}}{a \cdot 2}
\] |
sqrt-prod [=>]1.6 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{\sqrt{b} \cdot \sqrt{b}}}}{a \cdot 2}
\] |
add-sqr-sqrt [<=]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - \color{blue}{b}}}{a \cdot 2}
\] |
unsub-neg [<=]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}}{a \cdot 2}
\] |
+-commutative [<=]0.8 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{\color{blue}{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}}}{a \cdot 2}
\] |
Simplified32.7%
[Start]32.7 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \left(a \cdot c\right)\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
|---|---|
*-commutative [=>]32.7 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, 4 \cdot \color{blue}{\left(c \cdot a\right)}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
*-commutative [=>]32.7 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot a\right) \cdot 4}\right)}{b + \sqrt{\mathsf{fma}\left(b, b, c \cdot \left(a \cdot -4\right)\right)}}}{a \cdot 2}
\] |
fma-def [<=]32.7 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{b \cdot b + c \cdot \left(a \cdot -4\right)}}}}{a \cdot 2}
\] |
+-commutative [=>]32.7 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{c \cdot \left(a \cdot -4\right) + b \cdot b}}}}{a \cdot 2}
\] |
fma-def [=>]32.7 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\color{blue}{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}}{a \cdot 2}
\] |
Applied egg-rr18.8%
[Start]32.7 | \[ \frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}
\] |
|---|---|
expm1-log1p-u [=>]22.2 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}\right)\right)}
\] |
expm1-udef [=>]18.8 | \[ \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}{a \cdot 2}\right)} - 1}
\] |
associate-/l/ [=>]18.8 | \[ e^{\mathsf{log1p}\left(\color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, \left(c \cdot a\right) \cdot 4\right)}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}}\right)} - 1
\] |
associate-*l* [=>]18.8 | \[ e^{\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, \color{blue}{c \cdot \left(a \cdot 4\right)}\right)}{\left(a \cdot 2\right) \cdot \left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}\right)} - 1
\] |
*-commutative [=>]18.8 | \[ e^{\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\color{blue}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}}\right)} - 1
\] |
Simplified99.6%
[Start]18.8 | \[ e^{\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]22.2 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}\right)\right)}
\] |
expm1-log1p [=>]32.7 | \[ \color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}}
\] |
*-lft-identity [<=]32.7 | \[ \frac{\color{blue}{1 \cdot \left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right)}}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}
\] |
*-commutative [=>]32.7 | \[ \frac{\color{blue}{\left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right) \cdot 1}}{\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot \left(a \cdot 2\right)}
\] |
associate-*r* [=>]32.7 | \[ \frac{\left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right) \cdot 1}{\color{blue}{\left(\left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right) \cdot a\right) \cdot 2}}
\] |
*-commutative [<=]32.7 | \[ \frac{\left(b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)\right) \cdot 1}{\color{blue}{\left(a \cdot \left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)\right)} \cdot 2}
\] |
times-frac [=>]32.7 | \[ \color{blue}{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)} \cdot \frac{1}{2}}
\] |
metadata-eval [=>]32.7 | \[ \frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)} \cdot \color{blue}{0.5}
\] |
*-commutative [=>]32.7 | \[ \color{blue}{0.5 \cdot \frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{a \cdot \left(b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\right)}}
\] |
associate-/r* [=>]32.7 | \[ 0.5 \cdot \color{blue}{\frac{\frac{b \cdot b - \mathsf{fma}\left(b, b, c \cdot \left(a \cdot 4\right)\right)}{a}}{b + \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}}}
\] |
Taylor expanded in c around 0 99.7%
Simplified99.7%
[Start]99.7 | \[ 0.5 \cdot \frac{-4 \cdot c}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}
\] |
|---|---|
*-commutative [=>]99.7 | \[ 0.5 \cdot \frac{\color{blue}{c \cdot -4}}{b + \sqrt{\mathsf{fma}\left(c, -4 \cdot a, b \cdot b\right)}}
\] |
Taylor expanded in c around 0 99.7%
Simplified99.7%
[Start]99.7 | \[ 0.5 \cdot \frac{c \cdot -4}{b + \sqrt{{b}^{2} + -4 \cdot \left(c \cdot a\right)}}
\] |
|---|---|
unpow2 [=>]99.7 | \[ 0.5 \cdot \frac{c \cdot -4}{b + \sqrt{\color{blue}{b \cdot b} + -4 \cdot \left(c \cdot a\right)}}
\] |
fma-def [=>]99.7 | \[ 0.5 \cdot \frac{c \cdot -4}{b + \sqrt{\color{blue}{\mathsf{fma}\left(b, b, -4 \cdot \left(c \cdot a\right)\right)}}}
\] |
associate-*r* [=>]99.7 | \[ 0.5 \cdot \frac{c \cdot -4}{b + \sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(-4 \cdot c\right) \cdot a}\right)}}
\] |
*-commutative [=>]99.7 | \[ 0.5 \cdot \frac{c \cdot -4}{b + \sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(c \cdot -4\right)} \cdot a\right)}}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 7488 |
| Alternative 2 | |
|---|---|
| Accuracy | 90.7% |
| Cost | 1088 |
| Alternative 3 | |
|---|---|
| Accuracy | 80.8% |
| Cost | 256 |
herbie shell --seed 2023126
(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)))