
(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 (* a 4.0))))) (t_1 (/ b (- a))))
(if (<= b -7e+163)
(if (>= b 0.0) t_1 (/ c (- b)))
(if (<= b 4e+86)
(if (>= b 0.0) (/ (+ b t_0) (* a (- 2.0))) (/ (* c 2.0) (- t_0 b)))
t_1))))
double code(double a, double b, double c) {
double t_0 = sqrt(((b * b) - (c * (a * 4.0))));
double t_1 = b / -a;
double tmp_1;
if (b <= -7e+163) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b <= 4e+86) {
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 {
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) - (c * (a * 4.0d0))))
t_1 = b / -a
if (b <= (-7d+163)) then
if (b >= 0.0d0) then
tmp_2 = t_1
else
tmp_2 = c / -b
end if
tmp_1 = tmp_2
else if (b <= 4d+86) 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
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) - (c * (a * 4.0))));
double t_1 = b / -a;
double tmp_1;
if (b <= -7e+163) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_1;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b <= 4e+86) {
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 {
tmp_1 = t_1;
}
return tmp_1;
}
def code(a, b, c): t_0 = math.sqrt(((b * b) - (c * (a * 4.0)))) t_1 = b / -a tmp_1 = 0 if b <= -7e+163: tmp_2 = 0 if b >= 0.0: tmp_2 = t_1 else: tmp_2 = c / -b tmp_1 = tmp_2 elif b <= 4e+86: 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 else: tmp_1 = t_1 return tmp_1
function code(a, b, c) t_0 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) t_1 = Float64(b / Float64(-a)) tmp_1 = 0.0 if (b <= -7e+163) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_1; else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b <= 4e+86) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(b + t_0) / Float64(a * Float64(-2.0))); else tmp_3 = Float64(Float64(c * 2.0) / Float64(t_0 - b)); end tmp_1 = tmp_3; else tmp_1 = t_1; end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = sqrt(((b * b) - (c * (a * 4.0)))); t_1 = b / -a; tmp_2 = 0.0; if (b <= -7e+163) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_1; else tmp_3 = c / -b; end tmp_2 = tmp_3; elseif (b <= 4e+86) 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; 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[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, Block[{t$95$1 = N[(b / (-a)), $MachinePrecision]}, If[LessEqual[b, -7e+163], If[GreaterEqual[b, 0.0], t$95$1, N[(c / (-b)), $MachinePrecision]], If[LessEqual[b, 4e+86], 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]], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
t_1 := \frac{b}{-a}\\
\mathbf{if}\;b \leq -7 \cdot 10^{+163}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \leq 4 \cdot 10^{+86}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{b + t\_0}{a \cdot \left(-2\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{t\_0 - b}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if b < -7.0000000000000005e163Initial program 29.7%
Taylor expanded in b around inf 29.7%
associate-*r/29.7%
mul-1-neg29.7%
Simplified29.7%
Taylor expanded in b around -inf 97.6%
associate-*r/97.6%
neg-mul-197.6%
Simplified97.6%
if -7.0000000000000005e163 < b < 4.0000000000000001e86Initial program 84.9%
if 4.0000000000000001e86 < b Initial program 57.2%
Taylor expanded in b around inf 95.1%
associate-*r/95.1%
mul-1-neg95.1%
Simplified95.1%
Taylor expanded in c around 0 95.1%
associate-*r/95.1%
mul-1-neg95.1%
Simplified95.1%
Final simplification89.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ b (- a))))
(if (<= b -7e+163)
(if (>= b 0.0) t_0 (/ c (- b)))
(if (>= b 0.0)
t_0
(/ (* c 2.0) (- (sqrt (- (* b b) (* c (* a 4.0)))) b))))))
double code(double a, double b, double c) {
double t_0 = b / -a;
double tmp_1;
if (b <= -7e+163) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (c * 2.0) / (sqrt(((b * b) - (c * (a * 4.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
t_0 = b / -a
if (b <= (-7d+163)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = c / -b
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = (c * 2.0d0) / (sqrt(((b * b) - (c * (a * 4.0d0)))) - b)
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = b / -a;
double tmp_1;
if (b <= -7e+163) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (c * 2.0) / (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b);
}
return tmp_1;
}
def code(a, b, c): t_0 = b / -a tmp_1 = 0 if b <= -7e+163: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = c / -b tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = (c * 2.0) / (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) return tmp_1
function code(a, b, c) t_0 = Float64(b / Float64(-a)) tmp_1 = 0.0 if (b <= -7e+163) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(c * 2.0) / Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b)); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = b / -a; tmp_2 = 0.0; if (b <= -7e+163) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = c / -b; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = (c * 2.0) / (sqrt(((b * b) - (c * (a * 4.0)))) - b); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(b / (-a)), $MachinePrecision]}, If[LessEqual[b, -7e+163], If[GreaterEqual[b, 0.0], t$95$0, N[(c / (-b)), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(c * 2.0), $MachinePrecision] / N[(N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{-a}\\
\mathbf{if}\;b \leq -7 \cdot 10^{+163}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot 2}{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}\\
\end{array}
\end{array}
if b < -7.0000000000000005e163Initial program 29.7%
Taylor expanded in b around inf 29.7%
associate-*r/29.7%
mul-1-neg29.7%
Simplified29.7%
Taylor expanded in b around -inf 97.6%
associate-*r/97.6%
neg-mul-197.6%
Simplified97.6%
if -7.0000000000000005e163 < b Initial program 77.5%
Taylor expanded in b around inf 76.3%
associate-*r/76.3%
mul-1-neg76.3%
Simplified76.3%
Final simplification79.5%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ b (- a))))
(if (<= b -1.9e-69)
(if (>= b 0.0) t_0 (/ c (- b)))
(if (>= b 0.0) t_0 (/ (* c -2.0) (- b (sqrt (* a (* c -4.0)))))))))
double code(double a, double b, double c) {
double t_0 = b / -a;
double tmp_1;
if (b <= -1.9e-69) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (c * -2.0) / (b - sqrt((a * (c * -4.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 / -a
if (b <= (-1.9d-69)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = c / -b
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = (c * (-2.0d0)) / (b - sqrt((a * (c * (-4.0d0)))))
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = b / -a;
double tmp_1;
if (b <= -1.9e-69) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = (c * -2.0) / (b - Math.sqrt((a * (c * -4.0))));
}
return tmp_1;
}
def code(a, b, c): t_0 = b / -a tmp_1 = 0 if b <= -1.9e-69: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = c / -b tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = (c * -2.0) / (b - math.sqrt((a * (c * -4.0)))) return tmp_1
function code(a, b, c) t_0 = Float64(b / Float64(-a)) tmp_1 = 0.0 if (b <= -1.9e-69) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(Float64(c * -2.0) / Float64(b - sqrt(Float64(a * Float64(c * -4.0))))); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = b / -a; tmp_2 = 0.0; if (b <= -1.9e-69) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = c / -b; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = (c * -2.0) / (b - sqrt((a * (c * -4.0)))); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(b / (-a)), $MachinePrecision]}, If[LessEqual[b, -1.9e-69], If[GreaterEqual[b, 0.0], t$95$0, N[(c / (-b)), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(N[(c * -2.0), $MachinePrecision] / N[(b - N[Sqrt[N[(a * N[(c * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{-a}\\
\mathbf{if}\;b \leq -1.9 \cdot 10^{-69}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c \cdot -2}{b - \sqrt{a \cdot \left(c \cdot -4\right)}}\\
\end{array}
\end{array}
if b < -1.8999999999999999e-69Initial program 67.0%
Taylor expanded in b around inf 67.0%
associate-*r/67.0%
mul-1-neg67.0%
Simplified67.0%
Taylor expanded in b around -inf 89.4%
associate-*r/89.4%
neg-mul-189.4%
Simplified89.4%
if -1.8999999999999999e-69 < b Initial program 72.2%
Taylor expanded in b around inf 70.7%
associate-*r/70.7%
mul-1-neg70.7%
Simplified70.7%
Taylor expanded in b around 0 69.2%
associate-*r*69.2%
*-commutative69.2%
metadata-eval69.2%
distribute-rgt-neg-in69.2%
*-commutative69.2%
distribute-rgt-neg-in69.2%
metadata-eval69.2%
Simplified69.2%
div-inv69.2%
*-commutative69.2%
associate-*l*69.2%
frac-2neg69.2%
metadata-eval69.2%
distribute-neg-in69.2%
add-sqr-sqrt69.2%
sqrt-unprod68.9%
sqr-neg68.9%
sqrt-prod54.3%
add-sqr-sqrt68.6%
sub-neg68.6%
add-sqr-sqrt68.6%
sqrt-unprod68.6%
sqr-neg68.6%
sqrt-prod54.3%
add-sqr-sqrt69.2%
Applied egg-rr69.2%
associate-*r/69.2%
metadata-eval69.2%
associate-*r/69.2%
associate-*r*69.2%
*-commutative69.2%
associate-*l*69.2%
Simplified69.2%
Final simplification76.1%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (/ b (- a))))
(if (<= b -1.85e-70)
(if (>= b 0.0) t_0 (/ c (- b)))
(if (>= b 0.0) t_0 (* c (/ -2.0 (- b (sqrt (* c (* a -4.0))))))))))
double code(double a, double b, double c) {
double t_0 = b / -a;
double tmp_1;
if (b <= -1.85e-70) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = c * (-2.0 / (b - sqrt((c * (a * -4.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 / -a
if (b <= (-1.85d-70)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = c / -b
end if
tmp_1 = tmp_2
else if (b >= 0.0d0) then
tmp_1 = t_0
else
tmp_1 = c * ((-2.0d0) / (b - sqrt((c * (a * (-4.0d0))))))
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = b / -a;
double tmp_1;
if (b <= -1.85e-70) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = c / -b;
}
tmp_1 = tmp_2;
} else if (b >= 0.0) {
tmp_1 = t_0;
} else {
tmp_1 = c * (-2.0 / (b - Math.sqrt((c * (a * -4.0)))));
}
return tmp_1;
}
def code(a, b, c): t_0 = b / -a tmp_1 = 0 if b <= -1.85e-70: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = c / -b tmp_1 = tmp_2 elif b >= 0.0: tmp_1 = t_0 else: tmp_1 = c * (-2.0 / (b - math.sqrt((c * (a * -4.0))))) return tmp_1
function code(a, b, c) t_0 = Float64(b / Float64(-a)) tmp_1 = 0.0 if (b <= -1.85e-70) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = Float64(c / Float64(-b)); end tmp_1 = tmp_2; elseif (b >= 0.0) tmp_1 = t_0; else tmp_1 = Float64(c * Float64(-2.0 / Float64(b - sqrt(Float64(c * Float64(a * -4.0)))))); end return tmp_1 end
function tmp_4 = code(a, b, c) t_0 = b / -a; tmp_2 = 0.0; if (b <= -1.85e-70) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = c / -b; end tmp_2 = tmp_3; elseif (b >= 0.0) tmp_2 = t_0; else tmp_2 = c * (-2.0 / (b - sqrt((c * (a * -4.0))))); end tmp_4 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[(b / (-a)), $MachinePrecision]}, If[LessEqual[b, -1.85e-70], If[GreaterEqual[b, 0.0], t$95$0, N[(c / (-b)), $MachinePrecision]], If[GreaterEqual[b, 0.0], t$95$0, N[(c * N[(-2.0 / N[(b - N[Sqrt[N[(c * N[(a * -4.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{b}{-a}\\
\mathbf{if}\;b \leq -1.85 \cdot 10^{-70}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\frac{c}{-b}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;c \cdot \frac{-2}{b - \sqrt{c \cdot \left(a \cdot -4\right)}}\\
\end{array}
\end{array}
if b < -1.85e-70Initial program 67.0%
Taylor expanded in b around inf 67.0%
associate-*r/67.0%
mul-1-neg67.0%
Simplified67.0%
Taylor expanded in b around -inf 89.4%
associate-*r/89.4%
neg-mul-189.4%
Simplified89.4%
if -1.85e-70 < b Initial program 72.2%
Taylor expanded in b around inf 70.7%
associate-*r/70.7%
mul-1-neg70.7%
Simplified70.7%
Taylor expanded in b around 0 69.2%
associate-*r*69.2%
*-commutative69.2%
metadata-eval69.2%
distribute-rgt-neg-in69.2%
*-commutative69.2%
distribute-rgt-neg-in69.2%
metadata-eval69.2%
Simplified69.2%
div-inv69.2%
*-commutative69.2%
associate-*l*69.2%
frac-2neg69.2%
metadata-eval69.2%
distribute-neg-in69.2%
add-sqr-sqrt69.2%
sqrt-unprod68.9%
sqr-neg68.9%
sqrt-prod54.3%
add-sqr-sqrt68.6%
sub-neg68.6%
add-sqr-sqrt68.6%
sqrt-unprod68.6%
sqr-neg68.6%
sqrt-prod54.3%
add-sqr-sqrt69.2%
Applied egg-rr69.2%
associate-*r/69.2%
metadata-eval69.2%
Simplified69.2%
Final simplification76.1%
(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 70.4%
Taylor expanded in b around inf 69.4%
associate-*r/69.4%
mul-1-neg69.4%
Simplified69.4%
Taylor expanded in b around -inf 68.8%
associate-*r/68.8%
neg-mul-168.8%
Simplified68.8%
Final simplification68.8%
(FPCore (a b c) :precision binary64 (/ b (- a)))
double code(double a, double b, double c) {
return b / -a;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
code = b / -a
end function
public static double code(double a, double b, double c) {
return b / -a;
}
def code(a, b, c): return b / -a
function code(a, b, c) return Float64(b / Float64(-a)) end
function tmp = code(a, b, c) tmp = b / -a; end
code[a_, b_, c_] := N[(b / (-a)), $MachinePrecision]
\begin{array}{l}
\\
\frac{b}{-a}
\end{array}
Initial program 70.4%
Taylor expanded in b around inf 69.4%
associate-*r/69.4%
mul-1-neg69.4%
Simplified69.4%
Taylor expanded in c around 0 37.2%
associate-*r/37.2%
mul-1-neg37.2%
Simplified37.2%
Final simplification37.2%
herbie shell --seed 2024106
(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)))))))