2log (problem 3.3.6)

Percentage Accurate: 24.3% → 99.4%
Time: 9.6s
Alternatives: 12
Speedup: 68.3×

Specification

?
\[N > 1 \land N < 10^{+40}\]
\[\begin{array}{l} \\ \log \left(N + 1\right) - \log N \end{array} \]
(FPCore (N) :precision binary64 (- (log (+ N 1.0)) (log N)))
double code(double N) {
	return log((N + 1.0)) - log(N);
}
real(8) function code(n)
    real(8), intent (in) :: n
    code = log((n + 1.0d0)) - log(n)
end function
public static double code(double N) {
	return Math.log((N + 1.0)) - Math.log(N);
}
def code(N):
	return math.log((N + 1.0)) - math.log(N)
function code(N)
	return Float64(log(Float64(N + 1.0)) - log(N))
end
function tmp = code(N)
	tmp = log((N + 1.0)) - log(N);
end
code[N_] := N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\log \left(N + 1\right) - \log N
\end{array}

Sampling outcomes in binary64 precision:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 12 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 24.3% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \log \left(N + 1\right) - \log N \end{array} \]
(FPCore (N) :precision binary64 (- (log (+ N 1.0)) (log N)))
double code(double N) {
	return log((N + 1.0)) - log(N);
}
real(8) function code(n)
    real(8), intent (in) :: n
    code = log((n + 1.0d0)) - log(n)
end function
public static double code(double N) {
	return Math.log((N + 1.0)) - Math.log(N);
}
def code(N):
	return math.log((N + 1.0)) - math.log(N)
function code(N)
	return Float64(log(Float64(N + 1.0)) - log(N))
end
function tmp = code(N)
	tmp = log((N + 1.0)) - log(N);
end
code[N_] := N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\log \left(N + 1\right) - \log N
\end{array}

Alternative 1: 99.4% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0006:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{0.5 + \left(N + \left(\frac{0.25}{N} + \frac{0.125}{{N}^{2}}\right)\right)} - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 0.0006)
   (+
    (/ 0.3333333333333333 (pow N 3.0))
    (-
     (/ 1.0 (+ 0.5 (+ N (+ (/ 0.25 N) (/ 0.125 (pow N 2.0))))))
     (/ 0.25 (pow N 4.0))))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 0.0006) {
		tmp = (0.3333333333333333 / pow(N, 3.0)) + ((1.0 / (0.5 + (N + ((0.25 / N) + (0.125 / pow(N, 2.0)))))) - (0.25 / pow(N, 4.0)));
	} else {
		tmp = -log((N / (N + 1.0)));
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if ((log((n + 1.0d0)) - log(n)) <= 0.0006d0) then
        tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + ((1.0d0 / (0.5d0 + (n + ((0.25d0 / n) + (0.125d0 / (n ** 2.0d0)))))) - (0.25d0 / (n ** 4.0d0)))
    else
        tmp = -log((n / (n + 1.0d0)))
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.0006) {
		tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((1.0 / (0.5 + (N + ((0.25 / N) + (0.125 / Math.pow(N, 2.0)))))) - (0.25 / Math.pow(N, 4.0)));
	} else {
		tmp = -Math.log((N / (N + 1.0)));
	}
	return tmp;
}
def code(N):
	tmp = 0
	if (math.log((N + 1.0)) - math.log(N)) <= 0.0006:
		tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((1.0 / (0.5 + (N + ((0.25 / N) + (0.125 / math.pow(N, 2.0)))))) - (0.25 / math.pow(N, 4.0)))
	else:
		tmp = -math.log((N / (N + 1.0)))
	return tmp
function code(N)
	tmp = 0.0
	if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.0006)
		tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(1.0 / Float64(0.5 + Float64(N + Float64(Float64(0.25 / N) + Float64(0.125 / (N ^ 2.0)))))) - Float64(0.25 / (N ^ 4.0))));
	else
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if ((log((N + 1.0)) - log(N)) <= 0.0006)
		tmp = (0.3333333333333333 / (N ^ 3.0)) + ((1.0 / (0.5 + (N + ((0.25 / N) + (0.125 / (N ^ 2.0)))))) - (0.25 / (N ^ 4.0)));
	else
		tmp = -log((N / (N + 1.0)));
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.0006], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N[(0.5 + N[(N + N[(N[(0.25 / N), $MachinePrecision] + N[(0.125 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0006:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{0.5 + \left(N + \left(\frac{0.25}{N} + \frac{0.125}{{N}^{2}}\right)\right)} - \frac{0.25}{{N}^{4}}\right)\\

\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 5.99999999999999947e-4

    1. Initial program 19.9%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative19.9%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def20.0%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified20.0%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 99.7%

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \frac{1}{N}\right) - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)} \]
    5. Step-by-step derivation
      1. associate--l+99.7%

        \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right)} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot 1}{{N}^{3}}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      3. metadata-eval99.7%

        \[\leadsto \frac{\color{blue}{0.3333333333333333}}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      4. +-commutative99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \color{blue}{\left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)}\right) \]
      5. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      6. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{\color{blue}{0.5}}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      7. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right)\right) \]
      8. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{\color{blue}{0.25}}{{N}^{4}}\right)\right) \]
    6. Simplified99.7%

      \[\leadsto \color{blue}{\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{0.25}{{N}^{4}}\right)\right)} \]
    7. Taylor expanded in N around 0 99.7%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\frac{1}{N} - \left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right)} \]
    8. Step-by-step derivation
      1. associate--r+99.6%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right)} \]
      2. associate-*r/99.6%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      3. metadata-eval99.6%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{\color{blue}{0.5}}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      4. associate-*r/99.6%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right) \]
      5. metadata-eval99.6%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{\color{blue}{0.25}}{{N}^{4}}\right) \]
    9. Simplified99.6%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{0.25}{{N}^{4}}\right)} \]
    10. Step-by-step derivation
      1. frac-sub99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\frac{1 \cdot {N}^{2} - N \cdot 0.5}{N \cdot {N}^{2}}} - \frac{0.25}{{N}^{4}}\right) \]
      2. unpow299.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1 \cdot {N}^{2} - N \cdot 0.5}{N \cdot \color{blue}{\left(N \cdot N\right)}} - \frac{0.25}{{N}^{4}}\right) \]
      3. cube-mult99.3%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1 \cdot {N}^{2} - N \cdot 0.5}{\color{blue}{{N}^{3}}} - \frac{0.25}{{N}^{4}}\right) \]
      4. clear-num99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\frac{1}{\frac{{N}^{3}}{1 \cdot {N}^{2} - N \cdot 0.5}}} - \frac{0.25}{{N}^{4}}\right) \]
      5. *-un-lft-identity99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\frac{{N}^{3}}{\color{blue}{{N}^{2}} - N \cdot 0.5}} - \frac{0.25}{{N}^{4}}\right) \]
      6. unpow299.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\frac{{N}^{3}}{\color{blue}{N \cdot N} - N \cdot 0.5}} - \frac{0.25}{{N}^{4}}\right) \]
      7. distribute-lft-out--99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\frac{{N}^{3}}{\color{blue}{N \cdot \left(N - 0.5\right)}}} - \frac{0.25}{{N}^{4}}\right) \]
    11. Applied egg-rr99.4%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\frac{1}{\frac{{N}^{3}}{N \cdot \left(N - 0.5\right)}}} - \frac{0.25}{{N}^{4}}\right) \]
    12. Taylor expanded in N around inf 99.7%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\color{blue}{0.5 + \left(N + \left(0.125 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{N}\right)\right)}} - \frac{0.25}{{N}^{4}}\right) \]
    13. Step-by-step derivation
      1. +-commutative99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{0.5 + \left(N + \color{blue}{\left(0.25 \cdot \frac{1}{N} + 0.125 \cdot \frac{1}{{N}^{2}}\right)}\right)} - \frac{0.25}{{N}^{4}}\right) \]
      2. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{0.5 + \left(N + \left(\color{blue}{\frac{0.25 \cdot 1}{N}} + 0.125 \cdot \frac{1}{{N}^{2}}\right)\right)} - \frac{0.25}{{N}^{4}}\right) \]
      3. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{0.5 + \left(N + \left(\frac{\color{blue}{0.25}}{N} + 0.125 \cdot \frac{1}{{N}^{2}}\right)\right)} - \frac{0.25}{{N}^{4}}\right) \]
      4. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{0.5 + \left(N + \left(\frac{0.25}{N} + \color{blue}{\frac{0.125 \cdot 1}{{N}^{2}}}\right)\right)} - \frac{0.25}{{N}^{4}}\right) \]
      5. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{0.5 + \left(N + \left(\frac{0.25}{N} + \frac{\color{blue}{0.125}}{{N}^{2}}\right)\right)} - \frac{0.25}{{N}^{4}}\right) \]
    14. Simplified99.7%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\color{blue}{0.5 + \left(N + \left(\frac{0.25}{N} + \frac{0.125}{{N}^{2}}\right)\right)}} - \frac{0.25}{{N}^{4}}\right) \]

    if 5.99999999999999947e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 93.3%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative93.3%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def93.3%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified93.3%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp92.6%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt91.7%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod91.5%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow291.5%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log91.5%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative91.5%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff91.7%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef91.7%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log91.3%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log91.5%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr91.5%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow91.1%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in91.1%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval91.1%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified91.1%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp91.2%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative91.2%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow91.5%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow391.7%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt94.2%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num94.1%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div96.3%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval96.3%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr96.3%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub096.3%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified96.3%

      \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0006:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{0.5 + \left(N + \left(\frac{0.25}{N} + \frac{0.125}{{N}^{2}}\right)\right)} - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Alternative 2: 99.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(N \cdot \left({N}^{-3} \cdot \left(N + -0.5\right)\right) - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 0.0005)
   (+
    (/ 0.3333333333333333 (pow N 3.0))
    (- (* N (* (pow N -3.0) (+ N -0.5))) (/ 0.25 (pow N 4.0))))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 0.0005) {
		tmp = (0.3333333333333333 / pow(N, 3.0)) + ((N * (pow(N, -3.0) * (N + -0.5))) - (0.25 / pow(N, 4.0)));
	} else {
		tmp = -log((N / (N + 1.0)));
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if ((log((n + 1.0d0)) - log(n)) <= 0.0005d0) then
        tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + ((n * ((n ** (-3.0d0)) * (n + (-0.5d0)))) - (0.25d0 / (n ** 4.0d0)))
    else
        tmp = -log((n / (n + 1.0d0)))
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.0005) {
		tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((N * (Math.pow(N, -3.0) * (N + -0.5))) - (0.25 / Math.pow(N, 4.0)));
	} else {
		tmp = -Math.log((N / (N + 1.0)));
	}
	return tmp;
}
def code(N):
	tmp = 0
	if (math.log((N + 1.0)) - math.log(N)) <= 0.0005:
		tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((N * (math.pow(N, -3.0) * (N + -0.5))) - (0.25 / math.pow(N, 4.0)))
	else:
		tmp = -math.log((N / (N + 1.0)))
	return tmp
