
(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 7 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 (fma c (* a -4.0) (* b b)))) (t_1 (* a (/ c b))))
(if (<= b -5.8e+97)
(if (>= b 0.0)
(/ (* 2.0 (- c)) (+ b (+ b (* -2.0 t_1))))
(/ (- (- b) (fma -2.0 t_1 b)) (* 2.0 a)))
(if (<= b 3.4e+79)
(if (>= b 0.0) (* c (/ -2.0 (+ b t_0))) (/ (- b t_0) (* -2.0 a)))
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) b)) (/ (- b b) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma(c, (a * -4.0), (b * b)));
double t_1 = a * (c / b);
double tmp_1;
if (b <= -5.8e+97) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * -c) / (b + (b + (-2.0 * t_1)));
} else {
tmp_2 = (-b - fma(-2.0, t_1, b)) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 3.4e+79) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = c * (-2.0 / (b + t_0));
} else {
tmp_3 = (b - t_0) / (-2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-b - b);
} else {
tmp_1 = (b - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(c, Float64(a * -4.0), Float64(b * b))) t_1 = Float64(a * Float64(c / b)) tmp_1 = 0.0 if (b <= -5.8e+97) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * Float64(-c)) / Float64(b + Float64(b + Float64(-2.0 * t_1)))); else tmp_2 = Float64(Float64(Float64(-b) - fma(-2.0, t_1, b)) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 3.4e+79) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(c * Float64(-2.0 / Float64(b + t_0))); else tmp_3 = Float64(Float64(b - t_0) / Float64(-2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - b)); else tmp_1 = Float64(Float64(b - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -5.8e+97], If[GreaterEqual[b, 0.0], N[(N[(2.0 * (-c)), $MachinePrecision] / N[(b + N[(b + N[(-2.0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - N[(-2.0 * t$95$1 + b), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 3.4e+79], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - t$95$0), $MachinePrecision] / N[(-2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision], N[(N[(b - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(c, a \cdot -4, b \cdot b\right)}\\
t_1 := a \cdot \frac{c}{b}\\
\mathbf{if}\;b \leq -5.8 \cdot 10^{+97}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \left(-c\right)}{b + \left(b + -2 \cdot t\_1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - \mathsf{fma}\left(-2, t\_1, b\right)}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{+79}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - t\_0}{-2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -5.79999999999999974e97Initial program 54.9%
Taylor expanded in a around 0 54.9%
associate-/l*54.9%
Simplified54.9%
Taylor expanded in a around 0 2.1%
neg-sub02.1%
associate-+l-2.1%
sub-neg2.1%
distribute-neg-in2.1%
add-sqr-sqrt12.5%
sqrt-unprod0.9%
sqr-neg0.9%
sqrt-prod0.0%
add-sqr-sqrt86.4%
sub-neg86.4%
associate-*r/94.0%
*-commutative94.0%
cancel-sign-sub-inv94.0%
associate-*r/86.4%
add-sqr-sqrt0.0%
sqrt-prod86.5%
sqr-neg86.5%
sqrt-unprod86.8%
add-sqr-sqrt86.8%
distribute-frac-neg86.8%
frac-2neg86.8%
associate-*r/95.3%
Applied egg-rr95.3%
associate--r+95.3%
neg-sub095.3%
associate-/r/95.3%
associate-*l/86.8%
associate-/l*95.3%
Simplified95.3%
if -5.79999999999999974e97 < b < 3.40000000000000032e79Initial program 84.3%
Simplified84.9%
if 3.40000000000000032e79 < b Initial program 61.6%
Taylor expanded in b around inf 98.4%
Taylor expanded in b around inf 98.4%
Final simplification90.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))) (t_1 (* a (/ c b))))
(if (<= b -3e+98)
(if (>= b 0.0)
(/ (* 2.0 (- c)) (+ b (+ b (* -2.0 t_1))))
(/ (- (- b) (fma -2.0 t_1 b)) (* 2.0 a)))
(if (<= b 5.2e+81)
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (- t_0 b) (* 2.0 a)))
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) b)) (/ (- b b) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double t_1 = a * (c / b);
double tmp_1;
if (b <= -3e+98) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * -c) / (b + (b + (-2.0 * t_1)));
} else {
tmp_2 = (-b - fma(-2.0, t_1, b)) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 5.2e+81) {
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 = (2.0 * c) / (-b - b);
} else {
tmp_1 = (b - 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)))) t_1 = Float64(a * Float64(c / b)) tmp_1 = 0.0 if (b <= -3e+98) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * Float64(-c)) / Float64(b + Float64(b + Float64(-2.0 * t_1)))); else tmp_2 = Float64(Float64(Float64(-b) - fma(-2.0, t_1, b)) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 5.2e+81) 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 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - b)); else tmp_1 = Float64(Float64(b - 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]}, Block[{t$95$1 = N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -3e+98], If[GreaterEqual[b, 0.0], N[(N[(2.0 * (-c)), $MachinePrecision] / N[(b + N[(b + N[(-2.0 * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - N[(-2.0 * t$95$1 + b), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 5.2e+81], 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], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision], N[(N[(b - 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)}\\
t_1 := a \cdot \frac{c}{b}\\
\mathbf{if}\;b \leq -3 \cdot 10^{+98}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \left(-c\right)}{b + \left(b + -2 \cdot t\_1\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - \mathsf{fma}\left(-2, t\_1, b\right)}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 5.2 \cdot 10^{+81}:\\
\;\;\;\;\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:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -3.0000000000000001e98Initial program 54.9%
Taylor expanded in a around 0 54.9%
associate-/l*54.9%
Simplified54.9%
Taylor expanded in a around 0 2.1%
neg-sub02.1%
associate-+l-2.1%
sub-neg2.1%
distribute-neg-in2.1%
add-sqr-sqrt12.5%
sqrt-unprod0.9%
sqr-neg0.9%
sqrt-prod0.0%
add-sqr-sqrt86.4%
sub-neg86.4%
associate-*r/94.0%
*-commutative94.0%
cancel-sign-sub-inv94.0%
associate-*r/86.4%
add-sqr-sqrt0.0%
sqrt-prod86.5%
sqr-neg86.5%
sqrt-unprod86.8%
add-sqr-sqrt86.8%
distribute-frac-neg86.8%
frac-2neg86.8%
associate-*r/95.3%
Applied egg-rr95.3%
associate--r+95.3%
neg-sub095.3%
associate-/r/95.3%
associate-*l/86.8%
associate-/l*95.3%
Simplified95.3%
if -3.0000000000000001e98 < b < 5.19999999999999984e81Initial program 84.3%
if 5.19999999999999984e81 < b Initial program 61.6%
Taylor expanded in b around inf 98.4%
Taylor expanded in b around inf 98.4%
Final simplification90.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* a (/ c b)))
(t_1 (fma -2.0 t_0 b))
(t_2 (/ (* 2.0 (- c)) (+ b (+ b (* -2.0 t_0))))))
(if (<= b -1.2e+98)
(if (>= b 0.0) t_2 (/ (- (- b) t_1) (* 2.0 a)))
(if (<= b 1e-283)
(if (>= b 0.0)
(* (* 2.0 c) (/ 1.0 (- b t_1)))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)))
(if (>= b 0.0) t_2 (/ (- (+ b (* -2.0 (/ (* c a) b))) b) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = a * (c / b);
double t_1 = fma(-2.0, t_0, b);
double t_2 = (2.0 * -c) / (b + (b + (-2.0 * t_0)));
double tmp_1;
if (b <= -1.2e+98) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_2;
} else {
tmp_2 = (-b - t_1) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 1e-283) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (2.0 * c) * (1.0 / (b - t_1));
} 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_2;
} else {
tmp_1 = ((b + (-2.0 * ((c * a) / b))) - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(a * Float64(c / b)) t_1 = fma(-2.0, t_0, b) t_2 = Float64(Float64(2.0 * Float64(-c)) / Float64(b + Float64(b + Float64(-2.0 * t_0)))) tmp_1 = 0.0 if (b <= -1.2e+98) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_2; else tmp_2 = Float64(Float64(Float64(-b) - t_1) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 1e-283) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(2.0 * c) * Float64(1.0 / Float64(b - t_1))); 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_2; else tmp_1 = Float64(Float64(Float64(b + Float64(-2.0 * Float64(Float64(c * a) / b))) - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(-2.0 * t$95$0 + b), $MachinePrecision]}, Block[{t$95$2 = N[(N[(2.0 * (-c)), $MachinePrecision] / N[(b + N[(b + N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.2e+98], If[GreaterEqual[b, 0.0], t$95$2, N[(N[((-b) - t$95$1), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1e-283], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] * N[(1.0 / N[(b - t$95$1), $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[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$2, N[(N[(N[(b + N[(-2.0 * N[(N[(c * a), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \frac{c}{b}\\
t_1 := \mathsf{fma}\left(-2, t\_0, b\right)\\
t_2 := \frac{2 \cdot \left(-c\right)}{b + \left(b + -2 \cdot t\_0\right)}\\
\mathbf{if}\;b \leq -1.2 \cdot 10^{+98}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - t\_1}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{-283}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\left(2 \cdot c\right) \cdot \frac{1}{b - t\_1}\\
\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\_2\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(b + -2 \cdot \frac{c \cdot a}{b}\right) - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -1.1999999999999999e98Initial program 54.9%
Taylor expanded in a around 0 54.9%
associate-/l*54.9%
Simplified54.9%
Taylor expanded in a around 0 2.1%
neg-sub02.1%
associate-+l-2.1%
sub-neg2.1%
distribute-neg-in2.1%
add-sqr-sqrt12.5%
sqrt-unprod0.9%
sqr-neg0.9%
sqrt-prod0.0%
add-sqr-sqrt86.4%
sub-neg86.4%
associate-*r/94.0%
*-commutative94.0%
cancel-sign-sub-inv94.0%
associate-*r/86.4%
add-sqr-sqrt0.0%
sqrt-prod86.5%
sqr-neg86.5%
sqrt-unprod86.8%
add-sqr-sqrt86.8%
distribute-frac-neg86.8%
frac-2neg86.8%
associate-*r/95.3%
Applied egg-rr95.3%
associate--r+95.3%
neg-sub095.3%
associate-/r/95.3%
associate-*l/86.8%
associate-/l*95.3%
Simplified95.3%
if -1.1999999999999999e98 < b < 9.99999999999999947e-284Initial program 86.5%
Taylor expanded in a around 0 85.2%
associate-/l*85.2%
Simplified85.2%
div-inv85.2%
*-commutative85.2%
add-sqr-sqrt85.0%
sqrt-unprod85.2%
sqr-neg85.2%
sqrt-prod85.2%
add-sqr-sqrt85.2%
+-commutative85.2%
fma-define85.2%
Applied egg-rr85.2%
if 9.99999999999999947e-284 < b Initial program 72.7%
Taylor expanded in a around 0 66.5%
associate-/l*70.3%
Simplified70.3%
Taylor expanded in a around 0 70.3%
Final simplification80.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* a (/ c b))))
(if (<= b -4e+98)
(if (>= b 0.0)
(/ (* 2.0 (- c)) (+ b (+ b (* -2.0 t_0))))
(/ (- (- b) (fma -2.0 t_0 b)) (* 2.0 a)))
(if (>= b 0.0)
(/ (* 2.0 c) (- (- b) b))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))))))
double code(double a, double b, double c) {
double t_0 = a * (c / b);
double tmp_1;
if (b <= -4e+98) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * -c) / (b + (b + (-2.0 * t_0)));
} else {
tmp_2 = (-b - fma(-2.0, t_0, b)) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-b - b);
} 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(a * Float64(c / b)) tmp_1 = 0.0 if (b <= -4e+98) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * Float64(-c)) / Float64(b + Float64(b + Float64(-2.0 * t_0)))); else tmp_2 = Float64(Float64(Float64(-b) - fma(-2.0, t_0, b)) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - b)); 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[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -4e+98], If[GreaterEqual[b, 0.0], N[(N[(2.0 * (-c)), $MachinePrecision] / N[(b + N[(b + N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - N[(-2.0 * t$95$0 + b), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $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]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \frac{c}{b}\\
\mathbf{if}\;b \leq -4 \cdot 10^{+98}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \left(-c\right)}{b + \left(b + -2 \cdot t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - \mathsf{fma}\left(-2, t\_0, b\right)}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -3.99999999999999999e98Initial program 54.9%
Taylor expanded in a around 0 54.9%
associate-/l*54.9%
Simplified54.9%
Taylor expanded in a around 0 2.1%
neg-sub02.1%
associate-+l-2.1%
sub-neg2.1%
distribute-neg-in2.1%
add-sqr-sqrt12.5%
sqrt-unprod0.9%
sqr-neg0.9%
sqrt-prod0.0%
add-sqr-sqrt86.4%
sub-neg86.4%
associate-*r/94.0%
*-commutative94.0%
cancel-sign-sub-inv94.0%
associate-*r/86.4%
add-sqr-sqrt0.0%
sqrt-prod86.5%
sqr-neg86.5%
sqrt-unprod86.8%
add-sqr-sqrt86.8%
distribute-frac-neg86.8%
frac-2neg86.8%
associate-*r/95.3%
Applied egg-rr95.3%
associate--r+95.3%
neg-sub095.3%
associate-/r/95.3%
associate-*l/86.8%
associate-/l*95.3%
Simplified95.3%
if -3.99999999999999999e98 < b Initial program 77.8%
Taylor expanded in b around inf 75.1%
Final simplification79.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* a (/ c b))))
(if (>= b 0.0)
(/ (* 2.0 (- c)) (+ b (+ b (* -2.0 t_0))))
(/ (- (- b) (fma -2.0 t_0 b)) (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = a * (c / b);
double tmp;
if (b >= 0.0) {
tmp = (2.0 * -c) / (b + (b + (-2.0 * t_0)));
} else {
tmp = (-b - fma(-2.0, t_0, b)) / (2.0 * a);
}
return tmp;
}
function code(a, b, c) t_0 = Float64(a * Float64(c / b)) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * Float64(-c)) / Float64(b + Float64(b + Float64(-2.0 * t_0)))); else tmp = Float64(Float64(Float64(-b) - fma(-2.0, t_0, b)) / Float64(2.0 * a)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[(2.0 * (-c)), $MachinePrecision] / N[(b + N[(b + N[(-2.0 * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - N[(-2.0 * t$95$0 + b), $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \frac{c}{b}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \left(-c\right)}{b + \left(b + -2 \cdot t\_0\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - \mathsf{fma}\left(-2, t\_0, b\right)}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 72.5%
Taylor expanded in a around 0 69.1%
associate-/l*70.9%
Simplified70.9%
Taylor expanded in a around 0 35.3%
neg-sub035.3%
associate-+l-35.3%
sub-neg35.3%
distribute-neg-in35.3%
add-sqr-sqrt37.9%
sqrt-unprod35.1%
sqr-neg35.1%
sqrt-prod34.3%
add-sqr-sqrt65.4%
sub-neg65.4%
associate-*r/67.0%
*-commutative67.0%
cancel-sign-sub-inv67.0%
associate-*r/65.4%
add-sqr-sqrt34.3%
sqrt-prod66.0%
sqr-neg66.0%
sqrt-unprod66.2%
add-sqr-sqrt66.2%
distribute-frac-neg66.2%
frac-2neg66.2%
associate-*r/68.1%
Applied egg-rr68.1%
associate--r+68.1%
neg-sub068.1%
associate-/r/68.1%
associate-*l/66.2%
associate-/l*68.1%
Simplified68.1%
Final simplification68.1%
(FPCore (a b c) :precision binary64 (let* ((t_0 (- (- b) b))) (if (>= b 0.0) (/ (* 2.0 c) t_0) (/ t_0 (* 2.0 a)))))
double code(double a, double b, double c) {
double t_0 = -b - b;
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / t_0;
} else {
tmp = 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 = -b - b
if (b >= 0.0d0) then
tmp = (2.0d0 * c) / t_0
else
tmp = t_0 / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = -b - b;
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / t_0;
} else {
tmp = t_0 / (2.0 * a);
}
return tmp;
}
def code(a, b, c): t_0 = -b - b tmp = 0 if b >= 0.0: tmp = (2.0 * c) / t_0 else: tmp = t_0 / (2.0 * a) return tmp
function code(a, b, c) t_0 = Float64(Float64(-b) - b) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / t_0); else tmp = Float64(t_0 / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = -b - b; tmp = 0.0; if (b >= 0.0) tmp = (2.0 * c) / t_0; else tmp = t_0 / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-b) - b), $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / t$95$0), $MachinePrecision], N[(t$95$0 / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(-b\right) - b\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 72.5%
Taylor expanded in b around inf 70.5%
Taylor expanded in b around -inf 67.4%
mul-1-neg67.4%
Simplified67.4%
Final simplification67.4%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (- (- b) b)) (/ (- b b) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-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 = (2.0d0 * c) / (-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 = (2.0 * c) / (-b - b);
} else {
tmp = (b - b) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (-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(Float64(2.0 * c) / Float64(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 = (2.0 * c) / (-b - b); else tmp = (b - b) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - b), $MachinePrecision]), $MachinePrecision], N[(N[(b - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - b}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 72.5%
Taylor expanded in b around inf 70.5%
Taylor expanded in b around inf 35.3%
Final simplification35.3%
herbie shell --seed 2024111
(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))))