Same Story, Different Notation - Computerphile

**Understanding State Machines and Chomsky's Notation**

State machines are mathematical models that can be used to describe the behavior of various systems, including those related to computation and language. In the context of computer science, state machines are often used to model the behavior of finite automata, which are a type of abstract machine that can recognize patterns in input data.

In this article, we will explore the concept of state machines and how they relate to Chomsky's notation, which is a formal system for describing the syntax of programming languages. We will also delve into the details of Chomsky's notation and its application to finite automata.

**The State Machine**

A state machine is a simple device that can be in one of several states. The machine receives input data, uses it to transition from one state to another, and eventually produces an output. In the context of finite automata, the input data is typically represented by a sequence of symbols, such as letters or digits.

The key feature of a state machine is that each state can be associated with a particular set of rules for transitioning from one state to another. These rules are often referred to as "transition functions" and they determine how the machine responds to different inputs.

For example, consider a simple finite automaton that recognizes the pattern "any string of letters followed by a semicolon". In this case, the automaton might have three states: a starting state, an intermediate state, and an accepting state. The rules for transitioning from one state to another might be as follows:

* From the starting state, if the input is a letter, transition to the intermediate state.

* From the intermediate state, if the input is a semicolon, transition to the accepting state.

* From the starting state, if the input is not a letter, stay in the starting state.

This is a very simple example, but it illustrates the basic concept of a state machine. In practice, finite automata can be much more complex and may involve multiple states, inputs, and rules.

**Chomsky's Notation**

In 1956, Noam Chomsky developed a formal system for describing the syntax of programming languages using finite automata. This system is now known as Chomsky's notation or the Chomsky hierarchy.

Chomsky's notation provides a way to describe the behavior of finite automata in terms of rules and transitions between states. The rules are typically expressed in a recursive format, where each rule specifies how to transition from one state to another based on the input data.

For example, consider the following Chomsky grammar for recognizing the pattern "any string of letters followed by a semicolon":

L -> L (letter)

T -> T (terminal)

In this grammar, the first rule specifies that if the machine is in state L and receives an input letter, it transitions to another instance of state L. The second rule specifies that if the machine is in state T and receives an input terminal (such as a semicolon), it accepts the input data.

Chomsky's notation provides several benefits over other formal systems for describing finite automata. It allows for the representation of more complex rules and transitions between states, and it provides a clear and concise way to describe the behavior of finite automata.

**Recursion and Terminal Symbols**

One key feature of Chomsky's notation is its use of recursion and terminal symbols. Recursion allows us to define rules in terms of other rules, which can be used to describe more complex patterns. Terminal symbols are used to indicate when the input data has been accepted or rejected.

In the example above, the use of recursion allows us to define a rule for recognizing strings of letters followed by a semicolon. The recursive rule allows us to build up the string incrementally, using the rules provided in Chomsky's notation.

The use of terminal symbols is also important in Chomsky's notation. In this example, the terminal symbol is the semicolon (:) which indicates that the input data has been accepted.

**Memory and the Hierarchy**

One limitation of finite automata is that they do not have any built-in memory. This means that once the machine has processed an input sequence, it cannot retain any information about the input for future processing.

However, Chomsky's notation provides a way to extend finite automata with additional memory using a hierarchical structure. In this approach, multiple levels of finite automata are combined to form a single system with more complex behavior.

The hierarchy is typically divided into several levels, each with its own set of rules and transitions between states. The lowest level of the hierarchy corresponds to a simple finite automaton with no built-in memory, while higher-level systems can retain information about input sequences for longer periods of time.

For example, consider a system that combines multiple levels of finite automata to recognize patterns in input data. In this case, each level of the hierarchy would correspond to a specific type of rule or transition between states.

The benefits of using Chomsky's notation and hierarchical systems are numerous. They provide a clear and concise way to describe complex rules and transitions between states, and they allow for the extension of finite automata with additional memory.

In conclusion, state machines and Chomsky's notation provide powerful tools for describing and analyzing complex patterns in input data. By combining multiple levels of finite automata with recursive rules and terminal symbols, we can create systems that recognize and process a wide range of input sequences with ease.

