
(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 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) (/ (- (- b) t_0) (* 2.0 a)) (/ (* 2.0 c) (+ (- b) t_0)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt(((b * b) - ((4.0d0 * a) * c)))
if (b >= 0.0d0) then
tmp = (-b - t_0) / (2.0d0 * a)
else
tmp = (2.0d0 * c) / (-b + t_0)
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double t_0 = Math.sqrt(((b * b) - ((4.0 * a) * c)));
double tmp;
if (b >= 0.0) {
tmp = (-b - t_0) / (2.0 * a);
} else {
tmp = (2.0 * c) / (-b + t_0);
}
return tmp;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - ((4.0 * a) * c))) tmp = 0 if b >= 0.0: tmp = (-b - t_0) / (2.0 * a) else: tmp = (2.0 * c) / (-b + t_0) return tmp
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(Float64(4.0 * a) * c))) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(Float64(-b) - t_0) / Float64(2.0 * a)); else tmp = Float64(Float64(2.0 * c) / Float64(Float64(-b) + t_0)); end return tmp end
function tmp_2 = code(a, b, c) t_0 = sqrt(((b * b) - ((4.0 * a) * c))); tmp = 0.0; if (b >= 0.0) tmp = (-b - t_0) / (2.0 * a); else tmp = (2.0 * c) / (-b + t_0); end tmp_2 = tmp; end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(N[(4.0 * a), $MachinePrecision] * c), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(2.0 * a), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[((-b) + t$95$0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - \left(4 \cdot a\right) \cdot c}\\
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{2 \cdot a}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{\left(-b\right) + t_0}\\
\end{array}
\end{array}
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -1e+154)
(if (>= b 0.0) (/ (* b -2.0) (* a 2.0)) (/ (- c) b))
(if (<= b 1e+116)
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ (* 2.0 c) (- t_0 b)))
(if (>= b 0.0)
(* -0.5 (+ (/ b a) (/ (+ b (* -2.0 (/ c (/ b a)))) a)))
(/ 2.0 (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) c)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -1e+154) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (b * -2.0) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b <= 1e+116) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = (2.0 * c) / (t_0 - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a));
} 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
real(8) :: tmp_3
t_0 = sqrt(((b * b) - (c * (a * 4.0d0))))
if (b <= (-1d+154)) then
if (b >= 0.0d0) then
tmp_2 = (b * (-2.0d0)) / (a * 2.0d0)
else
tmp_2 = -c / b
end if
tmp_1 = tmp_2
else if (b <= 1d+116) then
if (b >= 0.0d0) then
tmp_3 = (-b - t_0) / (a * 2.0d0)
else
tmp_3 = (2.0d0 * c) / (t_0 - b)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = (-0.5d0) * ((b / a) + ((b + ((-2.0d0) * (c / (b / a)))) / a))
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 = Math.sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -1e+154) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (b * -2.0) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b <= 1e+116) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = (2.0 * c) / (t_0 - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a));
} 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 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if b <= -1e+154: tmp_2 = 0 if b >= 0.0: tmp_2 = (b * -2.0) / (a * 2.0) else: tmp_2 = -c / b tmp_1 = tmp_2 elif b <= 1e+116: tmp_3 = 0 if b >= 0.0: tmp_3 = (-b - t_0) / (a * 2.0) else: tmp_3 = (2.0 * c) / (t_0 - b) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a)) 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 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -1e+154) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); else tmp_2 = Float64(Float64(-c) / b); end tmp_1 = tmp_2; elseif (b <= 1e+116) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(-b) - t_0) / Float64(a * 2.0)); else tmp_3 = Float64(Float64(2.0 * c) / Float64(t_0 - b)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(-0.5 * Float64(Float64(b / a) + Float64(Float64(b + Float64(-2.0 * Float64(c / Float64(b / a)))) / a))); 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_5 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if (b <= -1e+154) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (b * -2.0) / (a * 2.0); else tmp_3 = -c / b; end tmp_2 = tmp_3; elseif (b <= 1e+116) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (-b - t_0) / (a * 2.0); else tmp_4 = (2.0 * c) / (t_0 - b); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a)); else tmp_2 = 2.0 / ((sqrt(((b * b) - (4.0 * (a * c)))) - b) / c); 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, -1e+154], If[GreaterEqual[b, 0.0], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]], If[LessEqual[b, 1e+116], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(2.0 * c), $MachinePrecision] / N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b / a), $MachinePrecision] + N[(N[(b + N[(-2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\\
\mathbf{elif}\;b \leq 10^{+116}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{2 \cdot c}{t_0 - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \left(\frac{b}{a} + \frac{b + -2 \cdot \frac{c}{\frac{b}{a}}}{a}\right)\\
\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.00000000000000004e154Initial program 37.1%
associate-*l*37.1%
*-commutative37.1%
associate-/l*37.2%
associate-*l*37.2%
Simplified37.2%
Taylor expanded in b around inf 37.2%
*-commutative37.2%
Simplified37.2%
Taylor expanded in b around -inf 95.6%
associate-*r/95.6%
mul-1-neg95.6%
Simplified95.6%
if -1.00000000000000004e154 < b < 1.00000000000000002e116Initial program 87.0%
if 1.00000000000000002e116 < b Initial program 57.0%
associate-*l*57.0%
*-commutative57.0%
associate-/l*57.0%
associate-*l*57.0%
Simplified57.0%
div-sub57.0%
neg-mul-157.0%
*-commutative57.0%
times-frac57.0%
metadata-eval57.0%
*-un-lft-identity57.0%
*-commutative57.0%
times-frac57.0%
metadata-eval57.0%
cancel-sign-sub-inv57.0%
fma-def57.0%
metadata-eval57.0%
Applied egg-rr57.0%
cancel-sign-sub-inv57.0%
metadata-eval57.0%
distribute-lft-out57.0%
*-commutative57.0%
*-commutative57.0%
associate-*l*57.0%
Simplified57.0%
Taylor expanded in b around inf 90.2%
associate-/l*98.7%
Simplified98.7%
Final simplification90.2%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* 4.0 (* a c))))) (t_1 (/ 2.0 (/ (- t_0 b) c))))
(if (<= b -1.1e+154)
(if (>= b 0.0) (/ (* b -2.0) (* a 2.0)) (/ (- c) b))
(if (<= b 5e+104)
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) t_1)
(if (>= b 0.0)
(* -0.5 (+ (/ b a) (/ (+ b (* -2.0 (/ c (/ b a)))) a)))
t_1)))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (4.0 * (a * c))));
double t_1 = 2.0 / ((t_0 - b) / c);
double tmp_1;
if (b <= -1.1e+154) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (b * -2.0) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b <= 5e+104) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = t_1;
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a));
} else {
tmp_1 = t_1;
}
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 = 2.0d0 / ((t_0 - b) / c)
if (b <= (-1.1d+154)) then
if (b >= 0.0d0) then
tmp_2 = (b * (-2.0d0)) / (a * 2.0d0)
else
tmp_2 = -c / b
end if
tmp_1 = tmp_2
else if (b <= 5d+104) then
if (b >= 0.0d0) then
tmp_3 = (-b - t_0) / (a * 2.0d0)
else
tmp_3 = t_1
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = (-0.5d0) * ((b / a) + ((b + ((-2.0d0) * (c / (b / a)))) / a))
else
tmp_1 = t_1
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 = 2.0 / ((t_0 - b) / c);
double tmp_1;
if (b <= -1.1e+154) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (b * -2.0) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b <= 5e+104) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = t_1;
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a));
} else {
tmp_1 = t_1;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (4.0 * (a * c)))) t_1 = 2.0 / ((t_0 - b) / c) tmp_1 = 0 if b <= -1.1e+154: tmp_2 = 0 if b >= 0.0: tmp_2 = (b * -2.0) / (a * 2.0) else: tmp_2 = -c / b tmp_1 = tmp_2 elif b <= 5e+104: tmp_3 = 0 if b >= 0.0: tmp_3 = (-b - t_0) / (a * 2.0) else: tmp_3 = t_1 tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a)) else: tmp_1 = t_1 return tmp_1
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(4.0 * Float64(a * c)))) t_1 = Float64(2.0 / Float64(Float64(t_0 - b) / c)) tmp_1 = 0.0 if (b <= -1.1e+154) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); else tmp_2 = Float64(Float64(-c) / b); end tmp_1 = tmp_2; elseif (b <= 5e+104) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(Float64(-b) - t_0) / Float64(a * 2.0)); else tmp_3 = t_1; end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(-0.5 * Float64(Float64(b / a) + Float64(Float64(b + Float64(-2.0 * Float64(c / Float64(b / a)))) / a))); else tmp_1 = t_1; end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = sqrt(((b * b) - (4.0 * (a * c)))); t_1 = 2.0 / ((t_0 - b) / c); tmp_2 = 0.0; if (b <= -1.1e+154) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (b * -2.0) / (a * 2.0); else tmp_3 = -c / b; end tmp_2 = tmp_3; elseif (b <= 5e+104) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (-b - t_0) / (a * 2.0); else tmp_4 = t_1; end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a)); else tmp_2 = t_1; 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[(2.0 / N[(N[(t$95$0 - b), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, -1.1e+154], If[GreaterEqual[b, 0.0], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]], If[LessEqual[b, 5e+104], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], t$95$1], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b / a), $MachinePrecision] + N[(N[(b + N[(-2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - 4 \cdot \left(a \cdot c\right)}\\
t_1 := \frac{2}{\frac{t_0 - b}{c}}\\
\mathbf{if}\;b \leq -1.1 \cdot 10^{+154}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\\
\mathbf{elif}\;b \leq 5 \cdot 10^{+104}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \left(\frac{b}{a} + \frac{b + -2 \cdot \frac{c}{\frac{b}{a}}}{a}\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
if b < -1.1000000000000001e154Initial program 37.1%
associate-*l*37.1%
*-commutative37.1%
associate-/l*37.2%
associate-*l*37.2%
Simplified37.2%
Taylor expanded in b around inf 37.2%
*-commutative37.2%
Simplified37.2%
Taylor expanded in b around -inf 95.6%
associate-*r/95.6%
mul-1-neg95.6%
Simplified95.6%
if -1.1000000000000001e154 < b < 4.9999999999999997e104Initial program 87.0%
associate-*l*86.9%
*-commutative86.9%
associate-/l*85.8%
associate-*l*85.8%
Simplified85.8%
if 4.9999999999999997e104 < b Initial program 57.0%
associate-*l*57.0%
*-commutative57.0%
associate-/l*57.0%
associate-*l*57.0%
Simplified57.0%
div-sub57.0%
neg-mul-157.0%
*-commutative57.0%
times-frac57.0%
metadata-eval57.0%
*-un-lft-identity57.0%
*-commutative57.0%
times-frac57.0%
metadata-eval57.0%
cancel-sign-sub-inv57.0%
fma-def57.0%
metadata-eval57.0%
Applied egg-rr57.0%
cancel-sign-sub-inv57.0%
metadata-eval57.0%
distribute-lft-out57.0%
*-commutative57.0%
*-commutative57.0%
associate-*l*57.0%
Simplified57.0%
Taylor expanded in b around inf 90.2%
associate-/l*98.7%
Simplified98.7%
Final simplification89.4%
(FPCore (a b c)
:precision binary64
(if (<= b -1.12e+151)
(if (>= b 0.0) (/ (* b -2.0) (* a 2.0)) (/ (- c) b))
(if (>= b 0.0)
(* -0.5 (+ (/ b a) (/ (+ b (* -2.0 (/ c (/ b a)))) a)))
(/ 2.0 (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) c)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -1.12e+151) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (b * -2.0) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a));
} 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) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
if (b <= (-1.12d+151)) then
if (b >= 0.0d0) then
tmp_2 = (b * (-2.0d0)) / (a * 2.0d0)
else
tmp_2 = -c / b
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = (-0.5d0) * ((b / a) + ((b + ((-2.0d0) * (c / (b / a)))) / a))
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 tmp_1;
if (b <= -1.12e+151) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (b * -2.0) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a));
} else {
tmp_1 = 2.0 / ((Math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / c);
}
return tmp_1;
}
def code(a, b, c): tmp_1 = 0 if b <= -1.12e+151: tmp_2 = 0 if b >= 0.0: tmp_2 = (b * -2.0) / (a * 2.0) else: tmp_2 = -c / b tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a)) else: tmp_1 = 2.0 / ((math.sqrt(((b * b) - (4.0 * (a * c)))) - b) / c) return tmp_1
function code(a, b, c) tmp_1 = 0.0 if (b <= -1.12e+151) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); else tmp_2 = Float64(Float64(-c) / b); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(-0.5 * Float64(Float64(b / a) + Float64(Float64(b + Float64(-2.0 * Float64(c / Float64(b / a)))) / a))); 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) tmp_2 = 0.0; if (b <= -1.12e+151) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (b * -2.0) / (a * 2.0); else tmp_3 = -c / b; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = -0.5 * ((b / a) + ((b + (-2.0 * (c / (b / a)))) / a)); else tmp_2 = 2.0 / ((sqrt(((b * b) - (4.0 * (a * c)))) - b) / c); end tmp_4 = tmp_2; end
code[a_, b_, c_] := If[LessEqual[b, -1.12e+151], If[GreaterEqual[b, 0.0], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b / a), $MachinePrecision] + N[(N[(b + N[(-2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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}
\mathbf{if}\;b \leq -1.12 \cdot 10^{+151}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \left(\frac{b}{a} + \frac{b + -2 \cdot \frac{c}{\frac{b}{a}}}{a}\right)\\
\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.12000000000000004e151Initial program 37.1%
associate-*l*37.1%
*-commutative37.1%
associate-/l*37.2%
associate-*l*37.2%
Simplified37.2%
Taylor expanded in b around inf 37.2%
*-commutative37.2%
Simplified37.2%
Taylor expanded in b around -inf 95.6%
associate-*r/95.6%
mul-1-neg95.6%
Simplified95.6%
if -1.12000000000000004e151 < b Initial program 81.4%
associate-*l*81.3%
*-commutative81.3%
associate-/l*80.5%
associate-*l*80.5%
Simplified80.5%
div-sub80.5%
neg-mul-180.5%
*-commutative80.5%
times-frac80.5%
metadata-eval80.5%
*-un-lft-identity80.5%
*-commutative80.5%
times-frac80.5%
metadata-eval80.5%
cancel-sign-sub-inv80.5%
fma-def80.5%
metadata-eval80.5%
Applied egg-rr80.5%
cancel-sign-sub-inv80.5%
metadata-eval80.5%
distribute-lft-out80.5%
*-commutative80.5%
*-commutative80.5%
associate-*l*80.5%
Simplified80.5%
Taylor expanded in b around inf 72.6%
associate-/l*74.1%
Simplified74.1%
Final simplification77.5%
(FPCore (a b c)
:precision binary64
(if (<= b -1.05e+151)
(if (>= b 0.0) (/ (* b -2.0) (* a 2.0)) (/ (- c) b))
(if (>= b 0.0)
(* -0.5 (fma (/ b a) 2.0 (/ -2.0 (/ b c))))
(/ 2.0 (/ (- (sqrt (- (* b b) (* 4.0 (* a c)))) b) c)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -1.05e+151) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (b * -2.0) / (a * 2.0);
} else {
tmp_2 = -c / b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -0.5 * fma((b / a), 2.0, (-2.0 / (b / c)));
} else {
tmp_1 = 2.0 / ((sqrt(((b * b) - (4.0 * (a * c)))) - b) / c);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -1.05e+151) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); else tmp_2 = Float64(Float64(-c) / b); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(-0.5 * fma(Float64(b / a), 2.0, Float64(-2.0 / Float64(b / c)))); 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
code[a_, b_, c_] := If[LessEqual[b, -1.05e+151], If[GreaterEqual[b, 0.0], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b / a), $MachinePrecision] * 2.0 + N[(-2.0 / N[(b / c), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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}
\mathbf{if}\;b \leq -1.05 \cdot 10^{+151}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \mathsf{fma}\left(\frac{b}{a}, 2, \frac{-2}{\frac{b}{c}}\right)\\
\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.05e151Initial program 37.1%
associate-*l*37.1%
*-commutative37.1%
associate-/l*37.2%
associate-*l*37.2%
Simplified37.2%
Taylor expanded in b around inf 37.2%
*-commutative37.2%
Simplified37.2%
Taylor expanded in b around -inf 95.6%
associate-*r/95.6%
mul-1-neg95.6%
Simplified95.6%
if -1.05e151 < b Initial program 81.4%
associate-*l*81.3%
*-commutative81.3%
associate-/l*80.5%
associate-*l*80.5%
Simplified80.5%
div-sub80.5%
neg-mul-180.5%
*-commutative80.5%
times-frac80.5%
metadata-eval80.5%
*-un-lft-identity80.5%
*-commutative80.5%
times-frac80.5%
metadata-eval80.5%
cancel-sign-sub-inv80.5%
fma-def80.5%
metadata-eval80.5%
Applied egg-rr80.5%
cancel-sign-sub-inv80.5%
metadata-eval80.5%
distribute-lft-out80.5%
*-commutative80.5%
*-commutative80.5%
associate-*l*80.5%
Simplified80.5%
pow1/280.6%
fma-udef80.5%
associate-*r*80.5%
*-commutative80.5%
*-commutative80.5%
metadata-eval80.5%
cancel-sign-sub-inv80.5%
metadata-eval80.5%
pow-pow72.7%
cancel-sign-sub-inv72.7%
metadata-eval72.7%
*-commutative72.7%
*-commutative72.7%
associate-*r*72.7%
fma-udef72.7%
pow1/374.3%
expm1-log1p-u73.5%
expm1-udef65.8%
Applied egg-rr63.2%
expm1-def72.1%
expm1-log1p73.1%
Simplified73.1%
Taylor expanded in b around inf 38.0%
+-commutative38.0%
*-commutative38.0%
fma-def38.0%
associate-*r/38.0%
*-commutative38.0%
associate-*r*38.0%
unpow238.0%
rem-square-sqrt74.2%
metadata-eval74.2%
associate-/l*74.2%
Simplified74.2%
Final simplification77.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (- (/ c b) (/ b a)) (* c (/ -2.0 (- b (fma 2.0 (/ c (/ b a)) (- b)))))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c / b) - (b / a);
} else {
tmp = c * (-2.0 / (b - fma(2.0, (c / (b / a)), -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(c * Float64(-2.0 / Float64(b - fma(2.0, Float64(c / Float64(b / a)), Float64(-b))))); end return tmp end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(c / b), $MachinePrecision] - N[(b / a), $MachinePrecision]), $MachinePrecision], N[(c * N[(-2.0 / N[(b - N[(2.0 * N[(c / N[(b / a), $MachinePrecision]), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \frac{-2}{b - \mathsf{fma}\left(2, \frac{c}{\frac{b}{a}}, -b\right)}\\
\end{array}
\end{array}
Initial program 74.3%
Simplified74.1%
Taylor expanded in b around -inf 73.1%
fma-def73.1%
associate-/l*73.5%
mul-1-neg73.5%
Simplified73.5%
Taylor expanded in a around 0 68.3%
mul-1-neg68.3%
unsub-neg68.3%
Simplified68.3%
Final simplification68.3%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* b -2.0) (* a 2.0)) (* c (/ 2.0 (* b -2.0)))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (b * -2.0) / (a * 2.0);
} else {
tmp = c * (2.0 / (b * -2.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) :: tmp
if (b >= 0.0d0) then
tmp = (b * (-2.0d0)) / (a * 2.0d0)
else
tmp = c * (2.0d0 / (b * (-2.0d0)))
end if
code = tmp
end function
public static double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (b * -2.0) / (a * 2.0);
} else {
tmp = c * (2.0 / (b * -2.0));
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (b * -2.0) / (a * 2.0) else: tmp = c * (2.0 / (b * -2.0)) return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(b * -2.0) / Float64(a * 2.0)); else tmp = Float64(c * Float64(2.0 / Float64(b * -2.0))); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = (b * -2.0) / (a * 2.0); else tmp = c * (2.0 / (b * -2.0)); end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(c * N[(2.0 / N[(b * -2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;c \cdot \frac{2}{b \cdot -2}\\
\end{array}
\end{array}
Initial program 74.3%
associate-*l*74.2%
*-commutative74.2%
associate-/l*73.5%
associate-*l*73.5%
Simplified73.5%
Taylor expanded in b around inf 68.1%
*-commutative68.1%
Simplified68.1%
Taylor expanded in b around -inf 67.4%
associate-*r/67.4%
*-commutative67.4%
Simplified67.4%
associate-/r/68.0%
Applied egg-rr68.0%
Final simplification68.0%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (* b -2.0) (* a 2.0)) (/ (- c) b)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (b * -2.0) / (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 * (-2.0d0)) / (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 * -2.0) / (a * 2.0);
} else {
tmp = -c / b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (b * -2.0) / (a * 2.0) else: tmp = -c / b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(b * -2.0) / 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 * -2.0) / (a * 2.0); else tmp = -c / b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[((-c) / b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{-c}{b}\\
\end{array}
\end{array}
Initial program 74.3%
associate-*l*74.2%
*-commutative74.2%
associate-/l*73.5%
associate-*l*73.5%
Simplified73.5%
Taylor expanded in b around inf 68.1%
*-commutative68.1%
Simplified68.1%
Taylor expanded in b around -inf 68.1%
associate-*r/68.1%
mul-1-neg68.1%
Simplified68.1%
Final simplification68.1%
herbie shell --seed 2023187
(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)))))))