Back to IF2224 Teori Bahasa Formal dan Otomata

Path Logic for Input A

When a marble is dropped in A, it first encounters lever x1.

ASCII Flowchart for Input A

      [Input A]
          |
         (x1)
        /    \
(State 0)    (State 1)
      /          \
    (x2)          (x3)
   /    \        /    \
(0)      (1)    (0)      (1)
 /        \    /        \
C          D  D          C

Step-by-Step Breakdown for Input A:

  1. First Decision at x1:

    • If x1 is 0 (Left): The marble follows the left path and goes to lever x2.

      • Second Decision at x2:

        • If x2 is 0 (Left): The marble exits at C.

        • If x2 is 1 (Right): The marble exits at D.

      • Levers Flipped: x1 and x2.

    • If x1 is 1 (Right): The marble follows the right path and goes to lever x3.

      • Second Decision at x3:

        • If x3 is 0 (Left): The marble exits at D.

        • If x3 is 1 (Right): The marble exits at C.

      • Levers Flipped: x1 and x3.

Path Logic for Input B

When a marble is dropped in B, it first encounters lever x3.

ASCII Flowchart for Input B

      [Input B]
          |
         (x3)
        /    \
(State 0)    (State 1)
      /          \
    (x2)          (x1)
   /    \        /    \
(0)      (1)    (0)      (1)
 /        \    /        \
D          C  C          D

Step-by-Step Breakdown for Input B:

  1. First Decision at x3:

    • If x3 is 0 (Left): The marble follows the left path and goes to lever x2.

      • Second Decision at x2:

        • If x2 is 0 (Left): The marble exits at D.

        • If x2 is 1 (Right): The marble exits at C.

      • Levers Flipped: x3 and x2.

    • If x3 is 1 (Right): The marble follows the right path and goes to lever x1.

      • Second Decision at x1:

        • If x1 is 0 (Left): The marble exits at C.

        • If x1 is 1 (Right): The marble exits at D.

      • Levers Flipped: x3 and x1.

a) Finite Automaton Model

The toy can be modeled as a finite automaton. The state of the system is determined by the orientation of the three levers x1, x2, x3. We’ll represent the left position as 0 and the right position as 1.

  • States (Q): A 3-bit string (x1, x2, x3). There are 2³ = 8 possible states.

    • Q = {000, 001, 010, 011, 100, 101, 110, 111}
  • Input Alphabet (Σ): The two drop points for the marble.

    • Σ = {A, B}
  • Start State (q₀): Assuming all levers start pointing left.

    • q₀ = 000
  • Transition (δ) and Output (λ) Functions: The core of the automaton is its transition function δ(state, input) -> next_state and its output function λ(state, input) -> output. A marble pass flips the levers it encounters. “Acceptance” is defined as the marble exiting at D.

The complete behavior is described in the table below:

Current State (q)InputPath TakenLevers FlippedExit (λ)Next State (δ)Accepts?
000AA → x1(L) → x2(L)x1, x2C110No
000BB → x3(L) → x2(L)x3, x2D011Yes
001AA → x1(L) → x2(L)x1, x2C111No
001BB → x3(R) → x1(L)x3, x1C100No
010AA → x1(L) → x2(R)x1, x2D100Yes
010BB → x3(L) → x2(R)x3, x2C001No
011AA → x1(L) → x2(R)x1, x2D101Yes
011BB → x3(R) → x1(L)x3, x1C110No
100AA → x1(R) → x3(L)x1, x3D001Yes
100BB → x3(L) → x2(L)x3, x2D111Yes
101AA → x1(R) → x3(R)x1, x3C000No
101BB → x3(R) → x1(L)x3, x1C000No
110AA → x1(R) → x3(L)x1, x3D011Yes
110BB → x3(L) → x2(R)x3, x2C101No
111AA → x1(R) → x3(R)x1, x3C010No
111BB → x3(R) → x1(R)x3, x1D010Yes

b) Informal Language Description

The language accepted by this automaton is the set of all sequences of marble drops (strings of ‘A’s and ‘B’s) where the final marble exits at port D.

An interesting property is that any input (A or B) always flips exactly two levers. This means the parity (even or odd) of the sum of the lever states (x1 + x2 + x3) never changes. Since we started in state 000 (an even sum), the machine can only ever be in states where the sum of the bits is even: {000, 011, 101, 110}.

So, the language can be described more precisely: It is the set of input strings w that end in a symbol (A or B) which causes an exit at D from the state the machine was in after processing the prefix of w.

c) Levers Switch Before Marble Passes

If the levers switch state before the marble passes, the logic for determining the path and the next state changes fundamentally. The path is now determined by the lever’s new position.

  • New Part (a): The states, alphabet, and start state are the same, but the transition and output functions are now different, as shown in the table below.
Current State (q)InputLogicExit (λ)Next State (δ)
000Ax1 flips to 1, path R → x3 flips to 1, exit CC101
000Bx3 flips to 1, path R → x1 flips to 1, exit DD101
001Ax1 flips to 1, path R → x3 flips to 0, exit DD100
001Bx3 flips to 0, path L → x2 flips to 1, exit CC010
010Ax1 flips to 1, path R → x3 flips to 1, exit CC111
010Bx3 flips to 1, path R → x1 flips to 1, exit DD111
011Ax1 flips to 1, path R → x3 flips to 0, exit DD110
011Bx3 flips to 0, path L → x2 flips to 0, exit DD000
100Ax1 flips to 0, path L → x2 flips to 1, exit DD010
100Bx3 flips to 1, path R → x1 flips to 0, exit CC001
101Ax1 flips to 0, path L → x2 flips to 1, exit DD011
101Bx3 flips to 0, path L → x2 flips to 1, exit CC110
110Ax1 flips to 0, path L → x2 flips to 0, exit CC000
110Bx3 flips to 1, path R → x1 flips to 0, exit CC011
111Ax1 flips to 0, path L → x2 flips to 0, exit CC001
111Bx3 flips to 0, path L → x2 flips to 0, exit DD100
  • New Part (b): The language changes entirely. The parity property still holds (every input flips two levers), but the conditions for exiting at D are now different, creating a new language based on the new state transitions.