Universal algebra Basics of universal algebra: signatures and - - PowerPoint PPT Presentation

universal algebra
SMART_READER_LITE
LIVE PREVIEW

Universal algebra Basics of universal algebra: signatures and - - PowerPoint PPT Presentation

Universal algebra Basics of universal algebra: signatures and algebras homomorphisms, subalgebras, congruences equations and varieties equational calculus equational specifications and initial algebras variations: partial


slide-1
SLIDE 1

Universal algebra

Basics of universal algebra:

  • signatures and algebras
  • homomorphisms, subalgebras, congruences
  • equations and varieties
  • equational calculus
  • equational specifications and initial algebras
  • variations: partial algebras, first-order structures

Plus some hints on applications in foundations of software semantics, verification, specification, development. . .

Andrzej Tarlecki: Semantics & Verification

  • 215 -
slide-2
SLIDE 2

Tiny data type

Its signature Σ (syntax): sorts Int, Bool;

  • pns

0, 1: Int; plus, times, minus : Int × Int → Int; false, true : Bool; lteq : Int × Int → Bool; not : Bool → Bool; and : Bool × Bool → Bool; and Σ-algebra A (semantics): carriers AInt = Int, ABool = Bool

  • perations

0A = 0, 1A = 1 plusA(n, m) = n + m, timesA(n, m) = n ∗ m minusA(n, m) = n − m falseA = ff, trueA = tt lteqA(n, m) = tt if n ≤ m else ff notA(b) = tt if b = ff else ff andA(b, b′) = tt if b = b′ = tt else ff

Andrzej Tarlecki: Semantics & Verification

  • 216 -
slide-3
SLIDE 3

Signatures

Algebraic signature: Σ = (S, Ω)

  • sort names: S
  • operation names, classified by arities and result sorts: Ω = Ωw,sw∈S∗,s∈S

Alternatively: Σ = (S, Ω, arity, sort) with sort names S, operation names Ω, and arity and result sort functions arity : Ω → S∗ and sort : Ω → S.

  • f : s1 × . . . × sn → s stands for s1, . . . , sn, s ∈ S and f ∈ Ωs1...sn,s

Compare the two notions

Andrzej Tarlecki: Semantics & Verification

  • 217 -
slide-4
SLIDE 4

Fix a signature Σ = (S, Ω) for a while.

Algebras

  • Σ-algebra:

A = (|A|, fAf∈Ω)

  • carrier sets: |A| = |A|ss∈S
  • operations: fA : |A|s1 × . . . × |A|sn → |A|s, for f : s1 × . . . × sn → s
  • the class of all Σ-algebras:

Alg(Σ) Can Alg(Σ) be empty? Finite? Can A ∈ Alg(Σ) have empty carriers?

Andrzej Tarlecki: Semantics & Verification

  • 218 -
slide-5
SLIDE 5

Subalgebras

  • for A ∈ Alg(Σ), a Σ-subalgebra Asub ⊆ A is given by subset |Asub| ⊆ |A| closed

under the operations: − for f : s1 × . . . × sn → s and a1 ∈ |Asub|s1, . . . , an ∈ |Asub|sn, fAsub(a1, . . . , an) = fA(a1, . . . , an)

  • for A ∈ Alg(Σ) and X ⊆ |A|, the subalgebra of A generated by X, AX, is the

least subalgebra of A that contains X.

  • A ∈ Alg(Σ) is reachable if A∅ coincides with A.

Fact: For any A ∈ Alg(Σ) and X ⊆ |A|, AX exists. Proof (idea):

  • generate the generated subalgebra from X by closing it under operations in A; or
  • the intersection of any family of subalgebras of A is a subalgebra of A.

Andrzej Tarlecki: Semantics & Verification

  • 219 -
slide-6
SLIDE 6

Homomorphisms

  • for A, B ∈ Alg(Σ), a Σ-homomorphism h: A → B is a function h: |A| → |B|

that preserves the operations: − for f : s1 × . . . × sn → s and a1 ∈ |A|s1, . . . , an ∈ |A|sn, hs(fA(a1, . . . , an)) = fB(hs1(a1), . . . , hsn(an)) Fact: Given a homomorphism h: A → B and subalgebras Asub of A and Bsub of B, the image of Asub under h, h(Asub), is a subalgebra of B, and the coimage of Bsub under h, h−1(Bsub), is a subalgebra of A. Fact: Given a homomorphism h: A → B and X ⊆ |A|, h(AX) = Bh(X). Fact: Identity function on the carrier of A ∈ Alg(Σ) is a homomorphism idA : A → A. Composition of homomorphisms h: A → B and g: B → C is a homomorphism h;g: A → C.

