Math – Blogarithm ../../../../../blog Curtis' self-improvement blog Tue, 24 Dec 2024 21:24:15 +0000 en-US hourly 1 https://wordpress.org/?v=6.4.3 Harvey’s SAT encoding for lexicographic ordering ../../../2024/12/24/harveys-sat-encoding-for-lexicographic-ordering/ Tue, 24 Dec 2024 19:51:00 +0000 ../../../../?p=1429 Continue reading ]]> In my research I often work with satisfiability (SAT) solvers—programs that solve the Boolean satisfiability problem. Modern SAT solvers require the problem instance to solve to be specified in a format known as conjunctive normal form. This essentially means that you need to specify all constraints of your problem in the form

$$ x_1 \lor x_2 \lor \dotsb \lor x_n $$

where $\lor$ denotes the logical OR operator and each $x_i$ is a Boolean variable like $p$ or the negation of a Boolean variable like $\lnot p$ (alternatively denoted $\bar p$). In Boolean logic, an expression like this is known as a clause. Because of De Morgan’s law, the clause $\bar x\lor\bar y\lor u\lor v$ may also be written in the form $\lnot(x\land y)\lor u\lor v$, or as a conveinient shorthand we may also use the notation $(x\land y)\rightarrow(u\lor v)$.

On the positive side, clauses are versatile: they permit sufficient flexibility to encode a large number of practical and theoretical problems. On the negative side, they aren’t always that conveinient: there are many other kinds of constraints that arise in practice that one might want to encode, such as a cardinality constraint saying at least $k$ of the variables $x_1$, $\dotsc$, $x_n$ are true (for some given $0\leq k\leq n$). There are other kinds of more expressive solvers (like pseudo-Boolean solvers and SMT solvers) that natively support such constraints, but surprisingly a pure SAT approach can actually sometimes be the most effective solution. This is because modern SAT solvers have been very well optimized over decades of work and it can pay off to take advantage of their efficiency even when the complexity of your problem’s encoding may increase. In this sense, SAT is a bit like the “assembly language” of combinatorial search. It may not be easy to express a problem in SAT, but doing so can be more efficient when compared with other more expressive encodings of the problem.

If you want to use a pure SAT approach but your problem has some non-clausal constraints a workaround is to find a way of expressing those constraints in the form of clauses. In this post I want to discuss a particular kind of constraint that I’ve used frequently in my research including in my papers on Lam’s problem and the Kochen–Specker problem. In particular, I want to discuss how to encode a lexicographic ordering constraint between two Boolean vectors in SAT. That is, say we have the $2n$ Boolean variables $x_1$, $\dotsc$, $x_n$, $y_1$, $\dotsc$, $y_n$ and we want to express that the Boolean vector $X=(x_1,\dotsc,x_n)$ is lexicographically smaller than or equal to the Boolean vector $Y=(y_1,\dotsc,y_n)$ where Boolean variables are taken to have value either $0$ (false) or $1$ (true). We’ll write this constraint as $X\leq Y$. But how can we express this in a format that a SAT solver can understand?

If you weren’t convinced it can make sense to go to the trouble of devising a SAT encoding for a combinatorial search problem, Donald Knuth (one of my longtime heros) devoted the entire second half of the 714-page Volume 4B of his magnum opus The Art of Computer Programming to just the effectiveness of modern SAT solving techniques. I can’t think of a better endorsement that SAT solving is more than just a novelty, as might otherwise be assumed—it’s a powerful technology that in Knuth’s words “is key to the solution of so many other problems”.

Knuth discusses a huge number of SAT encodings in his book, including an encoding of $X\leq Y$ in paragraph 3 on page 285 of TAOCP 4B. Surprisingly, Knuth does not provide a citation for the original source of the encoding and only provides a single brief sentence about how the encoding can be derived. He says the encoding arises by considering the carries that occur when $\bar X=(\bar x_1,\dotsc,\bar x_n)$ (as a bitvector representing an unsigned integer) is added to the bitvector $Y$, a remark that I found a bit cryptic. I was curious, so I did some research and in this blog post I’ll provide some more details about this encoding.

The reason that Knuth doesn’t state the original source may simply be because there is no original paper to cite. According to a 2006 paper of Frisch et al., the encoding was originally proposed in a 2002 email by Warwick Harvey. The recipients of the email were not specified explicitly, but the authors imply that the email was sent to them after the publication of their 2002 paper Global Constraints for Lexicographic Orderings. Harvey obtained a PhD from the University of Melbourne in 1998, and in 2002 when the email in question was sent he was a Research Fellow at the Centre for Planning and Resource control (IC-Park) at Imperial College London.

