
(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.3e+106)
(if (>= b 0.0) (/ (* 2.0 c) (* b -2.0)) (/ (- (* a (/ c b)) b) a))
(if (<= b 2.8e+114)
(if (>= b 0.0) (/ (* 2.0 c) (- (- b) t_0)) (/ (- t_0 b) (* 2.0 a)))
(if (>= b 0.0) (/ c (- 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 <= -1.3e+106) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (b * -2.0);
} else {
tmp_2 = ((a * (c / b)) - b) / a;
}
tmp_1 = tmp_2;
} else if (b <= 2.8e+114) {
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 = c / -b;
} else {
tmp_1 = (b - 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
real(8) :: tmp_3
t_0 = sqrt(((b * b) - (c * (a * 4.0d0))))
if (b <= (-1.3d+106)) then
if (b >= 0.0d0) then
tmp_2 = (2.0d0 * c) / (b * (-2.0d0))
else
tmp_2 = ((a * (c / b)) - b) / a
end if
tmp_1 = tmp_2
else if (b <= 2.8d+114) then
if (b >= 0.0d0) then
tmp_3 = (2.0d0 * c) / (-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 / -b
else
tmp_1 = (b - b) / ((-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.3e+106) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (b * -2.0);
} else {
tmp_2 = ((a * (c / b)) - b) / a;
}
tmp_1 = tmp_2;
} else if (b <= 2.8e+114) {
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 = c / -b;
} else {
tmp_1 = (b - b) / (-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.3e+106: tmp_2 = 0 if b >= 0.0: tmp_2 = (2.0 * c) / (b * -2.0) else: tmp_2 = ((a * (c / b)) - b) / a tmp_1 = tmp_2 elif b <= 2.8e+114: tmp_3 = 0 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 elif b >= 0.0: tmp_1 = c / -b else: tmp_1 = (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 <= -1.3e+106) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(b * -2.0)); else tmp_2 = Float64(Float64(Float64(a * Float64(c / b)) - b) / a); end tmp_1 = tmp_2; elseif (b <= 2.8e+114) 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(c / Float64(-b)); else tmp_1 = Float64(Float64(b - b) / 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.3e+106) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (2.0 * c) / (b * -2.0); else tmp_3 = ((a * (c / b)) - b) / a; end tmp_2 = tmp_3; elseif (b <= 2.8e+114) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (2.0 * c) / (-b - t_0); else tmp_4 = (t_0 - b) / (2.0 * a); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = c / -b; else tmp_2 = (b - b) / (-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.3e+106], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]], If[LessEqual[b, 2.8e+114], 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[(c / (-b)), $MachinePrecision], N[(N[(b - 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 -1.3 \cdot 10^{+106}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot \frac{c}{b} - b}{a}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.8 \cdot 10^{+114}:\\
\;\;\;\;\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{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - b}{-2 \cdot a}\\
\end{array}
\end{array}
if b < -1.3000000000000001e106Initial program 40.0%
Taylor expanded in b around -inf 77.9%
associate-*r*77.9%
mul-1-neg77.9%
associate-/l*95.9%
Simplified95.9%
Taylor expanded in a around 0 78.3%
Simplified96.8%
Taylor expanded in b around inf 96.8%
*-commutative96.8%
Simplified96.8%
if -1.3000000000000001e106 < b < 2.8e114Initial program 89.4%
if 2.8e114 < b Initial program 56.3%
Simplified56.5%
Taylor expanded in c around 0 56.5%
Taylor expanded in c around 0 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification92.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -5e+106)
(if (>= b 0.0) (/ (* 2.0 c) (* b -2.0)) (/ (- (* a (/ c b)) b) a))
(if (<= b -5e-311)
(if (>= b 0.0)
(/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))
(/ (- t_0 b) (* 2.0 a)))
(if (<= b 4e+114)
(if (>= b 0.0)
(/ (* 2.0 c) (- (- b) t_0))
(* b (+ (/ c (pow b 2.0)) (/ -1.0 a))))
(if (>= b 0.0) (/ c (- 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+106) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (b * -2.0);
} else {
tmp_2 = ((a * (c / b)) - b) / a;
}
tmp_1 = tmp_2;
} else if (b <= -5e-311) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} else {
tmp_3 = (t_0 - b) / (2.0 * a);
}
tmp_1 = tmp_3;
} else if (b <= 4e+114) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = (2.0 * c) / (-b - t_0);
} else {
tmp_4 = b * ((c / pow(b, 2.0)) + (-1.0 / a));
}
tmp_1 = tmp_4;
} else if (b >= 0.0) {
tmp_1 = c / -b;
} else {
tmp_1 = (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+106) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(b * -2.0)); else tmp_2 = Float64(Float64(Float64(a * Float64(c / b)) - b) / a); end tmp_1 = tmp_2; elseif (b <= -5e-311) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); else tmp_3 = Float64(Float64(t_0 - b) / Float64(2.0 * a)); end tmp_1 = tmp_3; elseif (b <= 4e+114) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(2.0 * c) / Float64(Float64(-b) - t_0)); else tmp_4 = Float64(b * Float64(Float64(c / (b ^ 2.0)) + Float64(-1.0 / a))); end tmp_1 = tmp_4; elseif (b >= 0.0) tmp_1 = Float64(c / Float64(-b)); else tmp_1 = Float64(Float64(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+106], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]], If[LessEqual[b, -5e-311], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - b), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 4e+114], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(b * N[(N[(c / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(c / (-b)), $MachinePrecision], N[(N[(b - 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^{+106}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot \frac{c}{b} - b}{a}\\
\end{array}\\
\mathbf{elif}\;b \leq -5 \cdot 10^{-311}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{2 \cdot a}\\
\end{array}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{+114}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;b \cdot \left(\frac{c}{{b}^{2}} + \frac{-1}{a}\right)\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c}{-b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b - b}{-2 \cdot a}\\
\end{array}
\end{array}
if b < -4.9999999999999998e106Initial program 40.0%
Taylor expanded in b around -inf 77.9%
associate-*r*77.9%
mul-1-neg77.9%
associate-/l*95.9%
Simplified95.9%
Taylor expanded in a around 0 78.3%
Simplified96.8%
Taylor expanded in b around inf 96.8%
*-commutative96.8%
Simplified96.8%
if -4.9999999999999998e106 < b < -5.00000000000023e-311Initial program 88.9%
Taylor expanded in a around 0 88.9%
distribute-lft-out--88.9%
associate-/l*88.9%
fma-neg88.9%
Simplified88.9%
if -5.00000000000023e-311 < b < 4e114Initial program 89.8%
Taylor expanded in b around -inf 89.8%
associate-*r*89.8%
mul-1-neg89.8%
associate-/l*89.8%
Simplified89.8%
Taylor expanded in b around inf 89.8%
if 4e114 < b Initial program 56.3%
Simplified56.5%
Taylor expanded in c around 0 56.5%
Taylor expanded in c around 0 100.0%
associate-*r/100.0%
mul-1-neg100.0%
Simplified100.0%
Final simplification92.7%
(FPCore (a b c)
:precision binary64
(if (<= b -8e+106)
(if (>= b 0.0) (/ (* 2.0 c) (* b -2.0)) (/ (- (* a (/ c b)) b) a))
(if (>= b 0.0)
(/ (* 2.0 c) (* 2.0 (fma a (/ c b) (- b))))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* 2.0 a)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -8e+106) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (2.0 * c) / (b * -2.0);
} else {
tmp_2 = ((a * (c / b)) - b) / a;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * c) / (2.0 * fma(a, (c / b), -b));
} 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 <= -8e+106) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(2.0 * c) / Float64(b * -2.0)); else tmp_2 = Float64(Float64(Float64(a * Float64(c / b)) - b) / a); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * c) / Float64(2.0 * fma(a, Float64(c / b), Float64(-b)))); 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, -8e+106], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(b * -2.0), $MachinePrecision]), $MachinePrecision], N[(N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $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 -8 \cdot 10^{+106}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot \frac{c}{b} - b}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{2 \cdot a}\\
\end{array}
\end{array}
if b < -8.00000000000000073e106Initial program 40.0%
Taylor expanded in b around -inf 77.9%
associate-*r*77.9%
mul-1-neg77.9%
associate-/l*95.9%
Simplified95.9%
Taylor expanded in a around 0 78.3%
Simplified96.8%
Taylor expanded in b around inf 96.8%
*-commutative96.8%
Simplified96.8%
if -8.00000000000000073e106 < b Initial program 81.9%
Taylor expanded in a around 0 71.4%
distribute-lft-out--71.4%
associate-/l*72.7%
fma-neg72.7%
Simplified72.7%
Final simplification77.0%
(FPCore (a b c) :precision binary64 (let* ((t_0 (- (* a (/ c b)) b))) (if (>= b 0.0) (/ (* 2.0 c) (* 2.0 t_0)) (/ t_0 a))))
double code(double a, double b, double c) {
double t_0 = (a * (c / b)) - b;
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (2.0 * t_0);
} else {
tmp = t_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 = (a * (c / b)) - b
if (b >= 0.0d0) then
tmp = (2.0d0 * c) / (2.0d0 * t_0)
else
tmp = t_0 / a
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = (a * (c / b)) - b;
double tmp;
if (b >= 0.0) {
tmp = (2.0 * c) / (2.0 * t_0);
} else {
tmp = t_0 / a;
}
return tmp;
}
def code(a, b, c): t_0 = (a * (c / b)) - b tmp = 0 if b >= 0.0: tmp = (2.0 * c) / (2.0 * t_0) else: tmp = t_0 / a return tmp
function code(a, b, c) t_0 = Float64(Float64(a * Float64(c / b)) - b) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(2.0 * c) / Float64(2.0 * t_0)); else tmp = Float64(t_0 / a); end return tmp end
function tmp_2 = code(a, b, c) t_0 = (a * (c / b)) - b; tmp = 0.0; if (b >= 0.0) tmp = (2.0 * c) / (2.0 * t_0); else tmp = t_0 / a; end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[(2.0 * c), $MachinePrecision] / N[(2.0 * t$95$0), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / a), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \frac{c}{b} - b\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{2 \cdot t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0}{a}\\
\end{array}
\end{array}
Initial program 74.5%
Taylor expanded in b around -inf 69.6%
associate-*r*69.6%
mul-1-neg69.6%
associate-/l*72.8%
Simplified72.8%
Taylor expanded in a around 0 70.6%
Simplified73.8%
Taylor expanded in a around 0 65.2%
distribute-lft-out--65.2%
associate-/l*66.3%
Simplified66.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* 2.0 c) (* b -2.0)) (/ (- (* a (/ 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 = ((a * (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 = ((a * (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 = ((a * (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 = ((a * (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(Float64(a * Float64(c / b)) - 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 = ((a * (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[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision] / a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot c}{b \cdot -2}\\
\mathbf{else}:\\
\;\;\;\;\frac{a \cdot \frac{c}{b} - b}{a}\\
\end{array}
\end{array}
Initial program 74.5%
Taylor expanded in b around -inf 69.6%
associate-*r*69.6%
mul-1-neg69.6%
associate-/l*72.8%
Simplified72.8%
Taylor expanded in a around 0 70.6%
Simplified73.8%
Taylor expanded in b around inf 66.1%
*-commutative66.1%
Simplified66.1%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ c (- b)) (/ (- b b) (* -2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c / -b;
} else {
tmp = (b - b) / (-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 - b) / ((-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 - b) / (-2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c / -b else: tmp = (b - b) / (-2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c / Float64(-b)); else tmp = Float64(Float64(b - b) / 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 - b) / (-2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c / (-b)), $MachinePrecision], N[(N[(b - b), $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 - b}{-2 \cdot a}\\
\end{array}
\end{array}
Initial program 74.5%
Simplified74.6%
Taylor expanded in c around 0 44.2%
Taylor expanded in c around 0 36.4%
associate-*r/36.4%
mul-1-neg36.4%
Simplified36.4%
Final simplification36.4%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ b (- a)) (/ (- b b) (* -2.0 a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = b / -a;
} else {
tmp = (b - b) / (-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 - b) / ((-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 - b) / (-2.0 * a);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = b / -a else: tmp = (b - b) / (-2.0 * a) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(b / Float64(-a)); else tmp = Float64(Float64(b - b) / 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 - b) / (-2.0 * a); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(b / (-a)), $MachinePrecision], N[(N[(b - b), $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 - b}{-2 \cdot a}\\
\end{array}
\end{array}
Initial program 74.5%
Simplified74.6%
Taylor expanded in c around 0 44.2%
Taylor expanded in b around -inf 2.9%
associate-*r/2.9%
mul-1-neg2.9%
Simplified2.9%
Final simplification2.9%
herbie shell --seed 2024137
(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))))