> For the complete documentation index, see [llms.txt](https://doc.verteego.com/verteego-doc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.verteego.com/verteego-doc/pipelines/forecasting-pipelines/calculators/mathematic/mathematical_expression.md).

# mathematical\_expression

Computes a mathematical expression between multiple columns.

## Usage

{% hint style="info" %}
Compute a mathematical expression between multiple columns as multiplication, addition, division;
{% endhint %}

This calculator can be used with the following method:

<mark style="color:red;">**`mathematical_expression`**</mark>

Examples:

* computing a boolean variable 'flag' with a float quantity in order to set my quantity variable to 0 based on the values of my flag
* Add a constant to a predicted variable

***

## Main Parameters

{% hint style="success" %}
**The bold options** represent the default values when the parameters are optional.
{% endhint %}

* *<mark style="color:blue;">input\_columns</mark>* \
  list of columns used as input of the calculators
* *<mark style="color:blue;">output\_columns</mark>* \
  list of columns added by the calculators
* *<mark style="color:blue;">global</mark>* *(true, **false)*** \
  Should this calculator be performed before data splitting during training for cross-validation
* *<mark style="color:blue;">steps</mark>* \[optionnal] *(**training, prediction**, postprocessing*)\
  List of steps in a pipeline where columns from this calculator are added to the data. Note that when the training option is listed, the calculator is actually added during preprocessing.
* *<mark style="color:blue;">store\_in\_model</mark>* \[optionnal] *(true, **false)*** \
  Please indicate whether the "calculated" columns by the calculator should be stored in the model or not to avoid recalculating them during prediction. This is only relevant if the calculated columns are added to both training and prediction. Without this parameter, the values will not be stored in the model. The following parameters only make sense if this parameter is set to *true*.
* *<mark style="color:blue;">stored\_columns</mark>* \[required if *store\_in\_model is true*] \
  List indicating the columns to be stored among the *<mark style="color:blue;">output\_columns</mark>*.
* *<mark style="color:blue;">stored\_keys</mark>* \[required if *store\_in\_model is true*] \
  List indicating the columns to use for identifying the correct values to join on the data for prediction among the stored values (logically, they are to be chosen from the *input\_columns*).

***

## Specific Parameters

* *<mark style="color:blue;">expression</mark>*\
  (+, -, \*, /, //, %, >, >=, <, <=, ==, !=) \
  You can compose your expression with operators (+, -, \*, /, //, %, >, >=, <, <=, ==, !=), column names, constants, parenthesis, white spaces.

***

## Examples

1.

````
```yaml
````

````
calculated_cols:
  add_a_b_minus_c_divided_by_3:
    method: mathematical_expression
    input_columns:
    - a
    - b
    - c
    output_columns:
    - add_a_b_minus_c_divided_by_3
    params:
      expression: (a + b - c) / 3
```
````

2\.  Imagine we want to tag the begin and the end of the month (salary day). Here we tag from the day 1 to 7 of the month and from 24 to 30/31. The input column `day` is provided by calulator [`date_attributes`](/verteego-doc/pipelines/forecasting-pipelines/calculators/temporal/date_attributes.md)

````
```yaml
calculated_cols:  
  tag_begin_end_of_month_feat:
    method: mathematical_expression
    input_columns:
    - day
    output_columns:
    - tag_salary_days
    params:
      expression: (day < 8) + (day > 23)
```
````
