Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
1 Concurrent Object-Oriented Programming Arnaud Bailly, Bertrand Meyer and Volkan Arslan Chair of Software Engineering 2 Lecture 6: Tutorial on Formal Logics for Computation and Concurrency. Chair of Software Engineering Formal Logics Have a syntax defining (legal) terms. Allow reasoning by providing: Axioms defining equality on terms, and/or A semantics defining the meaning of terms accompanied by a semantic equivalence. Soundness/Completeness properties may relate the two approaches. Chair of Software Engineering 3 Example: Integer Calculus Syntax in (Enhanced) Backus-Naur Form. Digit ::= 0 | 1 | … |9 Integer ::= <Digit> | <Integer><Digit> Term ::= <Term> + <Integer> | <Term> - <Integer> | <Term> * <Integer> Equality is symmetric, transitive, reflexive. Operators can be associative, commutative, distributive. Allows axiomatic reasoning, by tautology. How to define “reasonable” equality? Chair of Software Engineering 4 Formalisms are Useful for… Understanding (precise definitions). Documentation. Static analysis: protocol verification, code optimization (e.g. partial evaluation), code validation. Code generation. Test case generation. Execution monitoring. Chair of Software Engineering 5 Functions and Functional Programming Mathematical function: taking (positional) parameters x1, x 2,..., xn , potentially calling other functions, returning a result. The result depends only on x1, x 2,..., xn. Calls with same parameters yield same result. A function defines an input-output relation. Functional programming: Functions are 1st-class entities, Extensional equivalence with termination. Programs are more concrete than functions! Chair of Software Engineering 6 Lambda-Calculus [Church 1934] Calculus of (sequential) functional programs. t :: x | x.t | t t Two constructions (operators): lambda-abstraction, function application. Infinite but enumerable set of variables. Lambda acts as a binding operator. The scope of a lambda abstraction extends as far to the right as possible. Chair of Software Engineering 7 Syntactical Aspects (1) 8 Occurrences of a variable under a lambda are bound. Other occurrences are free. bv( x ) fv( x ) {x} fv(t u) fv( x.t ) Chair of Software Engineering fv(t ) fv(u) fv(t ) \ {x} bv(t u ) bv (t ) bv(u ) bv( x.t ) bv(t ) {x} Syntactical Aspects (2) The substitution of x[t / x ] t x by y z[t / x ] in t is noted t[ y / x ] z if z x (u v )[t / x ] u[t / x ] v[t / x ] ( y. u )[t / x ] y. u[t / x ] Alpha-conversion (renaming) is defined as: x. t y. t[ y / x] y fv(t ) We shall assume from now that all terms are considered modulo alpha-conversion. Chair of Software Engineering 9 : Operational Semantics Given as a set of rewriting rules. Only 1 rule, Beta-reduction: ( x. t ) u t[u / x ] Defines a transition relation. Repeatedly convert and reduce a term to have its semantics * given by transitive closure. A reducible part of a term is called a redex. Functional application associates to the left. Values are non-reducible terms (terminated computations). Chair of Software Engineering 10 Encoding Booleans (1) true t. f . t false t. f . f true v w ( t. f . t ) v w ( f . v ) w v false v w ( t. f . f ) v w ( f . f ) w w Chair of Software Engineering 11 Encoding Booleans (2) not b. b false true and b. c. b c false Chair of Software Engineering or b. c. b true c if b. t. f . b t f 12 Encoding Pairs (or lists, records…) A pair encloses two items f and s . There exists two projection functions 1 and 2 . 1 pair f s * f and 2 pair f s * s . pair ( 1 p, 2 p) * p where p pair f s ? pair f . s. b. b f s 1 p. p true 2 p. p false Chair of Software Engineering 13 Encoding Naturals (1) A natural n just applies n times a given function s to an argument z 0 s. z. z 1 s. z. s z 2 s. z. s ( s z ) 3 s. z. s ( s ( s z )) Chair of Software Engineering 14 Encoding Naturals (2) Successor: succ Addition: add m. n. s. z. m s (n s z ) Multiplication: mult Zero test: is _ zero Chair of Software Engineering s. z.n. s (n s z ) m. n. m (add n) 0 n.t. f . n ( x. f ) t 15 What Can You Do? Reason exactly about naturals. Encode objects! (almost with what we have seen) Write any sequential program (Church-Turing) Haskell, ML, Lisp, Scheme, etc. Prove properties? Chair of Software Engineering 16 Imperative Programming 17 Problem: encoding a state. Similar to semantic function for lambda terms. Operational semantics: give a function from states to states. Repeat it as long as possible. Computation finished when: semantic function not applicable, or Function yields always the same state (fixpoint). The result is contained in variable Result. In practice: x. t becomes x. s. t ' where s associates variables to values. Chair of Software Engineering Example of State Encoding function fact (int n) is int result := 1; while n > 1 do result := result * n; n := n – 1; od; return result; end; function fact (int n) is return fact_rec (n, 1) function fact_rec (int n, int result) is if (n > 1) then return fact_rec (n - 1, n * result); else return result; end Chair of Software Engineering 18 Modeling Concurrency x := 1 y := 1 Cobegin x := y + 1 || y := x + 1 Coend The choice operator can be used for expansion: (x := y + 1 || y := x + 1) (x := y + 1; y := x + 1) (y := x + 1; x := y + 1) (z:= y + 1; y := x + 1; x := z) Chair of Software Engineering 19 Non-Determinism in Lambda t t' t u t' u u u' t u t u' t t' x. t x. t ' Chair of Software Engineering 20 Encoding Non-Determinism? It does not work! Because of one property named either diamond, Church-Rosser, or confluence. In short: the order of reductions does not matter. Chair of Software Engineering 21 Example 22 Although a lambda-term can have more than one redex: add (3, mult (2,6)) 3 mult (2,6) add (3,12) 15 One can hardly say this models concurrency! Chair of Software Engineering Calculi for Concurrency Have (internal) non-deterministic operators: CCS, CSP, Pi-Calculus, Ambients… Next Time! Chair of Software Engineering 23