---
title: Expressions
---

Fzzy Config contains a math evaluation engine. It can be used to evaluate a wide array of basic math expressions with variable support, <a target="_blank" rel="noopener" href="https://fzzyhmstrs.github.io/fconfig/-fzzy%20-config/me.fzzyhmstrs.fzzy_config.util/-expression/index.html">see the documentation 🗗</a> for details. Expressions can be chained and nested, and variables are supported via the use of Character placeholders ('x', 'y', etc.)

## Creating an Expression
The basis of an `Expression` is a string representation of the math equation you want evaluated. This string is parsed into an `Expression` with `parse()`. Variable values are provided at evaluation time, see below.

<CodeTabs>

```java !!tabs Java
String math = "(x + 5) ^ 2 + x";
Expression mathExpression = Expression.parse(math);
```

```kotlin !!tabs Kotlin
val math = "(x + 5) ^ 2 + x"
val mathExpression = Expression.parse(math)
```

</CodeTabs>

## Evaluating an Expression
Once you have your expression, outputs are evaluated by passing replacement values for each placeholder character into the `eval` or `evalSafe` (recommended) methods.

<CodeTabs>

```java !!tabs Java
Map mathMap = Map.of('x', 2.5);
double mathResult = mathExpression.evalSafe(mathMap, 20.0); // evalSafe fails soft with a fallback value. eval throws exceptions if there is a problem.
```

```kotlin !!tabs Kotlin
val mathMap = mapOf('x' to 2.5)
val mathResult = mathExpression.evalSafe(mathMap, 20.0) // evalSafe fails soft with a fallback value. eval throws exceptions if there is a problem.
```

</CodeTabs>