Andrzej Tarlecki: Semantics & Verification

  • 220 -
slide-7
SLIDE 7

Isomorphisms

  • for A, B ∈ Alg(Σ), a Σ-isomorphism is any Σ-homomorphism i: A → B that

has an inverse, i.e., a Σ-homomorphism i−1 : B → A such that i;i−1 = idA and i−1;i = idB.

  • Σ-algebras are isomorphic if there exists an isomorphism between them.

Fact: A Σ-homomorphism is a Σ-isomorphism iff it is bijective (“1-1” and “onto”). Fact: Identities are isomorphisms, and any composition of isomorphisms is an isomorphism.

Andrzej Tarlecki: Semantics & Verification

  • 221 -
slide-8
SLIDE 8

Congruences

  • for A ∈ Alg(Σ), a Σ-congruence on A is an equivalence ≡ ⊆ |A| × |A| that is

closed under the operations: − for f : s1 × . . . × sn → s and a1, a′

1 ∈ |A|s1, . . . , an, a′ n ∈ |A|sn,

if a1 ≡s1 a′

1, . . . , an ≡sn a′ n then fA(a1, . . . , an) ≡s fA(a′ 1, . . . , a′ n).

Fact: For any relation R ⊆ |A| × |A| on the carrier of a Σ-algebra A, there exists the least congruence on A that contains R. Fact: For any Σ-homomorphism h: A → B, the kernel of h, K(h) ⊆ |A| × |A|, where a K(h) a′ iff h(a) = h(a′), is a Σ-congruence on A.

Andrzej Tarlecki: Semantics & Verification

  • 222 -
slide-9
SLIDE 9

Quotients

  • for A ∈ Alg(Σ) and Σ-congruence ≡ ⊆ |A| × |A| on A, the quotient algebra

A/≡ is built in the natural way on the equivalence classes of ≡: − for s ∈ S, |A/≡|s = {[a]≡ | a ∈ |A|s}, with [a]≡ = {a′ ∈ |A|s | a ≡ a′} − for f : s1 × . . . × sn → s and a1 ∈ |A|s1, . . . , an ∈ |A|sn, fA/≡([a1]≡, . . . , [an]≡) = [fA(a1, . . . , an)]≡ Fact: The above is well-defined; moreover, the natural map that assigns to every element its equivalence class is a Σ-homomorphisms [ ]≡ : A → A/≡. Fact: Given two Σ-congruences ≡ and ≡′ on A, ≡ ⊆ ≡′ iff there exists a Σ-homomorphism h: A/≡ → A/≡′ such that [ ]≡;h = [ ]≡′. Fact: For any Σ-homomorphism h: A → B, A/K(h) is isomorphic with h(A).

Andrzej Tarlecki: Semantics & Verification

  • 223 -
slide-10
SLIDE 10

Products

  • for Ai ∈ Alg(Σ), i ∈ I, the product of Aii∈I,

i∈I Ai is built in the natural

way on the Cartesian product of the carriers of Ai, i ∈ I: − for s ∈ S, |

i∈I Ai|s = i∈I |Ai|s

− for f : s1 × . . . × sn → s and a1 ∈ |

i∈I Ai|s1, . . . , an ∈ | i∈I Ai|sn, for

i ∈ I, f

i∈I Ai(a1, . . . , an)(i) = fAi(a1(i), . . . , an(i))

Fact: For any family Aii∈I of Σ-algebras, projections πi(a) = a(i), where i ∈ I and a ∈

i∈I |Ai|, are Σ-homomorphisms πi : i∈I Ai → Ai.

Define the product of the empty family of Σ-algebras. When the projection πi is an isomorphism?

Andrzej Tarlecki: Semantics & Verification

  • 224 -
slide-11
SLIDE 11

Terms

Consider an S-sorted set X of variables.

  • terms t ∈ |TΣ(X)| are built using variables X, constants and operations from Ω

in the usual way: |TΣ(X)| is the least set such that − X ⊆ |TΣ(X)| − for f : s1 × . . . × sn → s and t1 ∈ |TΣ(X)|s1, . . . , tn ∈ |TΣ(X)|sn, f(t1, . . . , tn) ∈ |TΣ(X)|s

  • for any Σ-algebra A and valuation v: X → |A|, the value tA[v] of a term

t ∈ |TΣ(X)| in A under v is determined inductively: − xA[v] = vs(x), for x ∈ Xs, s ∈ S − (f(t1, . . . , tn))A[v] = fA((t1)A[v], . . . , (tn)A[v]), for f : s1 × . . . × sn → s and t1 ∈ |TΣ(X)|s1, . . . , tn ∈ |TΣ(X)|sn Above and in the following: assuming unambiguous “parsing” of terms!

Andrzej Tarlecki: Semantics & Verification

  • 225 -
slide-12
SLIDE 12

Term algebras

Consider an S-sorted set X of variables.

  • The term algebra TΣ(X) has the set of terms as the carrier and operations

defined “syntactically”: − for f : s1 × . . . × sn → s and t1 ∈ |TΣ(X)|s1, . . . , tn ∈ |TΣ(X)|sn, fTΣ(X)(t1, . . . , tn) = f(t1, . . . , tn). Fact: For any S-sorted set X of variables, Σ-algebra A and valuation v: X → |A|, there is a unique Σ-homomorphism v# : TΣ(X) → A that extends v. Moreover, for t ∈ |TΣ(X)|, v#(t) = tA[v]. X |TΣ(X)| |A| TΣ(X) A ✲ ❍❍❍❍❍❍❍❍❍ ❥ ❄ ❄ idX ֒

→|TΣ (X )|

v ∃! v# |v#| SetS Alg(Σ)

Andrzej Tarlecki: Semantics & Verification

  • 226 -
slide-13
SLIDE 13

Equations

  • Equation:

∀X.t = t′ where: − X is a set of variables, and − t, t′ ∈ |TΣ(X)|s are terms of a common sort.

  • Satisfaction relation: Σ-algebra A satisfies ∀X.t = t′

A | = ∀X.t = t′ when for all v: X → |A|, tA[v] = t′

A[v].

Andrzej Tarlecki: Semantics & Verification

  • 227 -
slide-14
SLIDE 14

Semantic entailment

Φ | =Σ ϕ Σ-equation ϕ is a semantic consequence of a set of Σ-equations Φ if ϕ holds in every Σ-algebra that satisfies Φ. BTW:

  • Models of a set of equations: Mod(Φ) = {A ∈ Alg(Σ) | A |

= Φ}

  • Theory of a class of algebras: Th(C) = {ϕ | C |

= ϕ}

  • Φ |

= ϕ ⇐ ⇒ ϕ ∈ Th(Mod(Φ))

  • Mod and Th form a Galois connection

Andrzej Tarlecki: Semantics & Verification

  • 228 -
slide-15
SLIDE 15

Equational calculus

∀X.t = t ∀X.t = t′ ∀X.t′ = t ∀X.t = t′ ∀X.t′ = t′′ ∀X.t = t′′ ∀X.t1 = t′

1

. . . ∀X.tn = t′

n

∀X.f(t1 . . . tn) = f(t′

1 . . . t′ n)

∀X.t = t′ ∀Y.t[θ] = t′[θ] for θ: X → |TΣ(Y )| Mind the variables! a = b does not follow from a = f(x) and f(x) = b, unless. . .

Andrzej Tarlecki: Semantics & Verification

  • 229 -
slide-16
SLIDE 16

Proof-theoretic entailment

Φ ⊢Σ ϕ Σ-equation ϕ is a proof-theoretic consequence of a set of Σ-equations Φ if ϕ can be derived from Φ by the rules. How to justify this? Semantics!

Andrzej Tarlecki: Semantics & Verification

  • 230 -
slide-17
SLIDE 17

Soundness & completeness

Fact: The equational calculus is sound and complete: Φ | = ϕ ⇐ ⇒ Φ ⊢ ϕ

  • soundness: “all that can be proved, is true” (Φ |

= ϕ ⇐ = Φ ⊢ ϕ)

  • completeness: “all that is true, can be proved” (Φ |

= ϕ = ⇒ Φ ⊢ ϕ) Proof (idea):

  • soundness: easy!
  • completeness: not so easy!

Andrzej Tarlecki: Semantics & Verification

  • 231 -
slide-18
SLIDE 18

One motivation

Software systems (data types, modules, programs, databases. . . ): sets of data with operations on them

  • Disregarding: code, efficiency, robustness, reliability, . . .
  • Focusing on: CORRECTNESS

Universal algebra from rough analogy:

module interface ❀ signature module ❀ algebra module specification ❀ class of algebras

Andrzej Tarlecki: Semantics & Verification

  • 232 -
slide-19
SLIDE 19

Equational specifications

Σ, Φ

  • signature Σ, to determine the static module interface
  • axioms (Σ-equations), to determine required module properties

BUT: “if” is delicate Fact: A class of Σ-algebras is equationally definable iff it is closed under subalgebras, products and homomorphic images. Equational specifications typically admit a lot of undesirable “modules”

Andrzej Tarlecki: Semantics & Verification

  • 233 -
slide-20
SLIDE 20

Example

spec NaiveNat = sort Nat

  • pns 0: Nat;

succ : Nat → Nat; + : Nat × Nat → Nat axioms ∀n:Nat.n + 0 = n; ∀n, m:Nat.n + succ(m) = succ(n + m) Now: NaiveNat | = ∀n, m:Nat.n + m = m + n Perhaps worse: There are models M ∈ Mod(NaiveNat) such that M | = 0 = succ(0), or even: M | = ∀n, m:Nat.n = m

Andrzej Tarlecki: Semantics & Verification

  • 234 -
slide-21
SLIDE 21

How to fix this

  • Constraints:

initiality: “no junk” & “no confusion” Also: reachability (“no junk”), and their more general versions (freeness, generation). BTW: Constraints can be thought of as special (higher-order) formulae.

  • Other (stronger) logical systems: conditional equations, first-order logic,

higher-order logics, other bells-and-whistles − more about this elsewhere. . . ✗ ✖ ✔ ✕ ✎ ✍ ☞ ✌ Institutions! There has been a population explosion among logical systems. . .

Andrzej Tarlecki: Semantics & Verification

  • 235 -
slide-22
SLIDE 22

Initial models

Fact: Every equational specification Σ, Φ has an initial model: there exists a Σ-algebra I ∈ Mod(Φ) such that for every Σ-algebra M ∈ Mod(Φ) there exists a unique Σ-homomorphism from I to M. Proof (idea):

  • I is the quotient of the algebra of ground Σ-terms by the congruence that glues

together all ground terms t, t′ such that Φ | = ∀∅.t = t′.

  • I is the reachable subalgebra of the product of “all” (up to isomorphism)

reachable algebras in Mod(Φ). BTW: This can be generalised to the existence of a free model of Σ, Φ over any (many-sorted) set of data. BTW: Existence of initial (and free) models carries over to specifications with conditional equations, but not much further!

Andrzej Tarlecki: Semantics & Verification

  • 236 -
slide-23
SLIDE 23

Example

spec Nat = initial { sort Nat

  • pns 0: Nat;

succ : Nat → Nat; + : Nat × Nat → Nat axioms ∀n:Nat.n + 0 = n; ∀n, m:Nat.n + succ(m) = succ(n + m) } Now: Nat | = ∀n, m:Nat.n + m = m + n

Andrzej Tarlecki: Semantics & Verification

  • 237 -
slide-24
SLIDE 24

Try another example

spec NatPred = sort Nat

  • pns 0: Nat; error : Nat;

succ : Nat → Nat; + : Nat × Nat → Nat; pred : Nat → Nat axioms ∀n:Nat.n + 0 = n; ∀n, m:Nat.n + succ(m) = succ(n + m); ∀n:Nat.pred(succ(n)) = n; pred(0) = error; pred(error) = error; succ(error) = error; ∀n:Nat.error + n = error; ∀n:Nat.n + error = error Looks okay. But try to add multiplication: 0 ∗ n = 0; succ(m) ∗ n = n + (m ∗ n); error ∗ n = error; n ∗ error = error and now everything collapses!

Andrzej Tarlecki: Semantics & Verification

  • 238 -
slide-25
SLIDE 25

Partial algebras

  • Algebraic signature Σ: as before
  • Partial Σ-algebra:

A = (|A|, fAf∈Ω) as before, but operations fA : |A|s1 × . . . × |A|sn ⇀ |A|s, for f : s1 × . . . × sn → s, may now be partial functions. ☛ ✡ ✟ ✠ BTW: Constants may be undefined as well.

  • PAlg(Σ) stands for the class of all partial Σ-algebras.

Andrzej Tarlecki: Semantics & Verification

  • 239 -
slide-26
SLIDE 26

Fix a signature Σ = (S, Ω) for a while.

Few further notions

  • subalgebra Asub ⊆ A: given by subset |Asub| ⊆ |A| closed under the operations;

(BTW: at least two other natural notions are possible)

  • homomorphism h: A → B: map h: |A| → |B| that preserves definedness and

results of operations; it is strong if in addition it reflects definedness of

  • perations; (strong) homomorphisms are closed under composition;

(BTW: very interesting alternative: partial map h: |A| ⇀ |B| that preserves results of operations)

  • congruence ≡ on A: equivalence ≡ ⊆ |A| × |A| closed under the operations

whenever they are defined; it is strong if in addition it reflects definedness of

  • perations; (strong) congruences are kernels of (strong) homomorphisms;
  • quotient algebra A/≡: built in the natural way on the equivalence classes of ≡;

the natural homomorphism from A to A/≡ is strong if the congruence is strong.

Andrzej Tarlecki: Semantics & Verification

  • 240 -
slide-27
SLIDE 27

Formulae

(Strong) equation: ∀X.t

s

= t′ as before Definedness formula: ∀X.def t where X is a set of variables, and t ∈ |TΣ(X)|s is a term Satisfaction relation partial Σ-algebra A satisfies ∀X.t

s

= t′ A | = ∀X.t

s

= t′ when for all v: X → |A|, tA[v] is de- fined iff t′

A[v] is defined, and then tA[v] =

t′

A[v]

partial Σ-algebra A satisfies ∀X.def t A | = ∀X.def t when for all v: X → |A|, tA[v] is defined

Andrzej Tarlecki: Semantics & Verification

  • 241 -
slide-28
SLIDE 28

An alternative

  • (Existence) equation:

∀X.t

e

= t′ where: − X is a set of variables, and − t, t′ ∈ |TΣ(X)|s are terms of a common sort.

  • Satisfaction relation: Σ-algebra A satisfies ∀X.t

e

= t′ A | = ∀X.t

e

= t′ when for all v: X → |A|, tA[v] = t′

A[v] — both sides are defined and equal.

BTW:

  • ∀X.t

e

= t′ iff ∀X.(t

s

= t′ ∧ def t)

  • ∀X.t

s

= t′ iff ∀X.(def t ⇐ ⇒ def t′) ∧ (def t = ⇒ t

e

= t′)

Andrzej Tarlecki: Semantics & Verification

  • 242 -
slide-29
SLIDE 29

Example

spec NatPred = initial { sort Nat

  • pns 0: Nat;

succ : Nat → Nat; + : Nat × Nat → Nat; pred : Nat →? Nat axioms ∀n:Nat.n + 0 = n; ∀n, m:Nat.n + succ(m) = succ(n + m); ∀n:Nat.pred(succ(n))

s

= n }

Andrzej Tarlecki: Semantics & Verification

  • 243 -
slide-30
SLIDE 30

First-order structures

  • First-order signature Σ = (S, Ω, Π): algebraic signature (S, Ω) plus predicate

names, classified by arities: Π = Πww∈S∗

  • First-order Σ-structure:

A = (|A|, fAf∈Ω, pAp∈Π) consists of: − (S, Ω)-algebra (|A|, fAf∈Ω) − predicates (relations): pA ⊆ |A|s1 × . . . × |A|sn, for p: s1 × . . . × sn (i.e., p ∈ Πs1...sn)

  • Str(Σ) stands for the class of all first-order Σ-structures.

Andrzej Tarlecki: Semantics & Verification

  • 244 -
slide-31
SLIDE 31

Fix a signature Σ = (S, Ω, Π) for a while.

Few further notions

  • substructure Asub ⊆ A: given by subset |Asub| ⊆ |A| closed under the operations

and such that the inclusion preserves truth of predicates; the substructure is closed if the inclusion also preserves falsity of predicates;

  • homomorphism h: A → B: map h: |A| → |B| that preserves the results of
  • perations and truth of predicates; it is closed if in addition it preserves falsity of

predicates; (closed) homomorphisms are closed under composition;

  • congruence ≡ on A: equivalence ≡ ⊆ |A| × |A| closed under the operations; it is

closed if in addition it preserves truth (and falsity) of predicates; (closed) congruences are kernels of (closed) homomorphisms;

  • quotient structures A/≡: built in the natural way on the equivalence classes of ≡

so that the natural map from A to A/≡ is a homomorphism; it is closed if the congruence is closed.

Andrzej Tarlecki: Semantics & Verification

  • 245 -
slide-32
SLIDE 32

Formulae

  • atomic Σ-formulae over set X of variables:

− t = t′, where t, t′ ∈ |T(S,Ω)(X)|s, s ∈ S − p(t1, . . . tn), where p: s1 × . . . × sn, t1 ∈ |T(S,Ω)(X)|s1, . . . tn ∈ |T(S,Ω)(X)|sn

  • Σ-formulae contain atomic formulae and are closed under logical connectives and

quantification; Σ-sentences are Σ-formulae with no free variables

  • Satisfaction relation defined as usual between Σ-structures A and Σ-sentences ϕ

A | = ϕ As before, this yields the usual notions of the class of models for a set of sentences, the semantic consequences of a set of sentences, the theory of a class of models, etc. Initial (and free) models exist for first-order specifications with universally quantified conditional atomic formulae, but in general may fail to exist!

Andrzej Tarlecki: Semantics & Verification

  • 246 -