
(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 5 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 (/ x (sqrt (+ (* p_m (* 4.0 p_m)) (* x x))))))
(if (<= t_0 -0.5)
(- (/ p_m (- x)) (* -1.5 (pow (/ p_m x) 3.0)))
(sqrt (* 0.5 (+ t_0 1.0))))))p_m = fabs(p);
double code(double p_m, double x) {
double t_0 = x / sqrt(((p_m * (4.0 * p_m)) + (x * x)));
double tmp;
if (t_0 <= -0.5) {
tmp = (p_m / -x) - (-1.5 * pow((p_m / x), 3.0));
} else {
tmp = sqrt((0.5 * (t_0 + 1.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 = x / sqrt(((p_m * (4.0d0 * p_m)) + (x * x)))
if (t_0 <= (-0.5d0)) then
tmp = (p_m / -x) - ((-1.5d0) * ((p_m / x) ** 3.0d0))
else
tmp = sqrt((0.5d0 * (t_0 + 1.0d0)))
end if
code = tmp
end function
p_m = Math.abs(p);
public static double code(double p_m, double x) {
double t_0 = x / Math.sqrt(((p_m * (4.0 * p_m)) + (x * x)));
double tmp;
if (t_0 <= -0.5) {
tmp = (p_m / -x) - (-1.5 * Math.pow((p_m / x), 3.0));
} else {
tmp = Math.sqrt((0.5 * (t_0 + 1.0)));
}
return tmp;
}
p_m = math.fabs(p) def code(p_m, x): t_0 = x / math.sqrt(((p_m * (4.0 * p_m)) + (x * x))) tmp = 0 if t_0 <= -0.5: tmp = (p_m / -x) - (-1.5 * math.pow((p_m / x), 3.0)) else: tmp = math.sqrt((0.5 * (t_0 + 1.0))) return tmp
p_m = abs(p) function code(p_m, x) t_0 = Float64(x / sqrt(Float64(Float64(p_m * Float64(4.0 * p_m)) + Float64(x * x)))) tmp = 0.0 if (t_0 <= -0.5) tmp = Float64(Float64(p_m / Float64(-x)) - Float64(-1.5 * (Float64(p_m / x) ^ 3.0))); else tmp = sqrt(Float64(0.5 * Float64(t_0 + 1.0))); end return tmp end
p_m = abs(p); function tmp_2 = code(p_m, x) t_0 = x / sqrt(((p_m * (4.0 * p_m)) + (x * x))); tmp = 0.0; if (t_0 <= -0.5) tmp = (p_m / -x) - (-1.5 * ((p_m / x) ^ 3.0)); else tmp = sqrt((0.5 * (t_0 + 1.0))); end tmp_2 = tmp; end
p_m = N[Abs[p], $MachinePrecision]
code[p$95$m_, x_] := Block[{t$95$0 = N[(x / N[Sqrt[N[(N[(p$95$m * N[(4.0 * p$95$m), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -0.5], N[(N[(p$95$m / (-x)), $MachinePrecision] - N[(-1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(0.5 * N[(t$95$0 + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
p_m = \left|p\right|
\\
\begin{array}{l}
t_0 := \frac{x}{\sqrt{p\_m \cdot \left(4 \cdot p\_m\right) + x \cdot x}}\\
\mathbf{if}\;t\_0 \leq -0.5:\\
\;\;\;\;\frac{p\_m}{-x} - -1.5 \cdot {\left(\frac{p\_m}{x}\right)}^{3}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(t\_0 + 1\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) < -0.5Initial program 18.5%
+-commutative18.5%
sqr-neg18.5%
associate-*l*18.5%
sqr-neg18.5%
fma-define18.5%
sqr-neg18.5%
fma-define18.5%
associate-*l*18.5%
+-commutative18.5%
Simplified18.6%
Taylor expanded in x around -inf 43.4%
mul-1-neg43.4%
distribute-rgt-out43.4%
metadata-eval43.4%
Simplified43.4%
Taylor expanded in p around 0 49.4%
+-commutative49.4%
distribute-lft-in49.4%
associate-*r/49.5%
*-rgt-identity49.5%
*-commutative49.5%
associate-*r*49.5%
associate-/l*49.4%
unpow249.4%
cube-mult49.4%
*-commutative49.4%
cube-div53.8%
Simplified53.8%
if -0.5 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 #s(literal 4 binary64) p) p) (*.f64 x x)))) Initial program 100.0%
Final simplification87.5%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))))
(if (<= p_m 6.3e-257)
t_0
(if (<= p_m 4.5e-128)
1.0
(if (<= p_m 1.05e-80)
(- t_0 (* -1.5 (pow (/ p_m x) 3.0)))
(if (<= p_m 4.6e-57) 1.0 (if (<= p_m 4.5e-38) t_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 <= 6.3e-257) {
tmp = t_0;
} else if (p_m <= 4.5e-128) {
tmp = 1.0;
} else if (p_m <= 1.05e-80) {
tmp = t_0 - (-1.5 * pow((p_m / x), 3.0));
} else if (p_m <= 4.6e-57) {
tmp = 1.0;
} else if (p_m <= 4.5e-38) {
tmp = t_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 <= 6.3d-257) then
tmp = t_0
else if (p_m <= 4.5d-128) then
tmp = 1.0d0
else if (p_m <= 1.05d-80) then
tmp = t_0 - ((-1.5d0) * ((p_m / x) ** 3.0d0))
else if (p_m <= 4.6d-57) then
tmp = 1.0d0
else if (p_m <= 4.5d-38) then
tmp = t_0
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 <= 6.3e-257) {
tmp = t_0;
} else if (p_m <= 4.5e-128) {
tmp = 1.0;
} else if (p_m <= 1.05e-80) {
tmp = t_0 - (-1.5 * Math.pow((p_m / x), 3.0));
} else if (p_m <= 4.6e-57) {
tmp = 1.0;
} else if (p_m <= 4.5e-38) {
tmp = t_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 <= 6.3e-257: tmp = t_0 elif p_m <= 4.5e-128: tmp = 1.0 elif p_m <= 1.05e-80: tmp = t_0 - (-1.5 * math.pow((p_m / x), 3.0)) elif p_m <= 4.6e-57: tmp = 1.0 elif p_m <= 4.5e-38: tmp = t_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 <= 6.3e-257) tmp = t_0; elseif (p_m <= 4.5e-128) tmp = 1.0; elseif (p_m <= 1.05e-80) tmp = Float64(t_0 - Float64(-1.5 * (Float64(p_m / x) ^ 3.0))); elseif (p_m <= 4.6e-57) tmp = 1.0; elseif (p_m <= 4.5e-38) tmp = t_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 <= 6.3e-257) tmp = t_0; elseif (p_m <= 4.5e-128) tmp = 1.0; elseif (p_m <= 1.05e-80) tmp = t_0 - (-1.5 * ((p_m / x) ^ 3.0)); elseif (p_m <= 4.6e-57) tmp = 1.0; elseif (p_m <= 4.5e-38) tmp = t_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, 6.3e-257], t$95$0, If[LessEqual[p$95$m, 4.5e-128], 1.0, If[LessEqual[p$95$m, 1.05e-80], N[(t$95$0 - N[(-1.5 * N[Power[N[(p$95$m / x), $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[p$95$m, 4.6e-57], 1.0, If[LessEqual[p$95$m, 4.5e-38], t$95$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 6.3 \cdot 10^{-257}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 4.5 \cdot 10^{-128}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 1.05 \cdot 10^{-80}:\\
\;\;\;\;t\_0 - -1.5 \cdot {\left(\frac{p\_m}{x}\right)}^{3}\\
\mathbf{elif}\;p\_m \leq 4.6 \cdot 10^{-57}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 4.5 \cdot 10^{-38}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 6.29999999999999993e-257 or 4.6e-57 < p < 4.50000000000000009e-38Initial program 73.9%
+-commutative73.9%
sqr-neg73.9%
associate-*l*73.9%
sqr-neg73.9%
fma-define73.9%
sqr-neg73.9%
fma-define73.9%
associate-*l*73.9%
+-commutative73.9%
Simplified73.9%
Taylor expanded in x around -inf 14.3%
mul-1-neg14.3%
distribute-neg-frac214.3%
Simplified14.3%
if 6.29999999999999993e-257 < p < 4.4999999999999999e-128 or 1.05000000000000001e-80 < p < 4.6e-57Initial program 72.0%
Taylor expanded in x around inf 62.3%
if 4.4999999999999999e-128 < p < 1.05000000000000001e-80Initial program 36.1%
+-commutative36.1%
sqr-neg36.1%
associate-*l*36.1%
sqr-neg36.1%
fma-define36.1%
sqr-neg36.1%
fma-define36.1%
associate-*l*36.1%
+-commutative36.1%
Simplified36.1%
Taylor expanded in x around -inf 67.1%
mul-1-neg67.1%
distribute-rgt-out67.1%
metadata-eval67.1%
Simplified67.1%
Taylor expanded in p around 0 67.9%
+-commutative67.9%
distribute-lft-in67.9%
associate-*r/68.3%
*-rgt-identity68.3%
*-commutative68.3%
associate-*r*68.3%
associate-/l*68.3%
unpow268.3%
cube-mult68.3%
*-commutative68.3%
cube-div68.5%
Simplified68.5%
if 4.50000000000000009e-38 < p Initial program 95.7%
Taylor expanded in x around 0 88.5%
Final simplification41.6%
p_m = (fabs.f64 p)
(FPCore (p_m x)
:precision binary64
(let* ((t_0 (/ p_m (- x))))
(if (<= p_m 1.25e-256)
t_0
(if (<= p_m 7.3e-128)
1.0
(if (<= p_m 2.1e-81)
t_0
(if (<= p_m 1.65e-59) 1.0 (if (<= p_m 4.5e-38) t_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 <= 1.25e-256) {
tmp = t_0;
} else if (p_m <= 7.3e-128) {
tmp = 1.0;
} else if (p_m <= 2.1e-81) {
tmp = t_0;
} else if (p_m <= 1.65e-59) {
tmp = 1.0;
} else if (p_m <= 4.5e-38) {
tmp = t_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 <= 1.25d-256) then
tmp = t_0
else if (p_m <= 7.3d-128) then
tmp = 1.0d0
else if (p_m <= 2.1d-81) then
tmp = t_0
else if (p_m <= 1.65d-59) then
tmp = 1.0d0
else if (p_m <= 4.5d-38) then
tmp = t_0
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 <= 1.25e-256) {
tmp = t_0;
} else if (p_m <= 7.3e-128) {
tmp = 1.0;
} else if (p_m <= 2.1e-81) {
tmp = t_0;
} else if (p_m <= 1.65e-59) {
tmp = 1.0;
} else if (p_m <= 4.5e-38) {
tmp = t_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 <= 1.25e-256: tmp = t_0 elif p_m <= 7.3e-128: tmp = 1.0 elif p_m <= 2.1e-81: tmp = t_0 elif p_m <= 1.65e-59: tmp = 1.0 elif p_m <= 4.5e-38: tmp = t_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 <= 1.25e-256) tmp = t_0; elseif (p_m <= 7.3e-128) tmp = 1.0; elseif (p_m <= 2.1e-81) tmp = t_0; elseif (p_m <= 1.65e-59) tmp = 1.0; elseif (p_m <= 4.5e-38) tmp = t_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 <= 1.25e-256) tmp = t_0; elseif (p_m <= 7.3e-128) tmp = 1.0; elseif (p_m <= 2.1e-81) tmp = t_0; elseif (p_m <= 1.65e-59) tmp = 1.0; elseif (p_m <= 4.5e-38) tmp = t_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, 1.25e-256], t$95$0, If[LessEqual[p$95$m, 7.3e-128], 1.0, If[LessEqual[p$95$m, 2.1e-81], t$95$0, If[LessEqual[p$95$m, 1.65e-59], 1.0, If[LessEqual[p$95$m, 4.5e-38], t$95$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 1.25 \cdot 10^{-256}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 7.3 \cdot 10^{-128}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 2.1 \cdot 10^{-81}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;p\_m \leq 1.65 \cdot 10^{-59}:\\
\;\;\;\;1\\
\mathbf{elif}\;p\_m \leq 4.5 \cdot 10^{-38}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.25e-256 or 7.29999999999999972e-128 < p < 2.0999999999999999e-81 or 1.64999999999999991e-59 < p < 4.50000000000000009e-38Initial program 71.7%
+-commutative71.7%
sqr-neg71.7%
associate-*l*71.7%
sqr-neg71.7%
fma-define71.7%
sqr-neg71.7%
fma-define71.7%
associate-*l*71.7%
+-commutative71.7%
Simplified71.7%
Taylor expanded in x around -inf 17.3%
mul-1-neg17.3%
distribute-neg-frac217.3%
Simplified17.3%
if 1.25e-256 < p < 7.29999999999999972e-128 or 2.0999999999999999e-81 < p < 1.64999999999999991e-59Initial program 72.0%
Taylor expanded in x around inf 62.3%
if 4.50000000000000009e-38 < p Initial program 95.7%
Taylor expanded in x around 0 88.5%
Final simplification41.6%
p_m = (fabs.f64 p) (FPCore (p_m x) :precision binary64 (if (or (<= p_m 6e-81) (and (not (<= p_m 6.5e-68)) (<= p_m 8e-38))) (/ p_m (- x)) (sqrt 0.5)))
p_m = fabs(p);
double code(double p_m, double x) {
double tmp;
if ((p_m <= 6e-81) || (!(p_m <= 6.5e-68) && (p_m <= 8e-38))) {
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 <= 6d-81) .or. (.not. (p_m <= 6.5d-68)) .and. (p_m <= 8d-38)) 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 <= 6e-81) || (!(p_m <= 6.5e-68) && (p_m <= 8e-38))) {
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 <= 6e-81) or (not (p_m <= 6.5e-68) and (p_m <= 8e-38)): 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 <= 6e-81) || (!(p_m <= 6.5e-68) && (p_m <= 8e-38))) 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 <= 6e-81) || (~((p_m <= 6.5e-68)) && (p_m <= 8e-38))) 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[Or[LessEqual[p$95$m, 6e-81], And[N[Not[LessEqual[p$95$m, 6.5e-68]], $MachinePrecision], LessEqual[p$95$m, 8e-38]]], 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 6 \cdot 10^{-81} \lor \neg \left(p\_m \leq 6.5 \cdot 10^{-68}\right) \land p\_m \leq 8 \cdot 10^{-38}:\\
\;\;\;\;\frac{p\_m}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 5.9999999999999998e-81 or 6.4999999999999997e-68 < p < 7.9999999999999997e-38Initial program 71.0%
+-commutative71.0%
sqr-neg71.0%
associate-*l*71.0%
sqr-neg71.0%
fma-define71.0%
sqr-neg71.0%
fma-define71.0%
associate-*l*71.0%
+-commutative71.0%
Simplified71.0%
Taylor expanded in x around -inf 21.0%
mul-1-neg21.0%
distribute-neg-frac221.0%
Simplified21.0%
if 5.9999999999999998e-81 < p < 6.4999999999999997e-68 or 7.9999999999999997e-38 < p Initial program 96.0%
Taylor expanded in x around 0 86.0%
Final simplification39.3%
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 / Float64(-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.0%
+-commutative78.0%
sqr-neg78.0%
associate-*l*78.0%
sqr-neg78.0%
fma-define78.0%
sqr-neg78.0%
fma-define78.0%
associate-*l*78.0%
+-commutative78.0%
Simplified78.0%
Taylor expanded in x around -inf 17.0%
mul-1-neg17.0%
distribute-neg-frac217.0%
Simplified17.0%
(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 2024102
(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))))))))