Behavioral Decomposition

Many systems contain complex branching logic.

Even small functions can produce dozens or hundreds of distinct behavioral regions.

CodeLogician performs region decomposition to identify all of these behaviors systematically.


Setup

If Claude Code doesn't already know about CodeLogician, start with:

Learn how to use codelogician by running codelogician doc --help


Example: Payment Authorization

You have a Python function that decides whether to authorize a payment:

def authorize(method: str, amount: float, fraud_score: float) -> str:
    if fraud_score > 0.8:
        return "blocked"
    if method == "card":
        if amount > 10000:
            return "review"
        elif amount > 500 and fraud_score > 0.4:
            return "review"
        else:
            return "approved"
    elif method == "bank_transfer":
        if amount > 50000:
            return "review"
        else:
            return "approved"
    return "rejected"

Manually enumerating all paths through this logic is error-prone. Ask Claude Code:

Use CodeLogician to perform a region decomposition of the authorize function.


What Happens

Claude Code will:

  1. Translate the Python function into an IML model
  2. Run codelogician eval check-decomp to decompose the behavior
  3. Report every distinct behavioral region

Example output:

Region decomposition complete

Regions discovered: 8

Region 1: method = "card", amount <= 500, fraud_score <= 0.8 → approved
Region 2: method = "card", amount > 500, amount <= 10000, fraud_score <= 0.4 → approved
Region 3: method = "card", amount > 500, amount <= 10000, fraud_score > 0.4 → review
Region 4: method = "card", amount > 10000, fraud_score <= 0.8 → review
Region 5: method = "bank_transfer", amount <= 50000, fraud_score <= 0.8 → approved
Region 6: method = "bank_transfer", amount > 50000, fraud_score <= 0.8 → review
Region 7: fraud_score > 0.8 → blocked
Region 8: method ≠ "card", method ≠ "bank_transfer", fraud_score <= 0.8 → rejected

Why Region Decomposition Is Powerful

Region decomposition allows developers to:

  • Understand full system behavior — see every possible execution path
  • Visualize decision boundaries — know exactly where behavior changes
  • Identify unreachable states — find dead code or impossible conditions
  • Validate invariants across regions — verify properties hold everywhere

Example Uses

Behavioral decomposition is particularly useful for:

  • payment and pricing systems
  • trading rules and order matching
  • workflow engines and approval chains
  • access control and permission logic
  • compliance and regulatory decision trees

Next Steps

Continue with: