
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (- (- b) t_0) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) t_0)))))
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 = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + 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 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (-b - t_0) / (2.0d0 * a)
else
tmp = (2.0d0 * c) / (-b + t_0)
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 = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (-b - t_0) / (2.0 * a) else: tmp = (2.0 * c) / (-b + t_0) 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(Float64(-b) - t_0) / Float64(2.0 * a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_0)); 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 = (-b - t_0) / (2.0 * a); else tmp = (2.0 * c) / (-b + t_0); 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[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$0), $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{\left(-b\right) - t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t\_0}\\
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b c) :precision binary64 (let* ((t_0 (sqrt (- (* b b) (* (* 4.0 a) c))))) (if (>= b 0.0) (/ (- (- b) t_0) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) t_0)))))
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 = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + 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 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (-b - t_0) / (2.0d0 * a)
else
tmp = (2.0d0 * c) / (-b + t_0)
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 = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (-b - t_0) / (2.0 * a) else: tmp = (2.0 * c) / (-b + t_0) 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(Float64(-b) - t_0) / Float64(2.0 * a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_0)); 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 = (-b - t_0) / (2.0 * a); else tmp = (2.0 * c) / (-b + t_0); 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[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$0), $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{\left(-b\right) - t\_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t\_0}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (or (<= b -5e+127) (not (<= b 5e+103)))
(if (>= b 0.0) (/ (- b) a) (/ c (- b)))
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ (* c 2.0) (- t_0 b))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if ((b <= -5e+127) || !(b <= 5e+103)) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (-b - t_0) / (a * 2.0);
} else {
tmp_1 = (c * 2.0) / (t_0 - b);
}
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 = sqrt(((b * b) - (c * (a * 4.0d0))))
if ((b <= (-5d+127)) .or. (.not. (b <= 5d+103))) then
if (b >= 0.0d0) then
tmp_2 = -b / a
else
tmp_2 = c / -b
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = (-b - t_0) / (a * 2.0d0)
else
tmp_1 = (c * 2.0d0) / (t_0 - b)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if ((b <= -5e+127) || !(b <= 5e+103)) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (-b - t_0) / (a * 2.0);
} else {
tmp_1 = (c * 2.0) / (t_0 - b);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if (b <= -5e+127) or not (b <= 5e+103): tmp_2 = 0 if b >= 0.0: tmp_2 = -b / a else: tmp_2 = c / -b tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = (-b - t_0) / (a * 2.0) else: tmp_1 = (c * 2.0) / (t_0 - b) return tmp_1
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if ((b <= -5e+127) || !(b <= 5e+103)) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(Float64(-b) - t_0) / Float64(a * 2.0)); else tmp_1 = Float64(Float64(c * 2.0) / Float64(t_0 - b)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if ((b <= -5e+127) || ~((b <= 5e+103))) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = -b / a; else tmp_3 = c / -b; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = (-b - t_0) / (a * 2.0); else tmp_2 = (c * 2.0) / (t_0 - b); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[Or[LessEqual[b, -5e+127], N[Not[LessEqual[b, 5e+103]], $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(c / (-b)), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+127} \lor \neg \left(b \leq 5 \cdot 10^{+103}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t\_0 - b}\\
\end{array}
\end{array}
if b < -5.0000000000000004e127 or 5e103 < b Initial program 47.7%
Simplified47.9%
Taylor expanded in b around inf 74.1%
associate-*r/74.1%
mul-1-neg74.1%
Simplified74.1%
Taylor expanded in b around -inf 95.3%
*-commutative95.3%
Simplified95.3%
Taylor expanded in b around 0 95.4%
associate-*r/95.4%
neg-mul-195.4%
mul-1-neg95.4%
Simplified95.4%
if -5.0000000000000004e127 < b < 5e103Initial program 87.9%
Final simplification90.9%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* c 2.0) (- (sqrt (- (* b b) (* c (* a 4.0)))) b))))
(if (<= b -4.6e+128)
(if (>= b 0.0) (/ (- b) a) (/ c (- b)))
(if (<= b 1.15e-67)
(if (>= b 0.0) (* (+ b (sqrt (* c (* a -4.0)))) (/ -1.0 (* a 2.0))) t_0)
(if (>= b 0.0) (/ (* 2.0 (fma a (/ c b) (- b))) (* a 2.0)) t_0)))))
double code(double a, double b, double c) {
double t_0 = (c * 2.0) / (sqrt(((b * b) - (c * (a * 4.0)))) - b);
double tmp_1;
if (b <= -4.6e+128) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -b / a;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b <= 1.15e-67) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (b + sqrt((c * (a * -4.0)))) * (-1.0 / (a * 2.0));
} else {
tmp_3 = t_0;
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * fma(a, (c / b), -b)) / (a * 2.0);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
function code(a, b, c) t_0 = Float64(Float64(c * 2.0) / Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b)) tmp_1 = 0.0 if (b <= -4.6e+128) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-b) / a); else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b <= 1.15e-67) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) * Float64(-1.0 / Float64(a * 2.0))); else tmp_3 = t_0; end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * fma(a, Float64(c / b), Float64(-b))) / Float64(a * 2.0)); else tmp_1 = t_0; end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(c * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -4.6e+128], If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(c / (-b)), $MachinePrecision]], If[LessEqual[b, 1.15e-67], If[GreaterEqual[b, 0.0], N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[GreaterEqual[b, 0.0], N[(N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{c \cdot 2}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\
\mathbf{if}\;b \leq -4.6 \cdot 10^{+128}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \leq 1.15 \cdot 10^{-67}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-1}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -4.59999999999999996e128Initial program 46.2%
Simplified46.2%
Taylor expanded in b around inf 46.2%
associate-*r/46.2%
mul-1-neg46.2%
Simplified46.2%
Taylor expanded in b around -inf 95.5%
*-commutative95.5%
Simplified95.5%
Taylor expanded in b around 0 95.8%
associate-*r/95.8%
neg-mul-195.8%
mul-1-neg95.8%
Simplified95.8%
if -4.59999999999999996e128 < b < 1.15e-67Initial program 84.8%
add-sqr-sqrt84.7%
pow284.7%
pow1/284.7%
sqrt-pow184.7%
fma-neg84.7%
*-commutative84.7%
distribute-rgt-neg-in84.7%
distribute-lft-neg-in84.7%
metadata-eval84.7%
associate-*r*84.7%
metadata-eval84.7%
Applied egg-rr84.7%
Taylor expanded in b around 0 80.9%
associate-*r*80.9%
*-commutative80.9%
associate-*r*80.9%
*-commutative80.9%
Simplified80.9%
div-inv80.9%
pow-pow81.0%
*-commutative81.0%
associate-*r*81.0%
metadata-eval81.0%
pow1/281.0%
*-commutative81.0%
Applied egg-rr81.0%
if 1.15e-67 < b Initial program 68.1%
Taylor expanded in a around 0 79.1%
distribute-lft-out--79.1%
associate-/l*86.4%
fma-neg86.4%
Simplified86.4%
Final simplification85.6%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- b) a)))
(if (<= b -1.04e+129)
(if (>= b 0.0) t_0 (/ c (- b)))
(if (<= b 6.2e-19)
(if (>= b 0.0)
(* (+ b (sqrt (* c (* a -4.0)))) (/ -1.0 (* a 2.0)))
(/ (* c 2.0) (- (sqrt (- (* b b) (* c (* a 4.0)))) b)))
(if (>= b 0.0) t_0 (* c (/ -1.0 b)))))))
double code(double a, double b, double c) {
double t_0 = -b / a;
double tmp_1;
if (b <= -1.04e+129) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b <= 6.2e-19) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (b + sqrt((c * (a * -4.0)))) * (-1.0 / (a * 2.0));
} else {
tmp_3 = (c * 2.0) / (sqrt(((b * b) - (c * (a * 4.0)))) - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = c * (-1.0 / b);
}
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
real(8) :: tmp_3
t_0 = -b / a
if (b <= (-1.04d+129)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = c / -b
end if
tmp_1 = tmp_2
else if (b <= 6.2d-19) then
if (b >= 0.0d0) then
tmp_3 = (b + sqrt((c * (a * (-4.0d0))))) * ((-1.0d0) / (a * 2.0d0))
else
tmp_3 = (c * 2.0d0) / (sqrt(((b * b) - (c * (a * 4.0d0)))) - b)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = c * ((-1.0d0) / b)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = -b / a;
double tmp_1;
if (b <= -1.04e+129) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b <= 6.2e-19) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (b + Math.sqrt((c * (a * -4.0)))) * (-1.0 / (a * 2.0));
} else {
tmp_3 = (c * 2.0) / (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = c * (-1.0 / b);
}
return tmp_1;
}
def code(a, b, c): t_0 = -b / a tmp_1 = 0 if b <= -1.04e+129: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = c / -b tmp_1 = tmp_2 elif b <= 6.2e-19: tmp_3 = 0 if b >= 0.0: tmp_3 = (b + math.sqrt((c * (a * -4.0)))) * (-1.0 / (a * 2.0)) else: tmp_3 = (c * 2.0) / (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = c * (-1.0 / b) return tmp_1
function code(a, b, c) t_0 = Float64(Float64(-b) / a) tmp_1 = 0.0 if (b <= -1.04e+129) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b <= 6.2e-19) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(b + sqrt(Float64(c * Float64(a * -4.0)))) * Float64(-1.0 / Float64(a * 2.0))); else tmp_3 = Float64(Float64(c * 2.0) / Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(c * Float64(-1.0 / b)); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = -b / a; tmp_2 = 0.0; if (b <= -1.04e+129) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = c / -b; end tmp_2 = tmp_3; elseif (b <= 6.2e-19) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (b + sqrt((c * (a * -4.0)))) * (-1.0 / (a * 2.0)); else tmp_4 = (c * 2.0) / (sqrt(((b * b) - (c * (a * 4.0)))) - b); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = c * (-1.0 / b); end tmp_5 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-b) / a), $MachinePrecision]}, If[LessEqual[b, -1.04e+129], If[GreaterEqual[b, 0.0], t$95$0, N[(c / (-b)), $MachinePrecision]], If[LessEqual[b, 6.2e-19], If[GreaterEqual[b, 0.0], N[(N[(b + N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(-1.0 / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(c * N[(-1.0 / b), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-b}{a}\\
\mathbf{if}\;b \leq -1.04 \cdot 10^{+129}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \leq 6.2 \cdot 10^{-19}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\left(b + \sqrt{c \cdot \left(a \cdot -4\right)}\right) \cdot \frac{-1}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;c \cdot \frac{-1}{b}\\
\end{array}
\end{array}
if b < -1.04e129Initial program 46.2%
Simplified46.2%
Taylor expanded in b around inf 46.2%
associate-*r/46.2%
mul-1-neg46.2%
Simplified46.2%
Taylor expanded in b around -inf 95.5%
*-commutative95.5%
Simplified95.5%
Taylor expanded in b around 0 95.8%
associate-*r/95.8%
neg-mul-195.8%
mul-1-neg95.8%
Simplified95.8%
if -1.04e129 < b < 6.1999999999999998e-19Initial program 86.1%
add-sqr-sqrt86.0%
pow286.0%
pow1/286.0%
sqrt-pow186.0%
fma-neg86.0%
*-commutative86.0%
distribute-rgt-neg-in86.0%
distribute-lft-neg-in86.0%
metadata-eval86.0%
associate-*r*86.0%
metadata-eval86.0%
Applied egg-rr86.0%
Taylor expanded in b around 0 78.1%
associate-*r*78.1%
*-commutative78.1%
associate-*r*78.1%
*-commutative78.1%
Simplified78.1%
div-inv78.1%
pow-pow78.2%
*-commutative78.2%
associate-*r*78.2%
metadata-eval78.2%
pow1/278.2%
*-commutative78.2%
Applied egg-rr78.2%
if 6.1999999999999998e-19 < b Initial program 63.9%
Simplified64.1%
Taylor expanded in b around inf 90.3%
associate-*r/90.3%
mul-1-neg90.3%
Simplified90.3%
Taylor expanded in b around -inf 90.3%
*-commutative90.3%
Simplified90.3%
Taylor expanded in b around 0 90.3%
Final simplification85.2%
(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 / Float64(-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.9%
Simplified71.9%
Taylor expanded in b around inf 69.9%
associate-*r/69.9%
mul-1-neg69.9%
Simplified69.9%
Taylor expanded in b around -inf 65.8%
*-commutative65.8%
Simplified65.8%
Taylor expanded in b around 0 65.8%
associate-*r/65.8%
neg-mul-165.8%
mul-1-neg65.8%
Simplified65.8%
Final simplification65.8%
herbie shell --seed 2024129
(FPCore (a b c)
:name "jeff quadratic root 1"
:precision binary64
(if (>= b 0.0) (/ (- (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) (sqrt (- (* b b) (* (* 4.0 a) c)))))))