SimLang Functions
This page documents all built-in functions available in SimLang as implemented in Epicenter.
Table of contents
Click one of the function categories below or use the detailed table of contents on the right.
Operators
Logical operators can be part of an equation for any variable or decision. They are listed below in order of precedence (highest first).
| Operator | Description |
|---|---|
! | Logical NOT |
% | Percent — divides the value immediately to its left by 100 |
^ | Power |
* / | Multiply, Divide |
+ - | Add, Subtract |
== != | Logical equal, not equal |
> < >= <= | Comparison operators |
&& | Logical AND |
|| | Logical OR |
Logical functions
AND
Returns 1 (true) if all arguments are non-zero; returns 0 (false) if any argument is 0.
Syntax
AND(<expr1>, <expr2>, ...)
Example
V All True = AND(1, 5 > 4, 5 == 2) # returns 0
FALSE
Returns 0.
IF
Returns second argument if condition is true (non-zero), third argument if false (0).
Syntax
IF(<condition>, <if_true>, <if_false>)
Example
V Sell Stock = IF(58 > 20, 1, 0) # returns 1
NOT
Inverts a logical expression. Returns 0 if argument is non-zero, 1 if argument is 0.
Syntax
NOT(<expr>)
Example
V Opposite = NOT(FALSE) # returns 1
OR
Returns 0 if all arguments are 0; returns 1 if any argument is non-zero.
Syntax
OR(<expr1>, <expr2>, ...)
Example
V One Is True = OR(0, 3 > 2, 10 == 11) # returns 1
TRUE
Returns 1.
Mathematical functions
Some math functions may return NaN (not a number) for invalid inputs.
ABS
Absolute value.
Syntax
ABS(<expr>)
Example
V Change = ABS(-100) # returns 100
ACOS
Arc cosine in radians.
Syntax
ACOS(<expr>)
ASIN
Arc sine in radians.
Syntax
ASIN(<expr>)
ATAN
Arc tangent in radians.
Syntax
ATAN(<expr>)
CEILING
Rounds up to the nearest multiple of <significance> (default 1).
Syntax
CEILING(<expr>, <significance>)
Example
V Value = CEILING(44.2, 10) # returns 50
V Value = CEILING(2.5, 1) # returns 3
COS
Cosine of an angle in radians.
Syntax
COS(<expr>)
COSH
Hyperbolic cosine.
Syntax
COSH(<expr>)
E
Returns the value of e (2.718281828…).
EXP
Returns e raised to the given power.
Syntax
EXP(<expr>)
FLOOR
Rounds down to the nearest multiple of <significance> (default 1).
Syntax
FLOOR(<expr>, <significance>)
Example
V Value = FLOOR(112.7, 10) # returns 110
V Value = FLOOR(112.7) # returns 112
FRAC
Returns the fractional part of a number.
Syntax
FRAC(<expr>)
Example
V Population = FRAC(40.9) # returns 0.9
INT
Rounds down to the nearest integer (toward negative infinity).
Syntax
INT(<expr>)
Example
V Population = INT(40.9) # returns 40
LN
Natural logarithm.
Syntax
LN(<expr>)
LOG10
Base-10 logarithm.
Syntax
LOG10(<expr>)
MOD
Modulus (remainder after division).
Syntax
MOD(<expr>, <divisor>)
Example
V Remainder = MOD(8, 3) # returns 2
V Remainder = MOD(-1, 10) # returns 9
NAN
Returns NaN (not a number).
PCT
Converts a fraction to a percentage (multiplies by 100).
Syntax
PCT(<expr>)
Example
V Profitability = PCT(0.34) # returns 34
PI
Returns π (3.14159…).
ROUND
Rounds to a specified number of digits. If <num_digits> is omitted, rounds to nearest integer.
Syntax
ROUND(<expr>, <num_digits>)
Example
V Value = ROUND(2.15, 1) # returns 2.2
V Value = ROUND(45.7, -1) # returns 50
ROUNDDOWN
Rounds toward zero to a specified number of digits.
Syntax
ROUNDDOWN(<expr>, <num_digits>)
ROUNDUP
Rounds away from zero to a specified number of digits.
Syntax
ROUNDUP(<expr>, <num_digits>)
SAFEDIV0
Divides <expr1> by <expr2>; returns 0 if <expr2> is 0.
Syntax
SAFEDIV0(<expr1>, <expr2>)
SAFEDIVX
Divides <expr1> by <expr2>; returns <expr3> if <expr2> is 0.
Syntax
SAFEDIVX(<expr1>, <expr2>, <expr3>)
SIGN
Returns 1 if positive, 0 if zero, -1 if negative.
Syntax
SIGN(<expr>)
SIN
Sine of an angle in radians.
Syntax
SIN(<expr>)
SINH
Hyperbolic sine.
Syntax
SINH(<expr>)
SQRT
Square root. Returns NaN for negative inputs.
Syntax
SQRT(<expr>)
Example
V Root = SQRT(1000000) # returns 1000
TAN
Tangent of an angle in radians.
Syntax
TAN(<expr>)
TANH
Hyperbolic tangent.
Syntax
TANH(<expr>)
TRUNC
Truncates to an integer by removing the fractional part.
Syntax
TRUNC(<expr>)
Example
V Truncated = TRUNC(45.764) # returns 45
V Truncated = TRUNC(-8.9) # returns -8
Time functions
Time functions return values that change with each step or depend on values over time.
ACCUM
Accumulates <value> for each time step. If <init> is omitted, uses the first argument as the initial value.
Syntax
ACCUM(<value>, <init>)
Example
V Cumulative Sales = ACCUM(1, 100)
# Step 0: 100, Step 1: 101, Step 2: 102
ACCUMPERIOD
Returns the cumulative amount of <expr> over a <period> of steps, with optional <offset> and <initialvalue>.
Syntax
ACCUMPERIOD(<expr>, <period>, <offset>, <initialvalue>)
DELAY
Delays <input> by <delaytime> steps. Quantities in the pipeline are conserved even if the delay time changes.
Syntax
DELAY(<input>, <delaytime>, <initialvalue>)
Example
V Two Step Delay = DELAY(5, 2, 0)
# Step 0: 0, Step 1: 0, Step 2: 5, Step 3: 5
DELAYSTATE
Returns the internal state of a delay variable. <state_subscript> 1 returns the current output, 2 returns the next upcoming output, etc.
Syntax
DELAYSTATE(<delayed_variable>, <state_subscript>)
DERIVN
Returns the Nth order derivative of <input>. Defaults to first order.
Syntax
DERIVN(<input>, <order>)
ENDSTEP
Returns the final step number of the simulation (0-based).
Example
M StartTime = 2010
M EndTime = 2020
V Last Step = ENDSTEP # returns 10
ENDTIME
Returns the EndTime property value.
FORECAST
Returns a forecasted future value based on <input>, an <averagingtime>, and a <futuretime>.
Syntax
FORECAST(<input>, <averagingtime>, <futuretime>, <initial>)
HIVAL
Returns the highest value seen since the start of the simulation.
Syntax
HIVAL(<expr>)
IMMEDIATE
Returns the current user-entered value of a decision even when ExecuteDecisionImmediately is false.
Syntax
IMMEDIATE(<decision>)
INITIAL
Stores and always returns the initial value of an expression.
Syntax
INITIAL(<expr>)
Example
V Initial Sales = INITIAL(10 + STEP)
# Returns 10 at every step
INTERVALCOUNT
Counts steps where <expr> is within [<lowval>, <hival>]. Optional <includeHiVal> argument controls whether the upper bound is inclusive.
Syntax
INTERVALCOUNT(<expr>, <lowval>, <hival>, <includeHiVal>)
LOVAL
Returns the lowest value seen since the start of the simulation.
Syntax
LOVAL(<expr>)
NONNEGATIVE
Used as the third argument to STOCK to force a stock to always be zero or positive.
PREVIOUS
Returns the value from the previous step. <initvalue> is the value returned at step 0.
Syntax
PREVIOUS(<expr>, <initvalue>)
Example
V Sales = PREVIOUS(Sales * 1.1, 100)
# Step 0: 100, Step 1: 110, Step 2: 121
PULSE
A periodic pulse starting at <first> and repeating every <interval>. Pulse amount is <volume> / timestep.
Syntax
PULSE(<volume>, <first>, <interval>)
RAMP
Returns 0 before <starttime>, then increases with <slope> per time unit until <stoptime>, then holds constant.
Syntax
RAMP(<slope>, <starttime>, <stoptime>)
Example
V Steady Growth = RAMP(1, 1, 3)
# Step 0: 0, Step 1: 0, Step 2: 1, Step 3: 2, Step 4: 2
REMEMBER
Reads and stores a value from <inputstream> whenever <condition> is true.
Syntax
REMEMBER(<condition>, <inputstream>, <initvalue>)
SAMPLE
Periodically samples and holds a value from <inputstream>.
Syntax
SAMPLE(<inputstream>, <first>, <interval>, <initial>)
STEP
Returns the current step number (0-based).
SMOOTH
Returns an exponential smooth of <input>.
Syntax
SMOOTH(<input>, <delaytime>, <order>, <initial>)
Example
V Perceived Value = SMOOTH(10, 2, 1, 0)
# Step 0: 0, Step 1: 5, Step 2: 7.5, Step 3: 8.75
STARTTIME
Returns the StartTime property value.
STEPCHANGE
Returns 0 before <starttime>, then <height> from that step onward.
Syntax
STEPCHANGE(<height>, <starttime>)
STOCK
Accumulates flows. Equivalent to a system dynamics stock. If NONNEGATIVE is passed as the third argument, the stock is always forced to zero or positive after each step.
Syntax
STOCK(<flow>, <initialvalue>, <nonnegative>)
Example
V Inventory = STOCK(5, 100)
# Step 0: 100, Step 1: 105, Step 2: 110
V Inventory = STOCK(-10, 0, NONNEGATIVE)
# Step 0: -10, Step 1: 0, Step 2: 0
TIME
Returns the current simulation time.
TIMECYCLE
Returns 1 for <duration> steps every <interval>, starting at <first>; returns 0 otherwise.
Syntax
TIMECYCLE(<first>, <interval>, <duration>)
TIMESTEP
Returns the TimeStep property value.
TREND
Returns the relative change in <input> per time unit.
Syntax
TREND(<input>, <averagingtime>, <initial>)
Financial functions
ARRAYIRR
Internal Rate of Return for an array of cash flows. If multiple valid IRR values exist, returns the one closest to <guess> (default 0.2).
Syntax
ARRAYIRR(<cash_flow_array>, <guess>)
Example
V IRR = ARRAYIRR({-100, 30, 30, 30, 30, 30}) # returns 0.15
ARRAYNPV
Net Present Value for an array of cash flows at a given discount <rate>.
Syntax
ARRAYNPV(<cash_flow_array>, <rate>)
Example
V NPV = ARRAYNPV({-100, 30, 30, 30, 30, 30}, 10%) # returns 12.48
FV
Future Value. <type> 0 = payment at start of period (default), 1 = end of period.
Syntax
FV(<rate>, <nper>, <pmt>, <pv>, <type>)
Example
V Future Value = FV(10%, 3, -1000, 100, 0) # returns 3176.90