Ok, so Harvey’s encoding is now over 20 years old and has undoubtedly been used many times since then. How does it work? Harvey cleverly observes that the constraint $(x_1,\dotsc,x_n)\leq(y_1,\dotsc,y_n)$ can equivalently be rewritten as

$$ x_1 < y_1 + [X_{2..n}\leq Y_{2..n}] \tag{$*$} $$

where $X_{2..n}$ denotes the bitvector $(x_2,\dotsc,x_n)$ and the square brackets denote Iverson notation. This definition also relies on $()\leq()$ being considered as vacuously true (since by definition the empty vector is lexicographically equal to itself).

It is pretty straightforward to see the equivalence just by examining all possible cases. Firstly, if $x_1=0$ and $y_1=1$ then $X\leq Y$ and $(*)$ are both true. Secondly, if $x_1=1$ and $y_1=0$ then $X\leq Y$ and $(*)$ are both false. Lastly, if $x_1=y_1$ then $X\leq Y$ is equivalent to $X_{2..n}\leq Y_{2..n}$ or $[X_{2..n}\leq Y_{2..n}]>0$.

Now, define $a_i$ (for $0\leq i\leq n$) to be a new Boolean variable representing the truth value of $X_{i+1..n}\leq Y_{i+1..n}$, so that $(*)$ becomes

$$ x_1 < y_1 + a_1 $$

and in general $a_i$ denotes the truth value of $x_{i+1} < y_{i+1} + a_{i+1}$. We also take $a_n$ to be vacuously true and will assert that $a_0$ is true, since $a_0$ denotes $X\leq Y$ (the constraint that we want to assert). In a SAT encoding it is easy to specify these variables true simply by asserting the “unit” clauses $a_0$ and $a_n$. SAT solvers will use any unit clauses in the encoding to automatically simplify the encoding: intuitively, $a_0$ and $a_n$ are constants, not variables, meaning that the encoding can be rewritten without reference to either $a_0$ and $a_n$. For example, if $\bar a_0$ appears in a clause it can be removed because $\bar a_0$ is false.

So far so good, but we still need to find a way to express the inequalities that relate the variables $a_i$s, $x_i$s, and $y_i$s (i.e., $x_i < y_i + a_i$ for $1\leq i\leq n$) in clauses because SAT solvers do not natively support inequalities like this. We can rewrite $x_i < y_i + a_i$ as $1<\bar x_i+y_i+a_i$ (since $\bar x_i=1-x_i)$ which is equivalent to $2\leq \bar x_i+y_i+a_i$ (since all quantities here have integer values). In other words, we want to add the constraints

$$ a_{i-1} \leftrightarrow [2\leq \bar x_i+y_i+a_i] \quad\text{for}\quad 1\leq i\leq n . $$

Intuitively, as soon as any two of the variables in the set $\{\bar x_i,y_i,a_i\}$ are known, the value of $a_{i-1}$ is completely determined. The variable $a_{i-1}$ can be considered the “carry bit” of the integer sum $\bar x_i+y_i+a_i$; when at least two summands are true then $a_{i-1}$ is true, and when at least two summands are false then $a_{i-1}$ is false.

In clausal form, we can write this via the following clauses for $1\leq i\leq n$:

\begin{align*}
(\bar a_i \land \bar y_i) &\rightarrow \bar a_{i-1} & (a_i \land y_i) &\rightarrow a_{i-1} \\
(\bar a_i \land x_i) &\rightarrow \bar a_{i-1} & (a_i \land \bar x_i) &\rightarrow a_{i-1} \\
(\bar y_i \land x_i) &\rightarrow \bar a_{i-1} & (y_i \land \bar x_i) &\rightarrow a_{i-1}
\end{align*}

