# Numerology on MS SQL - an entertaining experiment

People since ancient times love to play numbers. Prove that the ratio of the length of the pyramid of Cheops to the height is equal to ... I do not remember what. Physicists, too, are not alien to this, for example, there is Koidé’s mystical formula , which relates the masses of an electron, muon, and tau particle. There is a formula for the constant fine structure - unlike the Koidé formula, which seems very artificial. How justified such formulas? I did an experiment.

Take N numbers: A, B, C ... In my experiment I limited myself to three numbers. For each number we can apply a unary function: SIN, COS, EXP, LN (I limited myself to four). This gives 4 * 3 = 12 new numbers, which together with the original gives 15 numbers. Further, we apply binary operations to their combination +, -, *, /. (You can also consider others, for example, exponentiation, but again I limited myself to four). Here, the new combinations are 15 * 15 * 4 (actually less, since some operations are prohibited, such as dividing by 0, and for + and * the number of combinations is less because of their symmetry).

Then we can repeat these steps again and again. Already at the second step, 34'513'800 formulas (now you understand why I limited the number of operations?) Which gave me for A = 1, B = 2, C = 3 whole 2'776'355 different numbers.

The graph above shows the concentration (number of different numbers) for the subranges of length 1 from -60 to +60. The Y scale is logarithmic. You can see the concentration of numbers near 0.

We make a zoom for the range -2..2:

Here the Y scale is already normal. The peaks are near 0 and 1.

We make the maximum zoom to see the “fine structure” of the distribution of numbers:

I wonder how accurately we can express an arbitrary number, say 1.23456789? This is determined by (half) the maximum length of the segment between two adjacent points (if we are unlucky). Below, these calculations are shown as a graph, and further from zero, the accuracy of the approximation falls:

Thus, as a rule, we can express any number with an accuracy from E-6 to E-5. For example, the number 1.23456789 is located between

cos (ln (3) / cos (3)) + sin (1 / ln (3)) = 1.23456481266341 (0.0002%)
ln (exp (1) * sin (2)) + exp (ln (3) / cos ( 3)) = 1.23456894186555 (0.000085%)

Finally, it’s interesting what happens if you take other numbers instead of A = 1, B = 2, C = 3, for example, A = sqrt (2), B = e, C = pi. Comparison of the density of numbers in the first (123) and second (2epi) you see in the picture:

As you can see, by and large, there is no difference. In conclusion, I want to tell you what does it have to do with MS SQL. The task is reborn, and the solution with a cross join, which implements Cartesian products of all available numbers for binary operations, is simply suggested. You can see a small code snippet at the end.

The full code is not published, because I want to modify it to automatically generate the texts of conspiracy theories based on numerology.

-- step 3insertinto Formula (step,path,Value)
select3,path+' '+op,
casewhen op='COS'thenCOS(Value)
when op='SIN'thenSIN(Value)
when op='EXP'thencasewhenValue<100thenEXP(Value) elseNULLendwhenValue<=0thenNULLwhen op='LN'thenLOG(Value)
endfrom Formula, Unary
-- step 4  select L.path+' '+R.path+' '+'+'aspath,L.value+R.value asvalueinto p1
from Formula L, Formula R
where L.n<=R.n
select L.path+' '+R.path+' '+'+'aspath,L.value+R.value asvalueinto p2
from Formula L, Formula R
where L.n<=R.n
select L.path+' '+R.path+' '+'+'aspath,L.value+R.value asvalueinto p3
from Formula L, Formula R
select L.path+' '+R.path+' '+'+'aspath,L.value+R.value asvalueinto p4
from Formula L, Formula R
where R.value<>0