# Prime time for Riemann Hypothesis

## Books that make you think

I already had a post where I mentioned Reimann Hypothesis after reading The Music of The Primes by Marcus du Sautoy. As far as I recall, I liked the book a lot. It was written for a wide audience and was an easy read. Later, I accidentally found another book on the subject that was intended for more mathematically inclined readers, namely, Prime Obsession by John Derbyshire. Having been fascinated by the subject of prime numbers, the prime number theorem it was a short way to other similar books, such as Prime Number and the Riemann Hypothesis by Barry Mazur and William Stein. Then smoothly transitioning to A Study of Bernhard Riemann’s 1895 Paper by Terrence P. Murphy. Just to conclude with H.M. Edwards Riemann Zeta Function. By the way, the order in which I mentioned the books more or less conveys the mastery of mathematics required to be able to understand what’s going on in them. Which means that two last books require substantial background in calculus and complex analysis. But it’s doable if you have time and prime obsession.

## Easy to not-so-easy books

I’d like to provide more details about the books above which I personally read end-to-end and also about ones that I bought, but haven’t finished yet, or only skimmed through.

Actually, I’d rather start with a short description of what the Reimann Hypothesis is by citing the Millennium Problems web site that describes a number of 21st century math problems that can bring you 1,000,000 USD for solving any of them.

So the Riemann Hypothesis is

Source: Millennium Problems

Some numbers have the special property that they cannot be expressed as the product of two smaller numbers, e.g., 2, 3, 5, 7, etc. Such numbers are called prime numbers, and they play an important role, both in pure mathematics and its applications. The distribution of such prime numbers among all natural numbers does not follow any regular pattern.  However, the German mathematician G.F.B. Riemann (1826 – 1866) observed that the frequency of prime numbers is very closely related to the behavior of an elaborate function
ζ(s) = 1 + 1/2s + 1/3s + 1/4s + …
called the Riemann Zeta function. The Riemann hypothesis asserts that all interesting solutions of the equation
ζ(s) = 0
lie on a certain vertical straight line.
This has been checked for the first 10,000,000,000,000 solutions. A proof that it is true for every interesting solution would shed light on many of the mysteries surrounding the distribution of prime numbers.

Having said that now let’s look at the books.

## The Music of The Primes

The book was written by Marcus du Sautoy in 2003. As I mentioned, the book does not require a degree in mathematics to be able to understands what it’s talking about. The material in it is interesting and engaging. In addition to covering, The Prime Number Theorem and Reimann Hypothesis it also covers other topics related to prime numbers usage, like cryptography. It can be a good starting point into a long journey with prime numbers.

## Prime Numbers and the Riemann Hypothesis

The book was written by Barry Mazur and William Stein in 2016. It has four parts, where first part intended for a wide audience, and each consecutive part presuppose gradually increasing knowledge of math to be able to grasp the content. What’s interesting about this book that it sheds light on some interesting connections between Riemann Hypothesis and Fourie Transform, which electrical engineers can relate to. Also the book is quite short.

## Prime Obsession

The book is written by John Derbyshire in 2003 (same year when Marcus du Sautoy wrote his book). This book has two parts: The Prime Number Theorem and The Riemann Hypothesis, but it goes into nitty gritty details of both of them and don’t allow a reader relax too much. Following the content of the book could require some math background and at times some calculations to be sure that one gets proper understanding of what’s going on. Personally, out of all the books I mention in this post I find this one the most engaging.

## A Study of Bernhard Riemann’s 1859 Paper

The book is written by Terrence P. Murthy in 2020. It is one of the two most technical books on the subject that requires substantial background in mathematics. The book provides Riemann’s 1859 paper in full in English and then systematically goes and provide proofs for all relevant parts of Riemann’s paper in subsequent chapters (except for the Riemann Hypothesis itself :). I think Terrence Murphy summarizes who this book is intended for in his own words the best:

Who Is This Book For?
If you are reading this, chances are you have developed a keen interest in the Reimann Hypothesis. Maybe you read John Derbyshire’s excellent book Prime Obsession. Or perhaps you read that the Riemann Hypothesis is one of the seven Millennium Prize Problems, with a \$1 million prize for its proof.
To advance your knowledge substantially beyond Derbyshire’s book, you must have (or develop) a good understanding of the field of complex analysis (we will describe that as knowledge at the “hobbyist” level). So, this book is probably not for you unless you are at least at the hobbyist level.

## Riemann Zeta Function

The book was written by H.M. Edwards in 1974. I’d rather describe it by continuing the citation from the previous book by Terrence P. Murthy:

After developing an interest in the Riemann Hypothesis, the first stopping point for many is Edwards’ excellent book Riemann’s Zeta Function. The Edwards book provides a wealth of information and insight on the zeta function, the Prime Number Theorem and the Riemann Hypothesis. And that brings us to the next group of people who do not need this book. If you eat, sleep and breath complex analysis, we will say you are at the “guru” level. In that case, the Edwards book will be easy reading and will provide you with the information you need to substantially advance your knowledge of Riemann’s Paper and the Riemann Hypothesis.