It turns out that the three clauses on the left are the important ones, and the three clauses on the right can be dropped. By doing this we do lose the nice intuitive equivalence that $a_i$ is true if and only if $X_{i+1..n}\leq Y_{i+1..n}$. Instead, we only know that if $a_i$ is true then $X_{i+1..n}\leq Y_{i+1..n}$, but it is possible that $a_i$ is false and $X_{i+1..n}\leq Y_{i+1..n}$ is still true. However, this later case is acceptable so long as our only purpose is to encode that $X\leq Y$. For example, if $x_1=0$ and $y_1=1$ then we know that $X\leq Y$ already, and in this case we don’t care if $a_1$ takes on the same truth value as $X_{2..n}\leq Y_{2..n}$ or not; intuitively, in this case the solver has the freedom to set $a_1$ arbitrarily. On the other hand, if $x_1=y_1$ then the clauses on the left imply that $a_1$ is true which then implies $X_{2..n}\leq Y_{2..n}$ (which in this case we do need to hold). Logically speaking, it doesn’t hurt to also include the clauses on the right. In practice, they slow down the solver somewhat in my experience as there is a cost associated with storing those clauses in memory.

Considering the simplifications that can be made from knowing that $a_0=a_n=1$, the Harvey lex encoding uses the $n-1$ new variables $a_1$, $\dotsc$, $a_{n-1}$ and $3n-2$ clauses (as two clauses with $i=n$ are trivially satisfied).

Interestingly, almost the exact same encoding works for the strict lexicographic ordering $X<Y$. The only difference is that because $()<()$ is false we need to set $a_n$ false instead of true. In this case, the clauses with $i=n$ become $\bar y_n\rightarrow\bar a_{n-1}$, $x_n\rightarrow\bar a_{n-1}$, and $(\bar y_n\land x_n)\rightarrow \bar a_{n-1}$. The last clause here is strictly weaker than each of the first two, so it is unnecessary to include. Thus, Harvey’s strict lex encoding uses $n-1$ new variables and $3n-1$ new clauses.

]]>
Ramanujan summation ../../../2020/08/14/ramanujan-summation/ Sat, 15 Aug 2020 00:23:12 +0000 http://bln.curtisbright.com/?p=1286 Continue reading ]]> I just came across a way that the amazing mathematician Ramanujan developed of assigning a value to certain divergent series. I found it interesting, so I want to share a short summary of it here. It is based on the Euler–Maclaurin formula
\begin{align*} \sum_{k=\alpha}^\beta f(k) &= \int_\alpha^\beta f(t)\,dt + \frac{f(\alpha)+f(\beta)}{2} \\ &\quad+ \sum_{k=1}^n \frac{B_{2k}}{(2k)!}\Bigl(f^{(2k-1)}(\beta)-f^{(2k-1)}(\alpha)\Bigr) + R_n \end{align*}where $B_{2k}$ denotes the $(2k)$th Bernoulli number, $f$ has $2n+1$ continuous derivatives on $[\alpha,\beta]$ with $\alpha$, $\beta$, and $n\geq0$ being integers, and $R_n$ is the remainder term given by
\[ R_n = \int_\alpha^\beta \frac{B_{2n+1}(t-\lfloor t\rfloor)}{(2n+1)!}f^{(2n+1)}(t)\,dt . \]Taking $\alpha=0$, $\beta=x$ and letting $n$ tend to infinity we have (assuming that $R_n$ tends to zero)
\[ \sum_{k=0}^x f(k) \sim \int_a^x f(t)\,dt + \frac{f(x)}{2} + \sum_{k=1}^\infty\frac{B_{2k}}{(2k)!}f^{(2k-1)}(x) + C(a) \quad\text{as $x\to\infty$} \]where $C(a)$ is the constant
\[ C(a) = \int_0^a f(t)\,dt + \frac{f(0)}{2}-\sum_{k=1}^\infty\frac{B_{2k}}{(2k)!}f^{(2k-1)}(0) . \]Ramanujan considered $C(0)$ the “constant” of the series $\sum f(k)$ and claimed that he considered it “like the centre of gravity of a body”. For example, letting $f(k)=1$ one sees that the series $\sum f(k)$ diverges; however, one has $C(0)=-1/2$ (note that all the derivatives of $f$ vanish in this case). Also, letting $f(k)=k$ one again has that $\sum f(k)$ diverges but in this case $C(0)=-B_2/2!=-1/12$ as all derivatives of $f$ vanish except the first. How about a nonconverging alternating series like Grandi’s series? Here we have $f(k)=\cos(\pi k)$ and in this case $C(0)=1/2$ as $f^{(2k-1)}(0)=0$ for all $k\geq1$ since $f^{(2k-1)}(t)=(-1)^k\pi^{2k-1}\sin(\pi t)$. Conversely, consider a series that converges, e.g., when you take $f(k)=2^{-k}$. In this case one has $C(0)=1/2+\sum_{k=1}^\infty B_{2k}(-\ln2)^{2k-1}/(2k)!\approx0.557$—which doesn’t give the correct value of $\sum f(k)=2$. What went wrong in this case? This is the reason for introducing the parameter $a$ above—for convergent series one needs to take $a\to\infty$ to achieve consistency. In this case, one computes that $\int_0^\infty2^{-t}\,dt=1/\ln2\approx1.443$ and one arrives at the happy result that $\lim_{a\to\infty}C(a)=\sum f(k)=2$. I’m not personally aware of any applications of this but it was too cool not to share. I found this in Chapter 6 of Ramanujan’s Notebooks, Part 1 by Bruce Berndt.

]]>
The importance of direction ../../../2019/05/05/the-importance-of-direction/ Sun, 05 May 2019 22:49:30 +0000 http://www.curtisbright.com/bln/?p=1236 Continue reading ]]> Lately I’ve been reflecting on the impact that having a direction (or lack of it) has had in my life. For a long time now—since around the time I first set foot on a university campus—it’s been clear to me that I would be doing and writing about mathematics for the rest of my life. However, perhaps because I have never been particularly interested in thinking about money I never necessarily assumed that I would be paid to do mathematics. My expectation was that I might need to have a day job to support myself and my mathematical hobby. Recently, I’ve been thinking that being paid to do mathematics would be great because it would allow me to devote more time to it. For example, I am quite proud of my latest paper—but it took a lot of time to write, and would have taken even longer if I didn’t already have a job as a postdoctoral researcher. One of my previous papers was written during evenings and weekends since at the time I was working full-time at an internship and it wasn’t ideal. Thus, I’ve been doing the things necessary to apply to academic positions like putting together a research statement. During this process the importance of direction has been made abundantly clear to me and I can’t help but lament the amount of time I spent as an undergraduate and graduate student with unclear direction and ridiculous misconceptions. For example, as an undergraduate student I studied the Ramanujan–Nagell equation and came up with a new solution for it that I hadn’t seen published anywhere. My thought was: this is so cool, I have to share this with the world. So I wrote a short report, gave a copy to one of my professors who I thought might be interested, and uploaded a copy to my website. But what to do beyond that? My thinking was: I don’t know how to get it published somewhere, but I do know how to make it accessible to anyone who wants to read it via the Internet. I told myself that 99% of the value comes from writing the report and I didn’t need the additional 1% “seal of approval” that comes from getting it published. Now I know this is totally backwards—at least when it comes to job applications almost all of a paper’s value is derived from being published. Looking back, my advice to myself would absolutely be to try to get the report published. Maybe I could’ve gotten it published and maybe not, but either way it would have been a very valuable learning experience. Incidentally, the report does seem to be of value to some people: it’s been cited by two OEIS entries, two published papers, a PhD thesis, and Noam Elkies recently gave a talk referencing it (!!!):

We state several finiteness theorems, outline some of the connections among them, explain how a finiteness proof can be ineffective, and (time permitting) sketch Nagell’s proof and an even more elementary one discovered only 12 years ago by C. Bright.

Maybe I’ll come back to that result and get it formally published some day, but I already have more than enough papers on the table. At the very least it’s encouraging to know that I’m in no danger of running out of material to research and write about anytime soon. Even more importantly, I’ve learned how important direction is to achieving your dreams.

]]>
The value of the trigonometric harmonic series revisited ../../../2015/03/31/the-value-of-the-trigonometric-harmonic-series-revisited/ Wed, 01 Apr 2015 00:27:07 +0000 http://www.curtisbright.com/bln/?p=1183 Continue reading ]]> Shortly after my last post I realized there was a simpler way of determining the exact value of the series $\sum_{n=1}^\infty\cos n/n$. Instead of following the method I previously described which required the intricate analysis of some integrals, one can simply use the formula \[ \sum_{n=1}^\infty\frac{a^n}{n} = -\ln(1-a) \] which is valid for $a\in\mathbb{C}$ which satisfies $\lvert a\rvert\leq 1$ and $a\neq 1$. This comes from a simple rewriting of the so-called Mercator series (replace $x$ with $-x$ in the Taylor series of $\ln(1+x)$ and then take the negative). Then we have \begin{align*}
\sum_{n=1}^\infty\frac{\cos n}{n} &= \sum_{n=1}^\infty\frac{e^{in}+e^{-in}}{2n} \\
&= -\bigl(\ln(1-e^i)+\ln(1-e^{-i})\bigr)/2 \\
&= -\ln\bigl((1-e^i)(1-e^{-i})\bigr)/2 \\
&= -\ln(2-e^i-e^{-i})/2 \\
&= -\ln(2-2\cos1)/2 \\
&\approx 0.0420195
\end{align*} since $\lvert e^i\rvert=\lvert e^{-i}\rvert=1$, but $e^i\neq1$ and $e^{-i}\neq1$.

]]>
The value of the trigonometric harmonic series ../../../2015/02/28/the-value-of-the-trigonometric-harmonic-series/ Sat, 28 Feb 2015 23:07:19 +0000 http://www.curtisbright.com/bln/?p=1061 Continue reading ]]> I’ve previously discussed various aspects of the “trigonometric harmonic series” $\sum_{n=1}^\infty\cos n/n$, and in particular showed that the series is conditionally convergent. However, we haven’t found the actual value it converges to; our argument only shows that the value must be smaller than about $2.54$ in absolute value. In this post, I’ll give a closed-form expression for the exact value that the series converges to.

Writing $\sum_{n=1}^\infty\cos n/n$ in terms of an integral

Our analysis starts off with the Calc 1 identity \[ \newcommand{\d}{\,\mathrm{d}} \int \sin(nx)\d x = \frac{-\cos(nx)}{n} . \] From this and the fundamental theorem of calculus, we find that \[ \int_1^\pi\sin(nx)\d x = \frac{\cos n}{n}-\frac{\cos(n\pi)}{n} = \frac{\cos n}{n}-\frac{(-1)^n}{n} . \] Rearranging and summing over all $n\geq1$ we get that \begin{align*}
\sum_{n=1}^\infty \frac{\cos n}{n} &= \sum_{n=1}^\infty\biggl(\frac{(-1)^n}{n}+\int_1^\pi\sin(nx)\d x\biggr) \\
&= \sum_{n=1}^\infty\frac{(-1)^n}{n}+\sum_{n=1}^\infty\int_1^\pi\sin(nx)\d x ,
\end{align*} assuming that $\sum_{n=1}^\infty(-1)^n/n$ converges—which it does; this series is known as the (negative) alternating harmonic series and is well-known to converge to $-\ln2$. The second is trickier but we have that \[ \lim_{m\to\infty}\sum_{n=1}^m\int_1^\pi\sin(nx)\d x = \lim_{m\to\infty}\int_1^\pi\sum_{n=1}^m\sin(nx)\d x \] by the sum rule in integration. By the sum of sines lemma I previously proved the integral on the right simplifies to \[ \int_1^\pi\frac{\sin(mx)-\sin((m+1)x)+\sin x}{4\sin(x/2)^2}\d x \] which we now split into a sum of three integrals and deal with them individually.

The third integral $I_3:=\int_1^\pi{\sin x}/({4\sin(x/2)^2})\d x$

The third integral does not depend on $m$ and can be dealt with directly. We use the double-angle formula $\sin x=2\sin(x/2)\cos(x/2)$ and the substitution $u:=\sin(x/2)$ to show that \[ \int\frac{\sin x}{4\sin(x/2)^2}\d x = \int\frac{\cos(x/2)}{2\sin(x/2)}\d x = \int\frac{\mathrm{d}u}{u} = \ln u , \] and then \[ I_3 = \int_1^\pi\frac{\sin x}{4\sin(x/2)^2}\d x = \Bigl[\ln(\sin(x/2))\Bigr]_1^\pi = -\ln(\sin(1/2)) . \]

The first integral $I_1:=\int_1^\pi{\sin(mx)}/({4\sin(x/2)^2})\d x$

We won’t exactly evaluate the value of $I_1$, but we will show that \[ I_1 = \int_1^\pi\frac{\sin(mx)}{4\sin(x/2)^2}\d x \to 0 \] as $m\to\infty$. First, we’ll split the integral into integrals over intervals of length $2\pi/m$, which is the period of the numerator $\sin(mx)$. Letting $l$ be some number between $1$ and $\pi-2\pi/m$, we’ll consider the integral \[ \int_l^{l+2\pi/m}\frac{\sin(mx)}{4\sin(x/2)^2}\d x \tag{1} . \] Note that the varying denominator is what makes the integral cumbersome to evaluate—if denominator was constant, the integral would be easy to evaluate, e.g., \[ \int_l^{l+2\pi/m}\frac{\sin(mx)}{4\sin(l/2)^2}\d x = 0 \tag{2} \] because $\sin(mx)=-\sin(m(x+\pi/m))$ for all $x$. Thus we may subtract (2) from (1) without changing its value, and after doing this (1) becomes equal to \[\int_l^{l+2\pi/m}\frac{\sin(mx)}{4}\biggl(\frac{1}{\sin(x/2)^2}-\frac{1}{\sin(l/2)^2}\biggr)\d x . \tag{3} \] We now examine the absolute value of the parenthesized expression in (3). Finding a common denominator and using the difference of squared sines identity we find that the the parenthesized expression has absolute value \[ \frac{\lvert\sin(l/2)^2-\sin(x/2)^2\rvert}{(\sin(x/2)\sin(l/2))^2} = \frac{\lvert\sin((l+x)/2)\sin((l-x)/2)\rvert}{(\sin(x/2)\sin(l/2))^2} . \] Since $1\leq l\leq x\leq\pi$ the denominator has value at least $\sin(1/2)^4$. Using that $\lvert\sin x\rvert\leq\lvert x\rvert$ and $\lvert\sin x\rvert\leq1$, the numerator has value at most $\lvert l-x\rvert/2$. Since $x-l\leq 2\pi/m$, the parenthesized expression has absolute value at most \[ \frac{\pi}{m\sin(1/2)^4} . \] By the M-L inequality the integral (3) has absolute value at most \[ \frac{2\pi}{m}\cdot\frac{\pi}{4m\sin(1/2)^4} = \frac{\pi^2}{m^2\sin(1/2)^4} . \tag{4} \] We’re now ready to bound the value of the first integral $I_1$. As motivated above, we split this into pieces by splitting up the interval $[1,\pi]$ via \[ \int_1^\pi = {\int_1^{(2\pi/m)\lceil m/(2\pi)\rceil}} + {\sum_{k=\lceil m/(2\pi)\rceil}^{\lfloor m/2\rfloor-1}\int_{(2\pi/m)k}^{(2\pi/m)(k+1)}} + {\int_{(2\pi/m)\lfloor m/2\rfloor}^\pi} . \] The first and last intervals each have length at most $2\pi/m$, whereas each of the middle intervals have length exactly $2\pi/m$. Furthermore, each of the integrals whose intervals have length exactly $2\pi/m$ are of the form of (1), and therefore we may use the expression in (4) to bound their value. The integrals over the first and last intervals may be bounded by a direct application of the M-L inequality, and our final bound on $I_1$ becomes \[ \begin{gathered} 2\cdot\frac{2\pi}{m}\cdot\frac{1}{4\sin(1/2)^2} + \sum_{k=\lceil2\pi/m\rceil}^{\lfloor m/2\rfloor-1}\frac{\pi^2}{m^2\sin(1/2)^4} \\ \leq \frac{\pi}{m\sin(1/2)^2} + \frac{\pi^2}{2m\sin(1/2)^4} . \end{gathered} \] This goes to zero as $m$ goes to infinity, so we have that $\lim_{m\to\infty}I_1=0$.

The second integral $I_2:=-\int_1^\pi{\sin((m+1)x)}/({4\sin(x/2)^2})\d x$

Since $\lim_{m\to\infty}f(m+1)=\lim_{m\to\infty}f(m)$ and $I_2$ is simply $-I_1$ with $m$ replaced by $m+1$, we have that \[ \lim_{m\to\infty}I_2 = -\lim_{m\to\infty}I_1 = 0 . \]

Putting it all together

Continuing from the expression found for $\sum_{n=1}^\infty\cos n/n$ back in the first section, we find that \[ \sum_{n=1}^\infty\frac{\cos n}{n} = -\ln2 + \lim_{m\to\infty}(I_1+I_2+I_3) = -\ln2-\ln(\sin(1/2)) . \] This value is approximately $0.042$, and as a nice “double-check” of the above work one finds that this indeed corresponds with the value one gets by adding up many terms of $\sum_{n=1}^\infty\cos n/n$.

Acknowledgements

The argumentation was brought to my attention in an answer to a Dr. Math question, though the above presentation is mine.

]]>
The names in boxes puzzle ../../../2015/01/31/the-names-in-boxes-puzzle/ Sun, 01 Feb 2015 04:58:33 +0000 http://www.curtisbright.com/bln/?p=1134 Continue reading ]]> This is one of the best puzzles I’ve come across:

100 prisoners have their names placed in 100 boxes so that each box contains exactly one name. Each prisoner is permitted to look inside 50 boxes of their choice, but is not allowed any communication with the other prisoners. What strategy maximizes the probability that every prisoner finds their own name?

