Presentation is loading. Please wait.

Presentation is loading. Please wait.

Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages.

Similar presentations


Presentation on theme: "Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages."— Presentation transcript:

1 Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages

2 Courtesy Costas Busch - RPI2 Instantaneous Description Current state Remaining input Current stack contents

3 3 Properties of Instantaneous Description If an ID sequence is a legal computation for a PDA, then so is the sequence obtained by adding an additional string at the end of component number two.

4 4 Properties of Instantaneous Description If an ID sequence is a legal computation for a PDA, then so is the sequence obtained by adding an additional string at the bottom of component number three.

5 5 Properties of Instantaneous Description If an ID sequence is a legal computation for a PDA, and some tail of the input is not consumed, then removing this tail from all ID's result in a legal computation sequence.

6 6 Languages of PDA Acceptance by Final State Language of NPDA : Initial state Final state

7 7 Languages of PDA Acceptance by Empty Stack Language of NPDA : Initial state Any state

8 8 From Empty Stack to Final State If of some PDA Then there is a PDA such that

9 9 From Empty Stack to Final State Proof: Let

10 10 Property # 2

11 11 Then there is a PDA such that From Final State to Empty Stack If for some PDA

12 12 From Final State to Empty Stack Proof: Let

13 13 from Property # 2 of ID

14 Courtesy Costas Busch - RPI14 Context-Free Languages (Grammars) Languages Accepted by NPDAs Theorem:

15 Courtesy Costas Busch - RPI15 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 1: Convert any context-free grammar to a NPDA with:

16 Courtesy Costas Busch - RPI16 Context-Free Languages (Grammars) Languages Accepted by NPDAs Proof - Step 2: Convert any NPDA to a context-free grammar with:

17 Courtesy Costas Busch - RPI17 Converting Context-Free Grammars to NPDAs Proof - step 1

18 Courtesy Costas Busch - RPI18 to an NPDA automaton We will convert any context-free grammar Such that: Simulates leftmost derivations of

19 Courtesy Costas Busch - RPI19 Input processed Stack contents Input Stack leftmost variable Leftmost derivation Simulation of derivation

20 Courtesy Costas Busch - RPI20 Input Stack Leftmost derivation Simulation of derivation string of terminals end of input is reached

21 Courtesy Costas Busch - RPI21 An example grammar: What is the equivalent NPDA?

22 Courtesy Costas Busch - RPI22 Grammar: NPDA:

23 Courtesy Costas Busch - RPI23 Grammar: A leftmost derivation:

24 Courtesy Costas Busch - RPI24 Input Stack Time 0 Derivation:

25 Courtesy Costas Busch - RPI25 Input Stack Time 0 Derivation:

26 Courtesy Costas Busch - RPI26 Input Stack Time 1 Derivation:

27 Courtesy Costas Busch - RPI27 Input Stack Time 2 Derivation:

28 Courtesy Costas Busch - RPI28 Input Stack Time 3 Derivation:

29 Courtesy Costas Busch - RPI29 Input Stack Time 4 Derivation:

30 Courtesy Costas Busch - RPI30 Input Stack Time 5 Derivation:

31 Courtesy Costas Busch - RPI31 Input Stack Time 6 Derivation:

32 Courtesy Costas Busch - RPI32 Input Stack Time 7 Derivation:

33 Courtesy Costas Busch - RPI33 Input Stack Time 8 Derivation:

34 Courtesy Costas Busch - RPI34 Input Stack accept Time 9 Derivation:

35 Courtesy Costas Busch - RPI35 In general: Given any grammar We can construct a NPDA With

36 Courtesy Costas Busch - RPI36 Constructing NPDA from grammar : For any production For any terminal

37 Courtesy Costas Busch - RPI37 Grammar generates string if and only if NPDA accepts

38 Courtesy Costas Busch - RPI38 Therefore: For any context-free language there is a NPDA that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs

39 Courtesy Costas Busch - RPI39 Note: From CFG to PDA accepting by emptying stack Given any grammar We can construct a NPDA With

40 Courtesy Costas Busch - RPI40 Constructing NPDA from grammar : For any production For any terminal

41 Courtesy Costas Busch - RPI41 Converting NPDAs to Context-Free Grammars Proof - step 2

42 Courtesy Costas Busch - RPI42 For any NPDA we will construct a context-free grammar with

43 Courtesy Costas Busch - RPI43 Intuition:The grammar simulates the machine A derivation in Grammar : Current configuration in NPDA Input processedStack contents terminalsvariables

44 Courtesy Costas Busch - RPI44 From NPDA to CFG Lets look at how a PDA can consume and empty the stack. We shall define a grammar with variables of the form [p i-1 Y i p i ] that would represent going from p i-1 to p i with the net effect of popping Y i.

45 45 To generate all those strings w that cause P to pop Z 0 from its stack while going from q 0 to p.

46 Courtesy Costas Busch - RPI46

47 47

48 48

49 49

50 Courtesy Costas Busch - RPI50 Some Necessary Modifications Modify (if necessary) the NPDA (accepting by reaching final state) so that: 1) The stack is never empty 2) It has a single final state and empties the stack when it accepts a string 3) Has transitions in a special form

51 Courtesy Costas Busch - RPI51 1)Modify the NPDA so that the stack is never empty Stack OK NOT OK