As you may tell, “guru” level in math is required to fully digest this book. So it want be easy to say the least.

### A good introductory paper on the subject

If you are interested in a short, but engaging introduction into what are Prime Number Theorem and the Riemann Hypothesis I recommend to read Don Zagier’s The First 50 Millions Prime Numbers paper, published in New Mathematical Intelligencer (1977) 1-19.

If you know Russian you can read the same paper that was published in Russian only in 1984 in the Uspekhi Matematicheskikh Nauk journal.

## Parting words

All in all, these five books can take a good chunk of a full year to work through or possibly even more, especially the last two. So what are you waiting for? Life is too short to waste it on watching TV series or YouTube nonsense. The treasures of math and deeper understanding of the world are awaiting for ones who know where to look for.

# Errata for the Thinking Better book and some commentary

This post is a continuation of the previous one about Thinking Better book (ISBN-13 ‏: ‎978-1541600362) by Marcus du Sautoy published in North America by Basic Books.

It seems like I was too eager to praise the book after reading just a few dozens of pages. Even though, on average the book is interesting to read, there were a number of things that could make the content of the Thinking Better even better. For example, having more diagrams accompanying the explanations for various concepts could be helpful. Having footnotes to provide more details or sources for cited papers could be helpful too etc.

## Errata

Having found a number of possible mistakes in the book I was sure that notifying Basic Books publishing about them would be valuable and they’d be happy to review and, if required, correct the content of the book. But since I’ve sent an email to the customer support there, I didn’t hear back. Below comes the table of potential issues that I was able to find while reading the book.

## Some other suggestions

The suggestions below are based on my experience with reading dozens of popular-science books on mathematics, physics neuroscience and biology.

### Diagram and Figures

The book has a number of diagrams in each chapter. Though most of them are helpful, some are not. The main issue I see with the diagrams in the book is that even though they are numbered, just like in the table above, that number isn’t referenced in the body of the book. This makes it hard to related the diagram to the content where it was mentioned.

There are places that I would add diagrams to clarify the content, since without having a diagram it is difficult to imagine what the text represent. Or it takes quite some time to understand author’s intent. For example, Figure 3.2. Six pyramids make a cuboid on page 84, is very confusing to say the least (no diagram is shown in my post due to copyright issues).

One additional example is when the sieve of Eratosthenes was mentioned on page 106. Usually, this method is visualized by a diagram, which helps a lot in understanding it. For a good visual example refer to the chapter 7 in the Prime Obsession book by John Derbyshire. Also check Wikipedia article about the sieve of Eratosthenes.

### Missing footnotes or notes

I agree that not all popular science books have footnotes or notes, but this particular book mentions a number of other books, papers and authors. Having footnotes or notes at the end of the book could have been beneficial to a curious reader. One of the papers cited in the book, had the names of the authors incorrect. For example, in the chapter 9, on page 261 it is written

Two mathematicians Duncan Watts and Steve Strogatz, discovered the secret, which they published in a paper in Nature in 1998.

The paper was Collective dynamics of ‘small-world’ networksNature 393, 440–442 (1998). And the authors were Duncan Watts and Steven Strogatz.

### Missing bibliography

There are no references in the book. Bibliography is also not a mandatory part of popular science books, but in most of the ones I read it was there and helped find similar books on the subject or get more details about specific topics mentioned in the book.

## Too harsh a criticism?

All in all, despite the drawbacks I mentioned above the book was worth reading. I think my criticism has to do with that fact that the Music of The Primes book, also written by Marucs du Satouy in 2003 didn’t have most of the issue I brought in this post.

# Reading by doing. ‘Thinking Better’ the book by Marcus du Sautoy

Have you heard about a new book Thinking Better: The Art of the Shortcut in Math and Life by Marcus du Sautoy? If not, you may consider given it a try, since this book is very engaging. The book is about various topics in mathematics and how they provide shortcuts that can be used in different fields of daily life to find solutions to seemingly daunting problems. These shortcuts speed up the computations and free time for you to do other things. Each chapter of the book starts with a puzzle that the reader is asked to solve. Then the main content of the chapter is related to the puzzle, while the solution is provided in the end.

I’ve already read The Music of the Primes that was also written by Marcus and thoroughly enjoyed it. What makes this book to stand out in comparison to The Music of The Primes is that it’s focused on practical advise that could be actioned by readers. But what I find most compelling about this book is that reading it is not enough to get the most out of the content, there is also a need to play with the content of each chapter, carefully examining it. Otherwise the subtle details and insight could be lost and not understood properly.

