logs (example 3.8)

Percentage Accurate: 1.6% → 100.0%
Time: 5.7s
Alternatives: 2
Speedup: 213.0×

Specification

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

\\
\left(\left(n + 1\right) \cdot \log \left(n + 1\right) - n \cdot \log n\right) - 1
\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 2 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: 1.6% accurate, 1.0× speedup?

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

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

Alternative 1: 100.0% accurate, 2.1× speedup?

\[\begin{array}{l} \\ \log n \end{array} \]
(FPCore (n) :precision binary64 (log n))
double code(double n) {
	return log(n);
}
real(8) function code(n)
    real(8), intent (in) :: n
    code = log(n)
end function
public static double code(double n) {
	return Math.log(n);
}
def code(n):
	return math.log(n)
function code(n)
	return log(n)
end
function tmp = code(n)
	tmp = log(n);
end
code[n_] := N[Log[n], $MachinePrecision]
\begin{array}{l}

\\
\log n
\end{array}
Derivation
  1. Initial program 1.6%

    \[\left(\left(n + 1\right) \cdot \log \left(n + 1\right) - n \cdot \log n\right) - 1 \]
  2. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \left(\left(n + 1\right) \cdot \log \left(n + 1\right) + \left(\mathsf{neg}\left(n \cdot \log n\right)\right)\right) - 1 \]
    2. associate--l+N/A

      \[\leadsto \left(n + 1\right) \cdot \log \left(n + 1\right) + \color{blue}{\left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right)} \]
    3. +-commutativeN/A

      \[\leadsto \left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right) + \color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)} \]
    4. cancel-sign-subN/A

      \[\leadsto \left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right) - \color{blue}{\left(\mathsf{neg}\left(\left(n + 1\right)\right)\right) \cdot \log \left(n + 1\right)} \]
    5. distribute-lft-neg-inN/A

      \[\leadsto \left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right) - \left(\mathsf{neg}\left(\left(n + 1\right) \cdot \log \left(n + 1\right)\right)\right) \]
    6. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right), \color{blue}{\left(\mathsf{neg}\left(\left(n + 1\right) \cdot \log \left(n + 1\right)\right)\right)}\right) \]
    7. sub-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) + \left(\mathsf{neg}\left(1\right)\right)\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)}\right)\right)\right) \]
    8. +-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\left(\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(n \cdot \log n\right)\right)\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)}\right)\right)\right) \]
    9. unsub-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\left(\left(\mathsf{neg}\left(1\right)\right) - n \cdot \log n\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)}\right)\right)\right) \]
    10. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(\left(\mathsf{neg}\left(1\right)\right), \left(n \cdot \log n\right)\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)}\right)\right)\right) \]
    11. metadata-evalN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \left(n \cdot \log n\right)\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right)} \cdot \log \left(n + 1\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \log n\right)\right), \left(\mathsf{neg}\left(\left(n + 1\right) \cdot \color{blue}{\log \left(n + 1\right)}\right)\right)\right) \]
    13. log-lowering-log.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \left(\mathsf{neg}\left(\left(n + 1\right) \cdot \log \left(n + 1\right)\right)\right)\right) \]
    14. *-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \left(\mathsf{neg}\left(\log \left(n + 1\right) \cdot \left(n + 1\right)\right)\right)\right) \]
    15. distribute-rgt-neg-inN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \left(\log \left(n + 1\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\left(n + 1\right)\right)\right)}\right)\right) \]
    16. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\log \left(n + 1\right), \color{blue}{\left(\mathsf{neg}\left(\left(n + 1\right)\right)\right)}\right)\right) \]
    17. +-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\log \left(1 + n\right), \left(\mathsf{neg}\left(\left(\color{blue}{n} + 1\right)\right)\right)\right)\right) \]
    18. accelerator-lowering-log1p.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\mathsf{log1p.f64}\left(n\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right)}\right)\right)\right)\right) \]
    19. +-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\mathsf{log1p.f64}\left(n\right), \left(\mathsf{neg}\left(\left(1 + n\right)\right)\right)\right)\right) \]
    20. distribute-neg-inN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\mathsf{log1p.f64}\left(n\right), \left(\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(n\right)\right)}\right)\right)\right) \]
  3. Simplified3.1%

    \[\leadsto \color{blue}{\left(-1 - n \cdot \log n\right) - \mathsf{log1p}\left(n\right) \cdot \left(-1 - n\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in n around inf

    \[\leadsto \color{blue}{n \cdot \left(-1 \cdot \frac{1 + -1 \cdot \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{n} - \left(\log \left(\frac{1}{n}\right) + -1 \cdot \log \left(\frac{1}{n}\right)\right)\right)} \]
  6. Step-by-step derivation
    1. distribute-rgt1-inN/A

      \[\leadsto n \cdot \left(-1 \cdot \frac{1 + -1 \cdot \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{n} - \left(-1 + 1\right) \cdot \color{blue}{\log \left(\frac{1}{n}\right)}\right) \]
    2. metadata-evalN/A

      \[\leadsto n \cdot \left(-1 \cdot \frac{1 + -1 \cdot \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{n} - 0 \cdot \log \color{blue}{\left(\frac{1}{n}\right)}\right) \]
    3. mul0-lftN/A

      \[\leadsto n \cdot \left(-1 \cdot \frac{1 + -1 \cdot \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{n} - 0\right) \]
    4. --rgt-identityN/A

      \[\leadsto n \cdot \left(-1 \cdot \color{blue}{\frac{1 + -1 \cdot \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{n}}\right) \]
    5. +-lft-identityN/A

      \[\leadsto n \cdot \left(0 + \color{blue}{-1 \cdot \frac{1 + -1 \cdot \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{n}}\right) \]
    6. +-lft-identityN/A

      \[\leadsto n \cdot \left(-1 \cdot \color{blue}{\frac{1 + -1 \cdot \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{n}}\right) \]
    7. mul-1-negN/A

      \[\leadsto n \cdot \left(\mathsf{neg}\left(\frac{1 + -1 \cdot \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{n}\right)\right) \]
    8. distribute-neg-frac2N/A

      \[\leadsto n \cdot \frac{1 + -1 \cdot \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{\color{blue}{\mathsf{neg}\left(n\right)}} \]
    9. mul-1-negN/A

      \[\leadsto n \cdot \frac{1 + \left(\mathsf{neg}\left(\left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)\right)\right)}{\mathsf{neg}\left(n\right)} \]
    10. unsub-negN/A

      \[\leadsto n \cdot \frac{1 - \left(1 + -1 \cdot \log \left(\frac{1}{n}\right)\right)}{\mathsf{neg}\left(\color{blue}{n}\right)} \]
    11. associate--r+N/A

      \[\leadsto n \cdot \frac{\left(1 - 1\right) - -1 \cdot \log \left(\frac{1}{n}\right)}{\mathsf{neg}\left(\color{blue}{n}\right)} \]
    12. metadata-evalN/A

      \[\leadsto n \cdot \frac{0 - -1 \cdot \log \left(\frac{1}{n}\right)}{\mathsf{neg}\left(n\right)} \]
    13. mul-1-negN/A

      \[\leadsto n \cdot \frac{0 - -1 \cdot \log \left(\frac{1}{n}\right)}{-1 \cdot \color{blue}{n}} \]
  7. Simplified100.0%

    \[\leadsto \color{blue}{-1 \cdot \frac{\log n}{-1}} \]
  8. Step-by-step derivation
    1. mul-1-negN/A

      \[\leadsto \mathsf{neg}\left(\frac{\log n}{-1}\right) \]
    2. distribute-neg-frac2N/A

      \[\leadsto \frac{\log n}{\color{blue}{\mathsf{neg}\left(-1\right)}} \]
    3. metadata-evalN/A

      \[\leadsto \frac{\log n}{1} \]
    4. /-rgt-identityN/A

      \[\leadsto \log n \]
    5. log-lowering-log.f64100.0%

      \[\leadsto \mathsf{log.f64}\left(n\right) \]
  9. Applied egg-rr100.0%

    \[\leadsto \color{blue}{\log n} \]
  10. Add Preprocessing

Alternative 2: 3.1% accurate, 213.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (n) :precision binary64 0.0)
double code(double n) {
	return 0.0;
}
real(8) function code(n)
    real(8), intent (in) :: n
    code = 0.0d0
end function
public static double code(double n) {
	return 0.0;
}
def code(n):
	return 0.0
function code(n)
	return 0.0
end
function tmp = code(n)
	tmp = 0.0;
end
code[n_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 1.6%

    \[\left(\left(n + 1\right) \cdot \log \left(n + 1\right) - n \cdot \log n\right) - 1 \]
  2. Step-by-step derivation
    1. sub-negN/A

      \[\leadsto \left(\left(n + 1\right) \cdot \log \left(n + 1\right) + \left(\mathsf{neg}\left(n \cdot \log n\right)\right)\right) - 1 \]
    2. associate--l+N/A

      \[\leadsto \left(n + 1\right) \cdot \log \left(n + 1\right) + \color{blue}{\left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right)} \]
    3. +-commutativeN/A

      \[\leadsto \left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right) + \color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)} \]
    4. cancel-sign-subN/A

      \[\leadsto \left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right) - \color{blue}{\left(\mathsf{neg}\left(\left(n + 1\right)\right)\right) \cdot \log \left(n + 1\right)} \]
    5. distribute-lft-neg-inN/A

      \[\leadsto \left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right) - \left(\mathsf{neg}\left(\left(n + 1\right) \cdot \log \left(n + 1\right)\right)\right) \]
    6. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) - 1\right), \color{blue}{\left(\mathsf{neg}\left(\left(n + 1\right) \cdot \log \left(n + 1\right)\right)\right)}\right) \]
    7. sub-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\left(\left(\mathsf{neg}\left(n \cdot \log n\right)\right) + \left(\mathsf{neg}\left(1\right)\right)\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)}\right)\right)\right) \]
    8. +-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\left(\left(\mathsf{neg}\left(1\right)\right) + \left(\mathsf{neg}\left(n \cdot \log n\right)\right)\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)}\right)\right)\right) \]
    9. unsub-negN/A

      \[\leadsto \mathsf{\_.f64}\left(\left(\left(\mathsf{neg}\left(1\right)\right) - n \cdot \log n\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)}\right)\right)\right) \]
    10. --lowering--.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(\left(\mathsf{neg}\left(1\right)\right), \left(n \cdot \log n\right)\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right) \cdot \log \left(n + 1\right)}\right)\right)\right) \]
    11. metadata-evalN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \left(n \cdot \log n\right)\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right)} \cdot \log \left(n + 1\right)\right)\right)\right) \]
    12. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \log n\right)\right), \left(\mathsf{neg}\left(\left(n + 1\right) \cdot \color{blue}{\log \left(n + 1\right)}\right)\right)\right) \]
    13. log-lowering-log.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \left(\mathsf{neg}\left(\left(n + 1\right) \cdot \log \left(n + 1\right)\right)\right)\right) \]
    14. *-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \left(\mathsf{neg}\left(\log \left(n + 1\right) \cdot \left(n + 1\right)\right)\right)\right) \]
    15. distribute-rgt-neg-inN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \left(\log \left(n + 1\right) \cdot \color{blue}{\left(\mathsf{neg}\left(\left(n + 1\right)\right)\right)}\right)\right) \]
    16. *-lowering-*.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\log \left(n + 1\right), \color{blue}{\left(\mathsf{neg}\left(\left(n + 1\right)\right)\right)}\right)\right) \]
    17. +-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\log \left(1 + n\right), \left(\mathsf{neg}\left(\left(\color{blue}{n} + 1\right)\right)\right)\right)\right) \]
    18. accelerator-lowering-log1p.f64N/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\mathsf{log1p.f64}\left(n\right), \left(\mathsf{neg}\left(\color{blue}{\left(n + 1\right)}\right)\right)\right)\right) \]
    19. +-commutativeN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\mathsf{log1p.f64}\left(n\right), \left(\mathsf{neg}\left(\left(1 + n\right)\right)\right)\right)\right) \]
    20. distribute-neg-inN/A

      \[\leadsto \mathsf{\_.f64}\left(\mathsf{\_.f64}\left(-1, \mathsf{*.f64}\left(n, \mathsf{log.f64}\left(n\right)\right)\right), \mathsf{*.f64}\left(\mathsf{log1p.f64}\left(n\right), \left(\left(\mathsf{neg}\left(1\right)\right) + \color{blue}{\left(\mathsf{neg}\left(n\right)\right)}\right)\right)\right) \]
  3. Simplified3.1%

    \[\leadsto \color{blue}{\left(-1 - n \cdot \log n\right) - \mathsf{log1p}\left(n\right) \cdot \left(-1 - n\right)} \]
  4. Add Preprocessing
  5. Taylor expanded in n around inf

    \[\leadsto \color{blue}{-1 \cdot \left(n \cdot \left(\log \left(\frac{1}{n}\right) + -1 \cdot \log \left(\frac{1}{n}\right)\right)\right)} \]
  6. Step-by-step derivation
    1. associate-*r*N/A

      \[\leadsto \left(-1 \cdot n\right) \cdot \color{blue}{\left(\log \left(\frac{1}{n}\right) + -1 \cdot \log \left(\frac{1}{n}\right)\right)} \]
    2. distribute-rgt1-inN/A

      \[\leadsto \left(-1 \cdot n\right) \cdot \left(\left(-1 + 1\right) \cdot \color{blue}{\log \left(\frac{1}{n}\right)}\right) \]
    3. metadata-evalN/A

      \[\leadsto \left(-1 \cdot n\right) \cdot \left(0 \cdot \log \color{blue}{\left(\frac{1}{n}\right)}\right) \]
    4. mul0-lftN/A

      \[\leadsto \left(-1 \cdot n\right) \cdot 0 \]
    5. mul0-rgt3.1%

      \[\leadsto 0 \]
  7. Simplified3.1%

    \[\leadsto \color{blue}{0} \]
  8. Add Preprocessing

Developer Target 1: 100.0% accurate, 1.0× speedup?

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

\\
\log \left(n + 1\right) - \left(\frac{1}{2 \cdot n} - \left(\frac{1}{3 \cdot \left(n \cdot n\right)} - \frac{4}{{n}^{3}}\right)\right)
\end{array}

Reproduce

?
herbie shell --seed 2024192 
(FPCore (n)
  :name "logs (example 3.8)"
  :precision binary64
  :pre (> n 6.8e+15)

  :alt
  (! :herbie-platform default (- (log (+ n 1)) (- (/ 1 (* 2 n)) (- (/ 1 (* 3 (* n n))) (/ 4 (pow n 3))))))

  (- (- (* (+ n 1.0) (log (+ n 1.0))) (* n (log n))) 1.0))