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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started