# Learn Prolog now Translations-chapter I-Facts, rules and queries-section III, exercises and answers

Source: Internet
Author: User
Tags knowledge base

Exercise 1.1 What are the following character sequences, which are atoms, which are variables, and which are not?

1. VINCENT

2. Footmassage

3. Variable23

4. Variable2000

5. Big_kahuna_burger

6. ' Big Kahuna Burger '

7. Big Kahuna Burger

8. ' Jules '

9. _jules

Ten. ' _jules '

Vincent,variable23,big_kahuna_burger, ' Big Kahuna Burger ', ' Jules ', ' _jules ' are atoms;

footmassage,variable2000 is a variable;

Big Kahuna Burger not both.

Exercise 1.2 Which of the following character sequences are atoms, which are variables, which are complex statements, and which are not? Gives the functor and the number of elements for each complex statement.

1. Loves (Vincent, Mia)

2. ' Loves (Vincent, Mia) '

3. Butch (boxer)

4. Boxer (Butch)

5. and (Big (burger), Kahuna (burger))

6. and (Big (x), Kahuna (x))

7. _and (Big (x), Kahuna (x))

8. (Butch kills Vincent)

9. Kills (Butch Vincent)

Kills (Butch, Vincent

' Loves (Vincent, Mia) ' is an atom;

no variables;

Complex statements are:

Loves (Vincent, Mia), functor is loves, the meta number is 2;

Boxer (Butch), functor is boxer, the meta number is 1;

and (Big (burger), Kahuna (burger)), functor is and, the number of tuples is 2;

and (Big (x), Kahuna (x)), the functor is and, the number of tuples is 2;

Nothing is included: Butch (boxer), _and (Big (x), Kahuna (x)), (Butch kills Vincent), kills (Butch Vincent), kills (Butch, Vincent.

Exercise 1.3 How many of the facts, rules, clauses, and predicates are in the following Knowledge base? Which are the head of the rule, and which are the corresponding targets?

Woman (Vincent).

Woman (MIA).

Man (Jules).

Person (x):-Mans (X); Woman (X).

Loves (x, y):-Father (x, y).

Father (Y, z):-Man (y), son (Z, y).

Father (Y, z):-Man (Y), daughter (Z, y).

There are 3 facts, and they are:

Woman (Vincent).

Woman (MIA).

Man (Jules).

There are a total of 4 rules, which are:

Person (x):-Mans (X); Woman (X).

Loves (x, y):-Father (x, y).

Father (Y, z):-Man (y), son (Z, y).

Father (Y, z):-Man (Y), daughter (Z, y).

There are 7 clauses, which are:

Man (X), woman (X), father (X, Y), Man (Y), son (Z, Y), Man (Y), daughter (Z, Y)

A total of 7 predicates, they are:

Woman,man,person,loves,father,son,daughter;

The head of the rule and the goals it contains are as follows:

 header contained targets person (x) man (x); Woman (x) loves (x, Y) father (X, Y) father (Y, Z) man (y), son (Z, y) father (Y, Z) td> man (Y), daughter (Z, Y)

Exercise 1.4 The following logic is expressed in Prolog

1. Butch is a killer

2. Mia and Marsellus are married

4. Marsellus kills everyone who gives Mia a footmassage.

5. Mia loves everyone who is a good dancer.

6. Jules eats anything is nutritious or tasty.

1. Killer (Butch).

2. Married (Mia, Marsellus).

4. Kills (Marsellus, x):-Footmassage (x, MIA).

5. Loves (Mia, x):-Good_dancer (x).

6. Eats (Jules, X):-Nutritious (x); Tasty (X).

Two points Personal Summary:

1. If the logic or information in reality is to be expressed in the form of a prolog, then the functor may be a verb, a name and an adjective, and the argument should be a noun or a complex statement.

2. The intrinsic meaning of the functor and predicate is consistent, and this is essentially different from a function or method in the traditional sense: the function and the way have the execution process, have the input and the output, the functor and the predicate are only the information in the Knowledge base storage way, through the query function.

Exercise 1.5 assumes that we have the following Knowledge Base:

Wizard (Ron).

Haswand (Harry).

Quidditchplayer (Harry).

Wizard (x):-Hasbroom (x), Haswand (x).

Hasbroom (x):-Quidditchplayer (x).

How will prolog respond to the query below?

1. Wizard (Ron).

2. Witch (Ron).

3. Wizard (Hermione).

4. Witch (Hermione).

5. Wizard (Harry).

6. Wizard (Y).

7. Witch (Y).

1. Prolog will answer true, because this is the fact that is directly defined in the Knowledge base.

2. Prolog will make an error because the Knowledge base does not define any facts and rules about witch.

3. Prolog will answer false because it does not directly define the fact, nor can it be derived indirectly.

4. Prolog will make an error, for the same reason as 2.

5. Prolog will answer true, because the fact can be inferred indirectly.

6. Prolog will answer: Y = Ron; Y = Harry.

7. Prolog will error, the principle of 2.

Learn Prolog now Translations-chapter I-Facts, rules and queries-section III, exercises and answers

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.