q. Growing pains - variations on an old tale

Defining Functions Iteratively – Variations on a Folk Tale

There is a legend about the game of chess.

When the creator of the game of chess  showed his invention to the ruler of the country, the ruler was so pleased that he gave the inventor the right to name his prize for the invention. The man, who was very wise, asked the king this: that for the first square of the chess board, he would receive one grain of wheat (in some tellings, rice), two for the second one, four on the third one, and so forth, doubling the amount each time. The ruler, arithmetically unaware, quickly accepted the inventor's offer, even getting offended by his perceived notion that the inventor was asking for such a low price, and ordered the treasurer to count and hand over the wheat to the inventor.[1]

The key to understanding this story and the astonishment of the ruler is the rule that was proposed to calculate the number of grains of wheat to be added each day – i.e. start with one grain of wheat on the first day and each day afterward add twice the number of grains of wheat that were added the day before. This rule generates an exponential growth of numbers of grains of wheat.

The rule the inventor chose to determine the change in the number from square to square is an example of a different way of defining a function from that which is ordinarily used in algebra. The function is defined by an iterative procedure – we are told how many to start with and we are given a rule for calculating the change from each square to the next square. 

Defining functions iteratively is at the heart of that branch of applied mathematics that uses calculus to build models of complex phenomena in physics, chemistry, biology and economics, not to mention a wide variety of engineering fields.

The story cited above describes an iterative procedure that leads to an exponential function. But the inventor in that story could have chosen other rules to determine how many grains of wheat to put down on the chessboard. The object of this paper is to examine other rules and in particular rules that lead to the generation of the functions most focused on in early algebra - linear, quadratic and absolute value functions.

Defining Functions Iteratively

Here are illustrations from a spreadsheet that explores these other rules for adding (or subtracting) grains.

The simplest change rule is to start with some number of grains of wheat and add a fixed number of grains of wheat each day. Here is a spreadsheet that shows what happens when one starts with 100 grains and adds two grains each day.

Change  =  constant

days later

# of grains
added or subtracted
that day

total #
of grains

how many grains do I start with?

 

 

100

100

1

2

102

 

2

2

104

each day add or subtract

3

2

106

2

4

2

108

 

5

2

110

 

6

2

112

 

7

2

114

 

8

2

116

 

9

2

118

 

10

2

120

 

11

2

122

 

12

2

124

 

13

2

126

 

14

2

128

 

15

2

130

 

16

2

132

 

17

2

134

 

18

2

136

 

19

2

138

 

20

2

140

 

21

2

142

 

22

2

144

 

23

2

146

 

24

2

148

 

25

2

150

 

26

2

152

 

27

2

154

 

28

2

156

 

29

2

158

 

30

2

160


If the same change is made each day, as in this case, then the total number of grains as a function of time will be a linear function of the number of days. By choosing the starting number you can control the vertical intercept. If you add a constant amount each day the total number of grains as a function of time will be a linear function with positive slope. If you subtract a constant number each day the total number of grains as a function of time will be a linear function with negative slope.

A linear function has the property that if you evaluate a linear function at uniformly spaced points in its domain, the values of the function for adjacent points will differ by a constant value. This is exactly how we calculated the number of grains to add each day in this case.

Suppose we choose a somewhat more complicated rule – suppose that each day we add a number of grains that is proportional to the number of days that have elapsed since the beginning of the procedure. For example, we might start with 100 grains on day 0 and then add 3 grains on day 1, 6 grains on day 2, 9 grains on day 3, etc.

Here is a spreadsheet that shows what happens when we do that.

Change = K x day #

days later

# of grains
added or subtracted
that day

total #
of grains

how many grains do I start with?

 

 

1000

1000

1

3

1003

 

2

6

1009

each day add / subtract K times day #

3

9

1018

3

4

12

1030

 

5

15

1045

 

6

18

1063

 

7

21

1084

 

8

24

1108

 

9

27

1135

 

10

30

1165

 

11

33

1198

 

12

36

1234

 

13

39

1273

 

14

42

1315

 

15

45

1360

 

16

48

1408

 

17

51

1459

 

18

54

1513

 

19

57

1570

 

20

60

1630

 

21

63

1693

 

22

66

1759

 

23

69

1828

 

24

72

1900

 

25

75

1975

 

26

78

2053

 

27

81

2134

 

28

84

2218

 

29

87

2305

 

30

90

2395


The total number of grains as a function of the number of days now looks very much like a quadratic function. Is it really a quadratic function and how can we tell?

A quadratic function has the following property – if you evaluate a quadratic function at uniformly spaced points in its domain, the values of the function for adjacent points will differ by an amount that changes linearly. This is exactly how we calculated the number of grains to add each day in this case.

Finally, let’s consider what kind of rule leads to the third family of functions widely used in early algebra – the absolute value function.

Absolute value functions are made up of two sections each of which is linear but the two linear sections have slopes that can be written as m and – m. We have seen that the change = constant rule leads to a total number of grains function that is linear. Suppose we use amend that rule in this way – let the change from the start to some particular later day be say 5 grains/day and after that particular day  –5 grains/day. Here is a spreadsheet of that rule.

Change =  step

days later

# of grains
added or subtracted
that day

total #
of grains

how many grains do I start with?

 

 

30

30

1

5

35

 

2

5

40

each day add or subtract

3

5

45

5

4

5

50

until day number

5

5

55

10

6

5

60

then

7

5

65

 

8

5

70

add or subtract

9

5

75

-5

10

-5

70

each day afterward

11

-5

65

 

12

-5

60

 

13

-5

55

 

14

-5

50

 

15

-5

45

 

16

-5

40

 

17

-5

35

 

18

-5

30

 

19

-5

25

 

20

-5

20

 

21

-5

15

 

22

-5

10

 

23

-5

5

 

24

-5

0

 

25

-5

-5

 

26

-5

-10

 

27

-5

-15

 

28

-5

-20

 

29

-5

-25

 

30

-5

-30

  
These sorts of rules can be more general than the cases we have looked at in several ways.
  • As we have just seen we can use rules that decrease the number of grains each day. This may lead to a “negative number of grains”. To make sense of this it is useful to stop thinking of these rules as applying only to grains of wheat but to quantities that can take on both positive and negative values.
  • We can imagine that the change might not be a whole number of of discrete objects such as grains – for example, we might subtract 3.6 liters of oil each day in the case of a constant increment  or add [2.4 x day #] liters of oil each day.
  • We can combine change rules – for example we can make a rule that the change is a constant + a multiple of the number of days.
  • We can imagine starting with a negative number of grains or whatever we are accumulating.
  • We can imagine that we start counting days from some number other that 0, - e.g. we might start counting days from  6  or  – 4.

Here is an example of a combined change rule [change = constant + multiple of day #] .

 

change = constant + K  x  day #

days later

# of grains
added or subtracted
that day

total #
of grains

how many grains do I start with?

 

 

-500.00

-500

1

230.00

-270.00

 

2

210.00

-60.00

each day add or subtract K times day #

3

190.00

130.00

-20

4

170.00

300.00

AND

5

150.00

450.00

 

6

130.00

580.00

add or subtract this constant number of grains

7

110.00

690.00

250

8

90.00

780.00

 

9

70.00

850.00

 

10

50.00

900.00

 

11

30.00

930.00

 

12

10.00

940.00

 

13

-10.00

930.00

 

14

-30.00

900.00

 

15

-50.00

850.00

 

16

-70.00

780.00

 

17

-90.00

690.00

 

18

-110.00

580.00

 

19

-130.00

450.00

 

20

-150.00

300.00

 

21

-170.00

130.00

 

22

-190.00

-60.00

 

23

-210.00

-270.00

 

24

-230.00

-500.00

 

25

-250.00

-750.00

 

26

-270.00

-1020.00

 

27

-290.00

-1310.00

 

28

-310.00

-1620.00

 

29

-330.00

-1950.00

 

30

-350.00

-2300.00

 
 

By now it should be clear that the rules we have been examining seem to produce linear, quadratic and absolute value functions for the total number of grains.

This way of defining functions is powerful for several reasons that we have not yet discussed.

  • We can ignore the fact that grains of wheat are discrete, countable objects and think of accumulating something continuous, for example cubic inches of water or grams of gold. This enables us to change the amount in each time period by an amount which is not a whole number.
  • We can use rules that each day add or subtract a number that is proportional to some other power of the day number. For example, suppose we start with some number of grains on day 0, and then each day add or subtract a number that is proportional to the square of the day number – say 12 on day 1, 22 on day 2, 32 on day 3, etc. or  6.7 x 12 on day 1,  6.7 x 22 on day 2, 6.7 x 32 on day 3, etc. In such cases the resulting number of grains as a function of day number will be a cubic function!

The Relation between this Way  & the Traditional way of Defining Functions

Traditionally, two parameters are used to define a linear function. There parameters could be

the slope and intercept with the vertical axis,

the slope and intercept with the horizontal axis or

the two intercepts with the axes.

After the two parameters are specified, values of the function for a given value of the variable can be calculated.

Similarly, three parameters define a quadratic function. Traditionally the quadratic function is written in one of three standard forms:

y = ax2 + bx + c                         (polynomial form)

 

y = a(x – r1)(x – r2)                    (root form)

 

y = a(x – h)2 + k                        (vertex form)

After the three parameters are specified, values of the function for a given value of the variable can be calculated.

The families of absolute value functions used in early algebra are all of the form

F(x) = a|x + b| + c

which also require specifying three parameters.

How does this new way of producing linear, quadratic and absolute value functions correspond to what we have done earlier?

The rule change = constant which produced a linear function for the total number of grains required us to specify two numbers, the number of grains to start with and the number to add or subtract each day. These parameters are quite different in nature from the ones that are used in the traditional definition of the linear function.

The rule change = K  x day #  which produced a quadratic function for the total number of grains required us to specify two numbers, the number of grains to start with, and the multiple of the day number to add or subtract each day. Although only two parameters are needed to generate these quadratic functions, this rule can only produce quadratic functions whose graphs start out flat and either always increase or always decrease. Can you see why this is so?

The rule change = constant + K  x  day #  which produced a quadratic function for the total number of grains required us to specify three numbers, the number of grains to start with, a constant number to add or subtract each day and the multiple of the day number to add or subtract each day. Here too it will be noticed that these parameters are quite different in nature from the ones that are used in the traditional definition of the quadratic function.

The rule change = constant up to a particular day combined with change = - constant after that day which produced an absolute value function for the total number of grains required us to specify three numbers, the number of grains to start with, the number to add or subtract each day in the beginning and the number of the day on which to switch from adding to subtracting (or vice versa).

In order to help answer the question of the correspondence between the traditional way of defining these functions and the way we have done so here let’s introduce a somewhat less awkward notation. Suppose we call the total number of grains n days after we start

Gn  grains

Then the first rule change = constant can be written

Gn+1  grains  = Gn  grains + C grains/day  x 1 day

The second rule change = K x day # can be written

Gn+1  grains  = Gn  grains + K grains/day  x n days

The third rule change = constant + K x day # can be written

Gn+1  grains  = Gn  grains  +  C grains/day  ´ 1 day  +  K grains/day  n days

The fourth rule can be written in two parts:

Gn+1  grains  = Gn  grains + C grains/day  x 1 day, on days before day T

Gn+1  grains  = Gn  grains – C grains/day  x 1 day, on days after day T 

It would be good to write these rules even more generally.

Clearly we can make such rules for accumulating things other than grains of wheat – we can, for example, accumulate grams of a liquid in a container that is filling or meters of distance covered as we go on a trip. Instead of grains, therefore let us use the symbol X for the amount of the quantity we are accumulating.

Secondly, we need not restrict ourselves to an increment a day. We could increment our amts every second, or every minute, or every week, or every year. To indicate this let us call the time between increments t (read delta t). These changes lead to the following notation:

The total amount at time t after we start can be written as

G(X, t)

Each of the rules we have studied can now be written in the form

 G(X, t  + t) = G(X, t)  change

where change stands for the amount added or subtracted each time period t .

In their more general form our rules look like this:

The first rule change = constant can be written

 G(X, t + t) = G(X, t) + C X / t  x t

The second rule change = K x day # can be written

  G(X, t + t) = G(X, t) + K X / t   x  t

The third rule change = constant + K x day # can be written

 G(X, t + t) = G(X, t) +  C X / t   t   +  K X /  t  x  t

The fourth rule can be written in two parts:

 G(X, t + t) = G(X, t)  + C X / t   t ,   for t < T

 G(X, t + t) = G(X, t) C X / t   t ,   for t > T

The units of each term in these rules are the units of X. The units of the C and the K that appear in these rules are the units of X / t.


Does t Matter?

You might well ask why we bother to write the change as  C grains/day  x 1 day in the case of the first rule or K grains/day  x n days in the second and third rules. Here’s why.

Suppose we wanted to try these rules for a year – with a change of say 30 grains/day and 5 times the day number. That would make a very long table in the spreadsheet. Couldn’t we write the rules in the following way;

first rule change = constant as

Gn+1  grains  = Gn  grains + 210 grains/week  x 1 week

second rule change = K x day # as

Gn+1  grains  = Gn  grains + 35 grains/week  x n weeks

third rule change = constant + K x day # as

Gn+1  grains  = Gn  grains  +  210 grains/week  x 1 week  +  35 grains/week  n weeks

In that way we could find out how many grains we had at the end of a year in just 52 steps. Or if we wanted an even shorter table we could make our changes every month – in that case (for a 30 day month). In that case...

the first rule change = constant becomes

Gn+1  grains  = Gn  grains + 900 grains/month  x 1 month

the second rule change = K x day # becomes

Gn+1  grains  = Gn  grains + 150 grains/month  x n months

the third rule change = constant + K x day #  becomes

Gn+1  grains  = Gn  grains  +  900 grains/month  x 1 month  +  150 grains/month  x n months

which would give us a number of grains at the end of the year in just 12 steps.

Aren’t all the following quantities all equivalent to 30 grains/day?

210 grains/week, 900 grains/month, 30/24 grains/hour, 30/(24 x 60) grains/minute, etc

Yes, of course – BUT! the way we are using these quantities in our rules for accumulating grains (or in general amounts of anything) means that the size of the change may depend on when the change is made.

For example, let’s consider the following case: Start from 0 grains and add 5 grains a day for 60 days or add 150 grains a month for 2 months. Using the change = constant rule, both of these cases will result in 300 grains accumulated at the end of 60 days or 2 months. 

On the other hand suppose we consider starting from 0 grains and adding K = 5 grains/day x day # for 60 days or adding K = 150 grains/month x month # for 2 month using the change = K x time period # rule. Using this rule, if we add 5 grains/day for 60 days we get an accumulation of 9,150 grains. Adding 150 grains a month results in accumulation of 450 grains!

Briefly stated our rule for generating linear accumulation functions does not depend on the size of the time increment. Our rules for generating quadratic functions do depend on the size of the time step. These rules will always generate quadratic functions but different time steps will lead to different quadratic functions. As the time steps become shorter and shorter, the quadratic accumulation functions generated by our rules get closer and closer to one another. The calculus provides an explanation for why this is the case.


Appendix


What happens in the original tale?  In the original tale the number of grains added is twice the number added the day before. This change rule is


Gn+1 = 2 x [Gn – Gn-1] with G0 = 1


It is easy to see that Gn = 2n x G0.  On the 64th day the number of accumulated grains would be 18,446,744,073,709,551,615




[1] From Wikipedia. The story continues…However, when the treasurer took more than a week to calculate the amount of wheat, the ruler asked him for a reason for his tardiness. The treasurer then gave him the result of the calculation, and explained that it would be impossible to give the inventor the reward. The ruler then, to get back at the inventor who tried to outsmart him, told the inventor that in order for him to receive his reward, he was to count every single grain that was given to him, in order to make sure that the ruler was not stealing from him. - Wikipedia