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89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
---
language:
  - en
license: apache-2.0
library_name: holo-program
tags:
  - memory
  - programmable-memory
  - membrane-computing
  - p-systems
  - cryptographic-memory
  - keyed-access
  - associative-memory
  - hyperdimensional-computing
  - vector-symbolic-architecture
  - numpy
  - educational
  - research
datasets: []
metrics:
  - chain-execution-accuracy
  - membrane-inheritance
  - key-separation
pipeline_tag: feature-extraction
---

# holo-program

**Programs as items, membranes as regions, keys as gates.**

A memory substrate with three stacked layers under one interface.
Programs are stored as key-value items and executed by
unbind-then-classify. Membranes are nested regions with child-to-parent
inheritance and P-systems operations. Cryptographic keying derives item
vectors from a secret; without the key, the trace is noise. Everything
is addressable through a single `ask()` primitive.

The three layers are views of one vector space. The caller does not
specify which layer to search. `ask()` returns heterogeneous hits.

## What it does

```python
from holo_program import HoloProgram

prog = HoloProgram(d=2048, key=None)

# Programs as items
prog.add_op("root", "inc", "0", "1")
prog.add_op("root", "inc", "1", "2")
prog.add_op("root", "double", "2", "4")

# Execute a chain
result = prog.run_chain("root", ["inc", "inc", "double"], "0")
# result = {"path": ["0", "1", "2", "4"], "ok": True}

# Membranes with inheritance
prog.add_membrane("alice", parent="root")
prog.store("alice", "alice_lives_in_paris")
prog.query("alice", "alice_lives_in_paris")   # ~1.0
prog.query("root",  "alice_lives_in_paris")   # ~0.0

# Keyed access
p_secret = HoloProgram(key="secret")
p_secret.store("root", "classified")
p_wrong = HoloProgram(key="wrong")
p_wrong.membranes["root"].trace = p_secret.membranes["root"].trace.copy()
p_secret.query("root", "classified")   # ~1.0
p_wrong.query("root", "classified")    # ~0.0

# Non-flat query
hits = prog.ask("inc")
# [operation] membrane=root  role=op  inc(0) -> 1
# [operation] membrane=root  role=op  inc(1) -> 2
```

## Why three layers

Standard memory tools are flat. A vector database accepts an
embedding; a KV cache accepts a key; a graph database accepts a
pattern. Each tool has one interface and one data layer. The user
adapts the problem to the tool.

The substrate here stacks three layers over the same vector space.
Each layer has been built before. The composition is what is new.
A user stores a fact, defines an operation, puts it in a membrane,
and locks it behind a key β€” all through the same primitives, all
retrievable through the same `ask()` call.

## Installation

```bash
pip install numpy
```

No other dependencies. Single file, approximately 600 lines.

## Usage

### CLI

```bash
python holo_program.py
python holo_program.py --output results/
```

Runs eight demonstrations and writes a JSON state file.

### Python

```python
from holo_program import HoloProgram

prog = HoloProgram(d=2048, key=None, threshold=0.05)

# Membranes
prog.add_membrane("alice", parent="root")
prog.add_membrane("alice_kitchen", parent="alice")

# Storage
prog.store("root", "earth_round")
prog.store("alice", "alice_lives_in_paris")
prog.store("alice_kitchen", "manager_is_bob")

# Operations
prog.add_op("root", "serve", "customer", "coffee")
prog.add_op("alice_kitchen", "brew", "coffee", "ready")

# Execute
result = prog.run_chain("root", ["inc", "inc"], "5")
result = prog.apply("alice_kitchen", "brew", "coffee")  # "ready"

# Data-driven walk
walk = prog.run_data_driven("root", "cold")  # ["cold", "warm", ...]

# P-systems operations
prog.move("private_note", "alice", "root")
prog.dissolve("alice_kitchen", "alice")

# Non-flat query
hits = prog.ask("coffee", top_k=8)

# Cryptographic layer
commitment = prog.commit("root", "secret_value", salt="random_salt_123")
ok = prog.verify("root", "secret_value", "random_salt_123", commitment)
```

## Results

All results at D=2048, threshold=0.05. Self-test verifies four
primitives before any demonstration: bind/unbind identity, key
separation, projection recovery, and random-key key-value retrieval
(49/50 at 50 superposed pairs).

### Program execution

Twenty `inc` operations (i β†’ i+1 for i = 0..19), twenty `double`
operations (i β†’ 2i), ten `square` operations (i β†’ iΒ²) stored as
key-value pairs.

| Chain | Start | Path | Result |
|---|---|---|---|
| inc, inc, double | 3 | 3 β†’ 4 β†’ 5 β†’ 10 | correct |
| square, inc | 4 | 4 β†’ 16 β†’ 17 | correct |
| double, inc, inc | 5 | 5 β†’ 10 β†’ 11 β†’ 12 | correct |
| inc, square | 2 | 2 β†’ 3 β†’ 9 | correct |

Single applies: `inc(7) = 8`, `double(7) = 14`, `square(7) = 49`.

The chains compose across different operations. The substrate does not
know which operations exist; it reads the key, retrieves the value,
classifies the out, and passes the result forward.

### Data-driven execution

State transitions: `cold β†’ warm β†’ hot β†’ boiling β†’ evaporated`.

Starting at `cold` with no predefined chain, the substrate walks by
finding whichever operation matches the current value at each step:

```
cold -> warm -> hot -> boiling -> evaporated
steps: 4
```

Starting at `evaporated` (no matching operation), the walk terminates
immediately.

### Membrane inheritance

Three nested membranes: `root`, `alice`, `alice_kitchen`.

| Query | root | alice | alice_kitchen |
|---|---|---|---|
| earth_round | +1.028 | +1.028 | +1.028 |
| alice_lives_in_paris | +0.023 | +1.004 | +1.004 |
| kitchen_floor_5 | -0.026 | -0.026 | +1.020 |
| manager_is_bob | -0.004 | -0.004 | +1.020 |

The child sees the parent's facts. The parent does not see the child's.
Inheritance is one-way, from child to parent.

### Movement and dissolution

**Move.** `private_note` stored in `inner`:

| | root | inner |
|---|---|---|
| before | +0.027 | +1.000 |
| after | +1.027 | +1.027 |

The content transferred completely.

**Dissolution.** `middle_fact` in `middle`, then dissolve `middle` into
`root`:

| | root | middle |
|---|---|---|
| before | +0.009 | +1.000 |
| after | +1.009 | (gone) |

Content transferred, membrane removed.

### Cryptographic keying

Two programs share the same trace. One has the correct key; the other
has a wrong key.

| Candidate | Correct key | Wrong key |
|---|---|---|
| classified_meeting_place | +0.997 | +0.004 |
| classified_meeting_time | +0.997 | -0.007 |
| paris | -0.018 | -0.022 |
| 3pm | -0.028 | +0.034 |
| unrelated_word | -0.028 | +0.010 |

With the correct key, stored items read at +0.997 and non-stored at
near zero. With the wrong key, all items read near zero. The trace
carries no usable signal without the key.

### Commitment scheme

Commitment = `bind(vector(label), vector(salt))`. Verification:

| Correct (label, salt) | Wrong salt | Wrong label |
|---|---|---|
| True | False | False |

Commitment vector magnitude is exactly 1.0000 (phase-only binding
preserves unit modulus).

### Unified `ask()`

Five example queries, each returning heterogeneous hits:

| Query | Result |
|---|---|
| `alice` | `[membrane] alice` |
| `alice_lives_in_paris` | `[item] alice sim=+1.004` |
| `coffee` | `[operation] serve(customer) β†’ coffee` in root; `[operation] brew(coffee) β†’ ready` in alice_kitchen |
| `alice_kitchen` | `[membrane] alice_kitchen` |
| `manager_is_bob` | `[item] alice_kitchen sim=+1.020` |

The caller does not specify which layer to search. The substrate
reports what it has.

### Programs as items

Querying `ask("inc")` returns the two stored `inc` operations.

Querying `ask("3")` returns both the operation where `3` is an
output (`inc(2) β†’ 3`) and the operation where `3` is an input
(`double(3) β†’ 6`). The `role` field distinguishes them.

The same primitive reads items and operations. There is no separate
"program layer" from the caller's perspective.

## API reference

### `HoloProgram`

```python
HoloProgram(d=2048, key=None, threshold=0.05)
```

**Membrane management**

- `add_membrane(name, parent="root")` β€” create a nested membrane.

**Storage**

