| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6848 |
\[\mathsf{fma}\left(x, x \cdot -0.5, -1 - x\right)
\]

(FPCore (x) :precision binary64 (/ (log (- 1.0 x)) (log (+ 1.0 x))))
(FPCore (x) :precision binary64 (fma x (* x -0.5) (- -1.0 x)))
double code(double x) {
return log((1.0 - x)) / log((1.0 + x));
}
double code(double x) {
return fma(x, (x * -0.5), (-1.0 - x));
}
function code(x) return Float64(log(Float64(1.0 - x)) / log(Float64(1.0 + x))) end
function code(x) return fma(x, Float64(x * -0.5), Float64(-1.0 - x)) end
code[x_] := N[(N[Log[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] / N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := N[(x * N[(x * -0.5), $MachinePrecision] + N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\mathsf{fma}\left(x, x \cdot -0.5, -1 - x\right)
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
| Original | 4.0% |
|---|---|
| Target | 99.5% |
| Herbie | 99.3% |
Initial program 3.3%
Simplified100.0%
[Start]3.3% | \[ \frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\] |
|---|---|
sub-neg [=>]3.3% | \[ \frac{\log \color{blue}{\left(1 + \left(-x\right)\right)}}{\log \left(1 + x\right)}
\] |
log1p-def [=>]4.1% | \[ \frac{\color{blue}{\mathsf{log1p}\left(-x\right)}}{\log \left(1 + x\right)}
\] |
log1p-def [=>]100.0% | \[ \frac{\mathsf{log1p}\left(-x\right)}{\color{blue}{\mathsf{log1p}\left(x\right)}}
\] |
Taylor expanded in x around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ \left(-0.5 \cdot {x}^{2} + -1 \cdot x\right) - 1
\] |
|---|---|
associate--l+ [=>]100.0% | \[ \color{blue}{-0.5 \cdot {x}^{2} + \left(-1 \cdot x - 1\right)}
\] |
*-commutative [=>]100.0% | \[ \color{blue}{{x}^{2} \cdot -0.5} + \left(-1 \cdot x - 1\right)
\] |
unpow2 [=>]100.0% | \[ \color{blue}{\left(x \cdot x\right)} \cdot -0.5 + \left(-1 \cdot x - 1\right)
\] |
associate-*l* [=>]100.0% | \[ \color{blue}{x \cdot \left(x \cdot -0.5\right)} + \left(-1 \cdot x - 1\right)
\] |
fma-def [=>]100.0% | \[ \color{blue}{\mathsf{fma}\left(x, x \cdot -0.5, -1 \cdot x - 1\right)}
\] |
sub-neg [=>]100.0% | \[ \mathsf{fma}\left(x, x \cdot -0.5, \color{blue}{-1 \cdot x + \left(-1\right)}\right)
\] |
metadata-eval [=>]100.0% | \[ \mathsf{fma}\left(x, x \cdot -0.5, -1 \cdot x + \color{blue}{-1}\right)
\] |
+-commutative [=>]100.0% | \[ \mathsf{fma}\left(x, x \cdot -0.5, \color{blue}{-1 + -1 \cdot x}\right)
\] |
mul-1-neg [=>]100.0% | \[ \mathsf{fma}\left(x, x \cdot -0.5, -1 + \color{blue}{\left(-x\right)}\right)
\] |
unsub-neg [=>]100.0% | \[ \mathsf{fma}\left(x, x \cdot -0.5, \color{blue}{-1 - x}\right)
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 6848 |
| Alternative 2 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 192 |
| Alternative 3 | |
|---|---|
| Accuracy | 97.8% |
| Cost | 64 |
herbie shell --seed 2023277
(FPCore (x)
:name "qlog (example 3.10)"
:precision binary64
:pre (and (< -1.0 x) (< x 1.0))
:herbie-target
(- (+ (+ (+ 1.0 x) (/ (* x x) 2.0)) (* 0.4166666666666667 (pow x 3.0))))
(/ (log (- 1.0 x)) (log (+ 1.0 x))))