Frédéric Wang Subscribe   About   Mathematics   Computer Science   Miscellaneous   Archive

Transcendental number from the oscillating zeno's paradox

Oscillating Zeno’s paradox

In a previous blog post, I described an oscillating Zeno’s paradox, which can be formalized as follows. Atalanta moves on the real line. She leaves from 0 and at step nn she decides to move forward or backward by 12n+1\frac{1}{2^{n+1}}. If ϵn{1,1}\epsilon_n \in {\{-1, 1\}} corresponds to the chosen direction then writing S0=0S_0 = 0 and

Sn+1=Sn+ϵn2n+1 S_{n+1} = S_n + \frac{\epsilon_n}{2^{n+1}}

we obtain sequence of Atalatan’s position on the real line.

In the non-oscillating case (ϵn=1\epsilon_n = 1 for all nn) then this just corresponds to a geometric series of common ration 12\frac{1}{2}. SnS_n converges to 1 by lower values, with remaining distance being 12n\frac{1}{2^n}. More generally, SnS_n is just the partial sum of an absolutely convergent series and so is convergent to a destination S=n=0+ϵn2n+1S_\infty = {\sum_{n=0}^{+\infty} \frac{\epsilon_n}{2^{n+1}}}. It is easy to see that |Sn|<1\left|S_n\right| < 1, |S|1\left|S_\infty\right| \leq 1 and |SSn|12n{\left| S_\infty - S_n \right| \leq \frac{1}{2^n}}. If additionally ϵn\epsilon_n is chosen so that it is not ultimately constant (i.e. Atalatan’s position keeps oscillating) then this becomes a strict inequality |SSn|<12n{\left| S_\infty - S_n \right| < \frac{1}{2^n}}.

In theory, it is possible to reach any destination x[1,1]x \in {[-1,1]} using this approach. Just define ϵn=1\epsilon_n = 1 if and only if SnxS_n \leq x (i.e. “move toward xx”). It is easy to prove by recurrence that |xSn|12n{\left| x - S_n \right| \leq \frac{1}{2^n}} for all nn and so S=xS_\infty = x. However, this assumes we already know xx in order to decide the sequence of directions ϵn\epsilon_n. Let’s see how to build sequences without knowing the destination.

Avoiding an at most countable subset

Suppose that XX \subseteq \mathbb R is at most countable and let (xn)n{(x_n)}_{n \in \mathbb N} be a sequence of real numbers such that X={xn:n}X = \left\{ x_n : n \in \mathbb N \right\}. We want to find a sequence such that SXS_\infty \notin X.

Assuming additionally that it has infinitely many terms above 11 and infinitely many terms below 1-1, then we obtain a non-ultimately-constant sequence by defining ϵn=1\epsilon_n = 1 if and only if SnxnS_n \geq x_n (i.e. “move away from xx”). This is because 1<Sn<1-1 < S_n < 1 so there are always infinitely many terms in front of and behind Atalanta.

Incidentally, X=X = \mathbb N with trivial enumeration xn=nx_n = n shows a simple counter-example with no term below 1-1 and ultimately constant ϵn\epsilon_n. In that case, S0=0S_0 = 0 and S1=12S_{1} = \frac{1}{2} and Sn+1=Sn12n+1S_{n+1} = S_{n} - \frac{1}{2^{n+1}} for n1n \geq 1. But S=0S_\infty = 0 \in \mathbb N.

To workaround that issue, we can alternatively define the sequence ϵ2n=1\epsilon_{2n} = 1 if and only if SnxS_n \geq x and ϵ2n+1=ϵ2n\epsilon_{2n+1} = -\epsilon_{2n}. This still moves away from all xnx_n once, keeps oscillating and does not require additional assumption on XX.

Whatever the decision chosen, we can show that SXS_{\infty} \notin X. Otherwise, consider one NN such that ϵN\epsilon_{N} is defined by moving away from SS_{\infty}. Then either SNS0{S_N - S_\infty} \geq 0 and SN+1=SN+12N+1S+12N+1S_{N+1} = {S_N + \frac{1}{2^{N+1}}} \geq {S_\infty + \frac{1}{2^{N+1}}} or SN+1=SN12N+1<S12N+1S_{N+1} = {S_N - \frac{1}{2^{N+1}}} < {S_\infty - \frac{1}{2^{N+1}}}. But in any case, we would have |SSN+1|12N+1{\left| S_\infty - S_{N+1} \right| \geq \frac{1}{2^{N+1}}} which contradicts our strict inequality for not ultimately constant ϵn\epsilon_n.

As explained in the previous blog, this shows that \mathbb R (or any complete subspace containing \mathbb Q) is uncountable. Otherwise, we could use a sequence enumerating it to arrive to a contradiction.

Similarly, because \mathbb Q is countable then we can find a sequence such that {xn:n}=\left\{ x_n : n \in \mathbb N \right\} = \mathbb Q, which gives us an irrational number SS_\infty. If instead XX is the set of algebraic numbers (which is countable and contains \mathbb Q) then we obtain a transcendental SS_\infty.

An explicit computation

The big difference between the case of \mathbb Q and the set of algebraic numbers is that it’s much easier to actually compute a list of (xn)n{(x_n)}_{n \in \mathbb N} that lists all the \mathbb Q. For example, a simple way to enumerate the fractions pq\frac{p}{q} without trying to avoid duplicate values is, for each M=0,1,2,...M=0, 1, 2, ... to enumerate the integers pp and q0q \neq 0 bounded by MM in the lexicographical order. One can similarly enumerate for each MM the non-constant polynomial of degree at most MM and integer coefficient bounded by MM but it’s not obvious how to actually compute their roots.

One can rely on root finding algorithm to estimate the roots α\alpha in order to be able to calculate the sign SnαS_n - \alpha and so determine ϵn\epsilon_n. But in theory, α\alpha can be arbitrary close to SnS_n so it’s not clear how much precision to request.

Instead, let’s consider (Pn)n{(P_n)}_{n \in \mathbb N} an enumeration of the non-constant polynomial with integer cofficients and define ϵn=1\epsilon_n = 1 if and only if (PnPn)(Sn)0{(P_n\prime P_n)}{(S_n)} \geq 0. With that new formula, ϵn\epsilon_n can be calculated very easily in O(degPn)O(\deg P_n) from the cofficients of PnP_n using Horner’s method.

For any integer M1M \geq 1, let’s consider QM±=(X±2)MQ_M^\pm = {(X \pm 2)}^M. Then its product with its derivative is M(X±2)2M1M {(X \pm 2)}^{2M -1}. Its value at any xx has the same sign as x±2x \pm 2 and if |x|<1\left|x\right| < 1 it just ±\pm. For any nn, we can find MM large enough such that QM+Q_M^+ and QMQ_M^- have not been enumerated yet. So ϵn\epsilon_n is not ultimately constant. Alternatively, we could have used the trick from the previous section to force that property.

Now let’s prove that SS_\infty is still algebraic. If that’s not the case, let nn such that Pn(S)=0{P_n(S_\infty)} = 0. We can choose nn such that PnP_n is of minimal degree and so Pn(S)0{P_n\prime(S_\infty)} \neq 0. Since PnP_n has only finitely many roots, there is knk \geq n such that at maximum distance 12k\frac{1}{2^k} around SS_\infty, SS_\infty is the only root of PnP_n and PnP_n\prime does not vanish. Let’s MM large enough such that the polynomial RM=Pn2M+1R_M = P_n^{2M+1} has not been enumerated before PkP_k. Let’s ll such that Pl=RMP_l = R_M.

In the considered neighbourhood of SS_\infty, PlP_l has only one root SS_\infty, has the same sign as PnP_n and its derivative (2M+1)Pn2MPn{(2M+1)}P_n^{2M} P_n\prime has the same nonzero constant sign as PnP_n\prime. Analyzing each combination PlP_l\prime positive/negative and SlS_l greater/smaller than SS_\infty, we verify that ϵl\epsilon_l is chosen such that |SSl+1|12l+1{\left| S_\infty - S_{l+1} \right| \geq \frac{1}{2^{l+1}}} which is obviously also true if Sl=SS_l = S_\infty. This agains contradict our strict inequality. Q.E.D.

A Zeno paradox to prove the reals are uncountable

A simple Zeno’s paradox

A simple variant of Zeno’s paradoxes can be described as follows. Atalanta wishes to walk to the end of a path. When she gets halfway, she still have to walk the remaining half of the path ; When she gets halfway of that remaining half, she still needs to walk the remaining quarter of the path ; When she gets halfway of that remaining quarter, she still needs to walk the remaining eight of the path ; and so on. Hence it seems she will never reach the end of the path, which is paradoxical.

Schema for classical Zeno's paradox

Obviously, this is not true: Atalanta is going to reach the end of the path after a certain amount of time. The issue in the previous reasoning is that (assuming she walks at constant velocity) walking these subpaths also takes her respectively half, a quarter, a eight, etc of the total time she actually needs to arrive to her destination… and the observations are only done for a total time that is less than the one needed.

A modern variant

Now suppose the ground is an infinite real line, itself covered by an infinite treadmill on which Atalanta is walking. This treadmill brings Atalanta in the opposite direction by twice her velocity. She can decide to turn the treadmill on or off, but its state must remain the same during the whole walk of a subpath. In the following schema, the treadmill was enabled when she was on the second subpath:

Schema for modern variant of Zeno's paradox

After the total duration considered in the previous problem, Atalanta has walked exactly the same total distance on the treadmill. The conveyor belt also moves by summing up distances that are twice the distances on subpaths. Because the treadmill can be on or off, the conveyor’s belt position is not following a simple linear function of the time. Let’s admit for a while it still converges to a certain distance when getting closer to the total duration, I will come back to this at the end of the blog post.

With respect to the ground, Atalanta’s position is basically given by her departure position, moved backward by the distance of the conveyor belt with respect to the ground and moved forward by the distance she walked on the treadmill. As a consequence of the previous paragraph, Atalanta is also converging to a destination with respect to the ground.

Modern Zeno’s paradox (with a flaw)

Now consider an enumeration of all the points of the real line. At the beginning the treadmill is off. Before walking the first half of the path, Atalanta picks the first point in that enumeration and enables the treadmill if she can see that point in front of her. Before walking the next quarter of the path, she picks the second point and enables or disables the treadmill according to whether she can see that second point in front of her. She continues that way for each subpath and each point of the real line.

When a given point is picked there are two options. Either it is not in front of her and so she will just walk forward to a certain distance ; or otherwise the the treamill will additionnaly take her backward by twice that distance. In any case, with respect to the ground, she is moving away from the picked point by the distance she walks during that subpath.

Schema for modern variant of Zeno's paradox (picking a point behind or in front of Atalanta)

At some step, the point of the real line corresponding to Atalanta’s destination will be picked and she will move away from that destination by a certain distance. But the remaining subpaths are half, a quarter, a eight, etc that distance. To have a chance to converge to the destination again she must now always keep the same direction. But so far, only finitely many points have been picked and so there is at least one point beyond the destination that has not been chosen yet (actually infinitely many). This means she will have to change her direction at least once in the future and so will never be able to reach her destination!

Uncountability of the real line

How to solve the paradox in this modern variant?

First, let’s go back to why the distance of the conveyor belt with respect to the ground is convergent. Consider the binary number whose digits describe the sequences of states of the treadmill: 0 if turned off and 1 if turned on. Place the binary point after the first digit to obtain a real number. Then one can check that the distance of the conveyor belt is given by that real number multiplied by Atalanta’s total distance on the treadmill. Of course, one must admit that such a binary number with infinitely many digits after the binary point is well defined!

For a rigorous proof, note that the conveyor belt is always going in the same direction and at most twice Atalanta’s total walking distance on the treadmill. So the convergence of the conveyor belt just comes from the monotone convergence theorem. This assumption was correct.

However, reading more carefully the argumentation, we actually assumed that there is a countable enumeration of all the points of the real line. But Cantor proved at the end of the 19th century that this is wrong, the real line is uncountable!

It is interesting to actually turn this modern Zeno’s paradox into an apparently “elementary” alternative of Cantor’s diagonal argument, in a way that involves only concepts understandable by the Ancient Greeks and no advanced mathematical formalisms. In particular, this is not mentioning explicitly the positional notation invented by Indian mathematicians. As a comparison, Cantor’s proof assumes that a decimal notation with infinitely many digits after the decimal point is well defined (similar to what we used for our proof with binary numbers) ; or it must deal with the edge case of a real number with two different decimal notations (e.g. 0.4999999… = 0.5).

