
(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
(if (<= b -5e+153)
(/ (* (+ b (- b (* 2.0 (/ c (/ b a))))) -0.5) a)
(if (<= b 2.8e-65)
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))
(- (/ (- c) b) (/ c (/ (/ (pow b 3.0) a) c))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+153) {
tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a;
} else if (b <= 2.8e-65) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
} else {
tmp = (-c / b) - (c / ((pow(b, 3.0) / a) / c));
}
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 <= (-5d+153)) then
tmp = ((b + (b - (2.0d0 * (c / (b / a))))) * (-0.5d0)) / a
else if (b <= 2.8d-65) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (2.0d0 * a)
else
tmp = (-c / b) - (c / (((b ** 3.0d0) / a) / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -5e+153) {
tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a;
} else if (b <= 2.8e-65) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
} else {
tmp = (-c / b) - (c / ((Math.pow(b, 3.0) / a) / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e+153: tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a elif b <= 2.8e-65: tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a) else: tmp = (-c / b) - (c / ((math.pow(b, 3.0) / a) / c)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e+153) tmp = Float64(Float64(Float64(b + Float64(b - Float64(2.0 * Float64(c / Float64(b / a))))) * -0.5) / a); elseif (b <= 2.8e-65) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(c / Float64(Float64((b ^ 3.0) / a) / c))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -5e+153) tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a; elseif (b <= 2.8e-65) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a); else tmp = (-c / b) - (c / (((b ^ 3.0) / a) / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e+153], N[(N[(N[(b + N[(b - N[(2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 2.8e-65], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(c / N[(N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+153}:\\
\;\;\;\;\frac{\left(b + \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)\right) \cdot -0.5}{a}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{-65}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}\\
\end{array}
\end{array}
if b < -5.00000000000000018e153Initial program 26.4%
neg-sub026.4%
associate-+l-26.4%
sub0-neg26.4%
neg-mul-126.4%
associate-*l/26.4%
*-commutative26.4%
associate-/r*26.4%
/-rgt-identity26.4%
metadata-eval26.4%
Simplified26.7%
Taylor expanded in b around -inf 80.2%
neg-mul-180.2%
unsub-neg80.2%
*-commutative80.2%
associate-/l*97.4%
associate-/r/97.4%
Simplified97.4%
associate-*r/97.7%
associate--r-97.7%
*-commutative97.7%
associate-*l/80.4%
associate-/l*97.7%
Applied egg-rr97.7%
if -5.00000000000000018e153 < b < 2.8e-65Initial program 83.0%
if 2.8e-65 < b Initial program 13.8%
neg-sub013.8%
associate-+l-13.8%
sub0-neg13.8%
neg-mul-113.8%
associate-*l/13.8%
*-commutative13.8%
associate-/r*13.8%
/-rgt-identity13.8%
metadata-eval13.8%
Simplified13.9%
Taylor expanded in b around inf 77.5%
+-commutative77.5%
mul-1-neg77.5%
unsub-neg77.5%
associate-*r/77.5%
neg-mul-177.5%
associate-/l*80.7%
unpow280.7%
associate-/l*93.4%
Simplified93.4%
Final simplification89.1%
(FPCore (a b c)
:precision binary64
(if (<= b -4.6e+83)
(/ (* (+ b (- b (* 2.0 (/ c (/ b a))))) -0.5) a)
(if (<= b 6.6e-67)
(* (- (sqrt (+ (* b b) (* a (* c -4.0)))) b) (/ 0.5 a))
(- (/ (- c) b) (/ c (/ (/ (pow b 3.0) a) c))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e+83) {
tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a;
} else if (b <= 6.6e-67) {
tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
} else {
tmp = (-c / b) - (c / ((pow(b, 3.0) / a) / c));
}
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.6d+83)) then
tmp = ((b + (b - (2.0d0 * (c / (b / a))))) * (-0.5d0)) / a
else if (b <= 6.6d-67) then
tmp = (sqrt(((b * b) + (a * (c * (-4.0d0))))) - b) * (0.5d0 / a)
else
tmp = (-c / b) - (c / (((b ** 3.0d0) / a) / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.6e+83) {
tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a;
} else if (b <= 6.6e-67) {
tmp = (Math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a);
} else {
tmp = (-c / b) - (c / ((Math.pow(b, 3.0) / a) / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.6e+83: tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a elif b <= 6.6e-67: tmp = (math.sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a) else: tmp = (-c / b) - (c / ((math.pow(b, 3.0) / a) / c)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.6e+83) tmp = Float64(Float64(Float64(b + Float64(b - Float64(2.0 * Float64(c / Float64(b / a))))) * -0.5) / a); elseif (b <= 6.6e-67) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) + Float64(a * Float64(c * -4.0)))) - b) * Float64(0.5 / a)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(c / Float64(Float64((b ^ 3.0) / a) / c))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.6e+83) tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a; elseif (b <= 6.6e-67) tmp = (sqrt(((b * b) + (a * (c * -4.0)))) - b) * (0.5 / a); else tmp = (-c / b) - (c / (((b ^ 3.0) / a) / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.6e+83], N[(N[(N[(b + N[(b - N[(2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 6.6e-67], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] + N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] * N[(0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(c / N[(N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.6 \cdot 10^{+83}:\\
\;\;\;\;\frac{\left(b + \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)\right) \cdot -0.5}{a}\\
\mathbf{elif}\;b \leq 6.6 \cdot 10^{-67}:\\
\;\;\;\;\left(\sqrt{b \cdot b + a \cdot \left(c \cdot -4\right)} - b\right) \cdot \frac{0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}\\
\end{array}
\end{array}
if b < -4.5999999999999999e83Initial program 45.5%
neg-sub045.5%
associate-+l-45.5%
sub0-neg45.5%
neg-mul-145.5%
associate-*l/45.4%
*-commutative45.4%
associate-/r*45.4%
/-rgt-identity45.4%
metadata-eval45.4%
Simplified45.6%
Taylor expanded in b around -inf 85.2%
neg-mul-185.2%
unsub-neg85.2%
*-commutative85.2%
associate-/l*98.0%
associate-/r/98.0%
Simplified98.0%
associate-*r/98.3%
associate--r-98.3%
*-commutative98.3%
associate-*l/85.5%
associate-/l*98.3%
Applied egg-rr98.3%
if -4.5999999999999999e83 < b < 6.6000000000000003e-67Initial program 80.8%
/-rgt-identity80.8%
metadata-eval80.8%
associate-/l*80.8%
associate-*r/80.6%
+-commutative80.6%
unsub-neg80.6%
fma-neg80.6%
associate-*l*80.6%
*-commutative80.6%
distribute-rgt-neg-in80.6%
metadata-eval80.6%
associate-/r*80.6%
metadata-eval80.6%
metadata-eval80.6%
Simplified80.6%
fma-udef80.6%
associate-*l*79.7%
Applied egg-rr79.7%
if 6.6000000000000003e-67 < b Initial program 13.8%
neg-sub013.8%
associate-+l-13.8%
sub0-neg13.8%
neg-mul-113.8%
associate-*l/13.8%
*-commutative13.8%
associate-/r*13.8%
/-rgt-identity13.8%
metadata-eval13.8%
Simplified13.9%
Taylor expanded in b around inf 77.5%
+-commutative77.5%
mul-1-neg77.5%
unsub-neg77.5%
associate-*r/77.5%
neg-mul-177.5%
associate-/l*80.7%
unpow280.7%
associate-/l*93.4%
Simplified93.4%
Final simplification88.7%
(FPCore (a b c)
:precision binary64
(if (<= b -1.35e-57)
(/ (* (+ b (- b (* 2.0 (/ c (/ b a))))) -0.5) a)
(if (<= b 1.32e-68)
(* (- b (sqrt (* c (* a -4.0)))) (/ -0.5 a))
(- (/ (- c) b) (/ c (/ (/ (pow b 3.0) a) c))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e-57) {
tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a;
} else if (b <= 1.32e-68) {
tmp = (b - sqrt((c * (a * -4.0)))) * (-0.5 / a);
} else {
tmp = (-c / b) - (c / ((pow(b, 3.0) / a) / c));
}
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-57)) then
tmp = ((b + (b - (2.0d0 * (c / (b / a))))) * (-0.5d0)) / a
else if (b <= 1.32d-68) then
tmp = (b - sqrt((c * (a * (-4.0d0))))) * ((-0.5d0) / a)
else
tmp = (-c / b) - (c / (((b ** 3.0d0) / a) / c))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -1.35e-57) {
tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a;
} else if (b <= 1.32e-68) {
tmp = (b - Math.sqrt((c * (a * -4.0)))) * (-0.5 / a);
} else {
tmp = (-c / b) - (c / ((Math.pow(b, 3.0) / a) / c));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.35e-57: tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a elif b <= 1.32e-68: tmp = (b - math.sqrt((c * (a * -4.0)))) * (-0.5 / a) else: tmp = (-c / b) - (c / ((math.pow(b, 3.0) / a) / c)) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.35e-57) tmp = Float64(Float64(Float64(b + Float64(b - Float64(2.0 * Float64(c / Float64(b / a))))) * -0.5) / a); elseif (b <= 1.32e-68) tmp = Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) * Float64(-0.5 / a)); else tmp = Float64(Float64(Float64(-c) / b) - Float64(c / Float64(Float64((b ^ 3.0) / a) / c))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.35e-57) tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a; elseif (b <= 1.32e-68) tmp = (b - sqrt((c * (a * -4.0)))) * (-0.5 / a); else tmp = (-c / b) - (c / (((b ^ 3.0) / a) / c)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.35e-57], N[(N[(N[(b + N[(b - N[(2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 1.32e-68], N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[(N[((-c) / b), $MachinePrecision] - N[(c / N[(N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.35 \cdot 10^{-57}:\\
\;\;\;\;\frac{\left(b + \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)\right) \cdot -0.5}{a}\\
\mathbf{elif}\;b \leq 1.32 \cdot 10^{-68}:\\
\;\;\;\;\left(b - \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b} - \frac{c}{\frac{\frac{{b}^{3}}{a}}{c}}\\
\end{array}
\end{array}
if b < -1.3500000000000001e-57Initial program 64.2%
neg-sub064.2%
associate-+l-64.2%
sub0-neg64.2%
neg-mul-164.2%
associate-*l/64.0%
*-commutative64.0%
associate-/r*64.0%
/-rgt-identity64.0%
metadata-eval64.0%
Simplified64.2%
Taylor expanded in b around -inf 83.6%
neg-mul-183.6%
unsub-neg83.6%
*-commutative83.6%
associate-/l*91.7%
associate-/r/91.7%
Simplified91.7%
associate-*r/92.0%
associate--r-92.0%
*-commutative92.0%
associate-*l/83.9%
associate-/l*92.0%
Applied egg-rr92.0%
if -1.3500000000000001e-57 < b < 1.32e-68Initial program 74.3%
neg-sub074.3%
associate-+l-74.3%
sub0-neg74.3%
neg-mul-174.3%
associate-*l/74.2%
*-commutative74.2%
associate-/r*74.2%
/-rgt-identity74.2%
metadata-eval74.2%
Simplified73.0%
Taylor expanded in a around inf 72.6%
*-commutative72.6%
associate-*r*72.6%
Simplified72.6%
if 1.32e-68 < b Initial program 13.8%
neg-sub013.8%
associate-+l-13.8%
sub0-neg13.8%
neg-mul-113.8%
associate-*l/13.8%
*-commutative13.8%
associate-/r*13.8%
/-rgt-identity13.8%
metadata-eval13.8%
Simplified13.9%
Taylor expanded in b around inf 77.5%
+-commutative77.5%
mul-1-neg77.5%
unsub-neg77.5%
associate-*r/77.5%
neg-mul-177.5%
associate-/l*80.7%
unpow280.7%
associate-/l*93.4%
Simplified93.4%
Final simplification86.7%
(FPCore (a b c)
:precision binary64
(if (<= b -3e-56)
(/ (* (+ b (- b (* 2.0 (/ c (/ b a))))) -0.5) a)
(if (<= b 1.55e-94)
(* (- b (sqrt (* c (* a -4.0)))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -3e-56) {
tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a;
} else if (b <= 1.55e-94) {
tmp = (b - sqrt((c * (a * -4.0)))) * (-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 <= (-3d-56)) then
tmp = ((b + (b - (2.0d0 * (c / (b / a))))) * (-0.5d0)) / a
else if (b <= 1.55d-94) then
tmp = (b - sqrt((c * (a * (-4.0d0))))) * ((-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 <= -3e-56) {
tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a;
} else if (b <= 1.55e-94) {
tmp = (b - Math.sqrt((c * (a * -4.0)))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -3e-56: tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a elif b <= 1.55e-94: tmp = (b - math.sqrt((c * (a * -4.0)))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -3e-56) tmp = Float64(Float64(Float64(b + Float64(b - Float64(2.0 * Float64(c / Float64(b / a))))) * -0.5) / a); elseif (b <= 1.55e-94) tmp = Float64(Float64(b - sqrt(Float64(c * Float64(a * -4.0)))) * 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 <= -3e-56) tmp = ((b + (b - (2.0 * (c / (b / a))))) * -0.5) / a; elseif (b <= 1.55e-94) tmp = (b - sqrt((c * (a * -4.0)))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -3e-56], N[(N[(N[(b + N[(b - N[(2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision] / a), $MachinePrecision], If[LessEqual[b, 1.55e-94], N[(N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -3 \cdot 10^{-56}:\\
\;\;\;\;\frac{\left(b + \left(b - 2 \cdot \frac{c}{\frac{b}{a}}\right)\right) \cdot -0.5}{a}\\
\mathbf{elif}\;b \leq 1.55 \cdot 10^{-94}:\\
\;\;\;\;\left(b - \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -2.99999999999999989e-56Initial program 64.2%
neg-sub064.2%
associate-+l-64.2%
sub0-neg64.2%
neg-mul-164.2%
associate-*l/64.0%
*-commutative64.0%
associate-/r*64.0%
/-rgt-identity64.0%
metadata-eval64.0%
Simplified64.2%
Taylor expanded in b around -inf 83.6%
neg-mul-183.6%
unsub-neg83.6%
*-commutative83.6%
associate-/l*91.7%
associate-/r/91.7%
Simplified91.7%
associate-*r/92.0%
associate--r-92.0%
*-commutative92.0%
associate-*l/83.9%
associate-/l*92.0%
Applied egg-rr92.0%
if -2.99999999999999989e-56 < b < 1.5499999999999999e-94Initial program 75.5%
neg-sub075.5%
associate-+l-75.5%
sub0-neg75.5%
neg-mul-175.5%
associate-*l/75.4%
*-commutative75.4%
associate-/r*75.4%
/-rgt-identity75.4%
metadata-eval75.4%
Simplified74.1%
Taylor expanded in a around inf 73.8%
*-commutative73.8%
associate-*r*73.8%
Simplified73.8%
if 1.5499999999999999e-94 < b Initial program 15.4%
neg-sub015.4%
associate-+l-15.4%
sub0-neg15.4%
neg-mul-115.4%
associate-*l/15.4%
*-commutative15.4%
associate-/r*15.4%
/-rgt-identity15.4%
metadata-eval15.4%
Simplified15.4%
Taylor expanded in b around inf 91.3%
associate-*r/91.3%
neg-mul-191.3%
Simplified91.3%
Final simplification86.6%
(FPCore (a b c) :precision binary64 (if (<= b -2e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e-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 <= (-2d-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 <= -2e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e-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 <= -2e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e-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 -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.999999999999994e-310Initial program 68.1%
neg-sub068.1%
associate-+l-68.1%
sub0-neg68.1%
neg-mul-168.1%
associate-*l/67.9%
*-commutative67.9%
associate-/r*67.9%
/-rgt-identity67.9%
metadata-eval67.9%
Simplified68.0%
Taylor expanded in b around -inf 65.5%
mul-1-neg65.5%
unsub-neg65.5%
Simplified65.5%
if -1.999999999999994e-310 < b Initial program 30.3%
neg-sub030.3%
associate-+l-30.3%
sub0-neg30.3%
neg-mul-130.3%
associate-*l/30.2%
*-commutative30.2%
associate-/r*30.2%
/-rgt-identity30.2%
metadata-eval30.2%
Simplified29.5%
Taylor expanded in b around inf 73.1%
associate-*r/73.1%
neg-mul-173.1%
Simplified73.1%
Final simplification69.4%
(FPCore (a b c) :precision binary64 (if (<= b 2400000.0) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 2400000.0) {
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 <= 2400000.0d0) 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 <= 2400000.0) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 2400000.0: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 2400000.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= 2400000.0) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 2400000.0], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2400000:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
if b < 2.4e6Initial program 65.3%
neg-sub065.3%
associate-+l-65.3%
sub0-neg65.3%
neg-mul-165.3%
associate-*l/65.1%
*-commutative65.1%
associate-/r*65.1%
/-rgt-identity65.1%
metadata-eval65.1%
Simplified64.7%
Taylor expanded in b around -inf 47.2%
associate-*r/47.2%
neg-mul-147.2%
Simplified47.2%
if 2.4e6 < b Initial program 13.1%
neg-sub013.1%
associate-+l-13.1%
sub0-neg13.1%
neg-mul-113.1%
associate-*l/13.1%
*-commutative13.1%
associate-/r*13.1%
/-rgt-identity13.1%
metadata-eval13.1%
Simplified13.1%
Taylor expanded in b around -inf 2.9%
neg-mul-12.9%
unsub-neg2.9%
*-commutative2.9%
associate-/l*2.9%
associate-/r/2.9%
Simplified2.9%
Taylor expanded in b around 0 32.5%
Final simplification42.5%
(FPCore (a b c) :precision binary64 (if (<= b 1.42e-288) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.42e-288) {
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 <= 1.42d-288) 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 <= 1.42e-288) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.42e-288: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.42e-288) 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 <= 1.42e-288) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.42e-288], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.42 \cdot 10^{-288}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 1.42e-288Initial program 67.8%
neg-sub067.8%
associate-+l-67.8%
sub0-neg67.8%
neg-mul-167.8%
associate-*l/67.7%
*-commutative67.7%
associate-/r*67.7%
/-rgt-identity67.7%
metadata-eval67.7%
Simplified67.8%
Taylor expanded in b around -inf 63.9%
associate-*r/63.9%
neg-mul-163.9%
Simplified63.9%
if 1.42e-288 < b Initial program 30.0%
neg-sub030.0%
associate-+l-30.0%
sub0-neg30.0%
neg-mul-130.0%
associate-*l/29.9%
*-commutative29.9%
associate-/r*29.9%
/-rgt-identity29.9%
metadata-eval29.9%
Simplified29.2%
Taylor expanded in b around inf 74.1%
associate-*r/74.1%
neg-mul-174.1%
Simplified74.1%
Final simplification69.1%
(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 48.7%
flip-+29.3%
pow229.3%
add-sqr-sqrt29.3%
*-commutative29.3%
*-commutative29.3%
*-commutative29.3%
*-commutative29.3%
Applied egg-rr29.3%
unpow229.3%
add-sqr-sqrt29.3%
flip-+48.7%
+-commutative48.7%
add-sqr-sqrt33.2%
sqrt-prod45.6%
unpow245.6%
neg-mul-145.6%
unpow-prod-down45.6%
metadata-eval45.6%
pow245.6%
*-un-lft-identity45.6%
sqrt-prod12.5%
add-sqr-sqrt30.8%
Applied egg-rr30.8%
Taylor expanded in b around inf 2.6%
Final simplification2.6%
(FPCore (a b c) :precision binary64 (/ c b))
double code(double a, double b, double c) {
return c / b;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = c / b
end function
public static double code(double a, double b, double c) {
return c / b;
}
def code(a, b, c): return c / b
function code(a, b, c) return Float64(c / b) end
function tmp = code(a, b, c) tmp = c / b; end
code[a_, b_, c_] := N[(c / b), $MachinePrecision]
\begin{array}{l}
\\
\frac{c}{b}
\end{array}
Initial program 48.7%
neg-sub048.7%
associate-+l-48.7%
sub0-neg48.7%
neg-mul-148.7%
associate-*l/48.6%
*-commutative48.6%
associate-/r*48.6%
/-rgt-identity48.6%
metadata-eval48.6%
Simplified48.3%
Taylor expanded in b around -inf 30.4%
neg-mul-130.4%
unsub-neg30.4%
*-commutative30.4%
associate-/l*33.1%
associate-/r/33.1%
Simplified33.1%
Taylor expanded in b around 0 12.3%
Final simplification12.3%
herbie shell --seed 2023229
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))