Average Error: 29.8 → 0.1
Time: 3.5s
Precision: 64
\[\log \left(N + 1\right) - \log N\]
\[\begin{array}{l} \mathbf{if}\;N \le 172828.268406431453:\\ \;\;\;\;\log \left(\frac{N + 1}{N}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \frac{0.5}{N}}{N}\\ \end{array}\]
\log \left(N + 1\right) - \log N
\begin{array}{l}
\mathbf{if}\;N \le 172828.268406431453:\\
\;\;\;\;\log \left(\frac{N + 1}{N}\right)\\

\mathbf{else}:\\
\;\;\;\;\frac{1 - \frac{0.5}{N}}{N}\\

\end{array}
double code(double N) {
	return (log((N + 1.0)) - log(N));
}
double code(double N) {
	double VAR;
	if ((N <= 172828.26840643145)) {
		VAR = log(((N + 1.0) / N));
	} else {
		VAR = ((1.0 - (0.5 / N)) / N);
	}
	return VAR;
}

Error

Bits error versus N

Try it out

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation

  1. Split input into 2 regimes
  2. if N < 172828.26840643145

    1. Initial program 0.2

      \[\log \left(N + 1\right) - \log N\]
    2. Using strategy rm
    3. Applied diff-log0.2

      \[\leadsto \color{blue}{\log \left(\frac{N + 1}{N}\right)}\]

    if 172828.26840643145 < N

    1. Initial program 59.8

      \[\log \left(N + 1\right) - \log N\]
    2. Using strategy rm
    3. Applied add-sqr-sqrt60.2

      \[\leadsto \color{blue}{\sqrt{\log \left(N + 1\right)} \cdot \sqrt{\log \left(N + 1\right)}} - \log N\]
    4. Applied fma-neg60.8

      \[\leadsto \color{blue}{\mathsf{fma}\left(\sqrt{\log \left(N + 1\right)}, \sqrt{\log \left(N + 1\right)}, -\log N\right)}\]
    5. Simplified60.8

      \[\leadsto \mathsf{fma}\left(\sqrt{\log \left(N + 1\right)}, \sqrt{\log \left(N + 1\right)}, \color{blue}{\log \left(\frac{1}{N}\right)}\right)\]
    6. Taylor expanded around inf 27.9

      \[\leadsto \color{blue}{\left(1 \cdot \frac{1}{N} + \left({\left(\sqrt{-\log \left(\frac{1}{N}\right)}\right)}^{2} + \log \left(\frac{1}{N}\right)\right)\right) - 0.5 \cdot \frac{1}{{N}^{2}}}\]
    7. Simplified0.1

      \[\leadsto \color{blue}{\frac{1}{N} \cdot \left(1 - \frac{0.5}{N}\right)}\]
    8. Using strategy rm
    9. Applied associate-*l/0.1

      \[\leadsto \color{blue}{\frac{1 \cdot \left(1 - \frac{0.5}{N}\right)}{N}}\]
    10. Simplified0.1

      \[\leadsto \frac{\color{blue}{1 - \frac{0.5}{N}}}{N}\]
  3. Recombined 2 regimes into one program.
  4. Final simplification0.1

    \[\leadsto \begin{array}{l} \mathbf{if}\;N \le 172828.268406431453:\\ \;\;\;\;\log \left(\frac{N + 1}{N}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \frac{0.5}{N}}{N}\\ \end{array}\]

Reproduce

herbie shell --seed 2020102 +o rules:numerics
(FPCore (N)
  :name "2log (problem 3.3.6)"
  :precision binary64
  (- (log (+ N 1)) (log N)))