560 likes | 725 Views
Languages and Finite Automata. or how to talk to machines. Languages. A language is a set of strings String: A sequence of letters (a word) Examples: “cat”, “dog”, “house”, … Defined over an alphabet: set of symbols (letters). Alphabets and Strings. We will use small alphabets Strings.
E N D
Languages and Finite Automata or how to talk to machines...
Languages • A language is a set of strings • String: • A sequence of letters (a word) • Examples: “cat”, “dog”, “house”, … • Defined over an alphabet: • set of symbols (letters)
Alphabets and Strings • We will use small alphabets • Strings
String Operations • Concatenation • Reverse
String Length • Length: • Examples:
Recursive Definition of Length • For any letter: • For any string : • Example:
Length of Concatenation • Example:
Proof of Concatenation Length • Claim: • Proof: • By induction on the length • Induction basis: • is only one symbol • From definition of length:
Inductive hypothesis: • for all with • Inductive step: • we will prove • for
Inductive Step • Write , where • From definition of length: • From inductive hypothesis: • Thus:
Empty String • A string with no letters: • Observations:
Substring • Definition: • A substring of a string is any sequence of consecutive characters • Example: Substrings
Prefix and Suffix • Prefixes Suffixes prefix suffix
Another Operation • Example: • Definition • for any :
The * Operation • : the set of all possible strings from • alphabet • Example:
Language • A language is any subset of • Examples: • A string is called “sentence”
Another Example • An infinite language
Operations on Languages • The usual set operations • Complement:
Reverse • Definition: • Examples:
Concatenation • Definition: • Example:
Another Operation • Definition: • Example: • Special case:
Star-Closure (Kleene *) • Definition: • Example:
Positive Closure • Definition:
Finite Automata Input String Output Finite Automaton String
Finite Accepter Input String Output “Accept” or “Reject” Finite Automaton
Transition Graph Abba -Finite Accepter initial state final state “accept” transition state
Initial Configuration Input String
Output: “reject”
Formalities • Deterministic Finite Accepter (DFA) : set of states : input alphabet : transition function : initial state : set of final states
Languages Accepted by DFAs • Take DFA • Definition: • The language accepted by • contains all input strings accepted by • In other words: • = { strings that drive to a final state}
Example accept
Another Example accept accept accept
Formally • For a DFA • Language accepted by : alphabet transition function initial state final states
Observation • Language accepted by : • Language rejected by :