
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))
double code(double a, double b, double c) {
return (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = (-b + sqrt(((b * b) - ((4.0d0 * a) * c)))) / (2.0d0 * a)
end function
public static double code(double a, double b, double c) {
return (-b + Math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a);
}
def code(a, b, c): return (-b + math.sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a)
function code(a, b, c) return Float64(Float64(Float64(-b) + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c)))) / Float64(2.0 * a)) end
function tmp = code(a, b, c) tmp = (-b + sqrt(((b * b) - ((4.0 * a) * c)))) / (2.0 * a); end
code[a_, b_, c_] := N[(N[((-b) + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(-b\right) + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}{2 \cdot a}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- c) b))
(t_1 (/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))))
(if (<= b -2e+146)
(- (/ c b) (/ b a))
(if (<= b 1.35e-88)
t_1
(if (<= b 1.05e-70)
(- t_0 (/ (pow c 2.0) (/ (pow b 3.0) a)))
(if (<= b 7.7e+27) t_1 t_0))))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (b <= -2e+146) {
tmp = (c / b) - (b / a);
} else if (b <= 1.35e-88) {
tmp = t_1;
} else if (b <= 1.05e-70) {
tmp = t_0 - (pow(c, 2.0) / (pow(b, 3.0) / a));
} else if (b <= 7.7e+27) {
tmp = t_1;
} else {
tmp = t_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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = -c / b
t_1 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
if (b <= (-2d+146)) then
tmp = (c / b) - (b / a)
else if (b <= 1.35d-88) then
tmp = t_1
else if (b <= 1.05d-70) then
tmp = t_0 - ((c ** 2.0d0) / ((b ** 3.0d0) / a))
else if (b <= 7.7d+27) then
tmp = t_1
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
double tmp;
if (b <= -2e+146) {
tmp = (c / b) - (b / a);
} else if (b <= 1.35e-88) {
tmp = t_1;
} else if (b <= 1.05e-70) {
tmp = t_0 - (Math.pow(c, 2.0) / (Math.pow(b, 3.0) / a));
} else if (b <= 7.7e+27) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c): t_0 = -c / b t_1 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) tmp = 0 if b <= -2e+146: tmp = (c / b) - (b / a) elif b <= 1.35e-88: tmp = t_1 elif b <= 1.05e-70: tmp = t_0 - (math.pow(c, 2.0) / (math.pow(b, 3.0) / a)) elif b <= 7.7e+27: tmp = t_1 else: tmp = t_0 return tmp
function code(a, b, c) t_0 = Float64(Float64(-c) / b) t_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)) tmp = 0.0 if (b <= -2e+146) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif (b <= 1.35e-88) tmp = t_1; elseif (b <= 1.05e-70) tmp = Float64(t_0 - Float64((c ^ 2.0) / Float64((b ^ 3.0) / a))); elseif (b <= 7.7e+27) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c) t_0 = -c / b; t_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); tmp = 0.0; if (b <= -2e+146) tmp = (c / b) - (b / a); elseif (b <= 1.35e-88) tmp = t_1; elseif (b <= 1.05e-70) tmp = t_0 - ((c ^ 2.0) / ((b ^ 3.0) / a)); elseif (b <= 7.7e+27) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2e+146], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.35e-88], t$95$1, If[LessEqual[b, 1.05e-70], N[(t$95$0 - N[(N[Power[c, 2.0], $MachinePrecision] / N[(N[Power[b, 3.0], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.7e+27], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
t_1 := \frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+146}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{-88}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;b \leq 1.05 \cdot 10^{-70}:\\
\;\;\;\;t\_0 - \frac{{c}^{2}}{\frac{{b}^{3}}{a}}\\
\mathbf{elif}\;b \leq 7.7 \cdot 10^{+27}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -1.99999999999999987e146Initial program 39.5%
*-commutative39.5%
Simplified39.5%
Taylor expanded in b around -inf 96.2%
+-commutative96.2%
mul-1-neg96.2%
unsub-neg96.2%
Simplified96.2%
if -1.99999999999999987e146 < b < 1.34999999999999997e-88 or 1.0500000000000001e-70 < b < 7.69999999999999953e27Initial program 87.2%
if 1.34999999999999997e-88 < b < 1.0500000000000001e-70Initial program 8.5%
*-commutative8.5%
Simplified8.5%
Taylor expanded in b around inf 98.7%
mul-1-neg98.7%
unsub-neg98.7%
mul-1-neg98.7%
distribute-neg-frac98.7%
*-commutative98.7%
associate-/l*100.0%
Simplified100.0%
if 7.69999999999999953e27 < b Initial program 11.5%
*-commutative11.5%
Simplified11.5%
Taylor expanded in b around inf 97.1%
mul-1-neg97.1%
distribute-neg-frac97.1%
Simplified97.1%
Final simplification91.6%
(FPCore (a b c)
:precision binary64
(if (<= b -2e+146)
(- (/ c b) (/ b a))
(if (or (<= b 2.25e-87) (and (not (<= b 5.5e-67)) (<= b 6.5e+27)))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -2e+146) {
tmp = (c / b) - (b / a);
} else if ((b <= 2.25e-87) || (!(b <= 5.5e-67) && (b <= 6.5e+27))) {
tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-2d+146)) then
tmp = (c / b) - (b / a)
else if ((b <= 2.25d-87) .or. (.not. (b <= 5.5d-67)) .and. (b <= 6.5d+27)) then
tmp = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -2e+146) {
tmp = (c / b) - (b / a);
} else if ((b <= 2.25e-87) || (!(b <= 5.5e-67) && (b <= 6.5e+27))) {
tmp = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -2e+146: tmp = (c / b) - (b / a) elif (b <= 2.25e-87) or (not (b <= 5.5e-67) and (b <= 6.5e+27)): tmp = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -2e+146) tmp = Float64(Float64(c / b) - Float64(b / a)); elseif ((b <= 2.25e-87) || (!(b <= 5.5e-67) && (b <= 6.5e+27))) tmp = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - 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 <= -2e+146) tmp = (c / b) - (b / a); elseif ((b <= 2.25e-87) || (~((b <= 5.5e-67)) && (b <= 6.5e+27))) tmp = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -2e+146], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[b, 2.25e-87], And[N[Not[LessEqual[b, 5.5e-67]], $MachinePrecision], LessEqual[b, 6.5e+27]]], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+146}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{elif}\;b \leq 2.25 \cdot 10^{-87} \lor \neg \left(b \leq 5.5 \cdot 10^{-67}\right) \land b \leq 6.5 \cdot 10^{+27}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.99999999999999987e146Initial program 39.5%
*-commutative39.5%
Simplified39.5%
Taylor expanded in b around -inf 96.2%
+-commutative96.2%
mul-1-neg96.2%
unsub-neg96.2%
Simplified96.2%
if -1.99999999999999987e146 < b < 2.24999999999999979e-87 or 5.5000000000000003e-67 < b < 6.5000000000000005e27Initial program 87.2%
if 2.24999999999999979e-87 < b < 5.5000000000000003e-67 or 6.5000000000000005e27 < b Initial program 11.3%
*-commutative11.3%
Simplified11.3%
Taylor expanded in b around inf 97.2%
mul-1-neg97.2%
distribute-neg-frac97.2%
Simplified97.2%
Final simplification91.5%
(FPCore (a b c)
:precision binary64
(if (<= b -8.8e-73)
(/ (- b) a)
(if (or (<= b 4.2e-88) (and (not (<= b 3.5e-65)) (<= b 6.5e+27)))
(* (- b (sqrt (* a (* c -4.0)))) (/ -0.5 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -8.8e-73) {
tmp = -b / a;
} else if ((b <= 4.2e-88) || (!(b <= 3.5e-65) && (b <= 6.5e+27))) {
tmp = (b - sqrt((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 <= (-8.8d-73)) then
tmp = -b / a
else if ((b <= 4.2d-88) .or. (.not. (b <= 3.5d-65)) .and. (b <= 6.5d+27)) then
tmp = (b - sqrt((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 <= -8.8e-73) {
tmp = -b / a;
} else if ((b <= 4.2e-88) || (!(b <= 3.5e-65) && (b <= 6.5e+27))) {
tmp = (b - Math.sqrt((a * (c * -4.0)))) * (-0.5 / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -8.8e-73: tmp = -b / a elif (b <= 4.2e-88) or (not (b <= 3.5e-65) and (b <= 6.5e+27)): tmp = (b - math.sqrt((a * (c * -4.0)))) * (-0.5 / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -8.8e-73) tmp = Float64(Float64(-b) / a); elseif ((b <= 4.2e-88) || (!(b <= 3.5e-65) && (b <= 6.5e+27))) tmp = Float64(Float64(b - sqrt(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 <= -8.8e-73) tmp = -b / a; elseif ((b <= 4.2e-88) || (~((b <= 3.5e-65)) && (b <= 6.5e+27))) tmp = (b - sqrt((a * (c * -4.0)))) * (-0.5 / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -8.8e-73], N[((-b) / a), $MachinePrecision], If[Or[LessEqual[b, 4.2e-88], And[N[Not[LessEqual[b, 3.5e-65]], $MachinePrecision], LessEqual[b, 6.5e+27]]], N[(N[(b - N[Sqrt[N[(a * N[(c * -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 -8.8 \cdot 10^{-73}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 4.2 \cdot 10^{-88} \lor \neg \left(b \leq 3.5 \cdot 10^{-65}\right) \land b \leq 6.5 \cdot 10^{+27}:\\
\;\;\;\;\left(b - \sqrt{a \cdot \left(c \cdot -4\right)}\right) \cdot \frac{-0.5}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -8.8000000000000001e-73Initial program 68.9%
*-commutative68.9%
Simplified68.9%
Taylor expanded in b around -inf 87.7%
associate-*r/87.7%
mul-1-neg87.7%
Simplified87.7%
if -8.8000000000000001e-73 < b < 4.1999999999999999e-88 or 3.50000000000000005e-65 < b < 6.5000000000000005e27Initial program 82.1%
*-commutative82.1%
Simplified82.1%
Applied egg-rr81.9%
*-commutative81.9%
associate-/r*81.9%
metadata-eval81.9%
Simplified81.9%
Taylor expanded in a around inf 76.1%
*-commutative76.1%
associate-*r*76.2%
Simplified76.2%
if 4.1999999999999999e-88 < b < 3.50000000000000005e-65 or 6.5000000000000005e27 < b Initial program 11.3%
*-commutative11.3%
Simplified11.3%
Taylor expanded in b around inf 97.2%
mul-1-neg97.2%
distribute-neg-frac97.2%
Simplified97.2%
Final simplification86.3%
(FPCore (a b c)
:precision binary64
(if (<= b -7.5e-73)
(/ (- b) a)
(if (or (<= b 2.1e-88) (and (not (<= b 4.6e-70)) (<= b 6.5e+27)))
(/ (- (sqrt (* a (* c -4.0))) b) (* a 2.0))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-73) {
tmp = -b / a;
} else if ((b <= 2.1e-88) || (!(b <= 4.6e-70) && (b <= 6.5e+27))) {
tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b <= (-7.5d-73)) then
tmp = -b / a
else if ((b <= 2.1d-88) .or. (.not. (b <= 4.6d-70)) .and. (b <= 6.5d+27)) then
tmp = (sqrt((a * (c * (-4.0d0)))) - b) / (a * 2.0d0)
else
tmp = -c / b
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b <= -7.5e-73) {
tmp = -b / a;
} else if ((b <= 2.1e-88) || (!(b <= 4.6e-70) && (b <= 6.5e+27))) {
tmp = (Math.sqrt((a * (c * -4.0))) - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -7.5e-73: tmp = -b / a elif (b <= 2.1e-88) or (not (b <= 4.6e-70) and (b <= 6.5e+27)): tmp = (math.sqrt((a * (c * -4.0))) - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -7.5e-73) tmp = Float64(Float64(-b) / a); elseif ((b <= 2.1e-88) || (!(b <= 4.6e-70) && (b <= 6.5e+27))) tmp = Float64(Float64(sqrt(Float64(a * Float64(c * -4.0))) - 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 <= -7.5e-73) tmp = -b / a; elseif ((b <= 2.1e-88) || (~((b <= 4.6e-70)) && (b <= 6.5e+27))) tmp = (sqrt((a * (c * -4.0))) - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -7.5e-73], N[((-b) / a), $MachinePrecision], If[Or[LessEqual[b, 2.1e-88], And[N[Not[LessEqual[b, 4.6e-70]], $MachinePrecision], LessEqual[b, 6.5e+27]]], N[(N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.5 \cdot 10^{-73}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 2.1 \cdot 10^{-88} \lor \neg \left(b \leq 4.6 \cdot 10^{-70}\right) \land b \leq 6.5 \cdot 10^{+27}:\\
\;\;\;\;\frac{\sqrt{a \cdot \left(c \cdot -4\right)} - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -7.5e-73Initial program 68.9%
*-commutative68.9%
Simplified68.9%
Taylor expanded in b around -inf 87.7%
associate-*r/87.7%
mul-1-neg87.7%
Simplified87.7%
if -7.5e-73 < b < 2.1e-88 or 4.60000000000000001e-70 < b < 6.5000000000000005e27Initial program 82.1%
*-commutative82.1%
Simplified82.1%
Taylor expanded in b around 0 76.3%
*-commutative76.3%
associate-*r*76.4%
Simplified76.4%
if 2.1e-88 < b < 4.60000000000000001e-70 or 6.5000000000000005e27 < b Initial program 11.3%
*-commutative11.3%
Simplified11.3%
Taylor expanded in b around inf 97.2%
mul-1-neg97.2%
distribute-neg-frac97.2%
Simplified97.2%
Final simplification86.3%
(FPCore (a b c)
:precision binary64
(if (<= b -4e-73)
(/ (- b) a)
(if (or (<= b 4.55e-88) (and (not (<= b 1.1e-71)) (<= b 6.5e+27)))
(* 0.5 (/ (sqrt (* a (* c -4.0))) a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-73) {
tmp = -b / a;
} else if ((b <= 4.55e-88) || (!(b <= 1.1e-71) && (b <= 6.5e+27))) {
tmp = 0.5 * (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 <= (-4d-73)) then
tmp = -b / a
else if ((b <= 4.55d-88) .or. (.not. (b <= 1.1d-71)) .and. (b <= 6.5d+27)) then
tmp = 0.5d0 * (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 <= -4e-73) {
tmp = -b / a;
} else if ((b <= 4.55e-88) || (!(b <= 1.1e-71) && (b <= 6.5e+27))) {
tmp = 0.5 * (Math.sqrt((a * (c * -4.0))) / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-73: tmp = -b / a elif (b <= 4.55e-88) or (not (b <= 1.1e-71) and (b <= 6.5e+27)): tmp = 0.5 * (math.sqrt((a * (c * -4.0))) / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-73) tmp = Float64(Float64(-b) / a); elseif ((b <= 4.55e-88) || (!(b <= 1.1e-71) && (b <= 6.5e+27))) tmp = Float64(0.5 * Float64(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 <= -4e-73) tmp = -b / a; elseif ((b <= 4.55e-88) || (~((b <= 1.1e-71)) && (b <= 6.5e+27))) tmp = 0.5 * (sqrt((a * (c * -4.0))) / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-73], N[((-b) / a), $MachinePrecision], If[Or[LessEqual[b, 4.55e-88], And[N[Not[LessEqual[b, 1.1e-71]], $MachinePrecision], LessEqual[b, 6.5e+27]]], N[(0.5 * N[(N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4 \cdot 10^{-73}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{elif}\;b \leq 4.55 \cdot 10^{-88} \lor \neg \left(b \leq 1.1 \cdot 10^{-71}\right) \land b \leq 6.5 \cdot 10^{+27}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{a \cdot \left(c \cdot -4\right)}}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.99999999999999999e-73Initial program 68.9%
*-commutative68.9%
Simplified68.9%
Taylor expanded in b around -inf 87.7%
associate-*r/87.7%
mul-1-neg87.7%
Simplified87.7%
if -3.99999999999999999e-73 < b < 4.54999999999999982e-88 or 1.09999999999999999e-71 < b < 6.5000000000000005e27Initial program 82.1%
*-commutative82.1%
Simplified82.1%
prod-diff81.9%
*-commutative81.9%
fma-def81.9%
associate-+l+81.9%
pow281.9%
distribute-lft-neg-in81.9%
*-commutative81.9%
distribute-rgt-neg-in81.9%
metadata-eval81.9%
associate-*r*81.9%
*-commutative81.9%
*-commutative81.9%
fma-udef81.9%
Applied egg-rr81.9%
fma-def81.9%
fma-def81.7%
associate-*l*81.7%
Simplified81.7%
Taylor expanded in b around 0 73.7%
associate-*l/73.9%
*-lft-identity73.9%
distribute-rgt-out75.2%
metadata-eval75.2%
associate-*r*75.3%
Simplified75.3%
if 4.54999999999999982e-88 < b < 1.09999999999999999e-71 or 6.5000000000000005e27 < b Initial program 11.3%
*-commutative11.3%
Simplified11.3%
Taylor expanded in b around inf 97.2%
mul-1-neg97.2%
distribute-neg-frac97.2%
Simplified97.2%
Final simplification85.9%
(FPCore (a b c) :precision binary64 (if (<= b -4e-310) (- (/ c b) (/ b a)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -4e-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 <= (-4d-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 <= -4e-310) {
tmp = (c / b) - (b / a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -4e-310: tmp = (c / b) - (b / a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -4e-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 <= -4e-310) tmp = (c / b) - (b / a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -4e-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 -4 \cdot 10^{-310}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -3.999999999999988e-310Initial program 74.6%
*-commutative74.6%
Simplified74.6%
Taylor expanded in b around -inf 71.1%
+-commutative71.1%
mul-1-neg71.1%
unsub-neg71.1%
Simplified71.1%
if -3.999999999999988e-310 < b Initial program 40.5%
*-commutative40.5%
Simplified40.5%
Taylor expanded in b around inf 62.6%
mul-1-neg62.6%
distribute-neg-frac62.6%
Simplified62.6%
Final simplification66.9%
(FPCore (a b c) :precision binary64 (if (<= b 1.5e-309) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= 1.5e-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 <= 1.5d-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 <= 1.5e-309) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= 1.5e-309: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= 1.5e-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 <= 1.5e-309) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, 1.5e-309], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.5 \cdot 10^{-309}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < 1.5e-309Initial program 74.6%
*-commutative74.6%
Simplified74.6%
Taylor expanded in b around -inf 71.0%
associate-*r/71.0%
mul-1-neg71.0%
Simplified71.0%
if 1.5e-309 < b Initial program 40.5%
*-commutative40.5%
Simplified40.5%
Taylor expanded in b around inf 62.6%
mul-1-neg62.6%
distribute-neg-frac62.6%
Simplified62.6%
Final simplification66.9%
(FPCore (a b c) :precision binary64 (/ (- b) a))
double code(double a, double b, double c) {
return -b / a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = -b / a
end function
public static double code(double a, double b, double c) {
return -b / a;
}
def code(a, b, c): return -b / a
function code(a, b, c) return Float64(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 58.0%
*-commutative58.0%
Simplified58.0%
Taylor expanded in b around -inf 37.6%
associate-*r/37.6%
mul-1-neg37.6%
Simplified37.6%
Final simplification37.6%
herbie shell --seed 2024026
(FPCore (a b c)
:name "Quadratic roots, full range"
:precision binary64
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))