For completeness

Nevertheless, we still had to use some kind of completeness property in order to prove that the moving distance of the conveyor belt is convergent. Actually, Cauchy completeness is enough.

It is also interesting to note that all the moves as well as Atalanta’s total distance on the treadmill are rational numbers. Since the rational numbers are countable, this modern Zeno’s paradox can also be performed by considering only rational points on the ground. In that case, the flaw is then in the assumption that the conveyor belt converges to a rational point: the set of rational numbers is not complete.

More generally, we can also applie this modern Zeno’s paradox to any ordered field since they include a subset isomorphic to the rational numbers. The conclusion becomes that if the field is Cauchy-complete then it is uncountable.

S[α] for strings of ordinals

Update 2020/03/10: Added complexity analysis for S.substr(α, N)

In a previous blog post, I defined for each ordinal α\alpha a string SαS_\alpha (made of the characters for the empty set, comma, opening brace and closing brace) that enumerates the element of α\alpha. I gave a simple formulas to calculate the length LαL_\alpha of this string.

My colleague Ioanna was a bit disappointed that I didn’t provide a script for calculating the infinite SαS_\alpha strings. Obviously, the complexity would be “Ω(ω)\Omega(\omega)” but it is still possible to evaluate the string at a given position: Given β<Lα\beta < L_\alpha, what is the character of SαS_\alpha at position β\beta?

Since the initial segments of the strings are compatible, another way to express this is by introducing the class S=αOrdSαS = \bigcup_{\alpha \in {\mathrm{Ord}}} S_\alpha corresponding to a giant string enumerating the class Ord\mathrm{Ord} of all ordinals. Given an ordinal α\alpha, what is S[α]S[\alpha]?

A small generalization of this S.charAt(α) operation is S.substr(α, N) calculating the substring of length NN starting at α\alpha.

Example

  • S2S_{2} is "∅,{∅}", so S[0]S[0] is the character ∅, S[1]S[1] is a comma, S[2]S[2] is an opening brace and S[4]S[4] is a closing brace.
  • Sω+1S_{\omega+1} is made of of an ω\omega-concatenation of finite strings (the character ∅, a comma, S1S_1 surrounded by braces, a comma, S2S_2 surrounded by braces, a comma, S4S_4 surrounded by braces, a comma, etc), followed by a comma, an opening brace, the same ω\omega-concatenation of finite strings and finally a closing brace. So S[ω]S[\omega] is a comma, S[ω+1]S[\omega+1] is an opening brace, S[ω+2]S[\omega+2] is the character "∅" and S[ω2]S[\omega2] is a closing brace.

In the previous example, we have basically analyzed the string Sα+1S_{\alpha+1} at a given successor ordinal, splitting it into two copies of SαS_\alpha, comma and braces. This suggests some easy values of SS:

Lemma

For any n<ωn < \omega and β1\beta \geq 1, S[α]S[\alpha] is:

  • A comma if α\alpha can be written 2n32^n - 3 or ωβ2n+n\omega^\beta 2^n + n
  • An opening brace if α\alpha can be written 2n22^n - 2 or ωβ2n+n+1\omega^\beta 2^n + n + 1
  • A closing brace if α\alpha can be written 2n+142^{n+1} - 4 or ωβ2n+1+n\omega^\beta 2^{n+1} + n

Proof: For any ordinal α\alpha, by viewing the string Sα+1S_{\alpha+1} as a concatenation of SαS_\alpha, a comma, an opening fence, SαS_\alpha and a closing fence, we deduce that:

  • S[Lα]{S\left[L_{\alpha}\right]} is a comma.
  • S[Lα+1]{S\left[L_{\alpha} + 1 \right]} is an opening brace.
  • Lα+1L_{\alpha+1} is a successor ordinal and S[Lα+11]{S\left[L_{\alpha+1} - 1 \right]} is a closing brace.

The lemma follows immediately from the calculation of string lengths performed in the previous blog post. □

Warning: The rest of the blog post gives the solution to this puzzle, so you might want to have fun solving it yourself first and then go back checking my proposed solution later 😉...

More generally, the proof of the lemma can be extended by saying that if we find nn such that 2n1α2n+15{2^n - 1} \leq \alpha \leq {2^{n+1} - 5} then δ=α(2n1)2n4\delta = {\alpha - {(2^n - 1)}} \leq {2^n - 4} is the index of S[α]{S[\alpha]} in the second substring SαS_\alpha of Sα+1S_{\alpha+1} and so S[α]=S[δ]{S[\alpha]} = {S[\delta]}.

Details will be provided in the theorem below but one can already write a simple JavaScript recursive program to evalute SS at finite ordinals:

Script for α<ω\alpha < \omega

The character of SS at position α=\alpha =

is

The following intermediary step will be helpful to evaluate SS at infinite ordinal α\alpha:

Proposition

Let α\alpha is infinite and β=logω(α)1\beta = \log_{\omega}(\alpha) \geq 1. Let 1q<ω1 \leq q < \omega and 0ρ<ωβ0 \leq \rho < \omega^\beta be the quotient and remainder of the euclidean division of α\alpha by ωβ\omega^\beta. Let’s define:

n={log2(q) if q is not a power of 2 or this value is ρlog2(q)1 otherwise.n = \begin{cases} \left\lfloor {\log_2(q)} \right\rfloor & \text{ if } q \text{ is not a power of 2 or this value is } \leq \rho \\ \left\lfloor {\log_2(q)} \right\rfloor - 1 & \text{ otherwise.} \end{cases}

Then S[α]S[\alpha] is:

  • A comma if α=ωβ2n+n\alpha = {\omega^{\beta} 2^n + n}
  • An opening brace if α=ωβ2n+n+1\alpha = {\omega^{\beta} 2^n + n + 1}
  • An closing brace if α=ωβ2n+1+n\alpha = {\omega^{\beta} 2^{n+1} + n}
  • S[δ]S[\delta] otherwise where δ\delta is the unique ordinal such that α=ωβ2n+n+2+δ\alpha = {\omega^\beta 2^n + n + 2 + \delta} and δ<ωβ2n+n\delta < {\omega^{\beta} 2^n + n}.

Proof: First by construction we have α=ωβq+ρ\alpha = { {\omega^\beta q } + \rho}.

If the first case of the definition of nn, 2nq<2n+12^n \leq q < 2^{n+1} so we always have α<ωβ(q+1)ωβ2n+1Lωβ+n+1\alpha < {\omega^\beta {(q+1)}} \leq \omega^\beta 2^{n+1} \leq L_{\omega{\beta} + n + 1}. If additionnaly qq is not a power then 2n<q2^n < q and so αωβqωβ(2n+1)Lωβ+n\alpha \geq {\omega^{\beta}q} \geq {\omega^{\beta}{(2^n+1)}} \geq L_{\omega{\beta} + n}. Otherwise q=2nq = 2^n and nρn \leq \rho and so again αLωβ+n\alpha \geq L_{\omega{\beta} + n}.

In the second case of the definition of nn, log2(q)ρ+1\left\lfloor {\log_2(q)} \right\rfloor \geq \rho + 1 so nρ0n \geq \rho \geq 0. qq is a power of 2 and more precisely q=2n+1>2nq = 2^{n+1} > 2^n so we deduce the same way as in the previous case that αLωβ+n\alpha \geq L_{\omega{\beta} + n}. Moreover, ρ<n+1\rho < n + 1 so again α=ωβ2n+1+ρ<Lωβ+n+1\alpha = {\omega^\beta 2^{n+1} + \rho} < L_{\omega{\beta} + n + 1}.

We can thus view Sωβ+n+1S_{\omega \beta + n + 1} as a concatenation of Sωβ+nS_{\omega \beta+n}, a comma, an opening brace, Sωβ+nS_{\omega \beta+n} and a closing brace. We assume that ωβ2n+n+2α<ωβ2n+1+n { {\omega^{\beta} {2^n}} + n + 2} \leq \alpha < {\omega^{\beta} 2^{n+1} + n} as the three other cases are handled by the lemma. Then δ\delta is well-defined and is actually the index of S[α]S[\alpha] in the second copy of Sωβ+nS_{\omega \beta + n} so S[α]=S[δ]{S[\alpha]} = S{[\delta]}. □

We are now ready to give a nice way to evaluate SS at any ordinal α\alpha:

Theorem

S[α]S[\alpha] can be calculated inductively as follows:

  • If α=0\alpha = 0, S[α]S[\alpha] is the character "∅".
  • If 0<αω0 < \alpha \leq \omega then 2log2(α+3)3α2log2(α+3)+14 \right\rfloor}} - 3} \leq \alpha \leq \right\rfloor + 1}} - 4} and S[α]S[\alpha] is equal to:
    • A comma if α=2log2(α+3)3\alpha = {2^{\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor} - 3}
    • An opening brace if α=2log2(α+3)2\alpha = {2^{\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor} - 2}
    • A closing brace if α=2log2(α+3)+14\alpha = {2^{\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor + 1}} - 4
    • S[δ]S[\delta] otherwise where δ=α(2log2(α+3)1)2log2(α+3)4α3\delta = {\alpha - \left( 2^{\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor} - 1 \right)} \leq {2^{\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor} - 4} \leq \alpha - 3.
      Moreover δ\delta compares against α\alpha as follows: δα12+12log2(α+3)+134\frac{\delta}{\alpha} \leq \frac{1}{2} + \frac{1}{2^{\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor + 1}} \leq \frac{3}{4} and log2(δ+3)<log2(α+3) {\left\lfloor {\log_2{(\delta+3)}} \right\rfloor} < {\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor}
  • If α\alpha is infinite, let 0<c1<ω0 < c_1 < \omega be the coefficient in its Cantor normal form corresponding to the smallest infinite term and c0<ωc_0 < \omega be finite term if there is one, or zero otherwise. Let kk be the exponent corresponding to the smallest nonzero term in the binary decomposition of c1c_1. Then S[α]S[\alpha] is equal to:
    • A closing brace if c0k1c_0 \leq k - 1.
    • A comma if c0=kc_0 = k.
    • An opening brace if c0=k+1c_0 = k + 1.
    • S[c0(k+2)]S[{c_0 - {(k+2)}}] if c0k+2c_0 \geq k + 2.

Proof:

The case α=0\alpha = 0 is clear. Suppose 0<α<ω0 < \alpha < \omega and let l=log2(α+3)l = {\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor}. By definition 2lα+3<2l+12^l \leq \alpha + 3 < 2^{l+1} so 2l3α2l+142^l - 3 \leq \alpha \leq 2^{l+1} - 4. Let’s consider the case 2l1α2l+152^l - 1 \leq \alpha \leq 2^{l+1} - 5 as the three other cases are already known from the Lemma. Sl+1S_{l+1} is made of the concatenation of SlS_l, a comma and SlS_l surrounded by braces. δ\delta is actually the index of S[α]S[\alpha] in the second copy of SlS_l so S[α]=S[δ]{S[\alpha]} = S{[\delta]}. The first equality is straighforward:

δ=α(2l1)2l+15(2l1)=2l4=2l13α3\delta = {\alpha - {(2^l -1)}} \leq {2^{l+1} - 5 - {(2^l -1)}} = {2^l - 4} = {2^l - 1 - 3}\leq \alpha - 3

Morever we have:

δα12l12l+1+512l12l+112+12l+1 \frac{\delta}{\alpha} \leq {1 - \frac{2^l - 1}{2^{l+1}+5}} \leq {1 - \frac{2^l - 1}{2^{l+1}}} \leq {\frac{1}{2} + \frac{1}{2^{l+1}}}

and so the second inequality follows from the fact that l1l \geq 1. Finally, the third inequality comes from:

2log2(δ+3)δ+32l4+3<2l 2^{\left\lfloor {\log_2{(\delta+3)}} \right\rfloor} \leq {\delta + 3} \leq {2^l - 4 + 3} < 2^l

Let’s consider the case of an infinite α\alpha. For some N1N \geq 1, βN>βN1>>β11\beta_N > \beta_{N-1} > \dots > \beta_1 \geq 1 and c0<ωc_0 < \omega and 0<c1,c2,cN<ω0 < c_1, c_2, c_N < \omega, we can write Cantor’s Normal form as:

α=ωβNcN+ωβN1cN1++ωβ1c1+c0\alpha = { \omega^{\beta_N} c_N} + { \omega^{\beta_{N-1}} c_{N-1} } + \dots + { \omega^{\beta_{1}} c_{1} } + c_0

With the notation of the proposition, we have β=βN\beta = \beta_N, q=cNq = c_N and

ρ=ωβN1cN1++ωβ1c1+c0 \rho = { \omega^{\beta_{N-1}} c_{N-1} } + \dots + { \omega^{\beta_{1}} c_{1} } + c_0

If N2N \geq 2, then ρ\rho is infinite and so n=log2(q)n = \left\lfloor {\log_2(q)} \right\rfloor and we are in the fouth bullet of the proposition. Moreover q2nq \geq 2^n and we can write:

α=ωβ2n+ωβ(q2n)+ρ=ωβ2n+n+2+δ\alpha = { \omega^{\beta} 2^n} + {\omega^{\beta} \left(q-2^n\right)} + \rho = { \omega^{\beta} 2^n} + n + 2 + \delta

where δ=ωβ(q2n)+ρ\delta = {\omega^{\beta} \left(q-2^n\right)} + \rho is infinite and so cancels out the n+2n + 2 term. It follows that S[α]=S[ωβ(q2n)+ρ]S{[\alpha]} = S\left[ {\omega^{\beta} \left(q-2^n\right)} + \rho \right]. Essentially, we have just removed from cNc_{N} its term of highest exponent in its binary decomposition!

By repeated application of the theorem, we can remove each binary digit of the cic_i for ii going from NN to 22. When then arrive at i=1i = 1:

S[α]=S[ωβ1c1+c0]{S[\alpha]} = S\left[ \omega^{\beta_1} c_1 + c_0\right]

With the notation of the proposition, we now have β=β1\beta = \beta_1, q=c1q = c_1 and ρ=c0\rho = c_0. If the binary decomposition of c1c_1 has more than one nonzero digit then so qq is not a power of 2. So although ρ\rho is now finite, we are still in the first case of the proposition and δ\delta remains infinite. So we can remove all but the last digit of c1c_1 by repeated application of the proposition:

S[α]=S[ωβ12k+c0]{S[\alpha]} = S\left[ \omega^{\beta_1} 2^k + c_0\right]

where kk is the exponent corresponding to the smallest nonzero term in the binary decomposition of c1c_1.

Using the lemma, S[α]S[\alpha] is a comma if k=c0k = c_0, an opening brace if k=c01k = c_0 - 1 and a closing brace if k=c0+1k = c_0 + 1.

If kc02k \leq c_0 - 2 then k=log2(2k)c0k = \left\lfloor {\log_2(2^k)} \right\rfloor \leq c_0 and writing

ωβ12k+c0=ωβ12k+k+2+(c0(k+2)){\omega^{\beta_1} 2^k + c_0} = \omega^{\beta_1} 2^k + k + 2 + \left(c_0 - {(k + 2)}\right)

we deduce from the proposition that S[α]=S[c0(k+2)]{S[\alpha]} = {S[{c_0 - {(k+2)}}]}.

Finally, if kc0+2k \geq c_0 + 2 then k=log2(2k)>c0k = \left\lfloor {\log_2(2^k)} \right\rfloor > c_0 and writing

ωβ12k+c0=ωβ12k1+k1+2+ωβ12k1+c0{\omega^{\beta_1} 2^k + c_0} = {\omega^{\beta_1} 2^{k-1}} + k - 1 + 2 + {\omega^{\beta_1} 2^{k-1}} + c_0

we deduce from the proposition that

S[α]=S[ωβ12k1+c0]{S[\alpha]} = S\left[ \omega^{\beta_1} 2^{k-1} + c_0\right]

We have essentially decremented kk and we can repeat this until we reach the case k=c0+1k = c_0 + 1 for which we already said that the character is a closing brace. □

As an application of this theorem, here is a few simple exercises:

Exercise 1

  1. S[272+2]S\left[2^72 + 2\right] is an empty set.
  2. S[ω72]S\left[\omega^72\right] is a comma.
  3. S[ω7272+72]S\left[\omega^72 72 + 72\right] is a closing brace.
  4. S[ω7272+ω4242+12]S\left[\omega^72 72 + \omega^42 42 + 12\right] is an opening brace.

Exercise 2

The evaluation of SS at

Corollary 1: Time complexity

Let α\alpha be an ordinal. Let c1<ωc_1 < \omega be the coefficient in its Cantor normal form corresponding to the smallest infinite term if there is one, or zero otherwise. Let c0<ωc_0 < \omega be its finite term if there is one, or zero otherwise. Then S[α]S[\alpha] can be evaluated in:

  • O(log2(c0+2)2+log2(c1+2))O\left( \log_2{(c_0+2)}^2 + \log_2{(c_1+2)} \right) elementary arithmetic operations and comparisons on integers.
  • O(log2(c0+2))O\left( \log_2{(c_0+2)}\right) elementary operations if integers are represented in binary and leading/trailing zero counting and bit shifts are elementary operations.

Proof: First note that the “+ 2” is just to workaround for the edge cases c0=0c_0 = 0 or c1=0c_1 = 0.

For the infinite case c1>0c_1 > 0 we need to calculate kk that is performing the find first set. A naive implementation can be done in O(log2(c1+2))O(\log_2{(c_1+2)}) steps by browsing the digits of c1c_1 to find the first nonzero for example by calculating the remainder modulo increasing power of 2. Each iteration requires only O(1)O(1) elementary integer operations %, * and comparisons. Then returning the result of moving to the finite case requires O(1)O(1) integer operations +, − and comparisons.

For the finite case c1=0c_1 = 0 and α=c0\alpha = c_0, first notice that we only require O(log2(c0+2))O\left( \log_2{(c_0+2)}\right) recursive calls given the inequality:

log2(δ+3)<log2(α+3) {\left\lfloor {\log_2{(\delta+3)}} \right\rfloor} < {\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor}

