
(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))))))
(if (<= b -1.85e+152)
(if (>= b 0.0) (* c -2.0) (/ (+ b b) (* -2.0 a)))
(if (<= b 1e+111)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_0)) (/ (- t_0 b) (* a 2.0)))
(if (>= b 0.0)
(/ (* c 2.0) (* 2.0 (fma a (/ c b) (- b))))
(* b (+ (/ c (pow b 2.0)) (/ -1.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 <= -1.85e+152) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * -2.0;
} else {
tmp_2 = (b + b) / (-2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 1e+111) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_0);
} else {
tmp_3 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_1 = b * ((c / pow(b, 2.0)) + (-1.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 <= -1.85e+152) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c * -2.0); else tmp_2 = Float64(Float64(b + b) / Float64(-2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 1e+111) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - t_0)); else tmp_3 = Float64(Float64(t_0 - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_1 = Float64(b * Float64(Float64(c / (b ^ 2.0)) + Float64(-1.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[LessEqual[b, -1.85e+152], If[GreaterEqual[b, 0.0], N[(c * -2.0), $MachinePrecision], N[(N[(b + b), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1e+111], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / a), $MachinePrecision]), $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 -1.85 \cdot 10^{+152}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot -2\\
\mathbf{else}:\\
\;\;\;\;\frac{b + b}{-2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{+111}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\
\end{array}
\end{array}
if b < -1.84999999999999998e152Initial program 35.7%
Simplified35.9%
Taylor expanded in b around -inf 98.2%
Taylor expanded in c around 0 98.2%
associate-*r/98.2%
flip-+98.2%
+-inverses98.2%
+-inverses98.2%
Applied egg-rr98.2%
Simplified98.2%
if -1.84999999999999998e152 < b < 9.99999999999999957e110Initial program 85.0%
if 9.99999999999999957e110 < b Initial program 44.6%
Taylor expanded in a around 0 85.0%
distribute-lft-out--85.0%
associate-/l*95.9%
fma-neg95.9%
Simplified95.9%
Taylor expanded in b around -inf 95.9%
associate-*r*95.9%
mul-1-neg95.9%
+-commutative95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
Final simplification89.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (+ b b) (* -2.0 a))))
(if (<= b -1e+154)
(if (>= b 0.0) (* c -2.0) t_0)
(if (<= b -4e-310)
(if (>= b 0.0)
(* (/ c 2.0) (/ 2.0 (fma a (/ c b) b)))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))
(if (>= b 0.0) (/ (/ c (+ b (fma -2.0 (* c (/ a b)) b))) -0.5) t_0)))))
double code(double a, double b, double c) {
double t_0 = (b + b) / (-2.0 * a);
double tmp_1;
if (b <= -1e+154) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * -2.0;
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b <= -4e-310) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c / 2.0) * (2.0 / fma(a, (c / b), b));
} else {
tmp_3 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c / (b + fma(-2.0, (c * (a / b)), b))) / -0.5;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(Float64(b + b) / Float64(-2.0 * a)) tmp_1 = 0.0 if (b <= -1e+154) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c * -2.0); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b <= -4e-310) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c / 2.0) * Float64(2.0 / fma(a, Float64(c / b), b))); else tmp_3 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c / Float64(b + fma(-2.0, Float64(c * Float64(a / b)), b))) / -0.5); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b + b), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1e+154], If[GreaterEqual[b, 0.0], N[(c * -2.0), $MachinePrecision], t$95$0], If[LessEqual[b, -4e-310], If[GreaterEqual[b, 0.0], N[(N[(c / 2.0), $MachinePrecision] * N[(2.0 / N[(a * N[(c / b), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c / N[(b + N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / -0.5), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + b}{-2 \cdot a}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot -2\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \leq -4 \cdot 10^{-310}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{2} \cdot \frac{2}{\mathsf{fma}\left(a, \frac{c}{b}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{\frac{c}{b + \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}}{-0.5}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -1.00000000000000004e154Initial program 35.7%
Simplified35.9%
Taylor expanded in b around -inf 98.2%
Taylor expanded in c around 0 98.2%
associate-*r/98.2%
flip-+98.2%
+-inverses98.2%
+-inverses98.2%
Applied egg-rr98.2%
Simplified98.2%
if -1.00000000000000004e154 < b < -3.999999999999988e-310Initial program 92.3%
Taylor expanded in a around 0 92.3%
distribute-lft-out--92.3%
associate-/l*92.3%
fma-neg92.3%
Simplified92.3%
*-commutative92.3%
times-frac92.3%
add-sqr-sqrt92.3%
sqrt-unprod92.3%
sqr-neg92.3%
sqrt-prod92.3%
add-sqr-sqrt92.3%
Applied egg-rr92.3%
if -3.999999999999988e-310 < b Initial program 65.0%
Simplified65.0%
Taylor expanded in b around -inf 65.0%
Taylor expanded in c around 0 54.8%
associate-/l*58.7%
Simplified58.7%
clear-num58.7%
un-div-inv59.0%
div-inv59.0%
+-commutative59.0%
fma-define59.0%
clear-num59.0%
un-div-inv59.0%
metadata-eval59.0%
Applied egg-rr59.0%
associate-/r*59.0%
associate-/r/59.1%
*-commutative59.1%
Simplified59.1%
Final simplification77.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (+ b b) (* -2.0 a))))
(if (<= b -9.1e+151)
(if (>= b 0.0) (* c -2.0) t_0)
(if (<= b 1e-189)
(if (>= b 0.0)
(/ b a)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))
(if (>= b 0.0) (/ (/ c (+ b (fma -2.0 (* c (/ a b)) b))) -0.5) t_0)))))
double code(double a, double b, double c) {
double t_0 = (b + b) / (-2.0 * a);
double tmp_1;
if (b <= -9.1e+151) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * -2.0;
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b <= 1e-189) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = b / a;
} else {
tmp_3 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c / (b + fma(-2.0, (c * (a / b)), b))) / -0.5;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(Float64(b + b) / Float64(-2.0 * a)) tmp_1 = 0.0 if (b <= -9.1e+151) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c * -2.0); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b <= 1e-189) 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(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c / Float64(b + fma(-2.0, Float64(c * Float64(a / b)), b))) / -0.5); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b + b), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -9.1e+151], If[GreaterEqual[b, 0.0], N[(c * -2.0), $MachinePrecision], t$95$0], If[LessEqual[b, 1e-189], 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[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c / N[(b + N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / -0.5), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b + b}{-2 \cdot a}\\
\mathbf{if}\;b \leq -9.1 \cdot 10^{+151}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot -2\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{-189}:\\
\;\;\;\;\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}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{\frac{c}{b + \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}}{-0.5}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -9.10000000000000003e151Initial program 35.7%
Simplified35.9%
Taylor expanded in b around -inf 98.2%
Taylor expanded in c around 0 98.2%
associate-*r/98.2%
flip-+98.2%
+-inverses98.2%
+-inverses98.2%
Applied egg-rr98.2%
Simplified98.2%
if -9.10000000000000003e151 < b < 1.00000000000000007e-189Initial program 88.7%
Taylor expanded in a around 0 77.3%
distribute-lft-out--77.3%
associate-/l*77.3%
fma-neg77.3%
Simplified77.3%
Taylor expanded in c around inf 77.3%
if 1.00000000000000007e-189 < b Initial program 64.0%
Simplified63.9%
Taylor expanded in b around -inf 63.9%
Taylor expanded in c around 0 63.1%
associate-/l*67.6%
Simplified67.6%
clear-num67.6%
un-div-inv67.9%
div-inv67.9%
+-commutative67.9%
fma-define67.9%
clear-num67.9%
un-div-inv67.9%
metadata-eval67.9%
Applied egg-rr67.9%
associate-/r*67.9%
associate-/r/68.0%
*-commutative68.0%
Simplified68.0%
Final simplification77.8%
(FPCore (a b c)
:precision binary64
(if (<= b -8.1e+152)
(if (>= b 0.0) (* c -2.0) (/ (+ b b) (* -2.0 a)))
(if (>= b 0.0)
(/ (* c 2.0) (* 2.0 (fma a (/ c b) (- b))))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -8.1e+152) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * -2.0;
} else {
tmp_2 = (b + b) / (-2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -8.1e+152) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c * -2.0); else tmp_2 = Float64(Float64(b + b) / Float64(-2.0 * a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -8.1e+152], If[GreaterEqual[b, 0.0], N[(c * -2.0), $MachinePrecision], N[(N[(b + b), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8.1 \cdot 10^{+152}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot -2\\
\mathbf{else}:\\
\;\;\;\;\frac{b + b}{-2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -8.09999999999999998e152Initial program 35.7%
Simplified35.9%
Taylor expanded in b around -inf 98.2%
Taylor expanded in c around 0 98.2%
associate-*r/98.2%
flip-+98.2%
+-inverses98.2%
+-inverses98.2%
Applied egg-rr98.2%
Simplified98.2%
if -8.09999999999999998e152 < b Initial program 76.1%
Taylor expanded in a around 0 70.2%
distribute-lft-out--70.2%
associate-/l*72.5%
fma-neg72.5%
Simplified72.5%
Final simplification77.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (/ c (+ b (fma -2.0 (* c (/ a b)) b))) -0.5) (/ (+ b b) (* -2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c / (b + fma(-2.0, (c * (a / b)), b))) / -0.5;
} else {
tmp = (b + b) / (-2.0 * a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c / Float64(b + fma(-2.0, Float64(c * Float64(a / b)), b))) / -0.5); else tmp = Float64(Float64(b + b) / Float64(-2.0 * a)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c / N[(b + N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / -0.5), $MachinePrecision], N[(N[(b + b), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\frac{c}{b + \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}}{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + b}{-2 \cdot a}\\
\end{array}
\end{array}
Initial program 67.9%
Simplified67.9%
Taylor expanded in b around -inf 71.5%
Taylor expanded in c around 0 66.7%
associate-/l*68.5%
Simplified68.5%
clear-num68.5%
un-div-inv68.6%
div-inv68.6%
+-commutative68.6%
fma-define68.6%
clear-num68.6%
un-div-inv68.6%
metadata-eval68.6%
Applied egg-rr68.6%
associate-/r*68.6%
associate-/r/68.7%
*-commutative68.7%
Simplified68.7%
Final simplification68.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c -2.0) (/ (+ b b) (* -2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * -2.0;
} else {
tmp = (b + b) / (-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) :: tmp
if (b >= 0.0d0) then
tmp = c * (-2.0d0)
else
tmp = (b + b) / ((-2.0d0) * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * -2.0;
} else {
tmp = (b + b) / (-2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c * -2.0 else: tmp = (b + b) / (-2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c * -2.0); else tmp = Float64(Float64(b + b) / Float64(-2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c * -2.0; else tmp = (b + b) / (-2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * -2.0), $MachinePrecision], N[(N[(b + b), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot -2\\
\mathbf{else}:\\
\;\;\;\;\frac{b + b}{-2 \cdot a}\\
\end{array}
\end{array}
Initial program 67.9%
Simplified67.9%
Taylor expanded in b around -inf 71.5%
Taylor expanded in c around 0 68.5%
associate-*r/68.6%
flip-+40.8%
+-inverses40.8%
+-inverses40.8%
Applied egg-rr40.8%
Simplified43.6%
Final simplification43.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ -2.0 (+ b b))) (/ (+ b b) (* -2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-2.0 / (b + b));
} else {
tmp = (b + b) / (-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) :: tmp
if (b >= 0.0d0) then
tmp = c * ((-2.0d0) / (b + b))
else
tmp = (b + b) / ((-2.0d0) * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-2.0 / (b + b));
} else {
tmp = (b + b) / (-2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c * (-2.0 / (b + b)) else: tmp = (b + b) / (-2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c * Float64(-2.0 / Float64(b + b))); else tmp = Float64(Float64(b + b) / Float64(-2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c * (-2.0 / (b + b)); else tmp = (b + b) / (-2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b + b), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + b}{-2 \cdot a}\\
\end{array}
\end{array}
Initial program 67.9%
Simplified67.9%
Taylor expanded in b around -inf 71.5%
Taylor expanded in c around 0 68.5%
Final simplification68.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ c (- b)) (/ (+ b b) (* -2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c / -b;
} else {
tmp = (b + b) / (-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) :: tmp
if (b >= 0.0d0) then
tmp = c / -b
else
tmp = (b + b) / ((-2.0d0) * a)
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) / (-2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c / -b else: tmp = (b + b) / (-2.0 * a) 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(-2.0 * a)); 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) / (-2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c / (-b)), $MachinePrecision], N[(N[(b + b), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b + b}{-2 \cdot a}\\
\end{array}
\end{array}
Initial program 67.9%
Simplified67.9%
Taylor expanded in b around -inf 71.5%
Taylor expanded in c around 0 68.6%
associate-*r/68.6%
mul-1-neg68.6%
Simplified68.6%
Final simplification68.6%
herbie shell --seed 2024060
(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))))