BuddyMath / proof_graph.py
dotandru's picture
Fix: Clean production deployment with sse-starlette
9d29c62
Raw
History Blame
1.49 kB
# proof_graph.py - Immutable Mathematical Structure
from pydantic import BaseModel, Field
from typing import Optional, List, Dict, Any
class ProofStep(BaseModel):
step_id: int
math_content: str # Immutable SymPy/LaTeX (or math_artifact)
logic_description: str = ""
operator_used: str = ""
# V6 Additions:
rule_id: str = "general_algebra"
allowed_concepts: List[str] = Field(default_factory=list)
complexity_score: float = 1.0
pedagogical_tag: str = "כללי"
class ProofGraph:
def __init__(self, steps: list[ProofStep]):
self.steps = steps
self.is_verified = False
def verify_consistency(self):
# SymPy identity checks between steps
pass
def validate_pedagogical_legality(proof_graph: ProofGraph, curriculum_rules: dict) -> tuple[bool, str]:
"""
V4.0: The Hard Enforcement Rule.
Checks if any step in the proof graph uses a forbidden math operator.
"""
forbidden = curriculum_rules.get("forbidden", [])
reason_map = curriculum_rules.get("reason_map", {})
for step in proof_graph.steps:
if step.operator_used in forbidden:
detailed_reason = reason_map.get(step.operator_used, step.operator_used)
msg = f"Forbidden operator used: {detailed_reason}. Not allowed for this grade/level."
print(f"🚨 [PEDAGOGY-GUARD] REJECTED: {msg}")
return False, msg
return True, "Solution is pedagogically legal."