Question: Write a Prolog relation eval ( E , V ) that evaluates integer arithmetic expressions consisting of integer constants and operators + , - ,

Write a Prolog relation eval(E,V) that evaluates integer arithmetic expressions consisting of integer constants and operators +,-,*,/,^ to a constant value. The first argument E is an arbitrary arithmetic expression, and the second argument V is the single integer value resulting from evaluating the entire expression E. Some tests to get started:
?- eval(5-6*18/3+2, Y).
Y =-29
?- eval(10*20-9/3+20, Y).
Y =217
?- eval(10^3*9-1, Y).
Y =8999
Write a Prolog relation simplify(E,S) that simplifies polynomial arithmetic expressions involving constants, variables (which are Prolog atoms that start with a lowercase letter), and operators +,-,*,/,^. The first argument E is a polynomial arithmetic expression, and the second argument is the simplified expression, which must be expressed in canonical form (for example, 2*x^2+4x-3). Handle multiplying, dividing by 0 or 1, adding or subtracting 0, x/x=1, x-x=0, x^0, x^1.
Some tests to get started:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!