Algebraic specifications : formal definitions - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Algebraic specifications : formal definitions

Description:

The equation e =(X , L, R) is called valid in a SIG-algebra A if for all ... is an algebra A of the signature SIG which satisfies all equations in E. ... – PowerPoint PPT presentation

Number of Views:27
Avg rating:3.0/5.0
Slides: 21
Provided by: Srid60
Category:

less

Transcript and Presenter's Notes

Title: Algebraic specifications : formal definitions


1
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
2
Algebraic specifications formal definitions
  • Evaluate add(succ(n),m)), with Xnat n,m and
    Assx(n)5 and assx(m) 3

3
Algebraic specifications Equations
  • By choosing an algebraic semantics to abstract
    data types, algebraic structures (e.g. monoid,
    group, rings, ..) are also endowed with equations
  • They express the relationship between different
    operators.
  • They allow to describe complex (defined) function
    symbols using elementary (constructor) operation
    symbols.
  • They allow us to have a simplified form of any
    term.

4
Algebraic specifications Equations
  • Examples
  • (a) bool
  • Sorts bool
  • Ops true, false ? bool
  • ? bool ? bool
  • ?, ? bool x bool ? bool
  • if_then_else_fi bool x bool x bool ? bool
  • Vars p, q bool
  • Eqs if true then p else q fi p
  • if false then p else q fi q
  • ? p if p then false else true fi
  • p ? q if p then q else false fi
  • p ? q if p then true else q fi

5
Algebraic specifications Equations
  • (b) nat
  • Sorts nat
  • Ops 0 ? bool
  • succ nat ? nat
  • add nat x nat ? nat
  • Vars n, m nat
  • Eqs add(n, 0) 0
  • add(succ(n), m)) succ(add(n,m))

6
Algebraic specifications Equations
  • (b) nat1 natbool
  • Ops ? nat x nat ? bool
  • Vars n, m nat
  • Eqs (0 ? n) true
  • (succ(n) ? 0) false
  • (succ(n) ? succ(m)) (n ? m)

7
Algebraic specifications Equations
  • (b) natstack nat1
  • Sorts S
  • Ops new ? S
  • push S x nat ? S
  • pop S ? S
  • top S ? nat
  • Vars s S n nat
  • Eqs pop(push(s,n) s
  • top(push(s,n)) n
  • pop(new) new
  • top(new) 0

8
Algebraic specifications Equations
  • Definition Given a signature SIG ?S, F? and
    variables X w.r.t. SIG
  • A triple e (X , L, R) with L, R ? TF,s (X) for
    some s?S, is called an equation of sort s w.r.t.
    SIG.
  • The equation e (X , L, R) is called valid in a
    SIG-algebra A if for all assignments ass X ? A
    we have
  • ass(L) ass(R)
  • Where ass is the extended assignment of ass. If
    e is valid in A we also say that A satisfies e.
  • 3. Ground equations are equations e (X , L, R)
    with X ? (that is when L and R are ground
    terms).

9
Algebraic specifications Equations
  • An equation is a universal first order formula
  • ? x1 ? s1, ? x2 ? s2 . . . . ? xn ? sn (L R)
    written usally as x1 ? s1, x2 ? s2 . . . . xn ?
    sn (L R)
  • X must contains all variables occuring in L and
    R.
  • In general, for sake of simplicity the variables
    set is omitted.

10
Algebraic specifications Specification and
SPEC-algebra
  • Definition (specification and SPEC-algebra)
  • A specification SPEC ?S, F, E? consists of a
    signature SIG ?S, F ? nand a set E of equations
    e w.r.t. SIG variables X w.r.t. SIG
  • An algebra A of the specification SPEC, short
    SPEC-algebra , is an algebra A of the signature
    SIG which satisfies all equations in E.

11
Algebraic specifications Specification and
SPEC-algebra
  • A specification is also called algebraic
    specification or equational specification.
  • If a specification SPEC1 consists of a given
    specification SPEC and additional sorts S1,
    operations F1, and equations E1, we write this in
    the form
  • SPEC1 SPEC (S1, F1, E1)
  • Which means
  • SPEC1 (S, S1, F F1, E, E1)

12
Algebraic specifications Specification and
SPEC-algebra
  • Show that NAT (N, , 1, ) is a nat-algebra,
    that is for each assignment ass X ? N with
    Xn,m the extended assignments applied to both
    equations deliver the same values.

13
Algebraic specifications Specification and
SPEC-algebra
  • Definition (derivation of rewriting of terms)
  • Given a set E of equations for a signature with
    a fixed set of variables X Xe for each
    equation e. (L,R) ? E defines two substitution
    rules
  • (1) L gt R (L-R-rule)
  • (2) R gt L (R-L-rule)
  • A rule t1 gt t2 is applicable to a term t ?
    TF(X) if there is an assignment assX? TF(X) with
    extension ass TF(X) ? TF(X) such that we have
    for t1 ass(t1) and t2 ass(t2)
  • (3) t1 is a subterm of t.

14
Algebraic specifications Specification and
SPEC-algebra
  • The replacement of t1 in t by t2 yields a term
    t, the replacement of t1 by t2 in t is denoted
    by
  • (4) t t(t1 / t2)
  • In this case we write
  • (5) t gt t, called direct
    derivation from t to t via E using the rule
    t1gt t2 and assignement ass.
  • (6) t gt t represent any sequence
  • t0gtt1 gt ....gt tn with t t0 and t
    tn. It is called derivation from t to t via E
    and it is correct w.r.t. SIG-algebra A if for
    each assignment ass X ? A
  • (7) ass(t) gt ass(t)


15
Algebraic specifications Specification and
SPEC-algebra
  • Definition (occurrence or positions in terms)
  • Given a term t, the set of positions in t,
    denoted by Dom(t), is the set of sequences of
    natural numbers defined as
  • If t is constant or variable, then Dom(t) ?
  • If t is of the form f(t1, ..., tn) then
  • Dom(t) ? ? i.p / i ? 1,..,n and p ?
    Dom(ti)
  • Definition (subterms)
  • Given a term t, and a position p ? Dom(t) we
    define a subterm of t rooted at a position
    denoted tp as
  • p ?, then tp t
  • If p i.pthen t f(t1, ...,ti,...)i.p
    tip
  • A term t is said to be a subterm of a t is there
    is a position p such that t tp

16
Algebraic specifications Specification and
SPEC-algebra
  • Definition (Term replacement)
  • Given a term t, a position p, and a term t, we
    define tp t as
  • If p ? then tp t t
  • If p i.p then t f(t1, ..., ti-1,ti,
    ti1...)i.p t
  • f(t1, ..., ti-1,ti p t,
    ti1...)
  • Definition (Rewriting term)
  • Given a system of rules (oriented equations), R,
    we define a rewrite relation by gtR , as t gt
    t, if
  • There is a rule r l gt r is R there is an
    assignement (substitution) ? X ? TF(X) and a
    position p in t such that tp ? (l) and t
    tp ? (r)

17
Algebraic specifications Specification and
SPEC-algebra
  • Definition (Congruence on Ground Terms)
  • Given a specification SPEC (S, F, E) the
    relation ? on ground terms defined for all t1, t2
    ? TF by
  • t1 ? t2 if and only if evalA(t1) evalA(t2)
    for all SPEC-algebra A is called congruence on
    ground terms.
  • It satisfies the following conditions for all t1,
    t2, t3 ? TF
  • - t1 ? t1 (reflexivity) t1 ? t2 implies t2 ?
    t1 (symmetry)
  • t1 ? t2 and t2 ? t3 implies t1 ? t3
    (transitivity)
  • - t1 ? t1 ,..., tn ? tn implies f(t1,...tn) ?
    f(t1,....,tn) (congruence)
  • - each derivation t1 gt t2 via E between ground
    terms t1, t2 ? TF implies t1 ? t2 .


18
Algebraic specifications Specification and
SPEC-algebra
  • A rewriting relation gtR is like a congruence
    relation without the reflexivity property.

19
Algebraic specifications Specification and
SPEC-algebra
  • Definition (Quotient Term Algebra TSPEC)
  • Given a specification SPEC (S, F, E) the
    quotient term algebra
  • TSPEC ((Qs) s?S, (fQ) f?F) is defined by
  • 1. For each s ? S, we have a base set
  • Qs t / t ? TF,s
  • where the congruence class t is defined by
  • t t / t ? t
  • 2. For each constant symbol f ? s in F the
    constant Qs is the congruence class generated
    by f fQ f
  • 3. For each operation symbol fs1 ...sn ? s in F
    the operation
  • fQ Qs1 x ... x Qsn ? Qs is defined by
  • fQ(t1, ...,tn) f(t1,...,tn)

20
Algebraic specifications Specification and
SPEC-algebra
  • Example (Quotient Term Algebra Tnat)
  • Tnat (Qnat , 0Q, SUCCQ, ADDQ)
  • With
  • - Qnat SUCCn(0) / n ? 0
  • - 0Q 0, and for n, m ? 0
  • - SUCCQ(SUCCn(0)) SUCCn1(0)
  • - ADDQ(SUCCn(0), SUCCm(0)) SUCCnm(0)
  • Fact TSPEC is a SPEC-Algebra and it is called
    the initial semantics with ADT(SPEC) A / A ?
    TSPEC is called the (initial) abstract data
    type defined by SPEC.
Write a Comment
User Comments (0)
About PowerShow.com