
(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:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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}
(FPCore (N)
:precision binary64
(if (<= (- (log (+ N 1.0)) (log N)) 0.0005)
(+
(/ 0.3333333333333333 (pow N 3.0))
(- (/ 1.0 N) (+ (/ 0.5 (pow N 2.0)) (/ 0.25 (pow N 4.0)))))
(pow (sqrt (log (/ (+ N 1.0) N))) 2.0)))
double code(double N) {
double tmp;
if ((log((N + 1.0)) - log(N)) <= 0.0005) {
tmp = (0.3333333333333333 / pow(N, 3.0)) + ((1.0 / N) - ((0.5 / pow(N, 2.0)) + (0.25 / pow(N, 4.0))));
} else {
tmp = pow(sqrt(log(((N + 1.0) / N))), 2.0);
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((log((n + 1.0d0)) - log(n)) <= 0.0005d0) then
tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + ((1.0d0 / n) - ((0.5d0 / (n ** 2.0d0)) + (0.25d0 / (n ** 4.0d0))))
else
tmp = sqrt(log(((n + 1.0d0) / n))) ** 2.0d0
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.0005) {
tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((1.0 / N) - ((0.5 / Math.pow(N, 2.0)) + (0.25 / Math.pow(N, 4.0))));
} else {
tmp = Math.pow(Math.sqrt(Math.log(((N + 1.0) / N))), 2.0);
}
return tmp;
}
def code(N): tmp = 0 if (math.log((N + 1.0)) - math.log(N)) <= 0.0005: tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((1.0 / N) - ((0.5 / math.pow(N, 2.0)) + (0.25 / math.pow(N, 4.0)))) else: tmp = math.pow(math.sqrt(math.log(((N + 1.0) / N))), 2.0) return tmp
function code(N) tmp = 0.0 if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.0005) tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(1.0 / N) - Float64(Float64(0.5 / (N ^ 2.0)) + Float64(0.25 / (N ^ 4.0))))); else tmp = sqrt(log(Float64(Float64(N + 1.0) / N))) ^ 2.0; end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((log((N + 1.0)) - log(N)) <= 0.0005) tmp = (0.3333333333333333 / (N ^ 3.0)) + ((1.0 / N) - ((0.5 / (N ^ 2.0)) + (0.25 / (N ^ 4.0)))); else tmp = sqrt(log(((N + 1.0) / N))) ^ 2.0; end tmp_2 = tmp; end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.0005], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / N), $MachinePrecision] - N[(N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision] + N[(0.25 / N[Power[N, 4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[Sqrt[N[Log[N[(N[(N + 1.0), $MachinePrecision] / N), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(\frac{1}{N} - \left(\frac{0.5}{{N}^{2}} + \frac{0.25}{{N}^{4}}\right)\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\sqrt{\log \left(\frac{N + 1}{N}\right)}\right)}^{2}\\
\end{array}
\end{array}
if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 5.0000000000000001e-4Initial program 19.6%
+-commutative19.6%
log1p-def19.6%
Simplified19.6%
Taylor expanded in N around inf 99.8%
associate--l+99.8%
associate-*r/99.8%
metadata-eval99.8%
+-commutative99.8%
associate-*r/99.8%
metadata-eval99.8%
associate-*r/99.8%
metadata-eval99.8%
Simplified99.8%
if 5.0000000000000001e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) Initial program 93.9%
+-commutative93.9%
log1p-def94.1%
Simplified94.1%
add-sqr-sqrt94.3%
pow294.3%
Applied egg-rr94.3%
add-log-exp94.1%
log1p-expm1-u94.1%
log1p-udef94.1%
diff-log93.9%
log1p-udef93.8%
rem-exp-log95.1%
+-commutative95.1%
add-exp-log95.1%
log1p-udef95.1%
log1p-expm1-u95.1%
add-exp-log96.4%
Applied egg-rr96.4%
Final simplification99.5%
(FPCore (N)
:precision binary64
(if (<= (- (log (+ N 1.0)) (log N)) 0.0005)
(+
(/ 0.3333333333333333 (pow N 3.0))
(+ (* (pow N -2.0) (+ N -0.5)) (* -0.25 (pow N -4.0))))
(pow (sqrt (log (/ (+ N 1.0) N))) 2.0)))
double code(double N) {
double tmp;
if ((log((N + 1.0)) - log(N)) <= 0.0005) {
tmp = (0.3333333333333333 / pow(N, 3.0)) + ((pow(N, -2.0) * (N + -0.5)) + (-0.25 * pow(N, -4.0)));
} else {
tmp = pow(sqrt(log(((N + 1.0) / N))), 2.0);
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((log((n + 1.0d0)) - log(n)) <= 0.0005d0) then
tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + (((n ** (-2.0d0)) * (n + (-0.5d0))) + ((-0.25d0) * (n ** (-4.0d0))))
else
tmp = sqrt(log(((n + 1.0d0) / n))) ** 2.0d0
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((Math.log((N + 1.0)) - Math.log(N)) <= 0.0005) {
tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((Math.pow(N, -2.0) * (N + -0.5)) + (-0.25 * Math.pow(N, -4.0)));
} else {
tmp = Math.pow(Math.sqrt(Math.log(((N + 1.0) / N))), 2.0);
}
return tmp;
}
def code(N): tmp = 0 if (math.log((N + 1.0)) - math.log(N)) <= 0.0005: tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((math.pow(N, -2.0) * (N + -0.5)) + (-0.25 * math.pow(N, -4.0))) else: tmp = math.pow(math.sqrt(math.log(((N + 1.0) / N))), 2.0) return tmp
function code(N) tmp = 0.0 if (Float64(log(Float64(N + 1.0)) - log(N)) <= 0.0005) tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64((N ^ -2.0) * Float64(N + -0.5)) + Float64(-0.25 * (N ^ -4.0)))); else tmp = sqrt(log(Float64(Float64(N + 1.0) / N))) ^ 2.0; end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((log((N + 1.0)) - log(N)) <= 0.0005) tmp = (0.3333333333333333 / (N ^ 3.0)) + (((N ^ -2.0) * (N + -0.5)) + (-0.25 * (N ^ -4.0))); else tmp = sqrt(log(((N + 1.0) / N))) ^ 2.0; end tmp_2 = tmp; end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 0.0005], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(N[Power[N, -2.0], $MachinePrecision] * N[(N + -0.5), $MachinePrecision]), $MachinePrecision] + N[(-0.25 * N[Power[N, -4.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Power[N[Sqrt[N[Log[N[(N[(N + 1.0), $MachinePrecision] / N), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 0.0005:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left({N}^{-2} \cdot \left(N + -0.5\right) + -0.25 \cdot {N}^{-4}\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\sqrt{\log \left(\frac{N + 1}{N}\right)}\right)}^{2}\\
\end{array}
\end{array}
if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 5.0000000000000001e-4Initial program 19.6%
+-commutative19.6%
log1p-def19.6%
Simplified19.6%
Taylor expanded in N around inf 99.8%
associate--l+99.8%
associate-*r/99.8%
metadata-eval99.8%
+-commutative99.8%
associate-*r/99.8%
metadata-eval99.8%
associate-*r/99.8%
metadata-eval99.8%
Simplified99.8%
associate--r+99.8%
add-cube-cbrt97.8%
fma-neg97.8%
Applied egg-rr97.9%
fma-udef97.9%
pow-plus97.9%
metadata-eval97.9%
cube-div98.0%
rem-cube-cbrt99.4%
associate-/l*99.4%
sub-neg99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
associate-/r/99.6%
pow199.6%
pow-div99.7%
metadata-eval99.7%
Applied egg-rr99.7%
if 5.0000000000000001e-4 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) Initial program 93.9%
+-commutative93.9%
log1p-def94.1%
Simplified94.1%
add-sqr-sqrt94.3%
pow294.3%
Applied egg-rr94.3%
add-log-exp94.1%
log1p-expm1-u94.1%
log1p-udef94.1%
diff-log93.9%
log1p-udef93.8%
rem-exp-log95.1%
+-commutative95.1%
add-exp-log95.1%
log1p-udef95.1%
log1p-expm1-u95.1%
add-exp-log96.4%
Applied egg-rr96.4%
Final simplification99.4%
(FPCore (N) :precision binary64 (if (<= (- (log (+ N 1.0)) (log N)) 6e-5) (+ (/ 0.3333333333333333 (pow N 3.0)) (/ 1.0 (+ 0.5 (+ N (/ 0.25 N))))) (log (/ (+ N 1.0) N))))
double code(double N) {
double tmp;
if ((log((N + 1.0)) - log(N)) <= 6e-5) {
tmp = (0.3333333333333333 / pow(N, 3.0)) + (1.0 / (0.5 + (N + (0.25 / N))));
} else {
tmp = log(((N + 1.0) / N));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if ((log((n + 1.0d0)) - log(n)) <= 6d-5) then
tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + (1.0d0 / (0.5d0 + (n + (0.25d0 / n))))
else
tmp = log(((n + 1.0d0) / n))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if ((Math.log((N + 1.0)) - Math.log(N)) <= 6e-5) {
tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + (1.0 / (0.5 + (N + (0.25 / N))));
} else {
tmp = Math.log(((N + 1.0) / N));
}
return tmp;
}
def code(N): tmp = 0 if (math.log((N + 1.0)) - math.log(N)) <= 6e-5: tmp = (0.3333333333333333 / math.pow(N, 3.0)) + (1.0 / (0.5 + (N + (0.25 / N)))) else: tmp = math.log(((N + 1.0) / N)) return tmp
function code(N) tmp = 0.0 if (Float64(log(Float64(N + 1.0)) - log(N)) <= 6e-5) tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(1.0 / Float64(0.5 + Float64(N + Float64(0.25 / N))))); else tmp = log(Float64(Float64(N + 1.0) / N)); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if ((log((N + 1.0)) - log(N)) <= 6e-5) tmp = (0.3333333333333333 / (N ^ 3.0)) + (1.0 / (0.5 + (N + (0.25 / N)))); else tmp = log(((N + 1.0) / N)); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N[(N[Log[N[(N + 1.0), $MachinePrecision]], $MachinePrecision] - N[Log[N], $MachinePrecision]), $MachinePrecision], 6e-5], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(0.5 + N[(N + N[(0.25 / N), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Log[N[(N[(N + 1.0), $MachinePrecision] / N), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\log \left(N + 1\right) - \log N \leq 6 \cdot 10^{-5}:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \frac{1}{0.5 + \left(N + \frac{0.25}{N}\right)}\\
\mathbf{else}:\\
\;\;\;\;\log \left(\frac{N + 1}{N}\right)\\
\end{array}
\end{array}
if (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) < 6.00000000000000015e-5Initial program 18.6%
+-commutative18.6%
log1p-def18.6%
Simplified18.6%
Taylor expanded in N around inf 99.6%
associate--l+99.6%
associate-*r/99.6%
metadata-eval99.6%
associate-*r/99.6%
metadata-eval99.6%
Simplified99.6%
frac-sub99.2%
unpow299.2%
cube-mult99.1%
clear-num99.3%
*-un-lft-identity99.3%
unpow299.3%
distribute-lft-out--99.3%
Applied egg-rr99.3%
Taylor expanded in N around inf 99.6%
associate-*r/99.6%
metadata-eval99.6%
Simplified99.6%
if 6.00000000000000015e-5 < (-.f64 (log.f64 (+.f64 N 1)) (log.f64 N)) Initial program 91.6%
+-commutative91.6%
log1p-def91.8%
Simplified91.8%
add-log-exp91.8%
log1p-expm1-u91.8%
log1p-udef91.8%
diff-log91.6%
log1p-udef91.4%
rem-exp-log92.5%
+-commutative92.5%
add-exp-log92.5%
log1p-udef92.5%
log1p-expm1-u92.5%
add-exp-log94.6%
Applied egg-rr94.6%
Final simplification99.1%
(FPCore (N)
:precision binary64
(if (<= N 1100.0)
(pow (sqrt (log (/ (+ N 1.0) N))) 2.0)
(+
(/ 0.3333333333333333 (pow N 3.0))
(+
(* -0.25 (pow N -4.0))
(/ N (+ (* N (+ N 0.5)) (+ 0.25 (/ 0.125 N))))))))
double code(double N) {
double tmp;
if (N <= 1100.0) {
tmp = pow(sqrt(log(((N + 1.0) / N))), 2.0);
} else {
tmp = (0.3333333333333333 / pow(N, 3.0)) + ((-0.25 * pow(N, -4.0)) + (N / ((N * (N + 0.5)) + (0.25 + (0.125 / N)))));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 1100.0d0) then
tmp = sqrt(log(((n + 1.0d0) / n))) ** 2.0d0
else
tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + (((-0.25d0) * (n ** (-4.0d0))) + (n / ((n * (n + 0.5d0)) + (0.25d0 + (0.125d0 / n)))))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= 1100.0) {
tmp = Math.pow(Math.sqrt(Math.log(((N + 1.0) / N))), 2.0);
} else {
tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((-0.25 * Math.pow(N, -4.0)) + (N / ((N * (N + 0.5)) + (0.25 + (0.125 / N)))));
}
return tmp;
}
def code(N): tmp = 0 if N <= 1100.0: tmp = math.pow(math.sqrt(math.log(((N + 1.0) / N))), 2.0) else: tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((-0.25 * math.pow(N, -4.0)) + (N / ((N * (N + 0.5)) + (0.25 + (0.125 / N))))) return tmp
function code(N) tmp = 0.0 if (N <= 1100.0) tmp = sqrt(log(Float64(Float64(N + 1.0) / N))) ^ 2.0; else tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(-0.25 * (N ^ -4.0)) + Float64(N / Float64(Float64(N * Float64(N + 0.5)) + Float64(0.25 + Float64(0.125 / N)))))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= 1100.0) tmp = sqrt(log(((N + 1.0) / N))) ^ 2.0; else tmp = (0.3333333333333333 / (N ^ 3.0)) + ((-0.25 * (N ^ -4.0)) + (N / ((N * (N + 0.5)) + (0.25 + (0.125 / N))))); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 1100.0], N[Power[N[Sqrt[N[Log[N[(N[(N + 1.0), $MachinePrecision] / N), $MachinePrecision]], $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.25 * N[Power[N, -4.0], $MachinePrecision]), $MachinePrecision] + N[(N / N[(N[(N * N[(N + 0.5), $MachinePrecision]), $MachinePrecision] + N[(0.25 + N[(0.125 / N), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 1100:\\
\;\;\;\;{\left(\sqrt{\log \left(\frac{N + 1}{N}\right)}\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(-0.25 \cdot {N}^{-4} + \frac{N}{N \cdot \left(N + 0.5\right) + \left(0.25 + \frac{0.125}{N}\right)}\right)\\
\end{array}
\end{array}
if N < 1100Initial program 93.9%
+-commutative93.9%
log1p-def94.1%
Simplified94.1%
add-sqr-sqrt94.3%
pow294.3%
Applied egg-rr94.3%
add-log-exp94.1%
log1p-expm1-u94.1%
log1p-udef94.1%
diff-log93.9%
log1p-udef93.8%
rem-exp-log95.1%
+-commutative95.1%
add-exp-log95.1%
log1p-udef95.1%
log1p-expm1-u95.1%
add-exp-log96.4%
Applied egg-rr96.4%
if 1100 < N Initial program 19.6%
+-commutative19.6%
log1p-def19.6%
Simplified19.6%
Taylor expanded in N around inf 99.8%
associate--l+99.8%
associate-*r/99.8%
metadata-eval99.8%
+-commutative99.8%
associate-*r/99.8%
metadata-eval99.8%
associate-*r/99.8%
metadata-eval99.8%
Simplified99.8%
associate--r+99.8%
add-cube-cbrt97.8%
fma-neg97.8%
Applied egg-rr97.9%
fma-udef97.9%
pow-plus97.9%
metadata-eval97.9%
cube-div98.0%
rem-cube-cbrt99.4%
associate-/l*99.4%
sub-neg99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in N around inf 99.5%
+-commutative99.5%
+-commutative99.5%
associate-+l+99.5%
+-commutative99.5%
unpow299.5%
distribute-rgt-out99.6%
associate-*r/99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.3%
(FPCore (N)
:precision binary64
(if (<= N 1100.0)
(log (/ (+ N 1.0) N))
(+
(/ 0.3333333333333333 (pow N 3.0))
(+
(* -0.25 (pow N -4.0))
(/ N (+ (* N (+ N 0.5)) (+ 0.25 (/ 0.125 N))))))))
double code(double N) {
double tmp;
if (N <= 1100.0) {
tmp = log(((N + 1.0) / N));
} else {
tmp = (0.3333333333333333 / pow(N, 3.0)) + ((-0.25 * pow(N, -4.0)) + (N / ((N * (N + 0.5)) + (0.25 + (0.125 / N)))));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 1100.0d0) then
tmp = log(((n + 1.0d0) / n))
else
tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + (((-0.25d0) * (n ** (-4.0d0))) + (n / ((n * (n + 0.5d0)) + (0.25d0 + (0.125d0 / n)))))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= 1100.0) {
tmp = Math.log(((N + 1.0) / N));
} else {
tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + ((-0.25 * Math.pow(N, -4.0)) + (N / ((N * (N + 0.5)) + (0.25 + (0.125 / N)))));
}
return tmp;
}
def code(N): tmp = 0 if N <= 1100.0: tmp = math.log(((N + 1.0) / N)) else: tmp = (0.3333333333333333 / math.pow(N, 3.0)) + ((-0.25 * math.pow(N, -4.0)) + (N / ((N * (N + 0.5)) + (0.25 + (0.125 / N))))) return tmp
function code(N) tmp = 0.0 if (N <= 1100.0) tmp = log(Float64(Float64(N + 1.0) / N)); else tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(Float64(-0.25 * (N ^ -4.0)) + Float64(N / Float64(Float64(N * Float64(N + 0.5)) + Float64(0.25 + Float64(0.125 / N)))))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= 1100.0) tmp = log(((N + 1.0) / N)); else tmp = (0.3333333333333333 / (N ^ 3.0)) + ((-0.25 * (N ^ -4.0)) + (N / ((N * (N + 0.5)) + (0.25 + (0.125 / N))))); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 1100.0], N[Log[N[(N[(N + 1.0), $MachinePrecision] / N), $MachinePrecision]], $MachinePrecision], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(N[(-0.25 * N[Power[N, -4.0], $MachinePrecision]), $MachinePrecision] + N[(N / N[(N[(N * N[(N + 0.5), $MachinePrecision]), $MachinePrecision] + N[(0.25 + N[(0.125 / N), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 1100:\\
\;\;\;\;\log \left(\frac{N + 1}{N}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \left(-0.25 \cdot {N}^{-4} + \frac{N}{N \cdot \left(N + 0.5\right) + \left(0.25 + \frac{0.125}{N}\right)}\right)\\
\end{array}
\end{array}
if N < 1100Initial program 93.9%
+-commutative93.9%
log1p-def94.1%
Simplified94.1%
add-log-exp94.1%
log1p-expm1-u94.1%
log1p-udef94.1%
diff-log93.9%
log1p-udef93.8%
rem-exp-log95.1%
+-commutative95.1%
add-exp-log95.1%
log1p-udef95.1%
log1p-expm1-u95.1%
add-exp-log96.4%
Applied egg-rr96.4%
if 1100 < N Initial program 19.6%
+-commutative19.6%
log1p-def19.6%
Simplified19.6%
Taylor expanded in N around inf 99.8%
associate--l+99.8%
associate-*r/99.8%
metadata-eval99.8%
+-commutative99.8%
associate-*r/99.8%
metadata-eval99.8%
associate-*r/99.8%
metadata-eval99.8%
Simplified99.8%
associate--r+99.8%
add-cube-cbrt97.8%
fma-neg97.8%
Applied egg-rr97.9%
fma-udef97.9%
pow-plus97.9%
metadata-eval97.9%
cube-div98.0%
rem-cube-cbrt99.4%
associate-/l*99.4%
sub-neg99.4%
metadata-eval99.4%
distribute-lft-neg-in99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in N around inf 99.5%
+-commutative99.5%
+-commutative99.5%
associate-+l+99.5%
+-commutative99.5%
unpow299.5%
distribute-rgt-out99.6%
associate-*r/99.6%
metadata-eval99.6%
Simplified99.6%
Final simplification99.3%
(FPCore (N) :precision binary64 (if (<= N 160000.0) (log (/ (+ N 1.0) N)) (+ (/ 0.3333333333333333 (pow N 3.0)) (/ 1.0 (+ N 0.5)))))
double code(double N) {
double tmp;
if (N <= 160000.0) {
tmp = log(((N + 1.0) / N));
} else {
tmp = (0.3333333333333333 / pow(N, 3.0)) + (1.0 / (N + 0.5));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 160000.0d0) then
tmp = log(((n + 1.0d0) / n))
else
tmp = (0.3333333333333333d0 / (n ** 3.0d0)) + (1.0d0 / (n + 0.5d0))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= 160000.0) {
tmp = Math.log(((N + 1.0) / N));
} else {
tmp = (0.3333333333333333 / Math.pow(N, 3.0)) + (1.0 / (N + 0.5));
}
return tmp;
}
def code(N): tmp = 0 if N <= 160000.0: tmp = math.log(((N + 1.0) / N)) else: tmp = (0.3333333333333333 / math.pow(N, 3.0)) + (1.0 / (N + 0.5)) return tmp
function code(N) tmp = 0.0 if (N <= 160000.0) tmp = log(Float64(Float64(N + 1.0) / N)); else tmp = Float64(Float64(0.3333333333333333 / (N ^ 3.0)) + Float64(1.0 / Float64(N + 0.5))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= 160000.0) tmp = log(((N + 1.0) / N)); else tmp = (0.3333333333333333 / (N ^ 3.0)) + (1.0 / (N + 0.5)); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 160000.0], N[Log[N[(N[(N + 1.0), $MachinePrecision] / N), $MachinePrecision]], $MachinePrecision], N[(N[(0.3333333333333333 / N[Power[N, 3.0], $MachinePrecision]), $MachinePrecision] + N[(1.0 / N[(N + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 160000:\\
\;\;\;\;\log \left(\frac{N + 1}{N}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{0.3333333333333333}{{N}^{3}} + \frac{1}{N + 0.5}\\
\end{array}
\end{array}
if N < 1.6e5Initial program 87.2%
+-commutative87.2%
log1p-def87.3%
Simplified87.3%
add-log-exp87.3%
log1p-expm1-u87.3%
log1p-udef87.3%
diff-log87.0%
log1p-udef86.9%
rem-exp-log88.0%
+-commutative88.0%
add-exp-log88.1%
log1p-udef88.1%
log1p-expm1-u88.1%
add-exp-log90.8%
Applied egg-rr90.7%
if 1.6e5 < N Initial program 16.3%
+-commutative16.3%
log1p-def16.4%
Simplified16.4%
Taylor expanded in N around inf 99.9%
associate--l+99.9%
associate-*r/99.9%
metadata-eval99.9%
associate-*r/99.9%
metadata-eval99.9%
Simplified99.9%
frac-sub99.5%
unpow299.5%
cube-mult99.4%
clear-num99.6%
*-un-lft-identity99.6%
unpow299.6%
distribute-lft-out--99.6%
Applied egg-rr99.6%
Taylor expanded in N around inf 98.9%
+-commutative98.9%
Simplified98.9%
Final simplification97.7%
(FPCore (N) :precision binary64 (if (<= N 160000.0) (log (/ (+ N 1.0) N)) (- (/ 1.0 N) (/ 0.5 (pow N 2.0)))))
double code(double N) {
double tmp;
if (N <= 160000.0) {
tmp = log(((N + 1.0) / N));
} else {
tmp = (1.0 / N) - (0.5 / pow(N, 2.0));
}
return tmp;
}
real(8) function code(n)
real(8), intent (in) :: n
real(8) :: tmp
if (n <= 160000.0d0) then
tmp = log(((n + 1.0d0) / n))
else
tmp = (1.0d0 / n) - (0.5d0 / (n ** 2.0d0))
end if
code = tmp
end function
public static double code(double N) {
double tmp;
if (N <= 160000.0) {
tmp = Math.log(((N + 1.0) / N));
} else {
tmp = (1.0 / N) - (0.5 / Math.pow(N, 2.0));
}
return tmp;
}
def code(N): tmp = 0 if N <= 160000.0: tmp = math.log(((N + 1.0) / N)) else: tmp = (1.0 / N) - (0.5 / math.pow(N, 2.0)) return tmp
function code(N) tmp = 0.0 if (N <= 160000.0) tmp = log(Float64(Float64(N + 1.0) / N)); else tmp = Float64(Float64(1.0 / N) - Float64(0.5 / (N ^ 2.0))); end return tmp end
function tmp_2 = code(N) tmp = 0.0; if (N <= 160000.0) tmp = log(((N + 1.0) / N)); else tmp = (1.0 / N) - (0.5 / (N ^ 2.0)); end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 160000.0], N[Log[N[(N[(N + 1.0), $MachinePrecision] / N), $MachinePrecision]], $MachinePrecision], N[(N[(1.0 / N), $MachinePrecision] - N[(0.5 / N[Power[N, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;N \leq 160000:\\
\;\;\;\;\log \left(\frac{N + 1}{N}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{N} - \frac{0.5}{{N}^{2}}\\
\end{array}
\end{array}
if N < 1.6e5Initial program 87.2%
+-commutative87.2%
log1p-def87.3%
Simplified87.3%
add-log-exp87.3%
log1p-expm1-u87.3%
log1p-udef87.3%
diff-log87.0%
log1p-udef86.9%
rem-exp-log88.0%
+-commutative88.0%
add-exp-log88.1%
log1p-udef88.1%
log1p-expm1-u88.1%
add-exp-log90.8%
Applied egg-rr90.7%
if 1.6e5 < N Initial program 16.3%
+-commutative16.3%
log1p-def16.4%
Simplified16.4%
Taylor expanded in N around inf 98.8%
associate-*r/98.8%
metadata-eval98.8%
Simplified98.8%
Final simplification97.7%
(FPCore (N) :precision binary64 (if (<= N 165000000.0) (- (log (/ N (+ N 1.0)))) (/ 1.0 N)))
double code(double N) {
double tmp;
if (N <= 165000000.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 <= 165000000.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 <= 165000000.0) {
tmp = -Math.log((N / (N + 1.0)));
} else {
tmp = 1.0 / N;
}
return tmp;
}
def code(N): tmp = 0 if N <= 165000000.0: tmp = -math.log((N / (N + 1.0))) else: tmp = 1.0 / N return tmp
function code(N) tmp = 0.0 if (N <= 165000000.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 <= 165000000.0) tmp = -log((N / (N + 1.0))); else tmp = 1.0 / N; end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 165000000.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 165000000:\\
\;\;\;\;-\log \left(\frac{N}{N + 1}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{N}\\
\end{array}
\end{array}
if N < 1.65e8Initial program 77.9%
+-commutative77.9%
log1p-def78.1%
Simplified78.1%
add-log-exp78.1%
log1p-expm1-u78.1%
log1p-udef78.1%
diff-log78.0%
log1p-udef77.8%
rem-exp-log78.7%
+-commutative78.7%
add-exp-log78.7%
log1p-udef78.7%
log1p-expm1-u78.7%
add-exp-log82.2%
Applied egg-rr82.2%
clear-num82.1%
log-rec82.7%
Applied egg-rr82.7%
if 1.65e8 < N Initial program 11.2%
+-commutative11.2%
log1p-def11.2%
Simplified11.2%
Taylor expanded in N around inf 95.0%
Final simplification92.2%
(FPCore (N) :precision binary64 (if (<= N 105000000.0) (log (/ (+ N 1.0) N)) (/ 1.0 N)))
double code(double N) {
double tmp;
if (N <= 105000000.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 <= 105000000.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 <= 105000000.0) {
tmp = Math.log(((N + 1.0) / N));
} else {
tmp = 1.0 / N;
}
return tmp;
}
def code(N): tmp = 0 if N <= 105000000.0: tmp = math.log(((N + 1.0) / N)) else: tmp = 1.0 / N return tmp
function code(N) tmp = 0.0 if (N <= 105000000.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 <= 105000000.0) tmp = log(((N + 1.0) / N)); else tmp = 1.0 / N; end tmp_2 = tmp; end
code[N_] := If[LessEqual[N, 105000000.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 105000000:\\
\;\;\;\;\log \left(\frac{N + 1}{N}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{N}\\
\end{array}
\end{array}
if N < 1.05e8Initial program 78.7%
+-commutative78.7%
log1p-def79.0%
Simplified79.0%
add-log-exp79.0%
log1p-expm1-u79.0%
log1p-udef79.0%
diff-log78.8%
log1p-udef78.6%
rem-exp-log79.7%
+-commutative79.7%
add-exp-log79.6%
log1p-udef79.6%
log1p-expm1-u79.6%
add-exp-log83.0%
Applied egg-rr83.0%
if 1.05e8 < N Initial program 11.6%
+-commutative11.6%
log1p-def11.6%
Simplified11.6%
Taylor expanded in N around inf 94.7%
Final simplification92.1%
(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}
Initial program 26.3%
+-commutative26.3%
log1p-def26.3%
Simplified26.3%
Taylor expanded in N around inf 82.6%
Final simplification82.6%
(FPCore (N) :precision binary64 (log1p (/ 1.0 N)))
double code(double N) {
return log1p((1.0 / N));
}
public static double code(double N) {
return Math.log1p((1.0 / N));
}
def code(N): return math.log1p((1.0 / N))
function code(N) return log1p(Float64(1.0 / N)) end
code[N_] := N[Log[1 + N[(1.0 / N), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\mathsf{log1p}\left(\frac{1}{N}\right)
\end{array}
herbie shell --seed 2024041
(FPCore (N)
:name "2log (problem 3.3.6)"
:precision binary64
:pre (and (> N 1.0) (< N 1e+40))
:herbie-target
(log1p (/ 1.0 N))
(- (log (+ N 1.0)) (log N)))