
(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 -1e+154)
(if (>= b 0.0) (/ c (- b)) (/ b (- a)))
(if (<= b 2.8e-281)
(if (>= b 0.0)
(/ 1.0 (fma -1.0 (/ b c) (/ a b)))
(/ (- t_0 b) (* a 2.0)))
(if (<= b 9e+91)
(if (>= b 0.0) (/ (* c (- 2.0)) (+ b t_0)) (/ (* b -2.0) (* a 2.0)))
(if (>= b 0.0)
(/ (* c 2.0) (* 2.0 (fma a (/ c b) (- b))))
(/ (* c (/ (* a -2.0) b)) (* 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 <= -1e+154) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c / -b;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b <= 2.8e-281) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = 1.0 / fma(-1.0, (b / c), (a / b));
} else {
tmp_3 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b <= 9e+91) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = (c * -2.0) / (b + t_0);
} else {
tmp_4 = (b * -2.0) / (a * 2.0);
}
tmp_1 = tmp_4;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_1 = (c * ((a * -2.0) / b)) / (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 <= -1e+154) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c / Float64(-b)); else tmp_2 = Float64(b / Float64(-a)); end tmp_1 = tmp_2; elseif (b <= 2.8e-281) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(1.0 / fma(-1.0, Float64(b / c), Float64(a / b))); else tmp_3 = Float64(Float64(t_0 - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b <= 9e+91) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(c * Float64(-2.0)) / Float64(b + t_0)); else tmp_4 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); end tmp_1 = tmp_4; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_1 = Float64(Float64(c * Float64(Float64(a * -2.0) / b)) / 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, -1e+154], If[GreaterEqual[b, 0.0], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]], If[LessEqual[b, 2.8e-281], If[GreaterEqual[b, 0.0], N[(1.0 / N[(-1.0 * N[(b / c), $MachinePrecision] + N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 9e+91], If[GreaterEqual[b, 0.0], N[(N[(c * (-2.0)), $MachinePrecision] / N[(b + t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * N[(N[(a * -2.0), $MachinePrecision] / b), $MachinePrecision]), $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 -1 \cdot 10^{+154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-281}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-1, \frac{b}{c}, \frac{a}{b}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 9 \cdot 10^{+91}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot \left(-2\right)}{b + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{a \cdot -2}{b}}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.00000000000000004e154Initial program 49.0%
Simplified49.1%
Taylor expanded in b around inf 49.1%
Taylor expanded in b around -inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
associate-*r/100.0%
neg-mul-1100.0%
associate-*r/100.0%
neg-mul-1100.0%
Simplified100.0%
if -1.00000000000000004e154 < b < 2.80000000000000005e-281Initial program 90.4%
add-sqr-sqrt90.2%
pow290.2%
*-commutative90.2%
Applied egg-rr90.2%
clear-num90.2%
inv-pow90.2%
pow290.2%
*-commutative90.2%
*-commutative90.2%
unpow290.2%
add-sqr-sqrt90.4%
Applied egg-rr90.4%
unpow-190.4%
associate-*r*90.4%
*-commutative90.4%
*-commutative90.4%
cancel-sign-sub-inv90.4%
metadata-eval90.4%
+-commutative90.4%
fma-define90.4%
*-commutative90.4%
Simplified90.4%
Taylor expanded in a around 0 90.4%
fma-define90.4%
Simplified90.4%
if 2.80000000000000005e-281 < b < 9e91Initial program 87.1%
Taylor expanded in b around -inf 87.1%
*-commutative87.1%
Simplified87.1%
if 9e91 < b Initial program 59.5%
Taylor expanded in a around 0 92.4%
distribute-lft-out--92.4%
associate-/l*98.5%
fma-neg98.5%
Simplified98.5%
Taylor expanded in b around inf 98.5%
associate-*r/98.5%
associate-*r*98.5%
*-rgt-identity98.5%
times-frac98.5%
/-rgt-identity98.5%
Simplified98.5%
Final simplification92.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma -1.0 (/ b a) (/ c b))))
(if (<= b -2e+153)
(if (>= b 0.0) (/ c (- b)) (/ b (- a)))
(if (<= b 2.8e-281)
(if (>= b 0.0)
(/ 1.0 (fma -1.0 (/ b c) (/ a b)))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))
(if (<= b 2.6e-67)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) (sqrt (* c (* a -4.0))))) t_0)
(if (>= b 0.0) (/ (* c 2.0) (* 2.0 (- (* a (/ c b)) b))) t_0))))))
double code(double a, double b, double c) {
double t_0 = fma(-1.0, (b / a), (c / b));
double tmp_1;
if (b <= -2e+153) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c / -b;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b <= 2.8e-281) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = 1.0 / fma(-1.0, (b / c), (a / b));
} else {
tmp_3 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b <= 2.6e-67) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = (c * 2.0) / (-b - sqrt((c * (a * -4.0))));
} else {
tmp_4 = t_0;
}
tmp_1 = tmp_4;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (2.0 * ((a * (c / b)) - b));
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(-1.0, Float64(b / a), Float64(c / b)) tmp_1 = 0.0 if (b <= -2e+153) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c / Float64(-b)); else tmp_2 = Float64(b / Float64(-a)); end tmp_1 = tmp_2; elseif (b <= 2.8e-281) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(1.0 / fma(-1.0, Float64(b / c), Float64(a / b))); else tmp_3 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b <= 2.6e-67) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -4.0))))); else tmp_4 = t_0; end tmp_1 = tmp_4; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2e+153], If[GreaterEqual[b, 0.0], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]], If[LessEqual[b, 2.8e-281], If[GreaterEqual[b, 0.0], N[(1.0 / N[(-1.0 * N[(b / c), $MachinePrecision] + N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.6e-67], 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[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\mathbf{if}\;b \leq -2 \cdot 10^{+153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-281}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{1}{\mathsf{fma}\left(-1, \frac{b}{c}, \frac{a}{b}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{-67}:\\
\;\;\;\;\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}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -2e153Initial program 49.0%
Simplified49.1%
Taylor expanded in b around inf 49.1%
Taylor expanded in b around -inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
associate-*r/100.0%
neg-mul-1100.0%
associate-*r/100.0%
neg-mul-1100.0%
Simplified100.0%
if -2e153 < b < 2.80000000000000005e-281Initial program 90.4%
add-sqr-sqrt90.2%
pow290.2%
*-commutative90.2%
Applied egg-rr90.2%
clear-num90.2%
inv-pow90.2%
pow290.2%
*-commutative90.2%
*-commutative90.2%
unpow290.2%
add-sqr-sqrt90.4%
Applied egg-rr90.4%
unpow-190.4%
associate-*r*90.4%
*-commutative90.4%
*-commutative90.4%
cancel-sign-sub-inv90.4%
metadata-eval90.4%
+-commutative90.4%
fma-define90.4%
*-commutative90.4%
Simplified90.4%
Taylor expanded in a around 0 90.4%
fma-define90.4%
Simplified90.4%
if 2.80000000000000005e-281 < b < 2.5999999999999999e-67Initial program 80.3%
Taylor expanded in b around -inf 80.3%
mul-1-neg80.3%
*-commutative80.3%
distribute-rgt-neg-in80.3%
associate-/l*80.3%
Simplified80.3%
Taylor expanded in a around inf 80.3%
fma-define80.3%
Simplified80.3%
Taylor expanded in b around 0 67.8%
associate-*r*67.8%
*-commutative67.8%
Simplified67.8%
if 2.5999999999999999e-67 < b Initial program 71.8%
Taylor expanded in b around -inf 71.8%
mul-1-neg71.8%
*-commutative71.8%
distribute-rgt-neg-in71.8%
associate-/l*71.8%
Simplified71.8%
Taylor expanded in a around inf 71.8%
fma-define71.8%
Simplified71.8%
Taylor expanded in a around 0 80.7%
distribute-lft-out--80.7%
associate-/l*84.7%
Simplified84.7%
Final simplification86.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -4e+153)
(if (>= b 0.0) (/ c (- b)) (/ b (- a)))
(if (<= b 1.6e+92)
(if (>= b 0.0) (/ (* c (- 2.0)) (+ b t_0)) (/ (- t_0 b) (* a 2.0)))
(if (>= b 0.0)
(/ (* c 2.0) (* 2.0 (fma a (/ c b) (- b))))
(/ (* c (/ (* a -2.0) b)) (* 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+153) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c / -b;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b <= 1.6e+92) {
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) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_1 = (c * ((a * -2.0) / b)) / (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+153) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c / Float64(-b)); else tmp_2 = Float64(b / Float64(-a)); end tmp_1 = tmp_2; elseif (b <= 1.6e+92) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * Float64(-2.0)) / 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(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_1 = Float64(Float64(c * Float64(Float64(a * -2.0) / b)) / 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+153], If[GreaterEqual[b, 0.0], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]], If[LessEqual[b, 1.6e+92], 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[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * N[(N[(a * -2.0), $MachinePrecision] / b), $MachinePrecision]), $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^{+153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.6 \cdot 10^{+92}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot \left(-2\right)}{b + t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot \frac{a \cdot -2}{b}}{a \cdot 2}\\
\end{array}
\end{array}
if b < -4e153Initial program 49.0%
Simplified49.1%
Taylor expanded in b around inf 49.1%
Taylor expanded in b around -inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in b around 0 100.0%
associate-*r/100.0%
neg-mul-1100.0%
associate-*r/100.0%
neg-mul-1100.0%
Simplified100.0%
if -4e153 < b < 1.60000000000000013e92Initial program 88.8%
if 1.60000000000000013e92 < b Initial program 59.5%
Taylor expanded in a around 0 92.4%
distribute-lft-out--92.4%
associate-/l*98.5%
fma-neg98.5%
Simplified98.5%
Taylor expanded in b around inf 98.5%
associate-*r/98.5%
associate-*r*98.5%
*-rgt-identity98.5%
times-frac98.5%
/-rgt-identity98.5%
Simplified98.5%
Final simplification92.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma -1.0 (/ b a) (/ c b))))
(if (<= b 1.85e-67)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) (sqrt (* c (* a -4.0))))) t_0)
(if (>= b 0.0) (/ (* c 2.0) (* 2.0 (- (* a (/ c b)) b))) t_0))))
double code(double a, double b, double c) {
double t_0 = fma(-1.0, (b / a), (c / b));
double tmp_1;
if (b <= 1.85e-67) {
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) / (2.0 * ((a * (c / b)) - b));
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(-1.0, Float64(b / a), Float64(c / b)) tmp_1 = 0.0 if (b <= 1.85e-67) 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(2.0 * Float64(Float64(a * Float64(c / b)) - b))); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.85e-67], 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[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\mathbf{if}\;b \leq 1.85 \cdot 10^{-67}:\\
\;\;\;\;\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}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < 1.85e-67Initial program 77.7%
Taylor expanded in b around -inf 69.7%
mul-1-neg69.7%
*-commutative69.7%
distribute-rgt-neg-in69.7%
associate-/l*71.1%
Simplified71.1%
Taylor expanded in a around inf 71.8%
fma-define71.8%
Simplified71.8%
Taylor expanded in b around 0 68.8%
associate-*r*68.8%
*-commutative68.8%
Simplified68.8%
if 1.85e-67 < b Initial program 71.8%
Taylor expanded in b around -inf 71.8%
mul-1-neg71.8%
*-commutative71.8%
distribute-rgt-neg-in71.8%
associate-/l*71.8%
Simplified71.8%
Taylor expanded in a around inf 71.8%
fma-define71.8%
Simplified71.8%
Taylor expanded in a around 0 80.7%
distribute-lft-out--80.7%
associate-/l*84.7%
Simplified84.7%
Final simplification75.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (fma -1.0 (/ b a) (/ c b))))
(if (<= b 2.65e-67)
(if (>= b 0.0) (* c (/ 2.0 (- (- b) (sqrt (* a (* c -4.0)))))) t_0)
(if (>= b 0.0) (/ (* c 2.0) (* 2.0 (- (* a (/ c b)) b))) t_0))))
double code(double a, double b, double c) {
double t_0 = fma(-1.0, (b / a), (c / b));
double tmp_1;
if (b <= 2.65e-67) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * (2.0 / (-b - sqrt((a * (c * -4.0)))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (2.0 * ((a * (c / b)) - b));
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = fma(-1.0, Float64(b / a), Float64(c / b)) tmp_1 = 0.0 if (b <= 2.65e-67) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c * Float64(2.0 / Float64(Float64(-b) - sqrt(Float64(a * Float64(c * -4.0)))))); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(2.0 * Float64(Float64(a * Float64(c / b)) - b))); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 2.65e-67], If[GreaterEqual[b, 0.0], N[(c * N[(2.0 / N[((-b) - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\mathbf{if}\;b \leq 2.65 \cdot 10^{-67}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{2}{\left(-b\right) - \sqrt{a \cdot \left(c \cdot -4\right)}}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < 2.64999999999999986e-67Initial program 77.7%
Taylor expanded in b around -inf 69.7%
mul-1-neg69.7%
*-commutative69.7%
distribute-rgt-neg-in69.7%
associate-/l*71.1%
Simplified71.1%
Taylor expanded in a around inf 71.8%
fma-define71.8%
Simplified71.8%
Taylor expanded in b around 0 68.8%
associate-*r*68.8%
*-commutative68.8%
Simplified68.8%
*-un-lft-identity68.8%
*-commutative68.8%
Applied egg-rr68.8%
*-lft-identity68.8%
associate-/l*68.8%
associate-*r*68.8%
Simplified68.8%
if 2.64999999999999986e-67 < b Initial program 71.8%
Taylor expanded in b around -inf 71.8%
mul-1-neg71.8%
*-commutative71.8%
distribute-rgt-neg-in71.8%
associate-/l*71.8%
Simplified71.8%
Taylor expanded in a around inf 71.8%
fma-define71.8%
Simplified71.8%
Taylor expanded in a around 0 80.7%
distribute-lft-out--80.7%
associate-/l*84.7%
Simplified84.7%
Final simplification75.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* c 2.0) (* 2.0 (- (* a (/ c 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) / (2.0 * ((a * (c / 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(Float64(c * 2.0) / Float64(2.0 * Float64(Float64(a * Float64(c / 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[(N[(c * 2.0), $MachinePrecision] / N[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - 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:\\
\;\;\;\;\frac{c \cdot 2}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\end{array}
\end{array}
Initial program 75.4%
Taylor expanded in b around -inf 70.5%
mul-1-neg70.5%
*-commutative70.5%
distribute-rgt-neg-in70.5%
associate-/l*71.3%
Simplified71.3%
Taylor expanded in a around inf 71.8%
fma-define71.8%
Simplified71.8%
Taylor expanded in a around 0 67.1%
distribute-lft-out--67.1%
associate-/l*68.8%
Simplified68.8%
Final simplification68.8%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ c (- b)) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c / -b;
} else {
tmp = 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 = 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 = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c / -b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c / Float64(-b)); else tmp = Float64(b / Float64(-a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c / -b; else tmp = b / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c / (-b)), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
Initial program 75.4%
Simplified75.4%
Taylor expanded in b around inf 71.9%
Taylor expanded in b around -inf 68.3%
*-commutative68.3%
Simplified68.3%
Taylor expanded in b around 0 68.4%
associate-*r/68.4%
neg-mul-168.4%
associate-*r/68.4%
neg-mul-168.4%
Simplified68.4%
Final simplification68.4%
herbie shell --seed 2024129
(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))))