Typed First-order Logic

Size: px
Start display at page:

Download "Typed First-order Logic"

Transcription

1 22c181: Formal Methods in Software Engineering The University of Iowa Spring 2008 Typed First-order Logic Copyright Reiner Hähnle and Cesare Tinelli. Notes originally developed by Reiner Hähnle at Chalmers University and modified by Cesare Tinelli at the University of Iowa. These notes are copyrighted materials and may not be used in other course settings outside of the University of Iowa in their current form or modified form without the express written permission of one of the copyright holders. 22c181: Formal Methods in Software Engineering p.1/31

2 Contents Overview of KeY UML and its semantics Introduction to OCL Specifying requirements with OCL Modelling of Systems with Formal Semantics Propositional & First-order logic, sequent calculus OCL to Logic, horizontal proof obligations, using KeY Dynamic logic, proving program correctness Java Card DL Vertical proof obligations, using KeY Wrap-up, trends 22c181: Formal Methods in Software Engineering p.2/31

3 Propositional Logic is insufficient A ALL PERSONS ARE HAPPY 22c181: Formal Methods in Software Engineering p.3/31

4 Propositional Logic is insufficient A B ALL PERSONS ARE HAPPY PAT IS A PERSON 22c181: Formal Methods in Software Engineering p.3/31

5 Propositional Logic is insufficient A B? ALL PERSONS ARE HAPPY PAT IS A PERSON PAT IS HAPPY Propositional logic lacks possibility to talk about individuals In particular, need to model objects, attributes, associations, etc. 22c181: Formal Methods in Software Engineering p.3/31

6 Propositional Logic is insufficient A B? ALL PERSONS ARE HAPPY PAT IS A PERSON PAT IS HAPPY Propositional logic lacks possibility to talk about individuals In particular, need to model objects, attributes, associations, etc. First-Order Logic (FOL) with Types 22c181: Formal Methods in Software Engineering p.3/31

7 First-Order Logic First-Order Formulas I, = First-Order Models First-Order Sequent Calculus 22c181: Formal Methods in Software Engineering p.4/31

8 OO Type Hierarchy Finite set T of static types, subtype relation, Dynamic types T d T, where T d Abstract types T a T, where T a T d T a =, T d T a = T, z for all z T Object AbstractCollection List int AbstractList ArrayList Null 22c181: Formal Methods in Software Engineering p.5/31

9 Signature of Typed First-Order Logic Given type hierarchy (T, T d, T a, ), Signature Σ = (V, P, F, α) let T q := T \{ } 22c181: Formal Methods in Software Engineering p.6/31

10 Signature of Typed First-Order Logic Given type hierarchy (T, T d, T a, ), let T q := T \{ } Signature Σ = (V, P, F, α) Variable Symbols V = {x i i N} Predicate Symbols P = {p i i N} Function Symbols F = {f i i N} 22c181: Formal Methods in Software Engineering p.6/31

11 Signature of Typed First-Order Logic Given type hierarchy (T, T d, T a, ), Signature Σ = (V, P, F, α) Variable Symbols V = {x i i N} Predicate Symbols P = {p i i N} Function Symbols F = {f i i N} Typing function α for all symbols: α(x) T q for all x V We write x:z instead of α(x) = z let T q := T \{ } (in Java: z t; ) α(p) Tq for all p P We write p:z 1,...,z r intead of α(p) = (z 1,...,z r ) α(f) T q T q for all f F We write f:z 1,...,z r z instead of α(f) = ((z 1,...,z r ),z) r = 0 ok, No overloading of variables, functions, predicates! 22c181: Formal Methods in Software Engineering p.6/31

12 Special Signature Symbols An Equality symbol. = in P, with typing. = :, A type predicate symbol z in P for each z T q. with typing z : Type cast symbol (z) in F for each z T q, with typing (z) :, z 22c181: Formal Methods in Software Engineering p.7/31

13 First-Order Signature Example Sticks and stones may break your bones, but flowers will never hurt 22c181: Formal Methods in Software Engineering p.8/31

14 First-Order Signature Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates P = {hurts : Any} Functions F = {stick : Stick, stone : Stone, r : Flower} Function with empty argument list: constant 22c181: Formal Methods in Software Engineering p.8/31

15 First-Order Signature Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates P = {hurts : Any} Functions F = {stick : Stick, stone : Stone, r : Flower} Function with empty argument list: constant cf. KeY book p28 22c181: Formal Methods in Software Engineering p.8/31

16 Terms of First-Order Logic Given signature (V, P, F, α) Terms: Set Term z of terms of type z, one for each static type z T x is term of type z for each variable x : z f(t 1,...,t r ) is term of type z for each function symbol f : z 1,...,z r z and terms t i of type z i z i for 1 i r If f is constant (r = 0) we write f instead of f() 22c181: Formal Methods in Software Engineering p.9/31

17 Terms of First-Order Logic Given signature (V, P, F, α) Terms: Set Term z of terms of type z, one for each static type z T x is term of type z for each variable x : z f(t 1,...,t r ) is term of type z for each function symbol f : z 1,...,z r z and terms t i of type z i z i for 1 i r If f is constant (r = 0) we write f instead of f() Example: T d = {Car, Person, } where Person, Car F = {owner : Car Person, pat : Person, herbie : Car}, x : Car Terms: herbie, owner(herbie), owner((car)pat) (!), owner(x) Non-terms: Car, owner(pat), owner((person)herbie) 22c181: Formal Methods in Software Engineering p.9/31

18 Formulas of First-Order Logic First-Order Formulas: Set F or of (first-order) formulas p(t 1,...,t r ) is an atomic formula for predicate symbol p : z 1,...,z r and terms t i of type z i z i for 1 i r Truth constants, connectives as in propositional logic If x is any variable, φ a formula, then x.φ and x.φ are formulas We call φ the scope of variable x. We say that x is bound by the quantifier in x.φ (similarly for x.φ) 22c181: Formal Methods in Software Engineering p.10/31

19 Formulas of First-Order Logic First-Order Formulas: Set F or of (first-order) formulas p(t 1,...,t r ) is an atomic formula for predicate symbol p : z 1,...,z r and terms t i of type z i z i for 1 i r Truth constants, connectives as in propositional logic If x is any variable, φ a formula, then x.φ and x.φ are formulas We call φ the scope of variable x. We say that x is bound by the quantifier in x.φ (similarly for x.φ) Bound variables in quantified formulas are analogous to local variables/formal parameters in programs Use pathentheses and usual precedence rules to avoid syntactic ambiguity 22c181: Formal Methods in Software Engineering p.10/31

20 First-Order Syntax Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Functions Variables P = {hurts : Any} F = {stick : Stick, stone : Stone, r : Flower} V = {x : Weapon, y : Flower} Examples: 22c181: Formal Methods in Software Engineering p.11/31

21 First-Order Syntax Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Functions Variables P = {hurts : Any} F = {stick : Stick, stone : Stone, r : Flower} V = {x : Weapon, y : Flower} Examples: x.hurts(x) & y.!hurts(y) We sometimes write the type of quantified variables explicitly. 22c181: Formal Methods in Software Engineering p.11/31

22 First-Order Syntax Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Functions Variables P = {hurts : Any} F = {stick : Stick, stone : Stone, r : Flower} V = {x : Weapon, y : Flower} Examples: x : Weapon.hurts(x) & y : Flower.!hurts(y) 22c181: Formal Methods in Software Engineering p.11/31

23 First-Order Syntax Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Functions Variables P = {hurts : Any} F = {stick : Stick, stone : Stone, r : Flower} V = {x : Weapon, y : Flower} Examples: x : Weapon.hurts(x) & y : Flower.!hurts(y) hurts(r) -> y. hurts(y) 22c181: Formal Methods in Software Engineering p.11/31

