
(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 9 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 (* a (* c -4.0))))
(if (<= b -2e+152)
(/ (fma b -2.0 (/ (* a 2.0) (/ b c))) (* a 2.0))
(if (<= b 5.9e-139)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(if (<= b 3.5e-80)
(/ (- c) b)
(if (<= b 3.55e-37)
(/ (/ t_0 (+ b (hypot (sqrt t_0) b))) (* a 2.0))
(/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b)))))))))))
double code(double a, double b, double c) {
double t_0 = a * (c * -4.0);
double tmp;
if (b <= -2e+152) {
tmp = fma(b, -2.0, ((a * 2.0) / (b / c))) / (a * 2.0);
} else if (b <= 5.9e-139) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else if (b <= 3.5e-80) {
tmp = -c / b;
} else if (b <= 3.55e-37) {
tmp = (t_0 / (b + hypot(sqrt(t_0), b))) / (a * 2.0);
} else {
tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
}
return tmp;
}
function code(a, b, c) t_0 = Float64(a * Float64(c * -4.0)) tmp = 0.0 if (b <= -2e+152) tmp = Float64(fma(b, -2.0, Float64(Float64(a * 2.0) / Float64(b / c))) / Float64(a * 2.0)); elseif (b <= 5.9e-139) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); elseif (b <= 3.5e-80) tmp = Float64(Float64(-c) / b); elseif (b <= 3.55e-37) tmp = Float64(Float64(t_0 / Float64(b + hypot(sqrt(t_0), b))) / Float64(a * 2.0)); else tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b))))); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2e+152], N[(N[(b * -2.0 + N[(N[(a * 2.0), $MachinePrecision] / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.9e-139], 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, 3.5e-80], N[((-c) / b), $MachinePrecision], If[LessEqual[b, 3.55e-37], N[(N[(t$95$0 / N[(b + N[Sqrt[N[Sqrt[t$95$0], $MachinePrecision] ^ 2 + b ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(c \cdot -4\right)\\
\mathbf{if}\;b \leq -2 \cdot 10^{+152}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}{a \cdot 2}\\
\mathbf{elif}\;b \leq 5.9 \cdot 10^{-139}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 3.5 \cdot 10^{-80}:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{elif}\;b \leq 3.55 \cdot 10^{-37}:\\
\;\;\;\;\frac{\frac{t_0}{b + \mathsf{hypot}\left(\sqrt{t_0}, b\right)}}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < -2.0000000000000001e152Initial program 40.0%
*-commutative40.0%
Simplified40.0%
Taylor expanded in b around -inf 90.9%
*-commutative90.9%
fma-def90.9%
associate-/l*100.0%
associate-*r/100.0%
*-commutative100.0%
Simplified100.0%
if -2.0000000000000001e152 < b < 5.8999999999999998e-139Initial program 83.3%
if 5.8999999999999998e-139 < b < 3.50000000000000015e-80Initial program 23.4%
*-commutative23.4%
Simplified23.4%
Taylor expanded in b around inf 81.2%
mul-1-neg81.2%
distribute-neg-frac81.2%
Simplified81.2%
if 3.50000000000000015e-80 < b < 3.54999999999999989e-37Initial program 76.3%
*-commutative76.3%
Simplified76.3%
prod-diff76.3%
*-commutative76.3%
fma-def76.3%
associate-+l+76.3%
pow276.3%
distribute-lft-neg-in76.3%
*-commutative76.3%
distribute-rgt-neg-in76.3%
metadata-eval76.3%
associate-*r*76.3%
*-commutative76.3%
*-commutative76.3%
fma-udef76.3%
Applied egg-rr76.3%
fma-def76.3%
fma-def76.3%
associate-*l*76.3%
Simplified76.3%
+-commutative76.3%
add-sqr-sqrt76.1%
unpow276.1%
hypot-def76.3%
*-commutative76.3%
Applied egg-rr76.3%
+-commutative76.3%
flip-+75.4%
Applied egg-rr75.3%
Simplified98.9%
if 3.54999999999999989e-37 < b Initial program 14.1%
*-commutative14.1%
Simplified14.1%
Applied egg-rr5.3%
unpow-15.3%
associate-/r/5.3%
Applied egg-rr5.3%
div-inv5.3%
frac-2neg5.3%
metadata-eval5.3%
distribute-neg-in5.3%
add-sqr-sqrt0.0%
sqrt-unprod13.3%
sqr-neg13.3%
sqrt-prod11.7%
add-sqr-sqrt14.2%
sub-neg14.2%
Applied egg-rr14.2%
Taylor expanded in a around 0 91.5%
Final simplification88.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.15e+150)
(/ (fma b -2.0 (/ (* a 2.0) (/ b c))) (* a 2.0))
(if (<= b 2.25e-138)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b))))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.15e+150) {
tmp = fma(b, -2.0, ((a * 2.0) / (b / c))) / (a * 2.0);
} else if (b <= 2.25e-138) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.15e+150) tmp = Float64(fma(b, -2.0, Float64(Float64(a * 2.0) / Float64(b / c))) / Float64(a * 2.0)); elseif (b <= 2.25e-138) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); else tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b))))); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.15e+150], N[(N[(b * -2.0 + N[(N[(a * 2.0), $MachinePrecision] / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.25e-138], 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[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.15 \cdot 10^{+150}:\\
\;\;\;\;\frac{\mathsf{fma}\left(b, -2, \frac{a \cdot 2}{\frac{b}{c}}\right)}{a \cdot 2}\\
\mathbf{elif}\;b \leq 2.25 \cdot 10^{-138}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < -1.15000000000000001e150Initial program 40.0%
*-commutative40.0%
Simplified40.0%
Taylor expanded in b around -inf 90.9%
*-commutative90.9%
fma-def90.9%
associate-/l*100.0%
associate-*r/100.0%
*-commutative100.0%
Simplified100.0%
if -1.15000000000000001e150 < b < 2.25000000000000004e-138Initial program 83.3%
if 2.25000000000000004e-138 < b Initial program 20.2%
*-commutative20.2%
Simplified20.2%
Applied egg-rr12.2%
unpow-112.2%
associate-/r/12.2%
Applied egg-rr12.2%
div-inv12.2%
frac-2neg12.2%
metadata-eval12.2%
distribute-neg-in12.2%
add-sqr-sqrt0.0%
sqrt-unprod19.5%
sqr-neg19.5%
sqrt-prod18.1%
add-sqr-sqrt20.2%
sub-neg20.2%
Applied egg-rr20.2%
Taylor expanded in a around 0 85.6%
Final simplification86.9%
(FPCore (a b c)
:precision binary64
(if (<= b -1.52e-164)
(- (/ c b) (/ b a))
(if (<= b 2.5e-138)
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b))))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.52e-164) {
tmp = (c / b) - (b / a);
} else if (b <= 2.5e-138) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / 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.52d-164)) then
tmp = (c / b) - (b / a)
else if (b <= 2.5d-138) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = 1.0d0 / (2.0d0 * (((b / c) * (-0.5d0)) + (0.5d0 * (a / b))))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.52e-164) {
tmp = (c / b) - (b / a);
} else if (b <= 2.5e-138) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.52e-164: tmp = (c / b) - (b / a) elif b <= 2.5e-138: tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b)))) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.52e-164) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.5e-138) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - b) / Float64(a * 2.0)); else tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b))))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.52e-164) tmp = (c / b) - (b / a); elseif (b <= 2.5e-138) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b)))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.52e-164], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.5e-138], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.52 \cdot 10^{-164}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-138}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < -1.52000000000000007e-164Initial program 69.5%
*-commutative69.5%
Simplified69.5%
Taylor expanded in b around -inf 79.0%
+-commutative79.0%
mul-1-neg79.0%
unsub-neg79.0%
Simplified79.0%
if -1.52000000000000007e-164 < b < 2.49999999999999994e-138Initial program 77.9%
*-commutative77.9%
Simplified77.9%
prod-diff77.6%
*-commutative77.6%
fma-def77.6%
associate-+l+77.6%
pow277.6%
distribute-lft-neg-in77.6%
*-commutative77.6%
distribute-rgt-neg-in77.6%
metadata-eval77.6%
associate-*r*77.6%
*-commutative77.6%
*-commutative77.6%
fma-udef77.6%
Applied egg-rr77.6%
fma-def77.6%
fma-def77.7%
associate-*l*77.7%
Simplified77.7%
Taylor expanded in b around 0 77.6%
mul-1-neg77.6%
unsub-neg77.6%
distribute-rgt-out77.8%
metadata-eval77.8%
associate-*r*77.9%
*-commutative77.9%
Simplified77.9%
if 2.49999999999999994e-138 < b Initial program 20.2%
*-commutative20.2%
Simplified20.2%
Applied egg-rr12.2%
unpow-112.2%
associate-/r/12.2%
Applied egg-rr12.2%
div-inv12.2%
frac-2neg12.2%
metadata-eval12.2%
distribute-neg-in12.2%
add-sqr-sqrt0.0%
sqrt-unprod19.5%
sqr-neg19.5%
sqrt-prod18.1%
add-sqr-sqrt20.2%
sub-neg20.2%
Applied egg-rr20.2%
Taylor expanded in a around 0 85.6%
Final simplification81.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.25e-170)
(- (/ c b) (/ b a))
(if (<= b 2.5e-138)
(* 0.5 (/ (sqrt (* a (* c -4.0))) a))
(/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b))))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.25e-170) {
tmp = (c / b) - (b / a);
} else if (b <= 2.5e-138) {
tmp = 0.5 * (sqrt((a * (c * -4.0))) / a);
} else {
tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / 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 <= (-3.25d-170)) then
tmp = (c / b) - (b / a)
else if (b <= 2.5d-138) then
tmp = 0.5d0 * (sqrt((a * (c * (-4.0d0)))) / a)
else
tmp = 1.0d0 / (2.0d0 * (((b / c) * (-0.5d0)) + (0.5d0 * (a / b))))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.25e-170) {
tmp = (c / b) - (b / a);
} else if (b <= 2.5e-138) {
tmp = 0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.25e-170: tmp = (c / b) - (b / a) elif b <= 2.5e-138: tmp = 0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b)))) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.25e-170) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 2.5e-138) tmp = Float64(0.5 * Float64(sqrt(Float64(a * Float64(c * -4.0))) / a)); else tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b))))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.25e-170) tmp = (c / b) - (b / a); elseif (b <= 2.5e-138) tmp = 0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b)))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.25e-170], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.5e-138], N[(0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.25 \cdot 10^{-170}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.5 \cdot 10^{-138}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < -3.25000000000000018e-170Initial program 69.3%
*-commutative69.3%
Simplified69.3%
Taylor expanded in b around -inf 78.6%
+-commutative78.6%
mul-1-neg78.6%
unsub-neg78.6%
Simplified78.6%
if -3.25000000000000018e-170 < b < 2.49999999999999994e-138Initial program 78.6%
*-commutative78.6%
Simplified78.6%
prod-diff78.3%
*-commutative78.3%
fma-def78.3%
associate-+l+78.3%
pow278.3%
distribute-lft-neg-in78.3%
*-commutative78.3%
distribute-rgt-neg-in78.3%
metadata-eval78.3%
associate-*r*78.3%
*-commutative78.3%
*-commutative78.3%
fma-udef78.3%
Applied egg-rr78.3%
fma-def78.3%
fma-def78.4%
associate-*l*78.4%
Simplified78.4%
Taylor expanded in b around 0 78.0%
associate-*l/78.1%
*-lft-identity78.1%
distribute-rgt-out78.3%
metadata-eval78.3%
associate-*r*78.4%
*-commutative78.4%
Simplified78.4%
if 2.49999999999999994e-138 < b Initial program 20.2%
*-commutative20.2%
Simplified20.2%
Applied egg-rr12.2%
unpow-112.2%
associate-/r/12.2%
Applied egg-rr12.2%
div-inv12.2%
frac-2neg12.2%
metadata-eval12.2%
distribute-neg-in12.2%
add-sqr-sqrt0.0%
sqrt-unprod19.5%
sqr-neg19.5%
sqrt-prod18.1%
add-sqr-sqrt20.2%
sub-neg20.2%
Applied egg-rr20.2%
Taylor expanded in a around 0 85.6%
Final simplification80.9%
(FPCore (a b c) :precision binary64 (if (<= b -2.4e-290) (- (/ c b) (/ b a)) (/ 1.0 (* 2.0 (+ (* (/ b c) -0.5) (* 0.5 (/ a b)))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-290) {
tmp = (c / b) - (b / a);
} else {
tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / 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.4d-290)) then
tmp = (c / b) - (b / a)
else
tmp = 1.0d0 / (2.0d0 * (((b / c) * (-0.5d0)) + (0.5d0 * (a / b))))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2.4e-290) {
tmp = (c / b) - (b / a);
} else {
tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b))));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.4e-290: tmp = (c / b) - (b / a) else: tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b)))) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.4e-290) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(1.0 / Float64(2.0 * Float64(Float64(Float64(b / c) * -0.5) + Float64(0.5 * Float64(a / b))))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.4e-290) tmp = (c / b) - (b / a); else tmp = 1.0 / (2.0 * (((b / c) * -0.5) + (0.5 * (a / b)))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.4e-290], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[(2.0 * N[(N[(N[(b / c), $MachinePrecision] * -0.5), $MachinePrecision] + N[(0.5 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{-290}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{2 \cdot \left(\frac{b}{c} \cdot -0.5 + 0.5 \cdot \frac{a}{b}\right)}\\
\end{array}
\end{array}
if b < -2.4000000000000001e-290Initial program 71.6%
*-commutative71.6%
Simplified71.6%
Taylor expanded in b around -inf 66.1%
+-commutative66.1%
mul-1-neg66.1%
unsub-neg66.1%
Simplified66.1%
if -2.4000000000000001e-290 < b Initial program 35.0%
*-commutative35.0%
Simplified35.0%
Applied egg-rr29.2%
unpow-129.2%
associate-/r/29.2%
Applied egg-rr29.2%
div-inv29.2%
frac-2neg29.2%
metadata-eval29.2%
distribute-neg-in29.2%
add-sqr-sqrt1.7%
sqrt-unprod34.5%
sqr-neg34.5%
sqrt-prod31.8%
add-sqr-sqrt35.0%
sub-neg35.0%
Applied egg-rr35.0%
Taylor expanded in a around 0 66.2%
Final simplification66.2%
(FPCore (a b c) :precision binary64 (if (<= b -1e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-310) {
tmp = (c / b) - (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 <= (-1d-310)) then
tmp = (c / b) - (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 <= -1e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-310) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-310], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.999999999999969e-311Initial program 71.5%
*-commutative71.5%
Simplified71.5%
Taylor expanded in b around -inf 64.8%
+-commutative64.8%
mul-1-neg64.8%
unsub-neg64.8%
Simplified64.8%
if -9.999999999999969e-311 < b Initial program 34.1%
*-commutative34.1%
Simplified34.1%
Taylor expanded in b around inf 67.7%
mul-1-neg67.7%
distribute-neg-frac67.7%
Simplified67.7%
Final simplification66.1%
(FPCore (a b c) :precision binary64 (if (<= b -8e-308) (/ (- b) a) (/ 0.0 a)))
double code(double a, double b, double c) {
double tmp;
if (b <= -8e-308) {
tmp = -b / a;
} else {
tmp = 0.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) :: tmp
if (b <= (-8d-308)) then
tmp = -b / a
else
tmp = 0.0d0 / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -8e-308) {
tmp = -b / a;
} else {
tmp = 0.0 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8e-308: tmp = -b / a else: tmp = 0.0 / a return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8e-308) tmp = Float64(Float64(-b) / a); else tmp = Float64(0.0 / a); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -8e-308) tmp = -b / a; else tmp = 0.0 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8e-308], N[((-b) / a), $MachinePrecision], N[(0.0 / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -8 \cdot 10^{-308}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0}{a}\\
\end{array}
\end{array}
if b < -8.00000000000000026e-308Initial program 71.3%
*-commutative71.3%
Simplified71.3%
Taylor expanded in b around -inf 64.4%
associate-*r/64.4%
mul-1-neg64.4%
Simplified64.4%
if -8.00000000000000026e-308 < b Initial program 34.7%
*-commutative34.7%
Simplified34.7%
Applied egg-rr34.3%
fma-def29.7%
distribute-neg-frac29.7%
Simplified29.7%
Taylor expanded in a around 0 19.3%
distribute-rgt-out19.3%
metadata-eval19.3%
mul0-rgt19.3%
Simplified19.3%
Final simplification43.8%
(FPCore (a b c) :precision binary64 (if (<= b 4.7e-305) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 4.7e-305) {
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 <= 4.7d-305) 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 <= 4.7e-305) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 4.7e-305: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 4.7e-305) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 4.7e-305) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 4.7e-305], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.7 \cdot 10^{-305}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 4.6999999999999996e-305Initial program 71.7%
*-commutative71.7%
Simplified71.7%
Taylor expanded in b around -inf 63.6%
associate-*r/63.6%
mul-1-neg63.6%
Simplified63.6%
if 4.6999999999999996e-305 < b Initial program 33.6%
*-commutative33.6%
Simplified33.6%
Taylor expanded in b around inf 68.3%
mul-1-neg68.3%
distribute-neg-frac68.3%
Simplified68.3%
Final simplification65.7%
(FPCore (a b c) :precision binary64 (/ 0.0 a))
double code(double a, double b, double c) {
return 0.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 = 0.0d0 / a
end function
public static double code(double a, double b, double c) {
return 0.0 / a;
}
def code(a, b, c): return 0.0 / a
function code(a, b, c) return Float64(0.0 / a) end
function tmp = code(a, b, c) tmp = 0.0 / a; end
code[a_, b_, c_] := N[(0.0 / a), $MachinePrecision]
\begin{array}{l}
\\
\frac{0}{a}
\end{array}
Initial program 54.6%
*-commutative54.6%
Simplified54.6%
Applied egg-rr54.4%
fma-def52.3%
distribute-neg-frac52.3%
Simplified52.3%
Taylor expanded in a around 0 10.4%
distribute-rgt-out10.4%
metadata-eval10.4%
mul0-rgt10.4%
Simplified10.4%
Final simplification10.4%
herbie shell --seed 2024017
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))