| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 6848 |
\[\log \left(x \cdot 2 + \frac{-0.5}{x}\right)
\]
(FPCore (x) :precision binary64 (log (+ x (sqrt (- (* x x) 1.0)))))
(FPCore (x) :precision binary64 (log1p (+ (* x 2.0) (+ -1.0 (/ -0.5 x)))))
double code(double x) {
return log((x + sqrt(((x * x) - 1.0))));
}
double code(double x) {
return log1p(((x * 2.0) + (-1.0 + (-0.5 / x))));
}
public static double code(double x) {
return Math.log((x + Math.sqrt(((x * x) - 1.0))));
}
public static double code(double x) {
return Math.log1p(((x * 2.0) + (-1.0 + (-0.5 / x))));
}
def code(x): return math.log((x + math.sqrt(((x * x) - 1.0))))
def code(x): return math.log1p(((x * 2.0) + (-1.0 + (-0.5 / x))))
function code(x) return log(Float64(x + sqrt(Float64(Float64(x * x) - 1.0)))) end
function code(x) return log1p(Float64(Float64(x * 2.0) + Float64(-1.0 + Float64(-0.5 / x)))) end
code[x_] := N[Log[N[(x + N[Sqrt[N[(N[(x * x), $MachinePrecision] - 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
code[x_] := N[Log[1 + N[(N[(x * 2.0), $MachinePrecision] + N[(-1.0 + N[(-0.5 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\log \left(x + \sqrt{x \cdot x - 1}\right)
\mathsf{log1p}\left(x \cdot 2 + \left(-1 + \frac{-0.5}{x}\right)\right)
Results
| Original | 31.9 |
|---|---|
| Target | 0.0 |
| Herbie | 0.4 |
Initial program 31.9
Applied egg-rr31.9
Simplified31.9
[Start]31.9 | \[ \mathsf{log1p}\left(x + \left(\sqrt{\mathsf{fma}\left(x, x, -1\right)} - 1\right)\right)
\] |
|---|---|
+-commutative [=>]31.9 | \[ \mathsf{log1p}\left(\color{blue}{\left(\sqrt{\mathsf{fma}\left(x, x, -1\right)} - 1\right) + x}\right)
\] |
sub-neg [=>]31.9 | \[ \mathsf{log1p}\left(\color{blue}{\left(\sqrt{\mathsf{fma}\left(x, x, -1\right)} + \left(-1\right)\right)} + x\right)
\] |
metadata-eval [=>]31.9 | \[ \mathsf{log1p}\left(\left(\sqrt{\mathsf{fma}\left(x, x, -1\right)} + \color{blue}{-1}\right) + x\right)
\] |
associate-+l+ [=>]31.9 | \[ \mathsf{log1p}\left(\color{blue}{\sqrt{\mathsf{fma}\left(x, x, -1\right)} + \left(-1 + x\right)}\right)
\] |
Taylor expanded in x around inf 0.4
Simplified0.4
[Start]0.4 | \[ \mathsf{log1p}\left(2 \cdot x - \left(0.5 \cdot \frac{1}{x} + 1\right)\right)
\] |
|---|---|
*-commutative [=>]0.4 | \[ \mathsf{log1p}\left(\color{blue}{x \cdot 2} - \left(0.5 \cdot \frac{1}{x} + 1\right)\right)
\] |
+-commutative [=>]0.4 | \[ \mathsf{log1p}\left(x \cdot 2 - \color{blue}{\left(1 + 0.5 \cdot \frac{1}{x}\right)}\right)
\] |
associate-*r/ [=>]0.4 | \[ \mathsf{log1p}\left(x \cdot 2 - \left(1 + \color{blue}{\frac{0.5 \cdot 1}{x}}\right)\right)
\] |
metadata-eval [=>]0.4 | \[ \mathsf{log1p}\left(x \cdot 2 - \left(1 + \frac{\color{blue}{0.5}}{x}\right)\right)
\] |
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 6848 |
| Alternative 2 | |
|---|---|
| Error | 0.6 |
| Cost | 6592 |
| Alternative 3 | |
|---|---|
| Error | 64.0 |
| Cost | 6464 |
herbie shell --seed 2023066
(FPCore (x)
:name "Rust f64::acosh"
:precision binary64
:pre (>= x 1.0)
:herbie-target
(log (+ x (* (sqrt (- x 1.0)) (sqrt (+ x 1.0)))))
(log (+ x (sqrt (- (* x x) 1.0)))))