
(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 (* 4.0 a)))))
(t_1 (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ b (- a))))
(t_2 (fma a (/ c b) (- b))))
(if (<= b -6.5e+155)
t_1
(if (<= b -3.8e-306)
(if (>= b 0.0) (/ (* 2.0 c) (* 2.0 t_2)) (/ (- t_0 b) (* 2.0 a)))
(if (<= b 2e+83) t_1 (if (>= b 0.0) (/ c t_2) 0.0))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (4.0 * a))));
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = b / -a;
}
double t_1 = tmp;
double t_2 = fma(a, (c / b), -b);
double tmp_1;
if (b <= -6.5e+155) {
tmp_1 = t_1;
} else if (b <= -3.8e-306) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (2.0 * t_2);
} else {
tmp_2 = (t_0 - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 2e+83) {
tmp_1 = t_1;
} else if (b >= 0.0) {
tmp_1 = c / t_2;
} else {
tmp_1 = 0.0;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = Float64(b / Float64(-a)); end t_1 = tmp t_2 = fma(a, Float64(c / b), Float64(-b)) tmp_1 = 0.0 if (b <= -6.5e+155) tmp_1 = t_1; elseif (b <= -3.8e-306) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(2.0 * t_2)); else tmp_2 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 2e+83) tmp_1 = t_1; elseif (b >= 0.0) tmp_1 = Float64(c / t_2); else tmp_1 = 0.0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]}, Block[{t$95$2 = N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]}, If[LessEqual[b, -6.5e+155], t$95$1, If[LessEqual[b, -3.8e-306], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * t$95$2), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2e+83], t$95$1, If[GreaterEqual[b, 0.0], N[(c / t$95$2), $MachinePrecision], 0.0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
t_1 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
t_2 := \mathsf{fma}\left(a, \frac{c}{b}, -b\right)\\
\mathbf{if}\;b \leq -6.5 \cdot 10^{+155}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;b \leq -3.8 \cdot 10^{-306}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot t\_2}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+83}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c}{t\_2}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -6.50000000000000046e155 or -3.8e-306 < b < 2.00000000000000006e83Initial program 66.6%
add-sqr-sqrt66.6%
pow266.6%
pow1/266.6%
sqrt-pow166.6%
fmm-def66.8%
*-commutative66.8%
distribute-rgt-neg-in66.8%
distribute-lft-neg-in66.8%
metadata-eval66.8%
*-commutative66.8%
metadata-eval66.8%
Applied egg-rr66.8%
Taylor expanded in b around -inf 92.3%
associate-*r/92.3%
neg-mul-192.3%
Simplified92.3%
if -6.50000000000000046e155 < b < -3.8e-306Initial program 89.9%
Taylor expanded in a around 0 89.9%
distribute-lft-out--89.9%
associate-/l*89.9%
fmm-def89.9%
Simplified89.9%
if 2.00000000000000006e83 < b Initial program 56.2%
Simplified56.2%
Taylor expanded in c around 0 93.2%
fma-define93.2%
associate-/l*99.7%
*-commutative99.7%
Simplified99.7%
Taylor expanded in c around 0 99.7%
Taylor expanded in b around 0 93.4%
metadata-eval93.4%
cancel-sign-sub-inv93.4%
associate-*r/93.4%
distribute-lft-out--93.4%
associate-/l*100.0%
fmm-undef100.0%
times-frac100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification93.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* 4.0 a)))))
(t_1 (fma a (/ c b) (- b)))
(t_2
(if (>= b 0.0)
(/ (* 2.0 c) (- (- b) t_0))
(* b (+ (/ c (pow b 2.0)) (/ -1.0 a))))))
(if (<= b -6.5e+155)
t_2
(if (<= b 1.4e-306)
(if (>= b 0.0) (/ (* 2.0 c) (* 2.0 t_1)) (/ (- t_0 b) (* 2.0 a)))
(if (<= b 5e+79) t_2 (if (>= b 0.0) (/ c t_1) 0.0))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (4.0 * a))));
double t_1 = fma(a, (c / b), -b);
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-b - t_0);
} else {
tmp = b * ((c / pow(b, 2.0)) + (-1.0 / a));
}
double t_2 = tmp;
double tmp_1;
if (b <= -6.5e+155) {
tmp_1 = t_2;
} else if (b <= 1.4e-306) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (2.0 * t_1);
} else {
tmp_2 = (t_0 - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 5e+79) {
tmp_1 = t_2;
} else if (b >= 0.0) {
tmp_1 = c / t_1;
} else {
tmp_1 = 0.0;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) t_1 = fma(a, Float64(c / b), Float64(-b)) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = Float64(b * Float64(Float64(c / (b ^ 2.0)) + Float64(-1.0 / a))); end t_2 = tmp tmp_1 = 0.0 if (b <= -6.5e+155) tmp_1 = t_2; elseif (b <= 1.4e-306) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(2.0 * t_1)); else tmp_2 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 5e+79) tmp_1 = t_2; elseif (b >= 0.0) tmp_1 = Float64(c / t_1); else tmp_1 = 0.0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]}, Block[{t$95$2 = If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]}, If[LessEqual[b, -6.5e+155], t$95$2, If[LessEqual[b, 1.4e-306], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 5e+79], t$95$2, If[GreaterEqual[b, 0.0], N[(c / t$95$1), $MachinePrecision], 0.0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
t_1 := \mathsf{fma}\left(a, \frac{c}{b}, -b\right)\\
t_2 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\
\end{array}\\
\mathbf{if}\;b \leq -6.5 \cdot 10^{+155}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;b \leq 1.4 \cdot 10^{-306}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot t\_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+79}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c}{t\_1}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -6.50000000000000046e155 or 1.4000000000000001e-306 < b < 5e79Initial program 67.8%
add-sqr-sqrt67.8%
pow267.8%
pow1/267.8%
sqrt-pow167.8%
fmm-def67.9%
*-commutative67.9%
distribute-rgt-neg-in67.9%
distribute-lft-neg-in67.9%
metadata-eval67.9%
*-commutative67.9%
metadata-eval67.9%
Applied egg-rr67.9%
Taylor expanded in b around -inf 94.0%
if -6.50000000000000046e155 < b < 1.4000000000000001e-306Initial program 88.0%
Taylor expanded in a around 0 88.0%
distribute-lft-out--88.0%
associate-/l*88.0%
fmm-def88.0%
Simplified88.0%
if 5e79 < b Initial program 56.2%
Simplified56.2%
Taylor expanded in c around 0 93.2%
fma-define93.2%
associate-/l*99.7%
*-commutative99.7%
Simplified99.7%
Taylor expanded in c around 0 99.7%
Taylor expanded in b around 0 93.4%
metadata-eval93.4%
cancel-sign-sub-inv93.4%
associate-*r/93.4%
distribute-lft-out--93.4%
associate-/l*100.0%
fmm-undef100.0%
times-frac100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification93.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* 4.0 a)))))
(t_1 (/ (* 2.0 c) (- (- b) t_0))))
(if (<= b -6.5e+155)
(if (>= b 0.0) t_1 (/ b (- a)))
(if (<= b 3.3e+83)
(if (>= b 0.0) t_1 (/ (- t_0 b) (* 2.0 a)))
(if (>= b 0.0) (/ c (fma a (/ c b) (- b))) 0.0)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (4.0 * a))));
double t_1 = (2.0 * c) / (-b - t_0);
double tmp_1;
if (b <= -6.5e+155) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b <= 3.3e+83) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_1;
} else {
tmp_3 = (t_0 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = c / fma(a, (c / b), -b);
} else {
tmp_1 = 0.0;
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) t_1 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)) tmp_1 = 0.0 if (b <= -6.5e+155) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(b / Float64(-a)); end tmp_1 = tmp_2; elseif (b <= 3.3e+83) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = t_1; else tmp_3 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(c / fma(a, Float64(c / b), Float64(-b))); else tmp_1 = 0.0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -6.5e+155], If[GreaterEqual[b, 0.0], t$95$1, N[(b / (-a)), $MachinePrecision]], If[LessEqual[b, 3.3e+83], If[GreaterEqual[b, 0.0], t$95$1, N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(c / N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision], 0.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
t_1 := \frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{if}\;b \leq -6.5 \cdot 10^{+155}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{+83}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -6.50000000000000046e155Initial program 36.3%
add-sqr-sqrt36.3%
pow236.3%
pow1/236.3%
sqrt-pow136.3%
fmm-def36.6%
*-commutative36.6%
distribute-rgt-neg-in36.6%
distribute-lft-neg-in36.6%
metadata-eval36.6%
*-commutative36.6%
metadata-eval36.6%
Applied egg-rr36.6%
Taylor expanded in b around -inf 98.0%
associate-*r/98.0%
neg-mul-198.0%
Simplified98.0%
if -6.50000000000000046e155 < b < 3.29999999999999985e83Initial program 89.2%
if 3.29999999999999985e83 < b Initial program 56.2%
Simplified56.2%
Taylor expanded in c around 0 93.2%
fma-define93.2%
associate-/l*99.7%
*-commutative99.7%
Simplified99.7%
Taylor expanded in c around 0 99.7%
Taylor expanded in b around 0 93.4%
metadata-eval93.4%
cancel-sign-sub-inv93.4%
associate-*r/93.4%
distribute-lft-out--93.4%
associate-/l*100.0%
fmm-undef100.0%
times-frac100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification93.2%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b)))) (/ (- (sqrt (- (* b b) (* c (* 4.0 a)))) b) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp = (sqrt(((b * b) - (c * (4.0 * a)))) - 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(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b) / Float64(2.0 * a)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 72.5%
Taylor expanded in a around 0 68.6%
distribute-lft-out--68.6%
associate-/l*70.2%
fmm-def70.2%
Simplified70.2%
Final simplification70.2%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ c (fma a (/ c b) (- b))) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c / fma(a, (c / b), -b);
} else {
tmp = 0.0;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c / fma(a, Float64(c / b), Float64(-b))); else tmp = 0.0; end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c / N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{\mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
Initial program 72.5%
Simplified72.5%
Taylor expanded in c around 0 68.6%
fma-define68.6%
associate-/l*70.2%
*-commutative70.2%
Simplified70.2%
Taylor expanded in c around 0 33.5%
Taylor expanded in b around 0 32.0%
metadata-eval32.0%
cancel-sign-sub-inv32.0%
associate-*r/32.0%
distribute-lft-out--32.0%
associate-/l*33.6%
fmm-undef33.6%
times-frac33.6%
metadata-eval33.6%
Simplified33.6%
Final simplification33.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ -2.0 (+ (* -2.0 (* a (/ c b))) (* b 2.0)))) (/ (- 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 * (a * (c / b))) + (b * 2.0)));
} 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) * (a * (c / b))) + (b * 2.0d0)))
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 * (a * (c / b))) + (b * 2.0)));
} 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 * (a * (c / b))) + (b * 2.0))) else: tmp = (b - b) / (a * -2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c * Float64(-2.0 / Float64(Float64(-2.0 * Float64(a * Float64(c / b))) + Float64(b * 2.0)))); else tmp = 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 * (a * (c / b))) + (b * 2.0))); else tmp = (b - b) / (a * -2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(N[(-2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b - b), $MachinePrecision] / N[(a * -2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{-2 \cdot \left(a \cdot \frac{c}{b}\right) + b \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - b}{a \cdot -2}\\
\end{array}
\end{array}
Initial program 72.5%
Simplified72.5%
Taylor expanded in c around 0 68.6%
fma-define68.6%
associate-/l*70.2%
*-commutative70.2%
Simplified70.2%
Taylor expanded in c around 0 33.5%
div-inv33.5%
Applied egg-rr33.5%
associate-*r/33.5%
metadata-eval33.5%
associate-*r/32.0%
Simplified32.0%
fma-undefine32.0%
associate-*r/33.5%
Applied egg-rr33.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ c (- b)) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c / -b;
} else {
tmp = 0.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 / -b
else
tmp = 0.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 / -b;
} else {
tmp = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c / -b else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c / Float64(-b)); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c / -b; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c / (-b)), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
Initial program 72.5%
Simplified72.5%
Taylor expanded in c around 0 68.6%
fma-define68.6%
associate-/l*70.2%
*-commutative70.2%
Simplified70.2%
Taylor expanded in c around 0 33.5%
Taylor expanded in a around 0 33.2%
Taylor expanded in b around 0 33.2%
associate-*r/33.2%
neg-mul-133.2%
Simplified33.2%
Final simplification33.2%
herbie shell --seed 2024149
(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))))