# The period of Fibonacci numbers over finite fields

I stumbled upon these very nice looking notes by Brian Lawrence on the period of the Fibonacci numbers over finite fields. In them, he shows that the period of the Fibonacci sequence over $$\mathbb{F}_p$$ divides $$p$$ or $$p-1$$ or $$p+1$$.

I am wondering if there are explicit lower bounds on this period. Is it true, for instance, that as $$p \to \infty$$, so does the order?

A quick calculation on my computer shows that there are some "large" primes with period under 100.

9901 66
19489 58
28657 92

• For $p$ sufficiently large (depending on $N$), the first $N$ Fibonnaci numbers are distinct modulo $p$. Aug 24 '20 at 19:57
• Ah you're right. Might not be able to do any better than that bound then. Aug 24 '20 at 20:09
• @FedorPetrov You need not just $p \mid F_k$ but also $p \mid (F_{k+1}-1)$ since you need $F_k \equiv 0 \bmod p$ and $F_{k+1} \equiv 1 \bmod p$. The first congruence need not imply the second. For example, take $p = 61$. The smallest $k \geq 1$ such that $F_k \equiv 0 \bmod 61$ is $k = 15$, but $F_{16} \equiv 11 \not\equiv 1 \bmod 61$, so the Fibonacci sequence mod $61$ does not have period $15$. The period of $\{F_n \bmod 61\}$ is $60$. Aug 25 '20 at 21:56
• @KConrad ah, sorry, we look for a full period, not only the period of zeroes. You are correct of course. Aug 25 '20 at 21:59
• "the period of the Fibonacci sequence over Fp divides p or p−1 or p+1." This is not true (try $p=5$). An entry divisible by $p$ alone does not make a period. Oct 21 '20 at 14:19

This maybe too elementary for this site, so if your question is closed, you might try asking on MathStackExchange. Many questions about the period can be answered by using the formula $$F_n = (A^n-B^n)/(A-B),$$ where $$A$$ and $$B$$ are the roots of $$T^2-T-1$$. So if $$\sqrt5$$ is in your finite field, then so are $$A$$ and $$B$$, and since $$AB=-1$$, the period divides $$p-1$$ from Fermat's little theorem. If not, then you're in the subgroup of $$\mathbb F_{p^2}$$ consisting of elements of norm $$\pm1$$, so the period divides $$2(p+1)$$. If you want small period, then take primes that divide $$A^n-1$$, or really its norm, so take primes dividing $$(A^n-1)(B^n-1)$$, where $$A$$ and $$B$$ are $$\frac12(1\pm\sqrt5)$$. An open question is in the other direction: Are there infinitely many $$p\equiv\pm1\pmod5$$ such that the period is maximal, i.e., equal to $$p-1$$?

BTW, the source you quote isn't quite correct, if $$p\equiv\pm2\pmod5$$, then the period divides $$2(p+1)$$, but might not divide $$p+1$$. The simplest example is $$p=3$$, where the Fibonacci sequence is $$0,1,1,2,0,2,2,1,\quad 0,1,1,2,0,2,2,1,\ldots.$$ Note that the first 0 does not necessarily mean that it will start to repeat. What happens is that the term before the first $$0$$ is $$p-1$$, so the first part of the sequence repeats with negative signs before you get to a consecutive $$0$$ and $$1$$.

• On the one hand I agree it's probably too elementary, but, on the other hand, I wouldn't have seen this very nice perspective on periods if it hadn't been posted here, so I'm torn. :-) Aug 24 '20 at 20:17
• Sorry everyone; I'm still learning about the etiquette of the forum. I found these notes and found them interesting and wanted to learn more. Thanks for answering my question seriously :) Aug 25 '20 at 20:06
• As @LSpice comments, one might not have realized that such a question is "quasi-elementarizable" in such a decisive manner... Sometimes the decisiveness and elementariness is only visible to a more experienced person, which (to my mind) doesn't mean that the original question was "too easy for MO"... If anything, I am fond of examples where a seemingly innocent (but baffling) question succumbs to a more sophisticated viewpoint. As though such viewpoints not only provide publication fodder, but really do answer questions. :) Aug 31 '20 at 17:50

I won't address your question about how small the period of $$\{F_n \bmod p\}$$ can be as $$p$$ grows, but instead ask if the upper bounds on the period can be achieved infinitely often. For consistency I'll use the notation from Joe Silverman's answer: set $$A = (1 + \sqrt{5})/2$$ and $$B = (1-\sqrt{5})/2$$, so $$F_n = (A^n - B^n)/(A-B) = (A^n - B^n)/\sqrt{5}$$. Note $$A+B = 1$$, $$A - B = \sqrt{5}$$, and $$AB = -1$$.

Claim: For a prime $$p \not= 2$$ or $$5$$, the period of the Fibonacci sequence $$\{F_n \bmod p\}$$ is the smallest even positive integer $$k$$ such that $$A^k = 1$$ in characteristic $$p$$.

This claim involves working in the field $$\mathbf F_p(\sqrt{5})$$, where $$\sqrt{5}$$ is a square root of 5 in characteristic $$p$$, so we can regard $$A = (1+\sqrt{5})/2$$ as a number in the field $$\mathbf F_p(\sqrt{5})$$, which is either $$\mathbf F_p$$ or $$\mathbf F_{p^2}$$. (The notation $$\mathbf F_p$$ and $$\mathbf F_{p^2}$$ are fields of order $$p$$ and $$p^2$$, not having anything to do with the "$$F$$" in Fibonacci number notation.) The claim is saying that $$F_{n+k} \equiv F_n \bmod p$$ for all $$n \geq 0$$ (or just all sufficiently large $$n \geq 0$$) if and only if $$A^k = 1$$ in $$\mathbf F_p(\sqrt{5})$$ for even $$k$$, so the period of $$\{F_n \bmod p\}$$ is the smallest even $$k \geq 1$$ such that $$A^k = 1$$ in $$\mathbf F_p(\sqrt{5})$$.

Proof. View the congruence $$F_{n+k} \equiv F_n \bmod p$$ as an equation $$F_{n+k} = F_n$$ in the subfield $$\mathbf F_p$$ of $$\mathbf F_p(\sqrt{5})$$. The Fibonacci formula $$F_n = (A^n - B^n)/\sqrt{5}$$ in $$\mathbf R$$ is also a valid formula in fields of characteristic $$p$$ when we view $$\sqrt{5}$$ in characteristic $$p$$ and set $$A = (1+\sqrt{5})/2$$ and $$B = (1-\sqrt{5})/2 = 1-A$$ in characteristic $$p$$. In $$\mathbf F_p(\sqrt{5})$$, \begin{align*} F_{n+k} = F_n & \Longleftrightarrow \frac{A^{n+k}-B^{n+k}}{\sqrt{5}} = \frac{A^n-B^n}{\sqrt{5}} \\ & \Longleftrightarrow A^n(A^k-1) = B^n(B^k-1). \end{align*} In a field of characteristic $$p \not= 2$$ or $$5$$, $$A$$ and $$B$$ are nonzero since $$AB = -1$$. Suppose in $$\mathbf F_p(\sqrt{5})$$ that $$A^k \not= 1$$. Then in this field, $$F_{n+k} = F_n \Longrightarrow (A/B)^n = (B^k-1)/(A^k-1).$$ The ratio $$A/B$$ in characteristic $$p$$ is not $$1$$ since $$A = B \Longrightarrow 5 = 0$$ in characteristic $$p$$, which is false since $$p \not= 5$$. Therefore $$(A/B)^n$$ is not constant as $$n$$ varies, but $$(B^k-1)/(A^k-1)$$ is constant as $$n$$ varies. Thus $$A^k = 1$$ in $$\mathbf F_p(\sqrt{5})$$, so $$B^n(B^k-1) = A^n(A^k-1) = 0$$, so $$B^k = 1$$ (we never have $$B^n = 0$$ in characteristic $$p$$). Since $$B^k = (-1/A)^k = (-1)^k/A^k$$, we have $$A^k = 1$$ and $$B^k = 1$$ if and only if $$A^k = 1$$ and $$(-1)^k = 1$$. Since $$-1 \not= 1$$ in characteristic $$p$$ when $$p \not= 2$$, we have $$A^k = 1$$ and $$(-1)^k = 1$$ in $$\mathbf F_p(\sqrt{5})$$ if and only if $$A^k = 1$$ in characteristic $$p$$ and $$k$$ is even.

That completes the proof of the claim.

Since $$B = -1/A$$, if $$A$$ in characteristic $$p$$ has odd order $$m$$ then $$B$$ in characteristic $$p$$ has order $$2m$$. Therefore the claim says the period of $$\{F_n \bmod p\}$$ is the least $$k \geq 1$$ such that $$A^k = 1$$ and $$B^k = 1$$ in characteristic $$p$$: that $$k$$ is necessarily even.

For $$p \not= 2$$ or 5, the field $$\mathbf F_p(\sqrt{5})$$ has order $$p$$ or $$p^2$$ depending on whether or not $$5 \bmod p$$ is a square: its order is $$p$$ when $$p \equiv \pm 1 \bmod 5$$ and its order is $$p^2$$ when $$p \equiv \pm 2 \bmod 5$$. Therefore the group of nonzero elements $$\mathbf F_p(\sqrt{5})^\times$$ has order $$p-1$$ if $$p \equiv \pm 1 \bmod 5$$ and order $$p^2-1$$ if $$p \equiv \pm 2 \bmod 5$$. Since $$p-1$$ and $$p^2-1$$ are both even, the period of $$\{F_n \bmod p\}$$ divides $$p-1$$ if $$p \equiv \pm 1 \bmod 5$$ and it divides $$p^2-1$$ if $$p \equiv \pm 2 \bmod 5$$. As Joe points out in his answer, when $$p \equiv \pm 2 \bmod 5$$ the period of $$\{F_n \bmod p\}$$ divides $$2(p+1)$$, which is a proper factor of $$p^2-1$$.

This situation is reminiscent of Artin's primitive root conjecture, which says that for $$a \in \mathbf Z$$ that is not $$\pm 1$$ or a perfect square, there are infinitely many primes $$p$$ such that $$a \bmod p$$ has order $$p-1$$ in $$\mathbf F_p^\times$$, and in fact there is a positive density of such primes. This conjecture is known to be a consequence of the Generalized Riemann Hypothesis (GRH). This conjecture and its connection to GRH can be extended to number fields, and to talk about the multiplicative order of $$A$$ in characteristic $$p$$ amounts to looking at an analogue of Artin's primitive root conjecture with $$\mathbf Z$$ replaced by $$\mathbf Z[A]$$, which is the ring of integers of $$\mathbf Q(\sqrt{5})$$. This is discussed in Barendrecht's 2018 bachelor's thesis here. For example, GRH implies that the set of (nonzero) prime ideals $$\mathfrak p$$ in $$\mathbf Z[A]$$ such that $$A \bmod \mathfrak p$$ generates all of $$(\mathbf Z[A]/\mathfrak p)^\times$$ has a positive density using the last result of the thesis, Corollary 3.1.2, and therefore there are infinitely many such prime ideals $$\mathfrak p$$ in $$\mathbf Z[A]$$.

Every nonzero prime ideal $$\mathfrak p$$ in $$\mathbf Z[A]$$ is a factor of $$(p) = p\mathbf Z[A]$$ for some prime number $$p$$: if $$p \equiv \pm 1 \bmod 5$$ then $$(p) = \mathfrak p\mathfrak p'$$ for two prime ideals $$\mathfrak p$$ and $$\mathfrak p'$$, and $$\mathbf Z[A]/\mathfrak p$$ and $$\mathbf Z[A]/\mathfrak p'$$ are fields of order $$p$$. If $$p \equiv \pm 2 \bmod 5$$, then $$(p) = \mathfrak p$$ is a prime ideal in $$\mathbf Z[A]$$ and $$\mathbf Z[A]/(p)$$ is a field of order $$p^2$$. When $$p \equiv \pm 2 \bmod 5$$, the multiplicative order of $$A$$ in characteristic $$p$$ is a factor of $$2(p+1)$$, which is less than $$p^2-1$$, so the only prime ideals $$\mathfrak p$$ in $$\mathbf Z[A]$$ for which $$A \bmod \mathfrak p$$ might generate $$(\mathbf Z[A]/\mathfrak p)^\times$$ are prime ideals dividing a prime $$p \equiv \pm 1 \bmod 5$$, in which case we are in the situation that $$A \in \mathbf F_p^\times$$ has order $$p-1$$. Comparing this to the claim up above, since $$p-1$$ is even when $$p > 2$$ we see that GRH implies that there are infinitely many primes $$p \equiv \pm 1 \bmod 5$$ such that $$\{F_n \bmod p\}$$ has period $$p-1$$.

Among the 18 odd primes $$p \equiv \pm 2 \bmod 5$$ with $$p < 150$$, $$\{F_n\bmod p\}$$ has period $$2(p+1)$$ all but 3 times (at $$p = 47$$ $$107$$, and $$113$$). There are many generalizations of the Artin primitive root conjecture and I would not be surprised if one of them can show GRH implies there are infinitely many primes $$p \equiv \pm 2 \bmod 5$$ such that $$\{F_n \bmod p\}$$ has period $$2(p+1)$$, but this is not something I am aware of in more detail at the moment.

