-
Notifications
You must be signed in to change notification settings - Fork 0
Building Blocks Reference
Samuele95 edited this page Jan 31, 2026
·
1 revision
The building blocks are self-stabilising library functions built on top of the field calculus primitives. They are the recommended API for writing aggregate programs.
Computes the shortest-path distance from source devices.
dist = gradient(ctx, is_source)-
Sources return
0.0 -
Non-sources return the minimum
neighbour_distance + edge_weight - Converges in O(diameter) rounds
- Alias:
dist_to(ctx, source)
Propagates a value outward from source devices:
value = broadcast(ctx, is_source, "hello")Every device receives the value from its nearest source.
Aggregates data inward along a potential field (toward lower potential).
total = collect(ctx, potential, lambda a, b: a + b, local_value, 0)-
potential— a distance field (data flows downhill) -
acc— associative binary operator -
local— this device's contribution -
null— identity element foracc
Elects uniformly-spaced leaders across the network.
is_leader = sparse(ctx, grain=3.0)- Returns
Truefor elected leaders,Falseotherwise - Leaders are separated by at least
graindistance - Ties broken by device ID
Countdown timer that decreases each round.
remaining = timer(ctx, duration=10.0) # counts down to 0Exponential smoothing of a value.
smoothed = decay(ctx, raw_value, rate=0.9)Logical corridor between source and destination regions.
on_channel = channel(ctx, is_source, is_destination, width=0.5)Composition: G(source) + G(destination) <= shortest_path + width
Divides the network into regions using sparse leaders.
leader_id = partition(ctx, grain=4.0)Computes the regional average of a sensor value.
avg = distributed_average(ctx, sensor_value)