52 Courtesy Costas Busch - RPI52 Introduce the new symbol to denote the bottom of the stack

53 Courtesy Costas Busch - RPI53 Original NPDA At the beginning push into the stack original initial state new initial state

54 Courtesy Costas Busch - RPI54 In transitions: replace every instance of with Example:

55 Courtesy Costas Busch - RPI55 if the automaton attempts to pop or replace it will halt Convert all transitions so that:

56 Courtesy Costas Busch - RPI56 $$ , Convert transitions as follows: halting state

57 Courtesy Costas Busch - RPI57 NPDA , Empty the stack 2) Modify the NPDA so that it empties the stack and has a unique final state , , Old final states

58 Courtesy Costas Busch - RPI58 3) modify the NPDA so that transitions have the following forms: OR

59 Courtesy Costas Busch - RPI59 Convert:

60 Courtesy Costas Busch - RPI60 Convert: symbols

61 Courtesy Costas Busch - RPI61 Convert: symbols Convert recursively

62 Courtesy Costas Busch - RPI62 Example of a NPDA in correct form:

63 Courtesy Costas Busch - RPI63 The Grammar Construction In grammar : Terminals: Input symbols of NPDA states Stack symbol Variables:

64 Courtesy Costas Busch - RPI64 For each transition We add production

65 Courtesy Costas Busch - RPI65 For each transition We add productions For all possible states in the automaton

66 Courtesy Costas Busch - RPI66 Start Variable: Stack bottom symbol Start state final state

67 Courtesy Costas Busch - RPI67 Example: Grammar production:

68 Courtesy Costas Busch - RPI68 Example: Grammar productions:

69 Courtesy Costas Busch - RPI69 Example: Grammar production:

70 Courtesy Costas Busch - RPI70 Resulting Grammar:

71 Courtesy Costas Busch - RPI71

72 Courtesy Costas Busch - RPI72 Derivation of string

73 Courtesy Costas Busch - RPI73 In general: if and only if the NPDA goes from to by reading string and the stack doesn’t change below and then is removed from stack

74 Courtesy Costas Busch - RPI74 Therefore: if and only if is accepted by the NPDA

75 Courtesy Costas Busch - RPI75 Therefore: For any NPDA there is a context-free grammar that accepts the same language Context-Free Languages (Grammars) Languages Accepted by NPDAs

76 Courtesy Costas Busch - RPI76 Deterministic PDA DPDA

77 Courtesy Costas Busch - RPI77 Deterministic PDA: DPDA Allowed transitions: (deterministic choices)

78 Courtesy Costas Busch - RPI78 Allowed transitions: (deterministic choices)

79 Courtesy Costas Busch - RPI79 Not allowed: (non deterministic choices)

80 Courtesy Costas Busch - RPI80 DPDA example

81 Courtesy Costas Busch - RPI81 The language is deterministic context-free

82 Courtesy Costas Busch - RPI82 Definition: A language is deterministic context-free if there exists some DPDA that accepts it

83 Courtesy Costas Busch - RPI83 Example of Non-DPDA (NPDA)

84 Courtesy Costas Busch - RPI84 Not allowed in DPDAs

85 Courtesy Costas Busch - RPI85 NPDAs Have More Power than DPDAs

86 Courtesy Costas Busch - RPI86 Deterministic Context-Free Languages (DPDA) Context-Free Languages NPDAs Since every DPDA is also a NPDA It holds that:

87 Courtesy Costas Busch - RPI87 We will actually show: We will show that there exists a context-free language which is not accepted by any DPDA Deterministic Context-Free Languages (DPDA) Context-Free Languages (NPDA)

88 Courtesy Costas Busch - RPI88 The language is: We will show: is context-free is not deterministic context-free

89 Courtesy Costas Busch - RPI89 Language is context-free Context-free grammar for :

90 Courtesy Costas Busch - RPI90 is not deterministic context-free Theorem: The language (there is no DPDA that accepts )

91 Courtesy Costas Busch - RPI91 Proof: Assume for contradiction that is deterministic context free Therefore: there is a DPDA that accepts

92 Courtesy Costas Busch - RPI92 DPDA with accepts

93 Courtesy Costas Busch - RPI93 DPDA with Such a path exists because of the determinism

94 Courtesy Costas Busch - RPI94 The language is not context-free (we will prove this at a later class using pumping lemma for context-free languages) Fact 1: Regular languages Context-free languages

95 Courtesy Costas Busch - RPI95 The language is not context-free Fact 2: (we can prove this using pumping lemma for context-free languages)

96 Courtesy Costas Busch - RPI96 We will construct a NPDA that accepts: which is a contradiction!

97 Courtesy Costas Busch - RPI97 Modify Replace with

98 Courtesy Costas Busch - RPI98 The NPDA that accepts Connect final states of with final states of

99 Courtesy Costas Busch - RPI99 Since is accepted by a NPDA it is context-free Contradiction! (since is not context-free)

100 Courtesy Costas Busch - RPI100 Therefore: There is no DPDA that accepts End of Proof Not deterministic context free


Download ppt "Courtesy Costas Busch - RPI1 NPDAs Accept Context-Free Languages."

Similar presentations


Ads by Google