Ciphertext operators
Ciphertext operators are the slot-vector arithmetic of a Ciphertext: +, -, *, unary -, Ciphertext.roll, Ciphertext.sum, and torch.roll/torch.sum applied to a ciphertext. They follow PyTorch semantics on the message: slot a * b holds a.roll(k) holds a.sum() holds engine.multiply and engine.rescale_to_next_depth run exactly the step they name, and this page calls such values written.
Engine binding
Every Ciphertext that an Engine produces holds a reference to that Engine, and every operator result holds the Engine of its operands. An operator runs on that Engine and selects its keys from engine.keys, as defined in Key lifecycle. Combining values of two different Engines raises ValueError. engine.attach(value) validates a value against the Engine's configuration and binds it; deserialized and transferred values need it before their operators run. The binding keeps the Engine, its keys and its tables allocated while the value is alive, and it is excluded from serialization, compile call signatures and compile cache keys.
Pending state
An operator result may be pending: it stores an unrescaled product, possibly with three components in the NTT domain, and the steps still to apply. A pending value reports the state it has after those steps:
where
Operation rules
With
| Expression | Steps | Result |
|---|---|---|
a * b | materialize both, ModSwitch the lower-depth operand to the other's depth, NTT, multiply | pending, three components, scale |
a * t | materialize, encode | pending |
a * x | materialize, multiply by | pending |
a * k, -a | multiply each residue by | state of a |
a + b, a - b | add directly when both have the same component count, pending state, depth, scale and domain; otherwise materialize and align both | pending when both were pending |
a + t, a + x | materialize, add a | materialized |
a - t, t - a | materialized | |
a.roll(k) | relinearize a three-component value, rotate by roll(0) returns a | keeps a pending rescale |
a.sum() | as roll, then | keeps a pending rescale |
Encoding, float scalars and scalar additions draw stochastic-rounding samples from the Engine's random stream; the other steps are deterministic.
Alignment
A product of two ciphertexts needs equal depths only: the operand of lower depth is ModSwitched to the depth of the other, and the product records scale
so the aligned operand records ScaleMismatchError when engine.add raise ScaleMismatchError for operands of different scales.
Compiled operators
Inside a compiled function, operators record fhelium_logical operations on ciphertext types of the materialized state. The placement pass of the default pipeline assigns pending states and inserts relinearization, rescaling and alignment by the rules above, so a compiled function produces the ciphertexts of its Eager execution for operations that draw no stochastic-rounding samples, except where the rotation merge below applies. A public Tensor that a compiled function encodes is prepared once, and its samples are drawn at preparation rather than in call order. Keys appear as the materials relinearization_key, conjugation_key and rotation_key_<step>, bound to the keys a depth-0 operation of the Engine selects. With placement="managed", written Engine operations are kept as written; placement="all" also lets placement move written relinearizations, rescales and rotations, which can change ciphertext residues. With placement="managed", the default pipeline rewrites