
(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 10 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 -9.5e-93)
(/ (* -0.5 c) b_2)
(if (<= b_2 5e+74)
(/ (+ b_2 (sqrt (- (* b_2 b_2) (* c a)))) (- a))
(/ (- (- b_2) (* b_2 (sqrt (- 1.0 (* a (* c (pow b_2 -2.0))))))) a))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -9.5e-93) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 5e+74) {
tmp = (b_2 + sqrt(((b_2 * b_2) - (c * a)))) / -a;
} else {
tmp = (-b_2 - (b_2 * sqrt((1.0 - (a * (c * pow(b_2, -2.0))))))) / 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 <= (-9.5d-93)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 5d+74) then
tmp = (b_2 + sqrt(((b_2 * b_2) - (c * a)))) / -a
else
tmp = (-b_2 - (b_2 * sqrt((1.0d0 - (a * (c * (b_2 ** (-2.0d0)))))))) / a
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -9.5e-93) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 5e+74) {
tmp = (b_2 + Math.sqrt(((b_2 * b_2) - (c * a)))) / -a;
} else {
tmp = (-b_2 - (b_2 * Math.sqrt((1.0 - (a * (c * Math.pow(b_2, -2.0))))))) / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -9.5e-93: tmp = (-0.5 * c) / b_2 elif b_2 <= 5e+74: tmp = (b_2 + math.sqrt(((b_2 * b_2) - (c * a)))) / -a else: tmp = (-b_2 - (b_2 * math.sqrt((1.0 - (a * (c * math.pow(b_2, -2.0))))))) / a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -9.5e-93) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 5e+74) tmp = Float64(Float64(b_2 + sqrt(Float64(Float64(b_2 * b_2) - Float64(c * a)))) / Float64(-a)); else tmp = Float64(Float64(Float64(-b_2) - Float64(b_2 * sqrt(Float64(1.0 - Float64(a * Float64(c * (b_2 ^ -2.0))))))) / a); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -9.5e-93) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 5e+74) tmp = (b_2 + sqrt(((b_2 * b_2) - (c * a)))) / -a; else tmp = (-b_2 - (b_2 * sqrt((1.0 - (a * (c * (b_2 ^ -2.0))))))) / a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -9.5e-93], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 5e+74], 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[((-b$95$2) - N[(b$95$2 * N[Sqrt[N[(1.0 - N[(a * N[(c * N[Power[b$95$2, -2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -9.5 \cdot 10^{-93}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 5 \cdot 10^{+74}:\\
\;\;\;\;\frac{b\_2 + \sqrt{b\_2 \cdot b\_2 - c \cdot a}}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\_2\right) - b\_2 \cdot \sqrt{1 - a \cdot \left(c \cdot {b\_2}^{-2}\right)}}{a}\\
\end{array}
\end{array}
if b_2 < -9.5000000000000001e-93Initial program 17.1%
Taylor expanded in b_2 around -inf 85.6%
associate-*r/85.6%
Simplified85.6%
if -9.5000000000000001e-93 < b_2 < 4.99999999999999963e74Initial program 79.4%
if 4.99999999999999963e74 < b_2 Initial program 50.7%
Taylor expanded in b_2 around inf 50.4%
mul-1-neg50.4%
unsub-neg50.4%
associate-/l*50.7%
Simplified50.7%
*-commutative50.7%
sqrt-prod55.5%
div-inv55.5%
pow-flip55.5%
metadata-eval55.5%
sqrt-pow197.9%
metadata-eval97.9%
pow197.9%
Applied egg-rr97.9%
Final simplification86.0%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.9e-93)
(/ (* -0.5 c) b_2)
(if (<= b_2 4e+81)
(/ (+ 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 <= -1.9e-93) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 4e+81) {
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 <= (-1.9d-93)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 4d+81) 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 <= -1.9e-93) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 4e+81) {
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 <= -1.9e-93: tmp = (-0.5 * c) / b_2 elif b_2 <= 4e+81: 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 <= -1.9e-93) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 4e+81) tmp = Float64(Float64(b_2 + sqrt(Float64(Float64(b_2 * b_2) - Float64(c * a)))) / 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 <= -1.9e-93) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 4e+81) 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, -1.9e-93], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 4e+81], 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 -1.9 \cdot 10^{-93}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 4 \cdot 10^{+81}:\\
\;\;\;\;\frac{b\_2 + \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 < -1.8999999999999999e-93Initial program 17.1%
Taylor expanded in b_2 around -inf 85.6%
associate-*r/85.6%
Simplified85.6%
if -1.8999999999999999e-93 < b_2 < 3.99999999999999969e81Initial program 79.4%
if 3.99999999999999969e81 < b_2 Initial program 50.7%
Taylor expanded in c around 0 93.9%
Final simplification85.1%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -2.8e-93)
(/ (* -0.5 c) b_2)
(if (<= b_2 6.2e-5)
(/ (- (- b_2) (sqrt (* 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 <= -2.8e-93) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 6.2e-5) {
tmp = (-b_2 - sqrt((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 <= (-2.8d-93)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 6.2d-5) then
tmp = (-b_2 - sqrt((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 <= -2.8e-93) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 6.2e-5) {
tmp = (-b_2 - Math.sqrt((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 <= -2.8e-93: tmp = (-0.5 * c) / b_2 elif b_2 <= 6.2e-5: tmp = (-b_2 - math.sqrt((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 <= -2.8e-93) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 6.2e-5) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(c * Float64(-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 <= -2.8e-93) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 6.2e-5) tmp = (-b_2 - sqrt((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, -2.8e-93], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 6.2e-5], N[(N[((-b$95$2) - N[Sqrt[N[(c * (-a)), $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 -2.8 \cdot 10^{-93}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 6.2 \cdot 10^{-5}:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{c \cdot \left(-a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\end{array}
\end{array}
if b_2 < -2.79999999999999998e-93Initial program 17.1%
Taylor expanded in b_2 around -inf 85.6%
associate-*r/85.6%
Simplified85.6%
if -2.79999999999999998e-93 < b_2 < 6.20000000000000027e-5Initial program 76.8%
Taylor expanded in b_2 around 0 68.4%
mul-1-neg68.4%
distribute-rgt-neg-out68.4%
Simplified68.4%
if 6.20000000000000027e-5 < b_2 Initial program 60.6%
Taylor expanded in c around 0 90.7%
Final simplification81.6%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1e-92)
(/ (* -0.5 c) b_2)
(if (<= b_2 6.2e-5)
(/ (sqrt (* 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 <= -1e-92) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 6.2e-5) {
tmp = sqrt((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 <= (-1d-92)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 6.2d-5) then
tmp = sqrt((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 <= -1e-92) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 6.2e-5) {
tmp = Math.sqrt((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 <= -1e-92: tmp = (-0.5 * c) / b_2 elif b_2 <= 6.2e-5: tmp = math.sqrt((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 <= -1e-92) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 6.2e-5) tmp = Float64(sqrt(Float64(c * Float64(-a))) / 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 <= -1e-92) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 6.2e-5) tmp = sqrt((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, -1e-92], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 6.2e-5], N[(N[Sqrt[N[(c * (-a)), $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 -1 \cdot 10^{-92}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 6.2 \cdot 10^{-5}:\\
\;\;\;\;\frac{\sqrt{c \cdot \left(-a\right)}}{-a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\end{array}
\end{array}
if b_2 < -9.99999999999999988e-93Initial program 17.1%
Taylor expanded in b_2 around -inf 85.6%
associate-*r/85.6%
Simplified85.6%
if -9.99999999999999988e-93 < b_2 < 6.20000000000000027e-5Initial program 76.8%
prod-diff76.3%
*-commutative76.3%
fmm-def76.3%
prod-diff76.3%
*-commutative76.3%
fmm-def76.3%
associate-+l+76.2%
pow276.2%
*-commutative76.2%
fma-undefine76.3%
distribute-lft-neg-in76.3%
*-commutative76.3%
distribute-rgt-neg-in76.3%
fma-define76.2%
*-commutative76.2%
fma-undefine76.3%
distribute-lft-neg-in76.3%
*-commutative76.3%
distribute-rgt-neg-in76.3%
Applied egg-rr76.2%
count-276.2%
Simplified76.2%
Taylor expanded in b_2 around 0 66.0%
mul-1-neg66.0%
distribute-lft1-in66.0%
metadata-eval66.0%
mul0-lft66.6%
metadata-eval66.6%
neg-sub066.6%
*-commutative66.6%
distribute-rgt-neg-in66.6%
Simplified66.6%
if 6.20000000000000027e-5 < b_2 Initial program 60.6%
Taylor expanded in c around 0 90.7%
Final simplification81.0%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.2e-178)
(/ (* -0.5 c) b_2)
(if (<= b_2 2.9e-74)
(- (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 <= -1.2e-178) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 2.9e-74) {
tmp = -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 <= (-1.2d-178)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 2.9d-74) then
tmp = -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 <= -1.2e-178) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 2.9e-74) {
tmp = -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 <= -1.2e-178: tmp = (-0.5 * c) / b_2 elif b_2 <= 2.9e-74: tmp = -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 <= -1.2e-178) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 2.9e-74) tmp = Float64(-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 <= -1.2e-178) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 2.9e-74) tmp = -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, -1.2e-178], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 2.9e-74], (-N[Sqrt[N[(c / (-a)), $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 -1.2 \cdot 10^{-178}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 2.9 \cdot 10^{-74}:\\
\;\;\;\;-\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 < -1.20000000000000002e-178Initial program 26.3%
Taylor expanded in b_2 around -inf 75.8%
associate-*r/75.8%
Simplified75.8%
if -1.20000000000000002e-178 < b_2 < 2.9e-74Initial program 70.2%
prod-diff69.4%
*-commutative69.4%
fmm-def69.4%
prod-diff69.4%
*-commutative69.4%
fmm-def69.4%
associate-+l+69.3%
pow269.3%
*-commutative69.3%
fma-undefine69.4%
distribute-lft-neg-in69.4%
*-commutative69.4%
distribute-rgt-neg-in69.4%
fma-define69.3%
*-commutative69.3%
fma-undefine69.4%
distribute-lft-neg-in69.4%
*-commutative69.4%
distribute-rgt-neg-in69.4%
Applied egg-rr69.3%
count-269.3%
Simplified69.3%
Taylor expanded in a around inf 40.3%
mul-1-neg40.3%
distribute-rgt1-in40.3%
metadata-eval40.3%
mul0-lft40.3%
metadata-eval40.3%
neg-sub040.3%
Simplified40.3%
if 2.9e-74 < b_2 Initial program 66.8%
Taylor expanded in c around 0 81.8%
Final simplification71.4%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -5e-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 <= -5e-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 <= (-5d-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 <= -5e-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 <= -5e-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 <= -5e-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 <= -5e-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, -5e-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 -5 \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 < -4.999999999999985e-310Initial program 33.1%
Taylor expanded in b_2 around -inf 64.8%
associate-*r/64.8%
Simplified64.8%
if -4.999999999999985e-310 < b_2 Initial program 67.5%
Taylor expanded in c around 0 66.1%
Final simplification65.4%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -8e-6) (* 0.5 (/ c b_2)) (/ b_2 (- a))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -8e-6) {
tmp = 0.5 * (c / b_2);
} else {
tmp = 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 <= (-8d-6)) then
tmp = 0.5d0 * (c / b_2)
else
tmp = 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 <= -8e-6) {
tmp = 0.5 * (c / b_2);
} else {
tmp = b_2 / -a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -8e-6: tmp = 0.5 * (c / b_2) else: tmp = b_2 / -a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -8e-6) tmp = Float64(0.5 * Float64(c / b_2)); else tmp = Float64(b_2 / Float64(-a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -8e-6) tmp = 0.5 * (c / b_2); else tmp = b_2 / -a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -8e-6], N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], N[(b$95$2 / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -8 \cdot 10^{-6}:\\
\;\;\;\;0.5 \cdot \frac{c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b\_2}{-a}\\
\end{array}
\end{array}
if b_2 < -7.99999999999999964e-6Initial program 13.6%
Taylor expanded in a around 0 2.3%
Taylor expanded in a around inf 35.5%
if -7.99999999999999964e-6 < b_2 Initial program 65.7%
Taylor expanded in b_2 around inf 43.3%
mul-1-neg43.3%
unsub-neg43.3%
associate-/l*40.8%
Simplified40.8%
add-sqr-sqrt40.8%
rem-sqrt-square40.8%
sqrt-prod42.5%
sqrt-pow157.6%
metadata-eval57.6%
pow157.6%
div-inv56.7%
pow-flip56.7%
metadata-eval56.7%
Applied egg-rr56.7%
Taylor expanded in b_2 around inf 22.0%
mul-1-neg22.0%
Simplified22.0%
Final simplification26.1%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2.15e-275) (/ (* -0.5 c) b_2) (/ b_2 (- a))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.15e-275) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = 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 <= (-2.15d-275)) then
tmp = ((-0.5d0) * c) / b_2
else
tmp = 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 <= -2.15e-275) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = b_2 / -a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2.15e-275: tmp = (-0.5 * c) / b_2 else: tmp = b_2 / -a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2.15e-275) tmp = Float64(Float64(-0.5 * c) / b_2); else tmp = Float64(b_2 / Float64(-a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2.15e-275) tmp = (-0.5 * c) / b_2; else tmp = b_2 / -a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2.15e-275], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], N[(b$95$2 / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2.15 \cdot 10^{-275}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b\_2}{-a}\\
\end{array}
\end{array}
if b_2 < -2.14999999999999988e-275Initial program 31.3%
Taylor expanded in b_2 around -inf 67.3%
associate-*r/67.3%
Simplified67.3%
if -2.14999999999999988e-275 < b_2 Initial program 67.9%
Taylor expanded in b_2 around inf 51.8%
mul-1-neg51.8%
unsub-neg51.8%
associate-/l*51.2%
Simplified51.2%
add-sqr-sqrt51.2%
rem-sqrt-square51.2%
sqrt-prod53.4%
sqrt-pow173.9%
metadata-eval73.9%
pow173.9%
div-inv73.1%
pow-flip73.1%
metadata-eval73.1%
Applied egg-rr73.1%
Taylor expanded in b_2 around inf 29.0%
mul-1-neg29.0%
Simplified29.0%
Final simplification47.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2.9e-275) (/ (* -0.5 c) b_2) (/ (* b_2 -2.0) a)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.9e-275) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = (b_2 * -2.0) / 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 <= (-2.9d-275)) then
tmp = ((-0.5d0) * c) / b_2
else
tmp = (b_2 * (-2.0d0)) / a
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.9e-275) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = (b_2 * -2.0) / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2.9e-275: tmp = (-0.5 * c) / b_2 else: tmp = (b_2 * -2.0) / a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2.9e-275) tmp = Float64(Float64(-0.5 * c) / b_2); else tmp = Float64(Float64(b_2 * -2.0) / a); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2.9e-275) tmp = (-0.5 * c) / b_2; else tmp = (b_2 * -2.0) / a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2.9e-275], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2.9 \cdot 10^{-275}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\end{array}
\end{array}
if b_2 < -2.9e-275Initial program 31.3%
Taylor expanded in b_2 around -inf 67.3%
associate-*r/67.3%
Simplified67.3%
if -2.9e-275 < b_2 Initial program 67.9%
Taylor expanded in b_2 around inf 63.3%
*-commutative63.3%
Simplified63.3%
Final simplification65.2%
(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(b_2 / Float64(-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 50.0%
Taylor expanded in b_2 around inf 34.3%
mul-1-neg34.3%
unsub-neg34.3%
associate-/l*32.6%
Simplified32.6%
add-sqr-sqrt32.6%
rem-sqrt-square32.6%
sqrt-prod34.2%
sqrt-pow153.3%
metadata-eval53.3%
pow153.3%
div-inv52.7%
pow-flip52.7%
metadata-eval52.7%
Applied egg-rr52.7%
Taylor expanded in b_2 around inf 16.2%
mul-1-neg16.2%
Simplified16.2%
Final simplification16.2%
(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 2024112
(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))