
(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 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (p x) :precision binary64 (sqrt (* 0.5 (+ 1.0 (/ x (sqrt (+ (* (* 4.0 p) p) (* x x))))))))
double code(double p, double x) {
return sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x)))))));
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = sqrt((0.5d0 * (1.0d0 + (x / sqrt((((4.0d0 * p) * p) + (x * x)))))))
end function
public static double code(double p, double x) {
return Math.sqrt((0.5 * (1.0 + (x / Math.sqrt((((4.0 * p) * p) + (x * x)))))));
}
def code(p, x): return math.sqrt((0.5 * (1.0 + (x / math.sqrt((((4.0 * p) * p) + (x * x)))))))
function code(p, x) return sqrt(Float64(0.5 * Float64(1.0 + Float64(x / sqrt(Float64(Float64(Float64(4.0 * p) * p) + Float64(x * x))))))) end
function tmp = code(p, x) tmp = sqrt((0.5 * (1.0 + (x / sqrt((((4.0 * p) * p) + (x * x))))))); end
code[p_, x_] := N[Sqrt[N[(0.5 * N[(1.0 + N[(x / N[Sqrt[N[(N[(N[(4.0 * p), $MachinePrecision] * p), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\sqrt{0.5 \cdot \left(1 + \frac{x}{\sqrt{\left(4 \cdot p\right) \cdot p + x \cdot x}}\right)}
\end{array}
(FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0) (fabs (/ p x)) (sqrt (* 0.5 (log (exp (+ 1.0 (/ x (hypot x (* p 2.0))))))))))
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = fabs((p / x));
} else {
tmp = sqrt((0.5 * log(exp((1.0 + (x / hypot(x, (p * 2.0))))))));
}
return tmp;
}
public static double code(double p, double x) {
double tmp;
if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = Math.abs((p / x));
} else {
tmp = Math.sqrt((0.5 * Math.log(Math.exp((1.0 + (x / Math.hypot(x, (p * 2.0))))))));
}
return tmp;
}
def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0: tmp = math.fabs((p / x)) else: tmp = math.sqrt((0.5 * math.log(math.exp((1.0 + (x / math.hypot(x, (p * 2.0)))))))) return tmp
function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0) tmp = abs(Float64(p / x)); else tmp = sqrt(Float64(0.5 * log(exp(Float64(1.0 + Float64(x / hypot(x, Float64(p * 2.0)))))))); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) tmp = abs((p / x)); else tmp = sqrt((0.5 * log(exp((1.0 + (x / hypot(x, (p * 2.0)))))))); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], N[Abs[N[(p / x), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(0.5 * N[Log[N[Exp[N[(1.0 + N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\left|\frac{p}{x}\right|\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \log \left(e^{1 + \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}}\right)}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1Initial program 17.4%
*-commutative17.4%
sqrt-prod17.4%
+-commutative17.4%
add-sqr-sqrt17.4%
hypot-def17.4%
associate-*l*17.4%
sqrt-prod17.4%
metadata-eval17.4%
sqrt-unprod8.2%
add-sqr-sqrt17.4%
Applied egg-rr17.4%
Taylor expanded in x around -inf 61.6%
mul-1-neg61.6%
associate-/l*61.5%
distribute-neg-frac61.5%
Simplified61.5%
*-commutative61.5%
associate-/r/61.4%
add-sqr-sqrt8.6%
sqrt-unprod16.5%
sqr-neg16.5%
unpow216.5%
add-sqr-sqrt0.0%
sqrt-prod70.6%
unpow270.6%
sqrt-div58.2%
sqrt-prod58.5%
*-commutative58.5%
pow1/258.5%
pow1/258.5%
pow-prod-down58.7%
Applied egg-rr66.7%
unpow1/266.7%
associate-*r*66.7%
metadata-eval66.7%
*-lft-identity66.7%
unpow266.7%
rem-sqrt-square100.0%
Simplified100.0%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.9%
add-log-exp99.9%
+-commutative99.9%
add-sqr-sqrt99.9%
hypot-def99.9%
associate-*l*99.9%
sqrt-prod99.9%
metadata-eval99.9%
sqrt-unprod45.9%
add-sqr-sqrt99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (p x) :precision binary64 (if (<= (/ x (sqrt (+ (* p (* 4.0 p)) (* x x)))) -1.0) (fabs (/ p x)) (sqrt (+ (* 0.5 (+ 2.0 (/ x (hypot x (* p 2.0))))) -0.5))))
double code(double p, double x) {
double tmp;
if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = fabs((p / x));
} else {
tmp = sqrt(((0.5 * (2.0 + (x / hypot(x, (p * 2.0))))) + -0.5));
}
return tmp;
}
public static double code(double p, double x) {
double tmp;
if ((x / Math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) {
tmp = Math.abs((p / x));
} else {
tmp = Math.sqrt(((0.5 * (2.0 + (x / Math.hypot(x, (p * 2.0))))) + -0.5));
}
return tmp;
}
def code(p, x): tmp = 0 if (x / math.sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0: tmp = math.fabs((p / x)) else: tmp = math.sqrt(((0.5 * (2.0 + (x / math.hypot(x, (p * 2.0))))) + -0.5)) return tmp
function code(p, x) tmp = 0.0 if (Float64(x / sqrt(Float64(Float64(p * Float64(4.0 * p)) + Float64(x * x)))) <= -1.0) tmp = abs(Float64(p / x)); else tmp = sqrt(Float64(Float64(0.5 * Float64(2.0 + Float64(x / hypot(x, Float64(p * 2.0))))) + -0.5)); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if ((x / sqrt(((p * (4.0 * p)) + (x * x)))) <= -1.0) tmp = abs((p / x)); else tmp = sqrt(((0.5 * (2.0 + (x / hypot(x, (p * 2.0))))) + -0.5)); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[N[(x / N[Sqrt[N[(N[(p * N[(4.0 * p), $MachinePrecision]), $MachinePrecision] + N[(x * x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], -1.0], N[Abs[N[(p / x), $MachinePrecision]], $MachinePrecision], N[Sqrt[N[(N[(0.5 * N[(2.0 + N[(x / N[Sqrt[x ^ 2 + N[(p * 2.0), $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + -0.5), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{\sqrt{p \cdot \left(4 \cdot p\right) + x \cdot x}} \leq -1:\\
\;\;\;\;\left|\frac{p}{x}\right|\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 \cdot \left(2 + \frac{x}{\mathsf{hypot}\left(x, p \cdot 2\right)}\right) + -0.5}\\
\end{array}
\end{array}
if (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) < -1Initial program 17.4%
*-commutative17.4%
sqrt-prod17.4%
+-commutative17.4%
add-sqr-sqrt17.4%
hypot-def17.4%
associate-*l*17.4%
sqrt-prod17.4%
metadata-eval17.4%
sqrt-unprod8.2%
add-sqr-sqrt17.4%
Applied egg-rr17.4%
Taylor expanded in x around -inf 61.6%
mul-1-neg61.6%
associate-/l*61.5%
distribute-neg-frac61.5%
Simplified61.5%
*-commutative61.5%
associate-/r/61.4%
add-sqr-sqrt8.6%
sqrt-unprod16.5%
sqr-neg16.5%
unpow216.5%
add-sqr-sqrt0.0%
sqrt-prod70.6%
unpow270.6%
sqrt-div58.2%
sqrt-prod58.5%
*-commutative58.5%
pow1/258.5%
pow1/258.5%
pow-prod-down58.7%
Applied egg-rr66.7%
unpow1/266.7%
associate-*r*66.7%
metadata-eval66.7%
*-lft-identity66.7%
unpow266.7%
rem-sqrt-square100.0%
Simplified100.0%
if -1 < (/.f64 x (sqrt.f64 (+.f64 (*.f64 (*.f64 4 p) p) (*.f64 x x)))) Initial program 99.9%
*-commutative99.9%
sqrt-prod99.4%
+-commutative99.4%
add-sqr-sqrt99.4%
hypot-def99.4%
associate-*l*99.4%
sqrt-prod99.4%
metadata-eval99.4%
sqrt-unprod45.7%
add-sqr-sqrt99.4%
Applied egg-rr99.4%
expm1-log1p-u99.4%
expm1-udef99.4%
log1p-udef99.4%
add-exp-log99.4%
rem-log-exp99.4%
rem-log-exp99.4%
Applied egg-rr99.4%
associate--l+99.4%
sub-neg99.4%
*-commutative99.4%
metadata-eval99.4%
Simplified99.4%
expm1-log1p-u98.3%
expm1-udef98.8%
sqrt-unprod98.8%
associate-+r+98.8%
metadata-eval98.8%
Applied egg-rr98.8%
expm1-def98.8%
expm1-log1p99.9%
*-commutative99.9%
associate-+r+99.9%
distribute-lft-in99.9%
metadata-eval99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (p x) :precision binary64 (if (or (<= x -2.4e+104) (and (not (<= x -7.2e+47)) (<= x -9.2e-29))) (fabs (/ p x)) (sqrt (* 0.5 (+ 1.0 (/ x (hypot (* p 2.0) x)))))))
double code(double p, double x) {
double tmp;
if ((x <= -2.4e+104) || (!(x <= -7.2e+47) && (x <= -9.2e-29))) {
tmp = fabs((p / x));
} else {
tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x)))));
}
return tmp;
}
public static double code(double p, double x) {
double tmp;
if ((x <= -2.4e+104) || (!(x <= -7.2e+47) && (x <= -9.2e-29))) {
tmp = Math.abs((p / x));
} else {
tmp = Math.sqrt((0.5 * (1.0 + (x / Math.hypot((p * 2.0), x)))));
}
return tmp;
}
def code(p, x): tmp = 0 if (x <= -2.4e+104) or (not (x <= -7.2e+47) and (x <= -9.2e-29)): tmp = math.fabs((p / x)) else: tmp = math.sqrt((0.5 * (1.0 + (x / math.hypot((p * 2.0), x))))) return tmp
function code(p, x) tmp = 0.0 if ((x <= -2.4e+104) || (!(x <= -7.2e+47) && (x <= -9.2e-29))) tmp = abs(Float64(p / x)); else tmp = sqrt(Float64(0.5 * Float64(1.0 + Float64(x / hypot(Float64(p * 2.0), x))))); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if ((x <= -2.4e+104) || (~((x <= -7.2e+47)) && (x <= -9.2e-29))) tmp = abs((p / x)); else tmp = sqrt((0.5 * (1.0 + (x / hypot((p * 2.0), x))))); end tmp_2 = tmp; end
code[p_, x_] := If[Or[LessEqual[x, -2.4e+104], And[N[Not[LessEqual[x, -7.2e+47]], $MachinePrecision], LessEqual[x, -9.2e-29]]], N[Abs[N[(p / x), $MachinePrecision]], $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}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.4 \cdot 10^{+104} \lor \neg \left(x \leq -7.2 \cdot 10^{+47}\right) \land x \leq -9.2 \cdot 10^{-29}:\\
\;\;\;\;\left|\frac{p}{x}\right|\\
\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 < -2.4e104 or -7.20000000000000015e47 < x < -9.19999999999999965e-29Initial program 33.6%
*-commutative33.6%
sqrt-prod33.6%
+-commutative33.6%
add-sqr-sqrt33.6%
hypot-def33.6%
associate-*l*33.6%
sqrt-prod33.6%
metadata-eval33.6%
sqrt-unprod13.6%
add-sqr-sqrt33.6%
Applied egg-rr33.6%
Taylor expanded in x around -inf 47.8%
mul-1-neg47.8%
associate-/l*47.7%
distribute-neg-frac47.7%
Simplified47.7%
*-commutative47.7%
associate-/r/47.7%
add-sqr-sqrt4.5%
sqrt-unprod6.4%
sqr-neg6.4%
unpow26.4%
add-sqr-sqrt0.0%
sqrt-prod58.4%
unpow258.4%
sqrt-div47.0%
sqrt-prod47.4%
*-commutative47.4%
pow1/247.4%
pow1/247.4%
pow-prod-down47.5%
Applied egg-rr47.8%
unpow1/247.8%
associate-*r*47.8%
metadata-eval47.8%
*-lft-identity47.8%
unpow247.8%
rem-sqrt-square75.2%
Simplified75.2%
if -2.4e104 < x < -7.20000000000000015e47 or -9.19999999999999965e-29 < x Initial program 90.8%
add-sqr-sqrt90.8%
hypot-def90.8%
associate-*l*90.8%
sqrt-prod90.8%
metadata-eval90.8%
sqrt-unprod42.3%
add-sqr-sqrt90.8%
Applied egg-rr90.8%
Final simplification87.2%
(FPCore (p x)
:precision binary64
(let* ((t_0 (fabs (/ p x))))
(if (<= p 5e-254)
t_0
(if (<= p 4.9e-132)
1.0
(if (<= p 1.46e-120)
t_0
(if (<= p 5e-89)
1.0
(if (<= p 1e-37)
(sqrt 0.5)
(if (<= p 3.3e+28) t_0 (sqrt (+ 0.5 (* (/ x p) 0.25)))))))))))
double code(double p, double x) {
double t_0 = fabs((p / x));
double tmp;
if (p <= 5e-254) {
tmp = t_0;
} else if (p <= 4.9e-132) {
tmp = 1.0;
} else if (p <= 1.46e-120) {
tmp = t_0;
} else if (p <= 5e-89) {
tmp = 1.0;
} else if (p <= 1e-37) {
tmp = sqrt(0.5);
} else if (p <= 3.3e+28) {
tmp = t_0;
} else {
tmp = sqrt((0.5 + ((x / p) * 0.25)));
}
return tmp;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = abs((p / x))
if (p <= 5d-254) then
tmp = t_0
else if (p <= 4.9d-132) then
tmp = 1.0d0
else if (p <= 1.46d-120) then
tmp = t_0
else if (p <= 5d-89) then
tmp = 1.0d0
else if (p <= 1d-37) then
tmp = sqrt(0.5d0)
else if (p <= 3.3d+28) then
tmp = t_0
else
tmp = sqrt((0.5d0 + ((x / p) * 0.25d0)))
end if
code = tmp
end function
public static double code(double p, double x) {
double t_0 = Math.abs((p / x));
double tmp;
if (p <= 5e-254) {
tmp = t_0;
} else if (p <= 4.9e-132) {
tmp = 1.0;
} else if (p <= 1.46e-120) {
tmp = t_0;
} else if (p <= 5e-89) {
tmp = 1.0;
} else if (p <= 1e-37) {
tmp = Math.sqrt(0.5);
} else if (p <= 3.3e+28) {
tmp = t_0;
} else {
tmp = Math.sqrt((0.5 + ((x / p) * 0.25)));
}
return tmp;
}
def code(p, x): t_0 = math.fabs((p / x)) tmp = 0 if p <= 5e-254: tmp = t_0 elif p <= 4.9e-132: tmp = 1.0 elif p <= 1.46e-120: tmp = t_0 elif p <= 5e-89: tmp = 1.0 elif p <= 1e-37: tmp = math.sqrt(0.5) elif p <= 3.3e+28: tmp = t_0 else: tmp = math.sqrt((0.5 + ((x / p) * 0.25))) return tmp
function code(p, x) t_0 = abs(Float64(p / x)) tmp = 0.0 if (p <= 5e-254) tmp = t_0; elseif (p <= 4.9e-132) tmp = 1.0; elseif (p <= 1.46e-120) tmp = t_0; elseif (p <= 5e-89) tmp = 1.0; elseif (p <= 1e-37) tmp = sqrt(0.5); elseif (p <= 3.3e+28) tmp = t_0; else tmp = sqrt(Float64(0.5 + Float64(Float64(x / p) * 0.25))); end return tmp end
function tmp_2 = code(p, x) t_0 = abs((p / x)); tmp = 0.0; if (p <= 5e-254) tmp = t_0; elseif (p <= 4.9e-132) tmp = 1.0; elseif (p <= 1.46e-120) tmp = t_0; elseif (p <= 5e-89) tmp = 1.0; elseif (p <= 1e-37) tmp = sqrt(0.5); elseif (p <= 3.3e+28) tmp = t_0; else tmp = sqrt((0.5 + ((x / p) * 0.25))); end tmp_2 = tmp; end
code[p_, x_] := Block[{t$95$0 = N[Abs[N[(p / x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[p, 5e-254], t$95$0, If[LessEqual[p, 4.9e-132], 1.0, If[LessEqual[p, 1.46e-120], t$95$0, If[LessEqual[p, 5e-89], 1.0, If[LessEqual[p, 1e-37], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 3.3e+28], t$95$0, N[Sqrt[N[(0.5 + N[(N[(x / p), $MachinePrecision] * 0.25), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{p}{x}\right|\\
\mathbf{if}\;p \leq 5 \cdot 10^{-254}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 4.9 \cdot 10^{-132}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.46 \cdot 10^{-120}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 5 \cdot 10^{-89}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 10^{-37}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p \leq 3.3 \cdot 10^{+28}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5 + \frac{x}{p} \cdot 0.25}\\
\end{array}
\end{array}
if p < 5.0000000000000003e-254 or 4.89999999999999981e-132 < p < 1.4599999999999999e-120 or 1.00000000000000007e-37 < p < 3.3e28Initial program 73.9%
*-commutative73.9%
sqrt-prod73.5%
+-commutative73.5%
add-sqr-sqrt73.5%
hypot-def73.5%
associate-*l*73.5%
sqrt-prod73.5%
metadata-eval73.5%
sqrt-unprod9.5%
add-sqr-sqrt73.5%
Applied egg-rr73.5%
Taylor expanded in x around -inf 19.1%
mul-1-neg19.1%
associate-/l*19.1%
distribute-neg-frac19.1%
Simplified19.1%
*-commutative19.1%
associate-/r/19.1%
add-sqr-sqrt5.8%
sqrt-unprod8.3%
sqr-neg8.3%
unpow28.3%
add-sqr-sqrt2.2%
sqrt-prod25.3%
unpow225.3%
sqrt-div21.8%
sqrt-prod21.9%
*-commutative21.9%
pow1/221.9%
pow1/221.9%
pow-prod-down21.9%
Applied egg-rr25.4%
unpow1/225.4%
associate-*r*25.4%
metadata-eval25.4%
*-lft-identity25.4%
unpow225.4%
rem-sqrt-square36.0%
Simplified36.0%
if 5.0000000000000003e-254 < p < 4.89999999999999981e-132 or 1.4599999999999999e-120 < p < 4.99999999999999967e-89Initial program 65.1%
add-log-exp65.1%
+-commutative65.1%
add-sqr-sqrt65.1%
hypot-def65.1%
associate-*l*65.1%
sqrt-prod65.1%
metadata-eval65.1%
sqrt-unprod65.1%
add-sqr-sqrt65.1%
Applied egg-rr65.1%
sqrt-prod64.2%
rem-log-exp64.2%
hypot-udef64.2%
+-commutative64.2%
hypot-udef64.2%
add-sqr-sqrt57.0%
add-sqr-sqrt64.2%
sqrt-prod65.1%
add-cbrt-cube65.1%
pow1/365.1%
Applied egg-rr65.1%
Taylor expanded in x around inf 59.6%
if 4.99999999999999967e-89 < p < 1.00000000000000007e-37Initial program 72.7%
Taylor expanded in x around 0 50.4%
if 3.3e28 < p Initial program 94.4%
add-sqr-sqrt94.4%
hypot-def94.4%
associate-*l*94.4%
sqrt-prod94.4%
metadata-eval94.4%
sqrt-unprod94.4%
add-sqr-sqrt94.4%
Applied egg-rr94.4%
Taylor expanded in x around 0 92.7%
*-commutative92.7%
Simplified92.7%
Final simplification50.9%
(FPCore (p x)
:precision binary64
(let* ((t_0 (fabs (/ p x))))
(if (<= p 4.5e-254)
t_0
(if (<= p 1.3e-131)
1.0
(if (<= p 2.6e-120)
t_0
(if (<= p 7e-87)
1.0
(if (<= p 1.2e-38)
(sqrt 0.5)
(if (<= p 3.4e-10) t_0 (sqrt 0.5)))))))))
double code(double p, double x) {
double t_0 = fabs((p / x));
double tmp;
if (p <= 4.5e-254) {
tmp = t_0;
} else if (p <= 1.3e-131) {
tmp = 1.0;
} else if (p <= 2.6e-120) {
tmp = t_0;
} else if (p <= 7e-87) {
tmp = 1.0;
} else if (p <= 1.2e-38) {
tmp = sqrt(0.5);
} else if (p <= 3.4e-10) {
tmp = t_0;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = abs((p / x))
if (p <= 4.5d-254) then
tmp = t_0
else if (p <= 1.3d-131) then
tmp = 1.0d0
else if (p <= 2.6d-120) then
tmp = t_0
else if (p <= 7d-87) then
tmp = 1.0d0
else if (p <= 1.2d-38) then
tmp = sqrt(0.5d0)
else if (p <= 3.4d-10) then
tmp = t_0
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
public static double code(double p, double x) {
double t_0 = Math.abs((p / x));
double tmp;
if (p <= 4.5e-254) {
tmp = t_0;
} else if (p <= 1.3e-131) {
tmp = 1.0;
} else if (p <= 2.6e-120) {
tmp = t_0;
} else if (p <= 7e-87) {
tmp = 1.0;
} else if (p <= 1.2e-38) {
tmp = Math.sqrt(0.5);
} else if (p <= 3.4e-10) {
tmp = t_0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
def code(p, x): t_0 = math.fabs((p / x)) tmp = 0 if p <= 4.5e-254: tmp = t_0 elif p <= 1.3e-131: tmp = 1.0 elif p <= 2.6e-120: tmp = t_0 elif p <= 7e-87: tmp = 1.0 elif p <= 1.2e-38: tmp = math.sqrt(0.5) elif p <= 3.4e-10: tmp = t_0 else: tmp = math.sqrt(0.5) return tmp
function code(p, x) t_0 = abs(Float64(p / x)) tmp = 0.0 if (p <= 4.5e-254) tmp = t_0; elseif (p <= 1.3e-131) tmp = 1.0; elseif (p <= 2.6e-120) tmp = t_0; elseif (p <= 7e-87) tmp = 1.0; elseif (p <= 1.2e-38) tmp = sqrt(0.5); elseif (p <= 3.4e-10) tmp = t_0; else tmp = sqrt(0.5); end return tmp end
function tmp_2 = code(p, x) t_0 = abs((p / x)); tmp = 0.0; if (p <= 4.5e-254) tmp = t_0; elseif (p <= 1.3e-131) tmp = 1.0; elseif (p <= 2.6e-120) tmp = t_0; elseif (p <= 7e-87) tmp = 1.0; elseif (p <= 1.2e-38) tmp = sqrt(0.5); elseif (p <= 3.4e-10) tmp = t_0; else tmp = sqrt(0.5); end tmp_2 = tmp; end
code[p_, x_] := Block[{t$95$0 = N[Abs[N[(p / x), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[p, 4.5e-254], t$95$0, If[LessEqual[p, 1.3e-131], 1.0, If[LessEqual[p, 2.6e-120], t$95$0, If[LessEqual[p, 7e-87], 1.0, If[LessEqual[p, 1.2e-38], N[Sqrt[0.5], $MachinePrecision], If[LessEqual[p, 3.4e-10], t$95$0, N[Sqrt[0.5], $MachinePrecision]]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left|\frac{p}{x}\right|\\
\mathbf{if}\;p \leq 4.5 \cdot 10^{-254}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 1.3 \cdot 10^{-131}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 2.6 \cdot 10^{-120}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;p \leq 7 \cdot 10^{-87}:\\
\;\;\;\;1\\
\mathbf{elif}\;p \leq 1.2 \cdot 10^{-38}:\\
\;\;\;\;\sqrt{0.5}\\
\mathbf{elif}\;p \leq 3.4 \cdot 10^{-10}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 4.5e-254 or 1.29999999999999998e-131 < p < 2.6000000000000001e-120 or 1.20000000000000011e-38 < p < 3.40000000000000015e-10Initial program 75.9%
*-commutative75.9%
sqrt-prod75.5%
+-commutative75.5%
add-sqr-sqrt75.5%
hypot-def75.5%
associate-*l*75.5%
sqrt-prod75.5%
metadata-eval75.5%
sqrt-unprod7.4%
add-sqr-sqrt75.5%
Applied egg-rr75.5%
Taylor expanded in x around -inf 16.4%
mul-1-neg16.4%
associate-/l*16.4%
distribute-neg-frac16.4%
Simplified16.4%
*-commutative16.4%
associate-/r/16.4%
add-sqr-sqrt6.2%
sqrt-unprod8.7%
sqr-neg8.7%
unpow28.7%
add-sqr-sqrt2.3%
sqrt-prod23.0%
unpow223.0%
sqrt-div19.2%
sqrt-prod19.3%
*-commutative19.3%
pow1/219.3%
pow1/219.3%
pow-prod-down19.3%
Applied egg-rr23.0%
unpow1/223.0%
associate-*r*23.0%
metadata-eval23.0%
*-lft-identity23.0%
unpow223.0%
rem-sqrt-square34.3%
Simplified34.3%
if 4.5e-254 < p < 1.29999999999999998e-131 or 2.6000000000000001e-120 < p < 7.00000000000000023e-87Initial program 65.1%
add-log-exp65.1%
+-commutative65.1%
add-sqr-sqrt65.1%
hypot-def65.1%
associate-*l*65.1%
sqrt-prod65.1%
metadata-eval65.1%
sqrt-unprod65.1%
add-sqr-sqrt65.1%
Applied egg-rr65.1%
sqrt-prod64.2%
rem-log-exp64.2%
hypot-udef64.2%
+-commutative64.2%
hypot-udef64.2%
add-sqr-sqrt57.0%
add-sqr-sqrt64.2%
sqrt-prod65.1%
add-cbrt-cube65.1%
pow1/365.1%
Applied egg-rr65.1%
Taylor expanded in x around inf 59.6%
if 7.00000000000000023e-87 < p < 1.20000000000000011e-38 or 3.40000000000000015e-10 < p Initial program 84.0%
Taylor expanded in x around 0 77.4%
Final simplification49.6%
(FPCore (p x) :precision binary64 (if (<= p 1.25e-85) 1.0 (sqrt 0.5)))
double code(double p, double x) {
double tmp;
if (p <= 1.25e-85) {
tmp = 1.0;
} else {
tmp = sqrt(0.5);
}
return tmp;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
real(8) :: tmp
if (p <= 1.25d-85) then
tmp = 1.0d0
else
tmp = sqrt(0.5d0)
end if
code = tmp
end function
public static double code(double p, double x) {
double tmp;
if (p <= 1.25e-85) {
tmp = 1.0;
} else {
tmp = Math.sqrt(0.5);
}
return tmp;
}
def code(p, x): tmp = 0 if p <= 1.25e-85: tmp = 1.0 else: tmp = math.sqrt(0.5) return tmp
function code(p, x) tmp = 0.0 if (p <= 1.25e-85) tmp = 1.0; else tmp = sqrt(0.5); end return tmp end
function tmp_2 = code(p, x) tmp = 0.0; if (p <= 1.25e-85) tmp = 1.0; else tmp = sqrt(0.5); end tmp_2 = tmp; end
code[p_, x_] := If[LessEqual[p, 1.25e-85], 1.0, N[Sqrt[0.5], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;p \leq 1.25 \cdot 10^{-85}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;\sqrt{0.5}\\
\end{array}
\end{array}
if p < 1.25e-85Initial program 75.9%
add-log-exp75.9%
+-commutative75.9%
add-sqr-sqrt75.9%
hypot-def75.9%
associate-*l*75.9%
sqrt-prod75.9%
metadata-eval75.9%
sqrt-unprod12.4%
add-sqr-sqrt75.9%
Applied egg-rr75.9%
sqrt-prod75.5%
rem-log-exp75.5%
hypot-udef75.5%
+-commutative75.5%
hypot-udef75.5%
add-sqr-sqrt51.6%
add-sqr-sqrt75.5%
sqrt-prod75.9%
add-cbrt-cube75.9%
pow1/375.9%
Applied egg-rr75.9%
Taylor expanded in x around inf 37.9%
if 1.25e-85 < p Initial program 80.9%
Taylor expanded in x around 0 72.9%
Final simplification49.8%
(FPCore (p x) :precision binary64 1.0)
double code(double p, double x) {
return 1.0;
}
real(8) function code(p, x)
real(8), intent (in) :: p
real(8), intent (in) :: x
code = 1.0d0
end function
public static double code(double p, double x) {
return 1.0;
}
def code(p, x): return 1.0
function code(p, x) return 1.0 end
function tmp = code(p, x) tmp = 1.0; end
code[p_, x_] := 1.0
\begin{array}{l}
\\
1
\end{array}
Initial program 77.6%
add-log-exp77.6%
+-commutative77.6%
add-sqr-sqrt77.6%
hypot-def77.6%
associate-*l*77.6%
sqrt-prod77.6%
metadata-eval77.6%
sqrt-unprod35.7%
add-sqr-sqrt77.6%
Applied egg-rr77.6%
sqrt-prod77.3%
rem-log-exp77.3%
hypot-udef77.3%
+-commutative77.3%
hypot-udef77.3%
add-sqr-sqrt46.6%
add-sqr-sqrt77.3%
sqrt-prod77.6%
add-cbrt-cube77.6%
pow1/377.6%
Applied egg-rr77.6%
Taylor expanded in x around inf 32.5%
Final simplification32.5%
(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 2023310
(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))))))))