
(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 10 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 (/ (- c) b)) (t_1 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -1e+133)
(if (>= b 0.0) t_0 (- (/ c b) (/ b a)))
(if (<= b 2e+140)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_1)) (/ (- t_1 b) (* a 2.0)))
(if (>= b 0.0) t_0 (/ (- b) a))))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -1e+133) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b <= 2e+140) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_1);
} else {
tmp_3 = (t_1 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -b / a;
}
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
real(8) :: tmp_3
t_0 = -c / b
t_1 = sqrt(((b * b) - (c * (a * 4.0d0))))
if (b <= (-1d+133)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = (c / b) - (b / a)
end if
tmp_1 = tmp_2
else if (b <= 2d+140) then
if (b >= 0.0d0) then
tmp_3 = (c * 2.0d0) / (-b - t_1)
else
tmp_3 = (t_1 - b) / (a * 2.0d0)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = -b / a
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = Math.sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -1e+133) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b <= 2e+140) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_1);
} else {
tmp_3 = (t_1 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -b / a;
}
return tmp_1;
}
def code(a, b, c): t_0 = -c / b t_1 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if b <= -1e+133: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = (c / b) - (b / a) tmp_1 = tmp_2 elif b <= 2e+140: tmp_3 = 0 if b >= 0.0: tmp_3 = (c * 2.0) / (-b - t_1) else: tmp_3 = (t_1 - b) / (a * 2.0) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = -b / a return tmp_1
function code(a, b, c) t_0 = Float64(Float64(-c) / b) t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -1e+133) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(c / b) - Float64(b / a)); end tmp_1 = tmp_2; elseif (b <= 2e+140) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - t_1)); else tmp_3 = Float64(Float64(t_1 - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(-b) / a); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = -c / b; t_1 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if (b <= -1e+133) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = (c / b) - (b / a); end tmp_2 = tmp_3; elseif (b <= 2e+140) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (c * 2.0) / (-b - t_1); else tmp_4 = (t_1 - b) / (a * 2.0); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = -b / a; end tmp_5 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -1e+133], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2e+140], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[((-b) / a), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
t_1 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+133}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+140}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -1e133Initial program 40.7%
Simplified41.0%
Taylor expanded in c around 0 41.0%
associate-*r/41.0%
neg-mul-141.0%
Simplified41.0%
Taylor expanded in b around -inf 98.1%
+-commutative98.1%
neg-mul-198.1%
unsub-neg98.1%
Simplified98.1%
if -1e133 < b < 2.00000000000000012e140Initial program 89.9%
if 2.00000000000000012e140 < b Initial program 39.4%
Simplified39.6%
Taylor expanded in c around 0 96.2%
associate-*r/96.2%
neg-mul-196.2%
Simplified96.2%
Taylor expanded in b around -inf 96.2%
associate-*r/96.2%
neg-mul-196.2%
Simplified96.2%
Final simplification92.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- c) b)) (t_1 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -5.2e+134)
(if (>= b 0.0) t_0 (- (/ c b) (/ b a)))
(if (<= b 2.8e+140)
(if (>= b 0.0) (* c (/ 2.0 (- (- b) t_1))) (/ (- t_1 b) (* a 2.0)))
(if (>= b 0.0) t_0 (/ (- b) a))))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -5.2e+134) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b <= 2.8e+140) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = c * (2.0 / (-b - t_1));
} else {
tmp_3 = (t_1 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -b / a;
}
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
real(8) :: tmp_3
t_0 = -c / b
t_1 = sqrt(((b * b) - (c * (a * 4.0d0))))
if (b <= (-5.2d+134)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = (c / b) - (b / a)
end if
tmp_1 = tmp_2
else if (b <= 2.8d+140) then
if (b >= 0.0d0) then
tmp_3 = c * (2.0d0 / (-b - t_1))
else
tmp_3 = (t_1 - b) / (a * 2.0d0)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = -b / a
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = Math.sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -5.2e+134) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b <= 2.8e+140) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = c * (2.0 / (-b - t_1));
} else {
tmp_3 = (t_1 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = -b / a;
}
return tmp_1;
}
def code(a, b, c): t_0 = -c / b t_1 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if b <= -5.2e+134: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = (c / b) - (b / a) tmp_1 = tmp_2 elif b <= 2.8e+140: tmp_3 = 0 if b >= 0.0: tmp_3 = c * (2.0 / (-b - t_1)) else: tmp_3 = (t_1 - b) / (a * 2.0) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = -b / a return tmp_1
function code(a, b, c) t_0 = Float64(Float64(-c) / b) t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -5.2e+134) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(c / b) - Float64(b / a)); end tmp_1 = tmp_2; elseif (b <= 2.8e+140) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(c * Float64(2.0 / Float64(Float64(-b) - t_1))); else tmp_3 = Float64(Float64(t_1 - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(-b) / a); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = -c / b; t_1 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if (b <= -5.2e+134) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = (c / b) - (b / a); end tmp_2 = tmp_3; elseif (b <= 2.8e+140) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = c * (2.0 / (-b - t_1)); else tmp_4 = (t_1 - b) / (a * 2.0); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = -b / a; end tmp_5 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -5.2e+134], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.8e+140], If[GreaterEqual[b, 0.0], N[(c * N[(2.0 / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[((-b) / a), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
t_1 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -5.2 \cdot 10^{+134}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{+140}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{2}{\left(-b\right) - t_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_1 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-b}{a}\\
\end{array}
\end{array}
if b < -5.2000000000000003e134Initial program 40.7%
Simplified41.0%
Taylor expanded in c around 0 41.0%
associate-*r/41.0%
neg-mul-141.0%
Simplified41.0%
Taylor expanded in b around -inf 98.1%
+-commutative98.1%
neg-mul-198.1%
unsub-neg98.1%
Simplified98.1%
if -5.2000000000000003e134 < b < 2.79999999999999983e140Initial program 89.9%
add-sqr-sqrt_binary6469.3%
Applied rewrite-once69.3%
rem-square-sqrt89.9%
associate-/l*89.7%
associate-/r/89.8%
*-commutative89.8%
*-commutative89.8%
Simplified89.8%
if 2.79999999999999983e140 < b Initial program 39.4%
Simplified39.6%
Taylor expanded in c around 0 96.2%
associate-*r/96.2%
neg-mul-196.2%
Simplified96.2%
Taylor expanded in b around -inf 96.2%
associate-*r/96.2%
neg-mul-196.2%
Simplified96.2%
Final simplification92.6%
(FPCore (a b c)
:precision binary64
(if (<= b -2.4e+137)
(if (>= b 0.0) (/ (- c) b) (- (/ c b) (/ b a)))
(if (>= b 0.0)
(* c (/ 2.0 (fma b -2.0 (* (/ c b) (* a 2.0)))))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -2.4e+137) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -c / b;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = c * (2.0 / fma(b, -2.0, ((c / b) * (a * 2.0))));
} else {
tmp_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -2.4e+137) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-c) / b); else tmp_2 = Float64(Float64(c / b) - Float64(b / a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(c * Float64(2.0 / fma(b, -2.0, Float64(Float64(c / b) * Float64(a * 2.0))))); else tmp_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -2.4e+137], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(c * N[(2.0 / N[(b * -2.0 + N[(N[(c / b), $MachinePrecision] * N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2.4 \cdot 10^{+137}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{2}{\mathsf{fma}\left(b, -2, \frac{c}{b} \cdot \left(a \cdot 2\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -2.39999999999999983e137Initial program 40.7%
Simplified41.0%
Taylor expanded in c around 0 41.0%
associate-*r/41.0%
neg-mul-141.0%
Simplified41.0%
Taylor expanded in b around -inf 98.1%
+-commutative98.1%
neg-mul-198.1%
unsub-neg98.1%
Simplified98.1%
if -2.39999999999999983e137 < b Initial program 78.1%
add-sqr-sqrt_binary6461.9%
Applied rewrite-once61.9%
rem-square-sqrt78.1%
associate-/l*78.0%
associate-/r/78.0%
*-commutative78.0%
*-commutative78.0%
Simplified78.0%
Taylor expanded in b around inf 77.1%
*-commutative77.1%
fma-def77.1%
*-commutative77.1%
*-commutative77.1%
associate-*l/79.2%
associate-*l*79.2%
Simplified79.2%
add-sqr-sqrt_binary6479.1%
Applied rewrite-once79.1%
rem-square-sqrt79.2%
+-commutative79.2%
unsub-neg79.2%
*-commutative79.2%
*-commutative79.2%
Simplified79.2%
Final simplification82.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- c) b)))
(if (<= b -1.4e-57)
(if (>= b 0.0) t_0 (- (/ c b) (/ b a)))
(if (>= b 0.0)
t_0
(/ (- (/ 1.0 (sqrt (/ -0.25 (* c a)))) b) (* a 2.0))))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double tmp_1;
if (b <= -1.4e-57) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = ((1.0 / sqrt((-0.25 / (c * a)))) - b) / (a * 2.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) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
t_0 = -c / b
if (b <= (-1.4d-57)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = (c / b) - (b / a)
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = ((1.0d0 / sqrt(((-0.25d0) / (c * a)))) - b) / (a * 2.0d0)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = -c / b;
double tmp_1;
if (b <= -1.4e-57) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = ((1.0 / Math.sqrt((-0.25 / (c * a)))) - b) / (a * 2.0);
}
return tmp_1;
}
def code(a, b, c): t_0 = -c / b tmp_1 = 0 if b <= -1.4e-57: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = (c / b) - (b / a) tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = ((1.0 / math.sqrt((-0.25 / (c * a)))) - b) / (a * 2.0) return tmp_1
function code(a, b, c) t_0 = Float64(Float64(-c) / b) tmp_1 = 0.0 if (b <= -1.4e-57) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(c / b) - Float64(b / a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(Float64(1.0 / sqrt(Float64(-0.25 / Float64(c * a)))) - b) / Float64(a * 2.0)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = -c / b; tmp_2 = 0.0; if (b <= -1.4e-57) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = (c / b) - (b / a); end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = ((1.0 / sqrt((-0.25 / (c * a)))) - b) / (a * 2.0); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, If[LessEqual[b, -1.4e-57], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(N[(1.0 / N[Sqrt[N[(-0.25 / N[(c * a), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
\mathbf{if}\;b \leq -1.4 \cdot 10^{-57}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{\frac{-0.25}{c \cdot a}}} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1.4e-57Initial program 66.7%
Simplified66.9%
Taylor expanded in c around 0 66.9%
associate-*r/66.9%
neg-mul-166.9%
Simplified66.9%
Taylor expanded in b around -inf 89.8%
+-commutative89.8%
neg-mul-189.8%
unsub-neg89.8%
Simplified89.8%
if -1.4e-57 < b Initial program 73.2%
Simplified73.2%
Taylor expanded in c around 0 75.0%
associate-*r/75.0%
neg-mul-175.0%
Simplified75.0%
*-commutative75.0%
metadata-eval75.0%
distribute-lft-neg-in75.0%
fma-def75.0%
*-commutative75.0%
+-commutative75.0%
cancel-sign-sub-inv75.0%
flip3--64.8%
clear-num64.9%
sqrt-div64.9%
metadata-eval64.9%
Applied egg-rr75.0%
Taylor expanded in c around inf 73.3%
Final simplification79.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (c / b) - (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 = (c / b) - (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 = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = (c / b) - (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(c / b) - 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 = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
Initial program 70.8%
Simplified70.8%
Taylor expanded in c around 0 72.0%
associate-*r/72.0%
neg-mul-172.0%
Simplified72.0%
Taylor expanded in b around -inf 70.7%
+-commutative70.7%
neg-mul-170.7%
unsub-neg70.7%
Simplified70.7%
Final simplification70.7%
(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 70.8%
Simplified70.8%
Taylor expanded in c around 0 72.0%
associate-*r/72.0%
neg-mul-172.0%
Simplified72.0%
Taylor expanded in b around -inf 70.4%
associate-*r/70.4%
neg-mul-170.4%
Simplified70.4%
Final simplification70.4%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) -8.0 (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -8.0;
} 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 = -8.0d0
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 = -8.0;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -8.0 else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = -8.0; else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -8.0; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], -8.0, N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-8\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
Initial program 70.8%
Simplified70.8%
Taylor expanded in b around -inf 67.1%
*-commutative67.1%
fma-def67.1%
*-commutative67.1%
associate-/l*69.6%
associate-/r/69.5%
Simplified69.5%
Taylor expanded in c around 0 70.2%
Taylor expanded in b around 0 36.2%
Applied egg-rr3.6%
Final simplification3.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) -0.125 (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -0.125;
} 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 = -0.125d0
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 = -0.125;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -0.125 else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = -0.125; else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -0.125; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], -0.125, N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;-0.125\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
Initial program 70.8%
Simplified70.8%
Taylor expanded in b around -inf 67.1%
*-commutative67.1%
fma-def67.1%
*-commutative67.1%
associate-/l*69.6%
associate-/r/69.5%
Simplified69.5%
Taylor expanded in c around 0 70.2%
Taylor expanded in b around 0 36.2%
Applied egg-rr3.6%
Final simplification3.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) 0.125 (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = 0.125;
} 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 = 0.125d0
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 = 0.125;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = 0.125 else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = 0.125; else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = 0.125; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], 0.125, N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;0.125\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
Initial program 70.8%
Simplified70.8%
Taylor expanded in b around -inf 67.1%
*-commutative67.1%
fma-def67.1%
*-commutative67.1%
associate-/l*69.6%
associate-/r/69.5%
Simplified69.5%
Taylor expanded in c around 0 70.2%
Taylor expanded in b around 0 36.2%
Applied egg-rr3.7%
Final simplification3.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) 0.5 (/ c b)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = 0.5;
} 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 = 0.5d0
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 = 0.5;
} else {
tmp = c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = 0.5 else: tmp = c / b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = 0.5; else tmp = Float64(c / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = 0.5; else tmp = c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], 0.5, N[(c / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}
\end{array}
Initial program 70.8%
Simplified70.8%
Taylor expanded in b around -inf 67.1%
*-commutative67.1%
fma-def67.1%
*-commutative67.1%
associate-/l*69.6%
associate-/r/69.5%
Simplified69.5%
Taylor expanded in c around 0 70.2%
Taylor expanded in b around 0 36.2%
Applied egg-rr3.7%
Final simplification3.7%
herbie shell --seed 2023297
(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))))