Skip to content

Instantly share code, notes, and snippets.

@Recoskie
Last active August 16, 2023 12:46
Show Gist options
  • Save Recoskie/e01a0467cfde28e3e14a42fd0ba9ce44 to your computer and use it in GitHub Desktop.
Save Recoskie/e01a0467cfde28e3e14a42fd0ba9ce44 to your computer and use it in GitHub Desktop.
Find the pattern to calculate a random number and classify it.

This fast algorithm can rationalize numbers as (a+√b)÷m. I'm putting this online mainly because I can't find it anywhere except for a lot of junk. I will show how to construct it so you can solve the computational number patterns to things like PI, base e, and even angles of sine and cosine.

Analizing finite numbers.

First, we will begin by dividing two numbers.

56÷25=2.24

If we ask how many times 25 goes into 56, the answer is 2 since the value before the decimal point is 2 after the division.

So if we take 25 away from 56 twice, we end up with 56-25-25=6.
Now we ask how many times 6 goes into the number we divided by 25.
25÷6=4.166
Now we take 6 away 4 times, going 25-6-6-6-6=1.
Now we ask how many times 1 goes into the number we divided by 6.

6÷1=6

When we take away six ones into 6 we are left with zero.
Our number 2.24 divides into values [2,4,6].

You still get the same value if you multiply both sides by any value (56x10=560)÷(25x10=250)=2.24. In this example, we multiply both sides by ten.

560÷250=2.24

When we reduce it the same way, we end up with.

560-250-250=60, in which 250 goes into 560 two times with 60 left.
250-60-60-60-60=10, in which 60 goes into 250 four times with 10 left.
60-10-10-10-10-10-10=0, in which 10 goes into 60 six times with 0 left.

We get the same answer [2,4,6]. The remaining amount we get back was ten just before zero which tells us how much we multiplied both sides by. Dividing both sides by the last remaining amount before zero will return it to the smallest (560÷10=56)÷(250÷10=25). This is known as finding the greatest common divider. If we are left with one before going to zero left, then dividing both sides by one has no effect.

Starting from 0÷1=0 and adding back [2,4,6] we end up with the two smallest numbers that divide into our value 56÷25.

Let's say we do not know the two numbers we divide by to produce the values [2,4,6]; instead, we only have the value 2.24.

The number 2, before the decimal point, is how many times the number divides evenly the first time. We take the number 2 away from the value going.

2.24-2=0.24

To find how many times the value divides evenly again, we divide what remains into 1 by going.

1÷0.24=4.166

This tells us it goes 4 times evenly, so we take 4 away by going.

4.166-4=0.166

We now ask how many times the remaining value divides evenly again by dividing into 1.

1÷0.166=6

We take 6 away, and we are left with nothing remaining after the decimal point.

So now we have found that the number 2.24 divides evenly as [2,4,6] without using the two numbers we used to divide into the number. By adding the values [2,4,6] together the same way, we can find the two closest numbers that divide to the value 2.24 giving us 56÷25.

We can also add each number [2,4,6] back into the number the same way we took the number apart.

(1÷((1÷6)+4))+2=2.24

We can write a fancy math function that converts a number back into the two closest numbers that divide into the number as follows.

var n = 3/7;

function fract(v,ac)
{
  var a1 = 1, a2 = 0, b1 = 0, b2 = 1, r1 = v, r2 = 0;
  
  while(Math.abs(v-(a1/b1)) > ac)
  {
    r1=1/(r1-(r2=r1&-1));
    a1=a2+(a2=a1)*r2;b1=b2+(b2=b1)*r2;
  }
  return(a1+"\xF7"+b1);
}

var f = fract(n, 1/Number.MAX_SAFE_INTEGER);

alert(f);

Change var n = 3/7, which is three divided by seven to whatever values you like, and it will take the value apart and add it back into the two closest numbers that divide into the value. If you go too big and go outside the max safe integer for a javascript number, it may become inaccurate as only so much information can be stored in one number.

Analizing infinite numbers.

When we look at the number of times square root values divide evenly, we end up with the following sequences for the roots of different numbers.

√2 = [1, 2, 2, 2, 2, 2]
√3 = [1, 1, 2, 1, 2, 1, 2] as 1,2 repeats.
√7 = [2, 1, 1, 1, 4, 1, 1, 1, 4] In which 1,1,1,4 repeats.

All square roots have a set of parts that repeat forever.

Some can be complex like

√14 = [3, 1, 2, 1, 6, 1, 2, 1, 6], which has the irrational radical pattern of 1, 2, 1, 6.

Any repeating pattern can be expressed as "b" to the closest square.

The square root of 7 is 2.6457513111.

We take away the whole value before the decimal point 2.6457513111-2=0.6457513111

The first part is 2.

We divide the value into one to find the next part.

1÷0.6457513111=1.5485837703

We take away the 1 before the decimal point and repeat this repeatedly to find the values.

This gives us √7 = [2, 1, 1, 1, 4, 1, 1, 1, 4].

All radical irrational numbers have a point at which the parts become a repeating pattern after the first part. The first part is known as the rational part, while the parts after the first part are radical.

Any repeating number pattern can be reduced into a division before dividing the number into one.

For the square root of 7, the value for all "b" is 3.

We take the two away 2.6457513111-2=0.6457513111

We then divide the value by three as 0.6457513111÷3=0.215250437 before dividing into 1.

We now divide the value 0.215250437 into one as 1÷0.215250437=4.6457513115.

We take away four as 4.6457513115-4=0.6457513111

Dividing by three will give us the exact number back again 0.215250437. Dividing into one will give us back four again.

So to show, we divided by three before moving to the next part in the number we show it as.

√7 is
A = [2, 4, 4, 4, 4, 4, 4, 4]
B = [3, 3, 3, 3, 3, 3, 3, 3]

This is much better than showing the radical as a repeating pattern of 1, 1, 1, 4.

The square root of 8 is the following.

√8 is
A = [2, 4, 4, 4, 4, 4, 4, 4]
B = [4, 4, 4, 4, 4, 4, 4, 4]

√9 is
A = [3, 0]
B = [1, 0]

It has no radical parts as it is three rational.

√10 is
A = [3, 6, 6, 6, 6, 6, 6, 6]
B = [1, 1, 1, 1, 1, 1, 1, 1]

√11 is
A = [3, 6, 6, 6, 6, 6, 6, 6]
B = [2, 2, 2, 2, 2, 2, 2, 2]

√12 is
A = [3, 6, 6, 6, 6, 6, 6, 6]
B = [3, 3, 3, 3, 3, 3, 3, 3]

All The way till b=[6,6,6..] in which we approach the next rational 4.

It is also essential to note that we can add all A and B together to calculate our number the same way we take a number apart.

If you divide the value by the proper value, the next part in the radical will match. The value we divide by is how far away we are from the previous whole square. For example, √14 is how far away from √9=3. We go 14-9=5.

So then, if we take the value √14=3.7416573868.

Subtract it by 3 as 3.7416573868-3=0.7416573868

Divide 0.7416573868 by 5 as 0.7416573868÷5=0.1483314774 before dividing into 1 for the next part.

We end up with 1÷0.1483314774=6.7416573847

We take 6 away and divide by 5, then divide the value into 1 and get the same number back 6.7416573847, and a new 6 for the next whole part in the number.

Doing this is known as the General CF forum. It also works for fractional square roots as there is a value for B to express any square root as All "A" and "B" as the same value except for the first part, known as the rational part, which is half the size of the next whole part in the radical unless it is plus or minus a value mixed with the radical.

So if we find what the value for what B is, we then know what the value is a root of, even if it is divided or mixed with other numbers.

We take What the value for A = [3,6,6,6,6,6] is, which is 6, excluding the first part, which is called the rational part. We divide the 6 by 2, giving us the closest whole square, which is 3, which was √9=3. The value for B tells us how far we are from √9=3, in which B=[4,4,4]. In which we only need the first value for B, so √(9+4)=√14 for the radical parts of your number, excluding the rational part. We take the value √14 and subtract it into our irrational number giving us plus or minus how much for the rational part.

The only problem we have is to solve the value for "B".

To solve B, the following can be used.

√7 = [2, 1, 1, 1, 4, 1, 1, 1, 4] In which 1,1,1,4 repeats.

The point at which the irrational repeated is the point at which the value for B can be calculated.

√7 = 2.6457513111

Take part away 2.6457513111-2=0.6457513111
Find next part 1÷0.6457513111=1.5485837703
Take part away 1.5485837703-1=0.5485837703
Find next part 1÷0.5485837703=1.8228756557
Take part away 1.8228756557-1=0.8228756557
Find next part 1÷0.8228756557=1.2152504368
Take part away 1.2152504368-1=0.2152504368
Find next part 1÷0.2152504368=4.6457513158
Take part away 4.6457513158-4=0.6457513158

As you can see, the last and first value match and are 0.6457513158, which means the pattern 1,1,1,4 will repeat after it.

Dividing 0.6457513158 by the value just before it 0.2152504368 gives us the value for what B is 0.6457513158/0.2152504368=3. Note this could also be a fractional number if the square root was fractional.

√7 = 2.6457513111

Take part away 2.6457513111-2=0.6457513111
Divide by 3, doing 0.6457513111÷3=0.215250437
Find next part 1÷0.215250437=4.6457513115
Take part away 4.6457513115-4=0.6457513115
Divide by 3, doing 0.6457513111÷3=0.215250437
Find next part 1÷0.215250437=4.6457513115

So now, by dividing by the value for B at the point at which the value repeated, we end up with the same value back at the repeat.

The only thing the algorithm has to do to calculate B is when the two values divide and are close to 1, we then have found where the value repeats. We then take the value 4 that happens at the repeat and divide it by 2 to find the closest whole square root 4÷2=2. Then squaring the value 2, we end up with 2x2=4 as the nearest whole square. Adding the value B for how far away we are from the whole square, we get 4+3=7.

