Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Prolog Language Assignment: Suppose we represent sets of (unsorted) integers as lists of integers with no duplicated elements. The universe will be the the integers

Prolog Language Assignment:

Suppose we represent sets of (unsorted) integers as lists of integers with no duplicated elements. The universe will be the the integers from 1 to 20. Write Prolog rules for the following set operations (do NOT use any pre-defined predicates):

nodups(A,B): succeeds when A and B have the same items but B has no duplicates.

subset(A,B): succeeds when set A is a subset of set B.

union(A,B,C): succeeds when the union of sets A and B is C.

intersection(A,B,C): succeeds when the intersection of sets A and B is C .

difference(A,B,C): succeeds when the set difference of sets A and B is C.

complement(A,B): succeeds when the complement of the set A is B.

Here are few examples of queries and expected responses for nodups:

?- nodups([1,3,5,3], R).

R=[1,3,5]

?- nodups([1,3,5], R).

R=[1,3,5]

?- nodups([a,b,a,c,b], R).

R=[a,b,c]

?- nodups([a,b,a,c,b,a], R).

R=[a,b,c]

Here are few examples of the other queries and expected responses:

?- subset([1,3,5], [5,1,2,3]).

yes

?- subset([1,3,5], [3,1,5]).

yes

?- union([1,2,3], [2,3,7,9], U).

U=[1,2,3,7,9]

?- intersection([1,2,3], [2,3,7,9], I).

I=[2,3]

?- difference([1,2,3], [2,7,9,3], D).

D=[1]

SUBMISSION:

Submit two (ascii) files. The first file should contain your program which will include your facts and rules. The facts should appear first and should allow robust testing. The second file should contain 4 queries for each predicate (24 queries total). The queries should be different from the ones provided here, and should demonstrate different kinds of questions. This file should be readable, containing the queries on separate lines and explanations of them on separate lines.

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

Handbook Of Relational Database Design

Authors: Candace C. Fleming, Barbara Von Halle

1st Edition

0201114348, 978-0201114348

More Books

Students also viewed these Databases questions

Question

Describe Balor method and give the chemical reaction.

Answered: 1 week ago

Question

How to prepare washing soda from common salt?

Answered: 1 week ago

Question

Explain strong and weak atoms with examples.

Answered: 1 week ago