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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
# Isomorphic Shift Architecture β€” Complete Specification

**Version**: 1.0  
**Status**: DESIGN & FOUNDATION COMPLETE  
**Authority**: Prolog/Datalog source-of-truth  
**Last Updated**: 2026-07-27

---

## Table of Contents

1. [Overview](#overview)
2. [Core Concepts](#core-concepts)
3. [Eight Required Mappings](#eight-required-mappings)
4. [Authority Model](#authority-model)
5. [Transaction Model](#transaction-model)
6. [Error Handling](#error-handling)
7. [Integration Points](#integration-points)
8. [Implementation Roadmap](#implementation-roadmap)

---

## Overview

The Isomorphic Shift layer is a formally-defined translation system that bridges multiple representation domains:

- **Notebook Instructions** (EmojiCode, HolyC, Python, JavaScript, Ada)
- **Canonical Intermediate Representation (ISIR)** (deterministic, CBOR-encoded)
- **Logic Terms** (Prolog/Datalog for reasoning)
- **Authorized Decisions** (with proof of authorization)
- **Runtime Commands** (executable on Rust, Erlang, LLVM, Ada targets)
- **Formal Proofs** (Lean 4, Agda proof obligations)
- **Execution Events** (runtime state changes)
- **Receipts** (WORM-sealed evidence of execution)
- **Notebook Cells** (Jupyter cells with sealed outputs)

Every transformation is **bidirectional** (or explicitly marked lossy), **semantically preserving**, **authority-preserving**, and **invertible**.

---

## Core Concepts

### Round-Trip Law

The fundamental property: For any isomorphic shift M,

```

inverse(forward(X)) = canonicalize(X)

forward(inverse(Y)) = canonicalize(Y)

```

This guarantees that information is not lost in either direction.

### Semantic Preservation

All transformations preserve:
- **Meaning**: The runtime behavior of the transformed value
- **Types**: Numeric types, arrays, unions, capabilities
- **Authority**: Permissions, proof status, release status
- **Structure**: Argument count, ordering, nesting

### Authority Preservation

Isomorphic Shift **MUST NOT**:
- Increase permissions (e.g., read-only β†’ read-write)
- Change proof verification status (e.g., failed β†’ passed)
- Modify release status (e.g., development β†’ production)
- Escalate agent trust level
- Remove revocations

### Classification

Each shift is classified as:
- **Isomorphism**: Fully bidirectional, bijective (round-trip perfect)
- **Partial Isomorphism**: Bidirectional but lossy in one direction (e.g., projection)
- **Embedding**: One-way injection into larger space
- **Projection**: One-way extraction from larger space
- **Normalization**: One-way canonicalization
- **Serialization**: One-way encoding to portable form

---

## Eight Required Mappings

### M1: SurfaceInstruction ↔ CanonicalInstruction

**Direction**: Bidirectional (full isomorphism)  
**Classification**: Normalization  
**Source Domains**: EmojiCode, HolyC, Python, JavaScript, Ada  
**Target**: Deterministic CBOR-encoded canonical form

**Forward Mapping**:
1. Parse surface syntax for language
2. Extract verb and arguments
3. Validate shell safety (no metacharacters)
4. Reorder arguments in canonical order
5. Encode as deterministic CBOR
6. Compute Blake3 hash
7. Wrap in ISIR with metadata

**Inverse Mapping**:
1. Decode CBOR
2. Extract verb and arguments
3. Reconstruct surface syntax for target language
4. Validate reconstructed syntax
5. Verify round-trip: parse reconstructed, compare to original

**Invariants Preserved**:
- verb_identity

- argument_identity
- type_preservation

- authorization_identity

**Example**:
```

Forward:  ⚑ fn:FreqAnchor1618

β†’ CanonicalInstruction(verb=execute, args=[fn, FreqAnchor1618])



Inverse:  CanonicalInstruction(verb=execute, args=[fn, FreqAnchor1618])

β†’ ⚑ fn:FreqAnchor1618

```

### M2: CanonicalInstruction ↔ LogicTerm

**Direction**: Bidirectional (full isomorphism)  
**Classification**: Serialization  
**Source**: Canonical instruction (CBOR)  
**Target**: Prolog logic term (ground, fully instantiated)

**Forward Mapping**:
1. Decode CBOR from canonical instruction
2. Extract verb β†’ functor
3. Extract arguments β†’ argument list
4. Convert each argument type to Prolog representation
5. Ground all variables (instantiate with concrete values)
6. Construct logic_term(functor, args)



**Inverse Mapping**:

1. Extract functor β†’ verb

2. Extract args β†’ argument list

3. Convert Prolog types back to canonical types

4. Reconstruct canonical instruction

5. Encode as CBOR



**Invariants Preserved**:

- functor_identity
- argument_identity

- grounding_identity
- type_correspondence



**Example**:

```

Forward:  canonical_instruction(execute, [fn, 1618])
β†’ logic_term(execute, [fn, 1618])



Inverse:  logic_term(execute, [fn, 1618])
β†’ canonical_instruction(execute, [fn, 1618])

```



### M3: AuthorizedLogicDecision β†’ RuntimeCommand



**Direction**: Primarily forward (projection)  

**Classification**: Projection (lossy in inverse)  

**Source**: Authorized logic decision (with Prolog proof)  

**Target**: Executable runtime command



**Forward Mapping**:

1. Extract agent and decision from authorized decision

2. Validate agent has sufficient trust for target

3. Query authorization rules: can_perform_shift/3

4. If authorized, extract command semantics

5. Map decision functor to runtime opcode

6. Map arguments to operands

7. Construct runtime_command(target, opcode, operands, context)

**Inverse Mapping** (Partial):
1. Extract opcode β†’ decision functor
2. Extract operands β†’ arguments
3. Reconstruct authorized_decision

4. Note: Authorization context may be lost (projection)



**Invariants Preserved**:

- semantics_preservation
- target_executability

- safety_preservation

**Authorization Check**:
- Agent must have execute permission
- Decision must pass authorization rules
- No permission escalation allowed

**Example**:
```

Forward:  authorized_decision(builder, logic_term(execute, [fn, 1618]), proof_hash, ts)

β†’ runtime_command(rust, execute_fn, [1618], {...})



Inverse:  runtime_command(rust, execute_fn, [1618], {...})

β†’ authorized_decision(?, logic_term(execute, [?, ?]), ?, ?)  [PARTIAL]

```

### M4: ProofObligation ↔ VerifierInvocation

**Direction**: Bidirectional (full isomorphism)  
**Classification**: Embedding  
**Source**: Formal proof obligation  
**Target**: Verifier invocation with result

**Forward Mapping**:
1. Extract theorem name and goal from obligation
2. Generate Blake3 hash of (theorem, hypotheses, goal)
3. Invoke verifier (Lean 4 or Agda)
4. Capture verification status (pending/verified/failed/timeout)
5. Wrap in verifier_invocation(proof_id, verifier, status, code, timestamp)

**Inverse Mapping**:
1. Extract proof_id

2. Extract theorem name from proof_code
3. Extract goal from proof_code

4. Reconstruct proof_obligation

**Invariants Preserved**:
- obligation_correspondence

- status_integrity
- proof_code_identity

**Example**:
```

Forward:  proof_obligation(Borrow_Step_Sound, [carry, borrow], goal_formula, bridge_verifier)

β†’ verifier_invocation(hash_xyz, lean4, verified, code, 1727404800)



Inverse:  verifier_invocation(hash_xyz, lean4, verified, code, 1727404800)

β†’ proof_obligation(Borrow_Step_Sound, [...], goal_formula, bridge_verifier)

```

### M5: ExecutionEvent ↔ LogicEventFact

**Direction**: Bidirectional (full isomorphism)  
**Classification**: Serialization  
**Source**: Runtime execution event  
**Target**: Prolog logic fact

**Forward Mapping**:
1. Extract event_id from event

2. Extract agent, action, outcome

3. Classify outcome (success/blocked/failed/timeout)

4. Generate WORM seal

5. Construct logic_event_fact(event_id, agent, action, outcome, worm_seal)



**Inverse Mapping**:

1. Extract event_id β†’ find original event
2. Reconstruct execution_event from fact data

3. Verify WORM seal unchanged



**Invariants Preserved**:

- event_correspondence
- outcome_integrity

- worm_immutability

**Example**:
```

Forward:  execution_event(hash_abc, 1727404800, builder, generate, {result: ok}, parent_hash)

β†’ logic_event_fact(hash_abc, builder, generate, success, worm_seal_xyz)



Inverse:  logic_event_fact(hash_abc, builder, generate, success, worm_seal_xyz)

β†’ execution_event(hash_abc, 1727404800, builder, generate, {...}, parent_hash)

```

### M6: ExecutionEvent β†’ ReceiptRecord

**Direction**: Primarily forward (projection)  
**Classification**: Projection (lossy in inverse)  
**Source**: Execution event  
**Target**: WORM-sealed receipt record

**Forward Mapping**:
1. Extract event_id from event

2. Generate receipt_id = hash(event_id, timestamp, authorization_proof)
3. Query authorization: was this event authorized?
4. Generate authorization_proof = hash(Prolog query result)

5. Determine verification_status (authorized/provisional/denied)
6. Generate WORM seal
7. Construct receipt_record(receipt_id, event_id, auth_proof, status, worm_seal, timestamp)



**Inverse Mapping** (Partial):

1. Extract event_id from receipt
2. Reconstruct partial execution_event

3. Note: Receipt-specific sealing and authorization proof may not be fully recoverable



**Invariants Preserved**:

- event_ancestry
- authorization_integrity

- worm_immutability
- timestamp_immutability



**Example**:

```

Forward:  execution_event(hash_abc, 1727404800, sentinel, verify, {...}, ...)

β†’ receipt_record(hash_receipt, hash_abc, proof_hash, authorized, worm_xyz, 1727404800)

Inverse:  receipt_record(hash_receipt, hash_abc, proof_hash, authorized, worm_xyz, 1727404800)

β†’ execution_event(hash_abc, 1727404800, sentinel, verify, {...}, ...)  [PARTIAL]

```



### M7: NotebookCellRecord ↔ LogicCellFact



**Direction**: Bidirectional (full isomorphism)  

**Classification**: Serialization  

**Source**: Jupyter notebook cell  

**Target**: Prolog logic fact



**Forward Mapping**:

1. Extract cell_id from notebook cell
2. Extract cell_type (code/markdown/raw)

3. Parse cell source to extract instructions

4. Extract proof obligations from cell comments

5. Generate WORM seal

6. Construct logic_cell_fact(cell_id, cell_type, instructions, obligations, worm_seal)

**Inverse Mapping**:
1. Extract cell_id

2. Find original notebook cell

3. Reconstruct cell record from fact



**Invariants Preserved**:

- cell_correspondence
- instruction_extraction_completeness
- worm_immutability



**Example**:

```

Forward:  notebook_cell(hash_c1, code, "⚑ fn:1618", [outputs], 5, metadata)

β†’ logic_cell_fact(hash_c1, code, [logic_term(execute, [fn, 1618])], [], worm_seal_m)



Inverse:  logic_cell_fact(hash_c1, code, [logic_term(execute, [fn, 1618])], [], worm_seal_m)

β†’ notebook_cell(hash_c1, code, "⚑ fn:1618", [...], 5, ...)

```



### M8: RuntimeSpecificValue ↔ CanonicalValue



**Direction**: Bidirectional (full isomorphism)  

**Classification**: Normalization  

**Source**: Language-specific value (i32, f64, string, array, capability)  

**Target**: Language-neutral canonical representation



**Forward Mapping**:

1. Inspect runtime value type

2. Map to canonical type:

   - i32, i64, u32, u64 β†’ integer

   - f32, f64, f128 β†’ float (with precision tag)

   - bool β†’ boolean

   - string β†’ string

   - bytes β†’ bytes

   - array β†’ list (with rank/shape)

   - map β†’ map

   - tagged union β†’ tagged_union
   - capability β†’ capability_ref

   - hash/proof β†’ hash_ref
3. Encode value as deterministic CBOR
4. Preserve all type information in type_tag

5. Construct canonical_value(type, cbor_bytes, type_tag)

**Inverse Mapping**:
1. Extract CBOR bytes
2. Decode using type_tag

3. Reconstruct runtime value in source language

4. Verify no type loss (array rank preserved, etc.)



**Invariants Preserved**:

- type_preservation
- value_preservation

- no_precision_loss

- no_capability_escalation



**Example**:

```

Forward:  runtime_value(i64, 1618, {})
β†’ canonical_value(integer, cbor_hex, i64_tag)



Inverse:  canonical_value(integer, cbor_hex, i64_tag)
β†’ runtime_value(i64, 1618, {})

```



---



## Authority Model



### Permission Hierarchy



```

none < read < write < execute < seal < verify < admin

```



### Agent Classes



- **sentinel**: sovereign trust (all permissions)

- **oracle**: high trust (read, analyze only)

- **builder**: high trust (read, write, generate, execute, seal)

- **archivist**: high trust (read, analyze, index, provenance)

- **berserker**: medium trust (read, analyze, inject)



### Shift Authorization



Each shift requires specific capabilities:



| Shift | Required Capability | Min Trust |

|-------|-------------------|-----------|

| M1 | read, write | low |

| M2 | read, analyze | medium |

| M3 | execute | high |

| M4 | verify | high |

| M5 | read, analyze | medium |

| M6 | seal | high |

| M7 | read, analyze | medium |

| M8 | read, write | low |



**Rule**: Agent must have required capability AND sufficient trust level.



**Absolute Prohibition**: No shift can escalate permissions or proof status.



---



## Transaction Model



### State Machine



```

   parsed

     ↓

 validated

     ↓

authorized  ← [Prolog query rejected: β†’ rejected]

     ↓

transformed  ← [Adapter error: β†’ failed]

     ↓

invariants_checked  ← [Invariant violated: β†’ rejected]
     ↓

committed  ← [If applicable]

     ↓

receipted

     ↓

  [done]

```


### Atomicity

- **Commit phase**: Write result and receipt atomically
- **Failure**: Automatic rollback
- **Idempotency**: Same (transaction_id, canonical_input) β†’ same result from ledger

### Transaction Record

```json

{

  "transaction_id": "blake3_hash",

  "shift_id": "M1",

  "agent": "builder",

  "source_value": "...",

  "target_value": "...",

  "timestamp": 1727404800,

  "state": "committed",

  "receipt_hash": "blake3_hash",

  "error": null

}

```

---

## Error Handling

### Rejection Codes

| Code | Meaning | Recoverable |
|------|---------|------------|
| MALFORMED_SOURCE | Source doesn't parse | Yes (fix input) |

| UNKNOWN_SHIFT | Shift not registered | No |
| UNSUPPORTED_VERSION | Shift version not supported | Yes (upgrade) |

| INCOMPATIBLE_SCHEMA | Source/target schema mismatch | No |
| AMBIGUOUS_MAPPING | Multiple interpretations | No |

| LOSSY_MAPPING | Claimed isomorphism but lossy | No (use projection) |
| INVALID_INVERSE | Inverse doesn't match forward | No (implementation bug) |

| MISSING_ADAPTER | Adapter not implemented | No |
| TIMEOUT | Transformation took too long | Yes (retry) |
| AUTHORIZATION_DENIED | Agent not authorized | No |

| INVARIANT_VIOLATION | Invariant not preserved | No (implementation bug) |
| SEMANTIC_MISMATCH | Meaning not preserved | No (implementation bug) |



### Failure Response



```json

{

  "error": {

    "code": "AUTHORIZATION_DENIED",
    "message": "Agent 'oracle' cannot perform M3 (execute permission required)",

    "detail": {

      "agent": "oracle",

      "shift": "M3",

      "reason": "ORACLE_READ_ONLY_VIOLATION"

    }

  }

}

```


---

## Integration Points

### Notebook System

- **Input**: Notebook cell source (EmojiCode, Python, etc.)
- **M1**: Convert to canonical instruction
- **M2**: Convert to logic term
- **M7**: Extract cell facts to Prolog
- **Output**: Logic facts queryable in Prolog

### Runtime Execution

- **Input**: Authorized decision from Prolog
- **M3**: Convert to runtime command
- **Execution**: Run on Rust/Erlang/Ada runtime
- **M5**: Record as execution event
- **M6**: Generate receipt
- **Output**: WORM-sealed receipt in ledger

### Formal Verification

- **Input**: Proof obligation from system
- **M4**: Invoke verifier (Lean 4/Agda)
- **Output**: Verification status and proof

### LOC Agent Integration

- **Source**: loc_agent.rs (DEVFLOW-FINANCE/snapkitty-core)

- **Triad Execution**: EmojiCode β†’ M1 β†’ M2 β†’ M3 β†’ Runtime β†’ M5/M6

- **WORM Sealing**: Receipt β†’ M6 β†’ WORM ledger



---



## Implementation Roadmap



### Phase 1: Foundation (Current)

- [x] Domain definitions (domains.schema.json, domains.pl)

- [x] Shift registration (shifts.pl)

- [x] Authorization rules (shift_authorization.pl)
- [x] Semantic equivalence rules (semantic_equivalence.pl)

- [x] Invariant definitions (invariants.pl)

- [x] Release gates (shift_release.pl)

### Phase 2: Adapters
- [ ] M1 adapter: SurfaceInstruction ↔ CanonicalInstruction (Rust)
- [ ] M2 adapter: CanonicalInstruction ↔ LogicTerm (Rust)
- [ ] M3 adapter: AuthorizedLogicDecision β†’ RuntimeCommand (Rust)
- [ ] M4 adapter: ProofObligation ↔ VerifierInvocation (Rust + FFI)
- [ ] M5 adapter: ExecutionEvent ↔ LogicEventFact (Rust)
- [ ] M6 adapter: ExecutionEvent β†’ ReceiptRecord (Rust)
- [ ] M7 adapter: NotebookCellRecord ↔ LogicCellFact (Rust)
- [ ] M8 adapter: RuntimeSpecificValue ↔ CanonicalValue (Rust)

### Phase 3: Testing
- [ ] Round-trip tests for all isomorphic shifts
- [ ] Semantic preservation tests
- [ ] Authority tests (no permission escalation)
- [ ] Failure mode tests
- [ ] Logic integration tests

### Phase 4: Integration
- [ ] Integrate with LOC agent
- [ ] Wire with Prolog reasoner
- [ ] Hook into notebook system
- [ ] WORM ledger integration
- [ ] Production deployment

---

## References

- **LOC Agent**: /DEVFLOW-FINANCE/snapkitty-core/src/agents/loc_agent.rs

- **Sovereign Kernel**: /bob-orchestrator/prolog/sovereign_kernel.pl
- **Notebook**: /DEVFLOW-FINANCE/sovereign_notebook.ipynb

- **Session Handoff**: /SESSION_HANDOFF.md
- **Previous Audits**: /sov-kernel-monster/*.md