
(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.98)
(/ (+ p_m (* -1.5 (/ (pow p_m 3.0) (pow x 2.0)))) (- x))
(pow
(pow (fma x (/ 0.5 (hypot x (* p_m 2.0))) 0.5) 1.5)
0.3333333333333333)))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 = (p_m + (-1.5 * (pow(p_m, 3.0) / pow(x, 2.0)))) / -x;
} else {
tmp = pow(pow(fma(x, (0.5 / hypot(x, (p_m * 2.0))), 0.5), 1.5), 0.3333333333333333);
}
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(p_m + Float64(-1.5 * Float64((p_m ^ 3.0) / (x ^ 2.0)))) / Float64(-x)); else tmp = (fma(x, Float64(0.5 / hypot(x, Float64(p_m * 2.0))), 0.5) ^ 1.5) ^ 0.3333333333333333; 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[(p$95$m + N[(-1.5 * N[(N[Power[p$95$m, 3.0], $MachinePrecision] / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision], N[Power[N[Power[N[(x * N[(0.5 / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + 0.5), $MachinePrecision], 1.5], $MachinePrecision], 0.3333333333333333], $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{p\_m + -1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}}}{-x}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(\mathsf{fma}\left(x, \frac{0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}, 0.5\right)\right)}^{1.5}\right)}^{0.3333333333333333}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) < -0.97999999999999998Initial program 12.8%
+-commutative12.8%
associate-*l*12.8%
fma-define12.8%
sqr-neg12.8%
fma-define12.8%
associate-*l*12.8%
+-commutative12.8%
distribute-lft-in12.8%
metadata-eval12.8%
Simplified12.8%
associate-*r/12.8%
clear-num12.8%
fma-undefine12.8%
associate-*r*12.8%
add-sqr-sqrt12.8%
hypot-define12.8%
associate-*r*12.8%
*-commutative12.8%
sqrt-prod12.8%
sqrt-prod5.6%
add-sqr-sqrt12.8%
metadata-eval12.8%
*-commutative12.8%
Applied egg-rr12.8%
associate-/r/12.9%
associate-*r*12.9%
associate-*l/12.8%
*-lft-identity12.8%
metadata-eval12.8%
times-frac12.8%
*-rgt-identity12.8%
Simplified12.8%
Taylor expanded in x around -inf 39.8%
associate-*r/39.8%
mul-1-neg39.8%
distribute-rgt-out39.8%
metadata-eval39.8%
Simplified39.8%
Taylor expanded in p around 0 47.5%
if -0.97999999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 100.0%
+-commutative100.0%
associate-*l*100.0%
fma-define100.0%
sqr-neg100.0%
fma-define100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
metadata-eval100.0%
Simplified100.0%
associate-*r/100.0%
clear-num100.0%
fma-undefine99.9%
associate-*r*99.9%
add-sqr-sqrt99.9%
hypot-define100.0%
associate-*r*100.0%
*-commutative100.0%
sqrt-prod100.0%
sqrt-prod52.1%
add-sqr-sqrt100.0%
metadata-eval100.0%
*-commutative100.0%
Applied egg-rr100.0%
associate-/r/100.0%
associate-*r*100.0%
associate-*l/100.0%
*-lft-identity100.0%
metadata-eval100.0%
times-frac100.0%
*-rgt-identity100.0%
Simplified100.0%
add-cbrt-cube99.9%
pow1/3100.0%
add-sqr-sqrt100.0%
pow1100.0%
pow1/2100.0%
pow-prod-up100.0%
+-commutative100.0%
associate-/l*100.0%
fma-define100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification86.0%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.98) (/ (+ p_m (* -1.5 (/ (pow p_m 3.0) (pow x 2.0)))) (- 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 = (p_m + (-1.5 * (pow(p_m, 3.0) / pow(x, 2.0)))) / -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(p_m + Float64(-1.5 * Float64((p_m ^ 3.0) / (x ^ 2.0)))) / Float64(-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[(p$95$m + N[(-1.5 * N[(N[Power[p$95$m, 3.0], $MachinePrecision] / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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{p\_m + -1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}}}{-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 12.8%
+-commutative12.8%
associate-*l*12.8%
fma-define12.8%
sqr-neg12.8%
fma-define12.8%
associate-*l*12.8%
+-commutative12.8%
distribute-lft-in12.8%
metadata-eval12.8%
Simplified12.8%
associate-*r/12.8%
clear-num12.8%
fma-undefine12.8%
associate-*r*12.8%
add-sqr-sqrt12.8%
hypot-define12.8%
associate-*r*12.8%
*-commutative12.8%
sqrt-prod12.8%
sqrt-prod5.6%
add-sqr-sqrt12.8%
metadata-eval12.8%
*-commutative12.8%
Applied egg-rr12.8%
associate-/r/12.9%
associate-*r*12.9%
associate-*l/12.8%
*-lft-identity12.8%
metadata-eval12.8%
times-frac12.8%
*-rgt-identity12.8%
Simplified12.8%
Taylor expanded in x around -inf 39.8%
associate-*r/39.8%
mul-1-neg39.8%
distribute-rgt-out39.8%
metadata-eval39.8%
Simplified39.8%
Taylor expanded in p around 0 47.5%
if -0.97999999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 100.0%
+-commutative100.0%
associate-*l*100.0%
fma-define100.0%
sqr-neg100.0%
fma-define100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
metadata-eval100.0%
Simplified100.0%
Applied egg-rr66.4%
*-un-lft-identity66.4%
*-commutative66.4%
*-un-lft-identity66.4%
times-frac66.4%
metadata-eval66.4%
metadata-eval66.4%
unpow266.4%
flip-+100.0%
metadata-eval100.0%
associate-+r+100.0%
+-commutative100.0%
+-commutative100.0%
associate-+l+100.0%
metadata-eval100.0%
Applied egg-rr100.0%
*-lft-identity100.0%
distribute-lft-in100.0%
associate-*r/100.0%
*-commutative100.0%
associate-*r/100.0%
metadata-eval100.0%
fma-undefine100.0%
Simplified100.0%
Final simplification86.0%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.98) (/ (+ p_m (* -1.5 (/ (pow p_m 3.0) (pow x 2.0)))) (- 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.98) {
tmp = (p_m + (-1.5 * (pow(p_m, 3.0) / pow(x, 2.0)))) / -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.98) {
tmp = (p_m + (-1.5 * (Math.pow(p_m, 3.0) / Math.pow(x, 2.0)))) / -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.98: tmp = (p_m + (-1.5 * (math.pow(p_m, 3.0) / math.pow(x, 2.0)))) / -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.98) tmp = Float64(Float64(p_m + Float64(-1.5 * Float64((p_m ^ 3.0) / (x ^ 2.0)))) / Float64(-x)); else tmp = sqrt(Float64(0.5 + Float64(Float64(x * 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.98) tmp = (p_m + (-1.5 * ((p_m ^ 3.0) / (x ^ 2.0)))) / -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.98], N[(N[(p$95$m + N[(-1.5 * N[(N[Power[p$95$m, 3.0], $MachinePrecision] / N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 + N[(N[(x * 0.5), $MachinePrecision] / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $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{p\_m + -1.5 \cdot \frac{{p\_m}^{3}}{{x}^{2}}}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{x \cdot 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.97999999999999998Initial program 12.8%
+-commutative12.8%
associate-*l*12.8%
fma-define12.8%
sqr-neg12.8%
fma-define12.8%
associate-*l*12.8%
+-commutative12.8%
distribute-lft-in12.8%
metadata-eval12.8%
Simplified12.8%
associate-*r/12.8%
clear-num12.8%
fma-undefine12.8%
associate-*r*12.8%
add-sqr-sqrt12.8%
hypot-define12.8%
associate-*r*12.8%
*-commutative12.8%
sqrt-prod12.8%
sqrt-prod5.6%
add-sqr-sqrt12.8%
metadata-eval12.8%
*-commutative12.8%
Applied egg-rr12.8%
associate-/r/12.9%
associate-*r*12.9%
associate-*l/12.8%
*-lft-identity12.8%
metadata-eval12.8%
times-frac12.8%
*-rgt-identity12.8%
Simplified12.8%
Taylor expanded in x around -inf 39.8%
associate-*r/39.8%
mul-1-neg39.8%
distribute-rgt-out39.8%
metadata-eval39.8%
Simplified39.8%
Taylor expanded in p around 0 47.5%
if -0.97999999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 100.0%
+-commutative100.0%
associate-*l*100.0%
fma-define100.0%
sqr-neg100.0%
fma-define100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
metadata-eval100.0%
Simplified100.0%
associate-*r/100.0%
clear-num100.0%
fma-undefine99.9%
associate-*r*99.9%
add-sqr-sqrt99.9%
hypot-define100.0%
associate-*r*100.0%
*-commutative100.0%
sqrt-prod100.0%
sqrt-prod52.1%
add-sqr-sqrt100.0%
metadata-eval100.0%
*-commutative100.0%
Applied egg-rr100.0%
associate-/r/100.0%
associate-*r*100.0%
associate-*l/100.0%
*-lft-identity100.0%
metadata-eval100.0%
times-frac100.0%
*-rgt-identity100.0%
Simplified100.0%
Final simplification86.0%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -740.0) (/ 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 <= -740.0) {
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 <= -740.0) {
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 <= -740.0: 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 (x <= -740.0) tmp = Float64(p_m / Float64(-x)); else tmp = sqrt(Float64(0.5 + Float64(Float64(x * 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 <= -740.0) 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[x, -740.0], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 + N[(N[(x * 0.5), $MachinePrecision] / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -740:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.5}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}}\\
\end{array}
\end{array}
if x < -740Initial program 48.6%
+-commutative48.6%
associate-*l*48.6%
fma-define48.6%
sqr-neg48.6%
fma-define48.6%
associate-*l*48.6%
+-commutative48.6%
distribute-lft-in48.6%
metadata-eval48.6%
Simplified48.6%
Taylor expanded in x around -inf 32.3%
mul-1-neg32.3%
distribute-neg-frac232.3%
Simplified32.3%
if -740 < x Initial program 87.0%
+-commutative87.0%
associate-*l*87.0%
fma-define87.0%
sqr-neg87.0%
fma-define87.0%
associate-*l*87.0%
+-commutative87.0%
distribute-lft-in87.0%
metadata-eval87.0%
Simplified87.0%
associate-*r/87.0%
clear-num87.0%
fma-undefine87.0%
associate-*r*87.0%
add-sqr-sqrt87.0%
hypot-define87.0%
associate-*r*87.0%
*-commutative87.0%
sqrt-prod87.0%
sqrt-prod45.7%
add-sqr-sqrt87.0%
metadata-eval87.0%
*-commutative87.0%
Applied egg-rr87.0%
associate-/r/87.0%
associate-*r*87.0%
associate-*l/87.0%
*-lft-identity87.0%
metadata-eval87.0%
times-frac87.0%
*-rgt-identity87.0%
Simplified87.0%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= p_m 3.4e-183) 1.0 (if (<= p_m 4.8e-68) (/ 1.0 (fabs (/ x p_m))) (sqrt 0.5))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (p_m <= 3.4e-183) {
tmp = 1.0;
} else if (p_m <= 4.8e-68) {
tmp = 1.0 / fabs((x / p_m));
} 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 <= 3.4d-183) then
tmp = 1.0d0
else if (p_m <= 4.8d-68) then
tmp = 1.0d0 / abs((x / p_m))
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 <= 3.4e-183) {
tmp = 1.0;
} else if (p_m <= 4.8e-68) {
tmp = 1.0 / Math.abs((x / p_m));
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if p_m <= 3.4e-183: tmp = 1.0 elif p_m <= 4.8e-68: tmp = 1.0 / math.fabs((x / p_m)) else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (p_m <= 3.4e-183) tmp = 1.0; elseif (p_m <= 4.8e-68) tmp = Float64(1.0 / abs(Float64(x / p_m))); 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 <= 3.4e-183) tmp = 1.0; elseif (p_m <= 4.8e-68) tmp = 1.0 / abs((x / p_m)); 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, 3.4e-183], 1.0, If[LessEqual[p$95$m, 4.8e-68], N[(1.0 / N[Abs[N[(x / p$95$m), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 3.4 \cdot 10^{-183}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 4.8 \cdot 10^{-68}:\\
\;\;\;\;\frac{1}{\left|\frac{x}{p\_m}\right|}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 3.40000000000000014e-183Initial program 74.3%
+-commutative74.3%
associate-*l*74.3%
fma-define74.3%
sqr-neg74.3%
fma-define74.3%
associate-*l*74.3%
+-commutative74.3%
distribute-lft-in74.3%
metadata-eval74.3%
Simplified74.3%
Applied egg-rr44.0%
expm1-log1p-u43.4%
expm1-undefine43.4%
Applied egg-rr73.7%
log1p-undefine73.7%
rem-exp-log73.7%
distribute-lft-in73.7%
metadata-eval73.7%
fma-define73.7%
Applied egg-rr73.7%
Taylor expanded in x around inf 39.7%
if 3.40000000000000014e-183 < p < 4.79999999999999982e-68Initial program 52.4%
+-commutative52.4%
associate-*l*52.4%
fma-define52.4%
sqr-neg52.4%
fma-define52.4%
associate-*l*52.4%
+-commutative52.4%
distribute-lft-in52.4%
metadata-eval52.4%
Simplified52.4%
Taylor expanded in x around -inf 52.5%
mul-1-neg52.5%
distribute-neg-frac252.5%
Simplified52.5%
clear-num52.2%
inv-pow52.2%
add-sqr-sqrt51.2%
sqrt-unprod53.6%
sqr-neg53.6%
sqrt-unprod2.2%
add-sqr-sqrt4.2%
Applied egg-rr4.2%
unpow-14.2%
Simplified4.2%
add-sqr-sqrt2.2%
sqrt-unprod37.1%
pow237.1%
Applied egg-rr37.1%
unpow237.1%
rem-sqrt-square53.6%
Simplified53.6%
if 4.79999999999999982e-68 < p Initial program 91.5%
Taylor expanded in x around 0 81.1%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= p_m 2.8e-183) 1.0 (if (<= p_m 1.6e-66) (/ p_m (- x)) (sqrt 0.5))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (p_m <= 2.8e-183) {
tmp = 1.0;
} else if (p_m <= 1.6e-66) {
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 <= 2.8d-183) then
tmp = 1.0d0
else if (p_m <= 1.6d-66) 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 <= 2.8e-183) {
tmp = 1.0;
} else if (p_m <= 1.6e-66) {
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 <= 2.8e-183: tmp = 1.0 elif p_m <= 1.6e-66: 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 <= 2.8e-183) tmp = 1.0; elseif (p_m <= 1.6e-66) 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 <= 2.8e-183) tmp = 1.0; elseif (p_m <= 1.6e-66) 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[LessEqual[p$95$m, 2.8e-183], 1.0, If[LessEqual[p$95$m, 1.6e-66], 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 2.8 \cdot 10^{-183}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 1.6 \cdot 10^{-66}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 2.79999999999999985e-183Initial program 74.3%
+-commutative74.3%
associate-*l*74.3%
fma-define74.3%
sqr-neg74.3%
fma-define74.3%
associate-*l*74.3%
+-commutative74.3%
distribute-lft-in74.3%
metadata-eval74.3%
Simplified74.3%
Applied egg-rr44.0%
expm1-log1p-u43.4%
expm1-undefine43.4%
Applied egg-rr73.7%
log1p-undefine73.7%
rem-exp-log73.7%
distribute-lft-in73.7%
metadata-eval73.7%
fma-define73.7%
Applied egg-rr73.7%
Taylor expanded in x around inf 39.7%
if 2.79999999999999985e-183 < p < 1.59999999999999991e-66Initial program 52.4%
+-commutative52.4%
associate-*l*52.4%
fma-define52.4%
sqr-neg52.4%
fma-define52.4%
associate-*l*52.4%
+-commutative52.4%
distribute-lft-in52.4%
metadata-eval52.4%
Simplified52.4%
Taylor expanded in x around -inf 52.5%
mul-1-neg52.5%
distribute-neg-frac252.5%
Simplified52.5%
if 1.59999999999999991e-66 < p Initial program 91.5%
Taylor expanded in x around 0 81.1%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -9.5e-211) (/ p_m (- x)) 1.0))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -9.5e-211) {
tmp = p_m / -x;
} else {
tmp = 1.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 (x <= (-9.5d-211)) then
tmp = p_m / -x
else
tmp = 1.0d0
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= -9.5e-211) {
tmp = p_m / -x;
} else {
tmp = 1.0;
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -9.5e-211: tmp = p_m / -x else: tmp = 1.0 return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -9.5e-211) tmp = Float64(p_m / Float64(-x)); else tmp = 1.0; end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -9.5e-211) tmp = p_m / -x; else tmp = 1.0; end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -9.5e-211], N[(p$95$m / (-x)), $MachinePrecision], 1.0]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-211}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -9.50000000000000008e-211Initial program 55.4%
+-commutative55.4%
associate-*l*55.4%
fma-define55.4%
sqr-neg55.4%
fma-define55.4%
associate-*l*55.4%
+-commutative55.4%
distribute-lft-in55.4%
metadata-eval55.4%
Simplified55.4%
Taylor expanded in x around -inf 25.9%
mul-1-neg25.9%
distribute-neg-frac225.9%
Simplified25.9%
if -9.50000000000000008e-211 < x Initial program 100.0%
+-commutative100.0%
associate-*l*100.0%
fma-define100.0%
sqr-neg100.0%
fma-define100.0%
associate-*l*100.0%
+-commutative100.0%
distribute-lft-in100.0%
metadata-eval100.0%
Simplified100.0%
Applied egg-rr48.7%
expm1-log1p-u48.0%
expm1-undefine48.0%
Applied egg-rr99.3%
log1p-undefine99.3%
rem-exp-log99.3%
distribute-lft-in99.3%
metadata-eval99.3%
fma-define99.3%
Applied egg-rr99.3%
Taylor expanded in x around inf 61.1%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 1.0)
p_m = fabs(p);
double code(double p_m, double x) {
return 1.0;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
code = 1.0d0
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
return 1.0;
}
p_m = math.fabs(p) def code(p_m, x): return 1.0
p_m = abs(p) function code(p_m, x) return 1.0 end
p_m = abs(p); function tmp = code(p_m, x) tmp = 1.0; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := 1.0
\begin{array}{l}
p_m = \left|p\right|
\\
1
\end{array}
Initial program 76.8%
+-commutative76.8%
associate-*l*76.8%
fma-define76.8%
sqr-neg76.8%
fma-define76.8%
associate-*l*76.8%
+-commutative76.8%
distribute-lft-in76.8%
metadata-eval76.8%
Simplified76.8%
Applied egg-rr52.2%
expm1-log1p-u51.5%
expm1-undefine51.5%
Applied egg-rr76.1%
log1p-undefine76.1%
rem-exp-log76.1%
distribute-lft-in76.1%
metadata-eval76.1%
fma-define76.1%
Applied egg-rr76.1%
Taylor expanded in x around inf 35.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 76.8%
+-commutative76.8%
associate-*l*76.8%
fma-define76.8%
sqr-neg76.8%
fma-define76.8%
associate-*l*76.8%
+-commutative76.8%
distribute-lft-in76.8%
metadata-eval76.8%
Simplified76.8%
Applied egg-rr52.2%
expm1-log1p-u51.5%
expm1-undefine51.5%
Applied egg-rr76.1%
Taylor expanded in x around -inf 5.5%
metadata-eval5.5%
Applied egg-rr5.5%
(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 2024172
(FPCore (p x)
:name "Given's Rotation SVD example"
:precision binary64
:pre (and (< 1e-150 (fabs x)) (< (fabs x) 1e+150))
:alt
(! :herbie-platform default (sqrt (+ 1/2 (/ (copysign 1/2 x) (hypot 1 (/ (* 2 p) x))))))
(sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))