
(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 (- b (sqrt (- (* b b) (* a (* c 4.0)))))))
(if (<= b -2e+146)
(/ (- b) a)
(if (<= b 5e-121)
(/ (* t_0 -0.5) a)
(if (or (<= b 1.3e-17) (not (<= b 2.2)))
(/ (- c) b)
(* t_0 (/ -0.5 a)))))))
double code(double a, double b, double c) {
double t_0 = b - sqrt(((b * b) - (a * (c * 4.0))));
double tmp;
if (b <= -2e+146) {
tmp = -b / a;
} else if (b <= 5e-121) {
tmp = (t_0 * -0.5) / a;
} else if ((b <= 1.3e-17) || !(b <= 2.2)) {
tmp = -c / b;
} else {
tmp = t_0 * (-0.5 / 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 = b - sqrt(((b * b) - (a * (c * 4.0d0))))
if (b <= (-2d+146)) then
tmp = -b / a
else if (b <= 5d-121) then
tmp = (t_0 * (-0.5d0)) / a
else if ((b <= 1.3d-17) .or. (.not. (b <= 2.2d0))) then
tmp = -c / b
else
tmp = t_0 * ((-0.5d0) / a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = b - Math.sqrt(((b * b) - (a * (c * 4.0))));
double tmp;
if (b <= -2e+146) {
tmp = -b / a;
} else if (b <= 5e-121) {
tmp = (t_0 * -0.5) / a;
} else if ((b <= 1.3e-17) || !(b <= 2.2)) {
tmp = -c / b;
} else {
tmp = t_0 * (-0.5 / a);
}
return tmp;
}
def code(a, b, c): t_0 = b - math.sqrt(((b * b) - (a * (c * 4.0)))) tmp = 0 if b <= -2e+146: tmp = -b / a elif b <= 5e-121: tmp = (t_0 * -0.5) / a elif (b <= 1.3e-17) or not (b <= 2.2): tmp = -c / b else: tmp = t_0 * (-0.5 / a) return tmp
function code(a, b, c) t_0 = Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 4.0))))) tmp = 0.0 if (b <= -2e+146) tmp = Float64(Float64(-b) / a); elseif (b <= 5e-121) tmp = Float64(Float64(t_0 * -0.5) / a); elseif ((b <= 1.3e-17) || !(b <= 2.2)) tmp = Float64(Float64(-c) / b); else tmp = Float64(t_0 * Float64(-0.5 / a)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = b - sqrt(((b * b) - (a * (c * 4.0)))); tmp = 0.0; if (b <= -2e+146) tmp = -b / a; elseif (b <= 5e-121) tmp = (t_0 * -0.5) / a; elseif ((b <= 1.3e-17) || ~((b <= 2.2))) tmp = -c / b; else tmp = t_0 * (-0.5 / a); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2e+146], N[((-b) / a), $MachinePrecision], If[LessEqual[b, 5e-121], N[(N[(t$95$0 * -0.5), $MachinePrecision] / a), $MachinePrecision], If[Or[LessEqual[b, 1.3e-17], N[Not[LessEqual[b, 2.2]], $MachinePrecision]], N[((-c) / b), $MachinePrecision], N[(t$95$0 * N[(-0.5 / a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+146}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{-121}:\\
\;\;\;\;\frac{t_0 \cdot -0.5}{a}\\
\mathbf{elif}\;b \leq 1.3 \cdot 10^{-17} \lor \neg \left(b \leq 2.2\right):\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;t_0 \cdot \frac{-0.5}{a}\\
\end{array}
\end{array}
if b < -1.99999999999999987e146Initial program 57.7%
neg-sub057.7%
associate-+l-57.7%
sub0-neg57.7%
neg-mul-157.7%
associate-*l/57.7%
*-commutative57.7%
associate-/r*57.7%
/-rgt-identity57.7%
metadata-eval57.7%
Simplified57.7%
Taylor expanded in b around -inf 95.1%
associate-*r/95.1%
mul-1-neg95.1%
Simplified95.1%
if -1.99999999999999987e146 < b < 4.99999999999999989e-121Initial program 79.0%
neg-sub079.0%
associate-+l-79.0%
sub0-neg79.0%
neg-mul-179.0%
associate-*l/78.8%
*-commutative78.8%
associate-/r*78.8%
/-rgt-identity78.8%
metadata-eval78.8%
Simplified78.8%
fma-udef78.8%
*-commutative78.8%
associate-*r*78.8%
metadata-eval78.8%
distribute-rgt-neg-in78.8%
*-commutative78.8%
distribute-lft-neg-in78.8%
+-commutative78.8%
sub-neg78.8%
*-commutative78.8%
associate-*l*78.8%
Applied egg-rr78.8%
*-commutative78.8%
Simplified78.8%
associate-*r/79.0%
Applied egg-rr79.0%
if 4.99999999999999989e-121 < b < 1.30000000000000002e-17 or 2.2000000000000002 < b Initial program 19.4%
neg-sub019.4%
associate-+l-19.4%
sub0-neg19.4%
neg-mul-119.4%
associate-*l/19.4%
*-commutative19.4%
associate-/r*19.4%
/-rgt-identity19.4%
metadata-eval19.4%
Simplified19.4%
Taylor expanded in b around inf 84.6%
mul-1-neg84.6%
distribute-neg-frac84.6%
Simplified84.6%
if 1.30000000000000002e-17 < b < 2.2000000000000002Initial program 83.1%
neg-sub083.1%
associate-+l-83.1%
sub0-neg83.1%
neg-mul-183.1%
associate-*l/83.1%
*-commutative83.1%
associate-/r*83.1%
/-rgt-identity83.1%
metadata-eval83.1%
Simplified83.1%
fma-udef83.1%
*-commutative83.1%
associate-*r*83.1%
metadata-eval83.1%
distribute-rgt-neg-in83.1%
*-commutative83.1%
distribute-lft-neg-in83.1%
+-commutative83.1%
sub-neg83.1%
*-commutative83.1%
associate-*l*83.1%
Applied egg-rr83.1%
*-commutative83.1%
Simplified83.1%
Final simplification83.5%
(FPCore (a b c)
:precision binary64
(if (<= b -6.6e+145)
(/ (- b) a)
(if (or (<= b 5.6e-121) (and (not (<= b 2.1e-17)) (<= b 2.2)))
(* (- b (sqrt (- (* b b) (* a (* c 4.0))))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -6.6e+145) {
tmp = -b / a;
} else if ((b <= 5.6e-121) || (!(b <= 2.1e-17) && (b <= 2.2))) {
tmp = (b - sqrt(((b * b) - (a * (c * 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 <= (-6.6d+145)) then
tmp = -b / a
else if ((b <= 5.6d-121) .or. (.not. (b <= 2.1d-17)) .and. (b <= 2.2d0)) then
tmp = (b - sqrt(((b * b) - (a * (c * 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 <= -6.6e+145) {
tmp = -b / a;
} else if ((b <= 5.6e-121) || (!(b <= 2.1e-17) && (b <= 2.2))) {
tmp = (b - Math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -6.6e+145: tmp = -b / a elif (b <= 5.6e-121) or (not (b <= 2.1e-17) and (b <= 2.2)): tmp = (b - math.sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -6.6e+145) tmp = Float64(Float64(-b) / a); elseif ((b <= 5.6e-121) || (!(b <= 2.1e-17) && (b <= 2.2))) tmp = Float64(Float64(b - sqrt(Float64(Float64(b * b) - Float64(a * Float64(c * 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 <= -6.6e+145) tmp = -b / a; elseif ((b <= 5.6e-121) || (~((b <= 2.1e-17)) && (b <= 2.2))) tmp = (b - sqrt(((b * b) - (a * (c * 4.0))))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -6.6e+145], N[((-b) / a), $MachinePrecision], If[Or[LessEqual[b, 5.6e-121], And[N[Not[LessEqual[b, 2.1e-17]], $MachinePrecision], LessEqual[b, 2.2]]], N[(N[(b - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(a * N[(c * 4.0), $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 -6.6 \cdot 10^{+145}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 5.6 \cdot 10^{-121} \lor \neg \left(b \leq 2.1 \cdot 10^{-17}\right) \land b \leq 2.2:\\
\;\;\;\;\left(b - \sqrt{b \cdot b - a \cdot \left(c \cdot 4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -6.60000000000000054e145Initial program 57.7%
neg-sub057.7%
associate-+l-57.7%
sub0-neg57.7%
neg-mul-157.7%
associate-*l/57.7%
*-commutative57.7%
associate-/r*57.7%
/-rgt-identity57.7%
metadata-eval57.7%
Simplified57.7%
Taylor expanded in b around -inf 95.1%
associate-*r/95.1%
mul-1-neg95.1%
Simplified95.1%
if -6.60000000000000054e145 < b < 5.6000000000000002e-121 or 2.09999999999999992e-17 < b < 2.2000000000000002Initial program 79.2%
neg-sub079.2%
associate-+l-79.2%
sub0-neg79.2%
neg-mul-179.2%
associate-*l/79.0%
*-commutative79.0%
associate-/r*79.0%
/-rgt-identity79.0%
metadata-eval79.0%
Simplified79.0%
fma-udef79.0%
*-commutative79.0%
associate-*r*79.0%
metadata-eval79.0%
distribute-rgt-neg-in79.0%
*-commutative79.0%
distribute-lft-neg-in79.0%
+-commutative79.0%
sub-neg79.0%
*-commutative79.0%
associate-*l*79.0%
Applied egg-rr79.0%
*-commutative79.0%
Simplified79.0%
if 5.6000000000000002e-121 < b < 2.09999999999999992e-17 or 2.2000000000000002 < b Initial program 19.4%
neg-sub019.4%
associate-+l-19.4%
sub0-neg19.4%
neg-mul-119.4%
associate-*l/19.4%
*-commutative19.4%
associate-/r*19.4%
/-rgt-identity19.4%
metadata-eval19.4%
Simplified19.4%
Taylor expanded in b around inf 84.6%
mul-1-neg84.6%
distribute-neg-frac84.6%
Simplified84.6%
Final simplification83.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.95e-60)
(- (/ c b) (/ b a))
(if (or (<= b 6e-121) (and (not (<= b 2.2e-17)) (<= b 2.2)))
(* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.95e-60) {
tmp = (c / b) - (b / a);
} else if ((b <= 6e-121) || (!(b <= 2.2e-17) && (b <= 2.2))) {
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 <= (-1.95d-60)) then
tmp = (c / b) - (b / a)
else if ((b <= 6d-121) .or. (.not. (b <= 2.2d-17)) .and. (b <= 2.2d0)) 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 <= -1.95e-60) {
tmp = (c / b) - (b / a);
} else if ((b <= 6e-121) || (!(b <= 2.2e-17) && (b <= 2.2))) {
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 <= -1.95e-60: tmp = (c / b) - (b / a) elif (b <= 6e-121) or (not (b <= 2.2e-17) and (b <= 2.2)): 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 <= -1.95e-60) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif ((b <= 6e-121) || (!(b <= 2.2e-17) && (b <= 2.2))) 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 <= -1.95e-60) tmp = (c / b) - (b / a); elseif ((b <= 6e-121) || (~((b <= 2.2e-17)) && (b <= 2.2))) 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, -1.95e-60], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 6e-121], And[N[Not[LessEqual[b, 2.2e-17]], $MachinePrecision], LessEqual[b, 2.2]]], 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 -1.95 \cdot 10^{-60}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-121} \lor \neg \left(b \leq 2.2 \cdot 10^{-17}\right) \land b \leq 2.2:\\
\;\;\;\;\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 < -1.9500000000000001e-60Initial program 74.8%
neg-sub074.8%
associate-+l-74.8%
sub0-neg74.8%
neg-mul-174.8%
associate-*l/74.8%
*-commutative74.8%
associate-/r*74.8%
/-rgt-identity74.8%
metadata-eval74.8%
Simplified74.8%
Taylor expanded in b around -inf 84.3%
mul-1-neg84.3%
unsub-neg84.3%
Simplified84.3%
if -1.9500000000000001e-60 < b < 5.9999999999999999e-121 or 2.2e-17 < b < 2.2000000000000002Initial program 73.6%
neg-sub073.6%
associate-+l-73.6%
sub0-neg73.6%
neg-mul-173.6%
associate-*l/73.3%
*-commutative73.3%
associate-/r*73.3%
/-rgt-identity73.3%
metadata-eval73.3%
Simplified73.3%
Taylor expanded in a around inf 67.9%
*-commutative67.9%
*-commutative67.9%
associate-*r*67.9%
Simplified67.9%
if 5.9999999999999999e-121 < b < 2.2e-17 or 2.2000000000000002 < b Initial program 19.4%
neg-sub019.4%
associate-+l-19.4%
sub0-neg19.4%
neg-mul-119.4%
associate-*l/19.4%
*-commutative19.4%
associate-/r*19.4%
/-rgt-identity19.4%
metadata-eval19.4%
Simplified19.4%
Taylor expanded in b around inf 84.6%
mul-1-neg84.6%
distribute-neg-frac84.6%
Simplified84.6%
Final simplification79.4%
(FPCore (a b c)
:precision binary64
(if (<= b -4.8e-66)
(- (/ c b) (/ b a))
(if (<= b 6e-121)
(/ (* -0.5 (- b (sqrt (* c (* a -4.0))))) a)
(if (or (<= b 2.2e-17) (not (<= b 2.2)))
(/ (- c) b)
(* (/ -0.5 a) (- b (sqrt (* a (* c -4.0)))))))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e-66) {
tmp = (c / b) - (b / a);
} else if (b <= 6e-121) {
tmp = (-0.5 * (b - sqrt((c * (a * -4.0))))) / a;
} else if ((b <= 2.2e-17) || !(b <= 2.2)) {
tmp = -c / b;
} else {
tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0))));
}
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.8d-66)) then
tmp = (c / b) - (b / a)
else if (b <= 6d-121) then
tmp = ((-0.5d0) * (b - sqrt((c * (a * (-4.0d0)))))) / a
else if ((b <= 2.2d-17) .or. (.not. (b <= 2.2d0))) then
tmp = -c / b
else
tmp = ((-0.5d0) / a) * (b - sqrt((a * (c * (-4.0d0)))))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -4.8e-66) {
tmp = (c / b) - (b / a);
} else if (b <= 6e-121) {
tmp = (-0.5 * (b - Math.sqrt((c * (a * -4.0))))) / a;
} else if ((b <= 2.2e-17) || !(b <= 2.2)) {
tmp = -c / b;
} else {
tmp = (-0.5 / a) * (b - Math.sqrt((a * (c * -4.0))));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4.8e-66: tmp = (c / b) - (b / a) elif b <= 6e-121: tmp = (-0.5 * (b - math.sqrt((c * (a * -4.0))))) / a elif (b <= 2.2e-17) or not (b <= 2.2): tmp = -c / b else: tmp = (-0.5 / a) * (b - math.sqrt((a * (c * -4.0)))) return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4.8e-66) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 6e-121) tmp = Float64(Float64(-0.5 * Float64(b - sqrt(Float64(c * Float64(a * -4.0))))) / a); elseif ((b <= 2.2e-17) || !(b <= 2.2)) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-0.5 / a) * Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -4.8e-66) tmp = (c / b) - (b / a); elseif (b <= 6e-121) tmp = (-0.5 * (b - sqrt((c * (a * -4.0))))) / a; elseif ((b <= 2.2e-17) || ~((b <= 2.2))) tmp = -c / b; else tmp = (-0.5 / a) * (b - sqrt((a * (c * -4.0)))); end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4.8e-66], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 6e-121], N[(N[(-0.5 * N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision], If[Or[LessEqual[b, 2.2e-17], N[Not[LessEqual[b, 2.2]], $MachinePrecision]], N[((-c) / b), $MachinePrecision], N[(N[(-0.5 / a), $MachinePrecision] * N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.8 \cdot 10^{-66}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-121}:\\
\;\;\;\;\frac{-0.5 \cdot \left(b - \sqrt{c \cdot \left(a \cdot -4\right)}\right)}{a}\\
\mathbf{elif}\;b \leq 2.2 \cdot 10^{-17} \lor \neg \left(b \leq 2.2\right):\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-0.5}{a} \cdot \left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right)\\
\end{array}
\end{array}
if b < -4.80000000000000052e-66Initial program 74.8%
neg-sub074.8%
associate-+l-74.8%
sub0-neg74.8%
neg-mul-174.8%
associate-*l/74.8%
*-commutative74.8%
associate-/r*74.8%
/-rgt-identity74.8%
metadata-eval74.8%
Simplified74.8%
Taylor expanded in b around -inf 84.3%
mul-1-neg84.3%
unsub-neg84.3%
Simplified84.3%
if -4.80000000000000052e-66 < b < 5.9999999999999999e-121Initial program 72.8%
neg-sub072.8%
associate-+l-72.8%
sub0-neg72.8%
neg-mul-172.8%
associate-*l/72.5%
*-commutative72.5%
associate-/r*72.5%
/-rgt-identity72.5%
metadata-eval72.5%
Simplified72.5%
fma-udef72.5%
*-commutative72.5%
associate-*r*72.5%
metadata-eval72.5%
distribute-rgt-neg-in72.5%
*-commutative72.5%
distribute-lft-neg-in72.5%
+-commutative72.5%
sub-neg72.5%
*-commutative72.5%
associate-*l*72.5%
Applied egg-rr72.5%
*-commutative72.5%
Simplified72.5%
associate-*r/72.8%
Applied egg-rr72.8%
Taylor expanded in b around 0 66.9%
*-commutative66.9%
associate-*l*66.9%
Simplified66.9%
if 5.9999999999999999e-121 < b < 2.2e-17 or 2.2000000000000002 < b Initial program 19.4%
neg-sub019.4%
associate-+l-19.4%
sub0-neg19.4%
neg-mul-119.4%
associate-*l/19.4%
*-commutative19.4%
associate-/r*19.4%
/-rgt-identity19.4%
metadata-eval19.4%
Simplified19.4%
Taylor expanded in b around inf 84.6%
mul-1-neg84.6%
distribute-neg-frac84.6%
Simplified84.6%
if 2.2e-17 < b < 2.2000000000000002Initial program 83.1%
neg-sub083.1%
associate-+l-83.1%
sub0-neg83.1%
neg-mul-183.1%
associate-*l/83.1%
*-commutative83.1%
associate-/r*83.1%
/-rgt-identity83.1%
metadata-eval83.1%
Simplified83.1%
Taylor expanded in a around inf 83.1%
*-commutative83.1%
*-commutative83.1%
associate-*r*83.1%
Simplified83.1%
Final simplification79.5%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
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-309)) 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-309) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) 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-309) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], 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^{-309}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 74.5%
neg-sub074.5%
associate-+l-74.5%
sub0-neg74.5%
neg-mul-174.5%
associate-*l/74.4%
*-commutative74.4%
associate-/r*74.4%
/-rgt-identity74.4%
metadata-eval74.4%
Simplified74.4%
Taylor expanded in b around -inf 68.4%
mul-1-neg68.4%
unsub-neg68.4%
Simplified68.4%
if -1.000000000000002e-309 < b Initial program 36.2%
neg-sub036.2%
associate-+l-36.2%
sub0-neg36.2%
neg-mul-136.2%
associate-*l/36.1%
*-commutative36.1%
associate-/r*36.1%
/-rgt-identity36.1%
metadata-eval36.1%
Simplified36.1%
Taylor expanded in b around inf 61.4%
mul-1-neg61.4%
distribute-neg-frac61.4%
Simplified61.4%
Final simplification64.8%
(FPCore (a b c) :precision binary64 (if (<= b -1e-309) (/ (- b) a) 0.0))
double code(double a, double b, double c) {
double tmp;
if (b <= -1e-309) {
tmp = -b / a;
} else {
tmp = 0.0;
}
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 = 0.0d0
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 = 0.0;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1e-309: tmp = -b / a else: tmp = 0.0 return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1e-309) tmp = Float64(Float64(-b) / a); else tmp = 0.0; end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1e-309) tmp = -b / a; else tmp = 0.0; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1e-309], N[((-b) / a), $MachinePrecision], 0.0]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;0\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 74.5%
neg-sub074.5%
associate-+l-74.5%
sub0-neg74.5%
neg-mul-174.5%
associate-*l/74.4%
*-commutative74.4%
associate-/r*74.4%
/-rgt-identity74.4%
metadata-eval74.4%
Simplified74.4%
Taylor expanded in b around -inf 67.9%
associate-*r/67.9%
mul-1-neg67.9%
Simplified67.9%
if -1.000000000000002e-309 < b Initial program 36.2%
neg-sub036.2%
associate-+l-36.2%
sub0-neg36.2%
neg-mul-136.2%
associate-*l/36.1%
*-commutative36.1%
associate-/r*36.1%
/-rgt-identity36.1%
metadata-eval36.1%
Simplified36.1%
Taylor expanded in a around 0 8.4%
unpow28.4%
Simplified8.4%
Taylor expanded in b around 0 21.1%
Final simplification43.8%
(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 -1 \cdot 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.000000000000002e-309Initial program 74.5%
neg-sub074.5%
associate-+l-74.5%
sub0-neg74.5%
neg-mul-174.5%
associate-*l/74.4%
*-commutative74.4%
associate-/r*74.4%
/-rgt-identity74.4%
metadata-eval74.4%
Simplified74.4%
Taylor expanded in b around -inf 67.9%
associate-*r/67.9%
mul-1-neg67.9%
Simplified67.9%
if -1.000000000000002e-309 < b Initial program 36.2%
neg-sub036.2%
associate-+l-36.2%
sub0-neg36.2%
neg-mul-136.2%
associate-*l/36.1%
*-commutative36.1%
associate-/r*36.1%
/-rgt-identity36.1%
metadata-eval36.1%
Simplified36.1%
Taylor expanded in b around inf 61.4%
mul-1-neg61.4%
distribute-neg-frac61.4%
Simplified61.4%
Final simplification64.6%
(FPCore (a b c) :precision binary64 0.0)
double code(double a, double b, double c) {
return 0.0;
}
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
end function
public static double code(double a, double b, double c) {
return 0.0;
}
def code(a, b, c): return 0.0
function code(a, b, c) return 0.0 end
function tmp = code(a, b, c) tmp = 0.0; end
code[a_, b_, c_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 54.8%
neg-sub054.8%
associate-+l-54.8%
sub0-neg54.8%
neg-mul-154.8%
associate-*l/54.7%
*-commutative54.7%
associate-/r*54.7%
/-rgt-identity54.7%
metadata-eval54.7%
Simplified54.7%
Taylor expanded in a around 0 30.1%
unpow230.1%
Simplified30.1%
Taylor expanded in b around 0 12.1%
Final simplification12.1%
herbie shell --seed 2023224
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))