nb DSL built-ins
Single source of truth for nb built-in functions.
Every built-in is declared exactly once here with its classification facts. Both the semantic analyzer (return types, depth-opacity) and the code generator (encrypted-ness, plaintext-ness, vector-ness) derive their tables from this registry — adding a built-in is a one-line change, and the two phases can no longer drift apart.
User-defined functions are NOT listed here: their classification comes from their declared signatures (see codegen's _fn_sigs lookup).
Return kinds:
'enc' — returns a ciphertext (Ciphertext<DCRTPoly> or enc<T>)
'plain' — returns plaintext data whose precise type isn't modeled
(vectors/matrices of cleartext values, paths into data, ...)
'u32'/'i64'/'f64'/'string'/'path'/'void' — concrete plaintext scalars
'keybundle'/'secretkey' — key objects
'unknown' — genuinely polymorphic (e.g. load() of an arbitrary wire type)Flags:
enc_hint — codegen treats the result as a ciphertext even though the
semantic return type stays unknown (e.g. reduce over a
ciphertext collection).
vector_return — generates a std::vector<double> (plaintext vector); drives
MakeCKKSPackedPlaintext wrapping in mixed ct/vector ops.
depth_opaque — performs homomorphic multiplications whose depth is not
statically modeled; suppresses the depth over-provision
warning for any program using it.Keys and encryption
| Built-in | Returns | Flags | Note |
|---|---|---|---|
keygen | keybundle | ||
encrypt | enc | ||
decrypt | plain | plaintext vector of slot values | |
save_secret_key | void | ||
load_secret_key | secretkey |
Serialization / data loading
| Built-in | Returns | Flags | Note |
|---|---|---|---|
load | unknown | wire-type dependent | |
load_all | unknown | ||
load_matrix | plain | ||
load_vec | plain | ||
load_model | unknown | ||
save | void |
Ciphertext operations
| Built-in | Returns | Flags | Note |
|---|---|---|---|
clone | enc | ||
zero | enc | ||
relin | enc | ||
rotate | enc | ||
negate | enc | ||
mul_monomial | enc | ||
chebyshev | enc | depth_opaque | |
slot_sum | enc | ||
total_sums | enc | ||
running_sums | void | depth_opaque | |
slot_replicator | unknown | ||
extern_call | unknown | depth_opaque |
Collection combinators (closure depth not modeled)
| Built-in | Returns | Flags | Note |
|---|---|---|---|
reduce | unknown | enc_hint, depth_opaque | |
map | unknown | depth_opaque | |
zip_map | unknown | depth_opaque |
Plaintext data shaping
| Built-in | Returns | Flags | Note |
|---|---|---|---|
tile | plain | vector_return | |
slot_mask | plain | vector_return | |
to_matrix_form | plain | vector_return | |
transpose | plain | ||
batch | plain | ||
scale | plain | ||
prepend_column | plain | ||
vec_zeros | unknown | vec_zeros<enc<...>> can hold cts | |
mat_zeros | plain | ||
sort | plain | ||
argmax | plain | ||
enumerate | unknown | ||
stride | plain |
Plaintext scalar helpers
| Built-in | Returns | Flags | Note |
|---|---|---|---|
len | u32 | ||
rows | u32 | ||
ceil_div | u32 | ||
log2 | u32 | ||
round | i64 | ||
int | i64 | ||
str | string | ||
abs | f64 | ||
exp | f64 | ||
tanh | f64 | ||
root | path |
I/O / debug
| Built-in | Returns | Flags | Note |
|---|---|---|---|
print | void |
Something not looking right? Suggest a change on GitHub.