
(FPCore (p r q) :precision binary64 (* (/ 1.0 2.0) (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
return (1.0 / 2.0) * ((fabs(p) + fabs(r)) - sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
real(8) function code(p, r, q)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q): return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q) return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0)))))) end
function tmp = code(p, r, q) tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0))))); end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (p r q) :precision binary64 (* (/ 1.0 2.0) (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))
double code(double p, double r, double q) {
return (1.0 / 2.0) * ((fabs(p) + fabs(r)) - sqrt((pow((p - r), 2.0) + (4.0 * pow(q, 2.0)))));
}
real(8) function code(p, r, q)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q
code = (1.0d0 / 2.0d0) * ((abs(p) + abs(r)) - sqrt((((p - r) ** 2.0d0) + (4.0d0 * (q ** 2.0d0)))))
end function
public static double code(double p, double r, double q) {
return (1.0 / 2.0) * ((Math.abs(p) + Math.abs(r)) - Math.sqrt((Math.pow((p - r), 2.0) + (4.0 * Math.pow(q, 2.0)))));
}
def code(p, r, q): return (1.0 / 2.0) * ((math.fabs(p) + math.fabs(r)) - math.sqrt((math.pow((p - r), 2.0) + (4.0 * math.pow(q, 2.0)))))
function code(p, r, q) return Float64(Float64(1.0 / 2.0) * Float64(Float64(abs(p) + abs(r)) - sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q ^ 2.0)))))) end
function tmp = code(p, r, q) tmp = (1.0 / 2.0) * ((abs(p) + abs(r)) - sqrt((((p - r) ^ 2.0) + (4.0 * (q ^ 2.0))))); end
code[p_, r_, q_] := N[(N[(1.0 / 2.0), $MachinePrecision] * N[(N[(N[Abs[p], $MachinePrecision] + N[Abs[r], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[Power[N[(p - r), $MachinePrecision], 2.0], $MachinePrecision] + N[(4.0 * N[Power[q, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{2} \cdot \left(\left(\left|p\right| + \left|r\right|\right) - \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q}^{2}}\right)
\end{array}
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(let* ((t_0 (hypot (* 2.0 q_m) p)))
(if (<= q_m 9e-56)
(* 0.5 (+ p (+ (fabs p) (- (fabs r) r))))
(if (or (<= q_m 3.1e+47) (not (<= q_m 2.6e+90)))
(*
(fma (pow (pow t_0 -0.5) 2.0) (* r p) (- (+ (fabs r) (fabs p)) t_0))
0.5)
(/ (* (- q_m) q_m) r)))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double t_0 = hypot((2.0 * q_m), p);
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else if ((q_m <= 3.1e+47) || !(q_m <= 2.6e+90)) {
tmp = fma(pow(pow(t_0, -0.5), 2.0), (r * p), ((fabs(r) + fabs(p)) - t_0)) * 0.5;
} else {
tmp = (-q_m * q_m) / r;
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) t_0 = hypot(Float64(2.0 * q_m), p) tmp = 0.0 if (q_m <= 9e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); elseif ((q_m <= 3.1e+47) || !(q_m <= 2.6e+90)) tmp = Float64(fma(((t_0 ^ -0.5) ^ 2.0), Float64(r * p), Float64(Float64(abs(r) + abs(p)) - t_0)) * 0.5); else tmp = Float64(Float64(Float64(-q_m) * q_m) / r); end return tmp end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := Block[{t$95$0 = N[Sqrt[N[(2.0 * q$95$m), $MachinePrecision] ^ 2 + p ^ 2], $MachinePrecision]}, If[LessEqual[q$95$m, 9e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[q$95$m, 3.1e+47], N[Not[LessEqual[q$95$m, 2.6e+90]], $MachinePrecision]], N[(N[(N[Power[N[Power[t$95$0, -0.5], $MachinePrecision], 2.0], $MachinePrecision] * N[(r * p), $MachinePrecision] + N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] - t$95$0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(2 \cdot q\_m, p\right)\\
\mathbf{if}\;q\_m \leq 9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{elif}\;q\_m \leq 3.1 \cdot 10^{+47} \lor \neg \left(q\_m \leq 2.6 \cdot 10^{+90}\right):\\
\;\;\;\;\mathsf{fma}\left({\left({t\_0}^{-0.5}\right)}^{2}, r \cdot p, \left(\left|r\right| + \left|p\right|\right) - t\_0\right) \cdot 0.5\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
\end{array}
\end{array}
if q < 9.0000000000000001e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 9.0000000000000001e-56 < q < 3.1000000000000001e47 or 2.5999999999999998e90 < q Initial program 25.9%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites23.4%
Applied rewrites23.4%
Applied rewrites56.7%
Applied rewrites57.2%
if 3.1000000000000001e47 < q < 2.5999999999999998e90Initial program 2.2%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f641.7
Applied rewrites1.7%
Taylor expanded in q around 0
Applied rewrites31.0%
Taylor expanded in r around 0
Applied rewrites35.4%
Final simplification28.4%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(let* ((t_0 (- (+ (fabs r) (fabs p)) (hypot (* 2.0 q_m) p))))
(if (<= q_m 7.8e-56)
(* 0.5 (+ p (+ (fabs p) (- (fabs r) r))))
(if (<= q_m 3.1e+47)
(* (fma (pow (fma (* q_m q_m) 4.0 (* p p)) -0.5) (* r p) t_0) 0.5)
(if (<= q_m 2.6e+90)
(/ (* (- q_m) q_m) r)
(* (fma (/ -0.5 q_m) (* r p) t_0) 0.5))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double t_0 = (fabs(r) + fabs(p)) - hypot((2.0 * q_m), p);
double tmp;
if (q_m <= 7.8e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else if (q_m <= 3.1e+47) {
tmp = fma(pow(fma((q_m * q_m), 4.0, (p * p)), -0.5), (r * p), t_0) * 0.5;
} else if (q_m <= 2.6e+90) {
tmp = (-q_m * q_m) / r;
} else {
tmp = fma((-0.5 / q_m), (r * p), t_0) * 0.5;
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) t_0 = Float64(Float64(abs(r) + abs(p)) - hypot(Float64(2.0 * q_m), p)) tmp = 0.0 if (q_m <= 7.8e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); elseif (q_m <= 3.1e+47) tmp = Float64(fma((fma(Float64(q_m * q_m), 4.0, Float64(p * p)) ^ -0.5), Float64(r * p), t_0) * 0.5); elseif (q_m <= 2.6e+90) tmp = Float64(Float64(Float64(-q_m) * q_m) / r); else tmp = Float64(fma(Float64(-0.5 / q_m), Float64(r * p), t_0) * 0.5); end return tmp end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := Block[{t$95$0 = N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(2.0 * q$95$m), $MachinePrecision] ^ 2 + p ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[q$95$m, 7.8e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[q$95$m, 3.1e+47], N[(N[(N[Power[N[(N[(q$95$m * q$95$m), $MachinePrecision] * 4.0 + N[(p * p), $MachinePrecision]), $MachinePrecision], -0.5], $MachinePrecision] * N[(r * p), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 2.6e+90], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision], N[(N[(N[(-0.5 / q$95$m), $MachinePrecision] * N[(r * p), $MachinePrecision] + t$95$0), $MachinePrecision] * 0.5), $MachinePrecision]]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := \left(\left|r\right| + \left|p\right|\right) - \mathsf{hypot}\left(2 \cdot q\_m, p\right)\\
\mathbf{if}\;q\_m \leq 7.8 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{elif}\;q\_m \leq 3.1 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left({\left(\mathsf{fma}\left(q\_m \cdot q\_m, 4, p \cdot p\right)\right)}^{-0.5}, r \cdot p, t\_0\right) \cdot 0.5\\
\mathbf{elif}\;q\_m \leq 2.6 \cdot 10^{+90}:\\
\;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-0.5}{q\_m}, r \cdot p, t\_0\right) \cdot 0.5\\
\end{array}
\end{array}
if q < 7.8e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 7.8e-56 < q < 3.1000000000000001e47Initial program 34.4%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.3%
Applied rewrites34.3%
Applied rewrites34.5%
if 3.1000000000000001e47 < q < 2.5999999999999998e90Initial program 2.2%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f641.7
Applied rewrites1.7%
Taylor expanded in q around 0
Applied rewrites31.0%
Taylor expanded in r around 0
Applied rewrites35.4%
if 2.5999999999999998e90 < q Initial program 21.7%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites18.0%
Applied rewrites18.0%
Applied rewrites67.5%
Taylor expanded in q around -inf
Applied rewrites67.5%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(let* ((t_0 (fma (* q_m q_m) 4.0 (* p p))) (t_1 (+ (fabs r) (fabs p))))
(if (<= q_m 9e-56)
(* 0.5 (+ p (+ (fabs p) (- (fabs r) r))))
(if (<= q_m 3.1e+47)
(* (fma (sqrt (pow t_0 -1.0)) (* r p) (- t_1 (sqrt t_0))) 0.5)
(if (<= q_m 2.6e+90)
(/ (* (- q_m) q_m) r)
(* (fma (/ -0.5 q_m) (* r p) (- t_1 (hypot (* 2.0 q_m) p))) 0.5))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double t_0 = fma((q_m * q_m), 4.0, (p * p));
double t_1 = fabs(r) + fabs(p);
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else if (q_m <= 3.1e+47) {
tmp = fma(sqrt(pow(t_0, -1.0)), (r * p), (t_1 - sqrt(t_0))) * 0.5;
} else if (q_m <= 2.6e+90) {
tmp = (-q_m * q_m) / r;
} else {
tmp = fma((-0.5 / q_m), (r * p), (t_1 - hypot((2.0 * q_m), p))) * 0.5;
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) t_0 = fma(Float64(q_m * q_m), 4.0, Float64(p * p)) t_1 = Float64(abs(r) + abs(p)) tmp = 0.0 if (q_m <= 9e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); elseif (q_m <= 3.1e+47) tmp = Float64(fma(sqrt((t_0 ^ -1.0)), Float64(r * p), Float64(t_1 - sqrt(t_0))) * 0.5); elseif (q_m <= 2.6e+90) tmp = Float64(Float64(Float64(-q_m) * q_m) / r); else tmp = Float64(fma(Float64(-0.5 / q_m), Float64(r * p), Float64(t_1 - hypot(Float64(2.0 * q_m), p))) * 0.5); end return tmp end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := Block[{t$95$0 = N[(N[(q$95$m * q$95$m), $MachinePrecision] * 4.0 + N[(p * p), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[q$95$m, 9e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[q$95$m, 3.1e+47], N[(N[(N[Sqrt[N[Power[t$95$0, -1.0], $MachinePrecision]], $MachinePrecision] * N[(r * p), $MachinePrecision] + N[(t$95$1 - N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 2.6e+90], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision], N[(N[(N[(-0.5 / q$95$m), $MachinePrecision] * N[(r * p), $MachinePrecision] + N[(t$95$1 - N[Sqrt[N[(2.0 * q$95$m), $MachinePrecision] ^ 2 + p ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(q\_m \cdot q\_m, 4, p \cdot p\right)\\
t_1 := \left|r\right| + \left|p\right|\\
\mathbf{if}\;q\_m \leq 9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{elif}\;q\_m \leq 3.1 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{{t\_0}^{-1}}, r \cdot p, t\_1 - \sqrt{t\_0}\right) \cdot 0.5\\
\mathbf{elif}\;q\_m \leq 2.6 \cdot 10^{+90}:\\
\;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-0.5}{q\_m}, r \cdot p, t\_1 - \mathsf{hypot}\left(2 \cdot q\_m, p\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if q < 9.0000000000000001e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 9.0000000000000001e-56 < q < 3.1000000000000001e47Initial program 34.4%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.3%
if 3.1000000000000001e47 < q < 2.5999999999999998e90Initial program 2.2%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f641.7
Applied rewrites1.7%
Taylor expanded in q around 0
Applied rewrites31.0%
Taylor expanded in r around 0
Applied rewrites35.4%
if 2.5999999999999998e90 < q Initial program 21.7%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites18.0%
Applied rewrites18.0%
Applied rewrites67.5%
Taylor expanded in q around -inf
Applied rewrites67.5%
Final simplification28.3%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(let* ((t_0 (fma (* q_m q_m) 4.0 (* p p))) (t_1 (+ (fabs r) (fabs p))))
(if (<= q_m 9e-56)
(* 0.5 (+ p (+ (fabs p) (- (fabs r) r))))
(if (<= q_m 3.1e+47)
(* (fma (sqrt (pow t_0 -1.0)) (* r p) (- t_1 (sqrt t_0))) 0.5)
(if (<= q_m 2.6e+90)
(/ (* (- q_m) q_m) r)
(*
(fma (* (/ r q_m) (/ r q_m)) -0.125 (- (/ (* 0.5 t_1) q_m) 1.0))
q_m))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double t_0 = fma((q_m * q_m), 4.0, (p * p));
double t_1 = fabs(r) + fabs(p);
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else if (q_m <= 3.1e+47) {
tmp = fma(sqrt(pow(t_0, -1.0)), (r * p), (t_1 - sqrt(t_0))) * 0.5;
} else if (q_m <= 2.6e+90) {
tmp = (-q_m * q_m) / r;
} else {
tmp = fma(((r / q_m) * (r / q_m)), -0.125, (((0.5 * t_1) / q_m) - 1.0)) * q_m;
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) t_0 = fma(Float64(q_m * q_m), 4.0, Float64(p * p)) t_1 = Float64(abs(r) + abs(p)) tmp = 0.0 if (q_m <= 9e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); elseif (q_m <= 3.1e+47) tmp = Float64(fma(sqrt((t_0 ^ -1.0)), Float64(r * p), Float64(t_1 - sqrt(t_0))) * 0.5); elseif (q_m <= 2.6e+90) tmp = Float64(Float64(Float64(-q_m) * q_m) / r); else tmp = Float64(fma(Float64(Float64(r / q_m) * Float64(r / q_m)), -0.125, Float64(Float64(Float64(0.5 * t_1) / q_m) - 1.0)) * q_m); end return tmp end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := Block[{t$95$0 = N[(N[(q$95$m * q$95$m), $MachinePrecision] * 4.0 + N[(p * p), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[q$95$m, 9e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[q$95$m, 3.1e+47], N[(N[(N[Sqrt[N[Power[t$95$0, -1.0], $MachinePrecision]], $MachinePrecision] * N[(r * p), $MachinePrecision] + N[(t$95$1 - N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 2.6e+90], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision], N[(N[(N[(N[(r / q$95$m), $MachinePrecision] * N[(r / q$95$m), $MachinePrecision]), $MachinePrecision] * -0.125 + N[(N[(N[(0.5 * t$95$1), $MachinePrecision] / q$95$m), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * q$95$m), $MachinePrecision]]]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(q\_m \cdot q\_m, 4, p \cdot p\right)\\
t_1 := \left|r\right| + \left|p\right|\\
\mathbf{if}\;q\_m \leq 9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{elif}\;q\_m \leq 3.1 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(\sqrt{{t\_0}^{-1}}, r \cdot p, t\_1 - \sqrt{t\_0}\right) \cdot 0.5\\
\mathbf{elif}\;q\_m \leq 2.6 \cdot 10^{+90}:\\
\;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{r}{q\_m} \cdot \frac{r}{q\_m}, -0.125, \frac{0.5 \cdot t\_1}{q\_m} - 1\right) \cdot q\_m\\
\end{array}
\end{array}
if q < 9.0000000000000001e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 9.0000000000000001e-56 < q < 3.1000000000000001e47Initial program 34.4%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.3%
if 3.1000000000000001e47 < q < 2.5999999999999998e90Initial program 2.2%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f641.7
Applied rewrites1.7%
Taylor expanded in q around 0
Applied rewrites31.0%
Taylor expanded in r around 0
Applied rewrites35.4%
if 2.5999999999999998e90 < q Initial program 21.7%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6420.3
Applied rewrites20.3%
Taylor expanded in q around inf
Applied rewrites67.0%
Final simplification28.2%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(let* ((t_0 (fma (* q_m q_m) 4.0 (* p p))) (t_1 (+ (fabs r) (fabs p))))
(if (<= q_m 9e-56)
(* 0.5 (+ p (+ (fabs p) (- (fabs r) r))))
(if (<= q_m 3.1e+47)
(* (fma (pow t_0 -0.5) (* r p) (- t_1 (sqrt t_0))) 0.5)
(if (<= q_m 2.6e+90)
(/ (* (- q_m) q_m) r)
(* (fma (/ -0.5 q_m) (* r p) (- t_1 (hypot (* 2.0 q_m) p))) 0.5))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double t_0 = fma((q_m * q_m), 4.0, (p * p));
double t_1 = fabs(r) + fabs(p);
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else if (q_m <= 3.1e+47) {
tmp = fma(pow(t_0, -0.5), (r * p), (t_1 - sqrt(t_0))) * 0.5;
} else if (q_m <= 2.6e+90) {
tmp = (-q_m * q_m) / r;
} else {
tmp = fma((-0.5 / q_m), (r * p), (t_1 - hypot((2.0 * q_m), p))) * 0.5;
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) t_0 = fma(Float64(q_m * q_m), 4.0, Float64(p * p)) t_1 = Float64(abs(r) + abs(p)) tmp = 0.0 if (q_m <= 9e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); elseif (q_m <= 3.1e+47) tmp = Float64(fma((t_0 ^ -0.5), Float64(r * p), Float64(t_1 - sqrt(t_0))) * 0.5); elseif (q_m <= 2.6e+90) tmp = Float64(Float64(Float64(-q_m) * q_m) / r); else tmp = Float64(fma(Float64(-0.5 / q_m), Float64(r * p), Float64(t_1 - hypot(Float64(2.0 * q_m), p))) * 0.5); end return tmp end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := Block[{t$95$0 = N[(N[(q$95$m * q$95$m), $MachinePrecision] * 4.0 + N[(p * p), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[q$95$m, 9e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[q$95$m, 3.1e+47], N[(N[(N[Power[t$95$0, -0.5], $MachinePrecision] * N[(r * p), $MachinePrecision] + N[(t$95$1 - N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 2.6e+90], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision], N[(N[(N[(-0.5 / q$95$m), $MachinePrecision] * N[(r * p), $MachinePrecision] + N[(t$95$1 - N[Sqrt[N[(2.0 * q$95$m), $MachinePrecision] ^ 2 + p ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(q\_m \cdot q\_m, 4, p \cdot p\right)\\
t_1 := \left|r\right| + \left|p\right|\\
\mathbf{if}\;q\_m \leq 9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{elif}\;q\_m \leq 3.1 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left({t\_0}^{-0.5}, r \cdot p, t\_1 - \sqrt{t\_0}\right) \cdot 0.5\\
\mathbf{elif}\;q\_m \leq 2.6 \cdot 10^{+90}:\\
\;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-0.5}{q\_m}, r \cdot p, t\_1 - \mathsf{hypot}\left(2 \cdot q\_m, p\right)\right) \cdot 0.5\\
\end{array}
\end{array}
if q < 9.0000000000000001e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 9.0000000000000001e-56 < q < 3.1000000000000001e47Initial program 34.4%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.3%
Applied rewrites34.3%
if 3.1000000000000001e47 < q < 2.5999999999999998e90Initial program 2.2%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f641.7
Applied rewrites1.7%
Taylor expanded in q around 0
Applied rewrites31.0%
Taylor expanded in r around 0
Applied rewrites35.4%
if 2.5999999999999998e90 < q Initial program 21.7%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites18.0%
Applied rewrites18.0%
Applied rewrites67.5%
Taylor expanded in q around -inf
Applied rewrites67.5%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(let* ((t_0 (+ (fabs r) (fabs p))))
(if (<= q_m 9e-56)
(* 0.5 (+ p (+ (fabs p) (- (fabs r) r))))
(if (<= q_m 3.1e+47)
(*
(fma (/ 0.5 q_m) (* r p) (- t_0 (sqrt (fma (* q_m q_m) 4.0 (* p p)))))
0.5)
(if (<= q_m 2.6e+90)
(/ (* (- q_m) q_m) r)
(*
(fma (* (/ r q_m) (/ r q_m)) -0.125 (- (/ (* 0.5 t_0) q_m) 1.0))
q_m))))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double t_0 = fabs(r) + fabs(p);
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else if (q_m <= 3.1e+47) {
tmp = fma((0.5 / q_m), (r * p), (t_0 - sqrt(fma((q_m * q_m), 4.0, (p * p))))) * 0.5;
} else if (q_m <= 2.6e+90) {
tmp = (-q_m * q_m) / r;
} else {
tmp = fma(((r / q_m) * (r / q_m)), -0.125, (((0.5 * t_0) / q_m) - 1.0)) * q_m;
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) t_0 = Float64(abs(r) + abs(p)) tmp = 0.0 if (q_m <= 9e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); elseif (q_m <= 3.1e+47) tmp = Float64(fma(Float64(0.5 / q_m), Float64(r * p), Float64(t_0 - sqrt(fma(Float64(q_m * q_m), 4.0, Float64(p * p))))) * 0.5); elseif (q_m <= 2.6e+90) tmp = Float64(Float64(Float64(-q_m) * q_m) / r); else tmp = Float64(fma(Float64(Float64(r / q_m) * Float64(r / q_m)), -0.125, Float64(Float64(Float64(0.5 * t_0) / q_m) - 1.0)) * q_m); end return tmp end
q_m = N[Abs[q], $MachinePrecision]
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
code[p_, r_, q$95$m_] := Block[{t$95$0 = N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[q$95$m, 9e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[q$95$m, 3.1e+47], N[(N[(N[(0.5 / q$95$m), $MachinePrecision] * N[(r * p), $MachinePrecision] + N[(t$95$0 - N[Sqrt[N[(N[(q$95$m * q$95$m), $MachinePrecision] * 4.0 + N[(p * p), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 2.6e+90], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision], N[(N[(N[(N[(r / q$95$m), $MachinePrecision] * N[(r / q$95$m), $MachinePrecision]), $MachinePrecision] * -0.125 + N[(N[(N[(0.5 * t$95$0), $MachinePrecision] / q$95$m), $MachinePrecision] - 1.0), $MachinePrecision]), $MachinePrecision] * q$95$m), $MachinePrecision]]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
t_0 := \left|r\right| + \left|p\right|\\
\mathbf{if}\;q\_m \leq 9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{elif}\;q\_m \leq 3.1 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(\frac{0.5}{q\_m}, r \cdot p, t\_0 - \sqrt{\mathsf{fma}\left(q\_m \cdot q\_m, 4, p \cdot p\right)}\right) \cdot 0.5\\
\mathbf{elif}\;q\_m \leq 2.6 \cdot 10^{+90}:\\
\;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{r}{q\_m} \cdot \frac{r}{q\_m}, -0.125, \frac{0.5 \cdot t\_0}{q\_m} - 1\right) \cdot q\_m\\
\end{array}
\end{array}
if q < 9.0000000000000001e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 9.0000000000000001e-56 < q < 3.1000000000000001e47Initial program 34.4%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.3%
Taylor expanded in p around 0
Applied rewrites33.8%
if 3.1000000000000001e47 < q < 2.5999999999999998e90Initial program 2.2%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f641.7
Applied rewrites1.7%
Taylor expanded in q around 0
Applied rewrites31.0%
Taylor expanded in r around 0
Applied rewrites35.4%
if 2.5999999999999998e90 < q Initial program 21.7%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6420.3
Applied rewrites20.3%
Taylor expanded in q around inf
Applied rewrites67.0%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(if (<= q_m 9e-56)
(* 0.5 (+ p (+ (fabs p) (- (fabs r) r))))
(if (<= q_m 3.1e+47)
(*
(fma
(/ 0.5 q_m)
(* r p)
(- (+ (fabs r) (fabs p)) (sqrt (fma (* q_m q_m) 4.0 (* p p)))))
0.5)
(if (<= q_m 2.6e+90)
(/ (* (- q_m) q_m) r)
(*
(- (+ (fma (fma r 0.5 (* p -0.25)) (/ p q_m) r) (fabs p)) (* q_m 2.0))
0.5)))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else if (q_m <= 3.1e+47) {
tmp = fma((0.5 / q_m), (r * p), ((fabs(r) + fabs(p)) - sqrt(fma((q_m * q_m), 4.0, (p * p))))) * 0.5;
} else if (q_m <= 2.6e+90) {
tmp = (-q_m * q_m) / r;
} else {
tmp = ((fma(fma(r, 0.5, (p * -0.25)), (p / q_m), r) + fabs(p)) - (q_m * 2.0)) * 0.5;
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (q_m <= 9e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); elseif (q_m <= 3.1e+47) tmp = Float64(fma(Float64(0.5 / q_m), Float64(r * p), Float64(Float64(abs(r) + abs(p)) - sqrt(fma(Float64(q_m * q_m), 4.0, Float64(p * p))))) * 0.5); elseif (q_m <= 2.6e+90) tmp = Float64(Float64(Float64(-q_m) * q_m) / r); else tmp = Float64(Float64(Float64(fma(fma(r, 0.5, Float64(p * -0.25)), Float64(p / q_m), r) + abs(p)) - Float64(q_m * 2.0)) * 0.5); end return tmp end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 9e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[q$95$m, 3.1e+47], N[(N[(N[(0.5 / q$95$m), $MachinePrecision] * N[(r * p), $MachinePrecision] + N[(N[(N[Abs[r], $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] - N[Sqrt[N[(N[(q$95$m * q$95$m), $MachinePrecision] * 4.0 + N[(p * p), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 2.6e+90], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision], N[(N[(N[(N[(N[(r * 0.5 + N[(p * -0.25), $MachinePrecision]), $MachinePrecision] * N[(p / q$95$m), $MachinePrecision] + r), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] - N[(q$95$m * 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{elif}\;q\_m \leq 3.1 \cdot 10^{+47}:\\
\;\;\;\;\mathsf{fma}\left(\frac{0.5}{q\_m}, r \cdot p, \left(\left|r\right| + \left|p\right|\right) - \sqrt{\mathsf{fma}\left(q\_m \cdot q\_m, 4, p \cdot p\right)}\right) \cdot 0.5\\
\mathbf{elif}\;q\_m \leq 2.6 \cdot 10^{+90}:\\
\;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(r, 0.5, p \cdot -0.25\right), \frac{p}{q\_m}, r\right) + \left|p\right|\right) - q\_m \cdot 2\right) \cdot 0.5\\
\end{array}
\end{array}
if q < 9.0000000000000001e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 9.0000000000000001e-56 < q < 3.1000000000000001e47Initial program 34.4%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites34.3%
Taylor expanded in p around 0
Applied rewrites33.8%
if 3.1000000000000001e47 < q < 2.5999999999999998e90Initial program 2.2%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f641.7
Applied rewrites1.7%
Taylor expanded in q around 0
Applied rewrites31.0%
Taylor expanded in r around 0
Applied rewrites35.4%
if 2.5999999999999998e90 < q Initial program 21.7%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites18.0%
Taylor expanded in p around 0
Applied rewrites66.9%
Applied rewrites66.3%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(if (<= q_m 9e-56)
(* 0.5 (+ p (+ (fabs p) (- (fabs r) r))))
(if (<= q_m 3.1e+47)
(- q_m)
(if (<= q_m 2.6e+90)
(/ (* (- q_m) q_m) r)
(*
(- (+ (fma (fma r 0.5 (* p -0.25)) (/ p q_m) r) (fabs p)) (* q_m 2.0))
0.5)))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else if (q_m <= 3.1e+47) {
tmp = -q_m;
} else if (q_m <= 2.6e+90) {
tmp = (-q_m * q_m) / r;
} else {
tmp = ((fma(fma(r, 0.5, (p * -0.25)), (p / q_m), r) + fabs(p)) - (q_m * 2.0)) * 0.5;
}
return tmp;
}
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (q_m <= 9e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); elseif (q_m <= 3.1e+47) tmp = Float64(-q_m); elseif (q_m <= 2.6e+90) tmp = Float64(Float64(Float64(-q_m) * q_m) / r); else tmp = Float64(Float64(Float64(fma(fma(r, 0.5, Float64(p * -0.25)), Float64(p / q_m), r) + abs(p)) - Float64(q_m * 2.0)) * 0.5); end return tmp end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 9e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[q$95$m, 3.1e+47], (-q$95$m), If[LessEqual[q$95$m, 2.6e+90], N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision], N[(N[(N[(N[(N[(r * 0.5 + N[(p * -0.25), $MachinePrecision]), $MachinePrecision] * N[(p / q$95$m), $MachinePrecision] + r), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] - N[(q$95$m * 2.0), $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision]]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{elif}\;q\_m \leq 3.1 \cdot 10^{+47}:\\
\;\;\;\;-q\_m\\
\mathbf{elif}\;q\_m \leq 2.6 \cdot 10^{+90}:\\
\;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(r, 0.5, p \cdot -0.25\right), \frac{p}{q\_m}, r\right) + \left|p\right|\right) - q\_m \cdot 2\right) \cdot 0.5\\
\end{array}
\end{array}
if q < 9.0000000000000001e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 9.0000000000000001e-56 < q < 3.1000000000000001e47Initial program 34.4%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f6433.6
Applied rewrites33.6%
if 3.1000000000000001e47 < q < 2.5999999999999998e90Initial program 2.2%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f641.7
Applied rewrites1.7%
Taylor expanded in q around 0
Applied rewrites31.0%
Taylor expanded in r around 0
Applied rewrites35.4%
if 2.5999999999999998e90 < q Initial program 21.7%
Taylor expanded in r around 0
distribute-lft-outN/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites18.0%
Taylor expanded in p around 0
Applied rewrites66.9%
Applied rewrites66.3%
q_m = (fabs.f64 q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
(FPCore (p r q_m)
:precision binary64
(if (<= q_m 9e-56)
(* 0.5 (+ p (+ (fabs p) (- (fabs r) r))))
(if (or (<= q_m 3.1e+47) (not (<= q_m 2.6e+90)))
(- q_m)
(/ (* (- q_m) q_m) r))))q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else if ((q_m <= 3.1e+47) || !(q_m <= 2.6e+90)) {
tmp = -q_m;
} else {
tmp = (-q_m * q_m) / r;
}
return tmp;
}
q_m = abs(q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
real(8) function code(p, r, q_m)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (q_m <= 9d-56) then
tmp = 0.5d0 * (p + (abs(p) + (abs(r) - r)))
else if ((q_m <= 3.1d+47) .or. (.not. (q_m <= 2.6d+90))) then
tmp = -q_m
else
tmp = (-q_m * q_m) / r
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (Math.abs(p) + (Math.abs(r) - r)));
} else if ((q_m <= 3.1e+47) || !(q_m <= 2.6e+90)) {
tmp = -q_m;
} else {
tmp = (-q_m * q_m) / r;
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if q_m <= 9e-56: tmp = 0.5 * (p + (math.fabs(p) + (math.fabs(r) - r))) elif (q_m <= 3.1e+47) or not (q_m <= 2.6e+90): tmp = -q_m else: tmp = (-q_m * q_m) / r return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (q_m <= 9e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); elseif ((q_m <= 3.1e+47) || !(q_m <= 2.6e+90)) tmp = Float64(-q_m); else tmp = Float64(Float64(Float64(-q_m) * q_m) / r); end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if (q_m <= 9e-56)
tmp = 0.5 * (p + (abs(p) + (abs(r) - r)));
elseif ((q_m <= 3.1e+47) || ~((q_m <= 2.6e+90)))
tmp = -q_m;
else
tmp = (-q_m * q_m) / r;
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 9e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[q$95$m, 3.1e+47], N[Not[LessEqual[q$95$m, 2.6e+90]], $MachinePrecision]], (-q$95$m), N[(N[((-q$95$m) * q$95$m), $MachinePrecision] / r), $MachinePrecision]]]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{elif}\;q\_m \leq 3.1 \cdot 10^{+47} \lor \neg \left(q\_m \leq 2.6 \cdot 10^{+90}\right):\\
\;\;\;\;-q\_m\\
\mathbf{else}:\\
\;\;\;\;\frac{\left(-q\_m\right) \cdot q\_m}{r}\\
\end{array}
\end{array}
if q < 9.0000000000000001e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 9.0000000000000001e-56 < q < 3.1000000000000001e47 or 2.5999999999999998e90 < q Initial program 25.9%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f6455.5
Applied rewrites55.5%
if 3.1000000000000001e47 < q < 2.5999999999999998e90Initial program 2.2%
Taylor expanded in p around 0
*-commutativeN/A
lower-*.f64N/A
lower--.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f641.7
Applied rewrites1.7%
Taylor expanded in q around 0
Applied rewrites31.0%
Taylor expanded in r around 0
Applied rewrites35.4%
Final simplification28.0%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (if (<= q_m 9e-56) (* 0.5 (+ p (+ (fabs p) (- (fabs r) r)))) (- q_m)))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (fabs(p) + (fabs(r) - r)));
} else {
tmp = -q_m;
}
return tmp;
}
q_m = abs(q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
real(8) function code(p, r, q_m)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
real(8) :: tmp
if (q_m <= 9d-56) then
tmp = 0.5d0 * (p + (abs(p) + (abs(r) - r)))
else
tmp = -q_m
end if
code = tmp
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
double tmp;
if (q_m <= 9e-56) {
tmp = 0.5 * (p + (Math.abs(p) + (Math.abs(r) - r)));
} else {
tmp = -q_m;
}
return tmp;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): tmp = 0 if q_m <= 9e-56: tmp = 0.5 * (p + (math.fabs(p) + (math.fabs(r) - r))) else: tmp = -q_m return tmp
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) tmp = 0.0 if (q_m <= 9e-56) tmp = Float64(0.5 * Float64(p + Float64(abs(p) + Float64(abs(r) - r)))); else tmp = Float64(-q_m); end return tmp end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp_2 = code(p, r, q_m)
tmp = 0.0;
if (q_m <= 9e-56)
tmp = 0.5 * (p + (abs(p) + (abs(r) - r)));
else
tmp = -q_m;
end
tmp_2 = tmp;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := If[LessEqual[q$95$m, 9e-56], N[(0.5 * N[(p + N[(N[Abs[p], $MachinePrecision] + N[(N[Abs[r], $MachinePrecision] - r), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-q$95$m)]
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
\begin{array}{l}
\mathbf{if}\;q\_m \leq 9 \cdot 10^{-56}:\\
\;\;\;\;0.5 \cdot \left(p + \left(\left|p\right| + \left(\left|r\right| - r\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;-q\_m\\
\end{array}
\end{array}
if q < 9.0000000000000001e-56Initial program 29.7%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f644.4
Applied rewrites4.4%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-/.f64N/A
associate--l+N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower--.f64N/A
lower-fabs.f6418.3
Applied rewrites18.3%
Taylor expanded in p around 0
Applied rewrites18.3%
if 9.0000000000000001e-56 < q Initial program 22.0%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f6447.0
Applied rewrites47.0%
q_m = (fabs.f64 q) NOTE: p, r, and q_m should be sorted in increasing order before calling this function. (FPCore (p r q_m) :precision binary64 (- q_m))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
return -q_m;
}
q_m = abs(q)
NOTE: p, r, and q_m should be sorted in increasing order before calling this function.
real(8) function code(p, r, q_m)
real(8), intent (in) :: p
real(8), intent (in) :: r
real(8), intent (in) :: q_m
code = -q_m
end function
q_m = Math.abs(q);
assert p < r && r < q_m;
public static double code(double p, double r, double q_m) {
return -q_m;
}
q_m = math.fabs(q) [p, r, q_m] = sort([p, r, q_m]) def code(p, r, q_m): return -q_m
q_m = abs(q) p, r, q_m = sort([p, r, q_m]) function code(p, r, q_m) return Float64(-q_m) end
q_m = abs(q);
p, r, q_m = num2cell(sort([p, r, q_m])){:}
function tmp = code(p, r, q_m)
tmp = -q_m;
end
q_m = N[Abs[q], $MachinePrecision] NOTE: p, r, and q_m should be sorted in increasing order before calling this function. code[p_, r_, q$95$m_] := (-q$95$m)
\begin{array}{l}
q_m = \left|q\right|
\\
[p, r, q_m] = \mathsf{sort}([p, r, q_m])\\
\\
-q\_m
\end{array}
Initial program 27.5%
Taylor expanded in q around inf
mul-1-negN/A
lower-neg.f6416.6
Applied rewrites16.6%
herbie shell --seed 2024343
(FPCore (p r q)
:name "1/2(abs(p)+abs(r) - sqrt((p-r)^2 + 4q^2))"
:precision binary64
(* (/ 1.0 2.0) (- (+ (fabs p) (fabs r)) (sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q 2.0)))))))