| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 14024 |
(FPCore (x) :precision binary64 (- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))
(FPCore (x)
:precision binary64
(if (<= (hypot 1.0 x) 2.0)
(+
(+ (* 0.125 (* x x)) (* 0.0673828125 (pow x 6.0)))
(* -0.0859375 (pow x 4.0)))
(/
(+ 0.5 (/ -0.5 (hypot 1.0 x)))
(+ 1.0 (sqrt (+ 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 tmp;
if (hypot(1.0, x) <= 2.0) {
tmp = ((0.125 * (x * x)) + (0.0673828125 * pow(x, 6.0))) + (-0.0859375 * pow(x, 4.0));
} else {
tmp = (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) {
return 1.0 - Math.sqrt((0.5 * (1.0 + (1.0 / Math.hypot(1.0, x)))));
}
public static double code(double x) {
double tmp;
if (Math.hypot(1.0, x) <= 2.0) {
tmp = ((0.125 * (x * x)) + (0.0673828125 * Math.pow(x, 6.0))) + (-0.0859375 * Math.pow(x, 4.0));
} else {
tmp = (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): return 1.0 - math.sqrt((0.5 * (1.0 + (1.0 / math.hypot(1.0, x)))))
def code(x): tmp = 0 if math.hypot(1.0, x) <= 2.0: tmp = ((0.125 * (x * x)) + (0.0673828125 * math.pow(x, 6.0))) + (-0.0859375 * math.pow(x, 4.0)) else: tmp = (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) return Float64(1.0 - sqrt(Float64(0.5 * Float64(1.0 + Float64(1.0 / hypot(1.0, x)))))) end
function code(x) tmp = 0.0 if (hypot(1.0, x) <= 2.0) tmp = Float64(Float64(Float64(0.125 * Float64(x * x)) + Float64(0.0673828125 * (x ^ 6.0))) + Float64(-0.0859375 * (x ^ 4.0))); else tmp = Float64(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 = code(x) tmp = 1.0 - sqrt((0.5 * (1.0 + (1.0 / hypot(1.0, x))))); end
function tmp_2 = code(x) tmp = 0.0; if (hypot(1.0, x) <= 2.0) tmp = ((0.125 * (x * x)) + (0.0673828125 * (x ^ 6.0))) + (-0.0859375 * (x ^ 4.0)); else tmp = (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_] := 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_] := If[LessEqual[N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision], 2.0], N[(N[(N[(0.125 * N[(x * x), $MachinePrecision]), $MachinePrecision] + N[(0.0673828125 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(-0.0859375 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(0.5 + N[(-0.5 / N[Sqrt[1.0 ^ 2 + x ^ 2], $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]]
1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\begin{array}{l}
\mathbf{if}\;\mathsf{hypot}\left(1, x\right) \leq 2:\\
\;\;\;\;\left(0.125 \cdot \left(x \cdot x\right) + 0.0673828125 \cdot {x}^{6}\right) + -0.0859375 \cdot {x}^{4}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.5 + \frac{-0.5}{\mathsf{hypot}\left(1, x\right)}}{1 + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}\\
\end{array}
Results
if (hypot.f64 1 x) < 2Initial program 52.2%
Simplified52.2%
[Start]52.2 | \[ 1 - \sqrt{0.5 \cdot \left(1 + \frac{1}{\mathsf{hypot}\left(1, x\right)}\right)}
\] |
|---|---|
distribute-lft-in [=>]52.2 | \[ 1 - \sqrt{\color{blue}{0.5 \cdot 1 + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]52.2 | \[ 1 - \sqrt{\color{blue}{0.5} + 0.5 \cdot \frac{1}{\mathsf{hypot}\left(1, x\right)}}
\] |
associate-*r/ [=>]52.2 | \[ 1 - \sqrt{0.5 + \color{blue}{\frac{0.5 \cdot 1}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]52.2 | \[ 1 - \sqrt{0.5 + \frac{\color{blue}{0.5}}{\mathsf{hypot}\left(1, x\right)}}
\] |
Taylor expanded in x around 0 99.7%
Applied egg-rr99.0%
[Start]99.7 | \[ 0.125 \cdot {x}^{2} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
|---|---|
add-sqr-sqrt [=>]99.3 | \[ \color{blue}{\sqrt{0.125 \cdot {x}^{2}} \cdot \sqrt{0.125 \cdot {x}^{2}}} + \left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
fma-def [=>]99.3 | \[ \color{blue}{\mathsf{fma}\left(\sqrt{0.125 \cdot {x}^{2}}, \sqrt{0.125 \cdot {x}^{2}}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)}
\] |
*-commutative [=>]99.3 | \[ \mathsf{fma}\left(\sqrt{\color{blue}{{x}^{2} \cdot 0.125}}, \sqrt{0.125 \cdot {x}^{2}}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
sqrt-prod [=>]99.3 | \[ \mathsf{fma}\left(\color{blue}{\sqrt{{x}^{2}} \cdot \sqrt{0.125}}, \sqrt{0.125 \cdot {x}^{2}}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
sqrt-pow1 [=>]74.1 | \[ \mathsf{fma}\left(\color{blue}{{x}^{\left(\frac{2}{2}\right)}} \cdot \sqrt{0.125}, \sqrt{0.125 \cdot {x}^{2}}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
metadata-eval [=>]74.1 | \[ \mathsf{fma}\left({x}^{\color{blue}{1}} \cdot \sqrt{0.125}, \sqrt{0.125 \cdot {x}^{2}}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
pow1 [<=]74.1 | \[ \mathsf{fma}\left(\color{blue}{x} \cdot \sqrt{0.125}, \sqrt{0.125 \cdot {x}^{2}}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
*-commutative [=>]74.1 | \[ \mathsf{fma}\left(x \cdot \sqrt{0.125}, \sqrt{\color{blue}{{x}^{2} \cdot 0.125}}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
sqrt-prod [=>]74.0 | \[ \mathsf{fma}\left(x \cdot \sqrt{0.125}, \color{blue}{\sqrt{{x}^{2}} \cdot \sqrt{0.125}}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
sqrt-pow1 [=>]99.0 | \[ \mathsf{fma}\left(x \cdot \sqrt{0.125}, \color{blue}{{x}^{\left(\frac{2}{2}\right)}} \cdot \sqrt{0.125}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
metadata-eval [=>]99.0 | \[ \mathsf{fma}\left(x \cdot \sqrt{0.125}, {x}^{\color{blue}{1}} \cdot \sqrt{0.125}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
pow1 [<=]99.0 | \[ \mathsf{fma}\left(x \cdot \sqrt{0.125}, \color{blue}{x} \cdot \sqrt{0.125}, 0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)
\] |
+-commutative [=>]99.0 | \[ \mathsf{fma}\left(x \cdot \sqrt{0.125}, x \cdot \sqrt{0.125}, \color{blue}{-0.0859375 \cdot {x}^{4} + 0.0673828125 \cdot {x}^{6}}\right)
\] |
fma-def [=>]99.0 | \[ \mathsf{fma}\left(x \cdot \sqrt{0.125}, x \cdot \sqrt{0.125}, \color{blue}{\mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right)}\right)
\] |
Applied egg-rr99.7%
[Start]99.0 | \[ \mathsf{fma}\left(x \cdot \sqrt{0.125}, x \cdot \sqrt{0.125}, \mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right)\right)
\] |
|---|---|
fma-udef [=>]99.0 | \[ \color{blue}{\left(x \cdot \sqrt{0.125}\right) \cdot \left(x \cdot \sqrt{0.125}\right) + \mathsf{fma}\left(-0.0859375, {x}^{4}, 0.0673828125 \cdot {x}^{6}\right)}
\] |
fma-udef [=>]99.0 | \[ \left(x \cdot \sqrt{0.125}\right) \cdot \left(x \cdot \sqrt{0.125}\right) + \color{blue}{\left(-0.0859375 \cdot {x}^{4} + 0.0673828125 \cdot {x}^{6}\right)}
\] |
+-commutative [=>]99.0 | \[ \left(x \cdot \sqrt{0.125}\right) \cdot \left(x \cdot \sqrt{0.125}\right) + \color{blue}{\left(0.0673828125 \cdot {x}^{6} + -0.0859375 \cdot {x}^{4}\right)}
\] |
associate-+r+ [=>]99.0 | \[ \color{blue}{\left(\left(x \cdot \sqrt{0.125}\right) \cdot \left(x \cdot \sqrt{0.125}\right) + 0.0673828125 \cdot {x}^{6}\right) + -0.0859375 \cdot {x}^{4}}
\] |
*-commutative [=>]99.0 | \[ \left(\color{blue}{\left(\sqrt{0.125} \cdot x\right)} \cdot \left(x \cdot \sqrt{0.125}\right) + 0.0673828125 \cdot {x}^{6}\right) + -0.0859375 \cdot {x}^{4}
\] |
*-commutative [=>]99.0 | \[ \left(\left(\sqrt{0.125} \cdot x\right) \cdot \color{blue}{\left(\sqrt{0.125} \cdot x\right)} + 0.0673828125 \cdot {x}^{6}\right) + -0.0859375 \cdot {x}^{4}
\] |
swap-sqr [=>]98.7 | \[ \left(\color{blue}{\left(\sqrt{0.125} \cdot \sqrt{0.125}\right) \cdot \left(x \cdot x\right)} + 0.0673828125 \cdot {x}^{6}\right) + -0.0859375 \cdot {x}^{4}
\] |
add-sqr-sqrt [<=]99.7 | \[ \left(\color{blue}{0.125} \cdot \left(x \cdot x\right) + 0.0673828125 \cdot {x}^{6}\right) + -0.0859375 \cdot {x}^{4}
\] |
if 2 < (hypot.f64 1 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)}}
\] |
Applied egg-rr98.5%
[Start]98.5 | \[ 1 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}
\] |
|---|---|
sub-neg [=>]98.5 | \[ \color{blue}{1 + \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}
\] |
flip-+ [=>]98.5 | \[ \color{blue}{\frac{1 \cdot 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 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}}
\] |
metadata-eval [=>]98.5 | \[ \frac{\color{blue}{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 - \left(-\sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}
\] |
neg-sub0 [=>]98.5 | \[ \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 - \color{blue}{\left(0 - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}}
\] |
metadata-eval [<=]98.5 | \[ \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 - \left(\color{blue}{\log 1} - \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}\right)}
\] |
associate--r- [=>]98.5 | \[ \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)}{\color{blue}{\left(1 - \log 1\right) + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}}
\] |
metadata-eval [=>]98.5 | \[ \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)}{\left(1 - \color{blue}{0}\right) + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
metadata-eval [=>]98.5 | \[ \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)}{\color{blue}{1} + \sqrt{0.5 + \frac{0.5}{\mathsf{hypot}\left(1, x\right)}}}
\] |
Simplified100.0%
[Start]98.5 | \[ \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 [=>]98.5 | \[ \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 [=>]100.0 | \[ \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+ [=>]100.0 | \[ \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 [=>]100.0 | \[ \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)}}}
\] |
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 14024 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.1% |
| Cost | 7492 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 7305 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 6985 |
| Alternative 5 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 6857 |
| Alternative 6 | |
|---|---|
| Accuracy | 60.0% |
| Cost | 712 |
| Alternative 7 | |
|---|---|
| Accuracy | 60.0% |
| Cost | 712 |
| Alternative 8 | |
|---|---|
| Accuracy | 60.0% |
| Cost | 584 |
| Alternative 9 | |
|---|---|
| Accuracy | 49.7% |
| Cost | 320 |
| Alternative 10 | |
|---|---|
| Accuracy | 26.4% |
| Cost | 64 |
herbie shell --seed 2023137
(FPCore (x)
:name "Given's Rotation SVD example, simplified"
:precision binary64
(- 1.0 (sqrt (* 0.5 (+ 1.0 (/ 1.0 (hypot 1.0 x)))))))