
(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 5 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}
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0) (- (/ p x)) (sqrt (+ 0.5 (* 0.5 (/ x (hypot x (* p 2.0))))))))
p = abs(p);
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = -(p / x);
} else {
tmp = sqrt((0.5 + (0.5 * (x / hypot(x, (p * 2.0))))));
}
return tmp;
}
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = -(p / x);
} else {
tmp = Math.sqrt((0.5 + (0.5 * (x / Math.hypot(x, (p * 2.0))))));
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0: tmp = -(p / x) else: tmp = math.sqrt((0.5 + (0.5 * (x / math.hypot(x, (p * 2.0)))))) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0) tmp = Float64(-Float64(p / x)); else tmp = sqrt(Float64(0.5 + Float64(0.5 * Float64(x / hypot(x, Float64(p * 2.0)))))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) tmp = -(p / x); else tmp = sqrt((0.5 + (0.5 * (x / hypot(x, (p * 2.0)))))); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], (-N[(p / x), $MachinePrecision]), N[Sqrt[N[(0.5 + N[(0.5 * N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;-\frac{p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + 0.5 \cdot \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1Initial program 12.6%
expm1-log1p-u12.6%
expm1-udef12.6%
Applied egg-rr12.6%
expm1-def12.6%
expm1-log1p12.6%
*-commutative12.6%
Simplified12.6%
Taylor expanded in x around -inf 47.7%
mul-1-neg47.7%
Simplified47.7%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 100.0%
expm1-log1p-u99.0%
expm1-udef98.9%
Applied egg-rr98.9%
expm1-def99.0%
expm1-log1p100.0%
*-commutative100.0%
Simplified100.0%
Final simplification85.7%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (- (/ p x))))
(if (<= x -14000000.0)
t_0
(if (<= x -8e-54)
(sqrt 0.5)
(if (<= x -1.05e-81)
t_0
(if (<= x 1.45)
(sqrt 0.5)
(if (<= x 3.95e+87) 1.0 (if (<= x 1.9e+101) (sqrt 0.5) 1.0))))))))p = abs(p);
double code(double p, double x) {
double t_0 = -(p / x);
double tmp;
if (x <= -14000000.0) {
tmp = t_0;
} else if (x <= -8e-54) {
tmp = sqrt(0.5);
} else if (x <= -1.05e-81) {
tmp = t_0;
} else if (x <= 1.45) {
tmp = sqrt(0.5);
} else if (x <= 3.95e+87) {
tmp = 1.0;
} else if (x <= 1.9e+101) {
tmp = sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = -(p / x)
if (x <= (-14000000.0d0)) then
tmp = t_0
else if (x <= (-8d-54)) then
tmp = sqrt(0.5d0)
else if (x <= (-1.05d-81)) then
tmp = t_0
else if (x <= 1.45d0) then
tmp = sqrt(0.5d0)
else if (x <= 3.95d+87) then
tmp = 1.0d0
else if (x <= 1.9d+101) then
tmp = sqrt(0.5d0)
else
tmp = 1.0d0
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double t_0 = -(p / x);
double tmp;
if (x <= -14000000.0) {
tmp = t_0;
} else if (x <= -8e-54) {
tmp = Math.sqrt(0.5);
} else if (x <= -1.05e-81) {
tmp = t_0;
} else if (x <= 1.45) {
tmp = Math.sqrt(0.5);
} else if (x <= 3.95e+87) {
tmp = 1.0;
} else if (x <= 1.9e+101) {
tmp = Math.sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = -(p / x) tmp = 0 if x <= -14000000.0: tmp = t_0 elif x <= -8e-54: tmp = math.sqrt(0.5) elif x <= -1.05e-81: tmp = t_0 elif x <= 1.45: tmp = math.sqrt(0.5) elif x <= 3.95e+87: tmp = 1.0 elif x <= 1.9e+101: tmp = math.sqrt(0.5) else: tmp = 1.0 return tmp
p = abs(p) function code(p, x) t_0 = Float64(-Float64(p / x)) tmp = 0.0 if (x <= -14000000.0) tmp = t_0; elseif (x <= -8e-54) tmp = sqrt(0.5); elseif (x <= -1.05e-81) tmp = t_0; elseif (x <= 1.45) tmp = sqrt(0.5); elseif (x <= 3.95e+87) tmp = 1.0; elseif (x <= 1.9e+101) tmp = sqrt(0.5); else tmp = 1.0; end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = -(p / x); tmp = 0.0; if (x <= -14000000.0) tmp = t_0; elseif (x <= -8e-54) tmp = sqrt(0.5); elseif (x <= -1.05e-81) tmp = t_0; elseif (x <= 1.45) tmp = sqrt(0.5); elseif (x <= 3.95e+87) tmp = 1.0; elseif (x <= 1.9e+101) tmp = sqrt(0.5); else tmp = 1.0; end tmp_2 = tmp; end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = (-N[(p / x), $MachinePrecision])}, If[LessEqual[x, -14000000.0], t$95$0, If[LessEqual[x, -8e-54], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[x, -1.05e-81], t$95$0, If[LessEqual[x, 1.45], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[x, 3.95e+87], 1.0, If[LessEqual[x, 1.9e+101], N[Sqrt[0.5], $MachinePrecision], 1.0]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := -\frac{p}{x}\\
\mathbf{if}\;x \leq -14000000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -8 \cdot 10^{-54}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;x \leq -1.05 \cdot 10^{-81}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 1.45:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;x \leq 3.95 \cdot 10^{+87}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{+101}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.4e7 or -8.0000000000000002e-54 < x < -1.05e-81Initial program 36.6%
expm1-log1p-u36.3%
expm1-udef36.2%
Applied egg-rr36.2%
expm1-def36.3%
expm1-log1p36.6%
*-commutative36.6%
Simplified36.6%
Taylor expanded in x around -inf 46.8%
mul-1-neg46.8%
Simplified46.8%
if -1.4e7 < x < -8.0000000000000002e-54 or -1.05e-81 < x < 1.44999999999999996 or 3.9499999999999998e87 < x < 1.8999999999999999e101Initial program 86.2%
Taylor expanded in x around 0 72.6%
if 1.44999999999999996 < x < 3.9499999999999998e87 or 1.8999999999999999e101 < x Initial program 100.0%
expm1-log1p-u99.6%
distribute-rgt-in99.6%
metadata-eval99.6%
+-commutative99.6%
add-sqr-sqrt99.6%
hypot-def99.6%
associate-*l*99.6%
sqrt-prod99.6%
metadata-eval99.6%
sqrt-unprod44.5%
add-sqr-sqrt99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 78.0%
Final simplification66.9%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (- (/ p x))))
(if (<= x -950000.0)
t_0
(if (<= x -1.7e-54)
(sqrt (+ 0.5 (/ (* x 0.25) p)))
(if (<= x -7e-81)
t_0
(if (<= x 0.5)
(sqrt 0.5)
(if (<= x 1e+87) 1.0 (if (<= x 5.4e+101) (sqrt 0.5) 1.0))))))))p = abs(p);
double code(double p, double x) {
double t_0 = -(p / x);
double tmp;
if (x <= -950000.0) {
tmp = t_0;
} else if (x <= -1.7e-54) {
tmp = sqrt((0.5 + ((x * 0.25) / p)));
} else if (x <= -7e-81) {
tmp = t_0;
} else if (x <= 0.5) {
tmp = sqrt(0.5);
} else if (x <= 1e+87) {
tmp = 1.0;
} else if (x <= 5.4e+101) {
tmp = sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = -(p / x)
if (x <= (-950000.0d0)) then
tmp = t_0
else if (x <= (-1.7d-54)) then
tmp = sqrt((0.5d0 + ((x * 0.25d0) / p)))
else if (x <= (-7d-81)) then
tmp = t_0
else if (x <= 0.5d0) then
tmp = sqrt(0.5d0)
else if (x <= 1d+87) then
tmp = 1.0d0
else if (x <= 5.4d+101) then
tmp = sqrt(0.5d0)
else
tmp = 1.0d0
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double t_0 = -(p / x);
double tmp;
if (x <= -950000.0) {
tmp = t_0;
} else if (x <= -1.7e-54) {
tmp = Math.sqrt((0.5 + ((x * 0.25) / p)));
} else if (x <= -7e-81) {
tmp = t_0;
} else if (x <= 0.5) {
tmp = Math.sqrt(0.5);
} else if (x <= 1e+87) {
tmp = 1.0;
} else if (x <= 5.4e+101) {
tmp = Math.sqrt(0.5);
} else {
tmp = 1.0;
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = -(p / x) tmp = 0 if x <= -950000.0: tmp = t_0 elif x <= -1.7e-54: tmp = math.sqrt((0.5 + ((x * 0.25) / p))) elif x <= -7e-81: tmp = t_0 elif x <= 0.5: tmp = math.sqrt(0.5) elif x <= 1e+87: tmp = 1.0 elif x <= 5.4e+101: tmp = math.sqrt(0.5) else: tmp = 1.0 return tmp
p = abs(p) function code(p, x) t_0 = Float64(-Float64(p / x)) tmp = 0.0 if (x <= -950000.0) tmp = t_0; elseif (x <= -1.7e-54) tmp = sqrt(Float64(0.5 + Float64(Float64(x * 0.25) / p))); elseif (x <= -7e-81) tmp = t_0; elseif (x <= 0.5) tmp = sqrt(0.5); elseif (x <= 1e+87) tmp = 1.0; elseif (x <= 5.4e+101) tmp = sqrt(0.5); else tmp = 1.0; end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = -(p / x); tmp = 0.0; if (x <= -950000.0) tmp = t_0; elseif (x <= -1.7e-54) tmp = sqrt((0.5 + ((x * 0.25) / p))); elseif (x <= -7e-81) tmp = t_0; elseif (x <= 0.5) tmp = sqrt(0.5); elseif (x <= 1e+87) tmp = 1.0; elseif (x <= 5.4e+101) tmp = sqrt(0.5); else tmp = 1.0; end tmp_2 = tmp; end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = (-N[(p / x), $MachinePrecision])}, If[LessEqual[x, -950000.0], t$95$0, If[LessEqual[x, -1.7e-54], N[Sqrt[N[(0.5 + N[(N[(x * 0.25), $MachinePrecision] / p), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, -7e-81], t$95$0, If[LessEqual[x, 0.5], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[x, 1e+87], 1.0, If[LessEqual[x, 5.4e+101], N[Sqrt[0.5], $MachinePrecision], 1.0]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := -\frac{p}{x}\\
\mathbf{if}\;x \leq -950000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -1.7 \cdot 10^{-54}:\\
\;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p}}\\
\mathbf{elif}\;x \leq -7 \cdot 10^{-81}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq 0.5:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;x \leq 10^{+87}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 5.4 \cdot 10^{+101}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -9.5e5 or -1.69999999999999994e-54 < x < -6.99999999999999973e-81Initial program 36.6%
expm1-log1p-u36.3%
expm1-udef36.2%
Applied egg-rr36.2%
expm1-def36.3%
expm1-log1p36.6%
*-commutative36.6%
Simplified36.6%
Taylor expanded in x around -inf 46.8%
mul-1-neg46.8%
Simplified46.8%
if -9.5e5 < x < -1.69999999999999994e-54Initial program 69.2%
expm1-log1p-u68.3%
expm1-udef68.3%
Applied egg-rr68.3%
expm1-def68.3%
expm1-log1p69.2%
*-commutative69.2%
Simplified69.2%
Taylor expanded in x around 0 65.6%
associate-*r/65.6%
Simplified65.6%
if -6.99999999999999973e-81 < x < 0.5 or 9.9999999999999996e86 < x < 5.40000000000000012e101Initial program 92.2%
Taylor expanded in x around 0 75.1%
if 0.5 < x < 9.9999999999999996e86 or 5.40000000000000012e101 < x Initial program 100.0%
expm1-log1p-u99.6%
distribute-rgt-in99.6%
metadata-eval99.6%
+-commutative99.6%
add-sqr-sqrt99.6%
hypot-def99.6%
associate-*l*99.6%
sqrt-prod99.6%
metadata-eval99.6%
sqrt-unprod44.5%
add-sqr-sqrt99.6%
Applied egg-rr99.6%
Taylor expanded in x around inf 78.0%
Final simplification66.9%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= x -8.5e-146) (- (/ p x)) 1.0))
p = abs(p);
double code(double p, double x) {
double tmp;
if (x <= -8.5e-146) {
tmp = -(p / x);
} else {
tmp = 1.0;
}
return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-8.5d-146)) then
tmp = -(p / x)
else
tmp = 1.0d0
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if (x <= -8.5e-146) {
tmp = -(p / x);
} else {
tmp = 1.0;
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if x <= -8.5e-146: tmp = -(p / x) else: tmp = 1.0 return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (x <= -8.5e-146) tmp = Float64(-Float64(p / x)); else tmp = 1.0; end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if (x <= -8.5e-146) tmp = -(p / x); else tmp = 1.0; end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[x, -8.5e-146], (-N[(p / x), $MachinePrecision]), 1.0]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.5 \cdot 10^{-146}:\\
\;\;\;\;-\frac{p}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -8.4999999999999997e-146Initial program 54.3%
expm1-log1p-u53.7%
expm1-udef53.6%
Applied egg-rr53.6%
expm1-def53.7%
expm1-log1p54.3%
*-commutative54.3%
Simplified54.3%
Taylor expanded in x around -inf 26.6%
mul-1-neg26.6%
Simplified26.6%
if -8.4999999999999997e-146 < x Initial program 100.0%
expm1-log1p-u99.2%
distribute-rgt-in99.2%
metadata-eval99.2%
+-commutative99.2%
add-sqr-sqrt99.2%
hypot-def99.2%
associate-*l*99.2%
sqrt-prod99.2%
metadata-eval99.2%
sqrt-unprod45.6%
add-sqr-sqrt99.2%
Applied egg-rr99.2%
Taylor expanded in x around inf 58.5%
Final simplification41.8%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 1.0)
p = abs(p);
double code(double p, double x) {
return 1.0;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = 1.0d0
end function
p = Math.abs(p);
public static double code(double p, double x) {
return 1.0;
}
p = abs(p) def code(p, x): return 1.0
p = abs(p) function code(p, x) return 1.0 end
p = abs(p) function tmp = code(p, x) tmp = 1.0; end
NOTE: p should be positive before calling this function code[p_, x_] := 1.0
\begin{array}{l}
p = |p|\\
\\
1
\end{array}
Initial program 76.1%
expm1-log1p-u75.4%
distribute-rgt-in75.4%
metadata-eval75.4%
+-commutative75.4%
add-sqr-sqrt75.4%
hypot-def75.4%
associate-*l*75.4%
sqrt-prod75.4%
metadata-eval75.4%
sqrt-unprod34.8%
add-sqr-sqrt75.4%
Applied egg-rr75.4%
Taylor expanded in x around inf 34.2%
Final simplification34.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 2023301
(FPCore (p x)
:name "Given's Rotation SVD example"
:precision binary64
:pre (and (< 1e-150 (fabs x)) (< (fabs x) 1e+150))
:herbie-target
(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))))))))