You are on page 1of 157

Propositional logic

Propositional logic

A statement is a declaratory sentence which is true


or false but not both. In other words , a statement is
a declarative sentence which has a definate truth
table.
Logical connectives or sentence
connectives
These are the words or symbols used to
combine two sentence to form a compound
statement.
logic Name rank
~ Negation 1

^ Conjunction 2

V Disjunction 3

=> Conditional 4

 Biconditional 5
A B ^ V ~A =>  NOR NAND XOR EX-
NOR
T T T T F T T F F F T

T F F T F F F F T T F

F T F T T T F F T T F

F F F F T T T T T F T
TAUTOLOGY

i. A TAUTOLOGY IS A PREPOSITION WHICH IS TRUE FOR


ALL TRUTH VALUES OF ITS SUB- PREPOSITIONS OR
COMPONENTS.
ii. A TAUTOLOGY IS ALSO CALLED LOGICALLY VALID OR
LOGICALLY TRUE.
iii. ALL ENTRIES IN THE COLUMN OF
TAUTOLOGY ARE TRUE.
For example:
p^q=>q
P q p^q q p^q=>
q
T T T T T
T F F F T
F T F T T
F F F F T
Contradictio

n
CONTRADICTION IS A PREPOSITION WHICH
IS ALWAYS FALSE FOR ALL TRUTH VALUES OF
ITS SUB-PREPOSITIONS OR COMPONENTS.

A CONTRADICTION IS ALSO CALLED


LOGICALLY INVALID OR LOGICALLY FALSE

ALL ENTRIES IN THE COLUMN


OF CONTRADICTION ARE
FALSE.
FOR EXAMPLE
(P v Q)^(~P)^(~Q)

P Q PVQ ~P ~Q (P v Q)^(~P)^(~Q)

T T T F F F
T F T F T F
F T T T F F
F F F T T F
Continge
ncy
It is a preposition which is either true or false
depending on the truth value of its components or
preposition..
FOR EXAMPLE
~p ^ ~q

p q ~p ~q ~p ^ ~q
T T F F F
T F F T F
F T T F F
F F T T T
Logical equivalence

Two statements are called logically equivalent if the


truth values of both the statements are always
identical..

For example:
If we take two statements p=>q and ~q =>~p , then there
truth table values must be equal to satisfy the condition
of logical equivalence..
p q ~p ~q p=>q ~q=>~p
T T F F T T
T F F T F F
F T T F T T
F F T T T T

SINCE,THE TRUTH TABLE VALUES OF BOTH


STATEMENTS IS SAME. THUS, THE TWO
STATEMENTS ARE LOGICALLY EQUIVALENT..
LOGICAL
IMPLICATIONS

 DIRECT IMPLICATION (p=>q)


 CONVERSE IMPLICATION (q=>p)
 INVERSE OR OPPOSITE IMPLICATION (~p=>~q)
 CONTRAPOSITIVE IMPLICATION
(~q=>~p)
Algebra of
preposition
1) Commutative law
2) Associative law
3) Distributive law
4) De Morgan’s law
5) Idempotent law
6) Identity law
Idempotent law

1. pVpp
2. p^pp

p p pvp p v pp p^p p^ pp

T T T T T T

F F F F F F
Commutative law
• pvq=qvp
• p^q=q^p
p q pvq qvp p^q q^p
T T T T T T

T F T T F F
F T T T F F
F F F F F F
Associative law
• (p v q) v r  p v (q v r)
• (p ^ q) ^ r  p ^ (q ^ r)
p q r pvq ( p v q) v r qVr p v (q v r)
T T T T T T T
T T F T T T T
T F T T T T T
T F F T T F T
F T T T T T T
F T F T T T T
F F T F T T T
F F F F F F F
Distributive law
• p ^ (q v r)  (p ^ q) v (p ^ r)
• p ^ (q v r)  (p ^ q) v (p ^ r)
p q r qvr p^(q v r) p^q p^r (p^q)v(p^r)
T T T T T T T T
T T F T T T F T
T F T T T F T T
T F F F F F F F
F T T T F F F F
F T F T F F F F
F F T T F F F F
F F F F F F F F
De Morgan’s law
• ~(p v q)  ~p ^ ~q
• ~(p ^ q)  ~p v ~q

p q (p v q) ~(p v q) ~p ~q ~p ^ ~q
T T T F F F F

T F T F F T F
F T T F T F F

F F F T T T T
Identity law

1) p ^ T  p 2) T ^ p  p
3) p v F  p 4) F v p  p
P T P^T
P F P v F
T T T
T F T
F T F
F F F
TRANSITIVE
RULE
pq

qr
pr

Rule of detachment
P
Pq

q
EXAMPLE

 TEST THE VALIDITY OF THE FOLLOWING


 ARGUMENT….
IF A MAN IS A BACHELOR,HE IS
WORRIED(A PREMISE) IF A MAN IS
WORRIED,HE DIES YOUNG(A
PREMISE)
--------------------------------------------------------
---------------------------------------------
 BACHELORS DIE
YOUNG(CONCLUSION)
The given argument in symbolic form can be
written as:
pq

(a premise) qr

(a premise)

pr
p q r pq qr pr pq ^ qr (pq) ^ (qr)
=> pr

T T T T T T T T

T T F T F F F T

T F T F T T F T

T F F F T F F T

F T T T T T T T

F T F T F T F T

F F T T T T T T

F F F T T T T T
Set Operations
26
Set operations

Set OperatiOnS

Intersection
Union Disjoint sets
27
Set OperatiOnS

AB A A
B B
Ac or A
28
Set operations: Union

U
B
A B
A
29
Set operations: Union

• Formal definition for the union of two sets:


AB x  A  x  B}
{x AB x  A or x 
• Further examples
 { x B}
{2, 3, 5, 7,11,13}  {1, 3, 5, 7, 9}  {1, 2, 3, 5, 7, 9,11,13}

{2, 3, 5, 7,11,13}    {2, 3, 5, 7,11,13}


30
Set operations: Union

• Properties of the union operation

 AA Identity law


 AU U Domination law
 AAA Idempotent law
Commutative law
 A  B B 
A
A  (B  C )  ( A  B) Associative law
 C
31
Set operations: Intersection
U
B
A B

A
32
Set operations: Intersection
• Formal definition for the intersection of two
AB
sets: x  A  x  B}
{x AB x  A and x 
{x B}
• Further examples
{2, 3, 5, 7,11,13}  {1, 3, 5, 7, 9}  {3,
5, 7}

{2, 3, 5, 7,11,13}    
Set operations: Intersection 4
33

• Properties of the intersection operation


 AU Identity law
A
 A Domination law

 AAA Idempotent law
 A  B B  Commutative law
A
 A  (B  C )  ( A  B) Associative law
C
Disjoint sets 34

A B
35
Disjoint sets
• Formal definition for disjoint sets: two sets
are disjoint if their intersection is the empty
set.
• i.e. A  B 
 examples
• Further
 {1, 2, 3} and {3, 4, 5} are not disjoint
 {1, 2} and  are disjoint
• Their intersection is the empty set
  and  are disjoint!
• Their intersection is the empty set
Set operations: Difference 36

U
B
AB
 A  B A
Set operations: Difference 37
• Formal definition for the difference of two
sets:
AB x  A  x  B}
A{ 
xB x  A and x 
{x B}
A  A  A  U  A
c

• Further examples
{2, 3, 5, 7,11,13}  {1, 3, 5, 7, 9} 
{2,11,13}
c
Set operations: Symmetric 38
Difference
• Formal definition for the symmetric difference of
two sets:
AB{x xABx
A  B}
A  B  ( A  B)  ( A  B)
A  B  ( A  B)  (B  A)
Further examples
{2, 3, 5, 7,11,13}  {1, 3, 5, 7, 9}  {2,11,13,1,
9}
39

B
AB BA
A
Complement sets 40

c U
B
B
A

Ac 
Complement sets
• Formal definition for the complement of a
set
A c  A  U 
A U  {1, 2,
3, ...,10}
A 3,
Ac  U  A  {1, 2,  4,
{2,5,3,
6, 7, 8, 9,10}  {2, 3,
5, 7} c5, 7}
A  {1, 4, 6, 8, 16
Exp.:
U  {1, 2, 3, ...,10} 42
A  {2, 3, 5, 7}
B  {2, 4, 5, 6, 8,10}
A  B  {3, 7}
B  A  {4, 6, 8,10}
A  B  {2, 3, 4, 5, 6, 7,
8,10}
A  B  {2, 5}
Formal Methods
REHMAT ULLAH
Formal Methods

 One way to improve the quality of software is to change the


way in which software is documented: at the design stage,
during development, and after release.
 Existing methods of documentation offer large amounts of text,
pictures, and diagrams, but these are often imprecise and
ambiguous.
 Important information is hidden amongst irrelevant detail, and
design flaws are discovered too late, making them expensive
or impossible to correct
Formal Methods

There is an alternative. Formal methods, based upon elementary


mathematics, can be used to produce precise, unambiguous
documentation, in which information is structured and presented at
an appropriate level of abstraction.
CICS

 CICS is one of the most successful pieces of software in the


world: there are over 30000 licences, and most of the world’ s
top companies use it.

 CICS stands for Customer Information Control System, a


family of transaction processing products produced by IBM
UK Laboratories at Hursley Park
CICS

CICS provides

1. Data access
2. Communications
3. Integrity
4. Security services

Put simply, CICS manages information.


CICS

 A particular formal method, the Z notation, was used to specify


the new CICS functionality. Hursley’s programmers were used
to writing specifications in English, and the rigorous,
mathematical notation was seen as a challenge.
 The first CICS product to be designed using Z was CICS/ESA
version 3, announced in June 1989
 In April 1992, the Queen’s Award for Technological
Achievement was conferred upon IBM
Abstraction
Abstraction
Abstraction

 Abstract.
 Concise.
 Complete
 Unambiguous.
 Cost-effective.
 Maintainable.
 Comprehensible.
Propositional logic

Propositional logic deals with the statement of facts which must be


either

 true
 false,
 but not both
Example

The following statements are propositions:

• A tomato is a fruit.

• An orange is a fruit.

• Oranges are not the only fruit.


Compound propositions

 ¬(Rahat cakes are biscuits)

 your cat is rich ∧ your dog is good looking

 The economic recovery has started ∨ the minister is lying

 Jim is thirty-something⇒Jim is under forty

 Jim is thirty-something a Jim is under fort


Connective’s Symbol
Tautologies and Contradictions

Propositions which evaluate to T in every combination of their


propositional variables are known as tautologies.
The following propositions are tautologies
p ∨¬p
p ⇒p
p ⇒(q ⇒p)
Contradictions

Propositions which evaluate to F in every combination of their


propositional variables are known as Contradictions.
while the following are contradictions
Tautologies and Contradictions

The negation of a contradiction is a tautology

&

The negation of a tautology is a contradiction


Equality

 The notion of equality is a familiar one: in arithmetic we learn


that 1+1 equals 2; in the Christian religion, the 25th of
December equals Christmas Day.
 Such statements are meant to indicate that the two expressions
concerned have the same value, or that they denote the same
object.
 In a formal description, we identify expressions using the
equality symbol:
1+1 = 2,
ChristmasDay = 25thDecember
Equality

A witness may state that


‘The man on the right is the man who stole my idea’,
making the following identification:
The man on the right
=
The man who stole my idea
Leibniz’s law

 Leibniz’s law, or the substitution of equals:


if s =t,
then whatever is true of s is also true of t.

In fact, Leibniz (1646–1716) stated s = t if and only if every


property of s is a property of t,
Equality

If we know that
Christmas Day = 25thDecember,
and that
25thDecember falls on a Sunday this year
Then we may apply the [eq-sub] rule and conclude that
Christmas Day falls on a Sunday this year
We have to learn,

 Quantifier

 Negation Of Quantifier
Quantifier
 The use of phrases like ‘ there exists ’ and ‘ for all ’
or ‘ for every’ is abundant in mathematics .
 These phrases are called as Quantifiers .

Example:

1. For every a set A ,   A .

2. There exists a real number x such that x2  0


.
Symbol

o ‘ There exists ’ is represented by 

o ‘ For all ’or ‘For every ’is represented by



 is called an Existential Quantifier.
 is called a Universal Quantifier.
Negation of Quantifier

 The negation of Existential quantifier will be Universal


quantifier and vice versa .

~(there exists p) = for all ( ~p ) or ~ (p)  (~ p)


~(for all p) = there exists ( ~p ) or ~ (p)  (~ p)
Examples

 Find the negation of given statement:

1. For every x  R, x  0  0  x
x 2  1
2. There exists x  R such
that
Answer:

1. There exists x  R x00


such that x

2. For every x  R , x2 
1st-order predicate logic

Mary loves everyone. [assuming D contains only humans]


∀x love (Mary, x)
I would also count as correct any of the following:
∀x (love (Mary, x)),
(∀x love (Mary, x)), (∀x (love (Mary, x)))
1st-order predicate logic

Mary loves everyone. [assuming D contains both humans and


non-humans, so we need to be explicit about ‘everyone’ as
‘every person’]
∀x (person(x) → love (Mary, x))
A wrong answer:
∀x (person(x) & love (Mary, x))
This says that everything in the universe is a person and loves
Mary.
1st-order predicate logic

No one talks. [assume D contains only humans unless specified


otherwise.]
¬∃x talk(x) or equivalently, ∀x¬talk(x)
Everyone loves himself.
∀x love (x, x)
Everyone loves everyone.
∀x∀y love (x, y)
1st-order predicate logic

Everyone loves everyone except himself.


(= Everyone loves everyone else.)

∀x∀y(¬ x = y → love (x, y))


or
∀x∀y( x ≠ y → love (x, y))
1st-order predicate logic

Everyone walks or talks.

∀x (walk (x) ∨ talk (x))

Every student walks or talks.

∀x (student(x) → (walk (x) ∨ talk (x)))


1st-order predicate logic

Every student who walks talks.

∀x ((student(x) & walk (x)) → talk (x)))

Every student who loves Mary is happy.

∀x ((student(x) & love (x, Mary)) → happy (x)))


1st-order predicate logic

Every student who loves Mary is happy.

∀x ((student(x) & love (x, Mary)) → happy (x)))

Every boy who loves Mary hates every boy who Mary loves.

∀x((boy(x) & love (x, Mary)) → ∀y((boy(y) & love(Mary, y))→


hate (x,y)))
Formal Methods
REHMAT ULLAH
Formal Methods Notations

 Z,
 Object-Z,
 VDM,
 Larch
Specification Language Z

 Jean-Raymond Abrial, late 1970s/early 1980s


 Under continuing development at the Programming Research Group,
Oxford University
 A state-based modeling/specification language
 Set theory, predicate logic
 Object-oriented variations
 Most popular formal methods notation
Z Schema

There are mainly three components In z Schema

1. Schema Name
2. Variable Declarations
3. Predicate
Z Schema

 Introduced, Schema Name will be associated with the schema


proper, which is the contents of the box

 The declarations part of the schema will contain:


1. a list of variable declarations;
2. and – references to other schemas (this is called schema
inclusion).

3. Variable declarations have the usual form: x1, x2, . . . , x n : T;


Z Schema

 The predicate part of a schema contains a list of predicates,


separated either by semi-colons or new lines.
Z Schemas

The building-block for structuring specifications


Z Schemas

The Z schema is a 2-dimensional graphical notation for describing:


 state spaces
 operations.
Identifiers in Z

Identifiers may be composed of upper and lower case letters,


digits, and the underscore character; must begin with a letter
Identifiers may have suffixes:
? means an input variable
! means an output variable
′ means a new value (i.e., the after-operation value)
Identifiers in Z

Schema identifiers may have prefixes:

 ∆ means the state has changed (described later)

 Ξ means no change in the state (described later)


Examples
Examples
SETS

Sets are the most basic types in Z. Examples of sets include:


SETS

Set Membership:

Set Equality:
{ 3, 6, 7 } = { 7, 6, 3, 6 }
SETS

 The following operators may be applied to sets:


 Union: S ∪ T
 Intersection: S ∩ T
 Difference: S \ T
 Subset: S ⊆ T E.g., {c, b} ⊆ {a, b, c}.
 Power Set: P S (set of subsets of S).
P{a, b, c} = { {}, {a}, {b}, {c}, {a, b}, {b, c}, {a, c}, {a, b, c} }
Z (Conti…)
REMAT ULLAH
“Conformance to requirements”
“Conformance to requirements”
“Conformance to requirements”
Formal Methods
 The notation used in a formal method is called a formal
specification language or 'notation‘.

 The language is 'formal' in that it has a formal semantics and


consequently can be used to express specifications in a clear
and unambiguous manner.
Programming languages are formal
languages?

Programming languages are formal languages, but are not


considered appropri-ate for use in formal specifications for a
number of reasons:
Programming languages are formal
languages?

 Firstly, very few programming languages have been given a


complete formal se-mantics (Ada and Modula-2 are
exceptions), which makes it difficult to prove programs correct
and to reason about them.
 Too much detail at an early stage in the development can lead
to a bias towards a particular implementation, and can result in
a system that does not meet the original requirements.
 Software Development Life Cycle:
 • Requirements analysis
 • Requirements specification
– As a process: when the functionality of the software is specified
– As a product: where the expected functionality is recorded
 • Architectural design
 • Detailed design
 • Implementation
 • Testing
Essential Properties of a Specification
Document

 • Correctness
 • Completeness
 • Unambiguous (one interpretation)
 • Precision (unnecessary detail suppressed)
 • Verifiable and traceable
 • Independent from design
 • Consistent (no conflicting features)
 • Concise (lack of noise, irrelevant features)
Z schema
Z schema Inclusion
Z schema Inclusion
Types
Types
Types

 A new basic type T is introduced to a specification by putting its name


in square brackets:
[T]
 This allows us to name the types of a specification without saying what
kind of objects they contain. For example, a specification of an address
book might introduce the basic types Name and Address without
worrying about the structure of these types:
[ Name, Address ]
 If we know the exact values of a type we use an enumerated type
declaration:
Direction == north | south | east | west
Predicates
Global Defination
Universal Quantification

(∀x : T •A)

This is true when A holds for all values x of type T. Here x is a said to be a
quantified or bound variable.
Existential Quantification

(∃x : T •A)

This is true when A holds for some value x of type T.


Quantifiers and declarations

In the Z notation, the two kinds of quantified expressions have a


similar syntax:
Qx : a |p •q
where
1. Q is the quantifier;
2. x is the bound variable;
3. a is the range of x;
4. p is the constraint;
5. q is the predicate.
Quantifiers and declarations

Consider the following quantified expression, which states that


every natural number x is greater than or equal to zero:
∀num : N•num ≥0

The choice of ‘num’ as the variable name is not important; the


following expression has the same meaning:
∀nat : N•nat ≥0
Relations

A Relation is simply a set of order pairs. An ordered pair of


values is written: (x,y)
Relations
Relations

A Relation is simply a set of order pairs. An ordered pair of


values is written: (x,y)
For example, a database relating names to telephone numbers can
be modelled as a set of ordered pairs:
directory = {(mary,287573), (mary,398620),
(john,829483), (jim,493028),
(jane,493028)}
The set directory has type,
directory : P(Person×Number)
Relations

Note that it is possible for a name to be related to more than one


number (mary may have a home number and a mobile number)
It is possible for two people to be related to the same number (jim
and jane may live together).
Because relations are commonly used in specification, they have
their own special symbol:
T ↔ S == P(T ×S)
So we can write:
directory : Person ↔ Number
Relations
Relations

Relations
Phone Directory Specification
Add Number
Get & Remove Entry
Combining Schemas

 Schemas may be combined using conjunction and disjunction


to form new schemas. Suppose we have the following two
schemas
Combining Schemas

 We can now define Schema3 to be the conjunction of Schema1


and Schema2
 we can define Schema4 to be the disjunction of these:
Schema3 == Schema1∧ Schema2
Schema4 == Schema1∨ Schema2
Combining Schemas
Example Specification:
Check-In/Check-Out

We consider a specification of a system used to check staff members in and out of


a building. Since we will be dealing with elements of type staff, we introduce the
type Staff as a basic type:
[Staff ]
Example Specification:
Check-In/Check-Out
Example Specification:
Check-In/Check-Out

The predicate part of the state schema describes an Invariant of the


system. The invariant says that

• No staff member is simultaneously in and out.

• The set of users of the system is exactly the union of those who
are in and those who are out.
Example Specification:
Check-In/Check-Out
Example Specification:
Check-In/Check-Out

A query operation to check whether a particular member of staff is


in or out will give an output parameter of the following type:
QueryReply == is in | is out
The operation is then specified as:
Example Specification:
Check-In/Check-Out
Example Specification:
Check-In/Check-Out

Robust Operations
Example Specification:
Check-In/Check-Out

Here, we assume that the type QueryReply has three possible


values:
QueryReply == is in | is out | not registered
Example Specification:
Check-In/Check-Out
Z (Domain Subtraction &
Partial Function)
REHMAT ULLAH
Domain Subtraction

we wish to remove all the entries associated with a name. This


may be achieved using the domain subtraction operation

S R represents the relation R with all mappings for domain


elements in the set S removed.
Domain Subtraction
Domain Subtraction
Domain Subtraction

Operation to remove all entries associated with a name is now


specified as:
Domain Subtraction

An operation to remove all entries associated with a set of names


is specified as:
Partial Function

A partial function is a special kind of relation in which each


domain element has at most one range element associated with it.
To declare f as a partial function we write:
Partial Function

For example, suppose dir1 Is defined as follows


Partial Function

Now suppose dir2 is defined as:

This time dir2 is not a partial function since mary is related to


more than one number and dir2(mary) is undefined.
Partial Function

An organization has a system for keeping track of its employees


while they are on the premises. Each employee is issued with an
active badge which reports their current position to a central
database. If the set of all people is Person, and the set of all
locations is Location, then the information provided by the system
may be described by a relation where is of type Person ↔
Location. It is impossible for an employee to be in two places at
once, so this relation will be a partial function:
Properties of functions

It is extremely helpful to categories functions according to whether


or not.
three key properties:
 injectivity,
 surjectivity,
 bijectivity.
Our mathematical language has a special symbol associated with
each category:
Properties of functions
Properties of functions
Injective Function
Surjective Function
Properties of functions
Bijection Function
Bijection Function

You might also like