# Basic Expressions & Formulas

SEL 101: Arithmetic & Text

Let's dig into a few concrete examples of events, the bits of code within them (what we call SEL formulas or expressions), and how you can use them to run simulations on your board.

## Formulas

When you create an event on a board, an event box appears, along with an input field to enter code, similar to the way you can write directly into a spreadsheet cell.

Like spreadsheet formulas, SEL is a declarative language, which means **we will use these formulas and expressions to declare the behavior of the event.**

When we declare an event's behavior, we should think of it at two points in time:

- First, how should the event behave the first time it runs.
- Second, how should it behave the next time it runs (if applicable).

Simple formulas may cause an event to behave the same way over and over, for example:

`=2+2`

An event, we'll call it Event A, with this formula will always evaluate to `4`

. If the event points to any other events, this value will be passed to those events (like cell references!).

A lot of events begin with an equals sign `=`

because the event simply needs to set a value and pass it along. However, events can also operate on values they receive from other events. So if you point Event A at an Event B, you could write an expression like so:

`/ 4`

This will divide whatever Event B receives by, you guessed it, 4. So when A sends 4 to B, B will divide it by 4, and store 1 as its own internal state. This state can then be passed along to another event.

We have a choice, then, when we create a model using SEL, as to whether we want to split a complex formula apart into its separate pieces to take advantage of labeling and a visual structure on the canvas, or if we want to collapse the formula into a single statement like:

`=(2+2) / 4`

Either way, you will get `1`

, but which path is "more correct" is up to you, and whether it's more clear to be able to label the `/ 4`

with its own title and whether you'd like to re-use the `/ 4`

. So you could also have an Event C that points to Event B and divides the output of C by four.

Code Re-use

Turning an expression as simple as

`/ 4`

into its own event may sound strange, but if`/ 4`

represents a parameter or policy of your business, there's a strong chance you'll re-use it, and labeling it can create clarity for others that may use or extend your model later.

## Numbers

SEL formulas and expressions can contain integers, decimals, positive or negative. And though many have resisted it throughout history -- we're also okay with zero.

Numbers in SEL should not contain commas, but you may use underscores `_`

to separate place values. In practice it is encouraged to write `100000`

as `100_000`

.

Because it's more natural, Summit also supports numerical abbreviations:

`K`

, `k`

, `M`

-> thousand

`MM`

, `mm`

, `m`

-> million

`B`

, `b`

-> billion

`T`

, `t`

-> trillion

For example: `1.2mm`

is shorthand for `1_200_000`

or `1200000`

.

You can also use decimals with these abbreviations, so `123.5k`

works.

Currency formatting

We love financial modeling, but you should not put currency symbols directly into your SEL expressions.

To format an event as currency, use the

`$`

option in the output table at the bottom of the screen. You'll need to have an event or row in focus for those formatting options to appear.

## Uncertainty

SEL has built-in symbols for declaring estimates and incorporating uncertainty. This is a valid formula:

`=2 + ~5`

This means two plus five, plus or minus 10%. So the answer of this formula will be somewhere between 6.5 (at a minimum) and 7.5 (maximum).

Any number in a SEL expression can be preceded by a ~ to inject this behavior.

You may also deepen this uncertainty by adding `?`

's. For example:

`=2 + ~5?`

This means two plus five, plus or minus 25%. Each `?`

represents an additional 25% variation. For example:

`=~100????`

Will translate into a random number somewhere between zero (100% less than 100) and two hundred (100% more than 100).

If you use `?`

, you must still begin the expression with `~`

.

## Text

A common first step with any programming language is learning how to print "Hello, World" to the screen.

SEL is a declarative language that primarily deals with numbers, but we still have a couple of ways to put words on the canvas! One way is by editing the event title.

Another way is using comments.

`=2+2 # Hello, World`

and:

`# Hello, World`

are both valid SEL expressions.

Updated over 1 year ago