Exploring Binary Fractions: Terminating Binaries

Why should you care about terminating binaries? Because, IDK, computers? Computers use binary? Or something like that.

But that’s beside the point. (No pun intended.)

Now let’s say I’m a computer. In computer science class a while back, I learned that there is a “floating point” representation that uses binary to represent decimals. Some decimals can be represented accurately in binary, which is nice. But some can’t.

How does the “float” type work? Let’s take a look at the IEEE 754-2008 documentation for a floating point number (available at www.math.fsu.edu/~gallivan/courses/…/IEEE-fpstandard-2008.pdf.gz):

IEEE_754_2008

So how does a 32-bit number work? Here are some definitions:

  • Segment “S” is known as the “sign.” It’s exactly what you think it is. One for negative, zero for positive.
  • Segment “E” is known as the “exponent.” This is an 8-bit unsigned expression for 32-bit numbers, and represents the power of two to multiply the following number by. (For the super-nerdy: a bias of 127, or 01111111, is added to the exponent so that negative exponents can be expressed as well).
  • Segment “T” is known as the “mantissa.” The mantissa is normalized – that is, in truncated scientific notation. Example: Take the binary number 10.001101. This is expressed as 1.0001101 \cdot 10^1. Then, this is truncated to 0001101 to form the mantissa.

So here’s an example: how do you express the number 12.375_{10} in binary, floating-point style?

  1. Find out how to express 12.375 in base 2. It’s relatively easy in this case: 8 + 4 + 0.25 + 0.125, or 2^3 + 2^2 + 2^{-2} + 2 ^ {-3} = 1100.011_2
  2. Convert this to base-2 scientific notation: 1100.011_2 = 1.100011 \cdot 10 ^ {11}
  3. Truncate that.
  4. Now you have all your information! Sign 0, exponent 11, and mantissa 100011.

Play around with http://www.easysurf.cc/fracton2.htm in your free time. If you notice repeating decimals, you know where to look: Part 4!

<< Part 2: How Binaries Work

Part 4: Yum, Repeating Binaries >>

Exploring Binary Fractions: What are Binaries?

Now that you’re a master at nonnegative integers in binary, let’s extend the amount we can express. What if we wanted to find a way to write any nonnegative rational number?!

I’m too lazy to scare you with fancy notation, so I’ll explain it in words instead ^_^

You know how, for integers, you go from left to right and multiply by increasing powers of whatever base you’re in? Now go to the right of the binary point, and multiply by increasing negative powers of what base you’re in. Nothing illustrates like an example:

Convert 101.101_2 to decimal.

Solution: 101.101_2 = 2^2 + 2^0 + 2^{-1} + 2^{-3} = 5.75

Please reply in the comments what I can do to improve this post! More examples? Better explanations? I want to do whatever is possible to be a better communicator.

Click onwards to Part 3, to learn more about binaries – specifically, terminating binaries.

<< Part 1: lol, what are binary numbers? xD

Part 3: Terminating Binaries >>

Exploring Binary Fractions: Intro to Binary

If you’re familiar with the binary system already, go ahead and skip this post. But if you’re not, this post is a great way to understand the interesting problem at hand. You won’t regret reading it.

How the Binary System Works (Don’t worry, you can skip this if you know this already)

In Decimal, we have a convenient system for expressing numbers. The numbers 0-9 express what they want to. When we have a two-digit number, the first digit (1-9) multiplied by 10, added to the second digit (0-9) expresses the value we want to communicate. In general, we can say (in base 10) digit i of number x = a_n a_{n-1} \ldots a_2 a_1 represents the value 10^{i-1}; the total value of the number is x = \sum\limits_{i = 1}^{n} {a_i \cdot 10^{i-1}}. Generalizing, we can make the following relationship between notation and value in any normal base:

given \ \{ a \in \mathbb{N}^0| a < b\},\ x_b = (a_n a_{n-1} \ldots a_2 a_1)_b = \sum\limits_{i = 1}^{n} {a_i \cdot b^{i-1}}

The set of all numbers that can be written this way has a one-to-one correspondence with the set of all numbers in \mathbb{N}^0 of any base b \in \mathbb{Z}^{+} (don’t even let me get into non-integer bases xD).

