Documentation

Tensors, neural nets and LLMs

Every operator a .lolo program can call, from the canonical registry the compiler bakes.

Namespaces on this page: llm/, nn/, tensor/, train/.

llm/

llm/call-tools

Call the LLM with tool definitions. Returns the assistant response with optional tool calls and token usage.

lolo
1 (llm/call-tools prompt tools)

Parameters

NameTypeDescription
promptstringUser prompt
toolsarrayTool definitions

Returns: LlmCallToolsResult · Runs on: any

Example

lolo
1 (llm/call-tools [{"role":"user","content":"What time is it?"}] [{"name":"getTime","description":"Get current time","parameters":{}}])

llm/compact

Compact the context window. Returns before/after token counts.

lolo
1 (llm/compact strategy)

Parameters

NameTypeDescription
strategy{'kind': 'union', 'of': [{'kind': 'literal', 'value': 'hybrid'}, {'kind': 'literal', 'value': 'summarize'}, {'kind': 'literal', 'value': 'truncate'}, {'kind': 'literal', 'value': 'extract'}]}Compaction strategy

Returns: object · Runs on: any

Example

lolo
1 (llm/compact) // => {before: 10000 after: 8000}

llm/embed

Generate embeddings for an array of texts. Returns a 2D array of floats.

lolo
1 (llm/embed texts)

Parameters

NameTypeDescription
textsarrayTexts to embed

Returns: array · Runs on: any

Example

lolo
1 (llm/embed ["hello" "world"])

llm/generate

Generate text from an LLM. Returns the generated string.

lolo
1 (llm/generate prompt)

Parameters

NameTypeDescription
promptstringGeneration prompt

Returns: string · Runs on: any

Example

lolo
1 (llm/generate "Write a haiku") // => "Spring rain falls gently"

llm/switch

Switch the active LLM provider and optionally the model.

lolo
1 (llm/switch provider)

Parameters

NameTypeDescription
providerstringLLM provider name

Returns: void · Runs on: any

Example

lolo
1 (llm/switch "claude")

llm/token-count

Get the current token count in the context window.

lolo
1 (llm/token-count)

Returns: number

Example

lolo
1 (llm/token-count) // => 5432

nn/

nn/batchnorm

Batch normalization layer

lolo
1 (nn/batchnorm input)

Parameters

NameTypeDescription
inputanyInput layer or config

Returns: nn/layer

Example

lolo
1 (nn/batchnorm 64)

nn/clone

Create a deep copy of the network with same weights

lolo
1 (nn/clone module)

Parameters

NameTypeDescription
moduleanyNeural network module

Returns: nn/module

Example

lolo
1 (nn/clone {"layers":[{"type":"dense","units":2}]})

nn/dropout

Dropout layer for regularization (randomly zeros elements during training)

lolo
1 (nn/dropout p)

Parameters

NameTypeDescription
pnumberDropout probability

Returns: nn/layer

Example

lolo
1 (nn/dropout)

nn/forward

Execute forward pass through network

lolo
1 (nn/forward module input)

Parameters

NameTypeDescription
moduleanyNeural network module
inputanyInput tensor

Returns: tensor

Example

lolo
1 (nn/forward {"layers":[{"type":"dense","units":2}]} [0.1,0.2])

nn/getWeights

Get network weights as a flat tensor

lolo
1 (nn/getWeights module)

Parameters

NameTypeDescription
moduleanyNeural network module

Returns: tensor

Example

lolo
1 (nn/getWeights {"layers":[{"type":"dense","units":2}]})

nn/layernorm

Layer normalization

lolo
1 (nn/layernorm input)

Parameters

NameTypeDescription
inputanyInput layer or config

Returns: nn/layer

Example

lolo
1 (nn/layernorm 64)

nn/linear

Fully connected linear layer (output = input * weights + bias)

lolo
1 (nn/linear inSize outSize)

Parameters

NameTypeDescription
inSizenumberInput dimension
outSizenumberOutput dimension

Returns: nn/layer

Example

lolo
1 (nn/linear 128 64)

nn/paramCount

Get total number of trainable parameters

lolo
1 (nn/paramCount module)

Parameters

NameTypeDescription
moduleanyNeural network module

Returns: number

Example

lolo
1 (nn/paramCount {"layers":[{"type":"dense","units":2}]})

nn/relu

ReLU activation function: max(0, x)

lolo
1 (nn/relu)

Returns: nn/layer

Example

