Algebra Term Algebras Take Σ = (S, Ω). Term algebra T (Σ): Wolfgang Schreiner [email protected] Σ-algebra whose carriers are Σ-terms. T (Σ)(s)= TΣ,s , for every s S. T (Σ)(ω)= n ∈ Research Institute for Symbolic Computation (RISC) for every ω =(n : s) Ω. Johannes Kepler University, Linz, Austria → ∈ http://www.risc.jku.at T (Σ)(ω)(t1,..., tk )= n(t1,..., tk )

for every ω =(n : s1 . . . sk s) Ω, ti T (Σ)(si ). × × → ∈ ∈ T (Σ) is the algebra of (well-typed) ground terms of Σ.

Wolfgang Schreiner http://www.risc.jku.at 1/11 Wolfgang Schreiner http://www.risc.jku.at 2/11

Term Algebras Initiality

Example: NAT = ( nat , 0 : nat, Succ : nat nat ). Take signature Σ, class Alg(Σ) of Σ-algebras, and Σ-algebra A . { } { → → } T (NAT)(nat)= 0, Succ(0), Succ(Succ(0)),... . C ⊆ ∈C { } A is initial in if T (NAT)(0) = 0. C T (NAT)(Succ)(t)= Succ(t), for every t T (NAT)(nat). for every B , there exists exactly one h : A B. ∈ A distinguishes∈C most among all algebras of . → Term value T (Σ)(t)= t, for every ground term t T (Σ). C ∈ Initial algebras are unique up to isomorphism: A ground term denotes itself. If A is initial in , then B is initial in iff A B. T (Σ) is freely generated. C C ≃ Theorem: T (Σ) is initial in Alg(Σ). Generated: every carrier is denoted by itself. Free: two different ground terms denote two different carriers. For every A Alg(Σ), there exists the unique evaluation homomorphism∈ : In a term algebra, a ground term and its interpretation coincide. h : T (Σ) A h(t) := A→(t), for every ground term t T . ∈ Σ The term algebra T (Σ) distinguish most among all Σ-algebras.

Wolfgang Schreiner http://www.risc.jku.at 3/11 Wolfgang Schreiner http://www.risc.jku.at 4/11 Congruence Relation Example

Take signature Σ = (S, Ω), Σ-algebra A. BOOL-algebra D: D(bool)= N Congruence relation Q = (Qs )s S on A: n +1, if n is even ∈ D( )(n)= Qs is an equivalence relation on A(s) for every s S. ¬ n 1, otherwise ∈  − (a1, a1′ ) Qs1 ... (ak , ak′ ) Qsk D( )(n, m)= n m ∈ ∧ ∧ ∈ ⇒ ∧ ∗ (A(ω)(a ,..., a ), A(ω)(a′ ,..., a′ )) Q 1 k 1 k ∈ s Q is a congruence relation on D. for every w =(n : s1 . . . sk s) Ω, and × × → ∈ (m, n) Qbool : m + n is even. for every a1, a′ A(s1),..., ak , a′ A(sk ). ∈ ⇔ 1 ∈ k ∈ Take ω = : bool bool: ¬ → Equivalent arguments yield equivalent results. Take n, n′ D(bool) with (n, n′) Qbool . ∈ ∈ We have to show (D( )(n), D( )(n′)) Qbool . A congruence relation preserves equivalence across function applications. ¬ ¬ ∈ n + n′ is even. Thus n and n′ are either both even or both odd. Case 1: we have to show (n + 1, n′ + 1) Qbool , i.e., ∈ (n +1)+(n′ +1)=(n + n′) + 2 is even. . . . Case 2: we have to show (n 1, n′ 1) Qbool , i.e., − − ∈ (n 1)+(n 1) =(n + n′) 2 is even. . . . Take ω =− : bool− bool bool−: . . . ∧ × →

Wolfgang Schreiner http://www.risc.jku.at 5/11 Wolfgang Schreiner http://www.risc.jku.at 6/11

Quotient Algebra Example

Take signature Σ = (S, Ω), Σ-algebra A, congruence relation Q on A. BOOL-algebra D and congruence relation Q on D (as before). (m, n) Qbool : m + n is even. Quotient (algebra) A/ of A by Q: ∈ ⇔ Q Quotient algebra D/Q : Σ-algebra whose carriers are congruence classes. [0] = n N 0+ n is even = n N n is even { ∈ | } { ∈ | } [a]Q = a′ :(a, a′) Q . [1] = n N 1+ n is even = n N n is odd { ∈ } { ∈ | } { ∈ | } Class of a with respect to congruence relation Q. (D/ )(bool)= [0], [1] . Q { } A/Q (s)= [a]Qs a A(s) [1] if n = [0] { | ∈ } (D/ )( )(n)= for every s S. Q ¬ [0] if n = [1] ∈  A/Q (ω)=[A(ω)]Qs [1] if n = m = [1] (D/ )( )(n, m)= for every ω =(n : s) Ω. Q ∧ [0] else → ∈  A/Q (ω)([a1]Q ,..., [ak ]Q )=[A(ω)(a1,..., ak )]Q s1 sk s (D/Q ) C for every ω =(n : s1 . . . sk s) Ω. ≃ × × → ∈ C(bool)= 0, 1 C(True)=1{ } Congruent elements of A are combined to a single element of A/Q . C(False)=0 C( )(n)=1 n C(¬)(n, m)=−n m ∧ ∗ Wolfgang Schreiner http://www.risc.jku.at 7/11 Wolfgang Schreiner http://www.risc.jku.at 8/11 Quotient Term Algebra Examples

Take signature Σ = (S, Ω) and class of algebras Alg(Σ). T (Σ, Alg(Σ)) T (Σ). ≃ C ⊆ Carriers of T (Σ, Alg(Σ)) are singletons [t]= t for every ground Congruence relation of : { } ≡C C term t TΣ. := ( ,s )s S . ∈ ≡C ≡C ∈ T (Σ, A ) A, for every Σ-algebra A. ,s := (t, u) TΣ,s TΣ,s A : A(t)= A(u) . { } ≃ ≡C { ∈ × | ∀ ∈C } Carriers of T (Σ, A ) are classes of all those terms that denote the All ground terms are congruent that have the same value in all { } algebras of . same carrier in A. C Quotient Term Algebra T (Σ, ) of : Let B be the “classical” NATBOOL-algebra. C C T (Σ, ) := T (Σ)/ . Terms True and False belong to the same carrier of T (Σ, B ). C ≡C Terms 0 and 0+0¬ belong to the same carrier of T (Σ, B ).{ } Σ-algebra whose carrier are congruence classes of ground terms of Σ. { } Theorem: If T (Σ, ) , then T (Σ, ) is initial in . C ∈C C C For every A , there exists the unique evaluation homomorphism: ∈C h : T (Σ, ) A h([t]) :=CA(t→), for every ground term t T . ∈ Σ T (Σ, ) relates similarly to as T (Σ) relates to Alg(Σ). C C Wolfgang Schreiner http://www.risc.jku.at 9/11 Wolfgang Schreiner http://www.risc.jku.at 10/11

Quotient Term Algebra of a Set of Formulas

Take L, signature Σ, set of formulas Φ L(Σ). ⊆ Quotient term algebra T (Σ, Φ) of Φ: T (Σ, Φ) := T (Σ, ModΣ(Φ)) (= T (Σ)/ ). ≡ModΣ(Φ) Mod Σ(Φ) = A Alg(Σ) A is a model of Φ . { ∈ | } = (t, u) TΣ,s TΣ,s A Mod Σ(Φ) : A(t)= A(u) . ≡ModΣ(Φ),s { ∈ × | ∀ ∈ } Σ-algebra whose carriers are classes of those terms that have the same value in all models of Φ.

Theorem: If T (Σ, Φ) is model of Φ, T (Σ, Φ) is initial in ModΣ(Φ). For every model A of Φ, there exists the unique evaluation homomorphism: h : T (Σ, Φ) A h([t]) := A(t→), for every ground term t T . ∈ Σ Basis of initial specification semantics.

Wolfgang Schreiner http://www.risc.jku.at 11/11