
(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 7 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 -1.75e-96)
(* -0.5 (/ c b_2))
(if (<= b_2 7.5e+69)
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* c a)))) a)
(+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.75e-96) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 7.5e+69) {
tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a;
} else {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
}
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.75d-96)) then
tmp = (-0.5d0) * (c / b_2)
else if (b_2 <= 7.5d+69) then
tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a
else
tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.75e-96) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 7.5e+69) {
tmp = (-b_2 - Math.sqrt(((b_2 * b_2) - (c * a)))) / a;
} else {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.75e-96: tmp = -0.5 * (c / b_2) elif b_2 <= 7.5e+69: tmp = (-b_2 - math.sqrt(((b_2 * b_2) - (c * a)))) / a else: tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.75e-96) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 7.5e+69) 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(Float64(c / b_2) * 0.5)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.75e-96) tmp = -0.5 * (c / b_2); elseif (b_2 <= 7.5e+69) tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a; else tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.75e-96], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 7.5e+69], 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[(N[(c / b$95$2), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.75 \cdot 10^{-96}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\mathbf{elif}\;b_2 \leq 7.5 \cdot 10^{+69}:\\
\;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\
\end{array}
\end{array}
if b_2 < -1.7499999999999999e-96Initial program 13.6%
Taylor expanded in b_2 around -inf 89.7%
if -1.7499999999999999e-96 < b_2 < 7.49999999999999939e69Initial program 83.0%
if 7.49999999999999939e69 < b_2 Initial program 62.2%
Taylor expanded in b_2 around inf 95.1%
Final simplification89.0%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -1.65e-96)
(* -0.5 (/ c b_2))
(if (<= b_2 2.7e-77)
(/ (- (- b_2) (sqrt (* c (- a)))) a)
(+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.65e-96) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 2.7e-77) {
tmp = (-b_2 - sqrt((c * -a))) / a;
} else {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
}
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.65d-96)) then
tmp = (-0.5d0) * (c / b_2)
else if (b_2 <= 2.7d-77) then
tmp = (-b_2 - sqrt((c * -a))) / a
else
tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.65e-96) {
tmp = -0.5 * (c / b_2);
} else if (b_2 <= 2.7e-77) {
tmp = (-b_2 - Math.sqrt((c * -a))) / a;
} else {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.65e-96: tmp = -0.5 * (c / b_2) elif b_2 <= 2.7e-77: tmp = (-b_2 - math.sqrt((c * -a))) / a else: tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.65e-96) tmp = Float64(-0.5 * Float64(c / b_2)); elseif (b_2 <= 2.7e-77) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(c * Float64(-a)))) / a); else tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(Float64(c / b_2) * 0.5)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.65e-96) tmp = -0.5 * (c / b_2); elseif (b_2 <= 2.7e-77) tmp = (-b_2 - sqrt((c * -a))) / a; else tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.65e-96], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 2.7e-77], 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[(N[(c / b$95$2), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.65 \cdot 10^{-96}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\mathbf{elif}\;b_2 \leq 2.7 \cdot 10^{-77}:\\
\;\;\;\;\frac{\left(-b_2\right) - \sqrt{c \cdot \left(-a\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\
\end{array}
\end{array}
if b_2 < -1.64999999999999995e-96Initial program 13.6%
Taylor expanded in b_2 around -inf 89.7%
if -1.64999999999999995e-96 < b_2 < 2.7e-77Initial program 76.5%
Taylor expanded in b_2 around 0 69.2%
associate-*r*69.2%
neg-mul-169.2%
*-commutative69.2%
Simplified69.2%
if 2.7e-77 < b_2 Initial program 71.5%
Taylor expanded in b_2 around inf 91.8%
Final simplification85.4%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-310) (* -0.5 (/ c b_2)) (+ (* -2.0 (/ b_2 a)) (* (/ c b_2) 0.5))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-310) {
tmp = -0.5 * (c / b_2);
} else {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
}
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 = (-0.5d0) * (c / b_2)
else
tmp = ((-2.0d0) * (b_2 / a)) + ((c / b_2) * 0.5d0)
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 = -0.5 * (c / b_2);
} else {
tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-310: tmp = -0.5 * (c / b_2) else: tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-310) tmp = Float64(-0.5 * Float64(c / b_2)); else tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(Float64(c / b_2) * 0.5)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-310) tmp = -0.5 * (c / b_2); else tmp = (-2.0 * (b_2 / a)) + ((c / b_2) * 0.5); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-310], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(N[(c / b$95$2), $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -2 \cdot 10^{-310}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b_2}{a} + \frac{c}{b_2} \cdot 0.5\\
\end{array}
\end{array}
if b_2 < -1.999999999999994e-310Initial program 27.6%
Taylor expanded in b_2 around -inf 72.9%
if -1.999999999999994e-310 < b_2 Initial program 75.2%
Taylor expanded in b_2 around inf 75.0%
Final simplification74.0%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-310) (* -0.5 (/ c b_2)) (/ (- b_2) a)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-310) {
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 <= (-2d-310)) 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 <= -2e-310) {
tmp = -0.5 * (c / b_2);
} else {
tmp = -b_2 / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-310: 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 <= -2e-310) tmp = Float64(-0.5 * Float64(c / b_2)); else tmp = Float64(Float64(-b_2) / a); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-310) 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, -2e-310], 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 -2 \cdot 10^{-310}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b_2}{a}\\
\end{array}
\end{array}
if b_2 < -1.999999999999994e-310Initial program 27.6%
Taylor expanded in b_2 around -inf 72.9%
if -1.999999999999994e-310 < b_2 Initial program 75.2%
add-sqr-sqrt75.0%
pow275.0%
pow1/275.0%
sqrt-pow175.0%
metadata-eval75.0%
Applied egg-rr75.0%
Taylor expanded in b_2 around inf 28.1%
mul-1-neg28.1%
Simplified28.1%
Final simplification49.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -3e-308) (* -0.5 (/ c b_2)) (/ (* b_2 -2.0) a)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -3e-308) {
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 <= (-3d-308)) 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 <= -3e-308) {
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 <= -3e-308: 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 <= -3e-308) tmp = Float64(-0.5 * Float64(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 <= -3e-308) 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, -3e-308], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -3 \cdot 10^{-308}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b_2 \cdot -2}{a}\\
\end{array}
\end{array}
if b_2 < -3.00000000000000022e-308Initial program 27.6%
Taylor expanded in b_2 around -inf 72.9%
if -3.00000000000000022e-308 < b_2 Initial program 75.2%
Taylor expanded in b_2 around inf 74.7%
*-commutative74.7%
Simplified74.7%
Final simplification73.9%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-310) (/ 0.0 a) (/ (- b_2) a)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-310) {
tmp = 0.0 / a;
} 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 <= (-2d-310)) then
tmp = 0.0d0 / a
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 <= -2e-310) {
tmp = 0.0 / a;
} else {
tmp = -b_2 / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-310: tmp = 0.0 / a else: tmp = -b_2 / a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-310) tmp = Float64(0.0 / a); else tmp = Float64(Float64(-b_2) / a); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-310) tmp = 0.0 / a; else tmp = -b_2 / a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-310], N[(0.0 / a), $MachinePrecision], N[((-b$95$2) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{0}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b_2}{a}\\
\end{array}
\end{array}
if b_2 < -1.999999999999994e-310Initial program 27.6%
add-sqr-sqrt24.0%
pow224.0%
pow1/224.0%
sqrt-pow123.9%
metadata-eval23.9%
Applied egg-rr23.9%
Taylor expanded in b_2 around -inf 17.9%
distribute-rgt1-in17.9%
metadata-eval17.9%
mul0-lft17.9%
Simplified17.9%
if -1.999999999999994e-310 < b_2 Initial program 75.2%
add-sqr-sqrt75.0%
pow275.0%
pow1/275.0%
sqrt-pow175.0%
metadata-eval75.0%
Applied egg-rr75.0%
Taylor expanded in b_2 around inf 28.1%
mul-1-neg28.1%
Simplified28.1%
Final simplification23.2%
(FPCore (a b_2 c) :precision binary64 (/ 0.0 a))
double code(double a, double b_2, double c) {
return 0.0 / 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 = 0.0d0 / a
end function
public static double code(double a, double b_2, double c) {
return 0.0 / a;
}
def code(a, b_2, c): return 0.0 / a
function code(a, b_2, c) return Float64(0.0 / a) end
function tmp = code(a, b_2, c) tmp = 0.0 / a; end
code[a_, b$95$2_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 52.2%
add-sqr-sqrt50.3%
pow250.3%
pow1/250.3%
sqrt-pow150.3%
metadata-eval50.3%
Applied egg-rr50.3%
Taylor expanded in b_2 around -inf 10.0%
distribute-rgt1-in10.0%
metadata-eval10.0%
mul0-lft10.0%
Simplified10.0%
Final simplification10.0%
herbie shell --seed 2023275
(FPCore (a b_2 c)
:name "quad2m (problem 3.2.1, negative)"
:precision binary64
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))