agenticraft_foundation.algebra.equivalence¶
Process equivalence checking — trace equivalence, strong/weak bisimulation, and failures equivalence.
Process equivalence checking for CSP.
This module provides: - Trace equivalence: P =_T Q iff traces(P) = traces(Q) - Strong bisimulation: P ∼ Q (finest equivalence) - Weak bisimulation: P ≈ Q (observational equivalence) - Failures equivalence: P =_F Q (CSP standard)
Equivalence hierarchy (finest to coarsest)::
Strong bisimulation (∼)
⊂ Weak bisimulation (≈)
⊂ Failures equivalence (=_F)
⊂ Trace equivalence (=_T)
EquivalenceResult
dataclass
¶
Result of an equivalence check.
Failure
dataclass
¶
A failure: (trace, refusal set).
trace_equivalent(p, q, max_trace_length=100)
¶
Check trace equivalence: traces(P) = traces(Q).
Two processes are trace equivalent if they can perform exactly the same sequences of visible events.
| PARAMETER | DESCRIPTION |
|---|---|
p
|
First process or LTS |
q
|
Second process or LTS |
max_trace_length
|
Maximum trace length to consider
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EquivalenceResult
|
EquivalenceResult with equivalence status |
strong_bisimilar(p, q)
¶
Check strong bisimulation: P ∼ Q.
Strong bisimulation is the finest process equivalence. P ∼ Q iff there exists a relation R such that: - (P, Q) ∈ R - If (P', Q') ∈ R and P' ─a→ P'', then Q' ─a→ Q'' and (P'', Q'') ∈ R - Symmetrically for Q'
| PARAMETER | DESCRIPTION |
|---|---|
p
|
First process or LTS |
q
|
Second process or LTS |
| RETURNS | DESCRIPTION |
|---|---|
EquivalenceResult
|
EquivalenceResult with bisimulation relation if equivalent |
weak_bisimilar(p, q)
¶
Check weak bisimulation: P ≈ Q.
Weak bisimulation ignores τ (internal) actions. P ≈ Q iff there exists a relation R such that: - (P, Q) ∈ R - If (P', Q') ∈ R and P' ─a→ P'', then Q' ═a⇒ Q'' and (P'', Q'') ∈ R where ═a⇒ means τ·a·τ (zero or more τ, then a, then zero or more τ) - Symmetrically for Q'
| PARAMETER | DESCRIPTION |
|---|---|
p
|
First process or LTS |
q
|
Second process or LTS |
| RETURNS | DESCRIPTION |
|---|---|
EquivalenceResult
|
EquivalenceResult with bisimulation relation if equivalent |
failures(lts, max_trace_length=50)
¶
Generate failures of an LTS.
A failure is a pair (s, X) where: - s is a trace the process can perform - X is a set of events the process can refuse after s
| PARAMETER | DESCRIPTION |
|---|---|
lts
|
The LTS to analyze
TYPE:
|
max_trace_length
|
Maximum trace length
TYPE:
|
| YIELDS | DESCRIPTION |
|---|---|
Failure
|
Failure objects |
failures_equivalent(p, q, max_trace_length=50)
¶
Check failures equivalence: P =_F Q.
Two processes are failures equivalent if they have exactly the same failures.
| PARAMETER | DESCRIPTION |
|---|---|
p
|
First process or LTS |
q
|
Second process or LTS |
max_trace_length
|
Maximum trace length
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EquivalenceResult
|
EquivalenceResult with equivalence status |
are_equivalent(p, q, equivalence='trace')
¶
Check if two processes are equivalent.
| PARAMETER | DESCRIPTION |
|---|---|
p
|
First process
TYPE:
|
q
|
Second process
TYPE:
|
equivalence
|
Type of equivalence: - "trace": Trace equivalence - "strong": Strong bisimulation - "weak": Weak bisimulation - "failures": Failures equivalence
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if processes are equivalent |