function code(N)
	tmp = 0.0
	if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.0005)
		tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(N * Float64((N ^ -3.0) * Float64(N + -0.5))) - Float64(0.25 / (N ^ 4.0))));
	else
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if ((log((N + 1.0)) - log(N)) <= 0.0005)
		tmp = (0.3333333333333333 / (N ^ 3.0)) + ((N * ((N ^ -3.0) * (N + -0.5))) - (0.25 / (N ^ 4.0)));
	else
		tmp = -log((N / (N + 1.0)));
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.0005], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N * N[(N[Power[N, -3.0], $MachinePrecision] * N[(N + -0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(N \cdot \left({N}^{-3} \cdot \left(N + -0.5\right)\right) - \frac{0.25}{{N}^{4}}\right)\\

\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 5.0000000000000001e-4

    1. Initial program 19.7%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative19.7%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def19.7%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified19.7%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 99.7%

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \frac{1}{N}\right) - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)} \]
    5. Step-by-step derivation
      1. associate--l+99.7%

        \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right)} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot 1}{{N}^{3}}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      3. metadata-eval99.7%

        \[\leadsto \frac{\color{blue}{0.3333333333333333}}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      4. +-commutative99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \color{blue}{\left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)}\right) \]
      5. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      6. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{\color{blue}{0.5}}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      7. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right)\right) \]
      8. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{\color{blue}{0.25}}{{N}^{4}}\right)\right) \]
    6. Simplified99.7%

      \[\leadsto \color{blue}{\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{0.25}{{N}^{4}}\right)\right)} \]
    7. Taylor expanded in N around 0 99.7%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\frac{1}{N} - \left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right)} \]
    8. Step-by-step derivation
      1. associate--r+99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right)} \]
      2. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      3. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{\color{blue}{0.5}}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      4. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right) \]
      5. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{\color{blue}{0.25}}{{N}^{4}}\right) \]
    9. Simplified99.7%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{0.25}{{N}^{4}}\right)} \]
    10. Step-by-step derivation
      1. frac-sub99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\frac{1 \cdot {N}^{2} - N \cdot 0.5}{N \cdot {N}^{2}}} - \frac{0.25}{{N}^{4}}\right) \]
      2. unpow299.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1 \cdot {N}^{2} - N \cdot 0.5}{N \cdot \color{blue}{\left(N \cdot N\right)}} - \frac{0.25}{{N}^{4}}\right) \]
      3. cube-mult99.3%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1 \cdot {N}^{2} - N \cdot 0.5}{\color{blue}{{N}^{3}}} - \frac{0.25}{{N}^{4}}\right) \]
      4. div-inv99.2%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\left(1 \cdot {N}^{2} - N \cdot 0.5\right) \cdot \frac{1}{{N}^{3}}} - \frac{0.25}{{N}^{4}}\right) \]
      5. *-un-lft-identity99.2%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\color{blue}{{N}^{2}} - N \cdot 0.5\right) \cdot \frac{1}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right) \]
      6. unpow299.2%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\color{blue}{N \cdot N} - N \cdot 0.5\right) \cdot \frac{1}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right) \]
      7. distribute-lft-out--99.3%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\left(N \cdot \left(N - 0.5\right)\right)} \cdot \frac{1}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right) \]
      8. pow-flip99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(N \cdot \left(N - 0.5\right)\right) \cdot \color{blue}{{N}^{\left(-3\right)}} - \frac{0.25}{{N}^{4}}\right) \]
      9. metadata-eval99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(N \cdot \left(N - 0.5\right)\right) \cdot {N}^{\color{blue}{-3}} - \frac{0.25}{{N}^{4}}\right) \]
    11. Applied egg-rr99.4%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\left(N \cdot \left(N - 0.5\right)\right) \cdot {N}^{-3}} - \frac{0.25}{{N}^{4}}\right) \]
    12. Step-by-step derivation
      1. associate-*l*99.3%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{N \cdot \left(\left(N - 0.5\right) \cdot {N}^{-3}\right)} - \frac{0.25}{{N}^{4}}\right) \]
      2. sub-neg99.3%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(N \cdot \left(\color{blue}{\left(N + \left(-0.5\right)\right)} \cdot {N}^{-3}\right) - \frac{0.25}{{N}^{4}}\right) \]
      3. metadata-eval99.3%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(N \cdot \left(\left(N + \color{blue}{-0.5}\right) \cdot {N}^{-3}\right) - \frac{0.25}{{N}^{4}}\right) \]
    13. Simplified99.3%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{N \cdot \left(\left(N + -0.5\right) \cdot {N}^{-3}\right)} - \frac{0.25}{{N}^{4}}\right) \]

    if 5.0000000000000001e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 92.4%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative92.4%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def92.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified92.4%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp91.8%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt90.9%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod90.7%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow290.7%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log90.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr91.0%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow90.8%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in90.8%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval90.8%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified90.8%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp90.7%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative90.7%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow90.9%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow391.1%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt93.5%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num93.4%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div95.8%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval95.8%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr95.8%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub095.8%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified95.8%

      \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(N \cdot \left({N}^{-3} \cdot \left(N + -0.5\right)\right) - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Alternative 3: 99.0% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\left(N \cdot \left(N - 0.5\right)\right) \cdot {N}^{-3} - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 0.0005)
   (+
    (/ 0.3333333333333333 (pow N 3.0))
    (- (* (* N (- N 0.5)) (pow N -3.0)) (/ 0.25 (pow N 4.0))))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 0.0005) {
		tmp = (0.3333333333333333 / pow(N, 3.0)) + (((N * (N - 0.5)) * pow(N, -3.0)) - (0.25 / pow(N, 4.0)));
	} else {
		tmp = -log((N / (N + 1.0)));
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if ((log((n + 1.0d0)) - log(n)) <= 0.0005d0) then
        tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + (((n * (n - 0.5d0)) * (n ** (-3.0d0))) - (0.25d0 / (n ** 4.0d0)))
    else
        tmp = -log((n / (n + 1.0d0)))
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.0005) {
		tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + (((N * (N - 0.5)) * Math.pow(N, -3.0)) - (0.25 / Math.pow(N, 4.0)));
	} else {
		tmp = -Math.log((N / (N + 1.0)));
	}
	return tmp;
}
def code(N):
	tmp = 0
	if (math.log((N + 1.0)) - math.log(N)) <= 0.0005:
		tmp = (0.3333333333333333 / math.pow(N, 3.0)) + (((N * (N - 0.5)) * math.pow(N, -3.0)) - (0.25 / math.pow(N, 4.0)))
	else:
		tmp = -math.log((N / (N + 1.0)))
	return tmp
