
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ c (- b)))
(t_1 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))))
(if (<= b -1.5e+87)
(/ (fabs (+ b (fma -2.0 (* a (/ c b)) b))) (* a 2.0))
(if (<= b 4e-127)
t_1
(if (<= b 1e-58)
t_0
(if (<= b 1.65e-13)
t_1
(if (<= b 1.55e+35)
(*
c
(+
(*
c
(-
(* -2.0 (/ (* c (pow a 2.0)) (pow b 5.0)))
(/ a (pow b 3.0))))
(/ -1.0 b)))
t_0)))))))
double code(double a, double b, double c) {
double t_0 = c / -b;
double t_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (b <= -1.5e+87) {
tmp = fabs((b + fma(-2.0, (a * (c / b)), b))) / (a * 2.0);
} else if (b <= 4e-127) {
tmp = t_1;
} else if (b <= 1e-58) {
tmp = t_0;
} else if (b <= 1.65e-13) {
tmp = t_1;
} else if (b <= 1.55e+35) {
tmp = c * ((c * ((-2.0 * ((c * pow(a, 2.0)) / pow(b, 5.0))) - (a / pow(b, 3.0)))) + (-1.0 / b));
} else {
tmp = t_0;
}
return tmp;
}
function code(a, b, c) t_0 = Float64(c / Float64(-b)) t_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (b <= -1.5e+87) tmp = Float64(abs(Float64(b + fma(-2.0, Float64(a * Float64(c / b)), b))) / Float64(a * 2.0)); elseif (b <= 4e-127) tmp = t_1; elseif (b <= 1e-58) tmp = t_0; elseif (b <= 1.65e-13) tmp = t_1; elseif (b <= 1.55e+35) tmp = Float64(c * Float64(Float64(c * Float64(Float64(-2.0 * Float64(Float64(c * (a ^ 2.0)) / (b ^ 5.0))) - Float64(a / (b ^ 3.0)))) + Float64(-1.0 / b))); else tmp = t_0; end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(c / (-b)), $MachinePrecision]}, Block[{t$95$1 = 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, -1.5e+87], N[(N[Abs[N[(b + N[(-2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4e-127], t$95$1, If[LessEqual[b, 1e-58], t$95$0, If[LessEqual[b, 1.65e-13], t$95$1, If[LessEqual[b, 1.55e+35], N[(c * N[(N[(c * N[(N[(-2.0 * N[(N[(c * N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision] / N[Power[b, 5.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(a / N[Power[b, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-1.0 / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c}{-b}\\
t_1 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -1.5 \cdot 10^{+87}:\\
\;\;\;\;\frac{\left|b + \mathsf{fma}\left(-2, a \cdot \frac{c}{b}, b\right)\right|}{a \cdot 2}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-127}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;b \leq 10^{-58}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 1.65 \cdot 10^{-13}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{+35}:\\
\;\;\;\;c \cdot \left(c \cdot \left(-2 \cdot \frac{c \cdot {a}^{2}}{{b}^{5}} - \frac{a}{{b}^{3}}\right) + \frac{-1}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -1.4999999999999999e87Initial program 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in a around 0 1.8%
add-sqr-sqrt1.8%
sqrt-unprod2.2%
pow22.2%
add-sqr-sqrt18.1%
sqrt-unprod29.9%
sqr-neg29.9%
sqrt-unprod0.0%
add-sqr-sqrt49.1%
+-commutative49.1%
fma-define49.1%
associate-/l*49.1%
Applied egg-rr49.1%
unpow249.1%
rem-sqrt-square92.0%
Simplified92.0%
if -1.4999999999999999e87 < b < 4.0000000000000001e-127 or 1e-58 < b < 1.65e-13Initial program 83.8%
if 4.0000000000000001e-127 < b < 1e-58 or 1.54999999999999993e35 < b Initial program 17.6%
*-commutative17.6%
Simplified17.6%
Taylor expanded in b around inf 83.4%
associate-*r/83.4%
mul-1-neg83.4%
Simplified83.4%
if 1.65e-13 < b < 1.54999999999999993e35Initial program 19.5%
*-commutative19.5%
Simplified19.5%
Taylor expanded in c around 0 92.6%
Final simplification86.3%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e+87)
(/ (fabs (+ b (fma -2.0 (* a (/ c b)) b))) (* a 2.0))
(if (<= b 4e-127)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e+87) {
tmp = fabs((b + fma(-2.0, (a * (c / b)), b))) / (a * 2.0);
} else if (b <= 4e-127) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.5e+87) tmp = Float64(abs(Float64(b + fma(-2.0, Float64(a * Float64(c / b)), b))) / Float64(a * 2.0)); elseif (b <= 4e-127) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.5e+87], N[(N[Abs[N[(b + N[(-2.0 * N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 4e-127], 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], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.5 \cdot 10^{+87}:\\
\;\;\;\;\frac{\left|b + \mathsf{fma}\left(-2, a \cdot \frac{c}{b}, b\right)\right|}{a \cdot 2}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-127}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.4999999999999999e87Initial program 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in a around 0 1.8%
add-sqr-sqrt1.8%
sqrt-unprod2.2%
pow22.2%
add-sqr-sqrt18.1%
sqrt-unprod29.9%
sqr-neg29.9%
sqrt-unprod0.0%
add-sqr-sqrt49.1%
+-commutative49.1%
fma-define49.1%
associate-/l*49.1%
Applied egg-rr49.1%
unpow249.1%
rem-sqrt-square92.0%
Simplified92.0%
if -1.4999999999999999e87 < b < 4.0000000000000001e-127Initial program 84.5%
if 4.0000000000000001e-127 < b Initial program 22.4%
*-commutative22.4%
Simplified22.4%
Taylor expanded in b around inf 80.0%
associate-*r/80.0%
mul-1-neg80.0%
Simplified80.0%
Final simplification84.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.5e+87)
(/ (* 0.5 (fabs (* -2.0 (- (* a (/ c b)) b)))) a)
(if (<= b 4e-127)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e+87) {
tmp = (0.5 * fabs((-2.0 * ((a * (c / b)) - b)))) / a;
} else if (b <= 4e-127) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-1.5d+87)) then
tmp = (0.5d0 * abs(((-2.0d0) * ((a * (c / b)) - b)))) / a
else if (b <= 4d-127) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.5e+87) {
tmp = (0.5 * Math.abs((-2.0 * ((a * (c / b)) - b)))) / a;
} else if (b <= 4e-127) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.5e+87: tmp = (0.5 * math.fabs((-2.0 * ((a * (c / b)) - b)))) / a elif b <= 4e-127: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.5e+87) tmp = Float64(Float64(0.5 * abs(Float64(-2.0 * Float64(Float64(a * Float64(c / b)) - b)))) / a); elseif (b <= 4e-127) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.5e+87) tmp = (0.5 * abs((-2.0 * ((a * (c / b)) - b)))) / a; elseif (b <= 4e-127) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.5e+87], N[(N[(0.5 * N[Abs[N[(-2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 4e-127], 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], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.5 \cdot 10^{+87}:\\
\;\;\;\;\frac{0.5 \cdot \left|-2 \cdot \left(a \cdot \frac{c}{b} - b\right)\right|}{a}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-127}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -1.4999999999999999e87Initial program 49.0%
*-commutative49.0%
Simplified49.0%
Taylor expanded in a around 0 1.8%
add-sqr-sqrt1.8%
sqrt-unprod2.2%
pow22.2%
add-sqr-sqrt18.1%
sqrt-unprod29.9%
sqr-neg29.9%
sqrt-unprod0.0%
add-sqr-sqrt49.1%
+-commutative49.1%
fma-define49.1%
associate-/l*49.1%
Applied egg-rr49.1%
unpow249.1%
rem-sqrt-square92.0%
Simplified92.0%
Taylor expanded in b around 0 83.0%
associate-*r/84.1%
metadata-eval84.1%
cancel-sign-sub-inv84.1%
distribute-lft-out--84.1%
associate-*r/91.9%
Simplified91.9%
if -1.4999999999999999e87 < b < 4.0000000000000001e-127Initial program 84.5%
if 4.0000000000000001e-127 < b Initial program 22.4%
*-commutative22.4%
Simplified22.4%
Taylor expanded in b around inf 80.0%
associate-*r/80.0%
mul-1-neg80.0%
Simplified80.0%
Final simplification84.7%
(FPCore (a b c) :precision binary64 (if (<= b -2.9e-5) (/ b (- a)) (if (<= b 4e-127) (/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-5) {
tmp = b / -a;
} else if (b <= 4e-127) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2.9d-5)) then
tmp = b / -a
else if (b <= 4d-127) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.9e-5) {
tmp = b / -a;
} else if (b <= 4e-127) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.9e-5: tmp = b / -a elif b <= 4e-127: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.9e-5) tmp = Float64(b / Float64(-a)); elseif (b <= 4e-127) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.9e-5) tmp = b / -a; elseif (b <= 4e-127) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.9e-5], N[(b / (-a)), $MachinePrecision], If[LessEqual[b, 4e-127], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.9 \cdot 10^{-5}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-127}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -2.9e-5Initial program 57.5%
*-commutative57.5%
Simplified57.5%
Taylor expanded in b around -inf 87.8%
associate-*r/87.8%
mul-1-neg87.8%
Simplified87.8%
if -2.9e-5 < b < 4.0000000000000001e-127Initial program 83.3%
*-commutative83.3%
Simplified83.3%
Taylor expanded in b around 0 76.0%
*-commutative76.0%
associate-*r*76.0%
Simplified76.0%
if 4.0000000000000001e-127 < b Initial program 22.4%
*-commutative22.4%
Simplified22.4%
Taylor expanded in b around inf 80.0%
associate-*r/80.0%
mul-1-neg80.0%
Simplified80.0%
Final simplification81.5%
(FPCore (a b c) :precision binary64 (if (<= b -215000.0) (/ (* 0.5 (fabs (* -2.0 (- (* a (/ c b)) b)))) a) (if (<= b 4e-127) (/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0)) (/ c (- b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -215000.0) {
tmp = (0.5 * fabs((-2.0 * ((a * (c / b)) - b)))) / a;
} else if (b <= 4e-127) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-215000.0d0)) then
tmp = (0.5d0 * abs(((-2.0d0) * ((a * (c / b)) - b)))) / a
else if (b <= 4d-127) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -215000.0) {
tmp = (0.5 * Math.abs((-2.0 * ((a * (c / b)) - b)))) / a;
} else if (b <= 4e-127) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -215000.0: tmp = (0.5 * math.fabs((-2.0 * ((a * (c / b)) - b)))) / a elif b <= 4e-127: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -215000.0) tmp = Float64(Float64(0.5 * abs(Float64(-2.0 * Float64(Float64(a * Float64(c / b)) - b)))) / a); elseif (b <= 4e-127) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -215000.0) tmp = (0.5 * abs((-2.0 * ((a * (c / b)) - b)))) / a; elseif (b <= 4e-127) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -215000.0], N[(N[(0.5 * N[Abs[N[(-2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 4e-127], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -215000:\\
\;\;\;\;\frac{0.5 \cdot \left|-2 \cdot \left(a \cdot \frac{c}{b} - b\right)\right|}{a}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{-127}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < -215000Initial program 58.1%
*-commutative58.1%
Simplified58.1%
Taylor expanded in a around 0 1.9%
add-sqr-sqrt1.8%
sqrt-unprod2.3%
pow22.3%
add-sqr-sqrt15.4%
sqrt-unprod24.5%
sqr-neg24.5%
sqrt-unprod0.0%
add-sqr-sqrt54.9%
+-commutative54.9%
fma-define54.9%
associate-/l*54.9%
Applied egg-rr54.9%
unpow254.9%
rem-sqrt-square89.1%
Simplified89.1%
Taylor expanded in b around 0 82.0%
associate-*r/82.9%
metadata-eval82.9%
cancel-sign-sub-inv82.9%
distribute-lft-out--82.9%
associate-*r/89.1%
Simplified89.1%
if -215000 < b < 4.0000000000000001e-127Initial program 82.2%
*-commutative82.2%
Simplified82.2%
Taylor expanded in b around 0 75.0%
*-commutative75.0%
associate-*r*75.0%
Simplified75.0%
if 4.0000000000000001e-127 < b Initial program 22.4%
*-commutative22.4%
Simplified22.4%
Taylor expanded in b around inf 80.0%
associate-*r/80.0%
mul-1-neg80.0%
Simplified80.0%
Final simplification81.6%
(FPCore (a b c) :precision binary64 (if (<= b 2.1e-295) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b <= 2.1e-295) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= 2.1d-295) then
tmp = b / -a
else
tmp = c / -b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= 2.1e-295) {
tmp = b / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2.1e-295: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2.1e-295) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2.1e-295) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2.1e-295], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.1 \cdot 10^{-295}:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
if b < 2.09999999999999993e-295Initial program 67.0%
*-commutative67.0%
Simplified67.0%
Taylor expanded in b around -inf 66.7%
associate-*r/66.7%
mul-1-neg66.7%
Simplified66.7%
if 2.09999999999999993e-295 < b Initial program 34.9%
*-commutative34.9%
Simplified34.9%
Taylor expanded in b around inf 65.1%
associate-*r/65.1%
mul-1-neg65.1%
Simplified65.1%
Final simplification65.9%
(FPCore (a b c) :precision binary64 (/ b (- a)))
double code(double a, double b, double c) {
return b / -a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / -a
end function
public static double code(double a, double b, double c) {
return b / -a;
}
def code(a, b, c): return b / -a
function code(a, b, c) return Float64(b / Float64(-a)) end
function tmp = code(a, b, c) tmp = b / -a; end
code[a_, b_, c_] := N[(b / (-a)), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{-a}
\end{array}
Initial program 50.5%
*-commutative50.5%
Simplified50.5%
Taylor expanded in b around -inf 33.6%
associate-*r/33.6%
mul-1-neg33.6%
Simplified33.6%
Final simplification33.6%
(FPCore (a b c) :precision binary64 (/ b a))
double code(double a, double b, double c) {
return b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / a
end function
public static double code(double a, double b, double c) {
return b / a;
}
def code(a, b, c): return b / a
function code(a, b, c) return Float64(b / a) end
function tmp = code(a, b, c) tmp = b / a; end
code[a_, b_, c_] := N[(b / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{a}
\end{array}
Initial program 50.5%
*-commutative50.5%
Simplified50.5%
sub-neg50.5%
fma-undefine50.5%
add-sqr-sqrt41.7%
hypot-define52.4%
*-commutative52.4%
associate-*r*52.4%
*-commutative52.4%
add-sqr-sqrt29.8%
sqrt-unprod40.1%
sqr-neg40.1%
sqrt-prod15.8%
add-sqr-sqrt27.9%
Applied egg-rr27.9%
Taylor expanded in b around inf 2.7%
Final simplification2.7%
herbie shell --seed 2024095
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))