3 Basic Algebra for Transformers 8
3.1 Axiomatic System 8
3.2 Operational Semantics 11
3.3 Soundness and Completeness 11
4 Algebra of Parallelism for Transformers 13
4.1 Operational Semantics 13
4.2 Axiomatic System 13
4.3 Soundness and Completeness 16
5 Recursion 18
5.1 Operational Semantics 19
5.2 Axiomatic System 19
5.3 Soundness and Completeness 20
6 Abstraction 21
6.1 Silent Step 21
6.1.1 Operational Semantics 21
6.1.2 Axiomatic System 23
6.1.3 Soundness and Completeness 23
6.2 Abstraction 24
6.2.1 Operational Semantics 25
6.2.2 Axiomatic System 25
6.2.3 Soundness and Completeness 26
i
7 Application 29
7.1 Verification of a Transformer for Most-Recent Induction ..... 29
7.1.1 A Transformer Construction of the Most-Recent Induction ..... 29
7.1.2 Algebraic Representation ..... 30
7.1.3 Verification of the Most-Recent Induction Transformer ..... 32
7.2 Verification of a Transformer for Dyck-1 ..... 33
7.2.1 A Transformer Construction for Dyck-1 ..... 33
7.2.2 Algebraic Representation ..... 35
7.2.3 Verification of the Dyck-1 Transformer ..... 37
7.3 Verification of a Transformer for Dyck-1-2 ..... 38
7.3.1 A Transformer Construction of Dyck-1-2 ..... 38
7.3.2 Algebraic Representation ..... 40
7.3.3 Verification of the Dyck-1-2 Transformer ..... 44
ii
1 Introduction
Because of the parallelizability of transformers [1], transformers are becoming the mainstream techniques in large language models (LLMs). On the theoretic analyses on transforms, they mainly focus on the computability analysis, such the Turing-completeness of unbounded precision transformers [2], the advantage of parallelizability of unbounded precision transformers [3] and the limitations of bounded precision transformers [4].
This paper give transformers an algebra for reasoning, which relies heavily on the functional decomposition results of transformers [5], we follow its notations and definitions of transformers.
We write [n] for the set {1,…,n}, X∗ for the set of sequences over set X, X+ for the set of non-empty sequences over X, string Σ∗ as w=w1⋯wn for a finite alphabet Σ, 0 for zero vector or matrix, I for identity matrix, 1 for a vector or matrix whose entries are all 1's. For any function f:R→R and any vector x=[xi]i=1d∈Rd, f is extended coordinate-wise:
f(x)=fx1x2⋮xd=f(x1)f(x2)⋮f(xd)
We write f:X+lpY+ for a function from X+ to Y+, which is length-preserving. And we write f.a for a parameter a of f.
Definition 1.1 (Transformers). A transformer is a function tf:Σ+lpY+, tf(x1⋯xn)=y1⋯yn, where zi(0)=tf.we(xi)+tf.pen(i), (z1(1),…,zn(1))=tf.tl(1)(z1(0),…,zn(0)),…,(z1(L),…,zn(L))=tf.tl(L)(z1(L−1),…,zn(L−1)), yi=tf.out(zi(L)). Where tf.we and tf.pen are word embedding function and position embedding function, tf.tl(ℓ) are transformer layers, tf.out is an unembedding function with some output space Y. For the details of these functions, please refer to [5].
The decomposition of transformers coming from [5] is shown in table 1. The idea of decomposition of a transformer is dividing a transformer into a set of atomic constructions, which are operations of vectors or matrices. For the details of these constructions, please refer to [5].
Table 1: Decomposition of Transformers
Names
Functions
Types
α1
word embedding
Σ→Rd
α2
position embedding
N→Rd
α3
identity
Rd→Rd
α4
min/max
R2→R
α5
add/subtract
R2→R
α6
multiply by c
R→R
α7
multiply xy
R2→R
α8
comparators
R→{0,1}
α9
boolean functions
{0,1}m→{0,1}
to be continued...
continuing: Decomposition of Transformers
Names
Functions
Types
α10
continuous piecewise linear functions
Rd→R
α11
cancel residual
Rd→Rd
α12
identity
(Rd)+→(Rd)+
α13
uniform average
(Rd)+→(Rd)+
α14
first
(Rd)+→(Rd)+
α15
index lookup
(Rd)+→R+
α16
predecessor
(Rd)+→(Rd)+
α17
tie-breaking
--
α18
multi-head
--
α19
unembedding
--
α20
layer normalization
Rd→Rd
ϕ1
conditional
{0,1}×R2→R
end of Decomposition of Transformers
Note that, the atomic constructions include two kinds: one for atomic actions, the other for guards in programming language. The set of atomic actions is denoted Act={α1,α2,α3,α4,α5}∪{α6,α7,α8,α9,α10,α11,α12,α13,α14,α15,α16,α17,α18,α19,α20} and the set of guards is denoted Grd={ϕ1}. In the boolean functions, the truth value true is interpreted as number 1 and false as 0; in the general vectors or matrices operations, true is interpreted as I and false as 0.
2 Preliminaries
For self-satisfactory, in this chapter, we introduce the preliminaries on multiset in section 2.1, equational logic in section 2.2 and pomset labelled transition systems in section 2.3.
2.1 Multiset
Definition 2.1 (Labelled poset). A labelled poset is a tuple u=⟨S,≤,λ⟩, where S is the carrier set, ≤ is a partial order on S and λ is a labelling function λ:S→Σ.
For a labelled poset u, Su, ≤u and λu denote the carrier, the partial order and the labelling of u respectively. The set of labelled posets is denoted LP and the empty labelled poset is 1.
Definition 2.2 (Poset morphism). For posets ⟨S,≤⟩ and ⟨S′,≤′⟩ and function φ:S→S′, f is called a poset morphism if for a0,a1∈S with a0≤a1, then φ(a0)≤′φ(a1) holds.
Definition 2.3 (Labelled poset isomorphism). Let u=⟨S1,≤1,λ1⟩ and v=⟨S2,≤2,λ2⟩ be labelled posets. A labelled poset morphism φ from u=⟨S1,≤1,λ1⟩ to v=⟨S2,≤2,λ2⟩ is a poset morphism from ⟨S1,≤1⟩ and ⟨S2,≤2⟩ with λ2∘φ=λ1. Moreover, φ is a labelled poset isomorphism if it is a bijection with φ−1 is a poset isomorphism from ⟨S2,≤2,λ2⟩ to ⟨S1,≤1,λ1⟩. We say that u=⟨S1,≤1,λ1⟩ is isomorphic to v=⟨S2,≤2,λ2⟩ denoted ⟨S1,≤1,λ1⟩∼⟨S2,≤2,λ2⟩, if there exists a poset isomorphism φ between ⟨S1,≤1,λ1⟩ and ⟨S2,≤2,λ2⟩.
Definition 2.4 (Multiset). A multiset is a kind of set of objects which may be repetitive denoted {−}, such that {a,b,b} is significantly distinguishable from {a,b}.
Definition 2.5 (Pomset). A partially ordered multiset, pomset, is a ~equivalence class of posets. The set of pomsets is denoted Pom; the empty pomset is denoted I and the ~equivalence class of I is also denoted by I.
Definition 2.6 (Pomset composition in parallel). Let U,V∈Pom with U=[u] and V=[v]. We write U∥V for the parallel composition of U and V, which is the pomset represented by u∥v, where
Au∥v=Au∪Av≤u∥v=≤u∪≤v
Definition 2.7 (Pomset composition in sequence). Let U,V∈Pom with U=[u] and V=[v]. We write U⋅V for the sequential composition of U and V, which is the pomset represented by u⋅v, where
Au⋅v=Au∪Av≤u⋅v=≤u∪≤v∪(Au×Av)
Definition 2.8 (Pomset types). Let U∈Pom, U is sequential (resp. parallel) if there exist non-empty pomsets U1 and U2 such that U=U1⋅U2 (resp. U=U1∥U2).
Definition 2.9 (Factorization). Let U∈Pom. (1) When U=U1⋯Ui⋯Un with each Ui non-sequential and non-empty, the sequence U1,⋯,Ui,⋯,Un is called a sequential factorization of U. (2) When U=U1∥⋯∥Ui∥⋯∥Un with each Ui non-parallel and non-empty, the multiset {U1,⋯,Ui,⋯,Un} is called a parallel factorization of U.
Lemma 2.10 (Factorization). Sequential and parallel factorizations exist uniquely.
2.2 Equational Logic
Definition 2.11 (Signature). A signature Σ consists of a finite set of function symbols (or operators) f,g,⋯, where each function symbol f has an arity ar(f), being its number of arguments. A function symbol α,β,γ,⋯ of arity zero is called a constant, a function symbol of arity one is called unary, and a function symbol of arity two is called binary.
Definition 2.12 (Term). Let Σ be a signature. The set T(Σ) of (open) terms s,t,u,⋯ over Σ is defined as the least set satisfying: (1) each variable is in T(Σ); (2) if f∈Σ and t1,⋯,tar(f)∈T(Σ), then f(t1,⋯,tar(f)∈T(Σ)). A term is closed if it does not contain free variables. The set of closed terms is denoted by T(Σ).
Definition 2.13 (Substitution). Let Σ be a signature. A substitution is a mapping σ from variables to the set T(Σ) of open terms. A substitution extends to a mapping from open terms to open terms: the term σ(t) is obtained by replacing occurrences of variables x in t by σ(x). A substitution σ is closed if σ(x)∈T(Σ) for all variables x.
Definition 2.14 (Axiomatization). An axiomatization over a signature Σ is a finite set of equations, called axioms, of the form s=t with s,t∈T(Σ).
Definition 2.15 (Equality relation). An axiomatization over a signature Σ induces a binary equality relation = on T(Σ) as follows. (1) (Substitution) If s=t is an axiom and σ a substitution, then σ(s)=σ(t). (2) (Equivalence) The relation = is closed under reflexivity, symmetry, and transitivity. (3) (Context) The relation = is closed under contexts: if t=u and f is a function symbol with ar(f)>0, then f(s1,⋯,si−1,t,si+1,⋯,sar(f))=f(s1,⋯,si−1,u,si+1,⋯,sar(f)).
Definition 2.16 (Model). Assume an axiomatization E over a signature Σ, which induces an equality relation =. A model for E consists of a set M together with a mapping ϕ:T(Σ)→M. (1) (M,ϕ) is sound for E if s=t implies ϕ(s)≡ϕ(t) for s,t∈T(Σ); (2) (M,ϕ) is complete for E if ϕ(s)≡ϕ(t) implies s=t for s,t∈T(Σ).
Definition 2.17 (Term rewriting system). Assume a signature Σ. A rewrite rule is an expression s→t with s,t∈T(Σ), where: (1) the left-hand side s is not a single variable; (2) all variables that occur at the right-hand side t also occur in the left-hand side s. A term rewriting system (TRS) is a finite set of rewrite rules.
Definition 2.18 (Rewrite relation). A TRS over a signature Σ induces an one-step rewrite relation → on T(Σ) as follows. (1) (Substitution) If s→t is a rewrite rule and σ a substitution, then σ(s)→σ(t). (2) (Context) The relation → is closed under contexts: if t→u and f is a function symbol with ar(f)>0, then f(s1,⋯,si−1,t,si+1,⋯,sar(f))→f(s1,⋯,si−1,u,si+1,⋯,sar(f)). The rewrite relation →∗ is the reflexive transitive closure of the one-step rewrite relation →: (1) if s→t, then s→∗t; (2) t→∗t; (3) if s→∗t and t→∗u, then s→∗u.
Definition 2.19 (Normal form). A term is called a normal form for a TRS if it cannot be reduced by any of the rewrite rules.
Definition 2.20 (Termination). A TRS is terminating if it does not induce infinite reductions t0→t1→t2→⋯.
Definition 2.21 (Weak confluence). A TRS is weakly confluent if for each pair of one-step reductions s→t1 and s→t2, there is a term u such that t1→∗u and t2→∗u.
Theorem 2.22 (Newman's lemma). If a TRS is terminating and weakly confluent, then it reduces each term to a unique normal form.
Definition 2.23 (Convergence). A pair of terms s and t is said to be convergent if there exists a term u such that s→∗u and t→∗u.
Axiomatizations can give rise to TRSs that are not weakly confluent, which can be remedied by Knuth-Bendix completion [6]. It determines overlaps in left hand sides of rewrite rules, and introduces extra rewrite rules to join the resulting right hand sides, witch are called critical pairs.
Theorem 2.24 (Weak confluence). A TRS is weakly confluent if and only if all its critical pairs are convergent.
Definition 2.25 (Elimination property). Let a process algebra with a defined set of basic terms as a subset of the set of closed terms over the process algebra. Then the process algebra has the elimination to basic terms property if for every closed term s of the algebra, there exists a basic term t of the algebra such that the algebra- s = t.
Definition 2.26 (Strongly normalizing). A term s0 is called strongly normalizing if does not an infinite series of reductions beginning in s0.
Definition 2.27. We write s>lpot if s→+t where →+ is the transitive closure of the reduction relation defined by the transition rules of an algebra.
Theorem 2.28 (Strong normalization). Let a term rewriting system (TRS) with finitely many rewriting rules and let > be a well-founded ordering on the signature of the corresponding algebra. If s>lpot for each rewriting rule s→t in the TRS, then the term rewriting system is strongly normalizing.
2.3 Pomset Labelled Transition System
Definition 2.29 (Pomset labelled transition system). A pomset labelled transition system (PLTS) is a quadruple ⟨Proc,Act,{U∣U∈Pom},Pred⟩, where:
Proc is a set of processes, ranged over by p, q.
Act is a set of actions, ranged over by a, b.
Pom is the set of pomsets over Act, ranged over by U, V.
U⊆Proc×Pom×Proc is called a pomset transition for every U∈Pom. We write pUq instead of (p,q)∈U, and write p↛UU if pUq with no state q. Intuitively, pUq means that state p can evolve into state q by the execution of pomset U. We see that traditional single action transition paq with a∈Act is a special case of pomset transition in which the pomset is primitive.
For every P∈Pred, we write pP (resp. p¬P) if state p satisfies (resp. does not satisfy) predicate P. Intuitively, pP means that predicate P holds in state p.
The binary pomset transitions pUq and unary predicates pP in a PLTS are called transitions. Note that, by replacing U∈Pom by a∈Act, we can get the definition of traditional labelled transition system (LTS). And we use Act(p)⊆Act to denote the set of actions occurring in p.
Definition 2.30 (Finiteness conditions on a PLTS). A PLTS is:
Finitely branching: if for every state p there are only finitely many outgoing pomset transitions pUq.
• Regular: if it is finitely branching and each state can reach only finitely many other states.
Finite: if it is finitely branching and there is no infinite sequence of pomset transitions p0U0p1U1⋯.
A pomset transition system specification is a collection of inductive proof rules to derive the pomset transitions over states in Proc.
Definition 2.31 (Pomset transition system specification). Let Σ be a signature, and t,t′∈T(Σ). A pomset transition rule ρ is of the form αH, where H is the set of premises with positive premises tUt′ and tP, and negative premises t↛ and t¬P; α is the conclusion with the form tUt′ and tP, and U∈Pom and P is a predicate. For the conclusion with the form of tUt′, the left-hand side of the conclusion t is called the source of ρ and the right-hand side of the conclusion t′ is called the target of ρ. A transition rule is closed if it does not contain variables.
A pomset transition system specification (PTSS) is a set of pomset transition rules. A PTSS is positive if its transition rules do not contain negative premises.
Definition 2.32 (Pomset transitions). Let p,q∈Proc and U∈Pom, pUq is called a pomset transition from p to q.
Definition 2.33 (Pomset bisimulation). Let ⟨Proc,Act,{U∣U∈Pom},Pred⟩ be a PLTS, S a set of states, and p,q∈Proc and s,s′∈S. A pomset bisimulation is a relation R⊆⟨Proc,S⟩×⟨Proc,S⟩, such that:
If ⟨p,s⟩R⟨q,s⟩ and ⟨p,s⟩U⟨p′,s′⟩, then ⟨q,s⟩U⟨q′,s′⟩, with U∈Pom, and ⟨p′,s′⟩R⟨q′,s′⟩.
If ⟨p,s⟩R⟨q,s⟩ and ⟨q,s⟩U⟨q′,s′⟩, then ⟨p,s⟩U⟨p′,s′⟩, with U∈Pom, and ⟨p′,s′⟩R⟨q′,s′⟩.
If ⟨p,s⟩R⟨q,s⟩ and ⟨p,s⟩P, then ⟨q,s⟩P.
If ⟨p,s⟩R⟨q,s⟩ and ⟨q,s⟩P, then ⟨p,s⟩P.
We say that p, q are pomset bisimilar, written p↔q, if there exists a pomset bisimulation R, such that ⟨p,s⟩R⟨q,s⟩.
Definition 2.34 (Congruence). Let Σ be a signature. An equivalence relation R on T(Σ) is a congruence if for each f∈Σ, if siRti for i∈{1,⋯,ar(f)}, then f(s1,⋯,sar(f))Rf(t1,⋯,tar(f)).
Definition 2.35 (Operational conservative extension). Σ0 and Σ1 are two signatures, the union of Σ0 and Σ1, denoted Σ0⊕Σ1, agrees on the arity of the function symbols in the intersection of Σ0 and Σ1. T0 and T1 are PTSSs over Σ0 and Σ1, the sum of T0 and T1, denoted T0⊕T1, is the PTSS over signature Σ0⊕Σ1 containing the pomset transition rules in T0 and T1. A PTSS T0⊕T1 is an operational conservative extension of PTSS T0, if for each closed transition rule αN such that:
• N contains only negative literals.
• The left-hand side of α is in T(Σ0).
• T0⊕T1⊢αN.
we have that T0⊢αN.
Definition 2.36 (Source-dependency). The source-dependent variables in a pomset transition rule ρ are defined inductively as follows:
• All variables in the source of ρ are source-dependent.
If tUt′ is a premise of ρ and all variables in t are source-dependent, then all variables in t′ are source-dependent.
A pomset transition rule is source-dependent if all its variables are.
Definition 2.37 (Freshness). We say that a term in T(Σ0⊕Σ1) is fresh if it contains a function symbol (may be a constant) from Σ1∖Σ0. Similarly, a predicate symbol in T1 is fresh if it does not occur in T0.
Theorem 2.38 (Operational conservative extension). Let T0 and T1 be PTSSs over signature Σ0 and Σ1, respectively. T0⊕T1 is an operational conservative extension of T0, if:
Each ρ∈T0 is source-dependent.
For each ρ∈T1,
• Either the source of ρ is fresh.
• Or ρ has a premise of the form tUt′ or tP, where:
−t∈T(Σ0).
– All variables in t occur in the source of ρ.
– t′, P and every a∈U are fresh.
3 Basic Algebra for Transformers
In this section, we will discuss the algebraic laws for the set of atomic actions Act the set of guards Grd, the deadlock constant 0 and the identity I, the set of pomsets over Act∪{0}∪{I} denoted Pom, and the serial composition ∘ and the alternative composition +, and let α∈Act∪{0}∪{I}, U∈Pom. The resulted algebra is called Basic Algebra for True Concurrency, abbreviated BAT.
3.1 Axiomatic System
In the following, let α,β,α′,β′∈Act, ϕ,ψ∈Grd, and let variables x,y,z range over the set of terms BAT, p,q,s range over the set of closed terms. The set of axioms of BAT consists of the laws given in Table 2. The predicate test(ϕ,s) represents that ϕ holds in the state s, and test(I,s) holds and test(0,s) does not hold. effect(U,s)∈S denotes s′ in sUs′ for U∈Pom. The predicate weakest precondition wp(U,ϕ) denotes that ∀s,s′∈S,test(ϕ,effect(U,s)) holds.
We extend Grd to the set of basic guards G with element ϕ,ψ,⋯, which is generated by the following formation rules:
ϕ::=0∣I∣¬ϕ∣ψ∈Grd∣ϕ+ψ∣ϕ∘ψ
The deadlock 0 is caused by incomposibility of serial composition, which may be caused by the mismatch of dimensions of vectors or matrices, we define the composibility function of two actions a,b∈Act as follows:
γ(a,b)={a∘b,0,a,barecomposable;otherwise.
Each serial composition implicitly executes this function.
Table 2: Axioms of BAT
No.
Axioms
A1
x+y=y+x
A2
(x+y)+z=x+(y+z)
A3
x+x=x
A4
(x+y)∘z=x∘z+y∘z
A5
(x∘y)∘z=x∘(y∘z)
A6
x+0=x
A7
0∘x=0
A8
I∘x=x
A9
x∘I=x
G1
ϕ∘¬ϕ=0
G2
ϕ+¬ϕ=I
G3
ϕ∘0=0
G4
ϕ∘(x+y)=ϕ∘x+ϕ∘y
to be continued...
continuing: Axioms of BAT
No.
Axioms
G5
ϕ∘(x∘y)=(ϕ∘x)∘y
G6
(ϕ+ψ)∘x=ϕ∘x+ψ∘x
G7
(ϕ∘ψ)∘x=ϕ∘(ψ∘x)
G8
ϕ=I if ∀s∈S.test(ϕ,s)
G9
ϕ0∘⋯∘ϕn=0 if ∀s∈S,∃i≤n.test(¬ϕi,s)
G10
wp(U,ϕ)Uϕ=wp(U,ϕ)U
G11
¬wp(U,ϕ)U¬ϕ=¬wp(U,ϕ)U
end of Axioms of BAT
Definition 3.1 (Basic terms of BAT). The set of basic terms of BAT, B(BAT), is inductively defined as follows:
Act∪{0}∪{I}⊂B(BAT).
Grd⊂B(BAT).
If U∈Pom,t∈B(BAT) then U∘t∈B(BAT).
If ϕ∈Grd,t∈B(BAT) then ϕ∘t∈B(BAT).
If t,s∈B(BAT) then t+s∈B(BAT).
Theorem 3.2 (Elimination theorem of BAT). Let p be a closed BAT term. Then there is a basic BAT term q such that BAT⊢p=q.
Proof. (1) Firstly, suppose that the following ordering on the signature of BAT is defined: ∘>+ and the symbol ∘ is given the lexicographical status for the first argument, then for each rewrite rule p→q in Table 3 relation p>lpoq can easily be proved. We obtain that the term rewrite system shown in Table 3 is strongly normalizing, for it has finitely many rewriting rules, and > is a well-founded ordering on the signature of BAT, and if s>lpot, for each rewriting rule s→t is in Table 3 (see Theorem 2.28).
Table 3: Rewriting rules of BAT
No.
Rewriting rules
RA3
x+x→x
RA4
(x+y)∘z→x∘z+y∘z
RA5
(x∘y)∘z→x∘(y∘z)
RA6
x+0→x
RA7
0∘x→0
RA8
I∘x→x
RA9
x∘I→x
RG1
ϕ∘¬ϕ→0
to be continued...
continuing: Rewriting rules of BAT
No.
Rewriting rules
RG2
ϕ+¬ϕ→I
RG3
ϕ∘0→0
RG4
ϕ∘(x+y)→ϕ∘x+ϕ∘y
RG5
ϕ∘(x∘y)→(ϕ∘x)∘y
RG6
(ϕ+ψ)∘x→ϕ∘x+ψ∘x
RG7
(ϕ∘ψ)∘x→ϕ∘(ψ∘x)
RG8
ϕ→I if ∀s∈S.test(ϕ,s)
RG9
ϕ0∘⋯∘ϕn→0 if ∀s∈S,∃i≤n.test(¬ϕi,s)
RG10
wp(U,ϕ)Uϕ→wp(U,ϕ)U
RG11
¬wp(U,ϕ)U¬ϕ→¬wp(U,ϕ)U
end of Axioms of BAT
(2) Then we prove that the normal forms of closed BAT terms are basic BAT terms.
Suppose that p is a normal form of some closed BAT term and suppose that p is not a basic term. Let p′ denote the smallest sub-term of p which is not a basic term. It implies that each sub-term of p′ is a basic term. Then we prove that p is not a term in normal form. It is sufficient to induct on the structure of p′:
Case p′≡U,U∈Pom. p′ is a basic term, which contradicts the assumption that p′ is not a basic term, so this case should not occur.
Case p′≡ϕ,ϕ∈Grd. p′ is a basic term, which contradicts the assumption that p′ is not a basic term, so this case should not occur.
Case p′≡p1∘p2. By induction on the structure of the basic term p1:
– Subcase p1∈Pom. p′ would be a basic term, which contradicts the assumption that p′ is not a basic term;
– Subcase p1∈Grd. p′ would be a basic term, which contradicts the assumption that p′ is not a basic term;
– Subcase p1≡U∘p1′. RA5 or RA9 rewriting rule can be applied. So p is not a normal form;
– Subcase p1≡ϕ∘p1′. RG1, RG3, RG4, RG5, RG7, or RG8 – 9 rewriting rules can be applied. So p is not a normal form;
– Subcase p1≡p1′+p1′′. RA4, RA6, RG2, or RG6 rewriting rules can be applied. So p is not a normal form.
Case p′≡p1+p2. By induction on the structure of the basic terms both p1 and p2, all subcases will lead to that p′ would be a basic term, which contradicts the assumption that p′ is not a basic term.
We give the operational transition rules for I, atomic action α∈Act, pomset U∈Pom, guard ϕ∈Grd and operators ∘ and + as Table 4 shows. And the predicate U represents successful termination after execution of U.
Theorem 3.3 (Congruence of BAT with respect to pomset bisimulation equivalence). Pomset bisimulation equivalence is a congruence with respect to BAT.
Proof. Since the PTSS of BAT in Table 4 is positive after reduction and in panth format, pomset bisimulation equivalence is a congruence with respect to BAT.
3.3 Soundness and Completeness
Theorem 3.4 (Soundness of BAT modulo pomset bisimulation equivalence). The axiomatization of BAT is sound modulo pomset bisimulation equivalence, i.e., let x and y be BAT terms. If BAT⊢x=y, then x↔y.
Proof. Since pomset bisimulation ⇔ is both an equivalent and a congruent relation, we only need to check if each axiom in Table 2 is sound modulo pomset bisimulation equivalence ⇔. The proof is trivial and we omit it.
Theorem 3.5 (Completeness of BAT modulo pomset bisimulation equivalence). The axiomatization of BAT is complete modulo pomset bisimulation equivalence, i.e., let p and q be closed BAT terms, if p↔q then p=q.
Proof. Firstly, by the elimination theorem of BAT, we know that for each closed BAT term p, there exists a closed basic BAT term p′, such that BAT⊢p=p′, so, we only need to consider closed basic BAT terms.
The basic terms (see Definition 3.1) modulo associativity and commutativity (AC) of conflict + (defined by axioms A1 and A2 in Table 2), and this equivalence is denoted by =_{AC}. Then, each equivalence class s modulo AC of + has the following normal form
s1+⋯+sk
with each si either an atomic event or of the form t1∘t2, and each si is called the summand of s.
Now, we prove that for normal forms n and n′, if n↔n′ then n=ACn′. It is sufficient to induct on the sizes of n and n′.
Consider a summand U of n. Then ⟨n,s⟩U⟨,s′⟩, so n∼pn′ implies ⟨n′,s⟩U⟨,s⟩, meaning that n′ also contains the summand U.
Consider a summand ϕ of n. Then ⟨n,s⟩→⟨,s⟩, if test(ϕ,s) holds, so n∼pn′ implies ⟨n′,s⟩→⟨,s⟩, if test(ϕ,s) holds, meaning that n′ also contains the summand ϕ.
Consider a summand t1∘t2 of n. Then ⟨n,s⟩t1⟨t2,s′⟩, so n∼pn′ implies ⟨n′,s⟩t1⟨t2′,s′⟩ with t2∼pt2′, meaning that n′ contains a summand t1∘t2′. Since t2 and t2′ are normal forms and have sizes smaller than n and n′, by the induction hypotheses t2↔t2′ implies t2=ACt2′.
So, we get n=ACn′.
Finally, let s and t be basic terms, and s↔t, there are normal forms n and n′, such that s=n and t=n′. The soundness theorem of BAT modulo pomset bisimulation equivalence (see Theorem 3.4) yields s↔n and t↔n′, so n↔s↔t↔n′. Since if n↔n′ then n=ACn′, s=n=ACn′=t, as desired.
In this section, we will discuss parallel composition. The resulted algebra is called Algebra of Parallelism for Transformers, abbreviated APT.
4.1 Operational Semantics
Firstly, we give the transition rules for parallelism as table 5 shows.
Theorem 4.1 (Congruence theorem of APT). Pomset bisimulation equivalences ↔ is a congruence with respect to APT.
Proof. Since the PTSS of APT in Table 5 is positive after reduction and in panth format, pomset bisimulation equivalence ↔ is a congruence with respect to APT. □
Definition 4.2 (Basic terms of APT). The set of basic terms of APT, B(APT), is inductively defined as follows:
Act∪{0}∪{I}⊂B(APT).
Grd⊂B(APT).
If U∈Pom,t∈B(APT) then U∘t∈B(APT).
If ϕ∈Grd,t∈B(APT) then ϕ∘t∈B(APT).
If t,s∈B(APT) then t+s∈B(APT).
If t,s∈B(APT) then t⊕s∈B(APT).
Theorem 4.3 (Elimination theorem of parallelism). Let p be a closed APT term. Then there is a basic APT term q such that APT⊢p=q.
Proof. (1) Firstly, suppose that the following ordering on the signature of APT is defined: ⊕>∘>+ and the symbol ∘ is given the lexicographical status for the first argument, then for each rewrite rule p→q in Table 7 relation p>lpoq can easily be proved. We obtain that the term rewrite system shown in Table 7 is strongly normalizing, for it has finitely many rewriting rules, and > is a well-founded ordering on the signature of APT, and if s>lpot, for each rewriting rule s→t is in Table 7 (see Theorem 2.28).
Table 7: Rewriting rules of APT
No.
Rewriting rules
RP1
α⊕(α′∘y)→(α⊕α′)∘y
RP2
(α∘x)⊕α′→(α⊕α′)∘x
RP3
(α∘x)⊕(α′∘y)→(α⊕α′)∘(x⊕y)
RP4
(x+y)⊕z→(x⊕z)+(y⊕z)
RP5
x⊕(y+z)→(x⊕y)+(x⊕z)
RP6
0⊕x→0
RP7
x⊕0→0
RP8
I⊕x→x
to be continued...
continuing: Rewriting rules of APT
No.
Rewriting rules
RP9
x⊕I→x
RG12
ϕ∘(x⊕y)→ϕ∘x⊕ϕ∘y
RG13
ϕ⊕0→0
RG14
0⊕ϕ→0
RG15
ϕ⊕I→ϕ
RG16
I⊕ϕ→ϕ
RG17
ϕ⊕¬ϕ→0
RG18
ϕ0⊕⋯⊕ϕn→0 if ∀s0,…,sn∈S,∃i≤n.test(¬ϕi,s0∪⋯∪sn)
end of Rewriting rules of APT
(2) Then we prove that the normal forms of closed APT terms are basic APT terms.
Suppose that p is a normal form of some closed APT term and suppose that p is not a basic APT term. Let p′ denote the smallest sub-term of p which is not a basic APT term. It implies that each sub-term of p′ is a basic APT term. Then we prove that p is not a term in normal form. It is sufficient to induct on the structure of p′:
Case p′≡U,U∈Pom. p′ is a basic APT term, which contradicts the assumption that p′ is not a basic APT term, so this case should not occur.
Case p′≡ϕ,ϕ∈Grd. p′ is a basic term, which contradicts the assumption that p′ is not a basic term, so this case should not occur.
Case p′≡p1∘p2. By induction on the structure of the basic APT term p1:
– Subcase p1∈Pom. p′ would be a basic APT term, which contradicts the assumption that p′ is not a basic APT term;
– Subcase p1∈Grd. p′ would be a basic term, which contradicts the assumption that p′ is not a basic term;
– Subcase p1≡U∘p1′. RA5 or RA9 rewriting rules in Table 3 can be applied. So p is not a normal form;
– Subcase p1≡ϕ⋅p1′. RG1, RG3, RG4, RG5, RG7, or RG8 – 9 rewriting rules can be applied. So p is not a normal form;
– Subcase p1≡p1′+p1′′. RA4, RA6, RG2, or RG6 rewriting rules in Table 3 can be applied. So p is not a normal form;
– Subcase p1≡p1′⊕p1′′. RP1-RP9 rewrite rules in Table 7 can be applied. So p is not a normal form.
Case p′≡p1+p2. By induction on the structure of the basic APT terms both p1 and p2, all subcases will lead to that p′ would be a basic APT term, which contradicts the assumption that p′ is not a basic APT term.
Case p′≡p1⊕p2. By induction on the structure of the basic APT terms both p1 and p2, all subcases will lead to that p′ would be a basic APT term, which contradicts the assumption that p′ is not a basic APT term.
4.3 Soundness and Completeness
Theorem 4.4 (Generalization of APT with respect to BAT). APT is a generalization of BAT.
Proof. It follows from the following three facts.
The transition rules of BAT Table 4 are all source-dependent;
The sources of the transition rules for APT in Table 5 contain an occurrence of ⊕;
The transition rules of APT are all source-dependent.
So, APT is a generalization of BAT, i.e., BAT is an embedding of APT, as desired.
Theorem 4.5 (Soundness of APT modulo pomset bisimulation equivalence). The axiomatization of APT is sound modulo pomset bisimulation equivalence, i.e., let x and y be APT terms. If APT⊢x=y, then x↔y.
Proof. Since pomset bisimulations ⇔ is both an equivalent and a congruent relation, we only need to check if each axiom in Table 6 is sound modulo pomset bisimulation equivalence ⇔. The proof is trivial and we omit it.
Theorem 4.6 (Completeness of APT modulo pomset bisimulation equivalence). The axiomatization of APT is complete modulo pomset bisimulation equivalence, i.e., let p and q be closed APT terms, if p↔q then p=q.
Proof. Firstly, by the elimination theorem of APT (see Theorem 4.3), we know that for each closed APT term p, there exists a closed basic APT term p′, such that APT⊢p=p′, so, we only need to consider closed basic APT terms.
The basic terms (see Definition 4.2) modulo associativity and commutativity (AC) of conflict + (defined by axioms A1 and A2 in Table 2), and these equivalences is denoted by =AC. Then, each equivalence class s modulo AC of + has the following normal form
s1+⋯+sk
with each si either an atomic event or of the form
t1∘⋯∘tm
with each tj either an atomic event or of the form
u1⊕⋯⊕uℓ
with each uℓ an atomic event, and each si is called the summand of s.
Now, we prove that for normal forms n and n′, if n↔n′ then n=ACn′. It is sufficient to induct on the sizes of n and n′.
Consider a summand U of n. Then ⟨n,s⟩U⟨,s′⟩, so n↔n′ implies ⟨n′,s⟩U⟨,s⟩, meaning that n′ also contains the summand U.
Consider a summand ϕ of n. Then ⟨n,s⟩→⟨,s⟩, if test(ϕ,s) holds, so n↔n′ implies ⟨n′,s⟩→⟨,s⟩, if test(ϕ,s) holds, meaning that n′ also contains the summand ϕ.
• Consider a summand t1⋅t2 of n,
if t1≡α′, then ⟨n,s⟩α′⟨t2,s′⟩, so n↔n′ implies ⟨n′,s⟩α′⟨t2′,s′⟩ with t2↔t2′, meaning that n′ contains a summand α′⋅t2′. Since t2 and t2′ are normal forms and have sizes smaller than n and n′, by the induction hypotheses if t2↔t2′ then t2=ACt2′;
if t1≡ϕ′, then ⟨n,s⟩→⟨t2,s⟩, if test(ϕ′,s) holds, so n↔n′ implies ⟨n′,s⟩→⟨t2′,s⟩ with t2↔t2′, if test(ϕ′,s) holds, meaning that n′ contains a summand ϕ′⋅t2′. Since t2 and t2′ are normal forms and have sizes smaller than n and n′, by the induction hypotheses if t2↔t2′ then t2=ACt2′;
if t1≡α1⊕⋯⊕αell, then ⟨n,s⟩{α1,⋯,αell}⟨t2,s′⟩, so n↔n′ implies ⟨n′,s⟩{α1,⋯,αell}⟨t2′,s′⟩ with t2↔t2′, meaning that n′ contains a summand (α1⊕⋯⊕αell)⋅t2′. Since t2 and t2′ are normal forms and have sizes smaller than n and n′, by the induction hypotheses if t2↔t2′ then t2=ACt2′;
if t1≡ϕ1⊕⋯⊕ϕell, then ⟨n,s⟩→⟨t2,s⟩, if test(ϕ1,s),⋯,test(ϕell,s) hold, so n↔n′ implies ⟨n′,s⟩→⟨t2′,s⟩ with t2↔t2′, if test(ϕ1,s),⋯,test(ϕell,s) hold, meaning that n′ contains a summand (ϕ1⊕⋯⊕ϕell)⋅t2′. Since t2 and t2′ are normal forms and have sizes smaller than n and n′, by the induction hypotheses if t2↔t2′ then t2=ACt2′.
So, we get n=ACn′.
Finally, let s and t be basic APT terms, and s↔t, there are normal forms n and n′, such that s=n and t=n′. The soundness theorem of parallelism modulo pomset bisimulation equivalence (see Theorem 4.5) yields s↔n and t↔n′, so n↔s↔t↔n′. Since if n↔n′ then n=ACn′, s=n=ACn′=t, as desired.
5 Recursion
In this section, we introduce recursion to capture infinite computations based on APT.
In the following, E, F, G are recursion specifications, X, Y, Z are recursive variables.
Definition 5.1 (Recursive specification). A recursive specification is a finite set of recursive equations
X1=t1(X1,⋯,Xn)Xn=tn(X1,⋯,Xn)
where the left-hand sides of Xi are called recursion variables, and the right-hand sides ti(X1,⋯,Xn) are process terms in APT with possible occurrences of the recursion variables X1,⋯,Xn.
Definition 5.2 (Solution). Processes p1,⋯,pn are solutions for a recursive specification {Xi=ti(X1,⋯,Xn)∣i∈{1,⋯,n}} (with respect to pomset bisimulation equivalence ⇔) if pi⇔ti(p1,⋯,pn) for i∈{1,⋯,n}.
Definition 5.3 (Guarded recursive specification). A recursive specification
X1=t1(X1,⋯,Xn)Xn=tn(X1,⋯,Xn)
is guarded if the right-hand sides of its recursive equations can be adapted to the form by applications of the axioms in APT and replacing recursion variables by the right-hand sides of their recursive equations, and there does not exist an infinite sequence of I-transitions ⟨X∣E⟩→⟨X′∣E⟩→⟨X′′∣E⟩→⋯,
U1∘s1(X1,⋯,Xn)+⋯+Uk∘sk(X1,⋯,Xn)+V1+⋯+Vℓ
where U1,⋯,Uk,V1,⋯,Vℓ∈Pom, and the sum above is allowed to be empty, in which case it represents the deadlock 0.
Definition 5.4 (Linear recursive specification). A recursive specification is linear if its recursive equations are of the form
U1∘X1+⋯+Uk∘Xk+V1+⋯+Vℓ
where U1,⋯,Uk,V1,⋯,Vℓ∈Pom, and the sum above is allowed to be empty, in which case it represents the deadlock 0.
For a guarded recursive specifications E with the form
X1=t1(X1,⋯,Xn)Xn=tn(X1,⋯,Xn)
the behavior of the solution ⟨Xi∣E⟩ for the recursion variable Xi in E, where i∈{1,⋯,n}, is exactly the behavior of their right-hand sides ti(X1,⋯,Xn), which is captured by the two transition rules in Table 8.
5.1 Operational Semantics
Theorem 5.5 (Conservativity of APT with guarded recursion). APT with guarded recursion is a conservative extension of APT.
Proof. Since the transition rules of APT are source-dependent, and the transition rules for guarded recursion in Table 8 contain only a fresh constant in their source, so the transition rules of APT with guarded recursion are conservative extensions of those of APT.
Theorem 5.6 (Congruence theorem of APT with guarded recursion). Pomset bisimulation equivalence ⇔ is a congruences with respect to APT with guarded recursion.
Proof. Since the PTSS of APT with guarded recursion in Table 8 is positive after reduction and in panth format, pomset bisimulation equivalence is a congruence with respect to APT with guarded recursion.
5.2 Axiomatic System
The RDP (Recursive Definition Principle) and the RSP (Recursive Specification Principle) are shown in Table 9.
Table 9: Recursive definition and specification principle
No.
Axioms
RDP
⟨Xi∣E⟩=ti(⟨X1∣E⟩,…,⟨Xn∣E⟩)(i∈{1,…,n})
RSP
if yi=ti(y1,…,yn) for i∈{1,…,n}, then yi=⟨Xi∣E⟩(i∈{1,…,n})
end of Recursive definition and specification principle
RDP follows immediately from the two transition rules for guarded recursion, which express that ⟨Xi∣E⟩ and ti(⟨X1∣E⟩,…,⟨Xn∣E⟩) have the same initial transitions for i∈{1,…,n}. RSP follows from the fact that guarded recursive specifications have only one solution.
5.3 Soundness and Completeness
Theorem 5.7 (Soundness of APT with guarded recursion). Let x and y be APT with guarded recursion terms. If APT with guarded recursion ⊢x=y, then x↔y.
Proof. Since pomset bisimulation equivalence is both an equivalent and a congruent relation with respect to APT with guarded recursion, we only need to check if each axiom in Table 9 is sound modulo pomset bisimulation equivalence. The proof is trivial and we omit it. □
Theorem 5.8 (Completeness of APT with linear recursion). Let p and q be closed APT with linear recursion terms, then, if p↔q then p=q.
Proof. Firstly, we know that each process term in APT with linear recursion is equal to a process term ⟨X1∣E⟩ with E a linear recursive specification.
Let E1 consist of recursive equations X=tX for X∈X and E2 consists of recursion equations Y=tY for Y∈Y. Let the linear recursive specification E consist of recursion equations ZXY=tXY, and ⟨X∣E1⟩∼s⟨Y∣E2⟩, and tXY consists of the following summands:
tXY contains a summand (α1⊕⋯⊕αm)ZX′Y′ iff tX contains the summand (α1⊕⋯⊕αm)X′ and tY contains the summand (α1⊕⋯⊕αm)Y′ such that ⟨X′∣E1⟩∼s⟨Y′∣E2⟩;
tXY contains a summand β1⊕⋯⊕βn iff tX contains the summand β1⊕⋯⊕βn and tY contains the summand β1⊕⋯⊕βn.
Let σ map recursion variable X in E1 to ⟨X∣E1⟩, and let ψ map recursion variable ZXY in E to ⟨X∣E1⟩. So, σ((α1⊕⋯⊕αm)X′)≡(α1⊕⋯⊕αm)⟨X′∣E1⟩≡ψ((α1⊕⋯⊕αm)ZX′Y′), so by RDP, we get ⟨X∣E1⟩=σ(tX)=ψ(tXY). Then by RSP, ⟨X∣E1⟩=⟨ZXY∣E⟩, particularly, ⟨X1∣E1⟩=⟨ZX1Y1∣E⟩. Similarly, we can obtain ⟨Y1∣E2⟩=⟨ZX1Y1∣E⟩. Finally, ⟨X1∣E1⟩=⟨ZX1Y1∣E⟩=⟨Y1∣E2⟩, as desired.
⟨τϕ,s⟩→⟨s⟩iftest(τϕ,s)⟨τ,s⟩→τ⟨τ(s)⟩
Table 10: Transition rule of the silent step
6 Abstraction
To abstract away from the internal implementations of a transformer, and verify that the transformer exhibits the desired external behaviors, the silent step τ and abstraction operator τI are introduced, where I⊆Act∪Grd denotes the internal events or guards.
6.1 Silent Step
The silent step τ represents the internal actions, and τϕ for internal guards, when we consider the external behaviors of a process, τ steps can be removed, i.e., τ steps must keep silent. The transition rule of τ is shown in Table 10. In the following, let the atomic action a range over Act∪{0}∪{I}∪{τ}, and ϕ range over Grd∪{τ}. We use τ(s) to denote effect(τ,s), for the fact that τ only change the state of internal data environment, that is, for the external data environments, s=τ(s).
6.1.1 Operational Semantics
Definition 6.1 (Weak pomset transitions). Let p,q∈Proc and U∈Pom, p⟹Uq is called a weak pomset transition from p to q, where we define ⟹a⟶τ∗⟶a⟶τ∗. And ⟹U⟶τ∗⟶U⟶τ∗, for every a∈U.
Definition 6.2 (Branching pomset bisimulation). Assume a special termination predicate ↓, and let √ represent a state with √ ↓. Let S be a set of states, p,q∈Proc, U∈Pom and s,s′∈S. A branching pomset bisimulation is a relation R⊆⟨Proc,S⟩×⟨Proc,S⟩, such that:
if ⟨p,s⟩,⟨q,s⟩∈R, and ⟨p,s⟩U⟨p′,s′⟩ then
• either U≡τ∗, and ⟨p′,s′⟩,⟨q,s⟩∈R with s′∈τ(s);
or there is a sequence of (zero or more) τ-transitions ⟨q,s⟩τ∗⟨q0,s0⟩, such that ⟨p,s⟩,⟨q0,s0⟩∈R and ⟨q0,s0⟩U⟨q′,s′⟩ with ⟨p′,s′⟩,⟨q′,s′⟩∈R;
if ⟨p,s⟩,⟨q,s⟩∈R, and ⟨q,s⟩U⟨q′,s′⟩ then
• either U≡τ∗, and ⟨p,s⟩,⟨q′,s′⟩∈R;
or there is a sequence of (zero or more) τ-transitions ⟨p,s⟩τ∗⟨p0,s0⟩, such that ⟨p0,s0⟩,⟨q,s⟩∈R and ⟨p0,s0⟩U⟨p′,s′⟩ with ⟨p′,s′⟩,⟨q′,s′⟩∈R;
if ⟨p,s⟩,⟨q,s⟩∈R and ⟨p,s⟩↓, then there is a sequence of (zero or more) τ-transitions ⟨q,s⟩τ∗⟨q0,s0⟩ such that ⟨p,s⟩,⟨q0,s0⟩∈R and ⟨q0,s0⟩↓;
if ⟨p,s⟩,⟨q,s⟩∈R and ⟨q,s⟩↓, then there is a sequence of (zero or more) τ-transitions ⟨p,s⟩τ∗⟨p0,s0⟩ such that ⟨p0,s0⟩,⟨q,s⟩∈R and ⟨p0,s0⟩↓.
We say that p,q are branching pomset bisimilar, written p↔bq, if there exists a branching pomset bisimulation R, such that (⟨p,s⟩,⟨q,s⟩)∈R.
Definition 6.3 (Rooted branching pomset, step bisimulation). Assume a special termination predicate ↓, and let ✓ represent a state with ✓ ↓. Let S be a set of states, p,q∈Proc, U∈Pom and s,s′∈S. A rooted branching pomset bisimulation is a relation R⊆⟨Proc,S⟩×⟨Proc,S⟩, such that:
if ⟨p,s⟩,⟨q,s⟩∈R, and ⟨p,s⟩U⟨p′,s′⟩ then ⟨q,s⟩U⟨q′,s′⟩ with ⟨p′,s′⟩b⟨q′,s′⟩;
if ⟨p,s⟩,⟨q,s⟩∈R, and ⟨q,s⟩U⟨q′,s′⟩ then ⟨p,s⟩U⟨p′,s′⟩ with ⟨p′,s′⟩b⟨q′,s′⟩;
if ⟨p,s⟩,⟨q,s⟩∈R and ⟨p,s⟩↓, then ⟨q,s⟩↓;
if ⟨p,s⟩,⟨q,s⟩∈R and ⟨q,s⟩↓, then ⟨p,s⟩↓.
We say that p,q are rooted branching pomset bisimilar, written p↔rbq, if there exists a rooted branching pomset bisimulation R, such that (⟨p,s⟩,⟨q,s⟩)∈R.
The silent step τ as an atomic event, is introduced into E. Considering the recursive specification X=τX, τs, ττs, and τ⋯s are all its solutions, that is, the solutions make the existence of τ-loops which cause unfairness. To prevent τ-loops, we extend the definition of linear recursive specification (Definition 5.4) to the guarded one.
Definition 6.4 (Guarded linear recursive specification). A recursive specification is linear if its recursive equations are of the form
U1∘X1+⋯+Uk∘Xk+V1+⋯+Vℓ
where U1,⋯,Uk,V1,⋯,Vℓ∈Pom, and the sum above is allowed to be empty, in which case it represents the deadlock 0.
A linear recursive specification E is guarded if there does not exist an infinite sequence of I-transitions ⟨X∣E⟩→⟨X′∣E⟩→⟨X′′∣E⟩→⋯ and τ-transitions ⟨X∣E⟩τ⟨X′∣E⟩τ⟨X′′∣E⟩τ⋯.
Theorem 6.5 (Conservativity of APT with silent step and guarded linear recursion). APT with silent step and guarded linear recursion is a conservative extension of APT with linear recursion.
Proof. Since the transition rules of APT with linear recursion are source-dependent, and the transition rules for silent step in Table 10 contain only a fresh constant τ in their source, so the transition rules of APT with silent step and guarded linear recursion is a conservative extension of those of APT with linear recursion.
Theorem 6.6 (Congruence theorem of APT with silent step and guarded linear recursion). Rooted branching pomset bisimulation equivalence ↔rb is a congruence with respect to APT with silent step and guarded linear recursion.
Proof. Since the PTSS of APT with silent step and guarded linear recursion in Table 10 is positive after reduction and in RBB cool format, rooted branching pomset bisimulation equivalence ↔rb is a congruence with respect to APT with silent step and guarded linear recursion. □
6.1.2 Axiomatic System
We design the axioms for the silent step τ in Table 11.
Table 11: Axioms of silent step
No.
Axioms
B1
U∘τ=U
B2
U∘(τ∘(x+y)+x)=U∘(x+y)
B3
x⊕τ=x
B4
τ⊕x=x
G26
τϕ⋅x=x
G19
x⋅τϕ=x
G20
x∥τϕ=x
G21
τϕ∥x=x
end of Axioms of silent step
6.1.3 Soundness and Completeness
Theorem 6.7 (Soundness of APT with silent step and guarded linear recursion). Let x and y be APT with silent step and guarded linear recursion terms. If APT with silent step and guarded linear recursion ⊢x=y, then x↔rby.
Proof. Since rooted branching pomset bisimulation ↔rb is both an equivalent and a congruent relation with respect to APT with silent step and guarded linear recursion, we only need to check if each axiom in Table 11 is sound modulo rooted branching pomset bisimulation equivalence. The proof is trivial and we omit it.
Theorem 6.8 (Completeness of APT with silent step and guarded linear recursion). Let p and q be closed APT with silent step and guarded linear recursion terms, then, if p↔rbq then p=q.
Proof. Firstly, we know that each process term in APT with silent step and guarded linear recursion is equal to a process term ⟨X1∣E⟩ with E a guarded linear recursive specification.
The recursive equation W=τ+⋯+τ with W=X1 in E1 and E2, can be removed, and the corresponding summands aW are replaced by α, to get E1′ and E2′, by use of the axioms RDP, A3 and B1, and ⟨X∣E1⟩=⟨X∣E1′⟩, ⟨Y∣E2⟩=⟨Y∣E2′⟩.
Let E1 consists of recursive equations X=tX for X∈X and E2 consists of recursion equations Y=tY for Y∈Y, and are not the form τ+⋯+τ. Let the guarded linear recursive specification E consists of recursion equations ZXY=tXY, and ⟨X∣E1⟩≈rbs⟨Y∣E2⟩, and tXY consists of the following summands:
tXY contains a summand (α1⊕⋯⊕αm)ZX′Y′ iff tX contains the summand (α1⊕⋯⊕αm)X′ and tY contains the summand (α1⊕⋯⊕αm)Y′ such that ⟨X′∣E1⟩≈rbs⟨Y′∣E2⟩;
tXY contains a summand β1⊕⋯⊕βn iff tX contains the summand β1⊕⋯⊕βn and tY contains the summand β1⊕⋯⊕βn;
tXY contains a summand τZX′Y iff XY=X1Y1, tX contains the summand τX′, and ⟨X′∣E1⟩≈rbs⟨Y∣E2⟩;
tXY contains a summand τZXY′ iff XY=X1Y1, tY contains the summand τY′, and ⟨X∣E1⟩≈rbs⟨Y′∣E2⟩.
Since E1 and E2 are guarded, E is guarded. Constructing the process term uXY consist of the following summands:
uXY contains a summand (α1⊕⋯⊕αm)⟨X′∣E1⟩ iff tX contains the summand (α1⊕⋯⊕αm)X′ and tY contains the summand (α1⊕⋯⊕αm)Y′ such that ⟨X′∣E1⟩≈rbs⟨Y′∣E2⟩;
uXY contains a summand β1⊕⋯⊕βn iff tX contains the summand β1⊕⋯⊕βn and tY contains the summand β1⊕⋯⊕βn;
uXY contains a summand τ⟨X′∣E1⟩ iff XY=X1Y1, tX contains the summand τX′, and ⟨X′∣E1⟩≈rbs⟨Y∣E2⟩.
Let the process term sXY be defined as follows:
sXY≜τ⟨X∣E1⟩+uXY iff XY=X1Y1, tY contains the summand τY′, and ⟨X∣E1⟩≈rbs⟨Y′∣E2⟩;
sXY≜⟨X∣E1⟩, otherwise.
So, ⟨X∣E1⟩=⟨X∣E1⟩+uXY, and (α1⊕⋯⊕αm)(τ⟨X∣E1⟩+uXY)=(α1⊕⋯⊕αm)((τ⟨X∣E1⟩+uXY)+uXY)=(α1⊕⋯⊕αm)((⟨X∣E1⟩+uXY)=(α1⊕⋯⊕αm)⟨X∣E1⟩, hence, (α1⊕⋯⊕αm)sXY=(α1⊕⋯⊕αm)⟨X∣E1⟩.
Let σ map recursion variable X in E1 to ⟨X∣E1⟩, and let ψ map recursion variable ZXY in E to sXY. It is sufficient to prove sXY=ψ(tXY) for recursion variables ZXY in E. Either XY≡X1Y1 or XY≡X1Y1, we all can get sXY=ψ(tXY). So, sXY=⟨ZXY∣E⟩ for recursive variables ZXY in E is a solution for E. Then by RSP, particularly, ⟨X1∣E1⟩=⟨ZX1Y1∣E⟩. Similarly, we can obtain ⟨Y1∣E2⟩=⟨ZX1Y1∣E⟩. Finally, ⟨X1∣E1⟩=⟨ZX1Y1∣E⟩=⟨Y1∣E2⟩, as desired.
6.2 Abstraction
The unary abstraction operator τI ( I⊆Act) renames all atomic events in I into τ. APT with silent step and abstraction operator is called APTτ.
Table 12: Transition rule of the abstraction operator
6.2.1 Operational Semantics
The transition rules of operator τI are shown in Table 12.
Theorem 6.9 (Conservativity of APTτ with guarded linear recursion). APTτ with guarded linear recursion is a conservative extension of APT with silent step and guarded linear recursion.
Proof. Since the transition rules of APT with silent step and guarded linear recursion are source-dependent, and the transition rules for abstraction operator in Table 12 contain only a fresh operator τI in their source, so the transition rules of APTτ with guarded linear recursion is a conservative extension of those of APT with silent step and guarded linear recursion.
Theorem 6.10 (Congruence theorem of APTτ with guarded linear recursion). Rooted branching pomset bisimulation equivalence ↔rb is a congruence with respect to APTτ with guarded linear recursion.
Proof. Since the PTSS of APTτ with guarded linear recursion in Table 12 is positive after reduction and in RBB cool format, rooted branching pomset bisimulation equivalence ↔rb is a congruence with respect to APTτ with guarded linear recursion.
6.2.2 Axiomatic System
We design the axioms for the abstraction operator τI in Table 13.
Table 13: Axioms of abstraction
No.
Axioms
TI1
α∈/IτI(α)=α
TI2
α∈IτI(α)=τ
TI3
τI(0)=0
TI4
τI(I)=I
TI5
τI(x+y)=τI(x)+τI(y)
TI6
τI(x∘y)=τI(x)∘τI(y)
TI7
τI(x⊕y)=τI(x)⊕τI(y)
G22
ϕ∈/IτI(ϕ)=ϕ
to be continued...
continuing: Axioms of abstraction
No.
Axioms
G23
ϕ∈IτI(ϕ)=τϕ
end of Axioms of abstraction
6.2.3 Soundness and Completeness
Theorem 6.11 (Soundness of APTτ with guarded linear recursion). Let x and y be APTτ with guarded linear recursion terms. If APTτ with guarded linear recursion ⊢x=y, then x↔rby.
Proof. Since rooted branching pomset bisimulation ↔rb is both an equivalent and a congruent relation with respect to APTτ with guarded linear recursion, we only need to check if each axiom in Table 13 is sound modulo rooted branching pomset bisimulation equivalence. The proof is trivial and we omit it.
Though τ-loops are prohibited in guarded linear recursive specifications (see Definition 6.4) in a specifiable way, they can be constructed using the abstraction operator, for example, there exist τ-loops in the process term τ{α}(⟨X∣X=aX⟩). To avoid τ-loops caused by τI and ensure fairness, the concept of cluster and CFAR (Cluster Fair Abstraction Rule) [7] are still valid, we introduce them below.
Definition 6.12 (Cluster). Let E be a guarded linear recursive specification, and I⊆Act. Two recursion variable X and Y in E are in the same cluster for I iff there exist sequences of transitions ⟨X∣E⟩∥β11,…,β1i∥⋯∥βm1,…,βmi∥⟨Y∣E⟩ and ⟨Y∣E⟩∥γ11,…,γ1j∥⋯∥γn1,…,γnj∥⟨X∣E⟩, where β11,…,βmi,γ11,…,γnj∈I∪{τ}.
α1⊕⋯⊕αk or (α1⊕⋯⊕αk)X is an exit for the cluster C iff: (1) α1⊕⋯⊕αk or (α1⊕⋯⊕αk)X is a summand at the right-hand side of the recursive equation for a recursion variable in C, and (2) in the case of (α1⊕⋯⊕αk)X, either αℓ∈/I∪{τ}(ℓ∈{1,2,⋯,k}) or X∈/C.
Table 14: Cluster fair abstraction rule
No.
Axioms
CFAR
If X is in a cluster for I with exits{(α11⊕⋯⊕α1i)Y1,…,(αm1⊕⋯⊕αmi)Ym,β11⊕⋯⊕β1j,…,βn1⊕⋯⊕βnj}, then τ∘τI(⟨X∣E⟩)=τ∘τI((α11⊕⋯⊕α1i)⟨Y1∣E⟩+⋯+(αm1⊕⋯⊕αmi)⟨Ym∣E⟩+β11⊕⋯⊕β1j+⋯+βn1⊕⋯⊕βnj)end of Cluster fair abstraction rule
Theorem 6.13 (Soundness of CFAR). CFAR is sound modulo rooted branching pomset bisimulation equivalence ↔rb.
Proof. Let X be in a cluster for I with exits {(α11⊕⋯⊕α1i)Y1,⋯,(αm1⊕⋯⊕αmi)Ym,β11⊕⋯⊕β1j,⋯,βn1⊕⋯⊕βnj}. Then ⟨X∣E⟩ can execute a string of atomic events from I∪{τ} inside the cluster of X, followed by an exit (αi′1⊕⋯⊕αi′i)Yi′ for i′∈{1,⋯,m} or βj′1⊕⋯⊕βj′j for j′∈{1,⋯,n}. Hence, τI(⟨X∣E⟩) can execute a string of τ∗ inside the cluster of X, followed by an exit τI((αi′1⊕⋯⊕αi′i)⟨Yi′∣E⟩) for i′∈{1,⋯,m} or τI(βj′1⊕⋯⊕βj′j) for j′∈{1,⋯,n}. And these τ∗ are non-initial in ττI(⟨X∣E⟩), so they are truly silent by the axiom B1, we obtain ττI(⟨X∣E⟩)≈rbsτ∘τI((α11⊕⋯⊕α1i)⟨Y1∣E⟩+⋯+(αm1⊕⋯⊕αmi)⟨Ym∣E⟩+β11⊕⋯⊕β1j+⋯+βn1⊕⋯⊕βnj), as desired.
Theorem 6.14 (Completeness of APTτ with guarded linear recursion and CFAR). Let p and q be closed APTτ with guarded linear recursion and CFAR terms, then, if p↔rbq then p=q.
Proof. Firstly, in the proof the Theorem 6.8, we know that each process term p in APT with silent step and guarded linear recursion is equal to a process term ⟨X1∣E⟩ with E a guarded linear recursive specification. And we prove if ⟨X1∣E1⟩≈rbs⟨Y1∣E2⟩, then ⟨X1∣E1⟩=⟨Y1∣E2⟩
The only new case is p≡τI(q). Let q=⟨X∣E⟩ with E a guarded linear recursive specification, so p=τI(⟨X∣E⟩). Then the collection of recursive variables in E can be divided into its clusters C1,⋯,CN for I. Let
This chapter applies APT to three Transformer constructions from The Transformer Cookbook [5]: Most-Recent Induction, Dyck-1 recognition, and Dyck-1-2 recognition. Each application first describes the construction and establishes its functional specification, then represents its components using the existing atomic constructions, and finally derives its external input-output behavior from recursive state-transition equations by abstraction. Functional correctness is established from the concrete computation before internal actions are hidden.
7.1 Verification of a Transformer for Most-Recent Induction
The subsection apply APT to the Most-Recent Induction construction presented in the Transformer Cookbook[5]. At each position, the construction predicts the symbol following the most recent earlier occurrence of the current symbol. If no earlier occurrence exists, it predicts the current symbol.
We first describe the construction and its functional specification. We then represent initialization, predecessor retrieval, induction retrieval, and unembedding using existing APT atomic constructions. Finally, we connect these components through recursive process equations and derive the expected external input-output behavior by abstraction.
7.1.1 A Transformer Construction of the Most-Recent Induction
Let Σ be a finite nonempty alphabet, and let
x=x1⋯xn∈Σ+,n=∣x∣,
be a nonempty input sequence, where xi denotes the symbol at position i, where 1≤i≤n. Each symbol σ∈Σ is represented by its one-hot encoding eσ.
At position i, attention compares exi with the predecessor embeddings at candidate positions j≤i. A position j matches when
Pred(xj)=exi.
For such a position, xj−1=xi, and the value exj represents the symbol following that earlier occurrence. Rightmost selection chooses the largest matching position index and returns its value:
Here, i is the current query position, and j denotes the largest index satisfying 2≤j≤i and xj−1=xi, whenever such an index exists. The largest candidate index corresponds to the most recent earlier occurrence.
receives the input sequence x=x1⋅xn and stores it. It performs no Transformer computation. Sequential composition transfers control to initialization.
The input and output actions describe interaction with the environment; they are not additional Transformer computational primitives.
Embedding. The initialization component is represented by
(α1⊕α2)∘α5.
Here:
α1 is the word-embedding action. It supplies the one-hot current-symbol embeddings, computes WE(xi)=exi at each position.
α2 is the position-embedding action. It supplies i/n for predecessor retrieval in the first self-attention component and rightmost selection in the second self-attention component.
• α5 is the addition action, which merges the outputs of α1 and α2 coordinatewise.
The two embedding actions execute in parallel, followed by their coordinatewise addition.
First Transformer layer. The first transformer component uses the predecessor construction to retrieve the embedding of the immediately preceding symbol. It is represented by
(α12⊕α16)∘α5.
Here:
α12 is the sequence identity action. It preserves the current-symbol embeddings and positional information.
α16 is the predecessor action. It retrieves Pred(xi) and routes the result to coordinates separate from the preserved embeddings.
• α5 combines the preserved information and predecessor embeddings.
The parallel composition preserves the current information while computing the predecessor embedding. The subsequent addition retains both results for the second Transformer layer.
Second Transformer layer. The second Transformer layer retrieves the symbol following the most recent earlier occurrence of the current symbol. Its self-attention component and residual connection are represented by
(α12⊕α18)∘α5.
Here:
α12 is the sequence identity action. It preserves the information produced by the first Transformer layer.
α18 is the multi-head action, configured with one effective retrieval head. It uses WE(xi) as the query content, Pred(xj) as the key content, and WE(xj) as the value at each candidate position j≤i. Content matching and rightmost selection produce Retrieve(xi). If no match exists, the configuration returns WE(xi).
α5 adds the attention output to the preserved input, retaining the retrieved embedding for unembedding.
The second-layer FFN is configured as zero because the attention component already produces the required prediction embedding. This inactive FFN is omitted from the process representation.
Unembedding. The unembedding action
α19
decodes each retrieved one-hot embedding Retrieve( xi) into its corresponding symbol. Applied at every position, it produces the prediction sequence
Inductrightmost(x).
Output interface. The output action reads and emits the computed prediction sequence. Its occurrence is therefore labelled
W(Inductrightmost(x))
7.1.3 Verification of the Most-Recent Induction Transformer
We now verify that the Most-Recent Induction Transformer exhibits the expected external behavior: it receives an input sequence, computes its Most-Recent Induction predictions, emits the result, and returns to the input-waiting process.
State-transition equations. Using the component representations in Section 7.1.2, define
Abstraction and external behavior. Use the abstraction set I defined earlier in the manuscript.
I⊆Act∪Grd
It contains all configured internal actions occurring in the process equations, while the input and output actions remain visible.
Theorem 7.1 (Correctness of the Most-Recent Induction Transformer). For every received input sequence x, the transformer construction of Most-Recent Induction computes and emits its Most-Recent Induction prediction sequence and returns to input-waiting state. Thus, τI(T) satisfies the external behavior equation:
τI(T)=R(x)∘W(Inductrightmost(x))∘τI(T).
Proof. Section 7.1.1 establishes that the predecessor and retrieval computations return the required prediction embedding at each position, including the no-match case. Unembedding therefore produces the stated output sequence.
Unfolding the state-transition equations and applying TI1, TI2, TI6, and TI7 gives
Applying this identity repeatedly within each input branch removes the seven sequential silent actions. Hence,
τI(T)=R(x)∘W(Inductrightmost(x))∘τI(T).
The resulting equation exhibits the required external behavior: the transformer receives an input sequence, computes its Most-Recent Induction predictions, emits the result, and returns to the input-waiting process.
7.2 Verification of a Transformer for Dyck-1
In this subsection, we apply APT to the verification of the uniform two-layer Transformer for the Dyck-1 language presented in the Transformer Cookbook[5]. The construction considered here is uniform: its parameters are independent of the input length, and the transformer computes the quantities required for recognition rather than an internal binary acceptance bit.
The verification has three complementary parts. First, we describe the numerical construction and establish its recognition criterion. Second, we represent its embedding, attention, and feedforward components using existing atomic constructions. Finally, we connect these components through recursive equations and derive the external input-output behavior by abstraction.
7.2.1 A Transformer Construction for Dyck-1
The Dyck-1 language consists of well-nested strings over the alphabet
Σ={(,)}.
A string w∈Σ∗ belongs to Dyck-1 exactly when it satisfies the following two conditions:
Property 1 (Prefix Condition): In every prefix of the string, the count of open brackets must be greater than or equal to the count of close brackets.
Property 2 (Balance Condition): The total count of open and close brackets in the entire string must be equal.
The construction below is stated for nonempty inputs because it inspects the representation at the final position. The empty string may be accepted separately by convention. Let w=w1⋅wn∈Σ+ be a nonempty input string. Encode its symbols by
oi={1,−1,wi=(,wi=).
For each i∈[n], let Oi and Ci be the numbers of opening and closing parentheses, respectively, in the prefix w1⋯wi. The corresponding prefix balance is
Bi=Oi−Ci=j=1∑ioj.
The embedding initializes
(oi,0,0,0)T.
The first attention component computes the normalized prefix balance:
i1j=1∑ioj=iBi.
The first FFN computes the prefix-error signal
Ei=ReLU(−iBi).
The second attention component computes its prefix average:
ti=i1j=1∑iEj.
The final residual representation at position i is
so zn,2=0 is equivalent to the balance condition. Moreover,
Ei=0⟺Bi≥0.
and all error signals Ei are nonnegative. Therefore,
tn=0⟺Ei=0foreveryi∈[n]⟺Bi≥0foreveryi∈[n].
Thus, zn,4=0 is equivalent to the prefix condition. It follows that
w∈Dyck−1⟺zn,2=0∧zn,4=0.
For later use, define the expected numerical output for w by
oD:=(nBn(w),tn(w)).
Then
w∈Dyck−1⟺oD=(0,0).
The equality test is an external observation. It is not an internal comparison layer or Boolean classifier.
7.2.2 Algebraic Representation
The construction uses causal uniform averaging, residual connections, and a four-dimensional residual workspace. No positional embedding or layer normalization is required.
Repeated occurrences of the same action symbol may therefore denote differently configured instances of the same construction. For example, the two occurrences of α13 below use different source and target workspace coordinates. All such parameter choices are meta-level configurations only and introduce neither new atomic actions nor new operators into APT.
Input interface. The input action
R(w)
receives the input string w from the external environment and stores it. This interface action does not itself perform a Transformer computation. Once it has terminated, sequential composition transfers control to embedding.
Embedding. The first internal Transformer action is the existing word-embedding action
α1
which reads the symbols wi from the input component, yields the first component oi at each position, and initializes the residual representation at position i as
oi000.
No separate position-embedding action α2 is required in this construction.
First self-attention component. The first self-attention component represented by
(α12⊕α13)∘α5.
Here:
• α12 is the sequence-identity construction used to preserve input information;
α13 is the uniform-average action, which reads the first coordinate and computes its uniform average over positions 1, ⋅, i. It writes the causal prefix average Bi/i to the second workspace coordinate and produce 0 in the other output coordinates;
• α5 merges the preserved input representation with the newly attention output.
Consequently, this component performs
oi000⟼oiBi/i00.
First feed-forward component. The first feed-forward component and its residual connection are
(α3⊕(α6∘α10))∘α5.
Here:
α3 is the vector-level identity construction that preserves the residual representation while the FFN branch computes the new error signal.
• α6 reads the normalized prefix balance Bi/i and multiplies it by -1;
α10 is the continuous-piecewise-linear action, applies ReLU to produce the prefix error signal Ei=ReLU(−Bi/i) and routes the result to the third coordinate;
• α5 adds the computational output to the retained identity-branch output.
The computational branch produces
00Ei0
Thus, this is the correction required to obtain
oiBi/i00⟼oiBi/iEi0.
Second self-attention component The second self-attention component is represented by
(α12⊕α13)∘α5.
Here:
• α12 preserves the residual sequence;
α13 now reads the third coordinate (the error signals Ei) and computes its causal prefix average ti. It writes this value into the fourth coordinate;
• α5 adds the routed output to the preserved representation.
The resulting transformation is
oiBi/iEi0⟼oiBi/iEiti.
Second feed-forward component. No additional feed-forward computation is required after the second self-attention stage. In the Dyck-1 construction, the second attention head already writes the accumulated error ti into the final workspace coordinate, after which recognition is specified by inspecting the final-position values. We therefore omit the second-layer FFN.
Output interface The output action reads the second and fourth coordinates at the final position:
(zn,2,zn,4)=(nBn(w),tn(w))=oD.
Its occurrence is therefore labelled
W(oD),
which emits a two-dimensional numerical result without performing the external acceptance test.
7.2.3 Verification of the Dyck-1 Transformer
We now verify that the Dyck-1 Transformer exhibits the expected external behavior: it receives a nonempty input string, computes and emits the corresponding numerical result, and returns to its input-waiting process.
State-transitions equations. For each w∈Σ+, define its processes are as follows:
Abstraction of internal actions. All configured internal actions belong to I. The interface actions R(w) and W(oD) remain visible.
Theorem 7.2 (Correctness of the Dyck-1 Transformer.). For every received input string w, the transformer construction of Dyck-1 computes and emits its numerical result oD and returns to input-waiting state. Thus, τI(T) satisfies the external behavior equation:
τI(T)=R(w)∘W(oD)∘τI(T).
Proof. First, for the process calculation, axiom P1 gives
α3⊕(α6∘α10)=(α3⊕α6)∘α10.
Together with A5, this rewrites the feed-forward residual process as
T4=(α3⊕α6)∘α10∘α5∘T5.
The abstraction axioms TI1, TI2, TI6, and TI7 apply to the residual-process equations, and using B4 to simplify
Substitution yields eight sequential silent actions between the visible input and output actions. For any continuation Y, A5 and B1 give
R(x)∘(τ∘Y)=A5(R(x)∘τ)∘Y=B1R(x)∘Y.
Applying this equality repeatedly within each input branch yields
τI(T)=R(w)∘W(oD)∘τI(T)
The resulting equation exhibits the required external behavior: the transformer receives a string, emits its corresponding numerical result, and returns to the input-waiting process.
7.3 Verification of a Transformer for Dyck-1-2
In this subsection, we apply APT to the depth-two bracket-matching construction for the Dyck-1-2 presented in the Transformer Cookbook[5]. Unlike the running-balance construction for Dyck-1, this Transformer maintains an active bit at every position and performs two rounds of nearest-neighbor matching.
We first summarize the construction and its recognition criterion. We then represent its embedding, positional encoding, attention, and feed-forward components using existing APT atomic constructions. Finally, we connect these components through recursive process equations and derive the expected external input-output behavior by abstraction.
7.3.1 A Transformer Construction of Dyck-1-2
The Dyck-1-2 language consists of well-nested strings with one type of bracket and maximum nesting depth two. Let Σ={(),}, and let
w=w1⋯wn∈Σ+,n=∣w∣,
be a nonempty input string, where wi is the bracket at position i.
For 1≤i≤n, define
oi={+1,−1,wi=(,wi=).
We initialize our embedding vector xi at each position i as follows:
xi=oi100i/n,
The second coordinate is an "active bit". Its initial value is 1, indicating that the bracket has not yet been matched. A successful match changes this coordinate to 0. The third and fourth coordinates provide scratch space for intermediate computations, and the fifth stores positional information.
Identifying depth-one matches. The first step retrieves the bracket types immediately to the left and right of each position using the predecessor and successor constructions with the corresponding strict masks. The intermediate representation contains the current bracket type and its two neighboring bracket types. An FFN then marks adjacent opening-closing pairs as matched and clears the scratch coordinates:
Thus, both brackets in each adjacent opening-closing pair are marked as matched.
Identifying depth-two matches. The second step searches for the nearest unmatched bracket on each side, ignoring positions whose active bits are zero. This selection through the UHAT expression
The source describes obtaining the required quantities through a linear transformation of the intermediate representation, using the attention query W(Q) and key matrices WK with a bias term. We then proceed analogously to first step, the workspace changes as follows:
Here, li and ri denote the types of the nearest unmatched brackets to the left and right, with 0 denoting a missing neighbor. The nearest unmatched bracket types li and ri are defined as above:
After the second step, the string is accepted if and only if all active bits are 0.
Recognition criterion. The final numerical output is the active-bit sequence
(a1′,…,an′).
The recognition condition is
w∈Dyck−1−2⟺ai′=0foreveryi=1,…,n.
The all-zero test is performed by the external environment.
7.3.2 Algebraic Representation
Input interface. The input action is represented by R(w) which receives the input string w defined in Section 7.3.1 and stores it. Sequential composition then transfers control to the embedding component.
Embedding. The initialization component is represented by
(α1⊕α2)∘α5.
Here:
α1 is the word embedding action, which supplies the bracket type oi and initializes the active bit ai.
α2 is the position embedding action used to supply i/n, which enables attention to identify neighboring positions and select the nearest unmatched brackets in the second matching step.
α5 is the addition action, which adds the outputs of α1 and α2 coordinatewise to obtain the initial workspace vector xi=(oi,1,0,0,i/n)⊤.
First attention component. The first attention component retrieves the bracket types immediately preceding and succeeding each position and stores them in the two scratch coordinates. Its algebraic representation is
(α12⊕α18)∘α5.
Here:
α12 is the sequence identity action. It preserves the current residual sequence, including the bracket types, active bits, and positional encodings.
α18 is a configured multi-head attention action containing two directional heads. The left head retrieves the bracket type oi−1 at position i−1, while the right head retrieves oi+1 at position i+1, using the corresponding strict masks. Their outputs are routed to the third and fourth coordinates, a missing neighbor contributes 0.
α5 adds the preserved residual sequence and the attention output coordinatewise.
Thus, the component performs
oi100i/n⟼oi1oi−1oi+1i/n.
First feed-forward component. The first feed-forward component identifies adjacent opening-closing pairs, changes their active bits to 0, and resets the third and fourth coordinates to 0. The active-bit update is
U1=(α3⊕α10)∘α5.
Here:
α3 is the vector identity action. It preserves the input vector at each position.
α10 is a configured piecewise-linear action. It reads the current bracket type and the two retrieved neighbor types, determines ai according to the first-step matching rule, and routes it only to the second coordinate.
α5 adds the correction to the preserved input vector. It changes the active bit from 1 to ai, resets the third and fourth coordinates to 0, and preserves the bracket type and positional encoding.
The temporary coordinates are cleared by
C3=(α3⊕α6)∘α5,C4=(α3⊕α6)∘α5.
In C3:
• α3 preserves the representation by U1;
α6 reads the third coordinate, multiplies its value by -1, and routes the result to the third output coordinate, with all other output coordinates set to zero;
α5 adds the separately retained branch outputs coordinatewise. The third coordinate becomes oi−1+(−oi−1)=0, while the remaining coordinates are preserved.
In C4:
• α3 preserves the representation produced by C3;
α6 reads the fourth coordinate, multiplies its value by -1, and routes the result to the fourth output coordinate, with all other output coordinates set to zero.
α5 adds the branch outputs coordinatewise. The fourth coordinate becomes oi+1+(−oi+1)=0, while the remaining coordinates are preserved.
updates the active bit and then resets the third and fourth coordinates to zero. It performs
oi1oi−1oi+1i/n⟼oiai00i/n.
Second attention component. The second attention component retrieves the nearest unmatched bracket on each side whenever such a bracket exists. Its algebraic representation is
(α12⊕α18)∘α5.
Here:
α12 preserves the residual sequence produced by the first matching step, including its updated active bits.
α18 is a configured multi-head attention action containing two directional heads. The left and right heads retrieve li and ri, respectively, and route them to the third and fourth coordinates.
• α5 adds the attention output to the preserved residual sequence.
Whenever the corresponding active neighbors exist, this gives
oiai00i/n⟼oiailirii/n.
Second feed-forward component. The second feed-forward component matches adjacent opening-closing pairs in the remaining active sequence, preserves previously matched positions, and resets the third and fourth coordinates to 0. The Second active bit update is
U2=(α3⊕α10)∘α5.
Here:
• α3 preserves the input vector at each position.
Output interface. The output action reads and emits the final active-bit sequence:
W((a1′,…,an′)).
The emitted values are determined by the computed residual state. The external environment accepts exactly when every emitted entry is 0. After output, control returns to the input-waiting process T.
7.3.3 Verification of the Dyck-1-2 Transformer
We now verify that the Dyck-1-2 Transformer exhibits the expected external behavior: it receives a nonempty input string, computes and emits the corresponding numerical result, and returns to its input-waiting process.
Here, F1 and F2 are the composite feed-forward terms defined above.
Abstraction and external behavior. Use the abstraction set I defined earlier in the manuscript, containing all configured internal actions occurring above. The interface actions R(w) and W(a1′,…,an′) remain visible.
Theorem 7.3 (External behavior of the Dyck-1 Transformer.). For every received input string w, the transformer construction of Dyck-1-2 computes and emits final active-bit sequence and returns to input-waiting state. Thus, τI(T) satisfies the external behavior equation
τI(T)=R(w)∘W(a1′,…,an′)∘τI(T).
Proof. Applying the abstraction axioms to the state-transition equations and expanding F1=U1∘C3∘C4 and F2=U2∘C3∘C4 gives
Substituting the abstracted continuation equations into each input branch and repeatedly applying this identity removes the finite sequence of internal silent actions. Consequently,
τI(T)=R(w)∘W((a1′,…,an′))∘τI(T).
The resulting equation exhibits the required external behavior: the transformer receives an input string, emits its computed final active-bit sequence, and returns to its input-waiting process. ☐
References
[1] A. Vaswani, N. Shazeer, N. Parmar, J. Uszkoreit, L. Jones, A. N. Gomez, L. Kaiser, I. Polosukhin, Attention is all you need (2023). arXiv:1706.03762. URL https://arxiv.org/abs/1706.03762
[2] J. Pérez, P. Barceló, J. Marinkovic, Attention is turing complete, Journal of Machine Learning Research 22 (2021) 1–35.
[3] D. H. C. Sanford, M. Telgarsky, Transformers, parallel computation, and logarithmic depth, Under reviewPreprint, available at arXiv:2402.09268 (2024).
[4] W. Merrill, A. Sabharwal, The parallelism tradeoff: Limitations of log-precision transformers, Transactions of the Association for Computational Linguistics 11.
[5] A. Yang, C. Watson, A. Xue, S. Bhattamishra, J. Llarena, W. Merrill, E. D. S. Ferreira, A. S., D. Chiang, The transformer cookbook (2025). arXiv:2510.00368. URL https://arxiv.org/abs/2510.00368
[6] D. Knuth, P. Bendix, Simple word problems in universal algebras, Computational Problems in Abstract Algebra (1970) 263–297.
[7] F. Vaandrager, Verification of two communication protocols by means of process algebra, Tech. Rep. Report CS-R8608, CWI, Amsterdam (1986).