540 likes | 692 Views
Lecture 9. Z Pi-Method Aspect-Oriented Programming . Project Proposal (10/10). Presentation 10 min + 2 min questions – in class Title, team member Startup/Research track: What to do, goals Why it is important Background An overview of the approach Plan: steps and time frame
E N D
Lecture 9 Z Pi-Method Aspect-Oriented Programming
Project Proposal (10/10) • Presentation 10 min + 2 min questions – in class • Title, team member • Startup/Research track: • What to do, goals • Why it is important • Background • An overview of the approach • Plan: steps and time frame • Engineering track: • Use case diagram/Use case descriptions/Sequence diagram • Who did which • Documentation 4:00pm, dropbox • Startup/Research Track: 1-page proposal • Engineering track: modeling documents
Review Lecture 8 OCL examples, Overview of FST Nobody has more than 3 black vehicles context Person inv: self.fleet->select(v | v.oclIsTypeOf(Car) and v.colour= colour::black)->size()) <= 3
Review Lecture 8 OCL examples, Overview of FST Navigate from car to vehicle for accessing overriden features context Car inv: self.oclAsType(Vehicle).colour = Colour::White -- access features define in Vecicle inv: self.colour = Colour::White -- access overriden features
Review Lecture 8 OCL examples, Overview of FST • Special Symbols: • selfrefers to an object of the class being constrained self.numberOfEmployees • In most cases, self can be left out, because the context is clear, as in the above examples. • resultis used in a post-condition inside an operation specification, to indicate the object returned Calling birthday() increments the age of a person by 1 context Person::birthday() post: self.age = self.age@pre + 1
Roadmap for Today • Background: propositional and first order logic • Intro to Z • Pi method • AOP
Proposition • Logic: study of reasoning, whether the relations among statements are correct • Proposition: a sentence is true or false • Declarative, compositional, context independent • Compound proposition: • conjunction pq • disjunction pq • negation • conditional p (hypothesis) q (conclusion) : if then • Bi-conditional p q: if and only if
Proposition logicUsing truth table to verify their correctness -- always have the same truth valueProof logically equivalent
Tautologies, contradictions, contingencies A compound proposition is called a tautology if no matter what truth values its atomic propositions have, its own truth value is T. p ¬p (Law of excluded middle) The opposite to a tautology, is a compound proposition that’s always false –a contradiction. p ¬p On the other hand, a compound proposition whose truth value isn’t constant is called a contingency. p ¬p
p p p p p p p p F T F T T F T F T T F F Tautologies and contradictions The easiest way to see if a compound proposition is a tautology/contradiction is to use a truth table.
Tautology example Demonstrate that [¬p(p q )]q is a tautology in two ways: • Using a truth table – show that [¬p(p q )]q is always true • Using a proof (will get to this later)
Logical Equivalences Two compound propositions p, q are logically equivalent if their biconditional joining p q is a tautology. Logical equivalence is denoted by p q. The contrapositive of a logical implication is the reversal of the implication, while negating both components. i.e. the contrapositive of pq is ¬q¬p . As we’ll see next: pq¬q¬p
p q p q p q ¬q ¬p ¬q¬p Logical Equivalence of Conditional and Contrapositive The easiest way to check for logical equivalence is to see if the truth tables of both variants have identical last columns: Q: why does this work given definition of ?
p q p q p q ¬q ¬p ¬q¬p T T F F T F T F T F T T Logical Equivalence of Conditional and Contrapositive The easiest way to check for logical equivalence is to see if the truth tables of both variants have identical last columns: Q: why does this work given definition of ?
p q p q p q ¬q ¬p ¬q¬p T T F F T F T F T F T T T T F F T F T F Logical Equivalence of Conditional and Contrapositive The easiest way to check for logical equivalence is to see if the truth tables of both variants have identical last columns: Q: why does this work given definition of ?
p q p q p q ¬q ¬p ¬q¬p T T F F T F T F T F T T T T F F T F T F F T F T Logical Equivalence of Conditional and Contrapositive The easiest way to check for logical equivalence is to see if the truth tables of both variants have identical last columns: Q: why does this work given definition of ?
p q p q p q ¬q ¬p ¬q¬p T T F F T F T F T F T T T T F F T F T F F T F T F F T T Logical Equivalence of Conditional and Contrapositive The easiest way to check for logical equivalence is to see if the truth tables of both variants have identical last columns: Q: why does this work given definition of ?
p q p q p q ¬q ¬p ¬q¬p T T F F T F T F T F T T T T F F T F T F F T F T F F T T T F T T Logical Equivalence of Conditional and Contrapositive The easiest way to check for logical equivalence is to see if the truth tables of both variants have identical last columns: Q: why does this work given definition of ?
Logical Equivalences A: p q by definition means that p q is a tautology. Furthermore, the biconditional is true exactly when the truth values of p and of q are identical. So if the last column of truth tables of p and of q is identical, the biconditional join of both is a tautology.
Derivational Proof Techniques When compound propositions involve more and more atomic components, the size of the truth table for the compound propositions increases Q1: How many rows are required to construct the truth-table of:( (q(pr)) ((sr)t) ) (qr) Q2: How many rows are required to construct the truth-table of a proposition involving n atomic components?
Derivational Proof Techniques A1: 32 rows, each additional variable doubles the number of rows A2: In general, 2n rows Therefore, as compound propositions grow in complexity, truth tables become more and more unwieldy. Checking for tautologies/logical equivalences of complex propositions can become a chore, especially if the problem is obvious.
Derivational Proof Techniques consider the compound proposition (p p ) ((sr)t) ) (qr) Why is this a tautology?
Derivational Proof Techniques A: Part of it is a tautology (p p ) and the disjunction of True with any other compound proposition is still True: (p p ) ((sr)t )) (qr ) • T ((sr)t )) (qr ) • T Derivational techniques formalize the intuition of this example.
Identity laws Like adding 0 Domination laws Like multiplying by 0 Idempotent laws Delete redundancies Double negation “I don’t like you, not” Commutativity Like “x+y = y+x” Associativity Like “(x+y)+z = y+(x+z)” Distributivity Like “(x+y)z = xz+yz” De Morgan Tables of Logical Equivalences
Excluded middle Negating creates opposite Definition of implication in terms of Not and Or Tables of Logical Equivalences
DeMorganLaw DeMorgan’slaw allow for simplification of negations of complex expressions • Conjunctional negation: (p1p2…pn) (p1p2…pn) “It’s not the case that all are true iff one is false.” • Disjunctional negation: (p1p2…pn) (p1p2…pn) “It’s not the case that one is true iff all are false.”
Tautology example Demonstrate that [¬p(p q )]q is a tautology in two ways: • Using a truth table (did above) • Deriving True through a series of logical equivalences
Tautology by proof [¬p(p q )]q
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive [ F (¬pq)]q ULE
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive [ F (¬pq)]q ULE [¬pq ]q Identity
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive [ F (¬pq)]q ULE [¬pq ]q Identity ¬[¬pq ] q ULE
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive [ F (¬pq)]q ULE [¬pq ]q Identity ¬[¬pq ] q ULE [¬(¬p)¬q ] q DeMorgan
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive [ F (¬pq)]q ULE [¬pq ]q Identity ¬[¬pq ] q ULE [¬(¬p)¬q ] q DeMorgan [p ¬q ] q Double Negation
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive [ F (¬pq)]q ULE [¬pq ]q Identity ¬[¬pq ] q ULE [¬(¬p)¬q ] q DeMorgan [p ¬q ] q Double Negation p [¬q q ]Associative
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive [ F (¬pq)]q ULE [¬pq ]q Identity ¬[¬pq ] q ULE [¬(¬p)¬q ] q DeMorgan [p ¬q ] q Double Negation p [¬q q ]Associative p [q ¬q ]Commutative
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive [ F (¬pq)]q ULE [¬pq ]q Identity ¬[¬pq ] q ULE [¬(¬p)¬q ] q DeMorgan [p ¬q ] q Double Negation p [¬q q ]Associative p [q ¬q ]Commutative p T ULE
Tautology by proof [¬p(p q )]q [(¬pp)(¬pq)]q Distributive [ F (¬pq)]q ULE [¬pq ]q Identity ¬[¬pq ] q ULE [¬(¬p)¬q ] q DeMorgan [p ¬q ] q Double Negation p [¬q q ]Associative p [q ¬q ]Commutative p T ULE T Domination
Example “I don’t drink and drive” is logically equivalent to “If I drink, then I don’t drive”
First order logic • Propositional logic: assume world contains facts • First order logic: assume world contains: • object • relations • functions • High order logic: quantifier and variable can be functions
Basic Elements of First Order Logic • Constants KingJohn, 2, NUS,... • Predicates Brother, >,... • Functions Sqrt, LeftLegOf,... • Variables x, y, a, b,... • Connectives , , , , • Equality = • Quantifiers ,
Atomic Sentences Atomic sentence = predicate (term1,...,termn) or term1 = term2 Term = function (term1,...,termn) or constant or variable • An atomic sentence predicate(term1,...,termn) is true iffthe objects referred to by term1,...,termn are in the relation referred to by predicate
Complex Sentences • Complex sentences are made from atomic sentences using connectives S, S1 S2, S1 S2, S1 S2, S1S2,
Quantifiers • Universal quantifier (bind the variable): <variables> <sentence> x P (x ) P (x1) P (x2) P (x3) … • x P (x) is true when an instance can be found which when plugged in for x makes P (x) true, like disjunction over entire universe: x P (x ) P (x1) P (x2) P (x3) … • Multivariate quantifier: x y z P (x,y,z) There is an x such that for all y there is a z such that P (x,y,z) holds.
Properties of quantifiers x y is the same as yx x y is the same as yx x y is not the same as yx x y Loves(x,y) “There is a person who loves everyone in the world” yx Loves(x,y) “Everyone in the world is loved by at least one person” Quantifier duality: each can be expressed using the other x Likes(x,IceCream) x Likes(x,IceCream) x Likes(x,Broccoli) xLikes(x,Broccoli)