| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 33736 |
(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)))
(t_1 (+ 0.5 t_0))
(t_2 (sqrt t_1))
(t_3 (+ 0.5 (+ t_0 t_2))))
(if (<= x -1.2)
(/ (+ 1.0 (+ -0.5 (/ 0.5 x))) (+ 1.0 (sqrt (+ 0.5 (/ -0.5 x)))))
(if (<= x 0.012)
(+
(* 0.125 (pow x 2.0))
(+ (* 0.0673828125 (pow x 6.0)) (* -0.0859375 (pow x 4.0))))
(/
(- 1.0 (pow t_1 1.5))
(/
(+ 1.0 (pow t_3 3.0))
(+ 0.5 (+ (* t_3 t_3) (- (/ -0.5 (hypot 1.0 x)) t_2)))))))))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 t_1 = 0.5 + t_0;
double t_2 = sqrt(t_1);
double t_3 = 0.5 + (t_0 + t_2);
double tmp;
if (x <= -1.2) {
tmp = (1.0 + (-0.5 + (0.5 / x))) / (1.0 + sqrt((0.5 + (-0.5 / x))));
} else if (x <= 0.012) {
tmp = (0.125 * pow(x, 2.0)) + ((0.0673828125 * pow(x, 6.0)) + (-0.0859375 * pow(x, 4.0)));
} else {
tmp = (1.0 - pow(t_1, 1.5)) / ((1.0 + pow(t_3, 3.0)) / (0.5 + ((t_3 * t_3) + ((-0.5 / hypot(1.0, x)) - t_2))));
}
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 t_1 = 0.5 + t_0;
double t_2 = Math.sqrt(t_1);
double t_3 = 0.5 + (t_0 + t_2);
double tmp;
if (x <= -1.2) {
tmp = (1.0 + (-0.5 + (0.5 / x))) / (1.0 + Math.sqrt((0.5 + (-0.5 / x))));
} else if (x <= 0.012) {
tmp = (0.125 * Math.pow(x, 2.0)) + ((0.0673828125 * Math.pow(x, 6.0)) + (-0.0859375 * Math.pow(x, 4.0)));
} else {
tmp = (1.0 - Math.pow(t_1, 1.5)) / ((1.0 + Math.pow(t_3, 3.0)) / (0.5 + ((t_3 * t_3) + ((-0.5 / Math.hypot(1.0, x)) - t_2))));
}
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) t_1 = 0.5 + t_0 t_2 = math.sqrt(t_1) t_3 = 0.5 + (t_0 + t_2) tmp = 0 if x <= -1.2: tmp = (1.0 + (-0.5 + (0.5 / x))) / (1.0 + math.sqrt((0.5 + (-0.5 / x)))) elif x <= 0.012: tmp = (0.125 * math.pow(x, 2.0)) + ((0.0673828125 * math.pow(x, 6.0)) + (-0.0859375 * math.pow(x, 4.0))) else: tmp = (1.0 - math.pow(t_1, 1.5)) / ((1.0 + math.pow(t_3, 3.0)) / (0.5 + ((t_3 * t_3) + ((-0.5 / math.hypot(1.0, x)) - t_2)))) 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)) t_1 = Float64(0.5 + t_0) t_2 = sqrt(t_1) t_3 = Float64(0.5 + Float64(t_0 + t_2)) tmp = 0.0 if (x <= -1.2) tmp = Float64(Float64(1.0 + Float64(-0.5 + Float64(0.5 / x))) / Float64(1.0 + sqrt(Float64(0.5 + Float64(-0.5 / x))))); elseif (x <= 0.012) tmp = Float64(Float64(0.125 * (x ^ 2.0)) + Float64(Float64(0.0673828125 * (x ^ 6.0)) + Float64(-0.0859375 * (x ^ 4.0)))); else tmp = Float64(Float64(1.0 - (t_1 ^ 1.5)) / Float64(Float64(1.0 + (t_3 ^ 3.0)) / Float64(0.5 + Float64(Float64(t_3 * t_3) + Float64(Float64(-0.5 / hypot(1.0, x)) - t_2))))); 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); t_1 = 0.5 + t_0; t_2 = sqrt(t_1); t_3 = 0.5 + (t_0 + t_2); tmp = 0.0; if (x <= -1.2) tmp = (1.0 + (-0.5 + (0.5 / x))) / (1.0 + sqrt((0.5 + (-0.5 / x)))); elseif (x <= 0.012) tmp = (0.125 * (x ^ 2.0)) + ((0.0673828125 * (x ^ 6.0)) + (-0.0859375 * (x ^ 4.0))); else tmp = (1.0 - (t_1 ^ 1.5)) / ((1.0 + (t_3 ^ 3.0)) / (0.5 + ((t_3 * t_3) + ((-0.5 / hypot(1.0, x)) - t_2)))); 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]}, Block[{t$95$1 = N[(0.5 + t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[Sqrt[t$95$1], $MachinePrecision]}, Block[{t$95$3 = N[(0.5 + N[(t$95$0 + t$95$2), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -1.2], N[(N[(1.0 + N[(-0.5 + N[(0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(1.0 + N[Sqrt[N[(0.5 + N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.012], N[(N[(0.125 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.0673828125 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(1.0 - N[Power[t$95$1, 1.5], $MachinePrecision]), $MachinePrecision] / N[(N[(1.0 + N[Power[t$95$3, 3.0], $MachinePrecision]), $MachinePrecision] / N[(0.5 + N[(N[(t$95$3 * t$95$3), $MachinePrecision] + N[(N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] - t$95$2), $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)}\\
t_1 := 0.5 + t_0\\
t_2 := \sqrt{t_1}\\
t_3 := 0.5 + \left(t_0 + t_2\right)\\
\mathbf{if}\;x \leq -1.2:\\
\;\;\;\;\frac{1 + \left(-0.5 + \frac{0.5}{x}\right)}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}\\
\mathbf{elif}\;x \leq 0.012:\\
\;\;\;\;0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1 - {t_1}^{1.5}}{\frac{1 + {t_3}^{3}}{0.5 + \left(t_3 \cdot t_3 + \left(\frac{-0.5}{\mathsf{hypot}\left(1, x\right)} - t_2\right)\right)}}\\
\end{array}
Results
if x < -1.19999999999999996Initial 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.7%
Simplified97.7%
[Start]97.7 | \[ 1 - \sqrt{0.5 - 0.5 \cdot \frac{1}{x}}
\] |
|---|---|
associate-*r/ [=>]97.7 | \[ 1 - \sqrt{0.5 - \color{blue}{\frac{0.5 \cdot 1}{x}}}
\] |
metadata-eval [=>]97.7 | \[ 1 - \sqrt{0.5 - \frac{\color{blue}{0.5}}{x}}
\] |
Applied egg-rr97.7%
[Start]97.7 | \[ 1 - \sqrt{0.5 - \frac{0.5}{x}}
\] |
|---|---|
sub-neg [=>]97.7 | \[ \color{blue}{1 + \left(-\sqrt{0.5 - \frac{0.5}{x}}\right)}
\] |
flip-+ [=>]97.7 | \[ \color{blue}{\frac{1 \cdot 1 - \left(-\sqrt{0.5 - \frac{0.5}{x}}\right) \cdot \left(-\sqrt{0.5 - \frac{0.5}{x}}\right)}{1 - \left(-\sqrt{0.5 - \frac{0.5}{x}}\right)}}
\] |
Simplified99.1%
[Start]97.7 | \[ \frac{1 - \left(-\sqrt{0.5 + \frac{-0.5}{x}}\right) \cdot \left(-\sqrt{0.5 + \frac{-0.5}{x}}\right)}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}
\] |
|---|---|
sqr-neg [=>]97.7 | \[ \frac{1 - \color{blue}{\sqrt{0.5 + \frac{-0.5}{x}} \cdot \sqrt{0.5 + \frac{-0.5}{x}}}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}
\] |
rem-square-sqrt [=>]99.1 | \[ \frac{1 - \color{blue}{\left(0.5 + \frac{-0.5}{x}\right)}}{1 + \sqrt{0.5 + \frac{-0.5}{x}}}
\] |
if -1.19999999999999996 < x < 0.012Initial program 53.8%
Simplified53.8%
[Start]53.8 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]53.8 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]53.8 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]53.8 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]53.8 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Taylor expanded in x around 0 99.8%
if 0.012 < x Initial 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)}}
\] |
|---|---|
flip3-- [=>]97.5 | \[ \color{blue}{\frac{{1}^{3} - {\left(\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{3}}{1 \cdot 1 + \left(\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 \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}}
\] |
metadata-eval [=>]97.5 | \[ \frac{{1}^{3} - {\left(\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{3}}{\color{blue}{1} + \left(\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 \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}
\] |
flip3-+ [=>]97.5 | \[ \frac{{1}^{3} - {\left(\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{3}}{\color{blue}{\frac{{1}^{3} + {\left(\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 \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}^{3}}{1 \cdot 1 + \left(\left(\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 \cdot \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)}} \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}} + 1 \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right) - 1 \cdot \left(\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 \cdot \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}}}
\] |
Simplified99.9%
[Start]99.9 | \[ \frac{1 - {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{1.5}}{1 + {\left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}^{3}} \cdot \left(1 + \left(\left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right) \cdot \left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right) - \left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)\right)\right)
\] |
|---|---|
associate-*l/ [=>]99.9 | \[ \color{blue}{\frac{\left(1 - {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{1.5}\right) \cdot \left(1 + \left(\left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right) \cdot \left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right) - \left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)\right)\right)}{1 + {\left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}^{3}}}
\] |
associate-/l* [=>]99.9 | \[ \color{blue}{\frac{1 - {\left(0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}\right)}^{1.5}}{\frac{1 + {\left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)}^{3}}{1 + \left(\left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right) \cdot \left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right) - \left(0.5 + \left(\frac{0.5}{\mathsf{hypot}\left(1, x\right)} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)\right)\right)}}}
\] |
Final simplification99.7%
| Alternative 1 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 33736 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 27396 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 26884 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 22472 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 21192 |
| Alternative 6 | |
|---|---|
| Accuracy | 99.7% |
| Cost | 20424 |
| Alternative 7 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 20360 |
| Alternative 8 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 7624 |
| Alternative 9 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 7492 |
| Alternative 10 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 7304 |
| Alternative 11 | |
|---|---|
| Accuracy | 98.3% |
| Cost | 7112 |
| Alternative 12 | |
|---|---|
| Accuracy | 98.4% |
| Cost | 6985 |
| Alternative 13 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 6857 |
| Alternative 14 | |
|---|---|
| Accuracy | 58.7% |
| Cost | 969 |
| Alternative 15 | |
|---|---|
| Accuracy | 58.7% |
| Cost | 584 |
| Alternative 16 | |
|---|---|
| Accuracy | 35.9% |
| Cost | 328 |
| Alternative 17 | |
|---|---|
| Accuracy | 27.9% |
| Cost | 64 |
herbie shell --seed 2023140
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))