# Formulas

Quadratic allows you to work with classic spreadsheet logic, including math operations, referencing cells, and writing formulas.

# Cells

Quadratic gives you the ability to write formulas on multiple lines using the built-in code editor. No more massive, single-line, indecipherable formulas!

## Referencing individual cells

To reference an individual cell, use the traditional `A1`

spreadsheet notation. Negative numbers start at `n1`

and count up while negative letters start at `nA`

and count to the left. For example:

Formula notation |
coordinate plane equivalent |

`A0` | `(0, 0)` |

`A1` | `(0, 1)` |

`B1` | `(1, 1)` |

`An1` | `(0, -1)` |

`nA1` | `(-1, 1)` |

`nAn1` | `(-1, -1)` |

## Referencing a range of cells

To reference a range of cells, use the traditional spreadsheet notation that separates two distinct cells using a semicolon as a delimiter, e.g. `A1:D3`

# Operators

Quadratic’s formula language supports the following operators:

Precedence | Symbol | Description |

1 | `x%` | Percent (divides by 100) |

2 | `+x` | Positive |

`-x` | Negative | |

3 | `a:b` | Cell range |

4 | `a..b` | Numeric range |

5 | `a^b` or `a**b` | Exponentiation |

6 | `a*b` | Multiplication |

`a/b` | Division | |

7 | `a+b` | Addition |

`a-b` | Subtraction | |

8 | `a<<b` | Bitshift `a` to the left by `b` |

`a>>b` | Bitshift `a` to the right by `b` | |

9 | `a&b` | |

10 | `a=b` or `a==b` | Equal comparison |

`a<>b` or `a!=b` | Not-equal comparison | |

`a<b` | Less-than comparison | |

`a>b` | Greater-than comparison | |

`a<=b` | Less-than-or-equal comparison | |

`a>=b` | Greater-than-or-equal comparison |

Exponentiation is right-associative, so `a^b^c`

is the same as `a^(b^c)`

. All other binary operators are left-associative, so `a-b-c`

is the same as `(a-b)-c`

.

# Functions

Quadratic supports a number of functions commonly used in spreadsheets, with more soon to be added.

## Mathematics functions

Function | Description |

`SUM(a, b, ...)` | Adds all values.
Returns `0` if given no values. |

`PRODUCT(a, b, ...)` | Multiplies all values.
Returns `1` if given no values. |

## Statistics functions

Function | Description |

`AVERAGE(a, b, ...)` | Returns the arithmetic mean of all values. |

`COUNT(a, b, ...)` | Returns the number of nonempty values. |

`MIN(a, b, ...)` | Returns the smallest value. Returns +∞ if given no values. |

`MAX(a, b, ...)` | Returns the largest value.
Returns -∞ if given no values. |

## Logic functions

These functions treat `FALSE`

and `0`

as “falsey” and all other values are “truthy.”

When used as a number, `TRUE`

is equivalent to `1`

and `FALSE`

is equivalent to `0`

.

Function | Description |

`TRUE()` | Returns `TRUE` . |

`FALSE()` | Returns `FALSE` . |

`NOT(a)` | Returns `TRUE` if `a` is falsey and `FALSE` if `a` is truthy. |

`AND(a, b, ...)` | Returns `TRUE` if all values are truthy and `FALSE` if any value is falsey.
Returns `TRUE` if given no values. |

`OR(a, b, ...)` | Returns `TRUE` if any value is truthy and `FALSE` if any value is falsey.
Returns `FALSE` if given no values. |

`XOR(a, b, ...)` | Returns `TRUE` if an odd number of values are truthy and `FALSE` if an even number of values are truthy.
Returns `FALSE` if given no values. |

`IF(cond, t, f)` | Returns `t` if `cond` is truthy and `f` if `cond` if falsey. |

## String functions

Function | Description |

`CONCAT(a, b, ...)` | Concatenates all values as strings. |

# Arrays

An array can be written using `{}`

, with `,`

between values within a row and `;`

between rows. For example, `{1, 2, 3; 4, 5, 6}`

is an array with two rows and three columns:

1 | 2 | 3 |

4 | 5 | 6 |

Arrays cannot be empty and every row must be the same length.

Numeric ranges (such as `1..10`

) and cell ranges (such as `A1:A10`

) also produce arrays. All operators and most functions can operate on arrays, following these rules:

- Operators always operate element-wise. For example,
`{1, 2, 3} + {10, 20, 30}`

produces`{11, 22, 33}`

. - Functions that take a fixed number of values operate element-wise. For example,
`NOT({TRUE, TRUE, FALSE})`

produces`{FALSE, FALSE, TRUE}`

. - Functions that can take any number of values expand the array into individual values. For example,
`SUM({1, 2, 3})`

is the same as`SUM(1, 2, 3)`

.

When arrays are used element-wise, they must be the same size. For example, `{1, 2} + {10, 20, 30}`

produces an error.

When an array is used element-wise with a single value, the value is expanded into an array of the same size. For example, `{1, 2, 3} + 10`

produces `{11, 12, 13}`

.