<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE article  PUBLIC "-//NLM//DTD Journal Publishing DTD v3.0 20080202//EN" "http://dtd.nlm.nih.gov/publishing/3.0/journalpublishing3.dtd"><article xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink" dtd-version="3.0" xml:lang="en" article-type="research article"><front><journal-meta><journal-id journal-id-type="publisher-id">OJDM</journal-id><journal-title-group><journal-title>Open Journal of Discrete Mathematics</journal-title></journal-title-group><issn pub-type="epub">2161-7635</issn><publisher><publisher-name>Scientific Research Publishing</publisher-name></publisher></journal-meta><article-meta><article-id pub-id-type="doi">10.4236/ojdm.2012.23020</article-id><article-id pub-id-type="publisher-id">OJDM-21127</article-id><article-categories><subj-group subj-group-type="heading"><subject>Articles</subject></subj-group><subj-group subj-group-type="Discipline-v2"><subject>Physics&amp;Mathematics</subject></subj-group></article-categories><title-group><article-title>
 
 
  An Entertaining Example of Using the Concepts of Context-Free Grammar and Pushdown Automation
 
</article-title></title-group><contrib-group><contrib contrib-type="author" xlink:type="simple"><name name-style="western"><surname>rasimir</surname><given-names>Yordzhev</given-names></name><xref ref-type="aff" rid="aff1"><sub>1</sub></xref><xref ref-type="corresp" rid="cor1"><sup>*</sup></xref></contrib></contrib-group><aff id="aff1"><label>1</label><addr-line>Faculty of Mathematics and Natural Sciences, South-West University, Blagoevgrad, Bulgaria</addr-line></aff><author-notes><corresp id="cor1">* E-mail:<email>yordzhev@swu.bg</email></corresp></author-notes><pub-date pub-type="epub"><day>18</day><month>07</month><year>2012</year></pub-date><volume>02</volume><issue>03</issue><fpage>105</fpage><lpage>108</lpage><history><date date-type="received"><day>April</day>	<month>13,</month>	<year>2012</year></date><date date-type="rev-recd"><day>May</day>	<month>10,</month>	<year>2012</year>	</date><date date-type="accepted"><day>June</day>	<month>4,</month>	<year>2012</year></date></history><permissions><copyright-statement>&#169; Copyright  2014 by authors and Scientific Research Publishing Inc. </copyright-statement><copyright-year>2014</copyright-year><license><license-p>This work is licensed under the Creative Commons Attribution International License (CC BY). http://creativecommons.org/licenses/by/4.0/</license-p></license></permissions><abstract><p>
 
 
  A formal-linguistic approach for solving an entertaining task is offered in this paper. The well-known task of the Hanoi towers is discussed in relation to some concepts of formal languages and grammars. A context-free grammar which generates an algorithm for solving this task is described. A deterministic pushdown automation which in its work imitates the work of monks in solving the task of the Hanoi towers is built.
 
</p></abstract><kwd-group><kwd>Context-Free Grammar; Context-Free Language; Pushdown Automation; Hanoi towers; Discrete Mathematics Learning</kwd></kwd-group></article-meta></front><body><sec id="s1"><title>1. Introduction</title><p>Task 1 (The Task of the Hanoi Towers [<xref ref-type="bibr" rid="scirp.21127-ref1">1</xref>]). The Hanoi Towers are made up of three vertical pins. A series of N discs is hung on the first pin. The discs are all different, but ordered by size with the largest being on the bottom and the smallest on top. The task is to move the discs from the first to the third pin, using the second pin as an assistant. There are several conditions to completing this exercise: only one disc may be moved at one time and while one disc is being moved, all other discs must be on one of the pins and also, during this time, it is prohibited for a larger disc to be placed on a smaller one.</p><p>The task of the Hanoi Towers is a classic example used to teach recursion in programming [1-4]. In this paper, we will look at this Task from the standpoint of mathematical linguistics, i.e. as a part of the discipline of “discrete mathematics” and “mathematical linguistics” studies by students in Informatics and Computer courses at university [2,5-9].</p><p>There are three interesting approaches associated with the task of Hanoi towers in terms of mathematical linguistics:</p><p>1) To generate the Hanoi moves using a finite automaton;</p><p>2) To generate the Hanoi moves using a context-free grammar;</p><p>3) To generate the Hanoi moves using a pushdown automation.</p><p>The first approach is described in [<xref ref-type="bibr" rid="scirp.21127-ref10">10</xref>] and an equivalent version (with morphisms) in [<xref ref-type="bibr" rid="scirp.21127-ref11">11</xref>]. In this paper we will consider the second and third tasks. These tasks have been formulated in a Bulgarian in the textbook [<xref ref-type="bibr" rid="scirp.21127-ref12">12</xref>].</p><p>The algebraic properties of context-free grammars and languages are discussed in [5,8,13,14]. Several applications of formal grammars and languages and pushdown automata are considered in [8,15].</p></sec><sec id="s2"><title>2. Context-Free Grammars and Languages</title><p>Let V be a finite and non-empty set. The elements of this set are called letters, and the whole set V—alphabet.</p><p>We will call a word over the alphabet V each finite string of letters from V. A word that does not contain any letter is called an empty word, which we will mark with<img src="6-1200073\a3ceb1ad-ec05-4377-b8bb-b37b0d489466.jpg" />. <img src="6-1200073\9c01bd7e-38b0-4499-89af-28d1cb4020e8.jpg" />denotes the set of all words over V, including empty set. The term length of a word refers to the number of letters in it. The length of the word <img src="6-1200073\81b6446d-589a-4538-8ff9-e5d4d4118875.jpg" /> will be expressed by<img src="6-1200073\6982bcae-4068-40d5-8641-9308cecc21f8.jpg" />.</p><p>Let <img src="6-1200073\eed5b0f2-a2db-4eb7-bcf5-1f7418004ccb.jpg" /> and <img src="6-1200073\db5b7370-ecdd-460f-ab30-76770ac6c810.jpg" /> be two words over the Alphabet V. By concatenation (multiplication) <img src="6-1200073\e7a79fe4-085b-4423-8aed-9e9a63588ff8.jpg" />of both words we will mean the word obtained by successive completion of the letters of <img src="6-1200073\6cf97430-c232-449b-85c0-26e097aaa301.jpg" /> after the last letter of<img src="6-1200073\50523893-f492-44ac-88f6-96b875a48c70.jpg" />.</p><p>Let V be an alphabet. Each subset L of <img src="6-1200073\db69cbba-e4f4-4fe3-bdd6-bc4eb51c3982.jpg" /> is called formal language (or only language) over alphabet V.</p><p>By generative grammar (or only grammar)<img src="6-1200073\8f92ed0b-a1c5-4e3c-9df8-bd507a6b16dc.jpg" />, we will understand the four ordered tuples<img src="6-1200073\23b810a0-988e-4e93-96e9-bcff9dbe8175.jpg" />, where V is a finite set (Alphabet) of terminal symbols, W—a set of nonterminal symbols, S—a start symbol of the grammar, which is an element of W, and P is a set of ordered pairs<img src="6-1200073\768b2325-52b3-4114-bf16-5efbcfabf12f.jpg" />, where<img src="6-1200073\6a322caa-265f-4bd0-902a-b9f7649a63b9.jpg" />, with at least there one non-terminal symbol in<img src="6-1200073\b1c233c5-749b-458c-acc0-193f50f2f6bf.jpg" />. In a number of sources (see references at the end), an additional condition is placed for sets W and P to be finite. For our needs this condition is not necessary. It is enough that these sets are countable. The elements of P are called productions. If<img src="6-1200073\548843e2-6b86-43fc-a493-8de99cf4bfdf.jpg" />, then it means<img src="6-1200073\bc6dc8e3-6952-4aea-bc15-c68be15c6ed8.jpg" />, as the symbol “<img src="6-1200073\12a1e34f-c0bc-4088-b122-6229a8ae28a5.jpg" />” does not belong to<img src="6-1200073\e7de0c16-ba15-48ce-8e70-259cfdde4bf4.jpg" />.</p><p>Let <img src="6-1200073\89bffb14-f717-498a-8ee8-6fe169b4f2c4.jpg" /> and <img src="6-1200073\ca6ec9d2-c3f5-4a99-8d75-daaa965a4874.jpg" /> be two words from<img src="6-1200073\a71e9639-943d-4611-83dc-aef65d552b19.jpg" />. We will say that <img src="6-1200073\f3b29430-2227-43a0-8db4-48dbb788f00a.jpg" /> is derived directly from <img src="6-1200073\cfe765b3-3e10-4040-9e57-441726321884.jpg" /> in the grammar <img src="6-1200073\1b32e925-caf6-4e1b-82fd-a7dc33d219c2.jpg" /> and will write <img src="6-1200073\59be0c39-257c-477b-9fc1-9cb627c71af4.jpg" /> (or only<img src="6-1200073\a6874eef-e314-4b09-9371-a25f8acf1927.jpg" />, if <img src="6-1200073\63a10c1f-3129-491f-9c9a-076bfa9a1ea5.jpg" /> is understandable), if there exists words <img src="6-1200073\7f55a2f2-9153-42c5-88b3-db4a4b92517b.jpg" /> and a production <img src="6-1200073\d940b8b7-d580-4390-a285-452e77435ae7.jpg" /> in <img src="6-1200073\9f299fa7-ad7a-4677-8ed2-be98ebf6596d.jpg" /> so that <img src="6-1200073\fee4259b-077a-4116-b517-c9d12ab9fd92.jpg" /> and<img src="6-1200073\152aede6-b8d2-48fe-b0b0-ea4704c76826.jpg" />.</p><p>If <img src="6-1200073\e88f9621-3063-480b-ac82-b05ce3a87800.jpg" /> is a word over<img src="6-1200073\40d53cb0-27df-4393-98a6-6868fc975946.jpg" />, for which<img src="6-1200073\a9224a9c-3af1-41d8-9b17-9e558a79c32a.jpg" />, we will say that the number of words is the derivation of <img src="6-1200073\634d9a7c-0350-4056-a917-4748d75a8ec0.jpg" /> from <img src="6-1200073\2c501150-a55f-409f-8c4b-0e20be61fab9.jpg" /> in<img src="6-1200073\3d63f2a9-fe78-4f2c-8175-b34c45192ae1.jpg" />, which we denote by <img src="6-1200073\33755b80-d682-4e18-a63a-efa2282bda00.jpg" /> or only<img src="6-1200073\987b4fe2-6021-49c5-b17f-a5da8d47570a.jpg" />, if <img src="6-1200073\e0e3251b-afbf-46d7-b2d2-069e466a3623.jpg" /> is default. The count n of the immediate derivations <img src="6-1200073\c6e7ba72-3996-4897-9c53-664c9c2dec48.jpg" /> will be called the length of derivation.</p><p>The Set <img src="6-1200073\2d5b4b9c-9028-47b9-a51d-fde7c07cfd6b.jpg" /> is called formal language over V, generated by the grammar<img src="6-1200073\bcc53740-6521-4ebf-a8eb-6328583e76f1.jpg" />. The Grammars <img src="6-1200073\2ad397f9-373b-4239-970d-b410aa7e9d35.jpg" /> and <img src="6-1200073\f27dc08c-07c8-4366-b3f2-67bd993c5c01.jpg" /> are equivalent if<img src="6-1200073\dd9b96d5-d307-4cee-b13b-73efe5714171.jpg" />.</p><p>A grammar <img src="6-1200073\39a7f969-4507-4e53-a8e9-aa09d59f6bfe.jpg" /> is context-free, if all the productions are of the type</p><p>where V and W are alphabets, respectively with terminal and nonterminal symbols.</p><p>Task 2. For a given positive integer N a context-free grammar <img src="6-1200073\0560f3a9-77f4-4a1e-ba47-0eedd533a466.jpg" /> should be built with a terminal alphabet encoding possible displacements and if<img src="6-1200073\d94b4310-d46c-4657-a68d-64ef735a85a5.jpg" />, then <img src="6-1200073\a05b7530-18ac-4e4a-aa5c-38245e1f4e0f.jpg" /> describes the algorithm that solves the Task 1. Prove that for each positive integer N language <img src="6-1200073\e3bdd898-1122-4bd3-bafb-71a028e22ed5.jpg" /> is not empty, i.e. for each positive integer N there is an algorithm that solves the task of the Hanoi towers<sup>1</sup>.</p><p>Solution. Let’s consider context-free grammar <img src="6-1200073\82006580-4505-40a1-8ab1-707772795a07.jpg" /> where<img src="6-1200073\d04c5353-7fc2-4f59-a75f-2bb900567bba.jpg" />. The meaning of <img src="6-1200073\09164209-2fd9-44b2-8952-2976131090bb.jpg" /> is “Move top disk from the i-th pin of the j-th pin”. In this way, if<img src="6-1200073\51822581-836b-421c-94ba-6c9a73fed426.jpg" />, where <img src="6-1200073\44eeb5cd-b825-4e66-b46f-8f85dbd05c76.jpg" /> <img src="6-1200073\ca44972c-f97a-4449-9427-4bb026d7c3e3.jpg" />, then <img src="6-1200073\eeffb236-0d24-44a5-a9cc-26a4f5874cca.jpg" /> describes the algorithm for the consecutive moving of <img src="6-1200073\f59b91c9-9d3c-49fc-a3f3-09c44d87198c.jpg" /> discs in the three pins.</p><p><img src="6-1200073\1e3d339b-4089-45fc-8185-730b24fa84c7.jpg" />the start symbol<img src="6-1200073\abd70c9f-5397-4660-93dd-0cc993f36997.jpg" />, <img src="6-1200073\798174b7-b9fb-4fb7-946b-4e166d61dde3.jpg" />consists of productions<img src="6-1200073\15ea5fec-82f5-4ea9-890b-deadd3167f24.jpg" />and <img src="6-1200073\35731d2f-9ea4-4a6f-867a-684551f60397.jpg" /> for<img src="6-1200073\5ad0627f-fcea-4d1b-8072-6a357016664e.jpg" />, where <img src="6-1200073\7902af1e-cc12-4c8c-bd2b-f6accb19660f.jpg" /> <img src="6-1200073\d70cdcb2-7de6-4026-927c-75973cdf54b3.jpg" /> <img src="6-1200073\801c38de-d26a-41dd-aa22-fb5eb362a736.jpg" /> <img src="6-1200073\2e9cf6a4-7b9b-4d76-9183-2c70bee7e539.jpg" />. Apparently, the grammar <img src="6-1200073\a0007245-bc0b-4be3-bcf2-bc19f67d2a37.jpg" /> constructed in this manner is context-free.</p><p>Let<img src="6-1200073\ee65acf1-5e22-452e-8cf5-5761ff2617e7.jpg" />, i.e. we assume that the derivation<img src="6-1200073\5bddc8b5-385f-4d9a-9238-b2fde4c140c9.jpg" />exists and let the length of the derivation is equal to<img src="6-1200073\02ad0bbc-2eda-46cf-8b28-0492302d0c8a.jpg" />. If<img src="6-1200073\cee9b99d-4ea2-4c45-8824-e197629fb7e2.jpg" />, then obviously this is possible if and only if the number of discs <img src="6-1200073\9a4e9ca2-9ae7-4b2e-8bb4-bdc75b3f5c50.jpg" /> and there is a direct derivation <img src="6-1200073\b2dda83f-9824-4941-bb4e-4993510ede09.jpg" /> and in the presence of a single disc, <img src="6-1200073\a69feafd-91d7-489b-8f80-94116e55345a.jpg" />describes an algorithm for solving Task 1. Similarly <img src="6-1200073\94284c65-3061-4292-b8eb-6c327b77353b.jpg" /> is a derivation with length 1 with start symbol <img src="6-1200073\eaf6e56c-e760-4f71-9dbd-e16e8039a9e7.jpg" /> and <img src="6-1200073\d8ed2c12-f967-4889-ae62-8c56de2bb295.jpg" /> describes the algorithm for moving a single disc from pin <img src="6-1200073\fa3ed4ec-c76f-435a-9416-85fd15ce3afa.jpg" /> to pin<img src="6-1200073\5ae8da87-f107-4f01-bb42-64a593dfa9dd.jpg" />, where <img src="6-1200073\c0648dd9-bb54-47d3-b572-f24013e18d1f.jpg" /> and<img src="6-1200073\530c6679-3cab-4354-8fa7-009937d9a331.jpg" />. Let<img src="6-1200073\f8d34e93-fb09-40b5-ad7d-90467a676136.jpg" />. We assume that if a derivation exists with length less than <img src="6-1200073\ac69757f-0b4d-4297-babd-cf9933e82c57.jpg" /> of type<img src="6-1200073\826f62af-a039-4909-be26-0da3e2198949.jpg" />, where<img src="6-1200073\3dbfe36e-6f1e-4e91-9a98-0c51662aae8c.jpg" />, <img src="6-1200073\918eda68-df47-48de-8196-4e917ab551d4.jpg" />then <img src="6-1200073\c8085ccf-b248-4016-bbbc-147200dde3aa.jpg" /> describes the moving of n discs from pin <img src="6-1200073\4666b740-cd9b-4435-9171-0dd4ea3296d4.jpg" /> to pin<img src="6-1200073\4b23807a-c03a-4e3b-8a85-9c1b993fa0b8.jpg" />, using pin k as assistant according to the constraints in Task 1, where<img src="6-1200073\da1c8b4b-ad5f-4c2d-8571-1abf9b0f0921.jpg" />,<img src="6-1200073\9c78a1a4-fa7d-4430-9cd5-7d3b40a1cec0.jpg" /><img src="6-1200073\9b2a228e-5abb-4add-94d6-1854b4f2a7c2.jpg" /><img src="6-1200073\6f3ec716-a09e-4a40-8ab9-4afae623cfce.jpg" />. When s &lt; 1 obviously derivation <img src="6-1200073\05100bcd-544a-434b-bf48-bdf563218f63.jpg" /> with length s (if existing) will be of the type <img src="6-1200073\2eefb45e-1fe6-4c8e-a73e-e0f01024ab0d.jpg" /> then the next derivations <img src="6-1200073\bff874a9-2cb1-4b8b-8f79-b2d819ea7429.jpg" /> and<img src="6-1200073\fb63f502-69ad-435b-bdd9-99baa6820984.jpg" />exist with lengths less then s, where<img src="6-1200073\2d22e3f6-cacf-4f57-aa0c-cad3008e8728.jpg" />and<img src="6-1200073\b6fa354f-0a38-418b-88e5-c1d6f8aca198.jpg" />. According to the induction assumption, <img src="6-1200073\08ca7416-7bfe-4557-8532-8371837587a4.jpg" />describes the algorithm for moving of <img src="6-1200073\8c33e7a4-2a65-44e0-a5ae-6d474af703c3.jpg" /> discs from the first to the second pin, using the third one as assistant, and <img src="6-1200073\8b99dbc7-25e7-42b5-a07d-17c2b3ce1bea.jpg" /> describes the algorithm for moving <img src="6-1200073\dc2d00f2-d0f7-48e1-84c8-6d30868a79e4.jpg" /> discs from the second to the third pin, using thr first one as assistant. Then <img src="6-1200073\712870e6-043a-4881-a098-9b4530a43aa7.jpg" /> describes the following algorithm: first under the constraints of Task 1 we move the top number <img src="6-1200073\a23db8ef-00d6-4183-8bec-e9667d5e47cc.jpg" /> of discs from the first pin to the second, then we move the largest bottom disk from the first pin of the empty third and finally, we move <img src="6-1200073\7e02284f-2a8b-47dc-999e-fed17ead4caf.jpg" /> number of discs from the second pin to the third one. Therefore <img src="6-1200073\758b3816-5e20-434e-b9e9-03e29bcc4036.jpg" /> (if existing) describes the solution of the task of the Hanoi towers.</p><p>Let’s prove for each positive integer N that language <img src="6-1200073\80570936-addf-43b4-82c2-0702041fcf0d.jpg" /> is not empty. When<img src="6-1200073\104e517a-6cdd-4ed8-a412-4e702ca8e698.jpg" />, the only production of <img src="6-1200073\5b5e1afa-1255-4dd2-9d82-b9833aba2c7c.jpg" /> which can be applied is <img src="6-1200073\2b5f8034-63ea-4cb3-abae-45beff751e03.jpg" /> and therefore<img src="6-1200073\3ab21099-6241-4f66-a6a4-a3d641a0ab79.jpg" />, i.e. <img src="6-1200073\884e53b7-32c1-4551-b1db-8435864347e6.jpg" />is not an empty language. Let’s assume that for each positive integer <img src="6-1200073\60737104-1257-43dc-aec1-6d02f2611dd8.jpg" /> the languages <img src="6-1200073\19160caf-e881-45c6-93b1-39e77f85939c.jpg" /> are not empty and put<img src="6-1200073\bbef462a-bbf4-4ee5-a28b-e76afaad1d65.jpg" />. Let’s consider the context-free grammars<img src="6-1200073\a34a582e-5c8e-464c-bcc9-f485434821cd.jpg" />and<img src="6-1200073\4d51ba20-db95-4028-8e3f-7c9c4645b5c1.jpg" />. Apparently <img src="6-1200073\d6c6a14b-eebb-4a06-b56a-3c0c8ecbbbb4.jpg" /> and <img src="6-1200073\3b9ec488-b354-44a4-9c46-6ecb13a4228a.jpg" /> work by analogy of <img src="6-1200073\7a97b4b5-d3b9-43b6-ae74-3b73a3850b3d.jpg" /> and according to the above proven if<img src="6-1200073\173e1b05-7203-4f34-8404-5780aae7e524.jpg" />, then <img src="6-1200073\74855ccf-eabe-402e-9217-709a523f0c8c.jpg" /> describes the algorithm for moving <img src="6-1200073\50045fa6-9bb5-4e4b-bf01-4fa6e09a7e52.jpg" /> discs from the first tos the second pin, using third one as assistant under the constraints described in Task 1, and if<img src="6-1200073\690435ec-4586-4573-8857-42061a716393.jpg" />, then <img src="6-1200073\56145e7c-157a-455f-8972-b2ce4c5b0dbd.jpg" /> describes the algorithm for moving t discs from the second pin to the third one using the first one as assistant. According to the induction assumption <img src="6-1200073\4847ecc7-c54b-4a7b-81eb-0dc3752bace5.jpg" /> and <img src="6-1200073\158c815f-3d5c-4e3f-a4d4-5501efb76741.jpg" /> there exists. Then in <img src="6-1200073\363d49d7-e42a-44d5-8aef-1e7fce405d1c.jpg" /> derivation exist<img src="6-1200073\56e5126d-9712-4238-9302-3f101be3c15c.jpg" />, where<img src="6-1200073\32b299a0-c0c7-403a-bbfe-bec40043b981.jpg" />and<img src="6-1200073\2f3aa0c9-4624-4300-aa85-b87d31afb814.jpg" />. Therefore<img src="6-1200073\8c9e9200-1bc0-4f67-bf1d-0cecd40c6f32.jpg" />, i.e. <img src="6-1200073\c9a09cb6-9720-492b-9f90-2dbd447ad584.jpg" />is a non empty language. <img src="6-1200073\7971b3f1-1480-4cf6-a5ed-dd15f813aaac.jpg" /></p><p>When <img src="6-1200073\5324a704-bbc6-44e0-b56d-ac8cdea73792.jpg" /> the following word is produced <img src="6-1200073\d4ed0412-8190-4daf-a9e2-c7f5c519ba94.jpg" /> <img src="6-1200073\96cf3dbd-9979-4fae-a447-056e17c19def.jpg" /> <img src="6-1200073\1a2b60ee-cdd2-43e4-af44-7a53fc5d9908.jpg" /> <img src="6-1200073\fc420875-8105-448e-b6e5-bad8ec92f8cb.jpg" /> <img src="6-1200073\d4f66df0-d001-4e15-978c-55d292656905.jpg" /> <img src="6-1200073\ec0eaff0-4116-40c2-b470-2e4ce11ba307.jpg" /> <img src="6-1200073\c9b7fa95-401f-42a2-bb23-d8c2ae112c21.jpg" /> <img src="6-1200073\65903d05-ca18-40f5-b612-a18f318c845e.jpg" /> <img src="6-1200073\cccfb667-9f69-4110-b850-cec0b9edd70f.jpg" /> <img src="6-1200073\951e5cc3-059b-435a-b131-daa9c714752b.jpg" /> <img src="6-1200073\7f627221-a98a-49cb-90c7-6a2b6fa6cc3e.jpg" /> <img src="6-1200073\1efd7a28-aa76-4524-a166-c2a46b73e6fa.jpg" /> <img src="6-1200073\5a93a7b4-b2bb-4530-bbcb-6939e70bd8b8.jpg" /> <img src="6-1200073\11996afd-b4b2-4870-879b-6a0252ea437e.jpg" /> <img src="6-1200073\81fbfd12-adfe-40c5-8971-0e3fa25a2912.jpg" /> <img src="6-1200073\f1087fa7-ffd8-47e9-8794-490cc7c82310.jpg" /> <img src="6-1200073\6eb5f496-ead7-4d18-8770-bcbd02866467.jpg" /> <img src="6-1200073\43b0da68-4102-462a-be9c-7f8ed97bcde9.jpg" /> <img src="6-1200073\94951dee-1252-4da6-996f-0fc889976080.jpg" /> <img src="6-1200073\17471256-4eea-409c-bc67-ff09ab5aef27.jpg" /> <img src="6-1200073\da375565-91d2-4ab0-bccb-e89777b598fe.jpg" /> <img src="6-1200073\78462a57-a4d7-492c-9182-93b51d926bdc.jpg" /> <img src="6-1200073\1e0b7bd0-2605-4066-b537-b1b1fe2051b6.jpg" /> <img src="6-1200073\97b47e7c-086e-4bdf-99fb-07b51f08bc98.jpg" /> <img src="6-1200073\af05a9ff-636f-4f9a-adf6-7d2f252fbd8c.jpg" /> <img src="6-1200073\b2639de8-d478-470a-a81c-609cbc3b69a7.jpg" /> <img src="6-1200073\446c6817-499a-4da0-a920-b5a49691b8ee.jpg" /> <img src="6-1200073\5d7510de-c22b-4bb1-b878-53c5321fafe2.jpg" /> <img src="6-1200073\36b77edb-e059-4ab7-923f-b83b6767b2f2.jpg" /> <img src="6-1200073\8869a176-685a-45f4-a322-7a481834c83e.jpg" /> <img src="6-1200073\ce134907-8d1a-4221-8d95-8f3f522fc8fa.jpg" />. We can verify the correctness of the algorithm using the example of the five consecutive playing cards.</p><p>The following is easy to prove (e.g. using induction):</p><p>Proposition 1. Let N be a positive integer, and <img src="6-1200073\09cbc516-d298-41ef-966c-6b8494c3bd9f.jpg" /> be defined as the solution of Task 2 context-free grammar, then</p><p>and if<img src="6-1200073\d15af226-bb81-41ae-a7e4-8c2d195698d2.jpg" />, then</p><p>In other words, for each positive integer N, grammar <img src="6-1200073\1066ede8-e6c4-49c1-af8f-9496cdfd7301.jpg" /> generates exactly one word that describes an algorithm for solving the task of the Hanoi towers with exactly <img src="6-1200073\1ec4a5fc-1802-405a-be4a-6115e2fe4afd.jpg" /> displacements of the disks from one pin to another.</p></sec><sec id="s3"><title>3. Pushdown Automata</title><p>By nondeterministic pushdown automation one will understand each ordered septuple</p><p><img src="6-1200073\b7797371-3cd1-4538-9806-dcf6b12c2d1c.jpg" /></p><p>where:</p><p>- K is a finite set of states of automaton;</p><p>- V is a finite set of entry letters (entry alphabet);</p><p>- W is a finite, non empty set of stack symbols (stack alphabet);</p><p>- <img src="6-1200073\52bace3b-5b05-4dc0-a765-a32cc8a7b93a.jpg" /> is a transition function;<sup>2</sup></p><p>- <img src="6-1200073\52d376e4-3355-4b8c-bef0-6d10bf099b0d.jpg" /> is a start state of automaton;</p><p>- <img src="6-1200073\bab4c824-9bd4-41a7-8629-7f05b749532c.jpg" /> is a start stack symbol;</p><p>- <img src="6-1200073\8c0f289e-e6a8-4d14-88d8-5d58762dedb7.jpg" /> is a set of accepting states.</p><p>The ordered triple <img src="6-1200073\b9b4c073-516b-4626-8e80-312cd357522d.jpg" /> will be called configuration of nondeterministic pushdown automaton M.</p><p>Let <img src="6-1200073\6d275dfe-6e0a-4b0e-b6dd-6e6b6da34249.jpg" /> <img src="6-1200073\7c4538c1-119a-47f3-ae93-1abb45202dd9.jpg" />. Then the transition function <img src="6-1200073\d11ec1d5-8ead-45d5-85ef-5a8ccf017380.jpg" /> defines a transition configuration <img src="6-1200073\dee0b59d-0924-43d4-a33d-766a301b9e16.jpg" /> to the next configuration in the following way:</p><p>1) For each pair <img src="6-1200073\736cf2be-c762-4bc6-b2b0-d0c2f51e73a8.jpg" /> the configuration <img src="6-1200073\fb6a3df6-d2bf-4f30-b4c5-59529e6ad857.jpg" /> passes in the configuration<img src="6-1200073\a5220985-cf44-49da-a2ca-1d4ee55a9c6a.jpg" />, where <img src="6-1200073\35669601-725b-4e1a-a2ce-bc0f35e8d92a.jpg" /> <img src="6-1200073\a2000bfa-669b-413d-be28-7adfed60d951.jpg" />, which we denote by<img src="6-1200073\87309e88-ea0e-4dde-b304-ad75b6677218.jpg" />.</p><p>2) For each pair <img src="6-1200073\787ecbd2-cb44-4456-a1dc-0b66c856aa1c.jpg" /> the configuration <img src="6-1200073\32dc68d5-10d1-4ce0-a094-576b27ba544b.jpg" /> passes in the configuration<img src="6-1200073\3d50a7c2-4d90-47fe-835f-0ebd390f5dfe.jpg" />, which we denote by<img src="6-1200073\d540ed60-9965-46c6-8671-fe1a506ac83d.jpg" />.</p><p>If the nondeterministic pushdown automation is initially given the word <img src="6-1200073\1ce001c2-69f0-4a16-9679-4d7214659fa3.jpg" /> then, according to the start configuration<img src="6-1200073\c5d34d1f-a8bf-4be8-9237-3b224d877da8.jpg" />, the following possible configurations are obtained by using a function of transitions<img src="6-1200073\42bdbdc2-61b1-48e3-b584-1550ca9d2e24.jpg" />. For each new configuration using <img src="6-1200073\6086509d-fa97-46b4-955f-1c0cac13c5e1.jpg" /> all possible next configurations are obtained and so on.</p><p>The nondeterministic pushdown automation <img src="6-1200073\b3e4d15a-bc19-4154-bc14-9ddb6dc36ea2.jpg" /> recognizes the word <img src="6-1200073\6da3eac3-01b3-465f-ac81-610aaea62438.jpg" /> by accepting state, if its work at the beginning of given word<img src="6-1200073\64fccb29-bd2d-428c-8795-a00b95cd6cfc.jpg" />, it reaches a configuration of type<img src="6-1200073\fbd97b84-f5ac-46b8-b216-b07d2ea7b66f.jpg" />, for each<img src="6-1200073\b1784714-9787-49a9-94de-511e22754c21.jpg" />, when<img src="6-1200073\fbf85413-7943-4654-9daa-9832a2e6e00b.jpg" />.</p><p>The nondeterministic pushdown automation M recognizes the word <img src="6-1200073\fe685968-d477-4311-93d9-ecb6ab479747.jpg" /> by empty stack, if its work at the beginning of a given word <img src="6-1200073\1e649cfc-3aa0-4047-9ce2-017e5e217344.jpg" /> reaches a configuration of type<img src="6-1200073\1d57cadd-5b64-49c1-af4f-2624eb49d5db.jpg" />.</p><p>The pushdown automation <img src="6-1200073\7fd48d9a-126a-4639-ad05-27231322a4bd.jpg" /> is called deterministic, if for each <img src="6-1200073\8909bc2a-41d9-4356-9208-f1465ea869e3.jpg" /> and <img src="6-1200073\117c6a57-15ad-4be1-aa4b-3b4f0b024900.jpg" /> exactly one of the following two conditions is valid:</p><p>1) <img src="6-1200073\3e633ba6-0303-427a-96c8-630f5c10b5c1.jpg" />contains no more than one element for each <img src="6-1200073\c36d0a29-8e82-4610-8127-af10a7d39a0b.jpg" /> and<img src="6-1200073\8aaf54c6-70aa-4f82-9c98-a3e2ad06fee9.jpg" />.</p><p>2) <img src="6-1200073\8613a64f-e6d4-45e7-b974-9492ba633b44.jpg" />for each <img src="6-1200073\94800d09-726a-4548-a713-7d86f2d2e04a.jpg" /> and <img src="6-1200073\be85bb0a-fad0-49ff-8e31-1811f641ac7c.jpg" /> contains no more than one element.</p><p>A language which is recognized by some deterministic pushdown automation is called a deterministic language. As it is known the relationship between context-free languages and pushdown automation is given by the following statements:</p><p>For each context-free language L a nondeterministic pushdown automation M exists, such that L is recognized by M through an accepting state.</p><p>Language L is recognized of a nondeterministic pushdown automation through an empty stack if and only if L is recognized of a nondeterministic pushdown automation through an accepting state.</p><p>If L is a language which is recognized by a nondeterministic pushdown automation, then L is a context-free language.</p><p>Task 3. For each positive integer <img src="6-1200073\c49f1c83-a63d-4db8-b8d8-f830796cf950.jpg" /> a deterministic pushdown automation M<sub>N</sub> should be built, which in its work should imitate the work of monks in solving the task of the Hanoi towers (see Task 1).</p><p>Solution. The requested pushdown automation is the following:<img src="6-1200073\84457f5b-78d8-4cb8-8954-7deb5b347470.jpg" />, where <img src="6-1200073\08aa67b4-0ca8-4c0f-b01e-dbc4df550cf9.jpg" /></p><p><img src="6-1200073\fc66a4c8-f3fd-4e91-9ea2-2db9524cc418.jpg" /></p><p>and <img src="6-1200073\f1e335b9-b4b9-429c-95f1-034bf422386e.jpg" /> is the empty set. Let<img src="6-1200073\9f7064fe-a284-4144-a684-02b3500dc2b7.jpg" />,<img src="6-1200073\5f05016b-052d-4199-8c2c-cd5b46cdd854.jpg" /><img src="6-1200073\8af488a7-1d48-446f-acec-af80d7c0ea47.jpg" /><img src="6-1200073\45012a52-b1af-4e50-9cd8-10015c63c819.jpg" />. Then the transition function <img src="6-1200073\6f57f698-c151-4b81-ba59-394b17c15459.jpg" /> is defined in following way:</p><disp-formula id="scirp.21127-formula118865"><label>(1)</label><graphic position="anchor" xlink:href="6-1200073\1757bc38-dc54-44fa-a461-f4d91c6ddb21.jpg"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.21127-formula118866"><label>(2)</label><graphic position="anchor" xlink:href="6-1200073\40c63f82-27cb-4ef5-b10a-226ae6159abe.jpg"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.21127-formula118867"><label>(3)</label><graphic position="anchor" xlink:href="6-1200073\4b80fa8e-05e9-4ff7-8490-ad6eb184166e.jpg"  xlink:type="simple"/></disp-formula><disp-formula id="scirp.21127-formula118868"><label>(4)</label><graphic position="anchor" xlink:href="6-1200073\e86c705c-0c3e-417f-9991-31c09daf19b8.jpg"  xlink:type="simple"/></disp-formula><p>Immediately after the inclusion of M<sub>N</sub>, before being submitted as any input signal, the automation replaces the start stack symbol z<sub>0</sub> with word <img src="6-1200073\d26b4663-6f4e-43f0-a571-54765f54813d.jpg" /> according to (1) and after a number of actions depending on the current stack symbol (2), (3), or (4). Moreover, we assume that automation M<sub>N</sub> is designed so that after the reading of the stack symbol of the type <img src="6-1200073\54a3ea20-149c-444f-8b93-dbfd4d59cc82.jpg" /> <img src="6-1200073\82bf8968-0c70-42f1-acc2-94ea8b2b1549.jpg" />, <img src="6-1200073\9039bb6c-ac7f-40b9-bd16-e845a7a74a87.jpg" />, simultaneously with the action according to (4) another action is carried out, namely the removal of top disk i-th pin on j-th. Transient function is defined so that after a finite number of beats the stack is empty and stops. This occurs because if the current stack symbol of the kind<img src="6-1200073\f42fde5a-97de-40ad-a988-0b700167dac0.jpg" />, then M<sub>N</sub> deletes it, and if the current stack symbol is of the type<img src="6-1200073\d6cb2efc-f20e-4ab2-baaa-0b10fd08e16a.jpg" />, then at the next beat of the parameter <img src="6-1200073\8eb088bc-4c3a-43f6-8562-2fc8a1286617.jpg" /> decreases by one unit, if<img src="6-1200073\6be44706-c3f6-4d47-a974-26a985b38da6.jpg" />, or <img src="6-1200073\4f5847d2-b3f7-46b1-b6f5-2ab9df31ee2b.jpg" /> passes into the symbol <img src="6-1200073\e24a463c-7e00-4946-b64d-cdc7cf6b258e.jpg" /> at<img src="6-1200073\5ce4bbec-a9e8-4ada-9c28-438cd96e8beb.jpg" />, then that symbol is deleted.</p><p>We will prove that <img src="6-1200073\65880af3-e02a-4280-8fef-a4750d42f268.jpg" /> the stack M<sub>N</sub> of configuration <img src="6-1200073\d9ea4f9b-0b10-42be-a79f-818f8c6550e3.jpg" /> where<img src="6-1200073\b696bdb1-259c-4b31-a9d8-2f63fff008ef.jpg" />, <img src="6-1200073\9c336c31-a62d-491c-a571-b23fa375b870.jpg" />, <img src="6-1200073\3836aa3c-107e-42b5-b4bd-429259ef1cc9.jpg" />as a result of their work reaches a configuration <img src="6-1200073\9a562c66-0bd4-4a71-93b2-497d5eb9f59b.jpg" /> and in the process it transfers, according to the restrictions of Task 1, s discs from pin i to pin j. When s = 1 we have<img src="6-1200073\e1474fae-85c9-4806-8e52-db7a34f9dbff.jpg" />, i.e. the assertion is met. Let’s assume that the assertion is fulfilled for any t, such that <img src="6-1200073\ad6df133-8fc5-45ce-a9aa-b43ed156c467.jpg" /> and let<img src="6-1200073\eaac45c2-fee5-42d6-b7e4-de52c49bfcf5.jpg" />. Then in<img src="6-1200073\641e2967-3a85-4129-8415-a3d8434728e3.jpg" />, <img src="6-1200073\0553e5e8-7bab-4b28-90eb-5387753b83cf.jpg" />, <img src="6-1200073\403a0e2f-8168-46b1-979a-7106aeeb6e77.jpg" />, <img src="6-1200073\6b7cfc85-7638-4e57-9eaa-0b22bb295b44.jpg" />we have<img src="6-1200073\8065ab16-cf11-43c3-bb84-2248f5def1ef.jpg" />. According to the induction assumption, M<sub>N</sub> reaches the configuration<img src="6-1200073\1d3e688d-c9b5-402e-aaf6-b750d69f1a42.jpg" /> moving t – 1 discs from i-th pin of k-th pin after which it passes in a configuration <img src="6-1200073\48ee3a1e-605f-4f38-b094-b981541b1cff.jpg" /> moving the next disc from pin <img src="6-1200073\1d0ef5ba-756f-4cae-bca1-58dfa2094392.jpg" /> to pin <img src="6-1200073\1b19ed6a-3382-4240-9036-b1d535edbccf.jpg" /> and again according to the induction, it moves <img src="6-1200073\bb2f5e85-cdd5-4724-adef-64b5f4f2c246.jpg" /> discs (as all are obviously smaller size) on this disk on pin <img src="6-1200073\a8946d71-ec16-464f-88c1-9352df4831bb.jpg" /> which are taken from pin<img src="6-1200073\66ca6517-49e9-4ff4-beb8-0317070bd9ca.jpg" />. Therefore the assertion is true for any<img src="6-1200073\ebc92a47-8346-4585-a898-830d7f126901.jpg" />.</p><p>According to the assertion that has just been just proved, we have:</p><p><img src="6-1200073\ce5c7942-179d-4376-9143-942b42589bd0.jpg" />while the stack moves to the upper <img src="6-1200073\29acdce3-7942-46e5-8fcf-dc29b49dbf18.jpg" /> discs from the first to the second pin, then it moves the biggest at the bottom from the first to the third pin and finally it moves discs (<img src="6-1200073\48b69b84-6f9a-4a40-a67c-5ea72927af48.jpg" />numbers from the second to the third pin observing the restrictions described in Task 1). Therefore the pushdown automation M<sub>N</sub> solves the task of the Hanoi towers.</p></sec><sec id="s4"><title>REFERENCES</title></sec><sec id="s5"><title>NOTES</title></sec></body><back><ref-list><title>References</title><ref id="scirp.21127-ref1"><label>1</label><mixed-citation publication-type="other" xlink:type="simple">J. Arsac, “Jeux et Casse—Tête a Programmer,” BORDAS, Paris, 1985.</mixed-citation></ref><ref id="scirp.21127-ref2"><label>2</label><mixed-citation publication-type="other" xlink:type="simple">A. V. Anisimov, “Recursive Information Transducers,” Vishcha Shkola, Kiev, 1987. </mixed-citation></ref><ref id="scirp.21127-ref3"><label>3</label><mixed-citation publication-type="other" xlink:type="simple">A. V. Anisimov, “Informatics, Creativity, Recursion,” Naukova Dumka, Kiev, 1988. </mixed-citation></ref><ref id="scirp.21127-ref4"><label>4</label><mixed-citation publication-type="other" xlink:type="simple">N. Wirth, “Algorithms + Data Structures = Programs,” Prentice Hall, Boston, 1976.</mixed-citation></ref><ref id="scirp.21127-ref5"><label>5</label><mixed-citation publication-type="other" xlink:type="simple">I. Chiswell, “A Course in Formal Languages, Automata and Groups.” Springer-Verlag, London, 2009.  
doi:10.1007/978-1-84800-940-0</mixed-citation></ref><ref id="scirp.21127-ref6"><label>6</label><mixed-citation publication-type="other" xlink:type="simple">J. Denev, R. Pavlov and I. Demetrovich, “Discrete Mathematics,” Science and Art, Soa, 1984. </mixed-citation></ref><ref id="scirp.21127-ref7"><label>7</label><mixed-citation publication-type="other" xlink:type="simple">J. Denev and S. Shtrakov, “Discrete Mathematics,” SouthWest University “N. Rilski”, Blagoevgrad, 1995.</mixed-citation></ref><ref id="scirp.21127-ref8"><label>8</label><mixed-citation publication-type="other" xlink:type="simple">J. E. Hopcroft, R. Motwani and J. D. Ullman, “Introduction to Automata Theory, Languages, and Computation,” Addison-Wesley, Boston, 2001.</mixed-citation></ref><ref id="scirp.21127-ref9"><label>9</label><mixed-citation publication-type="other" xlink:type="simple">K. Manev, “Introduction in Discrete Mathematics,” KLMN, Soa, 2003.</mixed-citation></ref><ref id="scirp.21127-ref10"><label>10</label><mixed-citation publication-type="other" xlink:type="simple">J.-P. Allouche and F. Dress. Tours de Hano? et automates. Informatique théorique et applications, 24(1):1{15, 1990. (in French).</mixed-citation></ref><ref id="scirp.21127-ref11"><label>11</label><mixed-citation publication-type="other" xlink:type="simple">J.-P. Allouche and J. Shallit, “Automatic Sequences: Theory, Applications, Generalizations,” University Press, Cambridge, 2003. doi:10.1017/CBO9780511546563</mixed-citation></ref><ref id="scirp.21127-ref12"><label>12</label><mixed-citation publication-type="other" xlink:type="simple">S. Shtrakov, K. Yordzhev and M. Todorova, “Guide for Solving of Tasks in Discrete Mathematics,” South-West University “N. Rilski”, Blagoevgrad, 2004.</mixed-citation></ref><ref id="scirp.21127-ref13"><label>13</label><mixed-citation publication-type="other" xlink:type="simple">S. Ginsburg, “The Mathematical Theory of Context-Free Languages,” McGraw-Hill, Boston, 1966.</mixed-citation></ref><ref id="scirp.21127-ref14"><label>14</label><mixed-citation publication-type="other" xlink:type="simple">G. Lallemant, “Semigroups and Combinatorial Applications,” John Wiley &amp; Sons, Hoboken, 1979.</mixed-citation></ref><ref id="scirp.21127-ref15"><label>15</label><mixed-citation publication-type="other" xlink:type="simple">A. V. Aho and J. D. Ullman, “The Theory of Parsing, Translation and Computing,” Prentice-Hall, Upper Saddle River, 1972.</mixed-citation></ref></ref-list></back></article>