
(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}
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (hypot x (* p 2.0))))
(if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0)
(/ (- p) x)
(sqrt
(*
0.5
(fma
(/ (pow (cbrt x) 2.0) (pow (cbrt t_0) 2.0))
(cbrt (/ x t_0))
1.0))))))p = abs(p);
double code(double p, double x) {
double t_0 = hypot(x, (p * 2.0));
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = -p / x;
} else {
tmp = sqrt((0.5 * fma((pow(cbrt(x), 2.0) / pow(cbrt(t_0), 2.0)), cbrt((x / t_0)), 1.0)));
}
return tmp;
}
p = abs(p) function code(p, x) t_0 = hypot(x, Float64(p * 2.0)) 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 * fma(Float64((cbrt(x) ^ 2.0) / (cbrt(t_0) ^ 2.0)), cbrt(Float64(x / t_0)), 1.0))); end return tmp end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, 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[(N[(N[Power[N[Power[x, 1/3], $MachinePrecision], 2.0], $MachinePrecision] / N[Power[N[Power[t$95$0, 1/3], $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision] * N[Power[N[(x / t$95$0), $MachinePrecision], 1/3], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, p \cdot 2\right)\\
\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 \cdot \mathsf{fma}\left(\frac{{\left(\sqrt[3]{x}\right)}^{2}}{{\left(\sqrt[3]{t_0}\right)}^{2}}, \sqrt[3]{\frac{x}{t_0}}, 1\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1Initial program 14.1%
Taylor expanded in x around -inf 52.3%
unpow252.3%
associate-*r/52.3%
unpow252.3%
Simplified52.3%
Taylor expanded in p around -inf 57.7%
associate-*r/57.7%
mul-1-neg57.7%
Simplified57.7%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.7%
+-commutative99.7%
add-cbrt-cube80.9%
cbrt-prod99.6%
add-cbrt-cube88.6%
add-sqr-sqrt88.6%
cbrt-prod99.7%
times-frac99.7%
cbrt-div99.7%
fma-def99.7%
Applied egg-rr99.8%
Final simplification89.2%
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) (exp (* 0.5 (log (fma (/ x (hypot x (* p 2.0))) 0.5 0.5))))))
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 = exp((0.5 * log(fma((x / hypot(x, (p * 2.0))), 0.5, 0.5))));
}
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 = exp(Float64(0.5 * log(fma(Float64(x / hypot(x, Float64(p * 2.0))), 0.5, 0.5)))); end return 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[Exp[N[(0.5 * N[Log[N[(N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * 0.5 + 0.5), $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}:\\
\;\;\;\;e^{0.5 \cdot \log \left(\mathsf{fma}\left(\frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}, 0.5, 0.5\right)\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1Initial program 14.1%
Taylor expanded in x around -inf 52.3%
unpow252.3%
associate-*r/52.3%
unpow252.3%
Simplified52.3%
Taylor expanded in p around -inf 57.7%
associate-*r/57.7%
mul-1-neg57.7%
Simplified57.7%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.7%
pow1/299.7%
pow-to-exp99.7%
Applied egg-rr99.8%
Final simplification89.2%
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 (+ 1.0 (/ x (hypot (* p 2.0) x)))))))
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 * (1.0 + (x / hypot((p * 2.0), x)))));
}
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 * (1.0 + (x / Math.hypot((p * 2.0), x)))));
}
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 * (1.0 + (x / math.hypot((p * 2.0), x))))) 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(1.0 + Float64(x / hypot(Float64(p * 2.0), x))))); 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 * (1.0 + (x / hypot((p * 2.0), x))))); 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[(1.0 + N[(x / N[Sqrt[N[(p * 2.0), $MachinePrecision] ^ 2 + x ^ 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 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p \cdot 2, x\right)}\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1Initial program 14.1%
Taylor expanded in x around -inf 52.3%
unpow252.3%
associate-*r/52.3%
unpow252.3%
Simplified52.3%
Taylor expanded in p around -inf 57.7%
associate-*r/57.7%
mul-1-neg57.7%
Simplified57.7%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.7%
add-sqr-sqrt99.7%
hypot-def99.7%
associate-*l*99.7%
sqrt-prod99.7%
metadata-eval99.7%
sqrt-unprod52.5%
add-sqr-sqrt99.7%
Applied egg-rr99.7%
Final simplification89.2%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(if (<= p 3.2e-267)
1.0
(if (<= p 1.8e-81)
(/ (- p) x)
(if (<= p 0.00146)
(sqrt 0.5)
(if (<= p 29000000000000.0)
(sqrt (* 0.5 (* 2.0 (* (/ p x) (/ p x)))))
(sqrt (* 0.5 (+ 1.0 (/ x (* p 2.0))))))))))p = abs(p);
double code(double p, double x) {
double tmp;
if (p <= 3.2e-267) {
tmp = 1.0;
} else if (p <= 1.8e-81) {
tmp = -p / x;
} else if (p <= 0.00146) {
tmp = sqrt(0.5);
} else if (p <= 29000000000000.0) {
tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
} else {
tmp = sqrt((0.5 * (1.0 + (x / (p * 2.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 (p <= 3.2d-267) then
tmp = 1.0d0
else if (p <= 1.8d-81) then
tmp = -p / x
else if (p <= 0.00146d0) then
tmp = sqrt(0.5d0)
else if (p <= 29000000000000.0d0) then
tmp = sqrt((0.5d0 * (2.0d0 * ((p / x) * (p / x)))))
else
tmp = sqrt((0.5d0 * (1.0d0 + (x / (p * 2.0d0)))))
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if (p <= 3.2e-267) {
tmp = 1.0;
} else if (p <= 1.8e-81) {
tmp = -p / x;
} else if (p <= 0.00146) {
tmp = Math.sqrt(0.5);
} else if (p <= 29000000000000.0) {
tmp = Math.sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / (p * 2.0)))));
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if p <= 3.2e-267: tmp = 1.0 elif p <= 1.8e-81: tmp = -p / x elif p <= 0.00146: tmp = math.sqrt(0.5) elif p <= 29000000000000.0: tmp = math.sqrt((0.5 * (2.0 * ((p / x) * (p / x))))) else: tmp = math.sqrt((0.5 * (1.0 + (x / (p * 2.0))))) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (p <= 3.2e-267) tmp = 1.0; elseif (p <= 1.8e-81) tmp = Float64(Float64(-p) / x); elseif (p <= 0.00146) tmp = sqrt(0.5); elseif (p <= 29000000000000.0) tmp = sqrt(Float64(0.5 * Float64(2.0 * Float64(Float64(p / x) * Float64(p / x))))); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / Float64(p * 2.0))))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if (p <= 3.2e-267) tmp = 1.0; elseif (p <= 1.8e-81) tmp = -p / x; elseif (p <= 0.00146) tmp = sqrt(0.5); elseif (p <= 29000000000000.0) tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x))))); else tmp = sqrt((0.5 * (1.0 + (x / (p * 2.0))))); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[p, 3.2e-267], 1.0, If[LessEqual[p, 1.8e-81], N[((-p) / x), $MachinePrecision], If[LessEqual[p, 0.00146], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 29000000000000.0], N[Sqrt[N[(0.5 * N[(2.0 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[(p * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;p \leq 3.2 \cdot 10^{-267}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.8 \cdot 10^{-81}:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{elif}\;p \leq 0.00146:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p \leq 29000000000000:\\
\;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{p \cdot 2}\right)}\\
\end{array}
\end{array}
if p < 3.19999999999999986e-267Initial program 77.8%
add-sqr-sqrt77.8%
hypot-def77.9%
associate-*l*77.9%
sqrt-prod77.9%
metadata-eval77.9%
sqrt-unprod6.2%
add-sqr-sqrt77.9%
Applied egg-rr77.9%
add-cbrt-cube77.8%
pow1/377.9%
add-sqr-sqrt77.9%
pow177.9%
pow1/277.9%
pow-prod-up77.8%
distribute-lft-in77.8%
metadata-eval77.8%
metadata-eval77.8%
Applied egg-rr77.8%
Taylor expanded in x around inf 35.1%
if 3.19999999999999986e-267 < p < 1.7999999999999999e-81Initial program 48.8%
Taylor expanded in x around -inf 22.7%
unpow222.7%
associate-*r/22.7%
unpow222.7%
Simplified22.7%
Taylor expanded in p around -inf 57.8%
associate-*r/57.8%
mul-1-neg57.8%
Simplified57.8%
if 1.7999999999999999e-81 < p < 0.0014599999999999999Initial program 84.1%
Taylor expanded in x around 0 50.8%
if 0.0014599999999999999 < p < 2.9e13Initial program 52.0%
Taylor expanded in x around -inf 53.3%
unpow253.3%
unpow253.3%
times-frac53.3%
Simplified53.3%
if 2.9e13 < p Initial program 95.6%
Taylor expanded in p around inf 89.3%
Final simplification54.0%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ (- p) x)))
(if (<= p 7e-268)
1.0
(if (<= p 1.05e-80)
t_0
(if (<= p 0.000205)
(sqrt 0.5)
(if (<= p 1.3e+14) t_0 (sqrt (* 0.5 (+ 1.0 (/ x (* p 2.0)))))))))))p = abs(p);
double code(double p, double x) {
double t_0 = -p / x;
double tmp;
if (p <= 7e-268) {
tmp = 1.0;
} else if (p <= 1.05e-80) {
tmp = t_0;
} else if (p <= 0.000205) {
tmp = sqrt(0.5);
} else if (p <= 1.3e+14) {
tmp = t_0;
} else {
tmp = sqrt((0.5 * (1.0 + (x / (p * 2.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 (p <= 7d-268) then
tmp = 1.0d0
else if (p <= 1.05d-80) then
tmp = t_0
else if (p <= 0.000205d0) then
tmp = sqrt(0.5d0)
else if (p <= 1.3d+14) then
tmp = t_0
else
tmp = sqrt((0.5d0 * (1.0d0 + (x / (p * 2.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 (p <= 7e-268) {
tmp = 1.0;
} else if (p <= 1.05e-80) {
tmp = t_0;
} else if (p <= 0.000205) {
tmp = Math.sqrt(0.5);
} else if (p <= 1.3e+14) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / (p * 2.0)))));
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = -p / x tmp = 0 if p <= 7e-268: tmp = 1.0 elif p <= 1.05e-80: tmp = t_0 elif p <= 0.000205: tmp = math.sqrt(0.5) elif p <= 1.3e+14: tmp = t_0 else: tmp = math.sqrt((0.5 * (1.0 + (x / (p * 2.0))))) return tmp
p = abs(p) function code(p, x) t_0 = Float64(Float64(-p) / x) tmp = 0.0 if (p <= 7e-268) tmp = 1.0; elseif (p <= 1.05e-80) tmp = t_0; elseif (p <= 0.000205) tmp = sqrt(0.5); elseif (p <= 1.3e+14) tmp = t_0; else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / Float64(p * 2.0))))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = -p / x; tmp = 0.0; if (p <= 7e-268) tmp = 1.0; elseif (p <= 1.05e-80) tmp = t_0; elseif (p <= 0.000205) tmp = sqrt(0.5); elseif (p <= 1.3e+14) tmp = t_0; else tmp = sqrt((0.5 * (1.0 + (x / (p * 2.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[p, 7e-268], 1.0, If[LessEqual[p, 1.05e-80], t$95$0, If[LessEqual[p, 0.000205], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 1.3e+14], t$95$0, N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[(p * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{-p}{x}\\
\mathbf{if}\;p \leq 7 \cdot 10^{-268}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.05 \cdot 10^{-80}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 0.000205:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p \leq 1.3 \cdot 10^{+14}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{p \cdot 2}\right)}\\
\end{array}
\end{array}
if p < 7.00000000000000011e-268Initial program 77.8%
add-sqr-sqrt77.8%
hypot-def77.9%
associate-*l*77.9%
sqrt-prod77.9%
metadata-eval77.9%
sqrt-unprod6.2%
add-sqr-sqrt77.9%
Applied egg-rr77.9%
add-cbrt-cube77.8%
pow1/377.9%
add-sqr-sqrt77.9%
pow177.9%
pow1/277.9%
pow-prod-up77.8%
distribute-lft-in77.8%
metadata-eval77.8%
metadata-eval77.8%
Applied egg-rr77.8%
Taylor expanded in x around inf 35.1%
if 7.00000000000000011e-268 < p < 1.05000000000000001e-80 or 2.05e-4 < p < 1.3e14Initial program 49.1%
Taylor expanded in x around -inf 25.7%
unpow225.7%
associate-*r/25.7%
unpow225.7%
Simplified25.7%
Taylor expanded in p around -inf 57.1%
associate-*r/57.1%
mul-1-neg57.1%
Simplified57.1%
if 1.05000000000000001e-80 < p < 2.05e-4Initial program 84.1%
Taylor expanded in x around 0 50.8%
if 1.3e14 < p Initial program 95.6%
Taylor expanded in p around inf 89.3%
Final simplification54.0%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(if (<= p 2.6e-269)
1.0
(if (or (<= p 6.5e-82) (and (not (<= p 0.00083)) (<= p 29000000000000.0)))
(/ (- p) x)
(sqrt 0.5))))p = abs(p);
double code(double p, double x) {
double tmp;
if (p <= 2.6e-269) {
tmp = 1.0;
} else if ((p <= 6.5e-82) || (!(p <= 0.00083) && (p <= 29000000000000.0))) {
tmp = -p / x;
} else {
tmp = sqrt(0.5);
}
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 (p <= 2.6d-269) then
tmp = 1.0d0
else if ((p <= 6.5d-82) .or. (.not. (p <= 0.00083d0)) .and. (p <= 29000000000000.0d0)) then
tmp = -p / x
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if (p <= 2.6e-269) {
tmp = 1.0;
} else if ((p <= 6.5e-82) || (!(p <= 0.00083) && (p <= 29000000000000.0))) {
tmp = -p / x;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if p <= 2.6e-269: tmp = 1.0 elif (p <= 6.5e-82) or (not (p <= 0.00083) and (p <= 29000000000000.0)): tmp = -p / x else: tmp = math.sqrt(0.5) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (p <= 2.6e-269) tmp = 1.0; elseif ((p <= 6.5e-82) || (!(p <= 0.00083) && (p <= 29000000000000.0))) tmp = Float64(Float64(-p) / x); else tmp = sqrt(0.5); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if (p <= 2.6e-269) tmp = 1.0; elseif ((p <= 6.5e-82) || (~((p <= 0.00083)) && (p <= 29000000000000.0))) tmp = -p / x; else tmp = sqrt(0.5); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[p, 2.6e-269], 1.0, If[Or[LessEqual[p, 6.5e-82], And[N[Not[LessEqual[p, 0.00083]], $MachinePrecision], LessEqual[p, 29000000000000.0]]], N[((-p) / x), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;p \leq 2.6 \cdot 10^{-269}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 6.5 \cdot 10^{-82} \lor \neg \left(p \leq 0.00083\right) \land p \leq 29000000000000:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 2.6e-269Initial program 77.8%
add-sqr-sqrt77.8%
hypot-def77.9%
associate-*l*77.9%
sqrt-prod77.9%
metadata-eval77.9%
sqrt-unprod6.2%
add-sqr-sqrt77.9%
Applied egg-rr77.9%
add-cbrt-cube77.8%
pow1/377.9%
add-sqr-sqrt77.9%
pow177.9%
pow1/277.9%
pow-prod-up77.8%
distribute-lft-in77.8%
metadata-eval77.8%
metadata-eval77.8%
Applied egg-rr77.8%
Taylor expanded in x around inf 35.1%
if 2.6e-269 < p < 6.4999999999999997e-82 or 8.3000000000000001e-4 < p < 2.9e13Initial program 49.1%
Taylor expanded in x around -inf 25.7%
unpow225.7%
associate-*r/25.7%
unpow225.7%
Simplified25.7%
Taylor expanded in p around -inf 57.1%
associate-*r/57.1%
mul-1-neg57.1%
Simplified57.1%
if 6.4999999999999997e-82 < p < 8.3000000000000001e-4 or 2.9e13 < p Initial program 93.9%
Taylor expanded in x around 0 83.5%
Final simplification53.9%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= x -1.65e-127) (/ (- p) x) 1.0))
p = abs(p);
double code(double p, double x) {
double tmp;
if (x <= -1.65e-127) {
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 <= (-1.65d-127)) 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 <= -1.65e-127) {
tmp = -p / x;
} else {
tmp = 1.0;
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if x <= -1.65e-127: tmp = -p / x else: tmp = 1.0 return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (x <= -1.65e-127) 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 <= -1.65e-127) 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, -1.65e-127], N[((-p) / x), $MachinePrecision], 1.0]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-127}:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -1.6499999999999999e-127Initial program 58.7%
Taylor expanded in x around -inf 28.7%
unpow228.7%
associate-*r/28.7%
unpow228.7%
Simplified28.7%
Taylor expanded in p around -inf 30.0%
associate-*r/30.0%
mul-1-neg30.0%
Simplified30.0%
if -1.6499999999999999e-127 < x Initial program 99.2%
add-sqr-sqrt99.2%
hypot-def99.2%
associate-*l*99.2%
sqrt-prod99.2%
metadata-eval99.2%
sqrt-unprod49.2%
add-sqr-sqrt99.2%
Applied egg-rr99.2%
add-cbrt-cube99.2%
pow1/399.2%
add-sqr-sqrt99.2%
pow199.2%
pow1/299.2%
pow-prod-up99.2%
distribute-lft-in99.2%
metadata-eval99.2%
metadata-eval99.2%
Applied egg-rr99.2%
Taylor expanded in x around inf 56.5%
Final simplification42.8%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= x -3.6e+85) (/ p x) 1.0))
p = abs(p);
double code(double p, double x) {
double tmp;
if (x <= -3.6e+85) {
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 <= (-3.6d+85)) 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 <= -3.6e+85) {
tmp = p / x;
} else {
tmp = 1.0;
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if x <= -3.6e+85: tmp = p / x else: tmp = 1.0 return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (x <= -3.6e+85) tmp = 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 <= -3.6e+85) 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, -3.6e+85], N[(p / x), $MachinePrecision], 1.0]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.6 \cdot 10^{+85}:\\
\;\;\;\;\frac{p}{x}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -3.5999999999999998e85Initial program 49.5%
Taylor expanded in x around -inf 55.9%
unpow255.9%
associate-*r/55.9%
unpow255.9%
Simplified55.9%
Taylor expanded in p around 0 44.8%
if -3.5999999999999998e85 < x Initial program 81.9%
add-sqr-sqrt81.9%
hypot-def81.9%
associate-*l*81.9%
sqrt-prod81.9%
metadata-eval81.9%
sqrt-unprod42.6%
add-sqr-sqrt81.9%
Applied egg-rr81.9%
add-cbrt-cube81.8%
pow1/381.9%
add-sqr-sqrt81.9%
pow181.9%
pow1/281.9%
pow-prod-up81.9%
distribute-lft-in81.9%
metadata-eval81.9%
metadata-eval81.9%
Applied egg-rr81.9%
Taylor expanded in x around inf 37.1%
Final simplification37.9%
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 78.3%
add-sqr-sqrt78.3%
hypot-def78.3%
associate-*l*78.3%
sqrt-prod78.3%
metadata-eval78.3%
sqrt-unprod40.9%
add-sqr-sqrt78.3%
Applied egg-rr78.3%
add-cbrt-cube78.3%
pow1/378.3%
add-sqr-sqrt78.3%
pow178.3%
pow1/278.3%
pow-prod-up78.3%
distribute-lft-in78.3%
metadata-eval78.3%
metadata-eval78.3%
Applied egg-rr78.3%
Taylor expanded in x around inf 33.9%
Final simplification33.9%
(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 2023229
(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))))))))