| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 19776 |

(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
(FPCore (x) :precision binary64 (/ (pow x -0.5) (+ (hypot x (sqrt x)) (+ x 1.0))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
double code(double x) {
return pow(x, -0.5) / (hypot(x, sqrt(x)) + (x + 1.0));
}
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 Math.pow(x, -0.5) / (Math.hypot(x, Math.sqrt(x)) + (x + 1.0));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
def code(x): return math.pow(x, -0.5) / (math.hypot(x, math.sqrt(x)) + (x + 1.0))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function code(x) return Float64((x ^ -0.5) / Float64(hypot(x, sqrt(x)) + Float64(x + 1.0))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
function tmp = code(x) tmp = (x ^ -0.5) / (hypot(x, sqrt(x)) + (x + 1.0)); 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[Power[x, -0.5], $MachinePrecision] / N[(N[Sqrt[x ^ 2 + N[Sqrt[x], $MachinePrecision] ^ 2], $MachinePrecision] + N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\frac{{x}^{-0.5}}{\mathsf{hypot}\left(x, \sqrt{x}\right) + \left(x + 1\right)}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 69.5% |
|---|---|
| Target | 99.0% |
| Herbie | 99.8% |
Initial program 70.9%
Applied egg-rr71.2%
[Start]70.9% | \[ \frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\] |
|---|---|
frac-sub [=>]71.0% | \[ \color{blue}{\frac{1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1}{\sqrt{x} \cdot \sqrt{x + 1}}}
\] |
div-inv [=>]71.0% | \[ \color{blue}{\left(1 \cdot \sqrt{x + 1} - \sqrt{x} \cdot 1\right) \cdot \frac{1}{\sqrt{x} \cdot \sqrt{x + 1}}}
\] |
*-un-lft-identity [<=]71.0% | \[ \left(\color{blue}{\sqrt{x + 1}} - \sqrt{x} \cdot 1\right) \cdot \frac{1}{\sqrt{x} \cdot \sqrt{x + 1}}
\] |
+-commutative [=>]71.0% | \[ \left(\sqrt{\color{blue}{1 + x}} - \sqrt{x} \cdot 1\right) \cdot \frac{1}{\sqrt{x} \cdot \sqrt{x + 1}}
\] |
*-rgt-identity [=>]71.0% | \[ \left(\sqrt{1 + x} - \color{blue}{\sqrt{x}}\right) \cdot \frac{1}{\sqrt{x} \cdot \sqrt{x + 1}}
\] |
metadata-eval [<=]71.0% | \[ \left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \frac{\color{blue}{1 \cdot 1}}{\sqrt{x} \cdot \sqrt{x + 1}}
\] |
frac-times [<=]71.0% | \[ \left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \color{blue}{\left(\frac{1}{\sqrt{x}} \cdot \frac{1}{\sqrt{x + 1}}\right)}
\] |
un-div-inv [=>]71.0% | \[ \left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \color{blue}{\frac{\frac{1}{\sqrt{x}}}{\sqrt{x + 1}}}
\] |
pow1/2 [=>]71.0% | \[ \left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \frac{\frac{1}{\color{blue}{{x}^{0.5}}}}{\sqrt{x + 1}}
\] |
pow-flip [=>]71.2% | \[ \left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \frac{\color{blue}{{x}^{\left(-0.5\right)}}}{\sqrt{x + 1}}
\] |
metadata-eval [=>]71.2% | \[ \left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \frac{{x}^{\color{blue}{-0.5}}}{\sqrt{x + 1}}
\] |
+-commutative [=>]71.2% | \[ \left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \frac{{x}^{-0.5}}{\sqrt{\color{blue}{1 + x}}}
\] |
Simplified71.2%
[Start]71.2% | \[ \left(\sqrt{1 + x} - \sqrt{x}\right) \cdot \frac{{x}^{-0.5}}{\sqrt{1 + x}}
\] |
|---|---|
associate-*r/ [=>]71.2% | \[ \color{blue}{\frac{\left(\sqrt{1 + x} - \sqrt{x}\right) \cdot {x}^{-0.5}}{\sqrt{1 + x}}}
\] |
Applied egg-rr72.0%
[Start]71.2% | \[ \frac{\left(\sqrt{1 + x} - \sqrt{x}\right) \cdot {x}^{-0.5}}{\sqrt{1 + x}}
\] |
|---|---|
flip-- [=>]71.3% | \[ \frac{\color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}
\] |
add-sqr-sqrt [<=]61.2% | \[ \frac{\frac{\color{blue}{\left(1 + x\right)} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}
\] |
add-sqr-sqrt [<=]72.0% | \[ \frac{\frac{\left(1 + x\right) - \color{blue}{x}}{\sqrt{1 + x} + \sqrt{x}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}
\] |
Simplified99.7%
[Start]72.0% | \[ \frac{\frac{\left(1 + x\right) - x}{\sqrt{1 + x} + \sqrt{x}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}
\] |
|---|---|
associate--l+ [=>]99.7% | \[ \frac{\frac{\color{blue}{1 + \left(x - x\right)}}{\sqrt{1 + x} + \sqrt{x}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}
\] |
+-inverses [=>]99.7% | \[ \frac{\frac{1 + \color{blue}{0}}{\sqrt{1 + x} + \sqrt{x}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}
\] |
metadata-eval [=>]99.7% | \[ \frac{\frac{\color{blue}{1}}{\sqrt{1 + x} + \sqrt{x}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}
\] |
Applied egg-rr67.0%
[Start]99.7% | \[ \frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}
\] |
|---|---|
expm1-log1p-u [=>]96.0% | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}\right)\right)}
\] |
expm1-udef [=>]66.9% | \[ \color{blue}{e^{\mathsf{log1p}\left(\frac{\frac{1}{\sqrt{1 + x} + \sqrt{x}} \cdot {x}^{-0.5}}{\sqrt{1 + x}}\right)} - 1}
\] |
associate-*l/ [=>]66.9% | \[ e^{\mathsf{log1p}\left(\frac{\color{blue}{\frac{1 \cdot {x}^{-0.5}}{\sqrt{1 + x} + \sqrt{x}}}}{\sqrt{1 + x}}\right)} - 1
\] |
*-un-lft-identity [<=]66.9% | \[ e^{\mathsf{log1p}\left(\frac{\frac{\color{blue}{{x}^{-0.5}}}{\sqrt{1 + x} + \sqrt{x}}}{\sqrt{1 + x}}\right)} - 1
\] |
associate-/l/ [=>]67.0% | \[ e^{\mathsf{log1p}\left(\color{blue}{\frac{{x}^{-0.5}}{\sqrt{1 + x} \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}}\right)} - 1
\] |
Simplified99.8%
[Start]67.0% | \[ e^{\mathsf{log1p}\left(\frac{{x}^{-0.5}}{\sqrt{1 + x} \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]96.0% | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{x}^{-0.5}}{\sqrt{1 + x} \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}\right)\right)}
\] |
expm1-log1p [=>]99.7% | \[ \color{blue}{\frac{{x}^{-0.5}}{\sqrt{1 + x} \cdot \left(\sqrt{1 + x} + \sqrt{x}\right)}}
\] |
distribute-rgt-in [=>]99.7% | \[ \frac{{x}^{-0.5}}{\color{blue}{\sqrt{1 + x} \cdot \sqrt{1 + x} + \sqrt{x} \cdot \sqrt{1 + x}}}
\] |
rem-square-sqrt [=>]99.8% | \[ \frac{{x}^{-0.5}}{\color{blue}{\left(1 + x\right)} + \sqrt{x} \cdot \sqrt{1 + x}}
\] |
+-commutative [=>]99.8% | \[ \frac{{x}^{-0.5}}{\color{blue}{\left(x + 1\right)} + \sqrt{x} \cdot \sqrt{1 + x}}
\] |
+-commutative [=>]99.8% | \[ \frac{{x}^{-0.5}}{\left(x + 1\right) + \sqrt{x} \cdot \sqrt{\color{blue}{x + 1}}}
\] |
Applied egg-rr67.0%
[Start]99.8% | \[ \frac{{x}^{-0.5}}{\left(x + 1\right) + \sqrt{x} \cdot \sqrt{x + 1}}
\] |
|---|---|
expm1-log1p-u [=>]96.1% | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{x}^{-0.5}}{\left(x + 1\right) + \sqrt{x} \cdot \sqrt{x + 1}}\right)\right)}
\] |
expm1-udef [=>]67.0% | \[ \color{blue}{e^{\mathsf{log1p}\left(\frac{{x}^{-0.5}}{\left(x + 1\right) + \sqrt{x} \cdot \sqrt{x + 1}}\right)} - 1}
\] |
sqrt-prod [<=]67.0% | \[ e^{\mathsf{log1p}\left(\frac{{x}^{-0.5}}{\left(x + 1\right) + \color{blue}{\sqrt{x \cdot \left(x + 1\right)}}}\right)} - 1
\] |
associate-+l+ [=>]67.0% | \[ e^{\mathsf{log1p}\left(\frac{{x}^{-0.5}}{\color{blue}{x + \left(1 + \sqrt{x \cdot \left(x + 1\right)}\right)}}\right)} - 1
\] |
distribute-rgt-in [=>]67.0% | \[ e^{\mathsf{log1p}\left(\frac{{x}^{-0.5}}{x + \left(1 + \sqrt{\color{blue}{x \cdot x + 1 \cdot x}}\right)}\right)} - 1
\] |
*-un-lft-identity [<=]67.0% | \[ e^{\mathsf{log1p}\left(\frac{{x}^{-0.5}}{x + \left(1 + \sqrt{x \cdot x + \color{blue}{x}}\right)}\right)} - 1
\] |
add-sqr-sqrt [=>]67.0% | \[ e^{\mathsf{log1p}\left(\frac{{x}^{-0.5}}{x + \left(1 + \sqrt{x \cdot x + \color{blue}{\sqrt{x} \cdot \sqrt{x}}}\right)}\right)} - 1
\] |
hypot-def [=>]67.0% | \[ e^{\mathsf{log1p}\left(\frac{{x}^{-0.5}}{x + \left(1 + \color{blue}{\mathsf{hypot}\left(x, \sqrt{x}\right)}\right)}\right)} - 1
\] |
Simplified99.9%
[Start]67.0% | \[ e^{\mathsf{log1p}\left(\frac{{x}^{-0.5}}{x + \left(1 + \mathsf{hypot}\left(x, \sqrt{x}\right)\right)}\right)} - 1
\] |
|---|---|
expm1-def [=>]96.1% | \[ \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{x}^{-0.5}}{x + \left(1 + \mathsf{hypot}\left(x, \sqrt{x}\right)\right)}\right)\right)}
\] |
expm1-log1p [=>]99.9% | \[ \color{blue}{\frac{{x}^{-0.5}}{x + \left(1 + \mathsf{hypot}\left(x, \sqrt{x}\right)\right)}}
\] |
+-commutative [=>]99.9% | \[ \frac{{x}^{-0.5}}{\color{blue}{\left(1 + \mathsf{hypot}\left(x, \sqrt{x}\right)\right) + x}}
\] |
+-commutative [=>]99.9% | \[ \frac{{x}^{-0.5}}{\color{blue}{\left(\mathsf{hypot}\left(x, \sqrt{x}\right) + 1\right)} + x}
\] |
associate-+r+ [<=]99.9% | \[ \frac{{x}^{-0.5}}{\color{blue}{\mathsf{hypot}\left(x, \sqrt{x}\right) + \left(1 + x\right)}}
\] |
+-commutative [<=]99.9% | \[ \frac{{x}^{-0.5}}{\mathsf{hypot}\left(x, \sqrt{x}\right) + \color{blue}{\left(x + 1\right)}}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 19776 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 26756 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.8% |
| Cost | 13380 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 7812 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.2% |
| Cost | 7300 |
| Alternative 6 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 7044 |
| Alternative 7 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 7044 |
| Alternative 8 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 6980 |
| Alternative 9 | |
|---|---|
| Accuracy | 98.2% |
| Cost | 6916 |
| Alternative 10 | |
|---|---|
| Accuracy | 68.6% |
| Cost | 6788 |
| Alternative 11 | |
|---|---|
| Accuracy | 67.2% |
| Cost | 6660 |
| Alternative 12 | |
|---|---|
| Accuracy | 22.3% |
| Cost | 576 |
| Alternative 13 | |
|---|---|
| Accuracy | 7.4% |
| Cost | 192 |
herbie shell --seed 2023165
(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)))))