
(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 (sqrt (fma (* -4.0 c) a (* b b)))))
(if (<= b -5e+128)
(fma (/ (/ c b) b) b (/ (- b) a))
(if (<= b 7.2e-211)
(/ (- t_0 b) (* 2.0 a))
(if (<= b 2.35e+91)
(/ (/ (* 2.0 (* c a)) a) (- (- b) t_0))
(/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma((-4.0 * c), a, (b * b)));
double tmp;
if (b <= -5e+128) {
tmp = fma(((c / b) / b), b, (-b / a));
} else if (b <= 7.2e-211) {
tmp = (t_0 - b) / (2.0 * a);
} else if (b <= 2.35e+91) {
tmp = ((2.0 * (c * a)) / a) / (-b - t_0);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) t_0 = sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))) tmp = 0.0 if (b <= -5e+128) tmp = fma(Float64(Float64(c / b) / b), b, Float64(Float64(-b) / a)); elseif (b <= 7.2e-211) tmp = Float64(Float64(t_0 - b) / Float64(2.0 * a)); elseif (b <= 2.35e+91) tmp = Float64(Float64(Float64(2.0 * Float64(c * a)) / a) / Float64(Float64(-b) - t_0)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -5e+128], N[(N[(N[(c / b), $MachinePrecision] / b), $MachinePrecision] * b + N[((-b) / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 7.2e-211], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 2.35e+91], N[(N[(N[(2.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+128}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{c}{b}}{b}, b, \frac{-b}{a}\right)\\
\mathbf{elif}\;b \leq 7.2 \cdot 10^{-211}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\mathbf{elif}\;b \leq 2.35 \cdot 10^{+91}:\\
\;\;\;\;\frac{\frac{2 \cdot \left(c \cdot a\right)}{a}}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5e128Initial program 53.9%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
*-lft-identityN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
distribute-frac-negN/A
lower-/.f64N/A
lower-neg.f6496.6
Applied rewrites96.6%
if -5e128 < b < 7.1999999999999998e-211Initial program 84.1%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6484.1
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval84.1
Applied rewrites84.1%
if 7.1999999999999998e-211 < b < 2.3499999999999999e91Initial program 56.2%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6456.1
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6456.1
Applied rewrites56.1%
Applied rewrites82.0%
lift-*.f64N/A
lift-/.f64N/A
associate-*r/N/A
lower-/.f64N/A
lift-/.f64N/A
associate-*l/N/A
lower-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
lower-*.f6482.6
lift-*.f64N/A
lift-fma.f64N/A
Applied rewrites82.6%
if 2.3499999999999999e91 < b Initial program 14.3%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6494.6
Applied rewrites94.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma (* -4.0 c) a (* b b)))))
(if (<= b -5e+128)
(fma (/ (/ c b) b) b (/ (- b) a))
(if (<= b 1.9e-139)
(/ (- t_0 b) (* 2.0 a))
(if (<= b 5.5e+30)
(/ (* 2.0 (* c a)) (* (- (- b) t_0) a))
(/ (- c) b))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma((-4.0 * c), a, (b * b)));
double tmp;
if (b <= -5e+128) {
tmp = fma(((c / b) / b), b, (-b / a));
} else if (b <= 1.9e-139) {
tmp = (t_0 - b) / (2.0 * a);
} else if (b <= 5.5e+30) {
tmp = (2.0 * (c * a)) / ((-b - t_0) * a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) t_0 = sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))) tmp = 0.0 if (b <= -5e+128) tmp = fma(Float64(Float64(c / b) / b), b, Float64(Float64(-b) / a)); elseif (b <= 1.9e-139) tmp = Float64(Float64(t_0 - b) / Float64(2.0 * a)); elseif (b <= 5.5e+30) tmp = Float64(Float64(2.0 * Float64(c * a)) / Float64(Float64(Float64(-b) - t_0) * a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -5e+128], N[(N[(N[(c / b), $MachinePrecision] / b), $MachinePrecision] * b + N[((-b) / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 1.9e-139], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 5.5e+30], N[(N[(2.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / N[(N[((-b) - t$95$0), $MachinePrecision] * a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+128}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{c}{b}}{b}, b, \frac{-b}{a}\right)\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{-139}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\mathbf{elif}\;b \leq 5.5 \cdot 10^{+30}:\\
\;\;\;\;\frac{2 \cdot \left(c \cdot a\right)}{\left(\left(-b\right) - t\_0\right) \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5e128Initial program 53.9%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
*-lft-identityN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
distribute-frac-negN/A
lower-/.f64N/A
lower-neg.f6496.6
Applied rewrites96.6%
if -5e128 < b < 1.90000000000000004e-139Initial program 82.3%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6482.3
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval82.3
Applied rewrites82.3%
if 1.90000000000000004e-139 < b < 5.50000000000000025e30Initial program 59.4%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6459.3
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6459.3
Applied rewrites59.3%
Applied rewrites87.0%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
lower-/.f64N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f6487.7
Applied rewrites87.7%
if 5.50000000000000025e30 < b Initial program 17.1%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6490.0
Applied rewrites90.0%
(FPCore (a b c)
:precision binary64
(if (<= b -5e+128)
(fma (/ (/ c b) b) b (/ (- b) a))
(if (<= b 3.3e-65)
(/ (- (sqrt (fma (* -4.0 c) a (* b b))) b) (* 2.0 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e+128) {
tmp = fma(((c / b) / b), b, (-b / a));
} else if (b <= 3.3e-65) {
tmp = (sqrt(fma((-4.0 * c), a, (b * b))) - b) / (2.0 * a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -5e+128) tmp = fma(Float64(Float64(c / b) / b), b, Float64(Float64(-b) / a)); elseif (b <= 3.3e-65) tmp = Float64(Float64(sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -5e+128], N[(N[(N[(c / b), $MachinePrecision] / b), $MachinePrecision] * b + N[((-b) / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.3e-65], N[(N[(N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{+128}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{c}{b}}{b}, b, \frac{-b}{a}\right)\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{-65}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -5e128Initial program 53.9%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
*-lft-identityN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
distribute-frac-negN/A
lower-/.f64N/A
lower-neg.f6496.6
Applied rewrites96.6%
if -5e128 < b < 3.3000000000000001e-65Initial program 83.4%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6483.4
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval83.4
Applied rewrites83.4%
if 3.3000000000000001e-65 < b Initial program 22.2%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6483.4
Applied rewrites83.4%
(FPCore (a b c)
:precision binary64
(if (<= b -9.2e+113)
(fma (/ (/ c b) b) b (/ (- b) a))
(if (<= b 3.3e-65)
(* (/ 0.5 a) (- (sqrt (fma (* -4.0 c) a (* b b))) b))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -9.2e+113) {
tmp = fma(((c / b) / b), b, (-b / a));
} else if (b <= 3.3e-65) {
tmp = (0.5 / a) * (sqrt(fma((-4.0 * c), a, (b * b))) - b);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -9.2e+113) tmp = fma(Float64(Float64(c / b) / b), b, Float64(Float64(-b) / a)); elseif (b <= 3.3e-65) tmp = Float64(Float64(0.5 / a) * Float64(sqrt(fma(Float64(-4.0 * c), a, Float64(b * b))) - b)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -9.2e+113], N[(N[(N[(c / b), $MachinePrecision] / b), $MachinePrecision] * b + N[((-b) / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.3e-65], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -9.2 \cdot 10^{+113}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{c}{b}}{b}, b, \frac{-b}{a}\right)\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{-65}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)} - b\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -9.19999999999999987e113Initial program 55.5%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
*-lft-identityN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
distribute-frac-negN/A
lower-/.f64N/A
lower-neg.f6496.8
Applied rewrites96.8%
if -9.19999999999999987e113 < b < 3.3000000000000001e-65Initial program 83.1%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6483.0
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6483.0
Applied rewrites83.0%
if 3.3000000000000001e-65 < b Initial program 22.2%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6483.4
Applied rewrites83.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.8e-117)
(fma (/ (/ c b) b) b (/ (- b) a))
(if (<= b 3.3e-65)
(/ (- (sqrt (* -4.0 (* a c))) b) (* 2.0 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-117) {
tmp = fma(((c / b) / b), b, (-b / a));
} else if (b <= 3.3e-65) {
tmp = (sqrt((-4.0 * (a * c))) - b) / (2.0 * a);
} else {
tmp = -c / b;
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b <= -1.8e-117) tmp = fma(Float64(Float64(c / b) / b), b, Float64(Float64(-b) / a)); elseif (b <= 3.3e-65) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(-c) / b); end return tmp end
code[a_, b_, c_] := If[LessEqual[b, -1.8e-117], N[(N[(N[(c / b), $MachinePrecision] / b), $MachinePrecision] * b + N[((-b) / a), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.3e-65], N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.8 \cdot 10^{-117}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\frac{c}{b}}{b}, b, \frac{-b}{a}\right)\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{-65}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.8e-117Initial program 72.1%
Taylor expanded in b around -inf
mul-1-negN/A
distribute-rgt-inN/A
distribute-neg-inN/A
mul-1-negN/A
distribute-lft-neg-outN/A
remove-double-negN/A
associate-*l/N/A
*-lft-identityN/A
lower-fma.f64N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
lower-/.f64N/A
distribute-frac-negN/A
lower-/.f64N/A
lower-neg.f6491.9
Applied rewrites91.9%
if -1.8e-117 < b < 3.3000000000000001e-65Initial program 76.1%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6476.1
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval76.1
Applied rewrites76.1%
Taylor expanded in a around inf
lower-*.f64N/A
lower-*.f6474.5
Applied rewrites74.5%
if 3.3000000000000001e-65 < b Initial program 22.2%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6483.4
Applied rewrites83.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.8e-117)
(* b (+ (/ -1.0 a) (/ c (* b b))))
(if (<= b 3.3e-65)
(/ (- (sqrt (* -4.0 (* a c))) b) (* 2.0 a))
(/ (- c) b))))
double code(double a, double b, double c) {
double tmp;
if (b <= -1.8e-117) {
tmp = b * ((-1.0 / a) + (c / (b * b)));
} else if (b <= 3.3e-65) {
tmp = (sqrt((-4.0 * (a * c))) - b) / (2.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 <= (-1.8d-117)) then
tmp = b * (((-1.0d0) / a) + (c / (b * b)))
else if (b <= 3.3d-65) then
tmp = (sqrt(((-4.0d0) * (a * c))) - b) / (2.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 <= -1.8e-117) {
tmp = b * ((-1.0 / a) + (c / (b * b)));
} else if (b <= 3.3e-65) {
tmp = (Math.sqrt((-4.0 * (a * c))) - b) / (2.0 * a);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -1.8e-117: tmp = b * ((-1.0 / a) + (c / (b * b))) elif b <= 3.3e-65: tmp = (math.sqrt((-4.0 * (a * c))) - b) / (2.0 * a) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -1.8e-117) tmp = Float64(b * Float64(Float64(-1.0 / a) + Float64(c / Float64(b * b)))); elseif (b <= 3.3e-65) tmp = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b) / Float64(2.0 * a)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b <= -1.8e-117) tmp = b * ((-1.0 / a) + (c / (b * b))); elseif (b <= 3.3e-65) tmp = (sqrt((-4.0 * (a * c))) - b) / (2.0 * a); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -1.8e-117], N[(b * N[(N[(-1.0 / a), $MachinePrecision] + N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[b, 3.3e-65], N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.8 \cdot 10^{-117}:\\
\;\;\;\;b \cdot \left(\frac{-1}{a} + \frac{c}{b \cdot b}\right)\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{-65}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -1.8e-117Initial program 72.1%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6472.1
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval72.2
Applied rewrites72.2%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6491.2
Applied rewrites91.2%
if -1.8e-117 < b < 3.3000000000000001e-65Initial program 76.1%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6476.1
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
metadata-eval76.1
Applied rewrites76.1%
Taylor expanded in a around inf
lower-*.f64N/A
lower-*.f6474.5
Applied rewrites74.5%
if 3.3000000000000001e-65 < b Initial program 22.2%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6483.4
Applied rewrites83.4%
Final simplification83.7%
(FPCore (a b c) :precision binary64 (if (<= b -5e-310) (/ (- b) a) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b <= -5e-310) {
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 <= (-5d-310)) 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 <= -5e-310) {
tmp = -b / a;
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b <= -5e-310: tmp = -b / a else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b <= -5e-310) 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 <= -5e-310) tmp = -b / a; else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[LessEqual[b, -5e-310], N[((-b) / a), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
if b < -4.999999999999985e-310Initial program 73.4%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6471.8
Applied rewrites71.8%
if -4.999999999999985e-310 < b Initial program 39.5%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6460.3
Applied rewrites60.3%
(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 57.1%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6438.5
Applied rewrites38.5%
(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(Float64(4.0 * 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[(N[(4.0 * a), $MachinePrecision] * c), $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 - \left(4 \cdot a\right) \cdot c}\\
\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 2024318
(FPCore (a b c)
:name "The quadratic formula (r1)"
:precision binary64
:alt
(! :herbie-platform default (let ((d (- (* b b) (* (* 4 a) c)))) (let ((r1 (/ (+ (- b) (sqrt d)) (* 2 a)))) (let ((r2 (/ (- (- b) (sqrt d)) (* 2 a)))) (if (< b 0) r1 (/ c (* a r2)))))))
(/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)))