An Example

Convert 123_4 to decimal.

Solution: 123_4 = 1 \cdot 4^2 + 2 \cdot 4^1 + 3 \cdot 4^0 = (16 + 8 + 3)_{10} = 27_{10}

Convert 10_{10} to binary.

Solution: We know that 10 is equal to 8, or 2^3, plus 2. So it’s 1010_2.

This was probably really alienating if you haven’t seen binary numbers before. Here are some links for understanding binary better:

http://www.codeconquest.com/code-tutorials/binary-tutorial/

http://www.mathsisfun.com/binary-number-system.html

Onward to Part 2, to find out how binaries work!

<< What are Binary Rational Numbers?

Part 2: How Binaries Work >>

Exploring Binary Fractions: What are Those?!?!

In the decimal system, we have numbers that can be expressed as integers – without decimal points. But we also have some numbers that require a decimal point when written out; we call these numbers “decimals.” As in, “hey you, can you write out \frac{1}{2} as a decimal?” “Why of course, it’s 0.5!”

Now, what if I said that non-integer rational numbers exist in binary as well? Now, let’s have some terminology that’s more accurate and makes things easier for us:

Binaries – Like “decimals,” they’re numbers that cannot be written out without the “dot.”

Binary Points – Like “decimal points” – the dot.

In this thread, we’re going to talk about all sorts of fun stuff. So follow to Part 1 on the Binary System!

<< What are Binary Rational Numbers?

Part 1: Intro to Binary 101 >>

Hair Length: Conclusions (and Math!)

This is the final part of the series on hair length.

Remember the super-large-scale graph that gave a smooth curve? Let’s take a look again:

Experiment1_pyplot

Isn’t that just beautiful? What amazes me is how consistently the graph forms a recognizable exponential curve. This suggests that the average growth of hair follows an exponential model. This gives rise to several conclusions:

  1. Hair, on average, grows faster when cut. That’s why people say that “shaving makes your hair grow faster.”
  2. This effect can be achieved through a simple model of growth that makes two basic assumptions: individual hairs grow at the same rate as their neighbors, and hairs fall out at a predictable rate.
  3. Because of this, different hairs can be at different lengths while keeping the average length converge to an “equilibrium.”
  4. The two main (and constant) factors in determining the length at which hair “knows to stop growing” are the falling-out frequency and the growth rate.
  5. Lists of five are important for creating convincing arguments.

Now, here’s the big question you’ve all been waiting for:

How can we tell what the “maximum” length is, just from our two constant factors: falling-out frequency and growth rate?

This is where math enters the equation! First, let’s make some definitions: we will let p be the probability of hairs falling out (in hairs per unit of time), r be the growth rate in length per unit of time, n be the number of hairs, and \bar x be the average length of all hairs.

So first we’ll start out with a differential equation; we know that the rate of change in hair length is equal to the rate of growth minus the rate of “loss” in the form of dropped hairs:

\frac{d \bar x} {dt}=r-loss

But what is the expression for “loss”? Using probability, p \cdot \bar n is the expected number of hairs to be dropped completely. Multiplying this by length, the expected total length lost after a unit of time is p \cdot n \cdot \bar x. The average length dropped, then, is this divided by n: \frac{p \cdot n \cdot \bar x}{n} = p \cdot x. Thus, our differential equation becomes:

\frac{d \bar x} {dt} = r - p \cdot \bar x

Now, let’s get serious and solve this!

\begin{array}{rcl}  \frac{d \bar x}{r-p\cdot x} &=& dt\\\\ -\frac{1}{p}\ln{|r - p \cdot \bar x|} & = & t + C \\\\ ln{|r - p \cdot \bar x|} & = & -p \cdot (t + C) \\\\ r - p \cdot \bar x &=& e^{-p \cdot (t + C)} \\\\ \bar x &=& \frac {r- e ^ {-p \cdot (t + C)}}{p}  \end{array}

Now, let’s assume that C = 0; in that case, we have the following:

CodeCogsEqn

You know what this means?! This means that the maximum average hair length approaches to the rate of hair growth divided by the rate of hair loss! Wow!