function code(N)
	tmp = 0.0
	if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.0005)
		tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(Float64(N * Float64(N - 0.5)) * (N ^ -3.0)) - Float64(0.25 / (N ^ 4.0))));
	else
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if ((log((N + 1.0)) - log(N)) <= 0.0005)
		tmp = (0.3333333333333333 / (N ^ 3.0)) + (((N * (N - 0.5)) * (N ^ -3.0)) - (0.25 / (N ^ 4.0)));
	else
		tmp = -log((N / (N + 1.0)));
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.0005], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(N * N[(N - 0.5), $MachinePrecision]), $MachinePrecision] * N[Power[N, -3.0], $MachinePrecision]), $MachinePrecision] - N[(0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\left(N \cdot \left(N - 0.5\right)\right) \cdot {N}^{-3} - \frac{0.25}{{N}^{4}}\right)\\

\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 5.0000000000000001e-4

    1. Initial program 19.7%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative19.7%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def19.7%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified19.7%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 99.7%

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \frac{1}{N}\right) - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)} \]
    5. Step-by-step derivation
      1. associate--l+99.7%

        \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right)} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot 1}{{N}^{3}}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      3. metadata-eval99.7%

        \[\leadsto \frac{\color{blue}{0.3333333333333333}}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      4. +-commutative99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \color{blue}{\left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)}\right) \]
      5. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      6. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{\color{blue}{0.5}}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      7. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right)\right) \]
      8. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{\color{blue}{0.25}}{{N}^{4}}\right)\right) \]
    6. Simplified99.7%

      \[\leadsto \color{blue}{\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{0.25}{{N}^{4}}\right)\right)} \]
    7. Taylor expanded in N around 0 99.7%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\frac{1}{N} - \left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right)} \]
    8. Step-by-step derivation
      1. associate--r+99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right)} \]
      2. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      3. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{\color{blue}{0.5}}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      4. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right) \]
      5. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{\color{blue}{0.25}}{{N}^{4}}\right) \]
    9. Simplified99.7%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{0.25}{{N}^{4}}\right)} \]
    10. Step-by-step derivation
      1. frac-sub99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\frac{1 \cdot {N}^{2} - N \cdot 0.5}{N \cdot {N}^{2}}} - \frac{0.25}{{N}^{4}}\right) \]
      2. unpow299.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1 \cdot {N}^{2} - N \cdot 0.5}{N \cdot \color{blue}{\left(N \cdot N\right)}} - \frac{0.25}{{N}^{4}}\right) \]
      3. cube-mult99.3%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1 \cdot {N}^{2} - N \cdot 0.5}{\color{blue}{{N}^{3}}} - \frac{0.25}{{N}^{4}}\right) \]
      4. div-inv99.2%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\left(1 \cdot {N}^{2} - N \cdot 0.5\right) \cdot \frac{1}{{N}^{3}}} - \frac{0.25}{{N}^{4}}\right) \]
      5. *-un-lft-identity99.2%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\color{blue}{{N}^{2}} - N \cdot 0.5\right) \cdot \frac{1}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right) \]
      6. unpow299.2%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\color{blue}{N \cdot N} - N \cdot 0.5\right) \cdot \frac{1}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right) \]
      7. distribute-lft-out--99.3%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\left(N \cdot \left(N - 0.5\right)\right)} \cdot \frac{1}{{N}^{3}} - \frac{0.25}{{N}^{4}}\right) \]
      8. pow-flip99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(N \cdot \left(N - 0.5\right)\right) \cdot \color{blue}{{N}^{\left(-3\right)}} - \frac{0.25}{{N}^{4}}\right) \]
      9. metadata-eval99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(N \cdot \left(N - 0.5\right)\right) \cdot {N}^{\color{blue}{-3}} - \frac{0.25}{{N}^{4}}\right) \]
    11. Applied egg-rr99.4%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\left(N \cdot \left(N - 0.5\right)\right) \cdot {N}^{-3}} - \frac{0.25}{{N}^{4}}\right) \]

    if 5.0000000000000001e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 92.4%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative92.4%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def92.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified92.4%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp91.8%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt90.9%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod90.7%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow290.7%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log90.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr91.0%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow90.8%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in90.8%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval90.8%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified90.8%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp90.7%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative90.7%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow90.9%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow391.1%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt93.5%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num93.4%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div95.8%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval95.8%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr95.8%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub095.8%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified95.8%

      \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.2%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\left(N \cdot \left(N - 0.5\right)\right) \cdot {N}^{-3} - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Alternative 4: 99.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 0.0005)
   (+
    (/ 0.3333333333333333 (pow N 3.0))
    (- (- (/ 1.0 N) (/ 0.5 (pow N 2.0))) (/ 0.25 (pow N 4.0))))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 0.0005) {
		tmp = (0.3333333333333333 / pow(N, 3.0)) + (((1.0 / N) - (0.5 / pow(N, 2.0))) - (0.25 / pow(N, 4.0)));
	} else {
		tmp = -log((N / (N + 1.0)));
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if ((log((n + 1.0d0)) - log(n)) <= 0.0005d0) then
        tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + (((1.0d0 / n) - (0.5d0 / (n ** 2.0d0))) - (0.25d0 / (n ** 4.0d0)))
    else
        tmp = -log((n / (n + 1.0d0)))
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.0005) {
		tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + (((1.0 / N) - (0.5 / Math.pow(N, 2.0))) - (0.25 / Math.pow(N, 4.0)));
	} else {
		tmp = -Math.log((N / (N + 1.0)));
	}
	return tmp;
}
def code(N):
	tmp = 0
	if (math.log((N + 1.0)) - math.log(N)) <= 0.0005:
		tmp = (0.3333333333333333 / math.pow(N, 3.0)) + (((1.0 / N) - (0.5 / math.pow(N, 2.0))) - (0.25 / math.pow(N, 4.0)))
	else:
		tmp = -math.log((N / (N + 1.0)))
	return tmp
function code(N)
	tmp = 0.0
	if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.0005)
		tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(Float64(1.0 / N) - Float64(0.5 / (N ^ 2.0))) - Float64(0.25 / (N ^ 4.0))));
	else
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if ((log((N + 1.0)) - log(N)) <= 0.0005)
		tmp = (0.3333333333333333 / (N ^ 3.0)) + (((1.0 / N) - (0.5 / (N ^ 2.0))) - (0.25 / (N ^ 4.0)));
	else
		tmp = -log((N / (N + 1.0)));
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.0005], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1.0 / N), $MachinePrecision] - N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{0.25}{{N}^{4}}\right)\\