Marcus tries to present his ideas in a way that is accessible to a reader who is not supposed to be a math expert. That is why it seems his approach is to use as little of math terminology and formulas as possible. Even the word ‘formula’ doesn’t show up until page 20 into the book. This approach to writing popular science books is not new and it tries to achieve a trade off between a number of readers who may be frightened by the mathematical notation, and the number of readers who could be disappointed by the lack of it. Which brings me to the main point of this post. Even though Marcus doesn’t shy away from writing down some equations to exactly convey his ideas, there are places in the book where additional mathematical details could clarify his point even better. I also suggest to name the math objects as they are used in mathematics. There is no harm in doing that just like Steven Strogatz did in The Joy of x or John Derbyshire in the Unknown Quantity books. Proper math notation doesn’t frighten, but could actually help readers understand concepts better.

For example, in the first chapter of the book, on page 20 the following sequence is introduced

1, 3, 6, 10, 15, 21 …

Which as Marcus explains is a sequence of triangular numbers and the general formula to get the nth triangular number is

1/2 * n * (n + 1)

What I think is missing here is the fact that Marcus stops short of explaining that there is a general formula to find the sum of members of a finite arithmetic sequence. This is important, since each nth number in the triangular numbers sequence is a sum of the nth numbers of the arithmetic sequence that Marcus mentions on page 2, talking about Gauss’s school lesson

1, 2, 3, 4, 5, 6 …

Notice that this sequence is arithmetic, since the difference between each consecutive member and the previous one is constant. In this particular case it equals to 1.

For example, that general formula is

Sumn = 1/2 * n * (a1 + an), where a1 is the first member, which in the case of natural number sequence is 1; an stands for the last number until which we want to sum and n stands for the number of members starting from the first to the last we want to sum. Then substituting these values into the general formula we arrive at the formula Marcus mentioned in the book

nthtriangular number = 1/2 * n * (1 + n)

What this gives a reader is that now it’s possible to use this general formula to calculate sums of other arithmetic sequences, for example the sequence of odd numbers.

1, 3, 5, 7, 9, 11, 13, 15 …

Let’s calculate the sum of first 8 members of this sequence, a1 = 1, an = 15, n = 8, then

Sumn = 1/2 * n * (a1 + an) = 1/2 * 8 * (1 + 15) = 64

One additional, example where this general formula could have been mentioned by Marcus was on page 28, where he explains how to calculate the number of handshakes in a population of a city having N people. It goes like this. Imagine these N people standing in a line. Then the first person can make N – 1 handshakes ( minus one, since he cannot shake his own hands). Then the second one can make N – 2 handshakes, continuing in similar fashion until the last person who can make no handshakes, since everyone already handshaked him. Then Marcus mentions that the sum of handshakes is the sum from 1 to N – 1, which is the sum that Gauss was asked to perform in his math class:

1/2 * (N – 1) * N

It seems to me a reader can be very confused at this point, since it’s not that clear that this is the sum Gauss was tasked to perform. This is because Gauss was asked to calculate the sum of the first nth natural numbers,

1, 2, 3, 4, 5, 6 …

As was mentioned earlier the general formula for this sum is Sumn = 1/2 * n * (a1 + an) and in this particular case it’s

Sumn = 1/2 * n * (1 + n), Then, one may ask, where does the 1/2 * (N – 1) * N comes from?

To get out of the confusion state, two things could be helpful. First, it’s a diagram of people standing in line waiting to be handshaked, and a little bit more details on how the 1/2 * (N – 1) * N formula was derived.

Looking at the diagram with four people in line we can see that the total number of handshakes is 3 + 2 + 1 + 0 = 6. Now, if we take N people in line as in the book’s example, then the first person in line is a1 = N – 1 , and the last person in line an = N – N, and the total number of people in line is N. Then substituting these numbers into the general formula for the sum of arithmetic sequence we got:

Sumn = 1/2 * n * (a1 + an) = 1/2 * (N – 1 + N – N) * N = 1/2 * (N – 1) * N

This is how the formula in the book was derived.

This post is not the last one, since I have not finished reading the book yet. There are more to come.

# What the hack is Rule 30? Cellular Automata Explained

## Introduction

If you ask the same question, what is this Rule 30, then you are not alone. This rule is related to one-dimensional Cellular Automata introduced by Stephen Wolfram in 1983 and later described in his A New Kind Of Science book. Even though, I skimmed through this book previously, I was never able to understand what was it all about. It had some neat diagrams, but I didn’t try to understand how the diagrams where generated. This changed a day ago when I watched an interesting interview that Lex Fridman had with Stephen Wolfram, where they discussed among other things Rule 30, which was the one that Wolfram described first. This rule is capable of generating a complex behavior even though the rule itself is very simple to define.

## Elementary Cellular Automaton

The Elementary Cellular Automaton consists of a one-dimensional array of cells that can be in just two sates, namely, black or white color. The cellular automaton starts from initial state, and then transition to the next state based on a certain function. The next state of the automaton is calculated based on the color of current cell and its left and right neighbors’ colors. By the way, that transition function, gives its name to the cellular automaton rule, just like Rule 30.

### Rule 30 transition function

Where, for example, the binary digits ‘111’ in the first column indicate the black color of the left, current and right cells, and the values, ‘0’ or ‘1’ indicate what will be the color of the current cell in the next state (iteration) of the automaton. If we write down all the the binary values of the next state together as a single 8 digit binary number, which is 00011110 and convert it to a decimal number we get 30, and hence the name of the Rule 30. In a Boolean form this transition function is

``(left, current, right) -> left XOR (current OR right)``

We’ll use this function later in the C++ implementation of the Rule 30.

This is how the output from Rule 30 looks like after 20 and 100 steps respectively.

## How to generate Rule 30?

It is easy to implement the Rule 30 using a 64 bit integer in C++. The only drawback is that we can get only 32 steps with the implementation below taken from Wikipedia.

#### Note: If this is a little bit to much for you now, then skip to the next part where we’ll use WolframAlpha to program it for us.

In the code below a 64 bit integer is used to generate an initial state using a bit mask in line 6. Then the outer for loop generates 32 steps of the Rule 30 by applying the transition function in line 19. The inner loop generates the black (using character ‘1’) and white (using character ‘-‘) colors using state bit mask.

```#include <stdint.h>
#include <iostream>

int main() {
// This is our bit mask with the 32 bit set to '1' for initial state
uint64_t state = 1u << 31;

for (int i = 0 ; i < 32 ; i++) {

for (int j = sizeof(uint64_t) * 8 - 1 ; j  >=  0 ; j--) {
// Here we decide what should be the color of the current cell based on the current state bit mask.
// Bitwise operator is used to accomplish this efficiently
std::cout << char(state  >>  j & 1 ? '1' : '-');
}
std::cout << '\n';

// This is just the (left, current, right) -> left XOR (current OR right) functioned mentioned previously
// Bitwise operators  are used to accomplish this efficiently
state = (state >> 1) ^ (state | state << 1);
}
}
```

It is possible to run this code in the online C++ compile. Just click on the link and then click on the green Run button at the top of the screen. The result looks similar to below.

The full output for 32 steps looks like this

``````--------------------------------1-------------------------------
-------------------------------111------------------------------
------------------------------11--1-----------------------------
-----------------------------11-1111----------------------------
----------------------------11--1---1---------------------------
---------------------------11-1111-111--------------------------
--------------------------11--1----1--1-------------------------
-------------------------11-1111--111111------------------------
------------------------11--1---111-----1-----------------------
-----------------------11-1111-11--1---111----------------------
----------------------11--1----1-1111-11--1---------------------
---------------------11-1111--11-1----1-1111--------------------
--------------------11--1---111--11--11-1---1-------------------
-------------------11-1111-11--111-111--11-111------------------
------------------11--1----1-111---1--111--1--1-----------------
-----------------11-1111--11-1--1-11111--1111111----------------
----------------11--1---111--1111-1----111------1---------------
---------------11-1111-11--111----11--11--1----111--------------
--------------11--1----1-111--1--11-111-1111--11--1-------------
-------------11-1111--11-1--111111--1---1---111-1111------------
------------11--1---111--1111-----1111-111-11---1---1-----------
-----------11-1111-11--111---1---11----1---1-1-111-111----------
----------11--1----1-111--1-111-11-1--111-11-1-1---1--1---------
---------11-1111--11-1--111-1---1--1111---1--1-11-111111--------
--------11--1---111--1111---11-11111---1-11111-1--1-----1-------
-------11-1111-11--111---1-11--1----1-11-1-----11111---111------
------11--1----1-111--1-11-1-1111--11-1--11---11----1-11--1-----
-----11-1111--11-1--111-1--1-1---111--1111-1-11-1--11-1-1111----
----11--1---111--1111---1111-11-11--111----1-1--1111--1-1---1---
---11-1111-11--111---1-11----1--1-111--1--11-1111---111-11-111--
--11--1----1-111--1-11-1-1--11111-1--111111--1---1-11---1--1--1-
-11-1111--11-1--111-1--1-1111-----1111-----1111-11-1-1-111111111

``````

Compare the image above to the one generated using WolframAlpha symbolic language in the Wolfram Notebook.

## Using WolframAlpha to generate Rule 30

WolframAlpha is a computational knowledge engine developed by Wolfram Research. It is embedded in Mathematica symbolic language and it has a declarative programming style. Which means that you specify what you want to be done instead of how it should be done.

For example, to generate Rule 30 and visualize it one simple writes

``````ArrayPlot[CellularAutomaton[30, {{1},0}, 64]]
``````

where CellularAutomaton function generates 64 states of the automaton, starting with a one black cell in accordance with the Rule 30 generation function, and ArrayPlot function prints the result.

And the output is

Please follow the this link to the Wolfram Notebook where the various Elementary Cellular Automata Rules are generated.

## Summary

Playing with cellular automat rules seems like an interesting game to play, plus doing it using WolframAlpha language is a piece of cake.

# Better understanding with Optimization for Machine Learning

## Long awaited book from Machine Learning Mastery

Recently, I’ve been reading the new Optimization for Machine Learning book from the Machine Learning Mastery written by Jason Brownlee. It just so happened that I read it fully from start to end, since I was one of the technical reviewers of the book. The book was interesting to read thanks to a number of ingredients.

As always Jason was able to write an engaging book with practical advice that can be actioned right away using open source software on Linux, Windows or MacOS. Apart from this the book has just enough clearly explained theoretical material so that even beginning machine learning practitioners can play with optimization algorithms described in the book.

## What I liked and what surprised me in the book

Personally, I think it was while reading and working with this book, that I truly understood what an optimizations is. How it is used in machine learning. What is an optimization algorithm, like gradient descent and how to implement one from scratch. I also very much enjoyed the chapter about Global Optimization with various types of Evolution Algorithms. What was funny, that about two weeks after I finished reading the book I came across Donald Hoffman’s The Interface Theory of Perception with relation to consciousness which is based on The Theory of Evolution by Natural Selection. For example, one of his papers written with colleagues namely Does evolution favor true perception? provides an example of Genetic Algorithm (GA) which very much resembles the GA in Chapter 17 of the book. It is highly recommended reading for anyone interested in how consciousness arises in the mind. By the way, does it?

## Overall

The Optimization for Machine Learning book is what you come to expect from Machine Learning Mastery books. It’s interesting, it’s practical and it makes you understand what is that you are doing in Machine Learning. As always, each chapter has extensive references to tutorials, technical papers and books on machine learning. So don’t wait and start reading it, maybe you’ll come up with a new theory of how consciousness emerges in the mind.

## References

Donald D. Hoffman, Manish Singh, Justin Mark, “Does evolution favor true perceptions?”, Proceedings Volume 8651, Human Vision and Electronic Imaging XVIII; 865104 (2013)

# Playing with the 3D Donut-shaped C code in JavaScript

## Background

Having seen a short YouTube video by Lex Fridman about Donut-shaped C code that generates a 3D spinning donut where in comments he encouraged to look at the code and play with I did just that.

But before this, I went to the Donut math: how donut.c works link where the author of that code Andy Sloane described how he came from geometry and math to implementation of the donut in C.

The Andy Sloane’s tutorial has two visualizations that you can launch and also the JavaScript implementation of the donut. One visualization is of ASCII donut while another one uses <canvas>: The Graphics Canvas element to create a visualization.

## Playing with the code

The easiest way to play with the 3D spinning donut in JavaScript is to use JSFiddle online editor. When the editor is opened you see four main areas, just like in almost any other JS editor, which are HTML, CSS, JavaScript and Result.

To be able to start playing with donut code like crazy we need to do a number of things.

### First

First, there is a need to create a basic HTML page with a number of buttons, a <pre> tag to store ASCII generated donut and a <canvas> tag to be able to show another type of donut animation. To do this just copy and paste into HTML area of JSFiddle editor the code below

```<html>
<body>
<button onclick="anim1();">toggle ASCII animation</button>
<button onclick="anim2();">toggle canvas animation</button>
<pre id="d" style="background-color:#000; color:#ccc; font-size: 10pt;"></pre>
<canvas id="canvasdonut" width="300" height="240">
</canvas>
</body>
</html>

```

### Second

Second, there is a need to copy and past JS code from Andy’s page or copy and paste the code below into JS area of the JSFiddle editor

```(function() {
var pretag = document.getElementById('d');
var canvastag = document.getElementById('canvasdonut');

var tmr1 = undefined, tmr2 = undefined;
var A=1, B=1;

// This is copied, pasted, reformatted, and ported directly from my original
// donut.c code
var asciiframe=function() {
var b=[];
var z=[];
A += 0.07;
B += 0.03;
var cA=Math.cos(A), sA=Math.sin(A),
cB=Math.cos(B), sB=Math.sin(B);
for(var k=0;k<1760;k++) {
b[k]=k%80 == 79 ? "\n" : " ";
z[k]=0;
}
for(var j=0;j<6.28;j+=0.07) { // j <=> theta
var ct=Math.cos(j),st=Math.sin(j);
for(i=0;i<6.28;i+=0.02) {   // i <=> phi
var sp=Math.sin(i),cp=Math.cos(i),
h=ct+2, // R1 + R2*cos(theta)
D=1/(sp*h*sA+st*cA+5), // this is 1/z
t=sp*h*cA-st*sA; // this is a clever factoring of some of the terms in x' and y'

var x=0|(40+30*D*(cp*h*cB-t*sB)),
y=0|(12+15*D*(cp*h*sB+t*cB)),
o=x+80*y,
N=0|(8*((st*sA-sp*ct*cA)*cB-sp*ct*sA-st*cA-cp*ct*sB));
if(y<22 && y>=0 && x>=0 && x<79 && D>z[o])
{
z[o]=D;
b[o]=".,-~:;=!*#\$@"[N>0?N:0];
}
}
}
pretag.innerHTML = b.join("");
};

window.anim1 = function() {
if(tmr1 === undefined) {
tmr1 = setInterval(asciiframe, 50);
} else {
clearInterval(tmr1);
tmr1 = undefined;
}
};

// This is a reimplementation according to my math derivation on the page
var R1 = 1;
var R2 = 2;
var K1 = 150;
var K2 = 5;
var canvasframe=function() {
var ctx = canvastag.getContext('2d');
ctx.fillStyle ='#000';
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);

if(tmr1 === undefined) { // only update A and B if the first animation isn't doing it already
A += 0.07;
B += 0.03;
}
// precompute cosines and sines of A, B, theta, phi, same as before
var cA=Math.cos(A), sA=Math.sin(A),
cB=Math.cos(B), sB=Math.sin(B);
for(var j=0;j<6.28;j+=0.3) { // j <=> theta
var ct=Math.cos(j),st=Math.sin(j); // cosine theta, sine theta
for(i=0;i<6.28;i+=0.1) {   // i <=> phi
var sp=Math.sin(i),cp=Math.cos(i); // cosine phi, sine phi
var ox = R2 + R1*ct, // object x, y = (R2,0,0) + (R1 cos theta, R1 sin theta, 0)
oy = R1*st;

var x = ox*(cB*cp + sA*sB*sp) - oy*cA*sB; // final 3D x coordinate
var y = ox*(sB*cp - sA*cB*sp) + oy*cA*cB; // final 3D y
var ooz = 1/(K2 + cA*ox*sp + sA*oy); // one over z
var xp=(150+K1*ooz*x); // x' = screen space coordinate, translated and scaled to fit our 320x240 canvas element
var yp=(120-K1*ooz*y); // y' (it's negative here because in our output, positive y goes down but in our 3D space, positive y goes up)
// luminance, scaled back to 0 to 1
var L=0.7*(cp*ct*sB - cA*ct*sp - sA*st + cB*(cA*st - ct*sA*sp));
if(L > 0) {
ctx.fillStyle = 'rgba(255,255,255,'+L+')';
ctx.fillRect(xp, yp, 1.5, 1.5);
}
}
}
}

window.anim2 = function() {
if(tmr2 === undefined) {
tmr2 = setInterval(canvasframe, 50);
} else {
clearInterval(tmr2);
tmr2 = undefined;
}
};

asciiframe();
canvasframe();
}

if(document.all)
else
})();
```

### Third

After HTML and JavaScript areas were populated click on the Run button (as indicated by me with number 1) in the screenshot below and you should see in the Result area on the right two buttons and two donuts (indicated with number 2).

When each button is clicked relevant animation is turned on. Both of them could run in parallel.

## Playground

If you want understand the math of how it’s done then first read the explanation by Andy Sloane here. If you want jump right into messing around with the code then stay here.

### Need for speed

To change the speed of the animations Ctrl + F in the JSFiddle and search for setInterval function

```tmr1 = setInterval(asciiframe, 50);

tmr2 = setInterval(canvasframe, 50);
```

The second argument controls the speed of rotation of the donut. Increasing it makes it rotate faster and vice versa.

### Paint it black

To change the background color of the donut created with the <canvas> animation search for ctx.fillStyle =’#000′;

```ctx.fillStyle='#000'; //this is currently black
```

To change the color of the donut created with the <canvas> animation search for ctx.fillStyle = ‘rgba(255,255,255,’+L+’)’;

```ctx.fillStyle = 'rgba(255,255,255,'+L+')'; // update any of the first three arguments which stand for Red, Green, Black in RGB.
```

## See you

There are plenty other things you can try with this code. So why are you waiting? Just do it!

# Salesforce Trailhead: An interesting approach to learning with inconclusive outcomes

## What’s new?

Recently, I have changed jobs and in my new position I use Salesforce CRM platform. In comparison to my previous positions to become a productive developer in this area there is a very different approach to learning.

First of all, Salesforce created the Trailhead site that contains a large number of e-learning courses, which are more like tutorials that supposed to teach certain practical aspect of the Salesforce platform. These tutorials are called Trails which in turn consist of smaller Modules, which consist of even smaller Units. The units are small and don’t take a lot of time to go through.

To engage people interested in learning Salesforce, accomplishing units, modules and trails gives you points and badges. There are two additional types of activities that trailhead consist of which are Projects and Superbadges. These two are more hands-on oriented with Superbadges being a kind of real taste of what it’s like to work with production type of Salesforce CRM platform. Last but not least is a Trailmix which is an option to compose a freestyle collection of Superbadges, Trails, Projects or Modules in one bundle.

## Overall, the structure of the Trailhead looks something like this

• Hands-on learning
• Project
• Units
• Trail
• Modules
• Units
• Module
• Units
• Trailmix
• Projects
• Trails
• Modules
• Units

## Some food for thoughts

After attempting and finishing each type of the e-learning in Trailhead I have some thoughts for improvements to this approach.

