Question

In: Computer Science

Extend the program by adding rules for the following family relationships (add more facts as you...

Extend the program by adding rules for the following family relationships (add more facts as you need ).
Rules
father(X.Y) >
Father (z,w)
where X is Y's father
father(X,Y):>male(X),Parent(X, Y).
brother(X, Y):
where X is Y's brother brother(X,Y):-male().praent(X,Y).
Brother (y.w)
sister(X,Y):-famale(X),praent(X, Y).
sister(X,
Y):
where X is Y's sister
Sister(w.y)
son(X, Y)>
son(X,Y):-male(X), praent(Y,X).
where X is Y's son
Son(y.z)
daughter(X, Y) :- Daughter (w,x)
where X is Y's daughter daughter(X,Y):-famale(X), praent(Y.X).
where X and Y are sibling Sibling(X, Y):-praent(X,Y), praent(X, Y).
Sibling(X.Y): Sibling(w.y)
hint) Solved example:
female(mary).
Facts
male(joe).
parent(mary, joe).
mother(MX)- female(M). parenx(M, X)
Rule
Question →
?-mother (mary. joe).
Answer
True.
(hint) draw a family tree if you need.

Solutions

Expert Solution

Most of the input from the terminal to the prompt "?-" are queries.

Question →

?-mother (mary. joe).

This query may be read "Is mary mother of Joe?" Queries end with a period.

Rules

?- [user].

child(X,Y) :- parent(Y,X).

% X is a child of Y if Y is a parent of X. %

mother(X,Y) :- parent(X,Y), female(X).

% X is a mother of Y if X is a female parent of Y
father(X,Y) :- parent(X,Y), male(X).

% X is a father of Y if X is a male parent of Y

son(X,Y) :- child(X,Y), male(X).

% X is a son of Y is X is a male child of Y

son(X,Y) :- child(X,Y), male(Y).

% X is a son of Y if X is a male child of Y.

So it is true that Mary is the mother of Joe

  • Multiple rules

given Sibling(X.Y): Sibling(w.y)

?- [user].

sibling(X,Y) :- parent(Z,X), parent(Z,Y).

   // A sibling is someone with the same parent

close-relation(X,Y) :- child(X,Y).

close-relation(X,Y) :- sibling(X,Y).

close-relation(X,Y) :- parent(X,Y).

// A close relation is either a child, or a sibling, or a parent.

When more than one rule is given for a goal, Prolog tries the various rules in the given order.

?- close-relation(anne,charles).

TRUE, so the second rule succeeds

· To extend program

?- close-relation(X,charles).

X = william ;

X = harry ;

X = charles ;

X = charles ;

X = anne ;

X = anne ;

X = andrew ;

X = Mary ;

X = Joe ;

FALSE

Prolog first goes through the answers given by the "child" rule, then the answers given by the "sibling" rule, then the answers given by the "parent" rule.The goal "sibling(charles,X)'' succeeds twice for each sibling of Charles as well as for himself, once for their common parent Mary and once for their common parent Joe.

  • Recursion      

?- [user].

ancestor(X,X).

ancestor(X,Y) :- parent(X,Z), ancestor(Z,Y).

The ancestor relationship is defined recursively in two rules:

Base case: Every man is his own ancestor.

Recursive case:If X is a parent of an ancestor of Y, then X is an ancestor of Y.

A literal with variables and no body, such as "ancestor(X,X)"is a statement that the form is true for all values of the variable ie, for any X "ancestor(X,X)" is true.

?- ancestor(charles,charles).

yes

The query matches the base rule "ancestor(X,X)".


Related Solutions

