instruction
stringlengths
0
29.8k
⌀
In the following grammar that is used for math expressions(and other grammars) how do I know where should I place action symbols(@add, @mul, @pushID)? Is there a algorithm for it? <pre> E -> TE` E'-> +T @add E'|ϵ T -> FT` T'-> xF @mul T'|ϵ F -> (E)|@pushID id </pre> For example why @add is between `+T` and `E...
Where should we place action symbols in a grammar?
|formal-grammars|compilers|
null
to complete Raphael's answer, there is an extension of Rice's theorem that says the following: > Generalized Rice's Theorem > === > Let $S \subseteq RE$ be some property, and let $L_S$ be all the TMs that satisfy the property $S$, that is, > $$L_S = \{ \langle M \rangle \mid L(M) \in S \}.$$ > Then, $L_S \in RE$...
Authoritative answers can be found in Cardelli and Wegner's survey article: [On Understanding Types, data abstraction and polymorphism](http://dl.acm.org/citation.cfm?id=6041.6042). Mind you that, while "strong typing" has an accepted meaning, "weak typing" doesn't. Any failure of strong typing might be considered ...
null
Here is the document: [More Undecidable Problems][1] Suppose we got: $$L_{p} = \{ L(M_{0}), L(M_{1}), L(M_{2}),..., L(M_{n}) \}$$ $$M_{i}\mspace{8mu} \text{is}\mspace{8mu} \text{an}\mspace{8mu} i\text{th}\mspace{8mu} \text{Turing} \mspace{8mu} \text{machine},\mspace{8mu} i ≤ n. $$ If $P$ is a trivial property,...
I think I got it. Here is Rice's Theorem ([Rice Theorem and Turing machine b ehavior prop erties][1]): ![Rice's Theorem][2] I looked it up here: [Decidability][3] for the definition of a problem in the context of Turing Machine (slides 9 and 11): > - Formally, a problem is a language. > - Each string encod...
I think I got it. Here is Rice's Theorem ([Rice Theorem and Turing machine b ehavior prop erties][1]): ![Rice's Theorem][2] I looked it up here: [Decidability][3] for the definition of a problem in the context of Turing Machine (slides 9 and 11): > - Formally, a problem is a language. > - Each string encod...
I’m working on a compiler for a concatenative language and would like to add type inference support. I understand Hindley–Milner, but I’ve been learning the type theory as I go, so I’m unsure of how to adapt it. Is the following system sound and decidably inferable? A term is a literal, a composition of terms, a quo...
Type inference with product types
|type-theory|type-checking|
Here is the document: [More Undecidable Problems][1] Suppose we got: $$L_{p} = \{ ⟨M_{0}⟩, ⟨M_{1}⟩, ⟨M_{2}⟩,..., ⟨M_{n}⟩ \}$$ $$M_{i}\mspace{8mu} \text{is}\mspace{8mu} \text{an}\mspace{8mu} i\text{th}\mspace{8mu} \text{Turing} \mspace{8mu} \text{machine},\mspace{8mu} i ≤ n. $$ If $P$ is a trivial property, $L_...
null
This is a good question, but some Googling would have told you that [there is no general method for deciding ambiguity][1], so you need to make your question more specific. [1]: http://cstheory.stackexchange.com/questions/4352/how-is-proving-a-context-free-language-to-be-ambiguous-undecidable
Basically, it's a child generation problem. Start with the first expression, and generate it's children .... Keep doing it recursively (DFS), and after quite a few iterations, see if you can generate the same expanded expression from two different children. If you are able to do that, it's ambiguous. There is no way to...
My problem is how can i prove that a grammar is unambiguous? I have the following grammar: $$S → statement ∣ \mbox{if } expression \mbox{ then } S ∣ \mbox{if } expression \mbox{ then } S \mbox{ else } S$$ and make this to an unambiguous grammar, I think its correct: - $ S → S_1 ∣ S_2 $ - $S_1 → \mbox{if ...
null
Is the following recurrence for this program's runtime correct?
|algorithms|algorithm-analysis|runtime-analysis|recurrence-relation|
|formal-grammars|context-free|proof-techniques|
There is (at least) one way to prove unambiguity of a grammar $G = (N,T,\delta,S)$ for language $L$. It consists of two steps: 1. Prove $L \subseteq \mathcal{L}(G)$. 2. Prove $[z^n]S_G(z) = |L_n|$. The first step is pretty clear: show that the grammar generates (at least) the words you want, that is correctn...
My problem is how can I prove that a grammar is unambiguous? I have the following grammar: $$S → statement ∣ \mbox{if } expression \mbox{ then } S ∣ \mbox{if } expression \mbox{ then } S \mbox{ else } S$$ and make this to an unambiguous grammar, I think its correct: - $ S → S_1 ∣ S_2 $ - $S_1 → \mbox{if ...
How to prove that a grammar is unambiguous?
There is (at least) one way to prove unambiguity of a grammar $G = (N,T,\delta,S)$ for language $L$. It consists of two steps: 1. Prove $L \subseteq \mathcal{L}(G)$. 2. Prove $[z^n]S_G(z) = |L_n|$. The first step is pretty clear: show that the grammar generates (at least) the words you want, that is correctn...
Here is the document: [More Undecidable Problems][1] For a given property $P$ of languages, define $L_P$ as the set of all Turing machines (resp. their encodings) that accept languages with $P$, that is $\qquad \displaystyle L_{p} = \{ ⟨M⟩ \mid \mathcal{L}(M) \text{ has property } P \}$ If $P$ is a trivial pro...
**tl;dr: NO. Well, okay, maybe.** Translating the pseudocode mechanically into a recurrence gives me $$ T(n) = \Theta(1) + F(n) + \max \begin{cases} \max_{0\le s \le n/4} T(s) \\ \\ \max_{n/4 < s < n} (T(s) + T(n-s)) \end{cases} $$ where $F(n)$ is the time for the first "find" step. Every outcome t...
**tl;dr: NO. Well, okay, maybe.** Translating the pseudocode mechanically into a recurrence gives me $$ T(n) = \Theta(1) + F(n) + \max \begin{cases} \max_{0\le s \le n/4} T(s) \\ \\ \max_{n/4 < s < n} (T(s) + T(n-s)) \end{cases} $$ where $F(n)$ is the time for the first "find" step. Every outcome t...
I’m working on a compiler for a concatenative language and would like to add type inference support. I understand Hindley–Milner, but I’ve been learning the type theory as I go, so I’m unsure of how to adapt it. Is the following system sound and decidably inferable? A term is a literal, a composition of terms, a quo...
The [Expression Problem][1], populated by Philip Wadler, is a often used to standard problem to evaluate programming languages. I think it is a very clear and popular example and I wonder if there are any similar standard problems that are possibly also as widely used and as clear. So, are there any similar st...
Expression Problem – looking for a similar standard problem
|reference-request|programming-languages|software-engineering|
null
I'm not sure that the problem is formulated quite as nicely, but the problem of implementing concurrency in an efficient manner has occupied at least as much effort as the expression problem, and prompted a [number of solutions][1], including the use of [semaphores][2] and [software transactional memory][3]. I'm cer...
Consider the following query: SELECT Customer.Name FROM Customer INNER JOIN Order on Order.CustomerId = Customer.Id WHERE Customer.Preferred = True AND Order.Complete = False Let's suppose all of the relevant attributes (Customer.Preferred, Order.Complete, Order.CustomerId and Customer.Id...
null
null
I wrote a [blogpost][1] about using minimax to play connect four a while ago. You can see the code in action [here][2]. [1]: http://lukasvermeer.wordpress.com/2011/09/24/connect-four-and-minimax/ [2]: http://destack.home.xs4all.nl/projects/minimax/
Ordering functions generally take a set of data to sort an a comparison function which can compare to individual elements. The assumption is that the compare function is stable, otherwise the sort may not product valid results. I am wondering though which sort algorithms would actually _work_ with a non-stable compa...
Sorting algorithms which can accept a random ordering
|algorithms|randomized-algorithms|sorting|
Ordering functions generally take a set of data to sort an a comparison function which can compare to individual elements. The assumption is that the compare function is stable, otherwise the sort may not product valid results. I am wondering though which sort algorithms would actually _work_ with a non-stable* comp...
Any algorithm that compares the same two elements twice is not a very clever algorithm, and in particular such an algorithm would perform less well than the [most common sorting algorithms][1] (merge-sort, quicksort, bubble-sort, insertion-sort). Any algorithm that compares pairs of elements at most once has the same (...
Ordering functions generally take a set of data to sort and a comparison function which can compare two individual elements. The assumption is that the compare function is stable¹, otherwise the sort may not product valid results. I am wondering though which sort algorithms would actually _work_ with a non-stable co...
In the context of our investigation of [heap automata](http://cs.stackexchange.com/questions/110/determining-capabilities-of-a-min-heap-or-other-exotic-state-machines), I would like to prove that a particular variant can not accept non-context-sensitive languages. As we have no equivalent grammar model, I need a proof ...
How to prove that ε-loops are not necessary in PDAs?
|automata|pushdown-automata|
It seems to me that the *per-record timeline consistency* as defined by Cooper et al. in "PNUTS: Yahoo!’s Hosted Data Serving Platform" mimics the (older?) definition of *monotonic writes*. From the paper: > per-record timeline consistency: all replicas of a given record apply > all updates to the record in the sam...
per-record timeline consistency vs. monotonic writes
|distributed-systems|
null
Maybe I am missing something obvious, but can it be that P = co-NP $\subsetneq$ NP or vice versa? My feeling is that there must be some theorem that rules out this possibility.
Can exactly one of NP and co-NP be equal to P?
|complexity-theory|p-vs-np|
$P$ is closed under complement (i.e. $P=\mbox{co-}P)$ so if $P=\mbox{co-}NP$ (or $P=NP$) then $\mbox{co-}NP = NP$
No, because P is closed to complement this cant be, and we even know that $P=NP \implies NP=co-NP$. <br><br> Let us assume that $P=NP$, and let $L \in co-NP$, thus $L^c \in NP$. We assumed $P=NP$, and therefore there exists a TM $M$ s.t. $L(M)=L^c$. If we take the "complement" of $M$, that is a machine $M'$ which is i...
$P$ is closed under complement (i.e. $P=\mbox{co-}P$ (*)); so if $P=\mbox{co-}NP$ (or $P=NP$) then $\mbox{co-}NP = NP$ (*) given a language $L \in P$, we can construct a deterministic TM' that decides $\overline L$ in polynomial time simply by taking the TM that decides $L$ and ...
Is the following statement always true: > if there is a mixed-strategy Nash equilibria then it is unique. I know that there can be several pure strategy Nash equilibrias.
Mixed-strategy Nash equilibria
|untagged|
|game-theory|
|programming-languages|logic|compilers|type-theory|type-checking|
Suppose there are 2 databases, 1 and 2. Let's further assume 1 is always up and 2 can be down sometimes. (When it goes up again, it has to restart.) 1 is filled by say a dozen other systems with event messages. Those messages have IDs and might be updated or deleted. 2 needs to be in sync with 1, which is realiz...
Uni-directional synchronization and locking issues
|untagged|
|distributed-systems|database-theory|
The following rank-2 type $$\text{compose}:\forall ABC\delta. \delta\ (\forall \alpha.\alpha\ A\to \alpha B)\ (\forall \beta.\beta\ B\to \beta C) \to \delta\ (\forall \gamma.\gamma\ A\to \gamma C)$$ seems to be sufficiently general. It is much more polymorphic than the type proposed in the question. _Greek letter...
Equipartition Problem: Instance: $2n$ positive integers $x_1,\dots,x_{2n}$ such that their sum is even. Let $B$ denote half their sum, so that $\sum x_{i} = 2B$. Query: Is there a subset $I \subseteq [2n]$ of size $|I| = n$ such that $\sum_{i \in I} x_{i} = B$? Can the <a href="http://en.wikipedia.org/wiki/Par...
Reduction to equipartition problem from the partition problem?
|complexity-theory|reductions|
|complexity-theory|reductions|np-hard|
Apologies if my question is very naive. Is it theoretically possible to specify a language for which no implementation could exist? What is are the minimal requirements of such a language?
Programming Lang Spec paradox
|formal-languages|
|formal-languages|computability|
So basically, you want to know if there is any sorting algorithm which wouldn't degrade from its average case if given a compare function similar to: int Compare(object a, object b) { return Random.Next(-1,1); } ... where Random.Next() is some method that will produce a randomly-generated number between a spe...
So basically, you want to know if there is any sorting algorithm which wouldn't degrade from its average case if given a compare function similar to: int Compare(object a, object b) { return Random.Next(-1,1); } ... where Random.Next() is some method that will produce a randomly-generated number between a spe...
null
This is a followup to [Tsuyoshi Ito's answer above](http://cs.stackexchange.com/a/2265/1786), summarizing the most relevant portion of the [GKZ05 paper](http://www.combinatorics.org/ojs/index.php/eljc/article/view/v12i1r50) he cited. The paper proves NP-completeness via an easy equivalence with the Maximal Independe...
Generic sorting algorithms generally take a set of data to sort and a comparator function which can compare two individual elements. If the comparator is an order relation¹, then the output of the algorithm is a sorted list/array. I am wondering though which sort algorithms would actually _work_ with a comparator th...
Sorting algorithms which accept a random comparator
Any algorithm that compares the same two elements twice is not a very clever algorithm, and in particular such an algorithm would perform less well than the [most common sorting algorithms][1] (merge-sort, quicksort, bubble-sort, insertion-sort). Any algorithm that compares pairs of elements at most once has the same (...
I want to determine which part of audio file contain speech or music. I hope someone has a made something like this or can tell me where to start. Can you please suggest some method/tutorial for doing the same. Thank you.
Speech/ Music classification
|reference-request|
|reference-request|
So basically, you want to know if there is any sorting algorithm which wouldn't degrade from its average case if given a compare function similar to: int Compare(object a, object b) { return Random.Next(-1,1); } ... where Random.Next() is some method that will produce a randomly-generated number between a spe...
So basically, you want to know if there is any sorting algorithm which wouldn't degrade from its average case if given a compare function similar to: int Compare(object a, object b) { return Random.Next(-1,1); } ... where Random.Next() is some method that will produce a randomly-generated number between a spe...
Is it theoretically possible to specify a language for which no implementation could exist? What is are the minimal requirements of such a language?
Can you specify a language without implementation?
Suppose there are two databases, $D_1$ and $D_2$. Let's further assume $D_1$ is always up and $D_2$ can be down sometimes. When it goes up again, it has to restart. $D_1$ is filled by say a dozen other systems with event messages. Those messages have IDs and might be updated or deleted. $D_2$ needs to be in sync w...
So basically, you want to know if there is any sorting algorithm which wouldn't degrade from its average case if given a compare function similar to: int Compare(object a, object b) { return Random.Next(-1,1); } ... where Random.Next() is some method that will produce a randomly-generated number between a spe...
No, because $\mathsf{P}$ is closed to complement this cant be, and we even know that $\mathsf{P}=\mathsf{NP} \implies \mathsf{NP}=\mathsf{co\text{-}NP}$. Let us assume that $\mathsf{P}=\mathsf{NP}$, and let $L \in \mathsf{co\text{-}NP}$, thus $L^c \in \mathsf{NP}$. We assumed $\mathsf{P}=\mathsf{NP}$, and therefore ...
$\mathsf{P}$ is closed under complement (i.e. $\mathsf{P}=\mathsf{co\text{-}P}$ ¹); so if $\mathsf{P}=\mathsf{co\text{-}NP}$ (or $\mathsf{P}=\mathsf{NP}$) then $\mathsf{co\text{-}NP} = \mathsf{NP}$ --- 1. Given a language $L \in \mathsf{P}$, we can construct a deterministic TM' that decides $\overline L$ in polyn...