\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 5.0000000000000001e-4

    1. Initial program 19.7%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative19.7%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def19.7%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified19.7%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 99.7%

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \frac{1}{N}\right) - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)} \]
    5. Step-by-step derivation
      1. associate--l+99.7%

        \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right)} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot 1}{{N}^{3}}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      3. metadata-eval99.7%

        \[\leadsto \frac{\color{blue}{0.3333333333333333}}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      4. +-commutative99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \color{blue}{\left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)}\right) \]
      5. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      6. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{\color{blue}{0.5}}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      7. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right)\right) \]
      8. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{\color{blue}{0.25}}{{N}^{4}}\right)\right) \]
    6. Simplified99.7%

      \[\leadsto \color{blue}{\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{0.25}{{N}^{4}}\right)\right)} \]
    7. Taylor expanded in N around 0 99.7%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\frac{1}{N} - \left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right)} \]
    8. Step-by-step derivation
      1. associate--r+99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right)} \]
      2. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      3. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{\color{blue}{0.5}}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      4. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right) \]
      5. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{\color{blue}{0.25}}{{N}^{4}}\right) \]
    9. Simplified99.7%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{0.25}{{N}^{4}}\right)} \]

    if 5.0000000000000001e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 92.4%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative92.4%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def92.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified92.4%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp91.8%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt90.9%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod90.7%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow290.7%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log90.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr91.0%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow90.8%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in90.8%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval90.8%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified90.8%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp90.7%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative90.7%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow90.9%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow391.1%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt93.5%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num93.4%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div95.8%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval95.8%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr95.8%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub095.8%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified95.8%

      \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Alternative 5: 99.3% accurate, 0.4× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.25}{{N}^{4}} + \frac{0.5}{{N}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 0.0005)
   (+
    (/ 0.3333333333333333 (pow N 3.0))
    (- (/ 1.0 N) (+ (/ 0.25 (pow N 4.0)) (/ 0.5 (pow N 2.0)))))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 0.0005) {
		tmp = (0.3333333333333333 / pow(N, 3.0)) + ((1.0 / N) - ((0.25 / pow(N, 4.0)) + (0.5 / pow(N, 2.0))));
	} else {
		tmp = -log((N / (N + 1.0)));
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if ((log((n + 1.0d0)) - log(n)) <= 0.0005d0) then
        tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + ((1.0d0 / n) - ((0.25d0 / (n ** 4.0d0)) + (0.5d0 / (n ** 2.0d0))))
    else
        tmp = -log((n / (n + 1.0d0)))
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.0005) {
		tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((1.0 / N) - ((0.25 / Math.pow(N, 4.0)) + (0.5 / Math.pow(N, 2.0))));
	} else {
		tmp = -Math.log((N / (N + 1.0)));
	}
	return tmp;
}
def code(N):
	tmp = 0
	if (math.log((N + 1.0)) - math.log(N)) <= 0.0005:
		tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((1.0 / N) - ((0.25 / math.pow(N, 4.0)) + (0.5 / math.pow(N, 2.0))))
	else:
		tmp = -math.log((N / (N + 1.0)))
	return tmp
function code(N)
	tmp = 0.0
	if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.0005)
		tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(1.0 / N) - Float64(Float64(0.25 / (N ^ 4.0)) + Float64(0.5 / (N ^ 2.0)))));
	else
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if ((log((N + 1.0)) - log(N)) <= 0.0005)
		tmp = (0.3333333333333333 / (N ^ 3.0)) + ((1.0 / N) - ((0.25 / (N ^ 4.0)) + (0.5 / (N ^ 2.0))));
	else
		tmp = -log((N / (N + 1.0)));
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.0005], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N), $MachinePrecision] - N[(N[(0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.25}{{N}^{4}} + \frac{0.5}{{N}^{2}}\right)\right)\\

\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 5.0000000000000001e-4

    1. Initial program 19.7%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative19.7%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def19.7%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified19.7%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 99.7%

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \frac{1}{N}\right) - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)} \]
    5. Step-by-step derivation
      1. associate--l+99.7%

        \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right)} \]
      2. associate-*r/99.7%

        \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot 1}{{N}^{3}}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      3. metadata-eval99.7%

        \[\leadsto \frac{\color{blue}{0.3333333333333333}}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      4. +-commutative99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \color{blue}{\left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)}\right) \]
      5. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      6. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{\color{blue}{0.5}}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      7. associate-*r/99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right)\right) \]
      8. metadata-eval99.7%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{\color{blue}{0.25}}{{N}^{4}}\right)\right) \]
    6. Simplified99.7%

      \[\leadsto \color{blue}{\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{0.25}{{N}^{4}}\right)\right)} \]

    if 5.0000000000000001e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 92.4%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative92.4%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def92.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified92.4%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp91.8%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt90.9%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod90.7%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow290.7%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log90.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef91.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log90.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log91.0%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr91.0%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow90.8%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in90.8%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval90.8%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified90.8%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp90.7%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative90.7%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow90.9%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow391.1%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt93.5%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num93.4%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div95.8%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval95.8%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr95.8%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub095.8%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified95.8%

      \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.5%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.25}{{N}^{4}} + \frac{0.5}{{N}^{2}}\right)\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Alternative 6: 99.0% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.00015:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N + \left(0.5 + \frac{0.25}{N}\right)} - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 0.00015)
   (+
    (/ 0.3333333333333333 (pow N 3.0))
    (- (/ 1.0 (+ N (+ 0.5 (/ 0.25 N)))) (/ 0.25 (pow N 4.0))))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 0.00015) {
		tmp = (0.3333333333333333 / pow(N, 3.0)) + ((1.0 / (N + (0.5 + (0.25 / N)))) - (0.25 / pow(N, 4.0)));
	} else {
		tmp = -log((N / (N + 1.0)));
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if ((log((n + 1.0d0)) - log(n)) <= 0.00015d0) then
        tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + ((1.0d0 / (n + (0.5d0 + (0.25d0 / n)))) - (0.25d0 / (n ** 4.0d0)))
    else
        tmp = -log((n / (n + 1.0d0)))
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.00015) {
		tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((1.0 / (N + (0.5 + (0.25 / N)))) - (0.25 / Math.pow(N, 4.0)));
	} else {
		tmp = -Math.log((N / (N + 1.0)));
	}
	return tmp;
}
def code(N):
	tmp = 0
	if (math.log((N + 1.0)) - math.log(N)) <= 0.00015:
		tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((1.0 / (N + (0.5 + (0.25 / N)))) - (0.25 / math.pow(N, 4.0)))
	else:
		tmp = -math.log((N / (N + 1.0)))
	return tmp