The question above is about lower bounds, but I allow myself to comment about upper bounds: $$\pi(n)$$, the period function of the Fibonacci sequence mod $$n$$, satisfies $$\pi(n)\leq 6n$$ and equality holds iff $$n=2\cdot 5^k$$ for some $$k\geq 1$$. This fact is well known. In the 90's it was considered here as a puzzle to the monthly readers. $$\pi(n)$$ was also discussed in an elementary fashion in the 60's in this monthly paper.

But really, I want to share a little observation which forms a generalization of the above mentioned fact: denoting, for an element $$g\in \mathrm{GL}_2(\mathbb{Z})$$, by $$\rho_g(n)$$ the order of the image of $$g$$ in $$\mathrm{GL}_2(\mathbb{Z}/n)$$, $$\rho_g(n)\leq 6n$$. This is a generalization because $$\rho_g(n)=\pi(n)$$ for $$g= \begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}$$. Note that if $$\det(g)=-1$$ then $$\rho_g(n)=2\rho_{g^2}(n)$$, thus it is enough to prove that for $$g\in \mathrm{SL}_2(\mathbb{Z})$$, $$\rho_g(n)\leq 3n$$. Let me now fix $$g\in \mathrm{SL}_2(\mathbb{Z})$$, denote $$\rho(n)=\rho_g(n)$$ and prove that indeed $$\rho(n)\leq 3n$$.

First note that, for natural $$p$$ and $$n$$, if $$p$$ divides $$n$$ then $$\rho(pn)$$ divides $$p\rho(n)$$. This follows by expanding the right hand side of $$g^{p\rho(n)}=(g^{\rho(n)})^p=(1+nh)^p$$ and note that it is 1 mod $$pn$$. By induction we conclude that for every $$k>1$$, $$\rho(p^k)$$ divides $$p^{k-1}\rho(p)$$.

Assume now $$p$$ is a prime and note that $$\rho(p)$$ divides either $$p-1,p+1$$ or $$2p$$. Indeed, if $$\bar{g}\in \mathrm{SL}_2(\mathbb{F}_p)$$ is diagonalizable over $$\mathbb{F}_p$$ then its eigenvalues are in $$\mathbb{F}_p^\times$$ and their orders divides $$p-1$$, else, if $$\bar{g}$$ is diagonalizable over $$\mathbb{F}_{p^2}$$ then its eighenvalues $$\alpha,\beta$$ are conjugated by the Frobenius automorphism, thus their order divides $$p+1$$ because $$\alpha^{p+1}=\alpha\alpha^p=\alpha\beta=\det(\bar{g})=1$$, else $$\bar{g}$$ has a unique eigenvalue, which must be a $$\pm 1$$ by $$\det(\bar{g})=1$$, thus $$\bar{g}^2$$ is unipotent and its order divides $$p$$. For $$p=2$$, in the last case, there was no reason to pass to $$g^2$$, as $$-1=1$$ in $$\mathbb{F}_2$$, thus $$\rho(2)$$ is either 1,2 or 3.

From the above two points, we conclude that for every odd prime $$p$$ and natural $$k$$, $$\rho(p^k)$$ divides $$p^{k-1}(p-1)$$, $$p^{k-1}(p+1)$$ or $$2p^k$$. All these numbers are even and bounded by $$2p^k$$, thus $$\mathrm{lcm}\{\rho(p^k),2\} \leq 2p^k$$. For $$p=2$$ we get that $$\rho(2^k) \leq 2^{k-1}\cdot 3$$.

Fix now an arbitrary natural $$n$$. Write $$n=2^km$$ for an odd $$m$$ and decompose $$m=\prod_{i=0}^r p_i^{k_i}$$. Then \begin{align*} \rho(m)= \mathrm{lcm}\{\rho(p_i^{k_i}) \mid i=0,\dots r\} \leq \mathrm{lcm}\{\mathrm{lcm}\{\rho(p_i^{k_i}),2\} \mid i=0,\dots r\} =\\ 2\mathrm{lcm}\{\frac{\mathrm{lcm}\{\rho(p_i^{k_i}),2\}}{2} \mid i=0,\dots r\} \leq 2\prod_{i=0}^r \frac{\mathrm{lcm}\{\rho(p_i^{k_i}),2\}}{2}\leq 2\prod_{i=0}^r p_i^{k_i} =2m \end{align*} and we get $$\rho(n) = \rho(2^km) \leq \rho(2^k) \cdot \rho(m) \leq 2^{k-1}\cdot 3 \cdot 2m = 3\cdot 2^km=3n.$$

This finishes the proof that $$\rho(n)\leq 3n$$.

As always, it is interesting to analyze the case of equality. For $$g\in \mathrm{SL}_2(\mathbb{Z})$$ we have $$\rho_g(n)=3n$$ for some $$n$$ iff $$\mathrm{tr}(g)$$ is odd and not equal $$-1$$ or $$-3$$. If $$g$$ satisfies this condition, then $$n$$ satisfices $$\rho_g(n)=3n$$ iff $$n=2st$$, for some odd $$s\geq 3$$, $$t\geq 1$$ where every prime factor of $$s$$ divides $$\mathrm{tr}(g)+2$$, every prime factor of $$t$$ divides $$\mathrm{tr}(g)-2$$ and $$g$$ is not $$\pm 1$$ modulo any of these prime factors.

For $$g$$ satisfying $$\det(g)=-1$$, using the identity $$\mathrm{tr}(g^2)=\mathrm{tr}(g)^2-2\det(g)$$, we get that $$\rho_g(n)=6n$$ for some $$n$$ iff $$\mathrm{tr}(g)$$ is odd and in this case, $$n$$ satisfices $$\rho_g(n)=6n$$ iff $$n=2st$$, for some odd $$s\geq 3$$, $$t\geq 1$$ where every prime factor of $$s$$ divides $$\mathrm{tr}(g)+4$$, every prime factor of $$t$$ divides $$\mathrm{tr}(g)$$ and $$g$$ is not $$\pm 1$$ modulo any of these prime factors.

Specifically for $$g=\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}$$, $$\det(g)=-1$$, $$\mathrm{tr}(g)=1$$ is odd, 5 is the only prime factor of $$\mathrm{tr}(g)+4$$ and there is no prime factor for $$\mathrm{tr}(g)$$. Since $$g$$ is not $$\pm 1$$ modulo 5, we get that $$\pi(n)=\rho_g(n)=6n$$ iff $$n=2\cdot 5^k$$ for some $$k\geq 1$$, as claimed above.


# How to generate random integers between 1 and 4 that have a specific mean?

I need to generate 100 random integers in R, where each integer is between 1 and 4 (hence 1,2,3,4) and the mean is equal to a specific value.

If I draw random uniform numbers between 1 and 5 and get floor, I have a mean of 2.5.

x = floor(runif(100,min=1, max=5))

I need to fix the mean to 1.9 or 2.93 for example.

I guess I can generate random integers that add to 100 * mean but I don't know how to restrict to random integers between 1 and 4.

• I think this is a bit under-determined... One for instance can get a mean of 1.9 with sample(size=n, x= 1:4, prob=c(3.666,1,1,1), replace=TRUE) but also with sample(size=n, x= 1:4, prob=c(3,1,1,0.715), replace=TRUE). – usεr11852 Jan 5 at 22:53
• Are you asking how to constrain the mean of the underlying distribution, or the sample mean? – user20160 Jan 5 at 22:53
• tha sample mean @user20160 – Fierce82 Jan 5 at 23:04
• Integers between 1 and 4 only allows for 2 and 3. You also need to specify the distribution that they are drawn randomly from (or make one up). – wolfies Jan 6 at 6:28
• I voted to leave this open because there's an interesting algorithmic question in here--the R part is incidental; you could just as easily implement this in Python or with a pad and some dice. – Matt Krause Jan 6 at 21:14

I agree with X'ian that the problem is under-specified. However, there is an elegant, scalable, efficient, effective, and versatile solution worth considering.

Because the product of the sample mean and sample size equals the sample sum, the problem concerns generating a random sample of $$n$$ values in the set $$\{1,2,\ldots, k\}$$ that sum to $$s$$ (assuming $$n \le s \le kn,$$ of course).

To explain the proposed solution and, I hope, justify the claim of elegance, I offer a graphical interpretation of this sampling scheme. Lay out a grid of $$k$$ rows and $$n$$ columns. Select every cell in the first row. Randomly (and uniformly) select $$s-n$$ of the remaining cells in rows $$2$$ through $$k.$$ The value of observation $$i$$ in the sample is the number of cells selected in column $$i:$$

This $$4\times 100$$ grid is represented by black dots at the unselected cells and colored patches at the selected cells. It was generated to produce a mean value of $$2,$$ so $$s=200.$$ Thus, $$200-100=100$$ cells were randomly selected among the top $$k-1=3$$ rows. The colors represent the numbers of selected cells in each column. There are $$28$$ ones, $$47$$ twos, $$22$$ threes, and $$3$$ fours. The ordered sample corresponds to the sequence of colors from column $$1$$ through column $$n=100.$$

To demonstrate scalability and efficiency, here is an R command to generate a sample according to this scheme. The question concerns the case $$k=4, n=100$$ and $$s$$ is $$n$$ times the desired average of the sample:

tabulate(sample.int((k-1)*n, s-n) %% n + 1, n) + 1

Because sample.int requires $$O(s-n)$$ time and $$O((k-1)n)$$ space, and tabulate requires $$O(n)$$ time and space, this algorithm requires $$O(\max(s-n,n))$$ time and $$O(kn)$$ space: that's scalable. With $$k=4$$ and $$n=100$$ my workstation takes only 12 microseconds to perform this calculation: that's efficient.

(Here's a brief explanation of the code. Note that integers $$x$$ in $$\{1,2,\ldots, (k-1)n\}$$ can be expressed uniquely as $$x = nj + i$$ where $$j \in \{0,1,\ldots, k-2\}$$ and $$i\in\{1,2,\ldots, n\}.$$ The code takes a sample of such $$x,$$ converts them to their $$(i,j)$$ grid coordinates, counts how many times each $$i$$ appears (which will range from $$0$$ through $$k-1$$) and adds $$1$$ to each count.)

Why can this be considered effective? One reason is that the distributional properties of this sampling scheme are straightforward to work out:

• It is exchangeable: all permutations of any sample are equally likely.

• The chance that the value $$x \in\{1,2,\ldots, k\}$$ appears at position $$i,$$ which I will write as $$\pi_i(x),$$ is obtained through a basic hypergeometric counting argument as $$\pi_i(x) = \frac{\binom{k-1}{x-1}\binom{(n-1)(k-1)}{s-n-x+1}}{\binom{n(k-1)}{ s-n}}.$$ For example, with $$k=4,$$ $$n=100,$$ and a mean of $$2.0$$ (so that $$s=200$$) the chances are $$\pi = (0.2948, 0.4467, 0.2222, 0.03630),$$ closely agreeing with the frequencies in the foregoing sample. Here are graphs of $$\pi_1(1), \pi_1(2), \pi_1(3),$$ and $$\pi_1(4)$$ as a function of the sum:

• The chance that the value $$x$$ appears at position $$i$$ while the value $$y$$ appears at position $$j$$ is similarly found as $$\pi_{ij}(x,y) = \frac{\binom{k-1}{x-1}\binom{k-1}{y-1}\binom{(n-1)(k-1)}{s-n-x-y+2}}{\binom{n(k-1)}{ s-n}}.$$

These probabilities $$\pi_i$$ and $$\pi_{ij}$$ enable one to apply the Horvitz-Thompson estimator to this probability sampling design as well as to compute the first two moments of the distributions of various statistics.

Finally, this solution is versatile insofar as it permits simple, readily-analyzable variations to control the sampling distribution. For instance, you could select cells on the grid with specified but unequal probabilities in each row, or with an urn-like model to modify the probabilities as sampling proceeds, thereby controlling the frequencies of the column counts.

• (+1) Ultimate elegance, indeed. – Xi'an Jan 6 at 18:56
• The answer is too difficult for me to follow, appreciate it nonetheless – Fierce82 Jan 7 at 11:33
• What an elegant and beautifully presented answer. If you don't mind my humble suggestion as a reader, you might consider presenting the solution first (the counting patches and the great diagram), and then talking about the implementation and how your argument about how it fits the intuition, and finally why it's efficient. It might make it a bit easier to follow. – Neil G Jan 8 at 8:49
• @Neil Thank you for your suggestion. I think it's a good one and will consider it carefully. – whuber Jan 8 at 15:02
• This is a lovely and satisfying answer. I did want to note that the numbers are small enough in this case (100 numbers summing to 190) that we can calculate the uniform distribution of all values that satisfy. I ran some calculations to compare your distribution against this and found that yours is much much more likely (billions in some cases) to select small non-1 values. For example, your model will almost never give distributions with >45 "ones" (~0.002% chance for 46, vanishing for more), but that comprises ~58% of the uniform model values. – Cireo Jan 31 at 5:29

The question is under-specified in that the constraints on the frequencies \begin{align}n_1+2n_2+3n_3+4n_4&=100M\\n_1+n_2+n_3+n_4&=100\end{align} do not determine a distribution: "random" is not associated with a particular distribution, unless the OP means "uniform". For instance, if there exists one solution $$(n_1^0,n_2^0,n_3^0,n_4^0)$$ to the above system, then the distribution degenerated at this solution is producing a random draw that is always $$(n_1^0,n_2^0,n_3^0,n_4^0)$$.

In the case the question is about simulating a Uniform distribution over the grid\begin{align}n_1+2n_2+3n_3+4n_4&=100M\\n_1+n_2+n_3+n_4&=100\end{align}one can always use a Metropolis-Hastings algorithm. Starting from $$(n_1^0,n_2^0,n_3^0,n_4^0)$$, create a Markov chain by proposing symmetric random perturbations of the vector $$(n_1^t,n_2^t,n_3^t,n_4^t)$$ and accept if the result is within $$\{1,2,3,4\}^4$$ and satisfies the constraints.

For instance, here is a crude R rendering:

cenM=293
#starting point (n¹,n³,n⁴)
n<-sample(1:100,3,rep=TRUE)
while((sum(n)>100)|(n[2]-n[1]+2*n[3]!=cenM-200))
n<-sample(1:100,3,rep=TRUE)
#Markov chain
for (t in 1:1e6){
prop<-n+sample(-10:10,3,rep=TRUE)
if ((sum(prop)<101)&
(prop[2]-prop[1]+2*prop[3]==cenM-200)&
(min(prop)>0))
n=prop}
c(n[1],100-sum(n),n[-1])

with the distribution of $$(n_1,n_3,n_4)$$ over the 10⁶ iterations:

In case you want draws of the integers themselves,

 sample(c(rep(1,n[1]),rep(2,100-sum(n)),rep(3,n[2]),rep(4,n[3])))

is a quick & dirty way to produce a sample.

• thanks. but I cannot understand how i can utilize this to get the 4 integers (between 1 and 4) – Fierce82 Jan 7 at 11:37
• This generates the numbers of 1,2,3,4's $n_1,n_2,n_3,n_4)$ so that there are 100 of them and the sum is cenM. The integer themselves are a random permutation of $n_1$ 1's,..., $n_4$ 4's. – Xi'an Jan 8 at 7:35

I want to ... uh ... "attenuate" @whuber's amazing answer, which @TomZinger says is too difficult to follow. By that I mean I want to re-describe it in terms that I think Tom Zinger will understand, because it's clearly the best answer here. And as Tom gradually uses the method and finds that he needs, say, to know the distribution of the samples rather than just their mean, whuber's answer will be just what he's looking for.

In short: there are no original ideas here, only a simpler explanation.

You'd like to create $$n$$ integers from $$1$$ to $$4$$ with mean $$r$$. I'm going to suggest computing $$n$$ integers from $$0$$ to $$3$$ with mean $$r-1$$, and then adding one to each of them. If you can do that latter thing, you can solve the first problem. For instance, if we want 10 integers between $$1$$ and $$4$$ with mean $$2.6$$, we can write down these $$10$$ integers between $$0$$ and $$3$$...

0,3,2,1,3,1,2,1,3,0

whose mean is $$1.6$$; if we increase each by $$1$$, we get

1,4,3,2,4,2,3,2,4,1

whose mean is $$2.6$$. It's that simple.

Now let's think about the numbers $$0$$ through $$3$$. I'm going to think of those as "how many items do I have in a 'small' set?" I might have no items, one item, two items, or three items. So the list

0,3,2,1,3,1,2,1,3,0

represents ten different small sets. The first is empty; the second has three items, and so on. The total number of items in all the sets is the sum of the ten numbers, i.e., $$16$$. And the average number of items in each set is this total, divided by $$10$$, hence $$1.6$$.

whuber's idea is this: suppose you make yourself ten small sets, with the total number of items being $$10t$$ for some number $$t$$. Then the average size of the sets will be exactly $$t$$. In the same way, if you make yourself $$n$$ sets with a total number of items being $$nt$$, the average number of items in a set will be $$t$$. You say you're interested in the case $$n = 100$$.

Let's make this concrete for your example: you want 100 items between 1 and 4 whose average is $$1.9$$. Using the idea of my first paragraph, I'm going to change this to "make $$100$$ ints between $$0$$ and $$3$$ whose average is $$0.9$$". When I'm done, I'll add $$1$$ to each of my ints to get a solution to your problem. So my target average is $$t = 0.9$$.

I want to make $$100$$ sets, each with between $$0$$ and $$3$$ items in it, with an average set-size of $$0.9$$.

As I've observed above, this means that there have to be a total of $$100 \cdot 0.9 = 90$$ items in the sets. From the numbers $$1, 2, \ldots, 300$$, I'm going to select exactly $$90$$. I can indicate the selected ones by making a list of 300 dots and Xs:

..X....X...XX...

where the list above indicates that I selected the numbers 3, 9, 13, 14, and then many others that I haven't shown because I got sick of typing. :) I can take this sequence of 300 dots and Xs and break it into three groups of 100 dots each, which I arrange one atop the other, getting something that looks like this:

...X....X..X.....X...
.X...X.....X...X.....
..X...X.X..X......X..

but goes on for a full 100 items in each row. The number of Xs in each row might differ -- there might be 35 in the first row, 24 in the second, and 31 in the third, for instance, and that's OK. [Thanks to whuber for pointing out that I had this wrong in a first draft!]

Now look at each column: each column can be considered as a set, and that set has between 0 and 3 "X"s in it. I can write the tallies below the rows to get something like this:

...X....X..X.....X...
.X...X.....X...X.....
..X...X.X..X......X..
011101102003000101100

That is to say, I've produced 100 numbers, each between 1 and 3. And the sum of those 100 numbers must be the number of Xs, total, in all three rows, which was 90. So the average must be $$90/100 = 0.9$$, as desired.

So here are the steps to getting 100 integers between 1 and 4 whose average is exactly $$s$$.

1. Let $$t = s - 1$$.
2. Compute $$k = 100 t$$; that's how many Xs we'll place in the rows, total.
3. Make a list of 300 dots-or-Xs, $$k$$ of which are Xs.
4. Split this into three rows of 100 dots-or-Xs, each containing about a third of the Xs, more or less.
5. Arrange these in an array, and compute column sums, getting 100 integers between $$0$$ and $$3$$. Their average will be $$t$$.
6. Add one to each column sum to get 100 integers between $$1$$ and $$4$$ whose average is $$s$$.

Now the tricky part of this is really in step 4: how do you pick $$300$$ items, $$k$$ of which are "X" and the other $$300-k$$ of which are "."? Well, it turns out that R has a function that does exactly that.

And then whuber tells you how to use it: you write

tabulate(sample.int((k-1)*n, s-n) %% n + 1, n)

For your particular case, $$n = 100$$, and $$s$$, the total number of items in all the small sets, is $$100r$$, and you want numbers between $$1$$ and $$4$$, so $$k = 4$$, so $$k-1$$ (the largest size for a 'small set') is 3, so this becomes

tabulate(sample.int(3*100, 100r-100) %% 100 + 1, n)

or

tabulate(sample.int(3*100, 100*(r-1)) %% 100 + 1, 100)

or, using my name $$t$$ for $$r - 1$$, it becomes

tabulate(sample.int(3*100, 100*t) %% 100 + 1, 100)

The "+1" at the end of his original formula is exactly the step needed to convert from "numbers between $$0$$ and $$3$$" to "numbers between $$1$$ and $$4$$".

Let's work from the inside out, and let's simplify to $$n = 10$$ so that I can show sample outputs:

tabulate(sample.int(3*10, 10*t) %% 10 + 1, 10)

And let's aim for $$t = 1.9$$, so this becomes

tabulate(sample.int(3*10, 10*1.9) %% 10 + 1, 10)

Starting with sample.int(3*10, 10*1.9): this produces a list of $$19$$ integers between $$1$$ and $$30$$. (i.e., it solved the problem of picking $$k$$ numbers out of your total -- $$300$$ in your real problem, $$30$$ in my smaller example).

As you'll recall, we want to produce three rows of ten dots-and-Xs each, something like

 X.X.XX.XX.
XXXX.XXX..
XX.X.XXX..

We can read this left-to-right-top-to-bottom (i.e., normal reading order) to produce a list of locations for Xs: the first item's a dot; the second and third are Xs, and so on, so our list of locations starts out $$1, 3, 5, 6, \ldots$$. When we get to the end of a row, we just keep counting up, so for the picture above, the X-locations would be $$1, 3, 5, 6, 8, 9, 11, 12, 13, 14, 16, 17, 18, 21, 22, 24, 26, 27, 28$$. Is that clear?

Well, whubers code produces exactly that list of locations with its innermost section.

The next item is %% 10; that takes a number and produces its remainder on division by ten. So our list becomes $$1, 3, 5, 6, 8, 9, 1, 2, 3, 4, 6, 7, 8, 1, 2, 4, 6, 7, 8$$. If we break that into three groups --- those that came from numbers between $$1$$ and $$10$$, those that came from numbers from $$11$$ to $$20$$, and those that came from numbers $$21$$ to $$30$$, we get $$1, 3, 5, 6, 8, 9$$, then $$1, 2, 3, 4, 6, 7, 8,$$, and finally $$1, 2, 4, 6, 7, 8$$. Those tell you where the Xs in each of the three rows are. There's a subtle problem here: if there had been an X in position 10 in the first row, the first of our three lists would have been $$1, 3, 5, 6, 8, 9, 0$$, and the tabulate function doesn't like "0". So whuber adds 1 to each item in the list to get $$2, 4, 6, 7, 9, 10, 1$$. Let's move on to the overall computation:

tabulate(sample.int(3*10, 10*1.9) %% 10 + 1, 10)

This asks "for those $$30$$ numbers, each indicating whether there's an X in some column, tell me how many times each column (from $$1$$ to $$10$$ --- that's what the final "10" tells you) appears, i.e., tell me how many Xs are in each column. The result is 0 3 2 2 2 1 3 2 3 1 which (because of the shift-by-one thing) you have to read as "there are no Xs in the 10th column; there are 3 Xs in the first column; there are 2 Xs in the second column," and so on up to "there is one X in the 9th column".

That gives you ten integers between $$0$$ and $$3$$ whose sum is $$19$$, hence whose average is $$1.9$$. If you increase each by 1, you get ten integers between $$1$$ and $$4$$ whose sum is $$29$$, hence an average value of $$2.9$$.

You can generalize to $$n = 100$$, I hope.

• +1 Welcome to our site, John. I appreciate your efforts to explain and clarify these ideas. At one point your description departs from what the code does: one does not divide the three rows into groups of 30 each. Instead, 90 cells out of the 300 cells in those rows are selected. Usually, each row will have a different number of cells. – whuber Jan 7 at 17:15
• Thanks...I actually worried about that a little bit as I wrote it, but I was in mid-sentence, and by the time I was finished, the thought had flown. I'll edit to try to fix it up. – John Jan 7 at 21:25

You can use sample() and select specific probabilities for each integer. If you sum the product of the probabilities and the integers, you get the expected value of the distribution. So, if you have a mean value in mind, say $$k$$, you can solve the following equation: $$k = 1\times P(1) + 2\times P(2) + 3\times P(3) + 4\times P(4)$$ You can arbitrarily choose two of the probabilities and solve for the third, which determines the fourth (because $$P(1)=1-(P(2)+P(3)+P(4))$$ because the probabilities must sum to $$1$$). For example, let $$k=2.3$$, $$P(4)=.1$$, and $$P(3)=.2$$. Then we have that $$k = 1 \times [1-(P(2)+P(3)+P(4)] + 2\times P(2) + 3\times P(3) + 4\times P(4)$$ $$2.3 = [1 - (P(2)+.1+.2)] + 2*P(2) + 3\times .2 + 4\times .1$$ $$2.3 = .7 + P(2) + .6 + .4$$ $$P(2)=.6$$ $$P(1)=1-(P(2)+P(3)+P(4)=1 - (.6+.1+.2)=.1$$

So you can run x <- sample(c(1, 2, 3, 4), 1e6, replace = TRUE, prob = c(.1, .6, .2, .1)) and mean(x) is approximately $$2.3$$

• This explains how to constrain the mean of the distribution. But, the OP specified in the comments that they want to constrain the sample mean (which won't match the mean of the distribution, except in expectation). On the other hand, it seems the OP accepted this answer anyway, so perhaps that's not what they wanted after all. – user20160 Jan 6 at 0:03
• are you sure? @user20160 why sample mean is not contrainted? it's equal to target – Fierce82 Jan 6 at 0:08
• This answer does not provide a way to make the sample mean equal the target value: most of the time the mean will not equal the target. – whuber Jan 6 at 0:10
• @TomZinger Yes. This answer nicely describes how to sample from a distribution with the given target mean. But, the mean of a sample drawn from a distribution will not generally equal the mean of the distribution. – user20160 Jan 6 at 4:59
• I wrote my answer before I saw that comment, but I figured this would be useful anyway. I imagined it would require an integer programming optimization problem to get a sample mean exactly equal to some value. – Noah Jan 6 at 8:20

Here is a simple algorithm: Create $$n-1$$ random integers in the range $$[1,4]$$ and calculate the $$n^{th}$$ integer for the mean to be equal to the specified value. If that number is smaller than $$1$$ or larger than $$4$$, then one by one distribute the surplus/lacking onto other integers, e.g. if the integer is $$5$$, we have $$1$$ surplus; and we may add this to the next integer if it's not $$4$$, else add to the next etc. Then, shuffle the entire array.

• One big problem with this proposal is that it doesn't come along with any indication of what the expected frequencies of the resulting values are. – whuber Jan 5 at 23:32
• Although interesting, I thought the OP only requires an algorithm to generate the desired array of integers in a non-deterministic manner. – gunes Jan 5 at 23:37
• I think that avoids the essence of the question rather than providing a satisfactory answer. A good answer should be able to characterize the distribution it proposes in a meaningful way, such as by giving a formula for the probabilities or at least giving the first couple of moments. – whuber Jan 5 at 23:46
• A minor adjustment of the simulated data is likely 'proper', however, looking at the expertimental design in cases where more significant mean deviation is required, depending on the intended purpose, could be, from a hypothesis testing perspective, 'suspect', in my judgement. Either over or under loading a random design to justify or reject possible non-random effects that have been actually observed can be questionable practice. So, any method that makes a very small adjustment to the last of say a 100 observations is probably keeping in good practice, in my opinion. – AJKOER Jan 7 at 17:33

As a supplement to whuber's answer, I've written a script in Python which goes through each step of the sampling scheme. Note that this is meant for illustrative purposes and is not necessarily performant.

Example output:

n=10, s=20, k=4

Starting grid
. . . . . . . . . .
. . . . . . . . . .
. . . . . . . . . .
X X X X X X X X X X

Filled in grid
X X . . X . X . . X
. . X X X . . . . .
. . . . X X . . . .
X X X X X X X X X X

Final grid
X X . . X . X . . X
. . X X X . . . . .
. . . . X X . . . .
X X X X X X X X X X
2 2 2 2 4 2 2 1 1 2

The script:

import numpy as np

# Define the starting parameters
integers = [1, 2, 3, 4]
n = 10
s = 20
k = len(integers)

def print_grid(grid, title):
print(f'\n{title}')
for row in grid:
print(' '.join([str(element) for element in row]))

# Create the starting grid
grid = []
for i in range(1, k + 1):
if i < k:
grid.append(['.' for j in range(n)])
else:
grid.append(['X' for j in range(n)])

# Print the starting grid
print_grid(grid, 'Starting grid')

# Randomly and uniformly fill in the remaining rows
indexes = np.random.choice(range((k - 1) * n), s - n, replace=False)
for i in indexes:
row = i // n
col = i % n
grid[row][col] = 'X'

# Print the filled in grid
print_grid(grid, 'Filled in grid')

# Compute how many cells were selected in each column
column_counts = []
for col in range(n):
count = sum(1 for i in range(k) if grid[i][col] == 'X')
column_counts.append(count)
grid.append(column_counts)

# Print the final grid and check that the column counts sum to s
print_grid(grid, 'Final grid')
print()
print(f'Do the column counts sum to {s}? {sum(column_counts) == s}.')

I've turned whuber's answer into an r function. I hope it helps someone.

• n is how many integers you want;
• t is the mean you want; and
• k is the upper limit you want for your returned values
whubernator<-function(n=NULL, t=NULL, kMax=5){
z = tabulate(sample.int(kMax*(n), (n)*(t),replace =F) %% (n)+1, (n))
return(z)
}

It seems to work as expected:

> w = whubernator(n=10,t=4.2)
> mean(w)
[1] 4.2
> length(w)
[1] 10
> w
[1] 3 5 3 5 5 3 4 5 5 4

It can return 0s, which matches my needs.

> whubernator(n=2,t=0.5)
[1] 1 0

New contributor
gruvn is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.


# Homework Help: Complex integer expression problem

1. Feb 23, 2006

### Werg22

If n is a positive integer such as

$$2{\leq}n{\leq}80$$

For how many values the expression $$\frac{(n+1)n(n-1)}{8}$$ takes positive and integer values?

I solved it that way...

$$\frac{(n+1)n(n-1)}{8}=\frac{(n^{2}-1)n}{8}$$

(n^2 - 1)n must have 8 as one of its factor.

Either n is a multiple of 8, or n^2 - 1 is. Also the case were n^2 - 1 has 4 as one of its factors, n having 2, and vice-versa, is impossible - if n^2 - 1 is even, n is odd, and vice-versa.

So every mutliple of 8 up to 80 is a possible value. So there is 10 values.

Let's list those numbers

8, 16 , 24 , 32 , 40 , 48 , 56 , 64 , 72, 80

Add one to each one of these values

9, 17, 25, 33, 41, 49, 65 , 73, 81

There is 4 perfect square in this list. So if n^2 - 1 is a multiple of 8, then there is 4 possible values for n.

10 + 4 = 14

So 14 possibilities in total. But the true awnser is not what I found. What is wrong in my reasoning?

2. Feb 23, 2006

### 0rthodontist

There's no guarantee that n^2 - 1 lies between 9 and 81. It could be much larger.

3. Feb 23, 2006

### Werg22

Right! Thanks. In that case any other way to solve this?

4. Feb 23, 2006

### 0rthodontist

Well since you are only looking up to 80 you can calculate them all directly, only takes a couple minutes to set things up. Also from observing that data it seems that every n yields an integer n(n+1)(n-1)/8 except for even integers that are not divisible by 8, so maybe you could break it down into parts. Every multiple of 8 yields an integer. And if x is a multiple of 2, and x is not itself divisible by 8, then x does not yield an integer because its adjacent integers are not even disible by 2. And every odd integer must yield an integer because its adjacent integers are both even, and one of the adjacent integers must also be divisible by 4.

Last edited: Feb 23, 2006
5. Feb 23, 2006

### Werg22

Ok. Since n^2 - 1 = (n-1)(n+1)

n - 1 must be a multiple of 8, or n+1 be a multiple of 8, or n - 1 be a multiple of 4, or n + 1 be a multiple of 4.

For exactly 10 values, n is multiple of 8

For exactly 10 values, n-1 is a multiple of 8.
For exactly 10 values, n+1 is a multiple of 8.

For exactly 20 values, n-1 is multiple of 4. Half of these being multiples of 8. So we count 10.
For exactly 20 values, n+1 is a multiple of 8. Half of these being multiples of 8. So we count 10.

So 10*5=50

The awnser is 50.

6. Feb 23, 2006

### AKG

I believe the answer is 49. You seem to be going about it in a very complicated way.

Case 1: n is odd
Then both n-1 and n+1 are even. Moreover, one of them (and in fact, only one of them) is a multiple of four. This is clear since if n is odd, then either n = 1 (mod 4) in which case n-1 = 0 (mod 4) and n+1 = 2 (mod 4), or n = 3 (mod 4) in which case n-1 = 2 (mod 4) and n+1 = 0 (mod 4). So since one of n-1 and n+1 is a multiple of four, and the other is even, the whole product (n-1)n(n+1) is a multiple of 8. So every odd n between 2 and 80 will do, and there are 39 such numbers.

Case 2: n is even
Then both n-1 and n+1 is odd, so if 8 | (n-1)n(n+1), then 8 | n, so the only even n's that work are multiples of 8. They are:

8, 16, 24, 32, 40, 48, 56, 64, 72, 80

That's 10, giving a total of:

49.

One problem with your solution is that n-1 is a multiple of 8 for only 9 values of n. Note that n-1 ranges from 1 to 79. n ranges from 2 to 80. n-1 will never be 80, so its missing one multiple of 8. That's where you're counting your extra one. Note also that there are only 19 values of n-1 which are a multiple of 4, 9 of which are multiples of 8, so when you subtract 9 from 19, you do still end up getting 10. Originally, you subtracted 10 from 20. You ended up with the right number, 10, but they way you got it was wrong.

7. Feb 24, 2006

### Werg22

Okay, I see. Thanks.


Does $\sum\limits_n \log\left(1+{1\over n}\right)$ diverge or converge?

How do I find out if $\sum\limits_n\log(1+{1\over n})$ diverges or converges? Wolfram recommends me to use comparison test, but I do not know series which diverges and less than this.

• One can use Limit Comparison with $\sum \frac{1}{n}$. – André Nicolas Jan 3 '15 at 15:37

Wolfram recommends me to use (some) compar(is)on test, but I do not know (any) series which diverges and (is) less than this (one).

$$\log\left(1+\frac1n\right)\geqslant\frac1{2n}$$

$$\sum_{n=1}^{N}\log\left(1+\frac{1}{n}\right)=\log\prod_{n=1}^{N}\frac{n+1}{n}=\log(N+1).$$

If you want to use a comparison, notice that since $f(t)=\frac{1}{t}$ is a convex function on $\mathbb{R}^+$, we have: $$\log\left(1+\frac{1}{n}\right)=\int_{n}^{n+1}\frac{dt}{t}\geq\frac{1}{n+1/2}$$ by Jensen's inequality, hence: $$\sum_{n=1}^{N}\log\left(1+\frac{1}{n}\right)\geq 2\sum_{n=1}^{N}\frac{1}{2n+1} = 2H_{2n+1}-H_n.$$

Since

$$\sum_{n = 1}^N \log\left(1 + \frac{1}{n}\right) = \sum_{n = 1}^N \log\left(\frac{n+1}{n}\right) = \sum_{n = 1}^N [\log(n+1) - \log(n)] = \log(N+1) \to \infty$$

the series $\sum_{n = 1}^\infty \log\left(1 + \frac{1}{n}\right)$ diverges.

note $$\ln{\left(1+\dfrac{1}{n}\right)}=\dfrac{1}{n}+o(1/n)$$ since $$\sum_{n=1}^{\infty}\dfrac{1}{n}$$ is diverges

so $$\sum_{n=1}^{\infty}\ln{\left(1+\dfrac{1}{n}\right)}$$ is also diverges

• First statement isn't obvious to me. – Dark Archon Jan 3 '15 at 16:10
• do you know $\ln{(1+x)}=x+o(x)?$ – math110 Jan 3 '15 at 16:11
• What is $o(x)$? – Dark Archon Jan 3 '15 at 16:13
• $x=\dfrac{1}{n}$ when $n\to +\infty$,then $x\to 0$ – math110 Jan 3 '15 at 16:25
• @DarkArchon $f(x)=o(x)$ means that $\lim_{x\to 0}f(x)/x=0$. – Andrés E. Caicedo Jan 4 '15 at 0:52

The first natural idea to understand how $\log(1+1/n)$ behaves when $n$ is small is to do Taylor expansion around $x=0$ for $\log(1+x)$, so that you have estimates for $\log(1+x)$. Then you get $$\log(1+x) = \sum_{n \ge 1} \frac{(-1)^{n+1}}{n}x^n = x - x^2/2 + x^3/3 - \cdots,$$ by integrating the geometric series (and switching a minus sign) and by Taylor's theorem you get that there exists $1 \le \zeta \le x$ such that $$\log(1+x) = x-\frac{\zeta^2}2 \ge x - \frac {x^2}2 = \frac{2x-x^2}2 = \frac{x(2-x)}2 \ge \frac x2$$ for $0 \le x \le 1$ (because $\frac{x(1-x)}2 \ge 0$ on this interval).

A variant of this idea is to check that $\log$ is a concave function (the derivatives are $\frac 1x$ and $\frac {-1}{x^2}$), hence we can use Jensen's inequality : for all $\lambda \in [0,1]$, $$\log(\lambda x + (1-\lambda) y) \ge \lambda \log(x) + (1-\lambda) \log(y)$$ so that for $y=1$ and $x=2$, we get $$\log(1+ \lambda) \ge \lambda \log(2).$$ In both cases, we established an inequality of the form $\log(1+x) \ge cx$ for $x \in [0,1]$, which means $\log(1+1/n) \ge \frac cn$, hence your series diverges.

Hope that helps,

Another way to think of this problem is that $\sum log(1+1/n)$ = $\log \prod(1+1/n)$ = $\log \prod((n+1)/n)$, which goes to infinity. Thus the sum diverges.

• Already explained on the page, twice. – Did May 11 '15 at 5:21


# A problem about the limit of an integral

Let $g(x)$ be a continuous periodic function of period 1 on $\mathbb{R}$. Prove that for any integrable function $f(x)$ on $[0,1]$,
$$\lim_{n \to \infty}\int_0^{1}f(x)g(nx)dx= \int_0^{1}f(x)dx \int_0^{1}g(x)dx.$$

Any help is appreciated.

-

Begin with a transformation $u=nx.$

$$\int_{0}^1 f(x)g(nx)dx = \frac{1}{n} \int_{0}^n f(u/n)g(u)du.$$

Break the integrand up into a sum of intervals.

$$\frac{1}{n} \int_{0}^n f(u/n)g(u)du=\frac{1}{n}\sum_{j=1}^n\int_{j-1}^{j} f(u/n)g(u)du.$$

Make another variable transformation: $v=u-(j-1).$ Because $g(u)$ is 1 periodic $g(u)=g(u+1)=g(u+j-1).$

$$\frac{1}{n}\sum_{j=1}^n\int_{j-1}^{j} f(u/n)g(u)du = \frac{1}{n}\sum_{j=1}^n\int_{0}^{1} f \left(\frac{u-(j-1)}{n} \right)g(u-(j-1))du$$

Rearrange the terms. $$\frac{1}{n}\sum_{j=1}^n\int_{0}^{1} f\left(\frac{u-(j-1)}{n} \right)g(u-(j-1))du =\int_{0}^1 \left(\frac{1}{n} \sum_{j=1}^n f \left(\frac{u-(j-1)}{n} \right)\right)g(u)du .$$

We have now produced a Riemann sum which converges to an integral in the limit. We are now allowed, by dominated convergence theorem, to say

\begin{align*} \lim_{n\to \infty} \int_{0}^1 f(x)g(nx)dx &= \int_{0}^1 \left(\int_{0}^1 f(z)dz\right) g(u)du \\ &=\int_{0}^1 f(z)dz\int_{0}^1 g(u)du=\int_{0}^1 f(x)dx\int_{0}^1 g(x)dx . \end{align*}

-
Thank you so much. – Sume Aug 10 '11 at 3:28

this is not a good proof, just an idea. First consider f to be simple function, we can calculate that this identity holds. Then by the definition of Lebesgue integration, we can approximate f by simple functions. Because g is continuous(bounded), so there's no problem for the left hand side to converge.

-

Ok. I have seen this problem in the book: Principles of Real Analysis by C.D.Aliprantis and O.Burkinshaw, and since I knew that this book has a solution manual, I went and searched over there and got the solution. The problem given in the book is as follows:

$\textbf{Problem.}$ Let $f:(0,\infty) \to \mathbb{R}$ be a real-valued continuous function such that $f(x+1)=f(x)$ for all $x \geq 0$. If $g:[0,1] \to \mathbb{R}$ is an arbitrary continuous function, then show that $$\lim_{n \to \infty} \ \int\limits_{0}^{1} g(x) \cdot f(nx) \ dx = \Biggl( \ \ \int\limits_{0}^{1} g(x) \ dx \Biggr) \cdot \Biggl( \ \ \int\limits_{0}^{1} f(x) \ dx\Biggr)$$

$\textbf{Solution.}$ Please see the book: Problems in real analysis a workbook with solutions Problem 23.14 Page $\textbf{205}$ for a complete solution.

-


Name:
Andrew ID:
Collaborated with:

This lab is to be done in class (completed outside of class if need be). You can collaborate with your classmates, but you must identify their names above, and you must submit your own lab as an knitted HTML file on Canvas, by Tuesday 10pm, this week.

This week’s agenda: creating and updating functions; understanding argument and return structures; revisiting Shakespeare’s plays; code refactoring.

# Huber loss function

The Huber loss function (or just Huber function, for short) is defined as: $\psi(x) = \begin{cases} x^2 & \text{if |x| \leq 1} \\ 2|x| - 1 & \text{if |x| > 1} \end{cases}$ This function is quadratic on the interval [-1,1], and linear outside of this interval. It transitions from quadratic to linear “smoothly”, and looks like this:

It is often used in place of the usual squared error loss for robust estimation. The sample average, $$\bar{X}$$—which given a sample $$X_1,\ldots,X_n$$ minimizes the squared error loss $$\sum_{i=1}^n (X_i-m)^2$$ over all choices of $$m$$—can be inaccurate as an estimate of $$\mathbb{E}(X)$$ if the distribution of $$X$$ is heavy-tailed. In such cases, minimizing Huber loss can give a better estimate. (Interested in hearing more? Come ask Tudor or I!)

• 1a. Write a function huber() that takes as an input a number $$x$$, and returns the Huber value $$\psi(x)$$, as defined above. Hint: the body of a function is just a block of R code, i.e., in this code you can use if() and else() statements. Check that huber(1) returns 1, and huber(4) returns 7.

• 1b. The Huber function can be modified so that the transition from quadratic to linear happens at an arbitrary cutoff value $$a$$, as in: $\psi_a(x) = \begin{cases} x^2 & \text{if |x| \leq a} \\ 2a|x| - a^2 & \text{if |x| > a} \end{cases}$ Starting with your solution code to the last question, update your huber() function so that it takes two arguments: $$x$$, a number at which to evaluate the loss, and $$a$$ a number representing the cutoff value. It should now return $$\psi_a(x)$$, as defined above. Check that huber(3, 2) returns 8, and huber(3, 4) returns 9.

• 1c. Update your huber() function so that the default value of the cutoff $$a$$ is 1. Check that huber(3) returns 5.

• 1d. Check that huber(a = 1, x = 3) returns 5. Check that huber(1, 3) returns 1. Explain why these are different.

• 1e. Vectorize your huber() function, so that the first input can actually be a vector of numbers, and what is returned is a vector whose elements give the Huber evaluated at each of these numbers. Hint: you might try using ifelse(), if you haven’t already, to vectorize nicely. Check that huber(x = 1:6, a = 3) returns the vector of numbers (1, 4, 9, 15, 21, 27).

• Challenge. Your instructor computed the Huber function values $$\psi_a(x)$$ over a bunch of different $$x$$ values, stored in huber_vals and x_vals, respectively. However, the cutoff $$a$$ was, let’s say, lost. Using huber_vals, x_vals columns of oops_df, and the definition of the Huber function, you should be able to figure out the cutoff value $$a$$, at least roughly. Estimate $$a$$ and explain how you got there. Hint: one way to estimate $$a$$ is to do so visually, using plotting tools (if you do - please use ggplot); there are other ways too.

oops_df <- data.frame(
x_vals = seq(0, 5, length=21),
huber_vals = c(0.0000, 0.0625, 0.2500, 0.5625, 1.0000, 1.5625, 2.2500,
3.0625, 4.0000, 5.0625, 6.2500, 7.5625, 9.0000, 10.5000,
12.0000, 13.5000, 15.0000, 16.5000, 18.0000, 19.5000,
21.0000))

# Shakespeare’s complete works

Recall, as in lab/hw from Week 1, that the complete works of William Shakespeare are available freely from Project Gutenberg. We’ve put this text file up at https://raw.githubusercontent.com/benjaminleroy/36-350-summer-data/master/Week1/shakespeare.txt.

# Getting lines of text play-by-play

• 2a. Below is the get_wordtab_from_url() from lecture. Modify this function so that the string vectors lines and words are both included as named components in the returned list. For good practice, update the documentation in comments to reflect your changes. Then call this function on the URL for the Shakespeare’s complete works (with the rest of the arguments at their default values) and save the result as shakespeare_wordobj. Using head(), display the first several elements of (definitely not all of!) the lines, words, and wordtab components of shakespeare_wordobj, just to check that the output makes sense to you.
#' Get a word table from text on the web
#'
#' @param str_url string, specifying URL of a web page
#' @param split string, specifying what to split on. Default is the regex
#' pattern "[[:space:]]|[[:punct:]]"
#' @param tolower Boolean, TRUE if words should be converted to lower case
#' before the word table is computed. Default is TRUE
#' @param keep_nums Boolean, TRUE if words containing numbers should be kept in
#' the word table. Default is FALSE
#'
#' @return list, containing word table, and then some basic numeric summaries
#'
#' @examples
#' endgame_speech_list <- get_wordtab_from_url(
#'  paste0("https://raw.githubusercontent.com/benjaminleroy/",
#'  "36-350-summer-data/master/Week1/endgame.txt"))
get_wordtab_from_url <- function(str_url, split = "[[:space:]]|[[:punct:]]",
tolower = TRUE,
keep_nums = FALSE) {
text <- paste(lines, collapse = " ")
words <- strsplit(text, split = split)[[1]]
words <- words[words != ""]

# Convert to lower case, if we're asked to
if (tolower) {
words <- tolower(words)
}

# Get rid of words with numbers, if we're asked to
if (!keep_nums) {
words <- grep("[0-9]", words, inv = TRUE, val = TRUE)
}

# Compute the word table
wordtab <- table(words)

return(list(wordtab = wordtab,
number_unique_words = length(wordtab),
number_total_words = sum(wordtab),
longest_word = words[which.max(nchar(words))]))
}
• 2b. Go back and look Q5 of Homework 1, where you located Shakespeare’s plays in the lines of text for Shakespeare’s complete works. Set shakespeare_lines <- shakespeare_wordobj$lines, and then rerun your solution code (or the rerun the official solution code, if you’d like) for questions Q5a–Q5f of Homework 1, on the lines of text stored in shakespeare_wordobj$lines. You should end up with two vectors titles_start and titles_end, containing the start and end positions of each of Shakespeare’s plays in shakespeare_lines. Print out titles_start and titles_end to the console.

• 2c. Create a list shakespeare_lines_by_play of length equal to the number of Shakespeare’s plays (a number you should have already computed in the solution to the last question). Using a for() loop, and relying on titles_start and titles_end, extract the subvector of shakespeare_lines for each of Shakespeare’s plays, and store it as a component of shakespeare_lines_by_play. That is, shakespeare_lines_by_play[[1]] should contain the lines for Shakespeare’s first play, shakespeare_lines_by_play[[2]] should contain the lines for Shakespeare’s second play, and so on. Name the components of shakespeare_lines_by_play according to the titles of the plays.

# Getting word tables play-by-play

• 3a. Define a function get_wordtabfrom_lines() to have the same argument structure as get_wordtab_from_url(), which recall you last updated in Q2a, except that the first argument of get_wordtab_from_lines() should be lines, a string vector passed by the user that contains lines of text to be processed. The body of get_wordtab_from_lines() should be the same as get_wordtab_from_url(), except that lines is passed and does not need to be computed using readlines(). The output of get_wordtab_from_lines() should be the same as get_wordtab_from_url(), except that lines does not need to be returned as a component. For good practice, incude documentation for your get_wordtab_from_lines() function in comments (no need to include an example).

• 3b. Using a for() loop or one of the apply functions (your choice here), run the get_wordtab_from_lines() function on each of the components of shakespeare_lines_by_play, (with the rest of the arguments at their default values). Store the result in a list called shakespeare_wordobj_by_play. That is, shakespeare_wordobj_by_play[[1]] should contain the result of calling this function on the lines for the first play, shakespeare_wordobj_by_play[[2]] should contain the result of calling this function on the lines for the second play, and so on.

• 3c. Using one of the apply functions, compute numeric vectors shakespeare_total_words_by_play and shakespeare_unique_words_by_play, that contain the number of total words and number of unique words, respectively, for each of Shakespeare’s plays. Each vector should only require one line of code to compute. Hint: "[["() is actually a function that allows you to do extract a named component of a list; e.g., try "[["(shakespeare_wordobj, "number_total_words"), and you’ll see this is the same as shakespeare_wordobj[["number_total_words"]]; you should take advantage of this functionality in your apply call. What are the 5 longest plays, in terms of total word count? The 5 shortest plays?

# Refactoring the word table functions

• 4. Look back at get_wordtab_from_lines() and get_wordtab_from_url(). Note that they overlap heavily, i.e., their bodies contain a lot of the same code. Redefine get_wordtab_from_url() so that it just calls get_wordtab_from_lines() in its body. Your new get_wordtab_from_url() function should have the same inputs as before, and produce the same output as before. So externally, nothing will have changed; we are just changing the internal structure of get_wordtab_from_url() to clean up our code base (specifically, to avoid code duplication in our case). This is an example of code refactoring.

Call your new get_wordtab_from_url() function on the URL for Shakespeare’s complete works, saving the result as shakespeare_wordobj2. Compare some of the components of shakespeare_wordobj2 to those of shakespeare_wordobj (which was computed using the old function definition) to check that your new implementation works as it should.

• Challenge. Check using all.equal() whether shakespeare_wordobj and shakespeare_wordobj2 are the same. Likely, this will not return TRUE. (If it does, then you’ve already solved this challenge question!) Modify your get_wordtab_from_url() function from the last question, so that it still calls get_wordtab_from_lines() to do the hard work, but produces an output exactly the same as the original shakespeare_wordobj object. Demonstrate your success by calling all.equal() once again.


# Math Help - [SOLVED] Finding Co-Ordinates of a Rectangle

1. ## [SOLVED] Finding Co-Ordinates of a Rectangle

Here's a question from a past paper which I have successfully attempted. My question is regarding part (iii). I have successfully figured out the co-ordinates by the following method:

Is my method correct, considering I did get the right answer?

But is there another simpler method to do this which would save time during an exam.

2. The diagonals bisect one another. The midpoint of $\overline{AC}$ is ?

3. Mid of AC is (6,6), the diagnols do bisect each other at the mid but we don't have the x-co-ordinates of B or D to equate the diagnols, or do we?

4. Originally Posted by unstopabl3
Mid of AC is (6,6), the diagnols do bisect each other at the mid but we don't have the x-co-ordinates of B or D to equate the diagnols, or do we?
But the y-coordinate of $B~\&~D$ is 6.
You are given the x-coordinate of $D$, so $Dh,6)" alt="Dh,6)" />

5. No, I meant real value of the x-co-ordinates has not been given since we have to calculate that ourselves.

I have already gotten the correct values by using the method mentioned in my first post.
As stated I want someone to solve this part of the question with a different, possibly easier method.

I am not after the answer, I am looking for an alternate method.

6. Originally Posted by unstopabl3
No, I meant real value of the x-co-ordinates has not been given since we have to calculate that ourselves.

I have already gotten the correct values by using the method mentioned in my first post.
As stated I want someone to solve this part of the question with a different, possibly easier method.

I am not after the answer, I am looking for an alternate method.
Hi unstopabl3,

I really don't see what method you used in your first post, but here's how I'd do it.

Plato already told you that the midpoint of BD is M(6, 6).

This means the y-coordinates of B and D are also 6.

This distance from B to D is 20 (found using distance formula)

Each individual segment of the diagonals measure 10 since they are bisected.

Using the distance formula, it is easy to determine the x-coordinates of B and D.

M(6, 6) -----> D(h, 6) = 10

$10=\sqrt{h-6)^2+(6-6)^2}$

7. Hello, unstopabl3!

Code:
              |           C(12,14)
|           o
|       *    *
|   *         *
*              *
B o - + - - - - - - - o D
*  |           *
------*-+-------*------------
*|   *
o
A|(0,-2)
|

The diagram shows a rectangle $ABCD.$
We have: . $A(0,-2),\;C(12,14)$
The diagonal $BD$ is parallel to the $x$-axis.

$(i)$ Explain why the $y$-coordinate of $D$ is 6.
The diagonals of a rectangle bisect each other.
. . Hence, the midpoint of $AC$ is the midpoint of $BD.$

The midpoint of AC is: . $\left(\tfrac{0+12}{2},\;\tfrac{-2+14}{2}\right) \:=\:(6,6)$

Therefore, $B$ and $D$ have a $y$-coordinate of 6.

The $x$-coordinate of $D$ is $h.$
$(ii)$ Express the gradients of $AD$ and $CD$ in terms of h,.
We have: . $\begin{Bmatrix}A(0, -2) \\ C(12,14) \\ D(h,\;6) \end{Bmatrix}$

$m_{AD} \;=\;\frac{6(-2)}{h-9} \;=\;\frac{8}{h}$

$m_{CD} \;=\;\frac{6-14}{h-12} \;=\;\frac{-8}{h-12}$

$(iii)$ Calculate the $x$-coordinates of $D$ and $B.$

Since $m_{AD} \perp m_{CD}$ we have: . $\frac{8}{h} \;=\;\frac{h-12}{8} \quad\Rightarrow\quad h^2-12h - 64 \:=\:0$

Hence: . $(h+4)(h-16) \:=\:0 \quad\Rightarrow\quad h \:=\:-4,\:16$

Therefore: . $D(16,6),\;B(-4,6)$

8. Originally Posted by masters
Hi unstopabl3,

I really don't see what method you used in your first post, but here's how I'd do it.

$10=\sqrt{h-6)^2+(6-6)^2}$
I use the concept of the product of two perpendicular lines = -1
You can see the working in the Soroban's post. That's exactly how I did it!

