## The x = sine x pitfall

Approximations and simplifications. They offer us an easy way to understand the world around us. If someone asked you what time it was, would you say it’s 8:23? You’d probably say it’s 8:25 or 8:30. Unless you’re Phileas Fogg.

PI? 3.14159. Free fall acceleration? 10 metres per second squared (corrected to 9.81 near pre-college level). Estimated time of arrival of your friends? Your appointed time, give or take half an hour (usually give).

This is fine, because the error is insignificant for the particular level of use. It’s when you have no idea what the *true accurate* is that’s the problem. For example, you and your friend have decided on a time to meet on a particular day. You can generally estimate when both of you will *actually* meet up.

Suppose you and your friend have decided to meet up on a particular day, but did *not* decide what time to do so. What’s the actual time that you will actually meet each other? You will only know when you’ve waited at the appointed place for an entire day, until your friend shows up. Let’s assume you’re a *really* good friend, and you’re *really* excited to meet your friend… and that your friend is going to come…

The point I want to highlight is about project deadline estimations. Before I talk about that, let me show you a graph.

### Only for small x

In math, there are situations where you can use x in place of sin(x).* Obviously x is not equal to sin(x). But, for small values of x, they are approximately equal.

x ≈ sin(x) for small values of x

Here’s a graph of sin(x) and x. The sine curve is coloured blue, and the line y = x is coloured red.

Here’s the code I used to generate it:

const int cnWidth = 400; const int cnHeight = 400; const int cnXOffset = 20; const int cnYOffset = 20; const int cnAxisLength = 360; const double cnHalfYAxis = 180.0; Bitmap bm = new Bitmap(cnWidth, cnHeight); Graphics g = Graphics.FromImage(bm); Pen p = new Pen(Color.Black); g.FillRectangle(Brushes.White, 0, 0, cnWidth, cnHeight); // the vertical axis g.DrawLine(p, cnXOffset, cnYOffset, cnXOffset, cnYOffset + cnAxisLength); // the horizontal axis g.DrawLine(p, cnXOffset, cnYOffset + cnAxisLength / 2, cnXOffset + cnAxisLength, cnYOffset + cnAxisLength / 2); Brush brWords = Brushes.LightSlateGray; Font ft = new Font(FontFamily.GenericMonospace, 8.0f); g.DrawString("1", ft, brWords, 5, 15); g.DrawString("0", ft, brWords, 5, 190); g.DrawString("-1", ft, brWords, 5, 370); g.DrawString("PI", ft, brWords, 190, 205); g.DrawString("2PI", ft, brWords, 370, 205); int i, j; for (i = 0; i < 360; ++i) { j = cnHeight / 2 - (int)(cnHalfYAxis * Math.Sin((i * Math.PI) / 180.0)); bm.SetPixel(cnXOffset + i, j, Color.SlateBlue); j = cnHeight / 2 - (int)(cnHalfYAxis * (i * Math.PI) / 180.0); if (j > cnYOffset) { bm.SetPixel(cnXOffset + i, j, Color.Crimson); } } bm.Save("sinewave.bmp");

The normal Y axis increases vertically upwards. In bitmap or raster graphics, the usual coordinate system has Y increasing *downwards*. **Exercise**: Determine which parts of the code correct this difference so that the bitmap still shows the Y axis increasing vertically.

As you can see from the graph, the line y = x is identical to the line y = sin(x) for small values of x, when discretisation of the values are considered. It doesn’t mean x = sin(x). It just means for a small part of sin(x), x is almost the same as sin(x).

### Giving the man hours

I was involved in a few projects where there were some unfamiliar situations, problems and techniques after I did requirement analysis. I had an idea how to solve them, but I had no idea how long it might take. I had to come up with prototype code to see if my solution could work. Then I had to come up with the full code to solve the problem.

When asked to give an estimate of the required man hours, I couldn’t say. It could take 3 hours. It could take 3 days. I wouldn’t know till I tried writing the code.

This happens when new requirements are involved. So new, that you have little background knowledge to work with, little past experience to guide you.

Sure, you can break up the project into small parts, and give estimates on the small parts. Then you add up the estimates for the small parts, and you get the final required man hours.

I’m asking you to be careful. **Don’t mistake a straight line for a sine curve**. Don’t fall into the x = sine x pitfall.

* I can’t remember what situations they are, nor even if there’s any use at all. I’m using it as an illustration.