
(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 6 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 (* 4.0 a))))))
(if (<= b -7e+85)
(if (>= b 0.0) (/ c b) (/ c (- b)))
(if (<= b 3.3e-306)
(if (>= b 0.0)
(/ (* 2.0 (fma a (/ c b) (- b))) (* a 2.0))
(/ (* c 2.0) (- t_0 b)))
(if (<= b 3.4e+102)
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ b a))
(if (>= b 0.0)
(* -0.5 (/ (+ b b) a))
(/ c (/ (pow b 2.0) (- b)))))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (4.0 * a))));
double tmp_1;
if (b <= -7e+85) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c / b;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b <= 3.3e-306) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (2.0 * fma(a, (c / b), -b)) / (a * 2.0);
} else {
tmp_3 = (c * 2.0) / (t_0 - b);
}
tmp_1 = tmp_3;
} else if (b <= 3.4e+102) {
double tmp_4;
if (b >= 0.0) {
tmp_4 = (-b - t_0) / (a * 2.0);
} else {
tmp_4 = b / a;
}
tmp_1 = tmp_4;
} else if (b >= 0.0) {
tmp_1 = -0.5 * ((b + b) / a);
} else {
tmp_1 = c / (pow(b, 2.0) / -b);
}
return tmp_1;
}
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) tmp_1 = 0.0 if (b <= -7e+85) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c / b); else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b <= 3.3e-306) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(2.0 * fma(a, Float64(c / b), Float64(-b))) / Float64(a * 2.0)); else tmp_3 = Float64(Float64(c * 2.0) / Float64(t_0 - b)); end tmp_1 = tmp_3; elseif (b <= 3.4e+102) tmp_4 = 0.0 if (b >= 0.0) tmp_4 = Float64(Float64(Float64(-b) - t_0) / Float64(a * 2.0)); else tmp_4 = Float64(b / a); end tmp_1 = tmp_4; elseif (b >= 0.0) tmp_1 = Float64(-0.5 * Float64(Float64(b + b) / a)); else tmp_1 = Float64(c / Float64((b ^ 2.0) / Float64(-b))); end return tmp_1 end
code[a_, b_, c_] := Block[{t$95$0 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -7e+85], If[GreaterEqual[b, 0.0], N[(c / b), $MachinePrecision], N[(c / (-b)), $MachinePrecision]], If[LessEqual[b, 3.3e-306], If[GreaterEqual[b, 0.0], N[(N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 3.4e+102], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(b / a), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(c / N[(N[Power[b, 2.0], $MachinePrecision] / (-b)), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
\mathbf{if}\;b \leq -7 \cdot 10^{+85}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \leq 3.3 \cdot 10^{-306}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t\_0 - b}\\
\end{array}\\
\mathbf{elif}\;b \leq 3.4 \cdot 10^{+102}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{a}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{\frac{{b}^{2}}{-b}}\\
\end{array}
\end{array}
if b < -7.0000000000000001e85Initial program 60.1%
Simplified59.9%
Taylor expanded in b around -inf 95.9%
mul-1-neg95.9%
distribute-neg-frac295.9%
Simplified95.9%
Taylor expanded in c around 0 95.9%
Taylor expanded in c around inf 95.9%
if -7.0000000000000001e85 < b < 3.3000000000000001e-306Initial program 87.0%
Taylor expanded in a around 0 87.0%
distribute-lft-out--87.0%
associate-/l*87.0%
fma-neg87.0%
Simplified87.0%
if 3.3000000000000001e-306 < b < 3.4e102Initial program 92.6%
*-commutative92.6%
add-sqr-sqrt92.6%
sqrt-unprod92.6%
*-commutative92.6%
*-commutative92.6%
swap-sqr92.6%
metadata-eval92.6%
metadata-eval92.6%
swap-sqr92.6%
sqrt-unprod92.6%
add-sqr-sqrt92.6%
pow192.6%
Applied egg-rr92.6%
unpow192.6%
Simplified92.6%
Taylor expanded in c around 0 92.6%
associate-*r/92.6%
Simplified92.6%
Taylor expanded in c around 0 92.6%
if 3.4e102 < b Initial program 45.9%
Simplified46.2%
Taylor expanded in b around -inf 46.2%
mul-1-neg46.2%
distribute-neg-frac246.2%
Simplified46.2%
Taylor expanded in c around 0 98.3%
neg-sub098.3%
flip--98.3%
metadata-eval98.3%
pow298.3%
add-sqr-sqrt98.3%
sqrt-prod98.3%
sqr-neg98.3%
sqrt-unprod98.3%
add-sqr-sqrt98.3%
sub-neg98.3%
neg-sub098.3%
add-sqr-sqrt98.3%
sqrt-unprod98.3%
sqr-neg98.3%
sqrt-prod98.3%
add-sqr-sqrt98.3%
Applied egg-rr98.3%
neg-sub098.3%
Simplified98.3%
Final simplification93.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* 4.0 a))))))
(if (<= b -7e+85)
(if (>= b 0.0) (/ c b) (/ c (- b)))
(if (<= b 2e+101)
(if (>= b 0.0) (/ (- (- b) t_0) (* a 2.0)) (/ (* c 2.0) (- t_0 b)))
(if (>= b 0.0) (* -0.5 (/ (+ b b) a)) (/ c (/ (pow b 2.0) (- b))))))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (4.0 * a))));
double tmp_1;
if (b <= -7e+85) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c / b;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b <= 2e+101) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = (c * 2.0) / (t_0 - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -0.5 * ((b + b) / a);
} else {
tmp_1 = c / (pow(b, 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) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
real(8) :: tmp_3
t_0 = sqrt(((b * b) - (c * (4.0d0 * a))))
if (b <= (-7d+85)) then
if (b >= 0.0d0) then
tmp_2 = c / b
else
tmp_2 = c / -b
end if
tmp_1 = tmp_2
else if (b <= 2d+101) then
if (b >= 0.0d0) then
tmp_3 = (-b - t_0) / (a * 2.0d0)
else
tmp_3 = (c * 2.0d0) / (t_0 - b)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = (-0.5d0) * ((b + b) / a)
else
tmp_1 = c / ((b ** 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) - (c * (4.0 * a))));
double tmp_1;
if (b <= -7e+85) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c / b;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b <= 2e+101) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (-b - t_0) / (a * 2.0);
} else {
tmp_3 = (c * 2.0) / (t_0 - b);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = -0.5 * ((b + b) / a);
} else {
tmp_1 = c / (Math.pow(b, 2.0) / -b);
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (4.0 * a)))) tmp_1 = 0 if b <= -7e+85: tmp_2 = 0 if b >= 0.0: tmp_2 = c / b else: tmp_2 = c / -b tmp_1 = tmp_2 elif b <= 2e+101: tmp_3 = 0 if b >= 0.0: tmp_3 = (-b - t_0) / (a * 2.0) else: tmp_3 = (c * 2.0) / (t_0 - b) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = -0.5 * ((b + b) / a) else: tmp_1 = c / (math.pow(b, 2.0) / -b) return tmp_1
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) tmp_1 = 0.0 if (b <= -7e+85) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c / b); else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b <= 2e+101) 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(c * 2.0) / Float64(t_0 - b)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(-0.5 * Float64(Float64(b + b) / a)); else tmp_1 = Float64(c / Float64((b ^ 2.0) / Float64(-b))); end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (4.0 * a)))); tmp_2 = 0.0; if (b <= -7e+85) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = c / b; else tmp_3 = c / -b; end tmp_2 = tmp_3; elseif (b <= 2e+101) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (-b - t_0) / (a * 2.0); else tmp_4 = (c * 2.0) / (t_0 - b); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = -0.5 * ((b + b) / a); else tmp_2 = c / ((b ^ 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[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -7e+85], If[GreaterEqual[b, 0.0], N[(c / b), $MachinePrecision], N[(c / (-b)), $MachinePrecision]], If[LessEqual[b, 2e+101], If[GreaterEqual[b, 0.0], N[(N[((-b) - t$95$0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(t$95$0 - b), $MachinePrecision]), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(-0.5 * N[(N[(b + b), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision], N[(c / N[(N[Power[b, 2.0], $MachinePrecision] / (-b)), $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)}\\
\mathbf{if}\;b \leq -7 \cdot 10^{+85}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \leq 2 \cdot 10^{+101}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{\left(-b\right) - t\_0}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t\_0 - b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;-0.5 \cdot \frac{b + b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{\frac{{b}^{2}}{-b}}\\
\end{array}
\end{array}
if b < -7.0000000000000001e85Initial program 60.1%
Simplified59.9%
Taylor expanded in b around -inf 95.9%
mul-1-neg95.9%
distribute-neg-frac295.9%
Simplified95.9%
Taylor expanded in c around 0 95.9%
Taylor expanded in c around inf 95.9%
if -7.0000000000000001e85 < b < 2e101Initial program 89.8%
if 2e101 < b Initial program 45.9%
Simplified46.2%
Taylor expanded in b around -inf 46.2%
mul-1-neg46.2%
distribute-neg-frac246.2%
Simplified46.2%
Taylor expanded in c around 0 98.3%
neg-sub098.3%
flip--98.3%
metadata-eval98.3%
pow298.3%
add-sqr-sqrt98.3%
sqrt-prod98.3%
sqr-neg98.3%
sqrt-unprod98.3%
add-sqr-sqrt98.3%
sub-neg98.3%
neg-sub098.3%
add-sqr-sqrt98.3%
sqrt-unprod98.3%
sqr-neg98.3%
sqrt-prod98.3%
add-sqr-sqrt98.3%
Applied egg-rr98.3%
neg-sub098.3%
Simplified98.3%
Final simplification93.3%
(FPCore (a b c)
:precision binary64
(if (<= b -7e+85)
(if (>= b 0.0) (/ c b) (/ c (- b)))
(if (>= b 0.0)
(/ (* 2.0 (fma a (/ c b) (- b))) (* a 2.0))
(/ (* c 2.0) (- (sqrt (- (* b b) (* c (* 4.0 a)))) b)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -7e+85) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = c / b;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = (2.0 * fma(a, (c / b), -b)) / (a * 2.0);
} else {
tmp_1 = (c * 2.0) / (sqrt(((b * b) - (c * (4.0 * a)))) - b);
}
return tmp_1;
}
function code(a, b, c) tmp_1 = 0.0 if (b <= -7e+85) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(c / b); else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = Float64(Float64(2.0 * fma(a, Float64(c / b), Float64(-b))) / Float64(a * 2.0)); else tmp_1 = Float64(Float64(c * 2.0) / Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(4.0 * a)))) - b)); end return tmp_1 end
code[a_, b_, c_] := If[LessEqual[b, -7e+85], If[GreaterEqual[b, 0.0], N[(c / b), $MachinePrecision], N[(c / (-b)), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(N[(2.0 * N[(a * N[(c / b), $MachinePrecision] + (-b)), $MachinePrecision]), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision], N[(N[(c * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(4.0 * a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq -7 \cdot 10^{+85}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{2 \cdot \mathsf{fma}\left(a, \frac{c}{b}, -b\right)}{a \cdot 2}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - c \cdot \left(4 \cdot a\right)} - b}\\
\end{array}
\end{array}
if b < -7.0000000000000001e85Initial program 60.1%
Simplified59.9%
Taylor expanded in b around -inf 95.9%
mul-1-neg95.9%
distribute-neg-frac295.9%
Simplified95.9%
Taylor expanded in c around 0 95.9%
Taylor expanded in c around inf 95.9%
if -7.0000000000000001e85 < b Initial program 77.0%
Taylor expanded in a around 0 74.6%
distribute-lft-out--74.6%
associate-/l*77.8%
fma-neg77.8%
Simplified77.8%
Final simplification82.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (- (/ c b) (/ b a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = (c / b) - (b / a);
} 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 = (c / b) - (b / a)
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 = (c / b) - (b / a);
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = (c / b) - (b / a) else: tmp = 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(c / Float64(-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 = 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[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b} - \frac{b}{a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
Initial program 72.5%
Simplified72.5%
Taylor expanded in b around -inf 72.2%
mul-1-neg72.2%
distribute-neg-frac272.2%
Simplified72.2%
Taylor expanded in c around 0 72.7%
Taylor expanded in b around 0 72.7%
distribute-lft-in72.7%
associate-*r*72.7%
metadata-eval72.7%
*-lft-identity72.7%
associate-*r*72.7%
metadata-eval72.7%
neg-mul-172.7%
sub-neg72.7%
neg-mul-172.7%
distribute-frac-neg272.7%
Simplified72.7%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ b (- a)) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = b / -a;
} 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 / -a
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 / -a;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = b / -a else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(b / Float64(-a)); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = b / -a; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(b / (-a)), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b}{-a}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
Initial program 72.5%
Simplified72.5%
Taylor expanded in b around -inf 72.2%
mul-1-neg72.2%
distribute-neg-frac272.2%
Simplified72.2%
Taylor expanded in c around 0 72.6%
Taylor expanded in b around 0 72.6%
Simplified72.6%
Final simplification72.6%
(FPCore (a b c) :precision binary64 (if (>= b 0.0) (/ c b) (/ c (- b))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = c / b;
} 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 = c / b
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 = c / b;
} else {
tmp = c / -b;
}
return tmp;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = c / b else: tmp = c / -b return tmp
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(c / b); else tmp = Float64(c / Float64(-b)); end return tmp end
function tmp_2 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = c / b; else tmp = c / -b; end tmp_2 = tmp; end
code[a_, b_, c_] := If[GreaterEqual[b, 0.0], N[(c / b), $MachinePrecision], N[(c / (-b)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}
\end{array}
Initial program 72.5%
Simplified72.5%
Taylor expanded in b around -inf 72.2%
mul-1-neg72.2%
distribute-neg-frac272.2%
Simplified72.2%
Taylor expanded in c around 0 72.7%
Taylor expanded in c around inf 39.7%
herbie shell --seed 2024120
(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)))))))