
(FPCore (a b_2 c) :precision binary64 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
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
public static double code(double a, double b_2, double c) {
return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
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 tmp = code(a, b_2, c) tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a; 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]
\begin{array}{l}
\\
\frac{\left(-b\_2\right) + \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b_2 c) :precision binary64 (/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))
double code(double a, double b_2, double c) {
return (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a;
}
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
public static double code(double a, double b_2, double c) {
return (-b_2 + Math.sqrt(((b_2 * b_2) - (a * c)))) / a;
}
def code(a, b_2, c): return (-b_2 + math.sqrt(((b_2 * b_2) - (a * c)))) / a
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 tmp = code(a, b_2, c) tmp = (-b_2 + sqrt(((b_2 * b_2) - (a * c)))) / a; 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]
\begin{array}{l}
\\
\frac{\left(-b\_2\right) + \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}
\end{array}
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -4.2e-24)
(+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))
(if (<= b_2 2.1e-43)
(fma (hypot b_2 (sqrt (* c (- a)))) (/ 1.0 a) (/ b_2 (- a)))
(/ 1.0 (fma 0.5 (/ a b_2) (* -2.0 (/ b_2 c)))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4.2e-24) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 2.1e-43) {
tmp = fma(hypot(b_2, sqrt((c * -a))), (1.0 / a), (b_2 / -a));
} else {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 * (b_2 / c)));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -4.2e-24) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); elseif (b_2 <= 2.1e-43) tmp = fma(hypot(b_2, sqrt(Float64(c * Float64(-a)))), Float64(1.0 / a), Float64(b_2 / Float64(-a))); else tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 * Float64(b_2 / c)))); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4.2e-24], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 2.1e-43], N[(N[Sqrt[b$95$2 ^ 2 + N[Sqrt[N[(c * (-a)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] * N[(1.0 / a), $MachinePrecision] + N[(b$95$2 / (-a)), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 * N[(b$95$2 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -4.2 \cdot 10^{-24}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 2.1 \cdot 10^{-43}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{hypot}\left(b\_2, \sqrt{c \cdot \left(-a\right)}\right), \frac{1}{a}, \frac{b\_2}{-a}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b\_2}, -2 \cdot \frac{b\_2}{c}\right)}\\
\end{array}
\end{array}
if b_2 < -4.1999999999999999e-24Initial program 57.6%
+-commutative57.6%
unsub-neg57.6%
Simplified57.6%
Taylor expanded in b_2 around -inf 76.3%
associate-*r*76.3%
neg-mul-176.3%
associate-/l*88.0%
Simplified88.0%
Taylor expanded in a around inf 88.0%
if -4.1999999999999999e-24 < b_2 < 2.1000000000000001e-43Initial program 77.6%
+-commutative77.6%
unsub-neg77.6%
Simplified77.6%
div-sub77.6%
div-inv77.5%
fma-neg77.5%
sub-neg77.5%
add-sqr-sqrt77.5%
hypot-define80.9%
*-commutative80.9%
distribute-rgt-neg-in80.9%
Applied egg-rr80.9%
distribute-neg-frac280.9%
Simplified80.9%
if 2.1000000000000001e-43 < b_2 Initial program 16.9%
+-commutative16.9%
unsub-neg16.9%
Simplified16.9%
clear-num16.8%
inv-pow16.8%
sub-neg16.8%
add-sqr-sqrt11.9%
hypot-define22.1%
*-commutative22.1%
distribute-rgt-neg-in22.1%
Applied egg-rr22.1%
unpow-122.1%
Simplified22.1%
Taylor expanded in a around 0 0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt87.5%
times-frac87.5%
metadata-eval87.5%
Simplified87.5%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -4.4e-24)
(+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))
(if (<= b_2 6.3e-50)
(- (/ (hypot b_2 (sqrt (* c (- a)))) a) (/ b_2 a))
(/ 1.0 (fma 0.5 (/ a b_2) (* -2.0 (/ b_2 c)))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4.4e-24) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 6.3e-50) {
tmp = (hypot(b_2, sqrt((c * -a))) / a) - (b_2 / a);
} else {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 * (b_2 / c)));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -4.4e-24) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); elseif (b_2 <= 6.3e-50) tmp = Float64(Float64(hypot(b_2, sqrt(Float64(c * Float64(-a)))) / a) - Float64(b_2 / a)); else tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 * Float64(b_2 / c)))); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4.4e-24], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 6.3e-50], N[(N[(N[Sqrt[b$95$2 ^ 2 + N[Sqrt[N[(c * (-a)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision] / a), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 * N[(b$95$2 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -4.4 \cdot 10^{-24}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 6.3 \cdot 10^{-50}:\\
\;\;\;\;\frac{\mathsf{hypot}\left(b\_2, \sqrt{c \cdot \left(-a\right)}\right)}{a} - \frac{b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b\_2}, -2 \cdot \frac{b\_2}{c}\right)}\\
\end{array}
\end{array}
if b_2 < -4.40000000000000003e-24Initial program 57.6%
+-commutative57.6%
unsub-neg57.6%
Simplified57.6%
Taylor expanded in b_2 around -inf 76.3%
associate-*r*76.3%
neg-mul-176.3%
associate-/l*88.0%
Simplified88.0%
Taylor expanded in a around inf 88.0%
if -4.40000000000000003e-24 < b_2 < 6.30000000000000023e-50Initial program 77.6%
+-commutative77.6%
unsub-neg77.6%
Simplified77.6%
div-sub77.6%
sub-neg77.6%
add-sqr-sqrt77.6%
hypot-define80.8%
*-commutative80.8%
distribute-rgt-neg-in80.8%
Applied egg-rr80.8%
if 6.30000000000000023e-50 < b_2 Initial program 16.9%
+-commutative16.9%
unsub-neg16.9%
Simplified16.9%
clear-num16.8%
inv-pow16.8%
sub-neg16.8%
add-sqr-sqrt11.9%
hypot-define22.1%
*-commutative22.1%
distribute-rgt-neg-in22.1%
Applied egg-rr22.1%
unpow-122.1%
Simplified22.1%
Taylor expanded in a around 0 0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt87.5%
times-frac87.5%
metadata-eval87.5%
Simplified87.5%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -4.2e+104)
(/ (* b_2 -2.0) a)
(if (<= b_2 7.6e-47)
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
(/ 1.0 (fma 0.5 (/ a b_2) (* -2.0 (/ b_2 c)))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4.2e+104) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 7.6e-47) {
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 * (b_2 / c)));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -4.2e+104) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= 7.6e-47) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a); else tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 * Float64(b_2 / c)))); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4.2e+104], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 7.6e-47], N[(N[(N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 * N[(b$95$2 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -4.2 \cdot 10^{+104}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{elif}\;b\_2 \leq 7.6 \cdot 10^{-47}:\\
\;\;\;\;\frac{\sqrt{b\_2 \cdot b\_2 - a \cdot c} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b\_2}, -2 \cdot \frac{b\_2}{c}\right)}\\
\end{array}
\end{array}
if b_2 < -4.1999999999999997e104Initial program 44.5%
+-commutative44.5%
unsub-neg44.5%
Simplified44.5%
Taylor expanded in b_2 around -inf 92.5%
*-commutative92.5%
Simplified92.5%
if -4.1999999999999997e104 < b_2 < 7.60000000000000029e-47Initial program 80.0%
+-commutative80.0%
unsub-neg80.0%
Simplified80.0%
if 7.60000000000000029e-47 < b_2 Initial program 16.9%
+-commutative16.9%
unsub-neg16.9%
Simplified16.9%
clear-num16.8%
inv-pow16.8%
sub-neg16.8%
add-sqr-sqrt11.9%
hypot-define22.1%
*-commutative22.1%
distribute-rgt-neg-in22.1%
Applied egg-rr22.1%
unpow-122.1%
Simplified22.1%
Taylor expanded in a around 0 0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt87.5%
times-frac87.5%
metadata-eval87.5%
Simplified87.5%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.25e-27)
(+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))
(if (<= b_2 9.2e-49)
(/ (- (sqrt (* c (- a))) b_2) a)
(/ 1.0 (fma 0.5 (/ a b_2) (* -2.0 (/ b_2 c)))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.25e-27) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 9.2e-49) {
tmp = (sqrt((c * -a)) - b_2) / a;
} else {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 * (b_2 / c)));
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.25e-27) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); elseif (b_2 <= 9.2e-49) tmp = Float64(Float64(sqrt(Float64(c * Float64(-a))) - b_2) / a); else tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 * Float64(b_2 / c)))); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.25e-27], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 9.2e-49], N[(N[(N[Sqrt[N[(c * (-a)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 * N[(b$95$2 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.25 \cdot 10^{-27}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 9.2 \cdot 10^{-49}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-a\right)} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b\_2}, -2 \cdot \frac{b\_2}{c}\right)}\\
\end{array}
\end{array}
if b_2 < -1.25e-27Initial program 58.2%
+-commutative58.2%
unsub-neg58.2%
Simplified58.2%
Taylor expanded in b_2 around -inf 76.6%
associate-*r*76.6%
neg-mul-176.6%
associate-/l*88.1%
Simplified88.1%
Taylor expanded in a around inf 88.1%
if -1.25e-27 < b_2 < 9.1999999999999996e-49Initial program 77.4%
+-commutative77.4%
unsub-neg77.4%
Simplified77.4%
Taylor expanded in b_2 around 0 67.8%
associate-*r*67.8%
neg-mul-167.8%
*-commutative67.8%
Simplified67.8%
if 9.1999999999999996e-49 < b_2 Initial program 16.9%
+-commutative16.9%
unsub-neg16.9%
Simplified16.9%
clear-num16.8%
inv-pow16.8%
sub-neg16.8%
add-sqr-sqrt11.9%
hypot-define22.1%
*-commutative22.1%
distribute-rgt-neg-in22.1%
Applied egg-rr22.1%
unpow-122.1%
Simplified22.1%
Taylor expanded in a around 0 0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt87.5%
times-frac87.5%
metadata-eval87.5%
Simplified87.5%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -6.5e-40) (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2))) (if (<= b_2 5.9e-40) (/ (- (sqrt (* c (- a))) b_2) a) (/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -6.5e-40) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 5.9e-40) {
tmp = (sqrt((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
real(8) :: tmp
if (b_2 <= (-6.5d-40)) then
tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
else if (b_2 <= 5.9d-40) then
tmp = (sqrt((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) {
double tmp;
if (b_2 <= -6.5e-40) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 5.9e-40) {
tmp = (Math.sqrt((c * -a)) - b_2) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -6.5e-40: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) elif b_2 <= 5.9e-40: tmp = (math.sqrt((c * -a)) - b_2) / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -6.5e-40) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); elseif (b_2 <= 5.9e-40) tmp = Float64(Float64(sqrt(Float64(c * Float64(-a))) - b_2) / a); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -6.5e-40) tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); elseif (b_2 <= 5.9e-40) tmp = (sqrt((c * -a)) - b_2) / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -6.5e-40], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 5.9e-40], N[(N[(N[Sqrt[N[(c * (-a)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -6.5 \cdot 10^{-40}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 5.9 \cdot 10^{-40}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-a\right)} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -6.4999999999999999e-40Initial program 58.2%
+-commutative58.2%
unsub-neg58.2%
Simplified58.2%
Taylor expanded in b_2 around -inf 76.6%
associate-*r*76.6%
neg-mul-176.6%
associate-/l*88.1%
Simplified88.1%
Taylor expanded in a around inf 88.1%
if -6.4999999999999999e-40 < b_2 < 5.89999999999999966e-40Initial program 77.4%
+-commutative77.4%
unsub-neg77.4%
Simplified77.4%
Taylor expanded in b_2 around 0 67.8%
associate-*r*67.8%
neg-mul-167.8%
*-commutative67.8%
Simplified67.8%
if 5.89999999999999966e-40 < b_2 Initial program 16.9%
+-commutative16.9%
unsub-neg16.9%
Simplified16.9%
Taylor expanded in b_2 around inf 87.1%
associate-*r/87.1%
*-commutative87.1%
Simplified87.1%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-310) (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2))) (/ (* c -0.5) b_2)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-310) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} 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
real(8) :: tmp
if (b_2 <= (-2d-310)) then
tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-310) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-310: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-310) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-310) tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-310], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-310}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -1.999999999999994e-310Initial program 68.1%
+-commutative68.1%
unsub-neg68.1%
Simplified68.1%
Taylor expanded in b_2 around -inf 56.9%
associate-*r*56.9%
neg-mul-156.9%
associate-/l*64.1%
Simplified64.1%
Taylor expanded in a around inf 66.8%
if -1.999999999999994e-310 < b_2 Initial program 33.0%
+-commutative33.0%
unsub-neg33.0%
Simplified33.0%
Taylor expanded in b_2 around inf 63.8%
associate-*r/63.8%
*-commutative63.8%
Simplified63.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-310) (/ (* b_2 -2.0) a) (/ (* c -0.5) b_2)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-310) {
tmp = (b_2 * -2.0) / 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
real(8) :: tmp
if (b_2 <= (-2d-310)) then
tmp = (b_2 * (-2.0d0)) / 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) {
double tmp;
if (b_2 <= -2e-310) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-310: tmp = (b_2 * -2.0) / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-310) tmp = Float64(Float64(b_2 * -2.0) / a); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-310) tmp = (b_2 * -2.0) / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-310], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -1.999999999999994e-310Initial program 68.1%
+-commutative68.1%
unsub-neg68.1%
Simplified68.1%
Taylor expanded in b_2 around -inf 66.5%
*-commutative66.5%
Simplified66.5%
if -1.999999999999994e-310 < b_2 Initial program 33.0%
+-commutative33.0%
unsub-neg33.0%
Simplified33.0%
Taylor expanded in b_2 around inf 63.8%
associate-*r/63.8%
*-commutative63.8%
Simplified63.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 1.4e+76) (/ (* b_2 -2.0) a) (* 0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 1.4e+76) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = 0.5 * (c / 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
real(8) :: tmp
if (b_2 <= 1.4d+76) then
tmp = (b_2 * (-2.0d0)) / a
else
tmp = 0.5d0 * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 1.4e+76) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = 0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= 1.4e+76: tmp = (b_2 * -2.0) / a else: tmp = 0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= 1.4e+76) tmp = Float64(Float64(b_2 * -2.0) / a); else tmp = Float64(0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= 1.4e+76) tmp = (b_2 * -2.0) / a; else tmp = 0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, 1.4e+76], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq 1.4 \cdot 10^{+76}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{c}{b\_2}\\
\end{array}
\end{array}
if b_2 < 1.3999999999999999e76Initial program 59.8%
+-commutative59.8%
unsub-neg59.8%
Simplified59.8%
Taylor expanded in b_2 around -inf 40.6%
*-commutative40.6%
Simplified40.6%
if 1.3999999999999999e76 < b_2 Initial program 14.6%
+-commutative14.6%
unsub-neg14.6%
Simplified14.6%
Taylor expanded in b_2 around -inf 2.2%
associate-*r*2.2%
neg-mul-12.2%
associate-/l*2.4%
Simplified2.4%
Taylor expanded in b_2 around 0 36.6%
(FPCore (a b_2 c) :precision binary64 (* 0.5 (/ c b_2)))
double code(double a, double b_2, double c) {
return 0.5 * (c / b_2);
}
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 = 0.5d0 * (c / b_2)
end function
public static double code(double a, double b_2, double c) {
return 0.5 * (c / b_2);
}
def code(a, b_2, c): return 0.5 * (c / b_2)
function code(a, b_2, c) return Float64(0.5 * Float64(c / b_2)) end
function tmp = code(a, b_2, c) tmp = 0.5 * (c / b_2); end
code[a_, b$95$2_, c_] := N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.5 \cdot \frac{c}{b\_2}
\end{array}
Initial program 48.7%
+-commutative48.7%
unsub-neg48.7%
Simplified48.7%
Taylor expanded in b_2 around -inf 26.5%
associate-*r*26.5%
neg-mul-126.5%
associate-/l*29.7%
Simplified29.7%
Taylor expanded in b_2 around 0 11.3%
(FPCore (a b_2 c)
:precision binary64
(let* ((t_0 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_1
(if (== (copysign a c) a)
(* (sqrt (- (fabs b_2) t_0)) (sqrt (+ (fabs b_2) t_0)))
(hypot b_2 t_0))))
(if (< b_2 0.0) (/ (- t_1 b_2) a) (/ (- c) (+ b_2 t_1)))))
double code(double a, double b_2, double c) {
double t_0 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((fabs(b_2) - t_0)) * sqrt((fabs(b_2) + t_0));
} else {
tmp = hypot(b_2, t_0);
}
double t_1 = tmp;
double tmp_1;
if (b_2 < 0.0) {
tmp_1 = (t_1 - b_2) / a;
} else {
tmp_1 = -c / (b_2 + t_1);
}
return tmp_1;
}
public static double code(double a, double b_2, double c) {
double t_0 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((Math.abs(b_2) - t_0)) * Math.sqrt((Math.abs(b_2) + t_0));
} else {
tmp = Math.hypot(b_2, t_0);
}
double t_1 = tmp;
double tmp_1;
if (b_2 < 0.0) {
tmp_1 = (t_1 - b_2) / a;
} else {
tmp_1 = -c / (b_2 + t_1);
}
return tmp_1;
}
def code(a, b_2, c): t_0 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((math.fabs(b_2) - t_0)) * math.sqrt((math.fabs(b_2) + t_0)) else: tmp = math.hypot(b_2, t_0) t_1 = tmp tmp_1 = 0 if b_2 < 0.0: tmp_1 = (t_1 - b_2) / a else: tmp_1 = -c / (b_2 + t_1) return tmp_1
function code(a, b_2, c) t_0 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(abs(b_2) - t_0)) * sqrt(Float64(abs(b_2) + t_0))); else tmp = hypot(b_2, t_0); end t_1 = tmp tmp_1 = 0.0 if (b_2 < 0.0) tmp_1 = Float64(Float64(t_1 - b_2) / a); else tmp_1 = Float64(Float64(-c) / Float64(b_2 + t_1)); end return tmp_1 end
function tmp_3 = code(a, b_2, c) t_0 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((abs(b_2) - t_0)) * sqrt((abs(b_2) + t_0)); else tmp = hypot(b_2, t_0); end t_1 = tmp; tmp_2 = 0.0; if (b_2 < 0.0) tmp_2 = (t_1 - b_2) / a; else tmp_2 = -c / (b_2 + t_1); end tmp_3 = tmp_2; end
code[a_, b$95$2_, c_] := Block[{t$95$0 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(N[Abs[b$95$2], $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(N[Abs[b$95$2], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[b$95$2 ^ 2 + t$95$0 ^ 2], $MachinePrecision]]}, If[Less[b$95$2, 0.0], N[(N[(t$95$1 - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(b$95$2 + t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_1 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{\left|b\_2\right| - t\_0} \cdot \sqrt{\left|b\_2\right| + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(b\_2, t\_0\right)\\
\end{array}\\
\mathbf{if}\;b\_2 < 0:\\
\;\;\;\;\frac{t\_1 - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b\_2 + t\_1}\\
\end{array}
\end{array}
herbie shell --seed 2024106
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
:herbie-expected 10
:alt
(if (< b_2 0.0) (/ (- (if (== (copysign a c) a) (* (sqrt (- (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot b_2 (* (sqrt (fabs a)) (sqrt (fabs c))))) b_2) a) (/ (- c) (+ b_2 (if (== (copysign a c) a) (* (sqrt (- (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot b_2 (* (sqrt (fabs a)) (sqrt (fabs c))))))))
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))