Average Error: 61.5 → 0.0
Time: 24.7s
Precision: binary64
Cost: 19908
\[-1 < x \land x < 1\]
\[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)} \]
\[\begin{array}{l} t_0 := \mathsf{log1p}\left(-x\right)\\ \mathbf{if}\;t_0 \ne 0:\\ \;\;\;\;\frac{\frac{1}{\mathsf{log1p}\left(x\right)}}{\frac{1}{t_0}}\\ \mathbf{else}:\\ \;\;\;\;\frac{t_0}{\mathsf{log1p}\left(x\right)}\\ \end{array} \]
(FPCore (x) :precision binary64 (/ (log (- 1.0 x)) (log (+ 1.0 x))))
(FPCore (x)
 :precision binary64
 (let* ((t_0 (log1p (- x))))
   (if (!= t_0 0.0) (/ (/ 1.0 (log1p x)) (/ 1.0 t_0)) (/ t_0 (log1p x)))))
double code(double x) {
	return log((1.0 - x)) / log((1.0 + x));
}
double code(double x) {
	double t_0 = log1p(-x);
	double tmp;
	if (t_0 != 0.0) {
		tmp = (1.0 / log1p(x)) / (1.0 / t_0);
	} else {
		tmp = t_0 / log1p(x);
	}
	return tmp;
}
public static double code(double x) {
	return Math.log((1.0 - x)) / Math.log((1.0 + x));
}
public static double code(double x) {
	double t_0 = Math.log1p(-x);
	double tmp;
	if (t_0 != 0.0) {
		tmp = (1.0 / Math.log1p(x)) / (1.0 / t_0);
	} else {
		tmp = t_0 / Math.log1p(x);
	}
	return tmp;
}
def code(x):
	return math.log((1.0 - x)) / math.log((1.0 + x))
def code(x):
	t_0 = math.log1p(-x)
	tmp = 0
	if t_0 != 0.0:
		tmp = (1.0 / math.log1p(x)) / (1.0 / t_0)
	else:
		tmp = t_0 / math.log1p(x)
	return tmp
function code(x)
	return Float64(log(Float64(1.0 - x)) / log(Float64(1.0 + x)))
end
function code(x)
	t_0 = log1p(Float64(-x))
	tmp = 0.0
	if (t_0 != 0.0)
		tmp = Float64(Float64(1.0 / log1p(x)) / Float64(1.0 / t_0));
	else
		tmp = Float64(t_0 / log1p(x));
	end
	return tmp
end
code[x_] := N[(N[Log[N[(1.0 - x), $MachinePrecision]], $MachinePrecision] / N[Log[N[(1.0 + x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
code[x_] := Block[{t$95$0 = N[Log[1 + (-x)], $MachinePrecision]}, If[Unequal[t$95$0, 0.0], N[(N[(1.0 / N[Log[1 + x], $MachinePrecision]), $MachinePrecision] / N[(1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], N[(t$95$0 / N[Log[1 + x], $MachinePrecision]), $MachinePrecision]]]
\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}
\begin{array}{l}
t_0 := \mathsf{log1p}\left(-x\right)\\
\mathbf{if}\;t_0 \ne 0:\\
\;\;\;\;\frac{\frac{1}{\mathsf{log1p}\left(x\right)}}{\frac{1}{t_0}}\\

\mathbf{else}:\\
\;\;\;\;\frac{t_0}{\mathsf{log1p}\left(x\right)}\\


\end{array}

Error

Target

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

Derivation

  1. Initial program 61.5

    \[\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)} \]
  2. Applied egg-rr0.2

    \[\leadsto \color{blue}{\frac{1}{\mathsf{log1p}\left(x\right)} \cdot \mathsf{log1p}\left(-x\right)} \]
  3. Applied egg-rr0.0

    \[\leadsto \color{blue}{\begin{array}{l} \color{blue}{\mathbf{if}\;\mathsf{log1p}\left(-x\right) \ne 0:\\ \;\;\;\;\frac{\frac{1}{\mathsf{log1p}\left(x\right)}}{\frac{1}{\mathsf{log1p}\left(-x\right)}}\\ \mathbf{else}:\\ \;\;\;\;\frac{\mathsf{log1p}\left(-x\right)}{\mathsf{log1p}\left(x\right)}\\ } \end{array}} \]

Alternatives

Alternative 1
Error0.0
Cost13056
\[\frac{\mathsf{log1p}\left(-x\right)}{\mathsf{log1p}\left(x\right)} \]
Alternative 2
Error0.3
Cost3140
\[\begin{array}{l} t_0 := \left(x \cdot x\right) \cdot \left(-0.4166666666666667 \cdot x + -0.5\right)\\ t_1 := t_0 - x\\ \mathbf{if}\;\left(\left(-0.5 \cdot x\right) \cdot x - x\right) - -1 \ne 0:\\ \;\;\;\;\frac{t_1 \cdot t_1 - 1}{t_1 - -1}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \left(-1 - x\right)\\ \end{array} \]
Alternative 3
Error0.3
Cost3140
\[\begin{array}{l} t_0 := \left(x \cdot x\right) \cdot \left(-0.4166666666666667 \cdot x + -0.5\right)\\ t_1 := t_0 - x\\ t_2 := t_1 - -1\\ \mathbf{if}\;t_2 \ne 0:\\ \;\;\;\;\frac{t_1 \cdot \left(\left(-0.5 \cdot x\right) \cdot x - x\right) - 1}{t_2}\\ \mathbf{else}:\\ \;\;\;\;t_0 + \left(-1 - x\right)\\ \end{array} \]
Alternative 4
Error0.3
Cost1152
\[\left(-1 + \left(x \cdot x\right) \cdot \left(-0.4166666666666667 \cdot x\right)\right) + \left(\left(-x\right) + x \cdot \left(x \cdot -0.5\right)\right) \]
Alternative 5
Error0.3
Cost832
\[\left(x \cdot x\right) \cdot \left(-0.4166666666666667 \cdot x + -0.5\right) - \left(x + 1\right) \]
Alternative 6
Error0.4
Cost576
\[\left(-1 + \left(-0.5 \cdot x\right) \cdot x\right) - x \]
Alternative 7
Error0.4
Cost576
\[\left(x \cdot \left(x \cdot -0.5\right) - x\right) - 1 \]
Alternative 8
Error0.6
Cost192
\[-1 - x \]
Alternative 9
Error1.2
Cost64
\[-1 \]

Error

Reproduce

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