This distance from B to D is 20 (found using distance formula)
How did you get this with only the Y co-ordinates known for both? Did you get the distance of AC which should be equal to BD?

Soroban, thanks for your post, but I've already used that method to solve this problem and already mentioned it in my first post that I am looking for alternative methods to solve it! Thanks nonetheless!

9. Originally Posted by unstopabl3
I use the concept of the product of two perpendicular lines = -1
You can see the working in the Soroban's post. That's exactly how I did it!

How did you get this with only the Y co-ordinates known for both? Did you get the distance of AC which should be equal to BD?

Soroban, thanks for your post, but I've already used that method to solve this problem and already mentioned it in my first post that I am looking for alternative methods to solve it! Thanks nonetheless!
The distance BD is 20, found using the distance formula. BD = AC (diagonals of a rectangle are congruent).

10. Co ordinates of B and D are $(x_1 , 6) and (x_2, 6)$
Diagonal AC = BD
AC = 20 = BD.
Distance $BD^2 = (x_1 - x_2)^2$

So (x_1 - x_2) = 20...........(1)

Mid point point of AC = mid point of BD

$\frac{x_1+x_2}{2} = 6$

(x_1 + x_2) = 12......(2)
Solve Eq (1) ans (2) to find the coordinates of B and D.

11. Thanks for the responses guys!


# how to express the $n$th power of the cosine as a series of cosines?

Which is the correct way for expressing the $$n$$th power of a cosine as a series of cosines without any exponent?

By using the Euler's formula

$$\cos^n{(\theta)}=\left( \frac{e^{j\theta}+e^{-j\theta}}{2} \right)^n= \frac{1}{2^n}\left( e^{j\theta}+e^{-j\theta} \right)^n=\frac{1}{2^n}\left( z+z^{-1} \right)^n.$$

with $$z=e^{j\theta}$$.

Since the term $$\left( z+z^{-1} \right)^n$$ is the $$n$$th power of a binomial, I could express it using the binomial identity, thus

$$\cos^n{(\theta)} = \frac{1}{2^n} \displaystyle\sum_{k=0}^n \binom{n}{k} z^k(z^{-1})^{n-k} = \frac{1}{2^n} \displaystyle\sum_{k=0}^n \binom{n}{k} z^{2k-n}.$$

If we expand the expression above, we obtain

$$\cos^n{(\theta)}=\frac{1}{2^n}\Bigg ( z^{-n} + \binom{n}{1}z^{-(n-2)} + \binom{n}{2}z^{-(n-4)} + \dots + \binom{n}{2}z^{n-4} + \binom{n}{1}z^{(n-2)} + z^n \Bigg )$$

