Saturday, May 16, 2009

Greatest Common Divisor (GCD), Least Common Multiple (LCM)

This calculator takes two numbers and finds the greatest common divisor and the least common multiple. If you multiply the gcm by the lcd you get the same as multiplying the two original numbers.

Friday, May 1, 2009

Prime Factors Calculator

I made this javascript prime factors calculator and have found it addictive. I just keep factorizing numbers. Enter the number to factorize in the left box and click on the 'factorize' button. The prime factors are shown in the right box.


I've never had a push button prime factor generator before.

You can easily check if a number is prime. It only has one prime factor: itself.

It's easy to generate a large prime number. Just type in a long random number and get its prime factors. If one of the factors is large, you've found a large prime number. If you don't get one, try changing your random number slightly.

For example: 384339387 gives 3,37,3462517. So 3462517 is a nice large prime number.

I like adding an extra digit and seeing what factors come out:

numberprime factors
1111
1113,37
111111,101
1111141,271
1111113,7,11,13,37
1111111239,4649
1111111111,73,101,137
1111111113,3,37,333667
111111111111,41,271,9091
1111111111121649,513239
1111111111113,7,11,13,37,101,9901

All the numbers with an even number of ones have the factor 11. And those with 4, 8 and 12 ones have factors of 11 and 101 because 1111 = 11 X 101.

Those with an odd number of ones have only two prime factors, except 111111111 (nine ones). I wonder if there's something going on here?

Oh no, the next number lets me down: 1111111111111 has factors 53,79 and 265371653.

If you find any interesting patterns with this prime factors calculator, let me know.

Wednesday, April 22, 2009

The Numbers go Social Networking

Names and photos are clickable.

Pythagoras is thinking that a2 + b2 = c2
for right angled triangles.

12 hours ago · Comment · Like
Natural at 10am on 14 April
Likes this!
Rational at a ¼ past 10 on 14 April
like 3,4,5 & 20,21,29
Natural at 11am on 14 April
Yeah!
Rational at ½ past 11 on 14 April
Just thought of another: ⅗, ⅘, 1
Natural at 12pm on 14 April
is confused
Real at 12:07 on 14 April
1, 1, √2 and 1, √3, 2 makes me think of sin and cos
Natural at 1pm on 14 April
is frightened
Complex at 13:07 + 00:03i on 14 April
I don't get it.
Pythagoras at 13:23 on 14 April
Sorry Complex, how about |a|2 + |b|2 = |c|2
Irrational at 32:07 on 12 April
That's just what Hitler did, you commie!
Complex at 13:52 on 14 April
Let's see... 8 + 4i, -3 + 6i, 5 + 10i. Yes!!!
Complex and Pythagoras are now friends.
11 hours 23i minutes ago · Comment · Like
Pythagoras has shared some photos.
11 hours ago · Comment · Like
Pythagoras is dividing a circle's circumference by its diameter.
9 hours ago · Comment · Like
Transcendental at e/4 pm on 14 April
Likes this!
Natural at 1pm on 14 April
I know this one. It's three.
Rational at ½ past 1 on 14 April
lol. you're way off, it's 22/7, no wait... 355/113
Transcendental at π/2 pm on 14 April
feels superior
Rational has invited Natural to the group Irrationality is the square root of all evil.
8½ hours ago · Comment · Like
Natural at 2pm on 14 April
doesn't like this.
Irrational has joined the group Irrationality is the square root of all evil.
√59 metres ago · Comment · Like
Pythagoras Is zero a number?
7 hours ago · Comment · Like
Rational at ¼ past 2 on 14 April
Yes
Real at 14:27 on 14 April
yes
Natural at 3pm on 14 April
yes
Irrational at 1 ABY
Han definately shot first
Complex at 15:07 + 00:08i on 14 April
Yes (to zero, not to Han)
Irrational at stardate -313713.3276255709
I've watched it over √17354 times and in reverse. Han shot first. That's what I'd do.
Pythagoras at 15:57 on 14 April
ok, ok, I get it. Zero is a number.
Irrational at 19:07 on 14 April
and Han shot first.
Integer took the quiz What sort of Infinity are you?
The answer is Countable. You are countable. You can be lined up one-to-one with the natural numbers.

