
(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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 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(4.0 * Float64(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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(if (<= b -3.5e+43)
(/ (- b) a)
(if (<= b -8.2e-248)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(if (<= b 1.35e-7)
(/ (* c -2.0) (+ b (hypot b (sqrt (* c (* a -4.0))))))
(/ (- c) b)))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e+43) {
tmp = -b / a;
} else if (b <= -8.2e-248) {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else if (b <= 1.35e-7) {
tmp = (c * -2.0) / (b + hypot(b, sqrt((c * (a * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
public static double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e+43) {
tmp = -b / a;
} else if (b <= -8.2e-248) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else if (b <= 1.35e-7) {
tmp = (c * -2.0) / (b + Math.hypot(b, Math.sqrt((c * (a * -4.0)))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.5e+43: tmp = -b / a elif b <= -8.2e-248: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) elif b <= 1.35e-7: tmp = (c * -2.0) / (b + math.hypot(b, math.sqrt((c * (a * -4.0))))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.5e+43) tmp = Float64(Float64(-b) / a); elseif (b <= -8.2e-248) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); elseif (b <= 1.35e-7) tmp = Float64(Float64(c * -2.0) / Float64(b + hypot(b, sqrt(Float64(c * Float64(a * -4.0)))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.5e+43) tmp = -b / a; elseif (b <= -8.2e-248) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); elseif (b <= 1.35e-7) tmp = (c * -2.0) / (b + hypot(b, sqrt((c * (a * -4.0))))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.5e+43], N[((-b) / a), $MachinePrecision], If[LessEqual[b, -8.2e-248], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e-7], N[(N[(c * -2.0), $MachinePrecision] / N[(b + N[Sqrt[b ^ 2 + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3.5 \cdot 10^{+43}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq -8.2 \cdot 10^{-248}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{-7}:\\
\;\;\;\;\frac{c \cdot -2}{b + \mathsf{hypot}\left(b, \sqrt{c \cdot \left(a \cdot -4\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.5000000000000001e43Initial program 61.5%
neg-sub061.5%
associate-+l-61.5%
sub0-neg61.5%
neg-mul-161.5%
*-commutative61.5%
associate-*r/61.2%
Simplified61.5%
Taylor expanded in b around -inf 95.3%
associate-*r/95.3%
mul-1-neg95.3%
Simplified95.3%
if -3.5000000000000001e43 < b < -8.20000000000000067e-248Initial program 83.7%
if -8.20000000000000067e-248 < b < 1.35000000000000004e-7Initial program 60.4%
neg-sub060.4%
associate-+l-60.4%
sub0-neg60.4%
neg-mul-160.4%
*-commutative60.4%
associate-*r/60.4%
Simplified60.4%
fma-udef60.4%
associate-*r*60.4%
metadata-eval60.4%
distribute-rgt-neg-in60.4%
*-commutative60.4%
+-commutative60.4%
sub-neg60.4%
*-commutative60.4%
associate-*l*60.4%
Applied egg-rr60.4%
flip--60.3%
add-sqr-sqrt60.3%
Applied egg-rr60.3%
sub-neg60.3%
associate--r+73.6%
+-inverses73.6%
neg-sub073.6%
remove-double-neg73.6%
associate-*r*73.5%
*-commutative73.5%
associate-*l*73.6%
sub-neg73.6%
rem-square-sqrt70.3%
distribute-rgt-neg-in70.3%
distribute-rgt-neg-in70.3%
metadata-eval70.3%
distribute-rgt-neg-in70.3%
distribute-rgt-neg-in70.3%
metadata-eval70.3%
Simplified70.4%
associate-*l/70.3%
Applied egg-rr70.3%
Taylor expanded in c around 0 85.6%
if 1.35000000000000004e-7 < b Initial program 14.3%
neg-sub014.3%
associate-+l-14.3%
sub0-neg14.3%
neg-mul-114.3%
*-commutative14.3%
associate-*r/14.3%
Simplified14.3%
Taylor expanded in b around inf 90.2%
associate-*r/90.2%
neg-mul-190.2%
Simplified90.2%
Final simplification89.0%
(FPCore (a b c)
:precision binary64
(if (<= b -1.35e+42)
(/ (- b) a)
(if (<= b 1.25e-137)
(* (- b (sqrt (- (* b b) (* a (* 4.0 c))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e+42) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
tmp = (b - sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / 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 <= (-1.35d+42)) then
tmp = -b / a
else if (b <= 1.25d-137) then
tmp = (b - sqrt(((b * b) - (a * (4.0d0 * c))))) * ((-0.5d0) / 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 <= -1.35e+42) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
tmp = (b - Math.sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e+42: tmp = -b / a elif b <= 1.25e-137: tmp = (b - math.sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e+42) tmp = Float64(Float64(-b) / a); elseif (b <= 1.25e-137) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(4.0 * c))))) * Float64(-0.5 / a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.35e+42) tmp = -b / a; elseif (b <= 1.25e-137) tmp = (b - sqrt(((b * b) - (a * (4.0 * c))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e+42], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.25e-137], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(4.0 * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{+42}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-137}:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(4 \cdot c\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.35e42Initial program 62.7%
neg-sub062.7%
associate-+l-62.7%
sub0-neg62.7%
neg-mul-162.7%
*-commutative62.7%
associate-*r/62.5%
Simplified62.7%
Taylor expanded in b around -inf 95.4%
associate-*r/95.4%
mul-1-neg95.4%
Simplified95.4%
if -1.35e42 < b < 1.25e-137Initial program 81.9%
neg-sub081.9%
associate-+l-81.9%
sub0-neg81.9%
neg-mul-181.9%
*-commutative81.9%
associate-*r/81.7%
Simplified81.7%
fma-udef81.7%
associate-*r*81.7%
metadata-eval81.7%
distribute-rgt-neg-in81.7%
*-commutative81.7%
+-commutative81.7%
sub-neg81.7%
*-commutative81.7%
associate-*l*81.7%
Applied egg-rr81.7%
if 1.25e-137 < b Initial program 19.1%
neg-sub019.1%
associate-+l-19.1%
sub0-neg19.1%
neg-mul-119.1%
*-commutative19.1%
associate-*r/19.1%
Simplified19.1%
Taylor expanded in b around inf 83.9%
associate-*r/83.9%
neg-mul-183.9%
Simplified83.9%
Final simplification86.0%
(FPCore (a b c)
:precision binary64
(if (<= b -3.5e+43)
(/ (- b) a)
(if (<= b 1.25e-137)
(/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3.5e+43) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - 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 <= (-3.5d+43)) then
tmp = -b / a
else if (b <= 1.25d-137) then
tmp = (sqrt(((b * b) - (4.0d0 * (a * c)))) - 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 <= -3.5e+43) {
tmp = -b / a;
} else if (b <= 1.25e-137) {
tmp = (Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3.5e+43: tmp = -b / a elif b <= 1.25e-137: tmp = (math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3.5e+43) tmp = Float64(Float64(-b) / a); elseif (b <= 1.25e-137) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -3.5e+43) tmp = -b / a; elseif (b <= 1.25e-137) tmp = (sqrt(((b * b) - (4.0 * (a * c)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3.5e+43], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 1.25e-137], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $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 -3.5 \cdot 10^{+43}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 1.25 \cdot 10^{-137}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.5000000000000001e43Initial program 61.5%
neg-sub061.5%
associate-+l-61.5%
sub0-neg61.5%
neg-mul-161.5%
*-commutative61.5%
associate-*r/61.2%
Simplified61.5%
Taylor expanded in b around -inf 95.3%
associate-*r/95.3%
mul-1-neg95.3%
Simplified95.3%
if -3.5000000000000001e43 < b < 1.25e-137Initial program 82.3%
if 1.25e-137 < b Initial program 19.1%
neg-sub019.1%
associate-+l-19.1%
sub0-neg19.1%
neg-mul-119.1%
*-commutative19.1%
associate-*r/19.1%
Simplified19.1%
Taylor expanded in b around inf 83.9%
associate-*r/83.9%
neg-mul-183.9%
Simplified83.9%
Final simplification86.0%
(FPCore (a b c)
:precision binary64
(if (<= b -2.1e-39)
(/ (- b) a)
(if (<= b 3.7e-141)
(* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2.1e-39) {
tmp = -b / a;
} else if (b <= 3.7e-141) {
tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.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.1d-39)) then
tmp = -b / a
else if (b <= 3.7d-141) then
tmp = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.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.1e-39) {
tmp = -b / a;
} else if (b <= 3.7e-141) {
tmp = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2.1e-39: tmp = -b / a elif b <= 3.7e-141: tmp = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2.1e-39) tmp = Float64(Float64(-b) / a); elseif (b <= 3.7e-141) tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -2.1e-39) tmp = -b / a; elseif (b <= 3.7e-141) tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2.1e-39], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 3.7e-141], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.1 \cdot 10^{-39}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 3.7 \cdot 10^{-141}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.09999999999999993e-39Initial program 67.4%
neg-sub067.4%
associate-+l-67.4%
sub0-neg67.4%
neg-mul-167.4%
*-commutative67.4%
associate-*r/67.2%
Simplified67.4%
Taylor expanded in b around -inf 91.1%
associate-*r/91.1%
mul-1-neg91.1%
Simplified91.1%
if -2.09999999999999993e-39 < b < 3.7e-141Initial program 80.2%
neg-sub080.2%
associate-+l-80.2%
sub0-neg80.2%
neg-mul-180.2%
*-commutative80.2%
associate-*r/80.0%
Simplified80.1%
Taylor expanded in a around inf 73.0%
*-commutative73.0%
*-commutative73.0%
associate-*r*73.0%
Simplified73.0%
if 3.7e-141 < b Initial program 19.1%
neg-sub019.1%
associate-+l-19.1%
sub0-neg19.1%
neg-mul-119.1%
*-commutative19.1%
associate-*r/19.1%
Simplified19.1%
Taylor expanded in b around inf 83.9%
associate-*r/83.9%
neg-mul-183.9%
Simplified83.9%
Final simplification82.9%
(FPCore (a b c)
:precision binary64
(if (<= b -6e-40)
(/ (- b) a)
(if (<= b 2.3e-139)
(/ (* -0.5 (- b (sqrt (* a (* c -4.0))))) a)
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6e-40) {
tmp = -b / a;
} else if (b <= 2.3e-139) {
tmp = (-0.5 * (b - sqrt((a * (c * -4.0))))) / 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 <= (-6d-40)) then
tmp = -b / a
else if (b <= 2.3d-139) then
tmp = ((-0.5d0) * (b - sqrt((a * (c * (-4.0d0)))))) / 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 <= -6e-40) {
tmp = -b / a;
} else if (b <= 2.3e-139) {
tmp = (-0.5 * (b - Math.sqrt((a * (c * -4.0))))) / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6e-40: tmp = -b / a elif b <= 2.3e-139: tmp = (-0.5 * (b - math.sqrt((a * (c * -4.0))))) / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6e-40) tmp = Float64(Float64(-b) / a); elseif (b <= 2.3e-139) tmp = Float64(Float64(-0.5 * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))) / a); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -6e-40) tmp = -b / a; elseif (b <= 2.3e-139) tmp = (-0.5 * (b - sqrt((a * (c * -4.0))))) / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6e-40], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 2.3e-139], N[(N[(-0.5 * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6 \cdot 10^{-40}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{-139}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -6.00000000000000039e-40Initial program 67.4%
neg-sub067.4%
associate-+l-67.4%
sub0-neg67.4%
neg-mul-167.4%
*-commutative67.4%
associate-*r/67.2%
Simplified67.4%
Taylor expanded in b around -inf 91.1%
associate-*r/91.1%
mul-1-neg91.1%
Simplified91.1%
if -6.00000000000000039e-40 < b < 2.30000000000000012e-139Initial program 80.2%
neg-sub080.2%
associate-+l-80.2%
sub0-neg80.2%
neg-mul-180.2%
*-commutative80.2%
associate-*r/80.0%
Simplified80.1%
Taylor expanded in a around inf 73.0%
*-commutative73.0%
*-commutative73.0%
associate-*r*73.0%
Simplified73.0%
associate-*r/73.1%
Applied egg-rr73.1%
if 2.30000000000000012e-139 < b Initial program 19.1%
neg-sub019.1%
associate-+l-19.1%
sub0-neg19.1%
neg-mul-119.1%
*-commutative19.1%
associate-*r/19.1%
Simplified19.1%
Taylor expanded in b around inf 83.9%
associate-*r/83.9%
neg-mul-183.9%
Simplified83.9%
Final simplification82.9%
(FPCore (a b c) :precision binary64 (if (<= b 1e-309) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1e-309) {
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 <= 1d-309) 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 <= 1e-309) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1e-309: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1e-309) 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 <= 1e-309) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1e-309], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 1.000000000000002e-309Initial program 73.0%
neg-sub073.0%
associate-+l-73.0%
sub0-neg73.0%
neg-mul-173.0%
*-commutative73.0%
associate-*r/72.8%
Simplified72.9%
Taylor expanded in b around -inf 63.2%
associate-*r/63.2%
mul-1-neg63.2%
Simplified63.2%
if 1.000000000000002e-309 < b Initial program 29.8%
neg-sub029.8%
associate-+l-29.8%
sub0-neg29.8%
neg-mul-129.8%
*-commutative29.8%
associate-*r/29.8%
Simplified29.8%
Taylor expanded in b around inf 70.6%
associate-*r/70.6%
neg-mul-170.6%
Simplified70.6%
Final simplification67.2%
(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(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.3%
neg-sub050.3%
associate-+l-50.3%
sub0-neg50.3%
neg-mul-150.3%
*-commutative50.3%
associate-*r/50.1%
Simplified50.2%
Taylor expanded in b around -inf 31.4%
associate-*r/31.4%
mul-1-neg31.4%
Simplified31.4%
Final simplification31.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))))
(if (< b 0.0)
(/ (+ (- b) t_0) (* 2.0 a))
(/ c (* a (/ (- (- 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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0d0 * a)
else
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a);
} else {
tmp = c / (a * ((-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 = (-b + t_0) / (2.0 * a) else: tmp = c / (a * ((-b - t_0) / (2.0 * a))) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) tmp = 0.0 if (b < 0.0) tmp = Float64(Float64(Float64(-b) + t_0) / Float64(2.0 * a)); else tmp = Float64(c / Float64(a * 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 = (-b + t_0) / (2.0 * a); else tmp = c / (a * ((-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[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Less[b, 0.0], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(c / N[(a * N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
\mathbf{if}\;b < 0:\\
\;\;\;\;\frac{\left(-b\right) + t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{a \cdot \frac{\left(-b\right) - t_0}{2 \cdot a}}\\
\end{array}
\end{array}
herbie shell --seed 2023257
(FPCore (a b c)
:name "quadp (p42, positive)"
:precision binary64
:herbie-target
(if (< b 0.0) (/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)) (/ c (* a (/ (- (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))))
(/ (+ (- b) (sqrt (- (* b b) (* 4.0 (* a c))))) (* 2.0 a)))