
(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 10 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
(let* ((t_0 (hypot x (* p_m 2.0))) (t_1 (/ t_0 x)) (t_2 (pow t_1 -3.0)))
(if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.99996)
(- (* 1.5 (pow (/ p_m x) 3.0)) (/ p_m x))
(/
(sqrt
(/
(fma 0.125 (pow t_2 3.0) 0.125)
(+ 0.25 (+ (* 0.25 (pow t_1 -6.0)) (* t_2 -0.25)))))
(sqrt (- (+ 1.0 (pow t_1 -2.0)) (/ x t_0)))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = hypot(x, (p_m * 2.0));
double t_1 = t_0 / x;
double t_2 = pow(t_1, -3.0);
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) {
tmp = (1.5 * pow((p_m / x), 3.0)) - (p_m / x);
} else {
tmp = sqrt((fma(0.125, pow(t_2, 3.0), 0.125) / (0.25 + ((0.25 * pow(t_1, -6.0)) + (t_2 * -0.25))))) / sqrt(((1.0 + pow(t_1, -2.0)) - (x / t_0)));
}
return tmp;
}
p_m = abs(p) function code(p_m, x) t_0 = hypot(x, Float64(p_m * 2.0)) t_1 = Float64(t_0 / x) t_2 = t_1 ^ -3.0 tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.99996) tmp = Float64(Float64(1.5 * (Float64(p_m / x) ^ 3.0)) - Float64(p_m / x)); else tmp = Float64(sqrt(Float64(fma(0.125, (t_2 ^ 3.0), 0.125) / Float64(0.25 + Float64(Float64(0.25 * (t_1 ^ -6.0)) + Float64(t_2 * -0.25))))) / sqrt(Float64(Float64(1.0 + (t_1 ^ -2.0)) - Float64(x / t_0)))); end return tmp end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / x), $MachinePrecision]}, Block[{t$95$2 = N[Power[t$95$1, -3.0], $MachinePrecision]}, 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.99996], N[(N[(1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(N[(0.125 * N[Power[t$95$2, 3.0], $MachinePrecision] + 0.125), $MachinePrecision] / N[(0.25 + N[(N[(0.25 * N[Power[t$95$1, -6.0], $MachinePrecision]), $MachinePrecision] + N[(t$95$2 * -0.25), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 + N[Power[t$95$1, -2.0], $MachinePrecision]), $MachinePrecision] - N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, p_m \cdot 2\right)\\
t_1 := \frac{t_0}{x}\\
t_2 := {t_1}^{-3}\\
\mathbf{if}\;\frac{x}{\sqrt{p_m \cdot \left(4 \cdot p_m\right) + x \cdot x}} \leq -0.99996:\\
\;\;\;\;1.5 \cdot {\left(\frac{p_m}{x}\right)}^{3} - \frac{p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{\frac{\mathsf{fma}\left(0.125, {t_2}^{3}, 0.125\right)}{0.25 + \left(0.25 \cdot {t_1}^{-6} + t_2 \cdot -0.25\right)}}}{\sqrt{\left(1 + {t_1}^{-2}\right) - \frac{x}{t_0}}}\\
\end{array}
\end{array}
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (hypot x (* p_m 2.0))) (t_1 (/ t_0 x)))
(if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.99996)
(- (* 1.5 (pow (/ p_m x) 3.0)) (/ p_m x))
(/
(log (exp (sqrt (fma 0.5 (pow t_1 -3.0) 0.5))))
(sqrt (- (+ 1.0 (pow t_1 -2.0)) (/ x t_0)))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = hypot(x, (p_m * 2.0));
double t_1 = t_0 / x;
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) {
tmp = (1.5 * pow((p_m / x), 3.0)) - (p_m / x);
} else {
tmp = log(exp(sqrt(fma(0.5, pow(t_1, -3.0), 0.5)))) / sqrt(((1.0 + pow(t_1, -2.0)) - (x / t_0)));
}
return tmp;
}
p_m = abs(p) function code(p_m, x) t_0 = hypot(x, Float64(p_m * 2.0)) t_1 = Float64(t_0 / x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.99996) tmp = Float64(Float64(1.5 * (Float64(p_m / x) ^ 3.0)) - Float64(p_m / x)); else tmp = Float64(log(exp(sqrt(fma(0.5, (t_1 ^ -3.0), 0.5)))) / sqrt(Float64(Float64(1.0 + (t_1 ^ -2.0)) - Float64(x / t_0)))); end return tmp end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / x), $MachinePrecision]}, 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.99996], N[(N[(1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[Exp[N[Sqrt[N[(0.5 * N[Power[t$95$1, -3.0], $MachinePrecision] + 0.5), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 + N[Power[t$95$1, -2.0], $MachinePrecision]), $MachinePrecision] - N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, p_m \cdot 2\right)\\
t_1 := \frac{t_0}{x}\\
\mathbf{if}\;\frac{x}{\sqrt{p_m \cdot \left(4 \cdot p_m\right) + x \cdot x}} \leq -0.99996:\\
\;\;\;\;1.5 \cdot {\left(\frac{p_m}{x}\right)}^{3} - \frac{p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\log \left(e^{\sqrt{\mathsf{fma}\left(0.5, {t_1}^{-3}, 0.5\right)}}\right)}{\sqrt{\left(1 + {t_1}^{-2}\right) - \frac{x}{t_0}}}\\
\end{array}
\end{array}
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (hypot x (* p_m 2.0))) (t_1 (/ t_0 x)))
(if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.99996)
(- (* 1.5 (pow (/ p_m x) 3.0)) (/ p_m x))
(/
(sqrt (+ 0.5 (* (pow t_1 -3.0) 0.5)))
(sqrt (- (+ 1.0 (pow t_1 -2.0)) (/ x t_0)))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = hypot(x, (p_m * 2.0));
double t_1 = t_0 / x;
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) {
tmp = (1.5 * pow((p_m / x), 3.0)) - (p_m / x);
} else {
tmp = sqrt((0.5 + (pow(t_1, -3.0) * 0.5))) / sqrt(((1.0 + pow(t_1, -2.0)) - (x / t_0)));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = Math.hypot(x, (p_m * 2.0));
double t_1 = t_0 / x;
double tmp;
if ((x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) {
tmp = (1.5 * Math.pow((p_m / x), 3.0)) - (p_m / x);
} else {
tmp = Math.sqrt((0.5 + (Math.pow(t_1, -3.0) * 0.5))) / Math.sqrt(((1.0 + Math.pow(t_1, -2.0)) - (x / t_0)));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = math.hypot(x, (p_m * 2.0)) t_1 = t_0 / x tmp = 0 if (x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996: tmp = (1.5 * math.pow((p_m / x), 3.0)) - (p_m / x) else: tmp = math.sqrt((0.5 + (math.pow(t_1, -3.0) * 0.5))) / math.sqrt(((1.0 + math.pow(t_1, -2.0)) - (x / t_0))) return tmp
p_m = abs(p) function code(p_m, x) t_0 = hypot(x, Float64(p_m * 2.0)) t_1 = Float64(t_0 / x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.99996) tmp = Float64(Float64(1.5 * (Float64(p_m / x) ^ 3.0)) - Float64(p_m / x)); else tmp = Float64(sqrt(Float64(0.5 + Float64((t_1 ^ -3.0) * 0.5))) / sqrt(Float64(Float64(1.0 + (t_1 ^ -2.0)) - Float64(x / t_0)))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = hypot(x, (p_m * 2.0)); t_1 = t_0 / x; tmp = 0.0; if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) tmp = (1.5 * ((p_m / x) ^ 3.0)) - (p_m / x); else tmp = sqrt((0.5 + ((t_1 ^ -3.0) * 0.5))) / sqrt(((1.0 + (t_1 ^ -2.0)) - (x / t_0))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / x), $MachinePrecision]}, 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.99996], N[(N[(1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(0.5 + N[(N[Power[t$95$1, -3.0], $MachinePrecision] * 0.5), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(N[(1.0 + N[Power[t$95$1, -2.0], $MachinePrecision]), $MachinePrecision] - N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, p_m \cdot 2\right)\\
t_1 := \frac{t_0}{x}\\
\mathbf{if}\;\frac{x}{\sqrt{p_m \cdot \left(4 \cdot p_m\right) + x \cdot x}} \leq -0.99996:\\
\;\;\;\;1.5 \cdot {\left(\frac{p_m}{x}\right)}^{3} - \frac{p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{\sqrt{0.5 + {t_1}^{-3} \cdot 0.5}}{\sqrt{\left(1 + {t_1}^{-2}\right) - \frac{x}{t_0}}}\\
\end{array}
\end{array}
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (hypot x (* p_m 2.0))) (t_1 (/ t_0 x)))
(if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.99996)
(- (* 1.5 (pow (/ p_m x) 3.0)) (/ p_m x))
(sqrt
(*
0.5
(/ (+ (pow t_1 -3.0) 1.0) (+ 1.0 (- (pow t_1 -2.0) (/ x t_0)))))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = hypot(x, (p_m * 2.0));
double t_1 = t_0 / x;
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) {
tmp = (1.5 * pow((p_m / x), 3.0)) - (p_m / x);
} else {
tmp = sqrt((0.5 * ((pow(t_1, -3.0) + 1.0) / (1.0 + (pow(t_1, -2.0) - (x / t_0))))));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = Math.hypot(x, (p_m * 2.0));
double t_1 = t_0 / x;
double tmp;
if ((x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) {
tmp = (1.5 * Math.pow((p_m / x), 3.0)) - (p_m / x);
} else {
tmp = Math.sqrt((0.5 * ((Math.pow(t_1, -3.0) + 1.0) / (1.0 + (Math.pow(t_1, -2.0) - (x / t_0))))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = math.hypot(x, (p_m * 2.0)) t_1 = t_0 / x tmp = 0 if (x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996: tmp = (1.5 * math.pow((p_m / x), 3.0)) - (p_m / x) else: tmp = math.sqrt((0.5 * ((math.pow(t_1, -3.0) + 1.0) / (1.0 + (math.pow(t_1, -2.0) - (x / t_0)))))) return tmp
p_m = abs(p) function code(p_m, x) t_0 = hypot(x, Float64(p_m * 2.0)) t_1 = Float64(t_0 / x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.99996) tmp = Float64(Float64(1.5 * (Float64(p_m / x) ^ 3.0)) - Float64(p_m / x)); else tmp = sqrt(Float64(0.5 * Float64(Float64((t_1 ^ -3.0) + 1.0) / Float64(1.0 + Float64((t_1 ^ -2.0) - Float64(x / t_0)))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = hypot(x, (p_m * 2.0)); t_1 = t_0 / x; tmp = 0.0; if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) tmp = (1.5 * ((p_m / x) ^ 3.0)) - (p_m / x); else tmp = sqrt((0.5 * (((t_1 ^ -3.0) + 1.0) / (1.0 + ((t_1 ^ -2.0) - (x / t_0)))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]}, Block[{t$95$1 = N[(t$95$0 / x), $MachinePrecision]}, 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.99996], N[(N[(1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[(N[Power[t$95$1, -3.0], $MachinePrecision] + 1.0), $MachinePrecision] / N[(1.0 + N[(N[Power[t$95$1, -2.0], $MachinePrecision] - N[(x / t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \mathsf{hypot}\left(x, p_m \cdot 2\right)\\
t_1 := \frac{t_0}{x}\\
\mathbf{if}\;\frac{x}{\sqrt{p_m \cdot \left(4 \cdot p_m\right) + x \cdot x}} \leq -0.99996:\\
\;\;\;\;1.5 \cdot {\left(\frac{p_m}{x}\right)}^{3} - \frac{p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \frac{{t_1}^{-3} + 1}{1 + \left({t_1}^{-2} - \frac{x}{t_0}\right)}}\\
\end{array}
\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.99996)
(- (* 1.5 (pow (/ p_m x) 3.0)) (/ p_m x))
(pow
(pow (+ 0.5 (* 0.5 (/ 1.0 (/ (hypot x (* p_m 2.0)) x)))) 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.99996) {
tmp = (1.5 * pow((p_m / x), 3.0)) - (p_m / x);
} else {
tmp = pow(pow((0.5 + (0.5 * (1.0 / (hypot(x, (p_m * 2.0)) / x)))), 1.5), 0.3333333333333333);
}
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.99996) {
tmp = (1.5 * Math.pow((p_m / x), 3.0)) - (p_m / x);
} else {
tmp = Math.pow(Math.pow((0.5 + (0.5 * (1.0 / (Math.hypot(x, (p_m * 2.0)) / x)))), 1.5), 0.3333333333333333);
}
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.99996: tmp = (1.5 * math.pow((p_m / x), 3.0)) - (p_m / x) else: tmp = math.pow(math.pow((0.5 + (0.5 * (1.0 / (math.hypot(x, (p_m * 2.0)) / x)))), 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.99996) tmp = Float64(Float64(1.5 * (Float64(p_m / x) ^ 3.0)) - Float64(p_m / x)); else tmp = (Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(hypot(x, Float64(p_m * 2.0)) / x)))) ^ 1.5) ^ 0.3333333333333333; 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.99996) tmp = (1.5 * ((p_m / x) ^ 3.0)) - (p_m / x); else tmp = ((0.5 + (0.5 * (1.0 / (hypot(x, (p_m * 2.0)) / x)))) ^ 1.5) ^ 0.3333333333333333; 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.99996], N[(N[(1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision], N[Power[N[Power[N[(0.5 + N[(0.5 * N[(1.0 / N[(N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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.99996:\\
\;\;\;\;1.5 \cdot {\left(\frac{p_m}{x}\right)}^{3} - \frac{p_m}{x}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(0.5 + 0.5 \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, p_m \cdot 2\right)}{x}}\right)}^{1.5}\right)}^{0.3333333333333333}\\
\end{array}
\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.99996) (- (* 1.5 (pow (/ p_m x) 3.0)) (/ 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 / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) {
tmp = (1.5 * pow((p_m / x), 3.0)) - (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 / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) {
tmp = (1.5 * Math.pow((p_m / x), 3.0)) - (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 / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996: tmp = (1.5 * math.pow((p_m / x), 3.0)) - (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 (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.99996) tmp = Float64(Float64(1.5 * (Float64(p_m / x) ^ 3.0)) - Float64(p_m / 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 / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99996) tmp = (1.5 * ((p_m / x) ^ 3.0)) - (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[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.99996], N[(N[(1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $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}\;\frac{x}{\sqrt{p_m \cdot \left(4 \cdot p_m\right) + x \cdot x}} \leq -0.99996:\\
\;\;\;\;1.5 \cdot {\left(\frac{p_m}{x}\right)}^{3} - \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}
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(if (<= x -1050000.0)
(* (/ (* p_m (sqrt 2.0)) x) (- (sqrt 0.5)))
(if (or (<= x -2.8e-32) (not (<= x -7.8e-91)))
(sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p_m 2.0) x)))))
(- (* 1.5 (pow (/ p_m x) 3.0)) (/ p_m x)))))p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -1050000.0) {
tmp = ((p_m * sqrt(2.0)) / x) * -sqrt(0.5);
} else if ((x <= -2.8e-32) || !(x <= -7.8e-91)) {
tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.0), x)))));
} else {
tmp = (1.5 * pow((p_m / x), 3.0)) - (p_m / x);
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= -1050000.0) {
tmp = ((p_m * Math.sqrt(2.0)) / x) * -Math.sqrt(0.5);
} else if ((x <= -2.8e-32) || !(x <= -7.8e-91)) {
tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p_m * 2.0), x)))));
} else {
tmp = (1.5 * Math.pow((p_m / x), 3.0)) - (p_m / x);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -1050000.0: tmp = ((p_m * math.sqrt(2.0)) / x) * -math.sqrt(0.5) elif (x <= -2.8e-32) or not (x <= -7.8e-91): tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p_m * 2.0), x))))) else: tmp = (1.5 * math.pow((p_m / x), 3.0)) - (p_m / x) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -1050000.0) tmp = Float64(Float64(Float64(p_m * sqrt(2.0)) / x) * Float64(-sqrt(0.5))); elseif ((x <= -2.8e-32) || !(x <= -7.8e-91)) tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p_m * 2.0), x))))); else tmp = Float64(Float64(1.5 * (Float64(p_m / x) ^ 3.0)) - Float64(p_m / x)); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -1050000.0) tmp = ((p_m * sqrt(2.0)) / x) * -sqrt(0.5); elseif ((x <= -2.8e-32) || ~((x <= -7.8e-91))) tmp = sqrt((0.5 * (1.0 + (x / hypot((p_m * 2.0), x))))); else tmp = (1.5 * ((p_m / x) ^ 3.0)) - (p_m / x); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -1050000.0], N[(N[(N[(p$95$m * N[Sqrt[2.0], $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision] * (-N[Sqrt[0.5], $MachinePrecision])), $MachinePrecision], If[Or[LessEqual[x, -2.8e-32], N[Not[LessEqual[x, -7.8e-91]], $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], N[(N[(1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1050000:\\
\;\;\;\;\frac{p_m \cdot \sqrt{2}}{x} \cdot \left(-\sqrt{0.5}\right)\\
\mathbf{elif}\;x \leq -2.8 \cdot 10^{-32} \lor \neg \left(x \leq -7.8 \cdot 10^{-91}\right):\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p_m \cdot 2, x\right)}\right)}\\
\mathbf{else}:\\
\;\;\;\;1.5 \cdot {\left(\frac{p_m}{x}\right)}^{3} - \frac{p_m}{x}\\
\end{array}
\end{array}
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (- (* 1.5 (pow (/ p_m x) 3.0)) (/ p_m x))))
(if (<= p_m 5.8e-262)
1.0
(if (<= p_m 1.9e-170)
t_0
(if (<= p_m 2.7e-153) 1.0 (if (<= p_m 4.2e-60) t_0 (sqrt 0.5)))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = (1.5 * pow((p_m / x), 3.0)) - (p_m / x);
double tmp;
if (p_m <= 5.8e-262) {
tmp = 1.0;
} else if (p_m <= 1.9e-170) {
tmp = t_0;
} else if (p_m <= 2.7e-153) {
tmp = 1.0;
} else if (p_m <= 4.2e-60) {
tmp = t_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 = (1.5d0 * ((p_m / x) ** 3.0d0)) - (p_m / x)
if (p_m <= 5.8d-262) then
tmp = 1.0d0
else if (p_m <= 1.9d-170) then
tmp = t_0
else if (p_m <= 2.7d-153) then
tmp = 1.0d0
else if (p_m <= 4.2d-60) then
tmp = t_0
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 = (1.5 * Math.pow((p_m / x), 3.0)) - (p_m / x);
double tmp;
if (p_m <= 5.8e-262) {
tmp = 1.0;
} else if (p_m <= 1.9e-170) {
tmp = t_0;
} else if (p_m <= 2.7e-153) {
tmp = 1.0;
} else if (p_m <= 4.2e-60) {
tmp = t_0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = (1.5 * math.pow((p_m / x), 3.0)) - (p_m / x) tmp = 0 if p_m <= 5.8e-262: tmp = 1.0 elif p_m <= 1.9e-170: tmp = t_0 elif p_m <= 2.7e-153: tmp = 1.0 elif p_m <= 4.2e-60: tmp = t_0 else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(Float64(1.5 * (Float64(p_m / x) ^ 3.0)) - Float64(p_m / x)) tmp = 0.0 if (p_m <= 5.8e-262) tmp = 1.0; elseif (p_m <= 1.9e-170) tmp = t_0; elseif (p_m <= 2.7e-153) tmp = 1.0; elseif (p_m <= 4.2e-60) tmp = t_0; else tmp = sqrt(0.5); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = (1.5 * ((p_m / x) ^ 3.0)) - (p_m / x); tmp = 0.0; if (p_m <= 5.8e-262) tmp = 1.0; elseif (p_m <= 1.9e-170) tmp = t_0; elseif (p_m <= 2.7e-153) tmp = 1.0; elseif (p_m <= 4.2e-60) tmp = t_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[(N[(1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision] - N[(p$95$m / x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p$95$m, 5.8e-262], 1.0, If[LessEqual[p$95$m, 1.9e-170], t$95$0, If[LessEqual[p$95$m, 2.7e-153], 1.0, If[LessEqual[p$95$m, 4.2e-60], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := 1.5 \cdot {\left(\frac{p_m}{x}\right)}^{3} - \frac{p_m}{x}\\
\mathbf{if}\;p_m \leq 5.8 \cdot 10^{-262}:\\
\;\;\;\;1\\
\mathbf{elif}\;p_m \leq 1.9 \cdot 10^{-170}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p_m \leq 2.7 \cdot 10^{-153}:\\
\;\;\;\;1\\
\mathbf{elif}\;p_m \leq 4.2 \cdot 10^{-60}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= p_m 9e-38) 1.0 (sqrt 0.5)))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (p_m <= 9e-38) {
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 <= 9d-38) 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 <= 9e-38) {
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 <= 9e-38: 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 <= 9e-38) 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 <= 9e-38) 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, 9e-38], 1.0, N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;p_m \leq 9 \cdot 10^{-38}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (sqrt 0.5))
p_m = fabs(p);
double code(double p_m, double x) {
return sqrt(0.5);
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
code = sqrt(0.5d0)
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
return Math.sqrt(0.5);
}
p_m = math.fabs(p) def code(p_m, x): return math.sqrt(0.5)
p_m = abs(p) function code(p_m, x) return sqrt(0.5) end
p_m = abs(p); function tmp = code(p_m, x) tmp = sqrt(0.5); end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := N[Sqrt[0.5], $MachinePrecision]
\begin{array}{l}
p_m = \left|p\right|
\\
\sqrt{0.5}
\end{array}
(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 2023347
(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))))))))