This exercise demonstrates that g(N)=O(f(N)) also encompasses asymptotically negative functions. Certain references, like CLRS's Introduction to Algorithms, restrict g(N) to nonnegative functions and employ a specific notation O' to remove this limitation within O-notation.
We start by factoring N/(N+1)=1−1/(N+1). Let’s show that the second summand is O(1/N)
1/N−1/(N+1)=N+1N<1 for all N≥0,
therefore, N/(N+1)=1+O(1/N). We also have
N→∞lim1−1/NN/(N+1)=1,
hence, N/(N+1)∼1−1/N.
Exercise 3
N→∞limNβNα=N→∞limNβ−α1=0,when α<β.
Therefore, Nα=o(Nβ) for α<β.
Exercise 4
The O- and o-notations provide ways to express upper bounds (with o being the stronger assertion). Consequently, g(N)=o(f(N))⟹g(N)=O(f(N)). By combining the results from the previous two exercises, for r≥0 fixed, we can conclude that (see also section 4.3 of the book)
Instead of relying on basic algebraic manipulations involving the O-notation, we can represent the numerator of (rN) as a polynomial P(N)=N(N−1)⋯(N−r+1). Since there are r terms in this product, multiplying the N from each term gives us a leading factor of Nr. To find the next term (the coefficient of Nr−1), we sum the constant terms from each factor
Sum of constants=−(0+1+2+⋯+(r−1))=−2(r−1)r.
Thus, the numerator expands to
P(N)=Nr−2r(r−1)Nr−1+…(lower order terms).
Dividing by r! gives
(rN)=r!Nr−2⋅r!r(r−1)Nr−1+…
The first term is our leading term. All subsequent terms form a polynomial of degree r−1. Therefore, their sum is O(Nr−1) (see also the previous exercise). An analogous reasoning applies for the case (rN+r).
The cosine function oscillates between -1 and 1, thus as N→∞ we have 1/(2+cosN)∈[1/3,1]. Clearly, it’s bounded from above, but doesn’t tend to 0. Therefore, it is O(1) but not o(1).
Exercise 7
The definition from the book "...we often refer informally to a quantity as being exponentially small if it is smaller than any negative power of N—that is, O(1/NM) for any positive M." is imprecise. Namely, the word "smaller" pertains to an asymptotic property of a decay, so instead of O- it should use o-notation.
In the last line MlnN=o(log2N), since after cancelling one logarithm on both sides, we are left with a constant term "against" a logarithm that grows to infinity. Observe that we don’t care about the base of a logarithm on the RHS, as it’s just a constant multiple of a natural logarithm. Therefore, e−log2N is exponentially small.
By employing the same reasoning as previously, we see that now loglogn grows faster than any constant. Therefore, (logN)−logN is exponentially small.
Exercise 9 🌟
This exercise shows why focusing on an asymptotically most significant term is beneficial. As the calculation shows, it’s a reliable estimator of the performance for sufficiently large problem sizes.
Let f(N) be exponentially small, meaning for every M>0, f(N)=o(N−M). For any polynomialg(N)=O(Nd), where d≥0 is the degree of the polynomial, we can choose M′=M+d, such that f(N)g(N)=o(N−M′)O(Nd)=o(N−M). This concludes the proof.
Exercise 11
Chapter 2 of the book explains the Master Theorem with a note that floors/ceilings can be ignored without breaking the asymptotic result. The term a⌊n/2⌋+O(1) implies that every time we recurse, we introduce a small discrepancy O(1) due to potential rounding errors. This gives
In a binary recursion tree, where every internal node has 2 children, the number of nodes doubles at every level. The sum of this error across the whole tree is proportional to the number of nodes in the tree
Total Error=k=0∑lgn2k⋅O(1)=O(n).
Consequently, an=(Ideal Solution)+O(n), where ideal solution denotes the case when n is a power of two. We’ll derive these ideal solutions and see that the extra O(n) error has no significance on them.
an=2an/2+O(n) essentially falls under case 2 of the Master Theorem. We have lgn levels in the recursion tree taking O(n) work per level. Therefore, an=O(nlogn). We cannot use Θ-notation because the term O(n) allows for the driving function to be 0 or even negative (see the next exercise).
an=2an/2+o(n) can also be handled using the summation approach. We have lgn levels in the recursion tree taking o(n) work per level. Therefore, an=o(nlogn).
an∼2an/2+n means that an=2an/2+n+o(n). Dividing by n and letting bn=an/n yields bn=bn/2+1+o(1). Iterating this recurrence gives bn=b0+lgn+o(lgn), so an=nlgn+o(nlgn). Therefore, an∼nlgn.
Exercise 12
This is a continuation of the previous exercise, where the first case is already covered:
an=2an/2+Θ(n) entails that an=Θ(nlogn).
an=2an/2+Ω(n) entails that an=Ω(nlogn).
Exercise 13
Both a(x) and b(x) grow like xα, and the additive perturbation c in the argument of b(x) becomes asymptotically negligible. To see this, we just need to iterate the recurrences until hitting the base cases.
For a(x) the recursion unfolds as
a(x)=f(x)+f(x/β)+f(x/β2)+⋯+f(x/βk),
where x/βk<1 eventually, so the sum terminates. Since f(x)=xα, each term is (x/βi)α, and the sum behaves like a convergent infinite geometric series as x→∞
a(x)=xαi=0∑logβxβ−αi∼βα−1βαxα.
For b(x) the recurrence is slightly perturbed
b(x)=f(x)+f(x/β+c)+f(x/β2+c(1+1/β))+⋯
But asymptotically x/βi+O(1)∼x/βi, so each term in the sum is still ∼(x/βi)α, and the same geometric series argument applies. Because α>0, the geometric series is "head-dominated" (the first few terms contribute the most to the sum). The errors introduced by the perturbation c accumulate at the tail end of the series where the terms are small. See the next section of why/how f(x)=xα belongs to the class of functions that permits this reasoning.
Extending the Class of Functions
In order to apply the above logic to a broader class of functions f(x), we would need the following to hold:
The term f(x/βi) behaves like β−αif(x), so we can factor f(x) out of the sum, just like we did with xα.
The perturbation c disappears for large x, since we expect f(x)f(x+c)→1 for this class of functions.
If f(x) is a positive non-decreasing regularly varying function with index ρ∈R (see Definition 4 in the cited paper), meaning
x→∞limf(x)f(γx)=γρ for any γ>0,
then we may assume the previously listed properties. This covers most functions polynomial in x and logx. For example, f(x)=x2logx satisfies this, since
f(γx)=(γx)2log(γx)=γ2x2(logγ+logx)∼γ2x2logx.
Let’s employ the squeeze theorem to prove that we can perturb the arguments without impacting the asymptotic behavior. For any ϵ>0, we can choose x large enough, such that the perturbed argument x+c is eventually "sandwiched" between two constant scalings of x. The rest follows from f being a positive non-decreasing regularly varying function.
A full generalization of this exercise is part of the Akra-Bazzi method, which should be included in the toolbox of techniques for finding asymptotic approximations of recurrences.
Thus, β=2, ν=1, g′(1/2)=−2 and f(1/2)=1, so the approximate solution is an∼2n as before.
The text of the exercise repeats the initial conditions, so we assume that it refers to the example given in section 3.3 of the book with a0=0 and a1=1.
g(z)f(z)=(1−2z)2z.
Thus, β=2, ν=2, g′′(1/2)=8 and f(1/2)=1/2, so the approximate solution is an∼n2n−1 as before.
We have two poles of the same modulus, so we must take the one of highest multiplicity. Thus, β=1, ν=2, g′′(1)=4 and f(1)=1, so the approximate solution is an∼n/2 as expected.
Observe that P(1)=1−t=0 for t>1, thus z=1 isn’t a root. Consequently, the roots of P(z) are exactly the roots of Q(z), excluding z=1. A polynomial Q(z) has multiple roots only if Q(z) and its derivative Q′(z) share a root.
Q′(z)=(t+1)zt−2tzt−1=zt−1[(t+1)z−2t].
The unique roots of the derivative are z=0 and z=t+12t. Apparently Q(0)=1, so z=0 isn’t shared. For the other candidate, we have
We would need (t+12t)tt+12=1. But for all t>1, t+12t>1, so the power term grows exponentially. Therefore, all roots of P(z) are distinct.
Showing that Exactly One Root has Modulus > 1
Because the coefficients of P(z) are real, the singleton dominant root must be a real number. We can verify that P(1)=1−t<0 and P(2)=1>0, hence by the intermediate value theorem, there is a real root in (1,2).
By using Rouché's theorem on the unit disk, we show that the remaining t−1 roots of P(z) lie inside the unit circle ∣z∣≤1; this theorem relates the number of zeros of two functions, f(z) and f(z)+g(z), inside a region. Let’s rearrange the terms of Q(z)
f(z)−2zt+g(z)zt+1+1.
We focus our attention on a circle of radius ∣z∣=1+ϵ (where ϵ is a very small positive number). The magnitudes of our functions on the contour line are:
∣f(z)∣=∣−2zt∣=2(1+ϵ)t≈2+2tϵ
∣g(z)∣≤∣z∣t+1+1=(1+ϵ)t+1+1≈1+(1+(t+1)ϵ)=2+(t+1)ϵ
Since t>1, we have 2t>t+1, thus ∣f(z)∣>∣g(z)∣. By Rouché's theorem, the polynomial Q(z)=f(z)+g(z) has the same number of roots inside the circle ∣z∣=1+ϵ as f(z).
f(z) has a root of multiplicity t at the origin (z=0). Therefore, Q(z) has exactly t roots strictly inside the circle ∣z∣<1+ϵ. Consequently, P(z) has exactly t−1 roots inside the same disk; recall that we must exclude z=1, which was counted for Q(z).
Exercise 18
We need to apply the result from the previous exercise. Since the recurrence formula reflects P(z)=zt–zt–1–…–z–1, we know there is a single root β (approaches 2 as t→∞) of highest modulus. According to Theorem 4.1, FN[t]∼CβN. Wikipedia describes this variant as n-acci sequence and provides a precise expression for the leading term.
Thus, β=1, ν=t and f(1)=1. We need to compute g(t)(1).
Each factor can be written as
1−zdi=(1−z)hi(z),hi(z)=zdi−1+zdi−2+⋯+1.
Apparently, hi(1)=di and g(z)=(1−z)th(z), where h(z)=∏i=1thi(z). Consequently, h(1)=∏i=1tdi. By the general Leibniz rule we have
g(t)(z)=k=0∑t(kt)dzkdk(1−z)t⋅h(t−k)(z).
At z=1 all terms with k<t vanish because dzkdk(1−z)t still contains a factor of 1−z. For k=t we have dztdt(1−z)t=(−1)tt!. Thus,
g(t)(1)=(tt)(−1)tt!h(1)=(−1)tt!i=1∏tdi.
By inserting all components into the formula from Theorem 4.1, we get the required identity of this exercise.
Exercise 20
The Python script below generates the extended table. It uses pandas to produce formatted output.
The code displays the following table:
Exercise 21
Tool support is useful, once the underlying mechanisms are properly understood, to save time and reduce a chance for an error. For example, we can type in WolframAlpha the following command
A more streamlined version would be stated in terms of 1/N, since N−1∼N. By taking x=1/N in the geometric series, we get 1/(N−1)=1/N+1/N2+1/N3+O(N−4). We need to replace the factors involving 1/(N−1) in the above series with the given expansion of 1/(N−1). This gives
N−1NlnN−1N=N1+2N23+6N311+O(N41).
Exercise 24
Let x=0.1, so ln0.9=ln(1−0.1). By using Table 4.2 and expanding each function to within O(x5), we get
2+2x+x2/2+x3/2+x4/3+O(x5).
We should be careful when summing up the terms of a logarithm, due to subtraction and negative value of x. The computed value is 2.20553, which is to within 10−4.
Exercise 25
Observe that 9801=992=(100−1)2, so
98011=(100−1)21=104(1−0.01)21.
Table 4.2 has an expansion of the geometric series. By differentiating both sides of that identity, we get
Vertical bars are used to delineate slots populated with successive natural numbers. Each slot accommodates two digits, enabling this sequence to progress up to the number 97. In other words, we can predict digits in this manner within 100−196. The pattern breaks at the slot with 98, as illustrated below:
The carry from the 100th term impacts the slots containing 98 and 99.
We can generalize this to generate sequences of integers padded to n digits
(10n−1)21=102n(1−10−n)21.
For example, 1/81=0.012345679… (8 is missing due to the carry-over from 9).
Exercise 26
If we apply the nonasymptotic version of Stirling’s formula to describe (N2N), we get
The specific bounds implied by the absolute formula are
7.4749709≤H^1000≤7.4949709
The specific bounds implied by the relative formula are
0≤H^1000≤16.9077553
The LHS is truncated to zero as a negative lower bound is meaningless. The RHS is huge, since the assumed constant is too large. In a relative formula, we expect h(N)=o(1) that should decay rapidly even for small problem sizes.
Recall that O(h(N)) with a constant ∣C∣<10 covers the range ±Ch(N).
Exercise 28
The exact value is T10=16,796.
The specific bounds implied by the relative formula are
0≤T^10≤37,416.
Exercise 29
Let’s split the original recurrence at the threshold value M>0
The derivation uses the gamma function and exponential integral to craft the "closed-form" solution. The last line follows after employing the substitution u=z−N.
Exercise 31
There is a complementary ω-notation for the opposite direction with respect to the o-notation. It denotes a strict lower bound (grows strictly faster than). We use it in our list below:
eN=O(N2) is false, since limN→∞N2eN=∞. We can say that eN=ω(N2).
eN=O(2N) is false (see Exercise 9). We can say that eN=ω(2N).
2−N is exponentially small, so 2−N=O(1/N10) is true (see Exercise 7).
NlnN=O(eln2N) is true, since NlnN=elnNlnN=eln2N.
Exercise 32
The Taylor expansion of ex in terms of x=1/(N+1) is
eN+11=1+N+11+2(N+1)21+O((N+1)31).
We can provide a more streamlined version in terms of 1/N (see also Exercise 23). The book shows the expansion of 1/(N+1)=1/N−1/N2+O(N−3). We need to replace the factors involving 1/(N+1) in the expansion of e1/(N+1) with the given expansion of 1/(N+1). We get
eN+11=1+N1−2N21+O(N−3).
Exercise 33
We can expand the number of terms for HN from Table 4.6. The first approximation to within O(1/N) is
The middle term in the penultimate line must be expanded as 1+x+x2/2, where x is the argument to the exponential function. We must retain the three asymptotically largest components.
Exercise 41
When interest is compounded daily at a 10% annual rate on a $10,000 principal, after 365 days, the amount is $10,000(1+0.1/365)365. Instead of computing this value directly, let’s apply the result from Exercise 39. Here, we have λ=−0.1, so the total amount increases to ≈$10,000×e0.1=$11,051.7. This is about $51.7 more than what would be paid if interest were paid once a year.
The exact formula gives ≈$11,051.6, which is $0.1 less than our quick calculation. This showcases the advantages of using asymptotic approximations.
At this point, we could say that the order of growth of sin(tan(1/N))–tan(sin(1/N)) is O(N−5), but this would be a loose bound. Since the first two terms match, we must expand until we find a difference. Let x=1/N and leverage WolframAlpha to perform the hard work.
series sin(tan(x)) to order 7series tan(sin(x)) to order 7=x+61x3−401x5−100855x7+O(x9)=x+61x3−401x5−5040107x7+O(x9).
Apparently, we have a mismatch at the 4th term, thus the order of growth of sin(tan(1/N))–tan(sin(1/N)) is O(N−7).
Exercise 45
TNHN=πN34N(1+O(1/N))=lnN+γ+O(1/N).
By substituting N=TN into the expansion of HN, we get
HTN=2Nln2−lnπN3+γ+O(1/N).
Exercise 46
This exercise is about the asymptotic expansion of the Lambert W function. The cited article contains the full expansion in terms of substitutions L1 and L2. We depict here the steps leading to the that expression using those symbols.
We derive the basic equation marked with an asterisk
nlnnan=anean=lnan+an=L1−lnan(*).
The first iteration of bootstrapping gives an∼L1. The second iteration gives an∼L1−L2. The third iteration gives
By carrying out one more iteration, we get the equation from the cited article to within the requested accuracy. For the sake of completeness, here is the identity without using symbols L1 and L2
This exercise generalizes the reversion method presented in the book.
We need to provide the reversion of the power series y = c0 + c1x + c2x2 + c3x3 + O(x4). By applying the hint from the book, this equation transform into z=x+c2′x2+c3′x3+O(x4). We already know the reversion of this form from the book:
x=z−c2′z2+(2c2′2−c3′)z3+O(z4).
Now, we just need to express it again in terms of y and the original coefficients
The expansion of x is in powers of the small quantity y−c0, not y itself (unless c0=0). Using purely y is incorrect when c0=0 because y doesn’t tend to zero.
Exercise 48
∑k≥11/k2=π2/6 is known as the Basel problem. According to the direct comparison test, the sum ∑k≥11/(k2Hk) also converges to some constant C. The tail RN can be approximated using the asymptotic expansion of HN∼lnN (see Table 4.6). This gives
RN=k>N∑k2Hk1<k>N∑k2lnk1≈∫N∞x2lnx1dx.
We can estimate RN by using integration by parts to find the leading asymptotic term. Let u=(lnx)−1 and dv=x−2dx. Then du=−x−1(lnx)−2dx and v=−x−1.
so that 1+1/6+1/16.5+1/(3ln3)≈1.53 is already a good approximation to the constant C, just by taking the first 3 terms (together with a correction factor). It is a trivial matter to calculate the value of this constant to any reasonable desired accuracy.
Exercise 49
k=0∑NFk1=ψ−RN.
The infinite sum converges to the reciprocal Fibonacci constantψ. Fibonacci numbers grow exponentially, Fk∼ϕk/5 where ϕ is the golden ratio. Consequently, the terms in the tail decay exponentially and the tail sum can be approximated by a geometric series. Thus, RN=O(ϕ−N).
The definite integral can be computed using WolframAlpha by issuing Integrate[1/(1+x^2),{x,0,1}].
Exercise 55
Let’s use the formula from the book
γ=Hn−lnn−2n1+12n21−120n41.
The following Python script dumps the value of γ accurate to 10 decimal places. By uncommenting (adding) additional correction terms, we can attain the same accuracy in third of the time, since we only need to take seven summands from the harmonic sum.
The fractional arguments of the Riemann zeta function do not have known simple closed forms, like in Exercise 56; they’re typically evaluated numerically.
S2n=k=1∑2nk(−1)k=−k=1∑2nk(−1)k+1(form used on Wikipedia)=k=1∑n2k1−k=1∑n2k−11=k=1∑n2k1−(H2n−k=1∑n2k1)=2⋅21Hn−H2n=Hn−H2n∼−ln2+4n1−16n21+…=−ln2+2N1−4N21+…
When N=2n−1, we have
S2n−1=S2n−2n(−1)2n=S2n−2n1.
Expansion of ∑1≤k≤Nk(−1)k
Let’s start by assuming N=2n. This gives (see also the previous exercise about the expansion of Hn(1/2))
The solution is available on StackExchange for Mathematics. In the cited post, we should assume z≥1, based on the identity from the book involving the generalized binomial coefficient.
Exercise 61
Replace the asymptotic estimate used in the derivation of Theorem 4.5 with the inequality −ln(1+x)≥−x, valid for x≥0. See the proof of the corollary of Theorem 4.5 for context.
Exercise 62
The proofs of the relative bounds for the Ramanujan Q- and R-distributions are literally the same. Stirling’s formula for lnN! is available in Table 4.6 in the book.
Notice that the above approximation is valid only for k=o(N2/3). Under this regime, both Stirling error terms, O(1/N) and O(1/(N−k)), "vanish" for large N. Furthermore, the O(k4/N3) term is absorbed into O(k3/N2).
The R-distribution is handled in an analogous fashion starting with
ln(N+k)!N!Nk=lnN!−ln(N+k)!+klnN.
Exercise 63
The best approach here is to simply reuse a high-quality implementation of the PMF for the binomial distribution. The following Python snippet demonstrates the typical usage scenario.
Exercise 64
If k=N+O(1) then we cannot reach the required accuracy by relying on Theorem 4.6 alone. We must go back to the proof from the book and add more terms to every component in the product. The augmented central binomial coefficient is
22N1(N2N)=πN1(1−8N1+O(N21)).
The extended product of the Ramanujan Q- and R-distributions is
The last two steps follow from substituting k=N+δ, where δ is the displacement (hidden constant inside the O-notation) and expanding ex. Multiplying together the two components, we get
To get an absolute error, we would just distribute the leading term all the way through in the formula above and simplify.
Exercise 65
Exercise 66
This is the case when the binomial distribution can be efficiently approximated by a normal distribution centered at pN (mean). For example, the book already uses such an approximation ∼1/πN/2 with p=1/2 in Figure 4.3. More generally, the estimated probability is
∼2πNpq1.
Exercise 67
The paper The Normal Approximation to the Binomial Distribution shows a full derivation by employing the hint from the book (see section 2); the shift factor k is denoted as δ. At the end, we get a formula similar to the one from Theorem 4.6.
This exercise demonstrates the principles of reuse within mathematics. Rather than constructing analyses from the ground up, it presents a systematic approach to modifying existing work to accommodate varying conditions.
Theorem 4.7 isn’t appropriate here because the mean μ=pN=λN isn’t bounded as N→∞. The previous exercise handles the case when p is fixed. Nonetheless, we can tweak the method from the cited paper to arrive at a different approximation. In other words, the method itself needs to be adapted to a different asymptotic regime.
We list here the recipe for arriving at the final formula:
Our starting point with Stirling's formula is precisely equation (1) in the notes.
The k in this exercise is analogous to δ in the paper. We set x=Np+δ. The standard deviation in our new regime is σ=Npq=Np(1−p)∼λN=λN1/4. So, allowing δ=O(N1/4) is exactly the same as allowing x to deviate by a few standard deviations.
The notes expand ln(Np/x) and ln(Nq/(N−x)) in powers of δ/(Np) and δ/(Nq). Nonetheless, δ/(Np)≫δ/(Nq), hence δ/(Nq) term's higher-order corrections are negligible compared to the former (only the one contributing to the exponent of e matters). Observe that the largest correction O(δ3/(Np)2) cannot hide p, since it isn’t a constant anymore. At any rate, this boils down to O(δ3/N).
The square root pre-factor is
2π(np+δ)(nq−δ)n=2πnpq1(1+npδ)−1/2(1−nqδ)−1/2
Using the Taylor expansion (1+u)−1/2∼1−21u for small u, we get that the dominant correction term becomes O(δ/(Np))=O(δ/N).
After incorporating all previously mentioned changes, we obtain (using k instead of δ)
If k=O(σ) then the relative error is O(N−1/4). If k=O(N1/3) then the error jumps to O(1), so we must have at least k=o(N1/3). Finally, the baseline error term O(N−1/2) covers the edge case k=0.
Exercise 69
This is a variation of the previous exercise, so we don’t repeat all the steps again; the methodology is the same. Let μ=Np=λN/lnN and σ2=Npq=μ(1−p)=μ(1−λ/lnN)∼μ. The following asymptotic holds:
Notice that pk is strictly decreasing as k grows and has the same asymptotic approxmation as the Q-distribution. Hence, by the same arguments as in the proof of Theorem 4.8, together with the solution of the previous exercise, we can confirm the validity of the approximation of P(N).
Exercise 72
The paper On Ramanujan's Q-function by Flajolet et al. elaborates in detail the developments around Q- and R- distributions and provides the proof of this exercise.
Exercise 73
Assume N is even for simplicity (odd N gives the same asymptotic behavior). Let k=N/2±δ with δ=o(N2/3). We know that most of the probability mass will be concentrated around the mean. We can now apply Theorem 4.6 to get
Here, we are only working with binomial coefficients rather than distribution. Therefore, we don’t divide by the normalization factor. By leveraging the Laplace method, similarly as in Theorem 4.8, we can uniformly bundle the diminishing tails (far away from the mean) into a single formula.
For the generalized version of this exercise refer to the article An Asymptotic Formula for Binomial Sums (see the beginning of section 4). A sequence of values of the sum for different N is known as the Franel numbers.
Exercise 74
Wikipedia offers a comprehensive summary of the problem, including the required asymptotic estimate, known as telephone numbers.
Exercise 75 🌟
This exercise demonstrates in detail the Laplace method for sums. There is a related concept called the saddle-point method, that shares the same underlying principle of focusing on areas that asymptotically contribute the most.
To derive the asymptotic estimate for our sum, we use Stirling's approximation (see Table 4.6) to transform the discrete sum into a continuous integral dominated by a single "peak". This is the main idea behind the Laplace method. We start with dissecting the summand
(kN−k)=k!(N−2k)!(N−k)!.
Observe that it’s nonzero for 0≤k≤N/2, so let k=αN with 0≤α≤1/2. Substituting the approximation for each factorial and simplifying, we get
We can find the maximum α0 by typing in WolframAlpha
It outputs α0=1/2−1/(25). At this specific point, ef(α0)=ϕ (golden ratio). To see this, we should just raise e to the maximum value reported by WolframAlpha. The square of this value is ϕ2.
Since the function (kN−k)2 drops rapidly from α0, we can approximate the sum using the Euler-Maclaurin formula. We expand 2Nf(α) as a Taylor series around α0
2Nf(α)≈2Nf(α0)+Nf′′(α0)(α−α0)2.
With the help of WolframAlpha, we can compute symbolically the second derivative and evaluate it at α0
In essence, the Laplace method relies on the fact that as N→∞, the function becomes so incredibly "sharp" at the peak α0 that the tails of the distribution become negligible. Therefore, the error introduced by extending the integration limits to ±∞ is exponentially small. For example, just at some ϵ>0 distance from α0 the contribution decreases to only ϕ2N⋅e−N(55)ϵ2 (see also Exercise 10).
Exercise 76
We’ve a flipped Figure 4.7, where the first lgN terms are negligible, whilst the rest contribute around 1. Using the same bounds as in Theorem 4.10, we get
0≤j≤N∑(1−2j1)N=N−lgN+O(loglogN).
As noted in Theorem 4.10, the error bound can be tightened all the way down to O(1).
Exercise 77
The first tN terms are significant, whilst the rest drops very quickly to zero. For large N, we can approximate this sum with an integral over the whole possible range for j. This gives
Slot: [97] [98] [99] [00] [01]
k = 97: 97
k = 98: 98
k = 99: 99
k = 100: 01 00
k = 101: 01 01
--------------------------------
Result: 97 99 00 01 02 ...
from decimal import Decimal, getcontext
getcontext().prec = 20
def calculate_gamma(n):
h_n = sum(Decimal(1) / Decimal(i) for i in range(1, n + 1))
ln_n = Decimal(n).ln()
# Euler-Maclaurin correction terms from the book.
term1 = Decimal(1) / (Decimal(2) * n)
term2 = Decimal(1) / (Decimal(12) * n ** 2)
term3 = Decimal(1) / (Decimal(120) * n ** 4)
# These are higher-order terms that can be included for speeding things up.
term4 = Decimal(1) / (Decimal(252) * n ** 6)
term5 = Decimal(1) / (Decimal(240) * n ** 8)
# Uncomment the last two terms for faster convergence.
return h_n - ln_n - term1 + term2 - term3 #+ term4 - term5
# Reduce this to 7 if you have uncommented the last two terms for faster convergence.
n_val = 21
result = calculate_gamma(n_val)
print(f"Euler's Constant (γ) ≈ {result:.10f}")
Euler's Constant (γ) ≈ 0.5772156649
from scipy.stats import binom
# Create a binomial distribution object to reuse for different values of k.
dist = binom(n=9, p=0.5)
# Get probability for specific value of k.
print(dist.pmf(3))