Reference no: EM132241777
Assignment -
Overview - In this assignment, you implement a restricted form of the classic problem of simplifying arithmetic expressions. You first implement two simplification operations, then a general algorithm to transform such expressions into a normal form.
The main restriction is that we only deal with the operations +, -, and *, and that the arguments are only integers and a single variable symbol x. Therefore, all expressions eventually simplify to apolynomial in x, with integer coefficients.
TYPES OF EXPRESSIONS IN THIS ASSIGNMENT
We have two main types of expressions in this assignment: Assignment 2 expressions or A2Expr are built as explained above, and polynomials in x or PExpr are represented in a specific short form.
1. Write a Lisp function: (remove-identities E)
2. Write a Lisp function: (simplify-zeroes E)
3.1 - Write a Lisp function: (simplify E)
BONUS QUESTION - Does the order of calls to remove-identities and simplify-zeroes in simplify matter? Could we get a different final result in simplify if we called these two functions in a different order?
- If your answer is yes, give an example with two different call sequences with different results.
- If your answer is no, give a good logical argument for why.
4. Write a Lisp function: (normalize P)
5. Write a Lisp function: (polynomial E)
5.1 Write two Lisp functions: (poly-add P1 P2) (poly-subtract P1 P2)
For these two functions, the inputs P1 and P2 are PExpr in normal form. The output should be the sum (for poly-add) or difference (for poly-subtract) of the two PExpr, also in normal form. See poly-add, poly-subtract examples in public tests.
5.2 Write a Lisp function: (poly-multiply P1 P2)
Again, the inputs P1 and P2 as well as the output are PExpr in normal form. See poly-multiply examples in public tests.
5.3 Implement polynomial, using the three helper functions.
Hint: use recursion, with the base cases:
1. integer n - represent by (n . 0)
2. atom x - represent by (1 . 1)
See polynomial examples in public tests.
6. Printing a PExpr in normal form.
Write a Lisp function: (print-pexpr P)
Instructions - Need to be done with LISP languages.
Attachment:- Assignment File.rar