First of all, the e-learning concept is fresh and works good. It allows one to learn with his/her own pace. In addition, the content quality is good and assignments can be carried out in the free instances of Salesforce CRM that Salesforce provides a learner for free.

Second, the points and badges are really creating, at least in my opinion, a contest feeling where one competes with oneself.

After praising the learning platform comes my harsh criticism.

1. There is no time stamp of when and also by whom the content was created. I deem this essential since I want to know is the content out of date, can I trust and rely on it. Also, it’s good to give a credit to creator of the content.
2. There is no small amount of modules that have too much wording in them which is kind of repetitive and takes valuable time to read.
3. The Modules present content in such a manner that doing it feels like being a machine, just type what they say as a dummy, and then by some magic the platform validates what’s done without providing too much useful feedback if something went wrong. This is especially frustrating while doing Superbadges. It’s easy to check that hundreds of novice Salesforce developers were daunted by the unintelligent feedback on the superbadge steps verification.
4. In addition, it feels like doing modules is useless in comparison to doing a superbadge. Which means modules are only good as part of superbadges.
5. But even superbadge doesn’t represent a real production Salesforce CRM environment and is a vanilla version of it, lacking crucial details, that make it or break it in the world of software development.

## What can be done to improve the drawbacks?

1. It would be nice for Modules and Projects to have an overview of how the content is used in a real life Salesforce development, by providing real use cases, even partially, without resorting to some kind of unreal companies with funny names.
2. Superbadges should also be more production oriented with good and intelligent feedback or explanation of how one can debug the Salesforce CRM environment to understands what’s wrong with the implementation.
3. It would be nice to try to incorporate the Trails, Modules etc. as part of the Salesforce CRM platform itself. This could assist in better understanding of how to work the CRM tool efficiently.
4. The points and badges systems seems fine, but it’s possible to collect points without really understanding what the content means which defeats the point of having points altogether.

## All in all

Trailhead is an interesting and engaging platform to learn Salesforce, but there are things that could and should be improved to make things better for the novice and seasoned Salesforce developers, admins etc.

# The Fabric of Reality : 24 years later

The Fabric Of Reality, the first book by David Deutsch, was written back in 1997. It have been twenty four years since then and it is interesting to see how the book feels to be read in 2021. Yes, you are right 24 years has passed since then. Even though this was the first book David Deutsch wrote, the first book I read was his second. It was The Beginning of Infinity that I read and found it very insightful that caused me to check other books David Deutsch wrote.

The Fabric of Reality describes four strands:

the quantum physics of the multiverse, Popperian epistemology, the Darwin-Dawkins theory of evolution and a strengthened version of Turing’s theory of universal computation.

The Fabric of Reality, p. 366

It provides a unified approach of how the world could be explained and apprehended. The book uses the Popperian explanation based approach to scientific understanding of the world. The first chapters of the book provide a reader with a gentle introduction why the Inductivism is a dead end as a scientific approach and then transitions to showing the benefits of using explanation based view of scientific discovery.

Since, I first read The Beginning of Infinity which was written in 2011 it was nice to know that it builds on the previous book and expands on some of its topics, literary, that science is about providing explanations to why things are the way they are, instead of claiming that science is about inferring theories from data observed in experiments.

In my opinion, two of the more interesting parts were about the objective existence of the multiverse, which is the only feasible explanation of the interference of particles in two slit experiment, and the universal image generator and universal virtual-reality generator. Back in 1997 computers were quite slow in comparison to what we got nowadays. Graphical Processing Units (GPU) as we know them now were non-existent, but nevertheless David Deutsch described his thoughts on the subject of virtual realty in such a way that it is still refreshing to read it when Oculus Rift – VR Headset and Microsoft HoloLense are here.

David Deutsch’s take on that mathematics is not some abstract subject detached from reality, but to the contrary a filed of study that is about physically existing entities at first sounds daring. But if you think about it you’ll see that we and mathematicians live in a physical world, and think using physically existing brains that are responsible for us to have thoughts and intuitions about mathematical objects, and imagination in general.

The book is not that easy to read, especially the chapters about spacetime and time travel, which were quite convoluted at times. Nevertheless, the book is worth reading, since it provides ample food for thoughts and have some daring unification of theories that on the surface seem not connected.

If you follow David Deutsch’s activities you could have known that some theories described in the book made it into Constructor Theory that David Deutsch and Chiara Marletto developing for about a decade. Particularly, the chapter about The Nature of Mathematics talks about a proof being a physical process or a type of computation.

Constructor theory expresses physical laws exclusively in terms of what physical transformations, or tasks, are possible versus which are impossible, and why. By allowing such counterfactual statements into fundamental physics, it allows new physical laws to be expressed, for instance those of the constructor theory of information.

Wikipedia

All in all, The Fabric of Realty book still feels like a contemporary book. Its content is still fresh and worth reading. The book is quite independent from its successor The Beginning of Infinity, but both are sources for interesting and insightful ideas and worth your time.

