
(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 -1e+143)
(+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))
(if (<= b_2 3.3e-85)
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
(* (/ c b_2) -0.5))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1e+143) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 3.3e-85) {
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = (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 <= (-1d+143)) then
tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
else if (b_2 <= 3.3d-85) then
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
else
tmp = (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 <= -1e+143) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 3.3e-85) {
tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = (c / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1e+143: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) elif b_2 <= 3.3e-85: tmp = (math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a else: tmp = (c / b_2) * -0.5 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1e+143) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); elseif (b_2 <= 3.3e-85) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a); else tmp = 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 <= -1e+143) tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); elseif (b_2 <= 3.3e-85) tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a; else tmp = (c / b_2) * -0.5; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1e+143], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 3.3e-85], 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 / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1 \cdot 10^{+143}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 3.3 \cdot 10^{-85}:\\
\;\;\;\;\frac{\sqrt{b\_2 \cdot b\_2 - a \cdot c} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b\_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < -1e143Initial program 52.5%
+-commutative52.5%
unsub-neg52.5%
Simplified52.5%
Taylor expanded in b_2 around -inf 95.9%
Taylor expanded in c around 0 96.2%
if -1e143 < b_2 < 3.29999999999999973e-85Initial program 86.2%
+-commutative86.2%
unsub-neg86.2%
Simplified86.2%
if 3.29999999999999973e-85 < b_2 Initial program 13.5%
+-commutative13.5%
unsub-neg13.5%
Simplified13.5%
Taylor expanded in b_2 around inf 92.5%
Final simplification90.1%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2.05e-105) (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2))) (if (<= b_2 3.8e-86) (/ (- (sqrt (* a (- c))) b_2) a) (* (/ c b_2) -0.5))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.05e-105) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 3.8e-86) {
tmp = (sqrt((a * -c)) - b_2) / a;
} else {
tmp = (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 <= (-2.05d-105)) then
tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
else if (b_2 <= 3.8d-86) then
tmp = (sqrt((a * -c)) - b_2) / a
else
tmp = (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 <= -2.05e-105) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 3.8e-86) {
tmp = (Math.sqrt((a * -c)) - b_2) / a;
} else {
tmp = (c / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2.05e-105: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) elif b_2 <= 3.8e-86: tmp = (math.sqrt((a * -c)) - b_2) / a else: tmp = (c / b_2) * -0.5 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2.05e-105) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); elseif (b_2 <= 3.8e-86) tmp = Float64(Float64(sqrt(Float64(a * Float64(-c))) - b_2) / a); else tmp = 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 <= -2.05e-105) tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); elseif (b_2 <= 3.8e-86) tmp = (sqrt((a * -c)) - b_2) / a; else tmp = (c / b_2) * -0.5; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2.05e-105], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 3.8e-86], N[(N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] - b$95$2), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2.05 \cdot 10^{-105}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 3.8 \cdot 10^{-86}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b\_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < -2.05000000000000015e-105Initial program 79.0%
+-commutative79.0%
unsub-neg79.0%
Simplified79.0%
Taylor expanded in b_2 around -inf 88.0%
Taylor expanded in c around 0 88.2%
if -2.05000000000000015e-105 < b_2 < 3.8e-86Initial program 74.6%
+-commutative74.6%
unsub-neg74.6%
Simplified74.6%
Taylor expanded in b_2 around 0 66.1%
associate-*r*66.1%
neg-mul-166.1%
*-commutative66.1%
Simplified66.1%
if 3.8e-86 < b_2 Initial program 13.5%
+-commutative13.5%
unsub-neg13.5%
Simplified13.5%
Taylor expanded in b_2 around inf 92.5%
Final simplification84.5%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1.7e-144) (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2))) (if (<= b_2 5e-74) (/ (sqrt (* a (- c))) a) (* (/ c b_2) -0.5))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.7e-144) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 5e-74) {
tmp = sqrt((a * -c)) / a;
} else {
tmp = (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.7d-144)) then
tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
else if (b_2 <= 5d-74) then
tmp = sqrt((a * -c)) / a
else
tmp = (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.7e-144) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else if (b_2 <= 5e-74) {
tmp = Math.sqrt((a * -c)) / a;
} else {
tmp = (c / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.7e-144: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) elif b_2 <= 5e-74: tmp = math.sqrt((a * -c)) / a else: tmp = (c / b_2) * -0.5 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.7e-144) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); elseif (b_2 <= 5e-74) tmp = Float64(sqrt(Float64(a * Float64(-c))) / a); else tmp = 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.7e-144) tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); elseif (b_2 <= 5e-74) tmp = sqrt((a * -c)) / a; else tmp = (c / b_2) * -0.5; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.7e-144], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 5e-74], N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.7 \cdot 10^{-144}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 5 \cdot 10^{-74}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b\_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < -1.70000000000000009e-144Initial program 80.1%
+-commutative80.1%
unsub-neg80.1%
Simplified80.1%
Taylor expanded in b_2 around -inf 84.3%
Taylor expanded in c around 0 84.5%
if -1.70000000000000009e-144 < b_2 < 4.99999999999999998e-74Initial program 70.3%
+-commutative70.3%
unsub-neg70.3%
Simplified70.3%
prod-diff69.7%
*-commutative69.7%
fmm-def69.7%
prod-diff69.7%
*-commutative69.7%
fmm-def69.7%
associate-+l+69.7%
pow269.7%
*-commutative69.7%
fma-undefine69.7%
distribute-lft-neg-in69.7%
*-commutative69.7%
distribute-rgt-neg-in69.7%
fma-define69.7%
*-commutative69.7%
fma-undefine69.7%
distribute-lft-neg-in69.7%
*-commutative69.7%
distribute-rgt-neg-in69.7%
Applied egg-rr69.7%
*-commutative69.7%
count-269.7%
*-commutative69.7%
Simplified69.7%
Taylor expanded in c around inf 68.2%
distribute-rgt1-in68.2%
metadata-eval68.2%
mul0-lft68.2%
metadata-eval68.2%
sub0-neg68.2%
Simplified68.2%
if 4.99999999999999998e-74 < b_2 Initial program 12.6%
+-commutative12.6%
unsub-neg12.6%
Simplified12.6%
Taylor expanded in b_2 around inf 93.5%
Final simplification84.2%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -5e-311) (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2))) (* (/ c b_2) -0.5)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5e-311) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else {
tmp = (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 <= (-5d-311)) then
tmp = ((-2.0d0) * (b_2 / a)) + (0.5d0 * (c / b_2))
else
tmp = (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 <= -5e-311) {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
} else {
tmp = (c / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -5e-311: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) else: tmp = (c / b_2) * -0.5 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -5e-311) tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + Float64(0.5 * Float64(c / b_2))); else tmp = 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 <= -5e-311) tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); else tmp = (c / b_2) * -0.5; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5e-311], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -5 \cdot 10^{-311}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b\_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < -5.00000000000023e-311Initial program 79.8%
+-commutative79.8%
unsub-neg79.8%
Simplified79.8%
Taylor expanded in b_2 around -inf 73.5%
Taylor expanded in c around 0 73.8%
if -5.00000000000023e-311 < b_2 Initial program 26.7%
+-commutative26.7%
unsub-neg26.7%
Simplified26.7%
Taylor expanded in b_2 around inf 72.3%
Final simplification73.1%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 6.1e-267) (/ (* b_2 -2.0) a) (* (/ c b_2) -0.5)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 6.1e-267) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = (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 <= 6.1d-267) then
tmp = (b_2 * (-2.0d0)) / a
else
tmp = (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 <= 6.1e-267) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = (c / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= 6.1e-267: tmp = (b_2 * -2.0) / a else: tmp = (c / b_2) * -0.5 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= 6.1e-267) tmp = Float64(Float64(b_2 * -2.0) / a); else tmp = 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 <= 6.1e-267) tmp = (b_2 * -2.0) / a; else tmp = (c / b_2) * -0.5; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, 6.1e-267], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq 6.1 \cdot 10^{-267}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b\_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < 6.10000000000000008e-267Initial program 80.3%
+-commutative80.3%
unsub-neg80.3%
Simplified80.3%
Taylor expanded in b_2 around -inf 71.5%
*-commutative71.5%
Simplified71.5%
if 6.10000000000000008e-267 < b_2 Initial program 24.1%
+-commutative24.1%
unsub-neg24.1%
Simplified24.1%
Taylor expanded in b_2 around inf 74.8%
Final simplification72.9%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 6.1e-267) (* b_2 (/ -2.0 a)) (* (/ c b_2) -0.5)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 6.1e-267) {
tmp = b_2 * (-2.0 / a);
} else {
tmp = (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 <= 6.1d-267) then
tmp = b_2 * ((-2.0d0) / a)
else
tmp = (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 <= 6.1e-267) {
tmp = b_2 * (-2.0 / a);
} else {
tmp = (c / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= 6.1e-267: tmp = b_2 * (-2.0 / a) else: tmp = (c / b_2) * -0.5 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= 6.1e-267) tmp = Float64(b_2 * Float64(-2.0 / a)); else tmp = 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 <= 6.1e-267) tmp = b_2 * (-2.0 / a); else tmp = (c / b_2) * -0.5; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, 6.1e-267], N[(b$95$2 * N[(-2.0 / a), $MachinePrecision]), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq 6.1 \cdot 10^{-267}:\\
\;\;\;\;b\_2 \cdot \frac{-2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b\_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < 6.10000000000000008e-267Initial program 80.3%
+-commutative80.3%
unsub-neg80.3%
Simplified80.3%
add-sqr-sqrt80.1%
pow280.1%
pow1/280.1%
sqrt-pow180.1%
pow280.1%
metadata-eval80.1%
Applied egg-rr80.1%
Taylor expanded in b_2 around -inf 71.5%
metadata-eval71.5%
distribute-lft-neg-in71.5%
associate-*r/71.5%
associate-*l/71.3%
*-commutative71.3%
distribute-rgt-neg-in71.3%
distribute-neg-frac71.3%
metadata-eval71.3%
Simplified71.3%
if 6.10000000000000008e-267 < b_2 Initial program 24.1%
+-commutative24.1%
unsub-neg24.1%
Simplified24.1%
Taylor expanded in b_2 around inf 74.8%
Final simplification72.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 6.1e-267) (/ b_2 (- a)) (* (/ c b_2) -0.5)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= 6.1e-267) {
tmp = b_2 / -a;
} else {
tmp = (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 <= 6.1d-267) then
tmp = b_2 / -a
else
tmp = (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 <= 6.1e-267) {
tmp = b_2 / -a;
} else {
tmp = (c / b_2) * -0.5;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= 6.1e-267: tmp = b_2 / -a else: tmp = (c / b_2) * -0.5 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= 6.1e-267) tmp = Float64(b_2 / Float64(-a)); else tmp = 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 <= 6.1e-267) tmp = b_2 / -a; else tmp = (c / b_2) * -0.5; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, 6.1e-267], N[(b$95$2 / (-a)), $MachinePrecision], N[(N[(c / b$95$2), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq 6.1 \cdot 10^{-267}:\\
\;\;\;\;\frac{b\_2}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b\_2} \cdot -0.5\\
\end{array}
\end{array}
if b_2 < 6.10000000000000008e-267Initial program 80.3%
+-commutative80.3%
unsub-neg80.3%
Simplified80.3%
Taylor expanded in b_2 around 0 48.3%
associate-*r*48.3%
neg-mul-148.3%
*-commutative48.3%
Simplified48.3%
Taylor expanded in b_2 around inf 33.9%
associate-*r/33.9%
neg-mul-133.9%
Simplified33.9%
if 6.10000000000000008e-267 < b_2 Initial program 24.1%
+-commutative24.1%
unsub-neg24.1%
Simplified24.1%
Taylor expanded in b_2 around inf 74.8%
Final simplification51.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1.6e-306) (/ b_2 (- a)) 0.0))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.6e-306) {
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 <= (-1.6d-306)) 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 <= -1.6e-306) {
tmp = b_2 / -a;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.6e-306: tmp = b_2 / -a else: tmp = 0.0 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.6e-306) tmp = Float64(b_2 / Float64(-a)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.6e-306) tmp = b_2 / -a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.6e-306], N[(b$95$2 / (-a)), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.6 \cdot 10^{-306}:\\
\;\;\;\;\frac{b\_2}{-a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b_2 < -1.59999999999999985e-306Initial program 79.6%
+-commutative79.6%
unsub-neg79.6%
Simplified79.6%
Taylor expanded in b_2 around 0 46.5%
associate-*r*46.5%
neg-mul-146.5%
*-commutative46.5%
Simplified46.5%
Taylor expanded in b_2 around inf 35.0%
associate-*r/35.0%
neg-mul-135.0%
Simplified35.0%
if -1.59999999999999985e-306 < b_2 Initial program 27.3%
+-commutative27.3%
unsub-neg27.3%
Simplified27.3%
div-sub26.1%
add-sqr-sqrt24.9%
associate-/l*25.0%
fmm-def23.0%
pow1/223.0%
sqrt-pow123.1%
pow223.1%
metadata-eval23.1%
pow1/223.1%
sqrt-pow123.0%
pow223.0%
metadata-eval23.0%
Applied egg-rr23.0%
*-commutative23.0%
*-commutative23.0%
distribute-neg-frac23.0%
Simplified23.0%
Taylor expanded in c around 0 15.0%
distribute-lft1-in15.0%
metadata-eval15.0%
mul0-lft19.1%
Simplified19.1%
Final simplification27.8%
(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 55.7%
+-commutative55.7%
unsub-neg55.7%
Simplified55.7%
div-sub55.2%
add-sqr-sqrt54.5%
associate-/l*54.5%
fmm-def53.6%
pow1/253.6%
sqrt-pow153.7%
pow253.7%
metadata-eval53.7%
pow1/253.7%
sqrt-pow153.7%
pow253.7%
metadata-eval53.7%
Applied egg-rr53.7%
*-commutative53.7%
*-commutative53.7%
distribute-neg-frac53.7%
Simplified53.7%
Taylor expanded in c around 0 8.0%
distribute-lft1-in8.0%
metadata-eval8.0%
mul0-lft10.1%
Simplified10.1%
(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 2024185
(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))