function code(N)
	tmp = 0.0
	if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.00015)
		tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(1.0 / Float64(N + Float64(0.5 + Float64(0.25 / N)))) - Float64(0.25 / (N ^ 4.0))));
	else
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if ((log((N + 1.0)) - log(N)) <= 0.00015)
		tmp = (0.3333333333333333 / (N ^ 3.0)) + ((1.0 / (N + (0.5 + (0.25 / N)))) - (0.25 / (N ^ 4.0)));
	else
		tmp = -log((N / (N + 1.0)));
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.00015], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N[(N + N[(0.5 + N[(0.25 / N), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.00015:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N + \left(0.5 + \frac{0.25}{N}\right)} - \frac{0.25}{{N}^{4}}\right)\\

\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 1.49999999999999987e-4

    1. Initial program 18.4%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative18.4%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def18.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified18.4%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 99.8%

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \frac{1}{N}\right) - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)} \]
    5. Step-by-step derivation
      1. associate--l+99.8%

        \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right)} \]
      2. associate-*r/99.8%

        \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot 1}{{N}^{3}}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      3. metadata-eval99.8%

        \[\leadsto \frac{\color{blue}{0.3333333333333333}}{{N}^{3}} + \left(\frac{1}{N} - \left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)\right) \]
      4. +-commutative99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \color{blue}{\left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)}\right) \]
      5. associate-*r/99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      6. metadata-eval99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{\color{blue}{0.5}}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right) \]
      7. associate-*r/99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right)\right) \]
      8. metadata-eval99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{\color{blue}{0.25}}{{N}^{4}}\right)\right) \]
    6. Simplified99.8%

      \[\leadsto \color{blue}{\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{0.25}{{N}^{4}}\right)\right)} \]
    7. Taylor expanded in N around 0 99.8%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\frac{1}{N} - \left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right)} \]
    8. Step-by-step derivation
      1. associate--r+99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right)} \]
      2. associate-*r/99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      3. metadata-eval99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{\color{blue}{0.5}}{{N}^{2}}\right) - 0.25 \cdot \frac{1}{{N}^{4}}\right) \]
      4. associate-*r/99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \color{blue}{\frac{0.25 \cdot 1}{{N}^{4}}}\right) \]
      5. metadata-eval99.8%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{\color{blue}{0.25}}{{N}^{4}}\right) \]
    9. Simplified99.8%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \color{blue}{\left(\left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right) - \frac{0.25}{{N}^{4}}\right)} \]
    10. Step-by-step derivation
      1. frac-sub99.5%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\frac{1 \cdot {N}^{2} - N \cdot 0.5}{N \cdot {N}^{2}}} - \frac{0.25}{{N}^{4}}\right) \]
      2. unpow299.5%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1 \cdot {N}^{2} - N \cdot 0.5}{N \cdot \color{blue}{\left(N \cdot N\right)}} - \frac{0.25}{{N}^{4}}\right) \]
      3. cube-mult99.5%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1 \cdot {N}^{2} - N \cdot 0.5}{\color{blue}{{N}^{3}}} - \frac{0.25}{{N}^{4}}\right) \]
      4. clear-num99.6%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\frac{1}{\frac{{N}^{3}}{1 \cdot {N}^{2} - N \cdot 0.5}}} - \frac{0.25}{{N}^{4}}\right) \]
      5. *-un-lft-identity99.6%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\frac{{N}^{3}}{\color{blue}{{N}^{2}} - N \cdot 0.5}} - \frac{0.25}{{N}^{4}}\right) \]
      6. unpow299.6%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\frac{{N}^{3}}{\color{blue}{N \cdot N} - N \cdot 0.5}} - \frac{0.25}{{N}^{4}}\right) \]
      7. distribute-lft-out--99.6%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\frac{{N}^{3}}{\color{blue}{N \cdot \left(N - 0.5\right)}}} - \frac{0.25}{{N}^{4}}\right) \]
    11. Applied egg-rr99.6%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\color{blue}{\frac{1}{\frac{{N}^{3}}{N \cdot \left(N - 0.5\right)}}} - \frac{0.25}{{N}^{4}}\right) \]
    12. Taylor expanded in N around inf 99.5%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\color{blue}{0.5 + \left(N + 0.25 \cdot \frac{1}{N}\right)}} - \frac{0.25}{{N}^{4}}\right) \]
    13. Step-by-step derivation
      1. associate-+r+99.5%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\color{blue}{\left(0.5 + N\right) + 0.25 \cdot \frac{1}{N}}} - \frac{0.25}{{N}^{4}}\right) \]
      2. +-commutative99.5%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\color{blue}{\left(N + 0.5\right)} + 0.25 \cdot \frac{1}{N}} - \frac{0.25}{{N}^{4}}\right) \]
      3. associate-+l+99.5%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\color{blue}{N + \left(0.5 + 0.25 \cdot \frac{1}{N}\right)}} - \frac{0.25}{{N}^{4}}\right) \]
      4. associate-*r/99.5%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N + \left(0.5 + \color{blue}{\frac{0.25 \cdot 1}{N}}\right)} - \frac{0.25}{{N}^{4}}\right) \]
      5. metadata-eval99.5%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N + \left(0.5 + \frac{\color{blue}{0.25}}{N}\right)} - \frac{0.25}{{N}^{4}}\right) \]
    14. Simplified99.5%

      \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{\color{blue}{N + \left(0.5 + \frac{0.25}{N}\right)}} - \frac{0.25}{{N}^{4}}\right) \]

    if 1.49999999999999987e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 89.1%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative89.1%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def89.1%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified89.1%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp88.5%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt87.9%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod87.6%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow287.6%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff87.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef87.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log87.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log87.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative87.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff87.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef87.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log87.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log87.6%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr87.6%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow87.5%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in87.5%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval87.5%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified87.5%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp87.4%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative87.4%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow87.6%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow387.7%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt90.7%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num90.7%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div93.0%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval93.0%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr93.0%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub093.0%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified93.0%

      \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.0%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.00015:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N + \left(0.5 + \frac{0.25}{N}\right)} - \frac{0.25}{{N}^{4}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Alternative 7: 98.9% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0001:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 0.0001)
   (+ (/ 0.3333333333333333 (pow N 3.0)) (- (/ 1.0 N) (/ 0.5 (pow N 2.0))))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 0.0001) {
		tmp = (0.3333333333333333 / pow(N, 3.0)) + ((1.0 / N) - (0.5 / pow(N, 2.0)));
	} else {
		tmp = -log((N / (N + 1.0)));
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if ((log((n + 1.0d0)) - log(n)) <= 0.0001d0) then
        tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + ((1.0d0 / n) - (0.5d0 / (n ** 2.0d0)))
    else
        tmp = -log((n / (n + 1.0d0)))
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.0001) {
		tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((1.0 / N) - (0.5 / Math.pow(N, 2.0)));
	} else {
		tmp = -Math.log((N / (N + 1.0)));
	}
	return tmp;
}
def code(N):
	tmp = 0
	if (math.log((N + 1.0)) - math.log(N)) <= 0.0001:
		tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((1.0 / N) - (0.5 / math.pow(N, 2.0)))
	else:
		tmp = -math.log((N / (N + 1.0)))
	return tmp
function code(N)
	tmp = 0.0
	if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.0001)
		tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(1.0 / N) - Float64(0.5 / (N ^ 2.0))));
	else
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if ((log((N + 1.0)) - log(N)) <= 0.0001)
		tmp = (0.3333333333333333 / (N ^ 3.0)) + ((1.0 / N) - (0.5 / (N ^ 2.0)));
	else
		tmp = -log((N / (N + 1.0)));
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.0001], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N), $MachinePrecision] - N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0001:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right)\\

\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 1.00000000000000005e-4

    1. Initial program 18.2%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative18.2%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def18.2%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified18.2%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 99.4%

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \frac{1}{N}\right) - 0.5 \cdot \frac{1}{{N}^{2}}} \]
    5. Step-by-step derivation
      1. associate--l+99.4%

        \[\leadsto \color{blue}{0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \left(\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}\right)} \]
      2. associate-*r/99.4%

        \[\leadsto \color{blue}{\frac{0.3333333333333333 \cdot 1}{{N}^{3}}} + \left(\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}\right) \]
      3. metadata-eval99.4%

        \[\leadsto \frac{\color{blue}{0.3333333333333333}}{{N}^{3}} + \left(\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}\right) \]
      4. associate-*r/99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}}\right) \]
      5. metadata-eval99.4%

        \[\leadsto \frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \frac{\color{blue}{0.5}}{{N}^{2}}\right) \]
    6. Simplified99.4%

      \[\leadsto \color{blue}{\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right)} \]

    if 1.00000000000000005e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 88.5%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative88.5%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def88.5%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified88.5%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp87.9%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt87.3%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod87.0%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow287.0%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff86.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef86.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log87.6%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log87.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative87.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff87.3%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef87.3%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log87.6%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log87.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr87.2%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow87.1%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in87.1%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval87.1%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified87.1%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp87.0%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative87.0%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow87.2%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow387.2%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt90.3%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num90.3%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div92.5%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval92.5%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr92.5%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub092.5%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified92.5%

      \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification98.9%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0001:\\ \;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \frac{0.5}{{N}^{2}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Alternative 8: 97.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 2 \cdot 10^{-6}:\\ \;\;\;\;\frac{1}{N} - \frac{0.5}{{N}^{2}}\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= (- (log (+ N 1.0)) (log N)) 2e-6)
   (- (/ 1.0 N) (/ 0.5 (pow N 2.0)))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 2e-6) {
		tmp = (1.0 / N) - (0.5 / pow(N, 2.0));
	} else {
		tmp = -log((N / (N + 1.0)));
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if ((log((n + 1.0d0)) - log(n)) <= 2d-6) then
        tmp = (1.0d0 / n) - (0.5d0 / (n ** 2.0d0))
    else
        tmp = -log((n / (n + 1.0d0)))
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if ((Math.log((N + 1.0)) - Math.log(N)) <= 2e-6) {
		tmp = (1.0 / N) - (0.5 / Math.pow(N, 2.0));
	} else {
		tmp = -Math.log((N / (N + 1.0)));
	}
	return tmp;
}
def code(N):
	tmp = 0
	if (math.log((N + 1.0)) - math.log(N)) <= 2e-6:
		tmp = (1.0 / N) - (0.5 / math.pow(N, 2.0))
	else:
		tmp = -math.log((N / (N + 1.0)))
	return tmp
function code(N)
	tmp = 0.0
	if (Float64(log(Float64(N + 1.0)) - log(N)) <= 2e-6)
		tmp = Float64(Float64(1.0 / N) - Float64(0.5 / (N ^ 2.0)));
	else
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if ((log((N + 1.0)) - log(N)) <= 2e-6)
		tmp = (1.0 / N) - (0.5 / (N ^ 2.0));
	else
		tmp = -log((N / (N + 1.0)));
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 2e-6], N[(N[(1.0 / N), $MachinePrecision] - N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision])]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 2 \cdot 10^{-6}:\\
\;\;\;\;\frac{1}{N} - \frac{0.5}{{N}^{2}}\\

\mathbf{else}:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 1.99999999999999991e-6

    1. Initial program 14.9%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative14.9%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def14.9%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified14.9%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 99.1%

      \[\leadsto \color{blue}{\frac{1}{N} - 0.5 \cdot \frac{1}{{N}^{2}}} \]
    5. Step-by-step derivation
      1. associate-*r/99.1%

        \[\leadsto \frac{1}{N} - \color{blue}{\frac{0.5 \cdot 1}{{N}^{2}}} \]
      2. metadata-eval99.1%

        \[\leadsto \frac{1}{N} - \frac{\color{blue}{0.5}}{{N}^{2}} \]
    6. Simplified99.1%

      \[\leadsto \color{blue}{\frac{1}{N} - \frac{0.5}{{N}^{2}}} \]

    if 1.99999999999999991e-6 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 83.0%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative83.0%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def83.0%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified83.0%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp82.7%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt82.1%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod82.5%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow282.5%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff82.3%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef82.3%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log82.5%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log82.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative82.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff82.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef82.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log83.1%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log82.3%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr82.3%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow82.7%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in82.7%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval82.7%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified82.7%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp82.4%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative82.4%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow82.5%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow382.3%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt86.1%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num86.0%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div87.2%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval87.2%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr87.2%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub087.2%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified87.2%

      \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 2 \cdot 10^{-6}:\\ \;\;\;\;\frac{1}{N} - \frac{0.5}{{N}^{2}}\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Alternative 9: 93.1% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;N \leq 130000000:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{N}\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= N 130000000.0) (- (log (/ N (+ N 1.0)))) (/ 1.0 N)))
