
(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}
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (cbrt (/ x (hypot x (* p_m 2.0))))))
(if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.99998)
(/ (- p_m) x)
(sqrt (* 0.5 (fma (pow t_0 2.0) t_0 1.0))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = cbrt((x / hypot(x, (p_m * 2.0))));
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99998) {
tmp = -p_m / x;
} else {
tmp = sqrt((0.5 * fma(pow(t_0, 2.0), t_0, 1.0)));
}
return tmp;
}
p_m = abs(p) function code(p_m, x) t_0 = cbrt(Float64(x / hypot(x, Float64(p_m * 2.0)))) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.99998) tmp = Float64(Float64(-p_m) / x); else tmp = sqrt(Float64(0.5 * fma((t_0 ^ 2.0), t_0, 1.0))); end return tmp end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[Power[N[(x / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]}, If[LessEqual[N[(x / N[Sqrt[N[(N[(p$95$m * N[(4.0 * p$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.99998], N[((-p$95$m) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[Power[t$95$0, 2.0], $MachinePrecision] * t$95$0 + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \sqrt[3]{\frac{x}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}}\\
\mathbf{if}\;\frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}} \leq -0.99998:\\
\;\;\;\;\frac{-p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \mathsf{fma}\left({t\_0}^{2}, t\_0, 1\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.99997999999999998Initial program 15.4%
+-commutative15.4%
sqr-neg15.4%
associate-*l*15.4%
sqr-neg15.4%
fma-def15.4%
sqr-neg15.4%
fma-def15.4%
associate-*l*15.4%
+-commutative15.4%
Simplified15.4%
Taylor expanded in x around -inf 58.0%
mul-1-neg58.0%
Simplified58.0%
if -0.99997999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.9%
+-commutative99.9%
add-cube-cbrt99.9%
fma-def99.9%
Applied egg-rr99.9%
Final simplification89.1%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.99998)
(/ (- p_m) x)
(pow
(pow (+ 0.5 (* 0.5 (/ 1.0 (/ (hypot x (* p_m 2.0)) x)))) 1.5)
0.3333333333333333)))p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99998) {
tmp = -p_m / x;
} else {
tmp = pow(pow((0.5 + (0.5 * (1.0 / (hypot(x, (p_m * 2.0)) / x)))), 1.5), 0.3333333333333333);
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if ((x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99998) {
tmp = -p_m / x;
} else {
tmp = Math.pow(Math.pow((0.5 + (0.5 * (1.0 / (Math.hypot(x, (p_m * 2.0)) / x)))), 1.5), 0.3333333333333333);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if (x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99998: tmp = -p_m / x else: tmp = math.pow(math.pow((0.5 + (0.5 * (1.0 / (math.hypot(x, (p_m * 2.0)) / x)))), 1.5), 0.3333333333333333) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.99998) tmp = Float64(Float64(-p_m) / x); else tmp = (Float64(0.5 + Float64(0.5 * Float64(1.0 / Float64(hypot(x, Float64(p_m * 2.0)) / x)))) ^ 1.5) ^ 0.3333333333333333; end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99998) tmp = -p_m / x; else tmp = ((0.5 + (0.5 * (1.0 / (hypot(x, (p_m * 2.0)) / x)))) ^ 1.5) ^ 0.3333333333333333; end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p$95$m * N[(4.0 * p$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.99998], N[((-p$95$m) / x), $MachinePrecision], N[Power[N[Power[N[(0.5 + N[(0.5 * N[(1.0 / N[(N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision], 0.3333333333333333], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}} \leq -0.99998:\\
\;\;\;\;\frac{-p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;{\left({\left(0.5 + 0.5 \cdot \frac{1}{\frac{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}{x}}\right)}^{1.5}\right)}^{0.3333333333333333}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.99997999999999998Initial program 15.4%
+-commutative15.4%
sqr-neg15.4%
associate-*l*15.4%
sqr-neg15.4%
fma-def15.4%
sqr-neg15.4%
fma-def15.4%
associate-*l*15.4%
+-commutative15.4%
Simplified15.4%
Taylor expanded in x around -inf 58.0%
mul-1-neg58.0%
Simplified58.0%
if -0.99997999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.9%
+-commutative99.9%
add-cube-cbrt99.9%
fma-def99.9%
Applied egg-rr99.9%
add-log-exp99.9%
fma-udef99.9%
unpow299.9%
add-cube-cbrt99.9%
Applied egg-rr99.9%
rem-log-exp99.9%
+-commutative99.9%
clear-num99.9%
*-commutative99.9%
*-commutative99.9%
add-cbrt-cube99.9%
pow1/399.9%
Applied egg-rr99.9%
clear-num99.9%
inv-pow99.9%
Applied egg-rr99.9%
unpow-199.9%
*-commutative99.9%
Simplified99.9%
Final simplification89.1%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -0.99998) (/ (- p_m) x) (sqrt (* 0.5 (+ 1.0 (/ 1.0 (/ (hypot x (* p_m 2.0)) x)))))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99998) {
tmp = -p_m / x;
} else {
tmp = sqrt((0.5 * (1.0 + (1.0 / (hypot(x, (p_m * 2.0)) / x)))));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if ((x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99998) {
tmp = -p_m / x;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (1.0 / (Math.hypot(x, (p_m * 2.0)) / x)))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if (x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99998: tmp = -p_m / x else: tmp = math.sqrt((0.5 * (1.0 + (1.0 / (math.hypot(x, (p_m * 2.0)) / x))))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) <= -0.99998) tmp = Float64(Float64(-p_m) / x); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / Float64(hypot(x, Float64(p_m * 2.0)) / x))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if ((x / sqrt(((p_m * (4.0 * p_m)) + (x * x)))) <= -0.99998) tmp = -p_m / x; else tmp = sqrt((0.5 * (1.0 + (1.0 / (hypot(x, (p_m * 2.0)) / x))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p$95$m * N[(4.0 * p$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.99998], N[((-p$95$m) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[(N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}} \leq -0.99998:\\
\;\;\;\;\frac{-p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{\frac{\mathsf{hypot}\left(x, p\_m \cdot 2\right)}{x}}\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.99997999999999998Initial program 15.4%
+-commutative15.4%
sqr-neg15.4%
associate-*l*15.4%
sqr-neg15.4%
fma-def15.4%
sqr-neg15.4%
fma-def15.4%
associate-*l*15.4%
+-commutative15.4%
Simplified15.4%
Taylor expanded in x around -inf 58.0%
mul-1-neg58.0%
Simplified58.0%
if -0.99997999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.9%
clear-num99.9%
+-commutative99.9%
associate-*r*99.9%
fma-udef99.9%
inv-pow99.9%
fma-udef99.9%
associate-*r*99.9%
add-sqr-sqrt99.9%
hypot-def99.9%
associate-*r*99.9%
*-commutative99.9%
sqrt-prod99.9%
sqrt-prod51.0%
add-sqr-sqrt99.9%
metadata-eval99.9%
Applied egg-rr99.9%
unpow-199.9%
*-commutative99.9%
Simplified99.9%
Final simplification89.1%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -2e+37) (/ (- p_m) x) (sqrt (* 0.5 (+ (/ x (hypot x (* p_m 2.0))) 1.0)))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -2e+37) {
tmp = -p_m / x;
} else {
tmp = sqrt((0.5 * ((x / hypot(x, (p_m * 2.0))) + 1.0)));
}
return tmp;
}
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= -2e+37) {
tmp = -p_m / x;
} else {
tmp = Math.sqrt((0.5 * ((x / Math.hypot(x, (p_m * 2.0))) + 1.0)));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -2e+37: tmp = -p_m / x else: tmp = math.sqrt((0.5 * ((x / math.hypot(x, (p_m * 2.0))) + 1.0))) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -2e+37) tmp = Float64(Float64(-p_m) / x); else tmp = sqrt(Float64(0.5 * Float64(Float64(x / hypot(x, Float64(p_m * 2.0))) + 1.0))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -2e+37) tmp = -p_m / x; else tmp = sqrt((0.5 * ((x / hypot(x, (p_m * 2.0))) + 1.0))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -2e+37], N[((-p$95$m) / x), $MachinePrecision], N[Sqrt[N[(0.5 * N[(N[(x / N[Sqrt[x ^ 2 + N[(p$95$m * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{+37}:\\
\;\;\;\;\frac{-p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(\frac{x}{\mathsf{hypot}\left(x, p\_m \cdot 2\right)} + 1\right)}\\
\end{array}
\end{array}
if x < -1.99999999999999991e37Initial program 43.6%
+-commutative43.6%
sqr-neg43.6%
associate-*l*43.6%
sqr-neg43.6%
fma-def43.6%
sqr-neg43.6%
fma-def43.6%
associate-*l*43.6%
+-commutative43.6%
Simplified43.6%
Taylor expanded in x around -inf 41.0%
mul-1-neg41.0%
Simplified41.0%
if -1.99999999999999991e37 < x Initial program 86.5%
+-commutative86.5%
sqr-neg86.5%
associate-*l*86.5%
sqr-neg86.5%
fma-def86.5%
sqr-neg86.5%
fma-def86.5%
associate-*l*86.5%
+-commutative86.5%
Simplified86.5%
*-commutative86.5%
fma-udef86.5%
associate-*r*86.5%
+-commutative86.5%
distribute-rgt1-in86.5%
+-commutative86.5%
Applied egg-rr86.5%
Final simplification77.6%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ (- p_m) x)))
(if (<= p_m 7.2e-188)
t_0
(if (<= p_m 1.4e-141)
(+ 1.0 (* (* (/ p_m x) (/ p_m x)) -0.5))
(if (<= p_m 2.1e-119)
t_0
(if (<= p_m 4.8e-79)
1.0
(sqrt
(*
0.5
(+ 1.0 (/ 1.0 (+ (* 0.25 (/ x p_m)) (* (/ p_m x) 2.0))))))))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = -p_m / x;
double tmp;
if (p_m <= 7.2e-188) {
tmp = t_0;
} else if (p_m <= 1.4e-141) {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
} else if (p_m <= 2.1e-119) {
tmp = t_0;
} else if (p_m <= 4.8e-79) {
tmp = 1.0;
} else {
tmp = sqrt((0.5 * (1.0 + (1.0 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0))))));
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = -p_m / x
if (p_m <= 7.2d-188) then
tmp = t_0
else if (p_m <= 1.4d-141) then
tmp = 1.0d0 + (((p_m / x) * (p_m / x)) * (-0.5d0))
else if (p_m <= 2.1d-119) then
tmp = t_0
else if (p_m <= 4.8d-79) then
tmp = 1.0d0
else
tmp = sqrt((0.5d0 * (1.0d0 + (1.0d0 / ((0.25d0 * (x / p_m)) + ((p_m / x) * 2.0d0))))))
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = -p_m / x;
double tmp;
if (p_m <= 7.2e-188) {
tmp = t_0;
} else if (p_m <= 1.4e-141) {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
} else if (p_m <= 2.1e-119) {
tmp = t_0;
} else if (p_m <= 4.8e-79) {
tmp = 1.0;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (1.0 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0))))));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = -p_m / x tmp = 0 if p_m <= 7.2e-188: tmp = t_0 elif p_m <= 1.4e-141: tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5) elif p_m <= 2.1e-119: tmp = t_0 elif p_m <= 4.8e-79: tmp = 1.0 else: tmp = math.sqrt((0.5 * (1.0 + (1.0 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0)))))) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(Float64(-p_m) / x) tmp = 0.0 if (p_m <= 7.2e-188) tmp = t_0; elseif (p_m <= 1.4e-141) tmp = Float64(1.0 + Float64(Float64(Float64(p_m / x) * Float64(p_m / x)) * -0.5)); elseif (p_m <= 2.1e-119) tmp = t_0; elseif (p_m <= 4.8e-79) tmp = 1.0; else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / Float64(Float64(0.25 * Float64(x / p_m)) + Float64(Float64(p_m / x) * 2.0)))))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = -p_m / x; tmp = 0.0; if (p_m <= 7.2e-188) tmp = t_0; elseif (p_m <= 1.4e-141) tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5); elseif (p_m <= 2.1e-119) tmp = t_0; elseif (p_m <= 4.8e-79) tmp = 1.0; else tmp = sqrt((0.5 * (1.0 + (1.0 / ((0.25 * (x / p_m)) + ((p_m / x) * 2.0)))))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[((-p$95$m) / x), $MachinePrecision]}, If[LessEqual[p$95$m, 7.2e-188], t$95$0, If[LessEqual[p$95$m, 1.4e-141], N[(1.0 + N[(N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 2.1e-119], t$95$0, If[LessEqual[p$95$m, 4.8e-79], 1.0, N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[(N[(0.25 * N[(x / p$95$m), $MachinePrecision]), $MachinePrecision] + N[(N[(p$95$m / x), $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \frac{-p\_m}{x}\\
\mathbf{if}\;p\_m \leq 7.2 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 1.4 \cdot 10^{-141}:\\
\;\;\;\;1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\
\mathbf{elif}\;p\_m \leq 2.1 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 4.8 \cdot 10^{-79}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{0.25 \cdot \frac{x}{p\_m} + \frac{p\_m}{x} \cdot 2}\right)}\\
\end{array}
\end{array}
if p < 7.1999999999999994e-188 or 1.40000000000000006e-141 < p < 2.1e-119Initial program 73.8%
+-commutative73.8%
sqr-neg73.8%
associate-*l*73.8%
sqr-neg73.8%
fma-def73.8%
sqr-neg73.8%
fma-def73.8%
associate-*l*73.8%
+-commutative73.8%
Simplified73.8%
Taylor expanded in x around -inf 17.1%
mul-1-neg17.1%
Simplified17.1%
if 7.1999999999999994e-188 < p < 1.40000000000000006e-141Initial program 72.5%
+-commutative72.5%
sqr-neg72.5%
associate-*l*72.5%
sqr-neg72.5%
fma-def72.5%
sqr-neg72.5%
fma-def72.5%
associate-*l*72.5%
+-commutative72.5%
Simplified72.5%
Taylor expanded in x around inf 73.4%
*-commutative73.4%
Simplified73.4%
unpow273.4%
unpow273.4%
times-frac73.4%
Applied egg-rr73.4%
if 2.1e-119 < p < 4.80000000000000011e-79Initial program 81.0%
Taylor expanded in x around inf 79.8%
if 4.80000000000000011e-79 < p Initial program 86.5%
+-commutative86.5%
sqr-neg86.5%
associate-*l*86.5%
sqr-neg86.5%
fma-def86.5%
sqr-neg86.5%
fma-def86.5%
associate-*l*86.5%
+-commutative86.5%
Simplified86.5%
*-commutative86.5%
fma-udef86.5%
associate-*r*86.5%
+-commutative86.5%
distribute-rgt1-in86.5%
+-commutative86.5%
Applied egg-rr86.5%
clear-num86.5%
inv-pow86.5%
Applied egg-rr86.5%
unpow-186.5%
*-commutative86.5%
Simplified86.5%
Taylor expanded in x around 0 81.4%
Final simplification41.7%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ (- p_m) x)) (t_1 (+ 1.0 (* (* (/ p_m x) (/ p_m x)) -0.5))))
(if (<= p_m 1.05e-188)
t_0
(if (<= p_m 4e-141)
t_1
(if (<= p_m 2.36e-119) t_0 (if (<= p_m 2.35e-81) t_1 (sqrt 0.5)))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = -p_m / x;
double t_1 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
double tmp;
if (p_m <= 1.05e-188) {
tmp = t_0;
} else if (p_m <= 4e-141) {
tmp = t_1;
} else if (p_m <= 2.36e-119) {
tmp = t_0;
} else if (p_m <= 2.35e-81) {
tmp = t_1;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = -p_m / x
t_1 = 1.0d0 + (((p_m / x) * (p_m / x)) * (-0.5d0))
if (p_m <= 1.05d-188) then
tmp = t_0
else if (p_m <= 4d-141) then
tmp = t_1
else if (p_m <= 2.36d-119) then
tmp = t_0
else if (p_m <= 2.35d-81) then
tmp = t_1
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = -p_m / x;
double t_1 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
double tmp;
if (p_m <= 1.05e-188) {
tmp = t_0;
} else if (p_m <= 4e-141) {
tmp = t_1;
} else if (p_m <= 2.36e-119) {
tmp = t_0;
} else if (p_m <= 2.35e-81) {
tmp = t_1;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = -p_m / x t_1 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5) tmp = 0 if p_m <= 1.05e-188: tmp = t_0 elif p_m <= 4e-141: tmp = t_1 elif p_m <= 2.36e-119: tmp = t_0 elif p_m <= 2.35e-81: tmp = t_1 else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(Float64(-p_m) / x) t_1 = Float64(1.0 + Float64(Float64(Float64(p_m / x) * Float64(p_m / x)) * -0.5)) tmp = 0.0 if (p_m <= 1.05e-188) tmp = t_0; elseif (p_m <= 4e-141) tmp = t_1; elseif (p_m <= 2.36e-119) tmp = t_0; elseif (p_m <= 2.35e-81) tmp = t_1; else tmp = sqrt(0.5); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = -p_m / x; t_1 = 1.0 + (((p_m / x) * (p_m / x)) * -0.5); tmp = 0.0; if (p_m <= 1.05e-188) tmp = t_0; elseif (p_m <= 4e-141) tmp = t_1; elseif (p_m <= 2.36e-119) tmp = t_0; elseif (p_m <= 2.35e-81) tmp = t_1; else tmp = sqrt(0.5); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[((-p$95$m) / x), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[(N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[p$95$m, 1.05e-188], t$95$0, If[LessEqual[p$95$m, 4e-141], t$95$1, If[LessEqual[p$95$m, 2.36e-119], t$95$0, If[LessEqual[p$95$m, 2.35e-81], t$95$1, N[Sqrt[0.5], $MachinePrecision]]]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \frac{-p\_m}{x}\\
t_1 := 1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\
\mathbf{if}\;p\_m \leq 1.05 \cdot 10^{-188}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 4 \cdot 10^{-141}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;p\_m \leq 2.36 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 2.35 \cdot 10^{-81}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.05e-188 or 4.0000000000000002e-141 < p < 2.35999999999999992e-119Initial program 73.8%
+-commutative73.8%
sqr-neg73.8%
associate-*l*73.8%
sqr-neg73.8%
fma-def73.8%
sqr-neg73.8%
fma-def73.8%
associate-*l*73.8%
+-commutative73.8%
Simplified73.8%
Taylor expanded in x around -inf 17.1%
mul-1-neg17.1%
Simplified17.1%
if 1.05e-188 < p < 4.0000000000000002e-141 or 2.35999999999999992e-119 < p < 2.35000000000000014e-81Initial program 77.5%
+-commutative77.5%
sqr-neg77.5%
associate-*l*77.5%
sqr-neg77.5%
fma-def77.5%
sqr-neg77.5%
fma-def77.5%
associate-*l*77.5%
+-commutative77.5%
Simplified77.5%
Taylor expanded in x around inf 77.8%
*-commutative77.8%
Simplified77.8%
unpow277.8%
unpow277.8%
times-frac77.8%
Applied egg-rr77.8%
if 2.35000000000000014e-81 < p Initial program 86.5%
Taylor expanded in x around 0 80.6%
Final simplification41.5%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ (- p_m) x)))
(if (<= p_m 2.6e-190)
t_0
(if (<= p_m 2.2e-141)
(+ 1.0 (* (* (/ p_m x) (/ p_m x)) -0.5))
(if (<= p_m 2.2e-119) t_0 (if (<= p_m 5.7e-79) 1.0 (sqrt 0.5)))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = -p_m / x;
double tmp;
if (p_m <= 2.6e-190) {
tmp = t_0;
} else if (p_m <= 2.2e-141) {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
} else if (p_m <= 2.2e-119) {
tmp = t_0;
} else if (p_m <= 5.7e-79) {
tmp = 1.0;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = -p_m / x
if (p_m <= 2.6d-190) then
tmp = t_0
else if (p_m <= 2.2d-141) then
tmp = 1.0d0 + (((p_m / x) * (p_m / x)) * (-0.5d0))
else if (p_m <= 2.2d-119) then
tmp = t_0
else if (p_m <= 5.7d-79) then
tmp = 1.0d0
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = -p_m / x;
double tmp;
if (p_m <= 2.6e-190) {
tmp = t_0;
} else if (p_m <= 2.2e-141) {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
} else if (p_m <= 2.2e-119) {
tmp = t_0;
} else if (p_m <= 5.7e-79) {
tmp = 1.0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = -p_m / x tmp = 0 if p_m <= 2.6e-190: tmp = t_0 elif p_m <= 2.2e-141: tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5) elif p_m <= 2.2e-119: tmp = t_0 elif p_m <= 5.7e-79: tmp = 1.0 else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(Float64(-p_m) / x) tmp = 0.0 if (p_m <= 2.6e-190) tmp = t_0; elseif (p_m <= 2.2e-141) tmp = Float64(1.0 + Float64(Float64(Float64(p_m / x) * Float64(p_m / x)) * -0.5)); elseif (p_m <= 2.2e-119) tmp = t_0; elseif (p_m <= 5.7e-79) tmp = 1.0; else tmp = sqrt(0.5); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = -p_m / x; tmp = 0.0; if (p_m <= 2.6e-190) tmp = t_0; elseif (p_m <= 2.2e-141) tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5); elseif (p_m <= 2.2e-119) tmp = t_0; elseif (p_m <= 5.7e-79) tmp = 1.0; else tmp = sqrt(0.5); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[((-p$95$m) / x), $MachinePrecision]}, If[LessEqual[p$95$m, 2.6e-190], t$95$0, If[LessEqual[p$95$m, 2.2e-141], N[(1.0 + N[(N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 2.2e-119], t$95$0, If[LessEqual[p$95$m, 5.7e-79], 1.0, N[Sqrt[0.5], $MachinePrecision]]]]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \frac{-p\_m}{x}\\
\mathbf{if}\;p\_m \leq 2.6 \cdot 10^{-190}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 2.2 \cdot 10^{-141}:\\
\;\;\;\;1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\
\mathbf{elif}\;p\_m \leq 2.2 \cdot 10^{-119}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 5.7 \cdot 10^{-79}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 2.5999999999999998e-190 or 2.20000000000000009e-141 < p < 2.2000000000000001e-119Initial program 73.8%
+-commutative73.8%
sqr-neg73.8%
associate-*l*73.8%
sqr-neg73.8%
fma-def73.8%
sqr-neg73.8%
fma-def73.8%
associate-*l*73.8%
+-commutative73.8%
Simplified73.8%
Taylor expanded in x around -inf 17.1%
mul-1-neg17.1%
Simplified17.1%
if 2.5999999999999998e-190 < p < 2.20000000000000009e-141Initial program 72.5%
+-commutative72.5%
sqr-neg72.5%
associate-*l*72.5%
sqr-neg72.5%
fma-def72.5%
sqr-neg72.5%
fma-def72.5%
associate-*l*72.5%
+-commutative72.5%
Simplified72.5%
Taylor expanded in x around inf 73.4%
*-commutative73.4%
Simplified73.4%
unpow273.4%
unpow273.4%
times-frac73.4%
Applied egg-rr73.4%
if 2.2000000000000001e-119 < p < 5.69999999999999957e-79Initial program 81.0%
Taylor expanded in x around inf 79.8%
if 5.69999999999999957e-79 < p Initial program 86.5%
Taylor expanded in x around 0 80.6%
Final simplification41.4%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x 7.5e-277) (/ (- p_m) x) (+ 1.0 (* (* (/ p_m x) (/ p_m x)) -0.5))))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= 7.5e-277) {
tmp = -p_m / x;
} else {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
}
return tmp;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 7.5d-277) then
tmp = -p_m / x
else
tmp = 1.0d0 + (((p_m / x) * (p_m / x)) * (-0.5d0))
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= 7.5e-277) {
tmp = -p_m / x;
} else {
tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= 7.5e-277: tmp = -p_m / x else: tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= 7.5e-277) tmp = Float64(Float64(-p_m) / x); else tmp = Float64(1.0 + Float64(Float64(Float64(p_m / x) * Float64(p_m / x)) * -0.5)); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= 7.5e-277) tmp = -p_m / x; else tmp = 1.0 + (((p_m / x) * (p_m / x)) * -0.5); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, 7.5e-277], N[((-p$95$m) / x), $MachinePrecision], N[(1.0 + N[(N[(N[(p$95$m / x), $MachinePrecision] * N[(p$95$m / x), $MachinePrecision]), $MachinePrecision] * -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.5 \cdot 10^{-277}:\\
\;\;\;\;\frac{-p\_m}{x}\\
\mathbf{else}:\\
\;\;\;\;1 + \left(\frac{p\_m}{x} \cdot \frac{p\_m}{x}\right) \cdot -0.5\\
\end{array}
\end{array}
if x < 7.49999999999999971e-277Initial program 57.2%
+-commutative57.2%
sqr-neg57.2%
associate-*l*57.2%
sqr-neg57.2%
fma-def57.2%
sqr-neg57.2%
fma-def57.2%
associate-*l*57.2%
+-commutative57.2%
Simplified57.2%
Taylor expanded in x around -inf 31.0%
mul-1-neg31.0%
Simplified31.0%
if 7.49999999999999971e-277 < x Initial program 100.0%
+-commutative100.0%
sqr-neg100.0%
associate-*l*100.0%
sqr-neg100.0%
fma-def100.0%
sqr-neg100.0%
fma-def100.0%
associate-*l*100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in x around inf 43.7%
*-commutative43.7%
Simplified43.7%
unpow243.7%
unpow243.7%
times-frac43.7%
Applied egg-rr43.7%
Final simplification37.2%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (/ (- p_m) x))
p_m = fabs(p);
double code(double p_m, double x) {
return -p_m / x;
}
p_m = abs(p)
real(8) function code(p_m, x)
real(8), intent (in) :: p_m
real(8), intent (in) :: x
code = -p_m / x
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
return -p_m / x;
}
p_m = math.fabs(p) def code(p_m, x): return -p_m / x
p_m = abs(p) function code(p_m, x) return Float64(Float64(-p_m) / x) end
p_m = abs(p); function tmp = code(p_m, x) tmp = -p_m / x; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := N[((-p$95$m) / x), $MachinePrecision]
\begin{array}{l}
p_m = \left|p\right|
\\
\frac{-p\_m}{x}
\end{array}
Initial program 78.1%
+-commutative78.1%
sqr-neg78.1%
associate-*l*78.1%
sqr-neg78.1%
fma-def78.1%
sqr-neg78.1%
fma-def78.1%
associate-*l*78.1%
+-commutative78.1%
Simplified78.1%
Taylor expanded in x around -inf 17.7%
mul-1-neg17.7%
Simplified17.7%
Final simplification17.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 2024040
(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))))))))