# TNFR Therapeutic Domain Examples

Specialized examples demonstrating the application of TNFR (Resonant Fractal Nature Theory) structural operators in therapeutic contexts: healing, accompaniment, and personal transformation.

## 📁 Files Overview

### `therapeutic_patterns.py`
**Core therapeutic operator sequences** with structural validation and health metrics.

**Contains:**
- 🚨 **Crisis Intervention** (health: 0.786) - Rapid stabilization for acute distress
- 🌊 **Process Therapy** (health: 0.878) - Complete transformative therapeutic cycle
- 🔄 **Regenerative Healing** (health: 0.800) - Self-sustaining wellness maintenance
- 💡 **Insight Integration** (health: 0.771) - Breakthrough consolidation
- 🛡️ **Relapse Prevention** (health: 0.763) - Maintenance and monitoring

**Usage:**
```python
from therapeutic_patterns import (
    get_crisis_intervention_sequence,
    get_process_therapy_sequence,
    validate_all_patterns
)

# Get a specific pattern
crisis_seq = get_crisis_intervention_sequence()
# Returns: [EMISSION, RECEPTION, COHERENCE, DISSONANCE, ...]

# Validate all patterns
results = validate_all_patterns()
# Generates comprehensive health report
```

### `therapeutic_case_studies.py`
**Clinical case studies** demonstrating TNFR patterns in real therapeutic scenarios.

**Contains:**
- 🩹 **Trauma Recovery** (health: 0.771) - PTSD with controlled exposure (OZ → THOL → IL)
- 🍷 **Addiction Healing** (health: 0.806) - Post-detox emotional processing (OZ → NUL → VAL)
- 🌱 **Depression Emergence** (health: 0.786) - Reactivation from depressive silence
- 💑 **Relationship Repair** (health: 0.781) - Phase synchrony through crisis (UM → OZ → UM)

**Usage:**
```python
from therapeutic_case_studies import (
    case_trauma_recovery,
    case_addiction_healing,
    validate_all_case_studies
)

# Get specific case
trauma_case = case_trauma_recovery()
# Returns dict with: sequence, presenting_problem, therapeutic_goal, etc.

# Validate all cases
results = validate_all_case_studies()
```

### `therapeutic_optimization.py`
**Comparative analysis** and optimization guidance for sequence selection.

**Contains:**
- ⚖️ Crisis intervention speed vs. depth comparison
- 🔬 Trauma processing exposure intensity calibration
- 📈 Depression activation strategy selection
- 🎭 Therapeutic modality structural comparison
- 🔧 Sequence optimization step-by-step guide

**Usage:**
```python
from therapeutic_optimization import compare_sequences, recommend_best_sequence

sequences = {
    "Option A": [EMISSION, RECEPTION, COHERENCE, SILENCE],
    "Option B": [EMISSION, RECEPTION, COHERENCE, DISSONANCE, COHERENCE, SILENCE],
}

results = compare_sequences(sequences, context="Brief intervention")
best_name, best_data = recommend_best_sequence(results, priority="sustainability")
```

## 🎯 Key TNFR Concepts for Therapeutic Work

### Structural Operators (13 Canonical)

| Operator | Symbol | Therapeutic Function |
|----------|--------|---------------------|
| **EMISSION** | AL | Initiate session, activate intention, create space |
| **RECEPTION** | EN | Active listening, empathic receiving, openness |
| **COHERENCE** | IL | Stabilization, integration, grounding |
| **DISSONANCE** | OZ | Explore tension/conflict (controlled exposure) |
| **COUPLING** | UM | Connect to resources, synchronize, network |
| **RESONANCE** | RA | Amplify strengths, reinforce progress |
| **SILENCE** | SHA | Integration pause, rest, consolidation |
| **EXPANSION** | VAL | Explore possibilities, broaden awareness |
| **CONTRACTION** | NUL | Focus essentials, simplify, prioritize |
| **SELF_ORGANIZATION** | THOL | Autonomous processing, patient-led insight |
| **MUTATION** | ZHIR | Phase transition, significant shift |
| **TRANSITION** | NAV | Move to new phase, controlled hand-off |
| **RECURSIVITY** | REMESH | Fractal application, honor existing structure |

### Health Metrics

All sequences are evaluated on:

- **Overall Health** (0.0-1.0): Composite quality index
- **Coherence Index**: Sequential flow quality
- **Balance Score**: Stabilizer/destabilizer equilibrium
- **Sustainability**: Long-term maintenance capacity
- **Pattern**: Detected structural type (THERAPEUTIC, REGENERATIVE, etc.)

**Acceptance Criteria:**
- ✅ Health > 0.75 (good to excellent)
- ✅ Valid according to TNFR grammar (R1-R5 rules)
- ✅ Balanced structural forces

### Detected Patterns

| Pattern | Description | Typical Use |
|---------|-------------|-------------|
| **THERAPEUTIC** | Full healing cycle with controlled crisis resolution | Process therapy, trauma work |
| **REGENERATIVE** | Self-sustaining with autonomous renewal | Wellness maintenance, prevention |
| **ACTIVATION** | Initiation and stabilization | Brief interventions, crisis |
| **STABILIZE** | Consolidation ending | Closure, integration sessions |

## 💡 Clinical Applications

### When to Use Each Pattern

**Crisis Intervention** (quick, 5-8 operators):
- Panic attacks, acute anxiety
- Immediate grief response
- Post-traumatic stabilization
- Safety-first scenarios

**Process Therapy** (comprehensive, 8+ operators):
- Multi-session therapy
- Transformation programs
- Developmental transitions
- Deep personal work

