Here is the first screen of code on my factoring program. I test to make sure the polynomial has roots before beginning to find them. What method is used to test this? Note: Just because the trinomial has roots does not mean that it is factorable where m, n, u, and v are integers.

The "Goto" command skips the rest of the code since it becomes pointless. It goes to a command line with the "Lbl" of 1 (appearing later in the code). "Goto" commands are useful, but try to limit them as much as possible. If overused, programs become very confusing.

I chose P to denote the product of A and C.

Think about what you do when P is postive versus when P is negative. If P is negative, then you know of the factor pair that adds up to be B, one factor must be postive and one factor must be negative. Does the sign of B make a difference when you are typing code?

What about when P is postive? Then the factor pair values must either both be positive, or both be negative. How can you tell from the value of B if both values are positive or both values are negative?

On these next lines of code, I test to see if P is postive. If it is, I store it to D as a negative. D is going to change in our "While" loop; it is incremented by +1 each time the loop is executed. Here is an example with numbers:

Say we have A*C=12 and B=-7. Because it is most convenient to increment our loop by +1, we can test factor pairs beginning with -12 and ending with positive 12.

The test if D+(P/D) = B would be as follows:

Does -12 + (12/12) = -7? NO.

The loop increments D, by 1. This will make D=-11, and P/D would be a yucky fraction. Obviously, the loop will continue since the fraction will not add to be B. All numbers that are not factors of 12 will give not integer values for D + (P/D) and therefore will not equal B. When D increments to -6, the loop tests

Does -6 + (12/-6) = -7? NO.

When D increments to -4 the calculator tests

Does -4 + (12/-4) = -7? YES!

The loop is then ended and the value of -4 is saved for D. It will no longer increment.

What happens when D is incremented to become ZERO? An error message would be displayed. Why? What command is added to prevent this?

An "Else" statement is now added for when P is negative. Instead of changing the P as before, we can store it into D and increment D by 1 as before.

Think: What if postive P were stored as D in the first loop? How can the increment be adjusted to have the program still work? Click here to find out.

Finding the factor pair is the trickiest part of the algorithm. Now that D is stored as one of the correct factors, we must determine the greatest common factor of A and D. The TI-83 has a gcd( command which is tempting to place right after the while loop. In order for it to work, however, both A and D must be postive. Instead of complicating the code, it is easier to write a smaller program to call inside "pgrmFACTOR." Use "IF statements to test whether or not A and D are positive or negative. How many cases will you have to test? To see my pgrmGCF, click here.

"pgrmGCF" returns a value for U. On your program, you may choose to return the variable m. Either way, it will be a coefficient of one of the Xs in your binomials.

Now, using the KEY, the other m, n, and v can be computed as follows.

You may choose to output m,n,u, and v in a way that is a bit more user friendly.

The "Lbl 1" command refers to the "Goto 1" from the beginning of the program.


RETURN to factoring algorithm

RETURN to Intro/Program list