Question: PLS WRITE IN PROLOG & ATTACH SCREENSHOTS OF TESTS Write a Prolog program deriv(E,D) to do symbolic differentiation of polynomial arithmetic expressions with respect to

PLS WRITE IN PROLOG & ATTACH SCREENSHOTS OF TESTS

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. (MAKE SURE THIS IS THE RESULT, NOT ANYTHING ELSE PLS!)

?- 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.

PLEASE WRITE THIS CODE SUCH THAT IT CAN WORK ON ANY FACTS, NOT JUST THE ONES PROVIDED HERE AS GRADING IS BASED ON DIFFERENT FACTS

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.

Pre-existing code in file:

eval(C, C) :- integer(C).

eval(X+Y, R) :- eval(X, XR), eval(Y, YR), R is XR+YR.

eval(X-Y, R) :- eval(X, XR), eval(Y, YR), R is XR-YR.

eval(X*Y, R) :- eval(X, XR), eval(Y, YR), R is XR*YR.

eval(X/Y, R) :- eval(X, XR), eval(Y, YR), R is XR/YR.

eval(X^Y, R) :- eval(X, XR), eval(Y, YR), R is XR**YR.

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 Databases Questions!