lolo
1 (nn/relu)

nn/sequential

Create a sequential neural network from layers

lolo
1 (nn/sequential layer)

Parameters

NameTypeDescription
layeranyFirst layer (variadic)

Returns: nn/module

Example

lolo
1 (nn/sequential ["nn/linear",16,64] ["nn/relu"] ["nn/linear",64,4])

nn/setWeights

Set network weights from a flat tensor

lolo
1 (nn/setWeights module weights)

Parameters

NameTypeDescription
moduleanyNeural network module
weightsanyWeight tensor (variadic)

Returns: nn/module · Runs on: any

Example

lolo
1 (nn/setWeights {"layers":[{"type":"dense","units":2}]} [0.1,0.2,0.3])

nn/sigmoid

Sigmoid activation function: 1 / (1 + e^-x)

lolo
1 (nn/sigmoid)

Returns: nn/layer

Example

lolo
1 (nn/sigmoid)

nn/softmax

Softmax activation function (normalizes to probability distribution)

lolo
1 (nn/softmax dim)

Parameters

NameTypeDescription
dimnumberDimension to apply softmax

Returns: nn/layer

Example

lolo
1 (nn/softmax)

nn/tanh

Tanh activation function: (e^x - e^-x) / (e^x + e^-x)

lolo
1 (nn/tanh)

Returns: nn/layer

Example

lolo
1 (nn/tanh)

tensor/

tensor/add

Element-wise addition

lolo
1 (tensor/add a b)

Parameters

NameTypeDescription
aanyFirst tensor
banySecond tensor

Returns: tensor

Example

lolo
1 (tensor/add [1,2] [3,4])

tensor/allInRange

Check if all elements are within range [min, max]

lolo
1 (tensor/allInRange tensor range)

Parameters

NameTypeDescription
tensoranyTensor to check
rangearrayRange [min, max]

Returns: boolean

Example

lolo
1 (tensor/allInRange [0.5,-0.2] [-1.0,1.0]) // => true

tensor/argmax

Index of maximum value

lolo
1 (tensor/argmax tensor)

Parameters

NameTypeDescription
tensoranyTensor to search (variadic)

Returns: number | tensor

Example

lolo
1 (tensor/argmax [0.1,0.9,0.3]) // => 1

tensor/cat

Concatenate two tensors along the last dimension

lolo
1 (tensor/cat a b)

Parameters

NameTypeDescription
atensorFirst tensor
btensorSecond tensor

Returns: tensor

Example

lolo
1 (tensor/cat [1,2] [3,4])

tensor/clamp

Clamp all elements to range [min, max]

lolo
1 (tensor/clamp t min max)

Parameters

NameTypeDescription
ttensorTensor to clamp
minnumberMinimum value
maxnumberMaximum value

Returns: tensor

Example

lolo
1 (tensor/clamp [5,-15,3] -10.0 10.0)

tensor/clampPerDim

Clamp each dimension to its specified range

lolo
1 (tensor/clampPerDim t ranges)

Parameters

NameTypeDescription
ttensorTensor to clamp
rangesobjectPer-dimension range specifications

Returns: tensor

Example

lolo
1 (tensor/clampPerDim [5,-15] {"0":{"min":0,"max":10},"1":{"min":-10,"max":10}})

tensor/div

Element-wise division

lolo
1 (tensor/div a b)

Parameters

NameTypeDescription
atensorDividend tensor
btensorDivisor tensor

Returns: tensor

Example

lolo
1 (tensor/div [10,20] 2)

tensor/dot

Dot product of two 1D tensors

lolo
1 (tensor/dot a b)

Parameters

NameTypeDescription
atensorFirst 1D tensor
btensorSecond 1D tensor

Returns: number

Example

lolo
1 (tensor/dot [1,2] [3,4]) // => 11

tensor/flatten

Flatten tensor to 1D

lolo
1 (tensor/flatten t)

Parameters

NameTypeDescription
ttensorTensor to flatten

Returns: tensor

Example

lolo
1 (tensor/flatten [[1,2],[3,4]])

tensor/from

Create tensor from array

lolo
1 (tensor/from arr)

Parameters

NameTypeDescription
arrarrayArray to convert

Returns: tensor

Example

lolo
1 (tensor/from [1 2 3 4])

tensor/get

Get element at index

lolo
1 (tensor/get t idx)

Parameters

NameTypeDescription
ttensorTensor to index
idxnumberIndex position

Returns: number

Example

lolo
1 (tensor/get [10,20,30,40] 3) // => 3.14

tensor/matmul

Matrix multiplication

lolo
1 (tensor/matmul a b)

Parameters

NameTypeDescription
atensorFirst matrix
btensorSecond matrix

Returns: tensor

Example

lolo
1 (tensor/matmul [[1,2],[3,4]] [[5,6],[7,8]])

tensor/max

Maximum value in tensor

lolo
1 (tensor/max t)

Parameters

NameTypeDescription
ttensorTensor

Returns: number | tensor

Example

lolo
1 (tensor/max [0.1,0.9,0.3]) // => 99

tensor/mean

Mean of tensor elements

lolo
1 (tensor/mean t)

Parameters

NameTypeDescription
ttensorTensor

Returns: number | tensor

Example

lolo
1 (tensor/mean [0.2,0.4,0.6]) // => 50

tensor/min

Minimum value in tensor

lolo
1 (tensor/min t)

Parameters

NameTypeDescription
ttensorTensor

Returns: number | tensor

Example

lolo
1 (tensor/min [3,1,2]) // => 1

tensor/mul

Element-wise multiplication

lolo
1 (tensor/mul a b)

Parameters

NameTypeDescription
atensorFirst tensor
btensorSecond tensor

Returns: tensor

Example

lolo
1 (tensor/mul [0.5,0.7] 0.99)

tensor/norm

L2 norm of tensor

lolo
1 (tensor/norm t)

Parameters

NameTypeDescription
ttensorTensor

Returns: number

Example

lolo
1 (tensor/norm [3,4]) // => 5.2

tensor/ones

Create tensor filled with ones

lolo
1 (tensor/ones shape)

Parameters

NameTypeDescription
shapearrayTensor shape

Returns: tensor

Example

lolo
1 (tensor/ones [2 3])

tensor/outOfRangeDims

Get dimensions that exceed their specified ranges

lolo
1 (tensor/outOfRangeDims t ranges)

Parameters

NameTypeDescription
ttensorTensor to check
rangesobjectDimension range specifications

Returns: array

Example

lolo
1 (tensor/outOfRangeDims [5,-15] {"0":{"min":0,"max":10},"1":{"min":-10,"max":10}}) // => [0]

tensor/outOfRangeIndices

Get indices of elements outside range

lolo
1 (tensor/outOfRangeIndices t ranges)

Parameters

NameTypeDescription
ttensorTensor to check
rangesobjectValue range specifications

Returns: number[]

Example

lolo
1 (tensor/outOfRangeIndices [0.5,1.5] [-1.0,1.0]) // => [0 2]

tensor/rand

Create tensor with random values in [0, 1)

lolo
1 (tensor/rand shape)

Parameters

NameTypeDescription
shapearrayTensor shape

Returns: tensor

Example

lolo
1 (tensor/rand [2 3])

tensor/randn

Create tensor with random values from standard normal distribution

lolo
1 (tensor/randn shape)

Parameters

NameTypeDescription
shapearrayTensor shape

Returns: tensor

Example

lolo
1 (tensor/randn [2 3])

tensor/reshape

Reshape tensor to new shape (total elements must match)

lolo
1 (tensor/reshape t shape)

Parameters

NameTypeDescription
ttensorTensor to reshape
shapearrayNew shape

Returns: tensor

Example

lolo
1 (tensor/reshape [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] [4,4])

tensor/shape

Get tensor shape as array

lolo
1 (tensor/shape t)

Parameters

NameTypeDescription
ttensorTensor

Returns: number[]

Example

lolo
1 (tensor/shape [[1,2],[3,4]]) // => [3 4 5]

tensor/slice

Get slice of tensor

lolo
1 (tensor/slice t start end)

Parameters

NameTypeDescription
ttensorTensor to slice
startnumberStart index
endnumberEnd index

Returns: tensor

Example

lolo
1 (tensor/slice [10,20,30,40] 0 3)

tensor/squeeze

Remove all dimensions of size one

lolo
1 (tensor/squeeze t)

Parameters

NameTypeDescription
ttensorTensor to squeeze

Returns: tensor

Example

lolo
1 (tensor/squeeze [[1,2,3]])

tensor/stack

Stack two tensors along a new leading dimension

lolo
1 (tensor/stack a b)

Parameters

NameTypeDescription
atensorFirst tensor
btensorSecond tensor

Returns: tensor

Example

lolo
1 (tensor/stack [1,2] [3,4])

tensor/sub

Element-wise subtraction

lolo
1 (tensor/sub a b)

Parameters

NameTypeDescription
atensorMinuend tensor
btensorSubtrahend tensor

Returns: tensor

Example

lolo
1 (tensor/sub [1,2] [3,4])

tensor/sum

Sum of tensor elements

lolo
1 (tensor/sum t)

Parameters

NameTypeDescription
ttensorTensor

Returns: number | tensor

Example

lolo
1 (tensor/sum [1,0,1]) // => 500

tensor/toArray

Convert tensor to nested array

lolo
1 (tensor/toArray t)

Parameters

NameTypeDescription
ttensorTensor to convert

Returns: array

Example

lolo
1 (tensor/toArray [[1,2],[3,4]]) // => [[1 2] [3 4]]

tensor/toList

Convert 1D tensor to flat array

lolo
1 (tensor/toList t)

Parameters

NameTypeDescription
ttensor1D tensor

Returns: number[]

Example

lolo
1 (tensor/toList [1,2,3]) // => [1 2 3]

tensor/transpose

Transpose a tensor (optionally swapping two named dimensions)

lolo
1 (tensor/transpose t)

Parameters

NameTypeDescription
ttensorTensor to transpose

Returns: tensor

Example

lolo
1 (tensor/transpose [[1,2],[3,4]] 0 1)

tensor/unsqueeze

Insert a dimension of size one at the given position

lolo
1 (tensor/unsqueeze t dim)

Parameters

NameTypeDescription
ttensorTensor to unsqueeze
dimnumberDimension position

Returns: tensor

Example

lolo
1 (tensor/unsqueeze [1,2,3] 0)

tensor/zeros

Create tensor filled with zeros

lolo
1 (tensor/zeros shape)

Parameters

NameTypeDescription
shapearrayTensor shape

Returns: tensor

Example

lolo
1 (tensor/zeros [2 3])

train/

train/adam

Adam optimizer step

lolo
1 (train/adam params grads)

Parameters

NameTypeDescription
paramsobjectModel parameters
gradsobjectGradient values

Returns: void · Runs on: any

Example

lolo
1 (train/adam {"layers":[{"type":"dense","units":2}]} 0.001)

train/checkConstraints

Check if network weights satisfy all constraints

lolo
1 (train/checkConstraints weights constraints)

Parameters

NameTypeDescription
weightsobjectNetwork weights
constraintsobjectConstraint specifications

Returns: train/constraintResult

Example

lolo
1 (train/checkConstraints [0.1,0.2] {"maxMagnitude":10})

train/checkForbiddenOutputs

Check if model produces outputs in forbidden regions

lolo
1 (train/checkForbiddenOutputs model outputs ranges)

Parameters

NameTypeDescription
modelobjectModel
outputsarrayModel outputs
rangesobjectForbidden output ranges

Returns: train/forbiddenResult

Example

lolo
1 (train/checkForbiddenOutputs {"layers":[{"type":"dense","units":2}]} [[0],[1]] {"0":{"min":100,"max":200}})

train/checkRegression

Check if new model regresses on required invariants

lolo
1 (train/checkRegression oldModel newModel testData)

Parameters

NameTypeDescription
oldModelobjectOld model
newModelobjectNew model
testDataarrayTest dataset

Returns: train/regressionResult

Example

lolo
1 (train/checkRegression [0.1,0.2] {"layers":[{"type":"dense","units":2}]} [{"input":[0],"expected":[1]}])

train/checkWeightMagnitude

Check if all weights are within magnitude limit

lolo
1 (train/checkWeightMagnitude weights maxMag)

Parameters

NameTypeDescription
weightsobjectNetwork weights
maxMagnumberMaximum magnitude

Returns: boolean

Example

lolo
1 (train/checkWeightMagnitude {"layers":[{"type":"dense","units":2}]} 10.0) // => true

train/clipGradients

Clip gradients to max norm (modifies in place)

lolo
1 (train/clipGradients grads maxNorm)

Parameters

NameTypeDescription
gradsobjectGradients to clip
maxNormnumberMaximum norm

Returns: number · Runs on: any

Example

lolo
1 (train/clipGradients {"layers":[{"type":"dense","units":2}]} 1.0)

train/clipWeights

Clip weights to max magnitude (modifies in place)

lolo
1 (train/clipWeights weights maxMag)

Parameters

NameTypeDescription
weightsobjectWeights to clip
maxMagnumberMaximum magnitude

