
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (2.0d0 * c) / (-b - t_0)
else
tmp = (-b + t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (-b - t_0) else: tmp = (-b + t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b >= 0.0) tmp = (2.0 * c) / (-b - t_0); else tmp = (-b + t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- b) t_0) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (2.0d0 * c) / (-b - t_0)
else
tmp = (-b + t_0) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = (-b + t_0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (-b - t_0) else: tmp = (-b + t_0) / (2.0 * a) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b >= 0.0) tmp = (2.0 * c) / (-b - t_0); else tmp = (-b + t_0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0)))))
(t_1 (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))))
(if (<= b -5e+154)
(if (>= b 0.0) t_1 (/ (fabs (+ b (fma -2.0 (* c (/ a b)) b))) (* 2.0 a)))
(if (<= b 1e+135)
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (- t_0 b) (* 2.0 a)))
(if (>= b 0.0) t_1 (* 0.5 (/ (* 2.0 (fabs (- (* a (/ c b)) b))) a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double t_1 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
double tmp_1;
if (b <= -5e+154) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = fabs((b + fma(-2.0, (c * (a / b)), b))) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 1e+135) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (2.0 * c) / (-b - t_0);
} else {
tmp_3 = (t_0 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_1;
} else {
tmp_1 = 0.5 * ((2.0 * fabs(((a * (c / b)) - b))) / a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) t_1 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))) tmp_1 = 0.0 if (b <= -5e+154) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(abs(Float64(b + fma(-2.0, Float64(c * Float64(a / b)), b))) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 1e+135) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp_3 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_1; else tmp_1 = Float64(0.5 * Float64(Float64(2.0 * abs(Float64(Float64(a * Float64(c / b)) - b))) / a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -5e+154], If[GreaterEqual[b, 0.0], t$95$1, N[(N[Abs[N[(b + N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1e+135], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$1, N[(0.5 * N[(N[(2.0 * N[Abs[N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
t_1 := \frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|b + \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)\right|}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{+135}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{2 \cdot \left|a \cdot \frac{c}{b} - b\right|}{a}\\
\end{array}
\end{array}
if b < -5.00000000000000004e154Initial program 41.1%
Taylor expanded in a around 0 41.1%
distribute-lft-out--41.1%
associate-/l*41.1%
fma-neg41.1%
Simplified41.1%
Taylor expanded in a around 0 2.0%
add-sqr-sqrt1.9%
sqrt-unprod2.1%
pow22.1%
add-sqr-sqrt12.4%
sqrt-unprod41.0%
sqr-neg41.0%
sqrt-prod0.0%
add-sqr-sqrt41.3%
+-commutative41.3%
fma-define41.3%
associate-/l*41.3%
Applied egg-rr41.3%
unpow241.3%
rem-sqrt-square98.3%
associate-*r/88.8%
*-commutative88.8%
associate-*r/98.3%
Simplified98.3%
if -5.00000000000000004e154 < b < 9.99999999999999962e134Initial program 87.4%
if 9.99999999999999962e134 < b Initial program 49.3%
Taylor expanded in a around 0 93.5%
distribute-lft-out--93.5%
associate-/l*96.8%
fma-neg96.8%
Simplified96.8%
Taylor expanded in a around 0 96.8%
add-sqr-sqrt96.8%
sqrt-unprod96.8%
pow296.8%
add-sqr-sqrt96.8%
sqrt-unprod96.8%
sqr-neg96.8%
sqrt-prod96.8%
add-sqr-sqrt96.8%
+-commutative96.8%
fma-define96.8%
associate-/l*96.8%
Applied egg-rr96.8%
unpow296.8%
rem-sqrt-square96.8%
associate-*r/96.8%
*-commutative96.8%
associate-*r/96.8%
Simplified96.8%
Taylor expanded in b around 0 96.8%
metadata-eval96.8%
cancel-sign-sub-inv96.8%
distribute-lft-out--96.8%
fabs-mul96.8%
metadata-eval96.8%
associate-/l*96.8%
Simplified96.8%
Final simplification91.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0)))))
(t_1
(if (>= b 0.0)
(/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))
(* 0.5 (/ (* 2.0 (fabs (- (* a (/ c b)) b))) a)))))
(if (<= b -1.5e+154)
t_1
(if (<= b -1e-310)
(if (>= b 0.0) (/ b a) (/ (- t_0 b) (* 2.0 a)))
(if (<= b 1e+135)
(if (>= b 0.0)
(/ (* 2.0 c) (- (- b) t_0))
(/ (* (fma 2.0 (/ b c) (* -2.0 (/ a b))) (- c)) (* 2.0 a)))
t_1)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp = 0.5 * ((2.0 * fabs(((a * (c / b)) - b))) / a);
}
double t_1 = tmp;
double tmp_1;
if (b <= -1.5e+154) {
tmp_1 = t_1;
} else if (b <= -1e-310) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = b / a;
} else {
tmp_2 = (t_0 - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 1e+135) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (2.0 * c) / (-b - t_0);
} else {
tmp_3 = (fma(2.0, (b / c), (-2.0 * (a / b))) * -c) / (2.0 * a);
}
tmp_1 = tmp_3;
} else {
tmp_1 = t_1;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp = Float64(0.5 * Float64(Float64(2.0 * abs(Float64(Float64(a * Float64(c / b)) - b))) / a)); end t_1 = tmp tmp_1 = 0.0 if (b <= -1.5e+154) tmp_1 = t_1; elseif (b <= -1e-310) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(b / a); else tmp_2 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 1e+135) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp_3 = Float64(Float64(fma(2.0, Float64(b / c), Float64(-2.0 * Float64(a / b))) * Float64(-c)) / Float64(2.0 * a)); end tmp_1 = tmp_3; else tmp_1 = t_1; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(2.0 * N[Abs[N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]}, If[LessEqual[b, -1.5e+154], t$95$1, If[LessEqual[b, -1e-310], If[GreaterEqual[b, 0.0], N[(b / a), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1e+135], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(2.0 * N[(b / c), $MachinePrecision] + N[(-2.0 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * (-c)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
t_1 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{2 \cdot \left|a \cdot \frac{c}{b} - b\right|}{a}\\
\end{array}\\
\mathbf{if}\;b \leq -1.5 \cdot 10^{+154}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{+135}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(2, \frac{b}{c}, -2 \cdot \frac{a}{b}\right) \cdot \left(-c\right)}{2 \cdot a}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if b < -1.50000000000000013e154 or 9.99999999999999962e134 < b Initial program 45.5%
Taylor expanded in a around 0 69.2%
distribute-lft-out--69.2%
associate-/l*71.0%
fma-neg71.0%
Simplified71.0%
Taylor expanded in a around 0 52.8%
add-sqr-sqrt52.8%
sqrt-unprod52.9%
pow252.9%
add-sqr-sqrt57.6%
sqrt-unprod70.9%
sqr-neg70.9%
sqrt-prod51.9%
add-sqr-sqrt71.0%
+-commutative71.0%
fma-define71.0%
associate-/l*71.0%
Applied egg-rr71.0%
unpow271.0%
rem-sqrt-square97.5%
associate-*r/93.1%
*-commutative93.1%
associate-*r/97.5%
Simplified97.5%
Taylor expanded in b around 0 93.1%
metadata-eval93.1%
cancel-sign-sub-inv93.1%
distribute-lft-out--93.1%
fabs-mul93.1%
metadata-eval93.1%
associate-/l*97.5%
Simplified97.5%
if -1.50000000000000013e154 < b < -9.999999999999969e-311Initial program 87.1%
Taylor expanded in a around 0 87.1%
distribute-lft-out--87.1%
associate-/l*87.1%
fma-neg87.1%
Simplified87.1%
Taylor expanded in c around inf 87.1%
if -9.999999999999969e-311 < b < 9.99999999999999962e134Initial program 88.0%
Taylor expanded in b around -inf 88.0%
mul-1-neg88.0%
distribute-rgt-neg-in88.0%
distribute-neg-in88.0%
metadata-eval88.0%
associate-/l*88.0%
associate-*r*88.0%
Simplified88.0%
pow288.0%
add-sqr-sqrt88.0%
sqrt-div88.0%
sqrt-prod88.0%
add-sqr-sqrt88.0%
sqrt-div88.0%
sqrt-prod88.0%
add-sqr-sqrt88.0%
Applied egg-rr88.0%
unpow288.0%
Simplified88.0%
Taylor expanded in c around -inf 88.0%
mul-1-neg88.0%
*-commutative88.0%
distribute-rgt-neg-in88.0%
fma-define88.0%
associate-*r/88.0%
*-commutative88.0%
unpow288.0%
rem-square-sqrt88.0%
associate-*r*88.0%
metadata-eval88.0%
associate-*r/88.0%
Simplified88.0%
Final simplification91.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (or (<= b -5e+154) (not (<= b 1e+135)))
(if (>= b 0.0)
(/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))
(* 0.5 (/ (* 2.0 (fabs (- (* a (/ c b)) b))) a)))
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (- t_0 b) (* 2.0 a))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if ((b <= -5e+154) || !(b <= 1e+135)) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_2 = 0.5 * ((2.0 * fabs(((a * (c / b)) - b))) / a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-b - t_0);
} else {
tmp_1 = (t_0 - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if ((b <= -5e+154) || !(b <= 1e+135)) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_2 = Float64(0.5 * Float64(Float64(2.0 * abs(Float64(Float64(a * Float64(c / b)) - b))) / a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp_1 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[b, -5e+154], N[Not[LessEqual[b, 1e+135]], $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(2.0 * N[Abs[N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+154} \lor \neg \left(b \leq 10^{+135}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{2 \cdot \left|a \cdot \frac{c}{b} - b\right|}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -5.00000000000000004e154 or 9.99999999999999962e134 < b Initial program 45.5%
Taylor expanded in a around 0 69.2%
distribute-lft-out--69.2%
associate-/l*71.0%
fma-neg71.0%
Simplified71.0%
Taylor expanded in a around 0 52.8%
add-sqr-sqrt52.8%
sqrt-unprod52.9%
pow252.9%
add-sqr-sqrt57.6%
sqrt-unprod70.9%
sqr-neg70.9%
sqrt-prod51.9%
add-sqr-sqrt71.0%
+-commutative71.0%
fma-define71.0%
associate-/l*71.0%
Applied egg-rr71.0%
unpow271.0%
rem-sqrt-square97.5%
associate-*r/93.1%
*-commutative93.1%
associate-*r/97.5%
Simplified97.5%
Taylor expanded in b around 0 93.1%
metadata-eval93.1%
cancel-sign-sub-inv93.1%
distribute-lft-out--93.1%
fabs-mul93.1%
metadata-eval93.1%
associate-/l*97.5%
Simplified97.5%
if -5.00000000000000004e154 < b < 9.99999999999999962e134Initial program 87.4%
Final simplification91.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))))
(if (<= b -5e+154)
(if (>= b 0.0) t_0 (* 0.5 (/ (* 2.0 (fabs (- (* a (/ c b)) b))) a)))
(if (<= b 1.22e-204)
(if (>= b 0.0)
(/ b a)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)))
(if (>= b 0.0)
t_0
(/ (- (+ b (* -2.0 (* c (* a (/ -1.0 b))))) b) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
double tmp_1;
if (b <= -5e+154) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = 0.5 * ((2.0 * fabs(((a * (c / b)) - b))) / a);
}
tmp_1 = tmp_2;
} else if (b <= 1.22e-204) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = b / a;
} else {
tmp_3 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = ((b + (-2.0 * (c * (a * (-1.0 / b))))) - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))) tmp_1 = 0.0 if (b <= -5e+154) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(0.5 * Float64(Float64(2.0 * abs(Float64(Float64(a * Float64(c / b)) - b))) / a)); end tmp_1 = tmp_2; elseif (b <= 1.22e-204) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(b / a); else tmp_3 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(Float64(b + Float64(-2.0 * Float64(c * Float64(a * Float64(-1.0 / b))))) - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -5e+154], If[GreaterEqual[b, 0.0], t$95$0, N[(0.5 * N[(N[(2.0 * N[Abs[N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1.22e-204], If[GreaterEqual[b, 0.0], N[(b / a), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(N[(b + N[(-2.0 * N[(c * N[(a * N[(-1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{2 \cdot \left|a \cdot \frac{c}{b} - b\right|}{a}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.22 \cdot 10^{-204}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(b + -2 \cdot \left(c \cdot \left(a \cdot \frac{-1}{b}\right)\right)\right) - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -5.00000000000000004e154Initial program 41.1%
Taylor expanded in a around 0 41.1%
distribute-lft-out--41.1%
associate-/l*41.1%
fma-neg41.1%
Simplified41.1%
Taylor expanded in a around 0 2.0%
add-sqr-sqrt1.9%
sqrt-unprod2.1%
pow22.1%
add-sqr-sqrt12.4%
sqrt-unprod41.0%
sqr-neg41.0%
sqrt-prod0.0%
add-sqr-sqrt41.3%
+-commutative41.3%
fma-define41.3%
associate-/l*41.3%
Applied egg-rr41.3%
unpow241.3%
rem-sqrt-square98.3%
associate-*r/88.8%
*-commutative88.8%
associate-*r/98.3%
Simplified98.3%
Taylor expanded in b around 0 88.8%
metadata-eval88.8%
cancel-sign-sub-inv88.8%
distribute-lft-out--88.8%
fabs-mul88.8%
metadata-eval88.8%
associate-/l*98.2%
Simplified98.2%
if -5.00000000000000004e154 < b < 1.22000000000000005e-204Initial program 85.9%
Taylor expanded in a around 0 76.1%
distribute-lft-out--76.1%
associate-/l*76.1%
fma-neg76.1%
Simplified76.1%
Taylor expanded in c around inf 76.1%
if 1.22000000000000005e-204 < b Initial program 67.2%
Taylor expanded in a around 0 76.7%
distribute-lft-out--76.7%
associate-/l*78.5%
fma-neg78.5%
Simplified78.5%
Taylor expanded in a around 0 78.5%
div-inv78.5%
*-commutative78.5%
frac-2neg78.5%
metadata-eval78.5%
add-sqr-sqrt78.5%
sqrt-unprod78.5%
sqr-neg78.5%
sqrt-prod78.5%
add-sqr-sqrt78.5%
Applied egg-rr78.5%
associate-*l*78.5%
Simplified78.5%
Final simplification81.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))))
(if (<= b -5e+154)
(if (>= b 0.0) t_0 (* 0.5 (/ (* 2.0 (fabs (- (* a (/ c b)) b))) a)))
(if (>= b 0.0)
t_0
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))))))
double code(double a, double b, double c) {
double t_0 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
double tmp_1;
if (b <= -5e+154) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = 0.5 * ((2.0 * fabs(((a * (c / b)) - b))) / a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))) tmp_1 = 0.0 if (b <= -5e+154) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(0.5 * Float64(Float64(2.0 * abs(Float64(Float64(a * Float64(c / b)) - b))) / a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -5e+154], If[GreaterEqual[b, 0.0], t$95$0, N[(0.5 * N[(N[(2.0 * N[Abs[N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{2 \cdot \left|a \cdot \frac{c}{b} - b\right|}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -5.00000000000000004e154Initial program 41.1%
Taylor expanded in a around 0 41.1%
distribute-lft-out--41.1%
associate-/l*41.1%
fma-neg41.1%
Simplified41.1%
Taylor expanded in a around 0 2.0%
add-sqr-sqrt1.9%
sqrt-unprod2.1%
pow22.1%
add-sqr-sqrt12.4%
sqrt-unprod41.0%
sqr-neg41.0%
sqrt-prod0.0%
add-sqr-sqrt41.3%
+-commutative41.3%
fma-define41.3%
associate-/l*41.3%
Applied egg-rr41.3%
unpow241.3%
rem-sqrt-square98.3%
associate-*r/88.8%
*-commutative88.8%
associate-*r/98.3%
Simplified98.3%
Taylor expanded in b around 0 88.8%
metadata-eval88.8%
cancel-sign-sub-inv88.8%
distribute-lft-out--88.8%
fabs-mul88.8%
metadata-eval88.8%
associate-/l*98.2%
Simplified98.2%
if -5.00000000000000004e154 < b Initial program 76.2%
Taylor expanded in a around 0 76.4%
distribute-lft-out--76.4%
associate-/l*77.3%
fma-neg77.3%
Simplified77.3%
Final simplification81.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b)))) (* 0.5 (/ (* 2.0 (fabs (- (* a (/ c b)) b))) a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp = 0.5 * ((2.0 * fabs(((a * (c / b)) - b))) / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp = Float64(0.5 * Float64(Float64(2.0 * abs(Float64(Float64(a * Float64(c / b)) - b))) / a)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(2.0 * N[Abs[N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{2 \cdot \left|a \cdot \frac{c}{b} - b\right|}{a}\\
\end{array}
\end{array}
Initial program 69.1%
Taylor expanded in a around 0 69.3%
distribute-lft-out--69.3%
associate-/l*70.0%
fma-neg70.0%
Simplified70.0%
Taylor expanded in a around 0 33.9%
add-sqr-sqrt33.7%
sqrt-unprod34.4%
pow234.4%
add-sqr-sqrt38.5%
sqrt-unprod42.3%
sqr-neg42.3%
sqrt-prod32.7%
add-sqr-sqrt59.4%
+-commutative59.4%
fma-define59.4%
associate-/l*59.4%
Applied egg-rr59.4%
unpow259.4%
rem-sqrt-square72.6%
associate-*r/70.6%
*-commutative70.6%
associate-*r/72.5%
Simplified72.5%
Taylor expanded in b around 0 70.6%
metadata-eval70.6%
cancel-sign-sub-inv70.6%
distribute-lft-out--70.6%
fabs-mul70.6%
metadata-eval70.6%
associate-/l*72.5%
Simplified72.5%
Final simplification72.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ -1.0 b)) (/ (+ b b) (* a -2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-1.0 / b);
} else {
tmp = (b + b) / (a * -2.0);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b >= 0.0d0) then
tmp = c * ((-1.0d0) / b)
else
tmp = (b + b) / (a * (-2.0d0))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-1.0 / b);
} else {
tmp = (b + b) / (a * -2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c * (-1.0 / b) else: tmp = (b + b) / (a * -2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c * Float64(-1.0 / b)); else tmp = Float64(Float64(b + b) / Float64(a * -2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c * (-1.0 / b); else tmp = (b + b) / (a * -2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * N[(-1.0 / b), $MachinePrecision]), $MachinePrecision], N[(N[(b + b), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-1}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + b}{a \cdot -2}\\
\end{array}
\end{array}
Initial program 69.1%
Simplified69.1%
Taylor expanded in b around -inf 71.2%
Taylor expanded in b around inf 71.9%
Final simplification71.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ c (- b)) (/ (+ b b) (* a -2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c / -b;
} else {
tmp = (b + b) / (a * -2.0);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b >= 0.0d0) then
tmp = c / -b
else
tmp = (b + b) / (a * (-2.0d0))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c / -b;
} else {
tmp = (b + b) / (a * -2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c / -b else: tmp = (b + b) / (a * -2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(b + b) / Float64(a * -2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c / -b; else tmp = (b + b) / (a * -2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c / (-b)), $MachinePrecision], N[(N[(b + b), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + b}{a \cdot -2}\\
\end{array}
\end{array}
Initial program 69.1%
Simplified69.1%
Taylor expanded in b around -inf 71.2%
Taylor expanded in c around 0 72.0%
associate-*r/72.0%
mul-1-neg72.0%
Simplified72.0%
Final simplification72.0%
herbie shell --seed 2024078
(FPCore (a b c)
:name "jeff quadratic root 2"
:precision binary64
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))