Lecture # 01-02
Lecture # 01-02
(CSC-161)
Mr. Faizan Ali (Teaching Assistant)
• As the name suggests, TPL focuses on the study of mathematical models and computational
machine or systems, commonly referred to as automata.
• It explores computational problems, analyzing which problems can be solved using these systems
and determining the extent of their solvability on a computer.
• The Theory of Programming Languages encompasses the study of various computational models
in computer science, evaluating both problem-solving capabilities and efficiency in execution.
• Problem Statement
• In today's world, digital, analog, and mechanical machines play a crucial role in human
development.
• To interact with these machines effectively, a structured communication mechanism is
required, which is achieved through programming languages and computational models.
Solution
Computer
Mathematical Definition of language
• Transition to Alphabets
•An alphabet is a finite, non-empty set of symbols, where
each language has its own unique alphabet. In TPL, we
use the symbol ∑ to represent an alphabet.
•Example:
•For binary representation: ∑ = {0,1}
•For the English language: ∑ = {a, b, c, ..., z}
(In English, an alphabet consists of letters, which
collectively form a structured language system.)
Cont.…
• Examples:
• Total set of alphabets {A,B,C,D,…. Z}
• ∑ (a, b, c)
• ∑ (1 + 2 + 3) = 6 → This means adding the numbers together.
• As a Symbol:
• Mathematics & Statistics:
• ∑ (Capital Sigma) → Represents summation (sum of a series).
• Example: ∑ (1 + 2 + 3) = 6
Cont.…
• String
• A string is a sequence of symbols that belong to a given alphabet set.
• Example:
• If ∑ = {a, b}, possible strings include aabb, aa, bb, cc, dd, etc.
• In English, strings are commonly referred to as words.
• Language
•A language is defined as a set of strings.
•In natural language, it consists of a predefined set of words and follows grammar rules,
forming structured sentences.
•In programming, a program can be considered a string, and its constructs/tokens (such as
keywords, operators, and data types) function like letters or symbols in a language.
Methods to Define Language
• In natural language, we define a list of words in a dictionary because they are finite and
predefined. However, we cannot list all the possible sentences that can be formed using these
words, as the combinations are infinite.
• To manage this, we use a mechanism called grammar, which consists of rules that help determine
whether a sentence is valid or invalid.
Basic Operations on Strings
So, before we proceed further, let's do a task on strings, which will help us throughout the subject.
Length of a string: It is defined as the number of symbols in the string. It is denoted as |A|.
•|aabbbcc| =
•|110011| =
Concatenation of String
Concatenation of a string: Let x and y be two strings. The concatenation of x and y is the string
formed by appending a copy of y after a copy of x.
Reverse of a string: If there is a string w then reverse of a string a denoted by wr it is just the same
string but written in reverse order.
• w = w1,w2,w3 ………. wn
• wr = solution?
• |w| = |wr
Empty/Null String- The string with zero occurrence of symbols. It is denoted by ∈,|∈|=0. If there is a
string w, then wn stands for the strings obtained by repeating w, n times.
• w3 = www
• w2 = ww
• w1 = w
• w0 =
• w∈ = ∈w =
Substring
• Substring- Any string of consecutive symbols in some string ‘w’ can be collectively said as
substring. E.g. w= abab its substrings can be ab, a, ba…etc.
S u b s t r i n g
• utg
• sbr
• rts
• str
• sub
• ∈
Examples:
A prefix is the beginning part of a string, while a suffix is the ending part of a string.
• Example:
• Let the string be “Hello"
• Prefixes: "", “h", “he", “hel", “hell", “hello"
• Suffixes: "", “o", “lo", “llo", “ello", “hello“
Here, "" (empty string) is always a prefix and suffix of any string.
Prefix and Suffix
• Q Consider a sting ‘HOPE’ find the total number of prefix and suffix possible?
• Prefix(HOPE) =
• Suffix(HOPE) =