
- 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 - Term Comparison Operators
Term Comparison Operators works on standard terms of prolog. Using term comparison operators, we can compare following types of terms in standard term order of prolog.
Variables − A variable if uninstantiated is ordered by its internal order by default.
Integers − Integers are compared and ordered by their numeric values.
Floating point numbers − Floating-point numbers are compared and ordered by their numeric values.
Atoms − Atoms are ordered lexicographically or alphabetically.
-
Compound Terms, Structures − In order to compare a compound term, prolog uses following rules −
First, arity is compared as number of arguments.
Second, functor name compared alphabetically.
lastly, arguments are compared from left to right recursively.
-
Lists − List is compared using following rules −
Each elements of the lists are compared from left to right.
In case, first list is prefix of second list, the first one comes first.
Following is the list of term comparison operators −
Operator | Meaning |
---|---|
X @> Y | X is strictly greater than Y |
X @< Y | X is strictly less than Y |
X @>= Y | X is strictly greater than or equal to Y |
X @=< Y | X is strictly less than or equal to Y |
X == Y | X and Y values are strictly identical. |
X \== Y | X and Y values are not strictly identical. |
Example - Compare simple terms
| ?- apple @< orange . yes | ?- 7 @< 10. yes | ?- 7 @< 5. no | ?-
Example - Compare complex terms
| ?- func(a, b) @< func(a, c). % arguments are compared. yes | ?- [a, b, c] @< [a, b, c, d]. % first list being prefix, is returned. yes | ?- X = Y, X == Y. % As X and Y are same variables Y = X yes | ?- X == 5. % X is uninstantiated variable and 5 is atom, not identical. no | ?-
Key differences between == and = operators.
= operator is known a unification operator and is used to make terms equal by instantiated the variables. For example −
| ?- X = 7. % variable X is now 7 X = 7 yes | ?-
Where as == operator is used to compare two terms witout instantiating the variable.
| ?- Y == 7. % false as Y is unintantiated. no | ?- X = Y, X == Y. % true as X and Y are now same variables. Y = X yes | ?-