Presentation is loading. Please wait.

Presentation is loading. Please wait.

Course: Software Engineering Unit 2: Theories and SchemasSlide Number 1 Unit 2: Theories and Schemas This lecture aims to: Recall some concepts in logic:

Similar presentations


Presentation on theme: "Course: Software Engineering Unit 2: Theories and SchemasSlide Number 1 Unit 2: Theories and Schemas This lecture aims to: Recall some concepts in logic:"— Presentation transcript:

1 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 1 Unit 2: Theories and Schemas This lecture aims to: Recall some concepts in logic: logical theories and models. Define state-based specifications as logical theories. Define basic ingredients of state-based specifications: » the schema notation; » the notion of schema inclusion. Aims and Objectives

2 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 2 Logical theories A logical theory is a set of formulae written in a given formal language. A formal language: extra-logical symbols:  Propositional letters  Constants  Function symbols  Predicate symbols don’t have a fixed meaning; logical operators: , , , , ,  have a fixed meaning  Constants are elements of a given domain (or sort) e.g. Peter is an element of a domain (sort) X = people  Functions map element(s) to an element of the domain e.g. mother: people  people  mother(Peter)=Anne  Predicates are relations over elements of the domain e.g. brother  people  people  brother(Peter,John)

3 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 3 Signature The constants, as elements of the domain: a:X The “arity” of each function symbol: f: X  X, g: X  X  X The “arity” of each predicate symbol: P  X  X, R  X The signature of a given logical theory is the collection of extra-logical symbols used in the theory. e.g., TheorySignature p  q  r p  q, r  x.  y. (P(a,y)  Q(f(y),x)) a, f, P  Q Given a domain “X” and a logical theory, defining a signature means defining:

4 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 4 Examples of theories and signatures  x. (a = 2*x) //meaning: A is a even integer  y. (Even(y)   x. (y = 2*x) //meaning: The set of even integers  y. (Even(y)   x. (y = 2*x) //meaning: A set of even integers //meaning: //All the employees of Doc are headed by Jeff; //Every first-year student has a tutor  x. (employee_Doc(x)  headed(x, Jeff))  x.((student(x)  first_year(x))  y.tutor(y,x)) Domain X = Z a : Z Domain X = Z Even  Z Domain X = people employee_Doc  people headed  people  people student  people first-year  people tutor  people  people Theories Signature definition

5 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 5 Structures and Models Structure Given a signature, a structure is a formal definition of the meaning of each symbol in the signature. Constants: a Function: f(x 1,…,x n ) Predicate: P(x 1,…,x m ) Symbols in a SignatureStructure Domain: X Domain of elements: [X] Element:[a]  [X] Function [f]: [X]  …  [X]  [X] Relation [P]  [X]  …  [X] Model Given a logical theory and its signature, a model is a structure that makes all the formulae in the theory true.

6 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 6 Evaluation in First-order Logic Once we have a structure, we can say if formulae are true or false. Structure  x.  y. (P(a,y)  Q(f(y),x))  x  N.  y  N. (2  y  y 2 divides x) false N X = N, a = 2, f(x) = x 2 P = {(x,y)| x  y} Q = {(x,y)| x divides y} ZZ  x  Z.  y  Z.(0=y  (y+1) 2 +x 2  100) true (x = 0) X = Z, a = 0, f(x) = x+1 P = {(x,y)| x = y} Q = {(x,y)| x 2 +y 2  100}  x  {T,M,H}.  y  {T,M,H}. (P(T,y)  f(y)=x) true (x = Harry) X = {Tom, Mark, Harry},a = Tom f(Tom) = Mark, f(Mark) = f(Harry) = Harry P = {(Tom,Mark),(Tom,Harry),(Mark,Harry)} Q = {(x,y)| x = y}

7 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 7 Signatures, Theories, Structures, Models A signature (or vocabulary or language) describes the extra-logical ingredients that need to be interpreted. A theory comprises a signature and some logical formulae (axioms) constructed using the signature’s symbols. Signatures are interpreted using structures (in which the ingredients are interpreted set-theoretically). Theories are interpreted using models (structures in which the axioms are true).

8 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 8 Schemas: Basic Idea Formal specifications can be seen as logical theories of which the system is the “real-world” model (domains are often collections of elements in the real world, not mathematical sets). We distinguish between state-based specifications and class-based specifications. In a state-based specification: Schemas specify state variables and constraints. Schema operations are used to define operations on states. In an class-based specification: Schemas specify the system in terms of objects (or components) and schema operations define operations on these objects that together capture the full system behaviour.

9 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 9 Schemas From a logic perspective, schemas can be seen as notation for theories. A schema has two parts: signatures and axioms. Theory name [carrier name] Signature(in Z: declarations) Axioms(in Z: predicate) Schema notation is adapted from Z. Our logical view of schemas is different from that of Z –but their use in practice is very similar.

10 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 10 Terminology Vocabulary, signature, extra-logical symbols and (in Z) declaration all mean more or less the same. So do assumptions, axioms and (in Z) predicate. “Predicate” in Z is not the same as “predicate” in predicate logic.

11 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 11 Example: a logical theory as schema “Prems” is just a name we’ve invented for this schema Given a schema, we can draw inferences from it –logical consequences of the axioms using the symbols in the signature. Prems [X] a: X f: X  X P, Q  X  X  x:X.  y:X. (P(a,y)  Q(f(y),x)) A schema can be used to describe vocabulary and assumptions. Consider the logical theory defined by:  x.  y. (P(a,y)  Q(f(y),x)) The schema The domain The signature The axioms

12 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 12 Notation “:” means “of type” “  ”  means functions - so f: X  X means f is a function with one argument “  ” is used for predicates “  ” means Cartesian product - so P  X  X means P is a predicate with two arguments The bound variables x and y don’t need declaring in the signature. Prems [X] a: X f: X  X P, Q  X  X  x:X.  y:X. (P(a,y)  Q(f(y),x)))

13 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 13 Example of a schema N N is a special purpose set with its own operators, predicates and reasoning principles already defined. No carrier needed! N –Structure needs carrier to show range of values of variables - but that is already fixed for variables of type N. No need to declare 0 or + in the signature. NN S: N  N S(0) = 0 N  x:N. S(x+1) = S(x)+x+1 SchemaS

14 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 14 A list example seqX is the type of finite sequences (lists) from X “:” is sometimes “of type”, sometimes “cons” »you can tell which by the context ++ and […] are ordinary list notation “scrub” means “delete all instances of an element from the list”. ScrubFn [X] scrub: X  seqX  seqX  y:X. scrub(y,[ ]) = [ ]  y,x:X.  xs: seqX. (y  x  scrub(y, x:xs) = [x] ++ scrub(y,xs))  x:X.  xs: seqX. scrub(x, x:xs) = scrub(x,xs)

15 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 15 Schema inclusion (an example) Consider now the extended theory:  x.  y. (P(a,y)  Q(f(y),x)),  y. (P(a,y)  Q(f(y),x 0 ))), P(a,y 0 )} ExtPrems Prems[X] x 0, y 0 : X  y. (P(a,y)  Q(f(y),x 0 ))) P(a,y 0 )

16 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 16 Schema inclusion (definition) ExtPrems Prems[X] x 0, y 0 : X  y. (P(a,y)  Q(f(y),x 0 )) P(a,y 0 ) It means everything in schema Prems is also part of schema ExtPrems. a, x 0, y 0 : X f: X  X P, Q  X  X  x.  y. (P(a,y)  Q(f(y),x))  y. (P(a,y)  Q(f(y),x 0 )) P(a,y 0 ) ExtPrems[X] ExtPrems written out in full.ExtPrems with Prems as inclusion. Very useful shorthand Shows hierarchy of schemas and sub-schemas Prems[X] written in ExtPrems is a schema inclusion

17 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 17 Example of schema (Many-sorted logic) Consider this: [people, towns] birthplace: people  towns Needs two carriers! –Structure = pair of sets with function between them. “people” and “towns” are two sorts in a many-sorted signature. One sort (ordinary predicate logic). No sorts (propositional logic).

18 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 18 Many-sorted Logic Signature A set of sorts or domains Sorts are like types in a programming language A set of predicate symbols, each with a given arity P is of this arity: P  X 1  …  X n, where X 1, ….,X n may be different domains. A set of function symbols, each with a given arity f is a function of this arity: f: X 1  …  X n  Y where X 1, ….,X n, and Y may be different domains Formulae can be meaningless simply because they are not “well- typed”. A set of constant symbols, each with its own sort

19 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 19 Examples of many-sorted formulae  s:StudentIC. (grade(s)=first) 1) All IC students graduate with a first  e:Employees. (salary(e) < 20000). 2)All employees have salary under 20000 pounds  b:books,  p:people. [(italian(p)  read(p,b))  b=topolino] 3) Italians read only Topolino  b:Lib_books. (borrowed(b)  status(b) = out_library). 4) All borrowed books are not in the library  t:Time,  s:Students,  b,b1:Lib_books. (borrowing(s,b,t)  borrowing(s,b1,t)  b=b1). 5) Students can borrow only one book

20 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 20 Sorts and types Sorts (logic) and types (programming) are roughly the same. Can construct lots, e.g. N, seqX, FX, etc. The only ones that go in square brackets at the top of the schema are the “primitive sorts”, which are not special purpose sets or sets constructed out of others. [X] N a:Netc. ….. right N [X,N,seq X] N a:Netc. ….. wrong

21 Course: Software Engineering Unit 2: Theories and SchemasSlide Number 21 Summary A schema is a way of describing a logical theory. The description has N –sorts (primitive sorts, constructed sorts like N, seqX) –constants, functions, predicates, propositions –axioms. A schema inclusion is a shorthand notation for schemas. A schema has models. If the schema is a specification, then a model is the real- world system that satisfies the axioms of the schema.


Download ppt "Course: Software Engineering Unit 2: Theories and SchemasSlide Number 1 Unit 2: Theories and Schemas This lecture aims to: Recall some concepts in logic:"

Similar presentations


Ads by Google