Formulas
Overview
Just as in a spreadsheet, Quantum4D provides support for various mathematical functions through its formula system. There are two ways to create a formula in Quantum4D:
- Create an attribute of type formula
- Map a lens feature to a formula
Both function the same way, using the same formula editor.
Editing a Formula
A formula consists of zero or more variables and an expression. Variables can be added or removed in the table at the top of the formula editor. These variables can be mapped to attributes and are defined using a naming convention similar to a spreadsheet column (“a,” “b,” “c,” etc.).
The expression is a general mathematical expression using the given variables, parentheses, and mathematical operators. Clicking the “Show Functions” button displays a short list of the operators and functions that are recognized by Quantum4D.
When you are finished editing your formula, be sure to click on the “Apply” button to apply any changes you have made. While editing, you can abort any changes you may have made since the last “Apply” by clicking on the “Reset” button.
Types
The formula system has built-in support for a variety of types:
- Floating-point numerical types
- Integers
- Dates
- Boolean values, including the predefined values true and false
- Strings
- The predefined value null
- Lists, defined using [] syntax
- Ranges of dates or numbers, defined using the operators x:y and x::y,,step
- Time series
- Moving Correlation & Covariance
Any of the above can be returned from the result of a formula. Lens settings may rely on being mapped to a particular type and may perform implicit conversion to interpret the result as the expected type. In general, the animation engine depends on time series results in order to determine what should be displayed in the 3D scene.
Examples
Suppose you have an attribute called “Price” that is a time series representing the price of a commodity, containing data for January 1, 2001 through December 31, 2003. For the same time period, suppose you also have an attribute called “Quantity.”
Now supposed you want to map “X Position” as a formula representing the “Total Value,” as defined simply by “Price” times “Quantity.” To create this formula in Quantum 4D, you:
- Double-click on “X Position” in the lens settings panel
- Click on the “From Formula” button
- Click on “Add” to add the variable “a”
- Click on the drop-down under the “Attribute” column for the new variable “a”, and select “Price”
- Click on “Add” to add the variable “b”
- Click on the drop-down for “b” and select “Quantity”
- In the “Formula” box, type in the expression: a*b
- Optional: click on “Evaluate…” to see the current value of your formula
- Click on “Apply” to map the X Position to the new formula
Here are some other sample formulas:
a*b+13
(a-3)/2
round(a) : Round a to the nearest whole number
if(a<13,4,100) : If a is less than 13, use the value 4, otherwise use the value 100
chg(a, “Nov 1, 2001”) : Change in value since November 1, 2001
sum(attributes(“Quant*”)) : The sum of all attributes with names starting with “Quant”
get(a, “Nov 1, 2001”) : The value of the attribute at November 1, 2001