fhelium.experimental.bootstrap.arithmetic
CKKS arithmetic and depth-dependent scale targets for Bootstrap components.
BootstrapArithmetic
class View source
BootstrapArithmetic(engine: Engine, constant_cache: MutableMapping[object, object] | None = None, retain_ntt: bool = True, modup_method: Literal['exact', 'crt', 'normalized_crt'] = 'exact')Execute Bootstrap CKKS arithmetic with depth-dependent scale targets.
target_scales gives an inspectable multiplication schedule derived from Q group products. Scalar and diagonal products select their plaintext scales to reach that schedule; ciphertext products retain actual scales. constant_cache retains compact scalar plaintexts and monomial tables for reuse across evaluation calls. Scalar entries preserve the first stochastic encoding sample; a hit does not advance rounding state. Clearing or omitting the cache permits fresh encoding. Scalar preparation requires max(abs(real(c)), abs(imag(c))) * scale < 2**63 before conversion to signed-integer polynomial coefficients. Addition uses the ciphertext scale; multiplication uses its selected plaintext scale. Values outside this preparation bound raise ValueError. retain_ntt=False selects coefficient-domain results for callers that compose Bootstrap without NTT-retaining Eager operations. FullSlotBootstrap creates this owner internally; custom compositions pass it to linear, polynomial, and periodic-reduction evaluators.
Attributes
| Name | Type | Default/value |
|---|---|---|
engine | Engine | |
constant_cache | MutableMapping[object, object] | None | None |
retain_ntt | bool | True |
modup_method | Literal['exact', 'crt', 'normalized_crt'] | 'exact' |
target_scales
property
target_scales: tuple[float, ...]Return the selected per-depth arithmetic scales.
The default selection is computed backward from the terminal default scale using for_input follows an actual input scale forward over the requested depths. scaled_targets instead describes coefficient accumulators multiplied by unscaled basis nodes.
for_input
method
def for_input(ciphertext: Ciphertext, required_depths: int) -> BootstrapArithmetic: ...Follow
Polynomial basis nodes use this recurrence through their required depths; coefficient products may select a different output scale.
scaled_targets
method
def scaled_targets(factor: float) -> BootstrapArithmetic: ...Use a common scale factor for polynomial coefficient accumulators.
plaintext_scale
method
def plaintext_scale(input_scale: float, depth: int) -> float: ...Choose
multiply_by_monomial
method
def multiply_by_monomial(ciphertext: Ciphertext, exponent: int) -> Ciphertext: ...Return
align_depths
method
def align_depths(lhs: Ciphertext, rhs: Ciphertext) -> tuple[Ciphertext, Ciphertext]: ...Advance the shallower value to the deeper value's Q depth.
advance_depth
method
def advance_depth(ciphertext: Ciphertext) -> Ciphertext: ...Advance one Q group and return at the next target scale.
relinearize
method
def relinearize(ciphertext: Ciphertext, key: RelinearizationKey | EvaluationKeySet | Mapping[int, RelinearizationKey], *, output_domain: Literal['coefficient', 'ntt']='coefficient', rescale: bool=False) -> Ciphertext: ...Reduce
A primitive key is consumed directly. During material preparation an inventory selects a key covering the product's Q rows. Prepared execution reads its selected per-depth references. The lift method and requested polynomial representation are forwarded to the Eager operation. Without rescaling, Q depth and actual scale are preserved. With rescale=True, the operation removes the next complete Q group
multiply_relinearize_rescale
method
def multiply_relinearize_rescale(lhs: Ciphertext, rhs: Ciphertext, *, relinearization_key: RelinearizationKey | EvaluationKeySet | Mapping[int, RelinearizationKey]) -> Ciphertext: ...Return relinearized
multiply_scalar
method
def multiply_scalar(ciphertext: Ciphertext, scalar: complex) -> Ciphertext: ...Multiply by one encoded scalar, rescale, and return target scale.
weighted_scalar_sum
method
def weighted_scalar_sum(terms: Sequence[tuple[Ciphertext, complex]]) -> Ciphertext: ...Return
add_scalar
method
def add_scalar(ciphertext: Ciphertext, scalar: complex) -> Ciphertext: ...Add a scalar without changing depth, scale, domain, or RNS basis.