# ?

Average Error: 2.2 → 0.2
Time: 9.0s
Precision: binary64
Cost: 19712

# ?

$0.001 \leq x \land x \leq 1$
$\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}$
$\frac{\mathsf{log1p}\left(x \cdot \left(-x\right)\right) - \mathsf{log1p}\left(x\right)}{\mathsf{log1p}\left(x\right)}$
(FPCore (x) :precision binary64 (/ (log (- 1.0 x)) (log (+ 1.0 x))))
(FPCore (x)
:precision binary64
(/ (- (log1p (* x (- x))) (log1p x)) (log1p x)))
double code(double x) {
return log((1.0 - x)) / log((1.0 + x));
}

double code(double x) {
return (log1p((x * -x)) - 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 * -x)) - 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 * -x)) - 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(Float64(log1p(Float64(x * Float64(-x))) - log1p(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[(N[Log[1 + N[(x * (-x)),$MachinePrecision]], $MachinePrecision] - N[Log[1 + x],$MachinePrecision]), $MachinePrecision] / N[Log[1 + x],$MachinePrecision]), \$MachinePrecision]

\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}

\frac{\mathsf{log1p}\left(x \cdot \left(-x\right)\right) - \mathsf{log1p}\left(x\right)}{\mathsf{log1p}\left(x\right)}


# Try it out?

Results

 In Out
Enter valid numbers for all inputs

# Derivation?

1. Initial program 2.2

$\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}$
2. Simplified2.6

$\leadsto \color{blue}{\frac{\log \left(1 - x\right)}{\mathsf{log1p}\left(x\right)}}$
Proof
[Start]2.2 $\frac{\log \left(1 - x\right)}{\log \left(1 + x\right)}$ $\frac{\log \left(1 - x\right)}{\color{blue}{\mathsf{log1p}\left(x\right)}}$
3. Applied egg-rr3.6

$\leadsto \frac{\color{blue}{\left(\log \left(1 - x \cdot x\right) - e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)}\right) + 1}}{\mathsf{log1p}\left(x\right)}$
4. Simplified0.2

$\leadsto \frac{\color{blue}{\mathsf{log1p}\left(x \cdot \left(-x\right)\right) - \mathsf{log1p}\left(x\right)}}{\mathsf{log1p}\left(x\right)}$
Proof
[Start]3.6 $\frac{\left(\log \left(1 - x \cdot x\right) - e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)}\right) + 1}{\mathsf{log1p}\left(x\right)}$ $\frac{\color{blue}{\log \left(1 - x \cdot x\right) - \left(e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)} - 1\right)}}{\mathsf{log1p}\left(x\right)}$ $\frac{\log \color{blue}{\left(1 + \left(-x \cdot x\right)\right)} - \left(e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)} - 1\right)}{\mathsf{log1p}\left(x\right)}$ $\frac{\color{blue}{\mathsf{log1p}\left(-x \cdot x\right)} - \left(e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)} - 1\right)}{\mathsf{log1p}\left(x\right)}$ $\frac{\mathsf{log1p}\left(\color{blue}{x \cdot \left(-x\right)}\right) - \left(e^{\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)} - 1\right)}{\mathsf{log1p}\left(x\right)}$ $\frac{\mathsf{log1p}\left(x \cdot \left(-x\right)\right) - \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\mathsf{log1p}\left(x\right)\right)\right)}}{\mathsf{log1p}\left(x\right)}$ $\frac{\mathsf{log1p}\left(x \cdot \left(-x\right)\right) - \color{blue}{\mathsf{log1p}\left(x\right)}}{\mathsf{log1p}\left(x\right)}$
5. Final simplification0.2

$\leadsto \frac{\mathsf{log1p}\left(x \cdot \left(-x\right)\right) - \mathsf{log1p}\left(x\right)}{\mathsf{log1p}\left(x\right)}$

# Alternatives

Alternative 1
Error0.3
Cost13056
$\frac{\mathsf{log1p}\left(-x\right)}{\mathsf{log1p}\left(x\right)}$
Alternative 2
Error30.7
Cost832
$-1 + \left(\left(x \cdot x\right) \cdot \left(x \cdot -0.4166666666666667 + -0.5\right) - x\right)$
Alternative 3
Error41.3
Cost192
$-1 - x$
Alternative 4
Error47.2
Cost64
$-1$

# Reproduce?

herbie shell --seed 1
(FPCore (x)
:name "log(1 - x) / log(1 + x)"
:precision binary64
:pre (and (<= 0.001 x) (<= x 1.0))
(/ (log (- 1.0 x)) (log (+ 1.0 x))))