
(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 (fma (- p (fabs p)) -0.5 r)))
(if (<= q_m 64000.0)
t_0
(if (<= q_m 8e+87)
(*
(pow 2.0 -1.0)
(+
(+ (fabs p) (fabs r))
(sqrt (+ (pow (- p r) 2.0) (* 4.0 (pow q_m 2.0))))))
(if (<= q_m 4.5e+160)
t_0
(*
(fma
(* (/ p q_m) (/ p q_m))
0.125
(fma (/ (+ r (fabs p)) q_m) 0.5 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((p - fabs(p)), -0.5, r);
double tmp;
if (q_m <= 64000.0) {
tmp = t_0;
} else if (q_m <= 8e+87) {
tmp = pow(2.0, -1.0) * ((fabs(p) + fabs(r)) + sqrt((pow((p - r), 2.0) + (4.0 * pow(q_m, 2.0)))));
} else if (q_m <= 4.5e+160) {
tmp = t_0;
} else {
tmp = fma(((p / q_m) * (p / q_m)), 0.125, fma(((r + fabs(p)) / q_m), 0.5, 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(p - abs(p)), -0.5, r) tmp = 0.0 if (q_m <= 64000.0) tmp = t_0; elseif (q_m <= 8e+87) tmp = Float64((2.0 ^ -1.0) * Float64(Float64(abs(p) + abs(r)) + sqrt(Float64((Float64(p - r) ^ 2.0) + Float64(4.0 * (q_m ^ 2.0)))))); elseif (q_m <= 4.5e+160) tmp = t_0; else tmp = Float64(fma(Float64(Float64(p / q_m) * Float64(p / q_m)), 0.125, fma(Float64(Float64(r + abs(p)) / q_m), 0.5, 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[(p - N[Abs[p], $MachinePrecision]), $MachinePrecision] * -0.5 + r), $MachinePrecision]}, If[LessEqual[q$95$m, 64000.0], t$95$0, If[LessEqual[q$95$m, 8e+87], N[(N[Power[2.0, -1.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$95$m, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[q$95$m, 4.5e+160], t$95$0, N[(N[(N[(N[(p / q$95$m), $MachinePrecision] * N[(p / q$95$m), $MachinePrecision]), $MachinePrecision] * 0.125 + N[(N[(N[(r + N[Abs[p], $MachinePrecision]), $MachinePrecision] / q$95$m), $MachinePrecision] * 0.5 + 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(p - \left|p\right|, -0.5, r\right)\\
\mathbf{if}\;q\_m \leq 64000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;q\_m \leq 8 \cdot 10^{+87}:\\
\;\;\;\;{2}^{-1} \cdot \left(\left(\left|p\right| + \left|r\right|\right) + \sqrt{{\left(p - r\right)}^{2} + 4 \cdot {q\_m}^{2}}\right)\\
\mathbf{elif}\;q\_m \leq 4.5 \cdot 10^{+160}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{p}{q\_m} \cdot \frac{p}{q\_m}, 0.125, \mathsf{fma}\left(\frac{r + \left|p\right|}{q\_m}, 0.5, 1\right)\right) \cdot q\_m\\
\end{array}
\end{array}
if q < 64000 or 7.9999999999999997e87 < q < 4.4999999999999998e160Initial program 48.2%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6433.9
Applied rewrites33.9%
Taylor expanded in p around 0
Applied rewrites38.0%
Applied rewrites37.5%
Taylor expanded in r around 0
Applied rewrites37.6%
if 64000 < q < 7.9999999999999997e87Initial program 79.1%
if 4.4999999999999998e160 < q Initial program 7.7%
Taylor expanded in r around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-fabs.f64N/A
lower-fabs.f647.7
Applied rewrites7.7%
Applied rewrites7.7%
Taylor expanded in q around inf
Applied rewrites84.5%
Final simplification45.9%
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 (- p (fabs p)) -0.5 r)))
(if (<= q_m 2.7e+18)
t_0
(if (<= q_m 8e+87)
(* (+ (+ (sqrt (fma (* q_m q_m) 4.0 (* p p))) r) (fabs p)) 0.5)
(if (<= q_m 4.5e+160)
t_0
(*
(fma
(* (/ p q_m) (/ p q_m))
0.125
(fma (/ (+ r (fabs p)) q_m) 0.5 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((p - fabs(p)), -0.5, r);
double tmp;
if (q_m <= 2.7e+18) {
tmp = t_0;
} else if (q_m <= 8e+87) {
tmp = ((sqrt(fma((q_m * q_m), 4.0, (p * p))) + r) + fabs(p)) * 0.5;
} else if (q_m <= 4.5e+160) {
tmp = t_0;
} else {
tmp = fma(((p / q_m) * (p / q_m)), 0.125, fma(((r + fabs(p)) / q_m), 0.5, 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(p - abs(p)), -0.5, r) tmp = 0.0 if (q_m <= 2.7e+18) tmp = t_0; elseif (q_m <= 8e+87) tmp = Float64(Float64(Float64(sqrt(fma(Float64(q_m * q_m), 4.0, Float64(p * p))) + r) + abs(p)) * 0.5); elseif (q_m <= 4.5e+160) tmp = t_0; else tmp = Float64(fma(Float64(Float64(p / q_m) * Float64(p / q_m)), 0.125, fma(Float64(Float64(r + abs(p)) / q_m), 0.5, 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[(p - N[Abs[p], $MachinePrecision]), $MachinePrecision] * -0.5 + r), $MachinePrecision]}, If[LessEqual[q$95$m, 2.7e+18], t$95$0, If[LessEqual[q$95$m, 8e+87], N[(N[(N[(N[Sqrt[N[(N[(q$95$m * q$95$m), $MachinePrecision] * 4.0 + N[(p * p), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + r), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 4.5e+160], t$95$0, N[(N[(N[(N[(p / q$95$m), $MachinePrecision] * N[(p / q$95$m), $MachinePrecision]), $MachinePrecision] * 0.125 + N[(N[(N[(r + N[Abs[p], $MachinePrecision]), $MachinePrecision] / q$95$m), $MachinePrecision] * 0.5 + 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(p - \left|p\right|, -0.5, r\right)\\
\mathbf{if}\;q\_m \leq 2.7 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;q\_m \leq 8 \cdot 10^{+87}:\\
\;\;\;\;\left(\left(\sqrt{\mathsf{fma}\left(q\_m \cdot q\_m, 4, p \cdot p\right)} + r\right) + \left|p\right|\right) \cdot 0.5\\
\mathbf{elif}\;q\_m \leq 4.5 \cdot 10^{+160}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{p}{q\_m} \cdot \frac{p}{q\_m}, 0.125, \mathsf{fma}\left(\frac{r + \left|p\right|}{q\_m}, 0.5, 1\right)\right) \cdot q\_m\\
\end{array}
\end{array}
if q < 2.7e18 or 7.9999999999999997e87 < q < 4.4999999999999998e160Initial program 48.5%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6434.0
Applied rewrites34.0%
Taylor expanded in p around 0
Applied rewrites38.0%
Applied rewrites37.5%
Taylor expanded in r around 0
Applied rewrites37.6%
if 2.7e18 < q < 7.9999999999999997e87Initial program 81.2%
Taylor expanded in r around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-fabs.f64N/A
lower-fabs.f6466.7
Applied rewrites66.7%
Applied rewrites61.8%
if 4.4999999999999998e160 < q Initial program 7.7%
Taylor expanded in r around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-fabs.f64N/A
lower-fabs.f647.7
Applied rewrites7.7%
Applied rewrites7.7%
Taylor expanded in q around inf
Applied rewrites84.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 (- p (fabs p)) -0.5 r)))
(if (<= q_m 2.7e+18)
t_0
(if (<= q_m 8e+87)
(* (+ (+ (sqrt (fma (* q_m q_m) 4.0 (* p p))) r) (fabs p)) 0.5)
(if (<= q_m 4.5e+160) t_0 (fma 0.5 (+ r (fabs p)) 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((p - fabs(p)), -0.5, r);
double tmp;
if (q_m <= 2.7e+18) {
tmp = t_0;
} else if (q_m <= 8e+87) {
tmp = ((sqrt(fma((q_m * q_m), 4.0, (p * p))) + r) + fabs(p)) * 0.5;
} else if (q_m <= 4.5e+160) {
tmp = t_0;
} else {
tmp = fma(0.5, (r + fabs(p)), 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(p - abs(p)), -0.5, r) tmp = 0.0 if (q_m <= 2.7e+18) tmp = t_0; elseif (q_m <= 8e+87) tmp = Float64(Float64(Float64(sqrt(fma(Float64(q_m * q_m), 4.0, Float64(p * p))) + r) + abs(p)) * 0.5); elseif (q_m <= 4.5e+160) tmp = t_0; else tmp = fma(0.5, Float64(r + abs(p)), 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[(p - N[Abs[p], $MachinePrecision]), $MachinePrecision] * -0.5 + r), $MachinePrecision]}, If[LessEqual[q$95$m, 2.7e+18], t$95$0, If[LessEqual[q$95$m, 8e+87], N[(N[(N[(N[Sqrt[N[(N[(q$95$m * q$95$m), $MachinePrecision] * 4.0 + N[(p * p), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] + r), $MachinePrecision] + N[Abs[p], $MachinePrecision]), $MachinePrecision] * 0.5), $MachinePrecision], If[LessEqual[q$95$m, 4.5e+160], t$95$0, N[(0.5 * N[(r + N[Abs[p], $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(p - \left|p\right|, -0.5, r\right)\\
\mathbf{if}\;q\_m \leq 2.7 \cdot 10^{+18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;q\_m \leq 8 \cdot 10^{+87}:\\
\;\;\;\;\left(\left(\sqrt{\mathsf{fma}\left(q\_m \cdot q\_m, 4, p \cdot p\right)} + r\right) + \left|p\right|\right) \cdot 0.5\\
\mathbf{elif}\;q\_m \leq 4.5 \cdot 10^{+160}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, r + \left|p\right|, q\_m\right)\\
\end{array}
\end{array}
if q < 2.7e18 or 7.9999999999999997e87 < q < 4.4999999999999998e160Initial program 48.5%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6434.0
Applied rewrites34.0%
Taylor expanded in p around 0
Applied rewrites38.0%
Applied rewrites37.5%
Taylor expanded in r around 0
Applied rewrites37.6%
if 2.7e18 < q < 7.9999999999999997e87Initial program 81.2%
Taylor expanded in r around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-+.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-sqrt.f64N/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-fabs.f64N/A
lower-fabs.f6466.7
Applied rewrites66.7%
Applied rewrites61.8%
if 4.4999999999999998e160 < q Initial program 7.7%
Taylor expanded in q around inf
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6485.3
Applied rewrites85.3%
Taylor expanded in p around 0
Applied rewrites85.3%
Applied rewrites85.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 (+ r (fabs p)))) (if (<= q_m 4.5e+160) (* -0.5 (- (- p t_0) (fabs r))) (fma 0.5 t_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 = r + fabs(p);
double tmp;
if (q_m <= 4.5e+160) {
tmp = -0.5 * ((p - t_0) - fabs(r));
} else {
tmp = fma(0.5, t_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(r + abs(p)) tmp = 0.0 if (q_m <= 4.5e+160) tmp = Float64(-0.5 * Float64(Float64(p - t_0) - abs(r))); else tmp = fma(0.5, t_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[(r + N[Abs[p], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[q$95$m, 4.5e+160], N[(-0.5 * N[(N[(p - t$95$0), $MachinePrecision] - N[Abs[r], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.5 * t$95$0 + 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 := r + \left|p\right|\\
\mathbf{if}\;q\_m \leq 4.5 \cdot 10^{+160}:\\
\;\;\;\;-0.5 \cdot \left(\left(p - t\_0\right) - \left|r\right|\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, t\_0, q\_m\right)\\
\end{array}
\end{array}
if q < 4.4999999999999998e160Initial program 50.7%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6432.9
Applied rewrites32.9%
Taylor expanded in p around 0
Applied rewrites36.6%
Taylor expanded in p around 0
Applied rewrites36.9%
if 4.4999999999999998e160 < q Initial program 7.7%
Taylor expanded in q around inf
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6485.3
Applied rewrites85.3%
Taylor expanded in p around 0
Applied rewrites85.3%
Applied rewrites85.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 (<= p -6.8e+77) (* (- p (fabs p)) -0.5) (if (<= p 3.6e-285) (fma 0.5 r q_m) (fma 0.5 (fabs p) r))))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (p <= -6.8e+77) {
tmp = (p - fabs(p)) * -0.5;
} else if (p <= 3.6e-285) {
tmp = fma(0.5, r, q_m);
} else {
tmp = fma(0.5, fabs(p), 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 (p <= -6.8e+77) tmp = Float64(Float64(p - abs(p)) * -0.5); elseif (p <= 3.6e-285) tmp = fma(0.5, r, q_m); else tmp = fma(0.5, abs(p), 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_] := If[LessEqual[p, -6.8e+77], N[(N[(p - N[Abs[p], $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision], If[LessEqual[p, 3.6e-285], N[(0.5 * r + q$95$m), $MachinePrecision], N[(0.5 * N[Abs[p], $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}\;p \leq -6.8 \cdot 10^{+77}:\\
\;\;\;\;\left(p - \left|p\right|\right) \cdot -0.5\\
\mathbf{elif}\;p \leq 3.6 \cdot 10^{-285}:\\
\;\;\;\;\mathsf{fma}\left(0.5, r, q\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|p\right|, r\right)\\
\end{array}
\end{array}
if p < -6.79999999999999993e77Initial program 30.5%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6484.4
Applied rewrites84.4%
Taylor expanded in p around 0
Applied rewrites84.4%
Applied rewrites84.0%
Taylor expanded in r around 0
Applied rewrites74.9%
if -6.79999999999999993e77 < p < 3.60000000000000004e-285Initial program 57.4%
Taylor expanded in q around inf
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6439.0
Applied rewrites39.0%
Taylor expanded in p around 0
Applied rewrites40.6%
Applied rewrites35.4%
Taylor expanded in p around 0
Applied rewrites35.7%
if 3.60000000000000004e-285 < p Initial program 44.5%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6414.1
Applied rewrites14.1%
Taylor expanded in p around 0
Applied rewrites18.4%
Applied rewrites18.0%
Taylor expanded in p around 0
Applied rewrites24.6%
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 4.5e+160) (fma (- p (fabs p)) -0.5 r) (fma 0.5 (+ r (fabs p)) 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 <= 4.5e+160) {
tmp = fma((p - fabs(p)), -0.5, r);
} else {
tmp = fma(0.5, (r + fabs(p)), 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 <= 4.5e+160) tmp = fma(Float64(p - abs(p)), -0.5, r); else tmp = fma(0.5, Float64(r + abs(p)), 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_] := If[LessEqual[q$95$m, 4.5e+160], N[(N[(p - N[Abs[p], $MachinePrecision]), $MachinePrecision] * -0.5 + r), $MachinePrecision], N[(0.5 * N[(r + N[Abs[p], $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}
\mathbf{if}\;q\_m \leq 4.5 \cdot 10^{+160}:\\
\;\;\;\;\mathsf{fma}\left(p - \left|p\right|, -0.5, r\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, r + \left|p\right|, q\_m\right)\\
\end{array}
\end{array}
if q < 4.4999999999999998e160Initial program 50.7%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6432.9
Applied rewrites32.9%
Taylor expanded in p around 0
Applied rewrites36.6%
Applied rewrites36.1%
Taylor expanded in r around 0
Applied rewrites36.2%
if 4.4999999999999998e160 < q Initial program 7.7%
Taylor expanded in q around inf
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6485.3
Applied rewrites85.3%
Taylor expanded in p around 0
Applied rewrites85.3%
Applied rewrites85.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 4.5e+160) (fma (- p (fabs p)) -0.5 r) (fma 0.5 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 <= 4.5e+160) {
tmp = fma((p - fabs(p)), -0.5, r);
} else {
tmp = fma(0.5, r, 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 <= 4.5e+160) tmp = fma(Float64(p - abs(p)), -0.5, r); else tmp = fma(0.5, r, 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_] := If[LessEqual[q$95$m, 4.5e+160], N[(N[(p - N[Abs[p], $MachinePrecision]), $MachinePrecision] * -0.5 + r), $MachinePrecision], N[(0.5 * r + 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}
\mathbf{if}\;q\_m \leq 4.5 \cdot 10^{+160}:\\
\;\;\;\;\mathsf{fma}\left(p - \left|p\right|, -0.5, r\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, r, q\_m\right)\\
\end{array}
\end{array}
if q < 4.4999999999999998e160Initial program 50.7%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6432.9
Applied rewrites32.9%
Taylor expanded in p around 0
Applied rewrites36.6%
Applied rewrites36.1%
Taylor expanded in r around 0
Applied rewrites36.2%
if 4.4999999999999998e160 < q Initial program 7.7%
Taylor expanded in q around inf
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6485.3
Applied rewrites85.3%
Taylor expanded in p around 0
Applied rewrites85.3%
Applied rewrites84.6%
Taylor expanded in p around 0
Applied rewrites84.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 (if (<= r 6.5e-15) (fma 0.5 r q_m) (fma 0.5 (fabs p) r)))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (r <= 6.5e-15) {
tmp = fma(0.5, r, q_m);
} else {
tmp = fma(0.5, fabs(p), 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 (r <= 6.5e-15) tmp = fma(0.5, r, q_m); else tmp = fma(0.5, abs(p), 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_] := If[LessEqual[r, 6.5e-15], N[(0.5 * r + q$95$m), $MachinePrecision], N[(0.5 * N[Abs[p], $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}\;r \leq 6.5 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(0.5, r, q\_m\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, \left|p\right|, r\right)\\
\end{array}
\end{array}
if r < 6.49999999999999991e-15Initial program 49.6%
Taylor expanded in q around inf
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6428.1
Applied rewrites28.1%
Taylor expanded in p around 0
Applied rewrites30.3%
Applied rewrites23.2%
Taylor expanded in p around 0
Applied rewrites19.9%
if 6.49999999999999991e-15 < r Initial program 33.6%
Taylor expanded in p around -inf
associate-*r*N/A
mul-1-negN/A
lower-*.f64N/A
lower-neg.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
+-commutativeN/A
associate-+r+N/A
lower-+.f64N/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6456.0
Applied rewrites56.0%
Taylor expanded in p around 0
Applied rewrites71.8%
Applied rewrites71.8%
Taylor expanded in p around 0
Applied rewrites63.9%
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 (<= p -2.2e+204) (* -0.5 p) (fma 0.5 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 (p <= -2.2e+204) {
tmp = -0.5 * p;
} else {
tmp = fma(0.5, r, 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 (p <= -2.2e+204) tmp = Float64(-0.5 * p); else tmp = fma(0.5, r, 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_] := If[LessEqual[p, -2.2e+204], N[(-0.5 * p), $MachinePrecision], N[(0.5 * r + 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}
\mathbf{if}\;p \leq -2.2 \cdot 10^{+204}:\\
\;\;\;\;-0.5 \cdot p\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(0.5, r, q\_m\right)\\
\end{array}
\end{array}
if p < -2.20000000000000011e204Initial program 7.9%
Taylor expanded in p around -inf
lower-*.f6417.7
Applied rewrites17.7%
if -2.20000000000000011e204 < p Initial program 49.2%
Taylor expanded in q around inf
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6429.0
Applied rewrites29.0%
Taylor expanded in p around 0
Applied rewrites31.4%
Applied rewrites26.5%
Taylor expanded in p around 0
Applied rewrites23.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 (if (<= p -2.2e+204) (* -0.5 p) q_m))
q_m = fabs(q);
assert(p < r && r < q_m);
double code(double p, double r, double q_m) {
double tmp;
if (p <= -2.2e+204) {
tmp = -0.5 * p;
} 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 (p <= (-2.2d+204)) then
tmp = (-0.5d0) * p
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 (p <= -2.2e+204) {
tmp = -0.5 * p;
} 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 p <= -2.2e+204: tmp = -0.5 * p 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 (p <= -2.2e+204) tmp = Float64(-0.5 * p); else tmp = 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 (p <= -2.2e+204)
tmp = -0.5 * p;
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[p, -2.2e+204], N[(-0.5 * p), $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}\;p \leq -2.2 \cdot 10^{+204}:\\
\;\;\;\;-0.5 \cdot p\\
\mathbf{else}:\\
\;\;\;\;q\_m\\
\end{array}
\end{array}
if p < -2.20000000000000011e204Initial program 7.9%
Taylor expanded in p around -inf
lower-*.f6417.7
Applied rewrites17.7%
if -2.20000000000000011e204 < p Initial program 49.2%
Taylor expanded in q around inf
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6429.0
Applied rewrites29.0%
Taylor expanded in p around 0
Applied rewrites31.4%
Applied rewrites21.8%
Taylor expanded in q around -inf
Applied rewrites20.9%
Final simplification20.6%
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 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 45.8%
Taylor expanded in q around inf
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
*-rgt-identityN/A
lower-fma.f64N/A
lower-*.f64N/A
lower-/.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-fabs.f64N/A
lower-fabs.f6427.9
Applied rewrites27.9%
Taylor expanded in p around 0
Applied rewrites30.3%
Applied rewrites20.0%
Taylor expanded in q around -inf
Applied rewrites19.3%
Final simplification19.3%
herbie shell --seed 2024340
(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)))))))