0% found this document useful (0 votes)
4 views

Prolog Key Concepts Summary

The document outlines key concepts of Prolog, including syntax for constants, variables, and structures, as well as arithmetic expressions and their evaluation using the 'is' operator. It explains the roles of facts, rules, and queries in knowledge representation, along with the processes of unification, conjunction, and disjunction. Additionally, it highlights the use of nested structures and the importance of operator precedence in arithmetic evaluation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Prolog Key Concepts Summary

The document outlines key concepts of Prolog, including syntax for constants, variables, and structures, as well as arithmetic expressions and their evaluation using the 'is' operator. It explains the roles of facts, rules, and queries in knowledge representation, along with the processes of unification, conjunction, and disjunction. Additionally, it highlights the use of nested structures and the importance of operator precedence in arithmetic evaluation.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Prolog Key Concepts Summary

1. Prolog Syntax and Basic Concepts

Constants

• Single, specific entities or values.

• Start with lowercase letters (e.g., john, apple) or quoted strings (e.g., 'Delicious').

Variables

• Placeholders for unknowns.

• Start with uppercase letters or underscores (e.g., X, Y, _food).

Structures

• Compound terms grouping multiple entities.

• Consist of a functor and arguments (e.g., owns(mary, pet(cat(fubby)))).

2. Arithmetic Expressions in Prolog

Operators

• Addition: +

• Multiplication: *

• Subtraction: -

• Division: /

• Power: ^

• Modulo: mod

Evaluation Using is

• The is operator evaluates arithmetic expressions on the right-hand side and assigns
the result to the variable on the left-hand side.

• Example:
?- X is 3 + 2 * 4 - 1. % Result: X = 10 (follows operator precedence).

Operator Precedence

• Multiplication (*) and division (/) are evaluated before addition (+) and subtraction (-).

3. Facts, Rules, and Queries


Facts

• Define specific relationships or truths.

• Example

food(burger). % Burger is a food.

Rules

• Define logical relationships between facts.

• Example:

meal(X) :- food(X). % Anything that is a food is also a meal.

Queries

• Ask questions about the defined facts and rules.

• Example

?- food(pizza). % Is pizza a food? (Result: true).

4. Unification

• Process of matching two terms and binding variables to make them identical.

• Example

?- is_bigger(X, dog) = is_bigger(elephant, dog). % Binds X to elephant.

5. Conjunction and Disjunction

Conjunction (AND)

• Combine multiple conditions using (,)

• Example:

?- likes(mary, john), likes(john, mary). % True if both conditions are satisfied.

Disjunction (OR)

• Combine multiple conditions using (;)

• Example

?- likes(mary, france); likes(john, france). % True if either condition is satisfied.


6. Anonymous Variables

• Represent any value when you don’t care about the specific value.

• Denoted by (_)

Ex:

?- male(_). % True (matches any male individual).

7. Nested Structures

• Structures can contain other structures as arguments.

• Example

study(alex, python(programming_course, code123)). % Represents Alex studying Python


with specific details.

8. Knowledge Representation

Representing Statements

• Use facts and rules to represent real-world statements.

• Example:

• Marcellus kills everyone who gives Mia a foot massage

kills(marcellus, X) :- givesFootMassage(X, mia).

Summary of Key Concepts

1. Constants, Variables, and Structures :

• Constants represent fixed values.

• Variables represent unknowns.

• Structures group multiple entities together.

2. Arithmetic Expressions :

• Use is for evaluation.

• Follow operator precedence.

3. Facts, Rules, and Queries :

• Facts define specific truths.

• Rules define logical relationships.


• Queries ask questions about the knowledge base.

4. Unification :

• Matches terms and binds variables.

5. Conjunction and Disjunction :

• Combine conditions using , (AND) or ; (OR).

6. Nested Structures :

• Represent complex relationships.

7. Knowledge Representation :

• Use facts and rules to model real-world statements

NOTE:

Arithmetic Evaluation (is):

The is operator evaluates arithmetic expressions on the right-hand side and assigns the result to
the variable on the left-hand side.

Operator precedence must be followed during evaluation.

Instantiation Without Evaluation (=):

The = operator unifies variables with terms but does not evaluate arithmetic expressions.

The unevaluated expression becomes the value of the variable.

Unification of Structured Terms:

The = operator unifies structured terms by matching functors and arguments.

Variables in one term can be bound to constants or other variables in the other term.

You might also like