Perform Math operations

Bizagi provides several functions that allow you to perform mathematical operations. This group of functions start with the same sentence:

CHelper.Math.

They are available in the Math category of the Functions Editor.

Below we will show you how to use Math functions in Bizagi:

ABS

This function returns the absolute value of a number.

CHelper.Math.Abs(Number)

The parameter of this function can be defined as an XPath, variable or a number.

Considerations

The input parameter must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns error if evaluates an undefined parameter.

Use the IsNaN function to validate the parameter used is a number.

Example

In an Expenses report Process an employee registers all the expenses of a business trip. If the expenses are higher than the approved ones, the difference has to be discounted from payroll. As this difference is always negative but the amount to discount has to be positive it is necessary to use the Abs function:

//Evaluate if the registered expenses are greater than the approved ones

if (<ExpensesReport.TotalExpenses> > <ExpensesReport.ApprovedExpenses>)

{

//If so obtain the absolute value of the difference

<ExpensesReport.AmountToDiscount> = CHelper.Math.Abs(<ExpensesReport.TotalExpenses> - <ExpensesReport.ApprovedExpenses>)

}else

//If not assign 0 to the amount to discount from payroll

<ExpensesReport.AmountToDiscount>=0

}

Average

This function obtains the average (arithmetic mean) of a set of numbers.

CHelper.Math.Average([Number1,Number2,...])

The parameter of this function is an array defined between brackets[], that can contain Xpaths, variables or numbers.

Considerations

The input parameter must be an array of doubles.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns an error if an empty input array is evaluated.

The function returns error if any input array is either too long or undefined.

Be careful when defining the input of the function to avoid errors for the end users.

Use the IsNaN function to validate the parameters used are numbers.

Example

In a Purchase Request Process an estimation of the price of a product is made based on the last three purchases of that product. The purchasing values are averaged to obtain an estimation. In Bizagi this estimation can be obtained using the Average function:

//Obtain the estimated price by averaging the last three purchasing prices

<Product.EstimatedPrice> = CHelper.Math.Average([<Product.Price1>,<Product.Price2>,<Product.Price3>])

//Alternative way

ArrayVariable=[<Product.Price1>,<Product.Price2>,<Product.Price3>]

<Product.EstimatedPrice> = CHelper.Math.Average(ArrayVariable)

Ceiling

This function rounds a number up.

CHelper.Math.Ceiling(Number)

The parameter of this function can be defined as an XPath, variable or number.

Considerations

The input parameter must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

Use the IsNaN function to validate the parameter is a number.

Example

A sand transporting company calculates the number of necessary trucks to transport a specific freight as the quotient of the freight weight and the capacity of trucks. As the result obtained might be fractional (which has no sense in this context because the company cannot hire a fraction of a truck), this result must be rounded up. In Bizagi this can be done by using the Ceiling function:

//Obtain the number of trucks needed

NumberofTrucks = <Freight.Weight>/<Freight.Trucks.WeightCapacity>;

//Round up the number of trucks

<Freight.RequiredTrucks> = CHelper.Math.Ceiling(NumberofTrucks);

Exp

This function returns e (the base of natural logarithms) raised to the given power.

CHelper.Math.Exp(Number)

The parameter of this function can be defined as an XPath, number or variable.

Considerations

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

Use the IsNaN function to validate the parameter is a number.

THE RESULT OF THIS FUNCTION MUST BE STORED IN A FLOAT-TYPE ATTRIBUTE.

Example

A Laboratory uses Bizagi to manage its medical researches. In these researches the laboratory commonly has to perform estimations of bacterial colonies growth. This growths are usually modeled using the following exponential relationship:

Where No is the initial population, e is the base of natural logarithms, k is a constant and N is the population at the t time.

To calculate the final population of bacterias in Bizagi you can use the Exp function. This function receives the power as parameter:

//Obtain the parameters of the formula in variables

No=<LabResearch.Bacteria.InitialPopulation>

k=<LabResearch.Bacteria.Growthconstant>

t=<LabResearch.Bacteria.TimeofEstimation>

//Apply the formula to obtain the final population

<LabResearch.Bacteria.Finalpopulation>=No*CHelper.Math.Exp(k*t)

Floor

This function rrounds a number down.

CHelper.Math.Floor(Number)

The parameter of this function can be defined as an XPath, variable or number.

Considerations

The input parameter must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

Use the IsNaN function to validate the parameter is a number.

Example

In a Purchase Request Process an estimation of the price of a product is made based on the last three purchases of that product. The purchasing values are averaged to obtain the estimation. The Purchase department has decided to round this estimation down to obtain an integer estimation. For this case the Floor function can be used:

//Obtain the estimated price by averaging the last three purchasing prices

EstimatedPrice = CHelper.Math.Average([<Product.Price1>,<Product.Price2>,<Product.Price3>]);

//Obtain the integer part of the estimated price

<Product.IntEstimatedPrice> = CHelper.Math.Floor(EstimatedPrice);

IsNaN

This function checks if a parameter is not a number:

Returns true if the parameter is not a number.

Returns false if the parameter is a number.

CHelper.Math.IsNaN(Parameter)

The parameter of this function can be defined as an XPath, variable or number.

Considerations

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

Example

Suppose you want to evaluate if the parameters to be used in a Math function are numbers in order to avoid errors or incoherent results. To do so you can use the IsNaN function:

//Evaluate if of the parameters to be used in the average function are numbers

Number1IsNotaNumber=CHelper.Math.IsNaN(<Product.Price1>);

Number2IsNotaNumber=CHelper.Math.IsNaN(<Product.Price2>);

if (Number1IsNotaNumber==true || Number1IsNotaNumber==true)

{

//If not show an error message

CHelper.ThrowValidationError ("The parameters of the Average function must be numbers")

}else{

//If so, apply the math function

CHelper.Math.Average([<Product.Price1>,<Product.Price2>]);

}

Ln

This function returns the natural logarithm of a number.

CHelper.Math.Ln(Number)

The parameter of this function can be defined as an XPath, variable or number.

Considerations

The input parameter must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns an error if the input parameter is less than or equal to 0.

The function returns an error if the input parameter is either too long or undefined.

Use the IsNaN function to validate the parameter is a number.

Example

A Laboratory uses Bizagi to manage its medical researches. In these researches the laboratory commonly has to perform estimations of bacterial colonies growth. The time a colony spends to achieve an expected growth is estimated using the following expression :

Where No is the initial population, e is the base of natural logarithms, k is a constant and N is the population at the t time.

To calculate the time to achieve the expected population of bacterias in Bizagi you can use the Ln function:

//Obtain the parameters of the formula in variables

No = <LabResearch.Bacteria.InitialPopulation>

N = <LabResearch.Bacteria.Finalpopulation>

k = <LabResearch.Bacteria.Growthconstant>

//Apply the formula to obtain the time to achieve the expected population

<LabResearch.Bacteria.TimeofEstimation> = (CHelper.Math.Ln(N / No) / k);

Log10

This function returns the base 10 logarithm of a number.

CHelper.Math.Log10(Number)

The parameter of this function can be defined as an xpath, variable or number.

Considerations

Input parameter must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns error if evaluates an input parameter that is less than or equal to 0.

The function returns error if an input array is either too long or undefined.

Use the IsNaN function to validate the parameter is a number.

Example

A Bank offers multiple products to its customers. When a customer is interested in a CD (Certificate of deposit) it is common that they ask for the necessary time (term) the money has to be invested to achieve an expected amount under the offered interest rate.

This term can be calculated using the following formula:

Where n is the necessary term (in months) the invested amount Po needs to remain invested to achieve the desired amount P at the interest rate i.

To perform this calculation in Bizagi you can use the Log10 function. This function receives a number as parameter:

//Obtain the parameters of the formula in variables

Po = <CDRequest.InvestedAmount>;

P = <CDRequest.DesiredAmount>;

i = <CDRequest.OfferedInterestRate>;

//Apply the formula to obtain the required term

<CDRequest.RequiredTerm> = (CHelper.Math.Log10(P / Po) / CHelper.Math.Log10(1+i));

Max

This function returns the largest value of a set of numbers.

CHelper.Math.Max([Number1,Number2])

The parameters of this function can be defined as Xpaths, variables or numbers, and must be between brackets

Considerations

Input parameters must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns error if an input array is either too long or undefined.

Use the IsNaN function to validate the parameters used are numbers.

Example

A loan application is not rejected if the  applicant or co-borrower bureau score is greater than 600. You can use the Max function to evaluate which is the best bureau score and based on that define if the application is rejected or not:

//Obtain the Best bureau score between the applicant and his/her borrower

Bestscore= CHelper.Math.Max(<LoanApplication.Applicant.Score>,<LoanApplication.Coborrower.Score>)

//Evaluate if the Best score is greater than or equal to 600

if (Bestscore>=600)

{

//If so do not reject the application

<LoanApplication.Rejected>= false;

}else

{

//If not reject the application

<LoanApplication.Rejected>= true;

}

Min

This function returns the smallest value of a set of numbers.

CHelper.Math.Min([Number1,Number2])

The parameters of this function can be defined as Xpaths, variables or numbers, and must be between brackets

Considerations

Input parameters must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns error if an input array is either too long or undefined.

Use the IsNaN function to validate the parameters used are numbers.

Example

A loan application is rejected if the applicant or co-borrower bureau score is less than 100. You can use the Min function to evaluate which is the lowest bureau score and based on that define if the application is rejected or not:

//Obtain the lowest bureau score between the applicant and his/her borrower

Worstscore= CHelper.Math.Min(<LoanApplication.Applicant.Score>,<LoanApplication.Coborrower.Score>)

//Evaluate if the lowest score is less than or equal to 100

if (Worstscore<=100)

{

//If so, reject the application

<LoanApplication.Rejected>= true;

}else

{

//If not, do not reject the application

<LoanApplication.Rejected>= false;

}

Module

This function returns the remainder after a number is divided by a divisor.

CHelper.Math.Module(Number,Divisor)

The parameters of this function can be defined as Xpaths, variables or numbers.

Considerations

Input parameters must be integers.

The supported attribute type to use as input XPath parameter (or Xpaths stored in variables) is integer.

The function returns an error if the Divisor is equal to 0.

Use the IsNaN function to validate the parameters used are numbers.

Example

Suppose in a Process it has to be evaluated if a number is pair. To do so you can use the Module function using the number 2 as the divisor. If the result obtained is equal to 0 then the number is pair.

//Obtain the Module of the number using 2 as divisor

Module= CHelper.Math.Module(<Process.NumbertoEvaluate>,2)

//Evaluate if the result is equal to 0

if (Module==0)

{

//If so the number is pair

<Process.IsPair>= true;

}else

{

//If not the number is not pair

<Process.IsPair>= false;

}

Percentage

This function returns the equivalent in percentage of a number.

CHelper.Math.Percentage(Number)

The parameter of this function can be defined as an XPath, variable or number.

Considerations

Input parameter must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns error if the input parameter is either too long or undefined.

Use the IsNaN function to validate the parameter is a number.

Example

In a Credit request process the information of interest rates is entered and displayed in Forms as numbers between 0 and 100. Suppose in an activity of the Process the interest amount caused in one period must be calculated. The process cannot use this number to perform the calculation so it must be normalized into a number between 0 and 1 to obtain a coherent and accuracy result. To do that in Bizagi you can use the Percentage function:

//Obtain the Interest rate (Between 0 and 1)

RealInterestRate = CHelper.Math.Percentage(<CreditRequest.InterestRate>);

//Calculate the Interest amount

<CreditRequest.InterestAmount> = RealInterestRate * <CreditRequest.RequestedAmount>;

Power

This function obtains the result of a number raised to a power.

CHelper.Math.Pow(Base,Power)

The parameters of this function can be defined as Xpaths, variables or numbers.

Considerations

Input parameters must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns an error if the Base is between 1 and -1 and the Power is either too long or negative number.

The function returns an error if the Base is either too long and the Power is greater than zero.

The function returns an error if the Base is negative and the Power is not integer.

The function returns an error if the Base is not between 1 and -1 and Power is too long.

The function returns an error if the Base is zero and the Power is negative.

The function returns an error if the Base or Power are undefined.

Use the IsNaN function to validate the parameters used are numbers.

Example

In a Credit Request Process a customer wishes to know what would be the total amount that he/she has to pay in a Personal loan after six months under a given interest rate.

This amount can be calculated using the following formula:

Where Po is the requested amount, i is the monthly interest rate and P is the amount at the month n.

To perform this calculation in Bizagi you can use the Power function. This function receives two parameters: Number and power.

As the requested amount and interest rate are known, the final amount can be easily calculated as follows:

//Obtain the parameters of the formula in variables

Po=<CreditRequest.RequestedAmount>

i=<CreditRequest.InterestRate>

//Apply the formula to obtain the final amount

<CreditRequest.FinalAmount>=Po*CHelper.Math.Pow(1+i,6)

Quotient

This function returns the integer portion of a division.

CHelper.Math.Quotient(Dividend,Divisor)

The parameters of this function can be defined as Xpaths, variables or numbers.

Considerations

Input parameters must be integers.

The supported attribute type to use as input XPath parameter (or Xpaths stored in variables) is integer.

The function returns an error if the Divisor is equal to 0.

Use the IsNaN function to validate the parameters used are numbers.

Example

A company uses Bizagi to manage their logistics processes. One of these processes is called Inventory management. In one of the activities of this process it is necessary to calculate the box storage capacity of a warehouse. To calculate it the dimensions of the warehouse and boxes are entered.

As the result may return a fractional number (which has no sense because you cannot store a fraction of a box) you can use the Quotient function to obtain only the integer part of the quotient.

The storage capacity of the warehouse could be calculated as below:

//Obtain the number of boxes that can be stored breadthways

WidthCapacity = CHelper.Math.Quotient(<InventoryManagement.Warehouse.Width>, <InventoryManagement.Boxes.Width>);

