Question: /* Problem 11: See Problem 1b above for the knowledge base used for defining subtract/3 . Define substract(Num1,Num2,Result) to succeed if Result is the result

/* Problem 11: See Problem 1b above for the knowledge base used for defining subtract/3 . Define substract(Num1,Num2,Result) to succeed if Result is the result of Num1 - Num2. Num1, Num2 and Result use four symbols: 0, succ , and the left and right parentheses to represent numbers.

Use the add/3, from problem 1b, definition to define subtract/3. Do not write a recursive definition for subtract/3. */

/* Problem 11 Test: */ % :- subtract(succ(succ(0)), succ(0), succ(0)). % SUCCEED % :- subtract(succ(succ(0)), 0, succ(succ(0))). % SUCCEED % :- subtract(succ(succ(0)), succ(succ(0)), 0). % SUCCEED % :- subtract(succ(succ(0)), 0, 0) -> fail ; true. % FAIL % :- subtract(succ(succ(0)), succ(0), succ(succ(0))) -> fail ; true. % FAIL

/* Problem 12: Write a predicate has_subseq(X,Y) that succeeds if Y is a list that is a subsequence of a list X.

For example... has_subseq([a,b,c,d],[b,d]) should succeed, but has_subseq([a,b,c,d],[b,e]) should fail. */

/* Problem 12 Test: */ %:- has_subseq([a,g,b,d],[g,b]). % SUCCEED %:- has_subseq([1,2,3,4],[2,4]). % SUCCEED %:- has_subseq([1,2,3,4],[2,3]). % SUCCEED %:- has_subseq([1,2,3,4],[]). % SUCCEED

%:- has_subseq([1,2,3,4],[2,5]) -> fail ; true. % FAIL %:- has_subseq([1,2,3,4],[4,3]) -> fail ; true. % FAIL

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!