| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 8128 |
\[\begin{array}{l}
t_0 := x \cdot \left(x \cdot -0.5\right)\\
\frac{t_0 \cdot t_0 + \left(-1 - x\right) \cdot \left(x - -1\right)}{x + \mathsf{fma}\left(x, x \cdot -0.5, 1\right)}
\end{array}
\]

(FPCore (x) :precision binary64 (/ (log (- 1.0 x)) (log (+ 1.0 x))))
(FPCore (x) :precision binary64 (/ (log1p (- x)) (log1p x)))
double code(double x) {
return log((1.0 - x)) / log((1.0 + x));
}
double code(double x) {
return log1p(-x) / log1p(x);
}
public static double code(double x) {
return Math.log((1.0 - x)) / Math.log((1.0 + x));
}
public static double code(double x) {
return Math.log1p(-x) / Math.log1p(x);
}
def code(x): return math.log((1.0 - x)) / math.log((1.0 + x))
def code(x): return math.log1p(-x) / math.log1p(x)
function code(x) return Float64(log(Float64(1.0 - x)) / log(Float64(1.0 + x))) end
function code(x) return Float64(log1p(Float64(-x)) / log1p(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[(N[Log[1 + (-x)], $MachinePrecision] / N[Log[1 + x], $MachinePrecision]), $MachinePrecision]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\frac{\mathsf{log1p}\left(-x\right)}{\mathsf{log1p}\left(x\right)}
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 4.4% |
|---|---|
| Target | 99.4% |
| Herbie | 100.0% |
Initial program 5.4%
Simplified100.0%
[Start]5.4 | \[ \frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\] |
|---|---|
sub-neg [=>]5.4 | \[ \frac{\log \color{blue}{\left(1 + \left(-x\right)\right)}}{\log \left(1 + x\right)}
\] |
log1p-def [=>]6.3 | \[ \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)}}
\] |
Final simplification100.0%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 8128 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 1856 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 576 |
| Alternative 4 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 576 |
| Alternative 5 | |
|---|---|
| Accuracy | 98.9% |
| Cost | 192 |
| Alternative 6 | |
|---|---|
| Accuracy | 97.7% |
| Cost | 64 |
herbie shell --seed 2023161
(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))))