Tuesday, February 8, 2022

Epicycloids and Hypocycloids

In the book Trigonometric Delights by Eli Maor, there is a chapter on epicycloids and hypocycloids and their many fascinating properties.

These properties are illustrated with both descriptions and diagrams, which is the best a book can do, but require an active imagination to visualize each moving part.  Fortunately in the last two decades since Trigonometric Delights was written, programs for making animated diagrams have become more and more accessible, and I was able to use the free websites www.desmos.com and www.gifsmos.com to make some animated epicycloids and animated hypocycloids to better illustrate these theorems.

Hypocycloids

A hypocycloid can be formed by tracing the path of a point on a small circle that is rolling on the inside of a larger circle, similar to a design that can be made with spirograph. 

Although different hypocycloids can be made by varying the radii of each circle, all of them can be described by parametric equations.  Consider the following diagram, where R is the radius of the large circle and r is the radius of the small circle:


The coordinates of P relative to C are P(r cos Φ, -r sin Φ) and the coordinates of C relative to O are C((R – r) cos θ, (R – r) sin θ) so that the coordinates of P relative to O are:

x = (R – r) cos θ + r cos Φ

y = (R – r) sin θ – r sin Φ

However, from the rolling motion, arc PQ’ = arc QQ’, and since PQ’ = Rθ and QQ’ = r(θ + Φ), that means Rθ = r(θ + Φ), which rearranges to Φ = (R – r)/r · θ.  Substituting Φ into the equations above gives the parametric equations for a hypocycloid:

x = (R – r) cos θ + r cos (R – r)/r · θ

y = (R – r) sin θ – r sin (R – r)/r · θ

If the larger circle is twice as big as the smaller circle, then R = 2r, and the equations become:

x = 2r cos θ

y = 0

which traces a horizontal line segment along the diameter:

If the larger circle is four times as big as the smaller circle, then R = 4r, and the equations become:

x = 3r cos θ + r cos 3θ

y = 3r sin θ – r sin 3θ

which traces an astroid:

Double Generation Theorem of Hypocycloids

In 1725, Daniel Bernoulli discovered the double generation theorem of hypocycloids: a circle of radius r1 rolling on the inside of a fixed circle of radius R generates the same hypocycloid as does a circle of radius r2 = R – r1 rolling inside the same fixed circle.

For example, here is the astroid again, the hypocycloid made by circles with radii R = 1 and r1 = ¼:



and the following is the same astroid formed by circles with radii R = 1 and r2 = R – r1 = 1 – ¼ = ¾, but with the smaller circle moving in the opposite direction: 


and here are both animations at the same time:

Here is the double generation theorem illustrated by circles with radii R = 1, r1 = 2/5, and r2 = 3/5: 

and here it is illustrated by circles with radii R = 1, r1 = 2/7, and r2 = 3/7:

The double generation theorem of hypocycloids can be proved by algebraic manipulation.  The hypocycloid formed by the circles with radii R and r2 has the parametric equations:

x = (R – r2) cos θ2 + r2 cos (R – r2)/r2 · θ2

y = (R – r2) sin θ2 – r2 sin (R – r2)/r2 · θ2

Replacing r2 = R – r1 and θ2 = 2πp – (R – r1)/r1 · θ1 (where p is an integer) and then simplifying gives: 

x = (R – r1) cos θ1 + r1 cos (R – r1)/r1 · θ1

y = (R – r1) sin θ1 – r1 sin (R – r1)/r1 · θ1

which are the parametric equations for the hypocycloid formed by the circles with radii R and r1.

Epicycloid

An epicycloid can be formed by tracing the path of a point on a small circle that is rolling on the outside of a larger circle: 

Using a similar argument as the hypocycloid, but adding r to R instead of subtracting r from R, the parametric equations for the epicycloid can be found to be: 

x = (R + r) cos θ – r cos (R + r)/r · θ

y = (R + r) sin θ – r sin (R + r)/r · θ

An epicycloid can also be formed by tracing the path of a point on a large circle that is rolling around a fixed smaller circle in its interior:

If r is the radius of the large circle and R is the radius of the fixed smaller circle, the parametric equations for this type of epicycloid can be found to be: 

x = r cos (r – R)/r · θ – (r – R) cos θ

y = r sin (r – R)/r · θ – (r – R) sin θ

Double Generation Theorem of Epicycloids

As alluded to in the epicycloid animations above, there is a double generation theorem for epicycloids: a circle of radius r1 rolling on the outside of a fixed circle of radius R generates the same epicycloid as does a circle of radius r2 = R + r1 rolling around the same fixed circle in its interior. 

 When the circles have radii R = 1, r1 = 1, and r2 = 2, the epicycloid traced is a cardioid:

And here is an epicycloid traced by circles with radii R = 1, r1 = 2/5, and r2 = 7/5:

Just like hypocycloids, the double generation theorem for epicycloids can be proved by algebraic manipulation.  The epicycloid formed by a large circle with a radius of r2 rotated around a fixed circle with a radius of R has the parametric equations:

x = r2 cos (r2 – R)/r2 · θ2 – (r2 – R) cos θ2

y = r2 sin (r2 – R)/r2 · θ2 – (r2 – R) sin θ2

Replacing r2 = R + r1 and θ2 = (R + r1)/r1 · θ1 and then simplifying gives:

x = (R + r1) cos θ1 – r1 cos (R + r1)/r1 · θ1

y = (R + r1) sin θ1 – r1 sin (R + r1)/ r1 · θ1

which are the parametric equations for the epicycloid formed by a circle with radius r1 rotating around a fixed circle with a radius of R.

Conclusion

Epicycloids and hypocycloids have many fascinating properties, as described by Eli Maor in his book Trigonometric Delights.  My hope is that these animated diagrams will help people understand these properties better, and give a better appreciation for mathematics in general.

Thursday, February 3, 2022

Proving Common Trig Identities with Circle Theorems

I just re-read Trigonometric Delights by Eli Maor, and in the middle of his historical account of mathematics, he gives creative proofs for some common trigonometric identities based solely on Greek circle theorems.

Using the inscribed angle theorem, Ptolemy’s Theorem, and Thales’s Theorem, Maor is able to prove the law of sines, the angle addition and subtraction formulas for sine, the Pythagorean Theorem, and the Pythagorean identity of sine and cosine.  His proofs are outlined below.

___________________________________________________________________________

Consider the following triangle that is inscribed in a circle:

By the inscribed angle theorem, ∠AOB = 2∠ACB = 2γ.

Since OM bisects ∠AOB = 2γ, ∠MOB = γ.

Then from ΔOMB,

which rearranges to:

By a similar argument,

and

Therefore,

which proves the law of sines.

If 2r = 1, then a = sin α, b = sin β, and c = sin γ.  In other words, the side of an inscribed triangle in a circle with a unit diameter is equal to the sine of its opposite angle.

___________________________________________________________________________

Now consider the following diagram, where AC = 1:

Since 2r = 1, then as shown above BD is equal to the sine of its opposite angle, so BD = sin(α + β).

From ΔABC, cos α = AB/AC = AB/1 = AB and sin α = BC/AC = BC/1 = BC. 

Similarly from ΔADC, AD = cos β and CD = sin β.

But by Ptolemy’s Theorem, 

AC · BD = AB · CD + BC · DA

and after substituting the sine and cosine values, 

1 · sin(α + β) = cos α · sin β + sin α · cos β

which proves the angle addition formula for sine. 

___________________________________________________________________________

Similarly, consider the following diagram, where AD = 1:

Now BC is equal to the sine of its opposite angle, so BC = sin(α – β). 

From ΔABD, cos α = AB/AD = AB/1 = AB and sin α = BD/AD = BD/1 = BD. 

Similarly from ΔACD, AC = cos β and CD = sin β.

But by Ptolemy’s Theorem, 

AC · BD = AB · CD + BC · DA

and after substituting the sine and cosine values,

cos β · sin α = cos α · sin β + sin (α – β) · 1

which rearranges to:

sin(α – β) = sin α · cos β – cos α · sin β

which proves the angle subtraction formula for sine.

___________________________________________________________________________ 

Lastly, consider the following diagram of rectangle ABCD inscribed in a circle:

By the properties of a rectangle, AB = CD and AD = BC.

By Thales’s Theorem, AC and BD are diameters, so AC = BD.

By Ptolemy’s Theorem, 

AC · BD = AB · CD + BC · DA

and after substituting AB = CD, AD = BC, and AC = BD,

(AC)2 = (AB)2 + (BC)2

which proves the Pythagorean Theorem.

___________________________________________________________________________ 

Furthermore, if AC = 1, then cos α = AB/AC = AB/1 = AB and sin α = BC/AC = BC/1 = BC.

Substituting AC = 1, AB = cos α, and BC = sin α into the Pythagorean Theorem gives:

1 = cos2α + sin2α

which proves the Pythagorean identity of sine and cosine.

___________________________________________________________________________ 

Today’s math textbooks also have proofs for these trigonometric identities, but they are typically long and cumbersome.  Maor’s proofs are much more elegant, and also logically flow from a historical perspective.

Tuesday, May 19, 2020

Circles of Apollonius of a Triangle

Let’s investigate all triangles in which one side length is twice another side length and the third side length is a constant length of 9. Some triangles that fit these requirements would include ones with integer side lengths (4, 8, 9), (5, 10, 9), (6, 12, 9), (7, 14, 9), and (8, 16, 9):

Placing each of these triangles one on top of the other, it would appear that the third vertex follows a circular path:

and can be animated as follows:

Is this path always a circle, or is this just a coincidence with the values that we picked? 

This is no coincidence.  The Greek mathematician Apollonius showed that any circle can be defined as the set of points with a constant ratio of distances to two set points.  Conversely, we can prove that a set of points which maintains a constant non-one ratio of distances to two fixed points will always form a circle. 

If the constant ratio is k = b/a and the distance between the two fixed points is c so that a < b < c, then we can make △ABC with side lengths a, b, and c and with opposite angles ∠A, ∠B, and ∠C, so that ∠B is at the origin and side c is along the x-axis so that the coordinate of A is (c, 0).

Then the locus of points C that are ak away from B and bk away from A can be expressed by the distance equation as x2 + y2 = a2k2 and (x – c)2 + y2 = b2k2.  Rearranging and combining gives a2b2k2 = b2x2 + b2y2 = a2(x – c)2 + a2y2, and further rearranging gives (x + a^2 c/b^2 – a^2)2 + y2 = (abc/b^2 – a^2)2, a circle equation with a radius of r = abc/b^2 – a^2. Therefore, vertex C will always lie on the path of a circle.

In fact, three circles of Apollonius can be drawn for any scalene triangle, one for each vertex:

Using the same argument as above, the radii of the three circles of Apollonius will be r1 = abc/c^2 – a^2, r2 = abc/c^2 – b^2, and r3 = abc/b^2 – a^2.  

Since 1/r1 = 1/abc(c2 – a2), 1/r2 = 1/abc(c2 – b2), and 1/r3 = 1/abc(b2 – a2), and since 1/abc(c2 – a2) = 1/abc(b2 – a2) + 1/abc(c2 – b2), we can derive the elegantly compact relation:

where r1 < r2 and r1 < r3.

Another way to write this equation is r2-1 + r3-1 = r1-1, which places it in an increasing list of geometric equations that are in the form of xn + yn = zn, the most famous being a2 + b2 = c2, the Pythagorean Theorem.  Other equations in that form include the relationship between the major axis, minor axis, and focal length of ellipses and hyperbolas (b2 + c2 = a2 and a2 + b2 = c2), the radii of three mutually tangent circles and a line  (r1-½ + r2-½ = r3-½), and, of course, the addition of segments (a1 + b1 = c1).

It is amazing that over a thousand years ago Apollonius showed that any circle can be defined as the set of points with a constant ratio of distances to two set points.  It is also amazing that the simple relationship of 1/r1 = 1/r2 + 1/r3 is true for the radii of the three circles of Apollonius for any scalene triangle, despite the complicated steps in between.


Monday, February 18, 2019

Perspective, Silhouettes, and Taxi-Cab Geometry

In a drawing with one-point perspective, all lines perpendicular to the picture plane converge to a single point on the horizon called the vanishing point.  In this picture of some railroad tracks, for example, it would appear that the railroad tracks meet at some point far off in the distance, even though they are actually parallel.

one-point perspective of railroad tracks

Now imagine that you are looking down at some cubes on a level surface, and that you draw them using one-point perspective.  The top of each cube will not only appear larger than the bottom of each cube, but also be drawn further away from the vanishing point.

one-point perspective of some level cubes
  
Next, you create a silhouette of each cube by coloring inside each of the drawn outlines.  The resulting shapes are either irregular hexagons, pentagons, or quadrilaterals.

the silhouettes of some level cubes drawn with one-point perspective

Amazingly, the area of each silhouette can be determined by just four variables – the side length a of the top square of the drawn cube, the side length b of the bottom square of the drawn cube, the horizontal shift x of the cube from a cube directly over the vanishing point, and the vertical shift y of the cube from a cube directly over the vanishing point.

The center of the top square of a cube in the first quadrant would be drawn at (ax, ay) and its vertices at (a(x ± ½), a(y ± ½)).


Likewise, the center of the bottom square of a cube in the first quadrant would be drawn at (bx, by) and its vertices at (b(x ± ½), b(y ± ½)). 

Each silhouette is a hexagon (or a degenerate hexagon) that is the difference between the area of a rectangle with sides c = a(x + ½) – b(x – ½) and d = a(y + ½) – b(y – ½) and the areas of the two opposite triangles, one with sides c – a and d – b, and the other with sides c – b and d – a. 


In other words, the area of the silhouette is A = cd – ½(c – a)(d – b) – ½(c – b)(d – a), and letting p = ½(a2 – b2) and q = ½(a2 + b2), this simplifies to A = p(x + y) + q.  A similar argument can be made for the other quadrants to give the general formula of A = pd + q, where d = |x| + |y|. 

Surprisingly, d = |x| + |y| is also the equation for distances in taxicab geometry, a seemingly unrelated mathematical topic.  In taxicab geometry, segments are limited to being either vertical or horizontal, just like roads in a city block.  Since a taxicab cannot drive through city blocks along a hypotenuse, the distance it must travel to get to an intersection that is 4 blocks east and 3 blocks north is at least |3| + |4| = 7 blocks (whereas a flying bird not limited to the roads can do it in √(32 + 42) = 5). 

taxicab geometry paths from (0, 0) to (4, 3)

In general, the distance a taxicab must travel to get to an intersection that is x blocks east or west and y blocks north or south is at least d = |x| + |y|.

Therefore, there is a surprising connection between one-point perspective drawings and taxicab geometry.  The area of the silhouette of a cube drawn in one-point perspective is A = pd + q, where d = |x| + |y|, the same distance a taxicab must at least travel to get to an intersection that is x blocks east or west and y blocks north or south.  This means that the area of the silhouette is a linear function of its own taxicab distance.

Thursday, January 18, 2018

Automorphic Numbers

While learning your multiplication tables, you may have noticed a peculiar property that some numbers, when multiplied by itself, ends in the same number.  For example, for 5 · 5 = 25, the product 25 ends in the same way as its square root, 5.  Such a number is called an automorphic number.  There are several methods for finding automorphic numbers.

Method 1 – Testing All Numbers

It is a simple exercise to find all the single-digit automorphic numbers by testing each single digit by hand:

0 · 0 = 0 (yes)
1 · 1 = 1 (yes)
2 · 2 = 4 (no)
3 · 3 = 9 (no)
4 · 4 = 16 (no)
5 · 5 = 25 (yes)
6 · 6 = 36 (yes)
7 · 7 = 49 (no)
8 · 8 = 64 (no)
9 · 9 = 81 (no)

Therefore, the only single-digit automorphic numbers are 0, 1, 5, and 6.

Trying to find automorphic numbers with multiple digits in this way would be very time-consuming, so here is a computer program that tests every number within a given range:

01
# Automorphic Numbers (Method 1)
02
# Python 2.7.3
03
# To find all automorphic numbers less than n, type "automorphic(n)".
04
#   For example, to find all automorphic numbers less than 1000, type
05
#   "automorphic(1000)".
06

07
# find all automorphic numbers less than n
08

09
def automorphic(n):
10
    # set up variables
11
    exponent = 2
12
    total = 0
13

14
    # print a title
15
    print "Automorphic Numbers from 1 to " + str(n) + ":"
16

17
    # go through each number and see if it has the same ending as its square.
18
    for a in range(1, n):
19
        if (str(a ** exponent))[-len(str(a)):] == str(a):
20
            # if it is automorphic, print it and add one to the total
21
            print "  " + str(a)
22
            total += 1
23

24
    # print the total
25
    print "Total: " + str(total)

According to this, the automorphic numbers between 1 and 1,000,000 are:

>> automorphic(1000000)
Automorphic Numbers from 1 to 1000000:
  1
  5
  6
  25
  76
  376
  625
  9376
  90625
  109376
  890625
Total: 11

Method 2 – Modular Arithmetic

As the number of digits increase, the above method becomes slower and slower, even for a computer.  Fortunately, the method for finding automorphic numbers can be shortened significantly by making use of the fact that the last digit of any product is determined by the last digit of its factors only.  Therefore, all double-digit automorphic numbers must end in one of the single-digit automorphic numbers.  A similar argument can be made to show that all three-digit automorphic numbers must end in one of the two-digit automorphic numbers, all four-digit automorphic numbers must end in one of the three-digit automorphic numbers, and so on.

The calculations for finding an automorphic number with multiple digits can be made even faster by making use of algebra.  Let n be an already known automorphic number with k digits, and m be the unknown first digit of an unknown automorphic numbers with k + 1 digits, then the unknown automorphic number can be expressed as 10km + n, and since m is a single digit, 0 ≤ m ≤ 9.  Furthermore, as an automorphic number, the square of 10km + n, when divided by 10k+1, must have a remainder of 10km + n, so (10km + n)2 ≡ 10km + n (mod 10k+1).  Simplifying,

01
(10km + n)2 ≡ 10km + n
(mod 10k+1)
(given)
02
102km + 2·10kmn + n2 ≡ 10km + n
(mod 10k+1)
(expand)
03
2·10kmn + n2 ≡ 10km + n
(mod 10k+1)
(102km (mod 10k+1) = 0)
04
2·10kmn – 10km ≡ n – n2
(mod 10k+1)
(subtract n2 and 10km)
05
(2n – 1)10km ≡ n – n2
(mod 10k+1)
(factor 10km)
06
(2n – 1)m ≡ n – n^2/10^k
(mod 10)
(divide by 10k)

Therefore, if n is an already known automorphic number with k digits, the last digit of (2n – 1)m mod 10 must be the same as the last digit of n – n^2/10^k (mod 10) and 0 ≤ m ≤ 9.

So to find all the double-digit automorphic numbers, test all known single-digit automorphic numbers as n (n = 0, n = 1, n = 5, and n = 6) and let k = 1.  Then:
For n = 0, (2n – 1)m ≡ n – n^2/10^k (mod 10) becomes 9m ≡ 0 (mod 10), which means m = 0 for 0 ≤ m ≤ 9, to make the double-digit automorphic number of 00 (which is a repeat of 0).
For n = 1, (2n – 1)m ≡ n – n^2/10^k (mod 10) becomes m ≡ 0 (mod 10), which means m = 0 for 0 ≤ m ≤ 9, to make the double-digit automorphic number of 01 (which is a repeat of 1).
For n = 5, (2n – 1)m ≡ n – n^2/10^k (mod 10) becomes 9m ≡ 8 (mod 10), which means m = 2 for 0 ≤ m ≤ 9, to make the double-digit automorphic number of 25.
For n = 6, (2n – 1)m ≡ n – n^2/10^k (mod 10) becomes m ≡ 7 (mod 10), which means m = 7 for 0 ≤ m ≤ 9, to make the double-digit automorphic number of 76.

Therefore, the only double-digit automorphic numbers are 25 and 76.  A quick test shows that 25·25 = 625 and 76·76 = 5776.  It should also be noted that when n = 0 and when n = 1, then n – n2 = 0 which means m = 0.  This means that a new automorphic number is never created, so both n = 0 and n = 1 do not need to be tested any more.

For three-digit automorphic numbers, test all known double-digit automorphic numbers as n (n = 25, and n = 76) and let k = 2.  Then:
For n = 25, (2n – 1)m ≡ n – n^2/10^k (mod 10) becomes 9m ≡ 4 (mod 10), which means m = 6 for 0 ≤ m ≤ 9, to make the three-digit automorphic number of 625.
For n = 76, (2n – 1)m ≡ n – n^2/10^k (mod 10) becomes m ≡ 3 (mod 10), which means m = 3 for 0 ≤ m ≤ 9, to make the three-digit automorphic number of 376.

Therefore, the only three-digit automorphic numbers are 625 and 376.  A quick test shows that 625·625 = 390625 and 376·376 = 141376.

Two observations can be made here.  First of all, 2n – 1 (mod 10) is always odd, which means there is exactly one solution for m.  Therefore, for k > 1 digits, there are exactly 2 k-digit automorphic numbers, one always ending in 5 and the other always ending in 6.  (However, sometimes the solution for m is 0, in which case a repeated automorphic number is found.)

Secondly, for k > 1 digits, the 2 k-digit automorphic numbers always add up to 10k + 1.  For example, 25 + 76 = 101 = 102 + 1 for k = 2, and 625 + 376 = 1001 = 103 + 1 for k = 3.  This can be proved by first of all showing that 10k + 1 minus a k-digit automorphic number is another k-digit automorphic number.  Let n be a k-digit automorphic number.  Then by definition, n2 ≡ n (mod 10k).  Then (10k + 1 – n)2 (mod 10k) simplifies to:

01
(10k + 1 – n)2 (mod 10k)
(given)
02
(1 – n)2 (mod 10k)
(10k (mod 10k) = 0)
03
1 – 2n + n2 (mod 10k)
(expand)
04
1 – 2n + n (mod 10k)
(n2 ≡ n (mod 10k))
05
1 – n (mod 10k)
(simplify)
06
10k + 1 – n (mod 10k)
(10k (mod 10k) = 0)

Therefore, (10k + 1 – n)2 ≡ 10k + 1 – n (mod 10k), making it another k-digit automorphic number.  Secondly, since 10k + 1 (mod 10k) is not even, the k-digit automorphic number must be different than its original, and since there are exactly 2 k-digit automorphic numbers (as proved above), the 2 k-digit automorphic numbers must add up to 10k + 1.

Using the shortcuts mentioned above, here is a more efficient computer program that finds all automorphic numbers up to a given digit length long:

01
# Automorphic Numbers (Method 2)
02
# Python 2.7.3
03
# To find all automorphic numbers up to d digits long, type "automorphic(d)".
04
#   For example, to find all automorphic numbers up to 10 digits long, type
05
#   "automorphic(10)".
06

07
# find all automorphic numbers up to d digits long
08
def automorphic(d):
09
    # set up variables
10
    total = 3
11
    n_five = 5
12
    n_six = 6
13

14
    # print a title and the first 3 digits
15
    print "Automorphic Numbers up to " + str(d) + " Digits Long:"
16
    print "  1"
17
    print "  5"
18
    print "  6"
19

20
    # find new n_five and n_six automorphic numbers based on the equations
21
    #  (2n – 1)m ≡ (n – n^2)/10^k (mod 10) and n_five + n_six = 10^k + 1
22
    #  for n as a known automorphic number with k digits, and m as the
23
    #  unknown first digit of an automorphic numbers with k + 1 digits.
24
    for k in range(1, d):
25
        m_six = ((n_six - n_six ** 2) / (10 ** k)) % 10
26
        m_five = 9 - m_six
27
        n_six = m_six * 10 ** k + n_six
28
        n_five = m_five * 10 ** k + n_five
29
        # print any new automorphic numbers in order,
30
        #   and add one to the total
31
        if m_six < m_five:
32
            if m_six > 0:
33
                print "  " + str(n_six)
34
                total += 1
35
            if m_five > 0:
36
                print "  " + str(n_five)
37
                total += 1
38
        else:
39
            if m_five > 0:
40
                print "  " + str(n_five)
41
                total += 1
42
            if m_six > 0:
43
                print "  " + str(n_six)
44
                total += 1
45

46
    # print the total
47
    print "Total: " + str(total)

According to this, the automorphic numbers up to 10 digits long are:

>> automorphic(10)
Automorphic Numbers up to 10 Digits Long:
  1
  5
  6
  25
  76
  376
  625
  9376
  90625
  109376
  890625
  2890625
  7109376
  12890625
  87109376
  212890625
  787109376
  1787109376
  8212890625
Total: 19

Method 3 – Automorphic Generator

Another way to find automorphic numbers is to create an automorphic generator using a known automorphic number.  Let n be a known automorphic number of k digits.  Then by definition, n2 – n ≡ 0 (mod 10k) or n(n – 1) ≡ 0 (mod 10k), and squaring this gives n2(n – 1)2 ≡ 0 (mod 102k).  Multiplying by some integer p = p1n + p2 and some integer q = q1n + q2 gives n2(n – 1)2pq ≡ 0 (mod 10k+1).  Then choose p1, p2, q1, and q2 values such that n2(n – 1)2pq = (n2q)2 – n2q (mod 10k+1), then (n2q)2 – n2q ≡ 0 (mod 10k+1) which would make n2q a larger automorphic number by definition.  Given these parameters, some values for p1, p2, q1, and q2 can be found:

01
n2(n – 1)2pq = (n2q)2 – n2q
(mod 10k+1)
(given)
02
n2(n – 1)2pq = n2q(n2q – 1)
(mod 10k+1)
(factor)
03
(n – 1)2p = n2q – 1
(mod 10k+1)
(divide by n2q)
04
(n – 1)2(p1n + p2) = n2(q1n + q2) – 1
(mod 10k+1)
(p = p1n + p2, q = q1n + q2)
05
(n2 – 2n + 1)(p1n + p2) =
q1n3 + q2n2 – 1 (mod 10k+1)
(multiply)
06
p1n3 + (p2–2p1)n2 + (p1–2p2)n + p2 = q1n3 + q2n2 – 1 (mod 10k+1)
(multiply and factor)

One possible solution for this is to set all like terms of n equal to each other, so that p1 = q1 for the n3 terms, p2 – 2p1 = q2 for the n2 terms, p1 – 2p2 = 0 for the n terms, and p2 = -1 for the units.  If p2 = -1 and p1 – 2p2 = 0, then p1 = -2.  If p1 = -2 and p1 = q1, then q1 = -2.  Finally, if p1 = -2 and p2 = -1 and p2 – 2p1 = q2, then q2 = 3.  Therefore, one possible solution is p1 = -2, p2 = -1, q1 = -2, and q2 = 3, which means p = -2n – 1 and q = -2n + 3. 

