Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* 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

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 Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

Only need the matlab code pls

Answered: 1 week ago

Question

3. Outline the four major approaches to informative speeches

Answered: 1 week ago

Question

4. Employ strategies to make your audience hungry for information

Answered: 1 week ago