# With composition

This document explains how to combine compiled functions with the `composable` flag in **Concrete**.

By setting the `composable` flag to `True`, you can compile a function such that its outputs can be reused as inputs. For example, you can then easily compute `f(f(x))` or `f**i(x) = f(f(...(f(x) ..))` for a non-encrypted integer `i` variable, which is usually required for recursions.

Here is an example:

```python
from concrete import fhe

@fhe.compiler({"counter": "encrypted"})
def increment(counter):
   return (counter + 1) % 100

print("Compiling `increment` function")
increment_fhe = increment.compile(list(range(0, 100)), composable=True)

print("Generating keyset ...")
increment_fhe.keygen()

print("Encrypting the initial counter value")
counter = 0
counter_enc = increment_fhe.encrypt(counter)

print(f"| iteration || decrypted | cleartext |")
for i in range(10):
    counter_enc = increment_fhe.run(counter_enc)
    counter = increment(counter)

    # For demo purpose; no decryption is needed.
    counter_dec = increment_fhe.decrypt(counter_enc)
    print(f"|     {i}     || {counter_dec:<9} | {counter:<9} |")
```

Remark that this option is the equivalent to using the `fhe.AllComposable` policy of [modules](https://docs.zama.org/concrete/compilation/combining/composing_functions_with_modules). In particular, the same limitations may occur (see [limitations documentation](https://docs.zama.org/concrete/compilation/composing_functions_with_modules#limitations) section).


---

# 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://docs.zama.org/concrete/compilation/combining/composition.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.
