Rules - Mathematical Functions -->

Mathematical functions are transformative expressions that change or transform numbers/number instances, and are used in rules. 

This article will demonstrate what the different functions do by themselves, but multiple functions can be combined in expressions, and the values generated by the functions can also be used in further expressions. You will need to use brackets if combining multiple functions, to ensure Rainbird calculates a value correctly. 

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The add expression, +, will add two values together. Below is an example of the add expression using the + function:


Figure 1: Add expression in a rule. The expression will add the values of %DIGIT_1 and %DIGIT_2 together

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The subtract expression, , will minus a value from another value. Below is an example of the subtract expression using the – function:

Figure 2: Subtract expression in a rule. The expression will minus the values of %DIGIT_2 from %DIGIT_1

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The divide expression, /, will divide a value by another value. Below is an example of the divide expression using the / function:

 

Figure 3: Divide expression in a rule. The expression will divide the value of %DIGIT_1 by the value of %DIGIT_2

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The multiply expression, *, is used to multiply a value by another value. Below is an example of a rule using the * function:

Figure 4: Multiply expression in a rule. The expression will multiply the value of %DIGIT_1 by the value of %DIGIT_2 

Expressions are used in rule conditions where specific logic and/or arithmetic is required. They sit inside the  tag within a rule. The round() function can be used to round a number to the nearest whole number Below is an example of a rule using the round() function:

 

Figure 5: Round expression in a rule. The expression will round a number entered at runtime (%DIGIT) to the nearest whole number

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The ceiling function, ceil(), is used to find the least greatest integer to a value. For example, the ceiling of 2.3, would be 3. The ceiling of a whole number is the same value (e.g. the ceiling of 3 is 3). Below is an example of the ceiling expression using the ceil() function:

Figure 6: Ceiling expression in a rule. The expression will find the least greatest integer of the %DIGIT value

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The factorial function, factorial(), will multiply a number by all of the preceding integers (down to 1). For example, the factorial of 5 would be 5x4x3x2x1=120

Below is an example of the factorial expression using the factorial() function:

Figure 7: Factorial expression in a rule. The rule would work out a factorial for a value, %DIGIT, entered at runtime

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The floor expression, floor(), is used to find the greatest integer that is less than or equal to a value. For example, the floor of 3.3 would be 3, and the floor of 3 would also be 3. Below is an example of a rule using the floor() function:

Figure 8: Floor expression in a rule. The expression will find the greatest integer that is less than or equal to the %DIGIT value

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The absolute value of a number may be thought of as its distance from zero (e.g. abs(5) = 5). Below is an example of the a rule using the abs() function:

Figure 9: Absolute expression in a rule. The expression will find the absolute value of %DIGIT

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The modulo or modulus operation, calculates the remainder after a number is divided by another number. Below is an example of the rule using the mod() function:

Figure 10: Modulus expression in a rule. The expression will calculate the remainder of %DIGIT_1/DIGIT_2 

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The power expression, pow() will times a value by the power of another value. For example, 2^2 = 4, 2^3 = 8 etc. Below is an example of a rule using the pow() function:

Expressions are used in rule conditions where specific logic and/or arithmetic is required. The square root expression, sqgrt(), is used to find the square root of a value. Below is an example of a rule using the sqrt() function:

 

Figure 11: Square root expression in a rule. The expression will calculate the square root of %DIGIT

Expressions are used in rule conditions where specific logic and/or arithmetic is required. Below is an example of the minimum expression using the min() function to find the lowest number for any digit or %OBJECT listed in the brackets:

Figure 12: Minimum expression in a rule. The expression will find the lowest number for any %DIGIT listed in the brackets

Expressions are used in rule conditions where specific logic and/or arithmetic is required. Below is an example of the maximum expression using the max() function to find the highest number for any digit or %OBJECT listed in the brackets:

 

Figure 13: Maximum expression in a rule. The expression will find the highest number for any digit in the brackets

Expressions are used in rule conditions where specific logic and/or arithmetic is required. Below is an example of a rule using the tan() function:

Figure 13: Tan expression in a rule

Expressions are used in rule conditions where specific logic and/or arithmetic is required. Below is an example of the cosecant expression using the cot() function:

Figure 14: Cosecant expression in a rule

Expressions are used in rule conditions where specific logic and/or arithmetic is required. Below is an example of the cotangent expression using the cot() function:

Figure 15: Cotangent expression in a rule

Expressions are used in rule conditions where specific logic and/or arithmetic is required. Below is an example of the secant expression using the sec() function:

 

Figure 16: Secant expression in a rule

Expressions are used in rule conditions where specific logic and/or arithmetic is required. Below is an example of the inverse tangent expression using the atan2() function:

Figure 17: Inverse tangent expression in a rule

Expressions are used in rule conditions where specific logic and/or arithmetic is required.  Below is an example of an average calculation, the sum of the digit values being divided by the amount of digits (2): 

Figure 18: Average calculation in a rule. The expression will find the mean value of %DIGIT_1 and DIGIT_2

The RBLang below will generate a map that uses the different expressions mentioned in the article. Click on ‘Export .rbird’ to download the knowledge map, or ‘copy RBLang’ and paste the code directly into Rainbird.

Query and Results

When using the below RBLang, please run the query on the relationship ‘outcome’ and select the which function you would like to see in action.

Article Feedback form
Did you find this article useful?

Version 1.01 – Last Update: 24/03/2021