| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 26756 |
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 0.5 (hypot 1.0 x))))
(if (<= x -0.0024)
(* (- 0.5 t_0) (/ 1.0 (+ 1.0 (sqrt (+ 0.5 t_0)))))
(if (<= x 1.15)
(+ (* 0.125 (* x x)) (* -0.0859375 (pow x 4.0)))
(/ (- 0.5 (/ 0.5 x)) (+ 1.0 (sqrt (+ 0.5 (/ 0.5 x)))))))))double code(double x) {
return 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x)))));
}
double code(double x) {
double t_0 = 0.5 / hypot(1.0, x);
double tmp;
if (x <= -0.0024) {
tmp = (0.5 - t_0) * (1.0 / (1.0 + sqrt((0.5 + t_0))));
} else if (x <= 1.15) {
tmp = (0.125 * (x * x)) + (-0.0859375 * pow(x, 4.0));
} else {
tmp = (0.5 - (0.5 / x)) / (1.0 + sqrt((0.5 + (0.5 / x))));
}
return tmp;
}
public static double code(double x) {
return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
public static double code(double x) {
double t_0 = 0.5 / Math.hypot(1.0, x);
double tmp;
if (x <= -0.0024) {
tmp = (0.5 - t_0) * (1.0 / (1.0 + Math.sqrt((0.5 + t_0))));
} else if (x <= 1.15) {
tmp = (0.125 * (x * x)) + (-0.0859375 * Math.pow(x, 4.0));
} else {
tmp = (0.5 - (0.5 / x)) / (1.0 + Math.sqrt((0.5 + (0.5 / x))));
}
return tmp;
}
def code(x): return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
def code(x): t_0 = 0.5 / math.hypot(1.0, x) tmp = 0 if x <= -0.0024: tmp = (0.5 - t_0) * (1.0 / (1.0 + math.sqrt((0.5 + t_0)))) elif x <= 1.15: tmp = (0.125 * (x * x)) + (-0.0859375 * math.pow(x, 4.0)) else: tmp = (0.5 - (0.5 / x)) / (1.0 + math.sqrt((0.5 + (0.5 / x)))) return tmp
function code(x) return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x)))))) end
function code(x) t_0 = Float64(0.5 / hypot(1.0, x)) tmp = 0.0 if (x <= -0.0024) tmp = Float64(Float64(0.5 - t_0) * Float64(1.0 / Float64(1.0 + sqrt(Float64(0.5 + t_0))))); elseif (x <= 1.15) tmp = Float64(Float64(0.125 * Float64(x * x)) + Float64(-0.0859375 * (x ^ 4.0))); 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 = code(x) tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x))))); end
function tmp_2 = code(x) t_0 = 0.5 / hypot(1.0, x); tmp = 0.0; if (x <= -0.0024) tmp = (0.5 - t_0) * (1.0 / (1.0 + sqrt((0.5 + t_0)))); elseif (x <= 1.15) tmp = (0.125 * (x * x)) + (-0.0859375 * (x ^ 4.0)); else tmp = (0.5 - (0.5 / x)) / (1.0 + sqrt((0.5 + (0.5 / x)))); end tmp_2 = tmp; 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]
code[x_] := Block[{t$95$0 = N[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -0.0024], N[(N[(0.5 - t$95$0), $MachinePrecision] * N[(1.0 / N[(1.0 + N[Sqrt[N[(0.5 + t$95$0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1.15], N[(N[(0.125 * N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $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]]]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
t_0 := \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
\mathbf{if}\;x \leq -0.0024:\\
\;\;\;\;\left(0.5 - t_0\right) \cdot \frac{1}{1 + \sqrt{0.5 + t_0}}\\
\mathbf{elif}\;x \leq 1.15:\\
\;\;\;\;0.125 \cdot \left(x \cdot x\right) + -0.0859375 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 - \frac{0.5}{x}}{1 + \sqrt{0.5 + \frac{0.5}{x}}}\\
\end{array}
Results
if x < -0.00239999999999999979Initial program 98.4%
Simplified98.4%
[Start]98.4 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]98.4 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]98.4 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]98.4 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]98.4 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Applied egg-rr99.9%
[Start]98.4 | \[ 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}
\] |
|---|---|
flip-- [=>]98.4 | \[ \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}
\] |
div-inv [=>]98.4 | \[ \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}
\] |
metadata-eval [=>]98.4 | \[ \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
add-sqr-sqrt [<=]99.9 | \[ \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
associate--r+ [=>]99.9 | \[ \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]99.9 | \[ \left(\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
if -0.00239999999999999979 < x < 1.1499999999999999Initial program 51.5%
Simplified51.5%
[Start]51.5 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]51.5 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]51.5 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]51.5 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]51.5 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Taylor expanded in x around 0 99.7%
Simplified99.7%
[Start]99.7 | \[ 0.125 \cdot {x}^{2} + -0.0859375 \cdot {x}^{4}
\] |
|---|---|
fma-def [=>]99.7 | \[ \color{blue}{\mathsf{fma}\left(0.125, {x}^{2}, -0.0859375 \cdot {x}^{4}\right)}
\] |
unpow2 [=>]99.7 | \[ \mathsf{fma}\left(0.125, \color{blue}{x \cdot x}, -0.0859375 \cdot {x}^{4}\right)
\] |
Applied egg-rr99.7%
[Start]99.7 | \[ \mathsf{fma}\left(0.125, x \cdot x, -0.0859375 \cdot {x}^{4}\right)
\] |
|---|---|
fma-udef [=>]99.7 | \[ \color{blue}{0.125 \cdot \left(x \cdot x\right) + -0.0859375 \cdot {x}^{4}}
\] |
if 1.1499999999999999 < x Initial program 98.5%
Simplified98.5%
[Start]98.5 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]98.5 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]98.5 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]98.5 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]98.5 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Taylor expanded in x around inf 97.9%
Applied egg-rr99.4%
[Start]97.9 | \[ 1 - \sqrt{0.5 + \frac{0.5}{x}}
\] |
|---|---|
flip-- [=>]97.9 | \[ \color{blue}{\frac{1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{x}} \cdot \sqrt{0.5 + \frac{0.5}{x}}}{1 + \sqrt{0.5 + \frac{0.5}{x}}}}
\] |
div-inv [=>]97.9 | \[ \color{blue}{\left(1 \cdot 1 - \sqrt{0.5 + \frac{0.5}{x}} \cdot \sqrt{0.5 + \frac{0.5}{x}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{x}}}}
\] |
metadata-eval [=>]97.9 | \[ \left(\color{blue}{1} - \sqrt{0.5 + \frac{0.5}{x}} \cdot \sqrt{0.5 + \frac{0.5}{x}}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{x}}}
\] |
add-sqr-sqrt [<=]99.4 | \[ \left(1 - \color{blue}{\left(0.5 + \frac{0.5}{x}\right)}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{x}}}
\] |
associate--r+ [=>]99.4 | \[ \color{blue}{\left(\left(1 - 0.5\right) - \frac{0.5}{x}\right)} \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{x}}}
\] |
metadata-eval [=>]99.4 | \[ \left(\color{blue}{0.5} - \frac{0.5}{x}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{x}}}
\] |
Simplified99.4%
[Start]99.4 | \[ \left(0.5 - \frac{0.5}{x}\right) \cdot \frac{1}{1 + \sqrt{0.5 + \frac{0.5}{x}}}
\] |
|---|---|
associate-*r/ [=>]99.4 | \[ \color{blue}{\frac{\left(0.5 - \frac{0.5}{x}\right) \cdot 1}{1 + \sqrt{0.5 + \frac{0.5}{x}}}}
\] |
*-rgt-identity [=>]99.4 | \[ \frac{\color{blue}{0.5 - \frac{0.5}{x}}}{1 + \sqrt{0.5 + \frac{0.5}{x}}}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 26756 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 13444 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.6% |
| Cost | 13316 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 7496 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 7305 |
| Alternative 6 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 6857 |
| Alternative 7 | |
|---|---|
| Accuracy | 60.5% |
| Cost | 713 |
| Alternative 8 | |
|---|---|
| Accuracy | 60.5% |
| Cost | 584 |
| Alternative 9 | |
|---|---|
| Accuracy | 60.5% |
| Cost | 584 |
| Alternative 10 | |
|---|---|
| Accuracy | 13.6% |
| Cost | 64 |
herbie shell --seed 2023147
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))