Monday, December 14, 2020

Visualizing chaotic attractors via 3D-printed models

 It has been 30 years since I first studied chaotic circuits and dynamical systems. At that time, we visualize the beautiful 3-D (and higher dimensional) chaotic attractors using a Silicon Graphics workstation. I was delighted to read in the December 2020 issue of the Notices of the AMS the article "Modeling Dynamical Systems for 3D Printing" by Stephen K. Lucas, Evelyn Sander and Laura Taalman. The ubiquity of inexpensive 3D printers makes it much easier to create 3D models of chaotic attractors. The authors provided excellent Mathematica and Matlab programs that make it easy to create STL files that can be sent to 3D printers to print these models. With python being able to be run on platforms ranging from PC to smartphones to Raspberry Pi's, I thought it would be nice to have a Python version of these programs. I ported the Matlab program to Python and utilized Python's object oriented features to make it easy to use them for other chaotic dynamical systems. 

The Python port is available here: https://github.com/postvakje/3d-printing-of-chaotic-attractor

The file dynamical_systems.py can be edited to add additional dynamical systems by providing the parameters, initial and ending simulation time, initial conditions and system equations. 

The data files that are output can be used with an script on OpenSCAD to create STL files.




Tuesday, November 24, 2020

The special place of the decimal number system

Modern society has been using the decimal number system for a long time, i.e. a number $n$ is expressed in base $10$ as $n = \sum_i b_i10^i$ where $0\leq b_i < 10$ are integers denoting the decimal digits of $n$.

Although there have been other cultures and civilizations who have used other number systems, most notably the Roman numerals and the Mayan base-20 number system, it was believed the decimal system was used by many due to us having 10 fingers. From a mathematical point of view, the base of the number system is arbitrary. For digital computers, using base 2 is more appropriate as it is easier to build components representing and processing 2-valued logic, or equivalently the binary digit, or the bit. It is interesting to note that one of the first (I said one of the first as there is a dispute whether the ABC computer is the first digital computer) digital computer, ENIAC, uses a decimal system and requires 10 vacuum tubes to represent a single decimal digit, each tube representing each of the numerals 0, 1, ..., 9.

Thus it came as a surprise to me that there is something inherently special about the decimal system. In 1964 Gustav Lochs proved the following theorem.

Lochs' theorem (1964): Let $m$ be the number of terms of a continued fraction expansion needed to determine the first $n$ decimal digits of a real number $x$. Then for almost all $x$, $\lim_{n\rightarrow \infty} \frac{m}{n} = \frac{ln(10)ln(64)}{\pi^2} \approx 0.970$.

What this tells us is that each coefficient of the continued fraction expansion contain slightly more information than each decimal digit. Had we use a base-11 numbering system, it would have been the opposite, each base-11 digit would contain more information than each additional continued fraction coefficient.


 


Monday, October 19, 2020

A 2D walk generated by primes

Consider starting at (0,0) on the plane and as we enumerate the primes p, except for 2 and 5, we take a step in the E, N, W, S direction depending on whether the last decimal digit of p is 1, 3, 7, 9 respectively.

The resulting 2D walk looks quite interesting. The first 200,000 steps looks like this:


The Python code used to generate this plot can be found here.
Using a different correspondence of last digit to directions, we get different, but qualitatively similar plots.
For instance (1->W, 3->E, 7->S, 9->N) gives us:
Overall, they seem more clustered and dense that a 2D random walk.

Wednesday, July 22, 2020

Happy casual π day!

Today is also known as π approximation day. Today is July 22, which is written as 22/7 in many countries.

22/7 is a rational number with repeating digits in decimal 3.14285714285714... and is one of the earliest approximation (besides the number 3) to π = 3.141592653589...  and has been used since antiquity. 22/7 approximates π to 2 decimal digits. 22/7 is also the second convergent in the simple continued fraction expansion of π. The convergents in this continued fraction are the best rational approximation of π, in the sense that if n/d with n and d coprime is a convergent, then no other rational number m/c with c ≤ d is closer to π.  It is interesting to note some other convergents have also been used as approximation to π. For instance the fourth convergent 355/113 = 3.141592920... matches up with π to 6 decimal places and was discovered by astronomer Zu Chongzhi (祖沖之) in the fifth century A.D.

I talked about these 2 approximations in my blog post from Pi Day 2017. For countries where the date format is YY/MM, we have to wait 2 years before we have a casual π or π approximation month during July 2022!

Monday, July 20, 2020

80's, 90's and today

I have been listening to a music channel called "80's, 90's and today" and it occurs to me that while there is only 1 decade between 80's and 90's, there are now 3 decades between 90's and today. When I was growing up, music from the 60's are considered oldies, perhaps the oldies today should include 80's and 90's music. Maybe the music channel should change its title, unless the implication is that "today" consists of music of the last 2+ decades (the 00's, the 10's and the start of the 20's) rather than grouped by a single decade, as was done before.

Thursday, November 7, 2019

Prepending and appending a repunit with the same number

Consider a repunit R(n) of n digits in decimal, i,e, the number consisting of n 1's which is equal to $(10^n-1)/9$. If we append and prepend R(n) with the same number k, which we will denote as  k|R(n)|k with | denoting concatenation of digits, will k|R(n)|k be prime? For instance, for k = 324 and n = 1111, $k|R(n)|k = 3241111324 = 2^2\times 11^2 \times 281\times 23831$. It turns out that if n is a power of 2, then k needs to have at least n digits for k|R(n)|k to be prime. In particular, we have the following result:

Theorem: If $2^r$ is the largest power of 2 that divides n and k has at most $2^r-1$ digits, then k|R(n)|k is not prime. This is true even if some of the digits of k are leading zeros.

Proof: If k has m digits, then $k|R(n)|k = k(10^{n+m}+1) + R(n)10^m$ which is a multiple of gcd$(R(n),10^{n+m}+1)$.

Since $10^{2^r} - 1 = (10^{2^{r-1} -1})\times (10^{2^{r-1} + 1})$ and 9 does not divide $10^n+1$, by induction it is easy to show that $10^{2^w} + 1$ is a divisor of  $R(2^r)$ for $1 \leq w < r$. Since $R(2^r)$ is a divisor of $R(2^r s)$, $10^{2^w} + 1$ is also a divisor of $R(2^r s)$.

For $1 \leq m < 2^r$, let $t$ be the 2-adic valuation (or 2-adic order) of m, i.e. t is the largest integer such that $2^t$ divides $m$. This means that  $0 \leq t  < r$.

Then $10^{2^r s+m}+1 = 10^{2^t q}+1 = (10^{2^t})^q + 1$ for some odd number $q$.

Since the sum of two odd powers $a^q+b^q$ is divisible by $a+b$, this implies that $10^{2^r s+m}+1$ is divisible by $10^{2^t}+1$.

This implies that for $n = 2^r s$ and for all $1 \leq m < 2^r$, gcd$(R(n),10^{n+m}+1) \geq 10^{2^t}+1 > 1$, i.e. $k|R(n)|k$ is not prime. QED

For example, for n = 32, the smallest $k$ such that $k|R(n)|k$ is prime is k = 10000000000000000000000000000077, a number with 32 digits. The smallest such $k$ for different $n$'s can be found in OEIS sequence A263182 (see also OEIS sequence A329121).

Wednesday, November 6, 2019

Product of a number and its reversal in decimal

The number 10119126106147652568 is the smallest number such that it is the product of a number and its reversal in decimal notation in exactly 5 ways. 

10119126106147652568 = 8848263411 * 1143628488 = 8044687521 * 1257864408 = 4884561702 * 2071654884 = 4440958722 * 2278590444 = 4082378742 * 2478732804.

Multiply this number by 10 and it is the smallest number such that it is the product of a number and its reversal in decimal notation in exactly 10 ways. 

101191261061476525680 = 88482634110 * 1143628488 = 80446875210 * 1257864408 = 48845617020 * 2071654884 = 44409587220 * 2278590444 = 40823787420 * 2478732804 = 24787328040 * 4082378742 = 22785904440 * 4440958722 = 20716548840 * 4884561702 = 12578644080 * 8044687521 = 11436284880 * 8848263411.

Friday, January 11, 2019

Numbers whose binary complement is larger than the binary complement of its square.

OEIS sequence A323192 lists numbers whose binary complement is larger than the binary complement of its square. The binary complement is defined as flipping each bit in its binary representation. For instance, 29 is 11101 in binary, so its binary complement is 2 which is 00010 in binary. Note that the binary complement function is not one-to-one, for instance the binary complement of 61 (111101 in binary) is also 2.  This function is not exactly the same as 1's complement in computer arithmetic, since the number of bits flipped is not fixed but is equal to the number of bits in the binary representation of the number.

Giovanni Resta noted that the first 13 terms of sequence A323192 are of the form $\lfloor\sqrt{2^k-1}\rfloor$. It turns out this is true in general. In fact we can prove more. In particular, we can show that the terms of this sequence corresponds to numbers of the form $\lfloor\sqrt{2^{2k-1}}\rfloor$ which are larger than $\frac{1}{2} + \sqrt{\frac{1}{4} + 2^{2k-1} - 2^k}$ with $k > 0$.

This result follows from the following theorem:

Theorem: if $n$ is a term of OEIS sequence A323192, then $n$ is of the form $\lfloor\sqrt{2^{2k-1}}\rfloor$ for some $k > 0$. In addition, $\lfloor\sqrt{2^{2k-1}}\rfloor$ is a term if and only if it is larger than $\frac{1}{2} + \sqrt{\frac{1}{4} + 2^{2k-1} - 2^k}$.

Proof: suppose $n$ has $k$ bits in its binary representation, i.e. $2^{k-1} \leq n < 2^k$. Then $n^2$ has either $2k-1$ or $2k$ bits.

First we show that if $n$ is a term of the sequence, then $n^2$ has $2k-1$ bits. Suppose $n^2$ has $2k$ bits, i.e. $n^2 \geq 2^{2k-1}$. Then $2^{2k} - 1 - n^2 < 2^k - 1 - n$. This is rearranged as $n^2 - n + 2^k - 2^{2k} > 0$. Solving this quadratic inequality leads to $n > 2^k$ which contradicts the fact that $n$ has $k$ bits.

Thus $n^2 < 2^{2k-1}$ and $2^{2k-1} - 1 - n^2 < 2^k - 1 - n$. Solving this inequality and combining it with $n < \sqrt{2^{2k-1}}$ shows that $n$ must satisfy $\sqrt{2^{2k-1}} > n >  \frac{1}{2}+ \sqrt{\frac{1}{4} + 2^{2k-1} - 2^k}$.

To complete the proof, we need to show that for each $k$, there is at most one integer satisfying this inequality. This is easily verified for $k = 1$. Assume that $k > 1$. Let $a = \sqrt{2^{2k-1}}$ and $b = \frac{1}{2} + \sqrt{\frac{1}{4}+ 2^{2k-1} - 2^k}$.

Using the identity $\sqrt{x} - \sqrt{y} = (x-y)/(\sqrt{x}+\sqrt{y})$ it follows that $a-b = -\frac{1}{2} + \frac{2^k - \frac{1}{4}}{\sqrt{2^{2k-1}}+\sqrt{\frac{1}{4}+ 2^{2k-1} - 2^k}} < -\frac{1}{2} + \frac{2^k}{\sqrt{2^{2k-1}} + \sqrt{2^{2k-1}-2^k}}$.

Since $k \geq 2$, $\sqrt{2^{2k-1}-2^k} = \sqrt{2^{2k-1}(1-2^{1-k})} \geq \sqrt{\frac{1}{2}}\ \sqrt{2^{2k-1}}$. This implies that $a-b < -\frac{1}{2} + \frac{2^k}{\frac{\sqrt{2}+1}{\sqrt{2}}\sqrt{2^{2k-1}}} = \frac{2\sqrt{2}}{\sqrt{2}+1} - \frac{1}{2} < 0.672$. Thus it follows that there is at most one integer in the range between $b$ and $a$.

The above discussion also completely characterizes the sequence. $\lfloor\sqrt{2^{2k-1}}\rfloor$ is a term if and only if $\sqrt{2^{2k-1}}-\lfloor\sqrt{2^{2k-1)}}\rfloor < a-b$ where $a-b$ is as defined above.

