![]() |
![]() |
|
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₃ = {2,3,5,7} 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₈ = reg-exp-example
How 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?
Exercise (challenge): Find two sets-of-strings A,B such that |AB| < |A| * |B| Answers:
smallest?)
Define: lexicographic order Sort by length, and within length alphabetically. E.g. {a,b}* = {ε,a,b,aa,ab,ba,bb,aaa,aab,aba, … }
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |