
- Prolog - Home
- Prolog - Introduction
- Prolog - Environment Setup
- Prolog - Hello World
- Prolog - Basics
- Prolog - Relations
- Prolog - Data Objects
- Loop & Decision Making
- Conjunctions & Disjunctions
Prolog Operators
- Prolog - Type of Operators
- Prolog - Arithmetic Comparison Operators
- Prolog - Unification Operators
- Prolog - Term Comparision Operators
- Prolog - Arithmetic Operators
- Prolog - Logical Operators
- Prolog - List Operators
- Prolog - Custom Operators
Prolog Lists
- Prolog - Lists
- Prolog - Member of List
- Prolog - Length of List
- Prolog - Concatenating Lists
- Prolog - Appending to a List
- Prolog - Deleting from a List
- Prolog - Inserting into a List
- Prolog - Permutation Operation
- Prolog - Combination Operation
- Prolog - Reverse Items of a List
- Prolog - Shift Items of a List
- Prolog - Check Order of a List
- Prolog - SubSet of a Set
- Prolog - Union of Sets
- Prolog - Intersection of Sets
- Prolog - Even and Odd Length Finding
- Prolog - Divide a List
- Prolog - Find Maximum of a List
- Prolog - Find Minimum of a List
- Prolog - Find Sum of a List
- Prolog - Sorting List using MergeSort
Built-In Predicates
- Prolog - Built-In Predicates
- Prolog - Identifying Terms
- Prolog - Decomposing Structures
- Prolog - Collecting All
- Prolog - Mathematical Predicates
- Prolog - Scientific Predicates
Miscellaneous
- Recursion and Structures
- Prolog - Backtracking
- Prolog - Preventing Backtracking
- Prolog - Different and Not
- Prolog - Inputs and Outputs
- Tree Data Structure (Case Study)
- Prolog - Examples
- Prolog - Basic Programs
- Prolog - Practical Arithmetic Examples
- Prolog - Examples of Cuts
- Towers of Hanoi Problem
- Prolog - Linked Lists
- Monkey and Banana Problem
- Prolog Useful Resources
- Prolog - Quick Guide
- Prolog - Useful Resources
- Prolog - Discussion
Prolog - Types of Operators
In prolog, we can define and categorise various operators by their arity(number of arguments on the operator) and the position of the operator with respect to the arguments of the operator.
-
Infix Operators − Most of the operators are infix operators where operator is in between the two arguments.
Example −
+
-
*
/
=
is
<
>
<=
>=
Usage −
A + B, X = Y.
-
Prefix Operators − Prefix operators comes before the arguments. Unary operators are prefix operators.
Example −
- (Unary minus)
\+ (Not Provable)
Usage −
-5, \+ goal
Operator Properties
When multiple operators are used in an expression, prolog determines the order of execution of operators as per their precedence and by use of associativity.
Precedence
Precedence determines the binding capacity of an operator with respect to other operator. For example * and / have higher precedence over + and -. Owing to precedence, A + B * C is interpreted by Prolog as A + (B * C).
Associativity
When operators of same precedence are grouped then we can use following rules of associativity.
xfx − In case of non-associative infix, we should use brackets to avoid error. For example A op B op C will throw an error.
xfy − In case of right-associative infix, Prolog will treat A op B op C as A op (B op C). Right-associative infix is useful in case of list concatenation and exponentiation operations.
yfx − In case of left-associative infix, Prolog will treat A op B op C as (A op B) op C). Left-associative infix is useful in case of arithmetic operators like +, -, * , /.
fx − In case of non-associative prefix, Prolog allows only single operator to appear.
yf − In case of right-associative prefix, Prolog allows multiple operator to stack. For example --X.