2log (problem 3.3.6)

Percentage Accurate: 24.4% → 99.4%
Time: 9.6s
Alternatives: 9
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 9 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.4% 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{1}{N} + \left(\left(\frac{-0.5}{{N}^{2}} + \frac{-0.25}{{N}^{4}}\right) + \frac{0.3333333333333333}{{N}^{3}}\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)
   (+
    (/ 1.0 N)
    (+
     (+ (/ -0.5 (pow N 2.0)) (/ -0.25 (pow N 4.0)))
     (/ 0.3333333333333333 (pow N 3.0))))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 0.0006) {
		tmp = (1.0 / N) + (((-0.5 / pow(N, 2.0)) + (-0.25 / pow(N, 4.0))) + (0.3333333333333333 / pow(N, 3.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 = (1.0d0 / n) + ((((-0.5d0) / (n ** 2.0d0)) + ((-0.25d0) / (n ** 4.0d0))) + (0.3333333333333333d0 / (n ** 3.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 = (1.0 / N) + (((-0.5 / Math.pow(N, 2.0)) + (-0.25 / Math.pow(N, 4.0))) + (0.3333333333333333 / Math.pow(N, 3.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 = (1.0 / N) + (((-0.5 / math.pow(N, 2.0)) + (-0.25 / math.pow(N, 4.0))) + (0.3333333333333333 / math.pow(N, 3.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(1.0 / N) + Float64(Float64(Float64(-0.5 / (N ^ 2.0)) + Float64(-0.25 / (N ^ 4.0))) + Float64(0.3333333333333333 / (N ^ 3.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 = (1.0 / N) + (((-0.5 / (N ^ 2.0)) + (-0.25 / (N ^ 4.0))) + (0.3333333333333333 / (N ^ 3.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[(1.0 / N), $MachinePrecision] + N[(N[(N[(-0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision] + N[(-0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 / N[Power[N, 3.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{1}{N} + \left(\left(\frac{-0.5}{{N}^{2}} + \frac{-0.25}{{N}^{4}}\right) + \frac{0.3333333333333333}{{N}^{3}}\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.5%

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

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

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

      \[\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. +-commutative99.7%

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

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

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

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

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

    1. Initial program 90.2%

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

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

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

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

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt90.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-prod89.8%

        \[\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. pow289.8%

        \[\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-diff89.8%

        \[\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-udef89.8%

        \[\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.0%

        \[\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-log90.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. +-commutative90.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-diff90.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-udef90.5%

        \[\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.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-log90.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-rr90.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-pow90.6%

        \[\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.6%

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

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

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

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

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

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

        \[\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.3%

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

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

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

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

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

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

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

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

Alternative 2: 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(\left(\frac{1}{N} - \frac{0.25}{{N}^{4}}\right) - \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.0006)
   (+
    (/ 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.0006) {
		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.0006d0) 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.0006) {
		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.0006:
		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.0006)
		tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(Float64(1.0 / N) - 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.0006)
		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.0006], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[(1.0 / N), $MachinePrecision] - N[(0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $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.0006:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\left(\frac{1}{N} - \frac{0.25}{{N}^{4}}\right) - \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)) < 5.99999999999999947e-4

    1. Initial program 19.5%

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

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

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

      \[\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. +-commutative99.7%

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

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \color{blue}{\left(0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \frac{1}{N}\right) - \left(0.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)} \]
    11. 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.5 \cdot \frac{1}{{N}^{2}} + 0.25 \cdot \frac{1}{{N}^{4}}\right)\right)} \]
      2. +-commutative99.7%

        \[\leadsto 0.3333333333333333 \cdot \frac{1}{{N}^{3}} + \left(\frac{1}{N} - \color{blue}{\left(0.25 \cdot \frac{1}{{N}^{4}} + 0.5 \cdot \frac{1}{{N}^{2}}\right)}\right) \]
      3. 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) \]
      4. 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) \]
      5. associate--r+99.7%

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

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

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

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

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

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

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

    1. Initial program 90.2%

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

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

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

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

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt90.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-prod89.8%

        \[\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. pow289.8%

        \[\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-diff89.8%

        \[\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-udef89.8%

        \[\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.0%

        \[\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-log90.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. +-commutative90.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-diff90.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-udef90.5%

        \[\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.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-log90.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-rr90.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-pow90.6%

        \[\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.6%

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

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

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

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

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

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

        \[\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.3%

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

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

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

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

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

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

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

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

Alternative 3: 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}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{0.25}{{N}^{4}}\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.0006)
   (+
    (/ 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.0006) {
		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.0006d0) 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.0006) {
		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.0006:
		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.0006)
		tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(1.0 / N) - Float64(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.0006)
		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.0006], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N), $MachinePrecision] - N[(N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.25 / N[Power[N, 4.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.0006:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{0.25}{{N}^{4}}\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.99999999999999947e-4

    1. Initial program 19.5%

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

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

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

      \[\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.99999999999999947e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N))

    1. Initial program 90.2%

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

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

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

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

        \[\leadsto \color{blue}{\log \left(e^{\mathsf{log1p}\left(N\right) - \log N}\right)} \]
      2. add-cube-cbrt90.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-prod89.8%

        \[\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. pow289.8%

        \[\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-diff89.8%

        \[\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-udef89.8%

        \[\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.0%

        \[\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-log90.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. +-commutative90.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-diff90.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-udef90.5%

        \[\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.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-log90.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-rr90.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-pow90.6%

        \[\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.6%

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

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

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

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

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

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

        \[\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.3%

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

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

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

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

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

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

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

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

Alternative 4: 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.0%

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

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

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

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

      \[\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.5%

        \[\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.5%

        \[\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.5%

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

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

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

      \[\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 86.8%

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

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

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

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

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

        \[\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-prod86.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. pow286.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-diff86.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-udef86.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-log86.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.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. +-commutative87.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-diff87.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-udef87.5%

        \[\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-log88.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-log87.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-rr87.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-pow87.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-in87.7%

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

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

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

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

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

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow387.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-cbrt90.4%

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

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

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

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

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

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

      \[\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 5: 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{1}{N} + \left(\frac{-0.5}{{N}^{2}} + \frac{0.3333333333333333}{{N}^{3}}\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)
   (+ (/ 1.0 N) (+ (/ -0.5 (pow N 2.0)) (/ 0.3333333333333333 (pow N 3.0))))
   (- (log (/ N (+ N 1.0))))))
double code(double N) {
	double tmp;
	if ((log((N + 1.0)) - log(N)) <= 0.0001) {
		tmp = (1.0 / N) + ((-0.5 / pow(N, 2.0)) + (0.3333333333333333 / pow(N, 3.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 = (1.0d0 / n) + (((-0.5d0) / (n ** 2.0d0)) + (0.3333333333333333d0 / (n ** 3.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 = (1.0 / N) + ((-0.5 / Math.pow(N, 2.0)) + (0.3333333333333333 / Math.pow(N, 3.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 = (1.0 / N) + ((-0.5 / math.pow(N, 2.0)) + (0.3333333333333333 / math.pow(N, 3.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(1.0 / N) + Float64(Float64(-0.5 / (N ^ 2.0)) + Float64(0.3333333333333333 / (N ^ 3.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 = (1.0 / N) + ((-0.5 / (N ^ 2.0)) + (0.3333333333333333 / (N ^ 3.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[(1.0 / N), $MachinePrecision] + N[(N[(-0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.3333333333333333 / N[Power[N, 3.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{1}{N} + \left(\frac{-0.5}{{N}^{2}} + \frac{0.3333333333333333}{{N}^{3}}\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.0%

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

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

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

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

      \[\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. sub-neg99.5%

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

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

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

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

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

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

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

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

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

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

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

    1. Initial program 86.8%

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

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

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

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

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

        \[\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-prod86.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. pow286.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-diff86.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-udef86.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-log86.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.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. +-commutative87.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-diff87.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-udef87.5%

        \[\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-log88.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-log87.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-rr87.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-pow87.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-in87.7%

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

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

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

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

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

        \[\leadsto \log \color{blue}{\left({\left(\sqrt[3]{\frac{N + 1}{N}}\right)}^{3}\right)} \]
      4. pow387.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-cbrt90.4%

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

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

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

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

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

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

      \[\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{1}{N} + \left(\frac{-0.5}{{N}^{2}} + \frac{0.3333333333333333}{{N}^{3}}\right)\\ \mathbf{else}:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \end{array} \]

Alternative 6: 97.8% accurate, 0.7× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\log \left(N + 1\right) - \log N \leq 5 \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)) 5e-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)) <= 5e-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)) <= 5d-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)) <= 5e-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)) <= 5e-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)) <= 5e-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)) <= 5e-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], 5e-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 5 \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)) < 5.00000000000000041e-6

    1. Initial program 15.2%

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

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

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

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

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

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

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

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

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

    1. Initial program 82.8%

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

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

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

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

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

        \[\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.7%

        \[\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.7%

        \[\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.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-log83.4%

        \[\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. +-commutative83.4%

        \[\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-diff83.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-udef83.5%

        \[\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-log84.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-log83.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-rr83.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-pow83.6%

        \[\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-in83.6%

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

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

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

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

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

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

        \[\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.4%

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

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

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

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

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

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

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

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

Alternative 7: 92.9% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;N \leq 105000000:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{N}\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= N 105000000.0) (- (log (/ N (+ N 1.0)))) (/ 1.0 N)))
double code(double N) {
	double tmp;
	if (N <= 105000000.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 <= 105000000.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 <= 105000000.0) {
		tmp = -Math.log((N / (N + 1.0)));
	} else {
		tmp = 1.0 / N;
	}
	return tmp;
}
def code(N):
	tmp = 0
	if N <= 105000000.0:
		tmp = -math.log((N / (N + 1.0)))
	else:
		tmp = 1.0 / N
	return tmp
function code(N)
	tmp = 0.0
	if (N <= 105000000.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 <= 105000000.0)
		tmp = -log((N / (N + 1.0)));
	else
		tmp = 1.0 / N;
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N, 105000000.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 105000000:\\
\;\;\;\;-\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.05e8

    1. Initial program 73.6%

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

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

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

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

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

        \[\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-prod73.2%

        \[\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. pow273.2%

        \[\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-diff73.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-udef73.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-log73.7%

        \[\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-log74.7%

        \[\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. +-commutative74.7%

        \[\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-diff74.6%

        \[\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-udef74.6%

        \[\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.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-log74.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-rr74.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-pow75.0%

        \[\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-in75.0%

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

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

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

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

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

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

        \[\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-cbrt78.1%

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

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

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

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

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

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

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

    if 1.05e8 < N

    1. Initial program 9.4%

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

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

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

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

      \[\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 105000000:\\ \;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{N}\\ \end{array} \]

Alternative 8: 92.7% accurate, 1.9× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;N \leq 106000000:\\ \;\;\;\;\log \left(\frac{N + 1}{N}\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{1}{N}\\ \end{array} \end{array} \]
(FPCore (N)
 :precision binary64
 (if (<= N 106000000.0) (log (/ (+ N 1.0) N)) (/ 1.0 N)))
double code(double N) {
	double tmp;
	if (N <= 106000000.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 <= 106000000.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 <= 106000000.0) {
		tmp = Math.log(((N + 1.0) / N));
	} else {
		tmp = 1.0 / N;
	}
	return tmp;
}
def code(N):
	tmp = 0
	if N <= 106000000.0:
		tmp = math.log(((N + 1.0) / N))
	else:
		tmp = 1.0 / N
	return tmp
function code(N)
	tmp = 0.0
	if (N <= 106000000.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 <= 106000000.0)
		tmp = log(((N + 1.0) / N));
	else
		tmp = 1.0 / N;
	end
	tmp_2 = tmp;
end
code[N_] := If[LessEqual[N, 106000000.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 106000000:\\
\;\;\;\;\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 < 1.06e8

    1. Initial program 73.2%

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 1.06e8 < N

    1. Initial program 9.1%

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

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

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

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

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

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

Alternative 9: 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.9%

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

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

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

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

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

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

Developer target: 99.3% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;N \geq 1000:\\
\;\;\;\;\left(\left(\frac{1}{N} + \frac{-1}{2 \cdot {N}^{2}}\right) + \frac{1}{3 \cdot {N}^{3}}\right) + \frac{-1}{4 \cdot {N}^{4}}\\

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


\end{array}
\end{array}

Reproduce

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

  :herbie-target
  (if (>= N 1000.0) (+ (+ (+ (/ 1.0 N) (/ -1.0 (* 2.0 (pow N 2.0)))) (/ 1.0 (* 3.0 (pow N 3.0)))) (/ -1.0 (* 4.0 (pow N 4.0)))) (log (+ 1.0 (/ 1.0 N))))

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