# How to Push Local Notification With React Native

### Prerequisites

To see React Native live without installing anything check out Snack.

#### With my current setup (Windows 10 64 bit and Android phone)

• I installed all prerequisites above
• Started development server
```C:\Users\xyz\AppData\Roaming>cd AwesomeProject

C:\Users\xyz\AppData\Roaming\AwesomeProject>yarn start
yarn run v1.22.10
```
• Scanned QR Code shown in the development server
• And I saw app started on my Android phone

I was looking for a simple solution to generate a local push notification in one of my projects,  when I came across this wonderful package that does exactly what is need and suitable for both iOS and Android, https://github.com/zo0r/react-native-push-notification.

The package has pretty good documentation, with only minor things missing to make it work straightforward. In the following guide I will present the configuration required and a suggested implementation to get you start pushing notifications locally.

This guide targets Android since I encounter a lot of questions around it.

• pending on your requests a dedicated guide for ios may be published as well.

Installation and linking, the short story.

```ext {
buildToolsVersion = "29.0.3"
minSdkVersion = 21
compileSdkVersion = 29
targetSdkVersion = 29
ndkVersion = "20.1.5948944"
googlePlayServicesVersion = "+" // default: "+"
firebaseMessagingVersion = "+" // default: "+"
supportLibVersion = "23.1.1" // default: 23.1.1
}
```
• android/app/src/main/AndroidManifest.xml
```<span class="has-inline-color has-black-color">...
<uses-permission android:name="android.permission.VIBRATE" />
...
<application
...>
android:value="false"/>
android:resource="@color/white"/>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
...
</application></span>

```
• create /app/src/main/res/values/colors.xml
```<span class="has-inline-color has-black-color"><resources>
<color name='white'>#FFF</color>
</resources></span>

```
```include ':react-native-push-notification'
```
```dependencies {
...
...
}
```

## Usage

Pay attention that for Android, creating a notification channel and setting the request permission as  “iOS only” is a must, as presented in the following example.

```<span class="has-inline-color has-black-color">import PushNotification from 'react-native-push-notification';
import { Platform } from 'react-native';

export const notificationsInit = () => {
channelId: 'channel-id-1',
channelName: 'channel-name-1',
playSound: true,
soundName: 'default',
importance: 4,
vibrate: true,
}, (created) => colnsloe.log(`createChannel returned '\${created}'`)
);
onRegister: function (token) {
console.log('TOKEN:', token);
},
},
permissions: {
sound: true,
},
requestPermissions: Platform.OS === 'ios',
});
}</span>

```
• create a new file src/handlers/notifications.js
```<span class="has-inline-color has-black-color">import PushNotification from 'react-native-push-notification';

export const showNotification = (title, message) => {
channelId: 'channel-id-1',
title: title,
message: message,
})
}
export const showScheduleNotification = (title, message) => {
channelId: 'channel-id-1',
title: title,
message: message,
date: new Date(Date.now() + 3 * 1000),
allowWhileIdle: true,
})
}
export const handleNotificationCancel = () => {
}
</span>

```
• Import and initialize notificationsInit in App.js
```<span class="has-inline-color has-black-color">import React from 'react';
import { View } from 'react-native';

const App = () => {

return (
<View>
</View>
);
};

export default App;</span>

```
• Now, lets display the notification
• create a new file src/components/TestNotifications.js
```<span class="has-inline-color has-black-color">import React from 'react';
import { View, TouchableOpacity, StyleSheet, Text } from 'react-native';
import {

export default class TestNotifications extends React.Component {

onTriggerPressHandle = () => {
}

onSchedulePressHandle = () => {
}

onCancelHandle = () => {
}

render() {
return (
<View>
<Text style={styles.title}>Click to try</Text>
<TouchableOpacity
style={styles.button}
onPress={this.onTriggerPressHandle}>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={this.onSchedulePressHandle}>
<Text style={styles.text}>{'--Scheduled notification--\nFire in 3 secondes'}</Text>
</TouchableOpacity>
<TouchableOpacity
style={[styles.button, {backgroundColor: 'red'}]}
onPress={this.onCancelHandle}>
</TouchableOpacity>
</View>
);
}
}

const styles = StyleSheet.create({
button: {
backgroundColor: 'dodgerblue',
height: 80,
margin: 20,
justifyContent: 'center'
},
text: {
color: 'white',
textAlign: 'center',
fontSize: 20,
},
title: {
backgroundColor:'dimgrey',
color: 'white',</span>
<span class="has-inline-color has-black-color">textAlign: 'center',
textAlignVertical: 'center',
fontSize: 30,
height: 100,
marginBottom: 20,
}
});</span>

```
• import TestNotifications component to App.js
```<span class="has-inline-color has-black-color">import React from 'react';
import { View } from 'react-native';

const App = () => {

return (
<View>
</View>
);
};

export default App;</span>

```

### Try out the buttons to trigger the notifications

Feel free to clone and play with this project sample