
(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.9995) (/ p_m (- x)) (sqrt (fma (/ 0.5 (hypot x (* p_m 2.0))) x 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.9995) {
tmp = p_m / -x;
} else {
tmp = sqrt(fma((0.5 / hypot(x, (p_m * 2.0))), x, 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.9995) tmp = Float64(p_m / Float64(-x)); else tmp = sqrt(fma(Float64(0.5 / hypot(x, Float64(p_m * 2.0))), x, 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.9995], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[N[(N[(0.5 / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * x + 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.9995:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{\mathsf{fma}\left(\frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}, x, 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.99950000000000006Initial program 10.0%
expm1-log1p-u10.0%
expm1-undefine10.0%
+-commutative10.0%
add-sqr-sqrt10.0%
hypot-define10.0%
associate-*l*10.0%
sqrt-prod10.0%
metadata-eval10.0%
sqrt-unprod5.5%
add-sqr-sqrt10.0%
Applied egg-rr10.0%
sub-neg10.0%
metadata-eval10.0%
+-commutative10.0%
log1p-undefine10.0%
rem-exp-log10.0%
associate-+r+10.0%
metadata-eval10.0%
Simplified10.0%
Taylor expanded in x around -inf 56.0%
associate-*r/56.0%
*-commutative56.0%
associate-/l*56.0%
Simplified56.0%
Taylor expanded in p around -inf 53.5%
mul-1-neg53.5%
distribute-neg-frac253.5%
Simplified53.5%
if -0.99950000000000006 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 99.7%
expm1-log1p-u99.2%
expm1-undefine99.2%
+-commutative99.2%
add-sqr-sqrt99.2%
hypot-define99.2%
associate-*l*99.2%
sqrt-prod99.4%
metadata-eval99.4%
sqrt-unprod41.3%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
sub-neg99.4%
metadata-eval99.4%
+-commutative99.4%
log1p-undefine99.9%
rem-exp-log99.9%
associate-+r+99.9%
metadata-eval99.9%
Simplified99.9%
Applied egg-rr99.9%
*-lft-identity99.9%
+-commutative99.9%
associate-/r/99.9%
fma-define99.9%
*-commutative99.9%
Simplified99.9%
Final simplification87.6%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.9995) (/ p_m (- x)) (sqrt (+ 0.5 (* x (/ 0.5 (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.9995) {
tmp = p_m / -x;
} else {
tmp = sqrt((0.5 + (x * (0.5 / 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.9995) {
tmp = p_m / -x;
} else {
tmp = Math.sqrt((0.5 + (x * (0.5 / 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.9995: tmp = p_m / -x else: tmp = math.sqrt((0.5 + (x * (0.5 / 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.9995) tmp = Float64(p_m / Float64(-x)); else tmp = sqrt(Float64(0.5 + Float64(x * Float64(0.5 / 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.9995) tmp = p_m / -x; else tmp = sqrt((0.5 + (x * (0.5 / 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.9995], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 + N[(x * N[(0.5 / 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}\;\frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}} \leq -0.9995:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + x \cdot \frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) < -0.99950000000000006Initial program 10.0%
expm1-log1p-u10.0%
expm1-undefine10.0%
+-commutative10.0%
add-sqr-sqrt10.0%
hypot-define10.0%
associate-*l*10.0%
sqrt-prod10.0%
metadata-eval10.0%
sqrt-unprod5.5%
add-sqr-sqrt10.0%
Applied egg-rr10.0%
sub-neg10.0%
metadata-eval10.0%
+-commutative10.0%
log1p-undefine10.0%
rem-exp-log10.0%
associate-+r+10.0%
metadata-eval10.0%
Simplified10.0%
Taylor expanded in x around -inf 56.0%
associate-*r/56.0%
*-commutative56.0%
associate-/l*56.0%
Simplified56.0%
Taylor expanded in p around -inf 53.5%
mul-1-neg53.5%
distribute-neg-frac253.5%
Simplified53.5%
if -0.99950000000000006 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 99.7%
expm1-log1p-u99.2%
expm1-undefine99.2%
+-commutative99.2%
add-sqr-sqrt99.2%
hypot-define99.2%
associate-*l*99.2%
sqrt-prod99.4%
metadata-eval99.4%
sqrt-unprod41.3%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
sub-neg99.4%
metadata-eval99.4%
+-commutative99.4%
log1p-undefine99.9%
rem-exp-log99.9%
associate-+r+99.9%
metadata-eval99.9%
Simplified99.9%
Applied egg-rr99.9%
*-lft-identity99.9%
associate-/r/99.9%
*-commutative99.9%
Simplified99.9%
Final simplification87.6%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -3.5e-55) (/ 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 <= -3.5e-55) {
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 <= -3.5e-55) {
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 <= -3.5e-55: 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 <= -3.5e-55) 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 <= -3.5e-55) 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, -3.5e-55], 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 -3.5 \cdot 10^{-55}:\\
\;\;\;\;\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 < -3.50000000000000025e-55Initial program 43.9%
expm1-log1p-u43.9%
expm1-undefine43.9%
+-commutative43.9%
add-sqr-sqrt43.9%
hypot-define43.9%
associate-*l*43.9%
sqrt-prod44.3%
metadata-eval44.3%
sqrt-unprod20.1%
add-sqr-sqrt44.3%
Applied egg-rr44.3%
sub-neg44.3%
metadata-eval44.3%
+-commutative44.3%
log1p-undefine44.3%
rem-exp-log44.3%
associate-+r+44.3%
metadata-eval44.3%
Simplified44.3%
Taylor expanded in x around -inf 41.4%
associate-*r/41.3%
*-commutative41.3%
associate-/l*41.4%
Simplified41.4%
Taylor expanded in p around -inf 35.7%
mul-1-neg35.7%
distribute-neg-frac235.7%
Simplified35.7%
if -3.50000000000000025e-55 < x Initial program 91.8%
add-sqr-sqrt91.8%
hypot-define91.8%
associate-*l*91.8%
sqrt-prod91.8%
metadata-eval91.8%
sqrt-unprod37.8%
add-sqr-sqrt91.8%
Applied egg-rr91.8%
Final simplification73.2%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))))
(if (<= p_m 3.8e-261)
1.0
(if (<= p_m 2.4e-113)
t_0
(if (<= p_m 1.08e-92)
1.0
(if (<= p_m 1.4e-34)
t_0
(if (<= p_m 7e+17)
(sqrt 0.5)
(if (<= p_m 1.22e+39)
t_0
(sqrt (+ 0.5 (/ (* x 0.25) p_m)))))))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = p_m / -x;
double tmp;
if (p_m <= 3.8e-261) {
tmp = 1.0;
} else if (p_m <= 2.4e-113) {
tmp = t_0;
} else if (p_m <= 1.08e-92) {
tmp = 1.0;
} else if (p_m <= 1.4e-34) {
tmp = t_0;
} else if (p_m <= 7e+17) {
tmp = sqrt(0.5);
} else if (p_m <= 1.22e+39) {
tmp = t_0;
} else {
tmp = sqrt((0.5 + ((x * 0.25) / 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 <= 3.8d-261) then
tmp = 1.0d0
else if (p_m <= 2.4d-113) then
tmp = t_0
else if (p_m <= 1.08d-92) then
tmp = 1.0d0
else if (p_m <= 1.4d-34) then
tmp = t_0
else if (p_m <= 7d+17) then
tmp = sqrt(0.5d0)
else if (p_m <= 1.22d+39) then
tmp = t_0
else
tmp = sqrt((0.5d0 + ((x * 0.25d0) / 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 <= 3.8e-261) {
tmp = 1.0;
} else if (p_m <= 2.4e-113) {
tmp = t_0;
} else if (p_m <= 1.08e-92) {
tmp = 1.0;
} else if (p_m <= 1.4e-34) {
tmp = t_0;
} else if (p_m <= 7e+17) {
tmp = Math.sqrt(0.5);
} else if (p_m <= 1.22e+39) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 + ((x * 0.25) / p_m)));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = p_m / -x tmp = 0 if p_m <= 3.8e-261: tmp = 1.0 elif p_m <= 2.4e-113: tmp = t_0 elif p_m <= 1.08e-92: tmp = 1.0 elif p_m <= 1.4e-34: tmp = t_0 elif p_m <= 7e+17: tmp = math.sqrt(0.5) elif p_m <= 1.22e+39: tmp = t_0 else: tmp = math.sqrt((0.5 + ((x * 0.25) / 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 <= 3.8e-261) tmp = 1.0; elseif (p_m <= 2.4e-113) tmp = t_0; elseif (p_m <= 1.08e-92) tmp = 1.0; elseif (p_m <= 1.4e-34) tmp = t_0; elseif (p_m <= 7e+17) tmp = sqrt(0.5); elseif (p_m <= 1.22e+39) tmp = t_0; else tmp = sqrt(Float64(0.5 + Float64(Float64(x * 0.25) / 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 <= 3.8e-261) tmp = 1.0; elseif (p_m <= 2.4e-113) tmp = t_0; elseif (p_m <= 1.08e-92) tmp = 1.0; elseif (p_m <= 1.4e-34) tmp = t_0; elseif (p_m <= 7e+17) tmp = sqrt(0.5); elseif (p_m <= 1.22e+39) tmp = t_0; else tmp = sqrt((0.5 + ((x * 0.25) / 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, 3.8e-261], 1.0, If[LessEqual[p$95$m, 2.4e-113], t$95$0, If[LessEqual[p$95$m, 1.08e-92], 1.0, If[LessEqual[p$95$m, 1.4e-34], t$95$0, If[LessEqual[p$95$m, 7e+17], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p$95$m, 1.22e+39], t$95$0, N[Sqrt[N[(0.5 + N[(N[(x * 0.25), $MachinePrecision] / p$95$m), $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 3.8 \cdot 10^{-261}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 2.4 \cdot 10^{-113}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 1.08 \cdot 10^{-92}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 1.4 \cdot 10^{-34}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 7 \cdot 10^{+17}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p\_m \leq 1.22 \cdot 10^{+39}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p\_m}}\\
\end{array}
\end{array}
if p < 3.8e-261 or 2.40000000000000012e-113 < p < 1.08e-92Initial program 78.0%
Taylor expanded in x around inf 40.6%
if 3.8e-261 < p < 2.40000000000000012e-113 or 1.08e-92 < p < 1.39999999999999998e-34 or 7e17 < p < 1.22e39Initial program 33.8%
expm1-log1p-u33.4%
expm1-undefine33.4%
+-commutative33.4%
add-sqr-sqrt33.4%
hypot-define33.4%
associate-*l*33.4%
sqrt-prod33.4%
metadata-eval33.4%
sqrt-unprod33.4%
add-sqr-sqrt33.4%
Applied egg-rr33.4%
sub-neg33.4%
metadata-eval33.4%
+-commutative33.4%
log1p-undefine33.8%
rem-exp-log33.8%
associate-+r+33.8%
metadata-eval33.8%
Simplified33.8%
Taylor expanded in x around -inf 43.7%
associate-*r/43.7%
*-commutative43.7%
associate-/l*43.7%
Simplified43.7%
Taylor expanded in p around -inf 73.1%
mul-1-neg73.1%
distribute-neg-frac273.1%
Simplified73.1%
if 1.39999999999999998e-34 < p < 7e17Initial program 86.3%
Taylor expanded in x around 0 54.6%
if 1.22e39 < p Initial program 98.0%
expm1-log1p-u98.0%
expm1-undefine97.9%
+-commutative97.9%
add-sqr-sqrt97.9%
hypot-define97.9%
associate-*l*97.9%
sqrt-prod97.9%
metadata-eval97.9%
sqrt-unprod97.9%
add-sqr-sqrt97.9%
Applied egg-rr97.9%
sub-neg97.9%
metadata-eval97.9%
+-commutative97.9%
log1p-undefine98.0%
rem-exp-log98.0%
associate-+r+98.0%
metadata-eval98.0%
Simplified98.0%
Applied egg-rr98.0%
*-lft-identity98.0%
associate-/r/98.0%
*-commutative98.0%
Simplified98.0%
Taylor expanded in x around 0 94.2%
associate-*r/94.2%
*-commutative94.2%
Simplified94.2%
Final simplification56.3%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))))
(if (<= p_m 4.2e-261)
1.0
(if (<= p_m 2.05e-113)
t_0
(if (<= p_m 5.8e-93)
1.0
(if (or (<= p_m 1.4e-34) (and (not (<= p_m 5e+17)) (<= p_m 1.75e+32)))
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 <= 4.2e-261) {
tmp = 1.0;
} else if (p_m <= 2.05e-113) {
tmp = t_0;
} else if (p_m <= 5.8e-93) {
tmp = 1.0;
} else if ((p_m <= 1.4e-34) || (!(p_m <= 5e+17) && (p_m <= 1.75e+32))) {
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 <= 4.2d-261) then
tmp = 1.0d0
else if (p_m <= 2.05d-113) then
tmp = t_0
else if (p_m <= 5.8d-93) then
tmp = 1.0d0
else if ((p_m <= 1.4d-34) .or. (.not. (p_m <= 5d+17)) .and. (p_m <= 1.75d+32)) 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 <= 4.2e-261) {
tmp = 1.0;
} else if (p_m <= 2.05e-113) {
tmp = t_0;
} else if (p_m <= 5.8e-93) {
tmp = 1.0;
} else if ((p_m <= 1.4e-34) || (!(p_m <= 5e+17) && (p_m <= 1.75e+32))) {
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 <= 4.2e-261: tmp = 1.0 elif p_m <= 2.05e-113: tmp = t_0 elif p_m <= 5.8e-93: tmp = 1.0 elif (p_m <= 1.4e-34) or (not (p_m <= 5e+17) and (p_m <= 1.75e+32)): 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 <= 4.2e-261) tmp = 1.0; elseif (p_m <= 2.05e-113) tmp = t_0; elseif (p_m <= 5.8e-93) tmp = 1.0; elseif ((p_m <= 1.4e-34) || (!(p_m <= 5e+17) && (p_m <= 1.75e+32))) 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 <= 4.2e-261) tmp = 1.0; elseif (p_m <= 2.05e-113) tmp = t_0; elseif (p_m <= 5.8e-93) tmp = 1.0; elseif ((p_m <= 1.4e-34) || (~((p_m <= 5e+17)) && (p_m <= 1.75e+32))) 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, 4.2e-261], 1.0, If[LessEqual[p$95$m, 2.05e-113], t$95$0, If[LessEqual[p$95$m, 5.8e-93], 1.0, If[Or[LessEqual[p$95$m, 1.4e-34], And[N[Not[LessEqual[p$95$m, 5e+17]], $MachinePrecision], LessEqual[p$95$m, 1.75e+32]]], 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 4.2 \cdot 10^{-261}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 2.05 \cdot 10^{-113}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 5.8 \cdot 10^{-93}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 1.4 \cdot 10^{-34} \lor \neg \left(p\_m \leq 5 \cdot 10^{+17}\right) \land p\_m \leq 1.75 \cdot 10^{+32}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 4.19999999999999991e-261 or 2.05e-113 < p < 5.7999999999999997e-93Initial program 78.0%
Taylor expanded in x around inf 40.6%
if 4.19999999999999991e-261 < p < 2.05e-113 or 5.7999999999999997e-93 < p < 1.39999999999999998e-34 or 5e17 < p < 1.75e32Initial program 32.7%
expm1-log1p-u32.3%
expm1-undefine32.3%
+-commutative32.3%
add-sqr-sqrt32.3%
hypot-define32.3%
associate-*l*32.3%
sqrt-prod32.3%
metadata-eval32.3%
sqrt-unprod32.3%
add-sqr-sqrt32.3%
Applied egg-rr32.3%
sub-neg32.3%
metadata-eval32.3%
+-commutative32.3%
log1p-undefine32.7%
rem-exp-log32.7%
associate-+r+32.7%
metadata-eval32.7%
Simplified32.7%
Taylor expanded in x around -inf 43.1%
associate-*r/43.1%
*-commutative43.1%
associate-/l*43.1%
Simplified43.1%
Taylor expanded in p around -inf 74.4%
mul-1-neg74.4%
distribute-neg-frac274.4%
Simplified74.4%
if 1.39999999999999998e-34 < p < 5e17 or 1.75e32 < p Initial program 94.1%
Taylor expanded in x around 0 84.0%
Final simplification56.2%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (or (<= p_m 1.4e-34) (and (not (<= p_m 7e+17)) (<= p_m 1.75e+32))) (/ p_m (- x)) (sqrt 0.5)))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if ((p_m <= 1.4e-34) || (!(p_m <= 7e+17) && (p_m <= 1.75e+32))) {
tmp = p_m / -x;
} 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 <= 1.4d-34) .or. (.not. (p_m <= 7d+17)) .and. (p_m <= 1.75d+32)) then
tmp = p_m / -x
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 <= 1.4e-34) || (!(p_m <= 7e+17) && (p_m <= 1.75e+32))) {
tmp = p_m / -x;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if (p_m <= 1.4e-34) or (not (p_m <= 7e+17) and (p_m <= 1.75e+32)): tmp = p_m / -x else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if ((p_m <= 1.4e-34) || (!(p_m <= 7e+17) && (p_m <= 1.75e+32))) tmp = Float64(p_m / Float64(-x)); 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 <= 1.4e-34) || (~((p_m <= 7e+17)) && (p_m <= 1.75e+32))) tmp = p_m / -x; else tmp = sqrt(0.5); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[Or[LessEqual[p$95$m, 1.4e-34], And[N[Not[LessEqual[p$95$m, 7e+17]], $MachinePrecision], LessEqual[p$95$m, 1.75e+32]]], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 1.4 \cdot 10^{-34} \lor \neg \left(p\_m \leq 7 \cdot 10^{+17}\right) \land p\_m \leq 1.75 \cdot 10^{+32}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.39999999999999998e-34 or 7e17 < p < 1.75e32Initial program 69.7%
expm1-log1p-u69.2%
expm1-undefine69.3%
+-commutative69.3%
add-sqr-sqrt69.3%
hypot-define69.3%
associate-*l*69.3%
sqrt-prod69.4%
metadata-eval69.4%
sqrt-unprod10.6%
add-sqr-sqrt69.4%
Applied egg-rr69.4%
sub-neg69.4%
metadata-eval69.4%
+-commutative69.4%
log1p-undefine69.9%
rem-exp-log69.9%
associate-+r+69.9%
metadata-eval69.9%
Simplified69.9%
Taylor expanded in x around -inf 21.1%
associate-*r/21.1%
*-commutative21.1%
associate-/l*21.1%
Simplified21.1%
Taylor expanded in p around -inf 19.6%
mul-1-neg19.6%
distribute-neg-frac219.6%
Simplified19.6%
if 1.39999999999999998e-34 < p < 7e17 or 1.75e32 < p Initial program 94.1%
Taylor expanded in x around 0 84.0%
Final simplification35.9%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -2e-311) (/ p_m (- x)) (/ p_m x)))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -2e-311) {
tmp = p_m / -x;
} else {
tmp = 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 <= (-2d-311)) then
tmp = p_m / -x
else
tmp = 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 <= -2e-311) {
tmp = p_m / -x;
} else {
tmp = p_m / x;
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -2e-311: tmp = p_m / -x else: tmp = p_m / x return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -2e-311) tmp = Float64(p_m / Float64(-x)); else tmp = Float64(p_m / x); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -2e-311) tmp = p_m / -x; else tmp = p_m / x; end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -2e-311], N[(p$95$m / (-x)), $MachinePrecision], N[(p$95$m / x), $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-311}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\frac{p\_m}{x}\\
\end{array}
\end{array}
if x < -1.9999999999999e-311Initial program 51.4%
expm1-log1p-u51.4%
expm1-undefine51.4%
+-commutative51.4%
add-sqr-sqrt51.4%
hypot-define51.4%
associate-*l*51.4%
sqrt-prod51.7%
metadata-eval51.7%
sqrt-unprod22.6%
add-sqr-sqrt51.7%
Applied egg-rr51.7%
sub-neg51.7%
metadata-eval51.7%
+-commutative51.7%
log1p-undefine51.7%
rem-exp-log51.7%
associate-+r+51.7%
metadata-eval51.7%
Simplified51.7%
Taylor expanded in x around -inf 32.3%
associate-*r/32.2%
*-commutative32.2%
associate-/l*32.3%
Simplified32.3%
Taylor expanded in p around -inf 29.9%
mul-1-neg29.9%
distribute-neg-frac229.9%
Simplified29.9%
if -1.9999999999999e-311 < x Initial program 100.0%
expm1-log1p-u99.2%
expm1-undefine99.2%
+-commutative99.2%
add-sqr-sqrt99.2%
hypot-define99.2%
associate-*l*99.2%
sqrt-prod99.2%
metadata-eval99.2%
sqrt-unprod40.8%
add-sqr-sqrt99.2%
Applied egg-rr99.2%
sub-neg99.2%
metadata-eval99.2%
+-commutative99.2%
log1p-undefine100.0%
rem-exp-log100.0%
associate-+r+100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around -inf 4.9%
associate-*r/4.9%
*-commutative4.9%
associate-/l*4.9%
Simplified4.9%
Taylor expanded in p around 0 3.2%
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 / 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 75.9%
expm1-log1p-u75.5%
expm1-undefine75.5%
+-commutative75.5%
add-sqr-sqrt75.5%
hypot-define75.5%
associate-*l*75.5%
sqrt-prod75.7%
metadata-eval75.7%
sqrt-unprod31.8%
add-sqr-sqrt75.7%
Applied egg-rr75.7%
sub-neg75.7%
metadata-eval75.7%
+-commutative75.7%
log1p-undefine76.0%
rem-exp-log76.0%
associate-+r+76.0%
metadata-eval76.0%
Simplified76.0%
Taylor expanded in x around -inf 18.5%
associate-*r/18.5%
*-commutative18.5%
associate-/l*18.5%
Simplified18.5%
Taylor expanded in p around 0 16.9%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 0.0)
p_m = fabs(p);
double code(double p_m, double x) {
return 0.0;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
code = 0.0d0
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
return 0.0;
}
p_m = math.fabs(p) def code(p_m, x): return 0.0
p_m = abs(p) function code(p_m, x) return 0.0 end
p_m = abs(p); function tmp = code(p_m, x) tmp = 0.0; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := 0.0
\begin{array}{l}
p_m = \left|p\right|
\\
0
\end{array}
Initial program 75.9%
Taylor expanded in x around -inf 4.8%
metadata-eval4.8%
metadata-eval4.8%
metadata-eval4.8%
pow1/24.8%
metadata-eval4.8%
metadata-eval4.8%
Applied egg-rr4.8%
(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 2024111
(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))))))))