
(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)))) -1.0) (/ p_m (- x)) (sqrt (* 0.5 (fma (/ 1.0 (hypot x (* p_m 2.0))) x 1.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 * fma((1.0 / hypot(x, (p_m * 2.0))), x, 1.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 * fma(Float64(1.0 / hypot(x, Float64(p_m * 2.0))), x, 1.0))); 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], -1.0], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[(1.0 / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * x + 1.0), $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 \mathsf{fma}\left(\frac{1}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}, x, 1\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) < -1Initial program 14.6%
add-sqr-sqrt14.6%
pow214.6%
Applied egg-rr14.6%
Taylor expanded in x around -inf 50.7%
mul-1-neg50.7%
distribute-neg-frac250.7%
Simplified50.7%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 99.9%
+-commutative99.9%
clear-num99.9%
associate-/r/99.9%
fma-define99.9%
+-commutative99.9%
add-sqr-sqrt99.9%
hypot-define99.9%
associate-*l*99.9%
sqrt-prod99.9%
metadata-eval99.9%
sqrt-unprod49.0%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Final simplification89.1%
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 (* x (/ 1.0 (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 + (x * (1.0 / 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 + (x * (1.0 / 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 + (x * (1.0 / 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(x * Float64(1.0 / 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 + (x * (1.0 / 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[(x * N[(1.0 / 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 + x \cdot \frac{1}{\mathsf{hypot}\left(x, p\_m \cdot 2\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 14.6%
add-sqr-sqrt14.6%
pow214.6%
Applied egg-rr14.6%
Taylor expanded in x around -inf 50.7%
mul-1-neg50.7%
distribute-neg-frac250.7%
Simplified50.7%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 99.9%
clear-num99.9%
associate-/r/99.9%
+-commutative99.9%
add-sqr-sqrt99.9%
hypot-define99.9%
associate-*l*99.9%
sqrt-prod99.9%
metadata-eval99.9%
sqrt-unprod49.0%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Final simplification89.1%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -1.1e+29) (/ 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.1e+29) {
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.1e+29) {
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.1e+29: 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.1e+29) 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.1e+29) 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.1e+29], 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.1 \cdot 10^{+29}:\\
\;\;\;\;\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.1000000000000001e29Initial program 50.9%
add-sqr-sqrt50.3%
pow250.3%
Applied egg-rr50.3%
Taylor expanded in x around -inf 39.4%
mul-1-neg39.4%
distribute-neg-frac239.4%
Simplified39.4%
if -1.1000000000000001e29 < x Initial program 88.0%
add-sqr-sqrt88.0%
hypot-define88.0%
associate-*l*88.0%
sqrt-prod88.0%
metadata-eval88.0%
sqrt-unprod42.7%
add-sqr-sqrt88.0%
Applied egg-rr88.0%
Final simplification79.1%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))) (t_1 (+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))))
(if (<= p_m 1.25e-289)
t_0
(if (<= p_m 3.75e-233)
t_1
(if (<= p_m 8.8e-126) t_0 (if (<= p_m 3.8e-63) t_1 (sqrt 0.5)))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = p_m / -x;
double t_1 = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
double tmp;
if (p_m <= 1.25e-289) {
tmp = t_0;
} else if (p_m <= 3.75e-233) {
tmp = t_1;
} else if (p_m <= 8.8e-126) {
tmp = t_0;
} else if (p_m <= 3.8e-63) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = p_m / -x
t_1 = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
if (p_m <= 1.25d-289) then
tmp = t_0
else if (p_m <= 3.75d-233) then
tmp = t_1
else if (p_m <= 8.8d-126) then
tmp = t_0
else if (p_m <= 3.8d-63) then
tmp = t_1
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 t_1 = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
double tmp;
if (p_m <= 1.25e-289) {
tmp = t_0;
} else if (p_m <= 3.75e-233) {
tmp = t_1;
} else if (p_m <= 8.8e-126) {
tmp = t_0;
} else if (p_m <= 3.8e-63) {
tmp = t_1;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = p_m / -x t_1 = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))) tmp = 0 if p_m <= 1.25e-289: tmp = t_0 elif p_m <= 3.75e-233: tmp = t_1 elif p_m <= 8.8e-126: tmp = t_0 elif p_m <= 3.8e-63: tmp = t_1 else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(p_m / Float64(-x)) t_1 = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x)))) tmp = 0.0 if (p_m <= 1.25e-289) tmp = t_0; elseif (p_m <= 3.75e-233) tmp = t_1; elseif (p_m <= 8.8e-126) tmp = t_0; elseif (p_m <= 3.8e-63) tmp = t_1; 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; t_1 = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))); tmp = 0.0; if (p_m <= 1.25e-289) tmp = t_0; elseif (p_m <= 3.75e-233) tmp = t_1; elseif (p_m <= 8.8e-126) tmp = t_0; elseif (p_m <= 3.8e-63) tmp = t_1; 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]}, Block[{t$95$1 = N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p$95$m, 1.25e-289], t$95$0, If[LessEqual[p$95$m, 3.75e-233], t$95$1, If[LessEqual[p$95$m, 8.8e-126], t$95$0, If[LessEqual[p$95$m, 3.8e-63], t$95$1, N[Sqrt[0.5], $MachinePrecision]]]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \frac{p\_m}{-x}\\
t_1 := 1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\
\mathbf{if}\;p\_m \leq 1.25 \cdot 10^{-289}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 3.75 \cdot 10^{-233}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;p\_m \leq 8.8 \cdot 10^{-126}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 3.8 \cdot 10^{-63}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.25000000000000007e-289 or 3.74999999999999987e-233 < p < 8.80000000000000058e-126Initial program 75.6%
add-sqr-sqrt75.0%
pow275.0%
Applied egg-rr75.0%
Taylor expanded in x around -inf 14.4%
mul-1-neg14.4%
distribute-neg-frac214.4%
Simplified14.4%
if 1.25000000000000007e-289 < p < 3.74999999999999987e-233 or 8.80000000000000058e-126 < p < 3.80000000000000017e-63Initial program 95.7%
add-sqr-sqrt95.7%
pow295.7%
Applied egg-rr95.7%
Taylor expanded in x around inf 86.0%
unpow286.0%
unpow286.0%
times-frac86.0%
Applied egg-rr86.0%
if 3.80000000000000017e-63 < p Initial program 88.7%
Taylor expanded in x around 0 82.4%
Final simplification40.7%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))))
(if (<= p_m 1.32e-288)
t_0
(if (<= p_m 1.4e-233)
(+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))
(if (<= p_m 1.08e-125) t_0 (if (<= p_m 2.15e-63) 1.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 <= 1.32e-288) {
tmp = t_0;
} else if (p_m <= 1.4e-233) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 1.08e-125) {
tmp = t_0;
} else if (p_m <= 2.15e-63) {
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) :: t_0
real(8) :: tmp
t_0 = p_m / -x
if (p_m <= 1.32d-288) then
tmp = t_0
else if (p_m <= 1.4d-233) then
tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
else if (p_m <= 1.08d-125) then
tmp = t_0
else if (p_m <= 2.15d-63) 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 t_0 = p_m / -x;
double tmp;
if (p_m <= 1.32e-288) {
tmp = t_0;
} else if (p_m <= 1.4e-233) {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
} else if (p_m <= 1.08e-125) {
tmp = t_0;
} else if (p_m <= 2.15e-63) {
tmp = 1.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 <= 1.32e-288: tmp = t_0 elif p_m <= 1.4e-233: tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))) elif p_m <= 1.08e-125: tmp = t_0 elif p_m <= 2.15e-63: tmp = 1.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 <= 1.32e-288) tmp = t_0; elseif (p_m <= 1.4e-233) tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x)))); elseif (p_m <= 1.08e-125) tmp = t_0; elseif (p_m <= 2.15e-63) tmp = 1.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 <= 1.32e-288) tmp = t_0; elseif (p_m <= 1.4e-233) tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))); elseif (p_m <= 1.08e-125) tmp = t_0; elseif (p_m <= 2.15e-63) tmp = 1.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, 1.32e-288], t$95$0, If[LessEqual[p$95$m, 1.4e-233], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 1.08e-125], t$95$0, If[LessEqual[p$95$m, 2.15e-63], 1.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 1.32 \cdot 10^{-288}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 1.4 \cdot 10^{-233}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\
\mathbf{elif}\;p\_m \leq 1.08 \cdot 10^{-125}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 2.15 \cdot 10^{-63}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.31999999999999999e-288 or 1.4000000000000001e-233 < p < 1.07999999999999998e-125Initial program 75.6%
add-sqr-sqrt75.0%
pow275.0%
Applied egg-rr75.0%
Taylor expanded in x around -inf 14.4%
mul-1-neg14.4%
distribute-neg-frac214.4%
Simplified14.4%
if 1.31999999999999999e-288 < p < 1.4000000000000001e-233Initial program 91.8%
add-sqr-sqrt91.8%
pow291.8%
Applied egg-rr91.8%
Taylor expanded in x around inf 91.2%
unpow291.2%
unpow291.2%
times-frac91.2%
Applied egg-rr91.2%
if 1.07999999999999998e-125 < p < 2.1499999999999999e-63Initial program 100.0%
Taylor expanded in x around inf 84.0%
if 2.1499999999999999e-63 < p Initial program 88.7%
Taylor expanded in x around 0 82.4%
Final simplification40.8%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x 1.1e-146) (/ p_m (- x)) (+ 1.0 (* -0.5 (* (/ p_m x) (/ p_m x))))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= 1.1e-146) {
tmp = p_m / -x;
} else {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.1d-146) then
tmp = p_m / -x
else
tmp = 1.0d0 + ((-0.5d0) * ((p_m / x) * (p_m / x)))
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= 1.1e-146) {
tmp = p_m / -x;
} else {
tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x)));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= 1.1e-146: tmp = p_m / -x else: tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= 1.1e-146) tmp = Float64(p_m / Float64(-x)); else tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p_m / x) * Float64(p_m / x)))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= 1.1e-146) tmp = p_m / -x; else tmp = 1.0 + (-0.5 * ((p_m / x) * (p_m / x))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, 1.1e-146], N[(p$95$m / (-x)), $MachinePrecision], N[(1.0 + N[(-0.5 * N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.1 \cdot 10^{-146}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right)\\
\end{array}
\end{array}
if x < 1.1e-146Initial program 61.8%
add-sqr-sqrt61.0%
pow261.0%
Applied egg-rr61.0%
Taylor expanded in x around -inf 24.3%
mul-1-neg24.3%
distribute-neg-frac224.3%
Simplified24.3%
if 1.1e-146 < x Initial program 100.0%
add-sqr-sqrt99.2%
pow299.2%
Applied egg-rr99.3%
Taylor expanded in x around inf 51.6%
unpow251.6%
unpow251.6%
times-frac51.6%
Applied egg-rr51.6%
Final simplification38.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 / 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 81.2%
add-sqr-sqrt80.4%
pow280.4%
Applied egg-rr80.4%
Taylor expanded in x around -inf 13.8%
mul-1-neg13.8%
distribute-neg-frac213.8%
Simplified13.8%
Final simplification13.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 2024071
(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))))))))