double code(double N) {
	double tmp;
	if (N <= 130000000.0) {
		tmp = -log((N / (N + 1.0)));
	} else {
		tmp = 1.0 / N;
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if (n <= 130000000.0d0) then
        tmp = -log((n / (n + 1.0d0)))
    else
        tmp = 1.0d0 / n
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if (N <= 130000000.0) {
		tmp = -Math.log((N / (N + 1.0)));
	} else {
		tmp = 1.0 / N;
	}
	return tmp;
}
def code(N):
	tmp = 0
	if N <= 130000000.0:
		tmp = -math.log((N / (N + 1.0)))
	else:
		tmp = 1.0 / N
	return tmp
function code(N)
	tmp = 0.0
	if (N <= 130000000.0)
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	else
		tmp = Float64(1.0 / N);
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if (N <= 130000000.0)
		tmp = -log((N / (N + 1.0)));
	else
		tmp = 1.0 / N;
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N, 130000000.0], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), N[(1.0 / N), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;N \leq 130000000:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if N < 1.3e8

    1. Initial program 75.6%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative75.6%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def75.6%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified75.6%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp75.5%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt75.1%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod75.4%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow275.4%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff75.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef75.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log75.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log75.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative75.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff75.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef75.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log75.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log75.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr75.9%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow76.1%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in76.1%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval76.1%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified76.1%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp75.9%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative75.9%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow75.9%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow375.8%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt79.1%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num79.0%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div80.2%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval80.2%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr80.2%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub080.2%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified80.2%

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

    if 1.3e8 < N

    1. Initial program 10.4%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative10.4%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def10.4%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified10.4%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 95.6%

      \[\leadsto \color{blue}{\frac{1}{N}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification92.5%

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

Alternative 10: 97.6% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;N \leq 200000:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(N + -0.5\right) \cdot {N}^{-2}\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= N 200000.0) (- (log (/ N (+ N 1.0)))) (* (+ N -0.5) (pow N -2.0))))
double code(double N) {
	double tmp;
	if (N <= 200000.0) {
		tmp = -log((N / (N + 1.0)));
	} else {
		tmp = (N + -0.5) * pow(N, -2.0);
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if (n <= 200000.0d0) then
        tmp = -log((n / (n + 1.0d0)))
    else
        tmp = (n + (-0.5d0)) * (n ** (-2.0d0))
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if (N <= 200000.0) {
		tmp = -Math.log((N / (N + 1.0)));
	} else {
		tmp = (N + -0.5) * Math.pow(N, -2.0);
	}
	return tmp;
}
def code(N):
	tmp = 0
	if N <= 200000.0:
		tmp = -math.log((N / (N + 1.0)))
	else:
		tmp = (N + -0.5) * math.pow(N, -2.0)
	return tmp
function code(N)
	tmp = 0.0
	if (N <= 200000.0)
		tmp = Float64(-log(Float64(N / Float64(N + 1.0))));
	else
		tmp = Float64(Float64(N + -0.5) * (N ^ -2.0));
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if (N <= 200000.0)
		tmp = -log((N / (N + 1.0)));
	else
		tmp = (N + -0.5) * (N ^ -2.0);
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N, 200000.0], (-N[Log[N[(N / N[(N + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), N[(N[(N + -0.5), $MachinePrecision] * N[Power[N, -2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;N \leq 200000:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\

\mathbf{else}:\\
\;\;\;\;\left(N + -0.5\right) \cdot {N}^{-2}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if N < 2e5

    1. Initial program 83.0%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative83.0%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def83.0%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified83.0%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp82.7%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt82.1%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod82.5%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow282.5%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff82.3%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef82.3%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log82.5%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log82.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative82.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff82.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef82.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log83.1%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log82.3%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr82.3%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow82.7%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in82.7%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval82.7%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified82.7%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Step-by-step derivation
      1. add-log-exp82.4%

        \[\leadsto \color{blue}{\log \left(e^{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)}\right)} \]
      2. *-commutative82.4%

        \[\leadsto \log \left(e^{\color{blue}{\log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \cdot 3}}\right) \]
      3. exp-to-pow82.5%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow382.3%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{\frac{N + 1}{N}} \cdot \sqrt[3]{\frac{N + 1}{N}}\right) \cdot \sqrt[3]{\frac{N + 1}{N}}\right)} \]
      5. add-cube-cbrt86.1%

        \[\leadsto \log \color{blue}{\left(\frac{N + 1}{N}\right)} \]
      6. clear-num86.0%

        \[\leadsto \log \color{blue}{\left(\frac{1}{\frac{N}{N + 1}}\right)} \]
      7. log-div87.2%

        \[\leadsto \color{blue}{\log 1 - \log \left(\frac{N}{N + 1}\right)} \]
      8. metadata-eval87.2%

        \[\leadsto \color{blue}{0} - \log \left(\frac{N}{N + 1}\right) \]
    9. Applied egg-rr87.2%

      \[\leadsto \color{blue}{0 - \log \left(\frac{N}{N + 1}\right)} \]
    10. Step-by-step derivation
      1. neg-sub087.2%

        \[\leadsto \color{blue}{-\log \left(\frac{N}{N + 1}\right)} \]
    11. Simplified87.2%

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

    if 2e5 < N

    1. Initial program 14.9%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative14.9%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def14.9%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified14.9%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp14.9%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt14.9%

        \[\leadsto \log \color{blue}{\left(\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      3. log-prod14.9%

        \[\leadsto \color{blue}{\log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}} \cdot \sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)} \]
      4. pow214.9%

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right)}^{2}\right)} + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      5. exp-diff14.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      6. log1p-udef14.9%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      7. rem-exp-log16.2%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      8. add-exp-log15.5%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      9. +-commutative15.5%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{\color{blue}{N + 1}}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{e^{\mathsf{log1p}\left(N\right) - \log N}}\right) \]
      10. exp-diff15.5%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\color{blue}{\frac{e^{\mathsf{log1p}\left(N\right)}}{e^{\log N}}}}\right) \]
      11. log1p-udef15.4%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{e^{\log N}}}\right) \]
      12. rem-exp-log16.8%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{\color{blue}{1 + N}}{e^{\log N}}}\right) \]
      13. add-exp-log15.7%

        \[\leadsto \log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{1 + N}{\color{blue}{N}}}\right) \]
    5. Applied egg-rr15.7%

      \[\leadsto \color{blue}{\log \left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{2}\right) + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    6. Step-by-step derivation
      1. log-pow15.7%

        \[\leadsto \color{blue}{2 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} + \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
      2. distribute-lft1-in15.7%

        \[\leadsto \color{blue}{\left(2 + 1\right) \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
      3. metadata-eval15.7%

        \[\leadsto \color{blue}{3} \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right) \]
    7. Simplified15.7%

      \[\leadsto \color{blue}{3 \cdot \log \left(\sqrt[3]{\frac{N + 1}{N}}\right)} \]
    8. Taylor expanded in N around inf 98.7%

      \[\leadsto 3 \cdot \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{N} - 0.16666666666666666 \cdot \frac{1}{{N}^{2}}\right)} \]
    9. Step-by-step derivation
      1. associate-*r/98.6%

        \[\leadsto 3 \cdot \left(\color{blue}{\frac{0.3333333333333333 \cdot 1}{N}} - 0.16666666666666666 \cdot \frac{1}{{N}^{2}}\right) \]
      2. metadata-eval98.6%

        \[\leadsto 3 \cdot \left(\frac{\color{blue}{0.3333333333333333}}{N} - 0.16666666666666666 \cdot \frac{1}{{N}^{2}}\right) \]
      3. associate-*r/98.6%

        \[\leadsto 3 \cdot \left(\frac{0.3333333333333333}{N} - \color{blue}{\frac{0.16666666666666666 \cdot 1}{{N}^{2}}}\right) \]
      4. metadata-eval98.6%

        \[\leadsto 3 \cdot \left(\frac{0.3333333333333333}{N} - \frac{\color{blue}{0.16666666666666666}}{{N}^{2}}\right) \]
    10. Simplified98.6%

      \[\leadsto 3 \cdot \color{blue}{\left(\frac{0.3333333333333333}{N} - \frac{0.16666666666666666}{{N}^{2}}\right)} \]
    11. Step-by-step derivation
      1. clear-num98.5%

        \[\leadsto 3 \cdot \left(\color{blue}{\frac{1}{\frac{N}{0.3333333333333333}}} - \frac{0.16666666666666666}{{N}^{2}}\right) \]
      2. frac-sub98.5%

        \[\leadsto 3 \cdot \color{blue}{\frac{1 \cdot {N}^{2} - \frac{N}{0.3333333333333333} \cdot 0.16666666666666666}{\frac{N}{0.3333333333333333} \cdot {N}^{2}}} \]
      3. *-un-lft-identity98.5%

        \[\leadsto 3 \cdot \frac{\color{blue}{{N}^{2}} - \frac{N}{0.3333333333333333} \cdot 0.16666666666666666}{\frac{N}{0.3333333333333333} \cdot {N}^{2}} \]
      4. div-inv98.5%

        \[\leadsto 3 \cdot \frac{{N}^{2} - \color{blue}{\left(N \cdot \frac{1}{0.3333333333333333}\right)} \cdot 0.16666666666666666}{\frac{N}{0.3333333333333333} \cdot {N}^{2}} \]
      5. metadata-eval98.5%

        \[\leadsto 3 \cdot \frac{{N}^{2} - \left(N \cdot \color{blue}{3}\right) \cdot 0.16666666666666666}{\frac{N}{0.3333333333333333} \cdot {N}^{2}} \]
      6. div-inv98.6%

        \[\leadsto 3 \cdot \frac{{N}^{2} - \left(N \cdot 3\right) \cdot 0.16666666666666666}{\color{blue}{\left(N \cdot \frac{1}{0.3333333333333333}\right)} \cdot {N}^{2}} \]
      7. metadata-eval98.6%

        \[\leadsto 3 \cdot \frac{{N}^{2} - \left(N \cdot 3\right) \cdot 0.16666666666666666}{\left(N \cdot \color{blue}{3}\right) \cdot {N}^{2}} \]
    12. Applied egg-rr98.6%

      \[\leadsto 3 \cdot \color{blue}{\frac{{N}^{2} - \left(N \cdot 3\right) \cdot 0.16666666666666666}{\left(N \cdot 3\right) \cdot {N}^{2}}} \]
    13. Step-by-step derivation
      1. unpow298.6%

        \[\leadsto 3 \cdot \frac{\color{blue}{N \cdot N} - \left(N \cdot 3\right) \cdot 0.16666666666666666}{\left(N \cdot 3\right) \cdot {N}^{2}} \]
      2. associate-*l*98.6%

        \[\leadsto 3 \cdot \frac{N \cdot N - \color{blue}{N \cdot \left(3 \cdot 0.16666666666666666\right)}}{\left(N \cdot 3\right) \cdot {N}^{2}} \]
      3. metadata-eval98.6%

        \[\leadsto 3 \cdot \frac{N \cdot N - N \cdot \color{blue}{0.5}}{\left(N \cdot 3\right) \cdot {N}^{2}} \]
      4. distribute-lft-out--98.6%

        \[\leadsto 3 \cdot \frac{\color{blue}{N \cdot \left(N - 0.5\right)}}{\left(N \cdot 3\right) \cdot {N}^{2}} \]
      5. sub-neg98.6%

        \[\leadsto 3 \cdot \frac{N \cdot \color{blue}{\left(N + \left(-0.5\right)\right)}}{\left(N \cdot 3\right) \cdot {N}^{2}} \]
      6. metadata-eval98.6%

        \[\leadsto 3 \cdot \frac{N \cdot \left(N + \color{blue}{-0.5}\right)}{\left(N \cdot 3\right) \cdot {N}^{2}} \]
      7. *-commutative98.6%

        \[\leadsto 3 \cdot \frac{N \cdot \left(N + -0.5\right)}{\color{blue}{\left(3 \cdot N\right)} \cdot {N}^{2}} \]
      8. associate-*r*98.5%

        \[\leadsto 3 \cdot \frac{N \cdot \left(N + -0.5\right)}{\color{blue}{3 \cdot \left(N \cdot {N}^{2}\right)}} \]
      9. unpow298.5%

        \[\leadsto 3 \cdot \frac{N \cdot \left(N + -0.5\right)}{3 \cdot \left(N \cdot \color{blue}{\left(N \cdot N\right)}\right)} \]
      10. cube-mult98.5%

        \[\leadsto 3 \cdot \frac{N \cdot \left(N + -0.5\right)}{3 \cdot \color{blue}{{N}^{3}}} \]
    14. Simplified98.5%

      \[\leadsto 3 \cdot \color{blue}{\frac{N \cdot \left(N + -0.5\right)}{3 \cdot {N}^{3}}} \]
    15. Step-by-step derivation
      1. expm1-log1p-u98.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(3 \cdot \frac{N \cdot \left(N + -0.5\right)}{3 \cdot {N}^{3}}\right)\right)} \]
      2. expm1-udef17.1%

        \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(3 \cdot \frac{N \cdot \left(N + -0.5\right)}{3 \cdot {N}^{3}}\right)} - 1} \]
      3. associate-*r/17.1%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{3 \cdot \left(N \cdot \left(N + -0.5\right)\right)}{3 \cdot {N}^{3}}}\right)} - 1 \]
      4. times-frac17.1%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{3}{3} \cdot \frac{N \cdot \left(N + -0.5\right)}{{N}^{3}}}\right)} - 1 \]
      5. metadata-eval17.1%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{1} \cdot \frac{N \cdot \left(N + -0.5\right)}{{N}^{3}}\right)} - 1 \]
      6. metadata-eval17.1%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{1}{1}} \cdot \frac{N \cdot \left(N + -0.5\right)}{{N}^{3}}\right)} - 1 \]
      7. times-frac17.1%

        \[\leadsto e^{\mathsf{log1p}\left(\color{blue}{\frac{1 \cdot \left(N \cdot \left(N + -0.5\right)\right)}{1 \cdot {N}^{3}}}\right)} - 1 \]
      8. *-un-lft-identity17.1%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{\color{blue}{N \cdot \left(N + -0.5\right)}}{1 \cdot {N}^{3}}\right)} - 1 \]
      9. *-un-lft-identity17.1%

        \[\leadsto e^{\mathsf{log1p}\left(\frac{N \cdot \left(N + -0.5\right)}{\color{blue}{{N}^{3}}}\right)} - 1 \]
    16. Applied egg-rr17.1%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{N \cdot \left(N + -0.5\right)}{{N}^{3}}\right)} - 1} \]
    17. Step-by-step derivation
      1. expm1-def98.7%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{N \cdot \left(N + -0.5\right)}{{N}^{3}}\right)\right)} \]
      2. expm1-log1p98.7%

        \[\leadsto \color{blue}{\frac{N \cdot \left(N + -0.5\right)}{{N}^{3}}} \]
      3. *-commutative98.7%

        \[\leadsto \frac{\color{blue}{\left(N + -0.5\right) \cdot N}}{{N}^{3}} \]
      4. associate-*r/98.7%

        \[\leadsto \color{blue}{\left(N + -0.5\right) \cdot \frac{N}{{N}^{3}}} \]
      5. cube-mult98.6%

        \[\leadsto \left(N + -0.5\right) \cdot \frac{N}{\color{blue}{N \cdot \left(N \cdot N\right)}} \]
      6. unpow298.6%

        \[\leadsto \left(N + -0.5\right) \cdot \frac{N}{N \cdot \color{blue}{{N}^{2}}} \]
      7. associate-/r*98.7%

        \[\leadsto \left(N + -0.5\right) \cdot \color{blue}{\frac{\frac{N}{N}}{{N}^{2}}} \]
      8. *-inverses98.7%

        \[\leadsto \left(N + -0.5\right) \cdot \frac{\color{blue}{1}}{{N}^{2}} \]
      9. unpow298.7%

        \[\leadsto \left(N + -0.5\right) \cdot \frac{1}{\color{blue}{N \cdot N}} \]
      10. associate-/r*99.0%

        \[\leadsto \left(N + -0.5\right) \cdot \color{blue}{\frac{\frac{1}{N}}{N}} \]
      11. *-rgt-identity99.0%

        \[\leadsto \left(N + -0.5\right) \cdot \frac{\color{blue}{\frac{1}{N} \cdot 1}}{N} \]
      12. associate-*r/98.7%

        \[\leadsto \left(N + -0.5\right) \cdot \color{blue}{\left(\frac{1}{N} \cdot \frac{1}{N}\right)} \]
      13. unpow-198.7%

        \[\leadsto \left(N + -0.5\right) \cdot \left(\color{blue}{{N}^{-1}} \cdot \frac{1}{N}\right) \]
      14. metadata-eval98.7%

        \[\leadsto \left(N + -0.5\right) \cdot \left({N}^{\color{blue}{\left(\frac{-2}{2}\right)}} \cdot \frac{1}{N}\right) \]
      15. unpow-198.7%

        \[\leadsto \left(N + -0.5\right) \cdot \left({N}^{\left(\frac{-2}{2}\right)} \cdot \color{blue}{{N}^{-1}}\right) \]
      16. metadata-eval98.7%

        \[\leadsto \left(N + -0.5\right) \cdot \left({N}^{\left(\frac{-2}{2}\right)} \cdot {N}^{\color{blue}{\left(\frac{-2}{2}\right)}}\right) \]
      17. sqr-pow98.9%

        \[\leadsto \left(N + -0.5\right) \cdot \color{blue}{{N}^{-2}} \]
    18. Simplified98.9%

      \[\leadsto \color{blue}{\left(N + -0.5\right) \cdot {N}^{-2}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification97.4%

    \[\leadsto \begin{array}{l} \mathbf{if}\;N \leq 200000:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\left(N + -0.5\right) \cdot {N}^{-2}\\ \end{array} \]

Alternative 11: 92.8% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;N \leq 98000000:\\ \;\;\;\;\log \left(\frac{N + 1}{N}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{N}\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= N 98000000.0) (log (/ (+ N 1.0) N)) (/ 1.0 N)))
double code(double N) {
	double tmp;
	if (N <= 98000000.0) {
		tmp = log(((N + 1.0) / N));
	} else {
		tmp = 1.0 / N;
	}
	return tmp;
}
real(8) function code(n)
    real(8), intent (in) :: n
    real(8) :: tmp
    if (n <= 98000000.0d0) then
        tmp = log(((n + 1.0d0) / n))
    else
        tmp = 1.0d0 / n
    end if
    code = tmp
