CIA2326 Week 14 - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

CIA2326 Week 14

Description:

CIA2326 Week 14 LECTURE: Formal Specifications. How to reason with Algebraic Specifications TUTORIAL/PRACTICAL: Do the exercises given in last week s handout – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 13
Provided by: COMPUTI354
Category:

less

Transcript and Presenter's Notes

Title: CIA2326 Week 14


1
CIA2326 Week 14
  • LECTURE
  • Formal Specifications.
  • How to reason with Algebraic Specifications
  • TUTORIAL/PRACTICAL
  • Do the exercises given in last weeks handout
  • Read through chapters 8 and 9 of the online book

2
Algebras and Algebraic Specifications
  • Last week we saw
  • - what an algebra was (values closed, total
    operations)
  • - a way to specify algebras by writing Signatures
    of operation
  • - we can give a semantics to data types via
    algebras
  • But how can we reason with values in an algebra?

3
Formal Specifications
  • - good for capturing requirements in safety
    related/critical applications
  • - can eliminate bugs EARLY in SD process
  • - can be used as a precise contract
  • - can be reasoned with using logic
  • - can be manipulated using computer tools
  • - can be used as a basis to prove code correct
  • BUT
  • - not very understandable if they are in Maths
  • - are only part of the story they do not
    guarantee quality

4
That Boolean Example again an algebraic
specification of the Boolean data type
  • SPEC Boolean
  • SORT bool
  • OPS
  • true -gt bool
  • false -gt bool
  • not bool -gt bool
  • and bool bool -gt bool
  • AXIOMS FORALL b bool
  • (1) not(true) false (2) not(false) true
    (3) and(true,b) b
  • (4) and(b,true) b (5) and(false,b) false (6)
    and(b,false) false
  • ENDSPEC

5
That Boolean Example again notations
  • NOTE
  • Operator application can be in different
    notations maths -like
  • not(true)
  • and(true,not(false))
  • or(and(true,not(false)),false)
  • Or more functional oriented -
  • not true
  • and true (not false)
  • or (and true (not false)) false

6
The Term Algebra of an Algebraic Specification
  • The Term Algebra of an Algebraic Specification is
    defined by
  • set of values the set of all terms that can be
    generated using the signature as a generative
    grammar
  • set of operations operations as in the
    signature of the spec.

7
Values of the Boolean Term Algebra
  • The Examples above -
  • not(true)
  • and(true,not(false))
  • or(and(true,not(false)),false)
  • Are values of the term algebra of Boolean.

8
Equational reasoning (READ section 8.8 in the
online book)
  • Assume we have an equation X Y in an Algebraic
    Specification and a member of its term algebra T.
  • X and Y may contain (universally quantified)
    variables, T contains only operators / values (no
    variables).
  • Then we can use the equation to REWRITE T to
    another (equal) term T1.
  • The process is as follows
  • 1. Find a substring of T called T' that MATCHES
    with X under substitution sequence S .
  • 2. Apply S to Y to get Y'
  • 3. Replace T' in T with Y' to form new term T1.

9
Similar examples from other areas..
Basic numeric algebra Term x2 2 Axiom
x 2 Term Rewrites to 222 Grammars for
Syntax definition Term ltexpgt ltexpgt Axiom
ltexpgt ( ltexpgt ltexpgt ) Term Rewrites to (
ltexpgt ltexpgt ) ltexpgt
10
Equational reasoning example
  • Let T or(and(true,not(false)),false)
  • Using the axiom
  • (3) and(true,b) b
  • Substring of T and(true,not(false)) matches
    with the LHS of this equation under the
    substitution S not(false) / b
  • Thus we can re-write term T or(and(true,not(fals
    e)),false) to new term
  • or(b,false) not(false) / b
    or(not(false),false)

11
Equational reasoning LEFT to RIGHT rewrite rules
  • To make re-writing more efficient, it is often
    assumed that it only happens using the axioms
    from left to right. Using them in this fashion
    leads them to be called left to right rewrite
    rules. They are similar (but more general than)
    BNF rules.
  • (1) not(true) gt false (2) not(false) gt true
    (3) and(true,b) gt b
  • (4) and(b,true) gt b (5) and(false,b) gt false
    (6) and(b,false) gt false
  • or(not(false),false) (2)gt or(true,false)

12
Conclusions
  • Algebraic Specs are using to abstractly define
    algebras. Data types can be modelled as algebras.
  • Equational Algebraic Specs can be prototyped
    (operationalised) by using the equations are L-R
    re-write rules
Write a Comment
User Comments (0)
About PowerShow.com