Regular expression and languages

Assignment Help Theory of Computation
Reference no: EM132949812

COSC 1107 Computing Theory - RMIT University

Assignment - Fundamentals

1 Overview

This assignment is intended both for introducing you to some basic concepts that we will use in various ways later in the course, and to provide some early feedback on your progress. The are six key concepts that we will return to again and again, which are formal languages, regular expressions, grammars, finite state automata, pushdown automata and Turing machines. A common thread in all of these is nondeterminism. This will come up in various contexts, as you will see. Much of this assignment is concerned with these concepts, to ensure that you are well-versed in these fundamentals. There is another part which deals with the Platypus game.

Assessment details

A Note on Notation of Regular Expressions: Unfortunately there isn't a uniformly accepted standard notation for regular expressions. Given we are using JFLAP, our notation should be as consistent as practicable with that, but that also means some things get quite cumbersome. The two main issues are the specification of alternatives, and how to abbreviate some obvious patterns like letters and numbers.
So in this assignment the following syntactic rules will be used.

ˆ '+' will be used to denote both alternatives (as in (1+2)∗) and also to denote one or more applications of Kleene star. You must take its application within the context in which it is applied (so you will need to use your brains!).

ˆ Ranges such as all letters or all digits will be represented as [a z] meaning (a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s + t + u + v + w + x + y + z). Hopefully the reason for using ranges is now obvious!

1. Regular Expression and languages.

The Ministry of Craziness uses email addresses of the form

[a - z]([a - z] + [A - Z] + [0 - 9])∗@(([a - z])+)∗moc.com

and employee identifiers of the form
moc([0 - 9])[email protected]

(a) Explain why there are email addresses which are also employee identifiers. Give at least three examples.

(b) Explain why both of the strings gandalf @a4moc.com and Gandalf are neither email addresses nor employee identifiers.

(c) In the company archives, the following regular expression has been found. Explain what the language of this expression is in terms of email addresses and employee identifiers. Is the empty string in this language?

([a - z]([a - z] + [A - Z] + [0 - 9])∗ @ (([a - z])+)∗moc.com + moc([0 - 9])[email protected])∗
(d) A director of the Ministry of Craziness, the Cut Snake, wants to change this arrangement so that employee identifiers are now of the form
moc([0 - 9])+ and that email addresses will now be of the form (moc([0 - 9])+ + [a - z]+)@moc.com

Which email addresses are unaffected by this change (i.e. satisfy both defini- tions)? Which old email addresses are no longer valid? Explain your answer, including examples.

(e) The Ministry of Craziness, and especially the the Cut Snake, have some specific rules about phone numbers. These are below.
ˆ Mobile numbers have exactly 9 digits, commence with 0 or 9 and must end with 321.
ˆ Landline numbers have at least 4 digits, and must not finish with any of the digits 0, 2, 4, 5, 6, or 8.
ˆ Franchise numbers have exactly 6 digits, and commence with either 22 or 44.
ˆ Nothing else is a phone number.
Give a regular expression for mobile numbers, another one for landline numbers and a third one for franchise numbers.

(f) Are there any phone numbers which are both mobile numbers and landline numbers? Explain your answer.

(g) Are there any phone numbers which are both landline numbers and franchise numbers? Explain your answer.

(h) The Cut Snake then decrees that all sequences of numbers (such as the Min- istry's list of phone numbers) must be ordered in such a way that any mobile number is followed by at least two franchise numbers, and any landline number is immediately preceded by a single franchise number. If M , L and F are reg- ular expressions for mobile, landline and franchise numbers respectively, give a regular expression in terms of M , L and F that specifies legal sequences of numbers.

2. Grammars.
(a) Consider the G grammar below.
S → aSbb |

aA A → ccA

| B B → Bd

| λ
i. Give a derivation of a string in L(G) which contains at least 4 occurrences of a.
ii. Give a derivation of length at least 8 of a string in L(G). (2 marks) iii.Is λ ∈ L(G)? Explain your answer.
iv.Express L(G) in set notation. (3 marks) (b)The Cut Snake University provides students with identifiers of the form @csu - N - P

where
ˆ N is a student number in quaternary (ie each digit is either 0, 1, 2, or 3) whose length is even and at least 4, and for which the last digit is 3
ˆ P is a program specifier, also in quaternary, and whose length is an even number which is at least 2, and whose first digit is 1
For example, csu - 3003 - 13 and csu - 310213 - 1230 are valid identifiers. Give a grammar whose language contains all valid Cut Snake University iden- tifiers, and only such identifiers.

(c)Give the derivation in your grammar for the two identifiers above. (2 marks) (d)The Cut Snake himself then decrees that all student numbers and all program specifiers must be palindromes (numbers which are the same when reversed).

Give a grammar for this new version of identifiers.

(e)Given the derivation in your grammar above for the (new) identifiers @ csu -3113 - 1221 and @csu - 321123 - 123321.

3. Finite State Automata.

(a) Consider the finite state automaton M below. You can download this from Canvas here.

i. Give three examples of strings in L(M ).

ii.Give three examples of strings not in L(M ) of length at least 4.

iii.Is this machine deterministic? Justify your answer.

iv.What is L(M )? Explain your answer.

(b) Your student number is a sequence of 7 digits. Construct a finite state au- tomaton (deterministic or otherwise) which accepts a sequence of digits if it is an even number of occurrences of the last four digits of your student num- ber. For example, if your student number is 7654839, you should describe how to construct an automaton which will accept the strings 48394839 and 4839483948394839 but not 4839 and not 4839 124839 and not 48394839 12. As part of your answer show the JFLAP output for at least three strings ac- cepted by the machine and at least three strings of length 4 or more rejected by it.

(c) Consider now the problem of constructing a similar automaton, but one ac- cepts any string which contains an even number of occurrences of the last four digits of your student number. For example, this machine should now accept 4839 124839 and 48394839 12 but not 4839. How would you construct this machine? Explain your answer.

4. Pushdown Automata
Consider the PDA M1 below. You can download this from Canvas here.

(a) Show the execution of the strings aabbb, aaabb and aaabbb in M.

(b)What is L(M1)? Explain your answer.

(c)Construct a PDA M2 such that L(M2) = w w a, b, c ∗, na(w) = nb(w) .

(d)Given any two PDAs M1 and M2, it is straightforward to construct a PDA M3 such that L(M3) = L(M1) L(M2). Given the two PDAs M1 and M2 above, is there a simpler PDA for this language? Explain your answer.

5. Turing machines

Consider the Turing machine M1 below. You can download this from Canvas here. Note that the input alphabet is 7, 8, 9 and the tape alphabet is 1, 2, 7, 8, 9, B where B is the blank symbol.

(a) What is L(M1)? Explain your answer. Show some examples of strings accepted and rejected to justify your answer. You must show at least one accepted string of length at least 6, and at least one rejected string of length at least 6.

(b) Consider the machines M2 and M3, where M2 is obtained from M1 by adding the first transition below, and M3 is obtained from M1 by adding both transi- tions below. What are L(M2) and L(M3)? How do these compare to L(M1)? Explain your answer.

State Input Output Direction New State
q0 7 1 R q1
q0 9 9 R q4

(c) Consider the language L = {w|w ∈ {a, b, c}∗, na(w) = nb(w) = nc(w)}. Con- struct a Turing machine M4 such that L(M4) = L.

(d) Is M4 deterministic? Explain your answer.

(e) Consider the language L. Will M4 be helpful in constructing a machine for this language? Explain your answer.

6. Universality

Universal Turing machines are often discussed, but are rarely explicitly defined. This question requires you to report on one of the following topics. You should choose the one that you find most interesting. Some pointers and resources for each topic will be made available on Canvas.

This will form part 1 of an investigation; you will be able to build on and extend on this topic (or explore a different one if you wish) in Assignment 2.

ˆ Two-dimensional Turing machines
ˆ Small universal Turing machines
ˆ Notable universal Turine machines
Some more detail on each of these is below. Whichever topic you choose, you are expected to write around 800-1000 words (approximately 4 or 5 paragraphs).

You may also propose an alternative topic of your choice if you wish. In particular, anyone wishing to write a creative story involving a Turing machine of some kind is strongly encouraged to do so. However, for any alternative topic or creative story, please seek approval from the lecturer before commencing work on it.
Two-dimensional Turing machines

Turing machines were conceived in a less visual era. Whilst in principle the re- striction to a one-dimensional tape does not reduce the scope of programs that can be written, there is a modern reason why a two-dimensional version is much more interesting: the predominance of the computer monitor as an output device. In particular, in the modern computing environment, there is every reason to consider abstract computations which use images as basic symbols, rather than numerals or similar strings (which, for all their mathematical properties, are visually rather pro- saic). There are several varieties of two-dimensional such machines that have some rather curious properties, such as Langton's ant, Turmites and Paterson's worms.

Small universal Turing machines Universal Turing machines are often rather large. In 2007, a competition was held to determine whether or not a given 2-state 3-symbol machine was universal or not. The question was settled in the affirmative, with the winner of a US$25,000 prize being a 20-year-old undergraduate. The quest for small universal machines continues, as there is some issue about the precise definition of universality used in the competition. You can write a report about the competition itself, or on aspects of the quest for small universal Turing machines. Perhaps pick a side in the debate (i.e. was the winning machine actually universal? Should the definition of universality be changed as a result?) and argue for it. Or argue for both sides and come to your own conclusion.

Notable universal Turing machines It is remarkably difficult to find 'good' explicit examples of Turing machines. Some well-known examples include Turing's original machine, and machines built in particular ways by Minsky, Colmerauer and Wolfram. For example, Colmerauer built his machine as a means of teaching assembly language programming (!!), and intended it to be programmable. Minsky, on the other hand, derived his machine from principles of tag systems, and while it is certainly universal, it is harder to imagine programming it. There is also a relatively recent universal machine in two dimensions constructed by Dershowitz and Dowek, for which a Java implementation is available via Github.

7. The Platypus game. For this task you will need to be familiar with the Platypus game.

You have been allocated a number of machines, based on your student number.

(a) Play a tournament amongst your entire list of machines. There is SWI-Prolog code available for you to do this in Canvas. The main thing you need to do is to use your particular list of machines for the tournament. You should report your results as follows.
i. Report the top 10 machines performance, ranked in 'football' order, ie by number of wins, and if the wins are equal, by the ratio of points score for to points scored against. You should include both the tournament.csv file generated by the software in your submission, as well as include a table in your PDF file with the top 10 according to this ranking.
ii. Examine your top 10 machines. Are they any key similarities or differences between them?
iii. How does your top 10 change if the ranking is based on overall points for, rather than as above?
iv. Were there any machines without a win?

v.Suggest at least one way in which the game rules can be changed which would alter the outcome of the tournament. Keep in mind that each tournament typically involves thousands of games, so any such change must not require input from the user during the game.

(b) Time how long it takes your tournament to run. Record that time along with the basics of the machine on which it was run. For example, "My tournament involved 42,132 matches which took 156.5 seconds on a Windows 10 desktop with an Intel i7 processor and 16GB of RAM."

State

Input

Output

Direction

New State

q0

7

1

R

q1

q0

9

9

R

q4

(c) A tournament of this form involving n teams requires n(n + 1)/2 matches.1 Use your time above to calculate the average time it takes for a match on your machine, and use this value to calculate long it would take to run a tournament for 100, 1,000, 10,000, 100,000, and 1,000,000 matches. Present your results in the form of a calculation and a table of the form below.

n

Matches

Estimated time

100

 

 

1,000

 

 

10,000

 

 

100,000

 

 

1,000,000

 

 

(d) Calculate the largest Platypus tournament you can play on your machine in 4 hours, ie 4 60 60 = 14, 400 seconds. Use the value calculated above for how long it takes you to play a match.

(e) The Platypus game is entirely deterministic, and hence a little boring as en- tertainment. Suggest at least two ways in which the game can be extended to increase player involvement in the game.

(f) As discussed in lectures, some variations of the Platypus game seem appro- priate. Your tasks is to rerun your tournament with your allocated machines, with different parameters, and to compare the results. You should include at least the variations below (and more if you wish). The code to do all this will be provided.

Variation        Description

Standard        No changes; this is the original version

Tree                    5 points for whenever either tree is reached

Green            2 points rather than 1 for changing green to yellow

Short              Maximum game length of 50 rather than 100

Long               Maximum game length of 200 rather than 100

Tiebreaker     A random starting configuration is chosen with game length is 200 For each of the variations above, you should report the following results.

ˆ Time taken
ˆ Top 10 machines ˆ Number of wins ˆ Number of draws
ˆ Number of winless machines Report your results in a table like this.

 

Standard

Tree

Green

Short

Long

Tiebreaker

Time

 

 

 

 

 

 

Top 10

 

 

 

 

 

 

Wins

 

 

 

 

 

 

Draws

 

 

 

 

 

 

Winless machines

 

 

 

 

 

 

You should identify your top ten machines by the overall number, ie in the range 1 to 268,435,456.

Attachment:- Computing Theory.rar

Reference no: EM132949812

Questions Cloud

What is the first year annual depreciation on the building : What is the CAP rate? What assumptions are you making in your cap rate calculation? What is the first year annual depreciation on the building?
How much is the rent expense for the year ended december : First 6 months at P12,000 per month; next 6 months at P8,000 per month. How much is the rent expense for the year ended December 31, 2020
What is the annual and monthly interest payments : What is the annual and monthly interest payments? Based on the indicated annual NOI, are we running a negative or positive cash flow? By how much?
Choosing restore from the home window file menu will : Choosing Restore from the home window file menu will? restore the classic view home window from an enhanced view module window
Regular expression and languages : Explain why there are email addresses which are also employee identifiers. Give at least three examples and Explain why both of the strings gandalf
Enter the tracking site information for a shipper : Enter the tracking site information for a shipper -sage 50. in the purchases journal tracking site field. in the payables ledger settings window.
Explain marketing healthcare services : Do you think that too much transparency in marketing healthcare services can be a bad thing?
Objective of finance department for apple company : What is the long term and short term objective of finance department for apple company?
What the npv of the project will be : If the required rate of return is 18%, the NPV of the project will be? X corporation is a Canadian company and new subsidiary in Chile is operational from 2021.

Reviews

Write a Review

Theory of Computation Questions & Answers

  Construct a phrase-structure grammar

Construct a phrase-structure grammar for the set of all fractions of the form a/b, where a is a signed integer in decimal notation and b is a positive integer.

  Explain proof of rice-s theorem for infinite language

If you perform reduction in proof of Rice's theorem for special case of property P: "infinite language", does this reduction also show that language P L = { | N is Turing machine.

  Analysis and formal reasoning about complex concepts

COMP30026 Models of Computation Assignment, The University of Melbourne, Australia. To develop skills in analysis and formal reasoning about complex concepts

  Describe languages denoted by regular expressions

Describe the languages denoted by the following regular ex-pressions and write regular expressions for the languages over the alphabet {a, b}

  Argue that the problem is np complete

Argue that the following prob is NP Complete. Given list of positive integers, u1,u2,...un (in binary representation) and asked if there is partition of this set into 3 subsets, each of which has same sum.

  Benefits that can arise from from the inclusion of ai

Managing a Successful Computing Project - Potential benefits and challenges that can arise from the inclusion of AI into a system

  How would go about interpreting regular expressions

Regular expressions, automata/computability/theory of computation :How would I go about interpreting regular expressions?

  Analyze information technology issues

Evaluate and justify theoretical and practical knowledge of information technology in a business context - Understand the ICT profession in information

  Construct a finite-state automaton with four states

Construct a finite-state automaton with four states that recognizes the set of bit strings containing an even number of 1s and an odd number of 0s.

  List three major components of bell-lapadula model

List 3 major components of Bell-LaPadula Model. Provide specific examples to explain how these 3 major components work. What are the limitations of this model.

  Briefly describe how your machine works

Describe a TM that solves the acceptance problem. Provide a brief but complete English description of how the machine works.

  Create a program that makes an object

Create a class named Pet, after creating the class, create a program that makes an object of the class and prompts the user to enter the name, type, and age of his pet.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd