You are on page 1of 32

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)))

You might also like