
(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%
*-commutative95.2%
Simplified95.2%
Taylor expanded in b around 0 95.2%
associate-*r/95.2%
mul-1-neg95.2%
associate-*r/95.2%
neg-mul-195.2%
Simplified95.2%
if -1.12000000000000001e75 < b < 9.00000000000000042e102Initial program 90.1%
Final simplification92.3%
(FPCore (a b c)
:precision binary64
(let* ((t_0 (sqrt (- (* b b) (* c (* a 4.0)))))
(t_1 (/ b (- a)))
(t_2 (if (>= b 0.0) (/ (- c) b) t_1)))
(if (<= b -2.05e+70)
t_2
(if (<= b -5e-310)
(if (>= b 0.0)
(* b (/ (+ (/ c a) (pow t_1 2.0)) c))
(/ (- t_0 b) (* a 2.0)))
(if (<= b 3.7e+107)
(if (>= b 0.0) (/ (* c 2.0) (- (- b) t_0)) (/ (* b -2.0) (* a 2.0)))
t_2)))))
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;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = t_1;
}
double t_2 = tmp;
double tmp_1;
if (b <= -2.05e+70) {
tmp_1 = t_2;
} else if (b <= -5e-310) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = b * (((c / a) + pow(t_1, 2.0)) / c);
} else {
tmp_2 = (t_0 - 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_0);
} else {
tmp_3 = (b * -2.0) / (a * 2.0);
}
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 = b / -a
if (b >= 0.0d0) then
tmp = -c / b
else
tmp = t_1
end if
t_2 = tmp
if (b <= (-2.05d+70)) then
tmp_1 = t_2
else if (b <= (-5d-310)) then
if (b >= 0.0d0) then
tmp_2 = b * (((c / a) + (t_1 ** 2.0d0)) / c)
else
tmp_2 = (t_0 - 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_0)
else
tmp_3 = (b * (-2.0d0)) / (a * 2.0d0)
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 = b / -a;
double tmp;
if (b >= 0.0) {
tmp = -c / b;
} else {
tmp = t_1;
}
double t_2 = tmp;
double tmp_1;
if (b <= -2.05e+70) {
tmp_1 = t_2;
} else if (b <= -5e-310) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = b * (((c / a) + Math.pow(t_1, 2.0)) / c);
} else {
tmp_2 = (t_0 - 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_0);
} else {
tmp_3 = (b * -2.0) / (a * 2.0);
}
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 = b / -a tmp = 0 if b >= 0.0: tmp = -c / b else: tmp = t_1 t_2 = tmp tmp_1 = 0 if b <= -2.05e+70: tmp_1 = t_2 elif b <= -5e-310: tmp_2 = 0 if b >= 0.0: tmp_2 = b * (((c / a) + math.pow(t_1, 2.0)) / c) else: tmp_2 = (t_0 - 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_0) else: tmp_3 = (b * -2.0) / (a * 2.0) 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(b / Float64(-a)) tmp = 0.0 if (b >= 0.0) tmp = Float64(Float64(-c) / b); else tmp = t_1; end t_2 = tmp tmp_1 = 0.0 if (b <= -2.05e+70) tmp_1 = t_2; elseif (b <= -5e-310) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = Float64(b * Float64(Float64(Float64(c / a) + (t_1 ^ 2.0)) / c)); else tmp_2 = Float64(Float64(t_0 - 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_0)); else tmp_3 = Float64(Float64(b * -2.0) / Float64(a * 2.0)); 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 = b / -a; tmp = 0.0; if (b >= 0.0) tmp = -c / b; else tmp = t_1; end t_2 = tmp; tmp_2 = 0.0; if (b <= -2.05e+70) tmp_2 = t_2; elseif (b <= -5e-310) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = b * (((c / a) + (t_1 ^ 2.0)) / c); else tmp_3 = (t_0 - 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_0); else tmp_4 = (b * -2.0) / (a * 2.0); 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[(b / (-a)), $MachinePrecision]}, Block[{t$95$2 = If[GreaterEqual[b, 0.0], N[((-c) / b), $MachinePrecision], t$95$1]}, If[LessEqual[b, -2.05e+70], t$95$2, If[LessEqual[b, -5e-310], If[GreaterEqual[b, 0.0], N[(b * N[(N[(N[(c / a), $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision] / c), $MachinePrecision]), $MachinePrecision], N[(N[(t$95$0 - 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$0), $MachinePrecision]), $MachinePrecision], N[(N[(b * -2.0), $MachinePrecision] / N[(a * 2.0), $MachinePrecision]), $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{b}{-a}\\
t_2 := \begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;\frac{-c}{b}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{if}\;b \leq -2.05 \cdot 10^{+70}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;b \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;b \cdot \frac{\frac{c}{a} + {t\_1}^{2}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{t\_0 - 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\_0}\\
\mathbf{else}:\\
\;\;\;\;\frac{b \cdot -2}{a \cdot 2}\\
\end{array}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\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%
*-commutative95.2%
Simplified95.2%
Taylor expanded in b around 0 95.2%
associate-*r/95.2%
mul-1-neg95.2%
associate-*r/95.2%
neg-mul-195.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%
fma-neg92.6%
Simplified92.6%
Taylor expanded in b around 0 92.6%
Taylor expanded in c around 0 92.6%
unpow292.6%
unpow292.6%
times-frac92.6%
sqr-neg92.6%
mul-1-neg92.6%
*-commutative92.6%
mul-1-neg92.6%
*-commutative92.6%
unpow192.6%
pow-plus92.6%
*-commutative92.6%
associate-*r/92.6%
neg-mul-192.6%
metadata-eval92.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
(let* ((t_0 (/ (- c) b)) (t_1 (/ b (- a))))
(if (<= b -5.7e+72)
(if (>= b 0.0) t_0 t_1)
(if (<= b 1.35e-166)
(if (>= b 0.0)
(* b (/ (+ (/ c a) (pow t_1 2.0)) c))
(/ (- (sqrt (- (* b b) (* c (* a 4.0)))) b) (* a 2.0)))
(if (>= b 0.0) (/ c (- (* a (/ c b)) b)) t_0)))))
double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = b / -a;
double tmp_1;
if (b <= -5.7e+72) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= 1.35e-166) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = b * (((c / a) + pow(t_1, 2.0)) / c);
} else {
tmp_3 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = c / ((a * (c / b)) - b);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
real(8) function code(a, b, c)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: c
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
real(8) :: tmp_1
real(8) :: tmp_2
real(8) :: tmp_3
t_0 = -c / b
t_1 = b / -a
if (b <= (-5.7d+72)) then
if (b >= 0.0d0) then
tmp_2 = t_0
else
tmp_2 = t_1
end if
tmp_1 = tmp_2
else if (b <= 1.35d-166) then
if (b >= 0.0d0) then
tmp_3 = b * (((c / a) + (t_1 ** 2.0d0)) / c)
else
tmp_3 = (sqrt(((b * b) - (c * (a * 4.0d0)))) - b) / (a * 2.0d0)
end if
tmp_1 = tmp_3
else if (b >= 0.0d0) then
tmp_1 = c / ((a * (c / b)) - b)
else
tmp_1 = t_0
end if
code = tmp_1
end function
public static double code(double a, double b, double c) {
double t_0 = -c / b;
double t_1 = b / -a;
double tmp_1;
if (b <= -5.7e+72) {
double tmp_2;
if (b >= 0.0) {
tmp_2 = t_0;
} else {
tmp_2 = t_1;
}
tmp_1 = tmp_2;
} else if (b <= 1.35e-166) {
double tmp_3;
if (b >= 0.0) {
tmp_3 = b * (((c / a) + Math.pow(t_1, 2.0)) / c);
} else {
tmp_3 = (Math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0);
}
tmp_1 = tmp_3;
} else if (b >= 0.0) {
tmp_1 = c / ((a * (c / b)) - b);
} else {
tmp_1 = t_0;
}
return tmp_1;
}
def code(a, b, c): t_0 = -c / b t_1 = b / -a tmp_1 = 0 if b <= -5.7e+72: tmp_2 = 0 if b >= 0.0: tmp_2 = t_0 else: tmp_2 = t_1 tmp_1 = tmp_2 elif b <= 1.35e-166: tmp_3 = 0 if b >= 0.0: tmp_3 = b * (((c / a) + math.pow(t_1, 2.0)) / c) else: tmp_3 = (math.sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0) tmp_1 = tmp_3 elif b >= 0.0: tmp_1 = c / ((a * (c / b)) - b) else: tmp_1 = t_0 return tmp_1
function code(a, b, c) t_0 = Float64(Float64(-c) / b) t_1 = Float64(b / Float64(-a)) tmp_1 = 0.0 if (b <= -5.7e+72) tmp_2 = 0.0 if (b >= 0.0) tmp_2 = t_0; else tmp_2 = t_1; end tmp_1 = tmp_2; elseif (b <= 1.35e-166) tmp_3 = 0.0 if (b >= 0.0) tmp_3 = Float64(b * Float64(Float64(Float64(c / a) + (t_1 ^ 2.0)) / c)); else tmp_3 = Float64(Float64(sqrt(Float64(Float64(b * b) - Float64(c * Float64(a * 4.0)))) - b) / Float64(a * 2.0)); end tmp_1 = tmp_3; elseif (b >= 0.0) tmp_1 = Float64(c / Float64(Float64(a * Float64(c / b)) - b)); else tmp_1 = t_0; end return tmp_1 end
function tmp_5 = code(a, b, c) t_0 = -c / b; t_1 = b / -a; tmp_2 = 0.0; if (b <= -5.7e+72) tmp_3 = 0.0; if (b >= 0.0) tmp_3 = t_0; else tmp_3 = t_1; end tmp_2 = tmp_3; elseif (b <= 1.35e-166) tmp_4 = 0.0; if (b >= 0.0) tmp_4 = b * (((c / a) + (t_1 ^ 2.0)) / c); else tmp_4 = (sqrt(((b * b) - (c * (a * 4.0)))) - b) / (a * 2.0); end tmp_2 = tmp_4; elseif (b >= 0.0) tmp_2 = c / ((a * (c / b)) - b); else tmp_2 = t_0; end tmp_5 = tmp_2; end
code[a_, b_, c_] := Block[{t$95$0 = N[((-c) / b), $MachinePrecision]}, Block[{t$95$1 = N[(b / (-a)), $MachinePrecision]}, If[LessEqual[b, -5.7e+72], If[GreaterEqual[b, 0.0], t$95$0, t$95$1], If[LessEqual[b, 1.35e-166], If[GreaterEqual[b, 0.0], N[(b * N[(N[(N[(c / a), $MachinePrecision] + N[Power[t$95$1, 2.0], $MachinePrecision]), $MachinePrecision] / c), $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]], If[GreaterEqual[b, 0.0], N[(c / N[(N[(a * N[(c / b), $MachinePrecision]), $MachinePrecision] - b), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-c}{b}\\
t_1 := \frac{b}{-a}\\
\mathbf{if}\;b \leq -5.7 \cdot 10^{+72}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}\\
\mathbf{elif}\;b \leq 1.35 \cdot 10^{-166}:\\
\;\;\;\;\begin{array}{l}
\mathbf{if}\;b \geq 0:\\
\;\;\;\;b \cdot \frac{\frac{c}{a} + {t\_1}^{2}}{c}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{b \cdot b - c \cdot \left(a \cdot 4\right)} - b}{a \cdot 2}\\
\end{array}\\
\mathbf{elif}\;b \geq 0:\\
\;\;\;\;\frac{c}{a \cdot \frac{c}{b} - b}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if b < -5.6999999999999997e72Initial 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%
*-commutative90.7%
Simplified90.7%
Taylor expanded in b around 0 90.7%
associate-*r/90.7%
mul-1-neg90.7%
associate-*r/90.7%
neg-mul-190.7%
Simplified90.7%
if -5.6999999999999997e72 < b < 1.35000000000000003e-166Initial program 90.6%
Taylor expanded in a around 0 74.6%
distribute-lft-out--74.6%
associate-/l*74.4%
fma-neg74.4%
Simplified74.4%
Taylor expanded in b around 0 74.1%
Taylor expanded in c around 0 74.2%
unpow274.2%
unpow274.2%
times-frac74.7%
sqr-neg74.7%
mul-1-neg74.7%
*-commutative74.7%
mul-1-neg74.7%
*-commutative74.7%
unpow174.7%
pow-plus74.7%
*-commutative74.7%
associate-*r/74.7%
neg-mul-174.7%
metadata-eval74.7%
Simplified74.7%
if 1.35000000000000003e-166 < b Initial program 71.3%
Taylor expanded in a around 0 71.4%
distribute-lft-out--71.4%
associate-/l*75.5%
fma-neg75.5%
Simplified75.5%
Taylor expanded in a around 0 75.5%
Taylor expanded in b around 0 71.4%
sub-neg71.4%
associate-*r/76.3%
+-commutative76.3%
neg-mul-176.3%
associate-*r/71.4%
neg-mul-171.4%
associate-*r/76.3%
+-commutative76.3%
sub-neg76.3%
associate-*r/76.3%
mul-1-neg76.3%
Simplified76.3%
Final simplification79.0%
(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 (fma 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 * fma(a, (c / b), -b));
} else {
tmp_1 = (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 * fma(a, Float64(c / b), Float64(-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
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[(a * N[(c / b), $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 \mathsf{fma}\left(a, \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%
*-commutative90.7%
Simplified90.7%
Taylor expanded in b around 0 90.7%
associate-*r/90.7%
mul-1-neg90.7%
associate-*r/90.7%
neg-mul-190.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%
fma-neg75.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%
*-commutative64.4%
Simplified64.4%
Taylor expanded in b around 0 64.4%
associate-*r/64.4%
mul-1-neg64.4%
associate-*r/64.4%
neg-mul-164.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))))