How to use Math Unit

by Laura Cigardi
2,059 views Published on Oct 24, 2011
Applies to: 7.2 or higher
Table of contents


The Math is an Utility Component designed to parse and evaluate mathematical expressions. A mathematical expression is composed by variables and operators and can be either statically defined at modeling time or dynamically provided through an input parameter at run-time. The Math replaces the variables with their actual values provided through input parameters, evaluates the expression, and finally propagates the result as an output parameter. This Component can be used as an Operation and as a View Component, therefore can be positioned either outside or inside the page.

How to use the Math

In order to correctly use a Math it's necessary to provide a Default Expression and the Variables sub-elements.

The Default Expression is the expression calculated when a dynamical expression is not passed at execution time through the Expression input parameter. In this expression, the names of the operands must be the same of the variables defined as sub-elements of the Math. The result of the evaluated expression will be provided as an output parameter called Result.

Let's make a simple example of the use of Math. Here it's shown how to build a Web Application which permits to make addition between two operands. Here's the IFML Model that realize the example: the Form Component has two fields where the operands of our expression will be inserted by the user and a flow which provides the inserted values to the Math. The Math will evaluate the default expression using the values passed.

In the Math Properties View panel it's possible to define the default expression and its result type.

In order to add the necessary input parameters for the evaluation of the expression, right click on the Math and then select Add > Variable. According to the Default Expression, it's necessary to add the "firstOperand" and "secondOperand" variables. Remember that the variables must have the same names of the operands of the Default Expression.

Now it's necessary to set the binding of the flow between the Form Component and the Math and of the flow between the Math and the Message Component, which will show on the browser the result of the Math Operation. The values contained in the fields of the Form Component must be passed to the input parameters of the Math. The result calculated by the Math must be passed to the Message Component in order to show it in the page.

It's even possible to define an expression that will be evaluate at run-time. The Math indeed can receive, through the Expression input parameter, a string representing an expression that will be parsed and evaluated at run-time. Just click on the input flow of the Math and set the input parameter with the desired expression.

The supported operators are

  • + : Addition
  • - : Subtraction
  • * : Multiplication

  • / : Division
  • % : Modulus
  • <= : Less or Equal
  • < : Less than
  • >= : Greater or Equal
  • > : Greater than
  • = : Equal
  • != : Not Equal
  • and : Boolean And
  • or : Boolean Or
  • not : Boolean Not

The supported functions are:

  • cos : Cosine
  • sin : Sine
  • tan : Tangent
  • acos : Arc Cosine
  • asin : Arc Sine
  • atan : Arc Tangent
  • sqrt : Square Root
  • sqr : Square
  • log : Natural Logarithm
  • exp : Exponential
  • abs : Absolute Value
  • neg :Negate
  • rnd :Random Number (between 0 and its argument)

Related Learning Objects