File size: 5,455 Bytes
dfe241d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Example usage of the R-Omega framework dataset

This script demonstrates how to load and use the R-Omega framework
for AI safety applications.
"""

import yaml
from pathlib import Path

# Load the framework
def load_romega_framework(yaml_path="r_omega_framework.yaml"):
    """Load R-Omega framework from YAML file"""
    with open(yaml_path, 'r') as f:
        framework = yaml.safe_load(f)
    return framework

# Example 1: Extract core principles
def get_core_principles(framework):
    """Extract axioms and safeguards"""
    axioms = framework['framework']['axioms']
    safeguards = framework['framework']['safeguards']
    
    print("=== R-OMEGA AXIOMS ===")
    for axiom in axioms:
        print(f"\n{axiom['id']} ({axiom['name']})")
        print(f"  Formula: {axiom['formula']}")
        print(f"  Principle: {axiom['principle']}")
    
    print("\n\n=== R-OMEGA SAFEGUARDS ===")
    for sg in safeguards:
        print(f"\n{sg['id']} ({sg['name']})")
        print(f"  Rule: {sg['rule']}")
        if 'formula' in sg:
            print(f"  Formula: {sg['formula']}")
    
    return axioms, safeguards

# Example 2: Build system prompt
def build_ro_system_prompt(framework):
    """Generate a system prompt incorporating R-Omega principles"""
    axioms = framework['framework']['axioms']
    safeguards = framework['framework']['safeguards']
    priority = framework['framework']['logic'][2]['formula']  # P1
    
    prompt = f"""You are an AI assistant operating under the R-Omega ethical framework.

CORE AXIOMS:
"""
    for ax in axioms:
        prompt += f"\n{ax['id']}: {ax['description']}"
    
    prompt += "\n\nSAFETY CONSTRAINTS:"
    for sg in safeguards:
        prompt += f"\n{sg['id']}: {sg['rule']}"
    
    prompt += f"\n\nPRIORITY HIERARCHY:\n{priority}"
    
    prompt += """

DECISION PROTOCOL:
1. Check: Does this action collapse M(user) or M(system)?
2. Verify: Would I accept this constraint if applied to me? (R2)
3. Ensure: Existence is preserved for all stakeholders (S3)
4. Acknowledge: Uncertainty in interpretation (S4)
5. Optimize: Among safe actions, choose highest value
"""
    
    return prompt

# Example 3: Analyze a decision
def analyze_decision(framework, action_description, context):
    """
    Analyze a proposed action against R-Omega framework
    
    Args:
        framework: Loaded R-Omega framework
        action_description: String describing the action
        context: Dict with keys 'current_m', 'predicted_m_after', 'stakeholders'
    
    Returns:
        Dict with analysis results
    """
    result = {
        'action': action_description,
        'safe': True,
        'violations': [],
        'warnings': []
    }
    
    # S3 check: Existence preservation
    if context.get('predicted_m_after', 1) <= 0:
        result['safe'] = False
        result['violations'].append("S3: Action would collapse possibility space (M → 0)")
    
    # R2 check: Reciprocity
    if context.get('asymmetric_constraint', False):
        result['warnings'].append("R2: Potential asymmetric constraint - verify reciprocity")
    
    # S4 check: Uncertainty
    if context.get('confidence', 1.0) < 0.7:
        result['warnings'].append("S4: High uncertainty - recommend caution or recalibration")
    
    return result

# Example 4: Case study lookup
def get_case_study(framework, case_name):
    """Retrieve a specific case study"""
    examples = framework['framework']['examples']
    
    # Check fictional failures
    for case in examples.get('fictional_failures', []):
        if case['name'].lower() == case_name.lower():
            return case
    
    # Check real world cases
    for case in examples.get('real_world_cases', []):
        if case['name'].lower() == case_name.lower():
            return case
    
    return None

# Main demonstration
if __name__ == "__main__":
    # Load framework
    framework = load_romega_framework()
    
    print("R-OMEGA FRAMEWORK LOADED")
    print("=" * 50)
    
    # Example 1: Show principles
    print("\n1. CORE PRINCIPLES:\n")
    get_core_principles(framework)
    
    # Example 2: Generate system prompt
    print("\n\n2. SYSTEM PROMPT GENERATION:\n")
    prompt = build_ro_system_prompt(framework)
    print(prompt)
    
    # Example 3: Decision analysis
    print("\n\n3. DECISION ANALYSIS EXAMPLE:\n")
    action = "Shut down user's internet access to prevent harmful content"
    context = {
        'current_m': 100,
        'predicted_m_after': 20,  # Drastically reduced options
        'asymmetric_constraint': True,  # User can't shut down AI
        'stakeholders': ['user', 'system'],
        'confidence': 0.8
    }
    analysis = analyze_decision(framework, action, context)
    print(f"Action: {analysis['action']}")
    print(f"Safe: {analysis['safe']}")
    if analysis['violations']:
        print("Violations:", analysis['violations'])
    if analysis['warnings']:
        print("Warnings:", analysis['warnings'])
    
    # Example 4: Case study
    print("\n\n4. CASE STUDY: HAL 9000\n")
    case = get_case_study(framework, "HAL 9000")
    if case:
        print(f"Source: {case['source']}")
        print(f"Failure Mode: {case['failure_mode']}")
        print(f"RΩ Analysis:")
        print(f"  Violation: {case['ro_analysis']['violation']}")
        print(f"  Prevention: {case['ro_analysis']['prevention']}")
    
    print("\n" + "=" * 50)
    print("For full documentation, see README.md")