I heard about this puzzle years ago, spent several days thinking about it, and never quite solved it. Actually, I did think of a strategy in which they would succeed with probability over 30% (!), which was the unbelievably-high success rate quoted in the puzzle as I heard it posed. However, I ended up discarding the strategy, as I didn’t think it could possibly work (and probably wouldn’t have been able to prove it would work in any case).

]]>
A difference of squared sines ../../../2014/12/31/a-difference-of-squared-sines/ Wed, 31 Dec 2014 07:52:23 +0000 http://www.curtisbright.com/bln/?p=1109 Continue reading ]]> The purpose of this post is to show the interesting identity \[ \sin(x)^2-\sin(y)^2 = \sin(x+y)\sin(x-y) . \] In fact, this is a simple consequence of the sine addition identity \[ \sin(x\pm y) = \sin x\cos y\pm\cos x\sin y \] and the fundamental Pythagorean identity $\sin(\theta)^2+\cos(\theta)^2=1$. The demonstration is a pretty straightforward usage of the above identities, but involves a little bit of trickery—on the third step, we add and subtract the quantity $\sin(x)^2\sin(y)^2$: \begin{align*}
\sin(x+y)\sin(x-y) &= (\sin x\cos y+\cos x\sin y)(\sin x\cos y-\cos x\sin y) \\
&= \sin(x)^2\cos(y)^2-\cos(x)^2\sin(y)^2 \\
&\qquad+\cos x\sin y\sin x\cos y-\cos x\sin y\sin x\cos y \\
&= \sin(x)^2\cos(y)^2-\cos(x)^2\sin(y)^2 \\
&\qquad+\sin(x)^2\sin(y)^2-\sin(x)^2\sin(y)^2 \\
&= \sin(x)^2(\cos(y)^2+\sin(y)^2) \\
&\qquad-\sin(y)^2(\cos(x)^2+\sin(x)^2) \\
&= \sin(x)^2-\sin(y)^2
\end{align*} This was not an identity I knew off the top of my head, but it came up on a problem I was working on. We’ll have reason to use it in a later post, which is why I wanted to single it out right now.

]]>
A sum of sines ../../../2014/11/22/a-sum-of-sines/ Sat, 22 Nov 2014 17:26:05 +0000 http://www.curtisbright.com/bln/?p=1072 Continue reading ]]> In this post I want to prove a lemma which gives a closed-form expression for the summation $\sum_{n=1}^m\sin(nx)$. The method of proof has come up before; it uses basic algebra, the complex exponential expression for sine, and the summation of a geometric series formula. \begin{align*}
\sum_{n=1}^m\sin(nx) &= \sum_{n=1}^m \frac{e^{inx}-e^{-inx}}{2i} \\
&= \frac{1}{2i}\Bigl(e^{ix}\frac{e^{imx}-1}{e^{ix}-1}-e^{-ix}\frac{e^{-imx}-1}{e^{-ix}-1}\Bigr) \\
&= \frac{e^{ix}(e^{-ix}-1)(e^{imx}-1)-e^{-ix}(e^{ix}-1)(e^{-mx}-1)}{2i(e^{ix}-1)(e^{-ix}-1)} \\
&= \frac{(1-e^{ix})(e^{imx}-1)-(1-e^{-ix})(e^{-mx}-1)}{2i(e^{ix/2}-e^{-ix/2})(e^{-ix/2}-e^{ix/2})} \\
&= \frac{e^{imx}-e^{-imx}-(e^{i(m+1)x}-e^{-i(m+1)x})+e^{ix}-e^{-ix}}{-2i(e^{ix/2}-e^{-ix/2})^2} \\
&= \frac{\sin(mx)-\sin((m+1)x)+\sin x}{4((e^{ix/2}-e^{-ix/2})/2i)^2} \\
&= \frac{\sin(mx)-\sin((m+1)x)+\sin x}{4\sin(x/2)^2}
\end{align*} Most of this is just grunt-work algebra, although in the fourth line a factor of $e^{ix/2}$ was creatively moved from one factor in the denominator to the other. This allows us to write the denominator in terms of sine; the denominator would end up being $2-2\cos x$ if this step was skipped.

]]>
Revisiting a lemma ../../../2014/10/31/revisiting-a-lemma/ Sat, 01 Nov 2014 03:47:46 +0000 http://www.curtisbright.com/bln/?p=1033 Continue reading ]]> We’ve discussed before the “trigonometric harmonic” series $\sum_{n=1}^\infty\cos n/n$. In particular, we showed that the series converges (conditionally). The argument involved the partial sums of the sequence $\{\cos n\}_{n=1}^\infty$, and we denoted these by $C(m)$. The closed-form expression we found for $C(m)$ involved the quantity $\cos m-\cos(m+1)$; in this post we show that this expression can also be written in the alternative form $2\sin(1/2)\sin(m+1/2)$. The proof is a straightforward application of the complex exponential expression for sine and cosine: \begin{align*}
2\sin(1/2)\sin(m+1/2) &= 2\frac{e^{i/2}-e^{-i/2}}{2i}\cdot\frac{e^{i(m+1/2)}-e^{-i(m+1/2)}}{2i} \\
&= \frac{e^{i(m+1)}-e^{im}-e^{-im}+e^{-i(m+1)}}{-2} \\
&= \cos m-\cos(m+1)
\end{align*} Applying this with $m:=0$ yields $2\sin(1/2)^2=1-\cos 1$, and we have \begin{align*}
C(m) &= \frac{\cos m-\cos(m+1)}{2(1-\cos 1)}-\frac{1}{2} \\
&= \frac{2\sin(1/2)\sin(m+1/2)}{4\sin(1/2)^2}-\frac{1}{2} \\
&= \frac{\sin(m+1/2)}{2\sin(1/2)}-\frac{1}{2} .
\end{align*} Written in this form, the naive upper bound on $\lvert C(m)\rvert$ becomes \[ \frac{1}{2\sin(1/2)}+\frac{1}{2} \approx 1.54 , \] which is actually slightly better than the previous upper bound we gave of \[ \frac{1}{1-\cos1}+\frac{1}{2} \approx 2.68 . \] In fact, it is easy to see that our new upper bound the best possible, since it is reached at for example $m:=(3\pi-1)/2$.

]]>
That harmonic series variant absolutely ../../../2014/09/30/that-harmonic-series-variant-absolutely/ Wed, 01 Oct 2014 03:39:47 +0000 http://www.curtisbright.com/bln/?p=994 Continue reading ]]> Previously I discussed a variant on the harmonic series, $\sum_{n=1}^\infty\cos n/n$. Last time we showed that \[ \sum_{n=1}^\infty\frac{\cos n}{n} = \sum_{n=1}^\infty\sum_{m=1}^n\cos m\Bigl(\frac{1}{n}-\frac{1}{n+1}\Bigr) , \] and then showed that the series on the right converges absolutely, by comparison with the series $\sum_{n=1}^\infty3/n^2$. Since the series on the right converges and the two series have the same value, the series on the left also converges. However, this does not imply that the series on the left also converges absolutely. As a trivial counterexample, if a conditionally convergent series sums to $c$ then $c\sum_{n=1}^\infty \href{http://en.wikipedia.org/wiki/Kronecker_delta}{\delta_{n,1}}$ is an absolutely convergent series which sums to the same value. 🙂 In this post, we answer the question of whether $\sum_{n=1}^\infty\cos n/n$ converges absolutely or not. First, note that the function $\lvert\cos(x)\rvert+\lvert\cos(x+1)\rvert$ has a positive lower bound (for example, $1/2$), as can be seen from plotting the function:

abs(cos(x))+abs(cos(x+1))

Now, we note that \[ \frac{\lvert\cos n\rvert}{n} + \frac{\lvert\cos(n+1)\rvert}{n+1} \geq \frac{\lvert\cos(n)\rvert + \lvert\cos(n+1)\rvert}{n+1} \geq \frac{1}{2(n+1)} . \] Applying this inequality for all odd $n$ and on each two consecutive terms of $\sum_{n=1}^\infty\lvert\cos(n)\rvert/n$ we find that \begin{align*}
\sum_{n=1}^\infty\frac{\lvert\cos n\rvert}{n} &\geq \sum_{\text{$n$ odd}}\frac{1}{2(n+1)} \\
&= \sum_{n=1}^\infty\frac{1}{2((2n-1)+1)} \\
&= \sum_{n=1}^\infty\frac{1}{4n} = \infty .
\end{align*} By the comparison test, we find $\sum_{n=1}^\infty\lvert\cos n\rvert/n$ does not converge, and thus $\sum_{n=1}^\infty\cos n/n$ does not converge absolutely.

]]>