Building Blocks


Updates in Version 7.0

In 7.0, the distinction between ordinary states and building blocks is completely eliminated. In order to make that clear visually, all Turing Machine states are now circular, whether they are building blocks or not. Every ordinary state can become a building block, by simply right clicking on it, and clicking Edit Block.
Turing machines within building blocks must have an initial state, although final states will be ignored. JFLAP begins to look for transitions out of a building block when the TM within the block halts. Please see the Preferences page of the tutorial for information on new preferences for Turing machines.


All files that are used in this tutorial, both the machines demonstrated and the library of building blocks used to build them, are available in buildingblocks.zip.

Building Blocks are small Turing machines you can build or get from a library of prebuilt machines. We have provided a few simple blocks to get you started, these are: "Move Left Until a", "Move Right Until a", "Move Left Until Not a", "Move Right Until Not a", and similar blocks for b's and blanks. The internals of the Building Block "Move Left Until a" is shown below.

Building blocks are meant to be used to assemble larger Turing machines quickly and easily. Any Turing machine built in JFLAP can be used as a building block by selecting the Building Block Tool (or pressing b), clicking in the editor pane, and choosing the file to use as a building block. Below is a Turing machine made out of building blocks that changes all “a”s to “y”s, adds an “X” character to the end of the input, and outputs after the “X” a number of “I”s that correspond to the number of “a”s. Thus, it serves to count the number of “a”s. For example f(ababb) = ybybbXII and f(baabaa) = byybyyXIIII. The alphabet is {a, b}.

To add a building block to a file use the Building Block Creator tool, highlighted in the image below.

Click on an empty part of the editor. A file open dialogue appears for you to choose what file to import as a block. When you find the file and press open it will appear as a square with the name of the file inside it.

Running Turing Machines With Building Blocks

The default view of a Turing machine while running is to view at the highest level, which only shows what block the configurations are in. To see the states within the block, you can select a configuration and then choose the Focus button. From that point until Defocus is chosen JFLAP will follow the configuration through the lowest level. displaying the state it is in inside the block. The focused configuration is colored yellow in the configuration pane.

To speed up stepping through the Turing machine when you don't want this kind of detail we have provided a new type of step called Step By Building Block. When chosen from the Input menu it will process an entire building block every time the Step button is clicked. Specifically, every time the step button is pressed JFLAP will continue running each configuration until it exits the block.

Here the machine that counts a's from above is shown in the middle of being tested.

Editing Building Blocks:

 Once a block, say "smallBlock.jff" has been added to your Turing machine, it is stored inside that turing machine's file which we'll call "largeMachine.jff", so making changes to the original file, “smallBlock.jff” will not change the building block inside “largeMachine.jff”.  To change the block select the Attribute Editor by pressing the letter a, right click on the block, and choose Edit Block.  This opens a new tab in which you can make changes to the block as with any other Turing machine.  When you are done making changes open the File menu and choose Dismiss Tab.  This will save the changes.   Multiple blocks from the same file may be added to a turing machine, but changes to one block will not affect the other blocks. When editing blocks you should be careful to update the name of the block to reflect the new changes as it can be easy to forget what you did making debugging difficult.

Mixing Blocks and States:

Building Blocks can be treated like States in that transitions can be added to them just like States.  However, there is also a Block Transition Creator tool that can be used instead, highlighted in the image below.  

This type of transition allows input of one letter.  When running the Turing machine, if it reaches the final state of the first block, and the head is pointing to the same letter as in the transition, it will move into the initial state of the second block.  The tape head will not move, and no letter will be written to the tape.

As you can see from the image below, any kind of transition can be added between any combination of blocks and states.

New Transition Syntax

Not X:

This allows transitions that read in any letter other than the ones specified, instead of having to create one for each letter.  For instance if you wish to transition from state one to state two after reading all letters except b, writing the letter c always, you could use the syntax read !b, write c, S. As shown in the machine below.

 

Variable Assignment :

To use this feature create a regular transition between two states or blocks, we'll call them A and B, and in the first field type the letters you wish to assign to the variable.  For example “a,b,c}w” would mean that when the Turing machine got state A if the head was on either a, b, or c the letter at the head would from then on be synonymous with w.  This means that later transitions that say read w or write w actually mean read the letter that was at the head or write that letter.   An example machine is shown below.  The first transition says to store the letter at the head as w and move the head right.  The next transition says if the new letter at the head is the same as w, write b and move right again. The input is only accepted when two of the same letters are in a row, aa, bb, or cc.  The output if used as a transducer is ab, bb, or cb.

Below is a Turing machine that duplicates the input string separated by 0 over the alphabet {a, b}. Input of aababacc for example gives aababacc0aababacc.

 

When the machine starts it moves right until it finds a blank, rights a 0, moves left until it finds a blank, moves one right so that the head is on the first letter of the input string. Out of this block there are two transitions; we'll focus on the one that says a,b,c}w, w, S. This states that if the letter pointed to by the head is a, b, or c that letter will be assigned to the variable w. We then write w to the tape, which is the same thing that was just read. In the next step we write a blank over what was just written, move right until the next blank, and write w over it. We then move left until the first blank and rewrite w over the blank. We are now back in the fifth block from start, labeled R and ready to continue duplicating the string or branch to the final state if everything has been duplicated.

Building Block Tools

Duplicate Block:

If you need a copy of a block, right click on it and select Duplicate Block. By default it will be named Copy of x, where x is the name of the original block, and will appear directly under the original. As with blocks loaded from the same files, changes to one will not affect the other as they are not linked.
This tool is especially useful for situations where you have loaded multiple blocks from the same file before discovering an error in the original file. Now all you have to do is edit one block to fix it, erase all the other blocks that were loaded from the file, and then replace them by duplicating the fixed block.

Replace Character Within Block

To replace all occurrences of a letter within a block, right click on the block and choose Replace Symbol. Type the character you want to replace and press enter, then type the character you want to take it's place and press enter. The character will be replaced in all transitions inside the block including all transitions inside all sub-blocks. The picture above shows a file that changes all A's in the input string to X's. Here is the inside of the block rightUntilA.

To change the file to one that changes all B's in the input string to X's instead, use Replace Character Within Block. Type A, press Enter, type B, press Enter. Now the inside of rightUntilA looks like this.

Be careful to change the name of the block to rightUntilB to avoid confusion.

This concludes our brief tutorial on building blocks. Thanks for reading!