
(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 (/ x (hypot x (* p 2.0)))))
(if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9998)
(/ (- p) x)
(sqrt
(*
0.5
(/
(+ 1.0 (pow t_0 9.0))
(*
(fma t_0 (+ t_0 -1.0) 1.0)
(+ 1.0 (- (pow t_0 6.0) (pow t_0 3.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.9998) {
tmp = -p / x;
} else {
tmp = sqrt((0.5 * ((1.0 + pow(t_0, 9.0)) / (fma(t_0, (t_0 + -1.0), 1.0) * (1.0 + (pow(t_0, 6.0) - pow(t_0, 3.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.9998) tmp = Float64(Float64(-p) / x); else tmp = sqrt(Float64(0.5 * Float64(Float64(1.0 + (t_0 ^ 9.0)) / Float64(fma(t_0, Float64(t_0 + -1.0), 1.0) * Float64(1.0 + Float64((t_0 ^ 6.0) - (t_0 ^ 3.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.9998], N[((-p) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[(1.0 + N[Power[t$95$0, 9.0], $MachinePrecision]), $MachinePrecision] / N[(N[(t$95$0 * N[(t$95$0 + -1.0), $MachinePrecision] + 1.0), $MachinePrecision] * N[(1.0 + N[(N[Power[t$95$0, 6.0], $MachinePrecision] - N[Power[t$95$0, 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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.9998:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \frac{1 + {t_0}^{9}}{\mathsf{fma}\left(t_0, t_0 + -1, 1\right) \cdot \left(1 + \left({t_0}^{6} - {t_0}^{3}\right)\right)}}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.99980000000000002Initial program 15.0%
Taylor expanded in x around -inf 58.5%
Taylor expanded in p around -inf 67.8%
associate-*r/67.8%
mul-1-neg67.8%
Simplified67.8%
if -0.99980000000000002 < (/.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-unprod51.0%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Applied egg-rr100.0%
*-commutative100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
*-commutative100.0%
Simplified100.0%
Final simplification91.2%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9998)
(/ (- p) x)
(pow
(pow (sqrt (* 0.5 (+ 1.0 (/ x (hypot x (* p 2.0)))))) 3.0)
0.3333333333333333)))p = abs(p);
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.9998) {
tmp = -p / x;
} else {
tmp = pow(pow(sqrt((0.5 * (1.0 + (x / hypot(x, (p * 2.0)))))), 3.0), 0.3333333333333333);
}
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.9998) {
tmp = -p / x;
} else {
tmp = Math.pow(Math.pow(Math.sqrt((0.5 * (1.0 + (x / Math.hypot(x, (p * 2.0)))))), 3.0), 0.3333333333333333);
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.9998: tmp = -p / x else: tmp = math.pow(math.pow(math.sqrt((0.5 * (1.0 + (x / math.hypot(x, (p * 2.0)))))), 3.0), 0.3333333333333333) 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.9998) tmp = Float64(Float64(-p) / x); else tmp = (sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(x, Float64(p * 2.0)))))) ^ 3.0) ^ 0.3333333333333333; 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.9998) tmp = -p / x; else tmp = (sqrt((0.5 * (1.0 + (x / hypot(x, (p * 2.0)))))) ^ 3.0) ^ 0.3333333333333333; 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.9998], N[((-p) / x), $MachinePrecision], N[Power[N[Power[N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 3.0], $MachinePrecision], 0.3333333333333333], $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.9998:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right)}\right)}^{3}\right)}^{0.3333333333333333}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.99980000000000002Initial program 15.0%
Taylor expanded in x around -inf 58.5%
Taylor expanded in p around -inf 67.8%
associate-*r/67.8%
mul-1-neg67.8%
Simplified67.8%
if -0.99980000000000002 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.9%
sqrt-prod99.4%
+-commutative99.4%
*-commutative99.4%
fma-udef99.4%
fma-udef99.4%
*-commutative99.4%
+-commutative99.4%
add-sqr-sqrt82.3%
Applied egg-rr71.0%
hypot-1-def71.0%
rem-square-sqrt99.4%
Simplified99.4%
add-cbrt-cube99.9%
pow1/399.4%
pow399.4%
sqrt-unprod99.9%
*-commutative99.9%
Applied egg-rr99.9%
Final simplification91.2%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.9998) (/ (- 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.9998) {
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.9998) {
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.9998: 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.9998) 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.9998) 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.9998], 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.9998:\\
\;\;\;\;\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.99980000000000002Initial program 15.0%
Taylor expanded in x around -inf 58.5%
Taylor expanded in p around -inf 67.8%
associate-*r/67.8%
mul-1-neg67.8%
Simplified67.8%
if -0.99980000000000002 < (/.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-unprod51.0%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Final simplification91.2%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (* p (sqrt (pow x -2.0)))))
(if (<= p 9.5e-285)
1.0
(if (<= p 1.25e-182)
t_0
(if (<= p 9e-113)
1.0
(if (<= p 200000000.0)
t_0
(sqrt (* 0.5 (+ 1.0 (/ x (* p 2.0)))))))))))p = abs(p);
double code(double p, double x) {
double t_0 = p * sqrt(pow(x, -2.0));
double tmp;
if (p <= 9.5e-285) {
tmp = 1.0;
} else if (p <= 1.25e-182) {
tmp = t_0;
} else if (p <= 9e-113) {
tmp = 1.0;
} else if (p <= 200000000.0) {
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 * sqrt((x ** (-2.0d0)))
if (p <= 9.5d-285) then
tmp = 1.0d0
else if (p <= 1.25d-182) then
tmp = t_0
else if (p <= 9d-113) then
tmp = 1.0d0
else if (p <= 200000000.0d0) 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 * Math.sqrt(Math.pow(x, -2.0));
double tmp;
if (p <= 9.5e-285) {
tmp = 1.0;
} else if (p <= 1.25e-182) {
tmp = t_0;
} else if (p <= 9e-113) {
tmp = 1.0;
} else if (p <= 200000000.0) {
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 * math.sqrt(math.pow(x, -2.0)) tmp = 0 if p <= 9.5e-285: tmp = 1.0 elif p <= 1.25e-182: tmp = t_0 elif p <= 9e-113: tmp = 1.0 elif p <= 200000000.0: 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(p * sqrt((x ^ -2.0))) tmp = 0.0 if (p <= 9.5e-285) tmp = 1.0; elseif (p <= 1.25e-182) tmp = t_0; elseif (p <= 9e-113) tmp = 1.0; elseif (p <= 200000000.0) 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 * sqrt((x ^ -2.0)); tmp = 0.0; if (p <= 9.5e-285) tmp = 1.0; elseif (p <= 1.25e-182) tmp = t_0; elseif (p <= 9e-113) tmp = 1.0; elseif (p <= 200000000.0) 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 * N[Sqrt[N[Power[x, -2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p, 9.5e-285], 1.0, If[LessEqual[p, 1.25e-182], t$95$0, If[LessEqual[p, 9e-113], 1.0, If[LessEqual[p, 200000000.0], 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 := p \cdot \sqrt{{x}^{-2}}\\
\mathbf{if}\;p \leq 9.5 \cdot 10^{-285}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.25 \cdot 10^{-182}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 9 \cdot 10^{-113}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 200000000:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{p \cdot 2}\right)}\\
\end{array}
\end{array}
if p < 9.4999999999999997e-285 or 1.25000000000000006e-182 < p < 9.0000000000000002e-113Initial program 81.4%
Taylor expanded in x around inf 42.3%
if 9.4999999999999997e-285 < p < 1.25000000000000006e-182 or 9.0000000000000002e-113 < p < 2e8Initial program 41.2%
Taylor expanded in x around -inf 35.4%
pow1/235.4%
associate-*r*35.4%
metadata-eval35.4%
*-un-lft-identity35.4%
div-inv35.4%
unpow-prod-down44.5%
pow1/244.5%
unpow244.5%
sqrt-prod65.4%
add-sqr-sqrt65.8%
pow-flip65.8%
metadata-eval65.8%
Applied egg-rr65.8%
unpow1/265.8%
Simplified65.8%
if 2e8 < p Initial program 93.8%
Taylor expanded in p around inf 89.6%
Final simplification58.9%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ (- p) x)))
(if (<= p 8e-285)
1.0
(if (<= p 1.25e-191)
t_0
(if (<= p 1.75e-113)
1.0
(if (<= p 185000000.0)
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 <= 8e-285) {
tmp = 1.0;
} else if (p <= 1.25e-191) {
tmp = t_0;
} else if (p <= 1.75e-113) {
tmp = 1.0;
} else if (p <= 185000000.0) {
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 <= 8d-285) then
tmp = 1.0d0
else if (p <= 1.25d-191) then
tmp = t_0
else if (p <= 1.75d-113) then
tmp = 1.0d0
else if (p <= 185000000.0d0) 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 <= 8e-285) {
tmp = 1.0;
} else if (p <= 1.25e-191) {
tmp = t_0;
} else if (p <= 1.75e-113) {
tmp = 1.0;
} else if (p <= 185000000.0) {
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 <= 8e-285: tmp = 1.0 elif p <= 1.25e-191: tmp = t_0 elif p <= 1.75e-113: tmp = 1.0 elif p <= 185000000.0: 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 <= 8e-285) tmp = 1.0; elseif (p <= 1.25e-191) tmp = t_0; elseif (p <= 1.75e-113) tmp = 1.0; elseif (p <= 185000000.0) 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 <= 8e-285) tmp = 1.0; elseif (p <= 1.25e-191) tmp = t_0; elseif (p <= 1.75e-113) tmp = 1.0; elseif (p <= 185000000.0) 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, 8e-285], 1.0, If[LessEqual[p, 1.25e-191], t$95$0, If[LessEqual[p, 1.75e-113], 1.0, If[LessEqual[p, 185000000.0], 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 8 \cdot 10^{-285}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.25 \cdot 10^{-191}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 1.75 \cdot 10^{-113}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 185000000:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{p \cdot 2}\right)}\\
\end{array}
\end{array}
if p < 8.00000000000000059e-285 or 1.25e-191 < p < 1.75000000000000014e-113Initial program 81.2%
Taylor expanded in x around inf 42.0%
if 8.00000000000000059e-285 < p < 1.25e-191 or 1.75000000000000014e-113 < p < 1.85e8Initial program 40.7%
Taylor expanded in x around -inf 34.8%
Taylor expanded in p around -inf 64.2%
associate-*r/64.2%
mul-1-neg64.2%
Simplified64.2%
if 1.85e8 < p Initial program 93.8%
Taylor expanded in p around inf 89.6%
Final simplification58.3%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ (- p) x)))
(if (<= p 6.4e-285)
1.0
(if (<= p 6.6e-193)
t_0
(if (<= p 8.6e-113) 1.0 (if (<= p 185000000.0) t_0 (sqrt 0.5)))))))p = abs(p);
double code(double p, double x) {
double t_0 = -p / x;
double tmp;
if (p <= 6.4e-285) {
tmp = 1.0;
} else if (p <= 6.6e-193) {
tmp = t_0;
} else if (p <= 8.6e-113) {
tmp = 1.0;
} else if (p <= 185000000.0) {
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 <= 6.4d-285) then
tmp = 1.0d0
else if (p <= 6.6d-193) then
tmp = t_0
else if (p <= 8.6d-113) then
tmp = 1.0d0
else if (p <= 185000000.0d0) 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 <= 6.4e-285) {
tmp = 1.0;
} else if (p <= 6.6e-193) {
tmp = t_0;
} else if (p <= 8.6e-113) {
tmp = 1.0;
} else if (p <= 185000000.0) {
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 <= 6.4e-285: tmp = 1.0 elif p <= 6.6e-193: tmp = t_0 elif p <= 8.6e-113: tmp = 1.0 elif p <= 185000000.0: 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 <= 6.4e-285) tmp = 1.0; elseif (p <= 6.6e-193) tmp = t_0; elseif (p <= 8.6e-113) tmp = 1.0; elseif (p <= 185000000.0) 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 <= 6.4e-285) tmp = 1.0; elseif (p <= 6.6e-193) tmp = t_0; elseif (p <= 8.6e-113) tmp = 1.0; elseif (p <= 185000000.0) 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, 6.4e-285], 1.0, If[LessEqual[p, 6.6e-193], t$95$0, If[LessEqual[p, 8.6e-113], 1.0, If[LessEqual[p, 185000000.0], 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 6.4 \cdot 10^{-285}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 6.6 \cdot 10^{-193}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 8.6 \cdot 10^{-113}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 185000000:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 6.40000000000000032e-285 or 6.5999999999999998e-193 < p < 8.6000000000000001e-113Initial program 81.2%
Taylor expanded in x around inf 42.0%
if 6.40000000000000032e-285 < p < 6.5999999999999998e-193 or 8.6000000000000001e-113 < p < 1.85e8Initial program 40.7%
Taylor expanded in x around -inf 34.8%
Taylor expanded in p around -inf 64.2%
associate-*r/64.2%
mul-1-neg64.2%
Simplified64.2%
if 1.85e8 < p Initial program 93.8%
Taylor expanded in x around 0 89.9%
Final simplification58.4%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= p 400000000.0) (/ (- p) x) (sqrt 0.5)))
p = abs(p);
double code(double p, double x) {
double tmp;
if (p <= 400000000.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 <= 400000000.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 <= 400000000.0) {
tmp = -p / x;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if p <= 400000000.0: tmp = -p / x else: tmp = math.sqrt(0.5) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (p <= 400000000.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 <= 400000000.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, 400000000.0], N[((-p) / x), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;p \leq 400000000:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 4e8Initial program 70.9%
Taylor expanded in x around -inf 22.8%
Taylor expanded in p around -inf 25.4%
associate-*r/25.4%
mul-1-neg25.4%
Simplified25.4%
if 4e8 < p Initial program 93.8%
Taylor expanded in x around 0 89.9%
Final simplification41.8%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= x -5e-310) (/ (- p) x) (/ p x)))
p = abs(p);
double code(double p, double x) {
double tmp;
if (x <= -5e-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 <= (-5d-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 <= -5e-310) {
tmp = -p / x;
} else {
tmp = p / x;
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if x <= -5e-310: tmp = -p / x else: tmp = p / x return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (x <= -5e-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 <= -5e-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, -5e-310], N[((-p) / x), $MachinePrecision], N[(p / x), $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{-310}:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{p}{x}\\
\end{array}
\end{array}
if x < -4.999999999999985e-310Initial program 53.7%
Taylor expanded in x around -inf 34.4%
Taylor expanded in p around -inf 38.7%
associate-*r/38.7%
mul-1-neg38.7%
Simplified38.7%
if -4.999999999999985e-310 < x Initial program 100.0%
Taylor expanded in x around -inf 4.9%
Taylor expanded in p around 0 3.5%
Final simplification21.3%
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 76.7%
Taylor expanded in x around -inf 19.8%
Taylor expanded in p around 0 14.5%
Final simplification14.5%
(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 2023318
(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))))))))