| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6985 |
\[\begin{array}{l}
\mathbf{if}\;x \leq -1 \cdot 10^{+16} \lor \neg \left(x \leq 400000000\right):\\
\;\;\;\;\frac{1}{x}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{\mathsf{fma}\left(x, x, 1\right)}\\
\end{array}
\]
(FPCore (x) :precision binary64 (/ x (+ (* x x) 1.0)))
(FPCore (x) :precision binary64 (/ (/ x (hypot 1.0 x)) (hypot 1.0 x)))
double code(double x) {
return x / ((x * x) + 1.0);
}
double code(double x) {
return (x / hypot(1.0, x)) / hypot(1.0, x);
}
public static double code(double x) {
return x / ((x * x) + 1.0);
}
public static double code(double x) {
return (x / Math.hypot(1.0, x)) / Math.hypot(1.0, x);
}
def code(x): return x / ((x * x) + 1.0)
def code(x): return (x / math.hypot(1.0, x)) / math.hypot(1.0, x)
function code(x) return Float64(x / Float64(Float64(x * x) + 1.0)) end
function code(x) return Float64(Float64(x / hypot(1.0, x)) / hypot(1.0, x)) end
function tmp = code(x) tmp = x / ((x * x) + 1.0); end
function tmp = code(x) tmp = (x / hypot(1.0, x)) / hypot(1.0, x); end
code[x_] := N[(x / N[(N[(x * x), $MachinePrecision] + 1.0), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(x / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision] / N[Sqrt[1.0 ^ 2 + x ^ 2], $MachinePrecision]), $MachinePrecision]
\frac{x}{x \cdot x + 1}
\frac{\frac{x}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(1, x\right)}
Results
| Original | 76.7% |
|---|---|
| Target | 99.8% |
| Herbie | 100.0% |
Initial program 76.7%
Applied egg-rr100.0%
[Start]76.7 | \[ \frac{x}{x \cdot x + 1}
\] |
|---|---|
*-un-lft-identity [=>]76.7 | \[ \frac{\color{blue}{1 \cdot x}}{x \cdot x + 1}
\] |
add-sqr-sqrt [=>]76.7 | \[ \frac{1 \cdot x}{\color{blue}{\sqrt{x \cdot x + 1} \cdot \sqrt{x \cdot x + 1}}}
\] |
times-frac [=>]76.8 | \[ \color{blue}{\frac{1}{\sqrt{x \cdot x + 1}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}}
\] |
+-commutative [=>]76.8 | \[ \frac{1}{\sqrt{\color{blue}{1 + x \cdot x}}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}
\] |
hypot-1-def [=>]76.8 | \[ \frac{1}{\color{blue}{\mathsf{hypot}\left(1, x\right)}} \cdot \frac{x}{\sqrt{x \cdot x + 1}}
\] |
+-commutative [=>]76.8 | \[ \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{x}{\sqrt{\color{blue}{1 + x \cdot x}}}
\] |
hypot-1-def [=>]100.0 | \[ \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{x}{\color{blue}{\mathsf{hypot}\left(1, x\right)}}
\] |
Applied egg-rr100.0%
[Start]100.0 | \[ \frac{1}{\mathsf{hypot}\left(1, x\right)} \cdot \frac{x}{\mathsf{hypot}\left(1, x\right)}
\] |
|---|---|
associate-*l/ [=>]100.0 | \[ \color{blue}{\frac{1 \cdot \frac{x}{\mathsf{hypot}\left(1, x\right)}}{\mathsf{hypot}\left(1, x\right)}}
\] |
*-un-lft-identity [<=]100.0 | \[ \frac{\color{blue}{\frac{x}{\mathsf{hypot}\left(1, x\right)}}}{\mathsf{hypot}\left(1, x\right)}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 6985 |
| Alternative 2 | |
|---|---|
| Accuracy | 100.0% |
| Cost | 712 |
| Alternative 3 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 456 |
| Alternative 4 | |
|---|---|
| Accuracy | 51.3% |
| Cost | 64 |
herbie shell --seed 2023131
(FPCore (x)
:name "x / (x^2 + 1)"
:precision binary64
:herbie-target
(/ 1.0 (+ x (/ 1.0 x)))
(/ x (+ (* x x) 1.0)))