# ?

Average Error: 3.1 → 0.2
Time: 7.7s
Precision: binary64
Cost: 6592

# ?

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

double code(double x) {
return log1p((1.0 / x));
}

public static double code(double x) {
return Math.log((x + 1.0)) - Math.log(x);
}

public static double code(double x) {
return Math.log1p((1.0 / x));
}

def code(x):
return math.log((x + 1.0)) - math.log(x)

def code(x):
return math.log1p((1.0 / x))

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

function code(x)
return log1p(Float64(1.0 / x))
end

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

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

\log \left(x + 1\right) - \log x

\mathsf{log1p}\left(\frac{1}{x}\right)


# Try it out?

Results

 In Out
Enter valid numbers for all inputs

# Derivation?

1. Initial program 3.1

$\log \left(x + 1\right) - \log x$
2. Applied egg-rr2.2

$\leadsto \color{blue}{\log \left(\frac{x + 1}{x}\right)}$
3. Applied egg-rr2.3

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

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

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

# Alternatives

Alternative 1
Error41.9
Cost6724
$\begin{array}{l} \mathbf{if}\;x \leq 0.9:\\ \;\;\;\;x - \log x\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \frac{-0.5}{x \cdot x}\\ \end{array}$
Alternative 2
Error2.2
Cost6720
$\log \left(1 + \frac{1}{x}\right)$
Alternative 3
Error43.7
Cost6660
$\begin{array}{l} \mathbf{if}\;x \leq 0.68:\\ \;\;\;\;-\log x\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \frac{-0.5}{x \cdot x}\\ \end{array}$
Alternative 4
Error45.7
Cost708
$\begin{array}{l} \mathbf{if}\;x \leq 0.85:\\ \;\;\;\;\frac{1}{x}\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{x} + \frac{-0.5}{x \cdot x}\\ \end{array}$
Alternative 5
Error49.0
Cost192
$\frac{1}{x}$

# Reproduce?

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