📜 ⬆️ ⬇️

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 are also not alien to this, for example, there is Koidé’s mystical formula , which relates the masses of an electron, a muon, and a tau particle. There is a formula for the constant fine structure - unlike the Koidé formula, which seems very artificial. How justified are these 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 subranges of length 1 from -60 to +60. The Y scale is logarithmic. Visible concentration of numbers about 0.



Make a zoom for the range -2..2:



Here the Y scale is normal. Peaks near 0 and 1.

We make the maximum zoom to see the “thin 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 in the form of 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 is interesting what will happen if, instead of A = 1, B = 2, C = 3, take other numbers, 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 MS SQL do with it. The task is reborn, and it just suggests a solution with a cross join that implements Cartesian products of all the available numbers for binary operations. You can see a small piece of code 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 3 insert into Formula (step,path,Value) select 3,path+' '+op, case when op='COS' then COS(Value) when op='SIN' then SIN(Value) when op='EXP' then case when Value<100 then EXP(Value) else NULL end when Value<=0 then NULL when op='LN' then LOG(Value) end from Formula, Unary -- step 4 select L.path+' '+R.path+' '+'+' as path,L.value+R.value as value into p1 from Formula L, Formula R where Ln<=Rn select L.path+' '+R.path+' '+'+' as path,L.value+R.value as value into p2 from Formula L, Formula R where Ln<=Rn select L.path+' '+R.path+' '+'+' as path,L.value+R.value as value into p3 from Formula L, Formula R select L.path+' '+R.path+' '+'+' as path,L.value+R.value as value into p4 from Formula L, Formula R where R.value<>0 

Source: https://habr.com/ru/post/438122/