| Alternative 1 | |
|---|---|
| Error | 0.1 |
| 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 (/ 0.5 (hypot 1.0 x))))
(t_1 (+ 1.0 (sqrt t_0)))
(t_2 (+ (* x x) 1.0)))
(if (<= x -0.002)
(/
(/ (+ 0.0625 (/ -0.0625 (* t_2 t_2))) (* t_0 (+ 0.25 (/ 0.25 t_2))))
t_1)
(if (<= x 0.0027)
(+ (* (pow x 4.0) -0.0859375) (* x (* x 0.125)))
(* (/ 1.0 t_1) (+ 0.5 (/ -0.5 (hypot 1.0 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 + (0.5 / hypot(1.0, x));
double t_1 = 1.0 + sqrt(t_0);
double t_2 = (x * x) + 1.0;
double tmp;
if (x <= -0.002) {
tmp = ((0.0625 + (-0.0625 / (t_2 * t_2))) / (t_0 * (0.25 + (0.25 / t_2)))) / t_1;
} else if (x <= 0.0027) {
tmp = (pow(x, 4.0) * -0.0859375) + (x * (x * 0.125));
} else {
tmp = (1.0 / t_1) * (0.5 + (-0.5 / hypot(1.0, 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 + (0.5 / Math.hypot(1.0, x));
double t_1 = 1.0 + Math.sqrt(t_0);
double t_2 = (x * x) + 1.0;
double tmp;
if (x <= -0.002) {
tmp = ((0.0625 + (-0.0625 / (t_2 * t_2))) / (t_0 * (0.25 + (0.25 / t_2)))) / t_1;
} else if (x <= 0.0027) {
tmp = (Math.pow(x, 4.0) * -0.0859375) + (x * (x * 0.125));
} else {
tmp = (1.0 / t_1) * (0.5 + (-0.5 / Math.hypot(1.0, 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 + (0.5 / math.hypot(1.0, x)) t_1 = 1.0 + math.sqrt(t_0) t_2 = (x * x) + 1.0 tmp = 0 if x <= -0.002: tmp = ((0.0625 + (-0.0625 / (t_2 * t_2))) / (t_0 * (0.25 + (0.25 / t_2)))) / t_1 elif x <= 0.0027: tmp = (math.pow(x, 4.0) * -0.0859375) + (x * (x * 0.125)) else: tmp = (1.0 / t_1) * (0.5 + (-0.5 / math.hypot(1.0, 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 + Float64(0.5 / hypot(1.0, x))) t_1 = Float64(1.0 + sqrt(t_0)) t_2 = Float64(Float64(x * x) + 1.0) tmp = 0.0 if (x <= -0.002) tmp = Float64(Float64(Float64(0.0625 + Float64(-0.0625 / Float64(t_2 * t_2))) / Float64(t_0 * Float64(0.25 + Float64(0.25 / t_2)))) / t_1); elseif (x <= 0.0027) tmp = Float64(Float64((x ^ 4.0) * -0.0859375) + Float64(x * Float64(x * 0.125))); else tmp = Float64(Float64(1.0 / t_1) * Float64(0.5 + Float64(-0.5 / hypot(1.0, 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 + (0.5 / hypot(1.0, x)); t_1 = 1.0 + sqrt(t_0); t_2 = (x * x) + 1.0; tmp = 0.0; if (x <= -0.002) tmp = ((0.0625 + (-0.0625 / (t_2 * t_2))) / (t_0 * (0.25 + (0.25 / t_2)))) / t_1; elseif (x <= 0.0027) tmp = ((x ^ 4.0) * -0.0859375) + (x * (x * 0.125)); else tmp = (1.0 / t_1) * (0.5 + (-0.5 / hypot(1.0, 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[(0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(1.0 + N[Sqrt[t$95$0], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]}, If[LessEqual[x, -0.002], N[(N[(N[(0.0625 + N[(-0.0625 / N[(t$95$2 * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(t$95$0 * N[(0.25 + N[(0.25 / t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / t$95$1), $MachinePrecision], If[LessEqual[x, 0.0027], N[(N[(N[Power[x, 4.0], $MachinePrecision] * -0.0859375), $MachinePrecision] + N[(x * N[(x * 0.125), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 / t$95$1), $MachinePrecision] * N[(0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $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 := 0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\\
t_1 := 1 + \sqrt{t_0}\\
t_2 := x \cdot x + 1\\
\mathbf{if}\;x \leq -0.002:\\
\;\;\;\;\frac{\frac{0.0625 + \frac{-0.0625}{t_2 \cdot t_2}}{t_0 \cdot \left(0.25 + \frac{0.25}{t_2}\right)}}{t_1}\\
\mathbf{elif}\;x \leq 0.0027:\\
\;\;\;\;{x}^{4} \cdot -0.0859375 + x \cdot \left(x \cdot 0.125\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{t_1} \cdot \left(0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right)\\
\end{array}
Results
if x < -2e-3Initial program 1.0
Simplified1.0
[Start]1.0 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]1.0 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]1.0 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]1.0 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]1.0 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Applied egg-rr1.1
Simplified0.1
[Start]1.1 | \[ \frac{1 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(-\sqrt{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)}}}
\] |
|---|---|
sqr-neg [=>]1.1 | \[ \frac{1 - \color{blue}{\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)}}}
\] |
rem-square-sqrt [=>]0.1 | \[ \frac{1 - \color{blue}{\left(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)}}}
\] |
associate--r+ [=>]0.1 | \[ \frac{\color{blue}{\left(1 - 0.5\right) - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]0.1 | \[ \frac{\color{blue}{0.5} - \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
Applied egg-rr0.1
Simplified0.1
[Start]0.1 | \[ \frac{\frac{0.0625 - \frac{0.25}{1 + x \cdot x} \cdot \frac{0.25}{1 + x \cdot x}}{\left(0.5 - \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
|---|---|
associate-*l/ [=>]0.1 | \[ \frac{\frac{0.0625 - \color{blue}{\frac{0.25 \cdot \frac{0.25}{1 + x \cdot x}}{1 + x \cdot x}}}{\left(0.5 - \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
associate-*r/ [=>]0.1 | \[ \frac{\frac{0.0625 - \frac{\color{blue}{\frac{0.25 \cdot 0.25}{1 + x \cdot x}}}{1 + x \cdot x}}{\left(0.5 - \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]0.1 | \[ \frac{\frac{0.0625 - \frac{\frac{\color{blue}{0.0625}}{1 + x \cdot x}}{1 + x \cdot x}}{\left(0.5 - \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
associate-/l/ [=>]0.1 | \[ \frac{\frac{0.0625 - \color{blue}{\frac{0.0625}{\left(1 + x \cdot x\right) \cdot \left(1 + x \cdot x\right)}}}{\left(0.5 - \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
+-commutative [=>]0.1 | \[ \frac{\frac{0.0625 - \frac{0.0625}{\color{blue}{\left(x \cdot x + 1\right)} \cdot \left(1 + x \cdot x\right)}}{\left(0.5 - \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
+-commutative [=>]0.1 | \[ \frac{\frac{0.0625 - \frac{0.0625}{\left(x \cdot x + 1\right) \cdot \color{blue}{\left(x \cdot x + 1\right)}}}{\left(0.5 - \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
sub-neg [=>]0.1 | \[ \frac{\frac{0.0625 - \frac{0.0625}{\left(x \cdot x + 1\right) \cdot \left(x \cdot x + 1\right)}}{\color{blue}{\left(0.5 + \left(-\frac{-0.5}{\mathsf{hypot}\left(1, x\right)}\right)\right)} \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
distribute-neg-frac [=>]0.1 | \[ \frac{\frac{0.0625 - \frac{0.0625}{\left(x \cdot x + 1\right) \cdot \left(x \cdot x + 1\right)}}{\left(0.5 + \color{blue}{\frac{--0.5}{\mathsf{hypot}\left(1, x\right)}}\right) \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]0.1 | \[ \frac{\frac{0.0625 - \frac{0.0625}{\left(x \cdot x + 1\right) \cdot \left(x \cdot x + 1\right)}}{\left(0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(0.25 + \frac{0.25}{1 + x \cdot x}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
+-commutative [=>]0.1 | \[ \frac{\frac{0.0625 - \frac{0.0625}{\left(x \cdot x + 1\right) \cdot \left(x \cdot x + 1\right)}}{\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right) \cdot \left(0.25 + \frac{0.25}{\color{blue}{x \cdot x + 1}}\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
if -2e-3 < x < 0.0027000000000000001Initial program 30.1
Simplified30.1
[Start]30.1 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]30.1 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]30.1 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]30.1 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]30.1 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Applied egg-rr30.1
Taylor expanded in x around 0 0.0
Simplified0.0
[Start]0.0 | \[ 0.125 \cdot {x}^{2} + -0.0859375 \cdot {x}^{4}
\] |
|---|---|
fma-def [=>]0.0 | \[ \color{blue}{\mathsf{fma}\left(0.125, {x}^{2}, -0.0859375 \cdot {x}^{4}\right)}
\] |
unpow2 [=>]0.0 | \[ \mathsf{fma}\left(0.125, \color{blue}{x \cdot x}, -0.0859375 \cdot {x}^{4}\right)
\] |
*-commutative [=>]0.0 | \[ \mathsf{fma}\left(0.125, x \cdot x, \color{blue}{{x}^{4} \cdot -0.0859375}\right)
\] |
Applied egg-rr0.0
if 0.0027000000000000001 < x Initial program 1.0
Simplified1.0
[Start]1.0 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]1.0 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]1.0 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]1.0 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]1.0 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Applied egg-rr0.1
Final simplification0.1
| Alternative 1 | |
|---|---|
| Error | 0.1 |
| Cost | 26756 |
| Alternative 2 | |
|---|---|
| Error | 0.1 |
| Cost | 20552 |
| Alternative 3 | |
|---|---|
| Error | 0.3 |
| Cost | 14088 |
| Alternative 4 | |
|---|---|
| Error | 0.3 |
| Cost | 8004 |
| Alternative 5 | |
|---|---|
| Error | 0.6 |
| Cost | 7624 |
| Alternative 6 | |
|---|---|
| Error | 0.6 |
| Cost | 7496 |
| Alternative 7 | |
|---|---|
| Error | 0.8 |
| Cost | 7304 |
| Alternative 8 | |
|---|---|
| Error | 1.0 |
| Cost | 7112 |
| Alternative 9 | |
|---|---|
| Error | 1.0 |
| Cost | 6985 |
| Alternative 10 | |
|---|---|
| Error | 1.4 |
| Cost | 6857 |
| Alternative 11 | |
|---|---|
| Error | 25.5 |
| Cost | 712 |
| Alternative 12 | |
|---|---|
| Error | 25.5 |
| Cost | 712 |
| Alternative 13 | |
|---|---|
| Error | 25.5 |
| Cost | 584 |
| Alternative 14 | |
|---|---|
| Error | 40.0 |
| Cost | 328 |
| Alternative 15 | |
|---|---|
| Error | 61.1 |
| Cost | 192 |
| Alternative 16 | |
|---|---|
| Error | 46.7 |
| Cost | 64 |
herbie shell --seed 2023066
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))