
(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))))))
(if (or (<= b -1.12e+75) (not (<= b 9e+102)))
(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 <= -1.12e+75) || !(b <= 9e+102)) {
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 <= (-1.12d+75)) .or. (.not. (b <= 9d+102))) 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 <= -1.12e+75) || !(b <= 9e+102)) {
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 <= -1.12e+75) or not (b <= 9e+102): 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 <= -1.12e+75) || !(b <= 9e+102)) 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 <= -1.12e+75) || ~((b <= 9e+102))) 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, -1.12e+75], N[Not[LessEqual[b, 9e+102]], $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 -1.12 \cdot 10^{+75} \lor \neg \left(b \leq 9 \cdot 10^{+102}\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 < -1.12000000000000001e75 or 9.00000000000000042e102 < b Initial program 53.4%
Simplified53.7%
Taylor expanded in c around 0 77.6%
associate-*r/77.6%
mul-1-neg77.6%
Simplified77.6%
Taylor expanded in b around -inf 95.2%
associate-*r/95.2%
mul-1-neg95.2%
Simplified95.2%
if -1.12000000000000001e75 < b < 9.00000000000000042e102Initial program 90.1%
Final simplification92.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (if (>= b 0.0) (/ (- c) b) (/ b (- a))))
(t_1 (sqrt (- (* b b) (* c (* a 4.0))))))
(if (<= b -2.05e+70)
t_0
(if (<= b -5e-310)
(if (>= b 0.0)
(/ 1.0 (/ a (+ b (/ (/ (pow b 3.0) c) a))))
(/ (- t_1 b) (* a 2.0)))
(if (<= b 3.7e+107)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_1)) (/ (* b -2.0) (* a 2.0)))
t_0)))))
double code(double a, double b, double c) {
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = b / -a;
}
double t_0 = tmp;
double t_1 = sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -2.05e+70) {
tmp_1 = t_0;
} else if (b <= -5e-310) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = 1.0 / (a / (b + ((pow(b, 3.0) / c) / a)));
} else {
tmp_2 = (t_1 - b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else if (b <= 3.7e+107) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_1);
} else {
tmp_3 = (b * -2.0) / (a * 2.0);
}
tmp_1 = tmp_3;
} 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) :: t_1
real(8) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
real(8) :: tmp_3
if (b >= 0.0d0) then
tmp = -c / b
else
tmp = b / -a
end if
t_0 = tmp
t_1 = sqrt(((b * b) - (c * (a * 4.0d0))))
if (b <= (-2.05d+70)) then
tmp_1 = t_0
else if (b <= (-5d-310)) then
if (b >= 0.0d0) then
tmp_2 = 1.0d0 / (a / (b + (((b ** 3.0d0) / c) / a)))
else
tmp_2 = (t_1 - b) / (a * 2.0d0)
end if
tmp_1 = tmp_2
else if (b <= 3.7d+107) then
if (b >= 0.0d0) then
tmp_3 = (c * 2.0d0) / (-b - t_1)
else
tmp_3 = (b * (-2.0d0)) / (a * 2.0d0)
end if
tmp_1 = tmp_3
else
tmp_1 = t_0
end if
code = tmp_1
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;
}
double t_0 = tmp;
double t_1 = Math.sqrt(((b * b) - (c * (a * 4.0))));
double tmp_1;
if (b <= -2.05e+70) {
tmp_1 = t_0;
} else if (b <= -5e-310) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = 1.0 / (a / (b + ((Math.pow(b, 3.0) / c) / a)));
} else {
tmp_2 = (t_1 - b) / (a * 2.0);
}
tmp_1 = tmp_2;
} else if (b <= 3.7e+107) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = (c * 2.0) / (-b - t_1);
} else {
tmp_3 = (b * -2.0) / (a * 2.0);
}
tmp_1 = tmp_3;
} else {
tmp_1 = t_0;
}
return tmp_1;
}
def code(a, b, c): tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = b / -a t_0 = tmp t_1 = math.sqrt(((b * b) - (c * (a * 4.0)))) tmp_1 = 0 if b <= -2.05e+70: tmp_1 = t_0 elif b <= -5e-310: tmp_2 = 0 if b >= 0.0: tmp_2 = 1.0 / (a / (b + ((math.pow(b, 3.0) / c) / a))) else: tmp_2 = (t_1 - b) / (a * 2.0) tmp_1 = tmp_2 elif b <= 3.7e+107: tmp_3 = 0 if b >= 0.0: tmp_3 = (c * 2.0) / (-b - t_1) else: tmp_3 = (b * -2.0) / (a * 2.0) tmp_1 = tmp_3 else: tmp_1 = t_0 return tmp_1
function code(a, b, c) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = Float64(b / Float64(-a)); end t_0 = tmp t_1 = sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) tmp_1 = 0.0 if (b <= -2.05e+70) tmp_1 = t_0; elseif (b <= -5e-310) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(1.0 / Float64(a / Float64(b + Float64(Float64((b ^ 3.0) / c) / a)))); else tmp_2 = Float64(Float64(t_1 - b) / Float64(a * 2.0)); end tmp_1 = tmp_2; elseif (b <= 3.7e+107) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(Float64(c * 2.0) / Float64(Float64(-b) - t_1)); else tmp_3 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); end tmp_1 = tmp_3; else tmp_1 = t_0; end return tmp_1 end
function tmp_5 = code(a, b, c) tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = b / -a; end t_0 = tmp; t_1 = sqrt(((b * b) - (c * (a * 4.0)))); tmp_2 = 0.0; if (b <= -2.05e+70) tmp_2 = t_0; elseif (b <= -5e-310) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = 1.0 / (a / (b + (((b ^ 3.0) / c) / a))); else tmp_3 = (t_1 - b) / (a * 2.0); end tmp_2 = tmp_3; elseif (b <= 3.7e+107) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = (c * 2.0) / (-b - t_1); else tmp_4 = (b * -2.0) / (a * 2.0); end tmp_2 = tmp_4; else tmp_2 = t_0; end tmp_5 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(b / (-a)), $MachinePrecision]]}, Block[{t$95$1 = N[Sqrt[N[(N[(b * b), $MachinePrecision] - N[(c * N[(a * 4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[b, -2.05e+70], t$95$0, If[LessEqual[b, -5e-310], If[GreaterEqual[b, 0.0], N[(1.0 / N[(a / N[(b + N[(N[(N[Power[b, 3.0], $MachinePrecision] / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$1 - b), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], If[LessEqual[b, 3.7e+107], If[GreaterEqual[b, 0.0], N[(N[(c * 2.0), $MachinePrecision] / N[((-b) - t$95$1), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $MachinePrecision]], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;\frac{b}{-a}\\
\end{array}\\
t_1 := \sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)}\\
\mathbf{if}\;b \leq -2.05 \cdot 10^{+70}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{1}{\frac{a}{b + \frac{\frac{{b}^{3}}{c}}{a}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_1 - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \leq 3.7 \cdot 10^{+107}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{c \cdot 2}{\left(-b\right) - t\_1}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -2.0500000000000001e70 or 3.7e107 < b Initial program 53.4%
Simplified53.7%
Taylor expanded in c around 0 77.6%
associate-*r/77.6%
mul-1-neg77.6%
Simplified77.6%
Taylor expanded in b around -inf 95.2%
associate-*r/95.2%
mul-1-neg95.2%
Simplified95.2%
if -2.0500000000000001e70 < b < -4.999999999999985e-310Initial program 92.6%
Taylor expanded in a around 0 92.6%
distribute-lft-out--92.6%
associate-/l*92.6%
Simplified92.6%
Taylor expanded in a around inf 92.6%
clear-num92.6%
inv-pow92.6%
*-commutative92.6%
Applied egg-rr92.6%
unpow-192.6%
associate-/r*92.6%
Simplified92.6%
if -4.999999999999985e-310 < b < 3.7e107Initial program 88.0%
Taylor expanded in b around -inf 88.0%
*-commutative88.0%
Simplified88.0%
Final simplification92.3%
(FPCore (a b c)
:precision binary64
(if (or (<= b -5.7e+72) (not (<= b 6.5e-301)))
(if (>= b 0.0) (/ (- c) b) (/ b (- a)))
(if (>= b 0.0)
(/ 1.0 (/ a (+ b (/ (/ (pow b 3.0) c) a))))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))))
double code(double a, double b, double c) {
double tmp_1;
if ((b <= -5.7e+72) || !(b <= 6.5e-301)) {
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 = 1.0 / (a / (b + ((pow(b, 3.0) / c) / a)));
} 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) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
if ((b <= (-5.7d+72)) .or. (.not. (b <= 6.5d-301))) 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 = 1.0d0 / (a / (b + (((b ** 3.0d0) / c) / a)))
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 tmp_1;
if ((b <= -5.7e+72) || !(b <= 6.5e-301)) {
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 = 1.0 / (a / (b + ((Math.pow(b, 3.0) / c) / a)));
} else {
tmp_1 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
return tmp_1;
}
def code(a, b, c): tmp_1 = 0 if (b <= -5.7e+72) or not (b <= 6.5e-301): 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 = 1.0 / (a / (b + ((math.pow(b, 3.0) / c) / a))) else: tmp_1 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) return tmp_1
function code(a, b, c) tmp_1 = 0.0 if ((b <= -5.7e+72) || !(b <= 6.5e-301)) 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(1.0 / Float64(a / Float64(b + Float64(Float64((b ^ 3.0) / c) / a)))); 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) tmp_2 = 0.0; if ((b <= -5.7e+72) || ~((b <= 6.5e-301))) 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 = 1.0 / (a / (b + (((b ^ 3.0) / c) / a))); else tmp_2 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); end tmp_4 = tmp_2; end
code[a_, b_, c_] := If[Or[LessEqual[b, -5.7e+72], N[Not[LessEqual[b, 6.5e-301]], $MachinePrecision]], If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], N[(b / (-a)), $MachinePrecision]], If[GreaterEqual[b, 0.0], N[(1.0 / N[(a / N[(b + N[(N[(N[Power[b, 3.0], $MachinePrecision] / c), $MachinePrecision] / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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}
\mathbf{if}\;b \leq -5.7 \cdot 10^{+72} \lor \neg \left(b \leq 6.5 \cdot 10^{-301}\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{1}{\frac{a}{b + \frac{\frac{{b}^{3}}{c}}{a}}}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -5.6999999999999997e72 or 6.49999999999999991e-301 < b Initial program 67.8%
Simplified67.9%
Taylor expanded in c around 0 63.5%
associate-*r/63.5%
mul-1-neg63.5%
Simplified63.5%
Taylor expanded in b around -inf 73.8%
associate-*r/73.8%
mul-1-neg73.8%
Simplified73.8%
if -5.6999999999999997e72 < b < 6.49999999999999991e-301Initial program 92.6%
Taylor expanded in a around 0 92.6%
distribute-lft-out--92.6%
associate-/l*92.6%
Simplified92.6%
Taylor expanded in a around inf 92.6%
clear-num92.6%
inv-pow92.6%
*-commutative92.6%
Applied egg-rr92.6%
unpow-192.6%
associate-/r*92.6%
Simplified92.6%
Final simplification78.6%
(FPCore (a b c)
:precision binary64
(if (<= b -7e+65)
(if (>= b 0.0) (/ (- c) b) (/ b (- a)))
(if (>= b 0.0)
(/ (* c 2.0) (* 2.0 (- (* a (/ c b)) b)))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))))
double code(double a, double b, double c) {
double tmp_1;
if (b <= -7e+65) {
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) / (2.0 * ((a * (c / b)) - b));
} 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) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
if (b <= (-7d+65)) 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) / (2.0d0 * ((a * (c / b)) - b))
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 tmp_1;
if (b <= -7e+65) {
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) / (2.0 * ((a * (c / b)) - b));
} else {
tmp_1 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
return tmp_1;
}
def code(a, b, c): tmp_1 = 0 if b <= -7e+65: 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) / (2.0 * ((a * (c / b)) - b)) else: tmp_1 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) return tmp_1
function code(a, b, c) tmp_1 = 0.0 if (b <= -7e+65) 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(2.0 * Float64(Float64(a * Float64(c / b)) - b))); 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) tmp_2 = 0.0; if (b <= -7e+65) 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) / (2.0 * ((a * (c / b)) - b)); else tmp_2 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); end tmp_4 = tmp_2; end
code[a_, b_, c_] := If[LessEqual[b, -7e+65], 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[(2.0 * N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 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}
\mathbf{if}\;b \leq -7 \cdot 10^{+65}:\\
\;\;\;\;\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}{2 \cdot \left(a \cdot \frac{c}{b} - b\right)}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\end{array}
\end{array}
if b < -7.0000000000000002e65Initial program 56.3%
Simplified56.5%
Taylor expanded in c around 0 56.5%
associate-*r/56.5%
mul-1-neg56.5%
Simplified56.5%
Taylor expanded in b around -inf 90.7%
associate-*r/90.7%
mul-1-neg90.7%
Simplified90.7%
if -7.0000000000000002e65 < b Initial program 79.4%
Taylor expanded in a around 0 72.7%
distribute-lft-out--72.7%
associate-/l*75.1%
Simplified75.1%
Final simplification78.6%
(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 74.2%
Simplified74.3%
Taylor expanded in c around 0 71.0%
associate-*r/71.0%
mul-1-neg71.0%
Simplified71.0%
Taylor expanded in b around -inf 64.4%
associate-*r/64.4%
mul-1-neg64.4%
Simplified64.4%
Final simplification64.4%
herbie shell --seed 2024123
(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))))