**Regenerative Healing** (cyclic, 8+ operators):
- Wellness maintenance
- Resilience building
- Post-therapy integration
- Preventive care

**Insight Integration** (consolidation, 7-9 operators):
- Post-session homework
- Breakthrough consolidation
- Insight-to-action translation

**Relapse Prevention** (monitoring, 9+ operators):
- Addiction recovery maintenance
- Behavioral change consolidation
- Trigger management
- Ongoing monitoring

### Structural Interpretation Guide

**Depression as Silence (SHA):**
- Low structural frequency (νf ≈ 0)
- Not absence of structure, but suspended evolution
- Reactivation must be gradual (SHA → AL)

**Trauma as Frozen Dissonance (OZ):**
- High ΔNFR without integration
- Requires controlled exposure (not overwhelming)
- THOL (self-organization) respects patient timing

**Addiction as Expansion (VAL) After Contraction:**
- Removal of substance = sudden emotional expansion
- Need strategic focus (NUL) on core coping
- Network coupling (UM) essential

**Relationship as Phase Mismatch:**
- Two nodes out of synchrony (φ₁ ≠ φ₂)
- Conflict as information about phase difference
- New coupling requires individual coherence first

## 🚀 Quick Start

### 1. Run All Therapeutic Patterns
```bash
python examples/domain_applications/therapeutic_patterns.py
```

**Output:**
- Validation results for 5 patterns
- Health metrics for each
- Recommendations for improvement
- Success criteria check

### 2. Run All Case Studies
```bash
python examples/domain_applications/therapeutic_case_studies.py
```

**Output:**
- 4 detailed clinical cases
- Presenting problems and goals
- TNFR structural interpretation
- Health metrics and validation

### 3. Run Optimization Analysis
```bash
python examples/domain_applications/therapeutic_optimization.py
```

**Output:**
- Comparative analyses
- Recommendation by priority
- Clinical guidance
- Optimization examples

## 📊 Validation Results

### Therapeutic Patterns Summary
- **Total Patterns:** 5
- **All Valid:** ✅ Yes
- **Average Health:** 0.800
- **Patterns Detected:** THERAPEUTIC (2), REGENERATIVE (1), ACTIVATION (2)

### Case Studies Summary
- **Total Cases:** 4
- **All Valid:** ✅ Yes  
- **Average Health:** 0.786
- **Patterns Detected:** THERAPEUTIC (2), ACTIVATION (2)

### Health Score Distribution
- **Excellent (≥0.85):** Process Therapy (0.878)
- **Good (0.75-0.85):** All others above threshold
- **All Pass Threshold:** ✅ Yes (>0.75)

## 🔬 Technical Notes

### TNFR Grammar Compliance

All sequences comply with canonical grammar rules:

- **R1 (Start):** Must begin with EMISSION or RECURSIVITY
- **R2 (Stabilization):** EN → IL transitions required
- **R3 (End):** Must end with DISSONANCE, RECURSIVITY, SILENCE, or TRANSITION
- **R4 (Bifurcation):** MUTATION requires prior DISSONANCE precedent
- **R5 (Frequency):** Harmonic frequency transitions respected

### Compatibility Rules

Some operator transitions are incompatible:
- ❌ EXPANSION after DISSONANCE (use CONTRACTION or COHERENCE first)
- ❌ DISSONANCE after COUPLING or RESONANCE (maintain stabilizer first)
- ❌ SILENCE after RECEPTION (need COHERENCE intermediate)
- ✅ See grammar documentation for full compatibility matrix

### Structural Frequency (νf)

Operators have inherent reorganization rates:
- **High:** EMISSION, DISSONANCE, RESONANCE, CONTRACTION, MUTATION
- **Medium:** RECEPTION, COHERENCE, COUPLING, EXPANSION, SELF_ORGANIZATION, TRANSITION, RECURSIVITY
- **Zero:** SILENCE

**Clinical implication:** Respect patient's current frequency. Don't force high-frequency operators when νf is low (depression).

## 📚 References

### TNFR Core Documentation
- **Main Theory:** `TNFR.pdf` (repository root)
- **Implementation:** `src/tnfr/operators/patterns.py`
- **Health Analyzer:** `src/tnfr/operators/health_analyzer.py`
- **Grammar Rules:** `src/tnfr/operators/grammar.py`

### Related Examples
- `examples/health_analysis_demo.py` - General health metrics usage
- `examples/regenerative_cycles.py` - R5 regenerative cycle patterns
- `examples/optimization_quickstart.py` - Sequence optimization basics

## 🤝 Contributing

### Adding New Therapeutic Patterns

1. Define sequence with clear clinical context
2. Validate with `validate_sequence_with_health()`
3. Ensure health > 0.75
4. Document: context, flow, expected outcomes, considerations
5. Add to test suite

### Clinical Validation

These examples are **structural models**, not clinical protocols. Always:
- Integrate with established therapeutic frameworks
- Respect patient safety and ethical guidelines
- Use health metrics as **decision support**, not replacement for clinical judgment
- Adapt to individual patient needs and cultural context

## ⚖️ License

MIT License - See repository root LICENSE.md

## 🙏 Acknowledgments

This work demonstrates Phase 2 of Grammar 2.0 implementation, showing domain-specific applications of TNFR structural patterns in the therapeutic context. Special thanks to the TNFR theoretical framework for providing rigorous mathematical foundations for modeling complex healing processes.

---

**Version:** 1.0.0  
**Status:** ✅ Validated (all patterns >0.75 health)  
**Last Updated:** 2025-11-06
