
(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 -1.9e+117)
(* -2.0 (/ b_2 a))
(if (<= b_2 3e-69)
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
(/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.9e+117) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 3e-69) {
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-1.9d+117)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 3d-69) then
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.9e+117) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 3e-69) {
tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.9e+117: tmp = -2.0 * (b_2 / a) elif b_2 <= 3e-69: tmp = (math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.9e+117) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 3e-69) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.9e+117) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 3e-69) tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.9e+117], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 3e-69], N[(N[(N[Sqrt[N[(N[(b$95$2 * b$95$2), $MachinePrecision] - N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.9 \cdot 10^{+117}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq 3 \cdot 10^{-69}:\\
\;\;\;\;\frac{\sqrt{b\_2 \cdot b\_2 - a \cdot c} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -1.9000000000000001e117Initial program 38.4%
+-commutative38.4%
unsub-neg38.4%
Simplified38.4%
Taylor expanded in b_2 around -inf 92.9%
if -1.9000000000000001e117 < b_2 < 2.99999999999999989e-69Initial program 79.5%
+-commutative79.5%
unsub-neg79.5%
Simplified79.5%
if 2.99999999999999989e-69 < b_2 Initial program 11.8%
+-commutative11.8%
unsub-neg11.8%
Simplified11.8%
Taylor expanded in b_2 around inf 92.6%
associate-*r/92.6%
*-commutative92.6%
Simplified92.6%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -7.5e-73) (* -2.0 (/ b_2 a)) (if (<= b_2 9.5e-70) (/ (- (sqrt (* a (- c))) b_2) a) (/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7.5e-73) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 9.5e-70) {
tmp = (sqrt((a * -c)) - b_2) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-7.5d-73)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 9.5d-70) then
tmp = (sqrt((a * -c)) - b_2) / a
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7.5e-73) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 9.5e-70) {
tmp = (Math.sqrt((a * -c)) - b_2) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -7.5e-73: tmp = -2.0 * (b_2 / a) elif b_2 <= 9.5e-70: tmp = (math.sqrt((a * -c)) - b_2) / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -7.5e-73) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 9.5e-70) tmp = Float64(Float64(sqrt(Float64(a * Float64(-c))) - b_2) / a); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -7.5e-73) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 9.5e-70) tmp = (sqrt((a * -c)) - b_2) / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7.5e-73], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 9.5e-70], N[(N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -7.5 \cdot 10^{-73}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq 9.5 \cdot 10^{-70}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -7.5e-73Initial program 64.9%
+-commutative64.9%
unsub-neg64.9%
Simplified64.9%
Taylor expanded in b_2 around -inf 77.6%
if -7.5e-73 < b_2 < 9.4999999999999994e-70Initial program 74.9%
+-commutative74.9%
unsub-neg74.9%
Simplified74.9%
Taylor expanded in b_2 around 0 68.5%
associate-*r*68.5%
neg-mul-168.5%
*-commutative68.5%
Simplified68.5%
if 9.4999999999999994e-70 < b_2 Initial program 11.8%
+-commutative11.8%
unsub-neg11.8%
Simplified11.8%
Taylor expanded in b_2 around inf 92.6%
associate-*r/92.6%
*-commutative92.6%
Simplified92.6%
Final simplification80.3%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-139) (* -2.0 (/ b_2 a)) (if (<= b_2 4e-69) (/ (sqrt (* a (- c))) a) (/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-139) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 4e-69) {
tmp = sqrt((a * -c)) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-2d-139)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 4d-69) then
tmp = sqrt((a * -c)) / a
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-139) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 4e-69) {
tmp = Math.sqrt((a * -c)) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-139: tmp = -2.0 * (b_2 / a) elif b_2 <= 4e-69: tmp = math.sqrt((a * -c)) / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-139) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 4e-69) tmp = Float64(sqrt(Float64(a * Float64(-c))) / a); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-139) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 4e-69) tmp = sqrt((a * -c)) / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-139], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 4e-69], N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-139}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq 4 \cdot 10^{-69}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -2.00000000000000006e-139Initial program 67.6%
+-commutative67.6%
unsub-neg67.6%
Simplified67.6%
Taylor expanded in b_2 around -inf 74.6%
if -2.00000000000000006e-139 < b_2 < 3.9999999999999999e-69Initial program 72.0%
+-commutative72.0%
unsub-neg72.0%
Simplified72.0%
prod-diff71.6%
*-commutative71.6%
fma-neg71.6%
prod-diff71.6%
*-commutative71.6%
fma-neg71.6%
associate-+l+71.6%
pow271.6%
*-commutative71.6%
fma-undefine71.6%
distribute-lft-neg-in71.6%
*-commutative71.6%
distribute-rgt-neg-in71.6%
fma-define71.6%
*-commutative71.6%
fma-undefine71.6%
distribute-lft-neg-in71.6%
*-commutative71.6%
distribute-rgt-neg-in71.6%
Applied egg-rr71.6%
associate-+l-71.6%
count-271.6%
Simplified71.6%
Taylor expanded in b_2 around 0 70.4%
distribute-lft1-in70.4%
metadata-eval70.4%
mul0-lft70.8%
metadata-eval70.8%
cancel-sign-sub-inv70.8%
mul0-lft70.8%
distribute-rgt-in70.8%
metadata-eval70.8%
mul0-lft70.8%
metadata-eval70.8%
distribute-rgt1-in70.8%
sub-neg70.8%
associate-*l/71.0%
Simplified71.0%
if 3.9999999999999999e-69 < b_2 Initial program 11.8%
+-commutative11.8%
unsub-neg11.8%
Simplified11.8%
Taylor expanded in b_2 around inf 92.6%
associate-*r/92.6%
*-commutative92.6%
Simplified92.6%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -5.2e-141) (* -2.0 (/ b_2 a)) (if (<= b_2 3.9e-148) (sqrt (/ c (- a))) (/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5.2e-141) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 3.9e-148) {
tmp = sqrt((c / -a));
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-5.2d-141)) then
tmp = (-2.0d0) * (b_2 / a)
else if (b_2 <= 3.9d-148) then
tmp = sqrt((c / -a))
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5.2e-141) {
tmp = -2.0 * (b_2 / a);
} else if (b_2 <= 3.9e-148) {
tmp = Math.sqrt((c / -a));
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -5.2e-141: tmp = -2.0 * (b_2 / a) elif b_2 <= 3.9e-148: tmp = math.sqrt((c / -a)) else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -5.2e-141) tmp = Float64(-2.0 * Float64(b_2 / a)); elseif (b_2 <= 3.9e-148) tmp = sqrt(Float64(c / Float64(-a))); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -5.2e-141) tmp = -2.0 * (b_2 / a); elseif (b_2 <= 3.9e-148) tmp = sqrt((c / -a)); else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5.2e-141], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 3.9e-148], N[Sqrt[N[(c / (-a)), $MachinePrecision]], $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -5.2 \cdot 10^{-141}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq 3.9 \cdot 10^{-148}:\\
\;\;\;\;\sqrt{\frac{c}{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -5.20000000000000022e-141Initial program 68.2%
+-commutative68.2%
unsub-neg68.2%
Simplified68.2%
Taylor expanded in b_2 around -inf 73.3%
if -5.20000000000000022e-141 < b_2 < 3.89999999999999994e-148Initial program 72.8%
+-commutative72.8%
unsub-neg72.8%
Simplified72.8%
prod-diff72.3%
*-commutative72.3%
fma-neg72.3%
prod-diff72.3%
*-commutative72.3%
fma-neg72.3%
associate-+l+72.3%
pow272.3%
*-commutative72.3%
fma-undefine72.3%
distribute-lft-neg-in72.3%
*-commutative72.3%
distribute-rgt-neg-in72.3%
fma-define72.3%
*-commutative72.3%
fma-undefine72.3%
distribute-lft-neg-in72.3%
*-commutative72.3%
distribute-rgt-neg-in72.3%
Applied egg-rr72.3%
associate-+l-72.3%
count-272.3%
Simplified72.3%
Taylor expanded in a around inf 46.0%
*-commutative46.0%
distribute-rgt1-in46.0%
metadata-eval46.0%
mul0-lft46.0%
metadata-eval46.0%
neg-sub046.0%
Simplified46.0%
if 3.89999999999999994e-148 < b_2 Initial program 18.5%
+-commutative18.5%
unsub-neg18.5%
Simplified18.5%
Taylor expanded in b_2 around inf 85.1%
associate-*r/85.1%
*-commutative85.1%
Simplified85.1%
Final simplification73.2%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-311) (* -2.0 (/ b_2 a)) (/ (* c -0.5) b_2)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -2.0 * (b_2 / a);
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-2d-311)) then
tmp = (-2.0d0) * (b_2 / a)
else
tmp = (c * (-0.5d0)) / b_2
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -2.0 * (b_2 / a);
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-311: tmp = -2.0 * (b_2 / a) else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-311) tmp = Float64(-2.0 * Float64(b_2 / a)); else tmp = Float64(Float64(c * -0.5) / b_2); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-311) tmp = -2.0 * (b_2 / a); else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-311], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-311}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -1.9999999999999e-311Initial program 69.4%
+-commutative69.4%
unsub-neg69.4%
Simplified69.4%
Taylor expanded in b_2 around -inf 62.0%
if -1.9999999999999e-311 < b_2 Initial program 27.0%
+-commutative27.0%
unsub-neg27.0%
Simplified27.0%
Taylor expanded in b_2 around inf 71.8%
associate-*r/71.8%
*-commutative71.8%
Simplified71.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-311) (* -2.0 (/ b_2 a)) (* c (/ -0.5 b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -2.0 * (b_2 / a);
} else {
tmp = c * (-0.5 / b_2);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-2d-311)) then
tmp = (-2.0d0) * (b_2 / a)
else
tmp = c * ((-0.5d0) / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -2.0 * (b_2 / a);
} else {
tmp = c * (-0.5 / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-311: tmp = -2.0 * (b_2 / a) else: tmp = c * (-0.5 / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-311) tmp = Float64(-2.0 * Float64(b_2 / a)); else tmp = Float64(c * Float64(-0.5 / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-311) tmp = -2.0 * (b_2 / a); else tmp = c * (-0.5 / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-311], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], N[(c * N[(-0.5 / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-311}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \frac{-0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -1.9999999999999e-311Initial program 69.4%
+-commutative69.4%
unsub-neg69.4%
Simplified69.4%
Taylor expanded in b_2 around -inf 62.0%
if -1.9999999999999e-311 < b_2 Initial program 27.0%
+-commutative27.0%
unsub-neg27.0%
Simplified27.0%
Taylor expanded in c around 0 65.6%
fma-neg65.6%
associate-/l*67.3%
associate-*r/67.3%
metadata-eval67.3%
Simplified67.3%
Taylor expanded in a around 0 71.6%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-311) (* -2.0 (/ b_2 a)) 0.0))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -2.0 * (b_2 / a);
} else {
tmp = 0.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 <= (-2d-311)) then
tmp = (-2.0d0) * (b_2 / a)
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -2.0 * (b_2 / a);
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-311: tmp = -2.0 * (b_2 / a) else: tmp = 0.0 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-311) tmp = Float64(-2.0 * Float64(b_2 / a)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-311) tmp = -2.0 * (b_2 / a); else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-311], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-311}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b_2 < -1.9999999999999e-311Initial program 69.4%
+-commutative69.4%
unsub-neg69.4%
Simplified69.4%
Taylor expanded in b_2 around -inf 62.0%
if -1.9999999999999e-311 < b_2 Initial program 27.0%
+-commutative27.0%
unsub-neg27.0%
Simplified27.0%
div-sub26.7%
add-sqr-sqrt25.6%
associate-/l*25.5%
fma-neg24.0%
pow1/224.0%
sqrt-pow124.0%
pow224.0%
metadata-eval24.0%
pow1/224.0%
sqrt-pow124.0%
pow224.0%
metadata-eval24.0%
Applied egg-rr24.0%
distribute-neg-frac224.0%
Simplified24.0%
Taylor expanded in a around 0 23.0%
distribute-rgt1-in23.0%
metadata-eval23.0%
mul0-lft23.0%
div023.0%
Simplified23.0%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-311) (/ (- b_2) a) 0.0))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -b_2 / a;
} else {
tmp = 0.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 <= (-2d-311)) then
tmp = -b_2 / a
else
tmp = 0.0d0
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -b_2 / a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-311: tmp = -b_2 / a else: tmp = 0.0 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-311) tmp = Float64(Float64(-b_2) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-311) tmp = -b_2 / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-311], N[((-b$95$2) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-311}:\\
\;\;\;\;\frac{-b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b_2 < -1.9999999999999e-311Initial program 69.4%
+-commutative69.4%
unsub-neg69.4%
Simplified69.4%
Taylor expanded in b_2 around 0 38.1%
associate-*r*38.1%
neg-mul-138.1%
*-commutative38.1%
Simplified38.1%
Taylor expanded in b_2 around inf 22.7%
associate-*r/22.7%
neg-mul-122.7%
Simplified22.7%
if -1.9999999999999e-311 < b_2 Initial program 27.0%
+-commutative27.0%
unsub-neg27.0%
Simplified27.0%
div-sub26.7%
add-sqr-sqrt25.6%
associate-/l*25.5%
fma-neg24.0%
pow1/224.0%
sqrt-pow124.0%
pow224.0%
metadata-eval24.0%
pow1/224.0%
sqrt-pow124.0%
pow224.0%
metadata-eval24.0%
Applied egg-rr24.0%
distribute-neg-frac224.0%
Simplified24.0%
Taylor expanded in a around 0 23.0%
distribute-rgt1-in23.0%
metadata-eval23.0%
mul0-lft23.0%
div023.0%
Simplified23.0%
(FPCore (a b_2 c) :precision binary64 0.0)
double code(double a, double b_2, double c) {
return 0.0;
}
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
end function
public static double code(double a, double b_2, double c) {
return 0.0;
}
def code(a, b_2, c): return 0.0
function code(a, b_2, c) return 0.0 end
function tmp = code(a, b_2, c) tmp = 0.0; end
code[a_, b$95$2_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 49.2%
+-commutative49.2%
unsub-neg49.2%
Simplified49.2%
div-sub49.1%
add-sqr-sqrt48.4%
associate-/l*48.4%
fma-neg47.7%
pow1/247.7%
sqrt-pow147.7%
pow247.7%
metadata-eval47.7%
pow1/247.7%
sqrt-pow147.7%
pow247.7%
metadata-eval47.7%
Applied egg-rr47.7%
distribute-neg-frac247.7%
Simplified47.7%
Taylor expanded in a around 0 12.5%
distribute-rgt1-in12.5%
metadata-eval12.5%
mul0-lft12.5%
div012.5%
Simplified12.5%
(FPCore (a b_2 c)
:precision binary64
(let* ((t_0 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_1
(if (== (copysign a c) a)
(* (sqrt (- (fabs b_2) t_0)) (sqrt (+ (fabs b_2) t_0)))
(hypot b_2 t_0))))
(if (< b_2 0.0) (/ (- t_1 b_2) a) (/ (- c) (+ b_2 t_1)))))
double code(double a, double b_2, double c) {
double t_0 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((fabs(b_2) - t_0)) * sqrt((fabs(b_2) + t_0));
} else {
tmp = hypot(b_2, t_0);
}
double t_1 = tmp;
double tmp_1;
if (b_2 < 0.0) {
tmp_1 = (t_1 - b_2) / a;
} else {
tmp_1 = -c / (b_2 + t_1);
}
return tmp_1;
}
public static double code(double a, double b_2, double c) {
double t_0 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((Math.abs(b_2) - t_0)) * Math.sqrt((Math.abs(b_2) + t_0));
} else {
tmp = Math.hypot(b_2, t_0);
}
double t_1 = tmp;
double tmp_1;
if (b_2 < 0.0) {
tmp_1 = (t_1 - b_2) / a;
} else {
tmp_1 = -c / (b_2 + t_1);
}
return tmp_1;
}
def code(a, b_2, c): t_0 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((math.fabs(b_2) - t_0)) * math.sqrt((math.fabs(b_2) + t_0)) else: tmp = math.hypot(b_2, t_0) t_1 = tmp tmp_1 = 0 if b_2 < 0.0: tmp_1 = (t_1 - b_2) / a else: tmp_1 = -c / (b_2 + t_1) return tmp_1
function code(a, b_2, c) t_0 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(abs(b_2) - t_0)) * sqrt(Float64(abs(b_2) + t_0))); else tmp = hypot(b_2, t_0); end t_1 = tmp tmp_1 = 0.0 if (b_2 < 0.0) tmp_1 = Float64(Float64(t_1 - b_2) / a); else tmp_1 = Float64(Float64(-c) / Float64(b_2 + t_1)); end return tmp_1 end
function tmp_3 = code(a, b_2, c) t_0 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((abs(b_2) - t_0)) * sqrt((abs(b_2) + t_0)); else tmp = hypot(b_2, t_0); end t_1 = tmp; tmp_2 = 0.0; if (b_2 < 0.0) tmp_2 = (t_1 - b_2) / a; else tmp_2 = -c / (b_2 + t_1); end tmp_3 = tmp_2; end
code[a_, b$95$2_, c_] := Block[{t$95$0 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(N[Abs[b$95$2], $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(N[Abs[b$95$2], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[b$95$2 ^ 2 + t$95$0 ^ 2], $MachinePrecision]]}, If[Less[b$95$2, 0.0], N[(N[(t$95$1 - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[((-c) / N[(b$95$2 + t$95$1), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_1 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{\left|b\_2\right| - t\_0} \cdot \sqrt{\left|b\_2\right| + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(b\_2, t\_0\right)\\
\end{array}\\
\mathbf{if}\;b\_2 < 0:\\
\;\;\;\;\frac{t\_1 - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b\_2 + t\_1}\\
\end{array}
\end{array}
herbie shell --seed 2024135
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
:herbie-expected 10
:alt
(! :herbie-platform default (let ((sqtD (let ((x (* (sqrt (fabs a)) (sqrt (fabs c))))) (if (== (copysign a c) a) (* (sqrt (- (fabs b_2) x)) (sqrt (+ (fabs b_2) x))) (hypot b_2 x))))) (if (< b_2 0) (/ (- sqtD b_2) a) (/ (- c) (+ b_2 sqtD)))))
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))