![]() |
![]() |
|
READING: Chpt.03
Examples of regular-expressions: For b(ba*b)* :
def'n: A Language is: a
Draw FSM for b(ba*b)* (and minimize it, informally).
Generalize: A FSM = ⟨K, Σ, δ, s, A⟩. In math:
alphabet– the set of letters we'll see of the input.
transition function.
typedef State String; // okay, this isn't legal Java, but fine: we're representing States by Strings (their name); using `int` is common too. (Really: we should have `class FSM<StateType>`.) class FSM { Set<State> K; CharSet Σ; State s; // @pre: K.contains(s) Set<State> A; // @pre: K.containsAll(A) Map< Pair<State,Character>, State> δ; // @pre States are all in K; Characters are all in Σ. // We could also use java.function.BiFunction } |
Example: All equivalent:
new FSM( Set.of( 0,1,2,3 ), new CharSet("ab"), 0, Set.of(1), Map.of( new Pair(0,'a'), 1, new Pair(0,'b'), 3, ... ) |
Def'n of FSM "accepts" a string:
(informal for now):
Feed a string w into the FSM M (starting at s); if after transitioning on all
characters of w, M is in a state in A, then we say "M accepts w".
(more formal def'n will use terms "configuration of M" and a sequencek-of-configurations,
"a computation".)
Def'n: For a FSM M, we say "L(M)" is the language it *accepts*; we also say M "recognizes" L.
E.g. We just gave a FSM which recognized b(ba*b)*
(and even: that machine computes
).
Common Sets: ∅, {false,true}, ℕ, ℤ, ℚ, ℝ, ℂ; Σ*
Sample sets to work with:
L₀ = {} L₁ = {17} L₂ = {vw, saab, bmw} L₃ = {1,2,3,4,5,6} P = prime numbers L₄ = state-abbreviations L₅ = strings over {a,b}* where every 'a' is followed by a 'b' L₆ = b*aa* = {a, aa, ba, aaa, baa, bba, …, bbbaa, … } L₇ = b*a*b* = { ε, a, b, aa, ab, ba, bb, aaa, aab, abb, baa, bab, bba, bbb, …} L₈ = b(ba*b)*
How to make new sets out of old ones:
Let's practice a bit:
Okay, some more ways to make new sets out of old ones:
For example, Σ* → ℕ is the set of all functions taking a string and returning a number;
string-length is one member of this set.
We say that Σ* → ℕ is string-length's signature.
(When you write a function in Java, you must give its signature — albeit in Java, not math.)
What about the signature of substring?
Questions, for various sets created from the ones listed above: No. of elements? Contains ε (the empty-string)?
Exercise (challenge): Find two sets-of-strings A,B such that |AB| < |A| * |B| Answers:
smallest pair?)
Define: lexicographic order
Sort by length, and within length sort alphabetically.
E.g. {a,b}* = {
}ε,a,b,aa,ab,ba,bb,aaa,aab,aba, …
We use Lexicographic order because, unlike alphabetical order, the enumeration actually hits every string. E.g. aba is the 10th string above. But if we'd tried to order the set as ε, a, aa, aaa, aaaa, … then aba wouldn't show up as the 10th or the 99th or the 10-billionth entry — it wouldn't be covered at any finite index!
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |