Terminology and mathematical model
This page defines FHElium terminology for CKKS parameters, value state, tensor layouts, and execution.
Ring, modulus, and scale notation
FHElium implements the Cheon–Kim–Kim–Song (CKKS) approximate homomorphic encryption scheme over
| Symbol or term | Meaning | FHElium representation |
|---|---|---|
| Polynomial-ring dimension | config.N | |
| Complex slot capacity | engine.num_slots | |
| Q group removed by transition | config.q_depth_groups[d] | |
Terminal Q group retained at max_depth | config.q_depth_groups[-1] | |
| Product of all Q groups active at depth | depth plus Q prime_ids | |
| One special prime | One prime in config.p_moduli | |
| Special modulus used by hybrid key switching | P portion of a QP basis | |
| Current modulus product, | modulus_basis, depth, and prime_ids | |
| Greatest public depth | config.max_depth or engine.max_depth | |
| Public rescale transitions remaining | engine.depth_remaining(value) | |
| Default creation and planning scale | config.default_scale | |
| Actual scale carried by value | value.scale | |
| Secret-key polynomial | SecretKey | |
| Ciphertext component polynomials | Leading component axis | |
| Galois automorphism | galois_element | |
| Signed slot rotation | rotation_step | |
| Stochastic integer quantization | Encoding quantizer |
A Q prime is a prime factor of the ciphertext modulus. Q primes are ordered inside depth groups. A scaling Q group is one public group max_depth; it remains available for ordinary arithmetic. A special prime is a factor of P. auxiliary basis describes a temporary basis-conversion role such as QP; it is not a prime kind.
A slot is one packed complex message position. Applications decide how vectors, matrices, padding, and masks map to the
Construction and compatibility objects
| Term | Definition |
|---|---|
Preset | A reviewed named recipe that resolves to one exact CkksConfig. Its name records slot capacity, default-scale target, maximum public depth, and the default Engine residue dtype selected by its primes. |
CkksConfig | The immutable mathematical and security parameter set: ring, default scale, exact Q depth groups, exact P special primes, Galois generator, Gaussian error standard deviation, security category, and budget-enforcement policy. It contains no device or machine-word policy. |
RnsExecutionFormat | The device-local residue dtype and Montgomery radix selected from the exact prime set, optionally constrained by an expert Engine override. |
fhelium.eager.Engine | The process-local eager evaluator. It selects an RNS execution format, lazily creates device resources, owns installed keys, and invokes registered implementations. |
Runtime values and keys do not store a parameter-set identifier. The caller retains provenance and supplies mathematically compatible configurations, values, and keys.
See Configuration and modulus chain.
CKKS value-state coordinates
A CKKS value state is the combination of concrete value type, tensor topology, depth, actual scale, ordered prime_ids, plaintext representation, polynomial domain, modulus basis, residue representation, and component or key specialization. Device placement is a separate storage property.
| Coordinate | Values | Meaning |
|---|---|---|
| Plaintext representation | slots, integer_coefficients, approximate_coefficients, rns | Meaning of the plaintext payload |
| Polynomial domain | coefficient, ntt | Polynomial coefficients or NTT evaluations |
| Residue representation | standard, montgomery | Ordinary or Montgomery residues |
| Modulus basis | Q, QP | Active |
prime_ids | Ordered parameter-row identifiers | Modulus represented by each physical limb row |
| Depth | Integer | Index of the first active Q depth group |
| Depth remaining | Public rescale transitions still available | |
| Actual scale | Positive finite binary64 | Per-value encoding factor |
| Component count | Usually two or three for ciphertexts | Degree of the ciphertext phase in |
| Placement | CPU or indexed CUDA device | Tensor storage location |
Each coordinate identifies a different property: QP names a modulus basis; depth locates a Q group in the chain; prime_ids identify physical rows; polynomial domain describes the coordinate system within each polynomial; plaintext representation describes the payload's numerical meaning. Placement locates its storage.
Plaintext representation
| Representation | Payload and use | Dense layout |
|---|---|---|
slots | Real or complex CKKS message before encoding | Scalar or [*batch, slot] |
integer_coefficients | Signed int64 coefficients after encoding and before modular reduction | [*batch, coefficient] |
approximate_coefficients | Binary64 centered reconstruction of the active-Q phase for decoding | [*batch, coefficient] |
rns | Operation-ready residues with complete RNS state | [*batch, limb, coefficient_or_ntt_index] |
integer_coefficients_to_rns is the representation boundary that reduces each signed integer coefficient modulo every active prime and materializes the Engine's RNS dtype. An approximate_coefficients plaintext stores the binary64 result of centered reconstruction over the active Q basis. Rounding during that conversion prevents general recovery of the original residue vector.
Polynomial domain, residue representation, and basis
A coefficient-domain polynomial is indexed by coefficients. An NTT-domain polynomial is indexed by Number Theoretic Transform evaluations. Montgomery representation stores residues in a form suitable for modular multiplication. Public ciphertexts couple these axes into two supported arithmetic states:
(coefficient, standard)
(ntt, montgomery)2
RNS plaintexts additionally support (coefficient, montgomery). A Residue Number System (RNS) represents an integer polynomial by residues modulo pairwise-coprime primes. One residue-polynomial row is a limb, and prime_ids[limb_index] identifies its modulus. The Chinese remainder theorem identifies that residue vector with a unique integer class modulo the prime product. Integer-to-RNS conversion and reconstruction gives the maps and representative conventions.
At depth
Tensor and dimension terminology
A homogeneous batch is zero or more local message dimensions whose members share one value's CKKS metadata. It is not the slot axis, limb distribution, hybrid key digits, or a set of distributed processes. *batch means those zero or more leading logical batch dimensions; broadcasting is valid only where an operation explicitly documents it.
| Value | Dense tensor layout |
|---|---|
Ciphertext.data | [component, *batch, limb, coefficient_or_ntt_index] |
CompressedPlaintext.data | [*batch, limb, unique_index], with optional per-batch/per-limb implicit values |
RNS Plaintext.data | [*batch, limb, coefficient_or_ntt_index] |
| Integer or approximate coefficient plaintext | [*batch, coefficient] |
| Slots plaintext | Scalar or [*batch, slot] |
SecretKey.data | [limb, coefficient_or_ntt_index] |
PublicKey.data | [key_component=2, limb, coefficient_or_ntt_index] |
KeySwitchKey.data | [key_digit, key_component=2, limb, coefficient_or_ntt_index] |
A compressed plaintext stores a structured polynomial or NTT layout whose compact entries and optional implicit values expand to a full RNS plaintext. Compression follows the encoded axis and retains depth, actual scale, domain, basis, and prime rows. Value model and identity defines cyclic, contiguous, and strided-sparse expansion.
A ciphertext component is one polynomial key_digit_index is the stable key-storage digit identity, whereas a local digit_index is the position among digits active at one depth.
The tensor axes and identifiers have the following distinct meanings:
| Term | Meaning |
|---|---|
| Process rank | Integer position of a process globally or within a process group |
LOCAL_RANK | Node-local process index commonly used to choose a local device |
| Device index | CPU/CUDA storage location identifier; not a process rank |
tensor.ndim | Number of tensor dimensions |
| Slot index | Semantic packed-message position |
| Limb index | Physical RNS-row position interpreted through prime_ids |
CKKS encoding, encryption, and arithmetic laws
Encoding and decoding
Let
For the finite-word rounding rule, write
Under the uniform-word model
The ideal stochastic-rounding probability is
encode returns integer_coefficients. integer_coefficients_to_rns performs modular reduction into coefficient-domain standard RNS. decode consumes integer coefficients or bounded approximate_coefficients; it does not consume unreconstructed RNS.
Ciphertext phase and key relations
A
For two components this is
An external cryptographic relation is an application-owned relation not represented by a symbolic lineage field. A public key is related to one destination secret polynomial through
Here
A generic key-switch key is directed from one source secret dependency to one destination dependency:
A key switch performs that transformation up to the configured key-switch error. Relinearization is its specialized three-to-two-component form:
The object stores no generic source/destination secret identifiers, so the application preserves the direction. A RotationKey does store its normalized signed rotation_step specialization. See Key lifecycle.
| Key material | Cryptographic relation or use |
|---|---|
SecretKey | Stores |
PublicKey | Encrypts under its externally tracked destination secret relation. |
KeySwitchKey | Maps |
RelinearizationKey | Maps the |
RotationKey | Maps |
ConjugationKey | Maps |
Domain and residue transitions
For ciphertexts, forward and inverse transitions preserve the ring element while applying the coupled domain/residue change:
For RNS plaintexts, standard_residues_to_montgomery_residues and its inverse change residue representation in coefficient domain, while the NTT methods change polynomial domain on Montgomery residues. These transitions preserve depth, actual scale, basis, and prime_ids. An inverse NTT remains RNS and is not CRT reconstruction. Every primitive transition requires its named source state. Callers inspect state before choosing a transition; numerical dispatch does not generally reject a value solely because its metadata already names the target state.
Addition, subtraction, and negation
Compatible ciphertexts add or subtract componentwise:
The operands must already match in tensor shape, depth, exact binary64 actual scale, component count, polynomial domain, basis, residue representation, and prime_ids. FHElium does not hide depth, scale, domain, or component alignment inside addition. The caller is responsible for selecting operands produced with compatible CKKS parameters. Negation maps each component to
Ciphertext multiplication
For two two-component NTT/Montgomery ciphertexts, multiplication is component convolution:
It returns three NTT/Montgomery components at unchanged depth with
Plaintext arithmetic
An operation-ready plaintext is encoded at a depth and prepared in the arithmetic state required by an evaluator operation; write its polynomial as
For multiplication it is NTT-domain Montgomery RNS and multiplies every component:
An unbatched operation-ready plaintext may broadcast over a homogeneous ciphertext batch in plaintext addition and multiplication; a batched plaintext has the ciphertext batch shape. Neither arithmetic primitive implicitly rescales.
Rescale and modulus switch
At depth
rounding="nearest" and rounding="floor" identify distinct quotient laws. A QP rescale retains P rows, so its output basis is engine.rescale_divisor(depth=...) for a non-final public depth; it is the product of every prime in the group removed by that transition.
A modulus switch restricts rows from
Message preservation requires the centered represented value not to wrap under the smaller target modulus.
Rotation, automorphism, and hoisting
For a signed rotation step
matching torch.roll(m, shifts=r). The backend maps rotation_step is a user-visible slot displacement; galois_element is a polynomial automorphism exponent.
Rotation hoisting reuses decomposition, ModUp, and NTT preparation shared by several direct rotations of one component. Each output still performs its step-specific automorphism, key products, ModDown, and output construction. Conjugation applies
Hybrid key switching and bootstrapping terms
| Term | Definition |
|---|---|
| ModUp | Basis extension of each active hybrid digit from its source-prime subset into active |
| ModDown | Hybrid key-switch down-conversion from QP to Q, including division by |
| ModRaise | Centered RNS basis extension used by bootstrapping. It reconstructs over a depleted source basis, chooses the centered representative, and reduces it into a larger Q basis. The current full-slot entry uses the single structural row [q_b]. |
| Bootstrapping | CKKS refresh that raises available modulus, maps coefficients to slots, applies periodic reduction, and maps slots back to coefficients. A bootstrap callable executes this composition; its output is a refreshed ciphertext. |
| CoeffsToSlots / SlotsToCoeffs | Linear transforms between coefficient coordinates and cyclotomic slot coordinates. Full-slot branch construction obtains the conjugate coordinate by conjugation. |
| BSGS | Baby-step/giant-step decomposition of a diagonal linear transform into caller-selected rotation groups and an execution schedule, trading key families and repeated work against intermediate computation. |
| Periodic reduction | Bootstrap approximation of the periodic map that removes the encoded large-modulus quotient. The composition field is named modular_reduction. |
| Structural base Q prime | The single Q prime left after the private bootstrap-entry transition drops every public scale prime. [q_b] remains a Q basis, not a third modulus_basis value. |
Basis-conversion equations
The equations in this section state the mathematical maps independently of a particular RNS kernel or table layout. For active hybrid-digit index
For one coefficient, the source residues uniquely determine
ModUp changes the RNS basis of each hybrid digit; it does not divide the represented integer.
ModDown is a basis reduction with division by
Then
Equivalently, for every active
Here
An implementation may evaluate this quotient one P prime at a time, but its tables and residue recurrences must realize the selected map above.
FHElium's current hybrid key-switch path selects
For centered ModRaise, let
and let
and extends it to the selected target depth
The application must establish that the intended integer coefficient lies in
Bootstrap and linear-transform equations
Let
Concrete algorithms may distribute a known normalization factor between these two linear maps. Let
For period
The opposite one-sided tie convention produces
for integer
For a cyclic-diagonal linear map, let
BSGS writes the rotation offset as
Direct and BSGS schedules therefore implement the same linear map while using different rotation grouping and intermediate accumulation orders. See Composable CKKS bootstrapping for the full normalization, depth, scale, key, and error model.
Distributed and multiparty terminology
FHElium's distributed model is Single Program, Multiple Data (SPMD): each process runs the same worker function over process-local data and a local device, with application-defined ownership and collective ordering. A process group is an ordered set of participating processes; world size is the number of processes in that group.
A collective is a communication operation that every participating process enters in compatible order. It is distinct from a collective cryptographic key or decryption protocol. Descriptor/payload separation exchanges typed value metadata first so a receiver can validate and allocate before transferring dense tensor payloads.
Mathematical relationships among process-local values
| Relationship or operation | Definition |
|---|---|
| Data parallelism | Processes evaluate independent requests or samples. Outputs remain distinct. |
| Gather | Transport that preserves independent process-local objects in a list; it performs no CKKS arithmetic. |
| Additive partial | One process-local ciphertext representing a summand of a shared logical result. |
| Additive-term parallelism | Processes own disjoint summands and combine compatible ciphertext partials by modular addition. Rotation/diagonal offsets are a common case. |
| Typed ciphertext reduction | A collective that combines additive partials through modulus-aware engine addition. |
| Limb parallelism | Processes own disjoint RNS rows of one logical value. Row-local work is possible only where the operation permits partial layouts. |
| Reconstruction | Structural concatenation of disjoint RNS rows into the complete active-row layout. |
These three operations must remain distinct:
independent objects -> gather into a list
additive partials -> reduce with CKKS modular addition
disjoint RNS rows -> reconstruct by ordered concatenation2
3
See Communication semantics for the collective selection model.
Cryptographic parties and processes
A cryptographic party is an independent trust-domain participant. A process rank is an execution identity. The application maps each party to its processes, devices, and transport endpoints.
Collective key generation (CKG) constructs collective public-key material. Relinearization-key generation (RKG) constructs the evaluation key for three-to-two-component relinearization. Applications supply coordination, authenticated membership, and transport around these arithmetic phases.
Collective-decryption shares fuse into an output under the experimental module's documented unsafe arithmetic scope. Public-key-switch shares fuse into a ciphertext under a destination public key. These output operations are limited to synthetic-data arithmetic studies; privacy and production security require a reviewed protocol and parameterization.
Execution, storage, and lifecycle terms
| Term | Definition |
|---|---|
TensorResident | Protocol for a FHElium value whose declared Tensor fields move together, with device/byte inspection and functional .to(...). |
| Value signature | Device-independent description of a nested Tensor/value structure and stored state used to validate reusable copies and graph inputs. External key relations remain properties of the concrete values. |
ReusableValueBuffer | Fixed-address storage for one value-tree signature on one target device, used for eager streaming or CUDA Graph input staging. |
CopyHandle | Handle for one reusable-buffer copy. It retains source storage and exposes event-based completion and stream-wait operations. |
| Eager execution | Immediate operation dispatch using the supplied values and execution resources. |
| CUDA Graph | Captured fixed GPU schedule replayed with stable addresses. CudaGraphProgram applies it to a deterministic process-local callable with fixed value signatures. |
| Borrowed output | Output backed by storage retained and reused by another owner, such as a CUDA Graph program. A later replay may overwrite it; an owned copy is required for retention. |
Residency is process-local management of logical FHElium values and their concrete storage locations. Reusable buffers and CUDA Graph programs retain ownership of their fixed storage.
| Residency term | Definition |
|---|---|
| Materialization | A ready managed value at one local location, such as pageable CPU, pinned CPU, or an indexed CUDA device. |
| Residency budget | Optional caller-supplied strict admission limit for managed charges and reservations at one location. Unbudgeted locations still retain current and peak accounting. |
| Residency request | Declarative handle/location postconditions and headroom requirements: what must be true. |
| Residency policy | Pure deterministic ordering and configured fallback choices used to evaluate a request. |
| Residency decision | Manager-issued, state-versioned plan plus policy evidence: why the selected actions are valid for the observed state. |
| Residency plan | Immutable ordered low-level intermediate representation (IR) of explicit ensure, move, drop, and discard actions plus scoped memory reservations: how placement changes. |
| Lease | Short-lived protection for active evaluator reads. It remains effective until all consumers, including asynchronous CUDA readers, complete. |
| Hold | Longer-lived retention protection for an idle materialization; active evaluator access uses a lease. |
ResidencyManager owns live values, accounting, transitions, and lifetimes. ResidencyController derives inspectable decisions against manager state. See Residency lifetimes.
Compiler, implementation, and build terms
| Term | Definition |
|---|---|
Program | Source-independent fhelium.ir.Program containing one structurally valid mixed-dialect xDSL module. Consumers separately check semantic completeness, CKKS consistency, Backend coverage, and executable readiness. |
Compilation | A Program together with a Compile workspace, ordered pass reports, and one material_bindings dictionary shared by successive passes. |
| Material binding | An assignment from a Program symbol to a live Tensor payload. Descriptions communicate purpose; the binding supplies numerical data used by operations. |
| Specialization | A prepared input variant containing its source and transformed Compilations, selected Backend, and linked executable. Compatible input metadata and immutable scalar parameters select its reuse; ordinary input Tensor contents may change. |
| Compile | Capture, Program transformation and callable preparation, with pass reports retained alongside the represented computation. |
| JIT compilation | The Compile usage model that prepares a specialization when inputs are first seen and reuses its Backend-linked executable for matching calls. @fc.compile returns a CompiledCallable. |
| Pass / pipeline | A pass analyzes or transforms recognized Program patterns. A pipeline is a caller-selected ordered pass sequence; unmatched or extension operations may remain. |
| Backend | OperationBackend owns an operation registry and an immutable resource workspace. Compile prepares and links the executable against those implementations and resources; backend.link(compilation) provides a direct entry to that linking procedure. Implementations may invoke native operations or generate kernels for selected fusion regions. |
| Native operator stack | PyTorch dispatcher schemas, C++ registrations/bindings, CPU/CUDA implementations, and generated Python interfaces loaded by FHElium. |
| Dispatcher schema | Backend-neutral torch.ops contract for arguments, returns, mutation, and aliasing. CPU and CUDA registrations implement the same schema where supported. |
| Generated wrapper | Mechanical typed Python interface generated from registered native schemas; handwritten API/orchestration documentation defines the mathematical semantics. |
| ABI | Application binary interface among CPython, the exact PyTorch build and CUDA variant, the local CUDA toolkit, the C++ ABI, target GPU architectures, and FHElium native binaries. FHElium records the additional compatibility identity absent from ordinary wheel tags in its native manifest. |
The word backend needs a qualifier when ambiguity is possible: NTT backend policy selects an NTT implementation; a process-group communication backend such as NCCL or Gloo transports distributed data; a Python build backend drives package construction; and a compiler backend builds an executable for a covered Program. These are independent choices.
See Open compiler stack and Neutral IR programs.
Distinctions to retain
The model distinguishes the following pairs and groups:
- default scale
and per-value actual scale ; - depth and ordered
prime_ids; - Q/QP modulus basis and depth;
- semantic
modulus_basisand the internalinclude_pimplementation selector; - plaintext representation, polynomial domain, and residue representation;
- inverse NTT and CRT reconstruction;
rotation_stepandgalois_element;- local
digit_indexand stablekey_digit_index; - process rank, device index, tensor
ndim, slot index, and limb index; - gather, additive ciphertext reduction, and limb reconstruction;
- cryptographic party and process rank;
- hold and lease;
- target, provider, NTT backend, communication backend, compiler backend, and Python build backend.