4 hours ago · Comment · Like
Natural at 7pm on 14 April
Likes this!
Natural has invited Integer, Complex and Irrational to join the group Become more natural: square yourself
3 hours ago · Comment · Like
Pythagoras Anyone out there know the square root of minus one?
3 hour ago · Comment · Like
Rational at ½ past 7 on 14 April
what's a square root?
Imaginary at 20:27i on 14 April
sqrt of -1 is i
Complex at 20:28 + 0.01i on 14 April
and -i
Imaginary at 20:30i on 14 April
oh yeah, -i too
Quaternion at 21:07 + 00:29ijk on 14 April
i, -i, j, -j, k and -k
Pythagoras at 20:57 on 14 April
Show off
Natural at 9pm on 14 April
what's minus one?
Irrational invited Pythagoras to join the group Han shot first
0 microseconds ago · Comment · Like

pythagoras image released under GNU Free Documentation License

Saturday, April 18, 2009

When are addition, subtraction, multiplication, division and exponentiation allowed?

Now that we've had a look at several groups of numbers let's bring together what operations are allowed for each one:

+-×÷ab
natural numbersyesonly larger number minus smaller or equal numberyesonly if it divides evenly; can't divide by zeroyes
integersyesyesyesonly if it divides evenly; can't divide by zeroonly positive and zero powers
rational numbersyesyesyescan't divide by zerointeger powers; some fractional powers
real numbersyesyesyescan't divide by zeronot allow some fractional powers of negative numbers e.q. (-1)(1/2)
complex numbersyesyesyescan't divide by zeroyes
The complex numbers are the only group that allows addition, subtraction, multiplication and exponentiation without restriction.

These increasingly larger groups of numbers can be seen as attempts to make subtraction, division and exponentiation work without restrictions.

The natural numbers allow exponentiation without restriction, but restrict subtraction and division. We can introduce negative numbers to allow subtraction (giving us the integers), but this forces restrictions on exponentiation.

We can then introduce fractions (giving us the rational numbers) to allow almost all divisions. Then adding irrational numbers (giving us the reals) allows fractional powers of all positive numbers and some powers of negative numbers.

To finally get back to having no restrictions on exponentiation, we need to include imaginary numbers leaving us with the complex numbers.

Beyond the complex numbers are the quaternions, octonians and sedenions.

+-×÷ab
complex numbersyesyesyescan't divide by zeroyes
quaternionsyesyesnot commutativecan't divide by zeroyes
octonionsyesyesnot commutative, not associativecan't divide by zeroyes
sedenionsyesyesnot commutative, not associative, not alternativecan't divide by zeroyes

Quaternions

The quaternions are an extension of the complex numbers. Instead of having just one square root of minus one: i, why not have 3: i, j and k?

We will need a way of multiplying them together. It turns out that the following works:

ij = k = -ji
jk = i = -kj
ki = j = -ki
ijk = -1

The quaternions are not commutative, which is quite strange. The order in which you multiply them matters! If you have two quaternions, x and y, then:

x × y = - y × x

Why have 3 square roots of -1 and not 2 square roots? Because with 2 the division doesn't work properly. Why not 4, 5, 6 roots etc? Well it works with 7 roots of -1. They are called the octonians. And with 15 roots you get the sedenions. The octonians are not commutative and not associative either. The sedenions are not commutative, associative or alternative.

The quaternions are given the symbol: ℍ

Complex Numbers

The complex numbers are the combination of the real numbers with the imaginary numbers. They are written as the real part plus the imaginary part. For example:

2 + 3i

The imaginary number i is defined as the square root of minus one, so i2 = -1. Multiplication of complex numbers follows the same rules as the real numbers, you just have to keep track of each part of the multiplication:

(2 + 3i) × ( 4 + 5i)
= 2 × 4 + 2 × 5i + 3i × 4 + 3i × 5i
= 8 + 10i + 12i - 15
= -7 + 22i

We can add, subtract, multiply and divide any two complex numbers and get a complex number* back (except dividing by zero). And, unlike the real numbers, we can raise any complex number to any other complex number without restriction.

For example:

32 = 9
3-2 = 1/9 = 0.11111111...
3(1/2) = √3 = 1.73205...
(-3)(1/2) = √(-3) = 1.73205i
32i = e2ln(3)i = cos(2ln(3)) + i sin(2ln(3)) = -0.5863 + 0.8101i
32+2i = 32 × 32i = 5.2763 + 7.2911i

The complex numbers are given the symbol: ℂ

-----

* the complex numbers include all real numbers. So 2 is the complex number 2 + 0i. Even though some complex multiplications give answers that are part of the real numbers, those answers are still complex numbers. For example (2 +3i) × (2 - 3i) = 13 (a real number) = 13 + 0i (a complex number).

Imaginary Numbers

The imaginary numbers are needed to fill in the last gap in exponentiation. The real numbers do not allow some negative numbers to be raised to fractional powers. For example they do not allow (-1)(1/2) = √(-1).

To get around this problem we can just make up an answer. We'll call this answer i. It can't be a real number, so it is outside the real numbers.

Using i allows us to find roots for all negative numbers. For example

√(-2) = √(2 × -1) = √2 × √(-1)= (√2)i = 1.414i

Both negative and positive numbers have two square roots. Just as both 42 and (-4)2 are 16, both (4i)2 and (-4i)2 are -16.

When we look at cube roots, thing get more complicated. Now every number has three cube roots, not just one, like it did with the real numbers. So not only does 33 equal 27, but so does (-3/2 + (3√3/2)i)3 and (-3/2 + (3√3/2)i)3

For more on this see the complex numbers.

Transcendental Numbers

The transcendental numbers are a part of the irrational numbers. Transcendental numbers are numbers that do not solve any polynomial equation that has rational coefficients. π and e are transcendental numbers so they don't solve any equations like:

4x - 7 =0
5x2 - 3x + 4 = 0
(4/5)x7 - 1.24x3 - 8 = 0

Strangely, it is not known whether π + e or π × e is transcendental, though at least one of them must be.

Real Numbers

If we combine the rational numbers with the irrational numbers we get the real numbers. In the real numbers we find positive numbers, negative numbers, integers, fractions, square roots, cube roots, fractional roots, π, e, zero...

Like the rational numbers, we can add, subtract, multiply and divide any two numbers (except dividing by zero). But with the real numbers we can also raise any positive number to the power of any other number. We can now do fractional powers and get a real answer because the irrationals are part of the reals. However, we cannot raise negative numbers to every fraction. (-1)(1/2) = √(-1) is not allowed with the real numbers, although (-1)(1/3) is allowed because it equals -1.

The real numbers are given the symbol: ℝ

Friday, April 17, 2009

Irrational Numbers

Just as rational numbers were made up by ratios, the irrational numbers cannot be expressed as a ratio. For example the square root of 2 does not equal one integer divided by another. You can get closer and closer with fractions, but you will never exactly equal √2.

This also means that the decimal expansion of an irrational number goes on forever.

Square roots, cube roots and other roots can all be irrational numbers. Transcendental numbers like pi and e are also irrational.

Raising an integer to a fraction will give an irrational number (unless it comes out exactly and gives an integer.) For example:

21/2 = √2 = 1.41421356...
53/2 = (√5)3 = 11.180339877...

Rational Numbers

We grouped the negative numbers with the natural numbers to get the integers. Now we increase our set of numbers further to get the rational numbers.

The rational numbers include all of the fractions made by dividing one integer by another, except that you can't divide by zero. So positive and negative fractions, fractions smaller than one, fractions larger than one, and all the integers (you can have 1 on the bottom your fraction) make up the rational numbers.

You can remember that the RATIOnals are made up from RATIOs.

Rational numbers do not have to be written as a fraction, but can be in decimal form - they are still rational.

Some rational numbers:
1/2, 6, -4/5, 10/3, 54 3/4, 1.75, -0.33333

With the inclusion of fractions in the rational numbers we are better off for division that we were with the integers. We can now divide any two numbers and get another rational number, with only one exception. We cannot divide by zero.

Like the integers, we can add, subtract and multiply without restriction. But we still have to be careful about exponentiation.

