
(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 -5e+153)
(/ (* b_2 -2.0) a)
(if (<= b_2 1.8e+14)
(/ (- (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 <= -5e+153) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 1.8e+14) {
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 <= (-5d+153)) then
tmp = (b_2 * (-2.0d0)) / a
else if (b_2 <= 1.8d+14) 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 <= -5e+153) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 1.8e+14) {
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 <= -5e+153: tmp = (b_2 * -2.0) / a elif b_2 <= 1.8e+14: 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 <= -5e+153) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= 1.8e+14) 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 <= -5e+153) tmp = (b_2 * -2.0) / a; elseif (b_2 <= 1.8e+14) 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, -5e+153], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 1.8e+14], 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 -5 \cdot 10^{+153}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{elif}\;b\_2 \leq 1.8 \cdot 10^{+14}:\\
\;\;\;\;\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 < -5.00000000000000018e153Initial program 39.9%
+-commutative39.9%
unsub-neg39.9%
Simplified39.9%
Taylor expanded in b_2 around -inf 95.5%
*-commutative95.5%
Simplified95.5%
if -5.00000000000000018e153 < b_2 < 1.8e14Initial program 82.8%
+-commutative82.8%
unsub-neg82.8%
Simplified82.8%
if 1.8e14 < b_2 Initial program 19.8%
+-commutative19.8%
unsub-neg19.8%
Simplified19.8%
Taylor expanded in b_2 around inf 90.5%
associate-*r/90.6%
*-commutative90.6%
Simplified90.6%
(FPCore (a b_2 c)
:precision binary64
(let* ((t_0 (sqrt (* a (- c)))))
(if (<= b_2 -4.6e-36)
(/ (* b_2 -2.0) a)
(if (<= b_2 4.6e-36)
(/ (- t_0 b_2) a)
(if (or (<= b_2 3.6) (not (<= b_2 1.8e+14)))
(/ (* c -0.5) b_2)
(/ t_0 a))))))
double code(double a, double b_2, double c) {
double t_0 = sqrt((a * -c));
double tmp;
if (b_2 <= -4.6e-36) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 4.6e-36) {
tmp = (t_0 - b_2) / a;
} else if ((b_2 <= 3.6) || !(b_2 <= 1.8e+14)) {
tmp = (c * -0.5) / b_2;
} else {
tmp = t_0 / a;
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((a * -c))
if (b_2 <= (-4.6d-36)) then
tmp = (b_2 * (-2.0d0)) / a
else if (b_2 <= 4.6d-36) then
tmp = (t_0 - b_2) / a
else if ((b_2 <= 3.6d0) .or. (.not. (b_2 <= 1.8d+14))) then
tmp = (c * (-0.5d0)) / b_2
else
tmp = t_0 / a
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double t_0 = Math.sqrt((a * -c));
double tmp;
if (b_2 <= -4.6e-36) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 4.6e-36) {
tmp = (t_0 - b_2) / a;
} else if ((b_2 <= 3.6) || !(b_2 <= 1.8e+14)) {
tmp = (c * -0.5) / b_2;
} else {
tmp = t_0 / a;
}
return tmp;
}
def code(a, b_2, c): t_0 = math.sqrt((a * -c)) tmp = 0 if b_2 <= -4.6e-36: tmp = (b_2 * -2.0) / a elif b_2 <= 4.6e-36: tmp = (t_0 - b_2) / a elif (b_2 <= 3.6) or not (b_2 <= 1.8e+14): tmp = (c * -0.5) / b_2 else: tmp = t_0 / a return tmp
function code(a, b_2, c) t_0 = sqrt(Float64(a * Float64(-c))) tmp = 0.0 if (b_2 <= -4.6e-36) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= 4.6e-36) tmp = Float64(Float64(t_0 - b_2) / a); elseif ((b_2 <= 3.6) || !(b_2 <= 1.8e+14)) tmp = Float64(Float64(c * -0.5) / b_2); else tmp = Float64(t_0 / a); end return tmp end
function tmp_2 = code(a, b_2, c) t_0 = sqrt((a * -c)); tmp = 0.0; if (b_2 <= -4.6e-36) tmp = (b_2 * -2.0) / a; elseif (b_2 <= 4.6e-36) tmp = (t_0 - b_2) / a; elseif ((b_2 <= 3.6) || ~((b_2 <= 1.8e+14))) tmp = (c * -0.5) / b_2; else tmp = t_0 / a; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := Block[{t$95$0 = N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b$95$2, -4.6e-36], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 4.6e-36], N[(N[(t$95$0 - b$95$2), $MachinePrecision] / a), $MachinePrecision], If[Or[LessEqual[b$95$2, 3.6], N[Not[LessEqual[b$95$2, 1.8e+14]], $MachinePrecision]], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision], N[(t$95$0 / a), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{a \cdot \left(-c\right)}\\
\mathbf{if}\;b\_2 \leq -4.6 \cdot 10^{-36}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{elif}\;b\_2 \leq 4.6 \cdot 10^{-36}:\\
\;\;\;\;\frac{t\_0 - b\_2}{a}\\
\mathbf{elif}\;b\_2 \leq 3.6 \lor \neg \left(b\_2 \leq 1.8 \cdot 10^{+14}\right):\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{a}\\
\end{array}
\end{array}
if b_2 < -4.59999999999999993e-36Initial program 71.7%
+-commutative71.7%
unsub-neg71.7%
Simplified71.7%
Taylor expanded in b_2 around -inf 85.0%
*-commutative85.0%
Simplified85.0%
if -4.59999999999999993e-36 < b_2 < 4.59999999999999993e-36Initial program 79.5%
+-commutative79.5%
unsub-neg79.5%
Simplified79.5%
Taylor expanded in b_2 around 0 70.5%
associate-*r*70.5%
neg-mul-170.5%
*-commutative70.5%
Simplified70.5%
if 4.59999999999999993e-36 < b_2 < 3.60000000000000009 or 1.8e14 < b_2 Initial program 19.4%
+-commutative19.4%
unsub-neg19.4%
Simplified19.4%
Taylor expanded in b_2 around inf 87.5%
associate-*r/87.5%
*-commutative87.5%
Simplified87.5%
if 3.60000000000000009 < b_2 < 1.8e14Initial program 99.4%
+-commutative99.4%
unsub-neg99.4%
Simplified99.4%
prod-diff99.4%
*-commutative99.4%
fma-neg99.4%
prod-diff99.4%
*-commutative99.4%
fma-neg99.4%
associate-+l+99.4%
pow299.4%
*-commutative99.4%
fma-undefine99.4%
distribute-lft-neg-in99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
fma-define99.4%
*-commutative99.4%
fma-undefine99.4%
distribute-lft-neg-in99.4%
*-commutative99.4%
distribute-rgt-neg-in99.4%
Applied egg-rr99.4%
associate-+l-99.4%
count-299.4%
Simplified99.4%
Taylor expanded in b_2 around 0 99.1%
associate-*l/99.4%
Simplified99.4%
Final simplification80.7%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -4e-235)
(/ (* b_2 -2.0) a)
(if (or (<= b_2 4.7e-216) (and (not (<= b_2 1.15e-56)) (<= b_2 4.2e-36)))
(sqrt (/ c (- a)))
(/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4e-235) {
tmp = (b_2 * -2.0) / a;
} else if ((b_2 <= 4.7e-216) || (!(b_2 <= 1.15e-56) && (b_2 <= 4.2e-36))) {
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 <= (-4d-235)) then
tmp = (b_2 * (-2.0d0)) / a
else if ((b_2 <= 4.7d-216) .or. (.not. (b_2 <= 1.15d-56)) .and. (b_2 <= 4.2d-36)) 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 <= -4e-235) {
tmp = (b_2 * -2.0) / a;
} else if ((b_2 <= 4.7e-216) || (!(b_2 <= 1.15e-56) && (b_2 <= 4.2e-36))) {
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 <= -4e-235: tmp = (b_2 * -2.0) / a elif (b_2 <= 4.7e-216) or (not (b_2 <= 1.15e-56) and (b_2 <= 4.2e-36)): 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 <= -4e-235) tmp = Float64(Float64(b_2 * -2.0) / a); elseif ((b_2 <= 4.7e-216) || (!(b_2 <= 1.15e-56) && (b_2 <= 4.2e-36))) 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 <= -4e-235) tmp = (b_2 * -2.0) / a; elseif ((b_2 <= 4.7e-216) || (~((b_2 <= 1.15e-56)) && (b_2 <= 4.2e-36))) 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, -4e-235], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[Or[LessEqual[b$95$2, 4.7e-216], And[N[Not[LessEqual[b$95$2, 1.15e-56]], $MachinePrecision], LessEqual[b$95$2, 4.2e-36]]], 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 -4 \cdot 10^{-235}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{elif}\;b\_2 \leq 4.7 \cdot 10^{-216} \lor \neg \left(b\_2 \leq 1.15 \cdot 10^{-56}\right) \land b\_2 \leq 4.2 \cdot 10^{-36}:\\
\;\;\;\;\sqrt{\frac{c}{-a}}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -3.9999999999999998e-235Initial program 77.7%
+-commutative77.7%
unsub-neg77.7%
Simplified77.7%
Taylor expanded in b_2 around -inf 69.3%
*-commutative69.3%
Simplified69.3%
if -3.9999999999999998e-235 < b_2 < 4.7e-216 or 1.15000000000000001e-56 < b_2 < 4.19999999999999982e-36Initial program 77.1%
+-commutative77.1%
unsub-neg77.1%
Simplified77.1%
prod-diff76.7%
*-commutative76.7%
fma-neg76.7%
prod-diff76.7%
*-commutative76.7%
fma-neg76.7%
associate-+l+76.8%
pow276.8%
*-commutative76.8%
fma-undefine76.7%
distribute-lft-neg-in76.7%
*-commutative76.7%
distribute-rgt-neg-in76.7%
fma-define76.8%
*-commutative76.8%
fma-undefine76.7%
distribute-lft-neg-in76.7%
*-commutative76.7%
distribute-rgt-neg-in76.7%
Applied egg-rr76.8%
associate-+l-76.8%
count-276.8%
Simplified76.8%
Taylor expanded in a around inf 49.9%
distribute-rgt1-in49.9%
metadata-eval49.9%
mul0-lft49.9%
metadata-eval49.9%
neg-sub049.9%
Simplified49.9%
if 4.7e-216 < b_2 < 1.15000000000000001e-56 or 4.19999999999999982e-36 < b_2 Initial program 36.2%
+-commutative36.2%
unsub-neg36.2%
Simplified36.2%
Taylor expanded in b_2 around inf 68.3%
associate-*r/68.3%
*-commutative68.3%
Simplified68.3%
Final simplification66.8%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -1.05e-77) (/ (* b_2 -2.0) a) (if (<= b_2 1.8e+14) (/ (sqrt (* a (- c))) a) (/ (* c -0.5) b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -1.05e-77) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 1.8e+14) {
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 <= (-1.05d-77)) then
tmp = (b_2 * (-2.0d0)) / a
else if (b_2 <= 1.8d+14) 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 <= -1.05e-77) {
tmp = (b_2 * -2.0) / a;
} else if (b_2 <= 1.8e+14) {
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 <= -1.05e-77: tmp = (b_2 * -2.0) / a elif b_2 <= 1.8e+14: 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 <= -1.05e-77) tmp = Float64(Float64(b_2 * -2.0) / a); elseif (b_2 <= 1.8e+14) 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 <= -1.05e-77) tmp = (b_2 * -2.0) / a; elseif (b_2 <= 1.8e+14) 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, -1.05e-77], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, 1.8e+14], 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 -1.05 \cdot 10^{-77}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{elif}\;b\_2 \leq 1.8 \cdot 10^{+14}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -1.05000000000000008e-77Initial program 73.3%
+-commutative73.3%
unsub-neg73.3%
Simplified73.3%
Taylor expanded in b_2 around -inf 81.6%
*-commutative81.6%
Simplified81.6%
if -1.05000000000000008e-77 < b_2 < 1.8e14Initial program 74.5%
+-commutative74.5%
unsub-neg74.5%
Simplified74.5%
prod-diff74.2%
*-commutative74.2%
fma-neg74.2%
prod-diff74.2%
*-commutative74.2%
fma-neg74.2%
associate-+l+74.2%
pow274.2%
*-commutative74.2%
fma-undefine74.2%
distribute-lft-neg-in74.2%
*-commutative74.2%
distribute-rgt-neg-in74.2%
fma-define74.2%
*-commutative74.2%
fma-undefine74.2%
distribute-lft-neg-in74.2%
*-commutative74.2%
distribute-rgt-neg-in74.2%
Applied egg-rr74.2%
associate-+l-74.2%
count-274.2%
Simplified74.2%
Taylor expanded in b_2 around 0 68.0%
associate-*l/68.1%
Simplified68.4%
if 1.8e14 < b_2 Initial program 19.8%
+-commutative19.8%
unsub-neg19.8%
Simplified19.8%
Taylor expanded in b_2 around inf 90.5%
associate-*r/90.6%
*-commutative90.6%
Simplified90.6%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -4e-310) (/ (* b_2 -2.0) a) (/ (* c -0.5) b_2)))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4e-310) {
tmp = (b_2 * -2.0) / 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 <= (-4d-310)) then
tmp = (b_2 * (-2.0d0)) / 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 <= -4e-310) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = (c * -0.5) / b_2;
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -4e-310: tmp = (b_2 * -2.0) / a else: tmp = (c * -0.5) / b_2 return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -4e-310) tmp = Float64(Float64(b_2 * -2.0) / 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 <= -4e-310) tmp = (b_2 * -2.0) / a; else tmp = (c * -0.5) / b_2; end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4e-310], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -3.999999999999988e-310Initial program 78.0%
+-commutative78.0%
unsub-neg78.0%
Simplified78.0%
Taylor expanded in b_2 around -inf 63.3%
*-commutative63.3%
Simplified63.3%
if -3.999999999999988e-310 < b_2 Initial program 41.1%
+-commutative41.1%
unsub-neg41.1%
Simplified41.1%
Taylor expanded in b_2 around inf 60.0%
associate-*r/60.0%
*-commutative60.0%
Simplified60.0%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -4e-310) (/ (* b_2 -2.0) a) (* c (/ -0.5 b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4e-310) {
tmp = (b_2 * -2.0) / 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 <= (-4d-310)) then
tmp = (b_2 * (-2.0d0)) / 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 <= -4e-310) {
tmp = (b_2 * -2.0) / a;
} else {
tmp = c * (-0.5 / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -4e-310: tmp = (b_2 * -2.0) / a else: tmp = c * (-0.5 / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -4e-310) tmp = Float64(Float64(b_2 * -2.0) / 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 <= -4e-310) tmp = (b_2 * -2.0) / a; else tmp = c * (-0.5 / b_2); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4e-310], N[(N[(b$95$2 * -2.0), $MachinePrecision] / a), $MachinePrecision], N[(c * N[(-0.5 / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{b\_2 \cdot -2}{a}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \frac{-0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -3.999999999999988e-310Initial program 78.0%
+-commutative78.0%
unsub-neg78.0%
Simplified78.0%
Taylor expanded in b_2 around -inf 63.3%
*-commutative63.3%
Simplified63.3%
if -3.999999999999988e-310 < b_2 Initial program 41.1%
+-commutative41.1%
unsub-neg41.1%
Simplified41.1%
add-sqr-sqrt36.0%
pow236.0%
pow1/236.0%
sqrt-pow136.1%
pow236.1%
metadata-eval36.1%
Applied egg-rr36.1%
Taylor expanded in b_2 around inf 60.0%
metadata-eval60.0%
times-frac60.0%
*-commutative60.0%
times-frac59.7%
/-rgt-identity59.7%
Simplified59.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -4e-310) (/ b_2 (- a)) (* c (/ -0.5 b_2))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4e-310) {
tmp = 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 <= (-4d-310)) then
tmp = 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 <= -4e-310) {
tmp = b_2 / -a;
} else {
tmp = c * (-0.5 / b_2);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -4e-310: tmp = b_2 / -a else: tmp = c * (-0.5 / b_2) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -4e-310) tmp = Float64(b_2 / Float64(-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 <= -4e-310) tmp = 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, -4e-310], N[(b$95$2 / (-a)), $MachinePrecision], N[(c * N[(-0.5 / b$95$2), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{b\_2}{-a}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \frac{-0.5}{b\_2}\\
\end{array}
\end{array}
if b_2 < -3.999999999999988e-310Initial program 78.0%
+-commutative78.0%
unsub-neg78.0%
Simplified78.0%
prod-diff77.8%
*-commutative77.8%
fma-neg77.8%
prod-diff77.8%
*-commutative77.8%
fma-neg77.8%
associate-+l+77.8%
pow277.8%
*-commutative77.8%
fma-undefine77.8%
distribute-lft-neg-in77.8%
*-commutative77.8%
distribute-rgt-neg-in77.8%
fma-define77.8%
*-commutative77.8%
fma-undefine77.8%
distribute-lft-neg-in77.8%
*-commutative77.8%
distribute-rgt-neg-in77.8%
Applied egg-rr77.8%
associate-+l-77.8%
count-277.8%
Simplified77.8%
Taylor expanded in c around inf 27.6%
mul-1-neg27.6%
unsub-neg27.6%
distribute-rgt1-in27.6%
metadata-eval27.6%
mul0-lft27.6%
metadata-eval27.6%
neg-sub027.6%
Simplified27.6%
Taylor expanded in b_2 around inf 24.7%
neg-mul-124.7%
distribute-neg-frac224.7%
Simplified24.7%
if -3.999999999999988e-310 < b_2 Initial program 41.1%
+-commutative41.1%
unsub-neg41.1%
Simplified41.1%
add-sqr-sqrt36.0%
pow236.0%
pow1/236.0%
sqrt-pow136.1%
pow236.1%
metadata-eval36.1%
Applied egg-rr36.1%
Taylor expanded in b_2 around inf 60.0%
metadata-eval60.0%
times-frac60.0%
*-commutative60.0%
times-frac59.7%
/-rgt-identity59.7%
Simplified59.7%
(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 / Float64(-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 61.4%
+-commutative61.4%
unsub-neg61.4%
Simplified61.4%
prod-diff61.2%
*-commutative61.2%
fma-neg61.2%
prod-diff61.2%
*-commutative61.2%
fma-neg61.2%
associate-+l+61.1%
pow261.1%
*-commutative61.1%
fma-undefine61.2%
distribute-lft-neg-in61.2%
*-commutative61.2%
distribute-rgt-neg-in61.2%
fma-define61.1%
*-commutative61.1%
fma-undefine61.2%
distribute-lft-neg-in61.2%
*-commutative61.2%
distribute-rgt-neg-in61.2%
Applied egg-rr61.1%
associate-+l-61.1%
count-261.1%
Simplified61.1%
Taylor expanded in c around inf 23.7%
mul-1-neg23.7%
unsub-neg23.7%
distribute-rgt1-in23.7%
metadata-eval23.7%
mul0-lft23.7%
metadata-eval23.7%
neg-sub023.7%
Simplified23.7%
Taylor expanded in b_2 around inf 14.8%
neg-mul-114.8%
distribute-neg-frac214.8%
Simplified14.8%
(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 2024089
(FPCore (a b_2 c)
:name "quad2p (problem 3.2.1, positive)"
:precision binary64
:herbie-expected 10
:alt
(if (< b_2 0.0) (/ (- (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) a) (/ (- c) (+ 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))))))))
(/ (+ (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))