
(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 8 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) (* 4.0 (* a c)))))
(t_1 (/ (- (- b) b) (* a 2.0))))
(if (<= b -1.25e+60)
(if (>= b 0.0) t_1 (/ (- c) b))
(if (<= b 2e+71)
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ 2.0 (/ (- t_0 b) c)))
(if (>= b 0.0) t_1 (/ 2.0 (/ (* a -2.0) b)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double t_1 = (-b - b) / (a * 2.0);
double tmp_1;
if (b <= -1.25e+60) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b <= 2e+71) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = 2.0 / ((t_0 - b) / c);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_1;
} else {
tmp_1 = 2.0 / ((a * -2.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) :: t_1
real(8) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
real(8) :: tmp_3
t_0 = sqrt(((b * b) - (4.0d0 * (a * c))))
t_1 = (-b - b) / (a * 2.0d0)
if (b <= (-1.25d+60)) then
if (b >= 0.0d0) then
tmp_2 = t_1
else
tmp_2 = -c / b
end if
tmp_1 = tmp_2
else if (b <= 2d+71) then
if (b >= 0.0d0) then
tmp_3 = (-b - t_0) / (a * 2.0d0)
else
tmp_3 = 2.0d0 / ((t_0 - b) / c)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = t_1
else
tmp_1 = 2.0d0 / ((a * (-2.0d0)) / 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) - (4.0 * (a * c))));
double t_1 = (-b - b) / (a * 2.0);
double tmp_1;
if (b <= -1.25e+60) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b <= 2e+71) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = 2.0 / ((t_0 - b) / c);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = t_1;
} else {
tmp_1 = 2.0 / ((a * -2.0) / b);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) t_1 = (-b - b) / (a * 2.0) tmp_1 = 0 if b <= -1.25e+60: tmp_2 = 0 if b >= 0.0: tmp_2 = t_1 else: tmp_2 = -c / b tmp_1 = tmp_2 elif b <= 2e+71: tmp_3 = 0 if b >= 0.0: tmp_3 = (-b - t_0) / (a * 2.0) else: tmp_3 = 2.0 / ((t_0 - b) / c) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = t_1 else: tmp_1 = 2.0 / ((a * -2.0) / b) return tmp_1
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) t_1 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= -1.25e+60) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(Float64(-c) / b); end tmp_1 = tmp_2; elseif (b <= 2e+71) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(-b) - t_0) / Float64(a * 2.0)); else tmp_3 = Float64(2.0 / Float64(Float64(t_0 - b) / c)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = t_1; else tmp_1 = Float64(2.0 / Float64(Float64(a * -2.0) / b)); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); t_1 = (-b - b) / (a * 2.0); tmp_2 = 0.0; if (b <= -1.25e+60) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_1; else tmp_3 = -c / b; end tmp_2 = tmp_3; elseif (b <= 2e+71) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (-b - t_0) / (a * 2.0); else tmp_4 = 2.0 / ((t_0 - b) / c); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = t_1; else tmp_2 = 2.0 / ((a * -2.0) / b); end tmp_5 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.25e+60], If[GreaterEqual[b, 0.0], t$95$1, N[((-c) / b), $MachinePrecision]], If[LessEqual[b, 2e+71], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(N[(t$95$0 - b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$1, N[(2.0 / N[(N[(a * -2.0), $MachinePrecision] / b), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
t_1 := \frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -1.25 \cdot 10^{+60}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+71}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\frac{t_0 - b}{c}}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\frac{a \cdot -2}{b}}\\
\end{array}
\end{array}
if b < -1.24999999999999994e60Initial program 51.8%
Simplified50.6%
Taylor expanded in b around inf 50.6%
Taylor expanded in b around -inf 94.5%
associate-*r/94.5%
neg-mul-194.5%
Simplified94.5%
if -1.24999999999999994e60 < b < 2.0000000000000001e71Initial program 85.6%
Simplified85.6%
if 2.0000000000000001e71 < b Initial program 57.2%
Simplified57.2%
Taylor expanded in b around inf 97.3%
Taylor expanded in b around inf 97.3%
associate-*r/97.3%
*-commutative97.3%
Simplified97.3%
Final simplification91.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- (- b) b) (* a 2.0))))
(if (<= b -1.25e+62)
(if (>= b 0.0) t_0 (/ (- c) b))
(if (>= b 0.0)
t_0
(/ 2.0 (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) c))))))
double code(double a, double b, double c) {
double t_0 = (-b - b) / (a * 2.0);
double tmp_1;
if (b <= -1.25e+62) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = 2.0 / ((sqrt(((b * b) - (4.0 * (a * c)))) - b) / c);
}
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 - b) / (a * 2.0d0)
if (b <= (-1.25d+62)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = -c / b
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = 2.0d0 / ((sqrt(((b * b) - (4.0d0 * (a * c)))) - b) / c)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = (-b - b) / (a * 2.0);
double tmp_1;
if (b <= -1.25e+62) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = 2.0 / ((Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / c);
}
return tmp_1;
}
def code(a, b, c): t_0 = (-b - b) / (a * 2.0) tmp_1 = 0 if b <= -1.25e+62: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = -c / b tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = 2.0 / ((math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / c) return tmp_1
function code(a, b, c) t_0 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= -1.25e+62) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(Float64(-c) / b); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(2.0 / Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) - b) / c)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = (-b - b) / (a * 2.0); tmp_2 = 0.0; if (b <= -1.25e+62) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = -c / b; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = 2.0 / ((sqrt(((b * b) - (4.0 * (a * c)))) - b) / c); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.25e+62], If[GreaterEqual[b, 0.0], t$95$0, N[((-c) / b), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(2.0 / N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(4.0 * N[(a * c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{if}\;b \leq -1.25 \cdot 10^{+62}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\frac{\sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)} - b}{c}}\\
\end{array}
\end{array}
if b < -1.25000000000000007e62Initial program 51.8%
Simplified50.6%
Taylor expanded in b around inf 50.6%
Taylor expanded in b around -inf 94.5%
associate-*r/94.5%
neg-mul-194.5%
Simplified94.5%
if -1.25000000000000007e62 < b Initial program 75.1%
Simplified75.1%
Taylor expanded in b around inf 74.9%
Final simplification80.1%
(FPCore (a b c)
:precision binary64
(if (<= b -1.85e-149)
(if (>= b 0.0) (/ (- (- b) b) (* a 2.0)) (/ (- c) b))
(if (>= b 0.0)
(fma -1.0 (/ b a) (/ c b))
(* 2.0 (pow (/ (/ a -0.25) c) -0.5)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -1.85e-149) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-b - b) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = fma(-1.0, (b / a), (c / b));
} else {
tmp_1 = 2.0 * pow(((a / -0.25) / c), -0.5);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -1.85e-149) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); else tmp_2 = Float64(Float64(-c) / b); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = fma(-1.0, Float64(b / a), Float64(c / b)); else tmp_1 = Float64(2.0 * (Float64(Float64(a / -0.25) / c) ^ -0.5)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -1.85e-149], If[GreaterEqual[b, 0.0], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[Power[N[(N[(a / -0.25), $MachinePrecision] / c), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.85 \cdot 10^{-149}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot {\left(\frac{\frac{a}{-0.25}}{c}\right)}^{-0.5}\\
\end{array}
\end{array}
if b < -1.84999999999999995e-149Initial program 65.9%
Simplified65.1%
Taylor expanded in b around inf 65.1%
Taylor expanded in b around -inf 84.3%
associate-*r/84.3%
neg-mul-184.3%
Simplified84.3%
if -1.84999999999999995e-149 < b Initial program 70.9%
Simplified70.9%
Taylor expanded in b around inf 70.7%
fma-def70.7%
Simplified70.7%
expm1-log1p-u68.0%
expm1-udef62.7%
Applied egg-rr61.8%
expm1-def61.7%
expm1-log1p61.8%
+-lft-identity61.8%
associate-/l*64.4%
distribute-rgt-neg-out64.4%
unpow264.4%
Simplified64.4%
Taylor expanded in c around 0 67.5%
*-commutative67.5%
Simplified67.5%
clear-num67.5%
associate-/r/67.5%
pow1/267.5%
pow-flip67.5%
*-commutative67.5%
associate-/r*67.5%
metadata-eval67.5%
Applied egg-rr67.5%
Final simplification74.2%
(FPCore (a b c)
:precision binary64
(if (<= b -7.8e-150)
(if (>= b 0.0) (/ (- (- b) b) (* a 2.0)) (/ (- c) b))
(if (>= b 0.0)
(fma -1.0 (/ b a) (/ c b))
(sqrt (/ 4.0 (/ (/ a -0.25) c))))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -7.8e-150) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-b - b) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = fma(-1.0, (b / a), (c / b));
} else {
tmp_1 = sqrt((4.0 / ((a / -0.25) / c)));
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -7.8e-150) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); else tmp_2 = Float64(Float64(-c) / b); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = fma(-1.0, Float64(b / a), Float64(c / b)); else tmp_1 = sqrt(Float64(4.0 / Float64(Float64(a / -0.25) / c))); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -7.8e-150], If[GreaterEqual[b, 0.0], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(4.0 / N[(N[(a / -0.25), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7.8 \cdot 10^{-150}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\frac{4}{\frac{\frac{a}{-0.25}}{c}}}\\
\end{array}
\end{array}
if b < -7.8000000000000004e-150Initial program 65.9%
Simplified65.1%
Taylor expanded in b around inf 65.1%
Taylor expanded in b around -inf 84.3%
associate-*r/84.3%
neg-mul-184.3%
Simplified84.3%
if -7.8000000000000004e-150 < b Initial program 70.9%
Simplified70.9%
Taylor expanded in b around inf 70.7%
fma-def70.7%
Simplified70.7%
expm1-log1p-u68.0%
expm1-udef62.7%
Applied egg-rr61.8%
expm1-def61.7%
expm1-log1p61.8%
+-lft-identity61.8%
associate-/l*64.4%
distribute-rgt-neg-out64.4%
unpow264.4%
Simplified64.4%
Taylor expanded in c around 0 67.5%
*-commutative67.5%
Simplified67.5%
add-sqr-sqrt67.5%
sqrt-unprod67.5%
frac-times67.5%
metadata-eval67.5%
add-sqr-sqrt67.5%
*-commutative67.5%
associate-/r*67.5%
Applied egg-rr67.5%
Final simplification74.2%
(FPCore (a b c)
:precision binary64
(if (<= b -1.65e-149)
(if (>= b 0.0) (/ (- (- b) b) (* a 2.0)) (/ (- c) b))
(if (>= b 0.0)
(fma -1.0 (/ b a) (/ c b))
(/ 2.0 (sqrt (/ a (* c -0.25)))))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -1.65e-149) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (-b - b) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = fma(-1.0, (b / a), (c / b));
} else {
tmp_1 = 2.0 / sqrt((a / (c * -0.25)));
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -1.65e-149) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); else tmp_2 = Float64(Float64(-c) / b); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = fma(-1.0, Float64(b / a), Float64(c / b)); else tmp_1 = Float64(2.0 / sqrt(Float64(a / Float64(c * -0.25)))); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -1.65e-149], If[GreaterEqual[b, 0.0], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(-1.0 * N[(b / a), $MachinePrecision] + N[(c / b), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[Sqrt[N[(a / N[(c * -0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -1.65 \cdot 10^{-149}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\mathsf{fma}\left(-1, \frac{b}{a}, \frac{c}{b}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\sqrt{\frac{a}{c \cdot -0.25}}}\\
\end{array}
\end{array}
if b < -1.65000000000000009e-149Initial program 65.9%
Simplified65.1%
Taylor expanded in b around inf 65.1%
Taylor expanded in b around -inf 84.3%
associate-*r/84.3%
neg-mul-184.3%
Simplified84.3%
if -1.65000000000000009e-149 < b Initial program 70.9%
Simplified70.9%
Taylor expanded in b around inf 70.7%
fma-def70.7%
Simplified70.7%
expm1-log1p-u68.0%
expm1-udef62.7%
Applied egg-rr61.8%
expm1-def61.7%
expm1-log1p61.8%
+-lft-identity61.8%
associate-/l*64.4%
distribute-rgt-neg-out64.4%
unpow264.4%
Simplified64.4%
Taylor expanded in c around 0 67.5%
*-commutative67.5%
Simplified67.5%
Final simplification74.2%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- (- b) b) (* a 2.0)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (-b - b) / (a * 2.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 = (-b - b) / (a * 2.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 = (-b - b) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (-b - b) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - b) / Float64(a * 2.0)); else tmp = Float64(Float64(-c) / b); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (-b - b) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[((-b) - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - b}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
Initial program 68.9%
Simplified68.6%
Taylor expanded in b around inf 68.4%
Taylor expanded in b around -inf 70.1%
associate-*r/70.1%
neg-mul-170.1%
Simplified70.1%
Final simplification70.1%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (- (/ c b) (/ b a)) (* 2.0 (* 0.0 c))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c / b) - (b / a);
} else {
tmp = 2.0 * (0.0 * c);
}
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) - (b / a)
else
tmp = 2.0d0 * (0.0d0 * c)
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) - (b / a);
} else {
tmp = 2.0 * (0.0 * c);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (c / b) - (b / a) else: tmp = 2.0 * (0.0 * c) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(2.0 * Float64(0.0 * c)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (c / b) - (b / a); else tmp = 2.0 * (0.0 * c); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(0.0 * c), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(0 \cdot c\right)\\
\end{array}
\end{array}
Initial program 68.9%
Simplified68.6%
Taylor expanded in b around -inf 69.6%
Taylor expanded in b around inf 69.5%
+-commutative69.5%
mul-1-neg69.5%
unsub-neg69.5%
Simplified69.5%
div-inv69.5%
clear-num70.2%
*-commutative70.2%
Applied egg-rr43.4%
Final simplification43.4%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (- (/ c b) (/ b a)) (/ 2.0 (/ -2.0 (/ c b)))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c / b) - (b / a);
} else {
tmp = 2.0 / (-2.0 / (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 = (c / b) - (b / a)
else
tmp = 2.0d0 / ((-2.0d0) / (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 = (c / b) - (b / a);
} else {
tmp = 2.0 / (-2.0 / (c / b));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (c / b) - (b / a) else: tmp = 2.0 / (-2.0 / (c / b)) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(c / b) - Float64(b / a)); else tmp = Float64(2.0 / Float64(-2.0 / Float64(c / b))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (c / b) - (b / a); else tmp = 2.0 / (-2.0 / (c / b)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(2.0 / N[(-2.0 / N[(c / b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2}{\frac{-2}{\frac{c}{b}}}\\
\end{array}
\end{array}
Initial program 68.9%
Simplified68.6%
Taylor expanded in b around -inf 69.6%
Taylor expanded in b around inf 69.5%
+-commutative69.5%
mul-1-neg69.5%
unsub-neg69.5%
Simplified69.5%
Taylor expanded in c around 0 70.2%
associate-*r/70.2%
associate-/l*69.5%
sub-neg69.5%
mul-1-neg69.5%
distribute-rgt-out69.5%
metadata-eval69.5%
*-commutative69.5%
associate-/l*69.5%
Simplified69.5%
Final simplification69.5%
herbie shell --seed 2023334
(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)))))))