
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
def code(x): return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
function code(x) return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x)))))) end
function tmp = code(x) tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x))))); end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
def code(x): return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
function code(x) return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x)))))) end
function tmp = code(x) tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x))))); end
code[x_] := N[(1.0 - N[Sqrt[N[(0.5 * N[(1.0 + N[(1.0 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\end{array}
(FPCore (x)
:precision binary64
(if (<= (hypot 1.0 x) 1.0)
(* x (* x 0.125))
(/
(log (exp (+ 0.5 (/ -0.5 (hypot 1.0 x)))))
(+
1.0
(/
(sqrt (- 0.25 (/ 0.25 (fma x x 1.0))))
(sqrt (- 0.5 (/ 0.5 (hypot 1.0 x)))))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.0) {
tmp = x * (x * 0.125);
} else {
tmp = log(exp((0.5 + (-0.5 / hypot(1.0, x))))) / (1.0 + (sqrt((0.25 - (0.25 / fma(x, x, 1.0)))) / sqrt((0.5 - (0.5 / hypot(1.0, x))))));
}
return tmp;
}
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 1.0) tmp = Float64(x * Float64(x * 0.125)); else tmp = Float64(log(exp(Float64(0.5 + Float64(-0.5 / hypot(1.0, x))))) / Float64(1.0 + Float64(sqrt(Float64(0.25 - Float64(0.25 / fma(x, x, 1.0)))) / sqrt(Float64(0.5 - Float64(0.5 / hypot(1.0, x))))))); end return tmp end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[Exp[N[(0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[(1.0 + N[(N[Sqrt[N[(0.25 - N[(0.25 / N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[(0.5 - N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\log \left(e^{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 + \frac{\sqrt{0.25 - \frac{0.25}{\mathsf{fma}\left(x, x, 1\right)}}}{\sqrt{0.5 - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1Initial program 50.1%
distribute-lft-in50.1%
metadata-eval50.1%
associate-*r/50.1%
metadata-eval50.1%
Simplified50.1%
Taylor expanded in x around 0 50.1%
*-commutative50.1%
fma-def50.1%
unpow250.1%
Simplified50.1%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
if 1 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
flip--98.4%
metadata-eval98.4%
add-sqr-sqrt99.9%
associate--r+99.9%
metadata-eval99.9%
Applied egg-rr99.9%
metadata-eval99.9%
associate--r+99.9%
metadata-eval99.9%
add-sqr-sqrt98.4%
add-log-exp98.4%
metadata-eval98.4%
add-sqr-sqrt99.9%
associate--r+99.9%
metadata-eval99.9%
sub-neg99.9%
distribute-neg-frac99.9%
metadata-eval99.9%
Applied egg-rr99.9%
flip-+99.9%
sqrt-div99.9%
metadata-eval99.9%
frac-times99.9%
metadata-eval99.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
+-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
Final simplification100.0%
(FPCore (x)
:precision binary64
(if (<= (hypot 1.0 x) 1.0)
(* x (* x 0.125))
(/
(- 0.5 (sqrt (/ 0.25 (fma x x 1.0))))
(+ 1.0 (cbrt (pow (+ 0.5 (/ 0.5 (hypot 1.0 x))) 1.5))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.0) {
tmp = x * (x * 0.125);
} else {
tmp = (0.5 - sqrt((0.25 / fma(x, x, 1.0)))) / (1.0 + cbrt(pow((0.5 + (0.5 / hypot(1.0, x))), 1.5)));
}
return tmp;
}
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 1.0) tmp = Float64(x * Float64(x * 0.125)); else tmp = Float64(Float64(0.5 - sqrt(Float64(0.25 / fma(x, x, 1.0)))) / Float64(1.0 + cbrt((Float64(0.5 + Float64(0.5 / hypot(1.0, x))) ^ 1.5)))); end return tmp end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 - N[Sqrt[N[(0.25 / N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Power[N[Power[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1.5], $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 - \sqrt{\frac{0.25}{\mathsf{fma}\left(x, x, 1\right)}}}{1 + \sqrt[3]{{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{1.5}}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1Initial program 50.1%
distribute-lft-in50.1%
metadata-eval50.1%
associate-*r/50.1%
metadata-eval50.1%
Simplified50.1%
Taylor expanded in x around 0 50.1%
*-commutative50.1%
fma-def50.1%
unpow250.1%
Simplified50.1%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
if 1 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
flip--98.4%
metadata-eval98.4%
add-sqr-sqrt99.9%
associate--r+99.9%
metadata-eval99.9%
Applied egg-rr99.9%
add-sqr-sqrt99.8%
sqrt-unprod99.9%
pow1/299.9%
frac-times99.9%
metadata-eval99.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
+-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
unpow1/299.9%
Simplified99.9%
add-cbrt-cube99.9%
pow399.9%
sqrt-pow299.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification100.0%
(FPCore (x)
:precision binary64
(if (<= (hypot 1.0 x) 1.0)
(* x (* x 0.125))
(/
(log (exp (+ 0.5 (/ -0.5 (hypot 1.0 x)))))
(+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.0) {
tmp = x * (x * 0.125);
} else {
tmp = log(exp((0.5 + (-0.5 / hypot(1.0, x))))) / (1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x)))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.hypot(1.0, x) <= 1.0) {
tmp = x * (x * 0.125);
} else {
tmp = Math.log(Math.exp((0.5 + (-0.5 / Math.hypot(1.0, x))))) / (1.0 + Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, x)))));
}
return tmp;
}
def code(x): tmp = 0 if math.hypot(1.0, x) <= 1.0: tmp = x * (x * 0.125) else: tmp = math.log(math.exp((0.5 + (-0.5 / math.hypot(1.0, x))))) / (1.0 + math.sqrt((0.5 + (0.5 / math.hypot(1.0, x))))) return tmp
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 1.0) tmp = Float64(x * Float64(x * 0.125)); else tmp = Float64(log(exp(Float64(0.5 + Float64(-0.5 / hypot(1.0, x))))) / Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x)))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (hypot(1.0, x) <= 1.0) tmp = x * (x * 0.125); else tmp = log(exp((0.5 + (-0.5 / hypot(1.0, x))))) / (1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x))))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision], N[(N[Log[N[Exp[N[(0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\log \left(e^{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1Initial program 50.1%
distribute-lft-in50.1%
metadata-eval50.1%
associate-*r/50.1%
metadata-eval50.1%
Simplified50.1%
Taylor expanded in x around 0 50.1%
*-commutative50.1%
fma-def50.1%
unpow250.1%
Simplified50.1%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
if 1 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
flip--98.4%
metadata-eval98.4%
add-sqr-sqrt99.9%
associate--r+99.9%
metadata-eval99.9%
Applied egg-rr99.9%
metadata-eval99.9%
associate--r+99.9%
metadata-eval99.9%
add-sqr-sqrt98.4%
add-log-exp98.4%
metadata-eval98.4%
add-sqr-sqrt99.9%
associate--r+99.9%
metadata-eval99.9%
sub-neg99.9%
distribute-neg-frac99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(if (<= (hypot 1.0 x) 1.0)
(* x (* x 0.125))
(/
(- 0.5 (sqrt (/ 0.25 (fma x x 1.0))))
(+ 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x))))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.0) {
tmp = x * (x * 0.125);
} else {
tmp = (0.5 - sqrt((0.25 / fma(x, x, 1.0)))) / (1.0 + sqrt((0.5 + (0.5 / hypot(1.0, x)))));
}
return tmp;
}
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 1.0) tmp = Float64(x * Float64(x * 0.125)); else tmp = Float64(Float64(0.5 - sqrt(Float64(0.25 / fma(x, x, 1.0)))) / Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x)))))); end return tmp end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 - N[Sqrt[N[(0.25 / N[(x * x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 - \sqrt{\frac{0.25}{\mathsf{fma}\left(x, x, 1\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1Initial program 50.1%
distribute-lft-in50.1%
metadata-eval50.1%
associate-*r/50.1%
metadata-eval50.1%
Simplified50.1%
Taylor expanded in x around 0 50.1%
*-commutative50.1%
fma-def50.1%
unpow250.1%
Simplified50.1%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
if 1 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
flip--98.4%
metadata-eval98.4%
add-sqr-sqrt99.9%
associate--r+99.9%
metadata-eval99.9%
Applied egg-rr99.9%
add-sqr-sqrt99.8%
sqrt-unprod99.9%
pow1/299.9%
frac-times99.9%
metadata-eval99.9%
hypot-udef99.9%
hypot-udef99.9%
add-sqr-sqrt99.9%
metadata-eval99.9%
+-commutative99.9%
fma-def99.9%
Applied egg-rr99.9%
unpow1/299.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 0.5 (hypot 1.0 x))))
(if (<= (hypot 1.0 x) 1.0)
(* x (* x 0.125))
(/ (- 0.5 t_0) (+ 1.0 (sqrt (+ 0.5 t_0)))))))
double code(double x) {
double t_0 = 0.5 / hypot(1.0, x);
double tmp;
if (hypot(1.0, x) <= 1.0) {
tmp = x * (x * 0.125);
} else {
tmp = (0.5 - t_0) / (1.0 + sqrt((0.5 + t_0)));
}
return tmp;
}
public static double code(double x) {
double t_0 = 0.5 / Math.hypot(1.0, x);
double tmp;
if (Math.hypot(1.0, x) <= 1.0) {
tmp = x * (x * 0.125);
} else {
tmp = (0.5 - t_0) / (1.0 + Math.sqrt((0.5 + t_0)));
}
return tmp;
}
def code(x): t_0 = 0.5 / math.hypot(1.0, x) tmp = 0 if math.hypot(1.0, x) <= 1.0: tmp = x * (x * 0.125) else: tmp = (0.5 - t_0) / (1.0 + math.sqrt((0.5 + t_0))) return tmp
function code(x) t_0 = Float64(0.5 / hypot(1.0, x)) tmp = 0.0 if (hypot(1.0, x) <= 1.0) tmp = Float64(x * Float64(x * 0.125)); else tmp = Float64(Float64(0.5 - t_0) / Float64(1.0 + sqrt(Float64(0.5 + t_0)))); end return tmp end
function tmp_2 = code(x) t_0 = 0.5 / hypot(1.0, x); tmp = 0.0; if (hypot(1.0, x) <= 1.0) tmp = x * (x * 0.125); else tmp = (0.5 - t_0) / (1.0 + sqrt((0.5 + t_0))); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 - t$95$0), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 - t_0}{1 + \sqrt{0.5 + t_0}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1Initial program 50.1%
distribute-lft-in50.1%
metadata-eval50.1%
associate-*r/50.1%
metadata-eval50.1%
Simplified50.1%
Taylor expanded in x around 0 50.1%
*-commutative50.1%
fma-def50.1%
unpow250.1%
Simplified50.1%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
if 1 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
flip--98.4%
metadata-eval98.4%
add-sqr-sqrt99.9%
associate--r+99.9%
metadata-eval99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x) :precision binary64 (if (<= (hypot 1.0 x) 1.0) (* x (* x 0.125)) (- 1.0 (sqrt (+ 0.5 (/ 0.5 (hypot 1.0 x)))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 1.0) {
tmp = x * (x * 0.125);
} else {
tmp = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.hypot(1.0, x) <= 1.0) {
tmp = x * (x * 0.125);
} else {
tmp = 1.0 - Math.sqrt((0.5 + (0.5 / Math.hypot(1.0, x))));
}
return tmp;
}
def code(x): tmp = 0 if math.hypot(1.0, x) <= 1.0: tmp = x * (x * 0.125) else: tmp = 1.0 - math.sqrt((0.5 + (0.5 / math.hypot(1.0, x)))) return tmp
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 1.0) tmp = Float64(x * Float64(x * 0.125)); else tmp = Float64(1.0 - sqrt(Float64(0.5 + Float64(0.5 / hypot(1.0, x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (hypot(1.0, x) <= 1.0) tmp = x * (x * 0.125); else tmp = 1.0 - sqrt((0.5 + (0.5 / hypot(1.0, x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 1.0], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision], N[(1.0 - N[Sqrt[N[(0.5 + N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 1:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 1Initial program 50.1%
distribute-lft-in50.1%
metadata-eval50.1%
associate-*r/50.1%
metadata-eval50.1%
Simplified50.1%
Taylor expanded in x around 0 50.1%
*-commutative50.1%
fma-def50.1%
unpow250.1%
Simplified50.1%
Taylor expanded in x around 0 100.0%
*-commutative100.0%
unpow2100.0%
associate-*l*100.0%
Simplified100.0%
if 1 < (hypot.f64 1 x) Initial program 98.4%
distribute-lft-in98.4%
metadata-eval98.4%
associate-*r/98.4%
metadata-eval98.4%
Simplified98.4%
Final simplification99.2%
(FPCore (x) :precision binary64 (if (<= (hypot 1.0 x) 2.0) (* x (* x 0.125)) (/ (- 0.5 (/ 0.5 x)) (+ 1.0 (sqrt (+ 0.5 (/ 0.5 x)))))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 2.0) {
tmp = x * (x * 0.125);
} else {
tmp = (0.5 - (0.5 / x)) / (1.0 + sqrt((0.5 + (0.5 / x))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.hypot(1.0, x) <= 2.0) {
tmp = x * (x * 0.125);
} else {
tmp = (0.5 - (0.5 / x)) / (1.0 + Math.sqrt((0.5 + (0.5 / x))));
}
return tmp;
}
def code(x): tmp = 0 if math.hypot(1.0, x) <= 2.0: tmp = x * (x * 0.125) else: tmp = (0.5 - (0.5 / x)) / (1.0 + math.sqrt((0.5 + (0.5 / x)))) return tmp
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 2.0) tmp = Float64(x * Float64(x * 0.125)); else tmp = Float64(Float64(0.5 - Float64(0.5 / x)) / Float64(1.0 + sqrt(Float64(0.5 + Float64(0.5 / x))))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (hypot(1.0, x) <= 2.0) tmp = x * (x * 0.125); else tmp = (0.5 - (0.5 / x)) / (1.0 + sqrt((0.5 + (0.5 / x)))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 2.0], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 - N[(0.5 / x), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(0.5 / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 2:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 - \frac{0.5}{x}}{1 + \sqrt{0.5 + \frac{0.5}{x}}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 2Initial program 50.7%
distribute-lft-in50.7%
metadata-eval50.7%
associate-*r/50.7%
metadata-eval50.7%
Simplified50.7%
Taylor expanded in x around 0 49.7%
*-commutative49.7%
fma-def49.7%
unpow249.7%
Simplified49.7%
Taylor expanded in x around 0 98.8%
*-commutative98.8%
unpow298.8%
associate-*l*98.8%
Simplified98.8%
if 2 < (hypot.f64 1 x) Initial program 98.5%
distribute-lft-in98.5%
metadata-eval98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in x around inf 97.2%
flip--97.2%
metadata-eval97.2%
add-sqr-sqrt98.7%
associate--r+98.7%
metadata-eval98.7%
Applied egg-rr98.7%
Final simplification98.8%
(FPCore (x) :precision binary64 (if (<= (hypot 1.0 x) 2.0) (* x (* x 0.125)) (/ 0.5 (+ 1.0 (sqrt 0.5)))))
double code(double x) {
double tmp;
if (hypot(1.0, x) <= 2.0) {
tmp = x * (x * 0.125);
} else {
tmp = 0.5 / (1.0 + sqrt(0.5));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.hypot(1.0, x) <= 2.0) {
tmp = x * (x * 0.125);
} else {
tmp = 0.5 / (1.0 + Math.sqrt(0.5));
}
return tmp;
}
def code(x): tmp = 0 if math.hypot(1.0, x) <= 2.0: tmp = x * (x * 0.125) else: tmp = 0.5 / (1.0 + math.sqrt(0.5)) return tmp
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 2.0) tmp = Float64(x * Float64(x * 0.125)); else tmp = Float64(0.5 / Float64(1.0 + sqrt(0.5))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (hypot(1.0, x) <= 2.0) tmp = x * (x * 0.125); else tmp = 0.5 / (1.0 + sqrt(0.5)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 2.0], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision], N[(0.5 / N[(1.0 + N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 2:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5}{1 + \sqrt{0.5}}\\
\end{array}
\end{array}
if (hypot.f64 1 x) < 2Initial program 50.7%
distribute-lft-in50.7%
metadata-eval50.7%
associate-*r/50.7%
metadata-eval50.7%
Simplified50.7%
Taylor expanded in x around 0 49.7%
*-commutative49.7%
fma-def49.7%
unpow249.7%
Simplified49.7%
Taylor expanded in x around 0 98.8%
*-commutative98.8%
unpow298.8%
associate-*l*98.8%
Simplified98.8%
if 2 < (hypot.f64 1 x) Initial program 98.5%
distribute-lft-in98.5%
metadata-eval98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in x around inf 96.0%
flip--96.0%
metadata-eval96.0%
add-sqr-sqrt97.5%
metadata-eval97.5%
div-inv97.5%
Applied egg-rr97.5%
associate-*r/97.5%
metadata-eval97.5%
Simplified97.5%
Final simplification98.2%
(FPCore (x) :precision binary64 (if (or (<= x -1.52) (not (<= x 1.52))) (- 1.0 (sqrt 0.5)) (* x (* x 0.125))))
double code(double x) {
double tmp;
if ((x <= -1.52) || !(x <= 1.52)) {
tmp = 1.0 - sqrt(0.5);
} else {
tmp = x * (x * 0.125);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if ((x <= (-1.52d0)) .or. (.not. (x <= 1.52d0))) then
tmp = 1.0d0 - sqrt(0.5d0)
else
tmp = x * (x * 0.125d0)
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x <= -1.52) || !(x <= 1.52)) {
tmp = 1.0 - Math.sqrt(0.5);
} else {
tmp = x * (x * 0.125);
}
return tmp;
}
def code(x): tmp = 0 if (x <= -1.52) or not (x <= 1.52): tmp = 1.0 - math.sqrt(0.5) else: tmp = x * (x * 0.125) return tmp
function code(x) tmp = 0.0 if ((x <= -1.52) || !(x <= 1.52)) tmp = Float64(1.0 - sqrt(0.5)); else tmp = Float64(x * Float64(x * 0.125)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x <= -1.52) || ~((x <= 1.52))) tmp = 1.0 - sqrt(0.5); else tmp = x * (x * 0.125); end tmp_2 = tmp; end
code[x_] := If[Or[LessEqual[x, -1.52], N[Not[LessEqual[x, 1.52]], $MachinePrecision]], N[(1.0 - N[Sqrt[0.5], $MachinePrecision]), $MachinePrecision], N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.52 \lor \neg \left(x \leq 1.52\right):\\
\;\;\;\;1 - \sqrt{0.5}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(x \cdot 0.125\right)\\
\end{array}
\end{array}
if x < -1.52 or 1.52 < x Initial program 98.5%
distribute-lft-in98.5%
metadata-eval98.5%
associate-*r/98.5%
metadata-eval98.5%
Simplified98.5%
Taylor expanded in x around inf 96.0%
if -1.52 < x < 1.52Initial program 50.7%
distribute-lft-in50.7%
metadata-eval50.7%
associate-*r/50.7%
metadata-eval50.7%
Simplified50.7%
Taylor expanded in x around 0 49.7%
*-commutative49.7%
fma-def49.7%
unpow249.7%
Simplified49.7%
Taylor expanded in x around 0 98.8%
*-commutative98.8%
unpow298.8%
associate-*l*98.8%
Simplified98.8%
Final simplification97.4%
(FPCore (x) :precision binary64 (* 0.125 (* x x)))
double code(double x) {
return 0.125 * (x * x);
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.125d0 * (x * x)
end function
public static double code(double x) {
return 0.125 * (x * x);
}
def code(x): return 0.125 * (x * x)
function code(x) return Float64(0.125 * Float64(x * x)) end
function tmp = code(x) tmp = 0.125 * (x * x); end
code[x_] := N[(0.125 * N[(x * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.125 \cdot \left(x \cdot x\right)
\end{array}
Initial program 74.8%
distribute-lft-in74.8%
metadata-eval74.8%
associate-*r/74.8%
metadata-eval74.8%
Simplified74.8%
Taylor expanded in x around 0 51.2%
unpow251.2%
Simplified51.2%
Final simplification51.2%
(FPCore (x) :precision binary64 (* x (* x 0.125)))
double code(double x) {
return x * (x * 0.125);
}
real(8) function code(x)
real(8), intent (in) :: x
code = x * (x * 0.125d0)
end function
public static double code(double x) {
return x * (x * 0.125);
}
def code(x): return x * (x * 0.125)
function code(x) return Float64(x * Float64(x * 0.125)) end
function tmp = code(x) tmp = x * (x * 0.125); end
code[x_] := N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(x \cdot 0.125\right)
\end{array}
Initial program 74.8%
distribute-lft-in74.8%
metadata-eval74.8%
associate-*r/74.8%
metadata-eval74.8%
Simplified74.8%
Taylor expanded in x around 0 26.8%
*-commutative26.8%
fma-def26.8%
unpow226.8%
Simplified26.8%
Taylor expanded in x around 0 51.2%
*-commutative51.2%
unpow251.2%
associate-*l*51.2%
Simplified51.2%
Final simplification51.2%
(FPCore (x) :precision binary64 0.0)
double code(double x) {
return 0.0;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 0.0d0
end function
public static double code(double x) {
return 0.0;
}
def code(x): return 0.0
function code(x) return 0.0 end
function tmp = code(x) tmp = 0.0; end
code[x_] := 0.0
\begin{array}{l}
\\
0
\end{array}
Initial program 74.8%
distribute-lft-in74.8%
metadata-eval74.8%
associate-*r/74.8%
metadata-eval74.8%
Simplified74.8%
Taylor expanded in x around 0 26.1%
Final simplification26.1%
herbie shell --seed 2023187
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))