Auxiliary helper rules

Assignment Help Other Subject
Reference no: EM13760348

Write Prolog rules as described in the questions below. You may use any Prolog builtin predicates. You may need to write auxiliary "helper" rules in some cases.

Your code may be tested by an automated script, so be sure to do as follows:

• Place all definitions in a single file that can be read without error by a Prolog interpreter.
If you add comment lines, prefix them with a % (prolog comment symbol)

• Submit just this text file electronically as directed on the course Study Desk page.
(Do not submit a word processed or PDF file.)

• Use the rule name and arguments exactly as specified.

• Do NOT submit your test facts. Do not submit (say) a set of parent facts that you used to test your work.

Questions

1. Assume the Prolog knowledge base contains a set of facts:

parent(parent,child) describes biological parent-child relationships. Assume that the Prolog knowledge base describes only families where all siblings share the same two parents. You are required to write rules that describe the cousin relationship. Consider the following definitions.

• First cousins are the children of two siblings. First cousins have grandparents in
common.

• Second cousins are the children of first cousins. Second cousins have great grandparents
in common.

(a)  Write the rule cousin1(Child1,Child2) that is true if Child1 and Child2 are first cousins.

(b) [1 mark] Write the rule cousin2(Child1,Child2) that is true if Child1 and Child2 are second cousins.

(c) [1 mark] Write the general rule cousin(N,Child1,Child2) that is true if Child1 and Child2 are Nth cousins. So

cousin1(Child1,Child2) ≡ cousin(1,Child1,Child2) and
cousin2(Child1,Child2) ≡ cousin(2,Child1,Child2) and so on for third and fourth
and even higher level cousins.
Hint: start by writing a sibling(Child1,Child2) rule.

2.  Write the rule single that removes duplicate entries from a list. single(L1,L2) if every value in L2 is in L1 and every value in L1 is in L2 and there is at most one occurrence of any value in L2. The order of values in L1 is unsorted, and no ordering of values in L2 is required.
?- single([a,a,b,2,1,a,2,3],L).
L = [b, 1, a, 2, 3].

3. Write the tr rule to translate all occurrences of a list element value to another
value.
tr(A,B,L,M) if list M is the same as list L, except that every occurrence of A in L is replaced
by B. For instance:
?- tr(1,2,[1,4,1,5],L).
L = [2, 4, 2, 5].

4. A time, in hours and minutes, is described by the time structure. For example, 9 hours and 33 minutes would be encoded as time(9,33).
Write the rule tgreater that compares two times. tgreater(T1,T2) if time T1 is a bigger value (is later than) time T2. For example:
?- tgreater(time(9,33), time(10,42)).
false.
?- tgreater(time(11,33), time(10,42)).
true.
?- tgreater(time(11,33), time(11,33)).
false.

5. A binary tree is defined by the structure node(left,right), where left and right can be either another node or any Prolog data item.

(a) Write the rule size(Tree,Size) that takes as input a tree and returns the number of leaf items in the tree. For example:
?- size(node(1,2),X).
X = 2.
?- size(node(1,[2,3,4]),X).
X = 2.
?- size(node(node(a,b),[2,3,4]),X).
X = 3.

(b) Write the rule isBalanced(Tree) that determines if the tree is balanced. A binary tree is balanced if, at every node, the difference between the number of leaves appearing in the left and right subtree is at most one. (A tree which contains just one leaf is considered balanced.)
For example:
?- isBalanced(1).
true.
?- isBalanced(node(1,2)).
true.
?- isBalanced(node(1,node(1,node(1,2)))).
false.

(c) Write the rule trav(Tree,List) that performs a left to right tree traversal; List is the list of leaf node values in the tree.
For example:
?- trav(x,L).
L = [x].
?- trav(node(1,node(2,node(a,b))),L).
L = [1, 2, a, b] .

Reference no: EM13760348

Questions Cloud

Job order cost accounting and of process cost accounting : Contrast the primary focus of job order cost accounting and of process cost accounting. What are the similarities between a job order and a processcost system?
Gaap and economic consequences : The following letter was sent to the SEC and the FASB by leaders of the business community. Dear Sirs: The FASB has been struggling with accounting for derivatives and hedging for many years.
What type of cost-output relationship : Statistically significant in explaining variations in the average operating expense ratio - what type of cost-output relationship (e.g., Linear, quadratic or cubic) is sugg ested by these statistical results?
How do you handle your emotions at work : How do you handle your emotions at work? How might emotional intelligence help us keep emotions in balance? What did you learn from this video clip about how to keep emotions in check?
Auxiliary helper rules : Write Prolog rules as described in the questions below. You may use any Prolog builtin predicates. You may need to write auxiliary "helper" rules in some cases.
Rewrite programming to create a gui : Rewrite Programming Exercise to create a GUI. Your probram should let the user eanter the loan amound and loan period in the the number of years from the tests fields and it should sisplay the monthly and total payments for each interest rate start..
Identify issues that your organization should address : When you evaluate your organization's outputs at the organizational, group, and individual levels, do you see anything that might identify issues that your organization should address?
Method of reporting cash flows from operating activities : On the basis of the following data for Teller Co. for 2006 and the preceding year ended December 31, 2005, prepare a statement of cash flows in excel. Use the indirect method of reporting cash flows from operating activities.
Medical sociolog : Health plays a major role in the functioning of society.

Reviews

Write a Review

Other Subject Questions & Answers

  Cross-cultural opportunities and conflicts in canada

Short Paper on Cross-cultural Opportunities and Conflicts in Canada.

  Sociology theory questions

Sociology are very fundamental in nature. Role strain and role constraint speak about the duties and responsibilities of the roles of people in society or in a group. A short theory about Darwin and Moths is also answered.

  A book review on unfaithful angels

This review will help the reader understand the social work profession through different concepts giving the glimpse of why the social work profession might have drifted away from its original purpose of serving the poor.

  Disorder paper: schizophrenia

Schizophrenia does not really have just one single cause. It is a possibility that this disorder could be inherited but not all doctors are sure.

  Individual assignment: two models handout and rubric

Individual Assignment : Two Models Handout and Rubric,    This paper will allow you to understand and evaluate two vastly different organizational models and to effectively communicate their differences.

  Developing strategic intent for toyota

The following report includes the description about the organization, its strategies, industry analysis in which it operates and its position in the industry.

  Gasoline powered passenger vehicles

In this study, we examine how gasoline price volatility and income of the consumers impacts consumer's demand for gasoline.

  An aspect of poverty in canada

Economics thesis undergrad 4th year paper to write. it should be about 22 pages in length, literature review, economic analysis and then data or cost benefit analysis.

  Ngn customer satisfaction qos indicator for 3g services

The paper aims to highlight the global trends in countries and regions where 3G has already been introduced and propose an implementation plan to the telecom operators of developing countries.

  Prepare a power point presentation

Prepare the power point presentation for the case: Santa Fe Independent School District

  Information literacy is important in this environment

Information literacy is critically important in this contemporary environment

  Associative property of multiplication

Write a definition for associative property of multiplication.

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