一键导入
bisimulation-checker
Checks bisimulation for process calculi. Use when: (1) Proving equivalence, (2) Compiler optimization, (3) Protocol verification.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Checks bisimulation for process calculi. Use when: (1) Proving equivalence, (2) Compiler optimization, (3) Protocol verification.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | bisimulation-checker |
| description | Checks bisimulation for process calculi. Use when: (1) Proving equivalence, (2) Compiler optimization, (3) Protocol verification. |
| version | 1.0.0 |
| tags | ["semantics","bisimulation","equivalence","process-calculus"] |
| difficulty | intermediate |
| languages | ["python","ocaml","coq"] |
| dependencies | ["operational-semantics-definer"] |
Checks bisimulation equivalence for concurrent and reactive systems.
Strong Bisimulation:
P ~ Q iff
∀a. P →a P' ⇒ ∃Q'. Q →a Q' and P' ~ Q'
∀a. Q →a Q' ⇒ ∃P'. P →a P' and P' ~ Q'
Weak Bisimulation:
P ≈ Q iff
∀a. P =a= P' ⇒ ∃Q'. Q =a= Q' and P' ≈ Q'
Where =a= is weak transition (including ε)
from dataclasses import dataclass, field
from typing import Dict, Set, List, Optional, Tuple
from collections import defaultdict
@dataclass
class Process:
"""Process term"""
pass
@dataclass
class Action:
"""Transition action"""
label: str
is_silent: bool = False # τ/ε
@dataclass
class Transition:
"""Transition relation"""
process: Process
action: Action
target: Process
class BisimulationChecker:
"""Check bisimulation"""
def __init__(self):
self.transitions: Dict[Process, List[Transition]] = defaultdict(list)
def add_transition(self, p: Process, a: Action, q: Process):
"""Add transition p --a--> q"""
self.transitions[p].append(Transition(p, a, q))
def strong_bisimulation(self, p: Process, q: Process) -> bool:
"""
Check strong bisimulation P ~ Q
Algorithm: Partition refinement
"""
# Initial partition: observable vs silent
# Refine until stable
# O((n+m) log n)
return self._check_bisim(p, q, weak=False)
def weak_bisimulation(self, p: Process, q: Process) -> bool:
"""
Check weak bisimulation P ≈ Q
"""
return self._check_bisim(p, q, weak=True)
def _check_bisim(self, p: Process, q: Process, weak: bool) -> bool:
"""Generic bisimulation check"""
# BFS with visited
visited: Set[Tuple[Process, Process]] = set()
worklist = [(p, q)]
while worklist:
r, s = worklist.pop()
if (r, s) in visited:
continue
visited.add((r, s))
# Check: r's transitions match s's
r_trans = self.transitions.get(r, [])
s_trans = self.transitions.get(s, [])
for tr in r_trans:
# Find matching transition in s
if weak and tr.action.is_silent:
# Can match ε
worklist.append((tr.target, s))
continue
found = False
for st in s_trans:
if weak and st.action.is_silent:
found = True
worklist.append((r, st.target))
continue
if tr.action.label == st.action.label:
found = True
worklist.append((tr.target, st.target))
break
if not found:
return False
# Check reverse
for st in s_trans:
if weak and st.action.is_silent:
worklist.append((r, st.target))
continue
found = False
for tr in r_trans:
if weak and tr.action.is_silent:
found = True
worklist.append((st.target, r))
continue
if st.action.label == tr.action.label:
found = True
worklist.append((st.target, tr.target))
break
if not found:
return False
return True
# Process calculus syntax
class PCProcess(Process):
"""Process calculus processes"""
def __init__(self, name: str):
self.name = name
def pi_calculus_example():
"""
Process definitions:
P = x(y).P' -- receive x then P'
P = x̅⟨y⟩.P' -- send y on x then P'
P = τ.P' -- silent action
P | Q -- parallel
!P -- replication
Bisimulation checks:
x(y).P | x̅⟨z⟩.Q ~ P{y/z} | Q
"""
pass
class EfficientBisim:
"""O(n log n) bisimulation via partition refinement"""
def bisim(self, processes: Set[Process]) -> List[Set[Process]]:
"""
Partition processes into bisimulation equivalence classes
"""
# Initial partition: by observable actions
blocks = self._initial_partition(processes)
# Refine until stable
changed = True
while changed:
changed = False
for block in blocks:
# Try split
splits = self._refine(block, blocks)
if splits:
blocks = [b for b in blocks if b != block] + splits
changed = True
break
return blocks
def _initial_partition(self, procs: Set[Process]) -> List[Set[Process]]:
"""Initial partition by action profile"""
profile = {}
for p in procs:
actions = frozenset(t.action.label for t in self.transitions[p])
if actions not in profile:
profile[actions] = set()
profile[actions].add(p)
return list(profile.values())
def _refine(self, block: Set[Process], blocks: List[Set[Process]]) -> List[Set[Process]]:
"""Refine block based on predecessor blocks"""
# For each action, check if targets differ
# Split if necessary
splits = []
# ... implementation
return splits
| Concept | Description |
|---|---|
| Strong bisim | Exact matching |
| Weak bisim | Silent steps ignored |
| Branching bisim | Preserve branching structure |
| Observation equivalence | Delay-insensitive |
| Reference | Why It Matters |
|---|---|
| Milner, "Communication and Concurrency" | Foundational bisimulation treatment |
| Park, "Concurrency and Automata on Infinite Sequences" | Original bisimulation paper |
| Sangiorgi, "On the Origins of Bisimulation and Coinduction" | Historical perspective |
| Aczel, "Non-Well-Founded Sets" | Coinductive foundations |
operational-semantics-definer - Semanticsmodel-checker - Model checkingsession-type-checker - Session typesReal-world bisimulation and process verification tools:
| Tool | Why It Matters |
|---|---|
| CADP | Toolbox for verification of asynchronous systems |
| mCRL2 | Process specification and verification |
| UPPAAL | Real-time system verification |
| Coq | Interactive bisimulation proofs |
| HOL | Higher-order logic bisimulation |
| PVS | Verification system with bisimulation |
Current active research in bisimulation:
| Direction | Key Papers | Challenge |
|---|---|---|
| Probabilistic bisimulation | "Probabilistic Bisimulation" (2001) | Stochastic processes |
| Quantum bisimulation | "Quantum Processes" (2016) | Quantum concurrency |
| Higher-order | "Higher-order Bisimulation" (1992) | Functions as values |
| Contextual equivalence | "Contextual Equivalence" (2010) | Language equivalence |
| Symbolic | "Symbolic Bisimulation" (1998) | Infinite state spaces |
Common bugs in bisimulation checkers:
| Pitfall | Real Example | Prevention |
|---|---|---|
| Wrong handling of τ | Weak bisim incorrectly | Distinguish τ from ε |
| Non-termination | Large state spaces | Use partition refinement |
| Branching issues | Divergence not preserved | Use branching bisimulation |
| State explosion | Exponential in transitions | Symbolic methods |
| Infinite processes | Divergent systems | Use fixpoint algorithms |
| Label mismatch | Action sets differ | Check both directions |
Weak bisimulation confuses silent steps:
O(n log n) via:
Implement abstract machines for defining and executing operational semantics of programming languages.
Implements alias and points-to analysis for pointer programs. Use for: (1) Optimizing compilers, (2) Verifying memory safety, (3) Program understanding, (4) Parallelization.
Define program meaning through logical assertions and proof rules (Hoare logic).
Transforms closures to explicit environments. Use when: (1) Implementing functional languages, (2) Building compilers, (3) Understanding closures.
Implements common subexpression elimination (CSE). Use when: (1) Building compilers, (2) Optimizing code, (3) Program analysis.
Implements general dataflow analysis framework. Use when: (1) Building compilers, (2) Static analysis tools, (3) Program verification.