
(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 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (p x) :precision binary64 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
double code(double p, double x) {
return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = sqrt((0.5d0 * (1.0d0 + (x / sqrt((((4.0d0 * p) * p) + (x * x)))))))
end function
public static double code(double p, double x) {
return Math.sqrt((0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))))));
}
def code(p, x): return math.sqrt((0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))))
function code(p, x) return sqrt(Float64(0.5 * Float64(1.0 + Float64(x / sqrt(Float64(Float64(Float64(4.0 * p) * p) + Float64(x * x))))))) end
function tmp = code(p, x) tmp = sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x))))))); end
code[p_, x_] := N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\end{array}
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.5) (/ (- p) x) (sqrt (+ 0.5 (* x (/ 0.5 (hypot x (* p 2.0))))))))
p = abs(p);
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5) {
tmp = -p / x;
} else {
tmp = sqrt((0.5 + (x * (0.5 / hypot(x, (p * 2.0))))));
}
return tmp;
}
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5) {
tmp = -p / x;
} else {
tmp = Math.sqrt((0.5 + (x * (0.5 / Math.hypot(x, (p * 2.0))))));
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5: tmp = -p / x else: tmp = math.sqrt((0.5 + (x * (0.5 / math.hypot(x, (p * 2.0)))))) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -0.5) tmp = Float64(Float64(-p) / x); else tmp = sqrt(Float64(0.5 + Float64(x * Float64(0.5 / hypot(x, Float64(p * 2.0)))))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.5) tmp = -p / x; else tmp = sqrt((0.5 + (x * (0.5 / hypot(x, (p * 2.0)))))); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.5], N[((-p) / x), $MachinePrecision], N[Sqrt[N[(0.5 + N[(x * N[(0.5 / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.5:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + x \cdot \frac{0.5}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.5Initial program 14.1%
expm1-log1p-u14.1%
expm1-udef14.1%
Applied egg-rr14.1%
expm1-def14.1%
expm1-log1p14.1%
associate-/r/13.0%
Simplified13.0%
Taylor expanded in x around -inf 54.4%
mul-1-neg54.4%
Simplified54.4%
if -0.5 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 100.0%
expm1-log1p-u99.0%
expm1-udef99.0%
Applied egg-rr99.0%
expm1-def99.0%
expm1-log1p100.0%
associate-/r/100.0%
Simplified100.0%
Final simplification87.2%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (* p (sqrt (pow x -2.0))))
(t_1 (/ (- p) x))
(t_2 (+ 1.0 (* -0.5 (* (/ p x) (/ p x))))))
(if (<= p 3.8e-246)
t_1
(if (<= p 2.55e-228)
t_2
(if (<= p 2.3e-165)
t_0
(if (<= p 5.4e-132)
t_2
(if (<= p 7.5e-66)
t_0
(if (<= p 920000000000.0)
1.0
(if (<= p 2.55e+64)
(sqrt (+ 0.5 (* x (/ 0.25 p))))
(if (<= p 2.6e+67) t_1 (sqrt 0.5)))))))))))p = abs(p);
double code(double p, double x) {
double t_0 = p * sqrt(pow(x, -2.0));
double t_1 = -p / x;
double t_2 = 1.0 + (-0.5 * ((p / x) * (p / x)));
double tmp;
if (p <= 3.8e-246) {
tmp = t_1;
} else if (p <= 2.55e-228) {
tmp = t_2;
} else if (p <= 2.3e-165) {
tmp = t_0;
} else if (p <= 5.4e-132) {
tmp = t_2;
} else if (p <= 7.5e-66) {
tmp = t_0;
} else if (p <= 920000000000.0) {
tmp = 1.0;
} else if (p <= 2.55e+64) {
tmp = sqrt((0.5 + (x * (0.25 / p))));
} else if (p <= 2.6e+67) {
tmp = t_1;
} 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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = p * sqrt((x ** (-2.0d0)))
t_1 = -p / x
t_2 = 1.0d0 + ((-0.5d0) * ((p / x) * (p / x)))
if (p <= 3.8d-246) then
tmp = t_1
else if (p <= 2.55d-228) then
tmp = t_2
else if (p <= 2.3d-165) then
tmp = t_0
else if (p <= 5.4d-132) then
tmp = t_2
else if (p <= 7.5d-66) then
tmp = t_0
else if (p <= 920000000000.0d0) then
tmp = 1.0d0
else if (p <= 2.55d+64) then
tmp = sqrt((0.5d0 + (x * (0.25d0 / p))))
else if (p <= 2.6d+67) then
tmp = t_1
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 * Math.sqrt(Math.pow(x, -2.0));
double t_1 = -p / x;
double t_2 = 1.0 + (-0.5 * ((p / x) * (p / x)));
double tmp;
if (p <= 3.8e-246) {
tmp = t_1;
} else if (p <= 2.55e-228) {
tmp = t_2;
} else if (p <= 2.3e-165) {
tmp = t_0;
} else if (p <= 5.4e-132) {
tmp = t_2;
} else if (p <= 7.5e-66) {
tmp = t_0;
} else if (p <= 920000000000.0) {
tmp = 1.0;
} else if (p <= 2.55e+64) {
tmp = Math.sqrt((0.5 + (x * (0.25 / p))));
} else if (p <= 2.6e+67) {
tmp = t_1;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = p * math.sqrt(math.pow(x, -2.0)) t_1 = -p / x t_2 = 1.0 + (-0.5 * ((p / x) * (p / x))) tmp = 0 if p <= 3.8e-246: tmp = t_1 elif p <= 2.55e-228: tmp = t_2 elif p <= 2.3e-165: tmp = t_0 elif p <= 5.4e-132: tmp = t_2 elif p <= 7.5e-66: tmp = t_0 elif p <= 920000000000.0: tmp = 1.0 elif p <= 2.55e+64: tmp = math.sqrt((0.5 + (x * (0.25 / p)))) elif p <= 2.6e+67: tmp = t_1 else: tmp = math.sqrt(0.5) return tmp
p = abs(p) function code(p, x) t_0 = Float64(p * sqrt((x ^ -2.0))) t_1 = Float64(Float64(-p) / x) t_2 = Float64(1.0 + Float64(-0.5 * Float64(Float64(p / x) * Float64(p / x)))) tmp = 0.0 if (p <= 3.8e-246) tmp = t_1; elseif (p <= 2.55e-228) tmp = t_2; elseif (p <= 2.3e-165) tmp = t_0; elseif (p <= 5.4e-132) tmp = t_2; elseif (p <= 7.5e-66) tmp = t_0; elseif (p <= 920000000000.0) tmp = 1.0; elseif (p <= 2.55e+64) tmp = sqrt(Float64(0.5 + Float64(x * Float64(0.25 / p)))); elseif (p <= 2.6e+67) tmp = t_1; else tmp = sqrt(0.5); end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = p * sqrt((x ^ -2.0)); t_1 = -p / x; t_2 = 1.0 + (-0.5 * ((p / x) * (p / x))); tmp = 0.0; if (p <= 3.8e-246) tmp = t_1; elseif (p <= 2.55e-228) tmp = t_2; elseif (p <= 2.3e-165) tmp = t_0; elseif (p <= 5.4e-132) tmp = t_2; elseif (p <= 7.5e-66) tmp = t_0; elseif (p <= 920000000000.0) tmp = 1.0; elseif (p <= 2.55e+64) tmp = sqrt((0.5 + (x * (0.25 / p)))); elseif (p <= 2.6e+67) tmp = t_1; 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 * N[Sqrt[N[Power[x, -2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[((-p) / x), $MachinePrecision]}, Block[{t$95$2 = N[(1.0 + N[(-0.5 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p, 3.8e-246], t$95$1, If[LessEqual[p, 2.55e-228], t$95$2, If[LessEqual[p, 2.3e-165], t$95$0, If[LessEqual[p, 5.4e-132], t$95$2, If[LessEqual[p, 7.5e-66], t$95$0, If[LessEqual[p, 920000000000.0], 1.0, If[LessEqual[p, 2.55e+64], N[Sqrt[N[(0.5 + N[(x * N[(0.25 / p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[p, 2.6e+67], t$95$1, N[Sqrt[0.5], $MachinePrecision]]]]]]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := p \cdot \sqrt{{x}^{-2}}\\
t_1 := \frac{-p}{x}\\
t_2 := 1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\
\mathbf{if}\;p \leq 3.8 \cdot 10^{-246}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;p \leq 2.55 \cdot 10^{-228}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;p \leq 2.3 \cdot 10^{-165}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 5.4 \cdot 10^{-132}:\\
\;\;\;\;t_2\\
\mathbf{elif}\;p \leq 7.5 \cdot 10^{-66}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 920000000000:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 2.55 \cdot 10^{+64}:\\
\;\;\;\;\sqrt{0.5 + x \cdot \frac{0.25}{p}}\\
\mathbf{elif}\;p \leq 2.6 \cdot 10^{+67}:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 3.79999999999999976e-246 or 2.55000000000000012e64 < p < 2.6e67Initial program 73.7%
expm1-log1p-u72.9%
expm1-udef73.0%
Applied egg-rr73.0%
expm1-def72.9%
expm1-log1p73.7%
associate-/r/73.0%
Simplified73.0%
Taylor expanded in x around -inf 11.9%
mul-1-neg11.9%
Simplified11.9%
if 3.79999999999999976e-246 < p < 2.5500000000000001e-228 or 2.3e-165 < p < 5.3999999999999998e-132Initial program 78.7%
expm1-log1p-u78.7%
expm1-udef78.7%
Applied egg-rr78.4%
expm1-def78.4%
expm1-log1p78.4%
associate-/r/78.4%
Simplified78.4%
Taylor expanded in x around inf 77.0%
unpow277.0%
unpow277.0%
times-frac77.0%
Applied egg-rr77.0%
if 2.5500000000000001e-228 < p < 2.3e-165 or 5.3999999999999998e-132 < p < 7.49999999999999995e-66Initial program 47.5%
expm1-log1p-u47.5%
log1p-def47.5%
expm1-udef47.5%
add-exp-log47.5%
associate-+r-47.5%
Applied egg-rr47.5%
Taylor expanded in x around -inf 16.9%
div-inv16.9%
sqrt-prod41.5%
unpow241.5%
sqrt-prod59.2%
add-sqr-sqrt59.2%
*-commutative59.2%
pow-flip59.2%
metadata-eval59.2%
Applied egg-rr59.2%
if 7.49999999999999995e-66 < p < 9.2e11Initial program 83.9%
Taylor expanded in x around inf 62.3%
if 9.2e11 < p < 2.55000000000000012e64Initial program 71.1%
expm1-log1p-u70.3%
expm1-udef70.3%
Applied egg-rr70.3%
expm1-def70.3%
expm1-log1p71.1%
associate-/r/71.4%
Simplified71.4%
Taylor expanded in x around 0 49.0%
if 2.6e67 < p Initial program 97.9%
Taylor expanded in x around 0 96.3%
Final simplification40.0%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ (- p) x)))
(if (<= p 5.2e-243)
t_0
(if (<= p 7.8e-227)
(+ 1.0 (* -0.5 (* (/ p x) (/ p x))))
(if (<= p 4.7e-163)
t_0
(if (<= p 1.02e-80)
1.0
(if (<= p 7e-67) t_0 (if (<= p 6800000000.0) 1.0 (sqrt 0.5)))))))))p = abs(p);
double code(double p, double x) {
double t_0 = -p / x;
double tmp;
if (p <= 5.2e-243) {
tmp = t_0;
} else if (p <= 7.8e-227) {
tmp = 1.0 + (-0.5 * ((p / x) * (p / x)));
} else if (p <= 4.7e-163) {
tmp = t_0;
} else if (p <= 1.02e-80) {
tmp = 1.0;
} else if (p <= 7e-67) {
tmp = t_0;
} else if (p <= 6800000000.0) {
tmp = 1.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 <= 5.2d-243) then
tmp = t_0
else if (p <= 7.8d-227) then
tmp = 1.0d0 + ((-0.5d0) * ((p / x) * (p / x)))
else if (p <= 4.7d-163) then
tmp = t_0
else if (p <= 1.02d-80) then
tmp = 1.0d0
else if (p <= 7d-67) then
tmp = t_0
else if (p <= 6800000000.0d0) then
tmp = 1.0d0
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 <= 5.2e-243) {
tmp = t_0;
} else if (p <= 7.8e-227) {
tmp = 1.0 + (-0.5 * ((p / x) * (p / x)));
} else if (p <= 4.7e-163) {
tmp = t_0;
} else if (p <= 1.02e-80) {
tmp = 1.0;
} else if (p <= 7e-67) {
tmp = t_0;
} else if (p <= 6800000000.0) {
tmp = 1.0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = -p / x tmp = 0 if p <= 5.2e-243: tmp = t_0 elif p <= 7.8e-227: tmp = 1.0 + (-0.5 * ((p / x) * (p / x))) elif p <= 4.7e-163: tmp = t_0 elif p <= 1.02e-80: tmp = 1.0 elif p <= 7e-67: tmp = t_0 elif p <= 6800000000.0: tmp = 1.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 <= 5.2e-243) tmp = t_0; elseif (p <= 7.8e-227) tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p / x) * Float64(p / x)))); elseif (p <= 4.7e-163) tmp = t_0; elseif (p <= 1.02e-80) tmp = 1.0; elseif (p <= 7e-67) tmp = t_0; elseif (p <= 6800000000.0) tmp = 1.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 <= 5.2e-243) tmp = t_0; elseif (p <= 7.8e-227) tmp = 1.0 + (-0.5 * ((p / x) * (p / x))); elseif (p <= 4.7e-163) tmp = t_0; elseif (p <= 1.02e-80) tmp = 1.0; elseif (p <= 7e-67) tmp = t_0; elseif (p <= 6800000000.0) tmp = 1.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, 5.2e-243], t$95$0, If[LessEqual[p, 7.8e-227], N[(1.0 + N[(-0.5 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p, 4.7e-163], t$95$0, If[LessEqual[p, 1.02e-80], 1.0, If[LessEqual[p, 7e-67], t$95$0, If[LessEqual[p, 6800000000.0], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{-p}{x}\\
\mathbf{if}\;p \leq 5.2 \cdot 10^{-243}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 7.8 \cdot 10^{-227}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\
\mathbf{elif}\;p \leq 4.7 \cdot 10^{-163}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 1.02 \cdot 10^{-80}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 7 \cdot 10^{-67}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 6800000000:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 5.1999999999999995e-243 or 7.7999999999999999e-227 < p < 4.7e-163 or 1.02000000000000005e-80 < p < 7.0000000000000001e-67Initial program 70.6%
expm1-log1p-u69.9%
expm1-udef69.9%
Applied egg-rr69.9%
expm1-def69.9%
expm1-log1p70.6%
associate-/r/70.0%
Simplified70.0%
Taylor expanded in x around -inf 17.1%
mul-1-neg17.1%
Simplified17.1%
if 5.1999999999999995e-243 < p < 7.7999999999999999e-227Initial program 100.0%
expm1-log1p-u100.0%
expm1-udef100.0%
Applied egg-rr100.0%
expm1-def100.0%
expm1-log1p100.0%
associate-/r/100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
unpow2100.0%
unpow2100.0%
times-frac100.0%
Applied egg-rr100.0%
if 4.7e-163 < p < 1.02000000000000005e-80 or 7.0000000000000001e-67 < p < 6.8e9Initial program 72.3%
Taylor expanded in x around inf 58.5%
if 6.8e9 < p Initial program 91.7%
Taylor expanded in x around 0 86.7%
Final simplification39.5%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ (- p) x)) (t_1 (+ 1.0 (* -0.5 (* (/ p x) (/ p x))))))
(if (<= p 3.6e-244)
t_0
(if (<= p 3.8e-228)
t_1
(if (<= p 7.6e-166)
t_0
(if (<= p 8.5e-85) t_1 (if (<= p 1.4e-64) t_0 (sqrt 0.5))))))))p = abs(p);
double code(double p, double x) {
double t_0 = -p / x;
double t_1 = 1.0 + (-0.5 * ((p / x) * (p / x)));
double tmp;
if (p <= 3.6e-244) {
tmp = t_0;
} else if (p <= 3.8e-228) {
tmp = t_1;
} else if (p <= 7.6e-166) {
tmp = t_0;
} else if (p <= 8.5e-85) {
tmp = t_1;
} else if (p <= 1.4e-64) {
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) :: t_1
real(8) :: tmp
t_0 = -p / x
t_1 = 1.0d0 + ((-0.5d0) * ((p / x) * (p / x)))
if (p <= 3.6d-244) then
tmp = t_0
else if (p <= 3.8d-228) then
tmp = t_1
else if (p <= 7.6d-166) then
tmp = t_0
else if (p <= 8.5d-85) then
tmp = t_1
else if (p <= 1.4d-64) 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 t_1 = 1.0 + (-0.5 * ((p / x) * (p / x)));
double tmp;
if (p <= 3.6e-244) {
tmp = t_0;
} else if (p <= 3.8e-228) {
tmp = t_1;
} else if (p <= 7.6e-166) {
tmp = t_0;
} else if (p <= 8.5e-85) {
tmp = t_1;
} else if (p <= 1.4e-64) {
tmp = t_0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = -p / x t_1 = 1.0 + (-0.5 * ((p / x) * (p / x))) tmp = 0 if p <= 3.6e-244: tmp = t_0 elif p <= 3.8e-228: tmp = t_1 elif p <= 7.6e-166: tmp = t_0 elif p <= 8.5e-85: tmp = t_1 elif p <= 1.4e-64: tmp = t_0 else: tmp = math.sqrt(0.5) return tmp
p = abs(p) function code(p, x) t_0 = Float64(Float64(-p) / x) t_1 = Float64(1.0 + Float64(-0.5 * Float64(Float64(p / x) * Float64(p / x)))) tmp = 0.0 if (p <= 3.6e-244) tmp = t_0; elseif (p <= 3.8e-228) tmp = t_1; elseif (p <= 7.6e-166) tmp = t_0; elseif (p <= 8.5e-85) tmp = t_1; elseif (p <= 1.4e-64) 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; t_1 = 1.0 + (-0.5 * ((p / x) * (p / x))); tmp = 0.0; if (p <= 3.6e-244) tmp = t_0; elseif (p <= 3.8e-228) tmp = t_1; elseif (p <= 7.6e-166) tmp = t_0; elseif (p <= 8.5e-85) tmp = t_1; elseif (p <= 1.4e-64) 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]}, Block[{t$95$1 = N[(1.0 + N[(-0.5 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p, 3.6e-244], t$95$0, If[LessEqual[p, 3.8e-228], t$95$1, If[LessEqual[p, 7.6e-166], t$95$0, If[LessEqual[p, 8.5e-85], t$95$1, If[LessEqual[p, 1.4e-64], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{-p}{x}\\
t_1 := 1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\
\mathbf{if}\;p \leq 3.6 \cdot 10^{-244}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 3.8 \cdot 10^{-228}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;p \leq 7.6 \cdot 10^{-166}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 8.5 \cdot 10^{-85}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;p \leq 1.4 \cdot 10^{-64}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 3.59999999999999975e-244 or 3.7999999999999999e-228 < p < 7.59999999999999964e-166 or 8.50000000000000052e-85 < p < 1.40000000000000002e-64Initial program 70.6%
expm1-log1p-u69.9%
expm1-udef69.9%
Applied egg-rr69.9%
expm1-def69.9%
expm1-log1p70.6%
associate-/r/70.0%
Simplified70.0%
Taylor expanded in x around -inf 17.1%
mul-1-neg17.1%
Simplified17.1%
if 3.59999999999999975e-244 < p < 3.7999999999999999e-228 or 7.59999999999999964e-166 < p < 8.50000000000000052e-85Initial program 64.9%
expm1-log1p-u64.9%
expm1-udef64.9%
Applied egg-rr64.8%
expm1-def64.8%
expm1-log1p64.8%
associate-/r/64.6%
Simplified64.6%
Taylor expanded in x around inf 59.1%
unpow259.1%
unpow259.1%
times-frac59.1%
Applied egg-rr59.1%
if 1.40000000000000002e-64 < p Initial program 89.8%
Taylor expanded in x around 0 75.1%
Final simplification37.8%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= x 4.3e-140) (/ (- p) x) (+ 1.0 (* -0.5 (* (/ p x) (/ p x))))))
p = abs(p);
double code(double p, double x) {
double tmp;
if (x <= 4.3e-140) {
tmp = -p / x;
} else {
tmp = 1.0 + (-0.5 * ((p / x) * (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 <= 4.3d-140) then
tmp = -p / x
else
tmp = 1.0d0 + ((-0.5d0) * ((p / x) * (p / x)))
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if (x <= 4.3e-140) {
tmp = -p / x;
} else {
tmp = 1.0 + (-0.5 * ((p / x) * (p / x)));
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if x <= 4.3e-140: tmp = -p / x else: tmp = 1.0 + (-0.5 * ((p / x) * (p / x))) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (x <= 4.3e-140) tmp = Float64(Float64(-p) / x); else tmp = Float64(1.0 + Float64(-0.5 * Float64(Float64(p / x) * Float64(p / x)))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if (x <= 4.3e-140) tmp = -p / x; else tmp = 1.0 + (-0.5 * ((p / x) * (p / x))); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[x, 4.3e-140], N[((-p) / x), $MachinePrecision], N[(1.0 + N[(-0.5 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq 4.3 \cdot 10^{-140}:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + -0.5 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\\
\end{array}
\end{array}
if x < 4.29999999999999962e-140Initial program 58.5%
expm1-log1p-u57.7%
expm1-udef57.7%
Applied egg-rr57.7%
expm1-def57.7%
expm1-log1p58.5%
associate-/r/57.9%
Simplified57.9%
Taylor expanded in x around -inf 27.8%
mul-1-neg27.8%
Simplified27.8%
if 4.29999999999999962e-140 < x Initial program 100.0%
expm1-log1p-u99.3%
expm1-udef99.3%
Applied egg-rr99.3%
expm1-def99.3%
expm1-log1p100.0%
associate-/r/100.0%
Simplified100.0%
Taylor expanded in x around inf 55.5%
unpow255.5%
unpow255.5%
times-frac55.5%
Applied egg-rr55.5%
Final simplification39.4%
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 57.6%
expm1-log1p-u56.9%
expm1-udef56.9%
Applied egg-rr56.9%
expm1-def56.9%
expm1-log1p57.6%
associate-/r/57.1%
Simplified57.1%
Taylor expanded in x around -inf 28.4%
mul-1-neg28.4%
Simplified28.4%
if -1.999999999999994e-310 < x Initial program 100.0%
expm1-log1p-u100.0%
log1p-def100.0%
expm1-udef100.0%
add-exp-log100.0%
associate-+r-100.0%
Applied egg-rr100.0%
Taylor expanded in x around -inf 5.3%
Taylor expanded in p around 0 3.6%
Final simplification17.7%
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 75.8%
expm1-log1p-u75.8%
log1p-def75.8%
expm1-udef75.8%
add-exp-log75.8%
associate-+r-75.8%
Applied egg-rr75.8%
Taylor expanded in x around -inf 15.9%
Taylor expanded in p around 0 18.6%
Final simplification18.6%
(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 2023305
(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))))))))