Date and time arithmetic

Date values and calculations are supported in Blockpad formulas.

Enter a date

To enter a date in a formula, is the basic syntax. However, the month or day can be typed in as one digit.

For example, the date January 3rd, 1892 is typed in as 1892.01.03 . You can also enter a date using the Date() function. Our example above would be Date(1892,1,3).

Enter a date and time of day

You can type in a date and time, where is the syntax. With this, military time must be used for p.m. times.

Seconds, minutes, or hours can be left off the end, but year, month, and date must all be specified. Otherwise, Blockpad will see a regular number with a decimal.

Date and time calculations

You can perform basic calculations with date values and numbers with time units. So, a date value subtracted from a date value gives a time number.

Also, a time number added to or subtracted from a date value gives a date value.

Logic and Boolean values

Blockpad supports logic tests and functions like normal spreadsheets.

The main difference between normal spreadsheets is that two equals signs are used to test equality. Other than that, it's the same.

  • == equal to
  • != not equal to
  • < less than
  • > greater than
  • <= less than/equal to
  • >= greater than/equal to

You can reference values like normal, and use logic functions like if().

You can also type Boolean values (true or false) directly into a formula.

If multiple tests are used in a row, then all of them must be true separately to yield true.

This is the same as using the And() function on each test separately.

Matrices and arrays

Blockpad dynamic equations support arrays and matrices. Many of the built-in functions are matrix compatible as well.

Enter an array or matrix

To create an array in a formula, brackets are used. Brackets ([ ]) specify the start and end of the array. Commas (,) separate members of one row into columns, and semi-colons (;) specify the end of a row. For example, [11, 22, 33; 22, 33, 11; 33, 11, 22] typed into a formula produces the matrix below.

In Blockpad, arrays and references to groups of cells are treated the same. So, arrays can be created by referencing a group of cells from a spreadsheet or table. In this case, the array will update with the table.

Array names

Array values can have names, just like normal number and text values.

Matrix calculations

To add, subtract, divide, and multiply matrices, the normal operators are used (+, -, /, *).

To find the inverse of a matrix, you can raise it to negative one (^-1) or use the inverse function.

If a matrix calculation can't be completed, then you will get an error.

Matrices also support units and unit tracking

Functions work with arrays too. Some treat the array like a group of spreadsheet cells.

And some treat the array as a matrix.

Arrays - more than just numbers

Arrays can have any type of values: text, numbers, even more arrays - anything that can go in a spreadsheet cell and a little more.

A useful application is to use lookup functions with arrays, just like using them with a spreadsheet.

Array formulas in spreadsheets

Arrays can be displayed in a spreadsheet too.

Make an array formula:
  1. Type in a formula that results in an array.
  2. Press ctrl+shift+enter instead of enter to complete the formula.

Now when you try to edit any cell in the array, you are prompted to edit the array formula. However, you can still reference the cells like normal.

If there are non-empty cells that an array formula tries to fill, then the formula still runs, but a red line appears to let you know it didn't fill all of the cells.

Array parentheses lookup

You can reference the values inside of an array using parentheses after the array name. The basic synax is ArrayName(RowNumber, ColumnNumber).

If you give just one number in the parentheses, then it specifies a row. You can specify a column by typing an asterisk for the row. This works to specify just a row too, just put an asterisk for the column.

Advanced array functions

There are a number of useful functions to work with arrays, most of them in the scripts library (Library.Scripts), which isn't automatically included in Blockpad files. To access them, you need to use the long form library name, create a shortcut name, or include the library in the file.

In these examples, the scripts library is included in the file, so below are instructions for how to do so.

Include the scripts library:
  1. In the toolbar, select Libary>Include Libraries.
  2. Click Add in the window that appears.
  3. Select Scripts.
  4. Click Ok.
  5. Click Close to exit the include libraries window.

Below we cover the following functions:

LinearSeries() Creates a one dimensional array given start, end, and interval.
Identity() Returns an indentity matrix given the size.
Each() Performs a function on each item in an array.
EachRow() Performs a function on each row in an array.
EachColumn() Performs a function on each column in an array.
Where() Returns a one dimensional array of items that meet provided criteria.
First() Returns the first item from an array that meets the provided criteria.
Last() Returns the first item from an array that meets the provided criteria.
ConcatRows() Combines arrays by vertical stacking.
ConcatColumns() Combines arrays by horizontal stacking.
ConcatItems() Combines arrays into a one-dimensional array.
Use LinearSeries() and Identity()

LinearSeries() is relatively straightforward. Specify the start of the array, the end of the array, and the interval of the steps between.

Identity() is even easier. Just specify the size (n) of the matrix, and the function will create an n x n identity matrix.

Using the Each() function.

The Each() function performs a specified function on each item in an array, and then returns that as a new array. It looks like this: Each(Array, In-line function to perform).

In the example above, each item in array A_4 is squared. Notice the in-line function. For Each() (and many other array formulas), the in-line function follows this form nameForItem => formula using nameForItem. Note that you name the nameForItem, so the example below works the same as the example above.

Below is another example. Notice that outside values can be used in the function, in this case Pressure.

EachRow() and EachColumn() are similar to the Each() function, but they work on rows and columns instead of individual items. The set up is the same, including the use of in-line functions, but the in-line function is working on a one-dimensional array (the row or column).

Note that because EachRow() and EachColumn() act on the rows/columns as arrays, the output can be an array of arrays, as in the example below.

Using Where(), First(), and Last().

Where(), First(), and Last() are used to find specific values in an array, and they all follow the same pattern. First let's look at Where(), the most general.

Where() finds all of the items in an array that meet a criteria, and returns them in a one dimensional array. It looks like this: Where(Array, Criteria function).

The criteria function typically consists of just a boolean operator (==, >, <, <=, or >=) and a value.

This is actually short hand for an in-line function (like talked about above). You can also specify criteria using the form nameForItem => formula using nameForItem. Where the formula has a boolean result. The examples below do the same thing as those above.

Most of the time you don't need this, but it allows more functionality. In the example below, the Where() function is used to filter out non-length units.

The First() and Last() functions are like the Where() function, but return a single value instead of an array. It's like if you performed the Where() function and then kept only the first (or last) value from the array.

You can also use First() and Last() without the criteria. They just return the first or last value from the array.

Using ConcatRows(), ConcatColumns(), and ConcatItems()

ConcatRows() and ConcatColumns() are used to combine arrays by stacking the rows or columns.

ConcatItems() combines arrays by putting all items into a single one-dimensional array.

Complex numbers

Blockpad supports complex numbers in a very simple way. Simply use the letter i to denote the imaginary number inside of a formula/dynamic equation. The square root of a negative number will also produce i.

Table of Contents