The following code can calculate the root of any number and show the steps.

var n = (5**0.5+1)/2;

//Begin analyzing the number.

var work = "";

function fract(v,ac,r)
{
  var o = {a:1,b:0,toString:function(){return(this.a+(this.b>1?"\xF7"+this.b:""));}}
  
  var a = 0, b = 1, r1 = v, r2 = 0, c = [], m = 0; o.root = {a:0,b:1};
  
  while(Math.abs(v-(o.a/o.b)) > ac)
  {
    work += "re=" + (c[c.push((r1=r1-(r2=r1&-1)))-1]+r2).toFixed(4) + "\r\n";
    
    o.a=a+(a=o.a)*r2;o.b=b+(b=o.b)*r2;
    
    //Square root pattern check.
    
    m=c.length - 2; for(;!r && m >= 0; m--)
    {
      if(1 / Math.abs(r1 - c[m]) > 1000)
      {
        r = (r2/2)**2+(c[m]/c[c.length-2]); r = (m%2==1) ? 1 / r : r;
      
        work += "root="+r.toFixed(4)+"\r\n";
      
        r = fract(r, 1/10000, true);
        
        work += "Root fract = " + r + "\r\n";
        
        o = fract(Math.abs(v) - (r.a/r.b)**0.5, 1/1000, true);
        
        o.root = r; return(o);
      }
    }
    
    r1 = 1 / r1;
  }
  
  return(o);
}

var f = fract(n, 1/Number.MAX_SAFE_INTEGER);

work += "Num fract = " + f + "\r\n";

//Convert to simple form.

work += f+(f.root.a>0?"+\u221A("+f.root+")":"")+"="+n+"";

alert(work);

This allows us to find the exact value for B and the root of the value. Still, it has its limits, as floating point numbers have limited accuracy. Some roots of a number, including fractional numbers, repeat past the accuracy outside of the precision of a floating point value. How can we improve the calculation for B, at which z is close or equal to zero?

Well, there is one other method. We can fractionally raise and adjust B till the next number we get back is very close to the same, finding the nearest square root to a number. This means we only need to divide the number into 1 twice for two parts and adjust the value for B as a fraction that gets as close as possible to the fractional value for the square from the nearest whole square.

The following code lets us adjust the value B and tells us how close we are to matching the next part with z = 0.

var n = 7**0.5;

var b = 3;

var f1 = (n-(n&-1));

n = (1/(f1/b));

var f2 = (n-(n&-1))

var z = (f1 - f2).toFixed(13);

alert(z + " = 0");

The first line does the square root of 7. We set the value for "B" to 3. The variable f1 is the first part of the number. The value f2 is the next part of the number with the division of "B" included. If f1 and f2 subtract to zero, then you have found the proper value for B, in which all the next parts are the same. You then can directly calculate what generated the irrational number back into (a+√b)÷m.

This is the fastest version as you only need the first two parts out of the number and only need to calculate z = 0 to find the irrational. Reversing the calculation of z = 0 calculates the value B directly, which may be fractional if the square root was fractional. If the square root is fractional, we then move it to the "m" outside the square root (a+√b)÷m by multiplying a+√b by the fractional to make the square a whole number and moving the fraction to "m". This can be done entirely in code with simple calculations.

This gives us a function that can directly calculate our irrational value back into (a+√b)÷m without any algorithm, which will always be the correct answer.

By computing (a+√b) and rounding the square so it is not fractional for the number PI, subtract it from PI and start over with what we have remaining. We can find the General CF for the following patterns to calculate PI and base E.

PI
A=[3,6,6,6,6]
B=[1,9,25,49,81]

In which the progression of B is each square per 6.

Adding in B makes the number PI computable. If we did not include the reduction of radical patterns into B, we end up with PI = [3, 7, 15, 1, 292, 1], which is what we get when we remove the whole number and divide it into one repeatably same as what we did with √14 = [3, 1, 2, 1, 6, 1, 2, 1, 6]. Adding in the division to reduce radical patterns with B allows us to generalize and compute any number.

E
A=[2,1,2,3,4]
B=[1,1,2,3,4]

Both A and B somehow raise to compute the next part to the irrational number base e value while the rational part is 2.

If we did not include the reduction of radical patterns into B, we end up with E = [2, 1, 2, 1, 1, 4, 1, 1, 6, 1, 1, 8], which is what we get when we remove the whole number and divide it into one repeatably. The only difference is that we can recognize a pattern without simplifying the radical parts with B.

I still need to understand why everyone acts like it is some big secret to know how to take a random number and find how to compute it.

The pattern can be found by matching each value as close to zero as possible.

Solve the pattern to sets of numbers

This document explains in detail how to take apart complex numbers in detail. It also shows how to line A and B up, but some sets for A and B can be so complex that you may not recognize the pattern to compute the number.

Converting sets of numbers back into math functions is explained in detail in another document.

The following document will explain the rest in detail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment