Combining Variables

Now that we have determined our variable set, our next task is to determine how those variables will combine to produce the final results. The simplest ways to combine two variables is to either add them or multiply them (subtraction and division are just the backwards forms of addition and multiplication.)

There’s a simple way to determine whether to add or multiply two variables: use the boolean shortening, with OR corresponding to addition and AND corresponding to multiplication. (If you carry out these operations at the single-bit level, you can see that they are in fact identical.)

Here’s an example of how you do it. Suppose that teenager Tom has been working under his car and he bumped the jack, causing the car to fall onto him. He cries out for help and his mom enters the garage and sees his predicament. She attempts to lift the car for Tom. Will she succeed? Well, it depends on how motivated she is to save her son and how strong she is. At the boolean level, we could say either:

Success = Motivation OR Strength

or 

Success = Motivation AND Strength

In the first case, mom will succeed if she is highly motivated and a weaking or unmotivated but strong. That’s obviously silly; a weakling couldn’t lift the car no matter how motivated she is. In the second case, she must be both motivated and strong. The multi-bit expression of these expressions is:

Success = Motivation + Strength

or 

Success = Motivation * Strength

Our analysis suggests that it will be better to use the lower expression. We multiply the two numbers together.

Another way to analyze the situation is to ask two questions:

“Can one value substitute for the other? That is, does a high value of one compensate for a low value of the other?”

“If one of the two values is zero, is the net result zero?”

This second question is especially helpful. If mom has zero motivation (she has disowned the brat) or zero strength (her arms fell off yesterday), then she cannot possibly lift the car.

Weighting the Factors
But perhaps we feel that one of the two factors is more important than the other. We don’t want to just add them or multiply them together; we want to bias the calculation in such a manner as to put more weight on one of the two factors. Yes, we can do that, but we use different methods for addition and multiplication.

Suppose, for example, that we are romantics and we believe that motivation is more important than strength. If we were adding the two values together, then we’d simply multiply the motivation by a weighting factor, like so:

Success = WeightingFactor * Motivation + Strength

WeightingFactor must be greater than 1.0. If you want more weighting, you make WeightingFactor bigger. Simple.

It’s trickier if you wish to weight the multiplication. You must use exponentiation:

Success = Motivation**WeightingFactor * Strength

Here you must make WeightingFactor greater than 1.0. However, this can get tricky. If Motivation is less than one, then there are several headache problems that I won’t explain here. Just make sure that Motivation is always greater than 1.0 and you’ll be fine. If in doubt, you can always add another factor to Motivation or multiply it to force it to be greater than 1.0.

Getting Snazzy
There are a million other ways to put two variables together, few of which are of any interest from the point of view of a designer. There is one overriding consideration: if the relationship is already specified by some fundamental law, you’d best obey the law. For example, in the rocket example from the previous page, the acceleration of the rocket must obey Newton’s Law F = ma (unless you are creating your own universe with its own laws of physics).