The criterion can be simplified as:
$\lfloor\sqrt{2^{2k-1}}\rfloor$ is a term if and only if it is larger than $\frac{1}{2} + \sqrt{\frac{1}{4} + 2^{2k-1} - 2^k}$. This concludes the proof.$\blacksquare$

Note that $a-b \rightarrow \frac{1}{2}$ as $k \rightarrow \infty$, i.e. for large $k$, the fractional part of $\sqrt{2^{2k-1}}$ should be less than about $\frac{1}{2}$ in order for the integer part to be a term.

The numbers $k$ such that $\lfloor\sqrt{2^{2k-1}}\rfloor$ is a term of OEIS sequence A323192 are listed in OEIS sequence A323062.

Monday, January 7, 2019

560106 and 601065

There is a remarkable property of the sequence of numbers 560106, 5606106, 56066106, 560666106, etc. Take any number of the sequence, say 56066106, reverse the digits: 60166560, multiply these 2 numbers, multiply the result by 10 and the result is a perfect square. Thus
$56066106 \times 60166065 \times 10 = 33732769778928900 = 183664830^2$.

To see this, let us denote the decimal digits reversal of a number $n$ as $R(n)$.   Let $a = 56\times 10^{4+k}+106 + 6000\times (10^k-1)/9$ for $k\geq 0$. Then $R(a) = 601\times 10^{3+k}+65 + 6000\times (10^k-1)/9$. The number $10\times a\times R(a)$ can be written as $30360100\times (10^{k + 3} - 1)^2/9$ whose square root is $5510\times (10^{k + 3} - 1)/3$.

It is clear the the digit reversals of these numbers, i.e. 601065, 6016065, 60166065, 601666065, ..., satisfy the same property.

Other numbers with this property can be found in OEIS sequence A323061.

Sunday, December 30, 2018

Christmas lights ring oscillator

We set up a string of Christmas lights wrapped around a pine tree outside and plug it into an outlet with a dusk to dawn sensor so it will only turn on at dusk. After a windy day, some of the lights fell from the tree so we adjusted it in the evening. After adjustment, my son noticed that the lights turn on and off at a regular interval, which was strange since these lights are not flashing lights, but are supposed to be on all the time. It turns out one of the light bulb is too close to the light sensor on the outlet, thus tricking it to turn off since the outlet assumed it was dawn. Since it is now dark without the lights, the sensor assumes it is dusk and turns the light back on and so on and so on. Since there is a delay in the sensor, this resulted in the lights being turned on and off periodically. In essence, we have constructed a ring oscillator. A ring oscillator consists of a loop of an odd number of NOT logic gates. The number of stages and the delay in each stage of the logic gates determine the frequency of the oscillator. In our case, we have a single NOT gate represented by the dawn-to-dusk light sensor/outlet combination.