computer-science

Does an algorithm exist which can determine whether one regular language matches any input another regular language matches?

醉酒当歌 提交于 2019-11-27 01:07:49
问题 Let's say we have regular expressions: Hello W.*rld Hello World .* World .* W.* I would like to minimize the number of regexes required to match arbitrary input. To do that, I need to find if one regular expression matches any input matched by another expression. Is that possible? Billy3 回答1: Any regular expression can be linked to a DFA - you can minimize the DFA and since the minimal form is unique, you can decide whether two expressions are equivalent. Dani Cricco pointed out the Hopcroft

Is finding the equivalence of two functions undecidable?

一个人想着一个人 提交于 2019-11-27 01:02:17
Is it impossible to know if two functions are equivalent? For example, a compiler writer wants to determine if two functions that the developer has written perform the same operation, what methods can he use to figure that one out? Or can what can we do to find out that two TMs are identical? Is there a way to normalize the machines? Edit: If the general case is undecidable, how much information do you need to have before you can correctly say that two functions are equivalent? Given an arbitrary function, f , we define a function f' which returns 1 on input n if f halts on input n . Now, for

What is a Lambda?

给你一囗甜甜゛ 提交于 2019-11-27 00:04:10
Could someone provide a good description of what a Lambda is? We have a tag for them and they're on the secrets of C# question, but I have yet to find a good definition and explanation of what they are in the first place. Closures, lambdas, and anonymous functions are not necessarily the same thing. An anonymous function is any function that doesn't have (or, at least, need) its own name. A closure is a function that can access variables that were in its lexical scope when it was declared, even after they have fallen out of scope. Anonymous functions do not necessarily have to be closures, but

How to deal with overflow and underflow?

喜夏-厌秋 提交于 2019-11-26 23:17:25
I am new to Matlab and trying to figure out how can I deal with overflow and underflow arithmetic when the answer is actually within the range. For example: x = 2e+160 x = x*x (which returns inf, an overflow) x = sqrt(x) (which is in the range) any help is appreciated. I am not a Matlab user so take that in mind. The main problem behind this is first to detect overflow/underflows That is sometimes hard because they appear also in other cases when the computation does not return zero or inf . For example during numerical integration overflow/underflows can cause the result to be wrong but still

Regular Expressions with repeated characters

让人想犯罪 __ 提交于 2019-11-26 20:57:26
I need to write a regular expression that can detect a string that contains only the characters x,y, and z, but where the characters are different from their neighbors. Here is an example xyzxzyz = Pass xyxyxyx = Pass xxyzxz = Fail (repeated x) zzzxxzz = Fail (adjacent characters are repeated) I thought that this would work ((x|y|z)?)*, but it does not seem to work. Any suggestions? EDIT Please note, I am looking for an answer that does not allow for look ahead or look behind operations. The only operations allowed are alternation, concatenation, grouping, and closure Usually for this type of

Is there ever a good reason to use Insertion Sort?

十年热恋 提交于 2019-11-26 19:49:17
For general-purpose sorting, the answer appears to be no, as quick sort, merge sort and heap sort tend to perform better in the average- and worst-case scenarios. However, insertion sort appears to excel at incremental sorting, that is, adding elements to a list one at a time over an extended period of time while keeping the list sorted, especially if the insertion sort is implemented as a linked list (O(log n) average case vs. O(n)). However, a heap seems to be able to perform just (or nearly) as well for incremental sorting (adding or removing a single element from a heap has a worst-case

Converting EBNF to BNF

岁酱吖の 提交于 2019-11-26 19:46:50
问题 It's been a few years since my computer-language class and so I've forgotten the finer points of BNF's and EBNF's and I don't have a textbook next to me. Specifically, I've forgotten how to convert an EBNF into BNF. From what little I remember, I know that one of the main points is to convert { term } into <term> | <many-terms> . But I don't remember the other rules. I've tried to look this up online but I can only find links to either homework questions, or a small comment about converting

What exactly is the halting problem?

廉价感情. 提交于 2019-11-26 19:46:26
Whenever people ask about the halting problem as it pertains to programming, people respond with "If you just add one loop, you've got the halting program and therefore you can't automate task " Makes sense. If your program has an infinite loop, then when your program is running, you have no way of knowing whether the program is still crunching input, or if it is just looping infinitely. But some of this seems counter intuitive. What if I was writing a halting problem solver, which takes source code as its input. rascher@localhost$ ./haltingSolver source.c If my code (source.c) looks like this

What is referential transparency?

给你一囗甜甜゛ 提交于 2019-11-26 19:10:50
What does the term referential transparency mean? I've heard it described as "it means you can replace equals with equals" but this seems like an inadequate explanation. Uday Reddy The term "referential transparency" comes from analytical philosophy , the branch of philosophy that analyzes natural language constructs, statements and arguments based on the methods of logic and mathematics. In other words, it is the closest subject outside computer science to what we call programming language semantics . The philosopher Willard Quine was responsible for initiating the concept of referential

Why binary and not ternary computing?

做~自己de王妃 提交于 2019-11-26 19:07:18
问题 Isn't a three state object immedately capable of holding more information and handling larger values? I know that processors currently use massive nets of XOR gates and that would need to be reworked. Since we are at 64 bit (we can represent 2^63 possible states) computing the equivalent ternary generation could support number with 30 more tens places log(3^63-2^63). I imagine it is as easy to detect the potential difference between +1 and 0 as it is between -1 and 0. Would some compexity of