
(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 (fma -4.0 (* a c) (* b b))))
(t_1 (/ (- (- b) b) (* a 2.0))))
(if (<= b -3e+116)
(if (>= b 0.0) (/ (- b) a) t_1)
(if (<= b 2e+130)
(if (>= b 0.0) (/ (* -2.0 c) (+ t_0 b)) (* 0.5 (/ (- t_0 b) a)))
(if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) t_1)))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma(-4.0, (a * c), (b * b)));
double t_1 = (-b - b) / (a * 2.0);
double tmp_1;
if (b <= -3e+116) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= 2e+130) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-2.0 * c) / (t_0 + b);
} else {
tmp_3 = 0.5 * ((t_0 - b) / a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (-2.0 * b);
} else {
tmp_1 = t_1;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) t_1 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= -3e+116) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= 2e+130) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(-2.0 * c) / Float64(t_0 + b)); else tmp_3 = Float64(0.5 * Float64(Float64(t_0 - b) / a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp_1 = t_1; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -3e+116], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], t$95$1], If[LessEqual[b, 2e+130], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(t$95$0 - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)}\\
t_1 := \frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -3 \cdot 10^{+116}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+130}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{t\_0 + b}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{t\_0 - b}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if b < -2.9999999999999999e116Initial program 58.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6498.0
Applied rewrites98.0%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6498.0
Applied rewrites98.0%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6498.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.0
Applied rewrites98.0%
if -2.9999999999999999e116 < b < 2.0000000000000001e130Initial program 87.8%
Taylor expanded in a around 0
lower-*.f6476.5
Applied rewrites76.5%
Taylor expanded in a around 0
Applied rewrites87.8%
if 2.0000000000000001e130 < b Initial program 47.5%
Taylor expanded in a around 0
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Final simplification92.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (* (* a c) -4.0))) (t_1 (/ (- (- b) b) (* a 2.0))))
(if (<= b -4.3e-76)
(if (>= b 0.0) (/ (- b) a) t_1)
(if (<= b -1e-310)
(if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) (/ (- t_0 b) (* a 2.0)))
(if (<= b 2.2e-153)
(if (>= b 0.0) (/ (* (- 2.0) c) (+ t_0 b)) t_1)
(if (>= b 0.0) (/ (* c 2.0) (* (fma a (/ c b) (- b)) 2.0)) t_1))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((a * c) * -4.0));
double t_1 = (-b - b) / (a * 2.0);
double tmp_1;
if (b <= -4.3e-76) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= -1e-310) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-2.0 * b);
} else {
tmp_3 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b <= 2.2e-153) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = (-2.0 * c) / (t_0 + b);
} else {
tmp_4 = t_1;
}
tmp_1 = tmp_4;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (fma(a, (c / b), -b) * 2.0);
} else {
tmp_1 = t_1;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(a * c) * -4.0)) t_1 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= -4.3e-76) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= -1e-310) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp_3 = Float64(Float64(t_0 - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b <= 2.2e-153) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(Float64(-2.0) * c) / Float64(t_0 + b)); else tmp_4 = t_1; end tmp_1 = tmp_4; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(fma(a, Float64(c / b), Float64(-b)) * 2.0)); else tmp_1 = t_1; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -4.3e-76], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], t$95$1], If[LessEqual[b, -1e-310], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.2e-153], If[GreaterEqual[b, 0.0], N[(N[((-2.0) * c), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision], t$95$1], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left(a \cdot c\right) \cdot -4}\\
t_1 := \frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -4.3 \cdot 10^{-76}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-2\right) \cdot c}{t\_0 + b}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(a, \frac{c}{b}, -b\right) \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if b < -4.2999999999999999e-76Initial program 76.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6487.8
Applied rewrites87.8%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6487.8
Applied rewrites87.8%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6487.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.8
Applied rewrites87.8%
if -4.2999999999999999e-76 < b < -9.999999999999969e-311Initial program 72.1%
Taylor expanded in a around 0
lower-*.f6472.1
Applied rewrites72.1%
Taylor expanded in a around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6468.3
Applied rewrites68.3%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6468.3
Applied rewrites68.3%
if -9.999999999999969e-311 < b < 2.20000000000000001e-153Initial program 75.0%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6475.0
Applied rewrites75.0%
Taylor expanded in a around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6475.0
Applied rewrites75.0%
if 2.20000000000000001e-153 < b Initial program 72.0%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6472.0
Applied rewrites72.0%
Taylor expanded in a around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6427.6
Applied rewrites27.6%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.9
Applied rewrites91.9%
Final simplification85.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (* (* a c) -4.0))) (t_1 (/ (- (- b) b) (* a 2.0))))
(if (<= b -4.3e-76)
(if (>= b 0.0) (/ (- b) a) t_1)
(if (<= b -1e-310)
(if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) (/ (- t_0 b) (* a 2.0)))
(if (<= b 2.2e-153)
(if (>= b 0.0) (* (- c) (/ 2.0 (+ t_0 b))) t_1)
(if (>= b 0.0) (/ (* c 2.0) (* (fma a (/ c b) (- b)) 2.0)) t_1))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((a * c) * -4.0));
double t_1 = (-b - b) / (a * 2.0);
double tmp_1;
if (b <= -4.3e-76) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= -1e-310) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-2.0 * b);
} else {
tmp_3 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b <= 2.2e-153) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = -c * (2.0 / (t_0 + b));
} else {
tmp_4 = t_1;
}
tmp_1 = tmp_4;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (fma(a, (c / b), -b) * 2.0);
} else {
tmp_1 = t_1;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(a * c) * -4.0)) t_1 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= -4.3e-76) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= -1e-310) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp_3 = Float64(Float64(t_0 - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b <= 2.2e-153) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(-c) * Float64(2.0 / Float64(t_0 + b))); else tmp_4 = t_1; end tmp_1 = tmp_4; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(fma(a, Float64(c / b), Float64(-b)) * 2.0)); else tmp_1 = t_1; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -4.3e-76], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], t$95$1], If[LessEqual[b, -1e-310], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.2e-153], If[GreaterEqual[b, 0.0], N[((-c) * N[(2.0 / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\left(a \cdot c\right) \cdot -4}\\
t_1 := \frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -4.3 \cdot 10^{-76}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\left(-c\right) \cdot \frac{2}{t\_0 + b}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(a, \frac{c}{b}, -b\right) \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if b < -4.2999999999999999e-76Initial program 76.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6487.8
Applied rewrites87.8%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6487.8
Applied rewrites87.8%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6487.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.8
Applied rewrites87.8%
if -4.2999999999999999e-76 < b < -9.999999999999969e-311Initial program 72.1%
Taylor expanded in a around 0
lower-*.f6472.1
Applied rewrites72.1%
Taylor expanded in a around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6468.3
Applied rewrites68.3%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6468.3
Applied rewrites68.3%
if -9.999999999999969e-311 < b < 2.20000000000000001e-153Initial program 75.0%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6475.0
Applied rewrites75.0%
Taylor expanded in a around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6475.0
Applied rewrites75.0%
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6474.8
Applied rewrites74.8%
if 2.20000000000000001e-153 < b Initial program 72.0%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6472.0
Applied rewrites72.0%
Taylor expanded in a around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6427.6
Applied rewrites27.6%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
mul-1-negN/A
lower-fma.f64N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6491.9
Applied rewrites91.9%
Final simplification85.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma (* -4.0 c) a (* b b))))
(t_1 (/ (- (- b) b) (* a 2.0))))
(if (<= b -2.9e+116)
(if (>= b 0.0) (/ (- b) a) t_1)
(if (<= b 2e+130)
(if (>= b 0.0) (* (/ c (+ t_0 b)) -2.0) (* (- t_0 b) (/ 0.5 a)))
(if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) t_1)))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma((-4.0 * c), a, (b * b)));
double t_1 = (-b - b) / (a * 2.0);
double tmp_1;
if (b <= -2.9e+116) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= 2e+130) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c / (t_0 + b)) * -2.0;
} else {
tmp_3 = (t_0 - b) * (0.5 / a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (-2.0 * b);
} else {
tmp_1 = t_1;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))) t_1 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= -2.9e+116) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= 2e+130) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c / Float64(t_0 + b)) * -2.0); else tmp_3 = Float64(Float64(t_0 - b) * Float64(0.5 / a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp_1 = t_1; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.9e+116], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], t$95$1], If[LessEqual[b, 2e+130], If[GreaterEqual[b, 0.0], N[(N[(c / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision] * -2.0), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)}\\
t_1 := \frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -2.9 \cdot 10^{+116}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+130}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{t\_0 + b} \cdot -2\\
\mathbf{else}:\\
\;\;\;\;\left(t\_0 - b\right) \cdot \frac{0.5}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if b < -2.9000000000000001e116Initial program 58.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6498.0
Applied rewrites98.0%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6498.0
Applied rewrites98.0%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6498.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.0
Applied rewrites98.0%
if -2.9000000000000001e116 < b < 2.0000000000000001e130Initial program 87.8%
Taylor expanded in a around 0
lower-*.f6476.5
Applied rewrites76.5%
Taylor expanded in a around 0
Applied rewrites87.8%
Applied rewrites87.8%
if 2.0000000000000001e130 < b Initial program 47.5%
Taylor expanded in a around 0
lower-*.f64100.0
Applied rewrites100.0%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Final simplification92.3%
(FPCore (a b c)
:precision binary64
(if (<= b -4.3e-76)
(if (>= b 0.0) (/ (- b) a) (/ (- (- b) b) (* a 2.0)))
(if (>= b 0.0)
(/ (* c 2.0) (* -2.0 b))
(/ (- (sqrt (* (* a c) -4.0)) b) (* a 2.0)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -4.3e-76) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = (-b - b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (-2.0 * b);
} else {
tmp_1 = (sqrt(((a * c) * -4.0)) - b) / (a * 2.0);
}
return tmp_1;
}
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
real(8) :: tmp_1
real(8) :: tmp_2
if (b <= (-4.3d-76)) then
if (b >= 0.0d0) then
tmp_2 = -b / a
else
tmp_2 = (-b - b) / (a * 2.0d0)
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = (c * 2.0d0) / ((-2.0d0) * b)
else
tmp_1 = (sqrt(((a * c) * (-4.0d0))) - b) / (a * 2.0d0)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double tmp_1;
if (b <= -4.3e-76) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = (-b - b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (-2.0 * b);
} else {
tmp_1 = (Math.sqrt(((a * c) * -4.0)) - b) / (a * 2.0);
}
return tmp_1;
}
def code(a, b, c): tmp_1 = 0 if b <= -4.3e-76: tmp_2 = 0 if b >= 0.0: tmp_2 = -b / a else: tmp_2 = (-b - b) / (a * 2.0) tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = (c * 2.0) / (-2.0 * b) else: tmp_1 = (math.sqrt(((a * c) * -4.0)) - b) / (a * 2.0) return tmp_1
function code(a, b, c) tmp_1 = 0.0 if (b <= -4.3e-76) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp_1 = Float64(Float64(sqrt(Float64(Float64(a * c) * -4.0)) - b) / Float64(a * 2.0)); end return tmp_1 end
function tmp_4 = code(a, b, c) tmp_2 = 0.0; if (b <= -4.3e-76) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = -b / a; else tmp_3 = (-b - b) / (a * 2.0); end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = (c * 2.0) / (-2.0 * b); else tmp_2 = (sqrt(((a * c) * -4.0)) - b) / (a * 2.0); end tmp_4 = tmp_2; end
code[a_, b_, c_] := If[LessEqual[b, -4.3e-76], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.3 \cdot 10^{-76}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\left(a \cdot c\right) \cdot -4} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -4.2999999999999999e-76Initial program 76.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6487.8
Applied rewrites87.8%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6487.8
Applied rewrites87.8%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6487.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6487.8
Applied rewrites87.8%
if -4.2999999999999999e-76 < b Initial program 72.3%
Taylor expanded in a around 0
lower-*.f6479.0
Applied rewrites79.0%
Taylor expanded in a around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6478.0
Applied rewrites78.0%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6478.0
Applied rewrites78.0%
Final simplification81.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) (/ (- (- b) b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (-2.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 * 2.0d0) / ((-2.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 * 2.0) / (-2.0 * b);
} else {
tmp = (-b - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (c * 2.0) / (-2.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(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp = Float64(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 * 2.0) / (-2.0 * b); else tmp = (-b - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.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:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 73.8%
Taylor expanded in a around 0
lower-*.f6478.1
Applied rewrites78.1%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6473.1
Applied rewrites73.1%
Final simplification73.1%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ (- (- b) b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} 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 = -b / a
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 = -b / a;
} else {
tmp = (-b - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = (-b - b) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(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 = -b / a; else tmp = (-b - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 73.8%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6468.8
Applied rewrites68.8%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6436.0
Applied rewrites36.0%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6436.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6436.0
Applied rewrites36.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (* (/ 0.5 a) (- (- b) b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = (0.5 / a) * (-b - b);
}
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 = -b / a
else
tmp = (0.5d0 / a) * (-b - b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = (0.5 / a) * (-b - b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = (0.5 / a) * (-b - b) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(0.5 / a) * Float64(Float64(-b) - b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -b / a; else tmp = (0.5 / a) * (-b - b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[(0.5 / a), $MachinePrecision] * N[((-b) - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\left(-b\right) - b\right)\\
\end{array}
\end{array}
Initial program 73.8%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6468.8
Applied rewrites68.8%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6436.0
Applied rewrites36.0%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6435.9
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6435.9
Applied rewrites35.9%
herbie shell --seed 2024304
(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))))