
(FPCore (p x) :precision binary64 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
double code(double p, double x) {
return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = sqrt((0.5d0 * (1.0d0 + (x / sqrt((((4.0d0 * p) * p) + (x * x)))))))
end function
public static double code(double p, double x) {
return Math.sqrt((0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))))));
}
def code(p, x): return math.sqrt((0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))))
function code(p, x) return sqrt(Float64(0.5 * Float64(1.0 + Float64(x / sqrt(Float64(Float64(Float64(4.0 * p) * p) + Float64(x * x))))))) end
function tmp = code(p, x) tmp = sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x))))))); end
code[p_, x_] := N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (p x) :precision binary64 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
double code(double p, double x) {
return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = sqrt((0.5d0 * (1.0d0 + (x / sqrt((((4.0d0 * p) * p) + (x * x)))))))
end function
public static double code(double p, double x) {
return Math.sqrt((0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))))));
}
def code(p, x): return math.sqrt((0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))))
function code(p, x) return sqrt(Float64(0.5 * Float64(1.0 + Float64(x / sqrt(Float64(Float64(Float64(4.0 * p) * p) + Float64(x * x))))))) end
function tmp = code(p, x) tmp = sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x))))))); end
code[p_, x_] := N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\end{array}
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.5) (- (* (pow (/ p_m x) 3.0) 1.5) (/ p_m x)) (sqrt (+ 0.5 (/ 0.5 (* (hypot x (* p_m 2.0)) (/ 1.0 x)))))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.5) {
tmp = (pow((p_m / x), 3.0) * 1.5) - (p_m / x);
} else {
tmp = sqrt((0.5 + (0.5 / (hypot(x, (p_m * 2.0)) * (1.0 / x)))));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if ((x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.5) {
tmp = (Math.pow((p_m / x), 3.0) * 1.5) - (p_m / x);
} else {
tmp = Math.sqrt((0.5 + (0.5 / (Math.hypot(x, (p_m * 2.0)) * (1.0 / x)))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if (x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.5: tmp = (math.pow((p_m / x), 3.0) * 1.5) - (p_m / x) else: tmp = math.sqrt((0.5 + (0.5 / (math.hypot(x, (p_m * 2.0)) * (1.0 / x))))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.5) tmp = Float64(Float64((Float64(p_m / x) ^ 3.0) * 1.5) - Float64(p_m / x)); else tmp = sqrt(Float64(0.5 + Float64(0.5 / Float64(hypot(x, Float64(p_m * 2.0)) * Float64(1.0 / x))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.5) tmp = (((p_m / x) ^ 3.0) * 1.5) - (p_m / x); else tmp = sqrt((0.5 + (0.5 / (hypot(x, (p_m * 2.0)) * (1.0 / x))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p$95$m * N[(4.0 * p$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.5], N[(N[(N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision] * 1.5), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 / N[(N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision] * N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}} \leq -0.5:\\
\;\;\;\;{\left(\frac{p\_m}{x}\right)}^{3} \cdot 1.5 - \frac{p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right) \cdot \frac{1}{x}}}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.5Initial program 20.6%
+-commutative20.6%
distribute-rgt-in20.6%
Applied egg-rr20.6%
Taylor expanded in x around -inf 44.9%
+-commutative44.9%
mul-1-neg44.9%
unsub-neg44.9%
Simplified54.1%
Taylor expanded in p around 0 54.2%
*-commutative54.2%
cube-div60.3%
Simplified60.3%
if -0.5 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 100.0%
+-commutative100.0%
distribute-rgt-in100.0%
Applied egg-rr100.0%
clear-num100.0%
inv-pow100.0%
Applied egg-rr100.0%
unpow-1100.0%
Simplified100.0%
*-un-lft-identity100.0%
fma-define100.0%
associate-*l/100.0%
metadata-eval100.0%
Applied egg-rr100.0%
fma-undefine100.0%
*-lft-identity100.0%
Simplified100.0%
div-inv100.0%
Applied egg-rr100.0%
Final simplification89.6%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(if (or (<= x -1.5e+75)
(and (not (<= x -1.56e+31))
(or (<= x -1.05e+22)
(and (not (<= x -8.5e-68)) (<= x -7.8e-84)))))
(/ p_m (- x))
(sqrt (+ 0.5 (* 0.5 (/ x (hypot x (* p_m 2.0))))))))p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if ((x <= -1.5e+75) || (!(x <= -1.56e+31) && ((x <= -1.05e+22) || (!(x <= -8.5e-68) && (x <= -7.8e-84))))) {
tmp = p_m / -x;
} else {
tmp = sqrt((0.5 + (0.5 * (x / hypot(x, (p_m * 2.0))))));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if ((x <= -1.5e+75) || (!(x <= -1.56e+31) && ((x <= -1.05e+22) || (!(x <= -8.5e-68) && (x <= -7.8e-84))))) {
tmp = p_m / -x;
} else {
tmp = Math.sqrt((0.5 + (0.5 * (x / Math.hypot(x, (p_m * 2.0))))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if (x <= -1.5e+75) or (not (x <= -1.56e+31) and ((x <= -1.05e+22) or (not (x <= -8.5e-68) and (x <= -7.8e-84)))): tmp = p_m / -x else: tmp = math.sqrt((0.5 + (0.5 * (x / math.hypot(x, (p_m * 2.0)))))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if ((x <= -1.5e+75) || (!(x <= -1.56e+31) && ((x <= -1.05e+22) || (!(x <= -8.5e-68) && (x <= -7.8e-84))))) tmp = Float64(p_m / Float64(-x)); else tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(x / hypot(x, Float64(p_m * 2.0)))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if ((x <= -1.5e+75) || (~((x <= -1.56e+31)) && ((x <= -1.05e+22) || (~((x <= -8.5e-68)) && (x <= -7.8e-84))))) tmp = p_m / -x; else tmp = sqrt((0.5 + (0.5 * (x / hypot(x, (p_m * 2.0)))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[Or[LessEqual[x, -1.5e+75], And[N[Not[LessEqual[x, -1.56e+31]], $MachinePrecision], Or[LessEqual[x, -1.05e+22], And[N[Not[LessEqual[x, -8.5e-68]], $MachinePrecision], LessEqual[x, -7.8e-84]]]]], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 * N[(x / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+75} \lor \neg \left(x \leq -1.56 \cdot 10^{+31}\right) \land \left(x \leq -1.05 \cdot 10^{+22} \lor \neg \left(x \leq -8.5 \cdot 10^{-68}\right) \land x \leq -7.8 \cdot 10^{-84}\right):\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}}\\
\end{array}
\end{array}
if x < -1.5e75 or -1.56000000000000004e31 < x < -1.0499999999999999e22 or -8.50000000000000026e-68 < x < -7.80000000000000045e-84Initial program 36.3%
+-commutative36.3%
sqr-neg36.3%
associate-*l*36.3%
sqr-neg36.3%
fma-define36.3%
sqr-neg36.3%
fma-define36.3%
associate-*l*36.3%
+-commutative36.3%
Simplified36.3%
Taylor expanded in x around -inf 46.2%
mul-1-neg46.2%
distribute-neg-frac246.2%
Simplified46.2%
if -1.5e75 < x < -1.56000000000000004e31 or -1.0499999999999999e22 < x < -8.50000000000000026e-68 or -7.80000000000000045e-84 < x Initial program 87.4%
+-commutative87.4%
distribute-rgt-in87.4%
Applied egg-rr87.4%
Final simplification80.8%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (hypot x (* p_m 2.0)))
(t_1 (/ p_m (- x)))
(t_2 (sqrt (+ 0.5 (* 0.5 (/ x t_0))))))
(if (<= x -1e+75)
t_1
(if (<= x -1.75e+32)
t_2
(if (<= x -2.1e+22)
t_1
(if (<= x -1.05e-67)
t_2
(if (<= x -1.7e-82) t_1 (sqrt (+ 0.5 (/ 0.5 (/ t_0 x)))))))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = hypot(x, (p_m * 2.0));
double t_1 = p_m / -x;
double t_2 = sqrt((0.5 + (0.5 * (x / t_0))));
double tmp;
if (x <= -1e+75) {
tmp = t_1;
} else if (x <= -1.75e+32) {
tmp = t_2;
} else if (x <= -2.1e+22) {
tmp = t_1;
} else if (x <= -1.05e-67) {
tmp = t_2;
} else if (x <= -1.7e-82) {
tmp = t_1;
} else {
tmp = sqrt((0.5 + (0.5 / (t_0 / x))));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = Math.hypot(x, (p_m * 2.0));
double t_1 = p_m / -x;
double t_2 = Math.sqrt((0.5 + (0.5 * (x / t_0))));
double tmp;
if (x <= -1e+75) {
tmp = t_1;
} else if (x <= -1.75e+32) {
tmp = t_2;
} else if (x <= -2.1e+22) {
tmp = t_1;
} else if (x <= -1.05e-67) {
tmp = t_2;
} else if (x <= -1.7e-82) {
tmp = t_1;
} else {
tmp = Math.sqrt((0.5 + (0.5 / (t_0 / x))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = math.hypot(x, (p_m * 2.0)) t_1 = p_m / -x t_2 = math.sqrt((0.5 + (0.5 * (x / t_0)))) tmp = 0 if x <= -1e+75: tmp = t_1 elif x <= -1.75e+32: tmp = t_2 elif x <= -2.1e+22: tmp = t_1 elif x <= -1.05e-67: tmp = t_2 elif x <= -1.7e-82: tmp = t_1 else: tmp = math.sqrt((0.5 + (0.5 / (t_0 / x)))) return tmp
p_m = abs(p) function code(p_m, x) t_0 = hypot(x, Float64(p_m * 2.0)) t_1 = Float64(p_m / Float64(-x)) t_2 = sqrt(Float64(0.5 + Float64(0.5 * Float64(x / t_0)))) tmp = 0.0 if (x <= -1e+75) tmp = t_1; elseif (x <= -1.75e+32) tmp = t_2; elseif (x <= -2.1e+22) tmp = t_1; elseif (x <= -1.05e-67) tmp = t_2; elseif (x <= -1.7e-82) tmp = t_1; else tmp = sqrt(Float64(0.5 + Float64(0.5 / Float64(t_0 / x)))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = hypot(x, (p_m * 2.0)); t_1 = p_m / -x; t_2 = sqrt((0.5 + (0.5 * (x / t_0)))); tmp = 0.0; if (x <= -1e+75) tmp = t_1; elseif (x <= -1.75e+32) tmp = t_2; elseif (x <= -2.1e+22) tmp = t_1; elseif (x <= -1.05e-67) tmp = t_2; elseif (x <= -1.7e-82) tmp = t_1; else tmp = sqrt((0.5 + (0.5 / (t_0 / x)))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[(p$95$m / (-x)), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[N[(0.5 + N[(0.5 * N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[x, -1e+75], t$95$1, If[LessEqual[x, -1.75e+32], t$95$2, If[LessEqual[x, -2.1e+22], t$95$1, If[LessEqual[x, -1.05e-67], t$95$2, If[LessEqual[x, -1.7e-82], t$95$1, N[Sqrt[N[(0.5 + N[(0.5 / N[(t$95$0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, p\_m \cdot 2\right)\\
t_1 := \frac{p\_m}{-x}\\
t_2 := \sqrt{0.5 + 0.5 \cdot \frac{x}{t\_0}}\\
\mathbf{if}\;x \leq -1 \cdot 10^{+75}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -1.75 \cdot 10^{+32}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq -2.1 \cdot 10^{+22}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq -1.05 \cdot 10^{-67}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;x \leq -1.7 \cdot 10^{-82}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\frac{t\_0}{x}}}\\
\end{array}
\end{array}
if x < -9.99999999999999927e74 or -1.75e32 < x < -2.0999999999999998e22 or -1.0500000000000001e-67 < x < -1.69999999999999988e-82Initial program 36.3%
+-commutative36.3%
sqr-neg36.3%
associate-*l*36.3%
sqr-neg36.3%
fma-define36.3%
sqr-neg36.3%
fma-define36.3%
associate-*l*36.3%
+-commutative36.3%
Simplified36.3%
Taylor expanded in x around -inf 46.2%
mul-1-neg46.2%
distribute-neg-frac246.2%
Simplified46.2%
if -9.99999999999999927e74 < x < -1.75e32 or -2.0999999999999998e22 < x < -1.0500000000000001e-67Initial program 70.7%
+-commutative70.7%
distribute-rgt-in70.7%
Applied egg-rr70.7%
if -1.69999999999999988e-82 < x Initial program 92.9%
+-commutative92.9%
distribute-rgt-in92.9%
Applied egg-rr92.9%
clear-num92.9%
inv-pow92.9%
Applied egg-rr92.9%
unpow-192.9%
Simplified92.9%
*-un-lft-identity92.9%
fma-define92.9%
associate-*l/92.9%
metadata-eval92.9%
Applied egg-rr92.9%
fma-undefine92.9%
*-lft-identity92.9%
Simplified92.9%
Final simplification80.8%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(if (<= p_m 1.2e-146)
(/ p_m (- x))
(if (<= p_m 1.1e-112)
(+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))
(if (<= p_m 7.5e-47)
(- (* (pow (/ p_m x) 3.0) 1.5) (/ p_m x))
(sqrt (+ 0.5 (/ 0.5 (+ (* 0.25 (/ x p_m)) (* (/ p_m x) 2.0)))))))))p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (p_m <= 1.2e-146) {
tmp = p_m / -x;
} else if (p_m <= 1.1e-112) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 7.5e-47) {
tmp = (pow((p_m / x), 3.0) * 1.5) - (p_m / x);
} else {
tmp = sqrt((0.5 + (0.5 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0)))));
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: tmp
if (p_m <= 1.2d-146) then
tmp = p_m / -x
else if (p_m <= 1.1d-112) then
tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
else if (p_m <= 7.5d-47) then
tmp = (((p_m / x) ** 3.0d0) * 1.5d0) - (p_m / x)
else
tmp = sqrt((0.5d0 + (0.5d0 / ((0.25d0 * (x / p_m)) + ((p_m / x) * 2.0d0)))))
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (p_m <= 1.2e-146) {
tmp = p_m / -x;
} else if (p_m <= 1.1e-112) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 7.5e-47) {
tmp = (Math.pow((p_m / x), 3.0) * 1.5) - (p_m / x);
} else {
tmp = Math.sqrt((0.5 + (0.5 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0)))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if p_m <= 1.2e-146: tmp = p_m / -x elif p_m <= 1.1e-112: tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))) elif p_m <= 7.5e-47: tmp = (math.pow((p_m / x), 3.0) * 1.5) - (p_m / x) else: tmp = math.sqrt((0.5 + (0.5 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0))))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (p_m <= 1.2e-146) tmp = Float64(p_m / Float64(-x)); elseif (p_m <= 1.1e-112) tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x)))); elseif (p_m <= 7.5e-47) tmp = Float64(Float64((Float64(p_m / x) ^ 3.0) * 1.5) - Float64(p_m / x)); else tmp = sqrt(Float64(0.5 + Float64(0.5 / Float64(Float64(0.25 * Float64(x / p_m)) + Float64(Float64(p_m / x) * 2.0))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (p_m <= 1.2e-146) tmp = p_m / -x; elseif (p_m <= 1.1e-112) tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))); elseif (p_m <= 7.5e-47) tmp = (((p_m / x) ^ 3.0) * 1.5) - (p_m / x); else tmp = sqrt((0.5 + (0.5 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[p$95$m, 1.2e-146], N[(p$95$m / (-x)), $MachinePrecision], If[LessEqual[p$95$m, 1.1e-112], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 7.5e-47], N[(N[(N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision] * 1.5), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 / N[(N[(0.25 * N[(x / p$95$m), $MachinePrecision]), $MachinePrecision] + N[(N[(p$95$m / x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 1.2 \cdot 10^{-146}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{elif}\;p\_m \leq 1.1 \cdot 10^{-112}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\
\mathbf{elif}\;p\_m \leq 7.5 \cdot 10^{-47}:\\
\;\;\;\;{\left(\frac{p\_m}{x}\right)}^{3} \cdot 1.5 - \frac{p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{0.25 \cdot \frac{x}{p\_m} + \frac{p\_m}{x} \cdot 2}}\\
\end{array}
\end{array}
if p < 1.2000000000000001e-146Initial program 76.9%
+-commutative76.9%
sqr-neg76.9%
associate-*l*76.9%
sqr-neg76.9%
fma-define76.9%
sqr-neg76.9%
fma-define76.9%
associate-*l*76.9%
+-commutative76.9%
Simplified76.9%
Taylor expanded in x around -inf 17.7%
mul-1-neg17.7%
distribute-neg-frac217.7%
Simplified17.7%
if 1.2000000000000001e-146 < p < 1.10000000000000011e-112Initial program 80.4%
+-commutative80.4%
sqr-neg80.4%
associate-*l*80.4%
sqr-neg80.4%
fma-define80.4%
sqr-neg80.4%
fma-define80.4%
associate-*l*80.4%
+-commutative80.4%
Simplified80.7%
Taylor expanded in x around inf 74.7%
*-commutative74.7%
Simplified74.7%
unpow274.7%
unpow274.7%
times-frac74.7%
Applied egg-rr74.7%
if 1.10000000000000011e-112 < p < 7.49999999999999969e-47Initial program 49.0%
+-commutative49.0%
distribute-rgt-in49.0%
Applied egg-rr49.0%
Taylor expanded in x around -inf 54.0%
+-commutative54.0%
mul-1-neg54.0%
unsub-neg54.0%
Simplified54.1%
Taylor expanded in p around 0 54.3%
*-commutative54.3%
cube-div54.6%
Simplified54.6%
if 7.49999999999999969e-47 < p Initial program 92.5%
+-commutative92.5%
distribute-rgt-in92.5%
Applied egg-rr92.5%
clear-num92.5%
inv-pow92.5%
Applied egg-rr92.5%
unpow-192.5%
Simplified92.5%
*-un-lft-identity92.5%
fma-define92.5%
associate-*l/92.5%
metadata-eval92.5%
Applied egg-rr92.5%
fma-undefine92.5%
*-lft-identity92.5%
Simplified92.5%
Taylor expanded in x around 0 87.3%
Final simplification38.4%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(if (<= p_m 2.7e-149)
(/ p_m (- x))
(if (<= p_m 6.8e-113)
(+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))
(if (<= p_m 1.12e-35)
(- (* (pow (/ p_m x) 3.0) 1.5) (/ p_m x))
(sqrt (+ 0.5 (* 0.25 (/ x p_m))))))))p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (p_m <= 2.7e-149) {
tmp = p_m / -x;
} else if (p_m <= 6.8e-113) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 1.12e-35) {
tmp = (pow((p_m / x), 3.0) * 1.5) - (p_m / x);
} else {
tmp = sqrt((0.5 + (0.25 * (x / p_m))));
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: tmp
if (p_m <= 2.7d-149) then
tmp = p_m / -x
else if (p_m <= 6.8d-113) then
tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
else if (p_m <= 1.12d-35) then
tmp = (((p_m / x) ** 3.0d0) * 1.5d0) - (p_m / x)
else
tmp = sqrt((0.5d0 + (0.25d0 * (x / p_m))))
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (p_m <= 2.7e-149) {
tmp = p_m / -x;
} else if (p_m <= 6.8e-113) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 1.12e-35) {
tmp = (Math.pow((p_m / x), 3.0) * 1.5) - (p_m / x);
} else {
tmp = Math.sqrt((0.5 + (0.25 * (x / p_m))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if p_m <= 2.7e-149: tmp = p_m / -x elif p_m <= 6.8e-113: tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))) elif p_m <= 1.12e-35: tmp = (math.pow((p_m / x), 3.0) * 1.5) - (p_m / x) else: tmp = math.sqrt((0.5 + (0.25 * (x / p_m)))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (p_m <= 2.7e-149) tmp = Float64(p_m / Float64(-x)); elseif (p_m <= 6.8e-113) tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x)))); elseif (p_m <= 1.12e-35) tmp = Float64(Float64((Float64(p_m / x) ^ 3.0) * 1.5) - Float64(p_m / x)); else tmp = sqrt(Float64(0.5 + Float64(0.25 * Float64(x / p_m)))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (p_m <= 2.7e-149) tmp = p_m / -x; elseif (p_m <= 6.8e-113) tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))); elseif (p_m <= 1.12e-35) tmp = (((p_m / x) ^ 3.0) * 1.5) - (p_m / x); else tmp = sqrt((0.5 + (0.25 * (x / p_m)))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[p$95$m, 2.7e-149], N[(p$95$m / (-x)), $MachinePrecision], If[LessEqual[p$95$m, 6.8e-113], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 1.12e-35], N[(N[(N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision] * 1.5), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.25 * N[(x / p$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 2.7 \cdot 10^{-149}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{elif}\;p\_m \leq 6.8 \cdot 10^{-113}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\
\mathbf{elif}\;p\_m \leq 1.12 \cdot 10^{-35}:\\
\;\;\;\;{\left(\frac{p\_m}{x}\right)}^{3} \cdot 1.5 - \frac{p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p\_m}}\\
\end{array}
\end{array}
if p < 2.70000000000000014e-149Initial program 76.9%
+-commutative76.9%
sqr-neg76.9%
associate-*l*76.9%
sqr-neg76.9%
fma-define76.9%
sqr-neg76.9%
fma-define76.9%
associate-*l*76.9%
+-commutative76.9%
Simplified76.9%
Taylor expanded in x around -inf 17.7%
mul-1-neg17.7%
distribute-neg-frac217.7%
Simplified17.7%
if 2.70000000000000014e-149 < p < 6.8000000000000005e-113Initial program 80.4%
+-commutative80.4%
sqr-neg80.4%
associate-*l*80.4%
sqr-neg80.4%
fma-define80.4%
sqr-neg80.4%
fma-define80.4%
associate-*l*80.4%
+-commutative80.4%
Simplified80.7%
Taylor expanded in x around inf 74.7%
*-commutative74.7%
Simplified74.7%
unpow274.7%
unpow274.7%
times-frac74.7%
Applied egg-rr74.7%
if 6.8000000000000005e-113 < p < 1.12e-35Initial program 46.2%
+-commutative46.2%
distribute-rgt-in46.2%
Applied egg-rr46.2%
Taylor expanded in x around -inf 56.9%
+-commutative56.9%
mul-1-neg56.9%
unsub-neg56.9%
Simplified57.0%
Taylor expanded in p around 0 57.2%
*-commutative57.2%
cube-div57.5%
Simplified57.5%
if 1.12e-35 < p Initial program 93.9%
Taylor expanded in x around 0 86.7%
Final simplification38.3%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))))
(if (<= p_m 4.2e-146)
t_0
(if (<= p_m 9.8e-113)
(+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))
(if (<= p_m 1.12e-35) t_0 (sqrt (+ 0.5 (* 0.25 (/ x p_m)))))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = p_m / -x;
double tmp;
if (p_m <= 4.2e-146) {
tmp = t_0;
} else if (p_m <= 9.8e-113) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 1.12e-35) {
tmp = t_0;
} else {
tmp = sqrt((0.5 + (0.25 * (x / p_m))));
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = p_m / -x
if (p_m <= 4.2d-146) then
tmp = t_0
else if (p_m <= 9.8d-113) then
tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
else if (p_m <= 1.12d-35) then
tmp = t_0
else
tmp = sqrt((0.5d0 + (0.25d0 * (x / p_m))))
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = p_m / -x;
double tmp;
if (p_m <= 4.2e-146) {
tmp = t_0;
} else if (p_m <= 9.8e-113) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 1.12e-35) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 + (0.25 * (x / p_m))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = p_m / -x tmp = 0 if p_m <= 4.2e-146: tmp = t_0 elif p_m <= 9.8e-113: tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))) elif p_m <= 1.12e-35: tmp = t_0 else: tmp = math.sqrt((0.5 + (0.25 * (x / p_m)))) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(p_m / Float64(-x)) tmp = 0.0 if (p_m <= 4.2e-146) tmp = t_0; elseif (p_m <= 9.8e-113) tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x)))); elseif (p_m <= 1.12e-35) tmp = t_0; else tmp = sqrt(Float64(0.5 + Float64(0.25 * Float64(x / p_m)))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = p_m / -x; tmp = 0.0; if (p_m <= 4.2e-146) tmp = t_0; elseif (p_m <= 9.8e-113) tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))); elseif (p_m <= 1.12e-35) tmp = t_0; else tmp = sqrt((0.5 + (0.25 * (x / p_m)))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[(p$95$m / (-x)), $MachinePrecision]}, If[LessEqual[p$95$m, 4.2e-146], t$95$0, If[LessEqual[p$95$m, 9.8e-113], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 1.12e-35], t$95$0, N[Sqrt[N[(0.5 + N[(0.25 * N[(x / p$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \frac{p\_m}{-x}\\
\mathbf{if}\;p\_m \leq 4.2 \cdot 10^{-146}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 9.8 \cdot 10^{-113}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\
\mathbf{elif}\;p\_m \leq 1.12 \cdot 10^{-35}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p\_m}}\\
\end{array}
\end{array}
if p < 4.1999999999999998e-146 or 9.8000000000000006e-113 < p < 1.12e-35Initial program 74.3%
+-commutative74.3%
sqr-neg74.3%
associate-*l*74.3%
sqr-neg74.3%
fma-define74.3%
sqr-neg74.3%
fma-define74.3%
associate-*l*74.3%
+-commutative74.3%
Simplified74.3%
Taylor expanded in x around -inf 21.1%
mul-1-neg21.1%
distribute-neg-frac221.1%
Simplified21.1%
if 4.1999999999999998e-146 < p < 9.8000000000000006e-113Initial program 80.4%
+-commutative80.4%
sqr-neg80.4%
associate-*l*80.4%
sqr-neg80.4%
fma-define80.4%
sqr-neg80.4%
fma-define80.4%
associate-*l*80.4%
+-commutative80.4%
Simplified80.7%
Taylor expanded in x around inf 74.7%
*-commutative74.7%
Simplified74.7%
unpow274.7%
unpow274.7%
times-frac74.7%
Applied egg-rr74.7%
if 1.12e-35 < p Initial program 93.9%
Taylor expanded in x around 0 86.7%
Final simplification38.3%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))))
(if (<= p_m 6.8e-147)
t_0
(if (<= p_m 1.35e-112)
(+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))
(if (<= p_m 3.8e-47) t_0 (sqrt 0.5))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = p_m / -x;
double tmp;
if (p_m <= 6.8e-147) {
tmp = t_0;
} else if (p_m <= 1.35e-112) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 3.8e-47) {
tmp = t_0;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = p_m / -x
if (p_m <= 6.8d-147) then
tmp = t_0
else if (p_m <= 1.35d-112) then
tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
else if (p_m <= 3.8d-47) then
tmp = t_0
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = p_m / -x;
double tmp;
if (p_m <= 6.8e-147) {
tmp = t_0;
} else if (p_m <= 1.35e-112) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 3.8e-47) {
tmp = t_0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = p_m / -x tmp = 0 if p_m <= 6.8e-147: tmp = t_0 elif p_m <= 1.35e-112: tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))) elif p_m <= 3.8e-47: tmp = t_0 else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(p_m / Float64(-x)) tmp = 0.0 if (p_m <= 6.8e-147) tmp = t_0; elseif (p_m <= 1.35e-112) tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x)))); elseif (p_m <= 3.8e-47) tmp = t_0; else tmp = sqrt(0.5); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = p_m / -x; tmp = 0.0; if (p_m <= 6.8e-147) tmp = t_0; elseif (p_m <= 1.35e-112) tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))); elseif (p_m <= 3.8e-47) tmp = t_0; else tmp = sqrt(0.5); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[(p$95$m / (-x)), $MachinePrecision]}, If[LessEqual[p$95$m, 6.8e-147], t$95$0, If[LessEqual[p$95$m, 1.35e-112], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 3.8e-47], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \frac{p\_m}{-x}\\
\mathbf{if}\;p\_m \leq 6.8 \cdot 10^{-147}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 1.35 \cdot 10^{-112}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\
\mathbf{elif}\;p\_m \leq 3.8 \cdot 10^{-47}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 6.79999999999999991e-147 or 1.35e-112 < p < 3.80000000000000015e-47Initial program 74.6%
+-commutative74.6%
sqr-neg74.6%
associate-*l*74.6%
sqr-neg74.6%
fma-define74.6%
sqr-neg74.6%
fma-define74.6%
associate-*l*74.6%
+-commutative74.6%
Simplified74.6%
Taylor expanded in x around -inf 20.6%
mul-1-neg20.6%
distribute-neg-frac220.6%
Simplified20.6%
if 6.79999999999999991e-147 < p < 1.35e-112Initial program 80.4%
+-commutative80.4%
sqr-neg80.4%
associate-*l*80.4%
sqr-neg80.4%
fma-define80.4%
sqr-neg80.4%
fma-define80.4%
associate-*l*80.4%
+-commutative80.4%
Simplified80.7%
Taylor expanded in x around inf 74.7%
*-commutative74.7%
Simplified74.7%
unpow274.7%
unpow274.7%
times-frac74.7%
Applied egg-rr74.7%
if 3.80000000000000015e-47 < p Initial program 92.5%
Taylor expanded in x around 0 84.6%
Final simplification37.7%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x 3e-149) (/ p_m (- x)) (+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= 3e-149) {
tmp = p_m / -x;
} else {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 3d-149) then
tmp = p_m / -x
else
tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= 3e-149) {
tmp = p_m / -x;
} else {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= 3e-149: tmp = p_m / -x else: tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= 3e-149) tmp = Float64(p_m / Float64(-x)); else tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x)))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= 3e-149) tmp = p_m / -x; else tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, 3e-149], N[(p$95$m / (-x)), $MachinePrecision], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 3 \cdot 10^{-149}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\
\end{array}
\end{array}
if x < 3.0000000000000002e-149Initial program 58.5%
+-commutative58.5%
sqr-neg58.5%
associate-*l*58.5%
sqr-neg58.5%
fma-define58.5%
sqr-neg58.5%
fma-define58.5%
associate-*l*58.5%
+-commutative58.5%
Simplified58.5%
Taylor expanded in x around -inf 33.0%
mul-1-neg33.0%
distribute-neg-frac233.0%
Simplified33.0%
if 3.0000000000000002e-149 < x Initial program 100.0%
+-commutative100.0%
sqr-neg100.0%
associate-*l*100.0%
sqr-neg100.0%
fma-define100.0%
sqr-neg100.0%
fma-define100.0%
associate-*l*100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 47.7%
*-commutative47.7%
Simplified47.7%
unpow247.7%
unpow247.7%
times-frac47.7%
Applied egg-rr47.7%
Final simplification40.3%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (/ p_m (- x)))
p_m = fabs(p);
double code(double p_m, double x) {
return p_m / -x;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
code = p_m / -x
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
return p_m / -x;
}
p_m = math.fabs(p) def code(p_m, x): return p_m / -x
p_m = abs(p) function code(p_m, x) return Float64(p_m / Float64(-x)) end
p_m = abs(p); function tmp = code(p_m, x) tmp = p_m / -x; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := N[(p$95$m / (-x)), $MachinePrecision]
\begin{array}{l}
p_m = \left|p\right|
\\
\frac{p\_m}{-x}
\end{array}
Initial program 79.2%
+-commutative79.2%
sqr-neg79.2%
associate-*l*79.2%
sqr-neg79.2%
fma-define79.2%
sqr-neg79.2%
fma-define79.2%
associate-*l*79.2%
+-commutative79.2%
Simplified79.2%
Taylor expanded in x around -inf 18.1%
mul-1-neg18.1%
distribute-neg-frac218.1%
Simplified18.1%
Final simplification18.1%
(FPCore (p x) :precision binary64 (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x))))))
double code(double p, double x) {
return sqrt((0.5 + (copysign(0.5, x) / hypot(1.0, ((2.0 * p) / x)))));
}
public static double code(double p, double x) {
return Math.sqrt((0.5 + (Math.copySign(0.5, x) / Math.hypot(1.0, ((2.0 * p) / x)))));
}
def code(p, x): return math.sqrt((0.5 + (math.copysign(0.5, x) / math.hypot(1.0, ((2.0 * p) / x)))))
function code(p, x) return sqrt(Float64(0.5 + Float64(copysign(0.5, x) / hypot(1.0, Float64(Float64(2.0 * p) / x))))) end
function tmp = code(p, x) tmp = sqrt((0.5 + ((sign(x) * abs(0.5)) / hypot(1.0, ((2.0 * p) / x))))); end
code[p_, x_] := N[Sqrt[N[(0.5 + N[(N[With[{TMP1 = Abs[0.5], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] / N[Sqrt[1.0 ^ 2 + N[(N[(2.0 * p), $MachinePrecision] / x), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 + \frac{\mathsf{copysign}\left(0.5, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}
\end{array}
herbie shell --seed 2024043
(FPCore (p x)
:name "Given's Rotation SVD example"
:precision binary64
:pre (and (< 1e-150 (fabs x)) (< (fabs x) 1e+150))
:alt
(sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x)))))
(sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))