
(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 -1.9e+117)
(* (/ b_2 a) -2.0)
(if (<= b_2 3e-69)
(/ (- (sqrt (- (* b_2 b_2) (* a c))) b_2) a)
(* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.9e+117) {
tmp = (b_2 / a) * -2.0;
} else if (b_2 <= 3e-69) {
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-1.9d+117)) then
tmp = (b_2 / a) * (-2.0d0)
else if (b_2 <= 3d-69) then
tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.9e+117) {
tmp = (b_2 / a) * -2.0;
} else if (b_2 <= 3e-69) {
tmp = (Math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -1.9e+117: tmp = (b_2 / a) * -2.0 elif b_2 <= 3e-69: tmp = (math.sqrt(((b_2 * b_2) - (a * c))) - b_2) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -1.9e+117) tmp = Float64(Float64(b_2 / a) * -2.0); elseif (b_2 <= 3e-69) tmp = Float64(Float64(sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c))) - b_2) / a); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -1.9e+117) tmp = (b_2 / a) * -2.0; elseif (b_2 <= 3e-69) tmp = (sqrt(((b_2 * b_2) - (a * c))) - b_2) / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -1.9e+117], N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $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[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -1.9 \cdot 10^{+117}:\\
\;\;\;\;\frac{b\_2}{a} \cdot -2\\
\mathbf{elif}\;b\_2 \leq 3 \cdot 10^{-69}:\\
\;\;\;\;\frac{\sqrt{b\_2 \cdot b\_2 - a \cdot c} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{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%
*-commutative92.9%
Simplified92.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%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -7.5e-73) (* (/ b_2 a) -2.0) (if (<= b_2 9.5e-70) (/ (- (sqrt (* a (- c))) b_2) a) (* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7.5e-73) {
tmp = (b_2 / a) * -2.0;
} else if (b_2 <= 9.5e-70) {
tmp = (sqrt((a * -c)) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-7.5d-73)) then
tmp = (b_2 / a) * (-2.0d0)
else if (b_2 <= 9.5d-70) then
tmp = (sqrt((a * -c)) - b_2) / a
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7.5e-73) {
tmp = (b_2 / a) * -2.0;
} else if (b_2 <= 9.5e-70) {
tmp = (Math.sqrt((a * -c)) - b_2) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -7.5e-73: tmp = (b_2 / a) * -2.0 elif b_2 <= 9.5e-70: tmp = (math.sqrt((a * -c)) - b_2) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -7.5e-73) tmp = Float64(Float64(b_2 / a) * -2.0); elseif (b_2 <= 9.5e-70) tmp = Float64(Float64(sqrt(Float64(a * Float64(-c))) - b_2) / a); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -7.5e-73) tmp = (b_2 / a) * -2.0; elseif (b_2 <= 9.5e-70) tmp = (sqrt((a * -c)) - b_2) / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7.5e-73], N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $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[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -7.5 \cdot 10^{-73}:\\
\;\;\;\;\frac{b\_2}{a} \cdot -2\\
\mathbf{elif}\;b\_2 \leq 9.5 \cdot 10^{-70}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)} - b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{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%
*-commutative77.6%
Simplified77.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%
Final simplification80.3%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-139) (* (/ b_2 a) -2.0) (if (<= b_2 4e-69) (/ (sqrt (* a (- c))) a) (* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-139) {
tmp = (b_2 / a) * -2.0;
} else if (b_2 <= 4e-69) {
tmp = sqrt((a * -c)) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-2d-139)) then
tmp = (b_2 / a) * (-2.0d0)
else if (b_2 <= 4d-69) then
tmp = sqrt((a * -c)) / a
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-139) {
tmp = (b_2 / a) * -2.0;
} else if (b_2 <= 4e-69) {
tmp = Math.sqrt((a * -c)) / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-139: tmp = (b_2 / a) * -2.0 elif b_2 <= 4e-69: tmp = math.sqrt((a * -c)) / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-139) tmp = Float64(Float64(b_2 / a) * -2.0); elseif (b_2 <= 4e-69) tmp = Float64(sqrt(Float64(a * Float64(-c))) / a); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-139) tmp = (b_2 / a) * -2.0; elseif (b_2 <= 4e-69) tmp = sqrt((a * -c)) / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-139], N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision], If[LessEqual[b$95$2, 4e-69], N[(N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-139}:\\
\;\;\;\;\frac{b\_2}{a} \cdot -2\\
\mathbf{elif}\;b\_2 \leq 4 \cdot 10^{-69}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{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%
*-commutative74.6%
Simplified74.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%
*-commutative71.6%
count-271.6%
*-commutative71.6%
Simplified71.6%
Taylor expanded in b_2 around 0 70.4%
associate-*l/70.6%
*-lft-identity70.6%
distribute-lft1-in70.6%
metadata-eval70.6%
mul0-lft71.0%
metadata-eval71.0%
neg-sub071.0%
distribute-rgt-neg-in71.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%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -5.2e-141) (* (/ b_2 a) -2.0) (if (<= b_2 3.9e-148) (sqrt (/ c (- a))) (* -0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5.2e-141) {
tmp = (b_2 / a) * -2.0;
} else if (b_2 <= 3.9e-148) {
tmp = sqrt((c / -a));
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-5.2d-141)) then
tmp = (b_2 / a) * (-2.0d0)
else if (b_2 <= 3.9d-148) then
tmp = sqrt((c / -a))
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -5.2e-141) {
tmp = (b_2 / a) * -2.0;
} else if (b_2 <= 3.9e-148) {
tmp = Math.sqrt((c / -a));
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -5.2e-141: tmp = (b_2 / a) * -2.0 elif b_2 <= 3.9e-148: tmp = math.sqrt((c / -a)) else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -5.2e-141) tmp = Float64(Float64(b_2 / a) * -2.0); elseif (b_2 <= 3.9e-148) tmp = sqrt(Float64(c / Float64(-a))); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -5.2e-141) tmp = (b_2 / a) * -2.0; elseif (b_2 <= 3.9e-148) tmp = sqrt((c / -a)); else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -5.2e-141], N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision], If[LessEqual[b$95$2, 3.9e-148], N[Sqrt[N[(c / (-a)), $MachinePrecision]], $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -5.2 \cdot 10^{-141}:\\
\;\;\;\;\frac{b\_2}{a} \cdot -2\\
\mathbf{elif}\;b\_2 \leq 3.9 \cdot 10^{-148}:\\
\;\;\;\;\sqrt{\frac{c}{-a}}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{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%
*-commutative73.3%
Simplified73.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%
*-commutative72.3%
count-272.3%
*-commutative72.3%
Simplified72.3%
Taylor expanded in a around inf 46.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%
Final simplification73.2%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-311) (* (/ b_2 a) -2.0) (* -0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = (b_2 / a) * -2.0;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-2d-311)) then
tmp = (b_2 / a) * (-2.0d0)
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = (b_2 / a) * -2.0;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-311: tmp = (b_2 / a) * -2.0 else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-311) tmp = Float64(Float64(b_2 / a) * -2.0); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-311) tmp = (b_2 / a) * -2.0; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-311], N[(N[(b$95$2 / a), $MachinePrecision] * -2.0), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-311}:\\
\;\;\;\;\frac{b\_2}{a} \cdot -2\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{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%
*-commutative62.0%
Simplified62.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%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2e-311) (/ (- b_2) a) (* -0.5 (/ c b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -b_2 / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-2d-311)) then
tmp = -b_2 / a
else
tmp = (-0.5d0) * (c / b_2)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2e-311) {
tmp = -b_2 / a;
} else {
tmp = -0.5 * (c / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2e-311: tmp = -b_2 / a else: tmp = -0.5 * (c / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2e-311) tmp = Float64(Float64(-b_2) / a); else tmp = Float64(-0.5 * Float64(c / b_2)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2e-311) tmp = -b_2 / a; else tmp = -0.5 * (c / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2e-311], N[((-b$95$2) / a), $MachinePrecision], N[(-0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2 \cdot 10^{-311}:\\
\;\;\;\;\frac{-b\_2}{a}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{c}{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 0 38.1%
associate-*r*38.1%
neg-mul-138.1%
*-commutative38.1%
Simplified38.1%
Taylor expanded in b_2 around inf 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%
Taylor expanded in b_2 around inf 71.8%
(FPCore (a b_2 c) :precision binary64 (/ (- b_2) a))
double code(double a, double b_2, double c) {
return -b_2 / a;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = -b_2 / a
end function
public static double code(double a, double b_2, double c) {
return -b_2 / a;
}
def code(a, b_2, c): return -b_2 / a
function code(a, b_2, c) return Float64(Float64(-b_2) / a) end
function tmp = code(a, b_2, c) tmp = -b_2 / a; end
code[a_, b$95$2_, c_] := N[((-b$95$2) / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{-b\_2}{a}
\end{array}
Initial program 49.2%
+-commutative49.2%
unsub-neg49.2%
Simplified49.2%
Taylor expanded in b_2 around 0 30.9%
associate-*r*30.9%
neg-mul-130.9%
*-commutative30.9%
Simplified30.9%
Taylor expanded in b_2 around inf 13.2%
neg-mul-113.2%
Simplified13.2%
(FPCore (a b_2 c) :precision binary64 (/ b_2 a))
double code(double a, double b_2, double c) {
return b_2 / a;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
code = b_2 / a
end function
public static double code(double a, double b_2, double c) {
return b_2 / a;
}
def code(a, b_2, c): return b_2 / a
function code(a, b_2, c) return Float64(b_2 / a) end
function tmp = code(a, b_2, c) tmp = b_2 / a; end
code[a_, b$95$2_, c_] := N[(b$95$2 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b\_2}{a}
\end{array}
Initial program 49.2%
+-commutative49.2%
unsub-neg49.2%
Simplified49.2%
Taylor expanded in b_2 around 0 30.9%
associate-*r*30.9%
neg-mul-130.9%
*-commutative30.9%
Simplified30.9%
Taylor expanded in b_2 around inf 13.2%
neg-mul-113.2%
Simplified13.2%
div-inv13.2%
add-sqr-sqrt11.9%
sqrt-unprod11.7%
sqr-neg11.7%
sqrt-prod1.6%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
associate-*r/2.5%
*-rgt-identity2.5%
Simplified2.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))