| Alternative 1 | |
|---|---|
| Accuracy | 88.9% |
| Cost | 20868 |
(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 0.07)
(* (- (sqrt (fma b b (* -4.0 (* a c)))) b) (/ 0.5 a))
(fma
(/ -0.25 a)
(/ (* (pow (* a c) 4.0) 20.0) (pow b 7.0))
(-
(* -2.0 (* (* (* c c) (* c (pow b -5.0))) (* a a)))
(fma (/ c (/ (pow b 3.0) c)) a (/ c b))))))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 <= 0.07) {
tmp = (sqrt(fma(b, b, (-4.0 * (a * c)))) - b) * (0.5 / a);
} else {
tmp = fma((-0.25 / a), ((pow((a * c), 4.0) * 20.0) / pow(b, 7.0)), ((-2.0 * (((c * c) * (c * pow(b, -5.0))) * (a * a))) - fma((c / (pow(b, 3.0) / c)), a, (c / b))));
}
return tmp;
}
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) tmp = 0.0 if (b <= 0.07) tmp = Float64(Float64(sqrt(fma(b, b, Float64(-4.0 * Float64(a * c)))) - b) * Float64(0.5 / a)); else tmp = fma(Float64(-0.25 / a), Float64(Float64((Float64(a * c) ^ 4.0) * 20.0) / (b ^ 7.0)), Float64(Float64(-2.0 * Float64(Float64(Float64(c * c) * Float64(c * (b ^ -5.0))) * Float64(a * a))) - fma(Float64(c / Float64((b ^ 3.0) / c)), a, Float64(c / b)))); end return tmp 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_] := If[LessEqual[b, 0.07], N[(N[(N[Sqrt[N[(b * b + N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[(-0.25 / a), $MachinePrecision] * N[(N[(N[Power[N[(a * c), $MachinePrecision], 4.0], $MachinePrecision] * 20.0), $MachinePrecision] / N[Power[b, 7.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-2.0 * N[(N[(N[(c * c), $MachinePrecision] * N[(c * N[Power[b, -5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(N[(c / N[(N[Power[b, 3.0], $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision] * a + N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\begin{array}{l}
\mathbf{if}\;b \leq 0.07:\\
\;\;\;\;\left(\sqrt{\mathsf{fma}\left(b, b, -4 \cdot \left(a \cdot c\right)\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-0.25}{a}, \frac{{\left(a \cdot c\right)}^{4} \cdot 20}{{b}^{7}}, -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{-5}\right)\right) \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)\\
\end{array}
if b < 0.070000000000000007Initial program 90.0%
Simplified90.2%
[Start]90.0 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
/-rgt-identity [<=]90.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 [<=]90.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* [<=]90.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/ [<=]90.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 [=>]90.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 [=>]90.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 [=>]90.2 | \[ \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* [=>]90.2 | \[ \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 [=>]90.2 | \[ \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 [=>]90.2 | \[ \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 [=>]90.2 | \[ \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* [=>]90.2 | \[ \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 [=>]90.2 | \[ \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 [=>]90.2 | \[ \left(\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot -4\right)} - b\right) \cdot \frac{\color{blue}{0.5}}{a}
\] |
if 0.070000000000000007 < b Initial program 53.2%
Simplified53.3%
[Start]53.2 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\] |
|---|---|
*-commutative [=>]53.2 | \[ \frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{\color{blue}{a \cdot 2}}
\] |
+-commutative [=>]53.2 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} + \left(-b\right)}}{a \cdot 2}
\] |
unsub-neg [=>]53.2 | \[ \frac{\color{blue}{\sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c} - b}}{a \cdot 2}
\] |
fma-neg [=>]53.3 | \[ \frac{\sqrt{\color{blue}{\mathsf{fma}\left(b, b, -\left(4 \cdot a\right) \cdot c\right)}} - b}{a \cdot 2}
\] |
associate-*l* [=>]53.3 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{4 \cdot \left(a \cdot c\right)}\right)} - b}{a \cdot 2}
\] |
*-commutative [=>]53.3 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, -\color{blue}{\left(a \cdot c\right) \cdot 4}\right)} - b}{a \cdot 2}
\] |
distribute-rgt-neg-in [=>]53.3 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, \color{blue}{\left(a \cdot c\right) \cdot \left(-4\right)}\right)} - b}{a \cdot 2}
\] |
metadata-eval [=>]53.3 | \[ \frac{\sqrt{\mathsf{fma}\left(b, b, \left(a \cdot c\right) \cdot \color{blue}{-4}\right)} - b}{a \cdot 2}
\] |
Taylor expanded in b around inf 91.1%
Simplified91.1%
[Start]91.1 | \[ -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 [=>]91.1 | \[ \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}}}
\] |
associate-+l+ [=>]91.1 | \[ \color{blue}{-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(\left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)}
\] |
associate-*r/ [=>]91.1 | \[ \color{blue}{\frac{-0.25 \cdot \left({\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)\right)}{a \cdot {b}^{7}}} + \left(\left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)
\] |
times-frac [=>]91.1 | \[ \color{blue}{\frac{-0.25}{a} \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{{b}^{7}}} + \left(\left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right) + -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}}\right)
\] |
+-commutative [<=]91.1 | \[ \frac{-0.25}{a} \cdot \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{{b}^{7}} + \color{blue}{\left(-1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)}
\] |
fma-def [=>]91.1 | \[ \color{blue}{\mathsf{fma}\left(\frac{-0.25}{a}, \frac{{\left(-2 \cdot \left({c}^{2} \cdot {a}^{2}\right)\right)}^{2} + 16 \cdot \left({c}^{4} \cdot {a}^{4}\right)}{{b}^{7}}, -1 \cdot \frac{{c}^{2} \cdot a}{{b}^{3}} + \left(-1 \cdot \frac{c}{b} + -2 \cdot \frac{{c}^{3} \cdot {a}^{2}}{{b}^{5}}\right)\right)}
\] |
Applied egg-rr91.1%
[Start]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\left({c}^{4} \cdot {a}^{4}\right) \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
|---|---|
add-log-exp [=>]68.0 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\color{blue}{\log \left(e^{{c}^{4} \cdot {a}^{4}}\right)} \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
*-un-lft-identity [=>]68.0 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\log \color{blue}{\left(1 \cdot e^{{c}^{4} \cdot {a}^{4}}\right)} \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
log-prod [=>]68.0 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\color{blue}{\left(\log 1 + \log \left(e^{{c}^{4} \cdot {a}^{4}}\right)\right)} \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
metadata-eval [=>]68.0 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\left(\color{blue}{0} + \log \left(e^{{c}^{4} \cdot {a}^{4}}\right)\right) \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
add-log-exp [<=]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\left(0 + \color{blue}{{c}^{4} \cdot {a}^{4}}\right) \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
pow-prod-down [=>]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\left(0 + \color{blue}{{\left(c \cdot a\right)}^{4}}\right) \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
Simplified91.1%
[Start]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\left(0 + {\left(c \cdot a\right)}^{4}\right) \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
|---|---|
+-lft-identity [=>]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{\color{blue}{{\left(c \cdot a\right)}^{4}} \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
Applied egg-rr91.1%
[Start]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{{\left(c \cdot a\right)}^{4} \cdot 20}{{b}^{7}}, -2 \cdot \left(\frac{{c}^{3}}{{b}^{5}} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
|---|---|
div-inv [=>]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{{\left(c \cdot a\right)}^{4} \cdot 20}{{b}^{7}}, -2 \cdot \left(\color{blue}{\left({c}^{3} \cdot \frac{1}{{b}^{5}}\right)} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
unpow3 [=>]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{{\left(c \cdot a\right)}^{4} \cdot 20}{{b}^{7}}, -2 \cdot \left(\left(\color{blue}{\left(\left(c \cdot c\right) \cdot c\right)} \cdot \frac{1}{{b}^{5}}\right) \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
associate-*l* [=>]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{{\left(c \cdot a\right)}^{4} \cdot 20}{{b}^{7}}, -2 \cdot \left(\color{blue}{\left(\left(c \cdot c\right) \cdot \left(c \cdot \frac{1}{{b}^{5}}\right)\right)} \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
pow-flip [=>]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{{\left(c \cdot a\right)}^{4} \cdot 20}{{b}^{7}}, -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot \color{blue}{{b}^{\left(-5\right)}}\right)\right) \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
metadata-eval [=>]91.1 | \[ \mathsf{fma}\left(\frac{-0.25}{a}, \frac{{\left(c \cdot a\right)}^{4} \cdot 20}{{b}^{7}}, -2 \cdot \left(\left(\left(c \cdot c\right) \cdot \left(c \cdot {b}^{\color{blue}{-5}}\right)\right) \cdot \left(a \cdot a\right)\right) - \mathsf{fma}\left(\frac{c}{\frac{{b}^{3}}{c}}, a, \frac{c}{b}\right)\right)
\] |
Final simplification91.0%
| Alternative 1 | |
|---|---|
| Accuracy | 88.9% |
| Cost | 20868 |
| Alternative 2 | |
|---|---|
| Accuracy | 85.1% |
| Cost | 13764 |
| Alternative 3 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 7492 |
| Alternative 4 | |
|---|---|
| Accuracy | 85.0% |
| Cost | 7492 |
| Alternative 5 | |
|---|---|
| Accuracy | 82.0% |
| Cost | 1024 |
| Alternative 6 | |
|---|---|
| Accuracy | 64.8% |
| Cost | 256 |
herbie shell --seed 2023160
(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)))