
(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 (- (* b b) (* c (* a 4.0))))))
(if (<= b -4e+148)
(if (>= b 0.0) (* c (/ -2.0 (+ b b))) (fma -1.0 (/ b a) (/ c b)))
(if (<= b 7.5e+67)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_0)) (/ (- t_0 b) (* a 2.0)))
(if (>= b 0.0) (/ (* c 2.0) (* b -2.0)) (/ (* b -2.0) (* a 2.0)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -4e+148) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * (-2.0 / (b + b));
} else {
tmp_2 = fma(-1.0, (b / a), (c / b));
}
tmp_1 = tmp_2;
} else if (b <= 7.5e+67) {
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) / (b * -2.0);
} else {
tmp_1 = (b * -2.0) / (a * 2.0);
}
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 <= -4e+148) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c * Float64(-2.0 / Float64(b + b))); else tmp_2 = fma(-1.0, Float64(b / a), Float64(c / b)); end tmp_1 = tmp_2; elseif (b <= 7.5e+67) 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(b * -2.0)); else tmp_1 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); 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, -4e+148], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 7.5e+67], 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[(b * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $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 -4 \cdot 10^{+148}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + b}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\end{array}\\
\mathbf{elif}\;b \leq 7.5 \cdot 10^{+67}:\\
\;\;\;\;\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}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}
\end{array}
if b < -4.0000000000000002e148Initial program 29.4%
Simplified29.7%
Taylor expanded in b around -inf 97.3%
fma-define97.3%
Simplified97.3%
Taylor expanded in c around 0 97.3%
if -4.0000000000000002e148 < b < 7.5000000000000005e67Initial program 87.8%
if 7.5000000000000005e67 < b Initial program 53.5%
Taylor expanded in b around -inf 53.5%
*-commutative53.5%
Simplified53.5%
Taylor expanded in b around inf 94.6%
associate-*r/94.6%
Simplified94.6%
Taylor expanded in b around inf 97.3%
*-commutative97.3%
Simplified97.3%
Final simplification91.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* b -2.0) (* a 2.0))))
(if (<= b 8.5e+67)
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (sqrt (- (* b b) (* c (* a 4.0))))))
t_0)
(if (>= b 0.0) (/ (* c 2.0) (* b -2.0)) t_0))))
double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (a * 2.0);
double tmp_1;
if (b <= 8.5e+67) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - sqrt(((b * b) - (c * (a * 4.0)))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (b * -2.0);
} else {
tmp_1 = t_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) :: t_0
real(8) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
t_0 = (b * (-2.0d0)) / (a * 2.0d0)
if (b <= 8.5d+67) then
if (b >= 0.0d0) then
tmp_2 = (c * 2.0d0) / (-b - sqrt(((b * b) - (c * (a * 4.0d0)))))
else
tmp_2 = t_0
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = (c * 2.0d0) / (b * (-2.0d0))
else
tmp_1 = t_0
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (a * 2.0);
double tmp_1;
if (b <= 8.5e+67) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - Math.sqrt(((b * b) - (c * (a * 4.0)))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (b * -2.0);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
def code(a, b, c): t_0 = (b * -2.0) / (a * 2.0) tmp_1 = 0 if b <= 8.5e+67: tmp_2 = 0 if b >= 0.0: tmp_2 = (c * 2.0) / (-b - math.sqrt(((b * b) - (c * (a * 4.0))))) else: tmp_2 = t_0 tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = (c * 2.0) / (b * -2.0) else: tmp_1 = t_0 return tmp_1
function code(a, b, c) t_0 = Float64(Float64(b * -2.0) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= 8.5e+67) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))))); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(b * -2.0)); else tmp_1 = t_0; end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = (b * -2.0) / (a * 2.0); tmp_2 = 0.0; if (b <= 8.5e+67) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (c * 2.0) / (-b - sqrt(((b * b) - (c * (a * 4.0))))); else tmp_3 = t_0; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = (c * 2.0) / (b * -2.0); else tmp_2 = t_0; end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 8.5e+67], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot -2}{a \cdot 2}\\
\mathbf{if}\;b \leq 8.5 \cdot 10^{+67}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < 8.50000000000000038e67Initial program 76.8%
Taylor expanded in b around -inf 74.0%
*-commutative74.0%
Simplified74.0%
if 8.50000000000000038e67 < b Initial program 53.5%
Taylor expanded in b around -inf 53.5%
*-commutative53.5%
Simplified53.5%
Taylor expanded in b around inf 94.6%
associate-*r/94.6%
Simplified94.6%
Taylor expanded in b around inf 97.3%
*-commutative97.3%
Simplified97.3%
Final simplification80.5%
(FPCore (a b c)
:precision binary64
(if (<= b 6.8e-77)
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (sqrt (* c (* a -4.0)))))
(/ (* b -2.0) (* a 2.0)))
(if (>= b 0.0)
(* c (/ -2.0 (+ b (fma -2.0 (* a (/ c b)) b))))
(fma -1.0 (/ b a) (/ c b)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= 6.8e-77) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - sqrt((c * (a * -4.0))));
} else {
tmp_2 = (b * -2.0) / (a * 2.0);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = c * (-2.0 / (b + fma(-2.0, (a * (c / b)), b)));
} else {
tmp_1 = fma(-1.0, (b / a), (c / b));
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= 6.8e-77) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -4.0))))); else tmp_2 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(c * Float64(-2.0 / Float64(b + fma(-2.0, Float64(a * Float64(c / b)), b)))); else tmp_1 = fma(-1.0, Float64(b / a), Float64(c / b)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, 6.8e-77], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + N[(-2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.8 \cdot 10^{-77}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + \mathsf{fma}\left(-2, a \cdot \frac{c}{b}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\end{array}
\end{array}
if b < 6.79999999999999966e-77Initial program 73.6%
Taylor expanded in b around -inf 70.3%
*-commutative70.3%
Simplified70.3%
Taylor expanded in b around 0 67.4%
*-commutative67.4%
*-commutative67.4%
associate-*r*67.4%
Simplified67.4%
if 6.79999999999999966e-77 < b Initial program 65.3%
Simplified65.2%
Taylor expanded in b around -inf 65.2%
fma-define65.2%
Simplified65.2%
Taylor expanded in c around 0 86.1%
+-commutative86.1%
fma-define86.1%
associate-/l*88.0%
Simplified88.0%
Final simplification75.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* b -2.0) (* a 2.0))))
(if (<= b 6.8e-78)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) (sqrt (* c (* a -4.0))))) t_0)
(if (>= b 0.0) (/ (* c 2.0) (* b -2.0)) t_0))))
double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (a * 2.0);
double tmp_1;
if (b <= 6.8e-78) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - sqrt((c * (a * -4.0))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (b * -2.0);
} else {
tmp_1 = t_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) :: t_0
real(8) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
t_0 = (b * (-2.0d0)) / (a * 2.0d0)
if (b <= 6.8d-78) then
if (b >= 0.0d0) then
tmp_2 = (c * 2.0d0) / (-b - sqrt((c * (a * (-4.0d0)))))
else
tmp_2 = t_0
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = (c * 2.0d0) / (b * (-2.0d0))
else
tmp_1 = t_0
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (a * 2.0);
double tmp_1;
if (b <= 6.8e-78) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - Math.sqrt((c * (a * -4.0))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (b * -2.0);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
def code(a, b, c): t_0 = (b * -2.0) / (a * 2.0) tmp_1 = 0 if b <= 6.8e-78: tmp_2 = 0 if b >= 0.0: tmp_2 = (c * 2.0) / (-b - math.sqrt((c * (a * -4.0)))) else: tmp_2 = t_0 tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = (c * 2.0) / (b * -2.0) else: tmp_1 = t_0 return tmp_1
function code(a, b, c) t_0 = Float64(Float64(b * -2.0) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= 6.8e-78) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -4.0))))); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(b * -2.0)); else tmp_1 = t_0; end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = (b * -2.0) / (a * 2.0); tmp_2 = 0.0; if (b <= 6.8e-78) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (c * 2.0) / (-b - sqrt((c * (a * -4.0)))); else tmp_3 = t_0; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = (c * 2.0) / (b * -2.0); else tmp_2 = t_0; end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 6.8e-78], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot -2}{a \cdot 2}\\
\mathbf{if}\;b \leq 6.8 \cdot 10^{-78}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < 6.80000000000000023e-78Initial program 73.6%
Taylor expanded in b around -inf 70.3%
*-commutative70.3%
Simplified70.3%
Taylor expanded in b around 0 67.4%
*-commutative67.4%
*-commutative67.4%
associate-*r*67.4%
Simplified67.4%
if 6.80000000000000023e-78 < b Initial program 65.3%
Taylor expanded in b around -inf 65.3%
*-commutative65.3%
Simplified65.3%
Taylor expanded in b around inf 86.4%
associate-*r/86.4%
Simplified86.4%
Taylor expanded in b around inf 87.8%
*-commutative87.8%
Simplified87.8%
Final simplification75.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ -2.0 (+ b b))) (fma -1.0 (/ b a) (/ c b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-2.0 / (b + b));
} else {
tmp = fma(-1.0, (b / a), (c / b));
}
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 = fma(-1.0, Float64(b / a), Float64(c / b)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + b}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\end{array}
\end{array}
Initial program 70.3%
Simplified70.3%
Taylor expanded in b around -inf 68.5%
fma-define68.5%
Simplified68.5%
Taylor expanded in c around 0 67.6%
Final simplification67.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ b a) (/ (* b -2.0) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = b / a;
} else {
tmp = (b * -2.0) / (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 * (-2.0d0)) / (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 * -2.0) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = b / a else: tmp = (b * -2.0) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(b / a); else tmp = Float64(Float64(b * -2.0) / 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 * -2.0) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(b / a), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 70.3%
Taylor expanded in b around -inf 68.3%
*-commutative68.3%
Simplified68.3%
Taylor expanded in b around inf 66.9%
associate-*r/66.9%
Simplified66.9%
Taylor expanded in c around inf 31.7%
Final simplification31.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* c 2.0) (* b -2.0)) (/ (* b -2.0) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (b * -2.0);
} else {
tmp = (b * -2.0) / (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) / (b * (-2.0d0))
else
tmp = (b * (-2.0d0)) / (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) / (b * -2.0);
} else {
tmp = (b * -2.0) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (c * 2.0) / (b * -2.0) else: tmp = (b * -2.0) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * 2.0) / Float64(b * -2.0)); else tmp = Float64(Float64(b * -2.0) / 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) / (b * -2.0); else tmp = (b * -2.0) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 70.3%
Taylor expanded in b around -inf 68.3%
*-commutative68.3%
Simplified68.3%
Taylor expanded in b around inf 66.9%
associate-*r/66.9%
Simplified66.9%
Taylor expanded in b around inf 67.5%
*-commutative67.5%
Simplified67.5%
Final simplification67.5%
herbie shell --seed 2024041
(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))))