> For the complete documentation index, see [llms.txt](https://devs.novanet.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://devs.novanet.xyz/jolt-atlas-zkml/onnx/tensor-instructions/virtual-instructions/sigmoid.md).

# Sigmoid

The quantized sigmoid function is defined as follows:

$$\sigma\_Q(x) = \dfrac{Q}{1 + 2^{-x}}$$

where $Q$ is the quantization (scaling) factor. We use $2$ instead of $e$ to avoid floating point operations.

### Implementation

| Step | Operation       | Description                                                                          |
| ---- | --------------- | ------------------------------------------------------------------------------------ |
| 1    | VirtualConst(0) | Create constant zero tensor for comparisons                                          |
| 2    | Gte             | Compute `ge0 = (z >= 0)` to track sign of input                                      |
| 3    | Sub             | Compute `neg_z = -z` for absolute value calculation                                  |
| 4    | Select          | Compute `abs_z = select(ge0, z, -z)` (absolute value)                                |
| 5    | VirtualPow2     | Compute \`pow2 = 2^{                                                                 |
| 6    | VirtualConst(Q) | Load quantization constant `Q`                                                       |
| 7    | Mul             | Compute `Q² = Q * Q`                                                                 |
| 8    | Div             | Compute \`div\_Q\_pow = Q / 2^{                                                      |
| 9    | Mul             | Compute \`mul\_Q\_pow = Q \* 2^{                                                     |
| 10   | Select          | Compute `a = select(ge0, div_Q_pow, mul_Q_pow)` (choose branch based on sign of `z`) |
| 11   | Add             | Compute `b = Q + a`                                                                  |
| 12   | Div             | Compute `c = Q² / b` → final quantized sigmoid output `σ_Q(z)`                       |
| 13   | VirtualMove     | Move final tensor `c` to output destination                                          |
