Simio Forum

#### Welcome to the Simio Forum

Welcome to the Simio Forum! Experience the full experience of the forum by becoming a Simio Insider! You must be an Insider to post on any forum!

# How do I use Math.IF for logical expressions?

## Recommended Posts

Excerpt From Help:

Math.If(test1, value1, test2, value2, test3, value3, …, otherwise value)

Returns the value specified in valueN if the testN is True. Returns the value specified in otherwiseValue if all the testN are False. For example, Math.If(ModelEntity.Priority == 2, 1, 3) would return the value of 1 if the expression ModelEntity.Priority == 2 is True and would return the value of 3, otherwise.

First of all, many people are not aware of the power of expressions. You can of course use all of the numeric states, properties, math functions, and general functions available. But you can go well beyond that using non-numeric items and logical relationships.

For example on a path weight, you might use the expression “Is.PartA==True” that is a logical expression that returns a value of 1 (True) if the item is a PartA and 0 (False) if it is not. A more concise expression that evaluates exactly the same is “Is.PartA”. Presumably on the other path you would have the reverse expression of “Is.PartA==False” or simply “!Is.PartA” (where "!" is read as not).

Even in this very simple example, you could perhaps add a bit of clarity by replacing the above with Math.If( Is.PartA, 1, 0) for the first path and Math.If( Is.PartA, 0, 1) for the second path.

The real power of the Math.If starts to become obvious when you have compound logical expressions. For example, say I have a processing time that is time dependent by shift and “Shift” is a predefined state. I could use an expression like Math.If(Shift==1, 15, Shift==2, Random.Uniform(10,20), 18.53). This simply says if it is 1st shift use 15, else if it is 2nd shift use a random sample, otherwise use the value 18.53.

You can even use these nested such as: Math.If(Shift==1, Math.If(Is.PartA, 10.5, 11.6), 12.7) which says if its first shift and its PartA use 10.5, if its first shift and not PartA use 11.6, and if it’s not first shift use 12.7. You can combine the compound and nesting as deep as you need.