
(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 8 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 -3.8e+31)
(/ (* -0.5 c) b_2)
(if (<= b_2 -1.72e-217)
(/ (/ (* a (- c)) (- b_2 (sqrt (- (pow b_2 2.0) (* c a))))) a)
(if (<= b_2 4.6e+57)
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* c a)))) a)
(- (- (* 0.5 (/ c b_2)) (/ b_2 a)) (/ b_2 a))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -3.8e+31) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= -1.72e-217) {
tmp = ((a * -c) / (b_2 - sqrt((pow(b_2, 2.0) - (c * a))))) / a;
} else if (b_2 <= 4.6e+57) {
tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a;
} else {
tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (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.8d+31)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= (-1.72d-217)) then
tmp = ((a * -c) / (b_2 - sqrt(((b_2 ** 2.0d0) - (c * a))))) / a
else if (b_2 <= 4.6d+57) then
tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a
else
tmp = ((0.5d0 * (c / b_2)) - (b_2 / a)) - (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.8e+31) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= -1.72e-217) {
tmp = ((a * -c) / (b_2 - Math.sqrt((Math.pow(b_2, 2.0) - (c * a))))) / a;
} else if (b_2 <= 4.6e+57) {
tmp = (-b_2 - Math.sqrt(((b_2 * b_2) - (c * a)))) / a;
} else {
tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -3.8e+31: tmp = (-0.5 * c) / b_2 elif b_2 <= -1.72e-217: tmp = ((a * -c) / (b_2 - math.sqrt((math.pow(b_2, 2.0) - (c * a))))) / a elif b_2 <= 4.6e+57: tmp = (-b_2 - math.sqrt(((b_2 * b_2) - (c * a)))) / a else: tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -3.8e+31) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= -1.72e-217) tmp = Float64(Float64(Float64(a * Float64(-c)) / Float64(b_2 - sqrt(Float64((b_2 ^ 2.0) - Float64(c * a))))) / a); elseif (b_2 <= 4.6e+57) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(c * a)))) / a); else tmp = Float64(Float64(Float64(0.5 * Float64(c / b_2)) - Float64(b_2 / a)) - Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -3.8e+31) tmp = (-0.5 * c) / b_2; elseif (b_2 <= -1.72e-217) tmp = ((a * -c) / (b_2 - sqrt(((b_2 ^ 2.0) - (c * a))))) / a; elseif (b_2 <= 4.6e+57) tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a; else tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -3.8e+31], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, -1.72e-217], N[(N[(N[(a * (-c)), $MachinePrecision] / N[(b$95$2 - N[Sqrt[N[(N[Power[b$95$2, 2.0], $MachinePrecision] - N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 4.6e+57], 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[(N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -3.8 \cdot 10^{+31}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\
\mathbf{elif}\;b_2 \leq -1.72 \cdot 10^{-217}:\\
\;\;\;\;\frac{\frac{a \cdot \left(-c\right)}{b_2 - \sqrt{{b_2}^{2} - c \cdot a}}}{a}\\
\mathbf{elif}\;b_2 \leq 4.6 \cdot 10^{+57}:\\
\;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \frac{c}{b_2} - \frac{b_2}{a}\right) - \frac{b_2}{a}\\
\end{array}
\end{array}
if b_2 < -3.8000000000000001e31Initial program 13.2%
div-sub10.0%
neg-sub010.0%
div-sub10.0%
associate--l-10.0%
+-commutative10.0%
pow210.0%
Applied egg-rr10.0%
associate--r+10.0%
div010.0%
neg-sub010.0%
distribute-neg-frac10.0%
Simplified10.0%
Taylor expanded in b_2 around -inf 90.8%
associate-*r/90.9%
Simplified90.9%
if -3.8000000000000001e31 < b_2 < -1.72e-217Initial program 38.6%
add-sqr-sqrt38.2%
pow238.2%
pow1/238.2%
sqrt-pow138.2%
pow238.2%
metadata-eval38.2%
Applied egg-rr38.2%
flip--38.0%
frac-2neg38.0%
Applied egg-rr67.9%
neg-sub067.9%
+-inverses67.9%
+-commutative67.9%
associate--r+67.9%
+-inverses67.9%
+-inverses67.9%
metadata-eval67.9%
neg-sub067.9%
distribute-rgt-neg-in67.9%
Simplified67.9%
if -1.72e-217 < b_2 < 4.5999999999999998e57Initial program 89.0%
if 4.5999999999999998e57 < b_2 Initial program 58.6%
div-sub58.6%
neg-sub058.6%
div-sub58.6%
associate--l-58.6%
+-commutative58.6%
pow258.6%
Applied egg-rr58.6%
associate--r+58.6%
div058.6%
neg-sub058.6%
distribute-neg-frac58.6%
Simplified58.6%
Taylor expanded in a around 0 92.7%
Final simplification86.4%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -8.2e-118)
(/ (* -0.5 c) b_2)
(if (<= b_2 4.6e+57)
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* c a)))) a)
(- (- (* 0.5 (/ c b_2)) (/ b_2 a)) (/ b_2 a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -8.2e-118) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 4.6e+57) {
tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a;
} else {
tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (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 <= (-8.2d-118)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 4.6d+57) then
tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a
else
tmp = ((0.5d0 * (c / b_2)) - (b_2 / a)) - (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 <= -8.2e-118) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 4.6e+57) {
tmp = (-b_2 - Math.sqrt(((b_2 * b_2) - (c * a)))) / a;
} else {
tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -8.2e-118: tmp = (-0.5 * c) / b_2 elif b_2 <= 4.6e+57: tmp = (-b_2 - math.sqrt(((b_2 * b_2) - (c * a)))) / a else: tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -8.2e-118) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 4.6e+57) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(c * a)))) / a); else tmp = Float64(Float64(Float64(0.5 * Float64(c / b_2)) - Float64(b_2 / a)) - Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -8.2e-118) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 4.6e+57) tmp = (-b_2 - sqrt(((b_2 * b_2) - (c * a)))) / a; else tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -8.2e-118], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 4.6e+57], 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[(N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -8.2 \cdot 10^{-118}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\
\mathbf{elif}\;b_2 \leq 4.6 \cdot 10^{+57}:\\
\;\;\;\;\frac{\left(-b_2\right) - \sqrt{b_2 \cdot b_2 - c \cdot a}}{a}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \frac{c}{b_2} - \frac{b_2}{a}\right) - \frac{b_2}{a}\\
\end{array}
\end{array}
if b_2 < -8.2000000000000006e-118Initial program 17.4%
div-sub15.1%
neg-sub015.1%
div-sub15.1%
associate--l-15.1%
+-commutative15.1%
pow215.1%
Applied egg-rr15.1%
associate--r+15.1%
div015.1%
neg-sub015.1%
distribute-neg-frac15.1%
Simplified15.1%
Taylor expanded in b_2 around -inf 82.3%
associate-*r/82.4%
Simplified82.4%
if -8.2000000000000006e-118 < b_2 < 4.5999999999999998e57Initial program 81.9%
if 4.5999999999999998e57 < b_2 Initial program 58.6%
div-sub58.6%
neg-sub058.6%
div-sub58.6%
associate--l-58.6%
+-commutative58.6%
pow258.6%
Applied egg-rr58.6%
associate--r+58.6%
div058.6%
neg-sub058.6%
distribute-neg-frac58.6%
Simplified58.6%
Taylor expanded in a around 0 92.7%
Final simplification84.7%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -7e-121)
(/ (* -0.5 c) b_2)
(if (<= b_2 2.35e-35)
(/ (- (- b_2) (sqrt (* a (- c)))) a)
(- (- (* 0.5 (/ c b_2)) (/ b_2 a)) (/ b_2 a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7e-121) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 2.35e-35) {
tmp = (-b_2 - sqrt((a * -c))) / a;
} else {
tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (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 <= (-7d-121)) then
tmp = ((-0.5d0) * c) / b_2
else if (b_2 <= 2.35d-35) then
tmp = (-b_2 - sqrt((a * -c))) / a
else
tmp = ((0.5d0 * (c / b_2)) - (b_2 / a)) - (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 <= -7e-121) {
tmp = (-0.5 * c) / b_2;
} else if (b_2 <= 2.35e-35) {
tmp = (-b_2 - Math.sqrt((a * -c))) / a;
} else {
tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -7e-121: tmp = (-0.5 * c) / b_2 elif b_2 <= 2.35e-35: tmp = (-b_2 - math.sqrt((a * -c))) / a else: tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -7e-121) tmp = Float64(Float64(-0.5 * c) / b_2); elseif (b_2 <= 2.35e-35) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(a * Float64(-c)))) / a); else tmp = Float64(Float64(Float64(0.5 * Float64(c / b_2)) - Float64(b_2 / a)) - Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -7e-121) tmp = (-0.5 * c) / b_2; elseif (b_2 <= 2.35e-35) tmp = (-b_2 - sqrt((a * -c))) / a; else tmp = ((0.5 * (c / b_2)) - (b_2 / a)) - (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7e-121], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 2.35e-35], N[(N[((-b$95$2) - N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(N[(N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] - N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -7 \cdot 10^{-121}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\
\mathbf{elif}\;b_2 \leq 2.35 \cdot 10^{-35}:\\
\;\;\;\;\frac{\left(-b_2\right) - \sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\left(0.5 \cdot \frac{c}{b_2} - \frac{b_2}{a}\right) - \frac{b_2}{a}\\
\end{array}
\end{array}
if b_2 < -6.99999999999999985e-121Initial program 17.4%
div-sub15.1%
neg-sub015.1%
div-sub15.1%
associate--l-15.1%
+-commutative15.1%
pow215.1%
Applied egg-rr15.1%
associate--r+15.1%
div015.1%
neg-sub015.1%
distribute-neg-frac15.1%
Simplified15.1%
Taylor expanded in b_2 around -inf 82.3%
associate-*r/82.4%
Simplified82.4%
if -6.99999999999999985e-121 < b_2 < 2.35e-35Initial program 76.7%
Taylor expanded in b_2 around 0 68.2%
mul-1-neg68.2%
distribute-rgt-neg-out68.2%
Simplified68.2%
if 2.35e-35 < b_2 Initial program 68.6%
div-sub68.6%
neg-sub068.6%
div-sub68.6%
associate--l-68.6%
+-commutative68.6%
pow268.6%
Applied egg-rr68.6%
associate--r+68.6%
div068.6%
neg-sub068.6%
distribute-neg-frac68.6%
Simplified68.6%
Taylor expanded in a around 0 84.9%
Final simplification79.9%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1.95e+24) (/ c b_2) (* (/ b_2 a) -2.0)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.95e+24) {
tmp = c / b_2;
} else {
tmp = (b_2 / a) * -2.0;
}
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.95d+24)) then
tmp = c / b_2
else
tmp = (b_2 / a) * (-2.0d0)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.95e+24) {
tmp = c / b_2;
} else {
tmp = (b_2 / a) * -2.0;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.95e+24: tmp = c / b_2 else: tmp = (b_2 / a) * -2.0 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.95e+24) tmp = Float64(c / b_2); else tmp = Float64(Float64(b_2 / a) * -2.0); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.95e+24) tmp = c / b_2; else tmp = (b_2 / a) * -2.0; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.95e+24], N[(c / b$95$2), $MachinePrecision], N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.95 \cdot 10^{+24}:\\
\;\;\;\;\frac{c}{b_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b_2}{a} \cdot -2\\
\end{array}
\end{array}
if b_2 < -1.9499999999999999e24Initial program 13.8%
div-inv13.8%
*-commutative13.8%
add-sqr-sqrt11.8%
sqrt-unprod12.9%
sqr-neg12.9%
sqrt-prod0.0%
add-sqr-sqrt4.4%
pow24.4%
Applied egg-rr4.4%
Applied egg-rr1.7%
*-commutative1.7%
*-commutative1.7%
mul-1-neg1.7%
neg-sub01.7%
+-inverses1.7%
+-commutative1.7%
associate--r+1.7%
+-inverses1.7%
+-inverses21.3%
metadata-eval21.3%
neg-sub021.3%
distribute-rgt-neg-in21.3%
Simplified21.3%
Taylor expanded in b_2 around 0 22.7%
mul-1-neg22.7%
distribute-lft-neg-in22.7%
*-commutative22.7%
Simplified22.7%
Taylor expanded in a around 0 27.9%
if -1.9499999999999999e24 < b_2 Initial program 65.1%
Taylor expanded in b_2 around inf 47.1%
Final simplification40.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1.72e-245) (* -0.5 (/ c b_2)) (* (/ b_2 a) -2.0)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.72e-245) {
tmp = -0.5 * (c / b_2);
} else {
tmp = (b_2 / a) * -2.0;
}
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.72d-245)) then
tmp = (-0.5d0) * (c / b_2)
else
tmp = (b_2 / a) * (-2.0d0)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.72e-245) {
tmp = -0.5 * (c / b_2);
} else {
tmp = (b_2 / a) * -2.0;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.72e-245: tmp = -0.5 * (c / b_2) else: tmp = (b_2 / a) * -2.0 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.72e-245) tmp = Float64(-0.5 * Float64(c / b_2)); else tmp = Float64(Float64(b_2 / a) * -2.0); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.72e-245) tmp = -0.5 * (c / b_2); else tmp = (b_2 / a) * -2.0; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.72e-245], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.72 \cdot 10^{-245}:\\
\;\;\;\;-0.5 \cdot \frac{c}{b_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b_2}{a} \cdot -2\\
\end{array}
\end{array}
if b_2 < -1.71999999999999997e-245Initial program 24.0%
Taylor expanded in b_2 around -inf 73.5%
if -1.71999999999999997e-245 < b_2 Initial program 73.8%
Taylor expanded in b_2 around inf 63.8%
Final simplification68.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1.72e-245) (/ (* -0.5 c) b_2) (* (/ b_2 a) -2.0)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.72e-245) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = (b_2 / a) * -2.0;
}
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.72d-245)) then
tmp = ((-0.5d0) * c) / b_2
else
tmp = (b_2 / a) * (-2.0d0)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.72e-245) {
tmp = (-0.5 * c) / b_2;
} else {
tmp = (b_2 / a) * -2.0;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.72e-245: tmp = (-0.5 * c) / b_2 else: tmp = (b_2 / a) * -2.0 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.72e-245) tmp = Float64(Float64(-0.5 * c) / b_2); else tmp = Float64(Float64(b_2 / a) * -2.0); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.72e-245) tmp = (-0.5 * c) / b_2; else tmp = (b_2 / a) * -2.0; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.72e-245], N[(N[(-0.5 * c), $MachinePrecision] / b$95$2), $MachinePrecision], N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -1.72 \cdot 10^{-245}:\\
\;\;\;\;\frac{-0.5 \cdot c}{b_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b_2}{a} \cdot -2\\
\end{array}
\end{array}
if b_2 < -1.71999999999999997e-245Initial program 24.0%
div-sub22.1%
neg-sub022.1%
div-sub22.1%
associate--l-22.1%
+-commutative22.1%
pow222.1%
Applied egg-rr22.1%
associate--r+22.1%
div022.1%
neg-sub022.1%
distribute-neg-frac22.1%
Simplified22.1%
Taylor expanded in b_2 around -inf 73.5%
associate-*r/73.5%
Simplified73.5%
if -1.71999999999999997e-245 < b_2 Initial program 73.8%
Taylor expanded in b_2 around inf 63.8%
Final simplification68.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2.1e+24) (/ c b_2) (/ (- b_2) a)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.1e+24) {
tmp = 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.1d+24)) then
tmp = 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.1e+24) {
tmp = c / b_2;
} else {
tmp = -b_2 / a;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2.1e+24: tmp = c / b_2 else: tmp = -b_2 / a return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2.1e+24) tmp = 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 <= -2.1e+24) tmp = 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.1e+24], N[(c / b$95$2), $MachinePrecision], N[((-b$95$2) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b_2 \leq -2.1 \cdot 10^{+24}:\\
\;\;\;\;\frac{c}{b_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b_2}{a}\\
\end{array}
\end{array}
if b_2 < -2.1000000000000001e24Initial program 13.8%
div-inv13.8%
*-commutative13.8%
add-sqr-sqrt11.8%
sqrt-unprod12.9%
sqr-neg12.9%
sqrt-prod0.0%
add-sqr-sqrt4.4%
pow24.4%
Applied egg-rr4.4%
Applied egg-rr1.7%
*-commutative1.7%
*-commutative1.7%
mul-1-neg1.7%
neg-sub01.7%
+-inverses1.7%
+-commutative1.7%
associate--r+1.7%
+-inverses1.7%
+-inverses21.3%
metadata-eval21.3%
neg-sub021.3%
distribute-rgt-neg-in21.3%
Simplified21.3%
Taylor expanded in b_2 around 0 22.7%
mul-1-neg22.7%
distribute-lft-neg-in22.7%
*-commutative22.7%
Simplified22.7%
Taylor expanded in a around 0 27.9%
if -2.1000000000000001e24 < b_2 Initial program 65.1%
add-sqr-sqrt64.9%
pow264.9%
pow1/264.9%
sqrt-pow164.9%
pow264.9%
metadata-eval64.9%
Applied egg-rr64.9%
Taylor expanded in b_2 around inf 20.6%
mul-1-neg20.6%
Simplified20.6%
Final simplification23.0%
(FPCore (a b_2 c) :precision binary64 (/ c b_2))
double code(double a, double b_2, double c) {
return 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 = c / b_2
end function
public static double code(double a, double b_2, double c) {
return c / b_2;
}
def code(a, b_2, c): return c / b_2
function code(a, b_2, c) return Float64(c / b_2) end
function tmp = code(a, b_2, c) tmp = c / b_2; end
code[a_, b$95$2_, c_] := N[(c / b$95$2), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b_2}
\end{array}
Initial program 48.3%
div-inv48.2%
*-commutative48.2%
add-sqr-sqrt13.6%
sqrt-unprod26.0%
sqr-neg26.0%
sqrt-prod20.5%
add-sqr-sqrt30.8%
pow230.8%
Applied egg-rr30.8%
Applied egg-rr18.3%
*-commutative18.3%
*-commutative18.3%
mul-1-neg18.3%
neg-sub018.3%
+-inverses18.3%
+-commutative18.3%
associate--r+18.3%
+-inverses18.3%
+-inverses25.1%
metadata-eval25.1%
neg-sub025.1%
distribute-rgt-neg-in25.1%
Simplified25.1%
Taylor expanded in b_2 around 0 25.3%
mul-1-neg25.3%
distribute-lft-neg-in25.3%
*-commutative25.3%
Simplified25.3%
Taylor expanded in a around 0 11.2%
Final simplification11.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 2023305
(FPCore (a b_2 c)
:name "quad2m (problem 3.2.1, negative)"
:precision binary64
:herbie-expected 10
:herbie-target
(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))