"WEBVTTKind: captionsLanguage: enif you look back at the car park video you'll see it's very handy everything's cut and dried every possible combination of 20s 10 and fives will work get us to 25 deliver a ticket if we turn to what we were talking about briefly at the end of that video something like I'm in a program language and I want to uh declare an identifier name for my integers I want to call mind did you sea and Dave or even K9 I said last time well they're fine but if you want arbitrary length variable names how do you say I don't know whether it's going to be three letters long five letters long or even 60 letters long maybe the compiler has an external limit anyway but in general how can we keep going round without knowing how many and the answer of course is recursion I'm now going to draw you a finite State automatan diagram for a programming identifier yeah and those of you from Electronics engineering department you can say yes we've known about these for years they're just State machines so here comes a state machine for identifiers you have to have a starting point we had in the car park and we'll have to have one here now and then what I'm going to do is to say well in order to get started on a programming language identifier the rule is you must start with a not a digit and I'll just denote any letter for the Moment by L this state here which I'm calling the tail piece of the identifier is to take care of the fact eventually that identifiers could just be a single letter it's perfectly possible to say in I semicolon it's just a single letter identifier so we've got to allow for that it can be just one letter long or it can be a letter followed by any mix of letters and digits in any order but eventually there has to be an end marker and of course typically in the C programming language the end marker is semicolon okay how do we do that any mixture of letters and digits stuff well here's something new inside this tailpiece state I am saying you can go back into yourself by accepting more letters down at the bottom I can say accept a digit I'll call any digit just d at the moment so can you see what's happening here you go in you must have an initial letter but once you're in the T State you can come back into yourself and that is recursion but as you go back and come back into yourself you must accept a letter or you must find a digit on the input stream eventually the party's got to end you can't keep recurring forever no good at all you will crash you will run out of memory So eventually there's got to be a way out of all this morass and what I'm going to do just so I can link up with what Nome Chomsky did the great noome really liked to think of everything as a legal sentence and called it s we've mentioned this already that you know in carar language a legal senten is 10 105 because it adds up to 25 and so on but to get into this final state which sometimes is called the finished State sometimes equally is called the accept state then I need to see an e and an e is a valid end marker and I'm saying that in for this subset of the C programming language we're doing here the N marker will be a semicolon I might later on extend that a bit because if I do some or examples I want to be able to accept new line as being an N marker as well but for the moment let's say yes it's semicolon so that's it then that is a state machine the factor that's new in it is the ability to do recursion for as long as you want until you finally bottle out the whole thing and take the N Mark and say that's the end of my day declaration okay well what emerged from all of this stuff about State machines and from chomsky's work in the mid to late 50s for every machine you can draw like this and this is a machine interpretation of identifiers there's always a grammatical alternative and the more if you like mathematical theoretician you are the more you like rather abstruse So-Cal top down ways of thinking about things so chomsky's notation let me just start you off on this for this would say look my goal is a sentence but what seems to be the case is that to get to sentence I've got to take first of all an l and then that gets me into a T State okay chsky notation you can read the arrow as being is defined as a sentence is defined as an L any letter followed by what I'll call a tail or a tail piece of the identifier L and T fine well what let's just do one example of what a t can be a t look let's take this one can be further defined as yet another letter followed by another T now look what's Happening Here For the First Time a rule for T is developing another visit into a t on its right hand side this is technically called right recursive and the Chomsky rules say you can be right recursive if you want to do it the other way around perversely and do T becomes TL that's okay that's still within the Chomsky rules it can be purely right recursive or purely left recursive I'll make it right recursive it's a bit more intuitive to me and just in case you think well this is going to go on forever and I can imagine a t becoming a DT and you're taking digits forever what's the thing that gets you out of all this in the end and the answer is well look back at the automatan diagram and say ah in the end you take the Escape Route you take a t is defined as being an e that's one of the options but what about e then ah well here's a classic example then of something that doesn't lead onto another rule it leads in tree terms to a leaf of the tree a terminal symbol that goes nowhere else and the one I'm hoping is there is just a semicolon of course you've spotted that the picture is completed refer back to the automatan again there's also a right recursive option to say yes accept any digit and go back into T so you're going back into yourself again but equally you can now write at the bottom here and it's in the handout we will do all of this in a linked handout so do read the info block of this video find out where the handout is download it read it you'll find in this complete thing I've also said a letter can be anything from a to zed or capital A to capital zed a digit can be anything from not to n that's the way you finish off that grammar this encourages you to think as computer scientists say top down you start with the purity of the abstraction of a sentence and then you develop the detail below it automet really I triy to show you the whole picture you can for me from an automatan get a to rather it's a bit top down but you can also get more of an idea of how all this is built up in sequential steps going through it there's nothing very magic then now it's just emphasizing what I said at the start to every machine picture of a circle in the hierarchy there is a corresponding grammatical expression of it it's just as we'll go out through the chsky hierar the machine interpretations become more complicated and more involving this magic thing called memory as an ancillary to what state is your machine in down here in type three where we are at the moment all we're saying is all you get is your States and yes you got to model those correctly but you don't need ancillary memory for any purpose later on we'll find that we do a hierarchy where as you go inside you make less and less demands on what you need and if you look so we can even eliminate cast Shadows which would be cast by direct sunlightif you look back at the car park video you'll see it's very handy everything's cut and dried every possible combination of 20s 10 and fives will work get us to 25 deliver a ticket if we turn to what we were talking about briefly at the end of that video something like I'm in a program language and I want to uh declare an identifier name for my integers I want to call mind did you sea and Dave or even K9 I said last time well they're fine but if you want arbitrary length variable names how do you say I don't know whether it's going to be three letters long five letters long or even 60 letters long maybe the compiler has an external limit anyway but in general how can we keep going round without knowing how many and the answer of course is recursion I'm now going to draw you a finite State automatan diagram for a programming identifier yeah and those of you from Electronics engineering department you can say yes we've known about these for years they're just State machines so here comes a state machine for identifiers you have to have a starting point we had in the car park and we'll have to have one here now and then what I'm going to do is to say well in order to get started on a programming language identifier the rule is you must start with a not a digit and I'll just denote any letter for the Moment by L this state here which I'm calling the tail piece of the identifier is to take care of the fact eventually that identifiers could just be a single letter it's perfectly possible to say in I semicolon it's just a single letter identifier so we've got to allow for that it can be just one letter long or it can be a letter followed by any mix of letters and digits in any order but eventually there has to be an end marker and of course typically in the C programming language the end marker is semicolon okay how do we do that any mixture of letters and digits stuff well here's something new inside this tailpiece state I am saying you can go back into yourself by accepting more letters down at the bottom I can say accept a digit I'll call any digit just d at the moment so can you see what's happening here you go in you must have an initial letter but once you're in the T State you can come back into yourself and that is recursion but as you go back and come back into yourself you must accept a letter or you must find a digit on the input stream eventually the party's got to end you can't keep recurring forever no good at all you will crash you will run out of memory So eventually there's got to be a way out of all this morass and what I'm going to do just so I can link up with what Nome Chomsky did the great noome really liked to think of everything as a legal sentence and called it s we've mentioned this already that you know in carar language a legal senten is 10 105 because it adds up to 25 and so on but to get into this final state which sometimes is called the finished State sometimes equally is called the accept state then I need to see an e and an e is a valid end marker and I'm saying that in for this subset of the C programming language we're doing here the N marker will be a semicolon I might later on extend that a bit because if I do some or examples I want to be able to accept new line as being an N marker as well but for the moment let's say yes it's semicolon so that's it then that is a state machine the factor that's new in it is the ability to do recursion for as long as you want until you finally bottle out the whole thing and take the N Mark and say that's the end of my day declaration okay well what emerged from all of this stuff about State machines and from chomsky's work in the mid to late 50s for every machine you can draw like this and this is a machine interpretation of identifiers there's always a grammatical alternative and the more if you like mathematical theoretician you are the more you like rather abstruse So-Cal top down ways of thinking about things so chomsky's notation let me just start you off on this for this would say look my goal is a sentence but what seems to be the case is that to get to sentence I've got to take first of all an l and then that gets me into a T State okay chsky notation you can read the arrow as being is defined as a sentence is defined as an L any letter followed by what I'll call a tail or a tail piece of the identifier L and T fine well what let's just do one example of what a t can be a t look let's take this one can be further defined as yet another letter followed by another T now look what's Happening Here For the First Time a rule for T is developing another visit into a t on its right hand side this is technically called right recursive and the Chomsky rules say you can be right recursive if you want to do it the other way around perversely and do T becomes TL that's okay that's still within the Chomsky rules it can be purely right recursive or purely left recursive I'll make it right recursive it's a bit more intuitive to me and just in case you think well this is going to go on forever and I can imagine a t becoming a DT and you're taking digits forever what's the thing that gets you out of all this in the end and the answer is well look back at the automatan diagram and say ah in the end you take the Escape Route you take a t is defined as being an e that's one of the options but what about e then ah well here's a classic example then of something that doesn't lead onto another rule it leads in tree terms to a leaf of the tree a terminal symbol that goes nowhere else and the one I'm hoping is there is just a semicolon of course you've spotted that the picture is completed refer back to the automatan again there's also a right recursive option to say yes accept any digit and go back into T so you're going back into yourself again but equally you can now write at the bottom here and it's in the handout we will do all of this in a linked handout so do read the info block of this video find out where the handout is download it read it you'll find in this complete thing I've also said a letter can be anything from a to zed or capital A to capital zed a digit can be anything from not to n that's the way you finish off that grammar this encourages you to think as computer scientists say top down you start with the purity of the abstraction of a sentence and then you develop the detail below it automet really I triy to show you the whole picture you can for me from an automatan get a to rather it's a bit top down but you can also get more of an idea of how all this is built up in sequential steps going through it there's nothing very magic then now it's just emphasizing what I said at the start to every machine picture of a circle in the hierarchy there is a corresponding grammatical expression of it it's just as we'll go out through the chsky hierar the machine interpretations become more complicated and more involving this magic thing called memory as an ancillary to what state is your machine in down here in type three where we are at the moment all we're saying is all you get is your States and yes you got to model those correctly but you don't need ancillary memory for any purpose later on we'll find that we do a hierarchy where as you go inside you make less and less demands on what you need and if you look so we can even eliminate cast Shadows which would be cast by direct sunlight\n"