Aka. Mathematical Induction, Weak Induction
Let
Base Case:
Proof:
Inductive Steps:
Assume:
Proof:
We can change the successor of
Aka. Strong Induction
Let
Base Case:
Proof:
Inductive Steps:
Assume:
Proof:
Alphabet:
Token: Element of Alphabet
Production: Symbol ::=
We define a language by BNF:
The
Non-terminal:
Terminal: characters in
A Context-free Grammar is a 4-tuple
-
$V$ : finite set, Variables or Non-terminals -
$\Sigma$ : finite set, Alphabet or Terminals -
$R$ : finite set, Rules or Production -
$S\in V$ : Start Variable
The set of strings (
Language produced by Context-free Grammar is known as Context-free Language (CFL)
Derivation Tree: parse tree
If we think a string as a parse tree, leftmost derivation means deriving from top to bottom and left to right, and rightmost derivation means deriving from top to bottom and right to left.
Parser: Programme constructs a derivation tree for a given word
CYK algorithm, etc.
- Create variable
$R_i$ for each state$q_i$ of DFA - Add rule
$R_i ::= aR_j$ to CFG, if$\delta(q_i, a)=q_j$ is transition in DFA - Add rule
$R_i ::= \epsilon$ to CFG, if$q_i$ is accepting state in DFA - Make
$R_0$ as the start variable where$q_i$ is the start state of DFA
- Create Var.
$R_1$ ,$R_2$ ,$R_3$ &$R_4$ - Add rules:
$R_1 ::= aR_2 \mid bR_1$ $R_2 ::= aR_3 \mid bR_1$ $R_3 ::= aR_3 \mid bR_4$ $R_4 ::= aR_4 \mid bR_4$
- Add rule:
$R_4 ::= aR_4 \mid bR_4 \mid \epsilon$
- Set start var
Consider grammar: $$ \Rightarrow A ::= A+A \mid A\times A \mid (A) \mid 3 \mid 5 $$
The word
We need to convert the grammar to account the precedence of operators by moving the higher priority operations lower in the grammar:
Allows rules with following kind:
- Derivation of a nonempty word involves
$2n-1$ steps where$n$ is the length of the word. - Check mechanically: generate all derivations of length
$2n-1$ and check if any of them work
- Introducing new start variable
- Remove all ε-rules of the form
$A ::= \epsilon$ - Remove all the unit productions of the form
$A ::= B$ - Patch-up/Fix grammar
- Convert remaining rules
-
Add start var
$$ \begin{aligned} \Rightarrow \boldsymbol{ S_0 } &::= \boldsymbol{S} \ S &::= ASA \mid aB \ A &::= B \mid S \ B &::= b \mid \epsilon \end{aligned} $$ -
Remove ε-rules
-
At
$B$
$$ \begin{aligned} \Rightarrow S_0 &::= S \ S &::= ASA \mid aB \mid \boldsymbol{a} \ A &::= B \mid S \mid \boldsymbol{\epsilon} \ B &::= b \end{aligned} $$ -
At
$A$
$$ \begin{aligned} \Rightarrow S_0 &::= S \ S &::= ASA \mid aB \mid a \mid \boldsymbol{SA} \mid \boldsymbol{AS} \mid \boldsymbol{S} \ A &::= B \mid S \ B &::= b \end{aligned} $$
- Remove Unit Rules
-
Case
$S ::= S$
$$ \begin{aligned} \Rightarrow S_0 &::= S \ S &::= ASA \mid aB \mid a \mid SA \mid AS \ A &::= B \mid S \ B &::= b \end{aligned} $$ -
Case
$S_0 ::= S$
$$ \begin{aligned} \Rightarrow S_0 &::= \boldsymbol { ASA \mid aB \mid a \mid SA \mid AS } \ S &::= ASA \mid aB \mid a \mid SA \mid AS \ A &::= B \mid S \ B &::= b \end{aligned} $$ -
Case
$A ::= B$
$$ \begin{aligned} \Rightarrow S_0 &::= ASA \mid aB \mid a \mid SA \mid AS \ S &::= ASA \mid aB \mid a \mid SA \mid AS \ A &::= \boldsymbol{b} \mid S \ B &::= b \end{aligned} $$ -
Case
$A ::= S$
$$ \begin{aligned} \Rightarrow S_0 &::= ASA \mid aB \mid a \mid SA \mid AS \ S &::= ASA \mid aB \mid a \mid SA \mid AS \ A &::= b \mid \boldsymbol { ASA \mid aB \mid a \mid SA \mid AS } \ B &::= b \end{aligned} $$
- Convert
We just turn into word repeatedly until we reach the end of the word.
We cannot test whether 2 CFGs accepts every word over the given alphabet. It is an undecidable problem. Therefore, whether 2 CFGs accept the same word is also undecidable.
- Mathematical Induction - Stanford University - https://web.stanford.edu/class/archive/cs/cs103/cs103.1134/lectures/04/Small04.pdf
- Chomsky normal form - Wikipedia - https://en.wikipedia.org/wiki/Chomsky_normal_form