end function
public static double code(double N) {
	double tmp;
	if (N <= 98000000.0) {
		tmp = Math.log(((N + 1.0) / N));
	} else {
		tmp = 1.0 / N;
	}
	return tmp;
}
def code(N):
	tmp = 0
	if N <= 98000000.0:
		tmp = math.log(((N + 1.0) / N))
	else:
		tmp = 1.0 / N
	return tmp
function code(N)
	tmp = 0.0
	if (N <= 98000000.0)
		tmp = log(Float64(Float64(N + 1.0) / N));
	else
		tmp = Float64(1.0 / N);
	end
	return tmp
end
function tmp_2 = code(N)
	tmp = 0.0;
	if (N <= 98000000.0)
		tmp = log(((N + 1.0) / N));
	else
		tmp = 1.0 / N;
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N, 98000000.0], N[Log[N[(N[(N + 1.0), $MachinePrecision] / N), $MachinePrecision]], $MachinePrecision], N[(1.0 / N), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;N \leq 98000000:\\
\;\;\;\;\log \left(\frac{N + 1}{N}\right)\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if N < 9.8e7

    1. Initial program 76.0%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative76.0%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def76.0%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified76.0%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Step-by-step derivation
      1. add-log-exp76.0%

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right)}\right)} - \log N \]
      2. log1p-expm1-u76.0%

        \[\leadsto \log \left(e^{\mathsf{log1p}\left(N\right)}\right) - \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log N\right)\right)} \]
      3. log1p-udef75.9%

        \[\leadsto \log \left(e^{\mathsf{log1p}\left(N\right)}\right) - \color{blue}{\log \left(1 + \mathsf{expm1}\left(\log N\right)\right)} \]
      4. diff-log75.8%

        \[\leadsto \color{blue}{\log \left(\frac{e^{\mathsf{log1p}\left(N\right)}}{1 + \mathsf{expm1}\left(\log N\right)}\right)} \]
      5. log1p-udef75.8%

        \[\leadsto \log \left(\frac{e^{\color{blue}{\log \left(1 + N\right)}}}{1 + \mathsf{expm1}\left(\log N\right)}\right) \]
      6. rem-exp-log75.2%

        \[\leadsto \log \left(\frac{\color{blue}{1 + N}}{1 + \mathsf{expm1}\left(\log N\right)}\right) \]
      7. +-commutative75.2%

        \[\leadsto \log \left(\frac{\color{blue}{N + 1}}{1 + \mathsf{expm1}\left(\log N\right)}\right) \]
      8. add-exp-log75.3%

        \[\leadsto \log \left(\frac{N + 1}{\color{blue}{e^{\log \left(1 + \mathsf{expm1}\left(\log N\right)\right)}}}\right) \]
      9. log1p-udef75.4%

        \[\leadsto \log \left(\frac{N + 1}{e^{\color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\log N\right)\right)}}}\right) \]
      10. log1p-expm1-u75.4%

        \[\leadsto \log \left(\frac{N + 1}{e^{\color{blue}{\log N}}}\right) \]
      11. add-exp-log79.5%

        \[\leadsto \log \left(\frac{N + 1}{\color{blue}{N}}\right) \]
    5. Applied egg-rr79.5%

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

    if 9.8e7 < N

    1. Initial program 10.6%

      \[\log \left(N + 1\right) - \log N \]
    2. Step-by-step derivation
      1. +-commutative10.6%

        \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
      2. log1p-def10.7%

        \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
    3. Simplified10.7%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
    4. Taylor expanded in N around inf 95.4%

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

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

Alternative 12: 84.0% accurate, 68.3× speedup?

\[\begin{array}{l} \\ \frac{1}{N} \end{array} \]
(FPCore (N) :precision binary64 (/ 1.0 N))
double code(double N) {
	return 1.0 / N;
}
real(8) function code(n)
    real(8), intent (in) :: n
    code = 1.0d0 / n
end function
public static double code(double N) {
	return 1.0 / N;
}
def code(N):
	return 1.0 / N
function code(N)
	return Float64(1.0 / N)
end
function tmp = code(N)
	tmp = 1.0 / N;
end
code[N_] := N[(1.0 / N), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{N}
\end{array}
Derivation
  1. Initial program 23.4%

    \[\log \left(N + 1\right) - \log N \]
  2. Step-by-step derivation
    1. +-commutative23.4%

      \[\leadsto \log \color{blue}{\left(1 + N\right)} - \log N \]
    2. log1p-def23.4%

      \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right)} - \log N \]
  3. Simplified23.4%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]
  4. Taylor expanded in N around inf 85.1%

    \[\leadsto \color{blue}{\frac{1}{N}} \]
  5. Final simplification85.1%

    \[\leadsto \frac{1}{N} \]

Developer target: 99.8% accurate, 2.0× speedup?

\[\begin{array}{l} \\ \mathsf{log1p}\left(\frac{1}{N}\right) \end{array} \]
(FPCore (N) :precision binary64 (log1p (/ 1.0 N)))
double code(double N) {
	return log1p((1.0 / N));
}
public static double code(double N) {
	return Math.log1p((1.0 / N));
}
def code(N):
	return math.log1p((1.0 / N))
function code(N)
	return log1p(Float64(1.0 / N))
end
code[N_] := N[Log[1 + N[(1.0 / N), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}

\\
\mathsf{log1p}\left(\frac{1}{N}\right)
\end{array}

Reproduce

?
herbie shell --seed 2024024 
(FPCore (N)
  :name "2log (problem 3.3.6)"
  :precision binary64
  :pre (and (> N 1.0) (< N 1e+40))

  :herbie-target
  (log1p (/ 1.0 N))

  (- (log (+ N 1.0)) (log N)))