The case α=0\alpha = 0 only requires one comparison. For the case α>0\alpha > 0, we need to calculate l=log2(α+3)l = {\left\lfloor {\log_2{(\alpha+3)}} \right\rfloor} which is integer rounding of the binary logarithm or even just 2l2^l. As above, we can provide a naive implementation by calculating the quotient modulo increasing power of 2 in O(l)O(l) comparisons and elementary integer operations /, *. Then returning the result of moving to a δ<α\delta < \alpha requires only O(1)O(1) integer operations and comparisons. In total, complexity is O(log2(c0+2)2)O\left( \log_2{(c_0+2)}^2\right).

Finally, this can be simplified if one calculates kk and ll by a simple leading/trailing zero counting (or similar) and 2l2^l by a bit shift. □

Script based on Cantor normal form

If the coefficients of Cantor normal form of α\alpha corresponding the smallest infinite term and finite term are
c1c_1 =
c0c_0 =
Then the character of SS at position α\alpha is

Once we have an algorithm for S.charAt(α), it is easy to get an algorithm of NN times that complexity for S.substr(α, N) calculating the substring of length NN starting at position α\alpha by repeated calls to S.charAt(α). Let’s analyze a bit more carefully how we can make this recursive and more efficient:

Corollary 2: Algorithm for S.substr(α, N)

Let α\alpha be an ordinal and N<ωN < \omega. Then S.substr(α, N) can be calculated as follows:

  • If N=0N = 0 then it is the empty string.
  • If α=0\alpha = 0 and N=1N = 1 then it is the character "∅".
  • If 0<α<ω0 < \alpha < \omega, let l=log2(α+N+2)l = \left\lfloor {\log_2{(\alpha+N+2)}} \right\rfloor. We have 2l3α+N12l+142^l-3 \leq {\alpha + N - 1} \leq 2^{l+1} - 4 and the result is obtained by concatenating the following strings:
    1. If α2l4\alpha \leq 2^l - 4, the substring at offset α\alpha and length 2l3α2^l - 3 - \alpha.
    2. If α2l3\alpha \leq {2^l - 3}, a comma.
    3. If α2l2α+N1\alpha \leq {2^l - 2} \leq {\alpha + N - 1}, an opening brace.
    4. If α+N12l1{\alpha + N - 1} \geq {2^l - 1}, the substring at offset δ=max(0,α(2l1))\delta = \mathrm{max}{(0, \alpha - {(2^l - 1)})} and length 1+min(α+N1,2l+15)max(α,(2l1))1 + \mathrm{min}{({\alpha + N - 1}, {2^{l+1} - 5})} - \mathrm{max}{(\alpha, {(2^l - 1)})}.
    5. If α+N1=2l+14{\alpha + N - 1} = {2^{l+1} - 4}, a closing brace.
  • If α\alpha is infinite, let 0<c1<ω0 < c_1 < \omega be the coefficient in its Cantor normal form corresponding to the smallest infinite term and c0<ωc_0 < \omega be finite term if there is one, or zero otherwise. Let kk be the exponent corresponding to the smallest nonzero term in the binary decomposition of c1c_1. Then the result is obtained by a concatenating the following strings:
    1. If c0k1c_0 \leq k - 1, min(N,kc0){\mathrm{min}{(N, k - c_0)}} closing braces.
    2. If c0kc0+N1c_0 \leq k \leq c_0 + N - 1, a comma.
    3. If c0k+1c0+N1c_0 \leq k + 1 \leq c_0 + N - 1, an opening brace.
    4. If c0+N1k+2c_0 + N - 1 \geq k + 2, the substring at offset δ=max(0,c0(k+2))\delta = \mathrm{max}{({0, {c_0 - {(k + 2)}}})} and length c0+Nmax(c0,k+2)c_0 + N - {\mathrm{max}{(c_0, k + 2)}}.

Moreover, this only adds O(N)O(N) compared to the complexity of evaluating to a single offset.

Proof: The algorithm is just direct application of the Theorem. For the case where αω\alpha \geq \omega, the only change is that we add at most NN characters before moving to the finite case. The case α<ω\alpha < \omega is essentially a divide-and-conquer algorithm and we have a relation of the form:

T(L)=2T(L2)+f(L){T(L)} = 2{T\left(\frac{L}{2}\right)} + {f(L)}

where L=2l=Θ(α+N)L = 2^l = {\Theta{(\alpha + N)}} and f(L)f{(L)} is O(1)O(1) or O(log2L)O(\log_2{L}) depending on available operations, but in any case O(L)O{(\sqrt{L})}. So from the master theorem, T(L)=O(L)=O(α+N){T{(L)}} = {O(L)} = {O(\alpha+N)}. In general, this bound is not as good as repeating NN calls to S.charAt!

However, we note that if we assume that α>N4\alpha > N - 4 then α+2+N<2(α+3){\alpha + 2 + N} < {2{(\alpha+3)}} and so

log2(α+2+N)<1+log2(α+3)\log_2\left(\alpha + 2 + N\right) < {1 + \log_2{(\alpha+3)}}

We can easily discard the edge case where these start/end offsets point to a brace surrounding the right substring of the iterative step and so we get:

log2(α+N+2)=log2(α+3)\left\lfloor {\log_2{(\alpha+N+2)}} \right\rfloor = \left\lfloor {\log_2{(\alpha+3)}} \right\rfloor

which means that the left substring is just empty and so the complexity is not changed compared to S.charAt. Finally, when αN4\alpha \leq N - 4 the previous bound tells us that the steps are done in O(N)O(N). □

Script for S.substr(α, N)

If the coefficients of Cantor normal form of α\alpha corresponding the smallest infinite term and finite term are
c1c_1 =
c0c_0 =
Then the character of SS substring of length NN =
and offset α\alpha is

Ordinals as strings of ∅, commas and braces

This week, my colleagues at Igalia were talking about cutting text at a 72-characters limit for word-wrapping emails. One might say that the real question is whether 72 is a cut or a limit. Or wonder how one has decided to set that particular value?

The latter link explains the recursive definition of 72 as a finite set, which can be written with only braces, commas and the empty set \empty:

0={}=0 = {\{\}} = \empty 1=0{0}={0}={}1 = 0 \union {\{0\}} = {\{0\}} = {\{\empty\}} 2=1{1}={0,1}={,{}}2 = 1 \union {\{1\}} = {\{0,1\}} = {\{ \empty, {\{\empty\}} \}} 3=2{2}={0,1,2}={,{},{,{}}}3 = 2 \union {\{2\}} = {\{0,1,2\}} = {\{ \empty, {\{\empty\}}, {\{ \empty, {\{\empty\}} \}} \}}

