
(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) (* c (* a 4.0))))))
(if (<= b -1.85e+77)
(if (>= b 0.0)
(* c (/ -1.0 b))
(* (+ (* -2.0 (/ c b)) (* 2.0 (/ b a))) -0.5))
(if (<= b 5e+83)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_0)) (/ (- t_0 b) (* 2.0 a)))
(if (>= b 0.0)
(/ (* c 2.0) (- (- (* -2.0 (* c (/ (- a) b))) b) b))
(/ (* b -2.0) (* 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 <= -1.85e+77) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * (-1.0 / b);
} else {
tmp_2 = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 5e+83) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_0);
} else {
tmp_3 = (t_0 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (((-2.0 * (c * (-a / b))) - b) - b);
} else {
tmp_1 = (b * -2.0) / (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
real(8) :: tmp_3
t_0 = sqrt(((b * b) - (c * (a * 4.0d0))))
if (b <= (-1.85d+77)) then
if (b >= 0.0d0) then
tmp_2 = c * ((-1.0d0) / b)
else
tmp_2 = (((-2.0d0) * (c / b)) + (2.0d0 * (b / a))) * (-0.5d0)
end if
tmp_1 = tmp_2
else if (b <= 5d+83) then
if (b >= 0.0d0) then
tmp_3 = (c * 2.0d0) / (-b - t_0)
else
tmp_3 = (t_0 - b) / (2.0d0 * a)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = (c * 2.0d0) / ((((-2.0d0) * (c * (-a / b))) - b) - b)
else
tmp_1 = (b * (-2.0d0)) / (2.0d0 * a)
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 <= -1.85e+77) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c * (-1.0 / b);
} else {
tmp_2 = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 5e+83) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_0);
} else {
tmp_3 = (t_0 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (((-2.0 * (c * (-a / b))) - b) - b);
} else {
tmp_1 = (b * -2.0) / (2.0 * a);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if b <= -1.85e+77: tmp_2 = 0 if b >= 0.0: tmp_2 = c * (-1.0 / b) else: tmp_2 = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5 tmp_1 = tmp_2 elif b <= 5e+83: tmp_3 = 0 if b >= 0.0: tmp_3 = (c * 2.0) / (-b - t_0) else: tmp_3 = (t_0 - b) / (2.0 * a) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = (c * 2.0) / (((-2.0 * (c * (-a / b))) - b) - b) else: tmp_1 = (b * -2.0) / (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 <= -1.85e+77) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c * Float64(-1.0 / b)); else tmp_2 = Float64(Float64(Float64(-2.0 * Float64(c / b)) + Float64(2.0 * Float64(b / a))) * -0.5); end tmp_1 = tmp_2; elseif (b <= 5e+83) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * 2.0) / 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(c * 2.0) / Float64(Float64(Float64(-2.0 * Float64(c * Float64(Float64(-a) / b))) - b) - b)); else tmp_1 = Float64(Float64(b * -2.0) / Float64(2.0 * a)); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if (b <= -1.85e+77) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = c * (-1.0 / b); else tmp_3 = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5; end tmp_2 = tmp_3; elseif (b <= 5e+83) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (c * 2.0) / (-b - t_0); else tmp_4 = (t_0 - b) / (2.0 * a); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = (c * 2.0) / (((-2.0 * (c * (-a / b))) - b) - b); else tmp_2 = (b * -2.0) / (2.0 * a); end tmp_5 = 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[LessEqual[b, -1.85e+77], If[GreaterEqual[b, 0.0], N[(c * N[(-1.0 / b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]], If[LessEqual[b, 5e+83], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $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[(c * 2.0), $MachinePrecision] / N[(N[(N[(-2.0 * N[(c * N[((-a) / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $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 -1.85 \cdot 10^{+77}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-1}{b}\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.5\\
\end{array}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+83}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-2 \cdot \left(c \cdot \frac{-a}{b}\right) - b\right) - b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\end{array}
\end{array}
if b < -1.84999999999999997e77Initial program 46.6%
Simplified46.8%
Taylor expanded in c around 0 46.8%
associate-/l*46.8%
Simplified46.8%
Taylor expanded in b around -inf 95.2%
Taylor expanded in b around inf 95.2%
if -1.84999999999999997e77 < b < 5.00000000000000029e83Initial program 83.4%
if 5.00000000000000029e83 < b Initial program 44.8%
Taylor expanded in b around -inf 44.8%
*-commutative44.8%
Simplified44.8%
Taylor expanded in b around inf 83.3%
associate-*l/94.5%
*-commutative94.5%
Simplified94.5%
Final simplification88.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* b -2.0) (* 2.0 a)))
(t_1
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (sqrt (* c (* a -4.0)))))
(fma -1.0 (/ b a) (/ c b))))
(t_2
(if (>= b 0.0)
(/ (* c 2.0) (- (- (* -2.0 (* c (/ (- a) b))) b) b))
t_0)))
(if (<= b 5e-169)
t_1
(if (<= b 2e-82)
t_2
(if (<= b 4.5e-21)
t_1
(if (<= b 1.86e+143) (if (>= b 0.0) (/ (- c) b) t_0) t_2))))))
double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (2.0 * a);
double tmp;
if (b >= 0.0) {
tmp = (c * 2.0) / (-b - sqrt((c * (a * -4.0))));
} else {
tmp = fma(-1.0, (b / a), (c / b));
}
double t_1 = tmp;
double tmp_1;
if (b >= 0.0) {
tmp_1 = (c * 2.0) / (((-2.0 * (c * (-a / b))) - b) - b);
} else {
tmp_1 = t_0;
}
double t_2 = tmp_1;
double tmp_2;
if (b <= 5e-169) {
tmp_2 = t_1;
} else if (b <= 2e-82) {
tmp_2 = t_2;
} else if (b <= 4.5e-21) {
tmp_2 = t_1;
} else if (b <= 1.86e+143) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = -c / b;
} else {
tmp_3 = t_0;
}
tmp_2 = tmp_3;
} else {
tmp_2 = t_2;
}
return tmp_2;
}
function code(a, b, c) t_0 = Float64(Float64(b * -2.0) / Float64(2.0 * a)) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -4.0))))); else tmp = fma(-1.0, Float64(b / a), Float64(c / b)); end t_1 = tmp tmp_1 = 0.0 if (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(Float64(Float64(-2.0 * Float64(c * Float64(Float64(-a) / b))) - b) - b)); else tmp_1 = t_0; end t_2 = tmp_1 tmp_2 = 0.0 if (b <= 5e-169) tmp_2 = t_1; elseif (b <= 2e-82) tmp_2 = t_2; elseif (b <= 4.5e-21) tmp_2 = t_1; elseif (b <= 1.86e+143) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(-c) / b); else tmp_3 = t_0; end tmp_2 = tmp_3; else tmp_2 = t_2; end return tmp_2 end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision]]}, Block[{t$95$2 = If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(N[(N[(-2.0 * N[(c * N[((-a) / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], t$95$0]}, If[LessEqual[b, 5e-169], t$95$1, If[LessEqual[b, 2e-82], t$95$2, If[LessEqual[b, 4.5e-21], t$95$1, If[LessEqual[b, 1.86e+143], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], t$95$0], t$95$2]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot -2}{2 \cdot a}\\
t_1 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{c \cdot \left(a \cdot -4\right)}}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\end{array}\\
t_2 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-2 \cdot \left(c \cdot \frac{-a}{b}\right) - b\right) - b}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{if}\;b \leq 5 \cdot 10^{-169}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq 2 \cdot 10^{-82}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;b \leq 4.5 \cdot 10^{-21}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;b \leq 1.86 \cdot 10^{+143}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t_2\\
\end{array}
\end{array}
if b < 5.0000000000000002e-169 or 2e-82 < b < 4.49999999999999968e-21Initial program 66.4%
Taylor expanded in b around -inf 68.7%
fma-def68.7%
Simplified68.7%
Taylor expanded in b around 0 67.0%
associate-*r*67.0%
Simplified67.0%
if 5.0000000000000002e-169 < b < 2e-82 or 1.8599999999999999e143 < b Initial program 52.2%
Taylor expanded in b around -inf 52.2%
*-commutative52.2%
Simplified52.2%
Taylor expanded in b around inf 78.8%
associate-*l/88.7%
*-commutative88.7%
Simplified88.7%
if 4.49999999999999968e-21 < b < 1.8599999999999999e143Initial program 87.1%
Taylor expanded in b around -inf 87.1%
*-commutative87.1%
Simplified87.1%
Taylor expanded in c around 0 81.2%
associate-*r/81.2%
neg-mul-181.2%
Simplified81.2%
Final simplification74.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* b -2.0) (* 2.0 a))))
(if (<= b 5.5e+83)
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (sqrt (- (* b b) (* c (* a 4.0))))))
t_0)
(if (>= b 0.0)
(/ (* c 2.0) (- (- (* -2.0 (* c (/ (- a) b))) b) b))
t_0))))
double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (2.0 * a);
double tmp_1;
if (b <= 5.5e+83) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - sqrt(((b * b) - (c * (a * 4.0)))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (((-2.0 * (c * (-a / b))) - b) - b);
} 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) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
t_0 = (b * (-2.0d0)) / (2.0d0 * a)
if (b <= 5.5d+83) then
if (b >= 0.0d0) then
tmp_2 = (c * 2.0d0) / (-b - sqrt(((b * b) - (c * (a * 4.0d0)))))
else
tmp_2 = t_0
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = (c * 2.0d0) / ((((-2.0d0) * (c * (-a / b))) - b) - b)
else
tmp_1 = t_0
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (2.0 * a);
double tmp_1;
if (b <= 5.5e+83) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - Math.sqrt(((b * b) - (c * (a * 4.0)))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (((-2.0 * (c * (-a / b))) - b) - b);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
def code(a, b, c): t_0 = (b * -2.0) / (2.0 * a) tmp_1 = 0 if b <= 5.5e+83: tmp_2 = 0 if b >= 0.0: tmp_2 = (c * 2.0) / (-b - math.sqrt(((b * b) - (c * (a * 4.0))))) else: tmp_2 = t_0 tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = (c * 2.0) / (((-2.0 * (c * (-a / b))) - b) - b) else: tmp_1 = t_0 return tmp_1
function code(a, b, c) t_0 = Float64(Float64(b * -2.0) / Float64(2.0 * a)) tmp_1 = 0.0 if (b <= 5.5e+83) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))))); else tmp_2 = t_0; end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(Float64(Float64(-2.0 * Float64(c * Float64(Float64(-a) / b))) - b) - b)); else tmp_1 = t_0; end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = (b * -2.0) / (2.0 * a); tmp_2 = 0.0; if (b <= 5.5e+83) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (c * 2.0) / (-b - sqrt(((b * b) - (c * (a * 4.0))))); else tmp_3 = t_0; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = (c * 2.0) / (((-2.0 * (c * (-a / b))) - b) - b); else tmp_2 = t_0; end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 5.5e+83], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$0], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(N[(N[(-2.0 * N[(c * N[((-a) / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot -2}{2 \cdot a}\\
\mathbf{if}\;b \leq 5.5 \cdot 10^{+83}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-2 \cdot \left(c \cdot \frac{-a}{b}\right) - b\right) - b}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if b < 5.4999999999999996e83Initial program 72.4%
Taylor expanded in b around -inf 73.7%
*-commutative73.7%
Simplified73.7%
if 5.4999999999999996e83 < b Initial program 44.8%
Taylor expanded in b around -inf 44.8%
*-commutative44.8%
Simplified44.8%
Taylor expanded in b around inf 83.3%
associate-*l/94.5%
*-commutative94.5%
Simplified94.5%
Final simplification78.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ -2.0 (+ b (+ b (* -2.0 (* c (/ a b))))))) (* (+ (* -2.0 (/ c b)) (* 2.0 (/ b a))) -0.5)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-2.0 / (b + (b + (-2.0 * (c * (a / b))))));
} else {
tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
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 * ((-2.0d0) / (b + (b + ((-2.0d0) * (c * (a / b))))))
else
tmp = (((-2.0d0) * (c / b)) + (2.0d0 * (b / a))) * (-0.5d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-2.0 / (b + (b + (-2.0 * (c * (a / b))))));
} else {
tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c * (-2.0 / (b + (b + (-2.0 * (c * (a / b)))))) else: tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5 return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c * Float64(-2.0 / Float64(b + Float64(b + Float64(-2.0 * Float64(c * Float64(a / b))))))); else tmp = Float64(Float64(Float64(-2.0 * Float64(c / b)) + Float64(2.0 * Float64(b / a))) * -0.5); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c * (-2.0 / (b + (b + (-2.0 * (c * (a / b)))))); else tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + N[(b + N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + \left(b + -2 \cdot \left(c \cdot \frac{a}{b}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.5\\
\end{array}
\end{array}
Initial program 66.8%
Simplified66.7%
Taylor expanded in c around 0 63.9%
associate-/l*66.2%
Simplified66.2%
Taylor expanded in b around -inf 67.5%
associate-/r/67.5%
Applied egg-rr67.5%
Final simplification67.5%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (* c (/ -1.0 b)) (* (+ (* -2.0 (/ c b)) (* 2.0 (/ b a))) -0.5)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-1.0 / b);
} else {
tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
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 * ((-1.0d0) / b)
else
tmp = (((-2.0d0) * (c / b)) + (2.0d0 * (b / a))) * (-0.5d0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c * (-1.0 / b);
} else {
tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c * (-1.0 / b) else: tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5 return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c * Float64(-1.0 / b)); else tmp = Float64(Float64(Float64(-2.0 * Float64(c / b)) + Float64(2.0 * Float64(b / a))) * -0.5); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c * (-1.0 / b); else tmp = ((-2.0 * (c / b)) + (2.0 * (b / a))) * -0.5; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c * N[(-1.0 / b), $MachinePrecision]), $MachinePrecision], N[(N[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(2.0 * N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-1}{b}\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b} + 2 \cdot \frac{b}{a}\right) \cdot -0.5\\
\end{array}
\end{array}
Initial program 66.8%
Simplified66.7%
Taylor expanded in c around 0 63.9%
associate-/l*66.2%
Simplified66.2%
Taylor expanded in b around -inf 67.5%
Taylor expanded in b around inf 67.3%
Final simplification67.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ (* b -2.0) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = (b * -2.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) :: tmp
if (b >= 0.0d0) then
tmp = -b / a
else
tmp = (b * (-2.0d0)) / (2.0d0 * a)
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 = (b * -2.0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = (b * -2.0) / (2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-b) / a); else tmp = Float64(Float64(b * -2.0) / Float64(2.0 * a)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -b / a; else tmp = (b * -2.0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-b) / a), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 66.8%
Taylor expanded in b around -inf 67.9%
*-commutative67.9%
Simplified67.9%
Taylor expanded in b around -inf 32.1%
associate-*r/32.1%
mul-1-neg32.1%
Simplified32.1%
Final simplification32.1%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (/ (* b -2.0) (* 2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (b * -2.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) :: tmp
if (b >= 0.0d0) then
tmp = -c / b
else
tmp = (b * (-2.0d0)) / (2.0d0 * 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 * -2.0) / (2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = (b * -2.0) / (2.0 * 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 * -2.0) / Float64(2.0 * 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 * -2.0) / (2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{2 \cdot a}\\
\end{array}
\end{array}
Initial program 66.8%
Taylor expanded in b around -inf 67.9%
*-commutative67.9%
Simplified67.9%
Taylor expanded in c around 0 67.1%
associate-*r/67.1%
neg-mul-167.1%
Simplified67.1%
Final simplification67.1%
herbie shell --seed 2024019
(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))))