Write a prolog program which describes a directed graph

Assignment Help Programming Languages
Reference no: EM131306409

Question 1:

Briefly explain these main programming paradigm (Logic, Functional, Object Oriented, Procedural, Imperative and Aspect-oriented), and for each of these paradigms name at least one language that can be used for programming in that paradigm.

Note: The purpose of this question is to motivate you to conduct a short research based on the available resources on the Internet or in our university library. For answering this question you should write one short paragraph for explaining each programming paradigm. For writing those short paragraphs, you can study or use all available online resources on the Internet or all textbooks from your library, etc. Please do not copy and paste paragraphs/sentences; try to write paragraphs based on your understanding. Also, you should mention (cite) all the recourses/references that you have used in order to answer this question.

Question 2:

Which of the following pairs of terms can be unified (matched) together? Where relevant, give the variable instantiations that lead to successful unification. (note = shows unification)

healtyFood(X) = healtyFood(bread) healtyFood(bread,X) = healtyFood(Y,salad) healtyFood(bread,X,milk) = healtyFood(Y,salad,X) healtyFood(X) = Y meal(healtyFood(bread),drink(milk)) = meal(X,Y)
meal(healtyFood(bread),drink(milk)) = meal(X, drink(Water)) meal(healtyFood(bread), Y) = meal(X, drink(water)) breakfast(healtyFood(bread),egg,milk)= breakfast(healtyFood(Y),Y, Z)

Question 3:

The Purpose of this question is to write a Prolog Program which describes a directed graph (G), with the following structure (shown below) and allows us to ask some questions about this graph.

A) write all possible node and edge facts that describes the structure of this graph G such as below:

node( a ). % "a" is a node of this graph.

516_Figure.jpg

edge( a, b ). % There is an edge (directed) from node "a" to "b".

B) complete the definition all these rules.

node(X) :- % X is a node in graph G
edge( X, Y) :- % There is an directed edge from X to Y. parent( X, Y) :- % There is a directed edge from X to Y. child(X, Y) :- % Y is parent of X.
path( X, Y) :- % find a directed path from node X to node Y. length_of_path( X, Y):- % Length of a path (directed) from X to Y. connected( X, Y):- % There is a directed path from X to Y, or from Y to X undirected_edge( X, Y) :- /* There is an edge (ignoring the directions) from X to Y or from Y to X */
undirected_path( X, Y) :- /* find a path (ignoring the directions) from node X to node Y. */

C) Create a knowledge base (KB) based on all the facts and rules you have written in parts (A), and (B), and save it in a prolog program file called "my_grapghG.pl", and show a printout of your file here.

D) Run this Prolog program, and write 4 queries about each of those rules that you have created in part B in order to test those rules, and show your queries and their results, and test the correctness of your results. (Note: you should write and test two ground quires (one with positive and one with negative answer) and two non-ground quires for each of the rules that you have created in Part B.)

E) add the following rule to your program, and test it and describe its function?

tpath(Node1,Node2):-edge(Node1, SomeNode), edge(SomeNode,Node2).

Question 4:

Assume we have the following knowledge base in a Prolog program:

man(jack). man(peter). woman(rebeca). woman(julia). woman(maria). hasWand(rebeca). hasWand(maria). hasWand(jack). quidditchPlayer(jack).
quidditchPlayer(rebeca). quidditchPlayer(maria).

quidditchPlayer(peter). playsAirGuitar(julia). playsAirGuitar(adam). playsAirGuitar(rebeca). playsAirGuitar(mary). playsAirGuitar(jack). wizard (jack).
hasBroom(X) :- quidditchPlayer(X).
warlock(X) :- man(X), hasBroom(X), hasWand(X).
witch(X) :- woman(X), hasBroom(X), hasWand(X).
wizard(X):- warlock(X) ; witch(X). % note: semicolon was used here

A) Determine type of each of the following queries (ground/non- ground), and explain what will Prolog respond for each of these queries (write all the steps of unifications and resolutions for each query)?

 -wizard(jack).
 -witch(jack).
 -warlock(jack).
 -witch(maria).
 -warlock(Y).
 -witch(Y).
 -wizard(X).
 -hasBroom(X).
 -playsAirGuitar(Y), witch(Y).

B) Implement your facts & rules as a Prolog program and test all quires in part B.

Question 5:

Write the following rules for lists in a Prolog program and try corresponding queries for each case.

A) my_length(List, Nr). % find the length of a given list.

?- my_length([a,b,[c,d], e, [f, g]],R).
?- my_length( [ [ ], [ ] ], R).
?- my_length( [ [ [ ] ] ], R).
?- my_length([a,b,[c,d],e],4).

