Prolog Key Concepts Summary
Prolog Key Concepts Summary
Constants
• Start with lowercase letters (e.g., john, apple) or quoted strings (e.g., 'Delicious').
Variables
Structures
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 (-).
• Example
Rules
• Example:
Queries
• Example
4. Unification
• Process of matching two terms and binding variables to make them identical.
• Example
Conjunction (AND)
• Example:
Disjunction (OR)
• Example
• Represent any value when you don’t care about the specific value.
• Denoted by (_)
Ex:
7. Nested Structures
• Example
8. Knowledge Representation
Representing Statements
• Example:
2. Arithmetic Expressions :
4. Unification :
6. Nested Structures :
7. Knowledge Representation :
NOTE:
The is operator evaluates arithmetic expressions on the right-hand side and assigns the result to
the variable on the left-hand side.
The = operator unifies variables with terms but does not evaluate arithmetic expressions.
Variables in one term can be bound to constants or other variables in the other term.