
(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
(let* ((t_0 (sqrt (fma (* a c) -4.0 (* b b)))) (t_1 (/ (- b) a)))
(if (<= b -2e+143)
(if (>= b 0.0) t_1 t_1)
(if (<= b 1e+110)
(if (>= b 0.0) (/ (* -2.0 c) (+ t_0 b)) (* 0.5 (/ (- t_0 b) a)))
(if (>= b 0.0)
(/ (* c 2.0) (* (fma a (/ c b) (- b)) 2.0))
(/ (- (- b) b) (* a 2.0)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma((a * c), -4.0, (b * b)));
double t_1 = -b / a;
double tmp_1;
if (b <= -2e+143) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= 1e+110) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-2.0 * c) / (t_0 + b);
} else {
tmp_3 = 0.5 * ((t_0 - b) / a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (fma(a, (c / b), -b) * 2.0);
} else {
tmp_1 = (-b - b) / (a * 2.0);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(Float64(a * c), -4.0, Float64(b * b))) t_1 = Float64(Float64(-b) / a) tmp_1 = 0.0 if (b <= -2e+143) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= 1e+110) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(-2.0 * c) / Float64(t_0 + b)); else tmp_3 = Float64(0.5 * Float64(Float64(t_0 - b) / a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(fma(a, Float64(c / b), Float64(-b)) * 2.0)); else tmp_1 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); 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[((-b) / a), $MachinePrecision]}, If[LessEqual[b, -2e+143], If[GreaterEqual[b, 0.0], t$95$1, t$95$1], If[LessEqual[b, 1e+110], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(t$95$0 - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $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{-b}{a}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+143}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{+110}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{t\_0 + b}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{t\_0 - b}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(a, \frac{c}{b}, -b\right) \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -2e143Initial program 46.5%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6446.5
Applied rewrites46.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
if -2e143 < b < 1e110Initial program 88.1%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6469.3
Applied rewrites69.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6456.5
Applied rewrites56.5%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6427.2
Applied rewrites27.2%
Taylor expanded in c around 0
Applied rewrites88.1%
if 1e110 < b Initial program 45.5%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6496.8
Applied rewrites96.8%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6496.8
Applied rewrites96.8%
Taylor expanded in c 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.f6496.8
Applied rewrites96.8%
Final simplification91.8%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (- (sqrt (fma -4.0 (* a c) (* b b))) b)) (t_1 (/ (- b) a)))
(if (<= b -2e+143)
(if (>= b 0.0) t_1 t_1)
(if (<= b 2.6e-86)
(if (>= b 0.0) (* (/ c t_0) -2.0) (* (/ t_0 a) 0.5))
(if (>= b 0.0)
(/ (* -2.0 c) (+ (fma (* -2.0 a) (/ c b) b) b))
(/ (- (- b) b) (* a 2.0)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma(-4.0, (a * c), (b * b))) - b;
double t_1 = -b / a;
double tmp_1;
if (b <= -2e+143) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= 2.6e-86) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c / t_0) * -2.0;
} else {
tmp_3 = (t_0 / a) * 0.5;
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (-2.0 * c) / (fma((-2.0 * a), (c / b), b) + b);
} else {
tmp_1 = (-b - b) / (a * 2.0);
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) - b) t_1 = Float64(Float64(-b) / a) tmp_1 = 0.0 if (b <= -2e+143) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= 2.6e-86) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c / t_0) * -2.0); else tmp_3 = Float64(Float64(t_0 / a) * 0.5); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(-2.0 * c) / Float64(fma(Float64(-2.0 * a), Float64(c / b), b) + b)); else tmp_1 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]}, Block[{t$95$1 = N[((-b) / a), $MachinePrecision]}, If[LessEqual[b, -2e+143], If[GreaterEqual[b, 0.0], t$95$1, t$95$1], If[LessEqual[b, 2.6e-86], If[GreaterEqual[b, 0.0], N[(N[(c / t$95$0), $MachinePrecision] * -2.0), $MachinePrecision], N[(N[(t$95$0 / a), $MachinePrecision] * 0.5), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(N[(N[(-2.0 * a), $MachinePrecision] * N[(c / b), $MachinePrecision] + b), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)} - b\\
t_1 := \frac{-b}{a}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+143}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{-86}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{t\_0} \cdot -2\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{a} \cdot 0.5\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{\mathsf{fma}\left(-2 \cdot a, \frac{c}{b}, b\right) + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -2e143Initial program 46.5%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6446.5
Applied rewrites46.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
if -2e143 < b < 2.6000000000000001e-86Initial program 84.7%
Applied rewrites79.9%
Taylor expanded in c around 0
Applied rewrites79.9%
if 2.6000000000000001e-86 < b Initial program 69.6%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6486.7
Applied rewrites86.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6486.7
Applied rewrites86.7%
Applied rewrites86.7%
Final simplification85.8%
(FPCore (a b c)
:precision binary64
(if (<= b -4.7e-66)
(if (>= b 0.0) (/ (- b) a) (* (- (/ c (* b b)) (/ 1.0 a)) b))
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (fma (* -2.0 a) (/ c b) b)))
(/ (- (sqrt (* -4.0 (* a c))) b) (* a 2.0)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -4.7e-66) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = ((c / (b * b)) - (1.0 / a)) * b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (-b - fma((-2.0 * a), (c / b), b));
} else {
tmp_1 = (sqrt((-4.0 * (a * c))) - b) / (a * 2.0);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -4.7e-66) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = Float64(Float64(Float64(c / Float64(b * b)) - Float64(1.0 / a)) * b); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - fma(Float64(-2.0 * a), Float64(c / b), b))); else tmp_1 = Float64(Float64(sqrt(Float64(-4.0 * Float64(a * c))) - b) / Float64(a * 2.0)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -4.7e-66], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[(N[(c / N[(b * b), $MachinePrecision]), $MachinePrecision] - N[(1.0 / a), $MachinePrecision]), $MachinePrecision] * b), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[(N[(-2.0 * a), $MachinePrecision] * N[(c / b), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -4.7 \cdot 10^{-66}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\left(\frac{c}{b \cdot b} - \frac{1}{a}\right) \cdot b\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \mathsf{fma}\left(-2 \cdot a, \frac{c}{b}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{-4 \cdot \left(a \cdot c\right)} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -4.6999999999999999e-66Initial program 71.9%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6471.9
Applied rewrites71.9%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6488.6
Applied rewrites88.6%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6488.6
Applied rewrites88.6%
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
sub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6489.0
Applied rewrites89.0%
if -4.6999999999999999e-66 < b Initial program 72.9%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6472.6
Applied rewrites72.6%
Taylor expanded in c around inf
lower-*.f64N/A
lower-*.f6470.3
Applied rewrites70.3%
Final simplification76.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* -2.0 c) (+ (fma (* -2.0 a) (/ c b) b) b)) (/ (- (- b) b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (-2.0 * c) / (fma((-2.0 * a), (c / b), b) + b);
} else {
tmp = (-b - b) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-2.0 * c) / Float64(fma(Float64(-2.0 * a), Float64(c / b), b) + b)); else tmp = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(N[(N[(-2.0 * a), $MachinePrecision] * N[(c / b), $MachinePrecision] + b), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{\mathsf{fma}\left(-2 \cdot a, \frac{c}{b}, b\right) + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 72.6%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6472.4
Applied rewrites72.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6471.7
Applied rewrites71.7%
Applied rewrites71.7%
Final simplification71.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* c 2.0) (* (fma a (/ c b) (- b)) 2.0)) (/ (- (- b) b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (fma(a, (c / b), -b) * 2.0);
} else {
tmp = (-b - b) / (a * 2.0);
}
return tmp;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * 2.0) / Float64(fma(a, Float64(c / b), Float64(-b)) * 2.0)); else tmp = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(a, \frac{c}{b}, -b\right) \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 72.6%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6472.4
Applied rewrites72.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6471.7
Applied rewrites71.7%
Taylor expanded in c 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.f6471.7
Applied rewrites71.7%
Final simplification71.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* c 2.0) (* -2.0 b)) (/ (- (- b) b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (-2.0 * b);
} else {
tmp = (-b - b) / (a * 2.0);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b >= 0.0d0) then
tmp = (c * 2.0d0) / ((-2.0d0) * b)
else
tmp = (-b - b) / (a * 2.0d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (-2.0 * b);
} else {
tmp = (-b - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (c * 2.0) / (-2.0 * b) else: tmp = (-b - b) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * 2.0) / Float64(-2.0 * b)); else tmp = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (c * 2.0) / (-2.0 * b); else tmp = (-b - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(-2.0 * b), $MachinePrecision]), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{-2 \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 72.6%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6472.4
Applied rewrites72.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6471.7
Applied rewrites71.7%
Taylor expanded in c around 0
lower-*.f6471.3
Applied rewrites71.3%
Final simplification71.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* (/ -2.0 (* 2.0 b)) c) (/ (- (- b) b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (-2.0 / (2.0 * b)) * c;
} else {
tmp = (-b - b) / (a * 2.0);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: tmp
if (b >= 0.0d0) then
tmp = ((-2.0d0) / (2.0d0 * b)) * c
else
tmp = (-b - b) / (a * 2.0d0)
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 / (2.0 * b)) * c;
} else {
tmp = (-b - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (-2.0 / (2.0 * b)) * c else: tmp = (-b - b) / (a * 2.0) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-2.0 / Float64(2.0 * b)) * c); else tmp = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (-2.0 / (2.0 * b)) * c; else tmp = (-b - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(-2.0 / N[(2.0 * b), $MachinePrecision]), $MachinePrecision] * c), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2}{2 \cdot b} \cdot c\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 72.6%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6472.4
Applied rewrites72.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6471.7
Applied rewrites71.7%
Applied rewrites71.6%
Taylor expanded in c around 0
lower-*.f6471.3
Applied rewrites71.3%
Final simplification71.3%
(FPCore (a b c) :precision binary64 (let* ((t_0 (/ (- b) a))) (if (>= b 0.0) t_0 t_0)))
double code(double a, double b, double c) {
double t_0 = -b / a;
double tmp;
if (b >= 0.0) {
tmp = t_0;
} 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) :: tmp
t_0 = -b / a
if (b >= 0.0d0) then
tmp = t_0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = -b / a;
double tmp;
if (b >= 0.0) {
tmp = t_0;
} else {
tmp = t_0;
}
return tmp;
}
def code(a, b, c): t_0 = -b / a tmp = 0 if b >= 0.0: tmp = t_0 else: tmp = t_0 return tmp
function code(a, b, c) t_0 = Float64(Float64(-b) / a) tmp = 0.0 if (b >= 0.0) tmp = t_0; else tmp = t_0; end return tmp end
function tmp_2 = code(a, b, c) t_0 = -b / a; tmp = 0.0; if (b >= 0.0) tmp = t_0; else tmp = t_0; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-b) / a), $MachinePrecision]}, If[GreaterEqual[b, 0.0], t$95$0, t$95$0]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-b}{a}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
Initial program 72.6%
Taylor expanded in c around 0
+-commutativeN/A
associate-/l*N/A
associate-*r*N/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f6472.4
Applied rewrites72.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6471.7
Applied rewrites71.7%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6431.7
Applied rewrites31.7%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6431.7
Applied rewrites31.7%
herbie shell --seed 2024275
(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))))