
(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 (* c (* a -4.0))))
(if (<= b -33500000000000.0)
(if (>= b 0.0)
(fma -1.0 (/ b a) (/ c b))
(* (+ (* (/ b a) 2.0) (/ (* c -2.0) b)) -0.5))
(if (<= b 1e+55)
(if (>= b 0.0)
(* c (/ -2.0 (+ b (sqrt (fma b b t_0)))))
(* -0.5 (- (/ b a) (/ (hypot b (sqrt t_0)) a))))
(if (>= b 0.0)
(/ (* c -2.0) (fma -2.0 (* c (/ a b)) (+ b b)))
(* -0.5 (/ (fma 0.5 (/ a (/ (/ b c) -4.0)) (* b 2.0)) a)))))))
double code(double a, double b, double c) {
double t_0 = c * (a * -4.0);
double tmp_1;
if (b <= -33500000000000.0) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = fma(-1.0, (b / a), (c / b));
} else {
tmp_2 = (((b / a) * 2.0) + ((c * -2.0) / b)) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 1e+55) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = c * (-2.0 / (b + sqrt(fma(b, b, t_0))));
} else {
tmp_3 = -0.5 * ((b / a) - (hypot(b, sqrt(t_0)) / a));
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * -2.0) / fma(-2.0, (c * (a / b)), (b + b));
} else {
tmp_1 = -0.5 * (fma(0.5, (a / ((b / c) / -4.0)), (b * 2.0)) / a);
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(c * Float64(a * -4.0)) tmp_1 = 0.0 if (b <= -33500000000000.0) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = fma(-1.0, Float64(b / a), Float64(c / b)); else tmp_2 = Float64(Float64(Float64(Float64(b / a) * 2.0) + Float64(Float64(c * -2.0) / b)) * -0.5); end tmp_1 = tmp_2; elseif (b <= 1e+55) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(c * Float64(-2.0 / Float64(b + sqrt(fma(b, b, t_0))))); else tmp_3 = Float64(-0.5 * Float64(Float64(b / a) - Float64(hypot(b, sqrt(t_0)) / a))); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * -2.0) / fma(-2.0, Float64(c * Float64(a / b)), Float64(b + b))); else tmp_1 = Float64(-0.5 * Float64(fma(0.5, Float64(a / Float64(Float64(b / c) / -4.0)), Float64(b * 2.0)) / a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -33500000000000.0], If[GreaterEqual[b, 0.0], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(b / a), $MachinePrecision] * 2.0), $MachinePrecision] + N[(N[(c * -2.0), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]], If[LessEqual[b, 1e+55], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + N[Sqrt[N[(b * b + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(b / a), $MachinePrecision] - N[(N[Sqrt[b ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * -2.0), $MachinePrecision] / N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(0.5 * N[(a / N[(N[(b / c), $MachinePrecision] / -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot -4\right)\\
\mathbf{if}\;b \leq -33500000000000:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{b}{a} \cdot 2 + \frac{c \cdot -2}{b}\right) \cdot -0.5\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{+55}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + \sqrt{\mathsf{fma}\left(b, b, t_0\right)}}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\frac{b}{a} - \frac{\mathsf{hypot}\left(b, \sqrt{t_0}\right)}{a}\right)\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot -2}{\mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b + b\right)}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{\mathsf{fma}\left(0.5, \frac{a}{\frac{\frac{b}{c}}{-4}}, b \cdot 2\right)}{a}\\
\end{array}
\end{array}
if b < -3.35e13Initial program 55.5%
Simplified55.5%
Taylor expanded in b around -inf 90.4%
+-commutative90.4%
fma-def90.4%
Simplified90.4%
Taylor expanded in b around -inf 90.4%
fma-def90.4%
Simplified90.4%
*-un-lft-identity90.4%
fma-udef90.4%
distribute-rgt-in90.4%
associate-*r/90.4%
Applied egg-rr90.4%
if -3.35e13 < b < 1.00000000000000001e55Initial program 82.3%
Simplified82.2%
div-sub82.2%
fma-udef82.2%
add-sqr-sqrt81.3%
hypot-def84.6%
Applied egg-rr84.6%
if 1.00000000000000001e55 < b Initial program 55.6%
Simplified55.5%
add-exp-log55.5%
fma-udef55.5%
add-sqr-sqrt55.5%
hypot-def55.5%
Applied egg-rr55.5%
Taylor expanded in b around -inf 55.5%
fma-def55.5%
associate-/l*55.5%
unpow255.5%
rem-square-sqrt55.5%
associate-/r*55.5%
*-commutative55.5%
Simplified55.5%
Taylor expanded in b around inf 95.5%
fma-def95.5%
associate-/l*99.8%
count-299.8%
Simplified99.8%
associate-*r/100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Final simplification89.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* c (* a -4.0))))
(if (<= b -66000000.0)
(if (>= b 0.0)
(fma -1.0 (/ b a) (/ c b))
(* (+ (* (/ b a) 2.0) (/ (* c -2.0) b)) -0.5))
(if (<= b 1e+55)
(if (>= b 0.0)
(* c (/ -2.0 (+ b (sqrt (fma b b t_0)))))
(* -0.5 (* (- b (hypot b (sqrt t_0))) (/ 1.0 a))))
(if (>= b 0.0)
(/ (* c -2.0) (fma -2.0 (* c (/ a b)) (+ b b)))
(* -0.5 (/ (fma 0.5 (/ a (/ (/ b c) -4.0)) (* b 2.0)) a)))))))
double code(double a, double b, double c) {
double t_0 = c * (a * -4.0);
double tmp_1;
if (b <= -66000000.0) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = fma(-1.0, (b / a), (c / b));
} else {
tmp_2 = (((b / a) * 2.0) + ((c * -2.0) / b)) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 1e+55) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = c * (-2.0 / (b + sqrt(fma(b, b, t_0))));
} else {
tmp_3 = -0.5 * ((b - hypot(b, sqrt(t_0))) * (1.0 / a));
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * -2.0) / fma(-2.0, (c * (a / b)), (b + b));
} else {
tmp_1 = -0.5 * (fma(0.5, (a / ((b / c) / -4.0)), (b * 2.0)) / a);
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(c * Float64(a * -4.0)) tmp_1 = 0.0 if (b <= -66000000.0) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = fma(-1.0, Float64(b / a), Float64(c / b)); else tmp_2 = Float64(Float64(Float64(Float64(b / a) * 2.0) + Float64(Float64(c * -2.0) / b)) * -0.5); end tmp_1 = tmp_2; elseif (b <= 1e+55) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(c * Float64(-2.0 / Float64(b + sqrt(fma(b, b, t_0))))); else tmp_3 = Float64(-0.5 * Float64(Float64(b - hypot(b, sqrt(t_0))) * Float64(1.0 / a))); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * -2.0) / fma(-2.0, Float64(c * Float64(a / b)), Float64(b + b))); else tmp_1 = Float64(-0.5 * Float64(fma(0.5, Float64(a / Float64(Float64(b / c) / -4.0)), Float64(b * 2.0)) / a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -66000000.0], If[GreaterEqual[b, 0.0], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(b / a), $MachinePrecision] * 2.0), $MachinePrecision] + N[(N[(c * -2.0), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]], If[LessEqual[b, 1e+55], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + N[Sqrt[N[(b * b + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(b - N[Sqrt[b ^ 2 + N[Sqrt[t$95$0], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * N[(1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * -2.0), $MachinePrecision] / N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(0.5 * N[(a / N[(N[(b / c), $MachinePrecision] / -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := c \cdot \left(a \cdot -4\right)\\
\mathbf{if}\;b \leq -66000000:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{b}{a} \cdot 2 + \frac{c \cdot -2}{b}\right) \cdot -0.5\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{+55}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + \sqrt{\mathsf{fma}\left(b, b, t_0\right)}}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \left(\left(b - \mathsf{hypot}\left(b, \sqrt{t_0}\right)\right) \cdot \frac{1}{a}\right)\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot -2}{\mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b + b\right)}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{\mathsf{fma}\left(0.5, \frac{a}{\frac{\frac{b}{c}}{-4}}, b \cdot 2\right)}{a}\\
\end{array}
\end{array}
if b < -6.6e7Initial program 55.5%
Simplified55.5%
Taylor expanded in b around -inf 90.4%
+-commutative90.4%
fma-def90.4%
Simplified90.4%
Taylor expanded in b around -inf 90.4%
fma-def90.4%
Simplified90.4%
*-un-lft-identity90.4%
fma-udef90.4%
distribute-rgt-in90.4%
associate-*r/90.4%
Applied egg-rr90.4%
if -6.6e7 < b < 1.00000000000000001e55Initial program 82.3%
Simplified82.2%
div-inv82.0%
fma-udef82.0%
add-sqr-sqrt81.2%
hypot-def84.4%
Applied egg-rr84.4%
if 1.00000000000000001e55 < b Initial program 55.6%
Simplified55.5%
add-exp-log55.5%
fma-udef55.5%
add-sqr-sqrt55.5%
hypot-def55.5%
Applied egg-rr55.5%
Taylor expanded in b around -inf 55.5%
fma-def55.5%
associate-/l*55.5%
unpow255.5%
rem-square-sqrt55.5%
associate-/r*55.5%
*-commutative55.5%
Simplified55.5%
Taylor expanded in b around inf 95.5%
fma-def95.5%
associate-/l*99.8%
count-299.8%
Simplified99.8%
associate-*r/100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Final simplification89.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* -0.5 (/ (fma 0.5 (/ a (/ (/ b c) -4.0)) (* b 2.0)) a)))
(t_1 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -2e+134)
(if (>= b 0.0) (* c (/ -2.0 (fma -2.0 (/ a (/ b c)) (+ b b)))) t_0)
(if (<= b 8.8e+54)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_1)) (/ (- t_1 b) (* a 2.0)))
(if (>= b 0.0) (/ (* c -2.0) (fma -2.0 (* c (/ a b)) (+ b b))) t_0)))))
double code(double a, double b, double c) {
double t_0 = -0.5 * (fma(0.5, (a / ((b / c) / -4.0)), (b * 2.0)) / a);
double t_1 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -2e+134) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * (-2.0 / fma(-2.0, (a / (b / c)), (b + b)));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b <= 8.8e+54) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_1);
} else {
tmp_3 = (t_1 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * -2.0) / fma(-2.0, (c * (a / b)), (b + b));
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(-0.5 * Float64(fma(0.5, Float64(a / Float64(Float64(b / c) / -4.0)), Float64(b * 2.0)) / a)) t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -2e+134) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c * Float64(-2.0 / fma(-2.0, Float64(a / Float64(b / c)), Float64(b + b)))); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b <= 8.8e+54) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - t_1)); else tmp_3 = Float64(Float64(t_1 - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * -2.0) / fma(-2.0, Float64(c * Float64(a / b)), Float64(b + b))); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(-0.5 * N[(N[(0.5 * N[(a / N[(N[(b / c), $MachinePrecision] / -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -2e+134], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(-2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[LessEqual[b, 8.8e+54], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * -2.0), $MachinePrecision] / N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := -0.5 \cdot \frac{\mathsf{fma}\left(0.5, \frac{a}{\frac{\frac{b}{c}}{-4}}, b \cdot 2\right)}{a}\\
t_1 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+134}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{\mathsf{fma}\left(-2, \frac{a}{\frac{b}{c}}, b + b\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{elif}\;b \leq 8.8 \cdot 10^{+54}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot -2}{\mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b + b\right)}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if b < -1.99999999999999984e134Initial program 39.8%
Simplified39.8%
add-exp-log39.2%
fma-udef39.2%
add-sqr-sqrt24.0%
hypot-def48.3%
Applied egg-rr48.3%
Taylor expanded in b around -inf 0.0%
fma-def0.0%
associate-/l*0.0%
unpow20.0%
rem-square-sqrt98.2%
associate-/r*98.2%
*-commutative98.2%
Simplified98.2%
Taylor expanded in b around inf 98.2%
fma-def98.2%
associate-/l*98.2%
count-298.2%
Simplified98.2%
if -1.99999999999999984e134 < b < 8.7999999999999996e54Initial program 82.7%
if 8.7999999999999996e54 < b Initial program 55.6%
Simplified55.5%
add-exp-log55.5%
fma-udef55.5%
add-sqr-sqrt55.5%
hypot-def55.5%
Applied egg-rr55.5%
Taylor expanded in b around -inf 55.5%
fma-def55.5%
associate-/l*55.5%
unpow255.5%
rem-square-sqrt55.5%
associate-/r*55.5%
*-commutative55.5%
Simplified55.5%
Taylor expanded in b around inf 95.5%
fma-def95.5%
associate-/l*99.8%
count-299.8%
Simplified99.8%
associate-*r/100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Final simplification89.1%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ -2.0 (fma -2.0 (/ a (/ b c)) (+ b b)))) (* -0.5 (/ (fma 0.5 (/ a (/ (/ b c) -4.0)) (* b 2.0)) a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-2.0 / fma(-2.0, (a / (b / c)), (b + b)));
} else {
tmp = -0.5 * (fma(0.5, (a / ((b / c) / -4.0)), (b * 2.0)) / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c * Float64(-2.0 / fma(-2.0, Float64(a / Float64(b / c)), Float64(b + b)))); else tmp = Float64(-0.5 * Float64(fma(0.5, Float64(a / Float64(Float64(b / c) / -4.0)), Float64(b * 2.0)) / a)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(-2.0 * N[(a / N[(b / c), $MachinePrecision]), $MachinePrecision] + N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(0.5 * N[(a / N[(N[(b / c), $MachinePrecision] / -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{\mathsf{fma}\left(-2, \frac{a}{\frac{b}{c}}, b + b\right)}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{\mathsf{fma}\left(0.5, \frac{a}{\frac{\frac{b}{c}}{-4}}, b \cdot 2\right)}{a}\\
\end{array}
\end{array}
Initial program 68.5%
Simplified68.4%
add-exp-log66.9%
fma-udef66.9%
add-sqr-sqrt58.9%
hypot-def65.8%
Applied egg-rr65.8%
Taylor expanded in b around -inf 32.2%
fma-def32.2%
associate-/l*32.2%
unpow232.2%
rem-square-sqrt70.7%
associate-/r*70.7%
*-commutative70.7%
Simplified70.7%
Taylor expanded in b around inf 62.2%
fma-def62.2%
associate-/l*62.9%
count-262.9%
Simplified62.9%
Final simplification62.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* c -2.0) (fma -2.0 (* c (/ a b)) (+ b b))) (* -0.5 (/ (fma 0.5 (/ a (/ (/ b c) -4.0)) (* b 2.0)) a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * -2.0) / fma(-2.0, (c * (a / b)), (b + b));
} else {
tmp = -0.5 * (fma(0.5, (a / ((b / c) / -4.0)), (b * 2.0)) / a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * -2.0) / fma(-2.0, Float64(c * Float64(a / b)), Float64(b + b))); else tmp = Float64(-0.5 * Float64(fma(0.5, Float64(a / Float64(Float64(b / c) / -4.0)), Float64(b * 2.0)) / a)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c * -2.0), $MachinePrecision] / N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-0.5 * N[(N[(0.5 * N[(a / N[(N[(b / c), $MachinePrecision] / -4.0), $MachinePrecision]), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot -2}{\mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b + b\right)}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{\mathsf{fma}\left(0.5, \frac{a}{\frac{\frac{b}{c}}{-4}}, b \cdot 2\right)}{a}\\
\end{array}
\end{array}
Initial program 68.5%
Simplified68.4%
add-exp-log66.9%
fma-udef66.9%
add-sqr-sqrt58.9%
hypot-def65.8%
Applied egg-rr65.8%
Taylor expanded in b around -inf 32.2%
fma-def32.2%
associate-/l*32.2%
unpow232.2%
rem-square-sqrt70.7%
associate-/r*70.7%
*-commutative70.7%
Simplified70.7%
Taylor expanded in b around inf 62.2%
fma-def62.2%
associate-/l*62.9%
count-262.9%
Simplified62.9%
associate-*r/62.9%
associate-/r/63.0%
Applied egg-rr63.0%
Final simplification63.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ -2.0 (+ b b))) (* -0.5 (/ (+ b b) a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-2.0 / (b + b));
} else {
tmp = -0.5 * ((b + b) / 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 = (-0.5d0) * ((b + b) / 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 = -0.5 * ((b + b) / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c * (-2.0 / (b + b)) else: tmp = -0.5 * ((b + b) / 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(-0.5 * Float64(Float64(b + b) / 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 = -0.5 * ((b + b) / 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[(-0.5 * N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + b}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{a}\\
\end{array}
\end{array}
Initial program 68.5%
Simplified68.4%
Taylor expanded in b around -inf 70.6%
Taylor expanded in b around inf 62.7%
Final simplification62.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (* -0.5 (/ (+ b b) a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = -0.5 * ((b + b) / 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 = (-0.5d0) * ((b + b) / 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 = -0.5 * ((b + b) / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = -0.5 * ((b + b) / a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(-0.5 * Float64(Float64(b + b) / a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = -0.5 * ((b + b) / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(-0.5 * N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{a}\\
\end{array}
\end{array}
Initial program 68.5%
Simplified68.4%
Taylor expanded in b around -inf 70.6%
Taylor expanded in c around 0 62.8%
mul-1-neg62.8%
distribute-neg-frac62.8%
Simplified62.8%
Final simplification62.8%
herbie shell --seed 2023280
(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))))