Algebraic specifications : formal definitions - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Algebraic specifications : formal definitions

Description:

The signature of an algebraic specification consists of sorts of some data and ... The teminal symbols are T = F {(,)} {where F is the disjunctive union of sets fs, ... – PowerPoint PPT presentation

Number of Views:813
Avg rating:3.0/5.0
Slides: 22
Provided by: Srid60
Category:

less

Transcript and Presenter's Notes

Title: Algebraic specifications : formal definitions


1
Algebraic specifications formal definitions
  • The signature of an algebraic specification
    consists of sorts of some data and some
    operation symbols on them
  • Definition 1 (Signature) A signature is a pair
    ? ?S, F?. With S a set of sorts, and F
    fs1,...,sn,s, with si ? F is a set of
    SxS-indexed operation symbols. Each operation
    is usually represented as f s1 x ...x sn
    s

2
Algebraic specifications formal definitions
  • Signature may be graphically represented as
    graphs with
  • There are two kinds of nodes each sort in an
    operation is node. Each operation is also
    represented by a node.
  • There are two kinds of arcs. Indirected arcs from
    argument sorts nodes to an operation node, and a
    directed node from an opration to the resulting
    sort.

3
Algebraic specifications formal definitions
s1
.
s
.
f s1 ... sn,s
sn
4
Algebraic specifications formal definitions
  • Examples
  • (a) nat
  • Sorts nat
  • Ops 0 ? nat
  • succ nat ? nat

succ
nat
0
5
Algebraic specifications formal definitions
  • Examples
  • (b) bool
  • Sorts bool
  • Ops true, false ? bool
  • ? bool ? bool
  • ?, ?, ... bool x bool ? bool

?
true
bool
false
?, ?, ...
6
Algebraic specifications formal definitions
  • Examples
  • (c) nat1 bool nat
  • Ops nat x nat ? nat
  • ? nat x nat ? bool

succ
true
0
nat
bool
?
false
?, ?, ...
7
Algebraic specifications formal definitions
  • Examples
  • (c) natstack nat1
  • Sorts Stack
  • Ops new ? stack
  • push stack x nat ? stack
  • pop stack ? stack
  • top stack ? nat

push
succ
new
8
Algebraic specifications formal definitions
  • Examples
  • (c) natqueue nat1
  • Sorts queue
  • Ops empty ? queue
  • in queue x nat ? queue
  • out queue ? queue
  • front queue ? nat

succ
in
empty
9
Algebraic specifications formal definitions
  • There is a close relationship between signatures
    ? ?S, F? and context-free grammars.
  • G(?)G(?)s0 (N,T,s0 ,P) s0?S
  • Non terminal symbols are N S
  • The teminal symbols are T F ? (,) ? ,
    where F is the disjunctive union of sets fs,s
  • The start symbol for G(?)s0 is s0 .
  • The production rules are given by
  • P s f(s1 ,..., sn) / f?F
  • G(bool) bool true false ?bool
    bool ? bool ...

10
Algebraic specifications formal definitions
  • Definition 2 (Terms) given a signature ?
    ?S, F?, With S a set of sorts, and F
    fs1,...,sn,s.
  • A set of (closed) terms of a sort s over F,
    denoted TF,s are constructed as follows
  • Each constant of sort s is a term in TF,s.
  • If t1, .., tn are terms of sorts s1, ..., sn
    respectively and fs1,...,sn,s is in F then
    f(t1,...,tn) is a term in TF,s
  • There no terms of sort s except those from 1. and
    2.

11
Algebraic specifications formal definitions
  • Examples
  • Nat spec. 0 succ(0) succ(succ(0)) ....
    (succ(succ(0)),0) succ((succ(0),succ(succ(succ
    (0))))).
  • bool spec. true ?true ?(true, ?true)
    ....
  • Natstack spec. new push(push(push(new,0),0),s
    ucc(0)) push(pop(new),top(pop(new))) ....
  • In addition of this prefix notations of terms, it
    is also possible to use the usual infix , postfix
    or mixfix notations succ(0) succ(succ(0))
    succ(succ(0))!, if true then succ(0) else
    succ(succ(succ(0)))

12
Algebraic specifications formal definitions
  • Terms with variables usually to express and use
    terms we include in terms also variables.
  • Given a signature SIG ?S, F?, we generally
    introduce a set Xs called a set of variables of
    sort s. Such variables are assumed to be pairwise
    disjoint and also disjoint with F. The union X
    ?s? S Xs is called set of variables w.r.t. SIG.
  • Terms (with variables) of sort s are constructed
    as in definitions 2, with additionally in 1.
    variables of sort s are also terms.

13
Algebraic specifications formal definitions
  • Examples
  • Nat spec. Xnat x, y Tnat(X) 0 succ(0)
    succ(succ(x)) .... (succ(succ(0)),y)
    succ((succ(x),succ(succ(succ(x))))) ... .
  • bool spec. Xbool z z, true ?true ?(z,
    ?true) ....
  • Natstack spec. Xstackst new
    push(push(push(st,0),0),succ(0))
    push(pop(new),top(pop(st))) ....
  • Terms without variables are called ground or
    closed terms. 0 succ(0) ...

14
Algebraic specifications formal definitions
  • Definition 3 An algebra A (SA, FA) of a
    signature SIG ?S, F? , also called SIG-algebra,
    is given by two families SA (As)s?S and FA
    (fA) f? F , where
  • As are sets for all s?S, called base sets or
    domains of A.
  • fA are elements fA ? As for all constant symbols
    in F i.e.
  • f ? s and s?S , called constant.
  • fA As1 x As2 x ... x Asn ? As are functions
    for all operation symbols f s1...sn,s from F,
    called operations of A, where x denotes the
    cartesian product of sets.
  • If a signature SIG ?S, F? is given as a list
    s1,..,sn of sorts and a list f1,..,fn of
    constants and operation symbols a SIG-algebra is
    represented as a list
  • A (As1,....,Asn, f1A,..., fnA)

15
Algebraic specifications formal definitions
  • Example
  • Nat-algebra NAT (Snat, Fnat) (natnat, 0nat,
    succnat)
  • natnat 0, 1 , 2 , 3 , ..... , n,...
    naturals
  • 0nat 0 (of the natural)
  • succnat successor (of the naturals) naturals
    ? naturals .

16
Algebraic specifications formal definitions
  • Binary trees
  • Binarytree-base
  • sorts alphabet
  • bintree
  • opns K1,...,Kn alphabet
  • LEAF alphabet ? bintree
  • RIGHT bintree alphabet ? bintree
  • BOTH bintree alphabet bintree ? bintree
  • BINTREE-BASE (A , B , a1 ,.., an ,leaf,left,
    right, both) where
  • A a1,...,an B the set of binary trees
  • leaf A ? B is defined by leaf(ai) tree(ai)
    for i 1,...,n
  • left B x A ? B adds a left subtree
  • right A x B ? B adds a right subtree, and
  • both B x A x B ? B adds a left and a right
    subtree .

17
Algebraic specifications formal definitions
  • Define the terms of bintree, and give the term
    corresponding to

18
Algebraic specifications formal definitions
  • Now we are going to define the evaluation of
    terms with and without variables in a given
    algebra A. For terms with variables we have to
    start an assignment for the variables. These
  • Definition 4 (evaluation of terms)
  • Let TF be the set of terms of a signature SIG
    ?S, F? and A a SIG-algebra. The evaluation eval
    TF ? A is recursively defined by
  • (i) Eval (f) fA for all constant symbols f ?
    F
  • (ii) Eval(f(t1,...,tn)) fA(eval(t1),...,eval(tn
    )) for all terms f(t1,...,tn) ? TF

19
Algebraic specifications formal definitions
  • Given a set of variables X and SIG (S,F) and an
    assignment ass X ? A with ass(x) ?As for x ?
    Xs and s ? S. The extended assignment, or simply
    extension ass TF(X) ? A of the assignment ass
    X ? A is recursively defined by
  • ass(x) ass(x) for all variables x
  • ass(f) fA for all constant
    symbols f ? F
  • (ii) ass(f(t1,...,tn)) fA(ass(t1),...,ass(tn))
    for all f(t1,...,tn) ? TF(X).

20
Algebraic specifications formal definitions
  • For X ? there is exactly one assignment ass
    which the empty assignment, and we have ass
    eval .
  • We have then families of functions
  • eval (evals TF,s ? As)s?S
  • ass (asss Xs ? As)s?S and
  • ass (asss TF,s (X)? As)s?S
  • The diagrams (1) and (2) commute
  • That is TF,s ? TF (X) A TF A
  • and X ? TF(X) A X A

TF(X)
TF(X)
X
(1)
(2)
ass
eval
A
ass
ass
ass
21
Algebraic specifications formal definitions
  • Evaluate add(succ(n),m)), with Xnat n,m and
    Assx(n)5 and assx(m) 3
Write a Comment
User Comments (0)
About PowerShow.com