Horner's Method Simulation

written by Teresa Carrigan



Top

WHAT IS IT?

This model demonstrates Horner's method of converting from any base to decimal. You may choose any base in the range of two to sixteen.

Top

HOW IT WORKS

First the arrow sets a variable (accumulator) to zero. It passes through the digits from left to right. Each time it finds a digit, it multiplies the accumulator by the base, and then adds the digit it just found. When it runs out of digits, what is in the accumulator is the answer. This gives us the decimal equivalent of an unsigned representation in the given base.

Top

HOW TO USE IT

If you want examples from a specific base: Use the number-of-digits slider to set the number of digits that the counter can hold. Use the base slider to set the base. Now press the setup button. This will generate a random number with that many digits in that base (although it is possible to have leading zeroes).

If you do not care which base is used, click the random button to generate an arbitrary base, number-of-digits, and number.

The slow-motion slider is an easy way to adjust the speed of the display. Set it to zero if you want to show the final result as quickly as possible. 0.7 is a good setting for most purposes.

The step button moves the red arrow one space, and processes a digit if it finds one. It then stops so you can take notes. This is useful when you are first learning the method.

The go button processes every remaining digit, from the left to the right, at a speed determined by the slow-motion slider. This is useful for showing the same problem several times, or when you do not need to take notes between each step.

The show-again button starts the exact problem from the beginning. You may then click either the step button or the go button to see the same demonstration.

The quiz button will generate a random number using the base and number-of-digits sliders, and ask you to convert it to decimal. If you want to drill conversion from binary, set the base to 2 and the number-of-digits to the maximum. If you want to drill conversion from hexadecimal, set the base to 16, and the number-of-digits to a small number unless you have a calculator and a lot of patience.

Top

THINGS TO NOTICE

When the base is 2 (binary), Horner's method is the same as the Double-Dabble method.

When the base is smaller than ten, the decimal equivalent will have at most the same number of digits as the original number, and usually it will have fewer digits. When the base is larger than ten, the decimal equivalent will have at least the same number of digits as the original number, and usually it will have more digits.

Top

THINGS TO TRY

Set slow-motion to 0.7, click random, and then click go.

Set the sliders to a problem type you want to drill, then click setup. Attempt one step at a time on paper, and then click the step button to check that you did that step correctly.

Top

EXTENDING THE MODEL

Modify the model to show fixed point representation; that is, specify a given number of digits to the right of the decimal place.

Allow the user to input a starting digit pattern.

Allow the user to input a decimal number, and then display the corresponding digit pattern.

Top

NETLOGO FEATURES

Extensive use is made of "patch-at", "BREED-at", and "VARIABLE-of".

It was awkward to be required to say "random-one-of" in order to return a single turtle instead of an agent set when there is only one turtle in the agent set.

Top

RELATED MODELS

Top

CREDITS AND REFERENCES

This model was written by Teresa W. Carrigan, 2004.

Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed:

  1. this copyright notice is included.
  2. this model will not be redistributed for profit without permission from Teresa Carrigan.
Contact Teresa Carrigan for appropriate licenses for redistribution for profit.

To refer to this model in academic publications, please use: Carrigan, T. (2004). Horner's Method Simulation model. Blackburn College, Carlinville, IL.

In other publications, please use: Copyright 2004 by Teresa W. Carrigan. All rights reserved.

Top

FOR MORE INFORMATION

For more information about Double Dabble, see:
  1. Null, L. and Lobur, J. Essentials of Computer Organization and Architecture, First Edition, Jones and Bartlett, pages 46-47.

For more information on Horner's Method, see:

  1. http://www.nist.gov/dads/HTML/hornersrule.html


Home

Applets on this website were written by Teresa Carrigan in 2004, for use in computer science courses at Blackburn College, with the exception of the Fireworks applet. The applets made with NetLogo require Java 1.4.1 or higher to run. The applets made with NetBeans require Java 1.4.2 or higher to run. Applets might not run on Windows 95 or Mac OS 8 or 9. You may obtain the latest Java plugin from Sun's Java site.