
- 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 - Mathematical Predicates
Following are the mathematical predicates −
Predicates | Description |
---|---|
random(L,H,X). | Get random value between L and H |
between(L,H,X). | Get all values between L and H |
succ(X,Y). | Add 1 and assign it to X |
abs(X). | Get absolute value of X |
max(X,Y). | Get largest value between X and Y |
min(X,Y). | Get smallest value between X and Y |
round(X). | Round a value near to X |
truncate(X). | Convert float to integer, delete the fractional part |
loor(X). | Round down |
ceiling(X). | Round up |
sqrt(X). | Square root |
Now let us see some of these functions in action using Prolog programs.
Example
| ?- random(0,10,X). X = 0 yes | ?- random(0,10,X). X = 5 yes | ?- random(0,10,X). X = 1 yes | ?- between(0,10,X). X = 0 ? a X = 1 X = 2 X = 3 X = 4 X = 5 X = 6 X = 7 X = 8 X = 9 X = 10 (31 ms) yes | ?-
Example
| ?- succ(2,X). X = 3 yes | ?- | ?- X is abs(-8). X = 8 yes | ?- X is max(10,5). X = 10 yes | ?- X is min(10,5). X = 5 yes | ?- X is round(10.56). X = 11 yes | ?-
Example
| ?- X is truncate(10.56). X = 10 yes | ?- X is floor(10.56). X = 10 yes | ?- X is ceiling(10.56). X = 11 yes | ?- X is sqrt(144). X = 12.0 yes | ?-
Advertisements