> For the complete documentation index, see [llms.txt](https://docs.zama.org/concrete/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.zama.org/concrete/explanations/fusing.md).

# Frontend fusing

This document describes the concept of fusing, which is the act of combining multiple nodes into a single node, which is converted to a Table Lookup.

## How is it done?

Code related to fusing is in the `frontends/concrete-python/concrete/fhe/compilation/utils.py` file. Fusing can be performed using the `fuse` function.

Within `fuse`:

1. We loop until there are no more subgraphs to fuse.
2. <mark style="background-color:yellow;">Within each iteration:</mark> 2.1. We find a subgraph to fuse.

   2.2. We search for a terminal node that is appropriate for fusing.

   2.3. We crawl backwards to find the closest integer nodes to this node.

   2.4. If there is a single node as such, we return the subgraph from this node to the terminal node.

   2.5. Otherwise, we try to find the lowest common ancestor (lca) of this list of nodes.

   2.6. If an lca doesn't exist, we say this particular terminal node is not fusable, and we go back to search for another subgraph.

   2.7. Otherwise, we use this lca as the input of the subgraph and continue with `subgraph` node creation below.

   2.8. We convert the subgraph into a `subgraph` node by checking fusability status of the nodes of the subgraph in this step.

   2.9. We substitute the `subgraph` node to the original graph.

## Limitations

With the current implementation, we cannot fuse subgraphs that depend on multiple encrypted values where those values don't have a common lca (e.g., `np.round(np.sin(x) + np.cos(y))`).


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zama.org/concrete/explanations/fusing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
