This article was automatically translated from Japanese using AI. The Japanese version is the authoritative version.
Bonsai is widely used for designing experiments in neuroscience and beyond.
With Bonsai you can build sophisticated programs without writing code, and run them with precise synchronization.
Because it is so simple, however, operations that would be trivial in ordinary programming—such as basic arithmetic—have to be done in a somewhat unintuitive way.
Here I explain how to perform arithmetic operations, using MouseMove as an example.
Below are the arithmetic operations in action: from top to bottom, addition, subtraction, multiplication, and division.

For clarity, I used the X and Y values from MouseMove as an example here.
In practice, though, you can perform calculations on values obtained from other sensors and the like.
The key point in Bonsai is that you need to combine the two values with “Zip” before performing the operation.

The contents of “Zip” take the form (value 1, value 2); its role is to bundle the two values at that moment into one.
Each operation then computes value 1 and value 2 together.
It is hard to explain in words, so try to get a rough intuition for it.
Without “Zip”, the program would not know which value to multiply with which, so the calculation could not be performed. That is why the X and Y values must first be combined so that they correspond to each other.
The names of the operators for each arithmetic operation are listed below.
- Addition => Add
- Subtraction => Subtract
- Multiplication => Multiply
- Division => Divide
I have included a demonstration below for your reference.