and so forth until

72=71{71}={0,1,2,,71}=72 = 71 \union {\{71\}} = {\{0,1,2,\dots,71\}} = \dots

You can notice that 11 has only one element and for any n1n \geq 1, in order to enumerate the elements of n+1n+1 using only the four characters "∅", ",", "{" and "}", you first write the elements of nn, followed by a comma, followed by an opening brace, followed by the elements of nn and finally followed by a closing brace. One can write a simple JavaScript loop that initializes a variable string = "∅" and performs the concatenation string += `,{${string}}` at each step:

The elements of are

Length of the string

You notice that the length of the string obtained for n=6n=6 already exceeds the 72-character limit. From the previous recursive construction of the string one can deduce a recursive definition of its length:

L1=1L_1 = 1 Ln+1=Ln+2+Ln+1=2Ln+3L_{n+1} = L_n + 2 + L_n + 1 = 2L_n +3

It is easy to see that Ln=Ω(2n)L_n = {\Omega{(2^n)}} so although the simple JavaScript loop above uses a time complexity of O(n){O{(n)}} string concatenations, the space complexity is at least exponential. That’s why in the definition of 72 above I used dots instead of showing the whole string!

One can however easily modify the previous JavaScript loop to calculate the length of such a string. At Igalia, we have been working on a new native type called BigInt which is particularly useful to accurately calculate large integers. The case n=72n = 72 demonstrates why it is more appropriate than JavaScript Number:

The length of the strings enumerating the elements of has the following length (first field uses Number, second field uses BigInt):

One can do better and try to calculate an explicit formula for LnL_n for any n1n \geq 1. Since for all i1i \geq 1, Li+2Li+1=2(Li+1Li)L_{i+2} - L_{i+1} = 2\left(L_{i+1} - L_i\right) the sequence (Li+1Li)i1\left(L_{i+1} - L_i\right)_{i \geq 1} is a geometric sequence with common ratio 2 and for all i1i \geq 1 we can write

Li+1Li=2i1(L2L1){L_{i+1} - L_{i}} = {2^{i-1} \left( L_2 - L_1 \right)}

Summing this up for 1in11 \leq i \leq n - 1:

LnL1=i=1n1Li+1Li=(L2L1)(i=0n22i)=(L2L1)(2n11) L_n - L_1 = {\sum_{i=1}^{n-1} L_{i+1} - L_{i}} = {\left( L_2 - L_1 \right) \left(\sum_{i=0}^{n-2} 2^i \right)}= { {\left( L_2 - L_1 \right)} {\left(2^{n-1}-1\right)} }

Finally, given that L1=1L_1 = 1 and L2=2L1+3=5L_2 = 2L_1 + 3 = 5, one can write for all n1n \geq 1:

Ln=(2n11)(51)+1=2n+13L_n = (2^{n-1}-1) (5-1) + 1 = 2^{n+1} - 3

This formula can be used to calculate LnL_n using built-in JavaScript exponentation instead of a loop, as done below.

The length of the strings enumerating the elements of has the following length (first field uses Number, second field uses BigInt):

Order-type of infinite strings

It is possible to generalize this problem to infinite ordinal numbers. The string SαS_{\alpha} and its length LαL_\alpha are defined by induction for any ordinal α\alpha. S0S_0 is the empty string L0=0L_0 = 0. S1S_1 is the string with one character "∅" and L1=1L_1 = 1. For α1\alpha \geq 1, Sα+1S_{\alpha+1} is the string obtained by concatenating the string SαS_\alpha, a comma character ",", an opening brace character "{", the string SαS_\alpha and finally a closing brace character "}". It is of length Lα+1=Lα+2+Lα+1L_{\alpha+1} = L_\alpha + 2 + L_\alpha + 1. Beware that ordinal operations are not commutative so this cannot be simplified a priori!

For any limit ordinal λ\lambda, the string SλS_\lambda is obtained by taking the union of the LαL_\alpha-sequence SαS_\alpha for α<λ\alpha < \lambda. This is still a well-defined sequence since these strings always agree on the character at a given index. SλS_\lambda is of length Lλ=supα<λLαL_\lambda = \sup_{\alpha < \lambda} L_\alpha.

By construction, LαL_\alpha is an increasing sequence of ordinals and so LααL_\alpha \geq \alpha. Can we calculate it more explicitly?

Warning: The rest of the blog post gives the solution to this puzzle, so you might want to have fun solving it yourself first and then go back checking my proposed solution later 😉...

Let’s consider some examples. In the case ω=\omega = \mathbb N, the string SωS_\omega can be more easily seen as the ω\omega-concatenation of finite strings: the empty set, a comma, S1S_1 surrounded by braces, a comma, S2S_2 surrounded by braces, a comma, S3S_3 surrounded by braces, a comma, etc So clearly Lω=ωL_{\omega} = \omega and this aligns with the definition for limit ordinal.

In order to write Sω+1S_{\omega+1}, you first write the elements of ω\omega, followed by a comma, followed by an opening brace, followed by the elements of ω\omega and finally followed by a closing brace. So really this is an ω+ω+1\omega + \omega + 1 sequence. This aligns with the definition in the successor ordinal case, using the fact that k+ω=ωk + \omega = \omega for any k<ωk < \omega:

Lω+1=Lω+2+Lω+1=ω+2+ω+1=ω2+1L_{\omega+1} = L_\omega + 2 + L_\omega + 1 = \omega + 2 + \omega + 1 = \omega2 + 1

Continuing for other successor ordinals, one can write

Lω+2=Lω+1+2+Lω+1+1=ω2+1+2+ω2+1+1=ω4+2L_{\omega+2} = L_{\omega+1} + 2 + L_{\omega+1} + 1 = \omega2 + 1 + 2 + \omega2 + 1 + 1 = \omega4 + 2 Lω+3=Lω+2+2+Lω+2+1=ω4+1+2+ω4+2+1=ω8+3L_{\omega+3} = L_{\omega+2} + 2 + L_{\omega+2} + 1 = \omega4 + 1 + 2 + \omega4 + 2 + 1 = \omega8 + 3

and more generally for all n<ωn < \omega:

Lω+n=ω2n+nL_{\omega+n} = \omega{2^n} + n

To calculate Sω2S_{\omega2}, one takes the union for n<ωn < \omega of the Lω+nL_{\omega+n}-sequence of characters describing ω+n\omega+n. Its length is

Lω2=supn<ω(ω2n+n)=ω2L_{\omega2} = {\sup_{n < \omega} \left(\omega{2^n} + n\right)} = \omega^2

Then the exact same calculation as above leads for all n<ωn < \omega to

Lω2+n=ω22n+nL_{\omega2+n} = \omega^2{2^n} + n

Continuing this kind of calculations for larger values ω3,ω4,,ω2\omega3, \omega4, \dots, \omega^2 suggests the following conjecture: For every infinite ordinal α\alpha, the order-type of the sequence describing its element is:

Lα=Lωβ+n=ωβ2n+nL_{\alpha} = L_{\omega \beta + n} = \omega^\beta 2^n + n

where β1\beta \geq 1 and n<ωn < \omega are the quotient and remainder of the euclidean division of α\alpha by ω\omega.

Let’s sketch the proof by induction on β\beta. We already explained the case β=1\beta = 1 in the example above. Similarly, for a given β1\beta \geq 1, it is enough to prove the case n=0n = 0, the formula for n>0n > 0 follows, using the property k<ω,k+ωβ=ωβ\forall k < \omega, k + \omega^\beta = \omega^\beta and the calculations we gave for the case β=1\beta = 1.

If the formula holds for some β1\beta \geq 1 then because ω(β+1)\omega{(\beta + 1)} is limit and the lengths are increasing, the formula holds for β+1\beta + 1:

Lω(β+1)=Lωβ+ω=supn<ωLωβ+n=supn<ω(ωβ2n+n)=ωβ+1L_{\omega {(\beta + 1)}} = L_{\omega\beta + \omega} = {\sup_{n < \omega} L_{\omega \beta + n}} = {\sup_{n < \omega} {(\omega^\beta 2^n + n)} } = \omega^{\beta+1}

Finally, if the formula holds for all β\beta below a limit ordinal λ\lambda then because the lengths are increasing the formula holds for λ\lambda too:

Lωλ=supβ<λLωβ=supβ<λωβ=ωλL_{\omega \lambda} = {\sup_{\beta < \lambda} L_{\omega \beta}} = {\sup_{\beta < \lambda} \omega^{\beta}} = \omega^{\lambda}

Q.E.D.

Sorry, no JavaScript program to calculate these infinite strings 😇...

Review of my year 2019 at Igalia

Co-owner and mentorship

In 2016, I was among the new software engineers who joined Igalia. Three years later I applied to become co-owner of the company and the legal paperwork was completed in April. As my colleague Andy explained on his blog, this does not change a lot of things in practice because most of the decisions are taken within the assembly. However, I’m still very happy and proud of having achieved this step 😄

One of my new duty has been to be the “mentor” of Miyoung Shin since February and to help with her integration at Igalia. Shin has been instrumental in Igalia’s project to improve Chromium’s Code Health with an impressive number of ~500 commits. You can watch the video of her BlinkOn lightning talk on YouTube. In addition to her excellent technical contribution she has also invested her energy in company’s life, helping with the organization of social activities during our summits, something which has really been appreciated by her colleagues. I’m really glad that she has recently entered the assembly and will be able to take a more active role in the company’s decisions!

Julie and Shin at BlinkOn11
Julie (left) and Shin (right) at BlinkOn 11.

Working with new colleagues

Igalia also hired Cathie Chen last December and I’ve gotten the chance to work with her as part of our Web Platform collaboration with AMP. Cathie has been very productive and we have been able to push forward several features, mostly related to scrolling. Additionally, she implemented ResizeObserver in WebKit, which is a quite exciting new feature for web developers!

Cathie Chen signing 溜溜溜
Cathie executing traditional Chinese sign language.

The other project I’ve been contributed to this year is MathML. We are introducing new math and font concepts into Chromium’s new layout engine, so the project is both technically challenging and fascinating. For this project, I was able to rely on Rob’s excellent development skills to complete this year’s implementation roadmap on our Chromium branch and start upstreaming patches.

In addition, a lot of extra non-implementation effort has been done which led to consensus between browser implementers, MathML enthusiasts and other web developer groups. Brian Kardell became a developer advocate for Igalia in March and has been very helpful talking to different people, explaining our project and introducing ideas from the Extensible Web, HTML or CSS Communities. I strongly recommend his recent Igalia chat and lightning talk for a good explanation of what we have been doing this year.

Photo of Brian
Brian presenting his lightning talk at BlinkOn11.

Conferences

These are the developer conferences I attended this year and gave talks about our MathML project:

Me at BlinkOn 11
Me, giving my BlinkOn 11 talk on "MathML Core".

As usual it was nice to meet the web platform and chromium communities during these events and to hear about the great projects happening. I’m also super excited that the assembly decided to try something new for my favorite event. Indeed, next year we will organize the Web Engines Hackfest in May to avoid conflicts with other browser events but more importantly, we will move to a bigger venue so that we can welcome more people. I’m really looking forward to seeing how things go!

Paris - A Coruña by train

Environmental protection is an important topic discussed in our cooperative. This year, I’ve tried to reduce my carbon footprint when traveling to Igalia’s headquarters by using train instead of plane. Obviously the latter is faster but the former is much more confortable and has less security constraints. It is possible to use high-speed train from Paris to Barcelona and then a Trenhotel to avoid a hotel night. For a quantitative comparison, let’s consider this table, based on my personal travel experience:

Traject Transport Duration Price CO2/passenger
Paris - Barcelona TGV ~6h30 60-90€ 6kg
Barcelona - A Coruña Trenhotel ~15h 40-60€ Unspecified
Paris - A Coruña
(via Madrid)
Iberia 4h30-5h 100-150€ 192kg

The price depends on how early the tickets are booked but it is more or less the same for train and plane. Renfe does not seem to indicate estimated CO2 emission and trains to Galicia are probably not the most eco-friendly. However, using this online estimator, the 1200 kilometers between Barcelona and A Coruña would emit 50kg by national train. This would mean a reduction of 71% in the emission of CO2, which is quite significant. Hopefully things will get better when one day AVE is available between Madrid and A Coruña… 😉