In most cases we can only raise rationals to the power of an integer. 32 is OK, and, unlike the integers, we can now do 3-2, but we cannot do 31/2 as that is outside of the rational numbers. We can only raise numbers to a fraction when the answer lies in the rational numbers. For example 25(1/2) = 5 or (8/27)(1/3) = 2/3.

The rational numbers are given the symbol: ℚ

Thursday, April 16, 2009

Integers

"Dad, can you buy me those butterfly wings?"
"They are seven dollars. How about you use some of your own money?"
"But I don't have my money with me."
"If I buy the wings, you can owe me the money and give it to me when we get back home."
Shortly afterwards my daughter has the butterfly wings and -$7 in her pocket and is thus introduced to negative numbers, and spending on credit.

The first extension we can make to the natural numbers is to go backwards as well as forwards to get the integers. The natural numbers start and zero and count 1, 2, 3 and so on. The integers allow us to count backwards as well. So -1, -2, -3... are integers, but are not natural numbers.

Now we can subtract any two integers and get another integer. We are not restricted like we were for the natural numbers. We can take a larger number from a smaller one and get an answer: a negative number.

And like with the natural numbers we can add and multiply any integer and get another integer. We are still restricted with division, though. 12 divided by 3 is fine, but 13 divided by 3 is a problem for the integers, just as it was for the natural numbers.

Strangely, exponentiation (raising a number to the power of something), which was OK for all natural numbers, is a problem for the integers. If we raise an integer to the power of a negative number we do not get an integer back. What is 3-1? or 2-2? Not an integer, that's for sure. So we can only use zero and positive powers in the land of the integers.

The Integers are given the symbol: ℤ

Wednesday, April 15, 2009

Natural Numbers

"What do you get when you take away 7 from 3?", I ask my daughter. "You can't do that. That's silly", she replies. "What about if I divide 5 in half?" "You get 2 in one group and 3 in the other."

Such in the world of a child, and such is the world of the natural numbers. In this world you start at zero and count 1, 2, 3 and so on. That's all the numbers you've got.

There's no problem with addition or multiplication or raising numbers to the power of something. The problems come with subtraction and division. When you try and subtract a larger number from a smaller one the answer is negative, which is outside the natural numbers. If you try to divide up a number that won't go evenly the answer is a fraction, once again outside the natural numbers.

What's 13 divided by 3? "4, and 1 remainder" in the world of the natural numbers.

The natural numbers are given the symbol: ℕ

Monday, April 13, 2009

Associative, but not commutative

Every operation mentioned in the previous post that is associative is also commutative, and everything mentioned that is not associative is not commutative.

associativecommutative
additionyesyes
mutiplicationyesyes
subtractionnono
divisionnono
exponentiationnono

So is there anything that is associative but not commutative?

Let's look at rotation.

Can we show that rotation is not commutative? In other words, does the order of rotations matter? If we do two rotations, do we get the same result if the do the second rotation first?

Start with a figure 1.



Rotate it by a quarter turn (90o) clockwise in the plane of the screen:



Then flip it upside down. (i.e. rotate it by a half turn (180o) about a line going from left to right through the middle of the 1.)



This is our result.

Now try doing the second rotation first, to see if the order matters.

Once again start with a figure 1.



This time, first flip it upside down (i.e. rotate it by a half turn (1800) about a line going from left to right through the middle of the 1.)



Then rotate it by a quarter turn (900) clockwise in the plane of the screen:



This (⥚) is different from our result above (⥟). So it matters which rotation is done first. Rotation does not commute.

So how about associativity? It turns out that rotations are associative. Giving examples can't prove that it works in every case, but let's look at one anyway.

Let's define a few things:

A = rotate it by a quarter turn (900) clockwise in the plane of the screen

B = flip it upside down (i.e. rotate it by a half turn (1800) about a line going from left to right through the middle of the 1.)

C = flip to back to front (i.e. rotate it by half a turn (1800) about a line going from top to bottom through the middle of the 1.)

We already know that AB ≠ BA (it does not commute). Now, are these rotations associative, does

(AB)C = A(BC)?

Let's do (AB)C:

Start with a figure 1.



From above we know that applying A then B gives:



Now apply C (flip back to front):



This is our result for (AB)C.

