At the heart of Silico are formulae, allowing you to define values and relationships between elements.

# Syntax

Formulae support normal mathematical syntax for defining equations.

## Arithmetic

### Addition, Subtraction, Multiplication

4 + 5

2 - 5

5 * 7

### Division

Divison is treated specially, in that if you divide by zero the result is also zero. This aligns with the error handling approach of Silico, and will in a future release raise an error in the formula as any other formula error.

Silico also supports integer division through the // operator, which gives a whole number division result.

5 / 6

7 // 2

### Exponents

Raise one number to the power of another.

2 ^ 3

## Conditionals

Frequently you will want to define a condition, such as different behaviour before a certain time, or when another value crosses a threshold. Silico supports two conditional constructs in if/then/else, and select.

### If/Then/Else

If you just need to choose between two options, then if/then/else can be used to select based upon a condition. The condition (between if and then) should be a comparison, but if a number is used then this is equivalent to checking if it is not-zero for the 'then' branch of the conditional.

if <condition>

then <when true>

else <when false>

if 6 > 5 then 1 else 2

### Select

If you have a series of conditions that may give rise to several different answers, then the select syntax is useful. The first condition which evaluates as true (or non-zero) will give the result of the select. Note that you can have any number of cases but must have a default statement. If a default statement is missing, then the select will default to a value of zero, and an error will be highlighted in the formula.

select case <condition a>: <when a true> case <condition b>: <when b true> ... default: <when none true> select case "time" < 30: 1 case "time" < 50: 2 default: 3

### Comparison Operators

Comparison operators let you compare two values.

- Greater Than:
`>`

- Greater Than or Equal:
`>=`

- Less Than:
`<`

- Less Than or Equal:
`<=`

- Equal:
`=`

if 6 > 5 then ...

if 6 <= 7 then ...

if 3 = 3 then ...

Comparisons should generally only be used in the test for an if/then/else or select. If used where a number is expected, then true will be treated as a 1, and false as a 0.

### Logical Operators

Logical operators let you combine comparisons together.

- And:
`&&`

/`and`

- Or:
`||`

/`or`

- Not:
`!`

/`not`

if 6 > 5 and 4 < 5 then ...

if not(5 > 6) then ...

# Using Functions

Silico has a large number of builtin functions that can provide functionality beyond simple arithmetic. When calling these functions, you use the name, then any arguments between parentheses, separated by commas.

ramp(5 + 7)

Please see the Functions page for a full listing of functions in Silico.

# Referencing Elements

## Variables, Stocks and Flows

When referencing elements in the same panel, you use the name of the element inside double quotes to refer to its value. The formula editor will auto-complete when a double-quote is typed, and give suggestions that are then narrowed based on any entered text. The entered text does not necessarily need to be at the start of the desired elements name, it can be anywhere within the name.

"Variable 1" + "Stock 2"

## Lookup Tables

Lookup tables can be thought of as a function taking a single argument, the value to lookup in the table. Along these lines, the syntax for lookup tables treats them just like a function.

"Lookup Table"(5)

## Panels

Panels can be used to break up a model into smaller pieces. Elements within a Panel are namespaced, that is, you don't need to worry about names in one panel being the same as elements in another panel. To reference elements in a panel, you first reference the panel by name, and then "point into" an element inside, using the arrow operator. The formula editor will autocomplete both the panel name and elements within.

"My Panel"->"My Variable"

## Submodels

Similarly to Panels, you can reference elements inside a Submodel using the arrow operator. As a submodel itself may contain panels and other submodels, you can do this multiple times, to walk down through the submodel and panels to the element you wish to reference.

"My Submodel"->"Inner Panel"->"Element"

# Errors

Silico will try its best to interpret formulae, even when incomplete. This means that even when a formula contains an error, it may still return you value you expect. These errors are highlighted and reported in the interface through the elements in the workspace as well as the inspector and formula editor. When parts of a formula cannot be understood, they will be highlighted, and treated as a 0 value when calculating the formula.

## Comments

0 comments

Please sign in to leave a comment.