# Exponentiation

## This page has been deprecated. V1 documentation is partially maintained [here](https://docs.balancer.fi/v/v1/core-concepts/protocol/index/approxing)

## Exponentiation

The main formulas used in Balancer protocol make use of a form of exponentiation where both the base and exponent are fixed-point (non-integer) values. Take for example the `swap` functions, where the weights in both the exponent and the base are fractions:

$$
A\_o = \left(1 - \left(\frac{B\_i}{B\_i+A\_i}\right)^{\frac{W\_i}{W\_o}}\right).B\_o
$$

$$
\begin{equation} \begin{gathered} A\_i = \left(\left(\frac{B\_o}{B\_o-A\_o}\right)^{\frac{W\_o}{W\_i}}-1\right).B\_i \end{gathered} \end{equation}
$$

Since solidity does not have fixed point algebra or more complex functions like fractional power we use the following binomial approximation:

$$
\begin{equation} \begin{gathered} \left(1+x\right)^\alpha=1+\alpha x+\frac{(\alpha)(\alpha-1)}{2!}x^2+ \frac{(\alpha)(\alpha-1)(\alpha-2)}{3!}x^3+ \cdots = \sum\_{k=0}^{\infty}{\alpha \choose k}x^k \end{gathered} \end{equation}
$$

which converges for $${|x| < 1}$$.

When $$\alpha>1$$ we split the calculation into two parts for increased accuracy, the first is the exponential with the integer part of $$\alpha$$ (which we can calculate exactly) and the second is the exponential with the fractional part of $$\alpha$$:

$$
\begin{equation}
\begin{gathered}
A\_i = \left(1 - \left(\frac{B\_o}{B\_o-A\_o}\right)^{int\left(\frac{W\_o}{W\_i}\right)}\left(\frac{B\_o}{B\_o-A\_o}\right)^{\frac{W\_o}{W\_i}%1}\right).B\_i
\end{gathered}
\end{equation}
$$


---

# 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://balancer.gitbook.io/balancer/core-concepts/protocol/index/approxing.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.
