Presentation is loading. Please wait.

Presentation is loading. Please wait.

School of Computing and Engineering, University of Huddersfield CIA2326 Week 14 LECTURE: Formal Specifications. How to reason with Algebraic Specifications.

Similar presentations


Presentation on theme: "School of Computing and Engineering, University of Huddersfield CIA2326 Week 14 LECTURE: Formal Specifications. How to reason with Algebraic Specifications."— Presentation transcript:

1 School of Computing and Engineering, University of Huddersfield CIA2326 Week 14 LECTURE: Formal Specifications. How to reason with Algebraic Specifications TUTORIAL/PRACTICAL: Do the exercises given in last week’s handout Read through chapters 8 and 9 of the online book

2 School of Computing and Engineering, 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 reason with values in an algebra?

3 School of Computing and Engineering, University of Huddersfield 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 School of Computing and Engineering, University of Huddersfield That Boolean Example again – an algebraic specification of the Boolean data type SPEC Boolean SORT bool OPS true : -> bool false : -> bool not : bool -> bool and : bool bool -> 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 School of Computing and Engineering, University of Huddersfield 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 School of Computing and Engineering, University of Huddersfield 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 School of Computing and Engineering, University of Huddersfield 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 School of Computing and Engineering, University of Huddersfield 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 School of Computing and Engineering, University of Huddersfield Similar examples from other areas.. Basic numeric “algebra” Term: x**2 + 2 Axiom: x = 2 Term Rewrites to: 2**2+2 Grammars for Syntax definition Term: * Axiom: ::= ( + ) Term Rewrites to: ( + ) *

10 School of Computing and Engineering, University of Huddersfield 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(false)),false) to new term: or(b,false) [not(false) / b ] = or(not(false),false)

11 School of Computing and Engineering, University of Huddersfield 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) => 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 or(not(false),false) =(2)=> or(true,false) =

12 School of Computing and Engineering, University of Huddersfield 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


Download ppt "School of Computing and Engineering, University of Huddersfield CIA2326 Week 14 LECTURE: Formal Specifications. How to reason with Algebraic Specifications."

Similar presentations


Ads by Google