1 Concurrent ObjectOriented Programming Arnaud Bailly Bertrand Meyer
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 , § potentially calling other functions, § returning a result. § The result depends only on. § Calls with same parameters yield same result. § A function defines an input-output relation. § Functional programming: § Functions are 1 st-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. § 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) § Occurrences of a variable under a lambda are bound. § Other occurrences are free. Chair of Software Engineering 8
Syntactical Aspects (2) § The substitution of by in is noted § Alpha-conversion (renaming) is defined as: § 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: § 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) Chair of Software Engineering 11
Encoding Booleans (2) Chair of Software Engineering 12
Encoding Pairs (or lists, records…) § A encloses two items and. § There exists two projection functions § and § where Chair of Software Engineering 13 and. ? .
Encoding Naturals (1) A natural Chair of Software Engineering just applies times a given function to an argument 14
Encoding Naturals (2) Chair of Software Engineering 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 § 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: becomes where associates variables to values. Chair of Software Engineering 17
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: Chair of Software Engineering 19
Non-Determinism in Lambda 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 § Although a lambda-term can have more than one redex: § One can hardly say this models concurrency! Chair of Software Engineering 22
Calculi for Concurrency § Have (internal) non-deterministic operators: § CCS, § CSP, § Pi-Calculus, § Ambients… § Next Time! Chair of Software Engineering 23
- Slides: 23