| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 712 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -0.86:\\
\;\;\;\;\frac{1}{x}\\
\mathbf{elif}\;x \leq 0.86:\\
\;\;\;\;x \cdot \left(1 - x \cdot x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\
\end{array}
\]
(FPCore (x) :precision binary64 (/ x (+ (* x x) 1.0)))
(FPCore (x) :precision binary64 (/ 1.0 (+ x (/ 1.0 x))))
double code(double x) {
return x / ((x * x) + 1.0);
}
double code(double x) {
return 1.0 / (x + (1.0 / x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = x / ((x * x) + 1.0d0)
end function
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + (1.0d0 / x))
end function
public static double code(double x) {
return x / ((x * x) + 1.0);
}
public static double code(double x) {
return 1.0 / (x + (1.0 / x));
}
def code(x): return x / ((x * x) + 1.0)
def code(x): return 1.0 / (x + (1.0 / x))
function code(x) return Float64(x / Float64(Float64(x * x) + 1.0)) end
function code(x) return Float64(1.0 / Float64(x + Float64(1.0 / x))) end
function tmp = code(x) tmp = x / ((x * x) + 1.0); end
function tmp = code(x) tmp = 1.0 / (x + (1.0 / x)); end
code[x_] := N[(x / N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(1.0 / N[(x + N[(1.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{x}{x \cdot x + 1}
\frac{1}{x + \frac{1}{x}}
Results
| Original | 76.6% |
|---|---|
| Target | 99.8% |
| Herbie | 99.8% |
Initial program 76.6%
Applied egg-rr58.6%
[Start]76.6 | \[ \frac{x}{x \cdot x + 1}
\] |
|---|---|
flip3-+ [=>]58.6 | \[ \frac{x}{\color{blue}{\frac{{\left(x \cdot x\right)}^{3} + {1}^{3}}{\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)}}}
\] |
associate-/r/ [=>]58.6 | \[ \color{blue}{\frac{x}{{\left(x \cdot x\right)}^{3} + {1}^{3}} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)\right)}
\] |
metadata-eval [=>]58.6 | \[ \frac{x}{{\left(x \cdot x\right)}^{3} + \color{blue}{1}} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)\right)
\] |
+-commutative [=>]58.6 | \[ \frac{x}{\color{blue}{1 + {\left(x \cdot x\right)}^{3}}} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)\right)
\] |
pow2 [=>]58.6 | \[ \frac{x}{1 + {\color{blue}{\left({x}^{2}\right)}}^{3}} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)\right)
\] |
pow-pow [=>]58.6 | \[ \frac{x}{1 + \color{blue}{{x}^{\left(2 \cdot 3\right)}}} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)\right)
\] |
metadata-eval [=>]58.6 | \[ \frac{x}{1 + {x}^{\color{blue}{6}}} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 \cdot 1 - \left(x \cdot x\right) \cdot 1\right)\right)
\] |
metadata-eval [=>]58.6 | \[ \frac{x}{1 + {x}^{6}} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(\color{blue}{1} - \left(x \cdot x\right) \cdot 1\right)\right)
\] |
*-rgt-identity [=>]58.6 | \[ \frac{x}{1 + {x}^{6}} \cdot \left(\left(x \cdot x\right) \cdot \left(x \cdot x\right) + \left(1 - \color{blue}{x \cdot x}\right)\right)
\] |
pow2 [=>]58.6 | \[ \frac{x}{1 + {x}^{6}} \cdot \left(\color{blue}{{x}^{2}} \cdot \left(x \cdot x\right) + \left(1 - x \cdot x\right)\right)
\] |
pow2 [=>]58.6 | \[ \frac{x}{1 + {x}^{6}} \cdot \left({x}^{2} \cdot \color{blue}{{x}^{2}} + \left(1 - x \cdot x\right)\right)
\] |
pow-sqr [=>]58.6 | \[ \frac{x}{1 + {x}^{6}} \cdot \left(\color{blue}{{x}^{\left(2 \cdot 2\right)}} + \left(1 - x \cdot x\right)\right)
\] |
metadata-eval [=>]58.6 | \[ \frac{x}{1 + {x}^{6}} \cdot \left({x}^{\color{blue}{4}} + \left(1 - x \cdot x\right)\right)
\] |
Applied egg-rr76.6%
[Start]58.6 | \[ \frac{x}{1 + {x}^{6}} \cdot \left({x}^{4} + \left(1 - x \cdot x\right)\right)
\] |
|---|---|
associate-*l/ [=>]58.5 | \[ \color{blue}{\frac{x \cdot \left({x}^{4} + \left(1 - x \cdot x\right)\right)}{1 + {x}^{6}}}
\] |
clear-num [=>]58.4 | \[ \color{blue}{\frac{1}{\frac{1 + {x}^{6}}{x \cdot \left({x}^{4} + \left(1 - x \cdot x\right)\right)}}}
\] |
*-commutative [=>]58.4 | \[ \frac{1}{\frac{1 + {x}^{6}}{\color{blue}{\left({x}^{4} + \left(1 - x \cdot x\right)\right) \cdot x}}}
\] |
associate-/r* [=>]58.5 | \[ \frac{1}{\color{blue}{\frac{\frac{1 + {x}^{6}}{{x}^{4} + \left(1 - x \cdot x\right)}}{x}}}
\] |
Taylor expanded in x around 0 99.8%
Final simplification99.8%
| Alternative 1 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 712 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 456 |
| Alternative 3 | |
|---|---|
| Accuracy | 51.6% |
| Cost | 64 |
herbie shell --seed 2023138
(FPCore (x)
:name "x / (x^2 + 1)"
:precision binary64
:herbie-target
(/ 1.0 (+ x (/ 1.0 x)))
(/ x (+ (* x x) 1.0)))