Updated April 6, 2023
Introduction Prolog Operator
The prolog operator is a function to operate and works on the programming operand or variable.This operator is a symbolic character to work arithmetic, logical, and comparison operations.It is a symbol to take action between two values and objects for a programming language.It is an expression to perform two or more than the two values in the arithmetic, logical, comparison, and another format.The prolog operator is a symbolic function to operate the “pl” files value in the console.The prolog operator is a function for the prolog console and operates files variable, objects, and given operand.
Prolog Operator Types
- The prolog operator is a function to work arithmetic, logic, comparison, and other operations.
- The prolog operator categorizes several operators for different operations.
- It’s types and its subcategory are given below.
Prolog Arithmetic operator
This operator is working for arithmetic expressions such as addition, subtraction, and so on.
The arithmetic operator types shown below.
- Addition (+) operator
- Subtraction (-) operator
- Multiplication (*) operator
- Division (%) operator
- Power (**) operator
- Integer division (//) operator
- Modulus (mod) operator
- Square root (sqrt) operator
- maximum (max) operator
Prolog Comparison operator:
- This operator is working for comparison between two operands and variables such as equality.
The comparison operator types shown below.
- Greater than (>)operator
- Less than (<) operator
- Greater than equal to (>=) operator
- Less than equal to (=<) operator
- Equal (=:=) operator
- Not equal (=\=) operator
Trigonometric operator:
• This operator works for operating operand and variable to find tangent and cotangent values.
• The trigonometric operator types are shown below.
- SIN operator
- COS operator
Explain Operator Types with Example
The arithmetic operator types examples show below.
Prolog Arithmetic operator:
Addition (+) operator:
- This operator uses for addition operation.
- The addition operation example shows below.
Example
| ?- ADD is 45 + 12.
Output:
Subtraction (-) operator:
- This operator uses for subtraction operation.
- The subtraction operation example shows below.
Example
| ?- SUB is 45 - 12.
Output:
Multiplication (*) operator:
- This operator uses for the multiplication operation.
- The multiplication operation example shows below.
Example
| ?- MUL is 45 * 12.
Output:
Division (/) operator:
- This operator uses for division operation.
- The division operation example shows below.
Example
| ?- Div is 45 / 12.
Output:
Power (**) operator:
- This operator uses for power operation.
- The power operation example shows below.
Example
| ?- POW is 12 ** 2.
Output:
Example
| ?- POW is 12 ^ 2.
Output:
Integer division (//) operator:
- This operator uses for number division operation.
- The integer division operation example shows below.
Example
| ?- IntDiv is 45 // 12.
Output:
Modulus (mod) operator:
- This operator uses for the division for reminder operation.
- The modulus operation example shows below.
Example
| ?- Mod is 45 mod 12.
Output:
Square root (sqrt) operator:
- This operator uses for finding the square root of the value.
- The square root operation example shows below.
Example
| ?- R is 144,
S is sqrt(R).
Output:
maximum (max) operator:
This operator uses for finding the maximum of the value from two values.
The max operator example shows below.
Example
| ?- R is 45, S is 48,
T is max(R, S).
Output:
Prolog comparison operator:
The comparison operator types examples show below.
Greater than (>) operator
- This operator uses for comparing two variables to “greater than” value operation.
- The Greater than (>) operator example shows below.
Example 1
| ?- 13 * 2 > 12 + 13 .
Output:
Example 2
| ?- 12 + 13 > 13 * 2.
Output:
Less than (<) operator
- This operator uses for comparing two variables to “less than” value operation.
- The less than (<) operator example shows below.
Example 1
| ?- 12 + 13 < 13 * 2.
Output:
Example 2
| ?- 13 * 2 < 12 + 13 .
Output:
Greater than equal to (>=) operator
- This operator uses for comparing two variables to “greater than and equal to” value operation.
- The Greater than (>=) operator example shows below.
Example 1
| ?- 13 * 2 >= 12 + 13 .
Output:
Example 2
| ?- 12 + 13 >= 13 * 2.
Output:
Example 3
| ?- 12 + 13 >= 13 + 12.
Output:
Less than equal to (=<) operator
- This operator uses for comparing two variables to “less than and equal to” value operation.
- The less than (=<) operator example shows below.
Example 1
| ?- 12 + 13 =< 13 * 2.
Output:
Example 2
| ?- 13 * 2 =< 12 + 13 .
Output:
Example 3
| ?- 12 + 13 =< 13 + 12.
Output:
Equal (=:=) operator
This operator uses for comparing two variables to “equal to” value operation.
The Equal (=:=) operator example shows below.
Example 1
| ?- 12 + 13 =:= 13 + 12.
Output:
Example 2
| ?- 12 + 13 =:= 13 + 14.
Output:
Not equal (=\=) operator
- This operator uses for comparing two variable to “not equal to” value operation.
- The Not equal (=\=) operator example shows below.
Example 1
| ?- 12 + 13 =\= 13 + 12.
Output:
Example 2
| ?- 12 + 13 =\= 13 + 14.
Output:
Prolog trigonometric operator:
The trigonometric operator types examples show below.
sin() operator
- This operator uses for finding the tangent of the trigonometric pattern.
- The sin operator example shows below.
Example 2
| ?- R is 45,
S is sin(R).
Output:
cos() operator
- This operator uses for finding the angle of the tangent of the trigonometric pattern.
- The COS() operator example shows below.
Example 2
| ?- R is 45,
S is cos(R).
Output:
Conclusion
- The prolog operator helps to work with multiple variables and objects.
- The arithmetic, comparison, trigonometric, logical operation using prolog operator.
- This operator makes the application easy, user-friendly, elegant.
Recommended Articles
We hope that this EDUCBA information on “Prolog Operator” was beneficial to you. You can view EDUCBA’s recommended articles for more information.