Formal Methods
Formal Methods
Development
Page | 1
Software Development
When creating a software there are few engineering stages that is normally be
followed to ensure that they software is built within the time and budget. These
stages collectively are called the software development life cycle (SDLC).
1. Initial Study
This is the first time the system development team meets the clients to
collective information regarding the problem. Normally this stage delivers
the proposal and quotation to the clients.
2. Analysis
After the client has agreed to the proposal and price, the team will go in
and study the current system with the intention to discover the source of
the problem. The System analyst will use diagrams and data collection
techniques (observation, inspections, interview, etc) to aid them. Normally
this stage delivers a report stating the source of the problem and more then
one alternative solutions.
3. Design
After the client agrees with the analysis findings, the client will choose one
(1) solution. From this one solution the system designer will create the
specification. Take note that different IT section will require different
specification. For the software section, the deliverables will take the form
of a screen design, logic design, representation of the codes, etc.
4. Development
Base on the given specification, the respective IT section will develop the
solution. For the software section, the deliverables will be a full running
software program created from the specification.
5. Testing
The test documents (Test Plan and Test Case) are normally created by the
System Analyst during the development stages. The tester (normally a 3rd
party) will use the Test Plan and Test Case to complete the testing. The
deliverables will be a letter from the tester stating the outcome of the test.
6. Implementation
At this stage onward the software is no longer a concern, the main objective
now will be to prepare the environment. The implementation plan will list
the tasks necessary to prepare the environment to accept new software,
such as installation, training, conversion of data, change over method, etc.
There are many deliverables here depending on what is listed in the
implantation plan. For example for user training a user manual is normally
created.
7. Review
This is the final stage where the software user and team will sit down to
review the software performance and to decide negotiate on the
maintenance contract. If all goes well normally but not necessary a sign
off letter will be the last deliverables.
Formal Method
Formal methods in software engineering or development are mathematical
techniques that are used in the design, implementation and testing of computer
systems. The application of
mathematical methods in the development and verification of software is very
labor intensive, and thus expensive. Therefore, it is not feasible to check all the
wanted properties of a complete
computer program in detail.
Formal method will also bring to light all different probable perspective to any
given variables and functions that could have been hidden behind the English
language.
This can be done using a number of formal languages such as Z notation, VDM,
Algebra, Functional Programming, etc.
Page | 3
Creating software need not use formal method, having said that, having formal
method imbedded into the SDLC does give the software huge advantages and
also a new set of disadvantages
Specification
Formal methods may be used to give a description of the system to be
developed, at whatever level(s) of detail desired. This formal description can be
used to guide further development activities additionally, it can be used to
verify that the requirements for the system being developed have been
completely and accurately specified.
The need for formal specification systems has been noted for years. In the
ALGOL 58 report, John Backus presented a formal notation for describing
programming language syntax, later named Backus normal form then renamed
Backus–Naur form (BNF).
Development
Once a formal specification has been produced, the specification may be used
as a guide while the concrete system is developed during the design process
(i.e., realized typically in software, but also potentially in hardware). For
example:
•If the formal specification is in an operational semantics, the observed
behavior of the concrete system can be compared with the behavior of the
specification (which itself should be executable). Additionally, the operational
commands of the specification may be amenable to direct translation into
executable code.
•If the formal specification is in an axiomatic semantics, the preconditions and
postconditions of the specification may become assertions in the executable
code.
Verification
Once a formal specification has been developed, the specification may be used
as the basis for proving properties of the specification (and hopefully by
inference the developed system).
Human-directed proof
Sometimes, the motivation for proving the correctness of a system is not the
obvious need for reassurance of the correctness of the system, but a desire to
understand the system better.
Consequently, some proofs of correctness are produced in the style of
mathematical proof:
handwritten (or typeset) using natural language, using a level of informality
common to such proofs. A "good" proof is one which is readable and
understandable by other human readers.
Critics of such approaches point out that the ambiguity inherent in natural
language allows errors to be undetected in such proofs; often, subtle errors can
be present in the low-level details typically overlooked by such proofs.
Additionally, the work involved in producing such a good proof requires a high
level of mathematical sophistication and expertise.
Automated proof
In contrast, there is increasing interest in producing proofs of correctness of
such systems by automated means. Automated techniques fall into three general
categories:
•Automated theorem proving, in which a system attempts to produce a formal
proof from scratch, given a description of the system, a set of logical axioms,
and a set of inference rules.
•Model checking, in which a system verifies certain properties by means of an
exhaustive search of all possible states that a system could enter during its
execution.
•Abstract interpretation, in which a system verifies an over-approximation of a
behavioural property of the program, using a fixpoint computation over a
(possibly complete) lattice representing it.
Some automated theorem provers require guidance as to which properties are
"interesting" enough to pursue, while others work without human intervention.
Model checkers can quickly get bogged down in checking millions of
uninteresting states if not given a sufficiently abstract model.
Proponents of such systems argue that the results have greater mathematical
certainty than human produced proofs, since all the tedious details have been
algorithmically verified. The training required to use such systems is also less
than that required to produce good mathematical proofs by hand, making the
techniques accessible to a wider variety of practitioners.
Critics note that some of those systems are like oracles: they make a
Page | 5
pronouncement of truth, yet give no explanation of that truth. There is also the
problem of "verifying the verifier"; if the program which aids in the verification
is itself unproven, there may be reason to doubt the soundness of the produced
results. Some modern model checking tools produce a "proof log" detailing
each step in their proof, making it possible to perform, given suitable tools,
independent verification.
The main feature of the abstract interpretation approach is that it provides a
sound analysis, i.e. no false negatives are returned. Moreover, it is efficiently
scalable, by tuning the abstract domain representing the property to be
analyzed, and by applying widening operators to get fast convergence.
Formal Method forces the System Analyst and Designer to think carefully about
the specification as it enforce proper engineering approach using discrete
mathematics.
Formal Method forces the System Analyst and Designer to see all the different
possible states for any given variables and functions thus will avoid many faults
and therefore reduces the bugs and errors from the design stage onward.
Formal Method requires the person to know how to apply discrete mathematics.
It will obviously slow down the analysis and design stage resources and time
therefore also the cost of the project.
There are too many different formal methods and most of them are not
compatible with each other.
Critical software
Having known the advantages and disadvantages, most clients will see the
justification to use formal methods for critical systems, but this thinking is now
slowly fading as most clients realize the important and cost saving and
convenience of having a good specification initially in the SDLC.
Many organizations today require a combination of the above as such you may
have a business mission critical system, a business safety critical system, etc.
Page | 7
Integrity Level
Integrity level refers to how much cost is an organization is willing to spend and
how much risk is an organization is willing to take when developing software.
1. Formal Specification
This is where normal system specification is use and translated using a
formal language into a formal specification. There are basically two type
of formal language; Model Oriented (VDM, Z, etc) and Properties
Oriented (Algebraic Logic, Temporal Logic, etc). This is the cheapest way
to handle formal method.
iii. After statements are clearly identified. Then find all assumptions
(Things that must be in place before something can happen) that is
state or not stated within the clarified requirement.
iv. Then expose every possible logic defect (fault) or omission in the
clarified requirement.
v. Identify what are the exceptions (bad things) that will arise if the
defects are not corrected.
vi. Find a way to test for all the possible each exception. Only when
you can test for an exception can you be able to stop that exception
from happening.
2. Formal Proof
This level studies the formal specification and retrieves the goals of the
formal specific. Then fixed rules are created and with these rules step by
step instructions are listed to achieve the specified goals. This is relatively
cheaper but there are more task steps.
3. Model Checking
This level studies the formal specification and formal proof deliverables to
make sure that the system or software contains ALL possible properties to
be able to handle all possible scenarios that could happen for a given
specification. This stage is beginning to be more expensive.
4. Abstraction
This level uses mathematical and physical models to create a prototype of
the entire system for simulation. This prototype is use to focus on the
properties and characteristic of the system. This is the most expensive
formal method.
Remember that the deeper into the formal method means more time and resources
thus more cost will be incurred.
Page | 9
High Low Model Checking
Proposition is a declarative statement that can result in either true or false. The
statement must be a constant thus the value cannot change.
For example:
Statement Result
FTMS College KL is a college. True
FTMS College KL is not a college False
“liar paradox”
Since proposition is either true or false thus we can use a truth table to list down
all the position state of that proposition.
(A) Ali is a
boy.
T
F
With an NOT operator true becomes false and false become true.
A Result (⌐A)
T F
F T
Notice that this is actually two proposition join with the AND operator.
We see it as A ^ M
Possible value: true or false for A and possible value: true or false for M
With an AND operator both statement must be true then the join statement will
be true.
A M Result ( A ^
M)
T T T
T F F
F T F
F F F
Once we understand the above explanation we can use the same principal for the
remaining proposition operators.
A M Result ( A v
M)
OR T T T
T F T
F T T
F F F
A M Result ( A M)
T T T
Implies T F F
F T T
F F T
A M Result ( A M)
T T T
Equals T F F
F T F
F F T
A M Result ( AM)
Different T T F
T F T
F T T
F F F
(P Q) v (Q P)
P Q PQ QP Result (P Q) v (Q P)
T T T T T
T F F T T
F T T F T
F F T T T
Tautology a.k.a. Valid (the above example) happen when all the result in a true
table is TRUE.
Un-satisfiable a.k.a. Invalid (Q ^ ⌐Q) happen when all the result in a true table
is FALSE.
Satisfiable happen when at least one (1) truth value brings the TRUE result.
Contingent happen when at least one (1) truth value brings the TRUE result
and at least one (1) false value also brings the TRUE result ->
Predicates
Introduction to Predicate
But this is not practical as most statement actually contains variables and changes
in the variables will change the validity of the statement to true or false, because
some statement refers to a set of different elements.
Therefore we use predicate to handle such statement. For this subject we will use
First-Order Logic only.
To use predicate there must at least two (2) elements;
1. A variable or a constant
2. A function that performs the variable
For example:
An ostrich has wing can fly, a eagle has wing can fly
The constant object here is “Wing”
The variable object here is either “Ostrich” or “Eagle”
The function here is “Fly”
Constant / Function Result
Variable
Wing / Ostrich Fly(Wing, False
Ostrich)
Wing / Eagle Fly(Wing, Eagle) True
Predicate quantifiers
The following are quantifiers that can be use with a predicate;
Symbol Meaning Example
∃ Existential There exists some or
For some the elements
including itself
∀ universal For every element
For all the elements obviously
including itself
Qualifier is normally place with an object (variable or constant)
Assuming a function call fly with only one (1) set of object Airplane, therefore
using the above qualifier we can have two (2) different statements.
If we have two sets of Airplane (Plane A and Plane B) using the above “Fly
Faster” function we can have four (4) different statements. Plane A is denoted
as A and Plane B is denoted as B.
∀A ∀B Fly Faster (A, B) = All Plane A fly faster then All Plane B
∀A ∃B Fly Faster (A, B) = All Plane A fly faster then Some Plane B
∃A ∀B Fly Faster (A, B) = Some Plane A fly faster then All Plane B
∃A ∃B Fly Faster (A, B) = Some Plane A fly faster then Some Plane
B
If we have two sets of different object Boys and Girls using the above “Run
Faster” function we also have four (4) different statements. Boys is denoted as
B and Girls is denoted as G.
∀B ∀G Run Faster (B, G) = All Boys run faster then All Girls
∀B ∃G Run Faster (B, G) = All Boys run faster then Some Girls
∃B ∀G Run Faster (B, G) = Some Boys run faster then All Girls
∃B ∃G Run Faster (B, G) = Some Boys run faster then Some Girls
All the operators used with proposition can be use to join different predicates.
Predicate Example Symbol Meaning
⌐ Fly (Airplane) ⌐ Airplane cannot fly
Fly (Airplane) ^ Fly (Birds) ^ Airplane fly AND Bird fly
Fly (Airplane) v Fly (Birds) v Airplane fly OR Bird fly
Repair (Airplane) Fly Repair the airplane then airplane
(Airplane) will fly.
Repair the Car is the same as
Repair (Car) Repair(Bus)
Repair Bus
Repair the airplane is different
Repair (Airplane) Repair(Bus) from Repair Bus
Because the result of a predict function can be true or false therefore Truth tables
can also be use with predicates. For example:
The idea is related to a symbol that will later be replaced with Strings or values.
It can also be represented by a wildcard character that stands for an unspecified
symbol.
Base on the example, below:
But technically the left x and right x could mean something else but this will
cause a lot of confusion, thus the symbol on the left is usually kept in consistent
with the symbol on the right.
->
Sets
Introduction to Set Theory
Set is very basic mathematical concept use to group objects. It is basically used
to show the relationship between each type of objects. The Venn diagram is
always used to picture the set theory graphically. A set is a group that may contain
none or one (1) or more elements.
In formal methods, there are many ways to use set theory. One example will be
to categories many types of objects available in a system mostly in the form of
data. Base on the purpose of the particular system or software the objects are
properly grouped and then related to one another.
Universe (U)
The Universe represents the scope of the system. All elements that is within the
universe is considered necessary and elements not mentioned in the universe is
considered none existence. Thus it is very important that we define the universe
accurately.
U
Elements
All elements in a set must be unique. In the Venn Diagrams the individual small
letter element name are prefix with a dot. Capital Letter names is use to group
many duplicates elements (sets) do not have a dot. The sequence or arrangement
of the elements is not important.
A = {4, 2, 1, 3}
B = {blue, white, red, yellow} Finite Elements
Some elements may be finite (with a starting and ending value) thus it can be
representation as:
F contains a number power by 2 minus 4 such that (: or |) all the numbers are
integer starting from 0 to 19 is represented as
Or
Infinite Elements
Some elements may be infinite (no ending value) thus it can be representation as:
Or
Cardinality
For example
| {1, 3, 9, 15 } | = 4
| {1, 2, 3, . . .} | = ∞
Membership (∈)
Membership happens when one element or a set is found inside another set. This
symbol is normally used in describing a set for example
A = {4, 2, 1, 3}
B = {1, 2, 3, 4, 5, 6, 7, 8, 9, U
B
10} .5 .6 .7
.8 .9 1 .2 A
.10 .3.4
A ⊆ B and A ⊂B
Disjoint Sets
A = {4, 2, 1, 3} U A B
.1 .2 .5 .6
B = {5, 6, 7, 8}
.3 .4 .7 .8
If every member of set A has no relation with set B and vice versa then we say
that A disjoint B. There is no special symbol to show this relationship.
NULL Set ( ∅ )
Every universe or set or subset contains a NULL set. A null set is an empty
set ({ }) that carries no elements. We can say that the NULL set is a subset
for every set.
Family Sets
There are times when a set does not contain individual elements but it
contains many subsets. Conveniently this is call a family set and is it
describes using the curly bracket within a curly bracket.
Union (∪): Add in all elements that are found in both sets.
A ∪ B = {-1, 0, 1, 2, 4, 5, 6, 8, 9, 10}
A ∪ C = {-1, 0, 1, 2, 3, 5, 6, 7, 9, 10}
B ∪ C = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
A∪B ∪C=U
Intersect (∩): Show only elements that is found only in both sets
Difference (-): Also known as subtract, this show only elements that is found
in this set but NOT found in another sets
B - A = {4, 8} C - A = {3, 7}
Complement (‘): Show only elements that is found NOT found this sets
A’ = {3, 4, 7, 8} B’ = {-1, 0, 3, 5, 7, 9} C’ = {-1, 0, 2, 4, 6, 8, 10}
Equality: Both sets must have exactly the same number of elements with
exactly the same value. Take note that sequence and duplication does not
affect the set.
A=B=Y=Z
Compatible: Two sets are compatible if all element in one of the set can fit
nicely inside another set.
Sequence
A sequence is simply a list, such as 2, 4, 6, . where the numbers 2, 4, etc. are the
terms of the sequence.
Terms (usually represented with a subscript italic letter “n”) refers to the index
for a given sequence starting from 0 to infinite. The sequence (usually
represented with any small letter “a”) refers to the value for a specific term. For
example:
Terms n 0 1 2 3
Sequence (a) 0 2 4 6
an a0 a1 a2 a3
Type of sequence
Finite sequence
A finite sequence has both a starting value and an ending value.
E.g. 1, 2, 3, 4, 5 and 6
Infinite sequence
An infinite sequence has both a starting value but no ending value
E.g. 1, 2, 3, 4, 5, 6 …
Arithmetic sequence
Geometric sequence
Arithmetic sequence
Geometric sequence
Arithmetic sequence
Remember:
Average the first and last then multiply by the number of terms
Example:
Term 1 2 3 4 5 6 7 8 9 10
1 3 5 7 9 11 13 15 17 19
Given X = 1, 3, 57, 9, 11, 13, 15, 17, 19 calculate the sum of X10?
Term 1 2 3 4 5 6 7 8 9 10
4 16 64 256 1024 4096 16384 65536 262144 1048576
Given X = = 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576,
Calculate the sum of X?
Infinite sequence that start (the first term value must above 0)
S a
1- r
Example:
Term 0 1 2 3 4 5 6 …
4 16 64 256 1024 4096 16384 …
Given X = = 4, 16, 64, 256, 1024, 4096, 16384 … Calculate the sum of X?
Sum X ∞ = 4 / 1 –
->
PROOF
What is proof?
Proof simply means to be able to show that a statement is correct or true. No matter
how the statement is twisted and turned or set against many different scenario, that
statement comes up with the constant answer.
Before a statement can be proof it can have two (2); the conditions followed by the
result. For example, if it rain then I will be wet. This can then express in a using
proposition symbols as;
Terminology
1) Conjecture/ Hypothesis
2) Axiom/ Postulate
If the statement is taken for granted to be true even though it was never tested,
but base on logic it is assume to be true.
3) Paradox/ Antinomy
4) Theorem
5) Un-decidable
6) Lemma
Theorem that is reversed or turned upside down or inward out thus a converse
of a theorem need not be always true.
Four (4) common proofing methods
1. Direct Proof
In direct proof, the conclusion is established by logically combining the
axioms, definitions, and earlier theorems. From the expression one can
directly see the answer.
->
Testing
Revise SDLC
1. Get user requirement usually from the specification written in the natural
language.
3. After statements are clearly identified. Then find all assumptions (Things that
must be in place before something can happen) that is state or not stated within
the clarified requirement.
4. Then expose every possible logic defect (fault) or omission in the clarified
requirement.
5. Identify what are the exceptions (bad things) that will arise if the defects are
not corrected.
6. Find a way to test for all the possible each exception. Only when you
can test for an exception can you be able to stop that exception from
happening.
Testing stage
A test stage has only one (1) important purpose, that is to ensure that they
software solution built solves the problem as specified in the analyst report and
the specification.
Validation focuses on are we building the right solution and Verification focuses
on are we building the product correctly are two terms used a lot during testing.
No software is 100% bugs free and testing cannot guarantee that there are
no bugs, it can only ensure to a certain reasonable level that the system is able to
perform the task it was created to do. It does not mean there are no more bugs in
the system.
Once the testing is done, the tester will write a letter to give their opinion on the
testing and the test result.
This letter will be given to the SA who then decides the following action, which may
take the form of returning to:
1) The development stage where the programmer will debug the problem.
2) The design stage to redesign the specification then later continue to the
development stage.
3) Worst case scenario, to return to the Analyst stage to redo the analyst for that
given module which will then continue into the design and development stage
again.
The same test document is reuse when the software returns to the testing stage.
The SA may add in new test item in the test plan and new test case but the
previous test document must remain intact. The tester will then repeat the testing
for the failed modules and the new modules.
After a successful test, if there are future changes, the same test document is also
reuse, thus the test plan can be use to audit the changes to ensure changes do not
introduce new problem.
The test document consist of a test plan that list down all the test item, each test item
will then be reflected in one (1) or more test case.
For example; Test plan will have many test items. In one (1) of the test item there
is a test for the customer name. There may be three (3) test cases for that test item;
Test plan
A test plan is a document that state down clearly every step (test item) that will be
taken during testing, basically a systematic approach to testing a system.
The Test Plan is created first by the System Analyst (SA) using the Analyst and
Design deliverables. This is done during the development stage when the work
load has been transferred to the software programmers.
In order to create the Test Plan, the SA must understand the testing concept, because
the strategy applied by the SA can easily be seen in the test plan.
3. The date for the completion of each test plan no. One (1) test item can hold
many test cases and each test case has a different purpose.
The tested date is inserted only after ALL the test cases for one (1) test
item is successfully tested. If after the testing is done and the test plan date
remains blank means that the software fails the testing.
Test Case
After completing the test plan the SA will then created a test case. There will be
at least one (1) test case for each of the test in the test plan. Each test case can
contain only one (1) set of instruction and one (1) outcome.
There will always be a BLANK table inserted in the test case to be use by the tested
to fill in the result of that particular testing.
1. The test plan no to tally back to the test plan and a test case number for that
given test case.
2. The test instruction explains to the tester exactly how to run that particular
test.
3. The expected result for that given test usually with a simple screen design or
simple sentences to describe the result.
** Please state the successful date in the test plan when all test cases is done.
Testing Concept
Test Flow
1. Top Down
This is a test flow that starts from a general level down to the specific detail
level. Example for an inventory system will be to start from a main menu
and slowly make the way down to the product module.
2. Bottom Up
This is a test flow that starts from a detail specific level up to the general
level. Example for an inventory system will be to start from the products
and slowly make the way up to the main menu.
Test Size
1. Unit Testing
This is a test that focuses on an individual specific independent module.
Example for an inventory system will be to start test the products module
alone and then the customer module alone.
2. Integration Testing
This is a test that starts to join individual module. Example for an inventory
system will be after testing out the product and customer module to test
out the sales invoice module.
3. System Testing
This is a test that starts to studies the system environment surrounding the
software. Example for an inventory system will be to test if the bar code
reader at the POS can read the barcode label on the product.
4. User Acceptance Testing
This is the final a test where the end user will physically tested out the
system themselves using real life data but still in a control testing
environment. Example for an inventory system will be to ask the POS staff
to test out the POS system and enter 100 products and produce the correct
balance on the receipt.
Test Depth
1. Black box testing
This is commonly known as a validation testing. This is an effectiveness
test that is result base, input is given and output is produce and compared.
Example for an inventory system will be to scan a barcode label on the
product and see it appear on the POS interface with the correct total.
Other Test
1. Boundary Testing
This is a test done usually with a black box that can be done at the unit
testing or integration testing stage. The main objective of this test is to
make sure that the software can make the correct decision. All the possible
result and alternative value is determined for the condition. Then extreme
test data are generated to see if the software can produce a correct result.
2. Stress Testing
This is a test done usually with a black box, unit testing approach. The
main objective will be to break the system. Thus this test will take along
time as it will continue until the system breaks down. From the break
down, a safe level can be reach for contingency planning.
Formal method
Formal methods are a way to apply mathematically-based techniques to the
specification, development and verification of software for computer science or
software engineering. When Formal method is applied it is likely to produce a
more reliability and robustness specification design.
Formal Method stages consist of; Formal Specification, Formal Proof, Model
Checking and Abstraction.
Formal Specification
Formal Specification is the initial part of formal method that describes what the
system must do without saying how it is to be done. It is totally language
independent and focuses only on the abstract rather then detail logic.
A formal specification can serve as a single, reliable reference point for those
who investigate the customer's needs, those who implement programs to satisfy
and those needs, those who test the results, and those who write instruction
manuals for the system.
Useful for consistency checks, but formal methods cannot guarantee the
completeness of a specifications
For the majority of systems does not offer significant cost or quality
advantages over others
Formal Specification in the SDLC
Two (2) things are very important during requirement gathering; the data and
the process done on the data. Formal specification will be applied directly on
these things.
If formal Specification is use during the Analysis and Design stage, there is no
need to use them again. If formal specification is not used by the SA and SD
then the only window of opportunity to apply it will be during the pre-
development stage.
If no formal specification was ever applied, and it is applied in the testing stage,
this will expose a lot of possible bugs not catered for and the problem will loop
back to the design and possibly the analysis stage.
Analyst Stage
The main purpose of Analyze is to find the source of the problem. During
this stage the System Analyst (SA) would collect all the data and processes
(observation, document inspection, interview, etc…). The SA would then
express the requirements into some form of diagrams such as DFD or Rich
Picture, Use Cases and Case Diagram, etc…
Then the SA will write a report (in English – common natural language) to
indicate the source of the problem and some alternative solution.
When studying the current system the SA could apply proposition and
predicate to every client’s statement thus translating them into mathematical
equivalent. This will remove ambiguity and expose all possible hidden state
of the process and data. Proof is then use to be sure if the statement given by
the client is correct. The SA can also apply set theories and series to
categories and view data from different perspective. This is very helpful
when SA needs to understand how reports are generated.
By doing this the SA can be to a certain degree confident to cover all possible
alternative to a given statement.
Design Stage
The main purpose of Design is to find create a specification for the selected
solution. It should be stressed that, the specification will be use to built the
solution, thus a good specification will create a good software and a bad
specification will create a bad software.
During this stage the System Designer (SD) uses the analyze report to create
the specification. The SD also expresses their specification into some form
of diagrams sometimes similar to those used by the SA.
Before creating the specification the SD could translate all the natural
language found in the analyze report into mathematical equivalent
(proposition and predicates) that will remove all ambiguity and uncertainty.
Proof can be use here to ensure that every statement given is logically correct.
Set theories and series are use to categories and view data from different
perspective and to create relevant reports.
.
Then studying the mathematical form, the SD will be able to create the new
system environment and also the solution that can cater for all possible
scenario and state for each data and processes.
Development Stage
The main purpose of Development is to find built the solution base on the
specification. During this stage the Senior Programmer (SP) will study the
specification, create the relevant data structure, study the modules and
delegate the programming team to develop the solution.
To apply formal specification at this stage will be a bit late but a small
window of opportunity still exists.
During this stage the Senior Programmer (SP) will study the specification.
The SP could translate all the natural language found in the specification into
mathematical equivalent (proposition and predicates) that will remove all
ambiguity and uncertainty. Proof can be use here to ensure that every
statement given is logically correct. Set theories and series are use to
categories and view data from different perspective and to create relevant
reports.
The SP can then verify that the specification is complete before starting out
the development.
If there is any problem with the design, the SP will stop the development and
return the specification to the SD for correction. Worst case scenario, the
entire specification is drop and the system is reanalyzed.
Testing Stage
The main purpose of Testing is to make sure that the solution solves the
problem found in the analysis and created base on the specification. Before
this stage the (SA) will have already created the test plan and test case. In
this stage the tester will then use the test plan and test case to execute the
testing.
During this stage the SA will revise the specification built during by the SD.
The SA could then translate all the natural language found in the
specification into mathematical equivalent (proposition and predicates) that
will remove all ambiguity and uncertainty. Proof can be use here to ensure
that every statement given is logically correct. Set theories and series are use
to categories and view data from different perspective and to create relevant
reports.
After studying the specification, then the SA can create a Test Plan that will
cover all aspect of the system. Using what is learnt from the Formal
specification, the SA will be able to create a test case for each test item to
test out all the different exception.
If there is any problem with the testing, the SA will stop the testing and return
the specification to the SD for correction. Worst case scenario, the entire
specification is drop and the system is reanalyzed.
Notice that this will not return to the development, because development only
follows the specification created during the deign stage.
Typical languages
TYPE Stack
FUNCTIONS
new: ()→ Stack; -- Create new (empty) stack
push: (Stack, elem) →Stack; -- add an element
-- remove most recent element from
pop: Stack →Stack;
stack
top: Stack → elem;
-- returns most recent element
empty: Stack →bool;
-- true if stack is empty
full: Stack →bool;
-- true if stack is full
Why OCL?
❍ Making UML models more precise
● Specification of Invariants (i.e., additional restrictions) on
UML models!
● Specification of the semantics of operations in UML models
❍ Also usable as a language to query UML models
HR_management
...!
OCL expressions: invariants
❍ OCL expression may be part of a UML model element
❍ Context for OCL expression is given implicitly
❍ OCL expression may be written separately
❍ Context must be specified explicitly
Employee
personId: Integer {personID > 0}
name: String
firstName: String [1..3]
dateOfBirth: Date
/age: Integer
jobFunction: String
...
...
context HR_manangement::Employee inv:
self.jobFunction = “driver” implies self.age ≥ 18
Proving properties
With formal specifications, we can prove if a model has some required
properties (e.g., safety-critical invariants)!
❍ Classic proofs (usually supported by theorem proving software) establish
that a property can be inferred from a set of given logical statements
❍ Model checking explores the full state space of a model, demonstrating that
a property holds in every possible state!
– Classic proofs are still hard and labor-intensive!
+ Model checking is fully automatic and produces counterexamples in case of
failure
– Exploring the full state state space is frequently infeasible
+ Exploring feasible subsets is a systematic, automated test
● (2) ⇒If Ready to move has a token, Door open hasn’t one (3)
● (2) ⇒If Elevator moving has a token, Door open hasn’t one (4)
● If Door open has no token, Door closed must have one (5)
● (1) & (3) & (4) & (5)⇒ (P)
Z notation
Before you can write create a formal specification in Z notation you must
understand some basic concept and terminology.
Terminology and Concept
Data Refers to necessary data use in the system
Schema Refers to a structure that has two (2) sections the signature and
predicates.
The signature (top section) contents all the set proposition thus the
data, and variables.
Injections
Surjections
7 Partial Injection
This is a one-to-one mapping
between elements in the domain
and the range. The value in the
domain may differ from the
values in the range.
6 Total Injection
This is a one to many mapping
where the domain completely
populates the set.
3 Partial
surjections This is a one to many mapping
where the range completely
populates the set Y.
5 Bijections
one-to-one total injective and
surjective functions.
Birthday Book
known : NAME
birthday : NAME
DATE known = dom
birthday
Signature
We have a variable call known represents set NAME(s).
We have a variable call birthday represents set DATE.
Predicate
The known variable (set NAME) exists within a domain call
Birthday. We can also show the above using the elements in the set.
OR
Birthday Book
known = {John, Mike, Susan}
birthday = {John 25/3,
Mike 22/12, Susan 22/12}
known = dom birthday
birthday
known =
2. Then we create an operation, let us do “add new birthday”, this will also
uses a schema, we call it (operation schema).
Add Birthday
name? known
Signature
Remember previously we declared known is a domain of birthday.
means this is an operation schema for Birthday Book where the value in
birthday domain will change
We have a variable call name? represents set NAME(s). This value will
be input by the user.
We have a variable call date? represents set DATE. This value will be
input by the user.
Predicate
The name? must not be found in the known (domain of birthday)
Then we create an operation, let us do “edit birthday”, this will also uses a
schema, we call it (operation schema).
Edit Birthday
.
Birthday
Book name? :
NAME date? :
DATE
name? known
date = birthday (name?)
date’ = date?
Signature
Remember previously we declared known is a domain of birthday.
means this is an operation schema for Birthday Book where the value in
birthday domain will change
We have a variable call name? represents set NAME(s). This value will
be input by the user.
We have a variable call date? represents set DATE. This value will be
input by the user.
Predicate
The name? must be found in the known (domain of birthday)
The date! will be shown base from the birthday domain where the name?
is use as a parameter.
The date! will be updated with the new date? entered by the user.
Then we create an operation, let us do “delete birthday”, this will also uses
a schema, we call it (operation schema).
Delete Birthday
Birthday
Book name? :
NAME date? :
DATE
name? known
birthday’ = birthday - {name? date?}
Signature
Remember previously we declared known is a domain of birthday.
means this is an operation schema for Birthday Book where the value in
birthday domain will change
We have a variable call name? represents set NAME(s). This value will
be input by the user.
We have a variable call date? represents set DATE. This value will be
input by the user.
Predicate
The name? must be found in the known (domain of birthday)
The record with the name will be remove from the birthday domain.
Signature
means this is an operation schema for Birthday Book where no value
will change
We have a variable call name? represents set NAME(s). The value will be
entered by the user.
We have a variable call date! represents set DATE. The value will be
shown or listed by the operation.
Predicate
Remember previously we declared known is a domain of birthday.
The date will be shown base from the birthday domain where the name? is
use as a parameter.
Signature
means this is an operation schema for Birthday Book where no value
will change
We have a variable call today? represents set DATE(s). The value will be
entered by the user.
We have a variable call cards! represents a set function. The value will be
shown or listed by the operation.
Predicate
Remember previously we declared known is a domain of birthday.
Cards will contain all n, where n is the domain birthday and the date that
is birthday is part of the n must be equal to today.
Meaning, show all birthday that is today from the set of birthday dates.