Linear regression in “The Man who counted”

Recently, I got a book by Brasilian writer  Júlio César de Mello e Souza (published under pen name Malba Tahan), titled The Man who counted. Book is a collection of mathematical stories very similar to Scheherazada’s 1001 Nights, where mathematical story-telling is the center of book.

                                               2017-03-25 19_38_40-the man who counted - Google Search

In story 5“In so many words”, Malba describes a simple algebraic problem of proportion between price for lodging offered and price of jewel sold.

This man,” old Salim said pointing to the jeweler “came from Syria to sell 
precious stones in Baghdad. He promised he would pay 20 dinars for his 
lodgings if he sold all of his jewels for 100 dinars and 35 dinars if he 
sold them for 200. After several days of wandering about, he ended up selling 
all of them for 140 dinars. How much does he owe me according to our agreement?”

Both, jeweler and lodge owner,  calculate the result each using percent proportion problem, both ending with wrong results, that was each to favor each:

  1. Jeweler:
200 : 35 :: 140 : x

x = (35 x 140) / 200 = 24.5

2. Lodge Owner:

100 : 20 :: 140 : x

x = (20 x 140) / 100 = 28


With two different results, both would end up in argument, so the third needed to be calculated:

Sale Price        Price of Lodgings
200               35
-100             -20
-----            -------
100               15


So the difference between both calculations forms a proportion to calculate the new case, when Sale price for jewel is 140, the price of lodging would be 26.

100: 15:: 40: x

x = (15 x 40) / 100 = 6


Mathematically speaking, problem is very interesting to be solved also using Linear Regression, since the two pair of points [200, 35] and [100, 20] form a linear prediction function and we would need to predict what would be the price of lodging, when sale price for jewel is 140.

diamond <- c(100, 200)
sleep   <- c(20, 35)

# regression
sleep_model <- lm(sleep ~ diamond)

plot(x=diamond, y=sleep)
abline(lm(sleep ~ diamond))

2017-03-25 21_07_29-Plot Zoom

Now, we can call this a prediction, what actually Beremiz does by heart.

predict_data <- data.frame(diamond=140)
fit <- predict(sleep_model, predict_data, interval = "predict")

#new value for diamond=140

Result is 26, which is strictly algebraic and R-prediction speaking correct result.

In this case, linear regression does same as proportion calculation, but what strikes me is which calculation – not mathematically speaking – does make more sense? 26 or 24,5 or 28 ? And which method for calculating next price lodge should satisfy both jeweler and lodge owner.

Happy reading!




5 thoughts on “Linear regression in “The Man who counted”

  1. If `x` is the vector of the jeweller’s income (called `dimanond` above) and `y` is the corresponding payment for lodging (called `sleep` above) then `approx(x, y, xout = 140)$y` giving 26, again, would be another way to get the same answer as the `lm` / `predict` code.

    There are also other possible assumptions for interpolation, as well. We might think that the proportion paid rather than the amount paid should be linearly interpolated based on `x`, i.e. `140 * approx(x, y/x, xout = 140)$y` which equals 26.6.


  2. Hi Alexander,

    This is good point given, that we think about the proportions based rather the amounts.

    with R code:
    approx(diamond, sleep, xout = 140)$y

    and with the proportion between sleep and diamond (sleep/diamond):

    140*approx(diamond, sleep/diamond, xout = 140)$y

    the result is 26,6.

    What if the jeweler and lodge owner does not agree on linearity of the price, but have some variations (let’s assume on the day of the week). Or assume that I put the interpolated result (26,6) into the dataset and calculate the slope and intercept again (intercept=5, slope = 0,15). When adding:

    diamond <- c(100, 200, 140)
    sleep 26.6
    diamond <- c(100, 200, 140)
    sleep <- c(20, 35, 26.6)
    glm.1 26
    diamond <- c(100, 200, 140)
    sleep <- c(20, 35, 26)
    glm.2 glm.1$residuals
    1 2 3
    -0.2368421 -0.1578947 0.3947368
    > glm.2$residuals
    1 2 3
    0.000000e+00 7.105427e-15 0.000000e+00

    Second residual from glm.2 is practically 0 (7.105e-15), where any given point from glm.1 have some residuals.


  3. The way I read the stated agreement it only stipulates that he would pay 20. He agrees to pay 35 if he made 200 not that he would pay more than the 20 if he sold more than 100 and less than 200.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s