
(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 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) (/ (* 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))))) (t_1 (/ (- c) b)))
(if (<= b -5e+148)
(if (>= b 0.0) (/ b a) (* (+ (* -2.0 (/ c b)) (* (/ b a) 2.0)) -0.5))
(if (<= b 7.8e+105)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_0)) (/ (- t_0 b) (* a 2.0)))
(if (>= b 0.0)
(/
(* c 2.0)
(+
(* b -2.0)
(*
a
(+
(* -1.3333333333333333 t_1)
(* -0.6666666666666666 (* (pow 1.0 0.3333333333333333) t_1))))))
(/ (* b -2.0) (* a 2.0)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double t_1 = -c / b;
double tmp_1;
if (b <= -5e+148) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = b / a;
} else {
tmp_2 = ((-2.0 * (c / b)) + ((b / a) * 2.0)) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 7.8e+105) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_0);
} else {
tmp_3 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / ((b * -2.0) + (a * ((-1.3333333333333333 * t_1) + (-0.6666666666666666 * (pow(1.0, 0.3333333333333333) * t_1)))));
} else {
tmp_1 = (b * -2.0) / (a * 2.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) :: t_1
real(8) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
real(8) :: tmp_3
t_0 = sqrt(((b * b) - (c * (a * 4.0d0))))
t_1 = -c / b
if (b <= (-5d+148)) then
if (b >= 0.0d0) then
tmp_2 = b / a
else
tmp_2 = (((-2.0d0) * (c / b)) + ((b / a) * 2.0d0)) * (-0.5d0)
end if
tmp_1 = tmp_2
else if (b <= 7.8d+105) then
if (b >= 0.0d0) then
tmp_3 = (c * 2.0d0) / (-b - t_0)
else
tmp_3 = (t_0 - b) / (a * 2.0d0)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = (c * 2.0d0) / ((b * (-2.0d0)) + (a * (((-1.3333333333333333d0) * t_1) + ((-0.6666666666666666d0) * ((1.0d0 ** 0.3333333333333333d0) * t_1)))))
else
tmp_1 = (b * (-2.0d0)) / (a * 2.0d0)
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 t_1 = -c / b;
double tmp_1;
if (b <= -5e+148) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = b / a;
} else {
tmp_2 = ((-2.0 * (c / b)) + ((b / a) * 2.0)) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 7.8e+105) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_0);
} else {
tmp_3 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / ((b * -2.0) + (a * ((-1.3333333333333333 * t_1) + (-0.6666666666666666 * (Math.pow(1.0, 0.3333333333333333) * t_1)))));
} else {
tmp_1 = (b * -2.0) / (a * 2.0);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (a * 4.0)))) t_1 = -c / b tmp_1 = 0 if b <= -5e+148: tmp_2 = 0 if b >= 0.0: tmp_2 = b / a else: tmp_2 = ((-2.0 * (c / b)) + ((b / a) * 2.0)) * -0.5 tmp_1 = tmp_2 elif b <= 7.8e+105: tmp_3 = 0 if b >= 0.0: tmp_3 = (c * 2.0) / (-b - t_0) else: tmp_3 = (t_0 - b) / (a * 2.0) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = (c * 2.0) / ((b * -2.0) + (a * ((-1.3333333333333333 * t_1) + (-0.6666666666666666 * (math.pow(1.0, 0.3333333333333333) * t_1))))) else: tmp_1 = (b * -2.0) / (a * 2.0) return tmp_1
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) t_1 = Float64(Float64(-c) / b) tmp_1 = 0.0 if (b <= -5e+148) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(b / a); else tmp_2 = Float64(Float64(Float64(-2.0 * Float64(c / b)) + Float64(Float64(b / a) * 2.0)) * -0.5); end tmp_1 = tmp_2; elseif (b <= 7.8e+105) 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(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(Float64(b * -2.0) + Float64(a * Float64(Float64(-1.3333333333333333 * t_1) + Float64(-0.6666666666666666 * Float64((1.0 ^ 0.3333333333333333) * t_1)))))); else tmp_1 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (a * 4.0)))); t_1 = -c / b; tmp_2 = 0.0; if (b <= -5e+148) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = b / a; else tmp_3 = ((-2.0 * (c / b)) + ((b / a) * 2.0)) * -0.5; end tmp_2 = tmp_3; elseif (b <= 7.8e+105) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (c * 2.0) / (-b - t_0); else tmp_4 = (t_0 - b) / (a * 2.0); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = (c * 2.0) / ((b * -2.0) + (a * ((-1.3333333333333333 * t_1) + (-0.6666666666666666 * ((1.0 ^ 0.3333333333333333) * t_1))))); else tmp_2 = (b * -2.0) / (a * 2.0); 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]}, Block[{t$95$1 = N[((-c) / b), $MachinePrecision]}, If[LessEqual[b, -5e+148], If[GreaterEqual[b, 0.0], N[(b / a), $MachinePrecision], N[(N[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(N[(b / a), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]], If[LessEqual[b, 7.8e+105], 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[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[(N[(b * -2.0), $MachinePrecision] + N[(a * N[(N[(-1.3333333333333333 * t$95$1), $MachinePrecision] + N[(-0.6666666666666666 * N[(N[Power[1.0, 0.3333333333333333], $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
t_1 := \frac{-c}{b}\\
\mathbf{if}\;b \leq -5 \cdot 10^{+148}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b} + \frac{b}{a} \cdot 2\right) \cdot -0.5\\
\end{array}\\
\mathbf{elif}\;b \leq 7.8 \cdot 10^{+105}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{b \cdot -2 + a \cdot \left(-1.3333333333333333 \cdot t_1 + -0.6666666666666666 \cdot \left({1}^{0.3333333333333333} \cdot t_1\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}
\end{array}
if b < -5.00000000000000024e148Initial program 38.0%
Simplified38.0%
Taylor expanded in c around 0 38.0%
+-commutative38.0%
fma-def38.0%
associate-/l*38.0%
associate-/r/38.0%
Simplified38.0%
Taylor expanded in b around -inf 89.6%
fma-def89.6%
associate-/l*97.5%
*-commutative97.5%
Simplified97.5%
Taylor expanded in c around inf 97.5%
Taylor expanded in a around 0 97.5%
if -5.00000000000000024e148 < b < 7.79999999999999957e105Initial program 89.6%
if 7.79999999999999957e105 < b Initial program 48.8%
Taylor expanded in b around -inf 48.8%
*-commutative48.8%
Simplified48.8%
add-cube-cbrt48.5%
pow348.5%
pow248.5%
associate-*l*48.5%
cancel-sign-sub-inv48.5%
metadata-eval48.5%
Applied egg-rr48.5%
Taylor expanded in a around 0 100.0%
Final simplification93.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -2.2e+147)
(if (>= b 0.0) (/ b a) (* (+ (* -2.0 (/ c b)) (* (/ b a) 2.0)) -0.5))
(if (<= b 2e+151)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_0)) (/ (- t_0 b) (* a 2.0)))
(if (>= b 0.0) (/ (- c) b) (/ (* b -2.0) (* a 2.0)))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -2.2e+147) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = b / a;
} else {
tmp_2 = ((-2.0 * (c / b)) + ((b / a) * 2.0)) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 2e+151) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_0);
} else {
tmp_3 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (b * -2.0) / (a * 2.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
real(8) :: tmp_3
t_0 = sqrt(((b * b) - (c * (a * 4.0d0))))
if (b <= (-2.2d+147)) then
if (b >= 0.0d0) then
tmp_2 = b / a
else
tmp_2 = (((-2.0d0) * (c / b)) + ((b / a) * 2.0d0)) * (-0.5d0)
end if
tmp_1 = tmp_2
else if (b <= 2d+151) then
if (b >= 0.0d0) then
tmp_3 = (c * 2.0d0) / (-b - t_0)
else
tmp_3 = (t_0 - b) / (a * 2.0d0)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = -c / b
else
tmp_1 = (b * (-2.0d0)) / (a * 2.0d0)
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 <= -2.2e+147) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = b / a;
} else {
tmp_2 = ((-2.0 * (c / b)) + ((b / a) * 2.0)) * -0.5;
}
tmp_1 = tmp_2;
} else if (b <= 2e+151) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_0);
} else {
tmp_3 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = (b * -2.0) / (a * 2.0);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if b <= -2.2e+147: tmp_2 = 0 if b >= 0.0: tmp_2 = b / a else: tmp_2 = ((-2.0 * (c / b)) + ((b / a) * 2.0)) * -0.5 tmp_1 = tmp_2 elif b <= 2e+151: tmp_3 = 0 if b >= 0.0: tmp_3 = (c * 2.0) / (-b - t_0) else: tmp_3 = (t_0 - b) / (a * 2.0) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = -c / b else: tmp_1 = (b * -2.0) / (a * 2.0) 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 <= -2.2e+147) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(b / a); else tmp_2 = Float64(Float64(Float64(-2.0 * Float64(c / b)) + Float64(Float64(b / a) * 2.0)) * -0.5); end tmp_1 = tmp_2; elseif (b <= 2e+151) 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(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(Float64(-c) / b); else tmp_1 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); 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 <= -2.2e+147) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = b / a; else tmp_3 = ((-2.0 * (c / b)) + ((b / a) * 2.0)) * -0.5; end tmp_2 = tmp_3; elseif (b <= 2e+151) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (c * 2.0) / (-b - t_0); else tmp_4 = (t_0 - b) / (a * 2.0); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = -c / b; else tmp_2 = (b * -2.0) / (a * 2.0); 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, -2.2e+147], If[GreaterEqual[b, 0.0], N[(b / a), $MachinePrecision], N[(N[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] + N[(N[(b / a), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]], If[LessEqual[b, 2e+151], 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[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $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 -2.2 \cdot 10^{+147}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b} + \frac{b}{a} \cdot 2\right) \cdot -0.5\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+151}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t_0 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}
\end{array}
if b < -2.2000000000000002e147Initial program 38.0%
Simplified38.0%
Taylor expanded in c around 0 38.0%
+-commutative38.0%
fma-def38.0%
associate-/l*38.0%
associate-/r/38.0%
Simplified38.0%
Taylor expanded in b around -inf 89.6%
fma-def89.6%
associate-/l*97.5%
*-commutative97.5%
Simplified97.5%
Taylor expanded in c around inf 97.5%
Taylor expanded in a around 0 97.5%
if -2.2000000000000002e147 < b < 2.00000000000000003e151Initial program 90.4%
if 2.00000000000000003e151 < b Initial program 36.9%
Taylor expanded in b around -inf 36.9%
*-commutative36.9%
Simplified36.9%
Taylor expanded in c around 0 99.7%
associate-*r/99.7%
neg-mul-199.7%
Simplified99.7%
Final simplification93.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* b -2.0) (* a 2.0))))
(if (<= b 1e+149)
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (sqrt (- (* b b) (* c (* a 4.0))))))
t_0)
(if (>= b 0.0) (/ (- c) b) t_0))))
double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (a * 2.0);
double tmp_1;
if (b <= 1e+149) {
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 / 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)) / (a * 2.0d0)
if (b <= 1d+149) 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 / 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) / (a * 2.0);
double tmp_1;
if (b <= 1e+149) {
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 / b;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
def code(a, b, c): t_0 = (b * -2.0) / (a * 2.0) tmp_1 = 0 if b <= 1e+149: 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 / b else: tmp_1 = t_0 return tmp_1
function code(a, b, c) t_0 = Float64(Float64(b * -2.0) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= 1e+149) 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) / b); else tmp_1 = t_0; end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = (b * -2.0) / (a * 2.0); tmp_2 = 0.0; if (b <= 1e+149) 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 / 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[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1e+149], 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[((-c) / b), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot -2}{a \cdot 2}\\
\mathbf{if}\;b \leq 10^{+149}:\\
\;\;\;\;\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}{b}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if b < 1.00000000000000005e149Initial program 80.9%
Taylor expanded in b around -inf 72.8%
*-commutative72.8%
Simplified72.8%
if 1.00000000000000005e149 < b Initial program 36.9%
Taylor expanded in b around -inf 36.9%
*-commutative36.9%
Simplified36.9%
Taylor expanded in c around 0 99.7%
associate-*r/99.7%
neg-mul-199.7%
Simplified99.7%
Final simplification78.3%
(FPCore (a b c)
:precision binary64
(if (<= b 3.8e-48)
(if (>= b 0.0)
(/ (* c 2.0) (- (- b) (sqrt (* c (* a -4.0)))))
(/ (* b -2.0) (* a 2.0)))
(if (>= b 0.0)
(* c (/ -2.0 (+ b (fma -2.0 (* c (/ a b)) b))))
(* (* -2.0 (/ c b)) -0.5))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= 3.8e-48) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - sqrt((c * (a * -4.0))));
} else {
tmp_2 = (b * -2.0) / (a * 2.0);
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = c * (-2.0 / (b + fma(-2.0, (c * (a / b)), b)));
} else {
tmp_1 = (-2.0 * (c / b)) * -0.5;
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= 3.8e-48) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(Float64(c * Float64(a * -4.0))))); else tmp_2 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(c * Float64(-2.0 / Float64(b + fma(-2.0, Float64(c * Float64(a / b)), b)))); else tmp_1 = Float64(Float64(-2.0 * Float64(c / b)) * -0.5); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, 3.8e-48], 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[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(c * N[(-2.0 / N[(b + N[(-2.0 * N[(c * N[(a / b), $MachinePrecision]), $MachinePrecision] + b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.8 \cdot 10^{-48}:\\
\;\;\;\;\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}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;c \cdot \frac{-2}{b + \mathsf{fma}\left(-2, c \cdot \frac{a}{b}, b\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b}\right) \cdot -0.5\\
\end{array}
\end{array}
if b < 3.80000000000000002e-48Initial program 77.8%
Taylor expanded in b around -inf 67.4%
*-commutative67.4%
Simplified67.4%
Taylor expanded in b around 0 65.2%
associate-*r*65.2%
*-commutative65.2%
*-commutative65.2%
Simplified65.2%
if 3.80000000000000002e-48 < b Initial program 62.6%
Simplified62.6%
Taylor expanded in c around 0 82.4%
+-commutative82.4%
fma-def82.4%
associate-/l*90.2%
associate-/r/90.2%
Simplified90.2%
Taylor expanded in b around -inf 90.2%
fma-def90.2%
associate-/l*90.2%
*-commutative90.2%
Simplified90.2%
Taylor expanded in a around inf 90.2%
Final simplification74.7%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (* b -2.0) (* a 2.0))))
(if (<= b 2.3e-53)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) (sqrt (* c (* a -4.0))))) t_0)
(if (>= b 0.0) (/ (- c) b) t_0))))
double code(double a, double b, double c) {
double t_0 = (b * -2.0) / (a * 2.0);
double tmp_1;
if (b <= 2.3e-53) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - sqrt((c * (a * -4.0))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -c / 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)) / (a * 2.0d0)
if (b <= 2.3d-53) then
if (b >= 0.0d0) then
tmp_2 = (c * 2.0d0) / (-b - sqrt((c * (a * (-4.0d0)))))
else
tmp_2 = t_0
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = -c / 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) / (a * 2.0);
double tmp_1;
if (b <= 2.3e-53) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = (c * 2.0) / (-b - Math.sqrt((c * (a * -4.0))));
} else {
tmp_2 = t_0;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = -c / b;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
def code(a, b, c): t_0 = (b * -2.0) / (a * 2.0) tmp_1 = 0 if b <= 2.3e-53: tmp_2 = 0 if b >= 0.0: tmp_2 = (c * 2.0) / (-b - math.sqrt((c * (a * -4.0)))) else: tmp_2 = t_0 tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = -c / b else: tmp_1 = t_0 return tmp_1
function code(a, b, c) t_0 = Float64(Float64(b * -2.0) / Float64(a * 2.0)) tmp_1 = 0.0 if (b <= 2.3e-53) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - sqrt(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) / b); else tmp_1 = t_0; end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = (b * -2.0) / (a * 2.0); tmp_2 = 0.0; if (b <= 2.3e-53) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = (c * 2.0) / (-b - sqrt((c * (a * -4.0)))); else tmp_3 = t_0; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = -c / 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[(a * 2.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 2.3e-53], 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], t$95$0], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b \cdot -2}{a \cdot 2}\\
\mathbf{if}\;b \leq 2.3 \cdot 10^{-53}:\\
\;\;\;\;\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}:\\
\;\;\;\;t_0\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if b < 2.3000000000000001e-53Initial program 77.8%
Taylor expanded in b around -inf 67.4%
*-commutative67.4%
Simplified67.4%
Taylor expanded in b around 0 65.2%
associate-*r*65.2%
*-commutative65.2%
*-commutative65.2%
Simplified65.2%
if 2.3000000000000001e-53 < b Initial program 62.6%
Taylor expanded in b around -inf 62.6%
*-commutative62.6%
Simplified62.6%
Taylor expanded in c around 0 90.1%
associate-*r/90.1%
neg-mul-190.1%
Simplified90.1%
Final simplification74.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ b a) (* (* -2.0 (/ c b)) -0.5)))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = b / a;
} else {
tmp = (-2.0 * (c / b)) * -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 = b / a
else
tmp = ((-2.0d0) * (c / b)) * (-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 = b / a;
} else {
tmp = (-2.0 * (c / b)) * -0.5;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = b / a else: tmp = (-2.0 * (c / b)) * -0.5 return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(b / a); else tmp = Float64(Float64(-2.0 * Float64(c / b)) * -0.5); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = b / a; else tmp = (-2.0 * (c / b)) * -0.5; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(b / a), $MachinePrecision], N[(N[(-2.0 * N[(c / b), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\left(-2 \cdot \frac{c}{b}\right) \cdot -0.5\\
\end{array}
\end{array}
Initial program 72.0%
Simplified72.0%
Taylor expanded in c around 0 68.6%
+-commutative68.6%
fma-def68.6%
associate-/l*71.6%
associate-/r/71.7%
Simplified71.7%
Taylor expanded in b around -inf 64.6%
fma-def64.6%
associate-/l*65.7%
*-commutative65.7%
Simplified65.7%
Taylor expanded in c around inf 30.7%
Taylor expanded in a around inf 4.1%
Final simplification4.1%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- b) a) (/ (* b -2.0) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -b / a;
} else {
tmp = (b * -2.0) / (a * 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 / a
else
tmp = (b * (-2.0d0)) / (a * 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 / a;
} else {
tmp = (b * -2.0) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -b / a else: tmp = (b * -2.0) / (a * 2.0) 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(a * 2.0)); 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) / (a * 2.0); 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[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 72.0%
Taylor expanded in b around -inf 65.5%
*-commutative65.5%
Simplified65.5%
Taylor expanded in b around -inf 29.6%
associate-*r/29.6%
mul-1-neg29.6%
Simplified29.6%
Final simplification29.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (/ (* b -2.0) (* a 2.0))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = (b * -2.0) / (a * 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 = -c / b
else
tmp = (b * (-2.0d0)) / (a * 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 = -c / b;
} else {
tmp = (b * -2.0) / (a * 2.0);
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = (b * -2.0) / (a * 2.0) 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(a * 2.0)); 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) / (a * 2.0); 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[(a * 2.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}
\end{array}
Initial program 72.0%
Taylor expanded in b around -inf 65.5%
*-commutative65.5%
Simplified65.5%
Taylor expanded in c around 0 65.2%
associate-*r/65.2%
neg-mul-165.2%
Simplified65.2%
Final simplification65.2%
herbie shell --seed 2024021
(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))))