Now work out A(BC).

First we need to work out what BC means. So we start with 1 and see where BC gets us, to work out what sort of rotation or transformation BC actually is.

Start with a figure 1.



Apply B:



Apply C:



So BC takes us from ⥠ to ⥝. So BC means a rotation of half a turn (1800) in the plane of the screen.

Now we can work out what A(BC) means.

Start with a figure 1.



Apply A:



Apply BC (half a turn in the place of the screen):



This is the same result that we got for (AB)C.

So for this one example we have demonstrated that rotation is associative, that (AB)C = A(BC).

Sunday, April 12, 2009

Would you eat chocolate milk powder? (associativity)

"Yuk! Why are you eating Milo* straight?", I ask my daughter. "Isn't it better mixed in milk?" "I've already drunk the milk", she replies, "so now I'm eating the Milo."

Is drinking milk and then eating Milo, the same as first mixing the Milo in the milk and then drinking the result? Maybe your stomach doesn't notice, but it certainly tastes different.

To write this another way, are these things the same:

Milo is put into (milk is put into your mouth)

(Milo is put into milk) is put into your mouth

They are the same except for the location of the parentheses, but that can make a big difference.

This example raises the question of associativity. When the position of the parentheses makes no difference, the operation is called "associative".

Addition is associative:

(a + b) + c = a + (b + c)

for example:

(2 + 3) + 4 = 6 + 4 = 9
2 + (3 + 4) = 2 + 7 = 9

Multiplication is associative:

(a × b) × c = a × (b × c)

for example:

(2 × 3) × 4 = 6 × 4 = 24
2 × (3 × 4) = 2 × 12 = 24

However addition and multiplication together are not associative:

(a + b) × c ≠ a + (b × c)

(2 + 3) × 4 = 6 × 4 = 20
2 + (3 × 4) = 2 + 12 = 14

Subtraction, division and 'to the power of' (exponentiation) each are not associative.

(a - b) - c ≠ a - (b - c)
(a / b) / c ≠ a / (b / c)
(ab)c ≠ a(bc)

Every operation mentioned above that is associative is also commutative, and everything mentioned above that is not associative is not commutative.

associativecommutative
additionyesyes
mutiplicationyesyes
subtractionnono
divisionnono
exponentiationnono
So is there anything that is associative but not commutative?

I'll have a look in my next post.

------

*Milo or Nesquik or Ovaltine or Horlicks: Chocolate flavoured powder that is added to milk and not usually consumed directly.

Saturday, April 11, 2009

Put on your shoes and socks: commutation

"Put on your shoes and socks - but not in that order", I say to my daughter, who sighs at my frequently repeated joke. The order you put your clothes on matters. Putting on your shoes then your socks is quite different from putting on your socks first and then your shoes.

On the other hand, it doesn't matter which sock you put on first, your left or your right.

In mathematics, when the order you do something is not important we say that operation is commutative. It commutes. The actions 'putting on your left sock' and 'putting on your right sock' commute. It doesn't matter which you do first, you get the same result. However, whether you put on your shoes or your socks first does matter. These tasks do not commute.

So because is some cases the order is important, the operation "putting on" is not commutative. However, if we restrict this and only deal with the operation of "putting on a sock", then this operation does commute, because it doesn't matter which foot you put your sock on first.*

In mathematics some operations commute and others do not.

Addition commutes, meaning that:

a + b = b + a

For example:

3 + 2 = 5
2 + 3 = 5

We get the same answer, no matter the order.

Multiplication also commutes:

ab = ba

3 X 2 = 6
2 X 3 = 6

So what does not commute? For some reason mathematicians seem to like jumping to more exotic examples like matrices, rotations or quaternions. But how about subtraction? Subtraction does not commute.

a - b ≠ b - a

For example:

3 - 2 = 1
2 - 3 = -1

Division does not commute either.

a / b ≠ b / a

For example:

3 / 2 = 1.5
2 / 3 = 0.666...

And 'raising to the power of' does not commute also:

ab ≠ ba

32 = 9
23 = 8

In future posts I'll look at other properties of these simple operations.

---------

