
(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 5 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 -2e+155)
(if (>= b 0.0) t_1 (/ b (- a)))
(if (<= b 2e+105)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_0)) (/ (- t_0 b) (* a 2.0)))
(if (>= b 0.0) t_1 (/ (/ (- (pow b 3.0)) (pow b 2.0)) a))))))
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 <= -2e+155) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b <= 2e+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 = t_1;
} else {
tmp_1 = (-pow(b, 3.0) / pow(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) :: 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 <= (-2d+155)) then
if (b >= 0.0d0) then
tmp_2 = t_1
else
tmp_2 = b / -a
end if
tmp_1 = tmp_2
else if (b <= 2d+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 = t_1
else
tmp_1 = (-(b ** 3.0d0) / (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 t_1 = -c / b;
double tmp_1;
if (b <= -2e+155) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b <= 2e+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 = t_1;
} else {
tmp_1 = (-Math.pow(b, 3.0) / Math.pow(b, 2.0)) / a;
}
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 <= -2e+155: tmp_2 = 0 if b >= 0.0: tmp_2 = t_1 else: tmp_2 = b / -a tmp_1 = tmp_2 elif b <= 2e+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 = t_1 else: tmp_1 = (-math.pow(b, 3.0) / math.pow(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)))) t_1 = Float64(Float64(-c) / b) tmp_1 = 0.0 if (b <= -2e+155) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(b / Float64(-a)); end tmp_1 = tmp_2; elseif (b <= 2e+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 = t_1; else tmp_1 = Float64(Float64(Float64(-(b ^ 3.0)) / (b ^ 2.0)) / a); 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 <= -2e+155) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_1; else tmp_3 = b / -a; end tmp_2 = tmp_3; elseif (b <= 2e+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 = t_1; else tmp_2 = (-(b ^ 3.0) / (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]}, Block[{t$95$1 = N[((-c) / b), $MachinePrecision]}, If[LessEqual[b, -2e+155], If[GreaterEqual[b, 0.0], t$95$1, N[(b / (-a)), $MachinePrecision]], If[LessEqual[b, 2e+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], t$95$1, N[(N[((-N[Power[b, 3.0], $MachinePrecision]) / N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision] / a), $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 -2 \cdot 10^{+155}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \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:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-{b}^{3}}{{b}^{2}}}{a}\\
\end{array}
\end{array}
if b < -2.00000000000000001e155Initial program 31.6%
Simplified32.2%
Taylor expanded in b around -inf 91.4%
Taylor expanded in b around inf 91.4%
Taylor expanded in b around inf 91.4%
mul-1-neg91.4%
associate-*r/91.4%
mul-1-neg91.4%
Simplified91.4%
if -2.00000000000000001e155 < b < 1.9999999999999999e105Initial program 86.7%
if 1.9999999999999999e105 < b Initial program 44.1%
Simplified44.3%
Taylor expanded in b around -inf 44.3%
Taylor expanded in b around inf 91.5%
Taylor expanded in b around inf 91.9%
mul-1-neg91.9%
associate-*r/91.9%
mul-1-neg91.9%
Simplified91.9%
neg-sub091.9%
flip3--91.9%
metadata-eval91.9%
metadata-eval91.9%
pow291.9%
Applied egg-rr91.9%
sub0-neg91.9%
+-lft-identity91.9%
mul0-lft91.9%
+-rgt-identity91.9%
Simplified91.9%
Final simplification88.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0)))))
(t_1 (/ (- c) b))
(t_2 (if (>= b 0.0) t_1 (/ b (- a)))))
(if (<= b -8e+150)
t_2
(if (<= b -4e-311)
(if (>= b 0.0) t_1 (/ (- t_0 b) (* a 2.0)))
(if (<= b 2.4e+104)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_0)) (/ c b))
t_2)))))
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;
if (b >= 0.0) {
tmp = t_1;
} else {
tmp = b / -a;
}
double t_2 = tmp;
double tmp_1;
if (b <= -8e+150) {
tmp_1 = t_2;
} else if (b <= -4e-311) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else if (b <= 2.4e+104) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_0);
} else {
tmp_3 = c / b;
}
tmp_1 = tmp_3;
} else {
tmp_1 = t_2;
}
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) :: t_2
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 >= 0.0d0) then
tmp = t_1
else
tmp = b / -a
end if
t_2 = tmp
if (b <= (-8d+150)) then
tmp_1 = t_2
else if (b <= (-4d-311)) then
if (b >= 0.0d0) then
tmp_2 = t_1
else
tmp_2 = (t_0 - b) / (a * 2.0d0)
end if
tmp_1 = tmp_2
else if (b <= 2.4d+104) then
if (b >= 0.0d0) then
tmp_3 = (c * 2.0d0) / (-b - t_0)
else
tmp_3 = c / b
end if
tmp_1 = tmp_3
else
tmp_1 = t_2
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;
if (b >= 0.0) {
tmp = t_1;
} else {
tmp = b / -a;
}
double t_2 = tmp;
double tmp_1;
if (b <= -8e+150) {
tmp_1 = t_2;
} else if (b <= -4e-311) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = (t_0 - b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else if (b <= 2.4e+104) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_0);
} else {
tmp_3 = c / b;
}
tmp_1 = tmp_3;
} else {
tmp_1 = t_2;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (a * 4.0)))) t_1 = -c / b tmp = 0 if b >= 0.0: tmp = t_1 else: tmp = b / -a t_2 = tmp tmp_1 = 0 if b <= -8e+150: tmp_1 = t_2 elif b <= -4e-311: tmp_2 = 0 if b >= 0.0: tmp_2 = t_1 else: tmp_2 = (t_0 - b) / (a * 2.0) tmp_1 = tmp_2 elif b <= 2.4e+104: tmp_3 = 0 if b >= 0.0: tmp_3 = (c * 2.0) / (-b - t_0) else: tmp_3 = c / b tmp_1 = tmp_3 else: tmp_1 = t_2 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 = 0.0 if (b >= 0.0) tmp = t_1; else tmp = Float64(b / Float64(-a)); end t_2 = tmp tmp_1 = 0.0 if (b <= -8e+150) tmp_1 = t_2; elseif (b <= -4e-311) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(Float64(t_0 - b) / Float64(a * 2.0)); end tmp_1 = tmp_2; elseif (b <= 2.4e+104) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - t_0)); else tmp_3 = Float64(c / b); end tmp_1 = tmp_3; else tmp_1 = t_2; 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 = 0.0; if (b >= 0.0) tmp = t_1; else tmp = b / -a; end t_2 = tmp; tmp_2 = 0.0; if (b <= -8e+150) tmp_2 = t_2; elseif (b <= -4e-311) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_1; else tmp_3 = (t_0 - b) / (a * 2.0); end tmp_2 = tmp_3; elseif (b <= 2.4e+104) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (c * 2.0) / (-b - t_0); else tmp_4 = c / b; end tmp_2 = tmp_4; else tmp_2 = t_2; 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]}, Block[{t$95$2 = If[GreaterEqual[b, 0.0], t$95$1, N[(b / (-a)), $MachinePrecision]]}, If[LessEqual[b, -8e+150], t$95$2, If[LessEqual[b, -4e-311], If[GreaterEqual[b, 0.0], t$95$1, N[(N[(t$95$0 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 2.4e+104], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - t$95$0), $MachinePrecision]), $MachinePrecision], N[(c / b), $MachinePrecision]], t$95$2]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
t_1 := \frac{-c}{b}\\
t_2 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
\mathbf{if}\;b \leq -8 \cdot 10^{+150}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;b \leq -4 \cdot 10^{-311}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 2.4 \cdot 10^{+104}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{b}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
if b < -7.99999999999999985e150 or 2.4e104 < b Initial program 38.1%
Simplified38.5%
Taylor expanded in b around -inf 66.8%
Taylor expanded in b around inf 91.4%
Taylor expanded in b around inf 91.6%
mul-1-neg91.6%
associate-*r/91.6%
mul-1-neg91.6%
Simplified91.6%
if -7.99999999999999985e150 < b < -3.99999999999979e-311Initial program 86.5%
add-cbrt-cube86.5%
pow386.5%
sqrt-pow286.5%
fmm-def86.5%
*-commutative86.5%
distribute-rgt-neg-in86.5%
distribute-lft-neg-in86.5%
metadata-eval86.5%
*-commutative86.5%
metadata-eval86.5%
Applied egg-rr86.5%
Taylor expanded in c around 0 86.5%
associate-*r/86.5%
mul-1-neg86.5%
Simplified86.5%
if -3.99999999999979e-311 < b < 2.4e104Initial program 86.8%
*-un-lft-identity86.8%
*-commutative86.8%
times-frac86.8%
div-inv86.8%
add-sqr-sqrt86.8%
sqrt-unprod86.8%
sqr-neg86.8%
sqrt-prod86.8%
add-sqr-sqrt86.8%
fmm-def86.8%
*-commutative86.8%
distribute-rgt-neg-in86.8%
distribute-lft-neg-in86.8%
metadata-eval86.8%
*-commutative86.8%
metadata-eval86.8%
Applied egg-rr86.8%
Taylor expanded in b around -inf 86.8%
Final simplification88.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (or (<= b -2e+152) (not (<= b 1.2e+107)))
(if (>= b 0.0) (/ (- c) b) (/ b (- a)))
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_0)) (/ (- t_0 b) (* 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 <= -2e+152) || !(b <= 1.2e+107)) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -c / b;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (-b - t_0);
} else {
tmp_1 = (t_0 - b) / (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
t_0 = sqrt(((b * b) - (c * (a * 4.0d0))))
if ((b <= (-2d+152)) .or. (.not. (b <= 1.2d+107))) then
if (b >= 0.0d0) then
tmp_2 = -c / b
else
tmp_2 = b / -a
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = (c * 2.0d0) / (-b - t_0)
else
tmp_1 = (t_0 - b) / (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 <= -2e+152) || !(b <= 1.2e+107)) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = -c / b;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (c * 2.0) / (-b - t_0);
} else {
tmp_1 = (t_0 - b) / (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 <= -2e+152) or not (b <= 1.2e+107): tmp_2 = 0 if b >= 0.0: tmp_2 = -c / b else: tmp_2 = b / -a tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = (c * 2.0) / (-b - t_0) else: tmp_1 = (t_0 - b) / (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 <= -2e+152) || !(b <= 1.2e+107)) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(Float64(-c) / b); else tmp_2 = Float64(b / Float64(-a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - t_0)); else tmp_1 = Float64(Float64(t_0 - b) / Float64(a * 2.0)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if ((b <= -2e+152) || ~((b <= 1.2e+107))) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = -c / b; else tmp_3 = b / -a; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = (c * 2.0) / (-b - t_0); else tmp_2 = (t_0 - b) / (a * 2.0); end tmp_4 = 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[Or[LessEqual[b, -2e+152], N[Not[LessEqual[b, 1.2e+107]], $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(b / (-a)), $MachinePrecision]], 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]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -2 \cdot 10^{+152} \lor \neg \left(b \leq 1.2 \cdot 10^{+107}\right):\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -2.0000000000000001e152 or 1.2e107 < b Initial program 38.1%
Simplified38.5%
Taylor expanded in b around -inf 66.8%
Taylor expanded in b around inf 91.4%
Taylor expanded in b around inf 91.6%
mul-1-neg91.6%
associate-*r/91.6%
mul-1-neg91.6%
Simplified91.6%
if -2.0000000000000001e152 < b < 1.2e107Initial program 86.7%
Final simplification88.4%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ (- c) b)))
(if (<= b -1e+153)
(if (>= b 0.0) t_0 (/ b (- a)))
(if (>= b 0.0)
t_0
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0))))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double tmp_1;
if (b <= -1e+153) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (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
t_0 = -c / b
if (b <= (-1d+153)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = b / -a
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = -c / b;
double tmp_1;
if (b <= -1e+153) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = b / -a;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
return tmp_1;
}
def code(a, b, c): t_0 = -c / b tmp_1 = 0 if b <= -1e+153: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = b / -a tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) return tmp_1
function code(a, b, c) t_0 = Float64(Float64(-c) / b) tmp_1 = 0.0 if (b <= -1e+153) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(b / Float64(-a)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = -c / b; tmp_2 = 0.0; if (b <= -1e+153) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = b / -a; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, If[LessEqual[b, -1e+153], If[GreaterEqual[b, 0.0], t$95$0, N[(b / (-a)), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
\mathbf{if}\;b \leq -1 \cdot 10^{+153}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -1e153Initial program 31.6%
Simplified32.2%
Taylor expanded in b around -inf 91.4%
Taylor expanded in b around inf 91.4%
Taylor expanded in b around inf 91.4%
mul-1-neg91.4%
associate-*r/91.4%
mul-1-neg91.4%
Simplified91.4%
if -1e153 < b Initial program 77.5%
add-cbrt-cube70.4%
pow370.4%
sqrt-pow270.4%
fmm-def70.5%
*-commutative70.5%
distribute-rgt-neg-in70.5%
distribute-lft-neg-in70.5%
metadata-eval70.5%
*-commutative70.5%
metadata-eval70.5%
Applied egg-rr70.5%
Taylor expanded in c around 0 72.6%
associate-*r/72.6%
mul-1-neg72.6%
Simplified72.6%
Final simplification75.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ (- c) b) (/ b (- a))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = 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 = -c / b
else
tmp = 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 = -c / b;
} else {
tmp = b / -a;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = b / -a return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(b / Float64(-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 / -a; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}
\end{array}
Initial program 70.0%
Simplified70.0%
Taylor expanded in b around -inf 69.5%
Taylor expanded in b around inf 65.3%
Taylor expanded in b around inf 65.5%
mul-1-neg65.5%
associate-*r/65.5%
mul-1-neg65.5%
Simplified65.5%
Final simplification65.5%
herbie shell --seed 2024117
(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))))