
(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) (* c (* a 4.0))))))
(if (<= b -5e+152)
(if (>= b 0.0) (/ (* 2.0 c) (* b -2.0)) (- (/ c b) (/ b a)))
(if (<= b 2.3e+89)
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (- t_0 b) (* 2.0 a)))
(if (>= b 0.0)
(/ (* 2.0 c) (fma b -2.0 (* 2.0 (* c (/ a b)))))
(/ (- (- (/ (* 2.0 (* c a)) b) b) b) (* 2.0 a)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -5e+152) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (b * -2.0);
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b <= 2.3e+89) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (2.0 * c) / (-b - t_0);
} else {
tmp_3 = (t_0 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / fma(b, -2.0, (2.0 * (c * (a / b))));
} else {
tmp_1 = ((((2.0 * (c * a)) / b) - b) - b) / (2.0 * a);
}
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+152) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(b * -2.0)); else tmp_2 = Float64(Float64(c / b) - Float64(b / a)); end tmp_1 = tmp_2; elseif (b <= 2.3e+89) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp_3 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / fma(b, -2.0, Float64(2.0 * Float64(c * Float64(a / b))))); else tmp_1 = Float64(Float64(Float64(Float64(Float64(2.0 * Float64(c * a)) / b) - b) - b) / Float64(2.0 * a)); end return tmp_1 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[LessEqual[b, -5e+152], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.3e+89], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(b * -2.0 + N[(2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(N[(N[(2.0 * N[(c * a), $MachinePrecision]), $MachinePrecision] / b), $MachinePrecision] - b), $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $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^{+152}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.3 \cdot 10^{+89}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\mathsf{fma}\left(b, -2, 2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(\frac{2 \cdot \left(c \cdot a\right)}{b} - b\right) - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -5e152Initial program 46.0%
Taylor expanded in b around inf 46.0%
*-commutative46.0%
Simplified46.0%
Taylor expanded in b around -inf 87.6%
+-commutative87.6%
neg-mul-187.6%
unsub-neg87.6%
associate-*r/87.6%
Simplified87.6%
Taylor expanded in b around 0 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
if -5e152 < b < 2.2999999999999999e89Initial program 87.3%
if 2.2999999999999999e89 < b Initial program 59.5%
Taylor expanded in b around inf 84.9%
*-commutative84.9%
fma-def84.9%
*-commutative84.9%
associate-/l*92.4%
associate-/r/92.4%
Simplified92.4%
Taylor expanded in b around -inf 92.4%
+-commutative92.2%
neg-mul-192.2%
unsub-neg92.2%
associate-*r/92.2%
Simplified92.4%
Final simplification90.6%
(FPCore (a b c)
:precision binary64
(if (<= b -2e+153)
(if (>= b 0.0) (/ (* 2.0 c) (* b -2.0)) (- (/ c b) (/ b a)))
(if (>= b 0.0)
(* 2.0 (/ 1.0 (/ (fma b -2.0 (* c (* 2.0 (/ a b)))) c)))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -2e+153) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (b * -2.0);
} else {
tmp_2 = (c / b) - (b / a);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = 2.0 * (1.0 / (fma(b, -2.0, (c * (2.0 * (a / b)))) / c));
} else {
tmp_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -2e+153) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(b * -2.0)); else tmp_2 = Float64(Float64(c / b) - Float64(b / a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(2.0 * Float64(1.0 / Float64(fma(b, -2.0, Float64(c * Float64(2.0 * Float64(a / b)))) / c))); else tmp_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -2e+153], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(2.0 * N[(1.0 / N[(N[(b * -2.0 + N[(c * N[(2.0 * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / c), $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[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -2 \cdot 10^{+153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;2 \cdot \frac{1}{\frac{\mathsf{fma}\left(b, -2, c \cdot \left(2 \cdot \frac{a}{b}\right)\right)}{c}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -2e153Initial program 46.0%
Taylor expanded in b around inf 46.0%
*-commutative46.0%
Simplified46.0%
Taylor expanded in b around -inf 87.6%
+-commutative87.6%
neg-mul-187.6%
unsub-neg87.6%
associate-*r/87.6%
Simplified87.6%
Taylor expanded in b around 0 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
if -2e153 < b Initial program 81.3%
Taylor expanded in b around inf 72.7%
*-commutative72.7%
fma-def72.7%
*-commutative72.7%
associate-/l*74.3%
associate-/r/74.3%
Simplified74.3%
associate-/l*73.6%
div-inv73.6%
*-commutative73.6%
associate-*l*73.6%
Applied egg-rr73.6%
Final simplification78.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* 2.0 c) (* b -2.0))))
(if (<= b -2e+154)
(if (>= b 0.0) t_0 (- (/ c b) (/ b a)))
(if (>= b 0.0)
t_0
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a))))))
double code(double a, double b, double c) {
double t_0 = (2.0 * c) / (b * -2.0);
double tmp_1;
if (b <= -2e+154) {
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 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * 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) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
t_0 = (2.0d0 * c) / (b * (-2.0d0))
if (b <= (-2d+154)) 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 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (2.0d0 * a)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = (2.0 * c) / (b * -2.0);
double tmp_1;
if (b <= -2e+154) {
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 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a);
}
return tmp_1;
}
def code(a, b, c): t_0 = (2.0 * c) / (b * -2.0) tmp_1 = 0 if b <= -2e+154: 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 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a) return tmp_1
function code(a, b, c) t_0 = Float64(Float64(2.0 * c) / Float64(b * -2.0)) tmp_1 = 0.0 if (b <= -2e+154) 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(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(2.0 * a)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = (2.0 * c) / (b * -2.0); tmp_2 = 0.0; if (b <= -2e+154) 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 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (2.0 * a); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(2.0 * c), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -2e+154], 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[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot c}{b \cdot -2}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+154}:\\
\;\;\;\;\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{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -2.00000000000000007e154Initial program 46.0%
Taylor expanded in b around inf 46.0%
*-commutative46.0%
Simplified46.0%
Taylor expanded in b around -inf 87.6%
+-commutative87.6%
neg-mul-187.6%
unsub-neg87.6%
associate-*r/87.6%
Simplified87.6%
Taylor expanded in b around 0 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
Simplified100.0%
if -2.00000000000000007e154 < b Initial program 81.3%
Taylor expanded in b around inf 74.2%
*-commutative74.2%
Simplified74.2%
Final simplification79.0%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* 2.0 c) (* b -2.0))))
(if (<= b -4.2e-51)
(if (>= b 0.0) t_0 (- (/ c b) (/ b a)))
(if (>= b 0.0) t_0 (/ (- (sqrt (* (* c a) -4.0)) b) (* 2.0 a))))))
double code(double a, double b, double c) {
double t_0 = (2.0 * c) / (b * -2.0);
double tmp_1;
if (b <= -4.2e-51) {
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 = (sqrt(((c * a) * -4.0)) - b) / (2.0 * 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) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
t_0 = (2.0d0 * c) / (b * (-2.0d0))
if (b <= (-4.2d-51)) 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 = (sqrt(((c * a) * (-4.0d0))) - b) / (2.0d0 * a)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = (2.0 * c) / (b * -2.0);
double tmp_1;
if (b <= -4.2e-51) {
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 = (Math.sqrt(((c * a) * -4.0)) - b) / (2.0 * a);
}
return tmp_1;
}
def code(a, b, c): t_0 = (2.0 * c) / (b * -2.0) tmp_1 = 0 if b <= -4.2e-51: 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 = (math.sqrt(((c * a) * -4.0)) - b) / (2.0 * a) return tmp_1
function code(a, b, c) t_0 = Float64(Float64(2.0 * c) / Float64(b * -2.0)) tmp_1 = 0.0 if (b <= -4.2e-51) 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(sqrt(Float64(Float64(c * a) * -4.0)) - b) / Float64(2.0 * a)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = (2.0 * c) / (b * -2.0); tmp_2 = 0.0; if (b <= -4.2e-51) 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 = (sqrt(((c * a) * -4.0)) - b) / (2.0 * a); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(2.0 * c), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -4.2e-51], 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[Sqrt[N[(N[(c * a), $MachinePrecision] * -4.0), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot c}{b \cdot -2}\\
\mathbf{if}\;b \leq -4.2 \cdot 10^{-51}:\\
\;\;\;\;\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{\sqrt{\left(c \cdot a\right) \cdot -4} - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -4.20000000000000003e-51Initial program 69.9%
Taylor expanded in b around inf 69.9%
*-commutative69.9%
Simplified69.9%
Taylor expanded in b around -inf 82.7%
+-commutative82.7%
neg-mul-182.7%
unsub-neg82.7%
associate-*r/82.7%
Simplified82.7%
Taylor expanded in b around 0 89.2%
+-commutative89.2%
mul-1-neg89.2%
unsub-neg89.2%
Simplified89.2%
if -4.20000000000000003e-51 < b Initial program 77.3%
Taylor expanded in b around inf 68.3%
*-commutative68.3%
Simplified68.3%
Taylor expanded in b around 0 66.1%
*-commutative66.1%
Simplified66.1%
Final simplification74.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (* b -2.0)) (- (/ c b) (/ b a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (b * -2.0);
} 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 = (2.0d0 * c) / (b * (-2.0d0))
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 = (2.0 * c) / (b * -2.0);
} else {
tmp = (c / b) - (b / a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (b * -2.0) else: tmp = (c / b) - (b / a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(b * -2.0)); 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 = (2.0 * c) / (b * -2.0); else tmp = (c / b) - (b / a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\end{array}
\end{array}
Initial program 74.6%
Taylor expanded in b around inf 68.9%
*-commutative68.9%
Simplified68.9%
Taylor expanded in b around -inf 62.0%
+-commutative62.0%
neg-mul-162.0%
unsub-neg62.0%
associate-*r/62.0%
Simplified62.0%
Taylor expanded in b around 0 64.4%
+-commutative64.4%
mul-1-neg64.4%
unsub-neg64.4%
Simplified64.4%
Final simplification64.4%
herbie shell --seed 2023335
(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))))