
(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 8 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) (/ (- (* 0.125 (* (/ -12.0 p_m) (/ (pow p_m 4.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.5) {
tmp = ((0.125 * ((-12.0 / p_m) * (pow(p_m, 4.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.5) {
tmp = ((0.125 * ((-12.0 / p_m) * (Math.pow(p_m, 4.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.5: tmp = ((0.125 * ((-12.0 / p_m) * (math.pow(p_m, 4.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.5) tmp = Float64(Float64(Float64(0.125 * Float64(Float64(-12.0 / p_m) * Float64((p_m ^ 4.0) / Float64(-(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.5) tmp = ((0.125 * ((-12.0 / p_m) * ((p_m ^ 4.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.5], N[(N[(N[(0.125 * N[(N[(-12.0 / p$95$m), $MachinePrecision] * N[(N[Power[p$95$m, 4.0], $MachinePrecision] / (-N[Power[x, 2.0], $MachinePrecision])), $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.5:\\
\;\;\;\;\frac{0.125 \cdot \left(\frac{-12}{p\_m} \cdot \frac{{p\_m}^{4}}{-{x}^{2}}\right) - 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.5Initial program 19.5%
sqrt-prod19.5%
*-commutative19.5%
+-commutative19.5%
add-sqr-sqrt19.5%
hypot-define19.5%
associate-*l*19.5%
sqrt-prod19.5%
metadata-eval19.5%
sqrt-unprod5.8%
add-sqr-sqrt19.5%
Applied egg-rr19.5%
sqrt-unprod19.5%
metadata-eval19.5%
*-commutative19.5%
associate-+r+19.5%
*-commutative19.5%
add-cbrt-cube19.5%
add-sqr-sqrt19.5%
pow119.5%
pow1/219.5%
pow-prod-up19.5%
Applied egg-rr19.5%
Taylor expanded in x around -inf 50.9%
mul-1-neg50.9%
distribute-neg-frac250.9%
distribute-rgt-out50.9%
*-commutative50.9%
times-frac60.4%
metadata-eval60.4%
Simplified60.4%
if -0.5 < (/.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-unprod43.2%
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%
*-commutative100.0%
Simplified100.0%
Final simplification89.9%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -1.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)))) <= -1.0) {
tmp = 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)))) <= -1.0) {
tmp = 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)))) <= -1.0: tmp = 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)))) <= -1.0) tmp = Float64(p_m / Float64(-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)))) <= -1.0) tmp = 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], -1.0], N[(p$95$m / (-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 -1:\\
\;\;\;\;\frac{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)))) < -1Initial program 18.1%
Taylor expanded in x around -inf 61.3%
mul-1-neg61.3%
Simplified61.3%
distribute-neg-frac61.3%
sqrt-unprod62.2%
metadata-eval62.2%
metadata-eval62.2%
*-rgt-identity62.2%
Applied egg-rr62.2%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 99.6%
expm1-log1p-u99.1%
expm1-undefine99.1%
+-commutative99.1%
add-sqr-sqrt99.1%
hypot-define99.1%
associate-*l*99.1%
sqrt-prod99.1%
metadata-eval99.1%
sqrt-unprod42.8%
add-sqr-sqrt99.1%
Applied egg-rr99.1%
sub-neg99.1%
metadata-eval99.1%
+-commutative99.1%
log1p-undefine99.6%
rem-exp-log99.6%
associate-+r+99.6%
metadata-eval99.6%
*-commutative99.6%
Simplified99.6%
Final simplification90.4%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -5.4e-40) (/ p_m (- x)) (sqrt (+ 0.5 (/ 0.5 (/ (hypot x (* p_m 2.0)) x))))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -5.4e-40) {
tmp = p_m / -x;
} else {
tmp = sqrt((0.5 + (0.5 / (hypot(x, (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 <= -5.4e-40) {
tmp = p_m / -x;
} else {
tmp = Math.sqrt((0.5 + (0.5 / (Math.hypot(x, (p_m * 2.0)) / x))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -5.4e-40: tmp = p_m / -x else: tmp = math.sqrt((0.5 + (0.5 / (math.hypot(x, (p_m * 2.0)) / x)))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -5.4e-40) tmp = Float64(p_m / Float64(-x)); else tmp = sqrt(Float64(0.5 + Float64(0.5 / Float64(hypot(x, 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 <= -5.4e-40) tmp = p_m / -x; else tmp = sqrt((0.5 + (0.5 / (hypot(x, (p_m * 2.0)) / x)))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -5.4e-40], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 + N[(0.5 / N[(N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.4 \cdot 10^{-40}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}{x}}}\\
\end{array}
\end{array}
if x < -5.4e-40Initial program 47.4%
Taylor expanded in x around -inf 42.1%
mul-1-neg42.1%
Simplified42.1%
distribute-neg-frac42.1%
sqrt-unprod42.7%
metadata-eval42.7%
metadata-eval42.7%
*-rgt-identity42.7%
Applied egg-rr42.7%
if -5.4e-40 < x Initial program 93.4%
+-commutative93.4%
distribute-rgt-in93.4%
+-commutative93.4%
add-sqr-sqrt93.4%
hypot-define93.4%
associate-*l*93.4%
sqrt-prod93.4%
metadata-eval93.4%
sqrt-unprod39.8%
add-sqr-sqrt93.4%
metadata-eval93.4%
Applied egg-rr93.4%
*-commutative93.4%
clear-num93.4%
un-div-inv93.4%
Applied egg-rr93.4%
Final simplification78.1%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -1.6e-38) (/ 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.6e-38) {
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.6e-38) {
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.6e-38: 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.6e-38) 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.6e-38) 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[LessEqual[x, -1.6e-38], 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.6 \cdot 10^{-38}:\\
\;\;\;\;\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.59999999999999989e-38Initial program 47.4%
Taylor expanded in x around -inf 42.1%
mul-1-neg42.1%
Simplified42.1%
distribute-neg-frac42.1%
sqrt-unprod42.7%
metadata-eval42.7%
metadata-eval42.7%
*-rgt-identity42.7%
Applied egg-rr42.7%
if -1.59999999999999989e-38 < x Initial program 93.4%
+-commutative93.4%
distribute-rgt-in93.4%
+-commutative93.4%
add-sqr-sqrt93.4%
hypot-define93.4%
associate-*l*93.4%
sqrt-prod93.4%
metadata-eval93.4%
sqrt-unprod39.8%
add-sqr-sqrt93.4%
metadata-eval93.4%
Applied egg-rr93.4%
Final simplification78.1%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= p_m 1.35e-294) (/ p_m (- x)) (if (<= p_m 2.75e-64) 1.0 (sqrt 0.5))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (p_m <= 1.35e-294) {
tmp = p_m / -x;
} else if (p_m <= 2.75e-64) {
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 <= 1.35d-294) then
tmp = p_m / -x
else if (p_m <= 2.75d-64) 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 <= 1.35e-294) {
tmp = p_m / -x;
} else if (p_m <= 2.75e-64) {
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 <= 1.35e-294: tmp = p_m / -x elif p_m <= 2.75e-64: 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 <= 1.35e-294) tmp = Float64(p_m / Float64(-x)); elseif (p_m <= 2.75e-64) 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 <= 1.35e-294) tmp = p_m / -x; elseif (p_m <= 2.75e-64) 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, 1.35e-294], N[(p$95$m / (-x)), $MachinePrecision], If[LessEqual[p$95$m, 2.75e-64], 1.0, N[Sqrt[0.5], $MachinePrecision]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 1.35 \cdot 10^{-294}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{elif}\;p\_m \leq 2.75 \cdot 10^{-64}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.35000000000000005e-294Initial program 81.3%
Taylor expanded in x around -inf 10.4%
mul-1-neg10.4%
Simplified10.4%
distribute-neg-frac10.4%
sqrt-unprod10.4%
metadata-eval10.4%
metadata-eval10.4%
*-rgt-identity10.4%
Applied egg-rr10.4%
if 1.35000000000000005e-294 < p < 2.7499999999999999e-64Initial program 69.3%
Taylor expanded in x around inf 60.4%
if 2.7499999999999999e-64 < p Initial program 82.8%
Taylor expanded in x around 0 78.0%
Final simplification36.9%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= p_m 1.65e-100) (/ p_m (- x)) (sqrt 0.5)))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (p_m <= 1.65e-100) {
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.65d-100) 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.65e-100) {
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.65e-100: 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.65e-100) 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.65e-100) 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, 1.65e-100], 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.65 \cdot 10^{-100}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.64999999999999998e-100Initial program 78.2%
Taylor expanded in x around -inf 17.1%
mul-1-neg17.1%
Simplified17.1%
distribute-neg-frac17.1%
sqrt-unprod17.2%
metadata-eval17.2%
metadata-eval17.2%
*-rgt-identity17.2%
Applied egg-rr17.2%
if 1.64999999999999998e-100 < p Initial program 82.9%
Taylor expanded in x around 0 74.2%
Final simplification33.5%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -1e-310) (/ p_m (- x)) (/ p_m x)))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -1e-310) {
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 <= (-1d-310)) 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 <= -1e-310) {
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 <= -1e-310: 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 <= -1e-310) 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 <= -1e-310) 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, -1e-310], 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 -1 \cdot 10^{-310}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\frac{p\_m}{x}\\
\end{array}
\end{array}
if x < -9.999999999999969e-311Initial program 59.1%
Taylor expanded in x around -inf 31.9%
mul-1-neg31.9%
Simplified31.9%
distribute-neg-frac31.9%
sqrt-unprod32.3%
metadata-eval32.3%
metadata-eval32.3%
*-rgt-identity32.3%
Applied egg-rr32.3%
if -9.999999999999969e-311 < x Initial program 100.0%
Taylor expanded in x around -inf 4.2%
mul-1-neg4.2%
Simplified4.2%
neg-sub04.2%
sub-neg4.2%
add-sqr-sqrt3.5%
sqrt-unprod5.3%
sqr-neg5.3%
sqrt-unprod2.1%
add-sqr-sqrt3.0%
sqrt-unprod3.0%
metadata-eval3.0%
metadata-eval3.0%
*-rgt-identity3.0%
Applied egg-rr3.0%
+-lft-identity3.0%
Simplified3.0%
Final simplification17.6%
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 79.5%
Taylor expanded in x around -inf 18.0%
mul-1-neg18.0%
Simplified18.0%
neg-sub018.0%
sub-neg18.0%
add-sqr-sqrt16.7%
sqrt-unprod20.7%
sqr-neg20.7%
sqrt-unprod14.9%
add-sqr-sqrt16.0%
sqrt-unprod16.2%
metadata-eval16.2%
metadata-eval16.2%
*-rgt-identity16.2%
Applied egg-rr16.2%
+-lft-identity16.2%
Simplified16.2%
(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 2024165
(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))))))))