# Stable Math

First introduced by Curve, the Stableswap is a hybrid algorithm, to bring solution to the problems of slippage and fixed liquidity. The Stableswap hybrid combines both **Constant Product** and **Constant Sum** models, and the following chart shows the Stableswap algorithm in relation to constant product and constant sum invariants.

The *amplification parameter*, $$A$$, defines the degree to which the Stable Math curve approximates the Constant Product curve (when $$A=0$$), or the Constant Sum curve (when $$A\rightarrow \infty$$).&#x20;

![](https://802879058-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FPkaSidqhw1DICqd2KNcD%2Fuploads%2F5X54VrId3G3UcnfyCYER%2Fimage.png?alt=media\&token=b7ab16f3-0a8a-4b46-8725-f839c1a94813)

* **Constant Sum:** When the liquidity pool portfolio is balanced, the algorithm functions as a Constant Sum formula; **x + y = k**. You can observe the StableSwap ***blue line*** staying close to the Constant Sum ***red line***, and the price is stable.
* **Constant Product:** As the liquidity pool portfolio becomes imbalanced, the StableSwap algorithm functions as a Constant Product formula; **x \* y = k**. You can observe the StableSwap ***blue line*** now resembling the Constant Product ***purple line***, and the price becoming expensive.

### Invariant

Since the Stable Math equation is quite complex, determining the invariant, $$D$$, is typically done iteratively.

$$
A \cdot n^n \cdot \sum{x\_i} +D = A \cdot D \cdot n^n + { \frac{D^{n+1}}{{n}^{n}\cdot \prod{x\_i} } }
$$

Where:

* $$n$$ is the number of tokens
* $$x\_i$$ is is balance of token $$i$$
* $$A$$ is the amplification parameter
