Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
overview
Sigma algebras
equational programming
2016 01 21
lecture 6
overview
syntax and semantics
initial models
Sigma Algebras
Let (S, Σ) be a signature.
A Σ-algebra A consists of
Sigma algebras
• a carrier (set) A
which is a S-sorted set (As )s∈S , and
syntax and semantics
• an interpretation IA ,
mapping function symbols in Σ to concrete functions over A.
initial models
That is, if f : s1 × · · · × sn → s, then
IA (f ) : As1 × · · · × Asn → As
Instead of IA (f ) we write fA .
remarks
example: a Naturals-algebra
A is {a, b, c}
Every many-sorted set with many-sorted functions is a Σ-algebra,
0A ≡ a;
the interpretations of succ, add and mul are given by the following tables:
as long as the sorts and types correspond to the signature.
At this point we do not yet consider the equations.
a
b
c
succA
a
a
a
addA
a
b
c
a
b
c
a
b
c
a
b
c
a
b
c
mulA
a
b
c
a
c
b
a
question: Are the equations for Naturals ‘valid’ in this algebra?
example: another Naturals-algebra
The ‘natural’ Naturals-algebra consists of the natural numbers:
questions
Give a Naturals-algebra with carrier {a}.
A is {0, 1, 2, . . .}, and
0A
≡ 0
succA (n)
≡ n+1
What is the ‘natural’ Booleans-algebra?
Give a Booleans-algebra that is well-defined but ‘nonsense’.
addA (m, n) ≡ m + n
mulA (m, n) ≡ m ∗ n
What is the‘natural’ Stacks-algebra?
b
c
b
a
c
c
b
a
overview
Sigma algebras
syntax and semantics
Assignments
Given:
(S, Σ) a signature
X an S-sorted set of variables
A = (A, IA ) a Σ-algebra
An assignment is a function θ : X → A
(with θ : Xs → As for all s ∈ S).
initial models
An assignment θ is inductively extended to a homeomorphism
θ̄ : Ter Σ (X ) → A:
θ̄(x)
≡ θ(x)
θ̄(f (t1 , . . . , tn )) ≡ fA (θ̄(t1 ), . . . , θ̄(tn ))
remark
definition: true in an algebra
An equation t = u is true (valid) in A if
On closed terms θ̄ does not depend on θ.
Then we often write eval A instead of θ̄.
for every assignment θ we have:
θ̄(t) ≡ θ̄(u)
example: Naturals algebra
model: definition
Take as carrier {a, b, c}
and as interpretation 0A ≡ a and
succA
a
a
b
a
a
c
addA
a
b
c
a
b
c
a
b
c
a
b
c
a
b
c
succ(succ(0)) = 0 is true in A:
Let ((S, Σ), E ) be an equational specification.
A Σ-algebra A is a model for E
eval A (succ(succ(0))) ≡ succA (succA (0A ))
if all equations in E are true in A.
≡ succA (succA (a)) ≡ succA (a) ≡ a
≡ 0A ≡ eval A (0)
add(x, 0) = x is not true in A. For example, let θ(x) ≡ a:
θ̄(add(x, 0)) ≡ addA (θ(x), 0A ) ≡ addA (a, a) ≡ b
θ̄(x) ≡ θ(x) ≡ a
model: examples
semantic consequence
example: A is {a, b, c} with 0A ≡ a and
succA
a
a
b
a
a
c
addA
a
b
c
a
b
c
a
b
c
a
b
c
a
b
c
Assume an equational specification ((S, Σ), E ).
An equation t = u is a semantic consequence of E ,
is not a model for [N1]-[N2].
notation E |= t = u,
example: A is {a} and fA (a, . . . , a) ≡ a for all f ∈ Σ. This is a model for
every equational specification.
if t = u is true in every model of E .
example: The natural numbers {0, 1, 2, . . .} with successor, addition and
multiplication is a model for [N1]-[N4].
Birkhoff’s Theorem
Birkshoff’s theorem: we have both correctness and completeness.
example
question: Do the following two equations follow semantically from
[B1]–[B2]?
and(and(F, x), y) = F
Correctness theorem: E ` t = u ⇒ E |= t = u
and(x, x) = x
Completeness theorem: E |= t = u ⇒ E ` t = u
The equations:
[B1] and(T, x) = x
As a consequence, add(x, y) = add(y, x) is not derivable from [N1]-[N2].
[B2] and(F, x) = F
overview
junk: definition
Sigma algebras
Assume an equational specification ((S, Σ), E ).
syntax and semantics
A model A for E contains junk
if there exists a ∈ A such that for all closed terms t:
initial models
eval A (t) 6≡ a
junk: example for Naturals
confusion: definition
A is {0, 1, 2, . . .} ∪ {∞} with
0A ≡ 0
succA (n) ≡ n + 1
addA (m, n) ≡ m + n
Assume an equational specification ((S, Σ), E ).
A model A for E contains confusion if there exist closed terms t and u such
that:
eval A (t) ≡ eval A (u) ∧ E 6` t = u
is a model for [N1] and [N2].
This model contains (a bit of) junk: ∞ is not the interpretation of a closed
term.
confusion: example for Naturals
initial model: definition
A is {a} with
0A ≡ a
succA (a) ≡ a
Assume an equational specification ((S, Σ), E ).
addA (a, a) ≡ a
A model for E is initial if it contains neither junk nor confusion.
is a model for [N1] and [N2].
This model contains (a lot of) confusion, for example:
eval A (succ(0)) ≡ a ≡ eval A (0)
although succ(0) = 0 is not derivable from [N1] and [N2].
example: initial model for Naturals
example: initial model for Booleans
A is {true, false} with
TA ≡ true
A is {0, 1, 2, . . .} with
FA ≡ false
andA (b1 , b2 ) ≡ b1 ∧ b2
0A ≡ 0
succA (n) ≡ n + 1
orA (b1 , b2 ) ≡ b1 ∨ b2
addA (m, n) ≡ m + n
notA (b) ≡ ¬b
mulA (m, n) ≡ m·n
is a model for
is a model for [N1]-[N4].
This model is initial: there is no junk and no confusion.
and(T, b) = b
and(F, b) = F
or(T, b) = T
or(F, b) = b
not(T) = F
question: initial model for Toy
question
Given the following function symbols:
This model is initial.
c
: → thing
d
: → thing
nxt : thing → thing
not(F) = T
Given an equational specification.
How do we intuitively construct an initial model?
and the following equations:
nxt(nxt(c)) = d
nxt(nxt(nxt(x))) = x
Give an initial model.
definition: initially correct specification
Assume the equational specification ((S, Σ), E ) is an initial model for a
Σ-algebra A.
Then ((S, Σ), E ) is said to be an initially correct specification for A.