
(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 7 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.98) (/ (- (* 1.5 (/ (pow p_m 3.0) (pow x 2.0))) p_m) x) (sqrt (fma x (/ 0.5 (hypot x (* p_m 2.0))) 0.5))))
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.98) {
tmp = ((1.5 * (pow(p_m, 3.0) / pow(x, 2.0))) - p_m) / x;
} else {
tmp = sqrt(fma(x, (0.5 / hypot(x, (p_m * 2.0))), 0.5));
}
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.98) tmp = Float64(Float64(Float64(1.5 * Float64((p_m ^ 3.0) / (x ^ 2.0))) - p_m) / x); else tmp = sqrt(fma(x, Float64(0.5 / hypot(x, Float64(p_m * 2.0))), 0.5)); end return 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.98], N[(N[(N[(1.5 * N[(N[Power[p$95$m, 3.0], $MachinePrecision] / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - p$95$m), $MachinePrecision] / x), $MachinePrecision], N[Sqrt[N[(x * N[(0.5 / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + 0.5), $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.98:\\
\;\;\;\;\frac{1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}} - p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(x, \frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}, 0.5\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) < -0.97999999999999998Initial program 14.4%
add-sqr-sqrt14.4%
pow214.4%
Applied egg-rr14.4%
Taylor expanded in x around -inf 49.1%
mul-1-neg49.1%
distribute-neg-frac249.1%
associate-*r/49.1%
distribute-rgt-out49.2%
metadata-eval49.2%
*-commutative49.2%
associate-*r*49.2%
metadata-eval49.2%
Simplified49.2%
Taylor expanded in x around inf 59.4%
+-commutative59.4%
mul-1-neg59.4%
unsub-neg59.4%
Simplified59.4%
if -0.97999999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 100.0%
add-sqr-sqrt98.9%
pow298.9%
Applied egg-rr98.9%
*-un-lft-identity98.9%
pow-pow100.0%
metadata-eval100.0%
pow1/2100.0%
Applied egg-rr100.0%
*-lft-identity100.0%
fma-undefine100.0%
associate-*l/100.0%
associate-/l*100.0%
fma-define100.0%
*-commutative100.0%
Simplified100.0%
Final simplification90.5%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.98) (/ (- (* 1.5 (/ (pow p_m 3.0) (pow x 2.0))) p_m) x) (sqrt (* 0.5 (+ -1.0 (+ 2.0 (/ x (hypot x (* p_m 2.0)))))))))
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.98) {
tmp = ((1.5 * (pow(p_m, 3.0) / pow(x, 2.0))) - p_m) / x;
} else {
tmp = sqrt((0.5 * (-1.0 + (2.0 + (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 / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.98) {
tmp = ((1.5 * (Math.pow(p_m, 3.0) / Math.pow(x, 2.0))) - p_m) / x;
} else {
tmp = Math.sqrt((0.5 * (-1.0 + (2.0 + (x / Math.hypot(x, (p_m * 2.0)))))));
}
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.98: tmp = ((1.5 * (math.pow(p_m, 3.0) / math.pow(x, 2.0))) - p_m) / x else: tmp = math.sqrt((0.5 * (-1.0 + (2.0 + (x / math.hypot(x, (p_m * 2.0))))))) 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.98) tmp = Float64(Float64(Float64(1.5 * Float64((p_m ^ 3.0) / (x ^ 2.0))) - p_m) / x); else tmp = sqrt(Float64(0.5 * Float64(-1.0 + Float64(2.0 + 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 / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.98) tmp = ((1.5 * ((p_m ^ 3.0) / (x ^ 2.0))) - p_m) / x; else tmp = sqrt((0.5 * (-1.0 + (2.0 + (x / hypot(x, (p_m * 2.0))))))); 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.98], N[(N[(N[(1.5 * N[(N[Power[p$95$m, 3.0], $MachinePrecision] / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - p$95$m), $MachinePrecision] / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(-1.0 + N[(2.0 + N[(x / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $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.98:\\
\;\;\;\;\frac{1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}} - p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(-1 + \left(2 + \frac{x}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}\right)\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) < -0.97999999999999998Initial program 14.4%
add-sqr-sqrt14.4%
pow214.4%
Applied egg-rr14.4%
Taylor expanded in x around -inf 49.1%
mul-1-neg49.1%
distribute-neg-frac249.1%
associate-*r/49.1%
distribute-rgt-out49.2%
metadata-eval49.2%
*-commutative49.2%
associate-*r*49.2%
metadata-eval49.2%
Simplified49.2%
Taylor expanded in x around inf 59.4%
+-commutative59.4%
mul-1-neg59.4%
unsub-neg59.4%
Simplified59.4%
if -0.97999999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 100.0%
expm1-log1p-u99.5%
expm1-undefine99.5%
+-commutative99.5%
add-sqr-sqrt99.5%
hypot-define99.5%
associate-*l*99.5%
sqrt-prod99.5%
metadata-eval99.5%
sqrt-unprod44.6%
add-sqr-sqrt99.5%
Applied egg-rr99.5%
sub-neg99.5%
metadata-eval99.5%
+-commutative99.5%
log1p-undefine100.0%
rem-exp-log100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification90.5%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -1.25e+27) (/ p_m (- x)) (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p_m 2.0) x)))))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -1.25e+27) {
tmp = p_m / -x;
} else {
tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.0), x)))));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= -1.25e+27) {
tmp = p_m / -x;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p_m * 2.0), x)))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -1.25e+27: tmp = p_m / -x else: tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p_m * 2.0), x))))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -1.25e+27) tmp = Float64(p_m / Float64(-x)); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p_m * 2.0), x))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -1.25e+27) tmp = p_m / -x; else tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.0), x))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -1.25e+27], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(p$95$m * 2.0), $MachinePrecision] ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+27}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p\_m \cdot 2, x\right)}\right)}\\
\end{array}
\end{array}
if x < -1.24999999999999995e27Initial program 44.8%
add-sqr-sqrt44.4%
pow244.4%
Applied egg-rr44.4%
Taylor expanded in x around -inf 43.4%
mul-1-neg43.4%
distribute-neg-frac243.4%
Simplified43.4%
if -1.24999999999999995e27 < x Initial program 88.5%
add-sqr-sqrt88.5%
hypot-define88.5%
associate-*l*88.5%
sqrt-prod88.5%
metadata-eval88.5%
sqrt-unprod39.7%
add-sqr-sqrt88.5%
Applied egg-rr88.5%
Final simplification79.7%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (+ 1.0 (* (* (/ p_m x) (/ p_m x)) -0.5))))
(if (<= p_m 6.2e-210)
t_0
(if (<= p_m 1.6e-133)
(/ p_m (- x))
(if (<= p_m 6.5e-71) t_0 (sqrt 0.5))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
double tmp;
if (p_m <= 6.2e-210) {
tmp = t_0;
} else if (p_m <= 1.6e-133) {
tmp = p_m / -x;
} else if (p_m <= 6.5e-71) {
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 = 1.0d0 + (((p_m / x) * (p_m / x)) * (-0.5d0))
if (p_m <= 6.2d-210) then
tmp = t_0
else if (p_m <= 1.6d-133) then
tmp = p_m / -x
else if (p_m <= 6.5d-71) 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 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
double tmp;
if (p_m <= 6.2e-210) {
tmp = t_0;
} else if (p_m <= 1.6e-133) {
tmp = p_m / -x;
} else if (p_m <= 6.5e-71) {
tmp = t_0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5) tmp = 0 if p_m <= 6.2e-210: tmp = t_0 elif p_m <= 1.6e-133: tmp = p_m / -x elif p_m <= 6.5e-71: tmp = t_0 else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(1.0 + Float64(Float64(Float64(p_m / x) * Float64(p_m / x)) * -0.5)) tmp = 0.0 if (p_m <= 6.2e-210) tmp = t_0; elseif (p_m <= 1.6e-133) tmp = Float64(p_m / Float64(-x)); elseif (p_m <= 6.5e-71) 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 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5); tmp = 0.0; if (p_m <= 6.2e-210) tmp = t_0; elseif (p_m <= 1.6e-133) tmp = p_m / -x; elseif (p_m <= 6.5e-71) 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[(1.0 + N[(N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p$95$m, 6.2e-210], t$95$0, If[LessEqual[p$95$m, 1.6e-133], N[(p$95$m / (-x)), $MachinePrecision], If[LessEqual[p$95$m, 6.5e-71], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := 1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\
\mathbf{if}\;p\_m \leq 6.2 \cdot 10^{-210}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 1.6 \cdot 10^{-133}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{elif}\;p\_m \leq 6.5 \cdot 10^{-71}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 6.19999999999999973e-210 or 1.60000000000000006e-133 < p < 6.50000000000000005e-71Initial program 79.3%
add-sqr-sqrt78.6%
pow278.6%
Applied egg-rr78.6%
Taylor expanded in x around inf 30.2%
*-commutative30.2%
Simplified30.2%
unpow230.2%
unpow230.2%
times-frac30.2%
Applied egg-rr30.2%
if 6.19999999999999973e-210 < p < 1.60000000000000006e-133Initial program 49.7%
add-sqr-sqrt49.7%
pow249.7%
Applied egg-rr49.7%
Taylor expanded in x around -inf 58.7%
mul-1-neg58.7%
distribute-neg-frac258.7%
Simplified58.7%
if 6.50000000000000005e-71 < p Initial program 89.8%
Taylor expanded in x around 0 79.2%
Final simplification45.5%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= p_m 5e-210) (+ 1.0 (* (* (/ p_m x) (/ p_m x)) -0.5)) (if (<= p_m 1.55e-133) (/ p_m (- x)) (if (<= p_m 7.8e-71) 1.0 (sqrt 0.5)))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (p_m <= 5e-210) {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
} else if (p_m <= 1.55e-133) {
tmp = p_m / -x;
} else if (p_m <= 7.8e-71) {
tmp = 1.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) :: tmp
if (p_m <= 5d-210) then
tmp = 1.0d0 + (((p_m / x) * (p_m / x)) * (-0.5d0))
else if (p_m <= 1.55d-133) then
tmp = p_m / -x
else if (p_m <= 7.8d-71) then
tmp = 1.0d0
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 tmp;
if (p_m <= 5e-210) {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
} else if (p_m <= 1.55e-133) {
tmp = p_m / -x;
} else if (p_m <= 7.8e-71) {
tmp = 1.0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if p_m <= 5e-210: tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5) elif p_m <= 1.55e-133: tmp = p_m / -x elif p_m <= 7.8e-71: tmp = 1.0 else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (p_m <= 5e-210) tmp = Float64(1.0 + Float64(Float64(Float64(p_m / x) * Float64(p_m / x)) * -0.5)); elseif (p_m <= 1.55e-133) tmp = Float64(p_m / Float64(-x)); elseif (p_m <= 7.8e-71) tmp = 1.0; else tmp = sqrt(0.5); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (p_m <= 5e-210) tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5); elseif (p_m <= 1.55e-133) tmp = p_m / -x; elseif (p_m <= 7.8e-71) tmp = 1.0; else tmp = sqrt(0.5); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[p$95$m, 5e-210], N[(1.0 + N[(N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 1.55e-133], N[(p$95$m / (-x)), $MachinePrecision], If[LessEqual[p$95$m, 7.8e-71], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 5 \cdot 10^{-210}:\\
\;\;\;\;1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\
\mathbf{elif}\;p\_m \leq 1.55 \cdot 10^{-133}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{elif}\;p\_m \leq 7.8 \cdot 10^{-71}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 5.0000000000000002e-210Initial program 79.2%
add-sqr-sqrt78.5%
pow278.5%
Applied egg-rr78.5%
Taylor expanded in x around inf 26.3%
*-commutative26.3%
Simplified26.3%
unpow226.3%
unpow226.3%
times-frac26.3%
Applied egg-rr26.3%
if 5.0000000000000002e-210 < p < 1.55000000000000008e-133Initial program 49.7%
add-sqr-sqrt49.7%
pow249.7%
Applied egg-rr49.7%
Taylor expanded in x around -inf 58.7%
mul-1-neg58.7%
distribute-neg-frac258.7%
Simplified58.7%
if 1.55000000000000008e-133 < p < 7.8000000000000004e-71Initial program 79.6%
add-sqr-sqrt79.5%
pow279.5%
Applied egg-rr79.5%
*-un-lft-identity79.5%
pow-pow79.6%
metadata-eval79.6%
pow1/279.6%
Applied egg-rr79.6%
*-lft-identity79.6%
fma-undefine79.6%
associate-*l/79.6%
associate-/l*79.7%
fma-define79.0%
*-commutative79.0%
Simplified79.0%
Taylor expanded in x around inf 73.9%
if 7.8000000000000004e-71 < p Initial program 89.8%
Taylor expanded in x around 0 79.2%
Final simplification45.6%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x 1.55e-150) (/ p_m (- x)) (+ 1.0 (* (* (/ p_m x) (/ p_m x)) -0.5))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= 1.55e-150) {
tmp = p_m / -x;
} else {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -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) :: tmp
if (x <= 1.55d-150) then
tmp = p_m / -x
else
tmp = 1.0d0 + (((p_m / x) * (p_m / x)) * (-0.5d0))
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= 1.55e-150) {
tmp = p_m / -x;
} else {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= 1.55e-150: tmp = p_m / -x else: tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= 1.55e-150) tmp = Float64(p_m / Float64(-x)); else tmp = Float64(1.0 + Float64(Float64(Float64(p_m / x) * Float64(p_m / x)) * -0.5)); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= 1.55e-150) tmp = p_m / -x; else tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, 1.55e-150], N[(p$95$m / (-x)), $MachinePrecision], N[(1.0 + N[(N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.55 \cdot 10^{-150}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\
\end{array}
\end{array}
if x < 1.54999999999999999e-150Initial program 63.0%
add-sqr-sqrt62.2%
pow262.2%
Applied egg-rr62.2%
Taylor expanded in x around -inf 27.2%
mul-1-neg27.2%
distribute-neg-frac227.2%
Simplified27.2%
if 1.54999999999999999e-150 < x Initial program 100.0%
add-sqr-sqrt99.3%
pow299.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 53.3%
*-commutative53.3%
Simplified53.3%
unpow253.3%
unpow253.3%
times-frac53.4%
Applied egg-rr53.4%
Final simplification39.1%
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.9%
add-sqr-sqrt79.1%
pow279.1%
Applied egg-rr79.1%
Taylor expanded in x around -inf 16.3%
mul-1-neg16.3%
distribute-neg-frac216.3%
Simplified16.3%
Final simplification16.3%
(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 2024072
(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))))))))