Therefore, if n is a known automorphic number of k digits, then n2q = -2n3 + 3n2 (mod 10k + 1) is another automorphic number with k + 1 digits.  For example, since 5 is an automorphic number with 1 digit, -2(5)3 + 3(5)2 = -175 ≡ 25 (mod 102) is an automorphic number with 2 digits.

Using the automorphic generator, here is an even more efficient computer program that finds all automorphic numbers up to a given digit length long:

01
# Automorphic Numbers (Method 3)
02
# Python 2.7.3
03
# To find all automorphic numbers up to d digits long, type "automorphic(d)".
04
#   For example, to find all automorphic numbers up to 10 digits long, type
05
#   "automorphic(10)".
06

07
# find all automorphic numbers up to d digits long
08
def automorphic(d):
09
    # set up variables
10
    total = 3
11
    n_five = 5
12
    n_six = 6
13

14
    # print a title and the first 3 digits
15
    print "Automorphic Numbers up to " + str(d) + " Digits Long:"
16
    print "  1"
17
    print "  5"
18
    print "  6"
19

20
    # find new n_five and n_six automorphic numbers based on the equations
21
    #  n' = -2n^3 + 3n^2 (mod 10^(k + 1)) and n_five + n_six = 10^k + 1,
22
    #  for n as a known automorphic number with k digits
23
    for k in range(1, d):
24
        n_five = (-2 * n_five ** 3 + 3 * n_five ** 2) % (10 ** (k + 1))
25
        n_six = 10 ** (k + 1) + 1 - n_five
26
        # print any new automorphic numbers in order,
27
        #   and add one to the total
28
        if n_six < n_five:
29
            if n_six > (10 ** k):
30
                print "  " + str(n_six)
31
                total += 1
32
            if n_five > (10 ** k)::
33
                print "  " + str(n_five)
34
                total += 1
35
        else:
36
            if n_five > (10 ** k):
37
                print "  " + str(n_five)
38
                total += 1
39
            if n_six > (10 ** k):
40
                print "  " + str(n_six)
41
                total += 1
42

43
    # print the total
44
    print "Total: " + str(total)

Its output is the same as the output from Method 2.

This computer program is so efficient that in a relatively short period of time, it can find an automorphic number that is 1000 digits long!  Here it is:

1278125400133690086034889084364023875765936821979626181917833520492704199324875237825867148278905344897440142612317035699548419499444610608146207254036559998271588356035049327795540741961849280952093753026852390937562839148571612367351970609224242398777007574955787271559767413458997537695515862718887941516307569668816352155048898271704378508028434084412644126821848514157729916034497017892335796684991447389566001932545827678000618329854426232827257556110733160697015864984222291255485729879337147866323172405515756102352543994999345608083801190741530060056055744818709692785099775918050075416428527708162011350246806058163276171676765260937528056844214486193960499834472806721906670417240094234466197812426690787535944616698508064636137166384049029219341881909581659524477861846140912878298438431703248173428886572737663146519104988029447960814673760503957196893714671801375619055462996814764263903953007319108169802938509890062166509580863811000557423423230896109004106619977392256259918212890625

Conclusion

An automorphic number has the special property that all of its digits also appear at the end of its square in the same order.  Some interesting properties of automorphic numbers include that there are exactly 2 k-digit automorphic numbers for k > 1 digits, one always ending in 5 and the other always ending in 6, and that these 2 k-digit automorphic numbers always add up to 10k + 1.  Also, if n is a known automorphic number of k digits, then another automorphic number with k + 1 digits can be generated by finding -2n3 + 3n2 (mod 10k + 1).  Finally, although there are several methods for finding an automorphic number, a computer is helpful in each method, especially to find large automorphic numbers.