For having to keep your logic straight, nothing beats a quadratic equation. Do you factor it? Use the quadratic formula? Maybe there's two roots? One root? No real roots?

How about some Prolog code that allows you to enter in a quadratic. It'll look at it and advise you on what to do with.

The underlying logic of "what to do" with a quadratic is to think of the quadratic formula. If you have a quadractic equation in "standard form," which is $Ax^2+Bx+C=0$, then the two solutions to this equation will be $$x=\frac{-B\pm\sqrt{B^2-4AC}}{2A}.$$ Now, if you look at the $B^2-4AC$, you can figure out what to do. In particular:

How about some Prolog code that allows you to enter in a quadratic. It'll look at it and advise you on what to do with.

The underlying logic of "what to do" with a quadratic is to think of the quadratic formula. If you have a quadractic equation in "standard form," which is $Ax^2+Bx+C=0$, then the two solutions to this equation will be $$x=\frac{-B\pm\sqrt{B^2-4AC}}{2A}.$$ Now, if you look at the $B^2-4AC$, you can figure out what to do. In particular:

- If it's $<0$, the equation won't have any real roots (because of the square-root).
- If it's $=0$, the equation will have $1$ root, because there won't be anything to add or subtract in the $\pm$ step.
- If it's a perfect square, then you'll be able to factor the equation.
- If it's not a perfect square, then you'll have to use the quadratic formula to solve the equation.

roots(A*X^2+B*X+C,Advice)

Move the mouse over a dotted box for more information.

Type your code here:

See your results here:

Put in some quadratic equations from your last math book. Look in the section that gives a variety of equations, asking you how you'd solve (or factor) each.

What do you think the last 3

What do you think the last 3

`roots(...)`

clauses do? Hint: They help the overall code be more "understanding" of what inputs it'll accept.