2log (problem 3.3.6)

?

Percentage Accurate: 54.2% → 100.0%
Time: 6.7s
Precision: binary64
Cost: 6592

?

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

Local Percentage Accuracy?

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.

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

Derivation?

  1. Initial program 52.2%

    \[\log \left(N + 1\right) - \log N \]
  2. Applied egg-rr52.3%

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

    [Start]52.2

    \[ \log \left(N + 1\right) - \log N \]

    diff-log [=>]52.3

    \[ \color{blue}{\log \left(\frac{N + 1}{N}\right)} \]
  3. Applied egg-rr52.2%

    \[\leadsto \color{blue}{0 + \left(\mathsf{log1p}\left(N\right) - \log N\right)} \]
    Step-by-step derivation

    [Start]52.3

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

    *-un-lft-identity [=>]52.3

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

    log-prod [=>]52.3

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

    metadata-eval [=>]52.3

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

    log-div [=>]52.2

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

    +-commutative [=>]52.2

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

    log1p-udef [<=]52.2

    \[ 0 + \left(\color{blue}{\mathsf{log1p}\left(N\right)} - \log N\right) \]
  4. Simplified100.0%

    \[\leadsto \color{blue}{\mathsf{log1p}\left(\frac{1}{N}\right)} \]
    Step-by-step derivation

    [Start]52.2

    \[ 0 + \left(\mathsf{log1p}\left(N\right) - \log N\right) \]

    +-lft-identity [=>]52.2

    \[ \color{blue}{\mathsf{log1p}\left(N\right) - \log N} \]

    log1p-def [<=]52.2

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

    +-commutative [<=]52.2

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

    log-div [<=]52.3

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

    *-lft-identity [<=]52.3

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

    associate-*l/ [<=]52.0

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

    distribute-lft-in [=>]52.1

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

    lft-mult-inverse [=>]52.3

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

    *-rgt-identity [=>]52.3

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

    log1p-def [=>]100.0

    \[ \color{blue}{\mathsf{log1p}\left(\frac{1}{N}\right)} \]
  5. Final simplification100.0%

    \[\leadsto \mathsf{log1p}\left(\frac{1}{N}\right) \]

Alternatives

Alternative 1
Accuracy98.5%
Cost6660
\[\begin{array}{l} \mathbf{if}\;N \leq 0.66:\\ \;\;\;\;-\log N\\ \mathbf{else}:\\ \;\;\;\;\frac{1 - \frac{0.5}{N}}{N}\\ \end{array} \]
Alternative 2
Accuracy51.6%
Cost192
\[\frac{1}{N} \]
Alternative 3
Accuracy4.6%
Cost64
\[N \]

Error

Reproduce?

herbie shell --seed 2023159 
(FPCore (N)
  :name "2log (problem 3.3.6)"
  :precision binary64
  (- (log (+ N 1.0)) (log N)))