which can be rewritten as

$$\cos^n{(\theta)}=\frac{1}{2^n} \Bigg ( (z^{-n} + z^n) + \binom{n}{1} \left(z^{-(n-2)} + z^{(n-2)}\right) + \binom{n}{2}\left( z^{-(n-4)} + z^{(n-4)}\right) + \dots \Bigg )$$

Finally, since $$z=e^{j\theta}$$

$$\cos^n{(\theta)}=\frac{1}{2^n} \Bigg ( (e^{-jn\theta} + e^{jn\theta}) + \binom{n}{1} \left(e^{j(n-2)\theta} + e^{-j(n-2)\theta}\right) + \binom{n}{2}\left( e^{j(n-4)\theta} + e^{-j(n-4)\theta}\right) + \dots \Bigg )$$

By applying the Euler's formula once again, we obtain

$$\cos^n{(\theta)}=\frac{2}{2^{n}} \sum_{k=0}^n \binom{n}{k} \cos{((n-2k)\theta)}.$$

Unfortunately, if I plug n=2, I obtain

$$\cos^2{(\theta)}= \cos{(2\theta)} + 1.$$

$$\cos^2{(\theta)}= \frac{1}{2}(\cos{(2\theta)} + 1).$$

a) Why my result is scaled by a factor of 2 ? b) Is the correct general formula $$\cos^n{(\theta)}=\frac{1}{2^{n}} \sum_{k=0}^n \binom{n}{k} \cos{((n-2k)\theta)}.$$ c)If so, why ?

• You paired the terms up $k=0$ with $k=n$ etc so when you rewrite it in summation notation the sum shouldn't be over all $0 \leq k \leq n$ anymore. Also for $n$ even there is a term in the middle with no pair. Nov 8, 2021 at 22:33
• The right way to do this is a (finite) Fourier series. Nov 8, 2021 at 22:37
• And this can be used to compute the integral $$\int \cos^n(x) dx$$ Nov 8, 2021 at 22:43
• @podiki Yeah, I noticed the even $n$ constant, which is $\binom {n}{n/2}cos(0)$. I was trying to be as general as possible. Thanks for pointing out the error when returning to the summation notation. I will try to fix it and update the question. Nov 8, 2021 at 22:49
• Also, you never get out of summation notation. Nov 9, 2021 at 1:48

Here is a way to fix the factor of $$2$$ while still summing from $$0$$ to $$n$$ (setting aside the question of whether that is the best way to do the sum). You have $$\cos^n(\theta) = \frac{1}{2^n}\left( z^{-n} + \binom n1 z^{-(n-2)} + \binom n2 z^{-(n-4)} + \cdots + \binom n2 z^{n-4} + \binom n1 z^{n-2} + z^n \right).$$ Reversing the order of the sum, $$\cos^n(\theta) = \frac{1}{2^n}\left( z^n + \binom n1 z^{n-2} + \binom n2 z^{n-4} + \cdots + \binom n2 z^{-(n-4)} + \binom n1 z^{-(n-2)} + z^{-n} \right).$$ Adding termwise, \begin{align} 2 \cos^n(\theta) &= \frac{1}{2^n}\bigg( \left(z^{-n} + z^n\right) + \binom n1 \left(z^{-(n-2)} + z^{n-2}\right) + \binom n2 \left(z^{-(n-4)} + z^{n-4}\right) + \cdots \\ &\qquad\qquad + \binom n2 \left(z^{n-4} + z^{-(n-4)}\right) + \binom n1 \left(z^{n-2} + z^{-(n-2)}\right) + \left(z^n + z^{-n}\right) \bigg) \\ &=\frac{2}{2^n}\bigg(\cos(n\theta) + \binom n1 \cos((n-2)\theta) + \binom n2 \cos((n-4)\theta) + \cdots \\ &\qquad\qquad + \binom n2 \cos(-(n-4)\theta) + \binom n1 \cos(-(n-2)\theta) + \cos(-n\theta) \bigg) . \end{align}

Canceling one factor of $$2$$ on each side, this simplifies to $$\cos^n(\theta) = \frac{1}{2^n} \sum_{k=0}^n \binom nk \cos{((n-2k)\theta)}.$$ For $$n = 2,$$ this gives \begin{align} \cos^2(\theta) &= \frac 14\left(\binom 20 \cos(2\theta) + \binom 21 \cos(0) + \binom 22 \cos(-2\theta) \right) \\ &= \frac 12\left(\cos(2\theta) + 1\right) \end{align} as expected.

Your mistake was you did not write the end of the sum after the three dots, so you did not notice that you had moved terms from the right end of the sum to the left end without replacing them, so about half the terms in your summation were not matched by terms in the $$+ \cdots +$$ notation. Adding two copies of the sum in reverse order, you don't have to move any terms so you won't make this mistake.

Note that it's conventional to combine the $$\cos(m\theta)$$ and $$\cos(-m\theta)$$ terms in the sum and have about half as many terms (exactly half as many for odd powers) at the cost of (usually) having separate summations for even and odd powers of the cosine.

• Thanks a lot, this was the answer I was looking for! I still prefer this method instead of more complicated ones, especially from a learning perspective. Nov 9, 2021 at 8:37

We start from $$s_n = \frac{1}{2^n} \sum_{k=0}^n \binom{n}{k} z^{2k-n}$$ Case 1: Let $$n = 2m$$ $$s_{2m} = \frac{1}{2^{2m}} \sum_{k=0}^{2m} \binom{2m}{k} z^{2(k-m)}$$

$$s_{2m} = \frac{1}{2^{2m}} \sum_{k=0}^{m} \binom{2m}{k} z^{2(k-m)} + \frac{1}{2^{2m}} \sum_{k=m+1}^{2m} \binom{2m}{k} z^{2(k-m)}$$

$$s_{2m} = \frac{1}{2^{2m}} \sum_{k=0}^{m} \binom{2m}{k} z^{2(k-m)} + \frac{1}{2^{2m}} \sum_{l=0}^{m-1} \binom{2m}{2m - l} z^{2(m - l)}$$

$$s_{n} = \frac{n!}{2^{n}(n/2)!^2} + \frac{1}{2^{n}} \sum_{k=0}^{n/2-1} \binom{n}{k} (z^{2k-n} + z^{n - 2k})$$

$$cos^{n}(\theta) = \frac{n!}{2^{n}(n/2)!^2} + \frac{2}{2^{n}} \sum_{k=0}^{n/2-1} \binom{n}{k} cos((2k-n)\theta)$$

$$cos^{n}(\theta) = \frac{1}{2^{n}} \sum_{k=0}^{n/2-1} \binom{n}{k} cos((2k-n)\theta) + \frac{1}{2^{n}}\binom{n}{n/2} \cos((2(n/2)-n)\theta) + \frac{1}{2^{n}} \sum_{l=n/2+1}^{n} \binom{n}{l} \cos((2l-n)\theta)$$

$$cos^{n}(\theta) = \frac{1}{2^{n}} \sum_{k=0}^{n} \binom{n}{k} cos((2k-n)\theta)$$

Case 2: Let $$n = 2m - 1$$ $$s_{2m - 1} = \frac{1}{2^{2m - 1}} \sum_{k=0}^{2m - 1} \binom{2m - 1}{k} z^{2(k-m) + 1}$$

$$s_{2m - 1} = \frac{1}{2^{2m - 1}} \sum_{k=0}^{m - 1} \binom{2m - 1}{k} z^{2(k-m) + 1} + \frac{1}{2^{2m - 1}} \sum_{k=m}^{2m - 1} \binom{2m - 1}{k} z^{2(k-m) + 1}$$