Notice this with the super-large-scale graph: with hairs growing at 1 unit/iteration, and hairs falling with a chance of 0.01/iteration, we use 1/0.01 = 100 to determine the final maximum length!

Using Real Data:

According to Yahoo Answers, head hair grows at 150 mm/year, and each hair lasts 2 to 6 years. Thus, it’s safe to say that, per year, the probability of a hair falling out is 1/6 to 1/2. Using our formula, the upper limit for head hair is 300 to 900 mm, or about 1 to 3 feet. Seems reasonable!

That’s all, folks! Hope you had just as much fun reading this as I had writing this!

<< Part 3: Large-Scale Modeling

Part 4: Conclusions

Hair Length: Large-Scale Models

This is the third part of the series on hair length.

You’ve hopefully read Part 2 and seen the 10-day/5-hair graph, so I’ll just dive right into this!

Here’s a 20-day/5-hair graph:

small_population_20days

And a 30-day/5-hair graph:

small_population_30days

And a 100-day/10-hair graph:

smallish_population_10hair

Notice: for each graph, there’s a beginning region of positive change in average hair length, followed by a region that oscillates around a fixed value. This value represents the point at which hair seems to “know” when to stop growing.

Still not convinced? Take a look at this super-large-scale graph, done with five trials:

Experiment1_pyplot

For some conclusions, move on to the next section!

Hair Length: An Example

This is the second part of the series on hair length.

Suppose I had a patch of five hairs, or grass, or something similar. The graph below (made with Matplotlib and pyplot) summarizes what would happen to the hairs over time if none were cut off:

small_population

Notice how the individual hairs grow at an average rate of 1mm/day, and so does the average hair length. But what if we let some fall? The graph below gives a typical example:

small_population_drops

Click onward to see more conclusions for this model… applied at even LARGER scales!

Hair Length: The Model

This is the first part of the series on hair length.

So we’re assuming that all hair grows at the same rate, and that the body does not know how long hair is.

Then how does hair “know” when to stop growing? How come hair grows fast when you shave it, but slowly reaches maximum length when you trim only a fraction of it? How can hair reach a stable average length even if some hairs are shorter and longer than others? And how come there’s the occasional hair that’s significantly longer than the rest?

The explanation is that hair falls out at a predictable rate. What we see when we try to determine our hair length is our average hair length; although the average hair length may increase at different rates over time, each individual hair grows at the same rate as its neighbor. When hair falls out, the average length decreases.

For an demonstration of the model, proceed to Part 2: An Example!

Hair Length: An Investigation

What if you learned one day that everything you thought you knew about hair growth was wrong?

Why does hair stop growing after a certain point? It’s a legitimate question, and there are many explanations that may or may not be wrong to varying degrees. But  there are two commonly heard justifications for why hair “knows” when to stop growing:

  1. Hair cannot grow after a certain length. According to this theory, hair needs nutrients to grow. The body produces these nutrients and sends them up the length of the hair, causing the hair to grow longer. However, when hair grows too long, the nutrients would not reach the top, and the hair stops growing.
  2. The body is able to detect how long hair is, and changes the rate of growth based on hair length. There are various mechanisms for this; for example, there may be specialized cells that measure the force a hair exerts as it hangs off the skin. Other proposed mechanisms involve cells that measure the frequency of dust collisions (more hair = fewer collisions = less growth) or follicles that use some form of physics calculation to tell how long the attached hair is.

These two explanations are very reasonable, and they may even be true. But they seem too involved, and there’s probably a better explanation out there. A preferable, less involved explanation has the following premises:

  • All hair grows at the same rate – Under this assumption, you don’t have to deal with complex hair-growth mechanisms that, in reality, would be too hard to implement.
  • The body has no way of knowing how long hair is – It seems pretty difficult for the body to find a mechanism to “know” how long hair is. It is possible, but very hard to implement.

Given these assumptions, how can a simpler model be made? Follow to the next post to find out!

Hair Length: An Investigation

Part 1: The Model >>

An Introduction

Math is cool. Yay. Give yourself a chance to see math applied to, like, anything and everything. And then you’ll know why this blog exists.

Math is a tool to understand nature. But no one said it can’t be fun!