STM Unit 3
STM Unit 3
UNIT-III
Topics:
Paths, Path products and Regular expressions: Path products &
path expression, reduction procedure, applications, regular
expressions & flow anomaly detection.
Logic based testing: overview ,decision tables,path
expressions,kv charts,specifications
Path Products & expressions
PURPOSE: APPLICATIONS
1.How many paths in a flow-graph?
graph)
Return)
Path Products & expressions
Path Expression:
Regular Expression:
1 2 3 4
a b d
Path Expression
Simply: Derive using path products.
c
1 2 3 4
a b d
Example:
+ abcbcbd + ….
Path Products & expressions – Path Expression
Example:
g
h i
e f j
a b c d
Path Products & expressions – Path Expression
Example:
h i
e f j
a b c d
•Loops:
•Identity element
a0 = 1 X0 = 1 (path of length
0)
Path Products & expressions – Path Product
Path Product
• Associative
A ( BC ) = ( AB ) C = : Rule
ABC 1
Path Products & expressions – Path Product
• Commutative
X +Y = : Rule
Y + X 2
• Associative
(X+Y)+Z = X+(Y+ : Rule
Z) =X+Y+Z 3
• Distributive
A ( B + C) = AB : Rule
+AC (A+B)C 4
= AC+BC
Path Products & expressions – Path Products
• Absorption: If X and Y denote the same set of paths, then the union of these sets is
unchanged
X +X =X : Rule 5
X + any subset of X = X
X = a + bc + X + a = X + bc + abcd =
abcd X
Example:
if X=a+ aa+ abc+abcd+def
X+a=X+aa=X+abc
Path Products & expressions – Path Products
• Loop:
b
An infinite set of parallel
paths. a c
b* = b0 + b + b + b + ……
1 2 3
X*
= X0 + X1 + X2 + X3 + ……
X+
= X1 + X2 + X3 + ……
• X X* = X* X a = a* a
X+ a+
= =
a*
X = X0 + X + X
n 1 2
+ X3 + …… + Xn
Path Products & expressions – Path products
More Rules…
X m + Xn if n ≥ m : Rule 6
Xn
= if n < m
= Xm
m n = Xm+n : Rule 7
X X
Xn X* = X* Xn X* : Rule
= 8
Xn X+ = X+ Xn X+ : Rule
= 9
X* X+ = X+ X* X+ : Rule
= 10
Path Products & expressions – Path products
Identity Elements ..
1 : Path of Zero
Length
1+1 = 1 : Rule 11
1X = X1 = X : Rule 12
1
n = 1n = 1* = 1+ = 1 : Rule 13
1 +
+ = 1* = 1 : Rule 14
1
Path Products & expressions – Path products
Identity Elements ..
0 : empty set of
paths
X +0 = 0+X : Rule
=X 15
X = 0X = 0 : Rule
0 16
0* = 1 + 0 + 02 + 0 3 + . . . = 1 : Rule
17
Path Products & expressions – Reduction Procedure
8. IF there’s just one node between entry & exit nodes, path expression for
the flow graph is the link’s path expression. ELSE, return to step 4.
Path Products & expressions – Reduction Procedure
• is not unique
• Removes nodes one by one till there’s one entry & one
exit node.
a c a b*c
1 2 1 2
d b*d
Path Products & expressions – Reduction Procedure Example
a b c
1 2 3 f4 5
d
e
bd
a bc f
1 2 4 5
a (bd)* bc f
1 2 4 5
e
Path Products & expressions – Reduction Procedure Example
Processing of Loop Terms:
a (bd)* bc f
1 2 4 5
a (bd)* bc f
1 4 5
e (bd)* bc
a (bd)* bc ( e (bd)* bc ) *
1 4 f 5
a (bd)* bc ( e (bd)* bc )* f
Two ways of loop removal:
Example of reduction procedure:
a(bgjf)*b(c+gkh)d((ilhd)*imf(bjgf)*b(c+gkh)d)*(ilhd)*e
Path Products & expressions – Reduction Procedure Example
Identities
graphs (routines)
Path Products & expressions – Identities / Rules
(A+B)* = ( A* + B* ) * : I1
= ( A* B* )* : I2
= ( A* B )* A* : I3
= ( B* A )* B* : I4
= ( A* B + A )* : I5
= ( B* A + B )* : I6
(A+B+C+...)* = ( A* + B* + C* + . . . )* : I7
= ( A* B* C* . . . )* : I8
A B A, B
Proces
s
A B A B
IF THEN .. ELSE ..
A B
WHILE .. DO ..
Path Products & expressions – Structured Flow Graphs
Structured flow graph transformations
A B A, B
REPEAT .. UNTIL ..
Properties:
• No cross-term transformation.
• No GOTOs.
• No entry into or exit from the middle of
a loop.
Path Products & expressions – Structured Flow Graphs
Some
examples:
f
d
b
a b c d e
a c g i
e h
j
Path Products & expressions – UNstructured Flow Graphs
Some examples – unstructured flow
graphs/code:
X
Jumping into loops
X
Jumping out of loops
A: The flow graph should be annotated by replacing the link name with the maximum of
paths through that link (1) and also note the number of times for looping.
B: Combine the first pair of parallel loops outside the loop and also the pair in the outer
loop.
C: Multiply the things out and remove nodes to clear the clutter.
Alternatively, you could have substituted a "1" for each link in the path expression and
then simplified, as follows:
a(b+c)d{e(fi)*fgj(m+l)k}*e(fi)*fgh
= 1(1 + 1)1(1(1 x 1)31 x 1 x 1(1 + 1)1)41(1 x 1)31 x 1 x 1
= 2(131 x (2))413
= 2(4 x 2)4 x 4
= 2 x 84 x 4 = 32,768
Calculating the Probability
Weights, Notations and Arithmetic:
Probabilities can come into the act only at decisions (including decisions associated with loops).
Annotate each out link with a weight equal to the probability of going in that direction.
For a simple loop, if the loop will be taken a mean of N times, the looping probability is N/(N + 1)
In this table, in case of a loop, PA is the probability of the link leaving the loop and PL is the probability of
looping.
The rules are those of ordinary probability theory.
If you can do something either from column A with a probability of P A or from column B with a probability
For the series case, if you must do both things, and their probabilities are independent (as assumed),
then the probability that you do both is the product of their probabilities.
For example, a loop node has a looping probability of P L and a probability of not looping of PA, which is
obviously equal to I - PL.
and I respectively.
Path abcbcbcdeabddea would have a probability of 5 x 10-10.
Long paths are usually improbable.
MEAN PROCESSING TIME OF A ROUTINE:
Given the execution time of all statements or instructions for every link in a flowgraph and
the probability for each direction for all decisions are to find the mean processing time for
the routine as a whole.
The model has two weights associated with every link: the processing time for that link,
denoted by T, and the probability of that link P.
The arithmetic rules for calculating the mean time:
25x0.3+40x0.7 = 35.5
20x0.95+300x0.05 = 34
Fig 1
Fig 2
12+8=20
8+5=13
Fig 4
10+35.5+16=61.5
Fig 3
Fig 4
(20x0.6)/(1-0.4) +53 = 30
(0.4x5/1-0.6)+8=13
116x0.3/(1-0.3)=49.714
PUSH/POP, GET/RETURN:
This model can be used to answer several different questions that can turn up in debugging. It can also help decide which
test cases to design.
The question is:
“ Given a pair of complementary operations such as PUSH (the stack) and POP (the stack), considering the set of all possible
paths through the routine, what is the net effect of the routine? PUSH or POP? How many times? Under what conditions?”
Here are some other examples of complementary operations to which this model applies:
GET/RETURN a resource block.
OPEN/CLOSE a file.
START/STOP a device or process
G(G + R)G(GR)*GGR*R
= G(G + R)G3R*R
= (G + R)G3R*
= (G4 + G2)R*
This expression specifies the conditions under which the resources will be balanced on leaving the routine.
If the upper branch is taken at the first decision, the second loop must be taken four times.
If the lower branch is taken at the first decision, the second loop must be taken twice.
For any other values, the routine will not balance. Therefore, the first loop does not have to be
instrumented to verify this behavior because its impact should be nil.
Regular Expression & Flow anomaly Detection
The generic flow-anomaly detection problem (note: not just data-flow anomalies, but any flow anomaly) is
that of looking for a specific sequence of options considering all possible paths through a routine.
Let the operations be SET and RESET, denoted by s and r respectively, and we want to know if there is a SET
followed immediately a SET or a RESET followed immediately by a RESET (an ss or an rr sequence).
EXAMPLE: Let A, B, C, be nonempty sets of character sequences whose smallest string is at least one character
long.
Let T be a two-character string of characters. Then if T is a substring of (i.e., if T appears within) ABnC, then T
will appear in AB2C. (HUANG's Theorem)
As an example, let
A = pp
B = srr
C = rp
T = ss
Boolean algebra is the way to work with logic – simplification & calculation.
Hardware logic testing – hardware logic test design tools and methods use logic & Boolean
algebra.
Hardware design language compilers/translators use logic & Boolean algebra.
Impact of errors in specifications of a software is high as these are first in and last out.
So, higher level language for specs is desired to reduce the number of errors.
• Indifferent Condition
– Condition whose value does not affect which action is taken for two
or more rules
• Standard procedure for creating decision tables
– Name the condition and values each condition can assume
– Name all possible actions that can occur
– List all rules
– Define the actions for each rule
– Simplify the table
Complete decision table for payroll system example
Constructing a Decision Table
• PART 1. FRAME THE PROBLEM.
– Identify the conditions (decision criteria).These are the factors that will influence
the decision.
• E.g., We want to know the total cost of a student’s tuition. What factors are
important?
A B A+B(OR)
T T T
T F T
F F T
F F F
Rules of a Boolean Algebra
The following ‘rules’ are satisfied for all elements x, y& z of B:
(1) x + y = y + x (commutative )
x× y = y × x
(2) x + (y + z) = (x + y) + z (associative )
x × (y × z) = (x × y) × z
(3) x × (y + z) = (x × y) + (x × z)
x + (y × z) = (x + y) × (x + z) (distributive)
(4) x + 0 = x (identity )
x×1=x
(5) x + x' = 1 (inverse)
x × x' = 0
Laws of Boolean Algebra
• In addition to the laws given by the rule of Boolean Algebra, we can show the
following laws
Thus (x' × y) + (x × y) = y
Boolean Notation
• This means that in effect we’ll be employing Boolean Algebra
notation.
• The truth tables can be rewritten as
Notational Short-cuts
(1) In ‘multiplication’ we’ll omit the symbol ×, & write xy for x × y (just as in ordinary
algebra)
(2) The associative law says that
x + (y + z) = (x + y) + z
So we’ll write this as simply x + y + z, because the brackets aren’t necessary.
Similarly, write the product of 3 terms as xyz
(3) In ordinary algebra, the expression
x + y × z means x + (y × z), because of the convention that multiplication takes
precedence over addition.
e.g. x + yz means x + (y × z), and not (x + y) × z
Similarly, ab + cd means (a × b) + (c × d)
Reducing Boolean Expressions
• Is this the smallest possible implementation of this expression? No!
x y F
y y
x 0 x 0 0 0
1 x’y
0 x’y’ 1 1
0 1 1
1 xy’ xy 0 1
1 0 0 1
1 0
0
1 1
0
Karnaugh maps
• Easy to convert between truth table, K-map, and SOP.
and-or form. x
y 0
1
1 1
0
0 0
1
Rules to consider
00 1
1 00 1
1 F=AB +A B +AB
A11 0 F=AB A11 1
+ A ’B
• Three variable maps. F=A+B
BC
00 01 11
A 10 1 0
00
11 1 1 F=A+B C +BC
1
F=AB’C’ + A B C +ABC + A BC + A’B’C +
More Karnaugh Map Examples
a a
Examples b 0 b 0
0 0 1 0 1 1
1 01 1 1 01 0
f=a g = b'
ab ab
c 00 01 11 10 c 00 01 11 10
0 0 0 1 0 0 0 0 1 1
1 0 1 1 1 1 0 0 1 1
cout = ab + bc + ac
f=a
2. Identify the predicates on which the cases are based. Name them with
suitable letters, such as A, B, C.
3.Rewrite the specification in English that uses only the logical connectives
AND, OR, and NOT, however stilted it may seem.