| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 13760 |
\[\frac{\frac{1}{x}}{\left(1 + x\right) \cdot \left({x}^{-0.5} + {\left(1 + x\right)}^{-0.5}\right)}
\]
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (/ (/ 1.0 (hypot x (sqrt x))) (+ (sqrt x) (sqrt (+ 1.0 x)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
return (1.0 / hypot(x, sqrt(x))) / (sqrt(x) + sqrt((1.0 + x)));
}
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
public static double code(double x) {
return (1.0 / Math.hypot(x, Math.sqrt(x))) / (Math.sqrt(x) + Math.sqrt((1.0 + x)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x): return (1.0 / math.hypot(x, math.sqrt(x))) / (math.sqrt(x) + math.sqrt((1.0 + x)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function code(x) return Float64(Float64(1.0 / hypot(x, sqrt(x))) / Float64(sqrt(x) + sqrt(Float64(1.0 + x)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
function tmp = code(x) tmp = (1.0 / hypot(x, sqrt(x))) / (sqrt(x) + sqrt((1.0 + x))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_] := N[(N[(1.0 / N[Sqrt[x ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision]), $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] + N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt{x} + \sqrt{1 + x}}
Results
| Original | 68.5% |
|---|---|
| Target | 99.0% |
| Herbie | 99.6% |
Initial program 68.5%
Applied egg-rr91.7%
Simplified91.7%
[Start]91.7 | \[ \frac{1 + \left(x - x\right)}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}
\] |
|---|---|
+-commutative [=>]91.7 | \[ \frac{\color{blue}{\left(x - x\right) + 1}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}
\] |
+-inverses [=>]91.7 | \[ \frac{\color{blue}{0} + 1}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}
\] |
metadata-eval [=>]91.7 | \[ \frac{\color{blue}{1}}{\sqrt{x + x \cdot x} \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}
\] |
+-commutative [=>]91.7 | \[ \frac{1}{\sqrt{x + x \cdot x} \cdot \color{blue}{\left(\sqrt{1 + x} + \sqrt{x}\right)}}
\] |
Applied egg-rr99.0%
Applied egg-rr64.5%
Simplified99.6%
[Start]64.5 | \[ e^{\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]95.5 | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}\right)\right)}
\] |
expm1-log1p [=>]99.0 | \[ \color{blue}{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right) \cdot \left(\sqrt{x} + \sqrt{1 + x}\right)}}
\] |
associate-/r* [=>]99.6 | \[ \color{blue}{\frac{\frac{1}{\mathsf{hypot}\left(x, \sqrt{x}\right)}}{\sqrt{x} + \sqrt{1 + x}}}
\] |
Final simplification99.6%
| Alternative 1 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 13760 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.7% |
| Cost | 13508 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 13508 |
| Alternative 4 | |
|---|---|
| Accuracy | 91.4% |
| Cost | 13380 |
| Alternative 5 | |
|---|---|
| Accuracy | 90.6% |
| Cost | 7364 |
| Alternative 6 | |
|---|---|
| Accuracy | 68.0% |
| Cost | 7044 |
| Alternative 7 | |
|---|---|
| Accuracy | 66.3% |
| Cost | 6788 |
| Alternative 8 | |
|---|---|
| Accuracy | 67.7% |
| Cost | 6788 |
| Alternative 9 | |
|---|---|
| Accuracy | 66.3% |
| Cost | 6660 |
| Alternative 10 | |
|---|---|
| Accuracy | 20.3% |
| Cost | 320 |
herbie shell --seed 2023122
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))