# mathBlock

The *mathBlock* (also known as *formula calculation block or FCB*) lets you to define calculations on document data in mathematical notation to be performed directly, without the need or optionally with limited use of coding.

<figure><img src="/files/Q6biShw5n9aVf7ET9QKf" alt=""><figcaption></figcaption></figure>

## 1.1 Properties

|               |                                                                                             |                       |
| ------------- | ------------------------------------------------------------------------------------------- | --------------------- |
| Input Schema  | The input document schema.Required                                                          | Net\_ERR\_Calculation |
| Output Schema | The output (results) document schema. Optional. If not specified, the input schema is used. | Net\_ERR\_Calculation |
| Unsigned VC   | Allows the use of a simple JSON document as input (no VC-style proofs required)             | Checked/Unchecked     |
| Expression    | The set of formulas and commands executed at policy runtime.                                | formulas defined      |

## 1.1.1 Expression definition

Expression definition is guided by a wizard with in-place test execution, allowing policy authors to define formulas and the data they apply to at policy runtime. It includes the following sections:

#### 1. Inputs

Use this section to map fields from the input document to short variable names that you can reference in formulas.

<figure><img src="/files/WrLMxSwnLVqEDvJOsEac" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/SSAxeffGlIIshgC0EAJr" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
**Note 1**: A variable in a formula may reference data from any field in any document, not just the input document itself. However, the referenced document must be associated with the input document (i.e. be part of its ‘relationships' chain). If no such relationship exists, the value cannot be resolved at runtime, which may lead to unpredictable or undefined behavior.
{% endhint %}

{% hint style="info" %}
**Note 2**: Source documents are located based on schema matching. If multiple related documents match the required schema, the system selects the nearest (most recent) document in the relationships chain as the data source.
{% endhint %}

### 2. Formulas

This section provides UI to defined formulas using standard mathematical notation and/or LateX or MathJSON formats.

<figure><img src="/files/25sHhaYdfSlPqCFbFzD2" alt=""><figcaption></figcaption></figure>

**2.1 Formula definition**

To define a formula, complete the following steps:

* Specify the formula name.
* Add () after the formula name and list any parameters inside. Separate parameters with a comma (,).

<figure><img src="/files/CjhIJFfQrHQpbkAkz6bK" alt=""><figcaption></figcaption></figure>

* Create the expression using math notation or an alternative format (LaTeX, MathJSON).

<figure><img src="/files/JJoBdPDzVjXTABQLkC4r" alt=""><figcaption></figcaption></figure>

In some cases, switching between math notation, LaTeX, and MathJSON can help you verify or correct a formula. You can edit in any format; the system automatically synchronizes changes across formats.

<figure><img src="/files/WZdBG1czv2fvE3NFMQ18" alt=""><figcaption></figcaption></figure>

You can reuse defined formulas in other formulas (by name) and in the code on the Advanced tab.

{% hint style="success" %}
**Note**: Not all commands supported in math notation are represented correctly in LaTeX. In LaTeX view, unsupported commands may appear as plain strings. For the complete list of commands supported by Guardian in math notation, see the MathLive Compute Engine standard library documentation: <https://mathlive.io/compute-engine/standard-library>
{% endhint %}

{% hint style="success" %}
**Note**: Avoid using i for indices, as it may be interpreted as the imaginary unit and lead to unexpected results
{% endhint %}

**2.2 Variables**

When parentheses are not included after the name (e.g., x vs. x()), it is treated as a variable definition. The variable value is calculated at initialization time.

<figure><img src="/files/8ZMi1p1NHyJ3q92TIZv5" alt=""><figcaption></figcaption></figure>

**2.3 Code (advanced)**

For complex scenarios where formulas are not sufficient for the required data transformations, use the Advanced (Optional) tab to add logic in JavaScript.

<figure><img src="/files/QSnnRCSn9X0ne98TMY1A" alt=""><figcaption></figcaption></figure>

In code, you can reference all defined formulas and variables by name.

<figure><img src="/files/pCTtRY0m6PLM8cqi7wM9" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Ak99glQmHEPRoJvrE27P" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/9oi7gLvxEsxvgkqTp3fr" alt=""><figcaption></figcaption></figure>

### 3. Outputs

Use this section to configure which document fields receive the results of calculations from the previous sections.

<figure><img src="/files/XtLxlFmKjWltpYacmYVE" alt=""><figcaption></figcaption></figure>

In this section, you can reference input/output fields and variables only. Formulas can be referenced only in the Formulas section.

<figure><img src="/files/AdxE7wzazU310BiU6nGq" alt=""><figcaption></figcaption></figure>

### 4. Tabs

For convenience Inputs\Formulas\Outputs can be visually partitioned using tabs. This partitioning has not impact on the functionality of the policy, it is used to ease UI navigation by policy authors.  

#### 4.1 Creation

<figure><img src="/files/Rle6VHMxJe2ngrPGZshf" alt=""><figcaption></figcaption></figure>

#### 4.2 Renaming

Tabs can be renamed as required.

<figure><img src="/files/QniZiWLSMEUmVXzFbuLr" alt=""><figcaption></figcaption></figure>

#### 4.3 Deletion

Tabs can be deleted.

<figure><img src="/files/4mRpnQVL5kexMHfeC80M" alt=""><figcaption></figcaption></figure>

#### 4.4 Navigation

<figure><img src="/files/HZzQ6mU6nurgDvrjeZSR" alt=""><figcaption></figcaption></figure>

### 5. Test

After you define formulas, you can validate them using the Test section. Complete the following steps:

#### a. Inputs

To begin testing, specify the main Input Document.

<figure><img src="/files/qxc85dWNL9aTEMtYxosz" alt=""><figcaption></figcaption></figure>

If required, add additional documents associated with the input document. Make sure these documents are part of the main Input Document’s relationships chain.

<figure><img src="/files/Svz9j1H2PXtPidCfghFw" alt=""><figcaption></figcaption></figure>

Provide input data in a document using one of the following three options:

* Use a form that matches the input schema.

<figure><img src="/files/s4UoxJALmCQeDvonIdDj" alt=""><figcaption></figcaption></figure>

* Provide JSON.

<figure><img src="/files/EvCDcxnwD8nWF4KwDbGa" alt=""><figcaption></figcaption></figure>

* Upload a file (the file must contain valid JSON).

<figure><img src="/files/kvXbXVs4vF9rOazgmIUf" alt=""><figcaption></figcaption></figure>

#### b. Select Test

<figure><img src="/files/EuzwyEIBYNbulU980eRu" alt=""><figcaption></figcaption></figure>

#### c. Results

Guardian displays test results for each element

<figure><img src="/files/PCmiWGz2chXVKjjhovPR" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/5TUl8yKi6pVxQM1FnjQA" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/fL4AfN6xTI7xgfg3Lm3W" alt=""><figcaption></figcaption></figure>

## 1.2 Visualization at Policy runtime

Once a policy is published, Guardian generates Formula-Linked Definitions (FLDs) for all mathBlock elements in the policy. You can explore these the same way as standard FLDs.

<figure><img src="/files/qJtvbq1i9mDDV1Jtk2nt" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Y7ouz1nSwOpZbDpVwppQ" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
**Note:** The *mathBlock* code section is not used when automatically generating FLDs and is not represented in any way in the resulting visuals.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://guardian.hedera.com/guardian/standard-registry/policies/policy-creation/introduction/mathblock.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
