> For the complete documentation index, see [llms.txt](https://balancer.gitbook.io/balancer-v2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://balancer.gitbook.io/balancer-v2/concepts/math/weighted-math.md).

# Weighted Math

## Overview

Weighted Math is designed to allow for swaps between any assets whether or not they have any price correlation. Prices are determined by the pool balances, pool weights, and amounts of the tokens that are being swapped.

Balancer's Weighted Math equation is a generalization of the $$x\*y=k$$ constant product formula recommended for Automated Market Makers (AMMs) in [a post by Vitalik Buterin](https://www.reddit.com/r/ethereum/comments/55m04x/lets_run_onchain_decentralized_exchanges_the_way/). Balancer's generalization accounts for cases with $$n \geq2$$ tokens as well as weightings that are not an even 50/50 split.&#x20;

As the price of each token changes, traders and arbitrageurs rebalance the pool by making swaps. This maintains the desired weighting of the value held by each token whilst collecting trading fees from the traders.

For more weighted math formulas, [check out the Developer Docs](https://dev.balancer.fi/resources/pool-math/weighted-math).

## Invariant

The value function $$V$$is defined as:

$$
V= \prod\_t B\_t^{W\_t}
$$

Where

* $$t$$ ranges over the tokens in the pool
* $$B\_t$$ is the balance of the token in the pool
* $$W\_t$$​is the normalized weight of the tokens, such that the sum of all normalized weights is 1.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://balancer.gitbook.io/balancer-v2/concepts/math/weighted-math.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
