Question
CS 4303 Programming Language Concepts Lab Chapter 12 Logic Programming The purpose of this lab is to learn basic Prolog programming. Activity 1. Install Prolog
CS 4303 Programming Language Concepts Lab
Chapter 12 Logic Programming
The purpose of this lab is to learn basic Prolog programming.
Activity 1. Install Prolog software SWI Prolog: Go to http://www.swi-prolog.org/, click download link on the left pane, choose stable release for MS Windows, on the list of the versions, choose the one for the computer you are using, install the software.
Activity 2. Get acquainted with SWI Prologs file editing and activation features. Learn how to edit and save Prolog program (follow File -> Edit path) and how to load the software into the runtime system (use File -> Consult).
Activity 3. Write the following statements as Prolog clauses, in the order given: If it is raining or snowing, then there is precipitation. If it is freezing and there is precipitation, then it is snowing. If it is not freezing and there is precipitation, then it is raining. It is snowing. What answer does Prolog give to the following queries: Is it freezing? Is it raining? Can you rearrange the clauses so that Prolog can give better answers?
Activity 4. Write the following statement as Prolog clauses: Mammals have four legs and no arms, or two arms and two legs. A horse is a mammal. A horse has no arms. Can Prolog derive that a horse has four legs?
Activity 5. Write Prolog clauses to express the following relationship, given the parent relationship: grandparent, sibling, cousin. Enter the following family relationship as Prolog clauses.
Use queries to find out: Who is Anas grandparent? Who is Jills sibling? Who is Sarahs cousin? If multiple answers exist, make sure to get all of them.
Bill
Jill Sarah
Sam Ana Jan Smith
Activity 6. Write a Prolog definition of the greatest common divisor of two numbers. Then use it to compute gcd(4, 10), gcd(15, 36), and gcd(25, 55). Activity 7. Write a Prolog program to find the last item in a list.
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