
(FPCore (p x) :precision binary64 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
double code(double p, double x) {
return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = sqrt((0.5d0 * (1.0d0 + (x / sqrt((((4.0d0 * p) * p) + (x * x)))))))
end function
public static double code(double p, double x) {
return Math.sqrt((0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))))));
}
def code(p, x): return math.sqrt((0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))))
function code(p, x) return sqrt(Float64(0.5 * Float64(1.0 + Float64(x / sqrt(Float64(Float64(Float64(4.0 * p) * p) + Float64(x * x))))))) end
function tmp = code(p, x) tmp = sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x))))))); end
code[p_, x_] := N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (p x) :precision binary64 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
double code(double p, double x) {
return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = sqrt((0.5d0 * (1.0d0 + (x / sqrt((((4.0d0 * p) * p) + (x * x)))))))
end function
public static double code(double p, double x) {
return Math.sqrt((0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))))));
}
def code(p, x): return math.sqrt((0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))))
function code(p, x) return sqrt(Float64(0.5 * Float64(1.0 + Float64(x / sqrt(Float64(Float64(Float64(4.0 * p) * p) + Float64(x * x))))))) end
function tmp = code(p, x) tmp = sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x))))))); end
code[p_, x_] := N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\end{array}
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ x (hypot x (* p 2.0)))))
(if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9999995)
(/ (- p) x)
(sqrt (* 0.5 (fma (cbrt (pow t_0 2.0)) (cbrt t_0) 1.0))))))p = abs(p);
double code(double p, double x) {
double t_0 = x / hypot(x, (p * 2.0));
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.9999995) {
tmp = -p / x;
} else {
tmp = sqrt((0.5 * fma(cbrt(pow(t_0, 2.0)), cbrt(t_0), 1.0)));
}
return tmp;
}
p = abs(p) function code(p, x) t_0 = Float64(x / hypot(x, Float64(p * 2.0))) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -0.9999995) tmp = Float64(Float64(-p) / x); else tmp = sqrt(Float64(0.5 * fma(cbrt((t_0 ^ 2.0)), cbrt(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[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.9999995], N[((-p) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[Power[N[Power[t$95$0, 2.0], $MachinePrecision], 1/3], $MachinePrecision] * N[Power[t$95$0, 1/3], $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\\
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.9999995:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \mathsf{fma}\left(\sqrt[3]{{t_0}^{2}}, \sqrt[3]{t_0}, 1\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.999999500000000041Initial program 18.3%
Taylor expanded in x around -inf 54.0%
unpow254.0%
unpow254.0%
times-frac63.9%
Simplified63.9%
Taylor expanded in p around -inf 56.8%
associate-*r/56.8%
neg-mul-156.8%
Simplified56.8%
if -0.999999500000000041 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.9%
+-commutative99.9%
add-cube-cbrt99.8%
fma-def99.8%
Applied egg-rr99.9%
Final simplification89.8%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9999995) (/ (- p) x) (sqrt (* 0.5 (fma (/ 1.0 (hypot x (* p 2.0))) x 1.0)))))
p = abs(p);
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.9999995) {
tmp = -p / x;
} else {
tmp = sqrt((0.5 * fma((1.0 / hypot(x, (p * 2.0))), x, 1.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)))) <= -0.9999995) tmp = Float64(Float64(-p) / x); else tmp = sqrt(Float64(0.5 * fma(Float64(1.0 / hypot(x, Float64(p * 2.0))), x, 1.0))); 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], -0.9999995], N[((-p) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[(1.0 / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] * x + 1.0), $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 -0.9999995:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \mathsf{fma}\left(\frac{1}{\mathsf{hypot}\left(x, p \cdot 2\right)}, x, 1\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.999999500000000041Initial program 18.3%
Taylor expanded in x around -inf 54.0%
unpow254.0%
unpow254.0%
times-frac63.9%
Simplified63.9%
Taylor expanded in p around -inf 56.8%
associate-*r/56.8%
neg-mul-156.8%
Simplified56.8%
if -0.999999500000000041 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.9%
+-commutative99.9%
clear-num99.8%
associate-/r/99.9%
fma-def99.9%
+-commutative99.9%
add-sqr-sqrt99.9%
hypot-def99.9%
associate-*l*99.9%
sqrt-prod99.9%
metadata-eval99.9%
sqrt-unprod50.0%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Final simplification89.8%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9999995) (/ (- 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)))) <= -0.9999995) {
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)))) <= -0.9999995) {
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)))) <= -0.9999995: 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)))) <= -0.9999995) 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)))) <= -0.9999995) 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], -0.9999995], 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 -0.9999995:\\
\;\;\;\;\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)))) < -0.999999500000000041Initial program 18.3%
Taylor expanded in x around -inf 54.0%
unpow254.0%
unpow254.0%
times-frac63.9%
Simplified63.9%
Taylor expanded in p around -inf 56.8%
associate-*r/56.8%
neg-mul-156.8%
Simplified56.8%
if -0.999999500000000041 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.9%
add-sqr-sqrt99.9%
hypot-def99.9%
associate-*l*99.9%
sqrt-prod99.9%
metadata-eval99.9%
sqrt-unprod50.0%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Final simplification89.8%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ (- p) x)))
(if (<= p 3.6e-199)
1.0
(if (<= p 1.15e-147)
t_0
(if (<= p 2.75e-101)
1.0
(if (<= p 8.5e-94)
t_0
(if (<= p 9.5e-51)
(sqrt (+ 0.5 (* 0.25 (/ x p))))
(if (<= p 1.3e-37) t_0 (sqrt 0.5)))))))))p = abs(p);
double code(double p, double x) {
double t_0 = -p / x;
double tmp;
if (p <= 3.6e-199) {
tmp = 1.0;
} else if (p <= 1.15e-147) {
tmp = t_0;
} else if (p <= 2.75e-101) {
tmp = 1.0;
} else if (p <= 8.5e-94) {
tmp = t_0;
} else if (p <= 9.5e-51) {
tmp = sqrt((0.5 + (0.25 * (x / p))));
} else if (p <= 1.3e-37) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = -p / x
if (p <= 3.6d-199) then
tmp = 1.0d0
else if (p <= 1.15d-147) then
tmp = t_0
else if (p <= 2.75d-101) then
tmp = 1.0d0
else if (p <= 8.5d-94) then
tmp = t_0
else if (p <= 9.5d-51) then
tmp = sqrt((0.5d0 + (0.25d0 * (x / p))))
else if (p <= 1.3d-37) then
tmp = t_0
else
tmp = sqrt(0.5d0)
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 <= 3.6e-199) {
tmp = 1.0;
} else if (p <= 1.15e-147) {
tmp = t_0;
} else if (p <= 2.75e-101) {
tmp = 1.0;
} else if (p <= 8.5e-94) {
tmp = t_0;
} else if (p <= 9.5e-51) {
tmp = Math.sqrt((0.5 + (0.25 * (x / p))));
} else if (p <= 1.3e-37) {
tmp = t_0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = -p / x tmp = 0 if p <= 3.6e-199: tmp = 1.0 elif p <= 1.15e-147: tmp = t_0 elif p <= 2.75e-101: tmp = 1.0 elif p <= 8.5e-94: tmp = t_0 elif p <= 9.5e-51: tmp = math.sqrt((0.5 + (0.25 * (x / p)))) elif p <= 1.3e-37: tmp = t_0 else: tmp = math.sqrt(0.5) return tmp
p = abs(p) function code(p, x) t_0 = Float64(Float64(-p) / x) tmp = 0.0 if (p <= 3.6e-199) tmp = 1.0; elseif (p <= 1.15e-147) tmp = t_0; elseif (p <= 2.75e-101) tmp = 1.0; elseif (p <= 8.5e-94) tmp = t_0; elseif (p <= 9.5e-51) tmp = sqrt(Float64(0.5 + Float64(0.25 * Float64(x / p)))); elseif (p <= 1.3e-37) tmp = t_0; else tmp = sqrt(0.5); end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = -p / x; tmp = 0.0; if (p <= 3.6e-199) tmp = 1.0; elseif (p <= 1.15e-147) tmp = t_0; elseif (p <= 2.75e-101) tmp = 1.0; elseif (p <= 8.5e-94) tmp = t_0; elseif (p <= 9.5e-51) tmp = sqrt((0.5 + (0.25 * (x / p)))); elseif (p <= 1.3e-37) tmp = t_0; else tmp = sqrt(0.5); 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, 3.6e-199], 1.0, If[LessEqual[p, 1.15e-147], t$95$0, If[LessEqual[p, 2.75e-101], 1.0, If[LessEqual[p, 8.5e-94], t$95$0, If[LessEqual[p, 9.5e-51], N[Sqrt[N[(0.5 + N[(0.25 * N[(x / p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[p, 1.3e-37], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{-p}{x}\\
\mathbf{if}\;p \leq 3.6 \cdot 10^{-199}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.15 \cdot 10^{-147}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 2.75 \cdot 10^{-101}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 8.5 \cdot 10^{-94}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 9.5 \cdot 10^{-51}:\\
\;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p}}\\
\mathbf{elif}\;p \leq 1.3 \cdot 10^{-37}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 3.6000000000000002e-199 or 1.14999999999999995e-147 < p < 2.74999999999999986e-101Initial program 78.7%
Taylor expanded in x around inf 42.0%
if 3.6000000000000002e-199 < p < 1.14999999999999995e-147 or 2.74999999999999986e-101 < p < 8.50000000000000003e-94 or 9.4999999999999998e-51 < p < 1.2999999999999999e-37Initial program 44.7%
Taylor expanded in x around -inf 31.7%
unpow231.7%
unpow231.7%
times-frac42.2%
Simplified42.2%
Taylor expanded in p around -inf 59.3%
associate-*r/59.3%
neg-mul-159.3%
Simplified59.3%
if 8.50000000000000003e-94 < p < 9.4999999999999998e-51Initial program 84.1%
Taylor expanded in x around 0 52.6%
*-commutative52.6%
associate-*l/52.6%
Simplified52.6%
expm1-log1p-u51.8%
expm1-udef52.1%
distribute-lft-in52.1%
metadata-eval52.1%
associate-/l*52.1%
Applied egg-rr52.1%
expm1-def51.8%
expm1-log1p52.6%
associate-/r/52.6%
*-commutative52.6%
associate-*r*52.6%
metadata-eval52.6%
Simplified52.6%
if 1.2999999999999999e-37 < p Initial program 96.2%
Taylor expanded in x around 0 86.5%
Final simplification54.8%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ (- p) x)))
(if (<= p 2.7e-202)
1.0
(if (<= p 1.92e-146)
t_0
(if (<= p 6.8e-50) 1.0 (if (<= p 1.3e-37) t_0 (sqrt 0.5)))))))p = abs(p);
double code(double p, double x) {
double t_0 = -p / x;
double tmp;
if (p <= 2.7e-202) {
tmp = 1.0;
} else if (p <= 1.92e-146) {
tmp = t_0;
} else if (p <= 6.8e-50) {
tmp = 1.0;
} else if (p <= 1.3e-37) {
tmp = t_0;
} 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) :: t_0
real(8) :: tmp
t_0 = -p / x
if (p <= 2.7d-202) then
tmp = 1.0d0
else if (p <= 1.92d-146) then
tmp = t_0
else if (p <= 6.8d-50) then
tmp = 1.0d0
else if (p <= 1.3d-37) then
tmp = t_0
else
tmp = sqrt(0.5d0)
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 <= 2.7e-202) {
tmp = 1.0;
} else if (p <= 1.92e-146) {
tmp = t_0;
} else if (p <= 6.8e-50) {
tmp = 1.0;
} else if (p <= 1.3e-37) {
tmp = t_0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = -p / x tmp = 0 if p <= 2.7e-202: tmp = 1.0 elif p <= 1.92e-146: tmp = t_0 elif p <= 6.8e-50: tmp = 1.0 elif p <= 1.3e-37: tmp = t_0 else: tmp = math.sqrt(0.5) return tmp
p = abs(p) function code(p, x) t_0 = Float64(Float64(-p) / x) tmp = 0.0 if (p <= 2.7e-202) tmp = 1.0; elseif (p <= 1.92e-146) tmp = t_0; elseif (p <= 6.8e-50) tmp = 1.0; elseif (p <= 1.3e-37) tmp = t_0; else tmp = sqrt(0.5); end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = -p / x; tmp = 0.0; if (p <= 2.7e-202) tmp = 1.0; elseif (p <= 1.92e-146) tmp = t_0; elseif (p <= 6.8e-50) tmp = 1.0; elseif (p <= 1.3e-37) tmp = t_0; else tmp = sqrt(0.5); 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, 2.7e-202], 1.0, If[LessEqual[p, 1.92e-146], t$95$0, If[LessEqual[p, 6.8e-50], 1.0, If[LessEqual[p, 1.3e-37], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{-p}{x}\\
\mathbf{if}\;p \leq 2.7 \cdot 10^{-202}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.92 \cdot 10^{-146}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 6.8 \cdot 10^{-50}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.3 \cdot 10^{-37}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 2.6999999999999999e-202 or 1.91999999999999999e-146 < p < 6.80000000000000029e-50Initial program 78.7%
Taylor expanded in x around inf 42.0%
if 2.6999999999999999e-202 < p < 1.91999999999999999e-146 or 6.80000000000000029e-50 < p < 1.2999999999999999e-37Initial program 40.2%
Taylor expanded in x around -inf 33.9%
unpow233.9%
unpow233.9%
times-frac46.3%
Simplified46.3%
Taylor expanded in p around -inf 63.4%
associate-*r/63.4%
neg-mul-163.4%
Simplified63.4%
if 1.2999999999999999e-37 < p Initial program 96.2%
Taylor expanded in x around 0 86.5%
Final simplification54.7%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (or (<= p 8.5e-94) (and (not (<= p 1.35e-50)) (<= p 1.3e-37))) (/ (- p) x) (sqrt 0.5)))
p = abs(p);
double code(double p, double x) {
double tmp;
if ((p <= 8.5e-94) || (!(p <= 1.35e-50) && (p <= 1.3e-37))) {
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 <= 8.5d-94) .or. (.not. (p <= 1.35d-50)) .and. (p <= 1.3d-37)) 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 <= 8.5e-94) || (!(p <= 1.35e-50) && (p <= 1.3e-37))) {
tmp = -p / x;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if (p <= 8.5e-94) or (not (p <= 1.35e-50) and (p <= 1.3e-37)): tmp = -p / x else: tmp = math.sqrt(0.5) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if ((p <= 8.5e-94) || (!(p <= 1.35e-50) && (p <= 1.3e-37))) 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 <= 8.5e-94) || (~((p <= 1.35e-50)) && (p <= 1.3e-37))) 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[Or[LessEqual[p, 8.5e-94], And[N[Not[LessEqual[p, 1.35e-50]], $MachinePrecision], LessEqual[p, 1.3e-37]]], N[((-p) / x), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;p \leq 8.5 \cdot 10^{-94} \lor \neg \left(p \leq 1.35 \cdot 10^{-50}\right) \land p \leq 1.3 \cdot 10^{-37}:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 8.50000000000000003e-94 or 1.35e-50 < p < 1.2999999999999999e-37Initial program 75.2%
Taylor expanded in x around -inf 18.9%
unpow218.9%
unpow218.9%
times-frac22.3%
Simplified22.3%
Taylor expanded in p around -inf 18.7%
associate-*r/18.7%
neg-mul-118.7%
Simplified18.7%
if 8.50000000000000003e-94 < p < 1.35e-50 or 1.2999999999999999e-37 < p Initial program 95.2%
Taylor expanded in x around 0 83.3%
Final simplification36.6%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= x -2e-310) (/ (- p) x) (/ p x)))
p = abs(p);
double code(double p, double x) {
double tmp;
if (x <= -2e-310) {
tmp = -p / x;
} else {
tmp = p / x;
}
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 <= (-2d-310)) then
tmp = -p / x
else
tmp = p / x
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if (x <= -2e-310) {
tmp = -p / x;
} else {
tmp = p / x;
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if x <= -2e-310: tmp = -p / x else: tmp = p / x return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (x <= -2e-310) tmp = Float64(Float64(-p) / x); else tmp = Float64(p / x); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if (x <= -2e-310) tmp = -p / x; else tmp = p / x; end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[x, -2e-310], N[((-p) / x), $MachinePrecision], N[(p / x), $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{p}{x}\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 58.2%
Taylor expanded in x around -inf 30.2%
unpow230.2%
unpow230.2%
times-frac35.4%
Simplified35.4%
Taylor expanded in p around -inf 30.3%
associate-*r/30.3%
neg-mul-130.3%
Simplified30.3%
if -1.999999999999994e-310 < x Initial program 100.0%
Taylor expanded in x around -inf 4.4%
unpow24.4%
unpow24.4%
times-frac4.7%
Simplified4.7%
Taylor expanded in p around 0 3.7%
Final simplification15.9%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (/ p x))
p = abs(p);
double code(double p, double x) {
return p / x;
}
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 = p / x
end function
p = Math.abs(p);
public static double code(double p, double x) {
return p / x;
}
p = abs(p) def code(p, x): return p / x
p = abs(p) function code(p, x) return Float64(p / x) end
p = abs(p) function tmp = code(p, x) tmp = p / x; end
NOTE: p should be positive before calling this function code[p_, x_] := N[(p / x), $MachinePrecision]
\begin{array}{l}
p = |p|\\
\\
\frac{p}{x}
\end{array}
Initial program 80.7%
Taylor expanded in x around -inf 16.3%
unpow216.3%
unpow216.3%
times-frac18.9%
Simplified18.9%
Taylor expanded in p around 0 16.7%
Final simplification16.7%
(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 2023230
(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))))))))