- `store(membrane, label, weight=1.0)` β€” store an item.
- `add_op(membrane, op_name, in_val, out_val)` β€” store an operation.
- `move(label, src, dst)` β€” transfer an item between membranes.
- `dissolve(child, into)` β€” merge a child membrane into its parent.

**Execution**

- `apply(membrane, op_name, in_val) -> out_val | None` β€” single step.
- `run_chain(membrane, ops, start) -> dict` β€” fixed sequence.
- `run_data_driven(membrane, start, max_steps=20) -> dict` β€” follow
  whichever operation matches at each step.

**Query**

- `query(membrane, label) -> float` β€” similarity in the membrane's
  inheritance chain.
- `ask(query, top_k=8) -> list[dict]` β€” heterogeneous search across
  all membranes and all layers.

**Cryptographic**

- `commit(membrane, label, salt) -> np.ndarray` β€” generate commitment.
- `verify(membrane, label, salt, commitment) -> bool` β€” verify.

**Diagnostics**

- `stats() -> dict` β€” per-membrane counts and magnitudes.
- `save_json(path)` β€” full state.

## Design notes

### Random keys, not structured keys

Operations use fully random keys derived from a hash of `(op_name,
in_val)`, not from a structured binding of role vectors. An earlier
version used `norm(bind(op, op_name) + bind(in, in_val))`, which
produced correlated keys for operations sharing a component. With
twenty `inc` operations, the shared `inc` component made the keys
correlated and cross-talk swamped the signal; only single applies
worked.

The random-key variant removes the cross-talk at the cost of treating
every `(op, in)` pair as structurally distinct. The `op` role is
still used for the value (`bind(out, out_val)`), but not for the key.

### Parent direction

Inheritance goes from child to parent. A child sees its parent's
facts; a parent does not see its child's facts. This is the natural
direction for a "context" relation: a specific context inherits from
a general one, not the other way around.

### Keyed codebook

Item vectors are derived from `random_vector(key, label)`. Different
keys produce uncorrelated vectors for the same label. A trace built
with key A, queried with key B, produces similarity near zero because
the two codebooks are independent.

This is access control at the codebook level. Without the key, the
trace is a random superposition of unknown vectors.

## Limitations

**Programs are not Turing-complete.** Chains and data-driven walks
compose operations. Branching, iteration, and recursion must be
encoded as larger operation sets or implemented outside the substrate.

**No catalysis.** An operation cannot require a third object to be
present. The structure supports it (a catalyst could be a role in the
operation and a check against the local trace) but it is not
implemented.

**No priority.** Multiple applicable operations are returned by
`find_applicable` sorted by similarity. There is no specificity-based
ordering or explicit precedence.

**No timed rules.** Operations have no validity windows.

**No provenance.** The substrate does not track which call produced
which weight. Two sources that store the same fact look identical.

**Keys are not secret against an adversary with the codebook.** The
key separation prevents a wrong-key query from retrieving items. It
does not prevent brute-force matching against the trace if the label
space is small.

**Commitments are not cryptographic.** `bind(vector(label),
vector(salt))` is a hash-like operation in the substrate's algebra.
It is not a cryptographically secure commitment in the formal sense.
It is useful for cooperative verification, not for adversarial
security.

**No cross-membrane queries.** A query goes to one membrane.
`ask()` searches all membranes for the query string, but it does not
propagate the query through the inheritance chain.

**No consolidation.** Traces grow linearly. Long-running stores need
external management. The four-axis tool provides consolidation; it is
not integrated here.

## Citation

```bibtex
@misc{holo-program2026,
  title  = {holo-program: Programs as items, membranes as regions,
            keys as gates},
  author = {zeechimp},
  year   = {2026},
  note   = {A memory substrate with three stacked layers under a
            single non-flat interface.}
}
```

## References

- Plate, T. A. "Holographic Reduced Representations." *IEEE Transactions on Neural Networks* 6:3 (1995), 623–641.
- Kanerva, P. "Hyperdimensional Computing." *Cognitive Computation* 1:2 (2009), 139–159.
- PΔƒun, Gh. "Computing with Membranes." *Journal of Computer and System Sciences* 61:1 (2000), 108–143.
- Gayler, R. W. "Vector Symbolic Architectures Answer Jackendoff's Challenges." *ICCS/ASCS* (2003).

## License

Apache 2.0