402_reading_material_1
402_reading_material_1
3.
5. Given an alphabet ∑={a, b,c,d} construct: Design an NFA over ∑ that accepts any
string in which baba is a sub-string.
Answer:
c,d
a,c,d b
b a b a
S S S S
0 1 S5
3 4
a,c,d b,c,d b
S a,c,d
2
Answer:
The name of the schema is Enrolok. The operation that will occur in this schema will
change the state of the schema “class”, that why it carries the delta symbol. The
input variable is student. The ? shows that is the input variable. The output variable is
response. The ! shows it’s an output variable. Now, the operations. We first check if
the student we are adding to the list of student is already a registered student. If its
2
not, then we check in the next line if the number of student that can be enrolled is not
up to the required size. Then we add the new student to the list of students using the
union operation. The tested is updated and the operation return success as our output
variable.
But in summary, you can just say “we are adding a new student to the list of students
but we have check if the student already belong to the students and the size hasn’t
met max. The operation if successful returns success.”
7. A video renter wants to computerize his shop. The database must keep a record of all
videos in the shop. The system must provide a possibility of performing and
accounting for daily activities such as renting a video or returning a video. Propose a
state schema for the system.
returned) ∨
d) Remove booked
a video Answer:
success) ∨
(video? ∉ videos ⋀ report!=video not in list )
8. a)
Ξ What is the difference between Verification and Validation?
(video? ∈ BOOKED ⋀ report! = booked) ∨
Videorenter video?: VIDEO report!: MESSAGE
Answer:
(video? ∉ BOOKED ⋀ report!= not booked)
3
Verification involves checking that the system matches its specification I.e building
the right system while Validation is checking that the specification reflects intention
of the user I.e building the right system.
Pk = false
wp = p1 V p2 V………v pk
wp = x = - 5
Using the appropriate quantifiers, express the statements.
∃x (Student(x) ∧ Hardworking(x))
iv. “some students are hardworking”
5
Consider the machine
4.
6.
The set of alphabets for the above DFA is
A. {a,b}
B. {0,1}
C. {10,01}
D.{a,b,c}
A. class
B. response
C. enrolled
D. student
A. class
B. response
C. Enrolok
D. student
8
FORUM DISCUSSION
Models
1. Turing machine
2. Finite automata
3. Formal language
4. Pushdown automata
5. Regular expressions
6. Z
Turing machines
A turing machine is an accepting device which accepts the language generated by 0
grammars. Alan turing in year 1936 invented. It was an attempt to formalize
computation[lamda-calculus, recursive function, concept of computability]. TM is a
universal model of computation.
TM is a mathematical model which of infinite length tape divided into cellson which
input is given, read/write from left to right.
Church thesis says that any real world computation can be translated into an
equivalent computation using a turing machine.
Chruch thesis was invented by Alonzo chruch. It identifies effectively calculable
functions. Chruch believes that, lets M be a method or procedure,and is refered to as
effective will have some set of instructions, produce the desired result when
processed with error and carried out in a human being manner.
The TM is defined using 7-tuples. check it up in your material.
Summary of TM
1. Any mathematical computation can be peformed by a turing machine
2. For every computation problem, there is a corresponding TM
3. If there is no TM that decides the problem P, that means there is no algortithm that
can solve it
Functions of a TM
1. Write a symbol
2. Read a symbol
3. Transit to next state
Parts of the TM
1. head
2. state register
3. input tape
2 Types of TM
1. deterministic
2. non-deterministic
9
Non-deterministic Turing Machine
A non-deterministic Turing machine is one that uses the concept of non-determinism to calculate a
solution to a problem. A non-deterministic Turing Machine differs from a deterministic Turing
Machine in the sense that a non-deterministic Turing Machine can have several possible states to
which it can transition from any given state.
10
Refinement: is the inverse of hoare logic where A and S is processed to get Q. The proper subset
symbol is the symbol for refinement.
Laws of Refinement
1. Safety- precondition for S statement must be acceptable for precondition. We need a weak
precondition.
2. Livens- The behavior of I-implementation must be allowed by S. We need strong post condition.
Definition of Hoare logic
The Hoare triple is made of {P} A {Q}. This triple means: If P is true in the initial state and A
terminates then Q will hold in the final state.
Why is Hoare logic partially correct?
Hoare logic expresses partial correctness in a very elegant way. We say a program is partially
correct if it gives the right answer whenever it terminates. This implies that such system never gives
a wrong answer, but it may give no answer at all.
WP Definition
The wp Function: If Q is a predicate on states and S is a code fragment, then the weakest
precondition for S with respect to Q is a predicate that is true for precisely those initial states from
which:
i. S must terminate, and
ii. executing S must produce a state satisfying Q.
11
Z to be discussed in next class.
Refinement
Refinement is the inverse of hoare logic where A and S is processed to get Q. The
proper subset symbol is the symbol for refinement.
Refinement is a process of refining a specification S to an implementation Z by
applying a series of transformationss.
Specification to Refinement to implementation to code
Laws
1. Safety- precondition for S statement must be acceptable for precondition. We
need a weak precondition
2. Liveness- The behavior of I-implemantation must be allowed by S. We need
strong postcondition.
NOTE- Weak precondition is needed so as the operation suceed in many states.
While strong postcondition is required to avoid ambiguity.The importance of
refinement is to ensure correctness of a software is checked sucessfully. Refinement
is difficult, expensive and some real life examples cannot be expressed which are
limitations of it.
Verification involves checking that the system matches its specification i.e
buildng the system right while Validation is checking that the specification
reflects the intention of the user [owner of the system] i.e building the right
system. Dear students, drop an assumed insights where a system passes the
verification test but fails to pass the validation test.
However, when it comes time to validate the system with the end-users the customers
who will actually be using the platform issues begin to arise. Despite meeting the
technical specifications, the system fails to meet the users' expectations and needs.
12
For example, the verification process may have ensured that the checkout process
functions correctly, with all payment methods integrated seamlessly. However,
during validation, users may find the checkout process confusing and cumbersome,
leading to frustration and abandoned carts.
This statement '?x, friends[x] ? ¬perfect[x]' can also be written using universal
quantifier as:
ANSWER:
'?x, friends[x] ? ¬perfect[x]' can be rewritten using the universal quantifier (?):
14
?x, friends[x] ? ¬perfect[x]
This means that for all x, if x is friends with someone (friends[x]), then x is not
perfect (¬perfect[x]).
NEXT:
Natural Deduction
introduction I elimination E
Introduction and Elimination
P Q PNQ
PNQ P Q
implication
intro P Q elimination
P implies Q p implies Q, P
Q
negation
intro P, q n -q elimination -p, -q n q
-p P
3 eg 1
p n q= q n p 1. P N Q
2. P EN 1
3. Q EN 1 4. Q n P In 2 and 3
eg 2
P implies Q,Q implies R = P implies R
4 1. P implies Q
2. Q implies R
3. P Ass.
4. Q E implies, 1 and 3
5. R E implies, 2 and 4
6. P implies R I implication, 3 and 5
eg 3 p implies Q, Q implies R = p implies [Q n R]
1. p implies Q
2. Q implies R
3. P Ass
4. Q E implication, 1 and 3
5. R E impication, 2 and 4
6. Q n R I and , 4 and 5
7. p implies[Q n R] I impication, 3 and 6
eg 4
P, p implies q = P n Q
15
1. P
2. P implies q
3. Q E implication, 1 and 2 4. P n Q I conjunction, 1 and 3
eg 5
P = Q imples P
1. P
2. Q ass
3. Q implies P I implication, 1 and 2
eg 6 p implies Q, not Q = not p
1. P implies Q
2. not Q
5 3. P ass
4. Q E implication, 1 and 3
5. Q n -q nI, 2 and 4
6. -p not I, 3 and 5
6 eg 7
P V [Q N R] = P V Q
1. p v [q N R]
2. P ass
3. q n R
4. Q n E, 3
5. p v q VI , 2 and 4
NEXT
Hoare logic
assignment
statement
sequencial
conditional loops
P A Q p- precondition A- statement
Q-postcondition
[P] y =x +2 [y >10]
[x + 2 > 10] y =x + 2 [y >10]
[x > 10-2] y =x + 2 [y >10] [x > 8] is the precondition
Assignment statement [Q[e]]x = e[Q[x]] eg 1 [P] x=y +3 [x >3]
[y +3 > 3] x=y +3 [x >3]
[y >0] x=y +3 [x >3] [y >0] is the precondition
eg 2 [P] x=x +1 [x >5]
[x+1 > 5]x =x +1 [x >5]
[x>4]x =x +1 [x >5]
[x >4] is the precondition eg 3 x= x + b +1 [ b=2 AND x=y + b] [ b=2 AND
x + b +1=y + b]
[ b=2 AND x =y + b -b -1]
[ b=2 AND x =y -1] is the precondition
16
Sequencing
[p]s1[Q] [Q]s2[R] [P]s1s2[R]
eg 1 x= x + 5; y =x-2[ y >0] x = x + 5; [ x-2>0] y= x-2 [ y >0]
[ x-2>0] x = x + 5; y= x-2 [ y >0]
[ x + 5-2 >0] x = x+ 5; y= x-2 [ y >0] [x > -3] is the precondition
eg 2 x=x + 1; x = x * x [ x ≥ 16] x=x + 1; [ x * x ≥ 16 ]x = x * x[ x ≥ 16]
[ x + 1 * x + 1 ≥ 16 ]x=x + 1; x = x * x[ x ≥ 16]
[[x + 1]2 ≥ 16]
a2 > b2 = [a > b] v [a < -b]
[[x + 1] 2 ≥ 4 2] a =x + 1 b =4
[x + 1 ≥ 4] v [x +1 ≤ -4]
[x ≥ 4-1] v [x ≤ -4 -1]
[x ≥ 3] v [x ≤ -5] is the precondition conditional statements
[P] if[condition]
statement1; else
statement2; [Q]
if-else b-condition [p and b ] s1 [Q] [p and `b ] s2 [Q]
eg 1 [x >2] if [x >2] then y=1; else y=-1 [y >0] [x >2 and x >2 ] y=1 [y >0]
-------- i
[x >2 and x≤-2] y=-1 [y >0] ------------ ii
`[x >2] = x≤-2
T and T = T
T and F = F
[x >2] y=1[y >0] -------- i [F] y=-1 [y >0]---------------ii
x >2 is the precondition
Loops
[P] while [b] do s1 s2
[Q]
invariant- a condition that never changes inside the loop
inside the loop [ b and p] s1s2 [p]
when the loop terminates = post condition Q
[p and `b]
Hoare logic is partial correct because it says nothing about termination.
Strengthening a precondition
[p]S[Q] S implies p [s]S[Q]
weakening a postcondition
[p]S[Q] Q implies w
[p]S[w]
NEXT
Using inference rule, what is the value of Q given that P ^ Q and P are true?
ANSWER
To infer the value of Q given that P ? Q and P are true.
17
18
Given:
1. P ? Q = T
2. P = T
P Q P?Q
TTT
Therefore, Q is True.
NEXT:
true 1 false 0
7 Conjunction [and]
p q p and q
T T T
T F F
F T F
F F F
8 Disjunction [or]
p q pvq
T T T
T F T
F T T
F F F
9 Negation [not]
p not p
T F
F T
10 Implication
p[IT RAINS] q[THE SOIL GETS WET] p implies q
T T T
T F F
F T T
F F T
when all the variables evaluates to true we have a tautology Contradiction is when all
the variables evaluates to false
Contigency is when you have variables to be true or false
order of priority in logic
1. not
2. and
3. or
4. implies
5. equality
eg 1
-p V q implies r n s
[not p]
19
[r n s]
[not p V q]
General format ∀x.p(x) => q(x) ∀ is the universal quantifier p is the domain q is the
11
All cosc402 students registered for the course p = cosc402 students q = registered
∃x ∈ D,P(x)
Existential quantifier
∃x E students, rich(x)
some students are rich
∃x ComputerScienceStudents(x) → Rich(x)
Conversion from universal quantifier to existential quantifier not all = some
12 Set theory
U=[1,2,3,4,5] A=[1,2] B=[2,3,4] union= [1,2,3,4] intersection = [2] complement=
A`=[3,4,5] B`=[1,5] cardinality = lAl = 2 lBl = 3
Cartesian product A X B =[1,2,3,4] power set[A] = [ [], [1], [2], [1,2]] power set[B]
= [[],[2],[3],[4],[2,3],[2,4],[3,4],[2,3,4]]
power set = 2 power n
A=2 4
B= 3 8
13 Soundness and Completeness
Sound system does not produce any bad results
Complete system can produce all the good results
Consistent system is a system that is always there and it does not produce result with
ambiguity.A consistent system does not produce conflicting results.
14 Inference rule
eg1
1. p v q T
2. not p F
What is the value of q
p v q = pvq F v T = T eg 2
1. p→q T 2. P T
what is q[true or false] q is true
20