//Obtain the number of boxes that can be stored lengthwise

LengthCapacity = CHelper.Math.Quotient(<InventoryManagement.Warehouse.Length>, <InventoryManagement.Boxes.Length>);

//Obtain the number of boxes that can be stored upward

HeightCapacity = CHelper.Math.Quotient(<InventoryManagement.Warehouse.Height>, <InventoryManagement.Boxes.Height>);

//Calculate the total number of boxes that can be stored in the warehouse

<InventoryManagement.Warehouse.Capacity> = WidthCapacity * LengthCapacity * HeightCapacity;

Rand (from,to)

This function returns an integer random number between two numbers.

CHelper.Math.Rand(ValueFrom,ValueTo)

The parameters of this function can be defined as Xpaths, variables or numbers.

Considerations

Input parameters must be integers.

The supported attribute type to use as input XPath parameter (or Xpaths stored in variables) is integer.

The function returns an error if the ValueFrom is greater than the ValueTo parameter.

Use the IsNaN function to validate the parameters used are numbers.

Example

A company uses Bizagi to raffle different prizes among its clients. Each customer is given a number between 0 and 100. Bizagi must generate a random number between the available numbers to obtain a winner.

To implement this logic you can use the Rand function:

//Generate the winner number

<RaffleProcees.WinnerNumber> = CHelper.Math.Rand(0,100)

Rand()

This function returns a decimal between 0.0 to 1.0, and it has NO parameters.

CHelper.Math.Rand()

Example

Suppose you need to generate a random number between 10 and 20 with two decimal places.

You have to use two functions: one to generate a random number between 10 and 20 and one to generate the decimal places. Then you can add both results.

<Request.RandomNumber> = (CHelper.Math.Rand(10,20))+(CHelper.Math.Rand())

Round

This function reduces a given number to a specific number of decimal places.

CHelper.Math.Round(Number,Decimalplaces)

The parameters of this function can be defined as Xpaths, variables or numbers.

Considerations

Number parameter must be double.

Decimalplaces parameter must be integer.

Use the IsNaN function to validate the parameters used are numbers.

Example

In a Expenses report Process an employee register all the expenses of a business trip. As the expenses can be entered in a currency different from the local currency a conversion has to be made. According to the exchange rate the amount obtained can contain many decimal places which are not significant. To round this amount to one with a significant number of decimal (let us say two) you can use the Round function:

//Calculate the expenses in local currency

ConvertedExpenses = <ExpensesReport.ReportedExpenses>*<ExpensesReport.ExpensesCurrency.ExchangeRate>;

//Round the expenses amount to a significant number of decimals

<ExpensesReport.TotalExpenses> = CHelper.Math.Round(ConvertedExpenses,2);

Sqrt

This function obtains the square root of a number

CHelper.Math.Sqrt(Number)

The parameter of this function can be defined as an XPath, variable or number.

Considerations

Input parameters must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns an error if the input parameter is either too long or undefined.

The function returns an error if the input parameter is negative.

Use the IsNaN function to validate the parameter is a number.

Example

A company uses Bizagi to manage their logistics processes. One of these is Inventory management. In one of the activities of this process it is necessary to calculate the economic quantity order of a product. This quantity can be obtained by using following formula:

Where Q* is the optimal quantity to order, D is the annual demand of the product, K is fixed cost per order and h is the annual holding cost per unit.

This quantity can be calculated in Bizagi by using the Sqrt function:

//Obtain the parameters of the formula in variables

D = <InventoryManagement.Demand>;

K = <InventoryManagement.OrderCost>;

h = <InventoryManagement.HoldingCost>;

//Calculate the economic quantity order

<InventoryManagement.EconomicQuantityOrder> = CHelper.Math.Sqrt(2*D*K / h);

Truncate

This function truncates a number to an integer by removing its decimal, or fractional part

CHelper.Math.Truncate(Number)

The parameter of this function can be defined as an XPath, variable or number.

Considerations

Input parameters must be double.

The supported attribute types to use as input XPath parameter (or Xpaths stored in variables) are: integer, currency, float, real.

The function returns an error if the input parameter is either too long or undefined.

Use the IsNaN function to validate the parameter is a number.

Example

In a Purchase Request Process an estimation of the price of a product is made based on the last three purchases of that product. The purchasing values are averaged to obtain the estimation. Likely this estimation will have a decimal part. In order to obtain an integer value, the Truncate function can be used:

//Obtain the estimated price by averaging the last three purchasing prices

EstimatedPrice = CHelper.Math.Average([<Product.Price1>,<Product.Price2>,<Product.Price3>]);

//Obtain the integer part of the estimated price

<Product.IntEstimatedPrice> = CHelper.Math.Truncate(EstimatedPrice);