Skip to content

Optimize NFA Construction for Simple Patterns #3

@ofabiodev

Description

@ofabiodev

Current NFA construction overestimates spectral radius for simple patterns like a+ or [0-9]+, marking them unsafe. This update will:

  • Detect simple vs nested loops correctly
  • Adjust spectral radius calculation
  • Apply DFA minimization to improve accuracy

⚠️ Impact:

Breaking change: patterns previously considered unsafe may now be safe. Users relying on old radius values might see different results.

⚙️ Proposed Implementation:

  • Implement cycle detection for simple loops
  • Modify spectral radius computation
  • Apply DFA minimization after NFA construction

📝 Examples:

check("a+")       // before: unsafe, now: safe ✅
check("(a+)+")    // remains unsafe

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions