# ?

Average Error: 2.9 → 0.2
Time: 12.0s
Precision: binary64
Cost: 13056

# ?

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

double code(double x) {
return log1p(-x) - log1p(x);
}

public static double code(double x) {
return Math.log(((1.0 - x) / (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) / (1.0 + x)))

def code(x):
return math.log1p(-x) - math.log1p(x)

function code(x)
return log(Float64(Float64(1.0 - x) / Float64(1.0 + x)))
end

function code(x)
return Float64(log1p(Float64(-x)) - log1p(x))
end

code[x_] := N[Log[N[(N[(1.0 - x), $MachinePrecision] / N[(1.0 + x),$MachinePrecision]), $MachinePrecision]],$MachinePrecision]

code[x_] := N[(N[Log[1 + (-x)], $MachinePrecision] - N[Log[1 + x],$MachinePrecision]), \$MachinePrecision]

\log \left(\frac{1 - x}{1 + x}\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.9

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

$\leadsto \color{blue}{\mathsf{log1p}\left(-x\right) - \mathsf{log1p}\left(x\right)}$
Proof
[Start]2.9 $\log \left(\frac{1 - x}{1 + x}\right)$ $\color{blue}{\log \left(1 - x\right) - \log \left(1 + x\right)}$ $\log \color{blue}{\left(1 + \left(-x\right)\right)} - \log \left(1 + x\right)$ $\color{blue}{\mathsf{log1p}\left(-x\right)} - \log \left(1 + x\right)$ $\mathsf{log1p}\left(-x\right) - \color{blue}{\mathsf{log1p}\left(x\right)}$
3. Final simplification0.2

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

# Alternatives

Alternative 1
Error2.9
Cost6848
$\log \left(\frac{1 - x}{x + 1}\right)$
Alternative 2
Error41.1
Cost192
$x \cdot -2$
Alternative 3
Error62.0
Cost64
$0$

# Reproduce?

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