Complete the attached program by adding the following: a) add the Java codes to complete the...
Complete the attached program by adding the following: a) add the Java codes to complete the constructors for Student class b) add the Java code to complete the findClassification() method c) create an object of Student and print out its info in main() method of StudentInfo class. * * @author * @CS206 HM#2 * @Description: * */ public class StudentInfo { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application...
In a few more weeks, you will be adding a new member to your family –...
In a few more weeks, you will be adding a new member to your family – a 10-week old golden retriever puppy! In previous litters, the average weight of 42 puppies at 10 weeks was 14.8 lbs with a standard deviation of 1.1 lbs. Find the 90% confidence interval for the average 10-week weight for golden retriever puppies. Show/explain your work, and identify the following: a. The estimated population mean and degrees of freedom b. The assumptions you are making...
Extend the custom unorderedLinkedList class by adding the following operation: Find and delete the node with...
Extend the custom unorderedLinkedList class by adding the following operation: Find and delete the node with the smallest info in the list. Delete only the first occurrence and traverse the list only once. The function's prototype is deleteSmallest() use this code #include <ctime> #include <iostream> #include <random> #include "unorderedLinkedList.h" using namespace std; int main() { default_random_engine e(1918); uniform_int_distribution<int> u(10, 99); int size = 12; unorderedLinkedList ul; while (ul.getnelts() < size) { int elt = u(e); ul.append(elt); ul.show(); cout << endl;...
You will extend last week's workshop activity by adding a Player class. Each player has a...
You will extend last week's workshop activity by adding a Player class. Each player has a number of Pokemons, and the player can select one of his or her Pokemon to play against another player's Pokenmon. The player who lost the battle lost his or her Pokemon to the other player. You will be working with three.java files in this zyLab. Pokemon.java - Class definition (completed) Player.java - Class definition PokemonField.java - Contains main() method Complete the Player class with...
The structure, authority relationships, and rules of the Alibaba organization. Use the organization chart , you...
The structure, authority relationships, and rules of the Alibaba organization. Use the organization chart , you can choose to use imformation about instructions on main executive positions, responsibilities of different departments, their authority relationships and conflicts the structure may bring, give your suggestion about its organization.
Step 1: Extend the dispenserType class per the following specifications. Add a parameterized constructor to initialize...
Step 1: Extend the dispenserType class per the following specifications. Add a parameterized constructor to initialize product name (name), product cost (cost) and product quantity (noOfItems). This constructor will be invoked from main.cpp. One such call to this constructor will look like: dispenserType sanitizer("hand sanitizer", 50, 100); Add the declaration and definition of this parameterized constructor to .h and .cpp files. Step2: Define a new class, cashRegister. Start by creating cashRegister.h and cashRegister.cpp files. Be sure to update your CMakeLists.txt...
Do you agree with Confucius that the family is the model for relationships in society? Do...
Do you agree with Confucius that the family is the model for relationships in society? Do you agree with Taoism that nature flows through all things, connecting all things, including human beings? In this sense, for both Confucianism and Taoism that which keeps us from seeing this is the ego. Is this the case, or are they mistaken?
Read the following scenario. A family-owned business can have special complications. The line separating family relationships...
Read the following scenario. A family-owned business can have special complications. The line separating family relationships and legal responsibilities can be unclear. It is important for directors, officers, and owners of a family-owned business to be aware of the issues to avoid misunderstandings and unintended liability and to preserve familial relationships. You are a consultant advising a "mom and pop" grocery store owned by Jeff and Joan, a married couple, and their two adult children, Martha and Henry. The grocery...
You are considering adding a new security to your portfolio. To decide whether you should add...
You are considering adding a new security to your portfolio. To decide whether you should add the security, you need to know the security's: A. Expected return and variance only B. Expected return only C. Expected return, variance, and covariance D. Expected return and covariance only
i am looking to add more detail into my program the runs a game of rock...
i am looking to add more detail into my program the runs a game of rock paper scissors i want to include a function or way to ask the user to input their name so that it could be shown in the results at the end of a round/game. after a round something like "Mike wins!" i also want to output the round number when the result of for each round is outputed Round 1: Mike Wins! Round 2: Computer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT