
(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 -6.8e-62)
(/ 1.0 (fma 0.5 (/ a b_2) (/ -2.0 (/ c b_2))))
(if (<= b_2 -5.1e-124)
(/ (/ (* a c) (fma -1.0 b_2 (hypot b_2 (sqrt (* a (- c)))))) a)
(if (<= b_2 -7e-135)
(/ (* c -0.5) b_2)
(if (<= b_2 5.6e+81)
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a)
(* -2.0 (/ b_2 a)))))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -6.8e-62) {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 / (c / b_2)));
} else if (b_2 <= -5.1e-124) {
tmp = ((a * c) / fma(-1.0, b_2, hypot(b_2, sqrt((a * -c))))) / a;
} else if (b_2 <= -7e-135) {
tmp = (c * -0.5) / b_2;
} else if (b_2 <= 5.6e+81) {
tmp = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -6.8e-62) tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 / Float64(c / b_2)))); elseif (b_2 <= -5.1e-124) tmp = Float64(Float64(Float64(a * c) / fma(-1.0, b_2, hypot(b_2, sqrt(Float64(a * Float64(-c)))))) / a); elseif (b_2 <= -7e-135) tmp = Float64(Float64(c * -0.5) / b_2); elseif (b_2 <= 5.6e+81) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -6.8e-62], N[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 / N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, -5.1e-124], N[(N[(N[(a * c), $MachinePrecision] / N[(-1.0 * b$95$2 + N[Sqrt[b$95$2 ^ 2 + N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b$95$2, -7e-135], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 5.6e+81], 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], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -6.8 \cdot 10^{-62}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b\_2}, \frac{-2}{\frac{c}{b\_2}}\right)}\\
\mathbf{elif}\;b\_2 \leq -5.1 \cdot 10^{-124}:\\
\;\;\;\;\frac{\frac{a \cdot c}{\mathsf{fma}\left(-1, b\_2, \mathsf{hypot}\left(b\_2, \sqrt{a \cdot \left(-c\right)}\right)\right)}}{a}\\
\mathbf{elif}\;b\_2 \leq -7 \cdot 10^{-135}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 5.6 \cdot 10^{+81}:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -6.79999999999999975e-62Initial program 14.4%
add-sqr-sqrt12.3%
pow212.3%
pow1/212.3%
sqrt-pow112.2%
pow212.2%
metadata-eval12.2%
Applied egg-rr12.2%
clear-num12.2%
inv-pow12.2%
pow-pow14.4%
metadata-eval14.4%
pow1/214.4%
sub-neg14.4%
unpow214.4%
distribute-rgt-neg-out14.4%
add-sqr-sqrt10.6%
hypot-undefine16.1%
Applied egg-rr16.1%
unpow-116.1%
distribute-rgt-neg-out16.1%
distribute-lft-neg-in16.1%
Simplified16.1%
Taylor expanded in b_2 around -inf 0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt90.3%
times-frac90.3%
metadata-eval90.3%
Simplified90.3%
clear-num90.4%
un-div-inv90.4%
Applied egg-rr90.4%
if -6.79999999999999975e-62 < b_2 < -5.1000000000000001e-124Initial program 67.4%
add-sqr-sqrt67.5%
pow267.5%
pow1/267.5%
sqrt-pow167.5%
pow267.5%
metadata-eval67.5%
Applied egg-rr67.5%
flip--67.3%
pow267.3%
pow-pow67.5%
metadata-eval67.5%
pow-pow66.9%
metadata-eval66.9%
pow1/266.9%
pow1/266.9%
add-sqr-sqrt67.3%
neg-mul-167.3%
fma-define67.3%
pow-pow67.5%
Applied egg-rr67.5%
associate--r-99.8%
unpow299.8%
sqr-neg99.8%
unpow299.8%
+-inverses99.8%
distribute-rgt-neg-out99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
if -5.1000000000000001e-124 < b_2 < -6.9999999999999997e-135Initial program 3.9%
Taylor expanded in b_2 around -inf 100.0%
*-commutative100.0%
associate-*l/100.0%
Simplified100.0%
if -6.9999999999999997e-135 < b_2 < 5.5999999999999999e81Initial program 80.3%
if 5.5999999999999999e81 < b_2 Initial program 59.0%
Taylor expanded in b_2 around inf 96.9%
Final simplification88.9%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -7e-135)
(/ 1.0 (fma 0.5 (/ a b_2) (/ -2.0 (/ c b_2))))
(if (<= b_2 3.5e+89)
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a)
(* -2.0 (/ b_2 a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7e-135) {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 / (c / b_2)));
} else if (b_2 <= 3.5e+89) {
tmp = (-b_2 - sqrt(((b_2 * b_2) - (a * c)))) / a;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -7e-135) tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 / Float64(c / b_2)))); elseif (b_2 <= 3.5e+89) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(Float64(b_2 * b_2) - Float64(a * c)))) / a); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7e-135], N[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 / N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 3.5e+89], 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], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -7 \cdot 10^{-135}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b\_2}, \frac{-2}{\frac{c}{b\_2}}\right)}\\
\mathbf{elif}\;b\_2 \leq 3.5 \cdot 10^{+89}:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{b\_2 \cdot b\_2 - a \cdot c}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -6.9999999999999997e-135Initial program 17.9%
add-sqr-sqrt15.9%
pow215.9%
pow1/215.9%
sqrt-pow115.9%
pow215.9%
metadata-eval15.9%
Applied egg-rr15.9%
clear-num15.9%
inv-pow15.9%
pow-pow17.8%
metadata-eval17.8%
pow1/217.8%
sub-neg17.8%
unpow217.8%
distribute-rgt-neg-out17.8%
add-sqr-sqrt14.4%
hypot-undefine19.3%
Applied egg-rr19.3%
unpow-119.3%
distribute-rgt-neg-out19.3%
distribute-lft-neg-in19.3%
Simplified19.3%
Taylor expanded in b_2 around -inf 0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt87.1%
times-frac87.1%
metadata-eval87.1%
Simplified87.1%
clear-num87.2%
un-div-inv87.2%
Applied egg-rr87.2%
if -6.9999999999999997e-135 < b_2 < 3.5000000000000001e89Initial program 80.3%
if 3.5000000000000001e89 < b_2 Initial program 59.0%
Taylor expanded in b_2 around inf 96.9%
Final simplification87.1%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -7e-135)
(/ (* c -0.5) b_2)
(if (<= b_2 2.65e-20)
(/ (- (- b_2) (sqrt (* a (- c)))) a)
(* -2.0 (/ b_2 a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7e-135) {
tmp = (c * -0.5) / b_2;
} else if (b_2 <= 2.65e-20) {
tmp = (-b_2 - sqrt((a * -c))) / a;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-7d-135)) then
tmp = (c * (-0.5d0)) / b_2
else if (b_2 <= 2.65d-20) then
tmp = (-b_2 - sqrt((a * -c))) / a
else
tmp = (-2.0d0) * (b_2 / a)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7e-135) {
tmp = (c * -0.5) / b_2;
} else if (b_2 <= 2.65e-20) {
tmp = (-b_2 - Math.sqrt((a * -c))) / a;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -7e-135: tmp = (c * -0.5) / b_2 elif b_2 <= 2.65e-20: tmp = (-b_2 - math.sqrt((a * -c))) / a else: tmp = -2.0 * (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -7e-135) tmp = Float64(Float64(c * -0.5) / b_2); elseif (b_2 <= 2.65e-20) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(a * Float64(-c)))) / a); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -7e-135) tmp = (c * -0.5) / b_2; elseif (b_2 <= 2.65e-20) tmp = (-b_2 - sqrt((a * -c))) / a; else tmp = -2.0 * (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7e-135], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision], If[LessEqual[b$95$2, 2.65e-20], N[(N[((-b$95$2) - N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -7 \cdot 10^{-135}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\mathbf{elif}\;b\_2 \leq 2.65 \cdot 10^{-20}:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -6.9999999999999997e-135Initial program 17.9%
Taylor expanded in b_2 around -inf 86.9%
*-commutative86.9%
associate-*l/86.9%
Simplified86.9%
if -6.9999999999999997e-135 < b_2 < 2.6500000000000001e-20Initial program 78.4%
Taylor expanded in b_2 around 0 69.5%
mul-1-neg69.5%
distribute-rgt-neg-out69.5%
Simplified69.5%
if 2.6500000000000001e-20 < b_2 Initial program 64.0%
Taylor expanded in b_2 around inf 94.6%
Final simplification83.5%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -7e-135)
(/ 1.0 (fma 0.5 (/ a b_2) (* -2.0 (/ b_2 c))))
(if (<= b_2 1.05e-17)
(/ (- (- b_2) (sqrt (* a (- c)))) a)
(* -2.0 (/ b_2 a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7e-135) {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 * (b_2 / c)));
} else if (b_2 <= 1.05e-17) {
tmp = (-b_2 - sqrt((a * -c))) / a;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -7e-135) tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 * Float64(b_2 / c)))); elseif (b_2 <= 1.05e-17) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(a * Float64(-c)))) / a); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7e-135], N[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 * N[(b$95$2 / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 1.05e-17], N[(N[((-b$95$2) - N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -7 \cdot 10^{-135}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b\_2}, -2 \cdot \frac{b\_2}{c}\right)}\\
\mathbf{elif}\;b\_2 \leq 1.05 \cdot 10^{-17}:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -6.9999999999999997e-135Initial program 17.9%
add-sqr-sqrt15.9%
pow215.9%
pow1/215.9%
sqrt-pow115.9%
pow215.9%
metadata-eval15.9%
Applied egg-rr15.9%
clear-num15.9%
inv-pow15.9%
pow-pow17.8%
metadata-eval17.8%
pow1/217.8%
sub-neg17.8%
unpow217.8%
distribute-rgt-neg-out17.8%
add-sqr-sqrt14.4%
hypot-undefine19.3%
Applied egg-rr19.3%
unpow-119.3%
distribute-rgt-neg-out19.3%
distribute-lft-neg-in19.3%
Simplified19.3%
Taylor expanded in b_2 around -inf 0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt87.1%
times-frac87.1%
metadata-eval87.1%
Simplified87.1%
if -6.9999999999999997e-135 < b_2 < 1.04999999999999996e-17Initial program 78.4%
Taylor expanded in b_2 around 0 69.5%
mul-1-neg69.5%
distribute-rgt-neg-out69.5%
Simplified69.5%
if 1.04999999999999996e-17 < b_2 Initial program 64.0%
Taylor expanded in b_2 around inf 94.6%
Final simplification83.6%
(FPCore (a b_2 c)
:precision binary64
(if (<= b_2 -7e-135)
(/ 1.0 (fma 0.5 (/ a b_2) (/ -2.0 (/ c b_2))))
(if (<= b_2 8.4e-18)
(/ (- (- b_2) (sqrt (* a (- c)))) a)
(* -2.0 (/ b_2 a)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -7e-135) {
tmp = 1.0 / fma(0.5, (a / b_2), (-2.0 / (c / b_2)));
} else if (b_2 <= 8.4e-18) {
tmp = (-b_2 - sqrt((a * -c))) / a;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -7e-135) tmp = Float64(1.0 / fma(0.5, Float64(a / b_2), Float64(-2.0 / Float64(c / b_2)))); elseif (b_2 <= 8.4e-18) tmp = Float64(Float64(Float64(-b_2) - sqrt(Float64(a * Float64(-c)))) / a); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -7e-135], N[(1.0 / N[(0.5 * N[(a / b$95$2), $MachinePrecision] + N[(-2.0 / N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b$95$2, 8.4e-18], N[(N[((-b$95$2) - N[Sqrt[N[(a * (-c)), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -7 \cdot 10^{-135}:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(0.5, \frac{a}{b\_2}, \frac{-2}{\frac{c}{b\_2}}\right)}\\
\mathbf{elif}\;b\_2 \leq 8.4 \cdot 10^{-18}:\\
\;\;\;\;\frac{\left(-b\_2\right) - \sqrt{a \cdot \left(-c\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -6.9999999999999997e-135Initial program 17.9%
add-sqr-sqrt15.9%
pow215.9%
pow1/215.9%
sqrt-pow115.9%
pow215.9%
metadata-eval15.9%
Applied egg-rr15.9%
clear-num15.9%
inv-pow15.9%
pow-pow17.8%
metadata-eval17.8%
pow1/217.8%
sub-neg17.8%
unpow217.8%
distribute-rgt-neg-out17.8%
add-sqr-sqrt14.4%
hypot-undefine19.3%
Applied egg-rr19.3%
unpow-119.3%
distribute-rgt-neg-out19.3%
distribute-lft-neg-in19.3%
Simplified19.3%
Taylor expanded in b_2 around -inf 0.0%
fma-define0.0%
associate-*r/0.0%
*-commutative0.0%
unpow20.0%
rem-square-sqrt87.1%
times-frac87.1%
metadata-eval87.1%
Simplified87.1%
clear-num87.2%
un-div-inv87.2%
Applied egg-rr87.2%
if -6.9999999999999997e-135 < b_2 < 8.39999999999999998e-18Initial program 78.4%
Taylor expanded in b_2 around 0 69.5%
mul-1-neg69.5%
distribute-rgt-neg-out69.5%
Simplified69.5%
if 8.39999999999999998e-18 < b_2 Initial program 64.0%
Taylor expanded in b_2 around inf 94.6%
Final simplification83.7%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -4e-310) (/ (* c -0.5) b_2) (+ (* -2.0 (/ b_2 a)) (* 0.5 (/ c b_2)))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -4e-310) {
tmp = (c * -0.5) / b_2;
} else {
tmp = (-2.0 * (b_2 / a)) + (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 <= (-4d-310)) then
tmp = (c * (-0.5d0)) / b_2
else
tmp = ((-2.0d0) * (b_2 / a)) + (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 <= -4e-310) {
tmp = (c * -0.5) / b_2;
} else {
tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2));
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -4e-310: tmp = (c * -0.5) / b_2 else: tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -4e-310) tmp = Float64(Float64(c * -0.5) / b_2); else tmp = Float64(Float64(-2.0 * Float64(b_2 / a)) + 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 <= -4e-310) tmp = (c * -0.5) / b_2; else tmp = (-2.0 * (b_2 / a)) + (0.5 * (c / b_2)); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -4e-310], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision], N[(N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision] + N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a} + 0.5 \cdot \frac{c}{b\_2}\\
\end{array}
\end{array}
if b_2 < -3.999999999999988e-310Initial program 30.0%
Taylor expanded in b_2 around -inf 71.2%
*-commutative71.2%
associate-*l/71.2%
Simplified71.2%
if -3.999999999999988e-310 < b_2 Initial program 70.7%
Taylor expanded in b_2 around inf 63.3%
Final simplification67.6%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -2.2e+17) (* 0.5 (/ c b_2)) (* -2.0 (/ b_2 a))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.2e+17) {
tmp = 0.5 * (c / b_2);
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-2.2d+17)) then
tmp = 0.5d0 * (c / b_2)
else
tmp = (-2.0d0) * (b_2 / a)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -2.2e+17) {
tmp = 0.5 * (c / b_2);
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -2.2e+17: tmp = 0.5 * (c / b_2) else: tmp = -2.0 * (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -2.2e+17) tmp = Float64(0.5 * Float64(c / b_2)); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -2.2e+17) tmp = 0.5 * (c / b_2); else tmp = -2.0 * (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -2.2e+17], N[(0.5 * N[(c / b$95$2), $MachinePrecision]), $MachinePrecision], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -2.2 \cdot 10^{+17}:\\
\;\;\;\;0.5 \cdot \frac{c}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -2.2e17Initial program 10.0%
Taylor expanded in b_2 around inf 2.3%
Taylor expanded in b_2 around 0 22.7%
if -2.2e17 < b_2 Initial program 65.9%
Taylor expanded in b_2 around inf 42.8%
Final simplification36.5%
(FPCore (a b_2 c) :precision binary64 (if (<= b_2 -9.4e-291) (/ (* c -0.5) b_2) (* -2.0 (/ b_2 a))))
double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -9.4e-291) {
tmp = (c * -0.5) / b_2;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
real(8) function code(a, b_2, c)
real(8), intent (in) :: a
real(8), intent (in) :: b_2
real(8), intent (in) :: c
real(8) :: tmp
if (b_2 <= (-9.4d-291)) then
tmp = (c * (-0.5d0)) / b_2
else
tmp = (-2.0d0) * (b_2 / a)
end if
code = tmp
end function
public static double code(double a, double b_2, double c) {
double tmp;
if (b_2 <= -9.4e-291) {
tmp = (c * -0.5) / b_2;
} else {
tmp = -2.0 * (b_2 / a);
}
return tmp;
}
def code(a, b_2, c): tmp = 0 if b_2 <= -9.4e-291: tmp = (c * -0.5) / b_2 else: tmp = -2.0 * (b_2 / a) return tmp
function code(a, b_2, c) tmp = 0.0 if (b_2 <= -9.4e-291) tmp = Float64(Float64(c * -0.5) / b_2); else tmp = Float64(-2.0 * Float64(b_2 / a)); end return tmp end
function tmp_2 = code(a, b_2, c) tmp = 0.0; if (b_2 <= -9.4e-291) tmp = (c * -0.5) / b_2; else tmp = -2.0 * (b_2 / a); end tmp_2 = tmp; end
code[a_, b$95$2_, c_] := If[LessEqual[b$95$2, -9.4e-291], N[(N[(c * -0.5), $MachinePrecision] / b$95$2), $MachinePrecision], N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b\_2 \leq -9.4 \cdot 10^{-291}:\\
\;\;\;\;\frac{c \cdot -0.5}{b\_2}\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot \frac{b\_2}{a}\\
\end{array}
\end{array}
if b_2 < -9.3999999999999997e-291Initial program 28.4%
Taylor expanded in b_2 around -inf 72.7%
*-commutative72.7%
associate-*l/72.7%
Simplified72.7%
if -9.3999999999999997e-291 < b_2 Initial program 71.5%
Taylor expanded in b_2 around inf 61.6%
Final simplification67.5%
(FPCore (a b_2 c) :precision binary64 (* -2.0 (/ b_2 a)))
double code(double a, double b_2, double c) {
return -2.0 * (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 = (-2.0d0) * (b_2 / a)
end function
public static double code(double a, double b_2, double c) {
return -2.0 * (b_2 / a);
}
def code(a, b_2, c): return -2.0 * (b_2 / a)
function code(a, b_2, c) return Float64(-2.0 * Float64(b_2 / a)) end
function tmp = code(a, b_2, c) tmp = -2.0 * (b_2 / a); end
code[a_, b$95$2_, c_] := N[(-2.0 * N[(b$95$2 / a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
-2 \cdot \frac{b\_2}{a}
\end{array}
Initial program 48.4%
Taylor expanded in b_2 around inf 30.2%
Final simplification30.2%
(FPCore (a b_2 c)
:precision binary64
(let* ((t_0 (* (sqrt (fabs a)) (sqrt (fabs c))))
(t_1
(if (== (copysign a c) a)
(* (sqrt (- (fabs b_2) t_0)) (sqrt (+ (fabs b_2) t_0)))
(hypot b_2 t_0))))
(if (< b_2 0.0) (/ c (- t_1 b_2)) (/ (+ b_2 t_1) (- a)))))
double code(double a, double b_2, double c) {
double t_0 = sqrt(fabs(a)) * sqrt(fabs(c));
double tmp;
if (copysign(a, c) == a) {
tmp = sqrt((fabs(b_2) - t_0)) * sqrt((fabs(b_2) + t_0));
} else {
tmp = hypot(b_2, t_0);
}
double t_1 = tmp;
double tmp_1;
if (b_2 < 0.0) {
tmp_1 = c / (t_1 - b_2);
} else {
tmp_1 = (b_2 + t_1) / -a;
}
return tmp_1;
}
public static double code(double a, double b_2, double c) {
double t_0 = Math.sqrt(Math.abs(a)) * Math.sqrt(Math.abs(c));
double tmp;
if (Math.copySign(a, c) == a) {
tmp = Math.sqrt((Math.abs(b_2) - t_0)) * Math.sqrt((Math.abs(b_2) + t_0));
} else {
tmp = Math.hypot(b_2, t_0);
}
double t_1 = tmp;
double tmp_1;
if (b_2 < 0.0) {
tmp_1 = c / (t_1 - b_2);
} else {
tmp_1 = (b_2 + t_1) / -a;
}
return tmp_1;
}
def code(a, b_2, c): t_0 = math.sqrt(math.fabs(a)) * math.sqrt(math.fabs(c)) tmp = 0 if math.copysign(a, c) == a: tmp = math.sqrt((math.fabs(b_2) - t_0)) * math.sqrt((math.fabs(b_2) + t_0)) else: tmp = math.hypot(b_2, t_0) t_1 = tmp tmp_1 = 0 if b_2 < 0.0: tmp_1 = c / (t_1 - b_2) else: tmp_1 = (b_2 + t_1) / -a return tmp_1
function code(a, b_2, c) t_0 = Float64(sqrt(abs(a)) * sqrt(abs(c))) tmp = 0.0 if (copysign(a, c) == a) tmp = Float64(sqrt(Float64(abs(b_2) - t_0)) * sqrt(Float64(abs(b_2) + t_0))); else tmp = hypot(b_2, t_0); end t_1 = tmp tmp_1 = 0.0 if (b_2 < 0.0) tmp_1 = Float64(c / Float64(t_1 - b_2)); else tmp_1 = Float64(Float64(b_2 + t_1) / Float64(-a)); end return tmp_1 end
function tmp_3 = code(a, b_2, c) t_0 = sqrt(abs(a)) * sqrt(abs(c)); tmp = 0.0; if ((sign(c) * abs(a)) == a) tmp = sqrt((abs(b_2) - t_0)) * sqrt((abs(b_2) + t_0)); else tmp = hypot(b_2, t_0); end t_1 = tmp; tmp_2 = 0.0; if (b_2 < 0.0) tmp_2 = c / (t_1 - b_2); else tmp_2 = (b_2 + t_1) / -a; end tmp_3 = tmp_2; end
code[a_, b$95$2_, c_] := Block[{t$95$0 = N[(N[Sqrt[N[Abs[a], $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[Abs[c], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = If[Equal[N[With[{TMP1 = Abs[a], TMP2 = Sign[c]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision], a], N[(N[Sqrt[N[(N[Abs[b$95$2], $MachinePrecision] - t$95$0), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(N[Abs[b$95$2], $MachinePrecision] + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[b$95$2 ^ 2 + t$95$0 ^ 2], $MachinePrecision]]}, If[Less[b$95$2, 0.0], N[(c / N[(t$95$1 - b$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(b$95$2 + t$95$1), $MachinePrecision] / (-a)), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left|a\right|} \cdot \sqrt{\left|c\right|}\\
t_1 := \begin{array}{l}
\mathbf{if}\;\mathsf{copysign}\left(a, c\right) = a:\\
\;\;\;\;\sqrt{\left|b\_2\right| - t\_0} \cdot \sqrt{\left|b\_2\right| + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{hypot}\left(b\_2, t\_0\right)\\
\end{array}\\
\mathbf{if}\;b\_2 < 0:\\
\;\;\;\;\frac{c}{t\_1 - b\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b\_2 + t\_1}{-a}\\
\end{array}
\end{array}
herbie shell --seed 2024046
(FPCore (a b_2 c)
:name "quad2m (problem 3.2.1, negative)"
:precision binary64
:herbie-expected 10
:alt
(if (< b_2 0.0) (/ c (- (if (== (copysign a c) a) (* (sqrt (- (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot b_2 (* (sqrt (fabs a)) (sqrt (fabs c))))) b_2)) (/ (+ b_2 (if (== (copysign a c) a) (* (sqrt (- (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c))))) (sqrt (+ (fabs b_2) (* (sqrt (fabs a)) (sqrt (fabs c)))))) (hypot b_2 (* (sqrt (fabs a)) (sqrt (fabs c)))))) (- a)))
(/ (- (- b_2) (sqrt (- (* b_2 b_2) (* a c)))) a))