
(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 6 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 (if (<= (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x)))) -1.0) (/ p_m (- x)) (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* 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)))) <= -1.0) {
tmp = p_m / -x;
} else {
tmp = sqrt((0.5 * (1.0 + (x / hypot((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)))) <= -1.0) {
tmp = p_m / -x;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((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)))) <= -1.0: tmp = p_m / -x else: tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((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)))) <= -1.0) tmp = Float64(p_m / Float64(-x)); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(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)))) <= -1.0) tmp = p_m / -x; else tmp = sqrt((0.5 * (1.0 + (x / hypot((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], -1.0], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(p$95$m * 2.0), $MachinePrecision] ^ 2 + x ^ 2], $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 -1:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p\_m \cdot 2, x\right)}\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) < -1Initial program 24.4%
Taylor expanded in x around -inf 60.9%
mul-1-neg60.9%
associate-/l*60.9%
distribute-rgt-neg-in60.9%
associate-/l*61.2%
Simplified61.2%
distribute-rgt-neg-out61.2%
neg-sub061.2%
associate-*r/60.9%
sqrt-unprod61.4%
metadata-eval61.4%
metadata-eval61.4%
associate-*r/61.7%
*-commutative61.7%
*-un-lft-identity61.7%
Applied egg-rr61.7%
neg-sub061.7%
distribute-neg-frac61.7%
Simplified61.7%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 99.8%
add-sqr-sqrt99.8%
hypot-define99.8%
associate-*l*99.8%
sqrt-prod99.8%
metadata-eval99.8%
sqrt-unprod47.6%
add-sqr-sqrt99.8%
Applied egg-rr99.8%
Final simplification92.4%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))))
(if (<= p_m 1.3e-248)
t_0
(if (<= p_m 9.5e-104)
1.0
(if (<= p_m 8.2e-84)
t_0
(if (<= p_m 2.75e-30) 1.0 (sqrt (+ 0.5 (/ (* x 0.25) p_m)))))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = p_m / -x;
double tmp;
if (p_m <= 1.3e-248) {
tmp = t_0;
} else if (p_m <= 9.5e-104) {
tmp = 1.0;
} else if (p_m <= 8.2e-84) {
tmp = t_0;
} else if (p_m <= 2.75e-30) {
tmp = 1.0;
} else {
tmp = sqrt((0.5 + ((x * 0.25) / p_m)));
}
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 <= 1.3d-248) then
tmp = t_0
else if (p_m <= 9.5d-104) then
tmp = 1.0d0
else if (p_m <= 8.2d-84) then
tmp = t_0
else if (p_m <= 2.75d-30) then
tmp = 1.0d0
else
tmp = sqrt((0.5d0 + ((x * 0.25d0) / p_m)))
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 <= 1.3e-248) {
tmp = t_0;
} else if (p_m <= 9.5e-104) {
tmp = 1.0;
} else if (p_m <= 8.2e-84) {
tmp = t_0;
} else if (p_m <= 2.75e-30) {
tmp = 1.0;
} else {
tmp = Math.sqrt((0.5 + ((x * 0.25) / p_m)));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = p_m / -x tmp = 0 if p_m <= 1.3e-248: tmp = t_0 elif p_m <= 9.5e-104: tmp = 1.0 elif p_m <= 8.2e-84: tmp = t_0 elif p_m <= 2.75e-30: tmp = 1.0 else: tmp = math.sqrt((0.5 + ((x * 0.25) / p_m))) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(p_m / Float64(-x)) tmp = 0.0 if (p_m <= 1.3e-248) tmp = t_0; elseif (p_m <= 9.5e-104) tmp = 1.0; elseif (p_m <= 8.2e-84) tmp = t_0; elseif (p_m <= 2.75e-30) tmp = 1.0; else tmp = sqrt(Float64(0.5 + Float64(Float64(x * 0.25) / p_m))); 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 <= 1.3e-248) tmp = t_0; elseif (p_m <= 9.5e-104) tmp = 1.0; elseif (p_m <= 8.2e-84) tmp = t_0; elseif (p_m <= 2.75e-30) tmp = 1.0; else tmp = sqrt((0.5 + ((x * 0.25) / p_m))); 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, 1.3e-248], t$95$0, If[LessEqual[p$95$m, 9.5e-104], 1.0, If[LessEqual[p$95$m, 8.2e-84], t$95$0, If[LessEqual[p$95$m, 2.75e-30], 1.0, N[Sqrt[N[(0.5 + N[(N[(x * 0.25), $MachinePrecision] / p$95$m), $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 1.3 \cdot 10^{-248}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 9.5 \cdot 10^{-104}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 8.2 \cdot 10^{-84}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 2.75 \cdot 10^{-30}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{x \cdot 0.25}{p\_m}}\\
\end{array}
\end{array}
if p < 1.30000000000000003e-248 or 9.5000000000000002e-104 < p < 8.2000000000000001e-84Initial program 81.6%
Taylor expanded in x around -inf 15.8%
mul-1-neg15.8%
associate-/l*15.8%
distribute-rgt-neg-in15.8%
associate-/l*15.8%
Simplified15.8%
distribute-rgt-neg-out15.8%
neg-sub015.8%
associate-*r/15.8%
sqrt-unprod15.9%
metadata-eval15.9%
metadata-eval15.9%
associate-*r/15.9%
*-commutative15.9%
*-un-lft-identity15.9%
Applied egg-rr15.9%
neg-sub015.9%
distribute-neg-frac15.9%
Simplified15.9%
if 1.30000000000000003e-248 < p < 9.5000000000000002e-104 or 8.2000000000000001e-84 < p < 2.74999999999999988e-30Initial program 76.1%
Taylor expanded in x around inf 65.8%
if 2.74999999999999988e-30 < p Initial program 97.2%
add-sqr-sqrt97.2%
hypot-define97.2%
associate-*l*97.2%
sqrt-prod97.2%
metadata-eval97.2%
sqrt-unprod97.2%
add-sqr-sqrt97.2%
Applied egg-rr97.2%
Taylor expanded in x around 0 90.6%
associate-*r/90.6%
Simplified90.6%
*-un-lft-identity90.6%
distribute-lft-in90.6%
metadata-eval90.6%
associate-/l*90.6%
associate-*r*90.6%
metadata-eval90.6%
Applied egg-rr90.6%
*-lft-identity90.6%
associate-*r/90.6%
Simplified90.6%
Final simplification42.3%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))))
(if (<= p_m 9.2e-250)
t_0
(if (<= p_m 3.3e-105)
1.0
(if (<= p_m 3.6e-84) t_0 (if (<= p_m 2e-30) 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 <= 9.2e-250) {
tmp = t_0;
} else if (p_m <= 3.3e-105) {
tmp = 1.0;
} else if (p_m <= 3.6e-84) {
tmp = t_0;
} else if (p_m <= 2e-30) {
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 <= 9.2d-250) then
tmp = t_0
else if (p_m <= 3.3d-105) then
tmp = 1.0d0
else if (p_m <= 3.6d-84) then
tmp = t_0
else if (p_m <= 2d-30) 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 <= 9.2e-250) {
tmp = t_0;
} else if (p_m <= 3.3e-105) {
tmp = 1.0;
} else if (p_m <= 3.6e-84) {
tmp = t_0;
} else if (p_m <= 2e-30) {
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 <= 9.2e-250: tmp = t_0 elif p_m <= 3.3e-105: tmp = 1.0 elif p_m <= 3.6e-84: tmp = t_0 elif p_m <= 2e-30: tmp = 1.0 else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(p_m / Float64(-x)) tmp = 0.0 if (p_m <= 9.2e-250) tmp = t_0; elseif (p_m <= 3.3e-105) tmp = 1.0; elseif (p_m <= 3.6e-84) tmp = t_0; elseif (p_m <= 2e-30) 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 <= 9.2e-250) tmp = t_0; elseif (p_m <= 3.3e-105) tmp = 1.0; elseif (p_m <= 3.6e-84) tmp = t_0; elseif (p_m <= 2e-30) 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, 9.2e-250], t$95$0, If[LessEqual[p$95$m, 3.3e-105], 1.0, If[LessEqual[p$95$m, 3.6e-84], t$95$0, If[LessEqual[p$95$m, 2e-30], 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 9.2 \cdot 10^{-250}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 3.3 \cdot 10^{-105}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 3.6 \cdot 10^{-84}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 2 \cdot 10^{-30}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 9.1999999999999998e-250 or 3.2999999999999999e-105 < p < 3.60000000000000003e-84Initial program 81.6%
Taylor expanded in x around -inf 15.8%
mul-1-neg15.8%
associate-/l*15.8%
distribute-rgt-neg-in15.8%
associate-/l*15.8%
Simplified15.8%
distribute-rgt-neg-out15.8%
neg-sub015.8%
associate-*r/15.8%
sqrt-unprod15.9%
metadata-eval15.9%
metadata-eval15.9%
associate-*r/15.9%
*-commutative15.9%
*-un-lft-identity15.9%
Applied egg-rr15.9%
neg-sub015.9%
distribute-neg-frac15.9%
Simplified15.9%
if 9.1999999999999998e-250 < p < 3.2999999999999999e-105 or 3.60000000000000003e-84 < p < 2e-30Initial program 76.1%
Taylor expanded in x around inf 65.8%
if 2e-30 < p Initial program 97.2%
Taylor expanded in x around 0 89.6%
Final simplification42.0%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= p_m 1.15e-61) (/ p_m (- x)) (sqrt 0.5)))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (p_m <= 1.15e-61) {
tmp = p_m / -x;
} 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) :: tmp
if (p_m <= 1.15d-61) then
tmp = p_m / -x
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 tmp;
if (p_m <= 1.15e-61) {
tmp = p_m / -x;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if p_m <= 1.15e-61: tmp = p_m / -x else: tmp = math.sqrt(0.5) return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (p_m <= 1.15e-61) tmp = Float64(p_m / Float64(-x)); else tmp = sqrt(0.5); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (p_m <= 1.15e-61) tmp = p_m / -x; else tmp = sqrt(0.5); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[p$95$m, 1.15e-61], N[(p$95$m / (-x)), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;p\_m \leq 1.15 \cdot 10^{-61}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.14999999999999996e-61Initial program 81.4%
Taylor expanded in x around -inf 17.2%
mul-1-neg17.2%
associate-/l*17.2%
distribute-rgt-neg-in17.2%
associate-/l*17.3%
Simplified17.3%
distribute-rgt-neg-out17.3%
neg-sub017.3%
associate-*r/17.2%
sqrt-unprod17.3%
metadata-eval17.3%
metadata-eval17.3%
associate-*r/17.4%
*-commutative17.4%
*-un-lft-identity17.4%
Applied egg-rr17.4%
neg-sub017.4%
distribute-neg-frac17.4%
Simplified17.4%
if 1.14999999999999996e-61 < p Initial program 93.8%
Taylor expanded in x around 0 84.6%
Final simplification37.6%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (<= x -2e-310) (/ p_m (- x)) (/ p_m x)))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if (x <= -2e-310) {
tmp = p_m / -x;
} else {
tmp = p_m / x;
}
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 <= (-2d-310)) then
tmp = p_m / -x
else
tmp = p_m / x
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double tmp;
if (x <= -2e-310) {
tmp = p_m / -x;
} else {
tmp = p_m / x;
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): tmp = 0 if x <= -2e-310: tmp = p_m / -x else: tmp = p_m / x return tmp
p_m = abs(p) function code(p_m, x) tmp = 0.0 if (x <= -2e-310) tmp = Float64(p_m / Float64(-x)); else tmp = Float64(p_m / x); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) tmp = 0.0; if (x <= -2e-310) tmp = p_m / -x; else tmp = p_m / x; end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision] code[p$95$m_, x_] := If[LessEqual[x, -2e-310], N[(p$95$m / (-x)), $MachinePrecision], N[(p$95$m / x), $MachinePrecision]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\frac{p\_m}{x}\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 69.8%
Taylor expanded in x around -inf 26.2%
mul-1-neg26.2%
associate-/l*26.2%
distribute-rgt-neg-in26.2%
associate-/l*26.3%
Simplified26.3%
distribute-rgt-neg-out26.3%
neg-sub026.3%
associate-*r/26.2%
sqrt-unprod26.4%
metadata-eval26.4%
metadata-eval26.4%
associate-*r/26.5%
*-commutative26.5%
*-un-lft-identity26.5%
Applied egg-rr26.5%
neg-sub026.5%
distribute-neg-frac26.5%
Simplified26.5%
if -1.999999999999994e-310 < x Initial program 100.0%
Taylor expanded in x around -inf 4.0%
mul-1-neg4.0%
associate-/l*4.0%
distribute-rgt-neg-in4.0%
associate-/l*4.0%
Simplified4.0%
add-sqr-sqrt0.0%
sqrt-unprod3.3%
sqr-neg3.3%
sqrt-unprod3.3%
add-sqr-sqrt3.3%
associate-*r/3.3%
sqrt-unprod3.3%
metadata-eval3.3%
metadata-eval3.3%
associate-*r/3.3%
*-commutative3.3%
*-un-lft-identity3.3%
Applied egg-rr3.3%
Final simplification14.8%
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(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 85.1%
Taylor expanded in x around -inf 14.9%
mul-1-neg14.9%
associate-/l*14.9%
distribute-rgt-neg-in14.9%
associate-/l*15.0%
Simplified15.0%
add-sqr-sqrt13.0%
sqrt-unprod14.7%
sqr-neg14.7%
sqrt-unprod1.7%
add-sqr-sqrt14.6%
associate-*r/14.6%
sqrt-unprod14.7%
metadata-eval14.7%
metadata-eval14.7%
associate-*r/14.7%
*-commutative14.7%
*-un-lft-identity14.7%
Applied egg-rr14.7%
Final simplification14.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 2024100
(FPCore (p x)
:name "Given's Rotation SVD example"
:precision binary64
:pre (and (< 1e-150 (fabs x)) (< (fabs x) 1e+150))
:alt
(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))))))))