Returns: void · Runs on: any

Example

lolo
1 (train/clipWeights {"layers":[{"type":"dense","units":2}]} 10.0)

train/computeAdvantages

Compute GAE advantages for policy gradient

lolo
1 (train/computeAdvantages rewards baseline gamma)

Parameters

NameTypeDescription
rewardsarrayReward trajectory
baselinearrayBaseline values
gammanumberDiscount factor

Returns: tensor

Example

lolo
1 (train/computeAdvantages [1,0,1] [0.5,0.4,0.3] {"gamma":0.99,"lambda":0.95})

train/computeReturns

Compute discounted returns from rewards

lolo
1 (train/computeReturns rewards gamma)

Parameters

NameTypeDescription
rewardsarrayReward trajectory
gammanumberDiscount factor

Returns: tensor

Example

lolo
1 (train/computeReturns [1,0,1] 0.99)

train/crossEntropy

Cross-entropy loss for classification

lolo
1 (train/crossEntropy predictions targets)

Parameters

NameTypeDescription
predictionsarrayPredicted probabilities
targetsarrayTarget labels

Returns: number

Example

lolo
1 (train/crossEntropy [0.1 0.9] [0 1]) // => 0.105

train/getGradientNorm

Get current gradient norm

lolo
1 (train/getGradientNorm gradients)

Parameters

NameTypeDescription
gradientsobjectGradient structure

Returns: number

Example

lolo
1 (train/getGradientNorm {"layers":[{"type":"dense","units":2}]})

train/getMaxWeightMagnitude

Get maximum weight magnitude in network

lolo
1 (train/getMaxWeightMagnitude model)

Parameters

NameTypeDescription
modelobjectNeural network model

Returns: number

Example

lolo
1 (train/getMaxWeightMagnitude {"layers":[{"type":"dense","units":2}]})

train/huber

Huber loss (smooth L1, robust to outliers)

lolo
1 (train/huber predicted target)

Parameters

NameTypeDescription
predictednumberPredicted value
targetnumberTarget value (variadic)

Returns: number

Example

lolo
1 (train/huber 0.5 0.7 1.0)

train/loop

Execute training loop with constraints

lolo
1 (train/loop model config callback)

Parameters

NameTypeDescription
modelobjectNeural network model
configobjectTraining configuration
callbacklambdaEpoch callback

Returns: train/result · Runs on: any

Example

lolo
1 (train/loop {"layers":[{"type":"dense","units":2}]} [{"state":[0],"action":1,"reward":1}] {"epochs":10})

train/mse

Mean squared error loss

lolo
1 (train/mse predicted target)

Parameters

NameTypeDescription
predictedarrayPredicted values
targetarrayTarget values

Returns: number

Example

lolo
1 (train/mse [1.0 2.0] [1.1 2.1]) // => 0.01

train/sampleBatch

Sample random batch from experience buffer

lolo
1 (train/sampleBatch buffer batch_size)

Parameters

NameTypeDescription
bufferarrayExperience buffer
batch_sizenumberBatch size

Returns: array

Example

lolo
1 (train/sampleBatch [{"state":[0],"reward":1},{"state":[1],"reward":0}] 2)

train/sgd

Stochastic gradient descent optimizer step

lolo
1 (train/sgd gradients learning_rate)

Parameters

NameTypeDescription
gradientsobjectGradient structure
learning_ratenumberLearning rate (variadic)

Returns: void · Runs on: any

Example

lolo
1 (train/sgd {"layers":[{"type":"dense","units":2}]} 0.01 0.9)

train/step

Execute single training step (forward, loss, backward, update)

lolo
1 (train/step model input target optimizer)

Parameters

NameTypeDescription
modelobjectNeural network model
inputanyInput data
targetanyTarget data
optimizerobjectOptimizer state

Returns: train/stepResult · Runs on: any

Example

lolo
1 (train/step {"layers":[{"type":"dense","units":2}]} [0.1,0.2] [1] {"lr":0.01})

train/validate

Validate model on test cases, returns pass/fail metrics

lolo
1 (train/validate model test_data)

Parameters

NameTypeDescription
modelobjectNeural network model
test_dataarrayTest dataset

Returns: train/validationResult

Example

lolo
1 (train/validate {"layers":[{"type":"dense","units":2}]} [{"input":[0],"expected":[1]}])
Orb

The language where the rule is the program.

© 2026 Almadar. Ljubljana, Slovenia.