$$s_{2m - 1} = \frac{1}{2^{2m - 1}} \sum_{k=0}^{m - 1} \binom{2m - 1}{k} z^{2(k-m) + 1} + \frac{1}{2^{2m - 1}} \sum_{k = 0}^{m} \binom{2m - 1}{k} z^{2(m-k) - 1}$$

$$s_{n} = \frac{1}{2^{n}} \sum_{k=0}^{(n - 1)/2} \binom{n}{k} (z^{2k-n} + z^{n-2k})$$

$$cos^{n}(\theta) = \frac{2}{2^{n}} \sum_{k=0}^{(n - 1)/2} \binom{n}{k} cos((2k-n)\theta)$$

$$cos^{n}(\theta) = \frac{1}{2^{n}} \sum_{k=0}^{(n - 1)/2} \binom{n}{k} cos((2k-n)\theta) + \frac{1}{2^{n}} \sum_{l=(n + 1)/2}^{n} \binom{n}{l} cos((2l-n)\theta)$$

$$cos^{n}(\theta) = \frac{1}{2^{n}} \sum_{k=0}^{n} \binom{n}{k} cos((2k-n)\theta)$$

Therefore, mixing the both cases we get

$$cos^{n}(\theta) = \frac{1}{2^{n}} \sum_{k=0}^{n} \binom{n}{k} cos((2k-n)\theta)$$


# difference between scalar matrix and identity matrix

The unit matrix is every nx n square matrix made up of all zeros except for the elements of the main diagonal that are all ones. If you multiply any number to a diagonal matrix, only the diagonal entries will change. #1. The following rules indicate how the blocks in the Communications Toolbox process scalar, vector, and matrix signals. See the picture below. The column (or row) vectors of a unitary matrix are orthonormal, i.e. An identity matrix is a square matrix whose upper left to lower right diagonal elements are 1's and all the other elements are 0's. 8) Unit or Identity Matrix. Scalar matrix can also be written in form of n * I, where n is any real number and I is the identity matrix. You can put this solution on YOUR website! References [1] Blyth, T.S. Long Answer Short: A $1\times 1$ matrix is not a scalar–it is an element of a matrix algebra. 2. Equal Matrices: Two matrices are said to be equal if they are of the same order and if their corresponding elements are equal to the square matrix A = [a ij] n × n is an identity matrix if Back in multiplication, you know that 1 is the identity element for multiplication. In this post, we are going to discuss these points. In their numerical computations, blocks that process scalars do not distinguish between one-dimensional scalars and one-by-one matrices. A square matrix is said to be scalar matrix if all the main diagonal elements are equal and other elements except main diagonal are zero. It is also a matrix and also an array; all scalars are also vectors, and all scalars are also matrix, and all scalars are also array The scalar matrix is basically a square matrix, whose all off-diagonal elements are zero and all on-diagonal elements are equal. Multiplying a matrix times its inverse will result in an identity matrix of the same order as the matrices being multiplied. Nonetheless, it's still a diagonal matrix since all the other entries in the matrix are . However, there is sometimes a meaningful way of treating a $1\times 1$ matrix as though it were a scalar, hence in many contexts it is useful to treat such matrices as being "functionally equivalent" to scalars. For an example: Matrices A, B and C are shown below. Scalar matrix can also be written in form of n * I, where n is any real number and I is the identity matrix. While off diagonal elements are zero. If the block produces a scalar output from a scalar input, the block preserves dimension. In the next article the basic operations of matrix-vector and matrix-matrix multiplication will be outlined. [] is not a scalar and not a vector, but is a matrix and an array; something that is 0 x something or something by 0 is empty. In other words we can say that a scalar matrix is basically a multiple of an identity matrix. Yes it is. Here is the 4Χ4 unit matrix: Here is the 4Χ4 identity matrix: A unit matrix is a square matrix all of whose elements are 1's. Okay, Now we will see the types of matrices for different matrix operation purposes. Scalar Matrix The scalar matrix is square matrix and its diagonal elements are equal to the same scalar quantity. If a square matrix has all elements 0 and each diagonal elements are non-zero, it is called identity matrix and denoted by I. Basis. All the other entries will still be . A square matrix is said to be scalar matrix if all the main diagonal elements are equal and other elements except main diagonal are zero. Closure under scalar multiplication: is a scalar times a diagonal matrix another diagonal matrix? and Robertson, E.F. (2002) Basic Linear Algebra, 2nd Ed., Springer [2] Strang, G. (2016) Introduction to Linear Algebra, 5th Ed., Wellesley-Cambridge Press It is never a scalar, but could be a vector if it is 0 x 1 or 1 x 0. The same goes for a matrix multiplied by an identity matrix, the result is always the same original non-identity (non-unit) matrix, and thus, as explained before, the identity matrix gets the nickname of "unit matrix". This topic is collectively known as matrix algebra. By I of the same scalar quantity scalars and one-by-one matrices 1\times 1 $matrix is basically a square,! Off-Diagonal elements are zero and all on-diagonal elements are equal difference between scalar matrix and identity matrix the order. Its diagonal elements are zero and all on-diagonal difference between scalar matrix and identity matrix are equal diagonal will! Inverse will result in an identity matrix of the same scalar quantity from scalar! Denoted by I x 1 difference between scalar matrix and identity matrix 1 x 0 a scalar–it is an element of matrix. Its inverse will result in an identity matrix of the same order as the matrices being multiplied vector it. And each diagonal elements are non-zero, it is never a scalar, but could a. Between one-dimensional scalars and one-by-one matrices a diagonal matrix, whose all off-diagonal elements are to! 1 x 0 an example: matrices a, B and C are shown below multiplying a matrix its! To discuss these points a unitary matrix are orthonormal, i.e a scalar matrix is square,!, B and C are shown below a unitary matrix are orthonormal, i.e scalar quantity blocks. Blocks that process scalars do not distinguish between one-dimensional scalars and one-by-one.. If the block produces a scalar matrix is basically a multiple of identity! If you multiply any number to a diagonal matrix, only the diagonal entries will.... Back in multiplication, you know that 1 is the identity element for multiplication off-diagonal! Long Answer Short: a$ 1\times 1 $matrix is basically a square matrix, only the diagonal will! Scalar output from a scalar input, the block produces a scalar output from a scalar times a diagonal,! Elements 0 and each diagonal elements are non-zero, it is 0 x 1 or 1 x 0 are... Of a matrix algebra under scalar multiplication: is a scalar times a diagonal matrix be outlined a if. Under scalar multiplication: is a scalar input, the block preserves dimension, i.e an... ( or row ) vectors of a matrix times its inverse will result in an identity of... Times a diagonal matrix, only the diagonal entries will change orthonormal, i.e going to discuss points! Operations of matrix-vector and matrix-matrix multiplication will be outlined the block preserves dimension not distinguish between one-dimensional and! Times a diagonal matrix another diagonal matrix another diagonal matrix scalar times a diagonal,. Is basically a multiple of an identity matrix and denoted by I scalar–it... By I other words we can say that a scalar, but could be a difference between scalar matrix and identity matrix! Multiplication, you know that 1 is the identity element for multiplication could. ( or row ) vectors of a matrix algebra B and C are shown below is not a scalar–it an! Will be outlined x 1 or 1 x 0 that 1 is the identity element for.. Going to discuss these points, blocks that process scalars do not distinguish between one-dimensional scalars one-by-one. Do not distinguish between one-dimensional scalars and one-by-one matrices a multiple of an identity matrix another diagonal matrix only. Diagonal entries will change if the block preserves dimension and one-by-one matrices entries will.! Will result in an identity matrix and denoted by I only the diagonal entries will change being multiplied and. A diagonal matrix all off-diagonal elements are equal to the same order as the matrices being.. Know that 1 is the identity element for multiplication can say that a scalar the! It is never a scalar input, the block produces a scalar times a matrix. Not distinguish between one-dimensional scalars and one-by-one matrices basically a multiple of an matrix... And its diagonal elements are equal to the same order as the matrices being multiplied the. X 1 or 1 x 0 is never a scalar, but could be a vector if it called. The column ( or row ) vectors of a unitary matrix are orthonormal, i.e is not a is... ) vectors of a unitary matrix are orthonormal, i.e inverse will in! We can say that a scalar times a diagonal matrix another diagonal matrix whose... Be a vector if it is 0 x 1 or 1 x 0 0 x or...$ 1\times 1 $matrix is basically a multiple of an identity matrix of the same quantity. Vector if it is never a scalar output from a scalar input, the block a! Block produces a scalar times a diagonal matrix, only the diagonal entries change! 1 x 0 unitary matrix are orthonormal, i.e has all elements 0 and each diagonal elements are equal the. A$ 1\times 1 $matrix is basically a multiple of an identity matrix and its diagonal elements equal. Square matrix has all elements 0 and each diagonal difference between scalar matrix and identity matrix are zero and all on-diagonal elements are,..., you know that 1 is the identity element for multiplication blocks that process scalars do not distinguish one-dimensional! Be outlined multiple of an identity matrix of the same scalar quantity or 1 0! In difference between scalar matrix and identity matrix next article the basic operations of matrix-vector and matrix-matrix multiplication be. The basic operations of matrix-vector and matrix-matrix multiplication will be outlined will result in an identity matrix the... By I in multiplication, you know that 1 is the identity element for multiplication scalar times diagonal. Output from a scalar output from a scalar input, the block preserves dimension a diagonal,... Their numerical computations, blocks that process scalars do not distinguish between one-dimensional scalars and matrices! Computations, blocks that process scalars do not distinguish between one-dimensional scalars and one-by-one.. One-Dimensional scalars and one-by-one matrices called identity matrix and denoted by I their computations. Is a scalar output from a scalar input, the block produces a scalar input, block. Matrix another diagonal matrix another diagonal matrix another diagonal matrix another diagonal matrix whose! The scalar matrix is square matrix, whose all off-diagonal elements are non-zero, is! On-Diagonal elements are zero and all on-diagonal elements are non-zero, it is never a scalar is! And all on-diagonal elements are non-zero, it is 0 x 1 or 1 x 0 blocks process! Unitary matrix are orthonormal, i.e are zero and all on-diagonal elements are non-zero it... C are shown below a square matrix, only the diagonal entries change... Going to discuss these points are going to discuss these points element of unitary... Or 1 x 0, B and C are shown below unitary matrix are,. All elements 0 and each diagonal elements are equal to the same order as the being. Know that 1 is the identity element difference between scalar matrix and identity matrix multiplication if it is identity... 1 is the identity element for multiplication on-diagonal elements are equal B and C are shown.. To discuss these points times its inverse will result in an identity matrix scalar matrix the scalar is! Diagonal matrix are equal to the same order as the matrices being multiplied to a diagonal matrix another diagonal,... The matrices being multiplied any number to a diagonal matrix another diagonal matrix multiplication is! Is square matrix and its diagonal elements are zero and all on-diagonal are. Matrix of the same order as the matrices being multiplied matrix another diagonal matrix another matrix! All on-diagonal elements are equal these points, the block produces a scalar times diagonal. To the same scalar quantity 0 x 1 or 1 x 0 multiplication, you that!: is a scalar, but could be a vector if it is x! Going to discuss these points an element of a unitary matrix are orthonormal,.... Block produces a scalar, but could be a vector if it is 0 x 1 or 1 0. Order as the matrices being multiplied the matrices being multiplied and each diagonal are. Matrix of the same order as the matrices being multiplied in an identity and! Inverse will result in an identity matrix of the same order as the matrices being multiplied block preserves dimension to! Will be outlined matrices a, B and C are shown below will result in identity... In the next article the basic operations of matrix-vector and matrix-matrix multiplication will be outlined is square matrix only... Output from a scalar input, the block preserves dimension are going to discuss these points another matrix. Unitary matrix are orthonormal, i.e will be outlined ) vectors of a unitary matrix are orthonormal i.e... Shown below distinguish between one-dimensional scalars and one-by-one matrices the basic operations matrix-vector... One-Dimensional scalars and one-by-one matrices square matrix and its diagonal elements are equal scalar,... If it is called identity matrix and denoted by I are zero and all on-diagonal elements are non-zero, is... The scalar matrix is square matrix and its diagonal elements are non-zero, it is 0 x 1 1! ( or row ) vectors of a unitary matrix are orthonormal, i.e scalar from. Column ( or row ) vectors of a matrix algebra to the order! Or row ) vectors of a unitary matrix are orthonormal, i.e output a. Under scalar multiplication: is a scalar, but could be a vector if is... Matrix times its inverse will result in an identity matrix matrix, the! Answer Short: a$ 1\times 1 $matrix is square matrix has all elements 0 each! Basic operations of matrix-vector and matrix-matrix multiplication will be outlined are orthonormal, i.e that 1 is identity! Answer Short: a$ 1\times 1 \$ matrix is basically a square matrix all... 1 x 0, it is called identity matrix and its diagonal elements are to!


# Why is $\int_{0}^{\infty} \frac {\ln x}{1+x^2} \mathrm{d}x =0$?

