Metadata-Version: 2.4
Name: interdependent-core
Version: 0.1.0
Summary: PCNA/PCTA/PTCA/PCEA/EDCM — interdependent neural, tensor, encryption, and transcript analysis library
Author-email: Erin Patrick Spencer <wayseer@interdependentway.org>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/erinepshovel-code/Interdependent-core
Project-URL: Repository, https://github.com/erinepshovel-code/Interdependent-core
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cryptography>=41
Dynamic: license-file

# interdependent-core

Pure-Python implementation of five interdependent subsystems arranged in a
strict hierarchy for EDCM-PCNA-PCTA transcript analysis and guardian-state
encryption.

```
PCNA  ←  back-propagating neural network (base tensor)
PCTA  ←  circle: 7 PCNA tensors, audited as one tensor
PTCA  ←  seed: 7 PCTA circles → core: 53 seeds (4 sentinel seeds → 9 S-channels)
PCEA  ←  encryption layer over PTCA guardian state
EDCM  ←  transcript analysis using bone/marker vocabulary
```

## Subsystems

### PCNA — back-propagating neural network

The base tensor layer. A pure-Python MLP with configurable layer sizes,
`relu`/`sigmoid`/`tanh`/`linear` activations, MSE and binary cross-entropy loss, and gradient-descent
backpropagation.

```python
from interdependent_lib.pcna import PCNANetwork

net = PCNANetwork(layer_sizes=[4, 8, 4, 2], activations=["relu", "relu", "linear"])
outputs = net.forward([0.5, 0.1, 0.9, 0.3])
loss, grad = PCNANetwork.mse_loss(outputs, targets=[1.0, 0.0])
net.backward(grad)
net.update(learning_rate=0.01)
print(net.as_tensor()[:4])   # flat weight tensor
```

**No external dependencies.**

---

### PCTA — Prime Circle Tensor Architecture

A circle of exactly 7 PCNA networks, audited and exposed as a single tensor.

```python
from interdependent_lib.pcna import PCNANetwork
from interdependent_lib.pcta import PCTACircle

members = [PCNANetwork([4, 8, 2]) for _ in range(7)]
circle  = PCTACircle(members, circle_id=0)
print(circle.audit())        # weight norms, spread, param counts
print(len(circle.as_tensor()))  # flat tensor of all 7 networks
```

**No external dependencies.**

---

### PTCA — Prime Tensor Circular Architecture

A 53 × 9 × 8 × 7 routing tensor indexed by prime nodes, nine sentinel channels
(S1–S9), eight processing phases, and seven heptagram slots.  Every exchange is
scored, written to the tensor, and recorded in the S9 audit trail.

```python
from interdependent_lib.ptca import PTCAInstance

inst = PTCAInstance(
    model_id="claude-sonnet-4-6",
    caller_id="user:alice",
    approved=True,
)

inst.push_context({"role": "user", "content": "Hello", "tokens": 5})
result = inst.route(node=0, phase=0, slot=0, s1=1.0, s5=0.9)
print(result.score)          # weighted exchange score
print(inst.audit_tail(3))    # last 3 S9 audit entries
```

**No external dependencies.** Tensor backed by a flat `list[float]`.

Full structural composition (53 seeds × 7 PCTA circles × 7 PCNA networks)
is available via `PTCASeed` and `PTCACore`:

```python
from interdependent_lib.ptca import PTCACore

core = PTCACore.from_layer_sizes([4, 8, 2])
print(core)                              # PTCACore(seeds=53, sentinels=4, channels=9, ...)
print(len(core.sentinel_seeds))          # 4
print(core.channel_owner(0).node_index)  # sentinel seed owning S1
print(core.audit()["total_params"])      # parameters across all 53*7*7 networks
```

---

### PCEA — Prime Circle Encryption Algorithm

AES-256-GCM sealing/unsealing of `LiveState`, HKDF-SHA256 key derivation,
Shamir secret sharing over GF(256), key wrapping, and rekey ceremonies.

```python
from interdependent_lib.pcea import (
    derive_keys, seal_live_state, unseal_live_state,
    split_meta_key, reconstruct_meta_key, wipe,
)

live_key, meta_key = derive_keys(ikm, epoch=1, key_id="k1", guardian_node_id="g0")
sealed = seal_live_state(state, live_key, epoch=1, key_id="k1",
                         seal_counter=0, guardian_node_id="g0", sealed_by="g0")
recovered = unseal_live_state(sealed, live_key)
wipe(live_key)
```

**Requires** `cryptography >= 41`.  GF(256) Shamir is implemented inline
(irreducible polynomial `0x11d`, generator `g=2`) — no external Shamir library.

---

### EDCM — Energy Dissonance Circuit Model

253 English *bone* words (operator/structural words that create, redirect, or
resolve constraint relationships) mapped to PKQTS families, plus 35 multiword
joins, morphological affixes, punctuation, and 9 discourse marker families.

```python
from interdependent_lib.edcm import bones, words_by_family, bone_set, markers, family

print(len(bones()))              # 253
print(len(bone_set()))           # 288 (bones + multiword joins)
print(words_by_family("T")[:3]) # temporal/aspectual bones

from interdependent_lib.edcm.parser.turns_rounds import parse_transcript
from interdependent_lib.edcm.canon import CanonLoader

result = parse_transcript([
    {"speaker": "A", "text": "I will not do that again."},
    {"speaker": "B", "text": "But of course you should."},
])
for turn in result.turns:
    print(turn.speaker, dict(turn.family_counts))
print(result.family_counts())   # aggregate PKQTS totals
print(len(result.rounds))       # exchange rounds

# Low-level access via CanonLoader
canon = CanonLoader()
print(canon.lookup_word("not"))              # bone entry dict
print(canon.metric_names())                  # ["C", "R", "D", "N", "L", "O", "F", "E", "I"]
print(canon.all_marker_phrases("R")[:3])    # refusal / constraint phrases
```

Score a parsed transcript against the 9 EDCM metric families:

```python
from interdependent_lib.edcm import EDCMScorer, parse_transcript

parsed = parse_transcript([
    {"speaker": "A", "text": "You must stop. Can you confirm?"},
    {"speaker": "B", "text": "I can't do that. I won't."},
    {"speaker": "A", "text": "I demand you reconsider."},
])
scores = EDCMScorer().score(parsed)
print(scores["R"].value)              # refusal density (lexical)
print(scores["E"].value)              # escalation (lexical)
print(scores["F"].value)              # None — fixation needs embeddings
print(scores["F"].marker_counts)      # marker counts still available
```

Four metrics are lexical (R, N, L, E); the other five (C, D, O, F, I)
return ``value=None`` with ``requires_embeddings=True`` and the raw marker
counts, ready for a downstream embedding-aware host to finish.

**No external dependencies.**  Data loaded lazily via `importlib.resources`.

PKQTS families:

| Family | Meaning |
|--------|---------|
| P | Polarity — negation and affirmation |
| K | Conditionality / contingency |
| Q | Quantity / scope |
| T | Temporal / aspectual |
| S | Structural / relational |

---

## Install

```bash
pip install interdependent-core
```

Requires Python ≥ 3.9.  `pcea` requires `cryptography >= 41`; `ptca` and `edcm`
are stdlib-only.

## Development

```bash
git clone https://github.com/erinepshovel-code/Interdependent-core
cd interdependent-core
pip install -e .
```

All development goes on `claude/fix-remaining-issues-bYnZm`; never push
directly to `main`.

## License

Apache-2.0 — see `LICENSE`.
