Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Computing and Mathematics, University of Huddersfield CAS2545: WEEK 11 LECTURE: n The meaning of Algebraic Specifications TUTORIAL/PRACTICAL:

Similar presentations


Presentation on theme: "School of Computing and Mathematics, University of Huddersfield CAS2545: WEEK 11 LECTURE: n The meaning of Algebraic Specifications TUTORIAL/PRACTICAL:"— Presentation transcript:

1 School of Computing and Mathematics, University of Huddersfield CAS2545: WEEK 11 LECTURE: n The meaning of Algebraic Specifications TUTORIAL/PRACTICAL: Do the exercises given in last week’s handout Look at the revision questions on the web and attempt them without looking at the answers

2 School of Computing and Mathematics, University of Huddersfield 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 show that an algebra ‘is specified’ by an algebraic specification? And what is the set of algebras specified by the specification?

3 School of Computing and Mathematics, University of Huddersfield MODELS of the “Metre” in Paris The “Metre” in Paris The “Metre” in BerlinThe “Metre” in London The “Metre” in Madrid The “Metre” in Rome

4 School of Computing and Mathematics, University of Huddersfield MODELS of the “Algebraic Specification” of some Data Type The Algebraic Specification Of the Data Type Algebras (data types)

5 School of Computing and Mathematics, University of Huddersfield Models of An Algebra Roughly: A model of an algebraic spec. AS is an algebra A which conforms to the spec. THE ALGEBRAIC SPEC is LIKE THE METRE IN PARIS! To show an algebra A conforms to a specification AS we have to be able to do the following: 1. Map every operation in AS to a unique operation in algebra A. 2. Using this mapping (interpretation), show that the equations in AS are made true.

6 School of Computing and Mathematics, University of Huddersfield Models of An Algebra 1. e.g. Truth table logic, 3 valued logic are models of Boolean specification. 2. e.g. decimal positive numbers, decimal positive numbers modulo 5, are models of the ‘Natural’ specification given out in the notes. 3. e.g. the C implementation of boolean type, with true = 1, false = 0, and = &&, not = !, can be said to be a model of the Boolean specification. 4. e.g. all ‘good’ implementations of a STACK data structure are models of the ‘Stack’ specification given out in the notes.

7 School of Computing and Mathematics, University of Huddersfield Good and Bad Models of An Algebraic Spec Models can be good or bad! For example, 3-valued logic is not a good model of Boolean. The set of models of an alg. spec. as defined is not restricted enough. To find the ‘good’ models we must look closely at an algebraic specification….

8 School of Computing and Mathematics, University of Huddersfield The Term Algebra of an Algebraic Specification The Term Algebra of an Alg. Spec. AS is a SPECIAL model (its similar idea to the Herbrand Universe of a set of well formed formulae in first order logic) The Term Algebra is defined by: n set of values = the set of all terms that can be generated using the signature as a generative grammar n set of operations = operations as in the signature of the spec.

9 School of Computing and Mathematics, University of Huddersfield Focus on the Type Of Interest If we have a heterogeneous algebra with N carrier sets, then the values in its term algebra will split into those N sets. E.g. in stack, (push init 3) is in stack, (is_empty init) is in bool, (top (push init 3)) is in nat. We focus in on the values of the TYPE OF INTEREST (TOI) e.g. stack in the ‘Stack’ spec

10 School of Computing and Mathematics, University of Huddersfield Equivalence Classes in a Term Algebra The values of the term algebra of the TOI fall into distinct equivalence classes If X, Y are in the TOI, then X = Y if and only if X can be transformed to Y using the equations. E.g. (push init 3) and (push init (top (push init 3))) are in the same equivalence class

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

12 School of Computing and Mathematics, University of Huddersfield Equational reasoning example n Let T = or(and(true,not(false)),false) n Using the axiom: n (3) and(true,b) = b n Substring of T “and(true,not(false))” matches with the LHS of this equation under the substitution S = [not(false) / b ] n Thus we can re-write term T = or(and(true,not(false)),false) to new term: n or(b,false) [not(false) / b ] = or(not(false),false)

13 School of Computing and Mathematics, University of Huddersfield Initial Models of An Algebraic Spec A model is INITIAL if two conditions hold: 1. All distinct values in the model are represented by an equivalence class in the spec’s term algebra This means NO JUNK - there are no DISTINCT values in the model (algebra) which aren’t represented by some DISTINCT equivalence class.

14 School of Computing and Mathematics, University of Huddersfield Initial Models of An Algebraic Spec 2. Each equivalence class in the spec’s term algebra represents a unique value in the model This means NO CONFUSION - we cannot have 2 equivalence classes in the model that map to the same value in the model.

15 School of Computing and Mathematics, University of Huddersfield INITIAL MODEL of an “Algebraic Specification” The Algebraic Specification Of the Data Type Algebras (data types) values A B C D Equivalence classes

16 School of Computing and Mathematics, University of Huddersfield JUNK! The Algebraic Specification Of the Data Type Algebras (data types) values A B C D E F Equivalence classes

17 School of Computing and Mathematics, University of Huddersfield CONFUSION! The Algebraic Specification Of the Data Type Algebras (data types) values A B C Equivalence classes

18 School of Computing and Mathematics, University of Huddersfield The Semantics of An Algebraic Spec Given an algebraic specification, its meaning is the set of all its INITIAL MODELS

19 School of Computing and Mathematics, University of Huddersfield Algebraic Specs as ‘Objects’ n An algebraic spec provides an INTERFACE SPECIFICATION informing a client what services are on offer (class and operations). n This spec. is a good one because it provides the formal syntax AND semantics. n The TOI is a defined CLASS.

20 School of Computing and Mathematics, University of Huddersfield Algebraic Specs as ‘Objects’ n A specification of an object’s states are the equiv classes of the spec’s term algebra. n However, algebraic specs give no notion of identity and persistence! n Alg. Specs are easily implemented in HASKELL.

21 School of Computing and Mathematics, University of Huddersfield Operational semantics of algebraic specifications Alg. Specs are easily operationalised (and implemented in HASKELL) The equations are treat as Left to Right re-write rules (or function definitions). But the equations must be in a certain form to make this work..

22 School of Computing and Mathematics, University of Huddersfield Conclusions n Algebraic Specs are using to abstractly define algebras n An algebra conforms to a spec if it is an initial model of that spec. n Equational Algebraic Specs can be prototyped (operationalised) by using the equations are L-R re-write rules


Download ppt "School of Computing and Mathematics, University of Huddersfield CAS2545: WEEK 11 LECTURE: n The meaning of Algebraic Specifications TUTORIAL/PRACTICAL:"

Similar presentations


Ads by Google