2017-06-28, post № 173
C, mathematics, programming, #constant
Today it is June the 28th which means that it is 𝜏 day!
The irrational and transcendental constant 𝜏 is what defines
, which obviously makes it an important constant. To celebrate this day, I created a C program which calculates 𝜏 by randomly creating 𝟫-dimensional points inside the 𝟫-dimensional hypercube and testing if they are inside the 𝟫-dimensional hypersphere with its center located at
.
Today’s 𝜏 time is 3:18:53
as
. As one does not know if the time is specified as ante or post meridiem, there are actually two perfectly acceptable 𝜏 times.
;b$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$b
h$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$+
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
,$$$$$$$$$kn}~I"`($$$$$$$x````````````````
)$$$m $$$$$$$$
+$$c q$$$$$$$>
$$ $$$$$$$$
$$$$$$$$.
'$$$$$$$$
$$$$$$$$
?$$$$$$$a
$$$$$$$$
Q$$$$$$$f
$$$$$$$$
$$$$$$$$i
$$$$$$$$
$$$$$$$$;
$$$$$$$$
J$$$$$$$w
$$$$$$$$; $$~
$$$$$$$$ $$$
'$$$$$$$$C "$$$
$$$$$$$$$w '$$$$
$$$$$$$$$$$$$$$$$$$$B
$$$$$$$$$$$$$$$$$$.
$$$$$$$$$$$$$$$'
8$$$$$$$q
The formula used for calculating 𝜏 is derived from a 𝟫-dimensional hypersphere’s hypervolume formula
(see this Wikipedia article).
The constant gets calculated to
. The real value is approximately 𝜏 = 𝟨.𝟤𝟪𝟥𝟣𝟪𝟧…, which makes the percent error
Thereby, this C program’s approximation is not too far off. The source code is listed below and can also be downloaded here. Instructions on how to compile it using GCC can be seen below or in the source code.
gcc tau.c -o tau -lm; ./tau
tau = 6.293700
Resources worth checking out regarding 𝜏 are The Tau Manifesto and 2 Pi or Not 2 Pi? I wish everybody a happy 𝜏 day.
2017-06-17, post № 172
ascii, HTML, JavaScript, mathematics, programming, Python, #animation, #fractal
The Mandelbrot Set is the set of all complex points which, when one iteratively and infinitely applies the function
, converge to a value. This simple rule results in stunning complexity and beauty.
Many Mandelbrot Set animations use regularly colored pixels to represent the number of iterations needed at the fractal’s edges to escape converging. Yet this mathematical object can also be represented as ASCII characters — similar to what I did in my Curses Cam post. The characters are chosen according to their opaqueness. A full stop (‘.’) looks lighter than a dollar sign (‘$’), so they represent a smaller or larger number of iterations needed. The order of characters used is taken from this post by Paul Bourke.
As there are only 𝟩𝟢 characters used, each frame is being rendered twice to determine the minimum number of iterations needed by every point in that frame. Thereby the full visual character range is used.
The characters shown below represent a Mandelbrot Set still. To see the zoom in action, either run the program (listed below) or take a look at this Mandelbrot Set ASCII journey.
..................''''''''``"">>II``''''......
..................''''''''``^^,,ii::^^``''''......
..................''''''''``^^::ww$$++,,````''''......
................''''''''``^^^^""::$$$$$$::""^^``''''......
..............''''''````""{{;;XX$$$$$$$$uuUU,,,,""''......
............''''``````^^,,rr$$$$$$$$$$$$$$$$<<$$--``........
........''``````````^^""LL$$$$$$$$$$$$$$$$$$$$__""``''......
..''''''^^!!"""",,""""::__$$$$$$$$$$$$$$$$$$$$$$ll""''........
''''````^^::__IIYYii::ll$$$$$$$$$$$$$$$$$$$$$$$$pp^^''........
''``````"";;[[$$$$$$++__$$$$$$$$$$$$$$$$$$$$$$$$$$^^''''......
``^^^^,,;;>>$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ww``''''......
"",,,,II$$nn$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$""``''''......
"",,,,II$$nn$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$""``''''......
``^^^^,,;;>>$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ww``''''......
''``````"";;[[$$$$$$++__$$$$$$$$$$$$$$$$$$$$$$$$$$^^''''......
''''````^^::__IIYYii::ll$$$$$$$$$$$$$$$$$$$$$$$$pp^^''........
..''''''^^!!"""",,""""::__$$$$$$$$$$$$$$$$$$$$$$ll""''........
........''``````````^^""LL$$$$$$$$$$$$$$$$$$$$__""``''......
............''''``````^^,,rr$$$$$$$$$$$$$$$$<<$$--``........
..............''''''````""{{;;XX$$$$$$$$uuUU,,,,""''......
................''''''''``^^^^""::$$$$$$::""^^``''''......
..................''''''''``^^::ww$$++,,````''''......
..................''''''''``^^,,ii::^^``''''......
The fractal viewer is written in Python 2.7 and works by determining the terminal’s size and then printing a string of according size. This creates the illusion of a moving image, as the terminal will hopefully always perfectly scroll so that only one frame is visible at a time.
In the code’s first non-comment line one can change the complex point at the image’s center, (really, its conjugate, which is partially irrelevant as the set is symmetric along the real axis) the initial zoom value (complex distance above the image’s center), the zoom factor (the factor by which the zoom value gets multiplied after a frame), the total number of frames (- 𝟣 means there is no upper limit), the delay between frames (in seconds, can be floating-point) and the color characters used.
The program’s source code may not be particularly easy to read, yet it does its job and only requires seven non-comment lines! The code is shown below, though the .py
file can also be downloaded.
To achieve the JavaScript animation linked to above, I wrote a simple Python converter which takes in the fractal renderer’s output and it spits out an HTML page. This converter’s code is not listed, though the .py
file can be downloaded. Instructions on how to use the converter can be seen in its source code.
# Python 2.7 Code; Jonathan Frech, 15th and 16th of June 2017
P,Z,F,N,D,K=-.707+.353j,3,.9,-1,.1," .'`^\",:;Il!i><~+_-?][}{1)(|\\/tfjrxnuvczXYUJCLQ0OZmwqpdbkhao*#MW&8%B@$"
import os,time,sys;H,W,S,n=map(int,os.popen("stty size").read().split())+[sys.stdout,0];W/=2
def C(c):
global m;z,i=0j,-1
while abs(z)<=2 and i<len(K)-1+M:z,i=z*z+c,i+1
m=min(m,i);return K[i-M]*2
while n<N or N==-1:h=Z*2.;w=h*W/H;R=lambda:"\n\n"*(n!=0)+"\n".join("".join(C(P-complex(w/2-w*x/W,h/2-h*y/H))for x in range(W))for y in range(H));M,m=0,len(K);R();M=max(M,m);S.write(R());S.flush();Z,n=Z*F,n+1;time.sleep(D)
2017-06-03, post № 171
mathematics, OEIS, programming, Python, Wolfram Language, #decimal, #decimal sum, #digit sum, #distinct prime, #int, #integer, #number, #number theory, #prime, #prime factors, #primes
The On-Line Encyclopedia of Integer Sequences gets regularly updated with new integer sequences. One of the recent updates was contributed by me, A285494.
A285494 is the list of all numbers 𝑘 so that its digit sum equals its number of distinct prime factors.
A number’s digit sum is the sum of all of its decimal digits. The number 𝟨𝟤𝟪𝟥𝟣𝟪𝟧𝟥, for example, has a digit sum of 𝟨 + 𝟤 + 𝟪 + 𝟥 + 𝟣 + 𝟪 + 𝟧 + 𝟥 = 𝟥𝟨.
A number’s number of distinct prime factors is the number of different prime numbers that multiply together to result in the original number. As an example,
, so it has five prime factors of which four are distinct.
Thereby one can conclude that 𝟨𝟤𝟪𝟥𝟣𝟪𝟧𝟥 is not an entry in this sequence, as
.
The sequence is certainly infinite, as the number
with
has a digit sum of
and — because
— exactly two distinct prime factors.
In the encyclopedia entry, I provided a Mathematica one-liner to compute the first few entries of this sequence. Since then, I have also written a Python two-liner to achieve the same goal.
(* Mathematica *)
Select[Range[2,10000],Total[IntegerDigits[#]]==Length[FactorInteger[#]]&]
Out = {20, 30, 102, 120, 200, 300, 1002, 1200, 2000, 2001, 2002, 3000, 3010}
# Python 2.7
>>> def p(n):exec"i,f=2,set()\nwhile n>1:\n\tif n%i==0:f.add(i);n/=i;i=1\n\ti+=1";return len(f)
>>> print filter(lambda n:p(n)==sum(map(int,str(n))),range(2,10001))
[20, 30, 102, 120, 200, 300, 1002, 1200, 2000, 2001, 2002, 3000, 3010]
Posts:
242-240, 239-237, 236-234, 233-231, 230-228, 227-225, 224-222, 221-219, 218-216, 215-213, 212-210, 209-207, 206-204, 203-201, 200-198, 197-195, 194-192, 191-189, 188-186, 185-183, 182-180, 179-177, 176-174, 173-171, 170-168, 167-165, 164-162, 161-159, 158-156, 155-153, 152-150, 149-147, 146-144, 143-141, 140-138, 137-135, 134-132, 131-129, 128-126, 125-123, 122-120, 119-117, 116-114, 113-111, 110-108, 107-105, 104-102, 101-99, 98-96, 95-93, 92-90, 89-87, 86-84, 83-81, 80-78, 77-75, 74-72, 71-69, 68-66, 65-63, 62-60, 59-57, 56-54, 53-51, 50-48, 47-45, 44-42, 41-39, 38-36, 35-33, 32-30, 29-27, 26-24, 23-21, 20-18, 17-15, 14-12, 11-9, 8-6, 5-3, 2-1Jonathan Frech's blog; built 2021/04/16 20:21:20 CEST