Symbolic and numerical mathematics tools for analyzing, verifying, and optimizing TNFR dynamics.
Provides formal mathematical verification of TNFR sequences and dynamics:
The module is included with TNFR-Python-Engine. Requires:
pip install sympy numpy scipyfrom tnfr.math import symbolic
# 1. Display the nodal equation
eq = symbolic.get_nodal_equation()
print(symbolic.pretty_print(eq))
# Output: ∂EPI/∂t = νf · ΔNFR
# 2. Check convergence (U2 grammar)
converges, explanation, value = symbolic.check_convergence_exponential(
growth_rate=0.15, # Positive growth
time_horizon=10.0
)
print(explanation)
# Output: DIVERGES: λ=0.15 > 0 (growing, NEEDS STABILIZERS!)
# 3. Evaluate bifurcation risk (U4 grammar)
at_risk, deriv, recommendation = symbolic.evaluate_bifurcation_risk(
nu_f_val=1.5,
delta_nfr_val=2.0,
d_nu_f_dt=0.3,
d_delta_nfr_dt=1.2,
threshold=1.0
)
print(recommendation)
# Output: ⚠️ BIFURCATION RISK: Apply handlers {THOL, IL}# Get canonical equation: ∂EPI/∂t = νf · ΔNFR
eq = symbolic.get_nodal_equation()
# Solve for constant parameters
solution = symbolic.solve_nodal_equation_constant_params(
nu_f_val=2.0, # Hz_str
delta_nfr_val=0.5,
EPI_0=1.0,
t0=0
)
# Returns: EPI(t) = 1.0*t + 1.0# Check if integral converges: ∫ νf·ΔNFR dt < ∞
converges, explanation, value = symbolic.check_convergence_exponential(
growth_rate=-0.1, # Negative = stabilized
time_horizon=10.0
)
if converges:
print("✓ U2 satisfied: Integral converges")
else:
print("⚠️ U2 violated: Needs stabilizers {IL, THOL}")# Evaluate ∂²EPI/∂t² threshold
at_risk, second_deriv, recommendation = symbolic.evaluate_bifurcation_risk(
nu_f_val=1.0, # Current frequency
delta_nfr_val=0.3, # Current gradient
d_nu_f_dt=0.1, # Rate of frequency change
d_delta_nfr_dt=0.2, # Rate of gradient change
threshold=1.0 # Bifurcation threshold τ
)
if at_risk:
print("⚠️ Apply handlers per U4a")# Get symbolic form: ∂²EPI/∂t² = (∂νf/∂t)·ΔNFR + νf·(∂ΔNFR/∂t)
second_deriv = symbolic.compute_second_derivative_symbolic()
print(symbolic.pretty_print(second_deriv))# Export to LaTeX
latex_str = symbolic.latex_export(eq)
# Output: \frac{d}{d t} \operatorname{EPI}{\left(t \right)} = \delta_{NFR} \nu_{f}
# Pretty print
print(symbolic.pretty_print(eq))
# Output:
# d
# ──(EPI(t)) = DELTA_NFR⋅ν_f
# dtSee examples/math_symbolic_usage.py for complete examples:
python examples/math_symbolic_usage.pyDemonstrates:
All functions derive from the canonical TNFR nodal equation:
∂EPI/∂t = νf · ΔNFRWhere:
Key insights:
See: AGENTS.md § Foundational Physics
Run the test suite:
pytest tests/test_math_symbolic.py -vCoverage:
All 15 tests pass.
Physics: For bounded evolution:
∫[t_0 to t_f] νf(τ) · ΔNFR(τ) dτ < ∞Validation:
converges, _, _ = symbolic.check_convergence_exponential(
growth_rate=0.1, # Destabilizer (positive)
time_horizon=10.0
)
assert not converges # Needs stabilizers!Physics: Bifurcation trigger:
∂²EPI/∂t² = (∂νf/∂t)·ΔNFR + νf·(∂ΔNFR/∂t) > τValidation:
at_risk, _, rec = symbolic.evaluate_bifurcation_risk(
nu_f_val=2.0,
delta_nfr_val=1.5,
d_nu_f_dt=0.5,
d_delta_nfr_dt=1.0,
threshold=1.0
)
assert at_risk # Needs handlers {THOL, IL}
assert "THOL" in rec or "IL" in recNew mathematical tools should:
Example structure:
def new_analysis_function(param1: float, param2: float) -> Tuple[bool, str]:
"""
Brief description.
Args:
param1: Description with units
param2: Description
Returns:
(result, explanation)
Physics:
Mathematical derivation or reference to TNFR physics.
See: AGENTS.md § Relevant Section
"""
# Implementation
passsympy for symbolic mathsrc/tnfr/operators/grammar.py: Grammar validation (computational)src/tnfr/metrics/: Coherence, Si, ΔNFR computationsrc/tnfr/physics/fields.py: Structural fields (Φ_s, ∇φ, K_φ)This module provides symbolic/analytical verification while other modules provide computational implementation.
Planned additions:
grammar_validators.py): Formal U1-U6 verificationfields.py): Φ_s, ∇φ, K_φ symbolic formsoptimizer.py): Find optimal operator sequencespredictor.py): Analytical trajectory predictionstability.py): Lyapunov analysis, eigenvaluesproofs.py): Formal proof export to LaTeXSee: GitHub issues for tracking
MIT License - Part of TNFR-Python-Engine
Developed for TNFR-Python-Engine project
See: CONTRIBUTING.md for contribution guidelines