
(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}
(FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.8) (sqrt (* 0.5 (fma (pow (/ p x) 4.0) -6.0 (* 2.0 (pow (/ p x) 2.0))))) (exp (* 0.5 (log (+ 0.5 (/ 0.5 (/ (hypot x (* p 2.0)) x))))))))
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.8) {
tmp = sqrt((0.5 * fma(pow((p / x), 4.0), -6.0, (2.0 * pow((p / x), 2.0)))));
} else {
tmp = exp((0.5 * log((0.5 + (0.5 / (hypot(x, (p * 2.0)) / x))))));
}
return tmp;
}
function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -0.8) tmp = sqrt(Float64(0.5 * fma((Float64(p / x) ^ 4.0), -6.0, Float64(2.0 * (Float64(p / x) ^ 2.0))))); else tmp = exp(Float64(0.5 * log(Float64(0.5 + Float64(0.5 / Float64(hypot(x, Float64(p * 2.0)) / x)))))); end return tmp end
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.8], N[Sqrt[N[(0.5 * N[(N[Power[N[(p / x), $MachinePrecision], 4.0], $MachinePrecision] * -6.0 + N[(2.0 * N[Power[N[(p / x), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[(0.5 * N[Log[N[(0.5 + N[(0.5 / N[(N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.8:\\
\;\;\;\;\sqrt{0.5 \cdot \mathsf{fma}\left({\left(\frac{p}{x}\right)}^{4}, -6, 2 \cdot {\left(\frac{p}{x}\right)}^{2}\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{0.5 \cdot \log \left(0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.80000000000000004Initial program 15.8%
add-log-exp15.9%
+-commutative15.9%
add-sqr-sqrt15.9%
hypot-def15.9%
associate-*l*15.9%
sqrt-prod15.9%
metadata-eval15.9%
sqrt-unprod9.0%
add-sqr-sqrt15.9%
Applied egg-rr15.9%
add-log-exp15.8%
clear-num15.8%
Applied egg-rr15.8%
Taylor expanded in x around -inf 44.8%
+-commutative44.8%
+-commutative44.8%
distribute-rgt-out44.8%
fma-def44.8%
Simplified65.9%
if -0.80000000000000004 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 100.0%
pow1/2100.0%
pow-to-exp100.0%
Applied egg-rr100.0%
fma-udef100.0%
metadata-eval100.0%
distribute-rgt-in100.0%
distribute-lft-in100.0%
clear-num100.0%
un-div-inv100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Final simplification92.5%
(FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0) (sqrt (* 0.5 (* 2.0 (* (/ p x) (/ p x))))) (exp (* 0.5 (log (+ 0.5 (/ 0.5 (/ (hypot x (* p 2.0)) x))))))))
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
} else {
tmp = exp((0.5 * log((0.5 + (0.5 / (hypot(x, (p * 2.0)) / x))))));
}
return tmp;
}
public static double code(double p, double x) {
double tmp;
if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = Math.sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
} else {
tmp = Math.exp((0.5 * Math.log((0.5 + (0.5 / (Math.hypot(x, (p * 2.0)) / x))))));
}
return tmp;
}
def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0: tmp = math.sqrt((0.5 * (2.0 * ((p / x) * (p / x))))) else: tmp = math.exp((0.5 * math.log((0.5 + (0.5 / (math.hypot(x, (p * 2.0)) / x)))))) return tmp
function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0) tmp = sqrt(Float64(0.5 * Float64(2.0 * Float64(Float64(p / x) * Float64(p / x))))); else tmp = exp(Float64(0.5 * log(Float64(0.5 + Float64(0.5 / Float64(hypot(x, Float64(p * 2.0)) / x)))))); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x))))); else tmp = exp((0.5 * log((0.5 + (0.5 / (hypot(x, (p * 2.0)) / x)))))); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], N[Sqrt[N[(0.5 * N[(2.0 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Exp[N[(0.5 * N[Log[N[(0.5 + N[(0.5 / N[(N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;e^{0.5 \cdot \log \left(0.5 + \frac{0.5}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1Initial program 14.8%
Taylor expanded in x around -inf 48.7%
unpow248.7%
unpow248.7%
times-frac65.7%
Simplified65.7%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.8%
pow1/299.8%
pow-to-exp99.8%
Applied egg-rr99.8%
fma-udef99.8%
metadata-eval99.8%
distribute-rgt-in99.8%
distribute-lft-in99.8%
clear-num99.8%
un-div-inv99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Final simplification92.5%
(FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0) (sqrt (* 0.5 (* 2.0 (* (/ p x) (/ p x))))) (sqrt (* 0.5 (+ 1.0 (/ 1.0 (/ (hypot x (* p 2.0)) x)))))))
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
} else {
tmp = sqrt((0.5 * (1.0 + (1.0 / (hypot(x, (p * 2.0)) / x)))));
}
return tmp;
}
public static double code(double p, double x) {
double tmp;
if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = Math.sqrt((0.5 * (2.0 * ((p / x) * (p / x)))));
} else {
tmp = Math.sqrt((0.5 * (1.0 + (1.0 / (Math.hypot(x, (p * 2.0)) / x)))));
}
return tmp;
}
def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0: tmp = math.sqrt((0.5 * (2.0 * ((p / x) * (p / x))))) else: tmp = math.sqrt((0.5 * (1.0 + (1.0 / (math.hypot(x, (p * 2.0)) / x))))) return tmp
function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0) tmp = sqrt(Float64(0.5 * Float64(2.0 * Float64(Float64(p / x) * Float64(p / x))))); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / Float64(hypot(x, Float64(p * 2.0)) / x))))); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) tmp = sqrt((0.5 * (2.0 * ((p / x) * (p / x))))); else tmp = sqrt((0.5 * (1.0 + (1.0 / (hypot(x, (p * 2.0)) / x))))); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], N[Sqrt[N[(0.5 * N[(2.0 * N[(N[(p / x), $MachinePrecision] * N[(p / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[(N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\sqrt{0.5 \cdot \left(2 \cdot \left(\frac{p}{x} \cdot \frac{p}{x}\right)\right)}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{\frac{\mathsf{hypot}\left(x, p \cdot 2\right)}{x}}\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1Initial program 14.8%
Taylor expanded in x around -inf 48.7%
unpow248.7%
unpow248.7%
times-frac65.7%
Simplified65.7%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.8%
add-log-exp99.8%
+-commutative99.8%
add-sqr-sqrt99.8%
hypot-def99.8%
associate-*l*99.8%
sqrt-prod99.8%
metadata-eval99.8%
sqrt-unprod45.1%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
add-log-exp99.8%
clear-num99.8%
Applied egg-rr99.8%
Final simplification92.5%
(FPCore (p x) :precision binary64 (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p 2.0) x))))))
double code(double p, double x) {
return sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x)))));
}
public static double code(double p, double x) {
return Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p * 2.0), x)))));
}
def code(p, x): return math.sqrt((0.5 * (1.0 + (x / math.hypot((p * 2.0), x)))))
function code(p, x) return sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p * 2.0), x))))) end
function tmp = code(p, x) tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x))))); end
code[p_, x_] := 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}
\\
\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p \cdot 2, x\right)}\right)}
\end{array}
Initial program 81.6%
add-sqr-sqrt81.6%
hypot-def81.6%
associate-*l*81.6%
sqrt-prod81.6%
metadata-eval81.6%
sqrt-unprod37.1%
add-sqr-sqrt81.6%
Applied egg-rr81.6%
Final simplification81.6%
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ (- p) x)))
(if (<= p -2.6e-62)
(sqrt 0.5)
(if (<= p -3.5e-196)
(/ p x)
(if (<= p 6.6e-232)
1.0
(if (<= p 7e-155)
t_0
(if (<= p 3.2e-24)
1.0
(if (<= p 2.4e-5)
t_0
(sqrt (* 0.5 (+ 1.0 (/ (* x 0.5) p))))))))))))
double code(double p, double x) {
double t_0 = -p / x;
double tmp;
if (p <= -2.6e-62) {
tmp = sqrt(0.5);
} else if (p <= -3.5e-196) {
tmp = p / x;
} else if (p <= 6.6e-232) {
tmp = 1.0;
} else if (p <= 7e-155) {
tmp = t_0;
} else if (p <= 3.2e-24) {
tmp = 1.0;
} else if (p <= 2.4e-5) {
tmp = t_0;
} else {
tmp = sqrt((0.5 * (1.0 + ((x * 0.5) / p))));
}
return tmp;
}
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.6d-62)) then
tmp = sqrt(0.5d0)
else if (p <= (-3.5d-196)) then
tmp = p / x
else if (p <= 6.6d-232) then
tmp = 1.0d0
else if (p <= 7d-155) then
tmp = t_0
else if (p <= 3.2d-24) then
tmp = 1.0d0
else if (p <= 2.4d-5) then
tmp = t_0
else
tmp = sqrt((0.5d0 * (1.0d0 + ((x * 0.5d0) / p))))
end if
code = tmp
end function
public static double code(double p, double x) {
double t_0 = -p / x;
double tmp;
if (p <= -2.6e-62) {
tmp = Math.sqrt(0.5);
} else if (p <= -3.5e-196) {
tmp = p / x;
} else if (p <= 6.6e-232) {
tmp = 1.0;
} else if (p <= 7e-155) {
tmp = t_0;
} else if (p <= 3.2e-24) {
tmp = 1.0;
} else if (p <= 2.4e-5) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 * (1.0 + ((x * 0.5) / p))));
}
return tmp;
}
def code(p, x): t_0 = -p / x tmp = 0 if p <= -2.6e-62: tmp = math.sqrt(0.5) elif p <= -3.5e-196: tmp = p / x elif p <= 6.6e-232: tmp = 1.0 elif p <= 7e-155: tmp = t_0 elif p <= 3.2e-24: tmp = 1.0 elif p <= 2.4e-5: tmp = t_0 else: tmp = math.sqrt((0.5 * (1.0 + ((x * 0.5) / p)))) return tmp
function code(p, x) t_0 = Float64(Float64(-p) / x) tmp = 0.0 if (p <= -2.6e-62) tmp = sqrt(0.5); elseif (p <= -3.5e-196) tmp = Float64(p / x); elseif (p <= 6.6e-232) tmp = 1.0; elseif (p <= 7e-155) tmp = t_0; elseif (p <= 3.2e-24) tmp = 1.0; elseif (p <= 2.4e-5) tmp = t_0; else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(Float64(x * 0.5) / p)))); end return tmp end
function tmp_2 = code(p, x) t_0 = -p / x; tmp = 0.0; if (p <= -2.6e-62) tmp = sqrt(0.5); elseif (p <= -3.5e-196) tmp = p / x; elseif (p <= 6.6e-232) tmp = 1.0; elseif (p <= 7e-155) tmp = t_0; elseif (p <= 3.2e-24) tmp = 1.0; elseif (p <= 2.4e-5) tmp = t_0; else tmp = sqrt((0.5 * (1.0 + ((x * 0.5) / p)))); end tmp_2 = tmp; end
code[p_, x_] := Block[{t$95$0 = N[((-p) / x), $MachinePrecision]}, If[LessEqual[p, -2.6e-62], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, -3.5e-196], N[(p / x), $MachinePrecision], If[LessEqual[p, 6.6e-232], 1.0, If[LessEqual[p, 7e-155], t$95$0, If[LessEqual[p, 3.2e-24], 1.0, If[LessEqual[p, 2.4e-5], t$95$0, N[Sqrt[N[(0.5 * N[(1.0 + N[(N[(x * 0.5), $MachinePrecision] / p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{-p}{x}\\
\mathbf{if}\;p \leq -2.6 \cdot 10^{-62}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p \leq -3.5 \cdot 10^{-196}:\\
\;\;\;\;\frac{p}{x}\\
\mathbf{elif}\;p \leq 6.6 \cdot 10^{-232}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 7 \cdot 10^{-155}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 3.2 \cdot 10^{-24}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 2.4 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x \cdot 0.5}{p}\right)}\\
\end{array}
\end{array}
if p < -2.5999999999999999e-62Initial program 95.4%
Taylor expanded in x around 0 83.4%
if -2.5999999999999999e-62 < p < -3.50000000000000004e-196Initial program 41.3%
Taylor expanded in x around -inf 29.6%
unpow229.6%
unpow229.6%
times-frac41.4%
Simplified41.4%
Taylor expanded in p around 0 64.4%
if -3.50000000000000004e-196 < p < 6.5999999999999997e-232 or 7.00000000000000031e-155 < p < 3.20000000000000012e-24Initial program 78.6%
Taylor expanded in x around inf 64.2%
if 6.5999999999999997e-232 < p < 7.00000000000000031e-155 or 3.20000000000000012e-24 < p < 2.4000000000000001e-5Initial program 24.1%
pow1/224.1%
pow-to-exp24.1%
Applied egg-rr24.1%
Taylor expanded in x around -inf 81.8%
associate-*r/81.8%
neg-mul-181.8%
Simplified81.8%
if 2.4000000000000001e-5 < p Initial program 99.5%
Taylor expanded in x around 0 96.1%
*-commutative96.1%
associate-*l/96.1%
Simplified96.1%
Final simplification79.6%
(FPCore (p x) :precision binary64 (if (<= x -2.15e+58) (/ p x) (sqrt (* 0.5 (+ 1.0 (/ 1.0 (+ 1.0 (* 2.0 (* p (/ p (* x x)))))))))))
double code(double p, double x) {
double tmp;
if (x <= -2.15e+58) {
tmp = p / x;
} else {
tmp = sqrt((0.5 * (1.0 + (1.0 / (1.0 + (2.0 * (p * (p / (x * x)))))))));
}
return tmp;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2.15d+58)) then
tmp = p / x
else
tmp = sqrt((0.5d0 * (1.0d0 + (1.0d0 / (1.0d0 + (2.0d0 * (p * (p / (x * x)))))))))
end if
code = tmp
end function
public static double code(double p, double x) {
double tmp;
if (x <= -2.15e+58) {
tmp = p / x;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (1.0 / (1.0 + (2.0 * (p * (p / (x * x)))))))));
}
return tmp;
}
def code(p, x): tmp = 0 if x <= -2.15e+58: tmp = p / x else: tmp = math.sqrt((0.5 * (1.0 + (1.0 / (1.0 + (2.0 * (p * (p / (x * x))))))))) return tmp
function code(p, x) tmp = 0.0 if (x <= -2.15e+58) tmp = Float64(p / x); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / Float64(1.0 + Float64(2.0 * Float64(p * Float64(p / Float64(x * x))))))))); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if (x <= -2.15e+58) tmp = p / x; else tmp = sqrt((0.5 * (1.0 + (1.0 / (1.0 + (2.0 * (p * (p / (x * x))))))))); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[x, -2.15e+58], N[(p / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[(1.0 + N[(2.0 * N[(p * N[(p / N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{+58}:\\
\;\;\;\;\frac{p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{1 + 2 \cdot \left(p \cdot \frac{p}{x \cdot x}\right)}\right)}\\
\end{array}
\end{array}
if x < -2.14999999999999996e58Initial program 46.7%
Taylor expanded in x around -inf 40.3%
unpow240.3%
unpow240.3%
times-frac40.7%
Simplified40.7%
Taylor expanded in p around 0 52.9%
if -2.14999999999999996e58 < x Initial program 88.0%
add-log-exp88.0%
+-commutative88.0%
add-sqr-sqrt88.0%
hypot-def88.0%
associate-*l*88.0%
sqrt-prod88.0%
metadata-eval88.0%
sqrt-unprod41.0%
add-sqr-sqrt88.0%
Applied egg-rr88.0%
add-log-exp88.0%
clear-num88.0%
Applied egg-rr88.0%
Taylor expanded in x around inf 85.7%
unpow285.7%
associate-*r/85.7%
unpow285.7%
Simplified85.7%
Final simplification80.6%
(FPCore (p x)
:precision binary64
(if (<= p -2.8e-63)
(sqrt 0.5)
(if (<= p -2.25e-195)
(/ p x)
(if (<= p 4.95e-231)
1.0
(if (<= p 1.06e-151) (/ (- p) x) (if (<= p 4.2e-62) 1.0 (sqrt 0.5)))))))
double code(double p, double x) {
double tmp;
if (p <= -2.8e-63) {
tmp = sqrt(0.5);
} else if (p <= -2.25e-195) {
tmp = p / x;
} else if (p <= 4.95e-231) {
tmp = 1.0;
} else if (p <= 1.06e-151) {
tmp = -p / x;
} else if (p <= 4.2e-62) {
tmp = 1.0;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: tmp
if (p <= (-2.8d-63)) then
tmp = sqrt(0.5d0)
else if (p <= (-2.25d-195)) then
tmp = p / x
else if (p <= 4.95d-231) then
tmp = 1.0d0
else if (p <= 1.06d-151) then
tmp = -p / x
else if (p <= 4.2d-62) then
tmp = 1.0d0
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
public static double code(double p, double x) {
double tmp;
if (p <= -2.8e-63) {
tmp = Math.sqrt(0.5);
} else if (p <= -2.25e-195) {
tmp = p / x;
} else if (p <= 4.95e-231) {
tmp = 1.0;
} else if (p <= 1.06e-151) {
tmp = -p / x;
} else if (p <= 4.2e-62) {
tmp = 1.0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
def code(p, x): tmp = 0 if p <= -2.8e-63: tmp = math.sqrt(0.5) elif p <= -2.25e-195: tmp = p / x elif p <= 4.95e-231: tmp = 1.0 elif p <= 1.06e-151: tmp = -p / x elif p <= 4.2e-62: tmp = 1.0 else: tmp = math.sqrt(0.5) return tmp
function code(p, x) tmp = 0.0 if (p <= -2.8e-63) tmp = sqrt(0.5); elseif (p <= -2.25e-195) tmp = Float64(p / x); elseif (p <= 4.95e-231) tmp = 1.0; elseif (p <= 1.06e-151) tmp = Float64(Float64(-p) / x); elseif (p <= 4.2e-62) tmp = 1.0; else tmp = sqrt(0.5); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if (p <= -2.8e-63) tmp = sqrt(0.5); elseif (p <= -2.25e-195) tmp = p / x; elseif (p <= 4.95e-231) tmp = 1.0; elseif (p <= 1.06e-151) tmp = -p / x; elseif (p <= 4.2e-62) tmp = 1.0; else tmp = sqrt(0.5); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[p, -2.8e-63], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, -2.25e-195], N[(p / x), $MachinePrecision], If[LessEqual[p, 4.95e-231], 1.0, If[LessEqual[p, 1.06e-151], N[((-p) / x), $MachinePrecision], If[LessEqual[p, 4.2e-62], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;p \leq -2.8 \cdot 10^{-63}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p \leq -2.25 \cdot 10^{-195}:\\
\;\;\;\;\frac{p}{x}\\
\mathbf{elif}\;p \leq 4.95 \cdot 10^{-231}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.06 \cdot 10^{-151}:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{elif}\;p \leq 4.2 \cdot 10^{-62}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < -2.8000000000000002e-63 or 4.1999999999999998e-62 < p Initial program 93.8%
Taylor expanded in x around 0 83.8%
if -2.8000000000000002e-63 < p < -2.25e-195Initial program 41.3%
Taylor expanded in x around -inf 29.6%
unpow229.6%
unpow229.6%
times-frac41.4%
Simplified41.4%
Taylor expanded in p around 0 64.4%
if -2.25e-195 < p < 4.9500000000000001e-231 or 1.06e-151 < p < 4.1999999999999998e-62Initial program 78.6%
Taylor expanded in x around inf 67.7%
if 4.9500000000000001e-231 < p < 1.06e-151Initial program 30.9%
pow1/230.9%
pow-to-exp30.9%
Applied egg-rr30.9%
Taylor expanded in x around -inf 75.7%
associate-*r/75.7%
neg-mul-175.7%
Simplified75.7%
Final simplification77.8%
(FPCore (p x) :precision binary64 (if (<= p -6.2e-65) (sqrt 0.5) (if (<= p -1.85e-278) (/ p x) (if (<= p 5e-10) (/ (- p) x) (sqrt 0.5)))))
double code(double p, double x) {
double tmp;
if (p <= -6.2e-65) {
tmp = sqrt(0.5);
} else if (p <= -1.85e-278) {
tmp = p / x;
} else if (p <= 5e-10) {
tmp = -p / x;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: tmp
if (p <= (-6.2d-65)) then
tmp = sqrt(0.5d0)
else if (p <= (-1.85d-278)) then
tmp = p / x
else if (p <= 5d-10) then
tmp = -p / x
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
public static double code(double p, double x) {
double tmp;
if (p <= -6.2e-65) {
tmp = Math.sqrt(0.5);
} else if (p <= -1.85e-278) {
tmp = p / x;
} else if (p <= 5e-10) {
tmp = -p / x;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
def code(p, x): tmp = 0 if p <= -6.2e-65: tmp = math.sqrt(0.5) elif p <= -1.85e-278: tmp = p / x elif p <= 5e-10: tmp = -p / x else: tmp = math.sqrt(0.5) return tmp
function code(p, x) tmp = 0.0 if (p <= -6.2e-65) tmp = sqrt(0.5); elseif (p <= -1.85e-278) tmp = Float64(p / x); elseif (p <= 5e-10) tmp = Float64(Float64(-p) / x); else tmp = sqrt(0.5); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if (p <= -6.2e-65) tmp = sqrt(0.5); elseif (p <= -1.85e-278) tmp = p / x; elseif (p <= 5e-10) tmp = -p / x; else tmp = sqrt(0.5); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[p, -6.2e-65], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, -1.85e-278], N[(p / x), $MachinePrecision], If[LessEqual[p, 5e-10], N[((-p) / x), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;p \leq -6.2 \cdot 10^{-65}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p \leq -1.85 \cdot 10^{-278}:\\
\;\;\;\;\frac{p}{x}\\
\mathbf{elif}\;p \leq 5 \cdot 10^{-10}:\\
\;\;\;\;\frac{-p}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < -6.20000000000000032e-65 or 5.00000000000000031e-10 < p Initial program 97.2%
Taylor expanded in x around 0 87.8%
if -6.20000000000000032e-65 < p < -1.85000000000000011e-278Initial program 54.4%
Taylor expanded in x around -inf 19.6%
unpow219.6%
unpow219.6%
times-frac32.8%
Simplified32.8%
Taylor expanded in p around 0 50.4%
if -1.85000000000000011e-278 < p < 5.00000000000000031e-10Initial program 64.9%
pow1/264.9%
pow-to-exp64.9%
Applied egg-rr64.9%
Taylor expanded in x around -inf 47.4%
associate-*r/47.4%
neg-mul-147.4%
Simplified47.4%
Final simplification71.3%
(FPCore (p x) :precision binary64 (if (<= p -1.85e-278) (/ p x) (/ (- p) x)))
double code(double p, double x) {
double tmp;
if (p <= -1.85e-278) {
tmp = p / x;
} else {
tmp = -p / x;
}
return tmp;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: tmp
if (p <= (-1.85d-278)) then
tmp = p / x
else
tmp = -p / x
end if
code = tmp
end function
public static double code(double p, double x) {
double tmp;
if (p <= -1.85e-278) {
tmp = p / x;
} else {
tmp = -p / x;
}
return tmp;
}
def code(p, x): tmp = 0 if p <= -1.85e-278: tmp = p / x else: tmp = -p / x return tmp
function code(p, x) tmp = 0.0 if (p <= -1.85e-278) tmp = Float64(p / x); else tmp = Float64(Float64(-p) / x); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if (p <= -1.85e-278) tmp = p / x; else tmp = -p / x; end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[p, -1.85e-278], N[(p / x), $MachinePrecision], N[((-p) / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;p \leq -1.85 \cdot 10^{-278}:\\
\;\;\;\;\frac{p}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{-p}{x}\\
\end{array}
\end{array}
if p < -1.85000000000000011e-278Initial program 80.3%
Taylor expanded in x around -inf 13.5%
unpow213.5%
unpow213.5%
times-frac18.6%
Simplified18.6%
Taylor expanded in p around 0 23.5%
if -1.85000000000000011e-278 < p Initial program 82.9%
pow1/282.9%
pow-to-exp82.9%
Applied egg-rr82.9%
Taylor expanded in x around -inf 24.5%
associate-*r/24.5%
neg-mul-124.5%
Simplified24.5%
Final simplification24.0%
(FPCore (p x) :precision binary64 (/ p x))
double code(double p, double x) {
return p / x;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = p / x
end function
public static double code(double p, double x) {
return p / x;
}
def code(p, x): return p / x
function code(p, x) return Float64(p / x) end
function tmp = code(p, x) tmp = p / x; end
code[p_, x_] := N[(p / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{p}{x}
\end{array}
Initial program 81.6%
Taylor expanded in x around -inf 14.5%
unpow214.5%
unpow214.5%
times-frac18.4%
Simplified18.4%
Taylor expanded in p around 0 15.9%
Final simplification15.9%
(FPCore (p x) :precision binary64 (sqrt (+ 0.5 (/ (copysign 0.5 x) (hypot 1.0 (/ (* 2.0 p) x))))))
double code(double p, double x) {
return sqrt((0.5 + (copysign(0.5, x) / hypot(1.0, ((2.0 * p) / x)))));
}
public static double code(double p, double x) {
return Math.sqrt((0.5 + (Math.copySign(0.5, x) / Math.hypot(1.0, ((2.0 * p) / x)))));
}
def code(p, x): return math.sqrt((0.5 + (math.copysign(0.5, x) / math.hypot(1.0, ((2.0 * p) / x)))))
function code(p, x) return sqrt(Float64(0.5 + Float64(copysign(0.5, x) / hypot(1.0, Float64(Float64(2.0 * p) / x))))) end
function tmp = code(p, x) tmp = sqrt((0.5 + ((sign(x) * abs(0.5)) / hypot(1.0, ((2.0 * p) / x))))); end
code[p_, x_] := N[Sqrt[N[(0.5 + N[(N[With[{TMP1 = Abs[0.5], TMP2 = Sign[x]}, TMP1 * If[TMP2 == 0, 1, TMP2]], $MachinePrecision] / N[Sqrt[1.0 ^ 2 + N[(N[(2.0 * p), $MachinePrecision] / x), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 + \frac{\mathsf{copysign}\left(0.5, x\right)}{\mathsf{hypot}\left(1, \frac{2 \cdot p}{x}\right)}}
\end{array}
herbie shell --seed 2023194
(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))))))))