automata

Context Free Language Question (Pumping Lemma)

风格不统一 提交于 2019-12-01 00:57:00
问题 I know this isn't directly related to programming, but I was wondering if anyone know how to apply the pumping lemma to the following proof: Show that L={(a^n)(b^n)(c^m) : n!=m} is not a context free language I'm pretty confident with applying pumping lemmas, but this one is really irking me. What do you think? 回答1: Edit: I was totally leading you down the wrong track. That's what happens when I try to help out when I haven't completely solved the problem myself. Ogden's Lemma Suppose L is

How are finite automata implemented in code?

空扰寡人 提交于 2019-11-30 07:09:13
问题 How does one implement a dfa or an nfa for that matter in Python code? What are some good ways to do it in python? And are they ever used in real world projects? 回答1: A straightforward way to represent a DFA is as a dictionary of dictionaries. For each state create a dictionary which is keyed by the letters of the alphabet and then a global dictionary which is keyed by the states. For example, the following DFA from the Wikipedia article on DFAs can be represented by a dictionary like this:

NFA/DFA implementation in C#

筅森魡賤 提交于 2019-11-30 00:50:00
Does anyone know of any good NFA and DFA implementation in C#, possibly implementing as well conversions between both? What I would like would be to be able to construct a NFA and then convert it automatically to a DFA, but without having to write my own code which would take a very long time. There is this Python code which perhaps I could use and integrate with C# using IronPython, but Python is slow. Take a look at my series of posts about this subject: Regular Expression Engine in C# (the Story) Regex engine in C# - the Regex Parser Regex engine in C# - the NFA Regex engine in C# - the DFA

Can someone give a simple but non-toy example of a context-sensitive grammar? [closed]

这一生的挚爱 提交于 2019-11-29 10:34:36
问题 I'm trying to understand context-sensitive grammars, and I understand why languages like {ww | w is a string} {a n b n c n | a,b,c are symbols} are not context free, but what I'd like to know if a language similar to the untyped lambda calculus is context sensitive. I'd like to see an example of a simple, but non-toy (I consider the above toy examples), example of a context-sensitive grammar that can, for some production rule, e.g., tell whether or not some string of symbols is in scope

How are finite automata implemented in code?

最后都变了- 提交于 2019-11-29 03:43:05
How does one implement a dfa or an nfa for that matter in Python code? What are some good ways to do it in python? And are they ever used in real world projects? A straightforward way to represent a DFA is as a dictionary of dictionaries. For each state create a dictionary which is keyed by the letters of the alphabet and then a global dictionary which is keyed by the states. For example, the following DFA from the Wikipedia article on DFAs can be represented by a dictionary like this: dfa = {0:{'0':0, '1':1}, 1:{'0':2, '1':0}, 2:{'0':1, '1':2}} To "run" a dfa against an input string drawn

NFA/DFA implementation in C#

懵懂的女人 提交于 2019-11-28 21:40:00
问题 Does anyone know of any good NFA and DFA implementation in C#, possibly implementing as well conversions between both? What I would like would be to be able to construct a NFA and then convert it automatically to a DFA, but without having to write my own code which would take a very long time. There is this Python code which perhaps I could use and integrate with C# using IronPython, but Python is slow. 回答1: Take a look at my series of posts about this subject: Regular Expression Engine in C#

Design Pattern problem involving N states and transitions between them

只愿长相守 提交于 2019-11-28 16:15:10
I have a problem at hand and I am not getting which design pattern to use. The problem goes as such: I have to build a system which has 'N' states and my system has to do a transition from any state to any other state depending on some conditions. Ex: On condition 1, movement from State 1 to 3 and on condition 2 from state 1 to 4. Even the transition from one state to other state can be done on 2 or more different conditions. For example, transition from State 1 to state 3 can be done when: condition 1 : "Its a Sunday" condition 2: "Its Raining" condition 3: "Its Raining and Sunday" In each

What will be the DFA for the regular expression 0(0+1)*0+1(0+1)*1?

孤人 提交于 2019-11-27 16:22:39
This is the DFA i have drawn- Is it correct? I am confused because q4 state has 2 different transitions for same input symbol which violates the rule of DFA , but I can't think of any other solution. Your DFA is not correct. your DFA is completely wrong so I don't comment DFA for RE: 0(1 + 0)*0 + 1(1 + 0)*1 Language Description : if string start with 0 it should end with 0 or if string start with 1 it should end with 1 . hence two final states (state-5, state-4). state-4 : accepts 1(1 + 0)*1 state-5 : accepts 0(1 + 0)*0 state-1 : start state. DFA : EDIT : + Operator in Regular Expression (0 +

Grammatical inference of regular expressions for given finite list of representative strings?

删除回忆录丶 提交于 2019-11-27 13:11:38
I'm working on analyzing a large public dataset with lots of verbose human-readable strings that were clearly generated by some regular (in the formal language theory sense) grammar. It's not too hard to look at sets of these strings one by one to see the patterns; unfortunately, there's about 24,000 of these unique strings broken up into 33 categories and 1714 subcategories, so it's somewhat painful to do this manually. Basically, I'm looking for an existing algorithm (preferably with an existing reference implementation ) to take an arbitrary list of strings and try to infer some minimal

Design DFA accepting binary strings divisible by a number 'n'

不打扰是莪最后的温柔 提交于 2019-11-27 09:59:07
I need to learn how to design a DFA such that given any number 'n', it accepts binary strings {0, 1} whose decimal equivalent number is divisible by 'n'. There will be different DFAs for different 'n', but can somebody give a basic approach that I should follow to proceed with any number 0 < n < 10 . Grijesh Chauhan Below, I have written an answer for n equals to 5, but you can apply same approach to draw DFAs for any value of n and 'any positional number system' e.g binary, ternary... First lean the term 'Complete DFA', A DFA defined on complete domain in δ:Q × Σ→Q is called 'Complete DFA'.