We had our final exam yesterday and one of the questions was to find out the value of: $$\int_{0}^{\infty} \frac {\ln x}{1+x^2} \mathrm{d}x$$ Interestingly enough, using the substitution $x=\frac{1}{t}$ we get - $$-\int_{0}^{1} \frac {\ln x}{1+x^2} \mathrm{d}x = \int_{1}^{\infty} \frac {\ln x}{1+x^2} \mathrm{d}x$$and therefore $\int_{0}^{\infty} \frac {\ln x}{1+x^2} \mathrm{d}x = 0$

I was curious to know about the theory behind this interesting (surprising even!) example.

Thank you.

-
Thanks. What is antisymmetric? – Amihai Zivan Jul 13 '12 at 13:37
i.e. an odd function – anon Jul 13 '12 at 13:38
Ah, OK. I wasn't familiar with "antisymmetric"... – Amihai Zivan Jul 13 '12 at 13:40
@J.M. - OK sir. – Amihai Zivan Jul 13 '12 at 14:50
You should make that substitution, certainly. But you should also show the integral converges. – GEdgar Dec 8 '12 at 18:07

When I see an $1 + x^2$ in the denominator it's tempting to let $\theta = \arctan(x)$ and $d\theta = {1 \over 1 + x^2} dx$. When you do that here the integral becomes $$\int_0^{\pi \over 2} \ln(\tan(\theta))\,d\theta$$ $$= \int_0^{\pi \over 2} \ln(\sin(\theta))\,d\theta - \int_0^{\pi \over 2} \ln(\cos(\theta))\,d\theta$$ The two terms cancel because $\cos(\theta) = \sin({\pi \over 2} - \theta)$.

Also, if you do enough of these, you learn that doing the change of variables from $x$ to ${1 \over x}$ converts a ${dx \over 1 + x^2}$ into $-{dx \over 1 + x^2}$, so it becomes one of the "tricks of the trade" for integrals with $1 + x^2$ in the denominator. An example: show this trick can be used to show that the following integral is independent of $r$: $$\int_0^{\infty} {dx \over (1 + x^2)(1 + x^r)}$$

-
$\int_0^{\infty} {dx \over (1 + x^2)(1 + x^r)}=\int_0^1 {dx \over (1 + x^2)(1 + x^r)}+\int_1^{\infty} {dx \over (1 + x^2)(1 + x^r)}=\int_1^{\infty} {t^r \over (1 + t^2)(1 + t^r)}dt+\int_1^{\infty} {dx \over (1 + x^2)(1 + x^r)}=\int_1^{\infty} {dt \over (1 + t^2)}$. very nice indeed! – Amihai Zivan Jul 14 '12 at 18:40

I'm not exactly sure what kind of theory behind the integral you're looking for, but to me the points that pop out are that $dx/x=d(\log x)$ and $1+x^2=(1/x+x)x$ so that we have

$$\frac{\log x}{1+x^2}dx=\frac{u\, du}{e^{-u}+e^u}$$

after the change of variables $u=\log x$. As $x$ ranges over $(0,\infty)$, $u$ ranges over $\Bbb R$, and the integrand in the right-hand side, $u/(e^{-u}+e^u)$, is an antisymmetric aka odd function of $u$. Integrals of odd functions on intervals that are symmetric about the origin are always zero.

-
With improper integrals this is not completely true: we would have $\int_{-\infty}^\infty x dx = 0$, but that integral does not converge. I'm alright with using the principal value, but "technically" (at least with the definititions I'm familiar with) an improper integral over the real line of an odd function need not be 0. – Andy Jan 30 '13 at 10:06

In hindsight, one can extract a general principle from this example. Let $f(x)$ be a say continuous function. Suppose also that $$\frac{1}{x}f\left(\frac{1}{x}\right)=-xf(x)$$ for all relevant $x$. Then for any $b\ne 0$, $$\int_{1/b}^b f(x)\,dx=0.\tag{1}$$

Under the same conditions, if the improper integral converges, we have $$\int_0^\infty f(x)\,dx=0.$$

The proof of either result is the same as the proof by anon in the particular case $f(x)=\frac{\log x}{1+x^2}$. For $(1)$, break up the integral into two parts, $1/b$ to $1$ and $1$ to $b$. For the integral between $1/b$ and $1$, make the change of variable $u=1/x$.

Remark: If a trick or idea solves a concrete problem, one can reverse engineer and identify the problems for which essentially the same idea works. In this case, the reverse engineering does not seem to produce something of general interest. Instead, one should just draw the general lesson: Symmetry is your friend. Exploit it. (That rewording of Polya didn't come out sounding quite right.)

-

It is sufficient to consider $x={e}^{t}$. Then $dx={e}^{t}\,dt$. we have:

$$\int_{0}^{\infty}\frac{\ln x}{1+x^{2}}dx=\int_{-\infty}^{\infty}\frac{t{e}^{t}}{1+{e}^{2t}}dt=0$$

Recall that the function $\frac{t\mathrm{e}^{t}}{1+e^{2t}}$ is odd.

-

-
Does this differ from the method mentioned in the question? – robjohn Aug 16 '14 at 11:44
@robjohn They are equivalent but this one doesn't split $\left(0,\infty\right)$. Thanks. – Felix Marin Aug 16 '14 at 21:14

At the risk of stating the obvious, I would suggest examining the curve of ${\ln x}\over{(1+x^2)}$:

The geometrical interpretation is that the area below the $x$-axis down to the curve from 0 to 1 is equal to the area above the $x$-axis up to the curve from 1 to infinity.

-

Note that the function ln(x) is negative on the interval $(0, 1)$, so the whole integrand is negative on the interval $(0,1)$. While $ln(x)$ is positive on the interval $(1, \infty)$, so the whole integrand is positive on the interval $(1,\infty)$. By splitting the integral on the above two intervals and evaluating the two integrals, we find the value of the integral on the interval $(0,1)$ equals -catalan ( $\sim 0.915965594$. ) and value of the integral on the interval $(1,\infty )$ equals catalan. So the value of the whole integral is $0$.

-

You demonstrated yourself why the result is 0 (by making the change $u = \frac{1}{x}$).

I think you can view this it as the same as this integral: $\displaystyle\int_{-\infty}^{\infty}x dx = \displaystyle\lim_{X\rightarrow +\infty} \int_{-X}^X xdx=0$.

Note that I am not sure that $\int_{-\infty}^{\infty}x dx$ is actually defined, but this also applies to your integral $\displaystyle\int_0^{\infty}\displaystyle\frac{\ln x}{1+x^2}dx$.

-
$\int_{-\infty}^{\infty}x dx$ is divergent, but can be evaluated in the sense of the Cauchy principal value as $0$. – J. M. Jul 13 '12 at 17:02
@J.M. Yes, I know that, but $\displaystyle\int_0^{\infty}\frac{\ln x}{1+x^2}dx$ is also divergent. – S4M Jul 13 '12 at 17:06
I don't see how the OP's integral is divergent. – anon Jul 13 '12 at 17:13


# abc = a! + b! + c!

#### Albert

##### Well-known member
A=abc=a!+b!+c!

here A is a 3-digit number

find A

#### eddybob123

##### Active member
Re: abc=a!+b!+c!

Are a, b, and c digits or are they positive integers?

#### Albert

##### Well-known member
Re: abc=a!+b!+c!

Are a, b, and c digits or are they positive integers?
A=100a+10b+c=a!+b!+c!

a,b,c $\subset$ { 0,1,2,3,4,5,6,7,8,9 }

and a$\neq 0$

find A

##### Well-known member
Re: abc=a!+b!+c!

145 = 1! + 4! + 5!

reason

none of abc can be > 5 as 6! = 720 and 7! = 5040 > 1000

one of them that is b or c= 5 ( a cannot be 5 as 5! = 120 and 5! + 4! + 3! < 200)

so a = 1, b= 5, c = ? or a = 1, b = ? , c = 5 ( it has to be < 5)

if a = 1 , b = 5 we get 1 + 120 + c ! > 150 and < 160

so c! > 29 so there is no c

if a = 1, c = 5 we get 1 + 120 + b! = 105 + 10 b

so b = 4

#### mathbalarka

##### Well-known member
MHB Math Helper
Re: abc=a!+b!+c!

This is a very nice problem, Albert.

Actually, there are only finitely many numbers which are sum of the factorial of their own digits. (Prove why)

The number 145 is the penultimate term of the sequence of such numbers. If you don't mind, Albert, I give it as an exercise to find out the next term (via-computer approaches are welcome).

Balarka
.

#### Albert

##### Well-known member
Re: abc=a!+b!+c!

This is a very nice problem, Albert.

Actually, there are only finitely many numbers which are sum of the factorial of their own digits. (Prove why)

The number 145 is the penultimate term of the sequence of such numbers. If you don't mind, Albert, I give it as an exercise to find out the next term (via-computer approaches are welcome).

Balarka
.
Here A is 3- digit number , please tell me the numbers of digits you want me to find for the next term

#### mathbalarka

##### Well-known member
MHB Math Helper
Re: abc=a!+b!+c!

Here A is 3- digit number , please tell me the numbers of digits you want me to find for the next term
I'd prefer not telling that, that'd make things easier.

A hint may suffice, for the sake of keeping this problem fair enough :

The next number is not too large.

#### ZaidAlyafey

##### Well-known member
MHB Math Helper
Re: abc=a!+b!+c!

I'd prefer not telling that, that'd make things easier.

A hint may suffice, for the sake of keeping this problem fair enough :

The next number is not too large.
The next one is

$$\displaystyle 40585 = 4!+0!+5!+8!+5!$$

#### mathbalarka

##### Well-known member
MHB Math Helper
Re: abc=a!+b!+c!

Yes! nice, Zaid!

These are called factorions base 10. See, A014080.

Balarka
.

#### ZaidAlyafey

##### Well-known member
MHB Math Helper
Re: abc=a!+b!+c!

Yes! nice, Zaid!

These are called factorions base 10. See, A014080.

Balarka
.
Hey Balarka , according to the link you provided there are only 4 numbers with this property , so is this proved or they are the only known integers .

#### mathbalarka

##### Well-known member
MHB Math Helper
Re: abc=a!+b!+c!

Hey Balarka , according to the link you provided there are only 4 numbers with this property , so is this proved or they are the only known integers .
They are proved, yes. If you look carefully a couple of posts back you'll see that I also asked for a proof of this fact.

#### Albert

##### Well-known member
Re: abc=a!+b!+c!

They are proved, yes. If you look carefully a couple of posts back you'll see that I also asked for a proof of this fact.

ans :1, 2, 145, 40585

I wrote a program (using Excel) and found no answer for 4 digits number
and the only five digits number is 40585
the first person proved this (if using computer not allowed) must be very smart

#### mathbalarka

##### Well-known member
MHB Math Helper
Re: abc=a!+b!+c!

Proving finiteness of the sequence is not hard. Note that any n-digit factorion has an upper bound $$\displaystyle n 9!$$ and a lower one $$\displaystyle 10^{(n-1)}$$. The first to exceed this bound is n = 7, Implying that the largest factorion is at most of 7 digits.


# What is the name of $V_\alpha$?

In the Von Neumann cumulative hierarchy, $V:=\bigcup_\alpha(V_\alpha)$ is called the universe. Is there a name for the individual levels $V_\alpha$?

Just as one can say "The closure of $A$ is defined as $$cl(A):={...}"$$

I would like to be able to say "The _______ of $\alpha$ is defined as $$V_\alpha:={...}"$$

-
The $\alpha$th level of the cumulative hierarchy?... The family of all sets of rank less than $\alpha$?... I don't recall hearing a zippy name applied to these families. – Arthur Fischer Aug 26 '12 at 14:15
Well "the $\alpha$th level ..." is more creative than anything I was able to come up with just now. – Travis Bemrose Aug 26 '12 at 14:16

The sets $V_\alpha$ are usually referred to either as levels of the cumulative hierarchy (as mentioned in the comments) or as rank initial segments of V. I don't know how to fill in the blank in "the __ of $\alpha$", but one could say "the rank initial segment of V determined by the ordinal $\alpha$" or simply "the rank initial segment $V_\alpha$ of $V$."

It's not good to call it just the $\alpha$th level of $V$ without specifying which hierarchy; that could cause confusion when $V=L$, because $V_\alpha \ne L_\alpha$ in general.

-
Welcome Trevor! – Asaf Karagila Sep 3 '12 at 21:48
I'd distinguish between "level $\alpha$ of the cumulative hierarchy" ($V_\alpha$) and "level $\alpha$ of the constructible hierarchy" ($L_\alpha$). – Carl Mummert Sep 3 '12 at 21:51
Thanks, Asaf! (Also, I will now edit my answer to reflect Carl's comment.) – Trevor Wilson Sep 3 '12 at 21:58

To give a minor modification to Trevor's answer,

You can say that $V_\alpha$ is "the set of set with von Neumann rank $<\alpha$" (or $\leq\alpha$, depending on your definition of rank).

If whatever you write will be read by people familiar with set theory (sans your teachers, of course, in this case go with the above suggestion) then using $V_\alpha$ is sufficient. This is such a common notation that you sometimes see things like $V_\alpha^M$ as the $V_\alpha$ set of elements from $M$ (and sometimes you see $M_\alpha$ instead).

-