regular-language

Why is {a^n a^n | n >= 0} regular?

前提是你 提交于 2019-12-19 11:34:06
问题 I understand the reason and the proof why {a^n b^n | n >= 0} is NOT regular. Why is {a^nb^n | n >= 0} not regular? The solution of one of my exercises is: {a^n a^n | n >= 0} is regular. How can I prove this thesis? 回答1: Yes, Language {a n a n | n >= 0} is a regular language . To proof that certain language is regular, you can draw its dfa/regular expression. And you can drive do for this language as follows: Because " a n a n for n >= 0 " is same as " a 2n for n >=0", and that is "set of all

Generative regular expressions

∥☆過路亽.° 提交于 2019-12-18 12:34:44
问题 Typically in our work we use regular expressions in capture or match operations. However, regular expressions can be used - manually at least - to generate legal sentences that match the regular expression. Of course, some regular expressions can match infinitely long sentences, e.g., the expression .+ . I have a problem that could be solved by using a regular expression sentence generating algorithm. In pseudocode, it would operate something like this: re = generate("foo(bar|baz)?", max

Determining whether a regex is a subset of another

ぃ、小莉子 提交于 2019-12-17 21:46:46
问题 I have a large collection of regular expression that when matched call a particular http handler. Some of the older regex's are unreachable (e.g. a.c* ⊃ abc* ) and I'd like to prune them. Is there a library that given two regex's will tell me if the second is subset of the first? I wasn't sure this was decidable at first (it smelled like the halting problem by a different name). But it turns out it's decidable. 回答1: Trying to find the complexity of this problem lead me to this paper. The

Regular vs Context Free Grammars

丶灬走出姿态 提交于 2019-12-17 07:59:56
问题 I'm studying for my computing languages test, and there's one idea I'm having problems wrapping my head around. I understood that regular grammars are simpler and cannot contain ambiguity, but can't do a lot of tasks that are required for programming languages. I also understood that context-free grammars allow ambiguity, but allow for some things necessary for programming languages (like palindromes). What I'm having trouble with is understanding how I can derive all of the above by knowing

How does “δ:Q×Σ→Q” read in the definition of a DFA (deterministic finite automaton)?

不想你离开。 提交于 2019-12-17 07:38:55
问题 How do you say δ: Q × Σ → Q in English? Describing what × and → mean would also help. 回答1: δ is like a mathematical function called the transition function . Something like. z = f(x, y) A function in mathematical defines mapping of elements in one set to another set. In function set of input arguments are called Domain of a function and output is the rage. [ANSWER] In expression "δ:Q×Σ → Q" , × means Cartesian product (that is a set), and → is a mapping . "δ:Q×Σ → Q" says δ is a transition

drawing minmal DFA for the given regular expression

房东的猫 提交于 2019-12-17 06:51:14
问题 What is the direct and easy approach to draw minimal DFA , that accepts the same language as of given Regular Expression(RE) . I know it can be done by: Regex ---to----► NFA ---to-----► DFA ---to-----► minimized DFA But is there any shortcut way? like for (a+b)*ab 回答1: Regular Expression to DFA Although there is NO algorithmic shortcut to draw DFA from a Regular Expression(RE) but a shortcut technique is possible by analysis not by derivation, it can save your time to draw a minimized dfa.

Is a*b* regular?

狂风中的少年 提交于 2019-12-17 05:11:11
问题 I know a n b n for n > 0 is not regular by the pumping lemma but I would imagine a*b* to be regular since both a,b don't have to be the same length. Is there a proof for it being regular or not? 回答1: Answer to your question: imagine a*b* to be regular, Is there a proof for it being regular or not? No need to imagine, expression a*b* is called regular expression (re), and regular expressions are possible only for regular languages. If a language is not a regular then regular expression is also

Determine if a language is context free

早过忘川 提交于 2019-12-13 22:30:55
问题 Lets say you have a language L and you want to determine if it is context free. Context free languages intersected with regular languages are context free. Is that enough to prove that L is context free? Meaning, L intersect P = T Where P is a regular language and T is context free. Does this imply that L is context free? 回答1: No, your statement is not true. Consider the following counter-example: L = {0 n 1 n 2 n | n > 0}, P = T = Ø . Clearly we have L ∩ P = L ∩ Ø = Ø = T , and Ø is both

Regular Expression Star Symbol

拟墨画扇 提交于 2019-12-13 17:42:02
问题 Maybe I have missed something, but what are wrong with this regular expresion? var str = "lorem ipsum 12345 dolor"; var x = /\d+/.exec(str); var y = /\d*/.exec(str); console.log(x); // will print 12345 console.log(y); // will print "" but why ? Can you please explain why /\d*/.exec(str); returns an empty string instead of "12345". * means zero or more number of matches. 回答1: \d* matches zero or more digits in a row. When you run exec on a regex, it starts at the beginning of the input and

Prove that a context-free-grammar is regular

耗尽温柔 提交于 2019-12-13 01:43:23
问题 I know that to prove that a language is non-regular one can use the pumping-lemma. I think I understand how it works, but when it comes to showing that a context-free-grammar is (or isn't regular) I'm having big problems. Here is an example of a CFG that I can't understand how to show is regular (or non-regular): i) S → NP VP ii) NP → DET N iii) VP → TV NP iv) N → N N v) N → A N vi) NP → Mary |John vii) DET → a |the |her |his viii) TV → bought |loves |misses ix) N → bike |jersey |mountain