Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE WRITE SIMPLE PROLOG PROGS. Write a Prolog relation eval(E,V) that evaluates integer arithmetic expressions consisting of integer constants and operators +,-,*,/,^ to a constant

PLEASE WRITE SIMPLE PROLOG PROGS.

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:

?- simplify(5-x*(3/3)+2, Y).

Y = 5-x+2

?- simplify(1*x-0/3+2, Y).

Y = x+2

Write a Prolog program deriv(E,D) to do symbolic differentiation of polynomial arithmetic expressions with respect to x. The first argument E is a polynomial arithmetic expression, and the second argument is the fully simplified expression, which must be expressed in canonical form.

You may use the cut symbol, !, e.g., after the Prolog interpreter finds an answer, to prevent the interpreter from returning the same answer again.

Tip: Beware of unary operators! -10 is different from -(10) or -x, and they have different expression trees.

Simplify as much as possible

Some test cases:

?- deriv(x^2, Y).

Y = 2*x.

?- deriv((x*2*x)/x, Y).

Y = 2.

?- deriv(x^4+2*x^3-x^2+5*x-1/x, Y).

Y = 4*x^3+6*x^2-2*x+5+1/x^2.

?- deriv(4*x^3+6*x^2-2*x+5+1/x^2, Y).

Y = 12*x^2+12*x-2-2/x^3.

?- deriv(12*x^2+12*x-2-2/x^3, Y).

Y = 24*x+12+6/x^4.

Write a Prolog relation party_seating(L) that seats party guests around a round table according to the following constraints, when given a list of facts about the guests (provided by the autograder), considering the following scenario: Prof. Klefstad is hosting a party for an international organization. The guests speak different languages, and some guests speak more than one language. He invited 9 guests for a round table discussion, so including himself will need 10 seats at the table. Because the table is round, the first person in the list will be seated next to the last person in the list. There will always be exactly 10 guests and 10 seats. To encourage variety of conversation, he sets the following seating constraints:

Adjacent guests must speak the same language.

No two females sit next to each other.

You can use the following information about the guests and the host for testing your solution to the problem, but DO NOT include these sample facts below (i-v) in the final code you submit. The autograder will provide a set of factsguests and the languages they speak, in the form of male(name). female(name) and speaks(name, language). If you include the facts below in your final submission, it is likely you will not get the correct answer on Gradescope:

Klefstad, Bill, Emily, Heidi, and Isaac speak English.

Beth, Mark, Susan, and Isaac can speak French.

Klefstad, Bill, Susan, Fred, and Jane speak Spanish.

Klefstad, Bill, Mark, Isaac, and Fred identify as Male.

Emily, Heidi, Beth, Susan, and Jane identify as Female.

party_seating(L) identifies a round-table seating arrangement to satisfy the constraints described above. e.g.

?- party_seating(L).

L = [jane, klefstad, susan, bill, emily, isaac, heidi, fred, beth, mark].

This is a made-up sample answer, not a correct answer, but shows the format in which your program should show correct seating. Remember, jane and mark are in adjacent seats at the round table.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

More Books

Students also viewed these Databases questions

Question

Write short notes on Marketing mix.

Answered: 1 week ago

Question

Analyse the process of new product of development.

Answered: 1 week ago

Question

Define Trade Mark.

Answered: 1 week ago