B) my_append(L1,L2,New_list). % append two given lists L1, L2, and return a new list.

?- myappend([a,b],[c],R).
?- myappend( _ ,[e,s],[f,o,x,e,s]).
?- myappend(X,[e,s],[f,o,x,e,s]).
?- myappend(X,Y,[a,b,c]).

C) mymember(X, L). % test if X is a member of list L.

?- mymember( a, [ [ ], a, b, c, f]).
?- mymember( X, [ [ ], a, b, c, f]).
?- mymember( [m k], [ [m k], a, b, c, f]).
?- mymember( X, [ [ ], [ [ ] ] , a, b, c, f]).

Reference no: EM131306409

Questions Cloud

Write your opinion about the given transcript : Write Your Opinion about the given Transcript. I don't I don't really think I've been battered. I mean it's not bad. I just been with this guy for a while and, my boyfriend, and he's fabulous. He's wonderful and we're gonna get married and.
Calculate the value of cash flow option : You have won the lottery and have the choice of the three cash flows each with a 7% rate of interest. You have won the lottery and have the choice of the three cash flows each with a 7% rate of interest.
What do you think is the main point of this video clip : What do you think is the main point of this video clip?- How might you reduce your taxes as a result of watching this video clip?
Demonstrate an understanding of integration of enterprise : Demonstrate an understanding of the integration of enterprise systems with inter-organizational partners. Use technology and information resources to research issues in enterprise architecture.
Write a prolog program which describes a directed graph : COMP348: PRINCIPLES OF PROGRAMMING LANGUAGES - write a Prolog Program which describes a directed graph (G), with the following structure (shown below) and allows us to ask some questions about this graph.
Calculate and compare the risk betas : Calculate and compare the risk (betas) of the following investments: (a) a share of Google stock; (b) a one-year call option on Google; (c) a one-year put option; (d) a portfolio consisting of a share of Google stock and a one-year put option; (e) a ..
Difference between the relevance of dividend policy : What is the difference between the relevance of dividend policy to an investor in their late twenties to an investor in retirement? If a firm sells and restocks its inventory every 64 days, what is its inventory turnover ratio?
How nonverbal cues are regulating the flow of conversation : Based on your observations on how nonverbal cues are regulating flow of conversation, write an analysis including answers to the following questions. You will explore role of nonverbal communication in interactions between genders.
What is the importance of forming a diversified portfolio : What is the importance of forming a diversified portfolio with respect to the risk-­-return trade-­-off, incorporating the measures of risk for both individual securities and portfolios?

Reviews

Write a Review

 

Programming Languages Questions & Answers

  Create math sorting game using visual basic studio

using visual basic studio 2010, Create math sorting game. Random number between 1 and 99 will be generated and displayed to the user.

  How many time is loop body of while statement executed

How many time is the loop body of the while statement executed? a) once, b) never, c) 49 times, d) 50 times, e) until a number 50 or larger is entered

  Modify the inventory program by adding a button to the gui

modify the inventory program by adding a button to the gui that allows the user to move to the first item the previous

  Compare the points by y major order

Compare the Points by y major order, that is, points with similar y-coordinate values should come before those with higher y coordinate values. Break ties by comparing x-coordinate values.

  Example on substitution model

Use the substitution model to illustrate what the result of calling (add1-iter '(1 2 3)) will be.  Why is the list reversed?

  Challenges of incorporating natural command language

From the e-Activity, Amore's and Quesada's article discusses the challenges of incorporating Natural Command Language Dialogs (NCLDs) into a phone system

  Construct a diagram using rationaleto map the arguments

Construct a diagram using Rationaleto map the arguments about a moral claim that you have identified in the article/case study

  Design an application for the homestead furniture store

Design an application for the Homestead Furniture Store that gets sales transaction data, including an account number, customer name, and purchase price.

  Write assignment statement with one arithmetic operator

Write a simple assignment statement with one arithmetic operator in some language you know. For each component of the statement.

  Develop a new predict function

Develop a new predict function so-called "elemnts_are_numbers" that checks all the elements of a list are numbers - Compare these two functions (sum-list 1 and sum-list2), what these function do?

  Develop class templates for administrative employees

Develop classes or class templates for the following: Administrative Employees are paid a salary, but they also receive a bonus at regular intervals during the year. Add a class "Administrator" to the Employee class hierarchy.

  Write gui program as subclass of jframe

Write a GUI program as subclass of JFrame. It should contain the following: Labels At the top (column headings): Meal, Quantity, Cost, At the left: label for each mea.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd