
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- 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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-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 = (2.0d0 * c) / (-b - t_0)
else
tmp = (-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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-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 = (2.0 * c) / (-b - t_0) else: tmp = (-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(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = 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 = (2.0 * c) / (-b - t_0); else tmp = (-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[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (+ (- 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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-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 = (2.0d0 * c) / (-b - t_0)
else
tmp = (-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 = (2.0 * c) / (-b - t_0);
} else {
tmp = (-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 = (2.0 * c) / (-b - t_0) else: tmp = (-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(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp = 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 = (2.0 * c) / (-b - t_0); else tmp = (-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[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + t\_0}{2 \cdot a}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma (* a c) -4.0 (* b b)))) (t_1 (/ (* -2.0 c) (+ t_0 b))))
(if (<= b -2.8e+125)
(if (>= b 0.0) t_1 (* (/ (- (- b) b) a) 0.5))
(if (<= b 1.9e+112)
(if (>= b 0.0) t_1 (* (/ (- t_0 b) a) 0.5))
(if (>= b 0.0) (/ (- c) b) (/ (+ (- b) (sqrt (* b b))) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma((a * c), -4.0, (b * b)));
double t_1 = (-2.0 * c) / (t_0 + b);
double tmp_1;
if (b <= -2.8e+125) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = ((-b - b) / a) * 0.5;
}
tmp_1 = tmp_2;
} else if (b <= 1.9e+112) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_1;
} else {
tmp_3 = ((t_0 - b) / a) * 0.5;
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (-b + sqrt((b * b))) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(Float64(a * c), -4.0, Float64(b * b))) t_1 = Float64(Float64(-2.0 * c) / Float64(t_0 + b)) tmp_1 = 0.0 if (b <= -2.8e+125) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(Float64(Float64(Float64(-b) - b) / a) * 0.5); end tmp_1 = tmp_2; elseif (b <= 1.9e+112) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = t_1; else tmp_3 = Float64(Float64(Float64(t_0 - b) / a) * 0.5); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(-c) / b); else tmp_1 = Float64(Float64(Float64(-b) + sqrt(Float64(b * b))) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2.8e+125], If[GreaterEqual[b, 0.0], t$95$1, N[(N[(N[((-b) - b), $MachinePrecision] / a), $MachinePrecision] * 0.5), $MachinePrecision]], If[LessEqual[b, 1.9e+112], If[GreaterEqual[b, 0.0], t$95$1, N[(N[(N[(t$95$0 - b), $MachinePrecision] / a), $MachinePrecision] * 0.5), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[((-b) + N[Sqrt[N[(b * b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}\\
t_1 := \frac{-2 \cdot c}{t\_0 + b}\\
\mathbf{if}\;b \leq -2.8 \cdot 10^{+125}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a} \cdot 0.5\\
\end{array}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{+112}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a} \cdot 0.5\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b}}{2 \cdot a}\\
\end{array}
\end{array}
if b < -2.8000000000000001e125Initial program 62.9%
Taylor expanded in a around 0
Applied rewrites62.9%
Taylor expanded in b around -inf
Applied rewrites96.2%
if -2.8000000000000001e125 < b < 1.90000000000000004e112Initial program 85.8%
Taylor expanded in a around 0
Applied rewrites85.8%
if 1.90000000000000004e112 < b Initial program 46.6%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
Taylor expanded in a around 0
unpow2N/A
lower-*.f6498.2
Applied rewrites98.2%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6498.2
Applied rewrites98.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma (* a c) -4.0 (* b b)))))
(if (<= b -2.8e+125)
(if (>= b 0.0) (/ (* -2.0 c) (+ t_0 b)) (* (/ (- (- b) b) a) 0.5))
(if (<= b 1.9e+112)
(if (>= b 0.0)
(* c (/ -2.0 (+ (sqrt (fma -4.0 (* a c) (* b b))) b)))
(* (/ (- t_0 b) a) 0.5))
(if (>= b 0.0) (/ (- c) b) (/ (+ (- b) (sqrt (* b b))) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma((a * c), -4.0, (b * b)));
double tmp_1;
if (b <= -2.8e+125) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-2.0 * c) / (t_0 + b);
} else {
tmp_2 = ((-b - b) / a) * 0.5;
}
tmp_1 = tmp_2;
} else if (b <= 1.9e+112) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = c * (-2.0 / (sqrt(fma(-4.0, (a * c), (b * b))) + b));
} else {
tmp_3 = ((t_0 - b) / a) * 0.5;
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (-b + sqrt((b * b))) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(Float64(a * c), -4.0, Float64(b * b))) tmp_1 = 0.0 if (b <= -2.8e+125) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-2.0 * c) / Float64(t_0 + b)); else tmp_2 = Float64(Float64(Float64(Float64(-b) - b) / a) * 0.5); end tmp_1 = tmp_2; elseif (b <= 1.9e+112) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(c * Float64(-2.0 / Float64(sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) + b))); else tmp_3 = Float64(Float64(Float64(t_0 - b) / a) * 0.5); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(-c) / b); else tmp_1 = Float64(Float64(Float64(-b) + sqrt(Float64(b * b))) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -2.8e+125], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision], N[(N[(N[((-b) - b), $MachinePrecision] / a), $MachinePrecision] * 0.5), $MachinePrecision]], If[LessEqual[b, 1.9e+112], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$0 - b), $MachinePrecision] / a), $MachinePrecision] * 0.5), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[((-b) + N[Sqrt[N[(b * b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)}\\
\mathbf{if}\;b \leq -2.8 \cdot 10^{+125}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{t\_0 + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a} \cdot 0.5\\
\end{array}\\
\mathbf{elif}\;b \leq 1.9 \cdot 10^{+112}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{\sqrt{\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)} + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a} \cdot 0.5\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b}}{2 \cdot a}\\
\end{array}
\end{array}
if b < -2.8000000000000001e125Initial program 62.9%
Taylor expanded in a around 0
Applied rewrites62.9%
Taylor expanded in b around -inf
Applied rewrites96.2%
if -2.8000000000000001e125 < b < 1.90000000000000004e112Initial program 85.8%
Taylor expanded in a around 0
Applied rewrites85.8%
Applied rewrites85.7%
if 1.90000000000000004e112 < b Initial program 46.6%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
Taylor expanded in a around 0
unpow2N/A
lower-*.f6498.2
Applied rewrites98.2%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6498.2
Applied rewrites98.2%
(FPCore (a b c)
:precision binary64
(if (<= b 1.9e+112)
(if (>= b 0.0)
(* c (/ -2.0 (+ (sqrt (fma -4.0 (* a c) (* b b))) b)))
(* (/ (- (sqrt (fma (* a c) -4.0 (* b b))) b) a) 0.5))
(if (>= b 0.0) (/ (- c) b) (/ (+ (- b) (sqrt (* b b))) (* 2.0 a)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= 1.9e+112) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * (-2.0 / (sqrt(fma(-4.0, (a * c), (b * b))) + b));
} else {
tmp_2 = ((sqrt(fma((a * c), -4.0, (b * b))) - b) / a) * 0.5;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (-b + sqrt((b * b))) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= 1.9e+112) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c * Float64(-2.0 / Float64(sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) + b))); else tmp_2 = Float64(Float64(Float64(sqrt(fma(Float64(a * c), -4.0, Float64(b * b))) - b) / a) * 0.5); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(-c) / b); else tmp_1 = Float64(Float64(Float64(-b) + sqrt(Float64(b * b))) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, 1.9e+112], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision] * 0.5), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[((-b) + N[Sqrt[N[(b * b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.9 \cdot 10^{+112}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{\sqrt{\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)} + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(a \cdot c, -4, b \cdot b\right)} - b}{a} \cdot 0.5\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b}}{2 \cdot a}\\
\end{array}
\end{array}
if b < 1.90000000000000004e112Initial program 80.3%
Taylor expanded in a around 0
Applied rewrites80.3%
Applied rewrites80.2%
if 1.90000000000000004e112 < b Initial program 46.6%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
Taylor expanded in a around 0
unpow2N/A
lower-*.f6498.2
Applied rewrites98.2%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6498.2
Applied rewrites98.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (* a (/ c b))))
(if (<= b 3.7e-29)
(* (/ (- (sqrt (fma (* c a) -4.0 (* b b))) b) a) 0.5)
(if (>= b 0.0)
(/ (+ c c) (* 2.0 (- t_0 b)))
(/ (* t_0 -2.0) (* 2.0 a))))))
double code(double a, double b, double c) {
double t_0 = a * (c / b);
double tmp;
if (b <= 3.7e-29) {
tmp = ((sqrt(fma((c * a), -4.0, (b * b))) - b) / a) * 0.5;
} else if (b >= 0.0) {
tmp = (c + c) / (2.0 * (t_0 - b));
} else {
tmp = (t_0 * -2.0) / (2.0 * a);
}
return tmp;
}
function code(a, b, c) t_0 = Float64(a * Float64(c / b)) tmp = 0.0 if (b <= 3.7e-29) tmp = Float64(Float64(Float64(sqrt(fma(Float64(c * a), -4.0, Float64(b * b))) - b) / a) * 0.5); elseif (b >= 0.0) tmp = Float64(Float64(c + c) / Float64(2.0 * Float64(t_0 - b))); else tmp = Float64(Float64(t_0 * -2.0) / Float64(2.0 * a)); end return tmp end
code[a_, b_, c_] := Block[{t$95$0 = N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 3.7e-29], N[(N[(N[(N[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0 + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision] * 0.5), $MachinePrecision], If[GreaterEqual[b, 0.0], N[(N[(c + c), $MachinePrecision] / N[(2.0 * N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \frac{c}{b}\\
\mathbf{if}\;b \leq 3.7 \cdot 10^{-29}:\\
\;\;\;\;\frac{\sqrt{\mathsf{fma}\left(c \cdot a, -4, b \cdot b\right)} - b}{a} \cdot 0.5\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c + c}{2 \cdot \left(t\_0 - b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 \cdot -2}{2 \cdot a}\\
\end{array}
\end{array}
if b < 3.6999999999999997e-29Initial program 77.6%
Taylor expanded in a around 0
Applied rewrites77.6%
Applied rewrites74.4%
Taylor expanded in a around 0
Applied rewrites74.4%
if 3.6999999999999997e-29 < b Initial program 64.2%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6491.5
Applied rewrites91.5%
Taylor expanded in a around 0
*-commutativeN/A
lower-*.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6491.5
Applied rewrites91.5%
lift-*.f64N/A
count-2-revN/A
lower-+.f6491.5
Applied rewrites91.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (/ (+ (- b) (sqrt (* b b))) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (-b + sqrt((b * b))) / (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) :: tmp
if (b >= 0.0d0) then
tmp = -c / b
else
tmp = (-b + sqrt((b * b))) / (2.0d0 * a)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (-b + Math.sqrt((b * b))) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = (-b + math.sqrt((b * b))) / (2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(Float64(-b) + sqrt(Float64(b * b))) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = (-b + sqrt((b * b))) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[((-b) + N[Sqrt[N[(b * b), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{b \cdot b}}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 73.3%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6472.3
Applied rewrites72.3%
Taylor expanded in a around 0
unpow2N/A
lower-*.f6460.9
Applied rewrites60.9%
Taylor expanded in a around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6460.7
Applied rewrites60.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ b a) (* (/ 0.5 a) (- (sqrt (* b b)) b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = b / a;
} else {
tmp = (0.5 / a) * (sqrt((b * b)) - 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 >= 0.0d0) then
tmp = b / a
else
tmp = (0.5d0 / a) * (sqrt((b * b)) - b)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = b / a;
} else {
tmp = (0.5 / a) * (Math.sqrt((b * b)) - b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = b / a else: tmp = (0.5 / a) * (math.sqrt((b * b)) - b) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(b / a); else tmp = Float64(Float64(0.5 / a) * Float64(sqrt(Float64(b * b)) - b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = b / a; else tmp = (0.5 / a) * (sqrt((b * b)) - b); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(b / a), $MachinePrecision], N[(N[(0.5 / a), $MachinePrecision] * N[(N[Sqrt[N[(b * b), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{a} \cdot \left(\sqrt{b \cdot b} - b\right)\\
\end{array}
\end{array}
Initial program 73.3%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
lower--.f64N/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f6472.3
Applied rewrites72.3%
Taylor expanded in a around 0
unpow2N/A
lower-*.f6460.9
Applied rewrites60.9%
Taylor expanded in b around -inf
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6429.3
Applied rewrites29.3%
Applied rewrites30.0%
herbie shell --seed 2024305
(FPCore (a b c)
:name "jeff quadratic root 2"
:precision binary64
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c))))) (/ (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a))))