Average Error: 61.3 → 0.5
Time: 8.0s
Precision: binary64
\[-1 < x \land x < 1\]
\[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)} \]
\[-1 - \mathsf{fma}\left(x, x \cdot 0.5, x\right) \]
(FPCore (x) :precision binary64 (/ (log (- 1.0 x)) (log (+ 1.0 x))))
(FPCore (x) :precision binary64 (- -1.0 (fma x (* x 0.5) x)))
double code(double x) {
	return log((1.0 - x)) / log((1.0 + x));
}
double code(double x) {
	return -1.0 - fma(x, (x * 0.5), x);
}
function code(x)
	return Float64(log(Float64(1.0 - x)) / log(Float64(1.0 + x)))
end
function code(x)
	return Float64(-1.0 - fma(x, Float64(x * 0.5), 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[(-1.0 - N[(x * N[(x * 0.5), $MachinePrecision] + x), $MachinePrecision]), $MachinePrecision]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
-1 - \mathsf{fma}\left(x, x \cdot 0.5, x\right)

Error

Bits error versus x

Target

Original61.3
Target0.4
Herbie0.5
\[-\left(\left(\left(1 + x\right) + \frac{x \cdot x}{2}\right) + 0.4166666666666667 \cdot {x}^{3}\right) \]

Derivation

  1. Initial program 61.3

    \[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)} \]
  2. Simplified0.0

    \[\leadsto \color{blue}{\frac{\mathsf{log1p}\left(-x\right)}{\mathsf{log1p}\left(x\right)}} \]
  3. Taylor expanded in x around 0 0.5

    \[\leadsto \color{blue}{-\left(1 + \left(0.5 \cdot {x}^{2} + x\right)\right)} \]
  4. Simplified0.5

    \[\leadsto \color{blue}{-1 - \mathsf{fma}\left(x, x \cdot 0.5, x\right)} \]
  5. Final simplification0.5

    \[\leadsto -1 - \mathsf{fma}\left(x, x \cdot 0.5, x\right) \]

Reproduce

herbie shell --seed 2022153 
(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))))