
(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 -7.5e-27)
(/ (* -0.5 c) b_2)
(if (<= b_2 1e+92)
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* c a)))) a)
(+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7.5e-27) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 1e+92) {
tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a;
} else {
tmp = (-2.0 * (b_2 / a)) + (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 <= (-7.5d-27)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 1d+92) then
tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a
else
tmp = ((-2.0d0) * (b_2 / a)) + (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 <= -7.5e-27) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 1e+92) {
tmp = (-b_2 - Math.sqrt(((b_2 * b_2) - (c * a)))) / a;
} else {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -7.5e-27: tmp = (-0.5 * c) / b_2 elif b_2 <= 1e+92: tmp = (-b_2 - math.sqrt(((b_2 * b_2) - (c * a)))) / a else: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -7.5e-27) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 1e+92) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(c * a)))) / a); else tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + 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 <= -7.5e-27) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 1e+92) tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a; else tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7.5e-27], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 1e+92], N[(N[((-b$95$2) - N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -7.5 \cdot 10^{-27}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 10^{+92}:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - c \cdot a}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\end{array}
\end{array}
if b_2 < -7.50000000000000029e-27Initial program 16.6%
Taylor expanded in b_2 around -inf 89.7%
associate-*r/89.7%
Simplified89.7%
if -7.50000000000000029e-27 < b_2 < 1e92Initial program 77.8%
if 1e92 < b_2 Initial program 60.2%
Taylor expanded in c around 0 98.0%
Final simplification85.7%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -3.7e-150)
(/ (* -0.5 c) b_2)
(if (<= b_2 1.2e-73)
(- (/ (- b_2) a) (sqrt (/ c (- a))))
(+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -3.7e-150) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 1.2e-73) {
tmp = (-b_2 / a) - sqrt((c / -a));
} else {
tmp = (-2.0 * (b_2 / a)) + (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 <= (-3.7d-150)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 1.2d-73) then
tmp = (-b_2 / a) - sqrt((c / -a))
else
tmp = ((-2.0d0) * (b_2 / a)) + (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 <= -3.7e-150) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 1.2e-73) {
tmp = (-b_2 / a) - Math.sqrt((c / -a));
} else {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -3.7e-150: tmp = (-0.5 * c) / b_2 elif b_2 <= 1.2e-73: tmp = (-b_2 / a) - math.sqrt((c / -a)) else: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -3.7e-150) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 1.2e-73) tmp = Float64(Float64(Float64(-b_2) / a) - sqrt(Float64(c / Float64(-a)))); else tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + 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 <= -3.7e-150) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 1.2e-73) tmp = (-b_2 / a) - sqrt((c / -a)); else tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -3.7e-150], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 1.2e-73], N[(N[((-b$95$2) / a), $MachinePrecision] - N[Sqrt[N[(c / (-a)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -3.7 \cdot 10^{-150}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 1.2 \cdot 10^{-73}:\\
\;\;\;\;\frac{-b\_2}{a} - \sqrt{\frac{c}{-a}}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\end{array}
\end{array}
if b_2 < -3.70000000000000001e-150Initial program 28.5%
Taylor expanded in b_2 around -inf 76.0%
associate-*r/76.0%
Simplified76.0%
if -3.70000000000000001e-150 < b_2 < 1.20000000000000003e-73Initial program 80.6%
prod-diff80.2%
*-commutative80.2%
fma-neg80.2%
prod-diff80.2%
*-commutative80.2%
fma-neg80.2%
associate-+l+80.0%
pow280.0%
*-commutative80.0%
fma-undefine80.2%
distribute-lft-neg-in80.2%
*-commutative80.2%
distribute-rgt-neg-in80.2%
fma-define80.0%
*-commutative80.0%
fma-undefine80.2%
distribute-lft-neg-in80.2%
*-commutative80.2%
distribute-rgt-neg-in80.2%
Applied egg-rr80.0%
count-280.0%
Simplified80.0%
Taylor expanded in a around inf 33.3%
+-commutative33.3%
mul-1-neg33.3%
sub-neg33.3%
associate-*r/33.3%
mul-1-neg33.3%
*-commutative33.3%
distribute-rgt1-in33.3%
metadata-eval33.3%
Simplified33.3%
*-un-lft-identity33.3%
add-log-exp5.0%
*-commutative5.0%
mul0-lft5.0%
metadata-eval5.0%
mul0-lft5.0%
exp-diff5.0%
mul0-lft5.0%
exp-05.0%
neg-log5.0%
add-log-exp33.3%
Applied egg-rr33.3%
*-lft-identity33.3%
Simplified33.3%
if 1.20000000000000003e-73 < b_2 Initial program 71.3%
Taylor expanded in c around 0 77.8%
Final simplification68.1%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.22e-61)
(/ (* -0.5 c) b_2)
(if (<= b_2 1.08e-75)
(/ (- (- b_2) (sqrt (* a (- c)))) a)
(* -2.0 (/ b_2 a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.22e-61) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 1.08e-75) {
tmp = (-b_2 - sqrt((a * -c))) / a;
} else {
tmp = -2.0 * (b_2 / a);
}
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.22d-61)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 1.08d-75) then
tmp = (-b_2 - sqrt((a * -c))) / a
else
tmp = (-2.0d0) * (b_2 / a)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.22e-61) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 1.08e-75) {
tmp = (-b_2 - Math.sqrt((a * -c))) / a;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.22e-61: tmp = (-0.5 * c) / b_2 elif b_2 <= 1.08e-75: tmp = (-b_2 - math.sqrt((a * -c))) / a else: tmp = -2.0 * (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.22e-61) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 1.08e-75) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(a * Float64(-c)))) / a); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.22e-61) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 1.08e-75) tmp = (-b_2 - sqrt((a * -c))) / a; else tmp = -2.0 * (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.22e-61], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 1.08e-75], N[(N[((-b$95$2) - N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.22 \cdot 10^{-61}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 1.08 \cdot 10^{-75}:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -1.22e-61Initial program 18.0%
Taylor expanded in b_2 around -inf 87.2%
associate-*r/87.2%
Simplified87.2%
if -1.22e-61 < b_2 < 1.08e-75Initial program 77.7%
Taylor expanded in b_2 around 0 74.1%
mul-1-neg74.1%
distribute-rgt-neg-out74.1%
Simplified74.1%
if 1.08e-75 < b_2 Initial program 70.5%
Taylor expanded in b_2 around inf 76.9%
Final simplification79.9%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -3.6e-148) (/ (* -0.5 c) b_2) (if (<= b_2 3.6e-141) (- (/ b_2 a) (sqrt (/ c (- a)))) (* -2.0 (/ b_2 a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -3.6e-148) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 3.6e-141) {
tmp = (b_2 / a) - sqrt((c / -a));
} else {
tmp = -2.0 * (b_2 / a);
}
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 <= (-3.6d-148)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 3.6d-141) then
tmp = (b_2 / a) - sqrt((c / -a))
else
tmp = (-2.0d0) * (b_2 / a)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -3.6e-148) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 3.6e-141) {
tmp = (b_2 / a) - Math.sqrt((c / -a));
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -3.6e-148: tmp = (-0.5 * c) / b_2 elif b_2 <= 3.6e-141: tmp = (b_2 / a) - math.sqrt((c / -a)) else: tmp = -2.0 * (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -3.6e-148) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 3.6e-141) tmp = Float64(Float64(b_2 / a) - sqrt(Float64(c / Float64(-a)))); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -3.6e-148) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 3.6e-141) tmp = (b_2 / a) - sqrt((c / -a)); else tmp = -2.0 * (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -3.6e-148], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 3.6e-141], N[(N[(b$95$2 / a), $MachinePrecision] - N[Sqrt[N[(c / (-a)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -3.6 \cdot 10^{-148}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 3.6 \cdot 10^{-141}:\\
\;\;\;\;\frac{b\_2}{a} - \sqrt{\frac{c}{-a}}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -3.5999999999999998e-148Initial program 28.5%
Taylor expanded in b_2 around -inf 76.0%
associate-*r/76.0%
Simplified76.0%
if -3.5999999999999998e-148 < b_2 < 3.60000000000000015e-141Initial program 81.1%
prod-diff80.8%
*-commutative80.8%
fma-neg80.8%
prod-diff80.8%
*-commutative80.8%
fma-neg80.8%
associate-+l+80.5%
pow280.5%
*-commutative80.5%
fma-undefine80.8%
distribute-lft-neg-in80.8%
*-commutative80.8%
distribute-rgt-neg-in80.8%
fma-define80.5%
*-commutative80.5%
fma-undefine80.8%
distribute-lft-neg-in80.8%
*-commutative80.8%
distribute-rgt-neg-in80.8%
Applied egg-rr80.5%
count-280.5%
Simplified80.5%
Taylor expanded in a around inf 37.0%
+-commutative37.0%
mul-1-neg37.0%
sub-neg37.0%
associate-*r/37.0%
mul-1-neg37.0%
*-commutative37.0%
distribute-rgt1-in37.0%
metadata-eval37.0%
Simplified37.0%
sub-neg37.0%
add-sqr-sqrt18.5%
sqrt-unprod36.7%
sqr-neg36.7%
sqrt-prod18.2%
add-sqr-sqrt36.3%
add-log-exp4.1%
*-commutative4.1%
mul0-lft4.1%
metadata-eval4.1%
mul0-lft4.1%
exp-diff4.1%
mul0-lft4.1%
exp-04.1%
neg-log4.1%
add-log-exp36.3%
Applied egg-rr36.3%
sub-neg36.3%
Simplified36.3%
if 3.60000000000000015e-141 < b_2 Initial program 71.9%
Taylor expanded in b_2 around inf 71.8%
Final simplification68.0%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1e-310) (/ (* -0.5 c) b_2) (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1e-310) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = (-2.0 * (b_2 / a)) + (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 <= (-1d-310)) then
tmp = ((-0.5d0) * c) / b_2
else
tmp = ((-2.0d0) * (b_2 / a)) + (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 <= -1e-310) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1e-310: tmp = (-0.5 * c) / b_2 else: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1e-310) tmp = Float64(Float64(-0.5 * c) / b_2); else tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + 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 <= -1e-310) tmp = (-0.5 * c) / b_2; else tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1e-310], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\end{array}
\end{array}
if b_2 < -9.999999999999969e-311Initial program 36.3%
Taylor expanded in b_2 around -inf 66.0%
associate-*r/66.0%
Simplified66.0%
if -9.999999999999969e-311 < b_2 Initial program 73.3%
Taylor expanded in c around 0 59.2%
Final simplification62.9%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1.35e-11) (* 0.5 (/ c b_2)) (* -2.0 (/ b_2 a))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.35e-11) {
tmp = 0.5 * (c / b_2);
} else {
tmp = -2.0 * (b_2 / a);
}
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.35d-11)) then
tmp = 0.5d0 * (c / b_2)
else
tmp = (-2.0d0) * (b_2 / a)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.35e-11) {
tmp = 0.5 * (c / b_2);
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.35e-11: tmp = 0.5 * (c / b_2) else: tmp = -2.0 * (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.35e-11) tmp = Float64(0.5 * Float64(c / b_2)); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.35e-11) tmp = 0.5 * (c / b_2); else tmp = -2.0 * (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.35e-11], N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.35 \cdot 10^{-11}:\\
\;\;\;\;0.5 \cdot \frac{c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -1.35000000000000002e-11Initial program 16.7%
Taylor expanded in c around 0 2.7%
Taylor expanded in b_2 around 0 27.5%
if -1.35000000000000002e-11 < b_2 Initial program 72.5%
Taylor expanded in b_2 around inf 41.8%
Final simplification36.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1.45e-282) (/ (* -0.5 c) b_2) (* -2.0 (/ b_2 a))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.45e-282) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = -2.0 * (b_2 / a);
}
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.45d-282)) then
tmp = ((-0.5d0) * c) / b_2
else
tmp = (-2.0d0) * (b_2 / a)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.45e-282) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.45e-282: tmp = (-0.5 * c) / b_2 else: tmp = -2.0 * (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.45e-282) tmp = Float64(Float64(-0.5 * c) / b_2); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.45e-282) tmp = (-0.5 * c) / b_2; else tmp = -2.0 * (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.45e-282], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.45 \cdot 10^{-282}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -1.44999999999999999e-282Initial program 34.9%
Taylor expanded in b_2 around -inf 67.3%
associate-*r/67.3%
Simplified67.3%
if -1.44999999999999999e-282 < b_2 Initial program 74.0%
Taylor expanded in b_2 around inf 57.7%
Final simplification62.9%
(FPCore (a b_2 c) :precision binary64 (* -2.0 (/ b_2 a)))
double code(double a, double b_2, double c) {
return -2.0 * (b_2 / 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 = (-2.0d0) * (b_2 / a)
end function
public static double code(double a, double b_2, double c) {
return -2.0 * (b_2 / a);
}
def code(a, b_2, c): return -2.0 * (b_2 / a)
function code(a, b_2, c) return Float64(-2.0 * Float64(b_2 / a)) end
function tmp = code(a, b_2, c) tmp = -2.0 * (b_2 / a); end
code[a_, b$95$2_, c_] := N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \frac{b\_2}{a}
\end{array}
Initial program 52.9%
Taylor expanded in b_2 around inf 28.1%
Final simplification28.1%
(FPCore (a b_2 c) :precision binary64 (/ (- b_2) a))
double code(double a, double b_2, double c) {
return -b_2 / 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 / a
end function
public static double code(double a, double b_2, double c) {
return -b_2 / a;
}
def code(a, b_2, c): return -b_2 / a
function code(a, b_2, c) return Float64(Float64(-b_2) / a) end
function tmp = code(a, b_2, c) tmp = -b_2 / a; end
code[a_, b$95$2_, c_] := N[((-b$95$2) / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-b\_2}{a}
\end{array}
Initial program 52.9%
prod-diff52.7%
*-commutative52.7%
fma-neg52.7%
prod-diff52.7%
*-commutative52.7%
fma-neg52.7%
associate-+l+52.6%
pow252.6%
*-commutative52.6%
fma-undefine52.7%
distribute-lft-neg-in52.7%
*-commutative52.7%
distribute-rgt-neg-in52.7%
fma-define52.6%
*-commutative52.6%
fma-undefine52.7%
distribute-lft-neg-in52.7%
*-commutative52.7%
distribute-rgt-neg-in52.7%
Applied egg-rr52.6%
count-252.6%
Simplified52.6%
Taylor expanded in a around inf 20.1%
+-commutative20.1%
mul-1-neg20.1%
sub-neg20.1%
associate-*r/20.1%
mul-1-neg20.1%
*-commutative20.1%
distribute-rgt1-in20.1%
metadata-eval20.1%
Simplified20.1%
Taylor expanded in b_2 around inf 13.8%
associate-*r/13.8%
mul-1-neg13.8%
Simplified13.8%
Final simplification13.8%
(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) (/ c (- t_1 b_2)) (/ (+ b_2 t_1) (- a)))))
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 = c / (t_1 - b_2);
} else {
tmp_1 = (b_2 + t_1) / -a;
}
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 = c / (t_1 - b_2);
} else {
tmp_1 = (b_2 + t_1) / -a;
}
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 = c / (t_1 - b_2) else: tmp_1 = (b_2 + t_1) / -a 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(c / Float64(t_1 - b_2)); else tmp_1 = Float64(Float64(b_2 + t_1) / Float64(-a)); 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 = c / (t_1 - b_2); else tmp_2 = (b_2 + t_1) / -a; 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[(c / N[(t$95$1 - b$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(b$95$2 + t$95$1), $MachinePrecision] / (-a)), $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{c}{t\_1 - b\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b\_2 + t\_1}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2024083
(FPCore (a b_2 c)
:name "quad2m (problem 3.2.1, negative)"
:precision binary64
:herbie-expected 10
:alt
(if (< b_2 0.0) (/ c (- (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)) (/ (+ 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)))))) (- a)))
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))