
(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}
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -0.98) (/ p (- x)) (sqrt (+ 0.5 (* x (/ 0.5 (hypot x (* p 2.0))))))))
p = abs(p);
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.98) {
tmp = p / -x;
} else {
tmp = sqrt((0.5 + (x * (0.5 / hypot(x, (p * 2.0))))));
}
return tmp;
}
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.98) {
tmp = p / -x;
} else {
tmp = Math.sqrt((0.5 + (x * (0.5 / Math.hypot(x, (p * 2.0))))));
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.98: tmp = p / -x else: tmp = math.sqrt((0.5 + (x * (0.5 / math.hypot(x, (p * 2.0)))))) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -0.98) tmp = Float64(p / Float64(-x)); else tmp = sqrt(Float64(0.5 + Float64(x * Float64(0.5 / hypot(x, Float64(p * 2.0)))))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -0.98) tmp = p / -x; else tmp = sqrt((0.5 + (x * (0.5 / hypot(x, (p * 2.0)))))); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -0.98], N[(p / (-x)), $MachinePrecision], N[Sqrt[N[(0.5 + N[(x * N[(0.5 / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -0.98:\\
\;\;\;\;\frac{p}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + x \cdot \frac{0.5}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -0.97999999999999998Initial program 23.7%
Taylor expanded in x around -inf 56.9%
unpow256.9%
unpow256.9%
times-frac63.2%
Simplified63.2%
Taylor expanded in p around -inf 65.1%
mul-1-neg65.1%
*-lft-identity65.1%
distribute-rgt-neg-in65.1%
metadata-eval65.1%
distribute-frac-neg65.1%
times-frac65.1%
neg-mul-165.1%
remove-double-neg65.1%
neg-mul-165.1%
Simplified65.1%
if -0.97999999999999998 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 100.0%
clear-num100.0%
inv-pow100.0%
+-commutative100.0%
add-sqr-sqrt100.0%
hypot-def100.0%
associate-*l*100.0%
sqrt-prod100.0%
metadata-eval100.0%
sqrt-unprod51.3%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
unpow-1100.0%
*-commutative100.0%
metadata-eval100.0%
div-inv100.0%
Applied egg-rr100.0%
expm1-log1p-u98.9%
expm1-udef98.9%
Applied egg-rr98.9%
expm1-def98.9%
expm1-log1p100.0%
associate-/l*100.0%
Simplified100.0%
associate-/r/100.0%
Applied egg-rr100.0%
Final simplification90.6%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (or (<= x -3.1e+50) (and (not (<= x -3.4e-7)) (<= x -1.35e-95))) (/ p (- x)) (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p 2.0) x)))))))
p = abs(p);
double code(double p, double x) {
double tmp;
if ((x <= -3.1e+50) || (!(x <= -3.4e-7) && (x <= -1.35e-95))) {
tmp = p / -x;
} else {
tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x)))));
}
return tmp;
}
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if ((x <= -3.1e+50) || (!(x <= -3.4e-7) && (x <= -1.35e-95))) {
tmp = p / -x;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p * 2.0), x)))));
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if (x <= -3.1e+50) or (not (x <= -3.4e-7) and (x <= -1.35e-95)): tmp = p / -x else: tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p * 2.0), x))))) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if ((x <= -3.1e+50) || (!(x <= -3.4e-7) && (x <= -1.35e-95))) tmp = Float64(p / Float64(-x)); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p * 2.0), x))))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if ((x <= -3.1e+50) || (~((x <= -3.4e-7)) && (x <= -1.35e-95))) tmp = p / -x; else tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x))))); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[Or[LessEqual[x, -3.1e+50], And[N[Not[LessEqual[x, -3.4e-7]], $MachinePrecision], LessEqual[x, -1.35e-95]]], N[(p / (-x)), $MachinePrecision], 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}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{+50} \lor \neg \left(x \leq -3.4 \cdot 10^{-7}\right) \land x \leq -1.35 \cdot 10^{-95}:\\
\;\;\;\;\frac{p}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{\mathsf{hypot}\left(p \cdot 2, x\right)}\right)}\\
\end{array}
\end{array}
if x < -3.10000000000000003e50 or -3.39999999999999974e-7 < x < -1.35e-95Initial program 49.1%
Taylor expanded in x around -inf 39.0%
unpow239.0%
unpow239.0%
times-frac44.5%
Simplified44.5%
Taylor expanded in p around -inf 46.7%
mul-1-neg46.7%
*-lft-identity46.7%
distribute-rgt-neg-in46.7%
metadata-eval46.7%
distribute-frac-neg46.7%
times-frac46.7%
neg-mul-146.7%
remove-double-neg46.7%
neg-mul-146.7%
Simplified46.7%
if -3.10000000000000003e50 < x < -3.39999999999999974e-7 or -1.35e-95 < x Initial program 93.5%
add-sqr-sqrt93.5%
hypot-def93.5%
associate-*l*93.5%
sqrt-prod93.5%
metadata-eval93.5%
sqrt-unprod48.8%
add-sqr-sqrt93.5%
Applied egg-rr93.5%
Final simplification78.7%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ p (- x))))
(if (<= x -6e+50)
t_0
(if (<= x -5.2e-7)
(sqrt 0.5)
(if (<= x -1.35e-95)
t_0
(sqrt (* 0.5 (+ 1.0 (/ x (+ x (* 2.0 (/ (* p p) x))))))))))))p = abs(p);
double code(double p, double x) {
double t_0 = p / -x;
double tmp;
if (x <= -6e+50) {
tmp = t_0;
} else if (x <= -5.2e-7) {
tmp = sqrt(0.5);
} else if (x <= -1.35e-95) {
tmp = t_0;
} else {
tmp = sqrt((0.5 * (1.0 + (x / (x + (2.0 * ((p * p) / x)))))));
}
return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = p / -x
if (x <= (-6d+50)) then
tmp = t_0
else if (x <= (-5.2d-7)) then
tmp = sqrt(0.5d0)
else if (x <= (-1.35d-95)) then
tmp = t_0
else
tmp = sqrt((0.5d0 * (1.0d0 + (x / (x + (2.0d0 * ((p * p) / x)))))))
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double t_0 = p / -x;
double tmp;
if (x <= -6e+50) {
tmp = t_0;
} else if (x <= -5.2e-7) {
tmp = Math.sqrt(0.5);
} else if (x <= -1.35e-95) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / (x + (2.0 * ((p * p) / x)))))));
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = p / -x tmp = 0 if x <= -6e+50: tmp = t_0 elif x <= -5.2e-7: tmp = math.sqrt(0.5) elif x <= -1.35e-95: tmp = t_0 else: tmp = math.sqrt((0.5 * (1.0 + (x / (x + (2.0 * ((p * p) / x))))))) return tmp
p = abs(p) function code(p, x) t_0 = Float64(p / Float64(-x)) tmp = 0.0 if (x <= -6e+50) tmp = t_0; elseif (x <= -5.2e-7) tmp = sqrt(0.5); elseif (x <= -1.35e-95) tmp = t_0; else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / Float64(x + Float64(2.0 * Float64(Float64(p * p) / x))))))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = p / -x; tmp = 0.0; if (x <= -6e+50) tmp = t_0; elseif (x <= -5.2e-7) tmp = sqrt(0.5); elseif (x <= -1.35e-95) tmp = t_0; else tmp = sqrt((0.5 * (1.0 + (x / (x + (2.0 * ((p * p) / x))))))); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = N[(p / (-x)), $MachinePrecision]}, If[LessEqual[x, -6e+50], t$95$0, If[LessEqual[x, -5.2e-7], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[x, -1.35e-95], t$95$0, N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[(x + N[(2.0 * N[(N[(p * p), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{p}{-x}\\
\mathbf{if}\;x \leq -6 \cdot 10^{+50}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -5.2 \cdot 10^{-7}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;x \leq -1.35 \cdot 10^{-95}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{x + 2 \cdot \frac{p \cdot p}{x}}\right)}\\
\end{array}
\end{array}
if x < -5.9999999999999996e50 or -5.19999999999999998e-7 < x < -1.35e-95Initial program 49.1%
Taylor expanded in x around -inf 39.0%
unpow239.0%
unpow239.0%
times-frac44.5%
Simplified44.5%
Taylor expanded in p around -inf 46.7%
mul-1-neg46.7%
*-lft-identity46.7%
distribute-rgt-neg-in46.7%
metadata-eval46.7%
distribute-frac-neg46.7%
times-frac46.7%
neg-mul-146.7%
remove-double-neg46.7%
neg-mul-146.7%
Simplified46.7%
if -5.9999999999999996e50 < x < -5.19999999999999998e-7Initial program 68.2%
Taylor expanded in x around 0 65.2%
if -1.35e-95 < x Initial program 98.7%
Taylor expanded in p around 0 96.4%
unpow296.4%
Simplified96.4%
Final simplification77.0%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ p (- x))))
(if (<= x -1.72e+50)
t_0
(if (<= x -4.2e-7)
(sqrt (* 0.5 (+ 1.0 (/ 1.0 (+ (* 2.0 (/ p x)) (* 0.25 (/ x p)))))))
(if (<= x -1.3e-95)
t_0
(sqrt (* 0.5 (+ 1.0 (/ x (+ x (* 2.0 (/ (* p p) x))))))))))))p = abs(p);
double code(double p, double x) {
double t_0 = p / -x;
double tmp;
if (x <= -1.72e+50) {
tmp = t_0;
} else if (x <= -4.2e-7) {
tmp = sqrt((0.5 * (1.0 + (1.0 / ((2.0 * (p / x)) + (0.25 * (x / p)))))));
} else if (x <= -1.3e-95) {
tmp = t_0;
} else {
tmp = sqrt((0.5 * (1.0 + (x / (x + (2.0 * ((p * p) / x)))))));
}
return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = p / -x
if (x <= (-1.72d+50)) then
tmp = t_0
else if (x <= (-4.2d-7)) then
tmp = sqrt((0.5d0 * (1.0d0 + (1.0d0 / ((2.0d0 * (p / x)) + (0.25d0 * (x / p)))))))
else if (x <= (-1.3d-95)) then
tmp = t_0
else
tmp = sqrt((0.5d0 * (1.0d0 + (x / (x + (2.0d0 * ((p * p) / x)))))))
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double t_0 = p / -x;
double tmp;
if (x <= -1.72e+50) {
tmp = t_0;
} else if (x <= -4.2e-7) {
tmp = Math.sqrt((0.5 * (1.0 + (1.0 / ((2.0 * (p / x)) + (0.25 * (x / p)))))));
} else if (x <= -1.3e-95) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / (x + (2.0 * ((p * p) / x)))))));
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = p / -x tmp = 0 if x <= -1.72e+50: tmp = t_0 elif x <= -4.2e-7: tmp = math.sqrt((0.5 * (1.0 + (1.0 / ((2.0 * (p / x)) + (0.25 * (x / p))))))) elif x <= -1.3e-95: tmp = t_0 else: tmp = math.sqrt((0.5 * (1.0 + (x / (x + (2.0 * ((p * p) / x))))))) return tmp
p = abs(p) function code(p, x) t_0 = Float64(p / Float64(-x)) tmp = 0.0 if (x <= -1.72e+50) tmp = t_0; elseif (x <= -4.2e-7) tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / Float64(Float64(2.0 * Float64(p / x)) + Float64(0.25 * Float64(x / p))))))); elseif (x <= -1.3e-95) tmp = t_0; else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / Float64(x + Float64(2.0 * Float64(Float64(p * p) / x))))))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = p / -x; tmp = 0.0; if (x <= -1.72e+50) tmp = t_0; elseif (x <= -4.2e-7) tmp = sqrt((0.5 * (1.0 + (1.0 / ((2.0 * (p / x)) + (0.25 * (x / p))))))); elseif (x <= -1.3e-95) tmp = t_0; else tmp = sqrt((0.5 * (1.0 + (x / (x + (2.0 * ((p * p) / x))))))); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = N[(p / (-x)), $MachinePrecision]}, If[LessEqual[x, -1.72e+50], t$95$0, If[LessEqual[x, -4.2e-7], N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[(N[(2.0 * N[(p / x), $MachinePrecision]), $MachinePrecision] + N[(0.25 * N[(x / p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], If[LessEqual[x, -1.3e-95], t$95$0, N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[(x + N[(2.0 * N[(N[(p * p), $MachinePrecision] / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{p}{-x}\\
\mathbf{if}\;x \leq -1.72 \cdot 10^{+50}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x \leq -4.2 \cdot 10^{-7}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{1}{2 \cdot \frac{p}{x} + 0.25 \cdot \frac{x}{p}}\right)}\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{-95}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(1 + \frac{x}{x + 2 \cdot \frac{p \cdot p}{x}}\right)}\\
\end{array}
\end{array}
if x < -1.72e50 or -4.2e-7 < x < -1.3e-95Initial program 49.1%
Taylor expanded in x around -inf 39.0%
unpow239.0%
unpow239.0%
times-frac44.5%
Simplified44.5%
Taylor expanded in p around -inf 46.7%
mul-1-neg46.7%
*-lft-identity46.7%
distribute-rgt-neg-in46.7%
metadata-eval46.7%
distribute-frac-neg46.7%
times-frac46.7%
neg-mul-146.7%
remove-double-neg46.7%
neg-mul-146.7%
Simplified46.7%
if -1.72e50 < x < -4.2e-7Initial program 68.2%
clear-num68.2%
inv-pow68.2%
+-commutative68.2%
add-sqr-sqrt68.2%
hypot-def68.2%
associate-*l*68.2%
sqrt-prod68.2%
metadata-eval68.2%
sqrt-unprod27.4%
add-sqr-sqrt68.2%
Applied egg-rr68.2%
unpow-168.2%
*-commutative68.2%
metadata-eval68.2%
div-inv68.2%
Applied egg-rr68.2%
Taylor expanded in x around 0 65.3%
if -1.3e-95 < x Initial program 98.7%
Taylor expanded in p around 0 96.4%
unpow296.4%
Simplified96.4%
Final simplification77.0%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ p (- x))))
(if (<= p 3.9e-192)
t_0
(if (<= p 1.55e-133)
1.0
(if (<= p 2.9e-69)
t_0
(if (<= p 3.8e-53)
1.0
(if (<= p 7.5e-35) t_0 (sqrt (+ 0.5 (* 0.25 (/ x p)))))))))))p = abs(p);
double code(double p, double x) {
double t_0 = p / -x;
double tmp;
if (p <= 3.9e-192) {
tmp = t_0;
} else if (p <= 1.55e-133) {
tmp = 1.0;
} else if (p <= 2.9e-69) {
tmp = t_0;
} else if (p <= 3.8e-53) {
tmp = 1.0;
} else if (p <= 7.5e-35) {
tmp = t_0;
} else {
tmp = sqrt((0.5 + (0.25 * (x / p))));
}
return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = p / -x
if (p <= 3.9d-192) then
tmp = t_0
else if (p <= 1.55d-133) then
tmp = 1.0d0
else if (p <= 2.9d-69) then
tmp = t_0
else if (p <= 3.8d-53) then
tmp = 1.0d0
else if (p <= 7.5d-35) then
tmp = t_0
else
tmp = sqrt((0.5d0 + (0.25d0 * (x / p))))
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double t_0 = p / -x;
double tmp;
if (p <= 3.9e-192) {
tmp = t_0;
} else if (p <= 1.55e-133) {
tmp = 1.0;
} else if (p <= 2.9e-69) {
tmp = t_0;
} else if (p <= 3.8e-53) {
tmp = 1.0;
} else if (p <= 7.5e-35) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 + (0.25 * (x / p))));
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = p / -x tmp = 0 if p <= 3.9e-192: tmp = t_0 elif p <= 1.55e-133: tmp = 1.0 elif p <= 2.9e-69: tmp = t_0 elif p <= 3.8e-53: tmp = 1.0 elif p <= 7.5e-35: tmp = t_0 else: tmp = math.sqrt((0.5 + (0.25 * (x / p)))) return tmp
p = abs(p) function code(p, x) t_0 = Float64(p / Float64(-x)) tmp = 0.0 if (p <= 3.9e-192) tmp = t_0; elseif (p <= 1.55e-133) tmp = 1.0; elseif (p <= 2.9e-69) tmp = t_0; elseif (p <= 3.8e-53) tmp = 1.0; elseif (p <= 7.5e-35) tmp = t_0; else tmp = sqrt(Float64(0.5 + Float64(0.25 * Float64(x / p)))); end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = p / -x; tmp = 0.0; if (p <= 3.9e-192) tmp = t_0; elseif (p <= 1.55e-133) tmp = 1.0; elseif (p <= 2.9e-69) tmp = t_0; elseif (p <= 3.8e-53) tmp = 1.0; elseif (p <= 7.5e-35) tmp = t_0; else tmp = sqrt((0.5 + (0.25 * (x / p)))); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = N[(p / (-x)), $MachinePrecision]}, If[LessEqual[p, 3.9e-192], t$95$0, If[LessEqual[p, 1.55e-133], 1.0, If[LessEqual[p, 2.9e-69], t$95$0, If[LessEqual[p, 3.8e-53], 1.0, If[LessEqual[p, 7.5e-35], t$95$0, N[Sqrt[N[(0.5 + N[(0.25 * N[(x / p), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{p}{-x}\\
\mathbf{if}\;p \leq 3.9 \cdot 10^{-192}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 1.55 \cdot 10^{-133}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 2.9 \cdot 10^{-69}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 3.8 \cdot 10^{-53}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 7.5 \cdot 10^{-35}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + 0.25 \cdot \frac{x}{p}}\\
\end{array}
\end{array}
if p < 3.9000000000000003e-192 or 1.55000000000000008e-133 < p < 2.8999999999999998e-69 or 3.7999999999999998e-53 < p < 7.5e-35Initial program 71.9%
Taylor expanded in x around -inf 23.6%
unpow223.6%
unpow223.6%
times-frac26.3%
Simplified26.3%
Taylor expanded in p around -inf 25.5%
mul-1-neg25.5%
*-lft-identity25.5%
distribute-rgt-neg-in25.5%
metadata-eval25.5%
distribute-frac-neg25.5%
times-frac25.5%
neg-mul-125.5%
remove-double-neg25.5%
neg-mul-125.5%
Simplified25.5%
if 3.9000000000000003e-192 < p < 1.55000000000000008e-133 or 2.8999999999999998e-69 < p < 3.7999999999999998e-53Initial program 83.2%
clear-num83.2%
inv-pow83.2%
+-commutative83.2%
add-sqr-sqrt83.2%
hypot-def83.2%
associate-*l*83.2%
sqrt-prod83.2%
metadata-eval83.2%
sqrt-unprod83.2%
add-sqr-sqrt83.2%
Applied egg-rr83.2%
unpow-183.2%
*-commutative83.2%
metadata-eval83.2%
div-inv83.2%
Applied egg-rr83.2%
expm1-log1p-u83.2%
expm1-udef83.2%
Applied egg-rr83.2%
expm1-def83.2%
expm1-log1p83.2%
associate-/l*83.2%
Simplified83.2%
Taylor expanded in x around inf 78.5%
if 7.5e-35 < p Initial program 94.3%
Taylor expanded in x around 0 88.1%
*-commutative88.1%
associate-*l/88.1%
Simplified88.1%
expm1-log1p-u86.8%
expm1-udef86.8%
distribute-rgt-in86.8%
metadata-eval86.8%
associate-/l*86.8%
Applied egg-rr86.8%
expm1-def86.8%
expm1-log1p88.1%
associate-/r/88.1%
associate-*l*88.1%
metadata-eval88.1%
Simplified88.1%
Final simplification47.8%
NOTE: p should be positive before calling this function
(FPCore (p x)
:precision binary64
(let* ((t_0 (/ p (- x))))
(if (<= p 7.6e-193)
t_0
(if (<= p 2.15e-134)
1.0
(if (<= p 2.6e-71)
t_0
(if (<= p 4.3e-53) 1.0 (if (<= p 9.5e-35) t_0 (sqrt 0.5))))))))p = abs(p);
double code(double p, double x) {
double t_0 = p / -x;
double tmp;
if (p <= 7.6e-193) {
tmp = t_0;
} else if (p <= 2.15e-134) {
tmp = 1.0;
} else if (p <= 2.6e-71) {
tmp = t_0;
} else if (p <= 4.3e-53) {
tmp = 1.0;
} else if (p <= 9.5e-35) {
tmp = t_0;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = p / -x
if (p <= 7.6d-193) then
tmp = t_0
else if (p <= 2.15d-134) then
tmp = 1.0d0
else if (p <= 2.6d-71) then
tmp = t_0
else if (p <= 4.3d-53) then
tmp = 1.0d0
else if (p <= 9.5d-35) then
tmp = t_0
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double t_0 = p / -x;
double tmp;
if (p <= 7.6e-193) {
tmp = t_0;
} else if (p <= 2.15e-134) {
tmp = 1.0;
} else if (p <= 2.6e-71) {
tmp = t_0;
} else if (p <= 4.3e-53) {
tmp = 1.0;
} else if (p <= 9.5e-35) {
tmp = t_0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): t_0 = p / -x tmp = 0 if p <= 7.6e-193: tmp = t_0 elif p <= 2.15e-134: tmp = 1.0 elif p <= 2.6e-71: tmp = t_0 elif p <= 4.3e-53: tmp = 1.0 elif p <= 9.5e-35: tmp = t_0 else: tmp = math.sqrt(0.5) return tmp
p = abs(p) function code(p, x) t_0 = Float64(p / Float64(-x)) tmp = 0.0 if (p <= 7.6e-193) tmp = t_0; elseif (p <= 2.15e-134) tmp = 1.0; elseif (p <= 2.6e-71) tmp = t_0; elseif (p <= 4.3e-53) tmp = 1.0; elseif (p <= 9.5e-35) tmp = t_0; else tmp = sqrt(0.5); end return tmp end
p = abs(p) function tmp_2 = code(p, x) t_0 = p / -x; tmp = 0.0; if (p <= 7.6e-193) tmp = t_0; elseif (p <= 2.15e-134) tmp = 1.0; elseif (p <= 2.6e-71) tmp = t_0; elseif (p <= 4.3e-53) tmp = 1.0; elseif (p <= 9.5e-35) tmp = t_0; else tmp = sqrt(0.5); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function
code[p_, x_] := Block[{t$95$0 = N[(p / (-x)), $MachinePrecision]}, If[LessEqual[p, 7.6e-193], t$95$0, If[LessEqual[p, 2.15e-134], 1.0, If[LessEqual[p, 2.6e-71], t$95$0, If[LessEqual[p, 4.3e-53], 1.0, If[LessEqual[p, 9.5e-35], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
t_0 := \frac{p}{-x}\\
\mathbf{if}\;p \leq 7.6 \cdot 10^{-193}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 2.15 \cdot 10^{-134}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 2.6 \cdot 10^{-71}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 4.3 \cdot 10^{-53}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 9.5 \cdot 10^{-35}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 7.60000000000000007e-193 or 2.14999999999999993e-134 < p < 2.5999999999999999e-71 or 4.3e-53 < p < 9.5000000000000003e-35Initial program 71.9%
Taylor expanded in x around -inf 23.6%
unpow223.6%
unpow223.6%
times-frac26.3%
Simplified26.3%
Taylor expanded in p around -inf 25.5%
mul-1-neg25.5%
*-lft-identity25.5%
distribute-rgt-neg-in25.5%
metadata-eval25.5%
distribute-frac-neg25.5%
times-frac25.5%
neg-mul-125.5%
remove-double-neg25.5%
neg-mul-125.5%
Simplified25.5%
if 7.60000000000000007e-193 < p < 2.14999999999999993e-134 or 2.5999999999999999e-71 < p < 4.3e-53Initial program 83.2%
clear-num83.2%
inv-pow83.2%
+-commutative83.2%
add-sqr-sqrt83.2%
hypot-def83.2%
associate-*l*83.2%
sqrt-prod83.2%
metadata-eval83.2%
sqrt-unprod83.2%
add-sqr-sqrt83.2%
Applied egg-rr83.2%
unpow-183.2%
*-commutative83.2%
metadata-eval83.2%
div-inv83.2%
Applied egg-rr83.2%
expm1-log1p-u83.2%
expm1-udef83.2%
Applied egg-rr83.2%
expm1-def83.2%
expm1-log1p83.2%
associate-/l*83.2%
Simplified83.2%
Taylor expanded in x around inf 78.5%
if 9.5000000000000003e-35 < p Initial program 94.3%
Taylor expanded in x around 0 86.4%
Final simplification47.3%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= p 1.55e-34) (/ p (- x)) (sqrt 0.5)))
p = abs(p);
double code(double p, double x) {
double tmp;
if (p <= 1.55e-34) {
tmp = p / -x;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: tmp
if (p <= 1.55d-34) then
tmp = p / -x
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if (p <= 1.55e-34) {
tmp = p / -x;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if p <= 1.55e-34: tmp = p / -x else: tmp = math.sqrt(0.5) return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (p <= 1.55e-34) tmp = Float64(p / Float64(-x)); else tmp = sqrt(0.5); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if (p <= 1.55e-34) tmp = p / -x; else tmp = sqrt(0.5); end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[p, 1.55e-34], N[(p / (-x)), $MachinePrecision], N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;p \leq 1.55 \cdot 10^{-34}:\\
\;\;\;\;\frac{p}{-x}\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.5499999999999999e-34Initial program 73.0%
Taylor expanded in x around -inf 22.6%
unpow222.6%
unpow222.6%
times-frac25.3%
Simplified25.3%
Taylor expanded in p around -inf 24.9%
mul-1-neg24.9%
*-lft-identity24.9%
distribute-rgt-neg-in24.9%
metadata-eval24.9%
distribute-frac-neg24.9%
times-frac24.9%
neg-mul-124.9%
remove-double-neg24.9%
neg-mul-124.9%
Simplified24.9%
if 1.5499999999999999e-34 < p Initial program 94.3%
Taylor expanded in x around 0 86.4%
Final simplification43.4%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (if (<= x -2e-310) (/ p (- x)) (/ p x)))
p = abs(p);
double code(double p, double x) {
double tmp;
if (x <= -2e-310) {
tmp = p / -x;
} else {
tmp = p / x;
}
return tmp;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: tmp
if (x <= (-2d-310)) then
tmp = p / -x
else
tmp = p / x
end if
code = tmp
end function
p = Math.abs(p);
public static double code(double p, double x) {
double tmp;
if (x <= -2e-310) {
tmp = p / -x;
} else {
tmp = p / x;
}
return tmp;
}
p = abs(p) def code(p, x): tmp = 0 if x <= -2e-310: tmp = p / -x else: tmp = p / x return tmp
p = abs(p) function code(p, x) tmp = 0.0 if (x <= -2e-310) tmp = Float64(p / Float64(-x)); else tmp = Float64(p / x); end return tmp end
p = abs(p) function tmp_2 = code(p, x) tmp = 0.0; if (x <= -2e-310) tmp = p / -x; else tmp = p / x; end tmp_2 = tmp; end
NOTE: p should be positive before calling this function code[p_, x_] := If[LessEqual[x, -2e-310], N[(p / (-x)), $MachinePrecision], N[(p / x), $MachinePrecision]]
\begin{array}{l}
p = |p|\\
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2 \cdot 10^{-310}:\\
\;\;\;\;\frac{p}{-x}\\
\mathbf{else}:\\
\;\;\;\;\frac{p}{x}\\
\end{array}
\end{array}
if x < -1.999999999999994e-310Initial program 61.5%
Taylor expanded in x around -inf 31.3%
unpow231.3%
unpow231.3%
times-frac34.6%
Simplified34.6%
Taylor expanded in p around -inf 34.5%
mul-1-neg34.5%
*-lft-identity34.5%
distribute-rgt-neg-in34.5%
metadata-eval34.5%
distribute-frac-neg34.5%
times-frac34.5%
neg-mul-134.5%
remove-double-neg34.5%
neg-mul-134.5%
Simplified34.5%
if -1.999999999999994e-310 < x Initial program 100.0%
Taylor expanded in x around -inf 5.1%
unpow25.1%
unpow25.1%
times-frac5.5%
Simplified5.5%
Taylor expanded in p around 0 3.7%
Final simplification20.2%
NOTE: p should be positive before calling this function (FPCore (p x) :precision binary64 (/ p x))
p = abs(p);
double code(double p, double x) {
return p / x;
}
NOTE: p should be positive before calling this function
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = p / x
end function
p = Math.abs(p);
public static double code(double p, double x) {
return p / x;
}
p = abs(p) def code(p, x): return p / x
p = abs(p) function code(p, x) return Float64(p / x) end
p = abs(p) function tmp = code(p, x) tmp = p / x; end
NOTE: p should be positive before calling this function code[p_, x_] := N[(p / x), $MachinePrecision]
\begin{array}{l}
p = |p|\\
\\
\frac{p}{x}
\end{array}
Initial program 79.4%
Taylor expanded in x around -inf 19.1%
unpow219.1%
unpow219.1%
times-frac21.1%
Simplified21.1%
Taylor expanded in p around 0 17.9%
Final simplification17.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 2023283
(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))))))))