
(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 8 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
(if (<= b -6.5e+81)
(if (>= b 0.0) (/ (- b) a) (/ (- (- b) b) (* 2.0 a)))
(if (<= b 1.08e+36)
(if (>= b 0.0)
(/ (* 2.0 (- c)) (+ b (sqrt (- (* b b) (* (* 4.0 a) c)))))
(/
(+ (- b) (sqrt (pow (pow (fma (* -4.0 c) a (* b b)) -1.0) -1.0)))
(* 2.0 a)))
(if (>= b 0.0) (/ (* 2.0 c) (* -2.0 b)) (/ (+ (- b) (- b)) (* 2.0 a))))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -6.5e+81) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = (-b - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 1.08e+36) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (2.0 * -c) / (b + sqrt(((b * b) - ((4.0 * a) * c))));
} else {
tmp_3 = (-b + sqrt(pow(pow(fma((-4.0 * c), a, (b * b)), -1.0), -1.0))) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-2.0 * b);
} else {
tmp_1 = (-b + -b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -6.5e+81) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 1.08e+36) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(2.0 * Float64(-c)) / Float64(b + sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))))); else tmp_3 = Float64(Float64(Float64(-b) + sqrt(((fma(Float64(-4.0 * c), a, Float64(b * b)) ^ -1.0) ^ -1.0))) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(-2.0 * b)); else tmp_1 = Float64(Float64(Float64(-b) + Float64(-b)) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -6.5e+81], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1.08e+36], If[GreaterEqual[b, 0.0], N[(N[(2.0 * (-c)), $MachinePrecision] / N[(b + N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + N[Sqrt[N[Power[N[Power[N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision], -1.0], $MachinePrecision], -1.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -6.5 \cdot 10^{+81}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.08 \cdot 10^{+36}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \left(-c\right)}{b + \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{{\left({\left(\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)\right)}^{-1}\right)}^{-1}}}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\
\end{array}
\end{array}
if b < -6.4999999999999996e81Initial program 59.2%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6459.2
Applied rewrites59.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6490.7
Applied rewrites90.7%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6490.7
Applied rewrites90.7%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6490.7
Applied rewrites90.7%
if -6.4999999999999996e81 < b < 1.08000000000000001e36Initial program 83.6%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6483.6
lift--.f64N/A
sub-negN/A
+-commutativeN/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-neg-inN/A
Applied rewrites83.6%
if 1.08000000000000001e36 < b Initial program 58.7%
Taylor expanded in a around 0
lower-*.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6495.2
Applied rewrites95.2%
Final simplification88.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma -4.0 (* c a) (* b b)))))
(if (<= b -6.5e+81)
(if (>= b 0.0) (/ (- b) a) (/ (- (- b) b) (* 2.0 a)))
(if (<= b 1.08e+36)
(if (>= b 0.0) (/ (* -2.0 c) (+ t_0 b)) (* (/ (- t_0 b) a) 0.5))
(if (>= b 0.0)
(/ (* 2.0 c) (* -2.0 b))
(/ (+ (- b) (- b)) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma(-4.0, (c * a), (b * b)));
double tmp_1;
if (b <= -6.5e+81) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = (-b - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 1.08e+36) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-2.0 * c) / (t_0 + b);
} else {
tmp_3 = ((t_0 - b) / a) * 0.5;
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (-2.0 * b);
} else {
tmp_1 = (-b + -b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(-4.0, Float64(c * a), Float64(b * b))) tmp_1 = 0.0 if (b <= -6.5e+81) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 1.08e+36) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(-2.0 * c) / Float64(t_0 + 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(2.0 * c) / Float64(-2.0 * b)); else tmp_1 = Float64(Float64(Float64(-b) + Float64(-b)) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -6.5e+81], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1.08e+36], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(t$95$0 - b), $MachinePrecision] / a), $MachinePrecision] * 0.5), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)}\\
\mathbf{if}\;b \leq -6.5 \cdot 10^{+81}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.08 \cdot 10^{+36}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{t\_0 + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a} \cdot 0.5\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\
\end{array}
\end{array}
if b < -6.4999999999999996e81Initial program 59.2%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6459.2
Applied rewrites59.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6490.7
Applied rewrites90.7%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6490.7
Applied rewrites90.7%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6490.7
Applied rewrites90.7%
if -6.4999999999999996e81 < b < 1.08000000000000001e36Initial program 83.6%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6465.6
Applied rewrites65.6%
Taylor expanded in a around 0
Applied rewrites83.6%
if 1.08000000000000001e36 < b Initial program 58.7%
Taylor expanded in a around 0
lower-*.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6495.2
Applied rewrites95.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma -4.0 (* c a) (* b b)))))
(if (<= b -5.8e-75)
(if (>= b 0.0) (/ (- b) a) (/ (- (- b) b) (* 2.0 a)))
(if (<= b 6e-78)
(if (>= b 0.0) (/ (* -2.0 c) (- t_0 b)) (/ (* -2.0 c) (+ t_0 b)))
(if (>= b 0.0)
(/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))
(/ (+ (- b) (- b)) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma(-4.0, (c * a), (b * b)));
double tmp_1;
if (b <= -5.8e-75) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = (-b - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b <= 6e-78) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-2.0 * c) / (t_0 - b);
} else {
tmp_3 = (-2.0 * c) / (t_0 + b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_1 = (-b + -b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(-4.0, Float64(c * a), Float64(b * b))) tmp_1 = 0.0 if (b <= -5.8e-75) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b <= 6e-78) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(-2.0 * c) / Float64(t_0 - b)); else tmp_3 = Float64(Float64(-2.0 * c) / Float64(t_0 + b)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_1 = Float64(Float64(Float64(-b) + Float64(-b)) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -5.8e-75], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 6e-78], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(-4, c \cdot a, b \cdot b\right)}\\
\mathbf{if}\;b \leq -5.8 \cdot 10^{-75}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 6 \cdot 10^{-78}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{t\_0 - b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-2 \cdot c}{t\_0 + b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\
\end{array}
\end{array}
if b < -5.8000000000000003e-75Initial program 69.7%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6469.7
Applied rewrites69.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6482.6
Applied rewrites82.6%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6482.6
Applied rewrites82.6%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6482.6
Applied rewrites82.6%
if -5.8000000000000003e-75 < b < 5.99999999999999975e-78Initial program 80.4%
Applied rewrites75.0%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
Applied rewrites74.8%
lift-*.f64N/A
*-commutativeN/A
lift--.f64N/A
flip--N/A
lift-/.f64N/A
frac-timesN/A
lower-/.f64N/A
Applied rewrites62.3%
Taylor expanded in a around 0
Applied rewrites68.0%
if 5.99999999999999975e-78 < b Initial program 63.4%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6487.3
Applied rewrites87.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6487.3
Applied rewrites87.3%
(FPCore (a b c)
:precision binary64
(if (<= b -7.6e-39)
(if (>= b 0.0) (/ (- b) a) (/ (- (- b) b) (* 2.0 a)))
(if (>= b 0.0)
(/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))
(/ (+ (- b) (sqrt (* -4.0 (* c a)))) (* 2.0 a)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -7.6e-39) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = (-b - b) / (2.0 * a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_1 = (-b + sqrt((-4.0 * (c * a)))) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -7.6e-39) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(2.0 * a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_1 = Float64(Float64(Float64(-b) + sqrt(Float64(-4.0 * Float64(c * a)))) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -7.6e-39], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + N[Sqrt[N[(-4.0 * N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.6 \cdot 10^{-39}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \sqrt{-4 \cdot \left(c \cdot a\right)}}{2 \cdot a}\\
\end{array}
\end{array}
if b < -7.6000000000000004e-39Initial program 69.0%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6469.0
Applied rewrites69.0%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6485.1
Applied rewrites85.1%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6485.1
Applied rewrites85.1%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6485.1
Applied rewrites85.1%
if -7.6000000000000004e-39 < b Initial program 71.0%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6475.1
Applied rewrites75.1%
Taylor expanded in a around inf
lower-*.f64N/A
*-commutativeN/A
lower-*.f6471.6
Applied rewrites71.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b)))) (/ (+ (- b) (- b)) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp = (-b + -b) / (2.0 * a);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp = Float64(Float64(Float64(-b) + Float64(-b)) / Float64(2.0 * a)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 70.4%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6473.2
Applied rewrites73.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6466.9
Applied rewrites66.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (* -2.0 b)) (/ (+ (- b) (- b)) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (-2.0 * b);
} else {
tmp = (-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 = (2.0d0 * c) / ((-2.0d0) * b)
else
tmp = (-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 = (2.0 * c) / (-2.0 * b);
} else {
tmp = (-b + -b) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (-2.0 * b) else: tmp = (-b + -b) / (2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(-2.0 * b)); else tmp = Float64(Float64(Float64(-b) + Float64(-b)) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (2.0 * c) / (-2.0 * b); else tmp = (-b + -b) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[((-b) + (-b)), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) + \left(-b\right)}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 70.4%
Taylor expanded in a around 0
lower-*.f6473.1
Applied rewrites73.1%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6466.9
Applied rewrites66.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ (- (- b) b) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = (-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 = -b / a
else
tmp = (-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 = -b / a;
} else {
tmp = (-b - b) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = (-b - b) / (2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(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 = -b / a; else tmp = (-b - b) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 70.4%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6473.2
Applied rewrites73.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6466.9
Applied rewrites66.9%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6432.5
Applied rewrites32.5%
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6432.5
Applied rewrites32.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (* (/ 0.5 a) (- (- b) b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = (0.5 / a) * (-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) * (-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) * (-b - b);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = (0.5 / a) * (-b - b) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(0.5 / a) * Float64(Float64(-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) * (-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[((-b) - 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(\left(-b\right) - b\right)\\
\end{array}
\end{array}
Initial program 70.4%
Taylor expanded in a around 0
distribute-lft-out--N/A
lower-*.f64N/A
sub-negN/A
associate-/l*N/A
lower-fma.f64N/A
lower-/.f64N/A
lower-neg.f6473.2
Applied rewrites73.2%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6466.9
Applied rewrites66.9%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6432.5
Applied rewrites32.5%
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
metadata-evalN/A
lower-/.f6432.4
lift-+.f64N/A
+-commutativeN/A
lift-neg.f64N/A
unsub-negN/A
lower--.f6432.4
Applied rewrites32.4%
herbie shell --seed 2024307
(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))))