November 17, 1995
Due in quiz sections November 30, 1995
In Assignment 3 you wrote a Lisp function print-polynomial
that accepted a Lisp s-expression representing a polynomial in a single
variable as input, and printed it out in normal form. For this assignment,
write a similar program in Prolog.
Since Prolog terms representing algebraic expressions print out just fine, you don't need to write the printing part -- just produce a legal Prolog term representing the symbolic polynomial in polynomial normal form.
Specifically, write a rule
Expr should be a ground term
representing a legal symbolic expression built up from a single symbol,
numbers, and the functors +, -, *,
and ^ (exponentiation). As before, the power in an
exponentiation is restricted to be a non-negative integer.
Symbol should be an atom representing the single variable in
Expr. Normalized should be a variable when you
call the rule; if the goal succeeds, Normalized should be
unified with a term representing the polynomial in normal form. If the
input is bad, the rule should fail.
Examples:
To help you get started, the file ~borning/341/polynomial.pl on mscc.ms contains the sample goals to run, and much of the program. The main rule is:
expr_to_terms; the others are in
the file. Also there are a set of goals pre-defined to run the required
tests. (You can modify the existing code in any way you wish, or start
from scratch. You may also want to look back at your solution to the Lisp
project or to Andy's solution.)