| Alternative 1 | |
|---|---|
| Accuracy | 83.5% |
| Cost | 7496 |

(FPCore (a b_2 c) :precision binary64 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.55e+91)
(/ (* b_2 -2.0) a)
(if (<= b_2 1e-198)
(- (/ (sqrt (- (* b_2 b_2) (* a c))) a) (/ b_2 a))
(/ (* c -0.5) b_2))))double code(double a, double b_2, double c) {
return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.55e+91) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 1e-198) {
tmp = (sqrt(((b_2 * b_2) - (a * c))) / a) - (b_2 / a);
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a
end function
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-1.55d+91)) then
tmp = (b_2 * (-2.0d0)) / a
else if (b_2 <= 1d-198) then
tmp = (sqrt(((b_2 * b_2) - (a * c))) / a) - (b_2 / a)
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.55e+91) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 1e-198) {
tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) / a) - (b_2 / a);
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
def code(a, b_2, c): tmp = 0 if b_2 <= -1.55e+91: tmp = (b_2 * -2.0) / a elif b_2 <= 1e-198: tmp = (math.sqrt(((b_2 * b_2) - (a * c))) / a) - (b_2 / a) else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) return Float64(Float64(Float64(-b_2) + sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a) end
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.55e+91) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= 1e-198) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) / a) - Float64(b_2 / a)); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp = code(a, b_2, c) tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a; end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.55e+91) tmp = (b_2 * -2.0) / a; elseif (b_2 <= 1e-198) tmp = (sqrt(((b_2 * b_2) - (a * c))) / a) - (b_2 / a); else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := N[(N[((-b$95$2) + N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.55e+91], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 1e-198], N[(N[(N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.55 \cdot 10^{+91}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\
\mathbf{elif}\;b_2 \leq 10^{-198}:\\
\;\;\;\;\frac{\sqrt{b_2 \cdot b_2 - a \cdot c}}{a} - \frac{b_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b_2}\\
\end{array}
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
if b_2 < -1.54999999999999999e91Initial program 53.0%
Simplified53.0%
[Start]53.0% | \[ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\] |
|---|---|
+-commutative [=>]53.0% | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a}
\] |
unsub-neg [=>]53.0% | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a}
\] |
Taylor expanded in b_2 around -inf 93.0%
Simplified93.0%
[Start]93.0% | \[ \frac{-2 \cdot b_2}{a}
\] |
|---|---|
*-commutative [=>]93.0% | \[ \frac{\color{blue}{b_2 \cdot -2}}{a}
\] |
if -1.54999999999999999e91 < b_2 < 9.9999999999999991e-199Initial program 85.2%
Simplified85.2%
[Start]85.2% | \[ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\] |
|---|---|
+-commutative [=>]85.2% | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a}
\] |
unsub-neg [=>]85.2% | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a}
\] |
Applied egg-rr84.8%
[Start]85.2% | \[ \frac{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}{a}
\] |
|---|---|
add-sqr-sqrt [=>]84.8% | \[ \frac{\color{blue}{\sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}} \cdot \sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}} - b_2}{a}
\] |
pow2 [=>]84.8% | \[ \frac{\color{blue}{{\left(\sqrt{\sqrt{b_2 \cdot b_2 - a \cdot c}}\right)}^{2}} - b_2}{a}
\] |
pow1/2 [=>]84.8% | \[ \frac{{\left(\sqrt{\color{blue}{{\left(b_2 \cdot b_2 - a \cdot c\right)}^{0.5}}}\right)}^{2} - b_2}{a}
\] |
sqrt-pow1 [=>]84.8% | \[ \frac{{\color{blue}{\left({\left(b_2 \cdot b_2 - a \cdot c\right)}^{\left(\frac{0.5}{2}\right)}\right)}}^{2} - b_2}{a}
\] |
fma-neg [=>]84.8% | \[ \frac{{\left({\color{blue}{\left(\mathsf{fma}\left(b_2, b_2, -a \cdot c\right)\right)}}^{\left(\frac{0.5}{2}\right)}\right)}^{2} - b_2}{a}
\] |
*-commutative [=>]84.8% | \[ \frac{{\left({\left(\mathsf{fma}\left(b_2, b_2, -\color{blue}{c \cdot a}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2} - b_2}{a}
\] |
distribute-rgt-neg-in [=>]84.8% | \[ \frac{{\left({\left(\mathsf{fma}\left(b_2, b_2, \color{blue}{c \cdot \left(-a\right)}\right)\right)}^{\left(\frac{0.5}{2}\right)}\right)}^{2} - b_2}{a}
\] |
metadata-eval [=>]84.8% | \[ \frac{{\left({\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{\color{blue}{0.25}}\right)}^{2} - b_2}{a}
\] |
Applied egg-rr85.2%
[Start]84.8% | \[ \frac{{\left({\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{0.25}\right)}^{2} - b_2}{a}
\] |
|---|---|
div-sub [=>]84.8% | \[ \color{blue}{\frac{{\left({\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{0.25}\right)}^{2}}{a} - \frac{b_2}{a}}
\] |
pow-pow [=>]85.2% | \[ \frac{\color{blue}{{\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{\left(0.25 \cdot 2\right)}}}{a} - \frac{b_2}{a}
\] |
metadata-eval [=>]85.2% | \[ \frac{{\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{\color{blue}{0.5}}}{a} - \frac{b_2}{a}
\] |
Applied egg-rr84.8%
[Start]85.2% | \[ \frac{{\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{0.5}}{a} - \frac{b_2}{a}
\] |
|---|---|
sqr-pow [=>]84.8% | \[ \frac{\color{blue}{{\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{\left(\frac{0.5}{2}\right)} \cdot {\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{\left(\frac{0.5}{2}\right)}}}{a} - \frac{b_2}{a}
\] |
distribute-rgt-neg-out [=>]84.8% | \[ \frac{{\left(\mathsf{fma}\left(b_2, b_2, \color{blue}{-c \cdot a}\right)\right)}^{\left(\frac{0.5}{2}\right)} \cdot {\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{\left(\frac{0.5}{2}\right)}}{a} - \frac{b_2}{a}
\] |
fma-neg [<=]84.8% | \[ \frac{{\color{blue}{\left(b_2 \cdot b_2 - c \cdot a\right)}}^{\left(\frac{0.5}{2}\right)} \cdot {\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{\left(\frac{0.5}{2}\right)}}{a} - \frac{b_2}{a}
\] |
metadata-eval [=>]84.8% | \[ \frac{{\left(b_2 \cdot b_2 - c \cdot a\right)}^{\color{blue}{0.25}} \cdot {\left(\mathsf{fma}\left(b_2, b_2, c \cdot \left(-a\right)\right)\right)}^{\left(\frac{0.5}{2}\right)}}{a} - \frac{b_2}{a}
\] |
distribute-rgt-neg-out [=>]84.8% | \[ \frac{{\left(b_2 \cdot b_2 - c \cdot a\right)}^{0.25} \cdot {\left(\mathsf{fma}\left(b_2, b_2, \color{blue}{-c \cdot a}\right)\right)}^{\left(\frac{0.5}{2}\right)}}{a} - \frac{b_2}{a}
\] |
fma-neg [<=]84.8% | \[ \frac{{\left(b_2 \cdot b_2 - c \cdot a\right)}^{0.25} \cdot {\color{blue}{\left(b_2 \cdot b_2 - c \cdot a\right)}}^{\left(\frac{0.5}{2}\right)}}{a} - \frac{b_2}{a}
\] |
metadata-eval [=>]84.8% | \[ \frac{{\left(b_2 \cdot b_2 - c \cdot a\right)}^{0.25} \cdot {\left(b_2 \cdot b_2 - c \cdot a\right)}^{\color{blue}{0.25}}}{a} - \frac{b_2}{a}
\] |
Simplified85.2%
[Start]84.8% | \[ \frac{{\left(b_2 \cdot b_2 - c \cdot a\right)}^{0.25} \cdot {\left(b_2 \cdot b_2 - c \cdot a\right)}^{0.25}}{a} - \frac{b_2}{a}
\] |
|---|---|
pow-sqr [=>]85.2% | \[ \frac{\color{blue}{{\left(b_2 \cdot b_2 - c \cdot a\right)}^{\left(2 \cdot 0.25\right)}}}{a} - \frac{b_2}{a}
\] |
metadata-eval [=>]85.2% | \[ \frac{{\left(b_2 \cdot b_2 - c \cdot a\right)}^{\color{blue}{0.5}}}{a} - \frac{b_2}{a}
\] |
unpow1/2 [=>]85.2% | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - c \cdot a}}}{a} - \frac{b_2}{a}
\] |
if 9.9999999999999991e-199 < b_2 Initial program 20.5%
Simplified20.5%
[Start]20.5% | \[ \frac{\left(-b_2\right) + \sqrt{b_2 \cdot b_2 - a \cdot c}}{a}
\] |
|---|---|
+-commutative [=>]20.5% | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} + \left(-b_2\right)}}{a}
\] |
unsub-neg [=>]20.5% | \[ \frac{\color{blue}{\sqrt{b_2 \cdot b_2 - a \cdot c} - b_2}}{a}
\] |
Taylor expanded in b_2 around inf 78.2%
Applied egg-rr78.2%
[Start]78.2% | \[ -0.5 \cdot \frac{c}{b_2}
\] |
|---|---|
associate-*r/ [=>]78.2% | \[ \color{blue}{\frac{-0.5 \cdot c}{b_2}}
\] |
Final simplification83.8%
| Alternative 1 | |
|---|---|
| Accuracy | 83.5% |
| Cost | 7496 |
| Alternative 2 | |
|---|---|
| Accuracy | 83.5% |
| Cost | 7368 |
| Alternative 3 | |
|---|---|
| Accuracy | 78.7% |
| Cost | 7304 |
| Alternative 4 | |
|---|---|
| Accuracy | 78.7% |
| Cost | 7176 |
| Alternative 5 | |
|---|---|
| Accuracy | 68.6% |
| Cost | 836 |
| Alternative 6 | |
|---|---|
| Accuracy | 47.9% |
| Cost | 452 |
| Alternative 7 | |
|---|---|
| Accuracy | 68.3% |
| Cost | 452 |
| Alternative 8 | |
|---|---|
| Accuracy | 68.3% |
| Cost | 452 |
| Alternative 9 | |
|---|---|
| Accuracy | 68.4% |
| Cost | 452 |
| Alternative 10 | |
|---|---|
| Accuracy | 23.6% |
| Cost | 388 |
| Alternative 11 | |
|---|---|
| Accuracy | 11.1% |
| Cost | 192 |
herbie shell --seed 2023263
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))