SlideShare a Scribd company logo
Formal Methods in
Software
Lecture 1. Introduction
Vlad Patryshev
SCU
2014
Content of this course
• FSM, deterministic/non-deterministic; (P/NP); regexp; code sample (the
one-liner), problem with the code; p!=np
• Stack machine, context-free languages; general languages; Turing
machine; some Turing stuff, examples of Turing machine
• Z specification language
• Pi calculus and its fate;
• Monoid, Group, Groupoid, Category, Monomorphisms, Epimorphisms,
Isomorphisms, show it on sets and monoids; Scala (Java) category
• terminal object, initial object; products, unions; show code samples;
equalizers, code samples; notation {x|f(x)==g(x)}; pullbacks, sql
• functors examples (diagrams; product; exponentiations); currying/yoneda
lemma; example with integers/rationals; monad?
What you have to know
• first-order logic; quantifiers (see COEN260 slides)
• some set theory; binary relationships, currying;
injection/surjection/bijection (see COEN260 slides)
• some intro to intuitionistic logic (see COEN260 slides)
• javascript or java or scala
Formal Methods
• Need them in:
o medical devices
o space
o military
o communications
• Don’t need them in:
o social networks
o ads and sales
o startups
Example of Algorithm Proof
Euclidean Algorithm:
Find GCD(a,b), where a and b are two natural numbers.
1. If a < b, use the fact that GCD(a,b)=GCD(b,a)
2. GCD(a,0) = a; done.
3. GCD(a,b) = GCD(a-b,a)
4. Repeat until done.
Proof:
A. Prove that GCD(a,b)=GCD(b,a)
B. Prove that GCD(a,0) = a
C. Prove that GCD(a,b) = GCD(a-b,a)
D. Prove that it takes not more than 2*max(a,b) steps.
You are asked to double a cube
Have a cube, V=x3
Build a cube of size 2*V, using a divider and a ruler
Informally: approximate; we only have doubles in Java.
Formally: have to calculate √3(2)
The thing is: You Can’t
A similar problem
Need an algorithm to find roots of a 5th degree polynomial
Explanation: 5 roots, S5 is the group of all permutations,
and it cannot be represented via a chain of +/-
symmetries.
x5-x+1 = 0
Gödel’s First Theorem
Meaning, if we have a theory T, we can always come up with a statement in T
that cannot be proved.
How?
• enumerate all sentences; then all proofs.
• isProvable(n) ≡ ∃F (n=#(F) ∧ F is provable)
• (diagonal lemma) ∀F ∃p (p ↔ F(#(p))
• how about p ↔ ¬isProvable(#(p))
A theory that contains arithmetics cannot be
at the same time consistent and complete.
Entscheidungsproblem
Is there an algorithm that, given a first-order theory, takes a statement
and checks whether the statement is true?
(The essence of the proof of program validity.)
The answer is: NO
Church proved that there is no computable function which decides for two
given λ calculus expressions whether they are equivalent or not.
Turing proved that it reduces to Halting Problem
Halting Problem
Given a program, can we decide if it ever ends?
Answer: NO
http://ro-che.info/ccc/03
Collatz Conjecture
function(n) {
while (n > 1) {
println(n);
n = n%2==0 ? n/2 : (3*n+1)
}
}
E.g. 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1
Will it ever stop?
Nobody Knows.
So, what can we do?
• limit ourselves by only provable algorithms
• count on the finiteness of the universe (is it finite?)
• count on the finiteness of time (is it finite?)
• write some unittests and pray (is it a formal method?!)
Unittests
• You cannot prove the program is right, but you can find errors
• Can cover main and corner cases
• Can check behavior independently from environment
• Can feel safe doing refactorings
Some people tried to formalize unittest creation (agitar.com) (see e.g. halting
problem)
Question: can you write a unittest for random numbers generator?
Formal methods   1 - introduction

More Related Content

PDF
Fafl notes [2010] (sjbit)
Siddharaj Junnarkar
 
PPT
Theory of Computation - Lectures 4 and 5
Dr. Maamoun Ahmed
 
PDF
Introduction to the theory of computation
prasadmvreddy
 
PDF
27 NP Completness
Andres Mendez-Vazquez
 
PDF
Isolation Lemma for Directed Reachability and NL vs. L
cseiitgn
 
PPT
Introduction to NP Completeness
Gene Moo Lee
 
PPTX
Finite Automata in compiler design
Riazul Islam
 
PDF
P versus NP
Farid El Hajj
 
Fafl notes [2010] (sjbit)
Siddharaj Junnarkar
 
Theory of Computation - Lectures 4 and 5
Dr. Maamoun Ahmed
 
Introduction to the theory of computation
prasadmvreddy
 
27 NP Completness
Andres Mendez-Vazquez
 
Isolation Lemma for Directed Reachability and NL vs. L
cseiitgn
 
Introduction to NP Completeness
Gene Moo Lee
 
Finite Automata in compiler design
Riazul Islam
 
P versus NP
Farid El Hajj
 

What's hot (20)

PPTX
P vs NP
Mikel Qafa
 
PPTX
Np Completeness
Rajan Shah
 
PDF
Algorithm chapter 10
chidabdu
 
PDF
Deterministic Finite Automata (DFA)
Animesh Chaturvedi
 
PPT
the halting_problem
Rajendran
 
PPT
Np completeness h4
Rajendran
 
PPTX
Thoery of Computaion and Chomsky's Classification
PrafullMisra
 
PPTX
Class 36: Halting Problem
David Evans
 
PDF
NFA to DFA
Animesh Chaturvedi
 
PDF
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
PDF
Lecture: Automata
Marina Santini
 
PPTX
Introduction TO Finite Automata
Ratnakar Mikkili
 
PPTX
Teori pnp
Tenia Wahyuningrum
 
PPT
Np completeness
Rajendran
 
PPT
Finite automata
Bipul Roy Bpl
 
PPT
Introduction to fa and dfa
deepinderbedi
 
PDF
Formal Languages and Automata Theory unit 5
Srimatre K
 
PPTX
np complete
Gayathri Gaayu
 
PPTX
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Mohammad Ilyas Malik
 
P vs NP
Mikel Qafa
 
Np Completeness
Rajan Shah
 
Algorithm chapter 10
chidabdu
 
Deterministic Finite Automata (DFA)
Animesh Chaturvedi
 
the halting_problem
Rajendran
 
Np completeness h4
Rajendran
 
Thoery of Computaion and Chomsky's Classification
PrafullMisra
 
Class 36: Halting Problem
David Evans
 
NFA to DFA
Animesh Chaturvedi
 
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
Lecture: Automata
Marina Santini
 
Introduction TO Finite Automata
Ratnakar Mikkili
 
Np completeness
Rajendran
 
Finite automata
Bipul Roy Bpl
 
Introduction to fa and dfa
deepinderbedi
 
Formal Languages and Automata Theory unit 5
Srimatre K
 
np complete
Gayathri Gaayu
 
Finite Automata: Deterministic And Non-deterministic Finite Automaton (DFA)
Mohammad Ilyas Malik
 
Ad

Viewers also liked (8)

PPS
Formal Methods
HendMuhammad
 
PPTX
Formal Methods lecture 01
Sidra Ashraf
 
PPT
Formal Specification in Software Engineering SE9
koolkampus
 
PDF
Using formal methods in Industrial Software Development
Robert van Lieshout
 
PDF
Industrial use of formal methods
Jonathan Bowen
 
PDF
Ten Commandments of Formal Methods: A decade later
Jonathan Bowen
 
PPTX
#1 formal methods – introduction for software engineering
Sharif Omar Salem
 
PPTX
Software quality
Sara Mehmood
 
Formal Methods
HendMuhammad
 
Formal Methods lecture 01
Sidra Ashraf
 
Formal Specification in Software Engineering SE9
koolkampus
 
Using formal methods in Industrial Software Development
Robert van Lieshout
 
Industrial use of formal methods
Jonathan Bowen
 
Ten Commandments of Formal Methods: A decade later
Jonathan Bowen
 
#1 formal methods – introduction for software engineering
Sharif Omar Salem
 
Software quality
Sara Mehmood
 
Ad

Similar to Formal methods 1 - introduction (20)

PDF
Cs6503 theory of computation book notes
appasami
 
PPTX
Logic
Hamxi
 
PPTX
unit 1.pptx-theory of computation complete notes
yuvaraniit
 
KEY
Pontificating quantification
Aaron Bedra
 
PPTX
Theory of computation:Finite Automata, Regualr Expression, Pumping Lemma
PRAVEENTALARI4
 
PDF
Theory of Computation Lecture Notes
FellowBuddy.com
 
PDF
ANOTHER PROOF OF THE DENUMERABILITY OF THE COMPLEX NUMBERS
csandit
 
PDF
theory of computation chapter 2 notes pdf
laleshpawar2025
 
PPTX
Unit -I Toc.pptx
viswanath kani
 
PDF
Formal language & automata theory
NYversity
 
PPT
2_1_DiscreteMathematics_05 2 slides about discrete subjects
RazaAhmad49
 
PDF
TMPA-2015: A Need To Specify and Verify Standard Functions
Iosif Itkin
 
PPTX
Incompleteness without Godel Numberings
Satvik Beri
 
PDF
CS.15.Turing.pdf
YasirAli74993
 
PPTX
Discrete Math IP4 - Automata Theory
Mark Simon
 
PDF
Algorithmic Mathematics.
Dr. Volkan OBAN
 
PDF
Theory ofcomputation
nesrine attia
 
PPTX
Ip 5 discrete mathematics
Mark Simon
 
PDF
QB104541.pdf
MrRRajasekarCSE
 
PPTX
Computability and Complexity
Edward Blurock
 
Cs6503 theory of computation book notes
appasami
 
Logic
Hamxi
 
unit 1.pptx-theory of computation complete notes
yuvaraniit
 
Pontificating quantification
Aaron Bedra
 
Theory of computation:Finite Automata, Regualr Expression, Pumping Lemma
PRAVEENTALARI4
 
Theory of Computation Lecture Notes
FellowBuddy.com
 
ANOTHER PROOF OF THE DENUMERABILITY OF THE COMPLEX NUMBERS
csandit
 
theory of computation chapter 2 notes pdf
laleshpawar2025
 
Unit -I Toc.pptx
viswanath kani
 
Formal language & automata theory
NYversity
 
2_1_DiscreteMathematics_05 2 slides about discrete subjects
RazaAhmad49
 
TMPA-2015: A Need To Specify and Verify Standard Functions
Iosif Itkin
 
Incompleteness without Godel Numberings
Satvik Beri
 
CS.15.Turing.pdf
YasirAli74993
 
Discrete Math IP4 - Automata Theory
Mark Simon
 
Algorithmic Mathematics.
Dr. Volkan OBAN
 
Theory ofcomputation
nesrine attia
 
Ip 5 discrete mathematics
Mark Simon
 
QB104541.pdf
MrRRajasekarCSE
 
Computability and Complexity
Edward Blurock
 

More from Vlad Patryshev (20)

PDF
Formal methods 8 - category theory (last one)
Vlad Patryshev
 
PDF
Formal methods 6 - elements of algebra
Vlad Patryshev
 
PPTX
Formal methods 5 - Pi calculus
Vlad Patryshev
 
PDF
Formal methods 4 - Z notation
Vlad Patryshev
 
PPTX
Formal methods 3 - languages and machines
Vlad Patryshev
 
PPTX
Formal methods 2 - languages and machines
Vlad Patryshev
 
PPTX
Formal methods 7 - category theory
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture i (last one)
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture h
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture g
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture f
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture e
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture d
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture c
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture b
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture a
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture 9
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture 8
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture 7
Vlad Patryshev
 
PDF
Truth, deduction, computation lecture 6
Vlad Patryshev
 
Formal methods 8 - category theory (last one)
Vlad Patryshev
 
Formal methods 6 - elements of algebra
Vlad Patryshev
 
Formal methods 5 - Pi calculus
Vlad Patryshev
 
Formal methods 4 - Z notation
Vlad Patryshev
 
Formal methods 3 - languages and machines
Vlad Patryshev
 
Formal methods 2 - languages and machines
Vlad Patryshev
 
Formal methods 7 - category theory
Vlad Patryshev
 
Truth, deduction, computation lecture i (last one)
Vlad Patryshev
 
Truth, deduction, computation lecture h
Vlad Patryshev
 
Truth, deduction, computation lecture g
Vlad Patryshev
 
Truth, deduction, computation lecture f
Vlad Patryshev
 
Truth, deduction, computation lecture e
Vlad Patryshev
 
Truth, deduction, computation lecture d
Vlad Patryshev
 
Truth, deduction, computation lecture c
Vlad Patryshev
 
Truth, deduction, computation lecture b
Vlad Patryshev
 
Truth, deduction, computation lecture a
Vlad Patryshev
 
Truth, deduction, computation lecture 9
Vlad Patryshev
 
Truth, deduction, computation lecture 8
Vlad Patryshev
 
Truth, deduction, computation lecture 7
Vlad Patryshev
 
Truth, deduction, computation lecture 6
Vlad Patryshev
 

Recently uploaded (20)

PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
CDH. pptx
AneetaSharma15
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
CDH. pptx
AneetaSharma15
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 

Formal methods 1 - introduction

  • 1. Formal Methods in Software Lecture 1. Introduction Vlad Patryshev SCU 2014
  • 2. Content of this course • FSM, deterministic/non-deterministic; (P/NP); regexp; code sample (the one-liner), problem with the code; p!=np • Stack machine, context-free languages; general languages; Turing machine; some Turing stuff, examples of Turing machine • Z specification language • Pi calculus and its fate; • Monoid, Group, Groupoid, Category, Monomorphisms, Epimorphisms, Isomorphisms, show it on sets and monoids; Scala (Java) category • terminal object, initial object; products, unions; show code samples; equalizers, code samples; notation {x|f(x)==g(x)}; pullbacks, sql • functors examples (diagrams; product; exponentiations); currying/yoneda lemma; example with integers/rationals; monad?
  • 3. What you have to know • first-order logic; quantifiers (see COEN260 slides) • some set theory; binary relationships, currying; injection/surjection/bijection (see COEN260 slides) • some intro to intuitionistic logic (see COEN260 slides) • javascript or java or scala
  • 4. Formal Methods • Need them in: o medical devices o space o military o communications • Don’t need them in: o social networks o ads and sales o startups
  • 5. Example of Algorithm Proof Euclidean Algorithm: Find GCD(a,b), where a and b are two natural numbers. 1. If a < b, use the fact that GCD(a,b)=GCD(b,a) 2. GCD(a,0) = a; done. 3. GCD(a,b) = GCD(a-b,a) 4. Repeat until done. Proof: A. Prove that GCD(a,b)=GCD(b,a) B. Prove that GCD(a,0) = a C. Prove that GCD(a,b) = GCD(a-b,a) D. Prove that it takes not more than 2*max(a,b) steps.
  • 6. You are asked to double a cube Have a cube, V=x3 Build a cube of size 2*V, using a divider and a ruler Informally: approximate; we only have doubles in Java. Formally: have to calculate √3(2) The thing is: You Can’t
  • 7. A similar problem Need an algorithm to find roots of a 5th degree polynomial Explanation: 5 roots, S5 is the group of all permutations, and it cannot be represented via a chain of +/- symmetries. x5-x+1 = 0
  • 8. Gödel’s First Theorem Meaning, if we have a theory T, we can always come up with a statement in T that cannot be proved. How? • enumerate all sentences; then all proofs. • isProvable(n) ≡ ∃F (n=#(F) ∧ F is provable) • (diagonal lemma) ∀F ∃p (p ↔ F(#(p)) • how about p ↔ ¬isProvable(#(p)) A theory that contains arithmetics cannot be at the same time consistent and complete.
  • 9. Entscheidungsproblem Is there an algorithm that, given a first-order theory, takes a statement and checks whether the statement is true? (The essence of the proof of program validity.) The answer is: NO Church proved that there is no computable function which decides for two given λ calculus expressions whether they are equivalent or not. Turing proved that it reduces to Halting Problem
  • 10. Halting Problem Given a program, can we decide if it ever ends? Answer: NO http://ro-che.info/ccc/03
  • 11. Collatz Conjecture function(n) { while (n > 1) { println(n); n = n%2==0 ? n/2 : (3*n+1) } } E.g. 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2, 1 Will it ever stop? Nobody Knows.
  • 12. So, what can we do? • limit ourselves by only provable algorithms • count on the finiteness of the universe (is it finite?) • count on the finiteness of time (is it finite?) • write some unittests and pray (is it a formal method?!)
  • 13. Unittests • You cannot prove the program is right, but you can find errors • Can cover main and corner cases • Can check behavior independently from environment • Can feel safe doing refactorings Some people tried to formalize unittest creation (agitar.com) (see e.g. halting problem) Question: can you write a unittest for random numbers generator?