
(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 7 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 (- (* b b) (* (* a 4.0) c)))) (t_1 (/ (- b) a)))
(if (<= b -1.55e+139)
(if (>= b 0.0) t_1 t_1)
(if (<= b 5.4e+117)
(if (>= b 0.0)
(/ (* (- c) 2.0) (+ t_0 b))
(/ (- (sqrt (/ 1.0 (/ 1.0 (fma (* -4.0 c) a (* b b))))) b) (* a 2.0)))
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (* (fma (* -2.0 (/ a b)) (/ c b) 1.0) b)))
(/ (- t_0 b) (* a 2.0)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((a * 4.0) * c)));
double t_1 = -b / a;
double tmp_1;
if (b <= -1.55e+139) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= 5.4e+117) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-c * 2.0) / (t_0 + b);
} else {
tmp_3 = (sqrt((1.0 / (1.0 / fma((-4.0 * c), a, (b * b))))) - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (-b - (fma((-2.0 * (a / b)), (c / b), 1.0) * b));
} else {
tmp_1 = (t_0 - b) / (a * 2.0);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) t_1 = Float64(Float64(-b) / a) tmp_1 = 0.0 if (b <= -1.55e+139) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= 5.4e+117) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(-c) * 2.0) / Float64(t_0 + b)); else tmp_3 = Float64(Float64(sqrt(Float64(1.0 / Float64(1.0 / fma(Float64(-4.0 * c), a, Float64(b * b))))) - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - Float64(fma(Float64(-2.0 * Float64(a / b)), Float64(c / b), 1.0) * b))); else tmp_1 = Float64(Float64(t_0 - b) / Float64(a * 2.0)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[((-b) / a), $MachinePrecision]}, If[LessEqual[b, -1.55e+139], If[GreaterEqual[b, 0.0], t$95$1, t$95$1], If[LessEqual[b, 5.4e+117], If[GreaterEqual[b, 0.0], N[(N[((-c) * 2.0), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(1.0 / N[(1.0 / N[(N[(-4.0 * c), $MachinePrecision] * a + N[(b * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[(N[(N[(-2.0 * N[(a / b), $MachinePrecision]), $MachinePrecision] * N[(c / b), $MachinePrecision] + 1.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}\\
t_1 := \frac{-b}{a}\\
\mathbf{if}\;b \leq -1.55 \cdot 10^{+139}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq 5.4 \cdot 10^{+117}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-c\right) \cdot 2}{t\_0 + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\frac{1}{\frac{1}{\mathsf{fma}\left(-4 \cdot c, a, b \cdot b\right)}}} - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \mathsf{fma}\left(-2 \cdot \frac{a}{b}, \frac{c}{b}, 1\right) \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.55e139Initial program 47.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6495.2
Applied rewrites95.2%
if -1.55e139 < b < 5.4000000000000005e117Initial program 85.3%
lift--.f64N/A
flip--N/A
clear-numN/A
lower-/.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
lower-/.f6485.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
Applied rewrites85.3%
if 5.4000000000000005e117 < b Initial program 47.5%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
unpow2N/A
times-fracN/A
associate-*r/N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6497.1
Applied rewrites97.1%
Final simplification89.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma -4.0 (* a c) (* b b)))) (t_1 (/ (- b) a)))
(if (<= b -1e+142)
(if (>= b 0.0) t_1 t_1)
(if (<= b 5.4e+117)
(if (>= b 0.0) (/ (* -2.0 c) (+ t_0 b)) (* 0.5 (/ (- t_0 b) a)))
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (* (fma (* -2.0 (/ a b)) (/ c b) 1.0) b)))
(/ (- (sqrt (- (* b b) (* (* a 4.0) c))) b) (* a 2.0)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(fma(-4.0, (a * c), (b * b)));
double t_1 = -b / a;
double tmp_1;
if (b <= -1e+142) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= 5.4e+117) {
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) / (-b - (fma((-2.0 * (a / b)), (c / b), 1.0) * b));
} else {
tmp_1 = (sqrt(((b * b) - ((a * 4.0) * c))) - b) / (a * 2.0);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) t_1 = Float64(Float64(-b) / a) tmp_1 = 0.0 if (b <= -1e+142) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= 5.4e+117) 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(Float64(-b) - Float64(fma(Float64(-2.0 * Float64(a / b)), Float64(c / b), 1.0) * b))); else tmp_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) - b) / Float64(a * 2.0)); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[((-b) / a), $MachinePrecision]}, If[LessEqual[b, -1e+142], If[GreaterEqual[b, 0.0], t$95$1, t$95$1], If[LessEqual[b, 5.4e+117], 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[((-b) - N[(N[(N[(-2.0 * N[(a / b), $MachinePrecision]), $MachinePrecision] * N[(c / b), $MachinePrecision] + 1.0), $MachinePrecision] * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - 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)}\\
t_1 := \frac{-b}{a}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+142}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq 5.4 \cdot 10^{+117}:\\
\;\;\;\;\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}{\left(-b\right) - \mathsf{fma}\left(-2 \cdot \frac{a}{b}, \frac{c}{b}, 1\right) \cdot b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.00000000000000005e142Initial program 47.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6495.2
Applied rewrites95.2%
if -1.00000000000000005e142 < b < 5.4000000000000005e117Initial program 85.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6460.3
Applied rewrites60.3%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6427.5
Applied rewrites27.5%
Taylor expanded in c around 0
Applied rewrites85.3%
if 5.4000000000000005e117 < b Initial program 47.5%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
associate-*r/N/A
associate-*r*N/A
unpow2N/A
times-fracN/A
associate-*r/N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
lower-/.f6497.1
Applied rewrites97.1%
Final simplification89.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (fma -4.0 (* a c) (* b b)))) (t_1 (/ (- b) a)))
(if (<= b -1e+142)
(if (>= b 0.0) t_1 t_1)
(if (<= b 5.4e+117)
(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(-4.0, (a * c), (b * b)));
double t_1 = -b / a;
double tmp_1;
if (b <= -1e+142) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= 5.4e+117) {
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(-4.0, Float64(a * c), Float64(b * b))) t_1 = Float64(Float64(-b) / a) tmp_1 = 0.0 if (b <= -1e+142) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= 5.4e+117) 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[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[((-b) / a), $MachinePrecision]}, If[LessEqual[b, -1e+142], If[GreaterEqual[b, 0.0], t$95$1, t$95$1], If[LessEqual[b, 5.4e+117], 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(-4, a \cdot c, b \cdot b\right)}\\
t_1 := \frac{-b}{a}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+142}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq 5.4 \cdot 10^{+117}:\\
\;\;\;\;\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 < -1.00000000000000005e142Initial program 47.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6495.2
Applied rewrites95.2%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6495.2
Applied rewrites95.2%
if -1.00000000000000005e142 < b < 5.4000000000000005e117Initial program 85.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6460.3
Applied rewrites60.3%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6427.5
Applied rewrites27.5%
Taylor expanded in c around 0
Applied rewrites85.3%
if 5.4000000000000005e117 < b Initial program 47.5%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6447.5
Applied rewrites47.5%
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.f6497.1
Applied rewrites97.1%
Final simplification89.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (- b) b) (* a 2.0))))
(if (<= b 1.3e-9)
(if (>= b 0.0) (/ (* (- c) 2.0) (+ (sqrt (* (* a c) -4.0)) b)) t_0)
(if (>= b 0.0) (/ (* c 2.0) (* (fma a (/ c b) (- b)) 2.0)) t_0))))
double code(double a, double b, double c) {
double t_0 = (-b - b) / (a * 2.0);
double tmp_1;
if (b <= 1.3e-9) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-c * 2.0) / (sqrt(((a * c) * -4.0)) + b);
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (fma(a, (c / b), -b) * 2.0);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= 1.3e-9) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(Float64(-c) * 2.0) / Float64(sqrt(Float64(Float64(a * c) * -4.0)) + b)); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(fma(a, Float64(c / b), Float64(-b)) * 2.0)); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.3e-9], If[GreaterEqual[b, 0.0], N[(N[((-c) * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(N[(a * c), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision], t$95$0], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{if}\;b \leq 1.3 \cdot 10^{-9}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-c\right) \cdot 2}{\sqrt{\left(a \cdot c\right) \cdot -4} + b}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\mathsf{fma}\left(a, \frac{c}{b}, -b\right) \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < 1.3000000000000001e-9Initial program 76.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6463.8
Applied rewrites63.8%
Taylor expanded in c around inf
*-commutativeN/A
lower-*.f64N/A
lower-*.f6460.6
Applied rewrites60.6%
if 1.3000000000000001e-9 < b Initial program 60.4%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6460.4
Applied rewrites60.4%
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.f6487.5
Applied rewrites87.5%
Final simplification68.9%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (/ (- b) a)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = -b / 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 / 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 / a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = -b / a return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(-b) / 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 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[((-b) / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
Initial program 71.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6462.8
Applied rewrites62.8%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6432.3
Applied rewrites32.3%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6432.3
Applied rewrites32.3%
Taylor expanded in c around 0
associate-*r/N/A
lower-/.f64N/A
mul-1-negN/A
lower-neg.f6461.8
Applied rewrites61.8%
(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 71.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6462.8
Applied rewrites62.8%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6432.3
Applied rewrites32.3%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6432.3
Applied rewrites32.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
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 >= 0.0d0) 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 >= 0.0) {
tmp = -b / a;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -b / a; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
Initial program 71.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6462.8
Applied rewrites62.8%
Taylor expanded in b around -inf
associate-*r/N/A
mul-1-negN/A
lower-/.f64N/A
lower-neg.f6432.3
Applied rewrites32.3%
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-*.f6432.2
Applied rewrites32.2%
Taylor expanded in c around inf
Applied rewrites3.2%
herbie shell --seed 2024276
(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))))