24 Semantics of First-Order Logic First-Order Formulas I, = First-Order Models First-Order Sequent Calculus 22c181: Formal Methods in Software Engineering p.12/31

25 Semantics of First-Order Logic A model of FOL is a triple M = (D,δ, I) where D is the universe or domain Contains objects and values δ is a dynamic typing function δ : D T d Each domain element has dynamic ( runtime ) type I is an interpretation of the function and predicate symbols s.t. If p : z 1,...,z r P, then I(p) D z 1 D z r If f : z 1,...,z r z F, then I(f) : D z 1 D z r D z Moreover, let D z = {d D δ(d) z} (the domain elements of type z). The dynamic types z T d must be non-empty: D z 22c181: Formal Methods in Software Engineering p.13/31

26 Semantics of Special Symbols Equality symbol. = in P, with typing. =:, Semantics: I(. =) = {(d,d) d D} D D Referential Equality 22c181: Formal Methods in Software Engineering p.14/31

27 Semantics of Special Symbols Equality symbol =. in P, with typing =:., Semantics: I( =). = {(d,d) d D} D D Referential Equality Type predicate symbol z in P for each z T q, with typing z : Semantics: I( z ) = D z D 22c181: Formal Methods in Software Engineering p.14/31

28 Semantics of Special Symbols Equality symbol =. in P, with typing =:., Semantics: I( =). = {(d,d) d D} D D Referential Equality Type predicate symbol z in P for each z T q, with typing z : Semantics: I( z ) = D z D Type cast symbol (z) in F for each z T q, with typing (z) :, z Semantics: I((z)) is a function such that x if δ(x) z I((z))(x) = d otherwise with d an arbitrary but fixed element of D z 22c181: Formal Methods in Software Engineering p.14/31

29 Semantics of First-Order Logic: Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Functions P = {hurts : Any} F = {stick : Stick, stone : Stone, r : Flower} Variables V = {x : Weapon, y : Flower} One of (infinitely) many possible models: 22c181: Formal Methods in Software Engineering p.15/31

30 Semantics of First-Order Logic: Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Functions P = {hurts : Any} F = {stick : Stick, stone : Stone, r : Flower} Variables V = {x : Weapon, y : Flower} One of (infinitely) many possible models: Domain D = {o 1,o 2,o 3,o 4 } 22c181: Formal Methods in Software Engineering p.15/31

31 Semantics of First-Order Logic: Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Functions P = {hurts : Any} F = {stick : Stick, stone : Stone, r : Flower} Variables V = {x : Weapon, y : Flower} One of (infinitely) many possible models: Domain D = {o 1,o 2,o 3,o 4 } Typing δ(o 1 ) = δ(o 4 ) = Stick, δ(o 2 ) = Stone, δ(o 3 ) = Flower D Stick = {o 1,o 4 }, D Stone = {o 2 }, D Flower = {o 3 }, D Any = {o 1,o 2,o 3,o 4 } 22c181: Formal Methods in Software Engineering p.15/31

32 Semantics of First-Order Logic: Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Functions P = {hurts : Any} F = {stick : Stick, stone : Stone, r : Flower} Variables V = {x : Weapon, y : Flower} One of (infinitely) many possible models: Domain D = {o 1,o 2,o 3,o 4 } Typing δ(o 1 ) = δ(o 4 ) = Stick, δ(o 2 ) = Stone, δ(o 3 ) = Flower D Stick = {o 1,o 4 }, D Stone = {o 2 }, D Flower = {o 3 }, D Any = {o 1,o 2,o 3,o 4 } Interpretation I(hurts) = {o 1,o 2,o 4 } I(stick) = o 1, I(stone) = o 2, I(r) = o 3 22c181: Formal Methods in Software Engineering p.15/31

33 Semantics of First-Order Logic, Cont d Assigning meaning to variables Let x be variable of static type z A Variable Assignment β maps x to an element of D z 22c181: Formal Methods in Software Engineering p.16/31

34 Semantics of First-Order Logic, Cont d Assigning meaning to variables Let x be variable of static type z A Variable Assignment β maps x to an element of D z Assigning meaning to terms: a mapping val M,β from Term z (t) to D z (dependind on model M and variable assignment β) such that val M,β (x) = β(x) (element in D z, where x has type z) val M,β (f(t 1,...,t r )) = I(f)(val M,β (t 1 ),...,val M,β (t r )) 22c181: Formal Methods in Software Engineering p.16/31

35 Semantics of First-Order Logic, Cont d Assigning meaning to variables Let x be variable of static type z A Variable Assignment β maps x to an element of D z Assigning meaning to terms: a mapping val M,β from Term z (t) to D z (dependind on model M and variable assignment β) such that val M,β (x) = β(x) (element in D z, where x has type z) val M,β (f(t 1,...,t r )) = I(f)(val M,β (t 1 ),...,val M,β (t r )) Modified variable assignment: β(x) For d D z let βy(x) d if x y := d if x = y 22c181: Formal Methods in Software Engineering p.16/31

36 Semantics of First-Order Logic, Cont d Assigning meaning to formulas Validity relation: M,β = φ for φ For M,β = p(t 1,...,t r ) iff (val M,β (t 1 ),...,val M,β (t r )) I(p) M,β = φ &ψ iff M,β = φ and M,β = ψ... M,β = x.φ iff M,β d x = φ for all d D z where the type of x is z M,β = x.φ iff M,β d x = φ for at least one d D z where the type of x is z 22c181: Formal Methods in Software Engineering p.17/31

37 Semantics of First-Order Logic: Example Sticks and stones may break your bones, but flowers will never hurt Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Functions Variables P = {hurts : Any} F = {stick : Stick, stone : Stone, r : Flower} V = {x : Weapon, y : Flower} In our previous model M: D Stick = {o 1,o 4 }, D Stone = {o 2 }, D Flower = {o 3 } D Weapon = {o 1,o 2,o 4 }, I(hurts) = {o 1,o 2,o 4 } D Any Evaluate these formulas: x.hurts(x), x.hurts(x), y. hurts(y) 22c181: Formal Methods in Software Engineering p.18/31

38 Semantics of First-Order Logic: Evaluation Example Let β be arbitrary. M,β = x : Weapon.hurts(x) iff Semantic Rule Information from model (D, δ, I) 22c181: Formal Methods in Software Engineering p.19/31

39 Semantics of First-Order Logic: Evaluation Example Let β be arbitrary. M,β = x : Weapon.hurts(x) iff There exists d D Weapon such that M,β d x = hurts(x) if Semantic Rule M,β = x.φ iff M,β d x = φ for at least one d D z where the type of x is z Information from model (D, δ, I) 22c181: Formal Methods in Software Engineering p.19/31

40 Semantics of First-Order Logic: Evaluation Example Let β be arbitrary. M,β = x : Weapon.hurts(x) iff There exists d D Weapon such that M,β d x = hurts(x) if M,β o 1 x = hurts(x) iff Semantic Rule Information from model (D, δ, I) D Weapon = {o 1,o 2,o 4 } 22c181: Formal Methods in Software Engineering p.19/31

41 Semantics of First-Order Logic: Evaluation Example Let β be arbitrary. M,β = x : Weapon.hurts(x) iff There exists d D Weapon such that M,β d x = hurts(x) if M,β o 1 x = hurts(x) val M,β o 1 x (x) I(hurts) iff Semantic Rule M,β = p(t 1,...,t r ) iff (val M,β (t 1 ),...,val M,β (t r )) I(p) Information from model (D, δ, I) 22c181: Formal Methods in Software Engineering p.19/31

42 Semantics of First-Order Logic: Evaluation Example Let β be arbitrary. M,β = x : Weapon.hurts(x) iff There exists d D Weapon such that M,β d x = hurts(x) if M,β o 1 x = hurts(x) val M,β o 1 x (x) I(hurts) iff since val M,β o 1 x (x) = βo 1 x (x) = o 1 iff Semantic Rule val M,β (x) = β(x), β d y(x) := β(x) x y d x = y Information from model (D, δ, I) 22c181: Formal Methods in Software Engineering p.19/31

43 Semantics of First-Order Logic: Evaluation Example Let β be arbitrary. M,β = x : Weapon.hurts(x) iff There exists d D Weapon such that M,β d x = hurts(x) if M,β o 1 x = hurts(x) val M,β o 1 x (x) I(hurts) iff since val o (x) = M,β 1 βo 1 x x (x) = o 1 o 1 I(hurts) = {o 1,o 2,o 4 } iff Semantic Rule Information from model (D, δ, I) I(hurts) = {o 1,o 2,o 4 } 22c181: Formal Methods in Software Engineering p.19/31

44 Semantics of First-Order Logic: Evaluation Example Let β be arbitrary. M,β = x : Weapon.hurts(x) iff There exists d D Weapon such that M,β d x = hurts(x) if M,β o 1 x = hurts(x) val M,β o 1 x (x) I(hurts) iff since val o (x) = M,β 1 βo 1 x x (x) = o 1 o 1 I(hurts) = {o 1,o 2,o 4 } ok! iff Semantic Rule Information from model (D, δ, I) 22c181: Formal Methods in Software Engineering p.19/31

45 First-Order Semantic Notions Satisfiability, truth, and validity M,β = φ (φ is satisfiable) M = φ iff for all β : M,β = φ (φ is true in M) = φ iff for all M : M = φ (φ is valid) Formula containing only variables in scope of a quantifier is closed Closed formulas that are satisfiable are also true: only one notion From now on only closed formulas are considered. 22c181: Formal Methods in Software Engineering p.20/31

46 First-Order Logic Example Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Variables P = {hurts : Any} V = {x : Weapon, y : Flower} 22c181: Formal Methods in Software Engineering p.21/31

47 First-Order Logic Example Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Variables P = {hurts : Any} V = {x : Weapon, y : Flower} x : Weapon.hurts(x) & y : Flower.!hurts(y) Satisfiable? True? Valid? 22c181: Formal Methods in Software Engineering p.21/31

48 First-Order Logic Example Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Variables P = {hurts : Any} V = {x : Weapon, y : Flower} x : Weapon.hurts(x) & y : Flower.!hurts(y) Satisfiable? True? Valid? Model: D = {o 1, o 2 }, δ(o 1 ) = Stone, δ(o 2 ) = Flower I(hurts) = {o 1 } 22c181: Formal Methods in Software Engineering p.21/31

49 First-Order Logic Example Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Variables P = {hurts : Any} V = {x : Weapon, y : Flower} x : Weapon.hurts(x) & y : Flower.!hurts(y) Satisfiable? True? Valid? Counter-model: D = {o 1, o 2 }, δ(o 1 ) = Stone, δ(o 2 ) = Flower I(hurts) = {} 22c181: Formal Methods in Software Engineering p.21/31

50 First-Order Logic Example Types T d = {Stick, Stone, Flower}, T a = {Weapon, Any} Stick, Stone Weapon Any, Flower Any Predicates Variables P = {hurts : Any} V = {x : Weapon, y : Flower} x : Weapon.hurts(x) & y : Flower.!hurts(y) Satisfiable? True? Valid? Another Counter-model: D = {o 1, o 2,o 3 }, δ(o 1 ) = Stone, δ(o 2 ) = δ(o 3 ) = Flower I(hurts) = {o 1,o 3 } 22c181: Formal Methods in Software Engineering p.21/31

51 Untyped First-Order Logic Standard FOL (as in most logic textbooks is untyped [single typed]) Obtained as special case of typed signature: T d = { }, T a = { } Hence, D = D, δ(d) = for all d D All variables, predicate and function symbols declared on Don t need type information of variables (omit) Only arity in signature of function/predicate symbols matters 22c181: Formal Methods in Software Engineering p.22/31

52 Untyped First-Order Logic Standard FOL (as in most logic textbooks is untyped [single typed]) Obtained as special case of typed signature: T d = { }, T a = { } Hence, D = D, δ(d) = for all d D All variables, predicate and function symbols declared on Don t need type information of variables (omit) Only arity in signature of function/predicate symbols matters Example: P = {person/1, happy/1}, F = {pat/0} 22c181: Formal Methods in Software Engineering p.22/31

53 Untyped First-Order Logic Standard FOL (as in most logic textbooks is untyped [single typed]) Obtained as special case of typed signature: T d = { }, T a = { } Hence, D = D, δ(d) = for all d D All variables, predicate and function symbols declared on Don t need type information of variables (omit) Only arity in signature of function/predicate symbols matters Example: P = {person/1, happy/1}, F = {pat/0} x.(person(x) -> happy(x)) ALL PERSONS ARE HAPPY 22c181: Formal Methods in Software Engineering p.22/31

54 Untyped First-Order Logic Standard FOL (as in most logic textbooks is untyped [single typed]) Obtained as special case of typed signature: T d = { }, T a = { } Hence, D = D, δ(d) = for all d D All variables, predicate and function symbols declared on Don t need type information of variables (omit) Only arity in signature of function/predicate symbols matters Example: P = {person/1, happy/1}, F = {pat/0} x.(person(x) -> happy(x)) person(pat) ALL PERSONS ARE HAPPY PAT IS A PERSON 22c181: Formal Methods in Software Engineering p.22/31

55 Untyped First-Order Logic Standard FOL (as in most logic textbooks is untyped [single typed]) Obtained as special case of typed signature: T d = { }, T a = { } Hence, D = D, δ(d) = for all d D All variables, predicate and function symbols declared on Don t need type information of variables (omit) Only arity in signature of function/predicate symbols matters Example: P = {person/1, happy/1}, F = {pat/0} x.(person(x) -> happy(x)) person(pat) happy(pat) ALL PERSONS ARE HAPPY PAT IS A PERSON PAT IS HAPPY 22c181: Formal Methods in Software Engineering p.22/31

56 Types and Symbols with Fixed Interpretation Certain symbols should have standard meaning in all interpretations So far:. =, z, (z) For certain types we also fix domain and dynamic typing: D int = {d D δ(d) = int} = These types appear between and, uncomparable to others Examples of types, function/predicate symbols with fixed meaning I(17) should be always 17, not e.g. towel int KeY can switch between JAVA 32-bit integers and but in FOL always math integers I(+) = +, I( * ) =,... boolean 22c181: Formal Methods in Software Engineering p.23/31

57 Some Predefined Symbols in KeY FO Logic Types int, short, byte, boolean with standard meaning All classes of current UML context diagram and Null If T is one of these types then also Set(T), Bag(T), Sequence(T) Predicates on integer types with standard meaning >, <, >=, <=,... (infix) Functions and Constants with standard meaning +, -, div, mod, 0, 1,... TRUE, FALSE Notation for quantifiers, variables declared at quantifier symbol \forall Type Variable; ScopeFormula 22c181: Formal Methods in Software Engineering p.24/31

58 First-Order Problems in KeY Syntax:.key \sorts { // types are called sorts person; // one declaration per line, end with ; } \functions { // ResultType FctSymbol(ParType,..,ParType) int age(person); // int predefined type } \predicates { // PredSymbol(ParType,..,ParType) parent(person,person); } \problem { // Goal formula \forall person son; \forall person father; (parent(father,son) -> age(father) > age(son)) } 22c181: Formal Methods in Software Engineering p.25/31

59 Contents Overview of KeY UML and its semantics Introduction to OCL Specifying requirements with OCL Modelling of Systems with Formal Semantics Propositional & First-order logic, sequent calculus OCL to Logic, horizontal proof obligations, using KeY Dynamic logic, proving program correctness Java Card DL Vertical proof obligations, using KeY Wrap-up, trends 22c181: Formal Methods in Software Engineering p.26/31

60 Sequent Calculus for FOL left side, antecedent right side, succedent [t/t ]φ is result of replacing each occurrence of t in φ with t s z,t z and t are arbitrary variable free terms x and s z have static type z and t z has static type z z c z new constant of type z (does not occur in current proof branch) Equations can be reversed (by symmetry of equality) 22c181: Formal Methods in Software Engineering p.27/31

61 Sequent Calculus for FOL left side, antecedent Γ, x.φ, h x/t z i φ ==> Γ, x.φ ==> right side, succedent Γ ==> [x/c z ]φ, Γ ==> x.φ, [t/t ]φ is result of replacing each occurrence of t in φ with t s z,t z and t are arbitrary variable free terms x and s z have static type z and t z has static type z z c z new constant of type z (does not occur in current proof branch) Equations can be reversed (by symmetry of equality) 22c181: Formal Methods in Software Engineering p.27/31

62 Sequent Calculus for FOL left side, antecedent Γ, x.φ, h x/t z i φ ==> Γ, x.φ ==> Γ, [x/c z ]φ ==> Γ, x.φ ==> right side, succedent Γ ==> [x/c z ]φ, Γ ==> x.φ, Γ ==> h x/t z i φ, x.φ, Γ ==> x.φ, [t/t ]φ is result of replacing each occurrence of t in φ with t s z,t z and t are arbitrary variable free terms x and s z have static type z and t z has static type z z c z new constant of type z (does not occur in current proof branch) Equations can be reversed (by symmetry of equality) 22c181: Formal Methods in Software Engineering p.27/31

63 Sequent Calculus for FOL left side, antecedent Γ, x.φ, h x/t z i φ ==> Γ, x.φ ==> Γ, [x/c z ]φ ==> Γ, x.φ ==> h.. = Γ,sz = t z, s z /t z i ψ ==> Γ,s z. = t z,ψ ==> φ, h s z /t z i φ, right side, succedent Γ ==> [x/c z ]φ, Γ ==> x.φ, Γ ==> h x/t z i φ, x.φ, Γ ==> x.φ, Γ ==> t. = t, [t/t ]φ is result of replacing each occurrence of t in φ with t s z,t z and t are arbitrary variable free terms x and s z have static type z and t z has static type z z c z new constant of type z (does not occur in current proof branch) Equations can be reversed (by symmetry of equality) 22c181: Formal Methods in Software Engineering p.27/31

64 A Simple Proof (Exercises p3.key) x. y.p(x,y) ==> y. x.p(x,y) Let static type of x and y be 22c181: Formal Methods in Software Engineering p.28/31

65 A Simple Proof (Exercises p3.key) y.p(c,y) ==> y. x.p(x,y) x. y.p(x,y) ==> y. x.p(x,y) ex left: substitute new constant c of type for x 22c181: Formal Methods in Software Engineering p.28/31

66 A Simple Proof (Exercises p3.key) y.p(c,y) ==> x.p(x,d) y.p(c,y) ==> y. x.p(x,y) x. y.p(x,y) ==> y. x.p(x,y) all right: substitute new constant d of type for y 22c181: Formal Methods in Software Engineering p.28/31

67 A Simple Proof (Exercises p3.key) p(c,d), y.p(c,y) ==> x.p(x,d) y.p(c,y) ==> x.p(x,d) y.p(c,y) ==> y. x.p(x,y) x. y.p(x,y) ==> y. x.p(x,y) all left: free to substitute any term of type for y, choose d 22c181: Formal Methods in Software Engineering p.28/31

68 A Simple Proof (Exercises p3.key) p(c,d) ==> x.p(x,d) y.p(c,y) ==> x.p(x,d) y.p(c,y) ==> y. x.p(x,y) x. y.p(x,y) ==> y. x.p(x,y) all left not needed anymore (hide) 22c181: Formal Methods in Software Engineering p.28/31

69 A Simple Proof (Exercises p3.key) p(c,d) p(c,d) ==> p(c,d), x.p(x,y) ==> x.p(x,d) y.p(c,y) ==> x.p(x,d) y.p(c,y) ==> y. x.p(x,y) x. y.p(x,y) ==> y. x.p(x,y) ex right: free to substitute any term of type for x, choose c 22c181: Formal Methods in Software Engineering p.28/31

70 A Simple Proof (Exercises p3.key) p(c, d) ==> p(c, d) p(c,d) ==> x.p(x,d) y.p(c,y) ==> x.p(x,d) y.p(c,y) ==> y. x.p(x,y) x. y.p(x,y) ==> y. x.p(x,y) ex right not needed anymore (hide) 22c181: Formal Methods in Software Engineering p.28/31

71 A Simple Proof (Exercises p3.key) p(c, d) ==> p(c, d) p(c,d) ==> x.p(x,d) y.p(c,y) ==> x.p(x,d) y.p(c,y) ==> y. x.p(x,y) x. y.p(x,y) ==> y. x.p(x,y) Close 22c181: Formal Methods in Software Engineering p.28/31

72 Rules for Type Casts and Type Predicates Type predicate formulas t z true iff dynamic type val M (t) is subtype of z Type cast terms (z)t evaluates to val M (t) if cast succeeds, arb. element otherwise 22c181: Formal Methods in Software Engineering p.29/31

73 Rules for Type Casts and Type Predicates Type predicate formulas t z true iff dynamic type val M (t) is subtype of z Type cast terms (z)t evaluates to val M (t) if cast succeeds, arb. element otherwise Typical rule: 22c181: Formal Methods in Software Engineering p.29/31

74 Rules for Type Casts and Type Predicates Type predicate formulas t z true iff dynamic type val M (t) is subtype of z Type cast terms (z)t evaluates to val M (t) if cast succeeds, arb. element otherwise Typical rule: The dynamic type of a term must be typeable to its static type TYPESTATIC Γ, t z ==> Γ ==> z static (declared) type of t Expresses type-safety of typed first-order logic 22c181: Formal Methods in Software Engineering p.29/31

75 Rules for Type Casts and Type Predicates Type predicate formulas t z true iff dynamic type val M (t) is subtype of z Type cast terms (z)t evaluates to val M (t) if cast succeeds, arb. element otherwise Typical rule: The dynamic type of a term must be typeable to its static type TYPESTATIC Γ, t z ==> Γ ==> z static (declared) type of t Expresses type-safety of typed first-order logic KeY first-order strategy applies suitable typing rules automatically 22c181: Formal Methods in Software Engineering p.29/31

76 Sequent Proofs: Important Issues Rules are applied to top-most connective/quantifier exleft and allright substitute new constant exright and allleft allow to substitute any variable-free term Formulas that are not needed in remaining proof may be hidden All branches must be closed with axiom There are many different possible proofs for a valid sequent KeY FO strategy applies all but exright and allleft automatically 22c181: Formal Methods in Software Engineering p.30/31

77 Another Proof Example Types T = {, } Predicates PSym = {p}, p :, Functions FSym = {} ( x. y.p(x,y) & x.!p(x,x)) -> x. y.(!x =. y) Intuitive Meaning? Satisfiable? True? Valid? oclfol/rel.key Demo 22c181: Formal Methods in Software Engineering p.31/31

15-819M: Data, Code, Decisions

15-819M: Data, Code, Decisions 15-819M: Data, Code, Decisions 08: First-Order Logic André Platzer aplatzer@cs.cmu.edu Carnegie Mellon University, Pittsburgh, PA André Platzer (CMU) 15-819M/08: Data, Code, Decisions 1 / 40 Outline 1

More information

From OCL to Typed First-order Logic

From OCL to Typed First-order Logic 22c181: Formal Methods in Software Engineering The University of Iowa Spring 2008 From OCL to Typed First-order Logic Copyright 2007-8 Reiner Hähnle and Cesare Tinelli. Notes originally developed by Reiner

More information

From OCL to Propositional and First-order Logic: Part I

From OCL to Propositional and First-order Logic: Part I 22c181: Formal Methods in Software Engineering The University of Iowa Spring 2008 From OCL to Propositional and First-order Logic: Part I Copyright 2007-8 Reiner Hähnle and Cesare Tinelli. Notes originally

More information

Fundamentals of Software Engineering

Fundamentals of Software Engineering Fundamentals of Software Engineering Reasoning about Programs with Dynamic Logic - Part I Ina Schaefer Institute for Software Systems Engineering TU Braunschweig, Germany Slides by Wolfgang Ahrendt, Richard

More information

Chapter 2 (First-Order Logic) of. Verification of Object-Oriented Software

Chapter 2 (First-Order Logic) of. Verification of Object-Oriented Software Chapter 2 (First-Order Logic) of Verification of Object-Oriented Software The KeY approach c 2007 Springer Verlag 1 First-Order Logic by Martin Giese In this chapter, we introduce a first-order logic.

More information

Automated Reasoning. Natural Deduction in First-Order Logic

Automated Reasoning. Natural Deduction in First-Order Logic Automated Reasoning Natural Deduction in First-Order Logic Jacques Fleuriot Automated Reasoning Lecture 4, page 1 Problem Consider the following problem: Every person has a heart. George Bush is a person.

More information

Overview of the KeY System

Overview of the KeY System 22c181: Formal Methods in Software Engineering The University of Iowa Spring 2008 Overview of the KeY System Copyright 2007-8 Reiner Hähnle and Cesare Tinelli. Notes originally developed by Reiner Hähnle

More information

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27

CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer Science (Arkoudas and Musser) Chapter 2.1-2.7 p. 1/27 CSCI.6962/4962 Software Verification Fundamental Proof Methods in Computer

More information

A Short Introduction to First-Order Theorem Proving with KeY

A Short Introduction to First-Order Theorem Proving with KeY 1 What is KeY? 1.1 Software Verification Karlsruher Institut für Technologie Institut für Theoretische Informatik Prof. Dr. Peter H. Schmitt Mattias Ulbrich A Short Introduction to First-Order Theorem

More information

The Typed λ Calculus and Type Inferencing in ML

The Typed λ Calculus and Type Inferencing in ML Notes on Types S. Arun-Kumar Department of Computer Science and Engineering Indian Institute of Technology New Delhi, 110016 email: sak@cse.iitd.ernet.in April 14, 2002 2 Chapter 1 The Typed λ Calculus

More information

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic.

Overview. CS389L: Automated Logical Reasoning. Lecture 6: First Order Logic Syntax and Semantics. Constants in First-Order Logic. Overview CS389L: Automated Logical Reasoning Lecture 6: First Order Logic Syntax and Semantics Işıl Dillig So far: Automated reasoning in propositional logic. Propositional logic is simple and easy to

More information

Towards a Logical Reconstruction of Relational Database Theory

Towards a Logical Reconstruction of Relational Database Theory Towards a Logical Reconstruction of Relational Database Theory On Conceptual Modelling, Lecture Notes in Computer Science. 1984 Raymond Reiter Summary by C. Rey November 27, 2008-1 / 63 Foreword DB: 2

More information

COS 320. Compiling Techniques

COS 320. Compiling Techniques Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly

More information

Fundamentals of Software Engineering

Fundamentals of Software Engineering Fundamentals of Software Engineering Reasoning about Programs with Dynamic Logic - Part II Ina Schaefer Institute for Software Systems Engineering TU Braunschweig, Germany Slides by Wolfgang Ahrendt, Richard

More information

Fundamentals of Software Engineering

Fundamentals of Software Engineering Fundamentals of Software Engineering Reasoning about Programs with Dynamic Logic - Part II Ina Schaefer Institute for Software Systems Engineering TU Braunschweig, Germany Slides by Wolfgang Ahrendt, Richard

More information

CS 512, Spring 2017: Take-Home End-of-Term Examination

CS 512, Spring 2017: Take-Home End-of-Term Examination CS 512, Spring 2017: Take-Home End-of-Term Examination Out: Tuesday, 9 May 2017, 12:00 noon Due: Wednesday, 10 May 2017, by 11:59 am Turn in your solutions electronically, as a single PDF file, by placing

More information

Software Engineering using Formal Methods

Software Engineering using Formal Methods Software Engineering using Formal Methods Reasoning about Programs with Dynamic Logic Wolfgang Ahrendt & Richard Bubel & Wojciech Mostowski 5 October 2011 SEFM: Java DL /GU 111005 1 / 45 Dynamic Logic

More information

Fall Lecture 3 September 4. Stephen Brookes

Fall Lecture 3 September 4. Stephen Brookes 15-150 Fall 2018 Lecture 3 September 4 Stephen Brookes Today A brief remark about equality types Using patterns Specifying what a function does equality in ML e1 = e2 Only for expressions whose type is

More information

Semantics and Pragmatics of NLP Propositional Logic, Predicates and Functions

Semantics and Pragmatics of NLP Propositional Logic, Predicates and Functions , Semantics and Pragmatics of NLP, and s Alex Ewan School of Informatics University of Edinburgh 10 January 2008 , 1 2 3 4 Why Bother?, Aim: 1 To associate NL expressions with semantic representations;

More information

Programming Languages Third Edition

Programming Languages Third Edition Programming Languages Third Edition Chapter 12 Formal Semantics Objectives Become familiar with a sample small language for the purpose of semantic specification Understand operational semantics Understand

More information

Typed Lambda Calculus for Syntacticians

Typed Lambda Calculus for Syntacticians Department of Linguistics Ohio State University January 12, 2012 The Two Sides of Typed Lambda Calculus A typed lambda calculus (TLC) can be viewed in two complementary ways: model-theoretically, as a

More information

A First-Order Logic with First-Class Types

A First-Order Logic with First-Class Types A First-Order Logic with First-Class Types joint work with Peter H. Schmitt and Mattias Ulbrich Institute for Theoretical Computer Science The 8th KeY Symposium, Speyer, 2009 Java Card DL modal logic based

More information

Formal Systems II: Applications

Formal Systems II: Applications Formal Systems II: Applications Functional Verification of Java Programs: Java Dynamic Logic Bernhard Beckert Mattias Ulbrich SS 2017 KIT INSTITUT FÜR THEORETISCHE INFORMATIK KIT University of the State

More information

Fundamentals of Software Engineering

Fundamentals of Software Engineering Fundamentals of Software Engineering Reasoning about Programs - Selected Features Ina Schaefer Institute for Software Systems Engineering TU Braunschweig, Germany Slides by Wolfgang Ahrendt, Richard Bubel,

More information

Typed Lambda Calculus

Typed Lambda Calculus Department of Linguistics Ohio State University Sept. 8, 2016 The Two Sides of A typed lambda calculus (TLC) can be viewed in two complementary ways: model-theoretically, as a system of notation for functions

More information

Formal Predicate Calculus. Michael Meyling

Formal Predicate Calculus. Michael Meyling Formal Predicate Calculus Michael Meyling May 24, 2013 2 The source for this document can be found here: http://www.qedeq.org/0_04_07/doc/math/qedeq_formal_logic_v1.xml Copyright by the authors. All rights

More information

Propositional Logic. Part I

Propositional Logic. Part I Part I Propositional Logic 1 Classical Logic and the Material Conditional 1.1 Introduction 1.1.1 The first purpose of this chapter is to review classical propositional logic, including semantic tableaux.

More information

Formal Systems and their Applications

Formal Systems and their Applications Formal Systems and their Applications Dave Clarke (Dave.Clarke@cs.kuleuven.be) Acknowledgment: these slides are based in part on slides from Benjamin Pierce and Frank Piessens 1 Course Overview Introduction

More information

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS

This is already grossly inconvenient in present formalisms. Why do we want to make this convenient? GENERAL GOALS 1 THE FORMALIZATION OF MATHEMATICS by Harvey M. Friedman Ohio State University Department of Mathematics friedman@math.ohio-state.edu www.math.ohio-state.edu/~friedman/ May 21, 1997 Can mathematics be

More information

CSC 501 Semantics of Programming Languages

CSC 501 Semantics of Programming Languages CSC 501 Semantics of Programming Languages Subtitle: An Introduction to Formal Methods. Instructor: Dr. Lutz Hamel Email: hamel@cs.uri.edu Office: Tyler, Rm 251 Books There are no required books in this

More information

Formal Specification and Verification

Formal Specification and Verification Formal Specification and Verification Introduction to Promela Bernhard Beckert Based on a lecture by Wolfgang Ahrendt and Reiner Hähnle at Chalmers University, Göteborg Formal Specification and Verification:

More information

COMBINING PARTIAL EVALUATION AND SYMBOLIC EXECUTION

COMBINING PARTIAL EVALUATION AND SYMBOLIC EXECUTION COMBINING PARTIAL EVALUATION AND SYMBOLIC EXECUTION Reiner Hähnle & Richard Bubel Chalmers University Symposium 09 Speyer CONTROL CIRCUIT y = 80; threshold = 100; if (y > threshold) { decrease = true;

More information

Handling Integer Arithmetic in the Verification of Java Programs

Handling Integer Arithmetic in the Verification of Java Programs Handling Integer Arithmetic in the Verification of Java Programs Steffen Schlager 1st Swedish-German KeY Workshop Göteborg, Sweden, June 2002 KeY workshop, June 2002 p.1 Introduction UML/OCL specification

More information

Going beyond propositional logic

Going beyond propositional logic Going beyond propositional logic Consider the following statements: p: Ling took CS245 q: Ling passed CS245 r: Ling failed CS245 Taken literally, these are all atomic statements, and formally they have

More information

Formal Specification and Verification

Formal Specification and Verification Formal Specification and Verification Proof Obligations Bernhard Beckert Based on a lecture by Wolfgang Ahrendt and Reiner Hähnle at Chalmers University, Göteborg Formal Specification and Verification:

More information

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics

CMSC 330: Organization of Programming Languages. Formal Semantics of a Prog. Lang. Specifying Syntax, Semantics Recall Architecture of Compilers, Interpreters CMSC 330: Organization of Programming Languages Source Scanner Parser Static Analyzer Operational Semantics Intermediate Representation Front End Back End

More information

Verifying Safety Property of Lustre Programs: Temporal Induction

Verifying Safety Property of Lustre Programs: Temporal Induction 22c181: Formal Methods in Software Engineering The University of Iowa Spring 2008 Verifying Safety Property of Lustre Programs: Temporal Induction Copyright 2008 Cesare Tinelli. These notes are copyrighted

More information

Application: Programming Language Semantics

Application: Programming Language Semantics Chapter 8 Application: Programming Language Semantics Prof. Dr. K. Madlener: Specification and Verification in Higher Order Logic 527 Introduction to Programming Language Semantics Programming Language

More information

RSL Reference Manual

RSL Reference Manual RSL Reference Manual Part No.: Date: April 6, 1990 Original Authors: Klaus Havelund, Anne Haxthausen Copyright c 1990 Computer Resources International A/S This document is issued on a restricted basis

More information

Basic Foundations of Isabelle/HOL

Basic Foundations of Isabelle/HOL Basic Foundations of Isabelle/HOL Peter Wullinger May 16th 2007 1 / 29 1 Introduction into Isabelle s HOL Why Type Theory Basic Type Syntax 2 More HOL Typed λ Calculus HOL Rules 3 Example proof 2 / 29

More information

Propositional Logic Formal Syntax and Semantics. Computability and Logic

Propositional Logic Formal Syntax and Semantics. Computability and Logic Propositional Logic Formal Syntax and Semantics Computability and Logic Syntax and Semantics Syntax: The study of how expressions are structured (think: grammar) Semantics: The study of the relationship

More information

Semantics and Pragmatics of NLP

Semantics and Pragmatics of NLP Semantics and Pragmatics of NLP Alex Ewan School of Informatics University of Edinburgh 10 January 2008 1 2 3 Transitive Verbs as Functions We looked at replacing n-ary relations with functions. How does

More information

1.3. Conditional expressions To express case distinctions like

1.3. Conditional expressions To express case distinctions like Introduction Much of the theory developed in the underlying course Logic II can be implemented in a proof assistant. In the present setting this is interesting, since we can then machine extract from a

More information

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur

Module 6. Knowledge Representation and Logic (First Order Logic) Version 2 CSE IIT, Kharagpur Module 6 Knowledge Representation and Logic (First Order Logic) 6.1 Instructional Objective Students should understand the advantages of first order logic as a knowledge representation language Students

More information

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS What is discrete? Sets (Rosen, Chapter 2) TOPICS Discrete math Set Definition Set Operations Tuples Consisting of distinct or unconnected elements, not continuous (calculus) Helps us in Computer Science

More information

3.7 Denotational Semantics

3.7 Denotational Semantics 3.7 Denotational Semantics Denotational semantics, also known as fixed-point semantics, associates to each programming language construct a well-defined and rigorously understood mathematical object. These

More information

Higher-Order Logic. Specification and Verification with Higher-Order Logic

Higher-Order Logic. Specification and Verification with Higher-Order Logic Higher-Order Logic Specification and Verification with Higher-Order Logic Arnd Poetzsch-Heffter (Slides by Jens Brandt) Software Technology Group Fachbereich Informatik Technische Universität Kaiserslautern

More information

(Not Quite) Minijava

(Not Quite) Minijava (Not Quite) Minijava CMCS22620, Spring 2004 April 5, 2004 1 Syntax program mainclass classdecl mainclass class identifier { public static void main ( String [] identifier ) block } classdecl class identifier

More information

Lecture 3: Recursion; Structural Induction

Lecture 3: Recursion; Structural Induction 15-150 Lecture 3: Recursion; Structural Induction Lecture by Dan Licata January 24, 2012 Today, we are going to talk about one of the most important ideas in functional programming, structural recursion

More information

Software Engineering using Formal Methods

Software Engineering using Formal Methods Software Engineering using Formal Methods Introduction to Promela Wolfgang Ahrendt & Richard Bubel & Reiner Hähnle & Wojciech Mostowski 31 August 2011 SEFM: Promela /GU 110831 1 / 35 Towards Model Checking

More information

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy

Polymorphic lambda calculus Princ. of Progr. Languages (and Extended ) The University of Birmingham. c Uday Reddy 06-02552 Princ. of Progr. Languages (and Extended ) The University of Birmingham Spring Semester 2016-17 School of Computer Science c Uday Reddy2016-17 Handout 6: Polymorphic Type Systems 1. Polymorphic

More information

Introduction to System F. Lecture 18 CS 565 4/20/09

Introduction to System F. Lecture 18 CS 565 4/20/09 Introduction to System F Lecture 18 CS 565 4/20/09 The Limitations of F 1 (simply-typed λ- calculus) In F 1 each function works exactly for one type Example: the identity function id = λx:τ. x : τ τ We

More information

Lee Pike. June 3, 2005

Lee Pike. June 3, 2005 Proof NASA Langley Formal Methods Group lee.s.pike@nasa.gov June 3, 2005 Proof Proof Quantification Quantified formulas are declared by quantifying free variables in the formula. For example, lem1: LEMMA

More information

Situation Calculus and YAGI

Situation Calculus and YAGI Situation Calculus and YAGI Institute for Software Technology 1 Progression another solution to the projection problem does a sentence hold for a future situation used for automated reasoning and planning

More information

First-Order Logic PREDICATE LOGIC. Syntax. Terms

First-Order Logic PREDICATE LOGIC. Syntax. Terms First-Order Logic PREDICATE LOGIC Aim of this lecture: to introduce first-order predicate logic. More expressive than propositional logic. Consider the following argument: all monitors are ready; X12 is

More information

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc.

CSC312 Principles of Programming Languages : Functional Programming Language. Copyright 2006 The McGraw-Hill Companies, Inc. CSC312 Principles of Programming Languages : Functional Programming Language Overview of Functional Languages They emerged in the 1960 s with Lisp Functional programming mirrors mathematical functions:

More information

Semantic Subtyping with an SMT Solver

Semantic Subtyping with an SMT Solver Semantic Subtyping with an SMT Solver Cătălin Hrițcu, Saarland University, Saarbrücken, Germany Joint work with Andy Gordon, Gavin Bierman, and Dave Langworthy (all from Microsoft) Refinement Types + Type-test

More information

Safe Stratified Datalog With Integer Order Does not Have Syntax

Safe Stratified Datalog With Integer Order Does not Have Syntax Safe Stratified Datalog With Integer Order Does not Have Syntax Alexei P. Stolboushkin Department of Mathematics UCLA Los Angeles, CA 90024-1555 aps@math.ucla.edu Michael A. Taitslin Department of Computer

More information

CSC Discrete Math I, Spring Sets

CSC Discrete Math I, Spring Sets CSC 125 - Discrete Math I, Spring 2017 Sets Sets A set is well-defined, unordered collection of objects The objects in a set are called the elements, or members, of the set A set is said to contain its

More information

Lambda Calculi With Polymorphism

Lambda Calculi With Polymorphism Resources: The slides of this lecture were derived from [Järvi], with permission of the original author, by copy & x = 1 let x = 1 in... paste or by selection, annotation, or rewording. [Järvi] is in turn

More information

Lecture 5: Predicate Calculus. ffl Predicate Logic ffl The Language ffl Semantics: Structures

Lecture 5: Predicate Calculus. ffl Predicate Logic ffl The Language ffl Semantics: Structures Lecture 5: Predicate Calculus ffl Predicate Logic ffl The Language ffl Semantics: Structures 1 Why Predicate Logic? Propositional logic is not powerful enough to express statements such as ffl For every

More information

CMSC 330: Organization of Programming Languages. Operational Semantics

CMSC 330: Organization of Programming Languages. Operational Semantics CMSC 330: Organization of Programming Languages Operational Semantics Notes about Project 4, Parts 1 & 2 Still due today (7/2) Will not be graded until 7/11 (along with Part 3) You are strongly encouraged

More information

Part I Logic programming paradigm

Part I Logic programming paradigm Part I Logic programming paradigm 1 Logic programming and pure Prolog 1.1 Introduction 3 1.2 Syntax 4 1.3 The meaning of a program 7 1.4 Computing with equations 9 1.5 Prolog: the first steps 15 1.6 Two

More information

Pure Lambda Calculus. Lecture 17

Pure Lambda Calculus. Lecture 17 Pure Lambda Calculus Lecture 17 Lambda Calculus Lambda Calculus (λ-calculus) is a functional notation introduced by Alonzo Church in the early 1930s to formalize the notion of computability. Pure λ-calculus

More information

1. Abstract syntax: deep structure and binding. 2. Static semantics: typing rules. 3. Dynamic semantics: execution rules.

1. Abstract syntax: deep structure and binding. 2. Static semantics: typing rules. 3. Dynamic semantics: execution rules. Introduction Formal definitions of programming languages have three parts: CMPSCI 630: Programming Languages Static and Dynamic Semantics Spring 2009 (with thanks to Robert Harper) 1. Abstract syntax:

More information

CIS 500 Software Foundations Midterm I

CIS 500 Software Foundations Midterm I CIS 500 Software Foundations Midterm I October 11, 2006 Name: Student ID: Email: Status: Section: registered for the course not registered: sitting in to improve a previous grade not registered: just taking

More information

Software Engineering Lecture Notes

Software Engineering Lecture Notes Software Engineering Lecture Notes Paul C. Attie August 30, 2013 c Paul C. Attie. All rights reserved. 2 Contents I Hoare Logic 11 1 Propositional Logic 13 1.1 Introduction and Overview..............................

More information

An Annotated Language

An Annotated Language Hoare Logic An Annotated Language State and Semantics Expressions are interpreted as functions from states to the corresponding domain of interpretation Operators have the obvious interpretation Free of

More information

Polymorphism. Lecture 19 CS 565 4/17/08

Polymorphism. Lecture 19 CS 565 4/17/08 Polymorphism Lecture 19 CS 565 4/17/08 The Limitations of F 1 (simply-typed λ- calculus) In F 1 each function works exactly for one type Example: the identity function id = λx:τ. x : τ τ We need to write

More information

Logic as a framework for NL semantics. Outline. Syntax of FOL [1] Semantic Theory Type Theory

Logic as a framework for NL semantics. Outline. Syntax of FOL [1] Semantic Theory Type Theory Logic as a framework for NL semantics Semantic Theory Type Theory Manfred Pinkal Stefan Thater Summer 2007 Approximate NL meaning as truth conditions. Logic supports precise, consistent and controlled

More information

Reasoning About Imperative Programs. COS 441 Slides 10

Reasoning About Imperative Programs. COS 441 Slides 10 Reasoning About Imperative Programs COS 441 Slides 10 The last few weeks Agenda reasoning about functional programming It s very simple and very uniform: substitution of equal expressions for equal expressions

More information

Lecture 2: SML Basics

Lecture 2: SML Basics 15-150 Lecture 2: SML Basics Lecture by Dan Licata January 19, 2012 I d like to start off by talking about someone named Alfred North Whitehead. With someone named Bertrand Russell, Whitehead wrote Principia

More information

Inductive Definitions, continued

Inductive Definitions, continued 1 / 27 Inductive Definitions, continued Assia Mahboubi Jan 7th, 2016 2 / 27 Last lecture Introduction to Coq s inductive types: Introduction, elimination and computation rules; Twofold implementation :

More information

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011

CS152: Programming Languages. Lecture 11 STLC Extensions and Related Topics. Dan Grossman Spring 2011 CS152: Programming Languages Lecture 11 STLC Extensions and Related Topics Dan Grossman Spring 2011 Review e ::= λx. e x e e c v ::= λx. e c τ ::= int τ τ Γ ::= Γ, x : τ (λx. e) v e[v/x] e 1 e 1 e 1 e

More information

Types, Expressions, and States

Types, Expressions, and States 8/27: solved Types, Expressions, and States CS 536: Science of Programming, Fall 2018 A. Why? Expressions represent values in programming languages, relative to a state. Types describe common properties

More information

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

5. Introduction to the Lambda Calculus. Oscar Nierstrasz

5. Introduction to the Lambda Calculus. Oscar Nierstrasz 5. Introduction to the Lambda Calculus Oscar Nierstrasz Roadmap > What is Computability? Church s Thesis > Lambda Calculus operational semantics > The Church-Rosser Property > Modelling basic programming

More information

1.3 Primitive Recursive Predicates and Bounded Minimalization

1.3 Primitive Recursive Predicates and Bounded Minimalization 12 1 Primitive Recursive Functions 1.3 Primitive Recursive Predicates and Bounded Minimalization 1.3.1 Case discrimination function The case discrimination function D is defined by D(x, y, z) = v x 0 v

More information

CS 242. Fundamentals. Reading: See last slide

CS 242. Fundamentals. Reading: See last slide CS 242 Fundamentals Reading: See last slide Syntax and Semantics of Programs Syntax The symbols used to write a program Semantics The actions that occur when a program is executed Programming language

More information

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus

Types. Type checking. Why Do We Need Type Systems? Types and Operations. What is a type? Consensus Types Type checking What is a type? The notion varies from language to language Consensus A set of values A set of operations on those values Classes are one instantiation of the modern notion of type

More information

Type Checking and Type Inference

Type Checking and Type Inference Type Checking and Type Inference Principles of Programming Languages CSE 307 1 Types in Programming Languages 2 Static Type Checking 3 Polymorphic Type Inference Version: 1.8 17:20:56 2014/08/25 Compiled

More information

Software Engineering using Formal Methods

Software Engineering using Formal Methods Software Engineering using Formal Methods Introduction to Promela Wolfgang Ahrendt 03 September 2015 SEFM: Promela /GU 150903 1 / 36 Towards Model Checking System Model Promela Program byte n = 0; active

More information

SOFTWARE ENGINEERING DESIGN I

SOFTWARE ENGINEERING DESIGN I 2 SOFTWARE ENGINEERING DESIGN I 3. Schemas and Theories The aim of this course is to learn how to write formal specifications of computer systems, using classical logic. The key descriptional technique

More information

Lecture 6: Arithmetic and Threshold Circuits

Lecture 6: Arithmetic and Threshold Circuits IAS/PCMI Summer Session 2000 Clay Mathematics Undergraduate Program Advanced Course on Computational Complexity Lecture 6: Arithmetic and Threshold Circuits David Mix Barrington and Alexis Maciel July

More information

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242

Foundations. Yu Zhang. Acknowledgement: modified from Stanford CS242 Spring 2013 Foundations Yu Zhang Acknowledgement: modified from Stanford CS242 https://courseware.stanford.edu/pg/courses/317431/ Course web site: http://staff.ustc.edu.cn/~yuzhang/fpl Reading Concepts

More information

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1

Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 Natural Semantics Goals: Define the syntax of a simple imperative language Define a semantics using natural deduction 1 1 Natural deduction is an instance of first-order logic; that is, it is the formal

More information

Introductory logic and sets for Computer scientists

Introductory logic and sets for Computer scientists Introductory logic and sets for Computer scientists Nimal Nissanke University of Reading ADDISON WESLEY LONGMAN Harlow, England II Reading, Massachusetts Menlo Park, California New York Don Mills, Ontario

More information

Lecture Note: Types. 1 Introduction 2. 2 Simple Types 3. 3 Type Soundness 6. 4 Recursive Types Subtyping 17

Lecture Note: Types. 1 Introduction 2. 2 Simple Types 3. 3 Type Soundness 6. 4 Recursive Types Subtyping 17 Jens Palsberg Sep 24, 1999 Contents Lecture Note: Types 1 Introduction 2 2 Simple Types 3 3 Type Soundness 6 4 Recursive Types 12 5 Subtyping 17 6 Decision Procedure for Subtyping 19 7 First-Order Unification

More information

(Refer Slide Time: 4:00)

(Refer Slide Time: 4:00) Principles of Programming Languages Dr. S. Arun Kumar Department of Computer Science & Engineering Indian Institute of Technology, Delhi Lecture - 38 Meanings Let us look at abstracts namely functional

More information

TRIAL EXAM C Software Engineering using Formal Methods TDA293 / DIT270

TRIAL EXAM C Software Engineering using Formal Methods TDA293 / DIT270 TRIAL EXAM C Software Engineering using Formal Methods TDA293 / DIT270 also serving as additional training material for the course Formal Methods for Software Development, TDA294/DIT271 1 Exam/Tenta SEFM

More information

Type Systems. Pierce Ch. 3, 8, 11, 15 CSE

Type Systems. Pierce Ch. 3, 8, 11, 15 CSE Type Systems Pierce Ch. 3, 8, 11, 15 CSE 6341 1 A Simple Language ::= true false if then else 0 succ pred iszero Simple untyped expressions Natural numbers encoded as succ succ

More information

1 Scope, Bound and Free Occurrences, Closed Terms

1 Scope, Bound and Free Occurrences, Closed Terms CS 6110 S18 Lecture 2 The λ-calculus Last time we introduced the λ-calculus, a mathematical system for studying the interaction of functional abstraction and functional application. We discussed the syntax

More information

Variables. Substitution

Variables. Substitution Variables Elements of Programming Languages Lecture 4: Variables, binding and substitution James Cheney University of Edinburgh October 6, 2015 A variable is a symbol that can stand for another expression.

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Operational Semantics CMSC 330 Summer 2018 1 Formal Semantics of a Prog. Lang. Mathematical description of the meaning of programs written in that language

More information

Introduction & Review

Introduction & Review Introduction & Review York University Department of Computer Science and Engineering 1 Why this course? Overview Programming Language Paradigms Brief review of Logic Propositional logic Predicate logic

More information

X-KIF New Knowledge Modeling Language

X-KIF New Knowledge Modeling Language Proceedings of I-MEDIA 07 and I-SEMANTICS 07 Graz, Austria, September 5-7, 2007 X-KIF New Knowledge Modeling Language Michal Ševčenko (Czech Technical University in Prague sevcenko@vc.cvut.cz) Abstract:

More information

Computer Science Technical Report

Computer Science Technical Report Computer Science Technical Report Feasibility of Stepwise Addition of Multitolerance to High Atomicity Programs Ali Ebnenasir and Sandeep S. Kulkarni Michigan Technological University Computer Science

More information

Last class. CS Principles of Programming Languages. Introduction. Outline

Last class. CS Principles of Programming Languages. Introduction. Outline Last class CS6848 - Principles of Programming Languages Principles of Programming Languages V. Krishna Nandivada IIT Madras Interpreters A Environment B Cells C Closures D Recursive environments E Interpreting

More information

Pierce Ch. 3, 8, 11, 15. Type Systems

Pierce Ch. 3, 8, 11, 15. Type Systems Pierce Ch. 3, 8, 11, 15 Type Systems Goals Define the simple language of expressions A small subset of Lisp, with minor modifications Define the type system of this language Mathematical definition using

More information

Computing Fundamentals 2 Introduction to CafeOBJ

Computing Fundamentals 2 Introduction to CafeOBJ Computing Fundamentals 2 Introduction to CafeOBJ Lecturer: Patrick Browne Lecture Room: K408 Lab Room: A308 Based on work by: Nakamura Masaki, João Pascoal Faria, Prof. Heinrich Hußmann. See notes on slides

More information