Preliminaries: TAFL: Theory of Automata and Formal Languages
Preliminaries: TAFL: Theory of Automata and Formal Languages
Preliminaries: TAFL: Theory of Automata and Formal Languages
Preliminaries
Outline :
Inverse Function Unit no : 1
Introduction to
Relations Compiler
Mathematical Proof Techniques (01CE0504)
Languages
1 A A 1
2 B B 2
3 C C 3
f f -1
Steps required to find the inverse function:
Example Step 1: Replace f(x) with y
(Inverse Step 2: Swap x and y
Function) Step 3: Isolate/Solve for y
Step 4: Replace y with f -1(x)
Find the inverse function of f(x) = (x – 3)/2
Example y = (x – 3)/2
(Inverse x = (y – 3)/2
Function) 2x + 3 = y
2x + 3 = f -1(x)
Find the inverse function of f(x) = (3x2 – 7)/4 +5
y = (3x2 – 7)/4 +5
x = (3y2 – 7)/4 +5
Example
(Inverse (x – 5) * 4 = 3y2 – 7
Function) 4x – 13 = 3y2
(4x – 13)/3 = y2
sqrt[(4x – 13)/3] = y
sqrt[(4x – 13)/3] = f -1(x)
To verify that f −1 is really the inverse of f, we should
show that the composition of f and f −1 doesn't do
anything to the input.
In previous example, f(x) = (3x2 – 7)/4 + 5 and f -1(x) =
sqrt[(4x – 13)/3]
Check (f ∘ f -1)(x) Check(f -1 ∘ f )(x)
Inverse = f (f -1(x)) = f -1 (f(x))
Function = f(sqrt[(4x – 13)/3]) = f -1 [(3x2 – 7)/4 + 5]
= {3[(4x – 13)/ 3] – 7 }/4 + 5 = sqrt{[4((3x2 – 7)/4 + 5) – 13]/3}
= (4x – 20)/4 + 5 = sqrt{[(3x2 – 7) + 20 – 13]/3}
= x – 5 + 5 = sqrt{[3x2]/3}
=x = sqrt{x2}
=x
Let f : R → R be defined by f(x) = x2. Does this
function posses an inverse function?
For any real number x, f(x) and f(-x) results in same
value as f(x) = f(-x) = x2
Moreover, if x ≠ 0, then x and –x are two different
Example numbers, and f maps these two distinct numbers to
the same output value.
If output of f(x) was given as y = 4, there’s no way to
know if x = 2 or x = -2 was the input function.
Hence, function f doesn’t have inverse function
possible.
Let f : R+ → R be defined by f(x) = x2. Does this
function posses an inverse function? If so, find f -1.
In this case, we have restricted the domain to the
non-negative real numbers.
Example Hence, every distinct input value x ≥ 0 will yield a
distinct output value x2. For this function, we can find
its inverse.
y = f(x) = x2.
Hence, x = sqrt(y) and f -1(y) = sqrt(y).
Relations
Relations may exist between objects of the same set
or between objects of two or more sets.
A binary relation R from set x to y is written as xRy or
R(x, y), which is a subset of the Cartesian product x x
y.
Domain of R is the set {x | (x, y) ∈ R for some y in B}
Relations Range of R, is the set {y | (x, y) ∈ R for some x in A}
Example:
A= {1, 2, 3}
A x A = {(1,1) (1,2) (1,3) (2,1) (2,2) (2,3) (3,1) (3,2)
(3,3)}
“>” relation on A x A results in, {(2,1) (3,1) (3,2)}
We say ∼ is an equivalence relation on a set A, if it
satisfies the following three properties:
Equivalence a) reflexivity: for all a ∈ A, a∼a.
Relation b) symmetry: for all a,b ∈ A, if a∼b then b∼a.
c) transitivity: for all a,b,c ∈ A, if a∼b and b∼c then
a∼c
A = {1, 2, 3}
R = {(1,1) (1,2) (1,3) (2,1) (2,2) (2,3) (3,1) (3,2)
(3,3)}
Example {(1, 1) (2, 2) (3, 3)} is reflexive.
(Relation) {(2, 3) (3, 2) (1, 1)} is symmetric.
{(2, 3) (3, 2) (1, 1) (2, 2)} is symmetric and transitive.
{(1,2) (2,3) (1, 3)} is transitive.
Exercise:
1. A = {a, b, c}, R = {(a, b) (a, a) (b, a) (b, b) (c, b) (c, c)}
does this relation is equivalent relation?
Example 2. Let A = {1, 2, 3, 4, 5}, R = {(a, b) | (a + b) is even}. R
(Relation) is relation on set A. Show that R is an equivalence
relation.
3. Let A = Z and let R = {(a, b) ∈ A x A : a ≡ b(mod 2)}.
Show that R is an equivalence relation.
R = {(a, b) | (a + b) is even}
Reflexive:
Odd + odd = even and even + even = even.
Here, same term is added, which results in even value.
Symmetric:
(Answer) Transitive:
a ≡ b(mod 2) ⇒ a – b = 2Q1
b ≡ c(mod 2) ⇒ b – c = 2Q2
a – b + b – c = 2(Q1 + Q2)
⇒ a – c = 2(Q1 + Q2)
Hence, a – c is also divisible by 2. This proves, transitivity.
Proof
A proof is a statement is essentially just a convincing
argument that the statement is true.
Steps in the proof are there to derive some
statements from:
Assumptions or hypothesis
Statements that have already been derived
Proof Other generally accepted facts
Methods to establish a proof, some of them are:
Direct proof
Proof by contradiction
Proof by contrapositive
Proof by mathematical induction
The simplest (from a logic perspective) style of proof
is a direct proof.
Often all that is required to prove something is a
systematic explanation of what everything means.
Direct Proof Direct proofs are especially useful when proving
implications.
The general format to prove P→Q is this:
Assume P. Explain, explain, …, explain. Therefore Q.
Prove: For all integers n, if n is even, then n2 is
even.
Example Solution:
Let n be an arbitrary integer. Suppose n is even.
(Direct
Then n=2k for some integer k.
Proof)
Now n2=(2k)2=4k2=2(2k2).
Since 2k2 is an integer, n2 is even.
Prove: For all integers a, b, and c, if a|b and b|c then a|
c. Here x|y, read “x divides y” means that y is a multiple
of x (so x will divide into y without remainder).
Solution:
Let a, b, and c be integers.
Example
Assume that a|b and b|c.
(Direct
In other words, b is a multiple of a and c is a multiple
Proof) of b. So there are integers k and j such that b=ka and c=jb.
Combining these (through substitution) we get that c=jka.
But jk is an integer, so this says that c is a multiple
of a. Therefore a|c.
It is known that, an implication P→Q is logically
equivalent to its contrapositive ¬Q→¬P.
There are plenty of examples of statements which are
Proof by hard to prove directly, but whose contrapositive can
Contrapositiv easily be proved directly.
This is all that proof by contrapositive does. It gives
e a direct proof of the contrapositive of the implication.
This is enough because the contrapositive is logically
equivalent to the original implication.
Prove: For all integers a and b, if a + b is odd, then a
is odd or b is odd.
Solution:
Example (Let a and b be integers, assume that a and b are even.
(Proof by EXPLAIN. Therefore a + b is even.)
Let a and b be integers. Assume that a and b are even.
Contrapositiv
Then a =2k and b = 2l for some integers l and k.
e)
Now, a + b = 2k + 2l = 2(k + l).
Since k+ l is an integer, we see that a+ b is even, this
completes the proof.
Prove: For every prime number, if p ≠ 2, then p is
odd.
Solution:
Example Let p be an arbitrary prime number.
(Proof by Assume p is not odd.
Contrapositiv So p is divisible by 2.
e) Since p is prime. It must have exactly two divisors,
and it has 2 as a divisor, so p must be divisible by 1
and 2.
Therefore p = 2. This completes the proof.
Some statements cannot be rephrased as
implications. It might be the case where, it is hard to
decide from where to start.
Proof by In proof by contradiction it process works as below:
Contradictio If we can prove that ¬P leads to a contradiction, then
the only conclusion is that ¬P is false, so P is true.
n That's what we wanted to prove.
In other words, if it is impossible for P to be
false, P must be true.
Prove: Suppose a ∈ Z. If a2 is even, then a is even.
Solution:
For the sake of contradiction suppose a2 is even and a
is not even.
Example Then a2 is even, and a is odd.
(Proof by Since a is odd, there is an integer c for which a = 2c +1.
Contradictio Then a2 = (2c +1)2 = 4c2 +4c +1 = 2(2c2 +2c)+1, so a2 is
n) odd.
Thus a2 is even and a2 is not even, a contradiction.
(And since we have arrived at a contradiction, our
original supposition that a2 is even and a is odd could
not be true.)
Prove: There are no integers x and y such that x2=4y+2.
Solution:
We proceed by contradiction.
So suppose there are integers x and y such that x2 = 4y+2 =
Example 2(2y+1).
(Proof by So x2 is even. This implies that x is even.
Contradictio So x = 2k for some integer k.
n) Then x2 = 4k2.
This in turn gives 2k2 = (2y+1).
But 2k2 is even, and 2y+1 is odd, so these cannot be equal.
Thus we have a contradiction, so there must not be any
integers x and y such that x2=4y+2.
Prove: The Pigeonhole Principle: If more
than n pigeons fly into n pigeon holes, then at least
one pigeon hole will contain at least two pigeons.
Solution:
Example
Suppose, contrary to stipulation, that each of the
(Proof by pigeon holes contain at most one pigeon.
Contradictio Then at most, there will be n pigeons.
n) But we assumed that there are more than n pigeons,
so this is impossible.
Thus there must be a pigeonhole with more than one
pigeon.
Prove: √2 is irrational
(Definition: A real number is rational if there are two
integers m and n so that x= m/n)
Proof:
Example For the sake of contradiction, assume √2 is rational.
(Proof by Hence, some integers m’ and n’ are there, such that
Contradictio √2 = m’/n’
n) By dividing m’ and n’ by all the factors that are
common in both, we obtain √2 = m/n, for some
integers m and n, which has no common factors.
Since, √2 = m/n, m =n √2. squaring both sides will
result in, m2 = 2n2, hence, m2 is even.
If a and b are odd, then ab is odd. Since a conditional
statement is logically equivalent to its contra positive,
we may conclude that for any a and b, if ab is not odd,
then either a is not odd or b is not odd.
However, an integer is not odd if and only if it is even,
Continued…. and so for any a and b, if ab is even, then a or b is
even.
If we apply this when a = b = m, we conclude that
since m2 is even, m must be even.
This means that for some k, m = 2k. Therefore, (2k)2
= 2n2.
Simplifying and cancelling 2 from both sides, we
obtain 2k2 = n2. Therefore n2 is even and therefore n =
2j for some j.
We have shown that m and n are both divisible by 2.
Continued…. This contradicts the previous statement that m and n
have no common factor.
The assumption that √2 is rational therefore leads to
a contradiction, and the conclusion is that √2 is
irrational.
Principle of
Mathematical Induction
Mathematical Induction is a technique of proving a
statement, theorem or formula, which is thought to be true.
Consider a statement P(n), where n is a natural number. Then
to determine the validity of P(n) for every n, use the following
principle:
Step 1: Check whether the given statement is true for n = n0.
Mathematical (n0 = base case)
Step 2: Assume that given statement P(n) is also true for n = k,
Induction where k is any positive integer. (Induction Hypothesis)
Step 3: Prove that the result is true for P(k+1) for any positive
integer k. (Proof of Induction)
If the above-mentioned conditions are satisfied, then it can be
concluded that P(n) is true for all n natural numbers.
Prove that the sum of all natural numbers is equal to
n(n + 1) / 2
Basic step:
We must show that it is true for P(1).
P(1) = 1 for LHS
Example P(1) = 1(1+1)/2 for RHS, and this proves true.
Proof:
We will prove by strong induction that the following statement holds for all integers n ≥ 2.
(P(n)) n can be represented as a product of one or more primes.
Base case:
The integer n = 2 is a prime since it cannot be written as a product ab, with integers a, b ≥ 2,
so P(n) holds for n = 2.
Induction step:
• Let k ≥ 2 be given and suppose P(n) is true for all integers 2 ≤ n ≤ k, i.e., suppose that all
such n can be represented as a product of one or more primes.
• We seek to show that k + 1 also has a representation of this form.
• If k + 1 itself is prime, then P(n) holds for n = k + 1, and we are done.
• Now consider the case when k + 1 is composite.
Continued…
• By definition, this means that k + 1 can be written in the form k + 1 = ab, where a and b
are integers satisfying 2 ≤ a, b < k + 1, i.e., 2 ≤ a, b ≤ k.
• Since 2 ≤ a, b ≤ k, the induction hypothesis can be applied to a and b and shows that a
and b can be represented as products of one or more primes.
• Multiplying these two representations gives a representation of k + 1 as a product of
primes.
• Hence k + 1 has a representation of the desired form, so P(n) holds for n = k + 1, and
the induction step is complete.
Conclusion: By the strong induction principle, it follows that P(n) is true for all n ≥ 2, i.e.,
every integer n ≥ 2 is either a prime or can be represented as a product of primes
Languages
An alphabet is a finite set of symbols. (Σ)
Example:
Alphabets in C lang. or any programming lang.
String
1 length string 0 or 1 Σ1 = {0, 1}1
All these are strings, they are not sets. (Set means written in {})
A language is any countable set of strings over some fixed
alphabet.
Example: Σ = {0, 1}
L = {} Empty Lang.
(Number of strings in Empty lang. = 0)
Example:
Union L1 = {ab, aaa} and L2 = {bba, aba}
Operation Ans: L1 | L2 = {ab, aaa, bba, aba}
Example:
Concatenatio L1 = {ab, aaa} and L2 = {bba, aba}
n Operation Ans: L1 | L2 = {abbba, aaabba, aaaaba, ababa}
Kleene Example:
L = {a}
Closure
Ans: L* = {^, a, aa, aaa, aaaa,……}
L = {ab}
Ans: L* = {^, ab, abab, ababab,…….}
L = {a, b}
Ans: L* = {^, a, b, aa, bb, ab, ba, aaa,…….}
If L is a set of strings then by L+ we mean the set of all finite strings
formed by concatenating words from L, where any string can be
used as we like, and NULL string is NOT included in the resultant
set.
Example:
Positive L = {a}
Closure Ans: L* = {a, aa, aaa, aaaa,……}
L = {ab}
Ans: L* = {ab, abab, ababab,…….}
L = {a, b}
Ans: L* = {a, b, aa, bb, ab, ba, aaa,…….}
Thanks
Prof. Dhara Sapara