## What Does This Mean?

Once you get to grade 10, you will start to learn about quadratic equations (degree of 2). More importantly, you will learn about finding the roots / zeroes / x-intercepts / solutions of the equation. To find the solutions, you can use several methods, but you are first taught about the product and sum method. Now, our goal is to use the logic in the product-sum method to create a function that will do the same for us. More importantly, before we go ahead and code this function, let’s see exactly how this methodology is used to factor equations:

Although finding the 2 values for product and sum will help us when we have to factor something like 2x^2 + 9x + 4, to factor it you will have to use something like decomposition:

## How Can We Program This?

Regardless, let’s see how we can create a program to factor equations that resemble the first example (where x^2 has a coefficient of 1). Well, let’s break it down into smaller steps:

We know that we need two numbers that multiply to a given product and have a given sum. Thus, we can use a for loop, along with an if statement to see if the product and sum requirements are fulfilled. Now, our for loop range should have all of the values from -1*product to product +1. However, if the equation has a negative product (like x^2 + 8x – 9), then the -1*product will actually be positive and our range will be incorrect. Thus, we will need to check if the product is positive or not. Meaning, we can assign a new variable as the product and then change it if the product turns out to be negative. Next, once our if statement gets activated or called upon, we can simply return the result. Now, let’s see where this gets us:

Finally, let’s test out this function with a couple of types of problems:

**x^2 + 8x + 15 (Basic example)****x^2 – 16 (Difference of squares)****x^2 + 6x + 9 (Perfect square trinomial)****Using the function to help factor 3x^2 + 19x + 30 (Decomposition required)**

1. x^2 + 8x + 15: (Product = 15, Sum = 8)

2. x^2 – 16: (Product = -16, Sum = 0)

3. x^2 + 6x + 9: (Product = 9, Sum = 6)

4. 3x^2 + 19x + 30: (Product = 90, Sum = 19)

Lastly, if you enjoyed this post, then please both share with your friends and leave a nice rating!