*I am assuming that you do not put more than one sock on each foot - then the order would matter (if you can tell your socks apart) as it would effect which sock was underneath and which sock on top.

Thursday, April 9, 2009

Continued fractions

Any whole number or simple fraction can be written as a continued fraction. Continued fractions appear a little strange and look like this:

        1
a0 + ----------------------
            1
     a1 + ---------------
               1
          a2 + --------
               a3 + ...
To make it easier to write down, the above fraction is written as:

[a0 ; a1, a2, a3 ...]

For example, the continued fraction for 40/33 is:

        1
 1 + ----------------------
            1
      4 + ---------------
                1
          1 + ---------
                   1
              2 + ---
                   2
= [1; 4, 1, 2, 2]

You can check this on a calculator by starting at the bottom of the fraction and working upwards. First calculate 1/2, then add 2, then do 1/x , then add 1, then do 1/x again, then add 4, do 1/x again and finally add one to get 1.21212... = 40/33.

To work out the numbers that go in a continued fraction you go in the opposite direction. Start with 40/33. = 1.21212.

1.2121212

Subtract the whole number part, in this case 1

value remainingcontinued fraction so far
0.2121212 1 + ...

Take 1/x

value remainingcontinued fraction so far
4.7142857 1 + 1/ ...

Subtract the whole number part, in this case 4

value remainingcontinued fraction so far
0.7142857 1 + 1/( 4 + ...)

Take 1/x

value remainingcontinued fraction so far
1.4000000 1 + 1/( 4 + 1/ ...)

Subtract the whole number part, in this case 1

value remainingcontinued fraction so far
0.4000000 1 + 1/( 4 + 1/ (1 +...))

Take 1/x

value remainingcontinued fraction so far
2.5000000 1 + 1/( 4 + 1/ (1 + 1/ ...))

Subtract the whole number part, in this case 2

value remainingcontinued fraction so far
0.5000000 1 + 1/( 4 + 1/ (1 + 1/ (2 + ...))

Take 1/x

value remainingcontinued fraction so far
2.0000000 1 + 1/( 4 + 1/ (1 + 1/ (2 + 1/...))

We are left with a whole number so put this number in our continued fraction and we have reached the end.

40/33 = 1 + 1/( 4 + 1/ (1 + 1/ (2 + 1/2))

You can use the same method to work out continued fractions for square roots. Then the continued fraction goes on forever (unless the square root is a whole number eg √4 = 2):

           1
√2 = 1 + ---------------------
               1
         2 + --------------
                  1
             2 + --------
                  2 + ...
= [1; 2, 2, 2, 2, ...]

For square roots, the continued fraction soon forms a repeating pattern.

√2 = [1; 2, 2, ...]
√3 = [1; 1, 2, 1, 2, ...]
√5 = [2; 4, 4, ...]
√6 = [2; 2, 4, 2, 4, ...]
√7 = [2; 1, 1, 1, 4, 1, 1, 1, 4, ...]

For other numbers, such as π, the continued fraction does not form a pattern:

π = [3; 7, 15, 1, 292, 1, 1, 1, 2. ...]

By using the start of a continued fraction we can determine a fraction that is close to the irrational number. For the case of π:

[3;] = 3/1 = 3 = π - 0.14
[3; 7] = 22/7 = 3.1428 = π + 0.0012
[3; 7, 15] = 333/106 = 3.141509 = π - 0.000083
[3; 7, 15, 1] = 355/113 = 3.14159292 = π + 0.00000027
[3; 7, 15, 1, 292] = 103993/33102 = 3.14159265301 = π - 0.00000000058

The 292 in the continued fraction for π is quite large. This indicates that we will have to use much larger numbers in the faction to estimate π, before we find a better approximation than 355/113. So 355/113 will be quite a good approximation for π.

Wednesday, April 8, 2009

Pi by fractions

The circumference of a circle divided by its diameter is always the same number, no matter the size of the circle. This number is called π (pi) and has the value 3.1415926535...

π is an irrational number, which means that it cannot be expressed as a simple fraction such as 1/5 or 3/4. However, you can get pretty close.

A fraction that is often used is 22/7. This is not all that good:

22/7 = 3.14285714...
π = 3.14159265...

Although within 0.04% of the correct answer, 22/7 is only correct to 2 decimal places. We can do better than this.

355/113 is correct to 6 decimal places. It's within 0.000009% of π.

355/113 = 3.1415929203...
π = 3.1415926535...

355/113 is such a good approximation to π, that there is not a more accurate fraction until 52163 / 16604, and that is only marginally closer to π, still only correct to 6 decimal places.

52163/16604 = 3.1415923874...
355/113 = 3.1415929203...
π = 3.1415926535...

To be accurate to 7 decimal places we need to go as far as 86953 / 27678

86953/27678 = 3.1415926006...
52163/16604 = 3.1415923874...
355/113 = 3.1415929203...
π = 3.1415926535...

The importance of 355/113 has been recognized, giving it the name Milü.

More Pythagorean Triangles

Here's another rule for generating Pythagorean trianges, Last time each triangle began with an odd number. This time we will use even numbers:

4, 3, 5 (16 + 9 = 25)
6, 8, 10 (36 + 64 = 100)
8, 15, 17 (64 + 225 = 289)
You generate first number of the next line by writing down the next even number. To find the second and third numbers, add the first number to the second number in the previous row. The second and third numbers are one before and one after the result. For example, in the second row above, the first number is 6 as it is the even number that comes after the first number in the row above it, which is 4. We then add this 6 to the second number in the row above, which is 3. This gives us 9. The second and third numbers are one either side of this: 8 and 10.

Let's find the next row. The last row begins with 8. The even number after 8 is 10. So this is the first number:

10

Add this 10 to the second number of the previous row, which is 15. 10 + 15 = 25. The second and third numbers are one either side of this: 24 and 26

10, 24, 26

102 + 242 = 100 + 576 = 676 = 262

Tuesday, April 7, 2009

Generate Pythagoras Triangles

Triangles containing a right angle are called Pythagorean triangles. Their side lengths have a simple relationship. The sum of the squares of the shorter side lengths equals the square of the length of the longer side.

A simple example is a triangle with side lengths:

3, 4 and 5

since

32 + 42 = 9 + 16 = 25 = 52

Some other examples are:

5, 12, 13 (25 + 144 = 169)
6, 8, 10 (36 + 64 = 100)
7, 24, 25 (49 + 576 = 625)
20, 21, 29 (400 + 441 = 841)
You can find some of these yourself as they fall into patterns. For example:

3, 4, 5
5, 12, 13
7, 24, 25

The first numbers in each row are the odd numbers 3, 5, 7 ...

To find the second number add the first number to the first two numbers in the previous row. So for the row starting with 5, add this 5 to the 3 and 4 from the previous row: 5 + 3 + 4 = 12. To get the final number just add one to the second number: 12 + 1 = 13.

Let's work out the next row. The odd number after 7 is 9:

9

Add 9 to the first two numbers in the previous row to get the second number: 9 + 7 + 24 = 40

9, 40

And add one more to get the final number is 40 + 1 = 41

9, 40, 41

(92 + 402 = 81 + 1600 = 1681 = 412)

Another way to get the second and third numbers is to square the first number and halve the result. The second and third numbers are the whole numbers on either side. So for this last row: 92 = 81. Half of this is 40.5. So the second and third numbers are 40 and 41.

This method does not generate every possible Pythagorean Triangle. I'll leave that for another time.

Sunday, April 5, 2009

Cube Sum is a Square

Pick a whole number. If you add up the cubes of all the whole numbers from 1 to your number, you will get the same as if you add up all the numbers from 1 to your number and then square the result.

For example choose the number 3:

Add up the cubes of all the numbers from 1 to 3:

13 + 23 + 33 = 1 + 8 + 27 = 36

Now, add up all the numbers from 1 to your number

1 + 2 + 3 = 6

and then square the result

62 = 36

The answers are the same.

In algebraic notation:

13 + 23 + 33 + ... + n3 = (1 + 2 + 3 + ... + n)2

We can show this with pictures:

It obviously works for 1:

13 = 12

* = *

for 2:

(1 + 2)2 =

* * *
* * *
* * *
remove one to the side. This is the 13. We need to show that the rest is 23.

* *    *
* * *
* * *
The remaining has a 22 in it. Separate that out

* *    *

* *  *
* *  *
Move the two at the top to match the two at the side:

       *

* *  * *
* *  * *
Two lots of 22 makes 23.

= 13 + 23

Now the case for 3:

(1 + 2 + 3)2 =


* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
* * * * * *
move 32 to one side. We already know that this is 13 + 23. So we need to show that the rest is 33.

* * *        * * *
* * *        * * *
* * *        * * *
* * * * * *
* * * * * *
* * * * * *
The remaining has a 32 in it at the bottom left. Separate that out

* * *        * * *
* * *        * * *
* * *        * * *

* * *   * * *
* * *   * * *
* * *   * * *
We have 3 lots of 32 which is 33.

= 13 + 23 + 33

We actually got a bit lucky with this one. The next case shows what we need to do for any size.

(1 + 2 + 3 + 4)2 =

* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
move 62 to one side. We already know that this is 13 + 23 + 33. So we need to show that the rest is 43.

* * * *              * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
* * * * * * * * * *
The remaining has a 42 in it at the bottom left. Separate that out

* * * *              * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *

* * * *   * * * * * *
* * * *   * * * * * *
* * * *   * * * * * *
* * * *   * * * * * *
The parts above and beside the 42 have side length 1+2+3. Separate it out this way.

* * * *              * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *
                     * * * * * *
* * * *              * * * * * *
* * * *              * * * * * *

* * * * 

* * * *   *  * *  * * *
* * * *   *  * *  * * *
* * * *   *  * *  * * *
* * * *   *  * *  * * *
Move those above the square to be with those beside the square. Matching the longest with the shortest and so on, 3 next to 1, 2 next to 2 and 1 next to 3.

                     * * * * * *
                     * * * * * *
                     * * * * * *
                     * * * * * *
                     * * * * * *
                     * * * * * *



* * * *   *  * * *    * *  * *    * * *  *
* * * *   *  * * *    * *  * *    * * *  *
* * * *   *  * * *    * *  * *    * * *  *
* * * *   *  * * *    * *  * *    * * *  *
Bunch together to make 4 squares

                     * * * * * *
                     * * * * * *
                     * * * * * *
                     * * * * * *
                     * * * * * *
                     * * * * * *



* * * *   * * * *    * * * *    * * * *
* * * *   * * * *    * * * *    * * * *
* * * *   * * * *    * * * *    * * * *
* * * *   * * * *    * * * *    * * * *
We now have 4 lots of 42 which is 43

= 13 + 23 + 33 + 43

This procedure can be applied to the general case n.

6174

Take a four digit number. Put the digits in order from smallest to biggest to make number A. Then put them in order from biggest to smallest to make number B. Calculate B minus A to get the answer.

Repeat this process with the answer, and keep repeating.

For example start with 7119.
Putting the digits in order from smallest to largest:
1179
Now from largest to smallest:
9711
Subtract:
9711 - 1179 = 8532

Now repeat with 8532:
8532 - 2358 = 6174

Now repeat with 6174:
7641 - 1467 = 6174

We've reached the end since applying this process to 6174 just gives 6174 back again.

If fact, no matter where you start, if you keep going, you will get to 6174. (Unless all the original digits were the same. Then you will get zero on the first calculation.)

How does this work?

It turns out that whatever number you start with, that after doing the process the first time you will be left with one of 54 numbers (or zero). From there it is at most 6 steps away from 6174.

Here is a graph of those 54 numbers. Start with a number and follow the arrow to see what you get after applying this process once. Keep following the arrows down to 6174.

Click on the graph to enlarge it.

Halve and Triple

Think of a whole number. If it's even, halve it. If it's odd, triple it and add one. Then repeat this procedure with the answer. Continue until you reach 1.

Did you get to 1 quickly? Or did it take a long time, going through many numbers?

It depends which number you start with. 8 is very quick, taking only three turns: 8, 4, 2, 1. But 9 takes 19 turns! (9, 28, 14, 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 18, 8, 4, 2, 1).

Can you see any patterns in the time it takes?

Here is a graph showing the path taken for all the numbers from 1 to 26. Why did I stop at 26?

Click on the graph for a larger version.