
(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 5 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 (/ (* (- c) 2.0) (+ t_0 b))))
(if (<= b -5e+107)
(if (>= b 0.0)
t_1
(/ (* (fma (* -2.0 (/ a b)) (/ c b) 2.0) (- b)) (* a 2.0)))
(if (<= b 1e+91)
(if (>= b 0.0) t_1 (/ (- t_0 b) (* a 2.0)))
(if (>= b 0.0) (/ (- c) b) (/ (- (- b) 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 = (-c * 2.0) / (t_0 + b);
double tmp_1;
if (b <= -5e+107) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = (fma((-2.0 * (a / b)), (c / b), 2.0) * -b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else if (b <= 1e+91) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = t_1;
} else {
tmp_3 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (-b - 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(Float64(-c) * 2.0) / Float64(t_0 + b)) tmp_1 = 0.0 if (b <= -5e+107) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(Float64(fma(Float64(-2.0 * Float64(a / b)), Float64(c / b), 2.0) * Float64(-b)) / Float64(a * 2.0)); end tmp_1 = tmp_2; elseif (b <= 1e+91) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = t_1; else tmp_3 = Float64(Float64(t_0 - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(-c) / 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[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[((-c) * 2.0), $MachinePrecision] / N[(t$95$0 + b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -5e+107], If[GreaterEqual[b, 0.0], t$95$1, N[(N[(N[(N[(-2.0 * N[(a / b), $MachinePrecision]), $MachinePrecision] * N[(c / b), $MachinePrecision] + 2.0), $MachinePrecision] * (-b)), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 1e+91], If[GreaterEqual[b, 0.0], t$95$1, N[(N[(t$95$0 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[((-b) - 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{\left(-c\right) \cdot 2}{t\_0 + b}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+107}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\mathsf{fma}\left(-2 \cdot \frac{a}{b}, \frac{c}{b}, 2\right) \cdot \left(-b\right)}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{+91}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -5.0000000000000002e107Initial program 53.2%
Taylor expanded in b around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.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-/.f6498.4
Applied rewrites98.4%
if -5.0000000000000002e107 < b < 1.00000000000000008e91Initial program 89.5%
if 1.00000000000000008e91 < b Initial program 48.6%
Applied rewrites0.2%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f642.6
Applied rewrites2.6%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f642.6
Applied rewrites2.6%
Taylor expanded in c around inf
Applied rewrites96.1%
Final simplification92.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (if (>= b 0.0) (/ (- c) b) (/ (- (- b) b) (* a 2.0))))
(t_1 (sqrt (- (* b b) (* (* a 4.0) c)))))
(if (<= b -1e+152)
t_0
(if (<= b 1e+91)
(if (>= b 0.0) (/ (* (- c) 2.0) (+ t_1 b)) (/ (- t_1 b) (* a 2.0)))
t_0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (-b - b) / (a * 2.0);
}
double t_0 = tmp;
double t_1 = sqrt(((b * b) - ((a * 4.0) * c)));
double tmp_1;
if (b <= -1e+152) {
tmp_1 = t_0;
} else if (b <= 1e+91) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-c * 2.0) / (t_1 + b);
} else {
tmp_2 = (t_1 - b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
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) :: t_1
real(8) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
if (b >= 0.0d0) then
tmp = -c / b
else
tmp = (-b - b) / (a * 2.0d0)
end if
t_0 = tmp
t_1 = sqrt(((b * b) - ((a * 4.0d0) * c)))
if (b <= (-1d+152)) then
tmp_1 = t_0
else if (b <= 1d+91) then
if (b >= 0.0d0) then
tmp_2 = (-c * 2.0d0) / (t_1 + b)
else
tmp_2 = (t_1 - b) / (a * 2.0d0)
end if
tmp_1 = tmp_2
else
tmp_1 = t_0
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (-b - b) / (a * 2.0);
}
double t_0 = tmp;
double t_1 = Math.sqrt(((b * b) - ((a * 4.0) * c)));
double tmp_1;
if (b <= -1e+152) {
tmp_1 = t_0;
} else if (b <= 1e+91) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-c * 2.0) / (t_1 + b);
} else {
tmp_2 = (t_1 - b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = (-b - b) / (a * 2.0) t_0 = tmp t_1 = math.sqrt(((b * b) - ((a * 4.0) * c))) tmp_1 = 0 if b <= -1e+152: tmp_1 = t_0 elif b <= 1e+91: tmp_2 = 0 if b >= 0.0: tmp_2 = (-c * 2.0) / (t_1 + b) else: tmp_2 = (t_1 - b) / (a * 2.0) tmp_1 = tmp_2 else: tmp_1 = t_0 return tmp_1
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); end t_0 = tmp t_1 = sqrt(Float64(Float64(b * b) - Float64(Float64(a * 4.0) * c))) tmp_1 = 0.0 if (b <= -1e+152) tmp_1 = t_0; elseif (b <= 1e+91) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(Float64(-c) * 2.0) / Float64(t_1 + b)); else tmp_2 = Float64(Float64(t_1 - b) / Float64(a * 2.0)); end tmp_1 = tmp_2; else tmp_1 = t_0; end return tmp_1 end
function tmp_4 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = (-b - b) / (a * 2.0); end t_0 = tmp; t_1 = sqrt(((b * b) - ((a * 4.0) * c))); tmp_2 = 0.0; if (b <= -1e+152) tmp_2 = t_0; elseif (b <= 1e+91) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (-c * 2.0) / (t_1 + b); else tmp_3 = (t_1 - b) / (a * 2.0); end tmp_2 = tmp_3; else tmp_2 = t_0; end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(a * 4.0), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1e+152], t$95$0, If[LessEqual[b, 1e+91], If[GreaterEqual[b, 0.0], N[(N[((-c) * 2.0), $MachinePrecision] / N[(t$95$1 + b), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\\
t_1 := \sqrt{b \cdot b - \left(a \cdot 4\right) \cdot c}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+152}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 10^{+91}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-c\right) \cdot 2}{t\_1 + b}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -1e152 or 1.00000000000000008e91 < b Initial program 44.0%
Applied rewrites18.4%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6419.7
Applied rewrites19.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6448.6
Applied rewrites48.6%
Taylor expanded in c around inf
Applied rewrites97.9%
if -1e152 < b < 1.00000000000000008e91Initial program 89.9%
Final simplification92.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (if (>= b 0.0) (/ (- c) b) (/ (- (- b) b) (* a 2.0))))
(t_1 (sqrt (fma -4.0 (* a c) (* b b)))))
(if (<= b -1e+152)
t_0
(if (<= b 1e+91)
(if (>= b 0.0) (/ (* -2.0 c) (+ t_1 b)) (* 0.5 (/ (- t_1 b) a)))
t_0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (-b - b) / (a * 2.0);
}
double t_0 = tmp;
double t_1 = sqrt(fma(-4.0, (a * c), (b * b)));
double tmp_1;
if (b <= -1e+152) {
tmp_1 = t_0;
} else if (b <= 1e+91) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-2.0 * c) / (t_1 + b);
} else {
tmp_2 = 0.5 * ((t_1 - b) / a);
}
tmp_1 = tmp_2;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); end t_0 = tmp t_1 = sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) tmp_1 = 0.0 if (b <= -1e+152) tmp_1 = t_0; elseif (b <= 1e+91) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-2.0 * c) / Float64(t_1 + b)); else tmp_2 = Float64(0.5 * Float64(Float64(t_1 - b) / a)); end tmp_1 = tmp_2; else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]}, Block[{t$95$1 = N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1e+152], t$95$0, If[LessEqual[b, 1e+91], If[GreaterEqual[b, 0.0], N[(N[(-2.0 * c), $MachinePrecision] / N[(t$95$1 + b), $MachinePrecision]), $MachinePrecision], N[(0.5 * N[(N[(t$95$1 - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\\
t_1 := \sqrt{\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+152}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 10^{+91}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-2 \cdot c}{t\_1 + b}\\
\mathbf{else}:\\
\;\;\;\;0.5 \cdot \frac{t\_1 - b}{a}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -1e152 or 1.00000000000000008e91 < b Initial program 44.0%
Applied rewrites18.4%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6419.7
Applied rewrites19.7%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6448.6
Applied rewrites48.6%
Taylor expanded in c around inf
Applied rewrites97.9%
if -1e152 < b < 1.00000000000000008e91Initial program 89.9%
lift-sqrt.f64N/A
lift--.f64N/A
flip--N/A
clear-numN/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lower-sqrt.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
Applied rewrites89.5%
Taylor expanded in c around 0
lower->=.f64N/A
associate-*r/N/A
lower-/.f64N/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites89.9%
Final simplification92.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (if (>= b 0.0) (/ (- c) b) (/ (- (- b) b) (* a 2.0)))))
(if (<= b -1e+152)
t_0
(if (<= b 6.2e-98)
(* 0.5 (/ (- (sqrt (fma -4.0 (* a c) (* b b))) b) a))
t_0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (-b - b) / (a * 2.0);
}
double t_0 = tmp;
double tmp_1;
if (b <= -1e+152) {
tmp_1 = t_0;
} else if (b <= 6.2e-98) {
tmp_1 = 0.5 * ((sqrt(fma(-4.0, (a * c), (b * b))) - b) / a);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); end t_0 = tmp tmp_1 = 0.0 if (b <= -1e+152) tmp_1 = t_0; elseif (b <= 6.2e-98) tmp_1 = Float64(0.5 * Float64(Float64(sqrt(fma(-4.0, Float64(a * c), Float64(b * b))) - b) / a)); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]}, If[LessEqual[b, -1e+152], t$95$0, If[LessEqual[b, 6.2e-98], N[(0.5 * N[(N[(N[Sqrt[N[(-4.0 * N[(a * c), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+152}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-98}:\\
\;\;\;\;0.5 \cdot \frac{\sqrt{\mathsf{fma}\left(-4, a \cdot c, b \cdot b\right)} - b}{a}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -1e152 or 6.2e-98 < b Initial program 59.0%
Applied rewrites16.4%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6415.3
Applied rewrites15.3%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6436.1
Applied rewrites36.1%
Taylor expanded in c around inf
Applied rewrites92.7%
if -1e152 < b < 6.2e-98Initial program 88.0%
lift-sqrt.f64N/A
lift--.f64N/A
flip--N/A
clear-numN/A
sqrt-divN/A
metadata-evalN/A
lower-/.f64N/A
lower-sqrt.f64N/A
clear-numN/A
flip--N/A
lift--.f64N/A
Applied rewrites87.5%
Applied rewrites87.8%
lift-/.f64N/A
lift-+.f64N/A
flip-+N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
lift-*.f64N/A
lift-fma.f64N/A
lift--.f64N/A
associate-/r/N/A
Applied rewrites87.2%
Taylor expanded in c around 0
if-sameN/A
*-commutativeN/A
div-subN/A
+-commutativeN/A
metadata-evalN/A
cancel-sign-sub-invN/A
div-subN/A
lower-*.f64N/A
Applied rewrites87.9%
Final simplification90.2%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (/ (- (- b) b) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / 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 / 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 / b;
} else {
tmp = (-b - b) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / 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) / 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 / b; else tmp = (-b - b) / (a * 2.0); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $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}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 73.9%
Applied rewrites49.5%
Taylor expanded in b around inf
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-/.f64N/A
unpow2N/A
lower-*.f6443.6
Applied rewrites43.6%
Taylor expanded in b around -inf
mul-1-negN/A
lower-neg.f6442.0
Applied rewrites42.0%
Taylor expanded in c around inf
Applied rewrites69.5%
Final simplification69.5%
herbie shell --seed 2024248
(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))))