instruction
stringlengths
0
29.8k
⌀
(Initially this question was on cstheory, but I was told cs would be a better fit, so posting it here.) All other things being equal, which of the following languages would be more challenging to design a compiler and/or interpreter for? (If the answer would vary depending on whether one is designing a compiler or...
Programming language implementation challenge: is recursion harder than HOFs, or vice versa?
|programming-languages|compilers|recursion|functional-programming|interpreters|
I apologize if I did not use the terminology entirely correctly in the title. This problem seems to me quite similar to an assignment problem and likely something that occurs in real life in business. **The problem**: - In this problem, we have a set of assets (in the economics/finance sense) $\left\{ a_i \right\}...
null
(Initially this question was on cstheory, but I was told cs would be a better fit, so posting it here.) All other things being equal, which of the following languages would be more challenging to design a compiler and/or interpreter for? (If the answer would vary depending on whether one is designing a compiler or...
The Pumping Lemma says that if a language is regular then there is an associated natural number, the pumping length. The point of that length is that for any string in the language at least as long as that length, that string has a decomposition, etc. So the short answer is that you look at one decomposition, not all...
Show that the following language or problem is not recursive: $$ L=\{\langle M,w\rangle\mid \text{computation of TM } M \text{ on input } w \text{ uses all states of } M\} $$ I was trying to prove it using reduction, but I cannot seem to find a language to reduce it to. I also tried it for the complement of L: $$ ...
Decidable or Not: Set of all Turing Machines M that on input w uses all states of M
|turing-machines|computability|undecidability|
I see a repeated pattern here, and I'm unsure how to help. I believe the question is meaningless, so instead of trying to answer an ill-defined question that I don't think can be answered, I'm going to instead try to see if I can offer something to help you achieve better understanding of the topic more broadly. I se...
Seth Lloyd claims in [this video][1] that free will stems from our impossibility of determining how a system capable of self-reference will behave in the future (e.g. whether a human being will have chosen to drink tea or coffee in 5 minutes). He relates this to Gödel's incompleteness theorem in a way that seems comple...
Self-referential systems cannot predict their future behaviour? (reference request)
|turing-machines|incompleteness|
It sounds like a very muddled analysis. "Data structures" are fundamentally a system of *addressing* - the management of the *placement* of values in a systematic way. It is not merely a "collection" of data values, but a collection that is ordered or arranged in a particular way. It is no more concerned with the...
The decomposition of the input string matches exactly a cycle in the finite state machine used to parse the language. So you have to either find one suitable decomposition that meets the conditions of the pumping lemma (in that case it is quite likely but not guaranteed the language is regular), or you show no such...
I'm assuming that $M$ is a decider and that by "all states" you are excluding the accepting and rejecting state. Given a Turing machine $M$, you can build an equivalent Turing machine $M'$ that behaves like $M$ except that $M'$: - has one additional state $q$ and one additional tape symbol $x$; - whenever $M$ woul...
I see a repeated pattern here, and I'm unsure how to help. I believe the question is meaningless, so instead of trying to answer an ill-defined question that I don't think can be answered, I'm going to instead try to see if I can offer something to help you achieve better understanding of the topic more broadly. I se...
The Pumping Lemma says that if a language is regular then there is an associated natural number, the pumping length. The point of that length is that for any string in the language at least as long as that length, that string has a decomposition, etc. So the short answer is that you look at one decomposition, not all...
null
I'm not going to watch or engage with the video but to answer your question, it is possible for a self-referencing function to make statements about its own behaviour. Fix an encoding of programs. There is a program with index $e$ that takes another program index as an argument and searches for proofs about the beha...
null
I'm not going to watch or engage with the video but to answer your question, it is possible for a self-referencing program to make statements about its own behaviour. Fix an encoding of programs. There is a program with index $e$ that takes another program index as an argument and searches for proofs about the behav...
Please note I don't use any of the "verifier" notation, I only concern definitions made with DTM and NTM . Now there are two definitions of *decidability*: **1. A set (predicate) is decidable (solvable) iff exist a machine (DTM/NTM) M(x) that accepts iff x∈A, and rejects iff x∉A. i.e. if it halts correctly agains...
Which definition of decidable is correct?
|algorithms|complexity-theory|time-complexity|turing-machines|
Please note I don't use any of the "verifier" notation, I only concern definitions made with DTM and NTM . Now there are two definitions of *decidability*: **1. A set (predicate) is decidable (solvable) iff exist a machine (DTM/NTM) M(x) that accepts iff x∈A, and rejects iff x∉A. i.e. if it halts correctly agains...
Please note I don't use any of the "verifier" notation, I only concern definitions made with DTM and NTM . Now there are two definitions of *decidability*: **1. A set (predicate) is decidable (solvable) iff exist a machine (DTM/NTM) M(x) that accepts iff x∈A, and rejects iff x∉A. i.e. if it halts correctly agains...
Please note I don't use any of the "verifier" notation, I only concern definitions made with DTM and NTM . Now there are two definitions of *decidability*: **1. A set (predicate) is decidable (solvable) iff exist a machine (DTM/NTM) M(x) that accepts iff x∈A, and rejects iff x∉A. i.e. if it halts correctly agains...
#1 looks good, but check a textbook for a formal, precise definition. None of the sources you mentioned are authoritative sources for this. If you need a correct definition, you should be consulting a textbook, not Internet sources. A textbook would be an authoritative source for the definitions of decidability....
Can you please explain to me why the following is true? Ιf 3SAT reduces to its complement then NP=coNP. Thoughts: 3SAT is NP-complete so for every X in NP $X \leq 3SAT$ $\overline {3SAT} $ is NP-complete so for every Y in coNP $Y \leq \overline {3SAT} $ So, $X \leq 3SAT \leq \overline {3SAT}$ ...
Ιf 3SAT reduces to its complement then NP=coNP
|np-complete|reductions|np|complexity-classes|3-sat|
Consider $N$ points that are located on a 2D plane where the $i$-th point’s location is denoted as $(x_i, y_i)$. Is there any efficient algorithm that can compute $d_i$ that is defined as the number of points with $x<x_i$ and $y<y_i$ for all $i$? In other words, we would like to count the number of points on the low...
Efficient algorithm to compute the number of points at the lower left of another point
|algorithms|
Consider $N$ points that are located on a 2D plane where the $i$-th point’s location is denoted as $(x_i, y_i)$. Is there any efficient algorithm that can compute $d_i$ that is defined as the number of points with $x<x_i$ and $y<y_i$ for all $i$? In other words, we would like to count the number of points on the low...
|algorithms|computational-geometry|
I am wondering if my solution is correct or I am on the right track. I have searched online and found a paper about [Java type system being unsound](https://dl.acm.org/doi/10.1145/2983990.2984004) but that doesn't really answer the progress and preservation issue. Question: Give a non-obvious problem in the langu...
Example of progress and preservation failing in a commonly used programming language like Java
|types-and-programming-languages|
Sort the points from left to right. Then scan from left to right, keeping the points sorted by ordinate in a balanced search tree. Now every time you insert a new point, the tree contains all points to its left and by finding the insertion point in the tree you obtain the number of lower points. These two steps e...
Sort the points from left to right. Then scan from left to right, keeping the points met sorted by ordinate in a balanced search tree. Now every time you insert a new point, the tree contains all points to its left and by finding the insertion point in the tree you obtain the number of lower points. These two ste...
If we have a regular expression $R$, will $R$ describe only regular language $L$, but that language $L$ can have multiple different regular expressions such as $Q,W,A,S,D \ etc..$ describing it Also, $R$ can be equivalent, in terms of describing $L$, to infinite regular expressions including $ Q,W,A,S,D \ etec..$ ...
Does every regular expression describe only 1 language?
|regular-languages|finite-automata|regular-expressions|
Primitive data types are predefined entities that the language handles atomically. E.g. a floating-point number. Data structures are user-defined aggregates created using the primitive data types and the aggregation rules supported by the language. E.g. a list of pairs of integers. An Abstract Data Type is a data...
Primitive data types are predefined entities that the language handles atomically. They have no structure. E.g. a floating-point number. Data structures are user-defined aggregates created using the primitive data types and the aggregation rules supported by the language. E.g. a list of pairs of integers. An Abst...
Let's say that we have a DFA, where the initial state was also the accept state. Meaning the DFA accepts the "empty string". Now, let's say that we convert the DFA to regular expression $R$, using Arden's Method ( my prefered method ) Now, the resultant expression looks something like $(R)^*$, which is obviously cap...
When converting DFA/NFA to regular expression, where the DFA/NFA accepted empty string, is it okay to not have empty string as kleene star?
|formal-languages|regular-expressions|
I have a sequence of integer tuples $t_0, t_1,..., t_{N-1}$ of different sizes in lexicographic order, e.g.: $(1, 1), (1, 2), (1, 3, 5), (1, 3, 6), (1, 5), (3), (3, 2, 3), (3, 7), (3, 8, 1), ...$ - sequence length is $N \le 10^9 \space (2^{30})$, - a tuple size bounded by $S, |t| \le S$, - $i$-th element of...
Ordered hash function with fast inverse
|time-complexity|search-algorithms|hash|
I have a sequence of integer tuples $t_0, t_1,..., t_{N-1}$ of different sizes in lexicographic order, e.g.: $(1, 1), (1, 2), (1, 3, 5), (1, 3, 6), (1, 5), (3), (3, 2, 3), (3, 7), (3, 8, 1), ...$ - sequence length is $N \le 10^9 \space (2^{30})$, - a tuple size bounded by $S, |t| \le S$, - $i$-th element of...
Perfect ordered hash function on ordered sequence
If the start state is also a final state, then the empty word **must** be in the interpretation of the regular expression you obtain. That does not necessarily mean that the regular expression $e$ you obtain is of the form $E = F^*$, for example, the interpretation of $(a+b)^*aab(a+b)^*\mid (ba)^*$ contains the empt...
If $e$ is a regular expression such that $\mathcal{L}(e) = L$, then so is $e+\emptyset$, $e+\emptyset+\emptyset$, …
Hint 1: $Y\in \text{co}\mathsf{NP}$ if and only if $\overline{Y}\in\mathsf{NP}$. Hint 2: $A\leqslant B$ if and only if $\overline{A}\leqslant \overline{B}$.
For $A \in \mathsf{NP}$ you have $ A \le_p 3SAT \le_p \overline{3SAT} \in \mathsf{co{\text -}NP}$, which implies $A \in \mathsf{co{\text -}NP}$ and hence $\mathsf{NP} \subseteq \mathsf{co{\text -}NP}$. Simmetrically, for $A \in \mathsf{co{\text -}NP}$, you have $A \le_p \overline{3SAT} \le_p 3SAT \in \mathsf{NP}$, ...
I've seen arguments for $P \ne NP$ that rely on certain intuitions about how the real world actually is, generally making the point that it "makes sense" that there exist problems which have an *easily verifiable* solution that's *hard to find.* For example, on his blog, Scott Aaronson has a ["Reasons to believe"][1...
null
I have the following alphabet $\Sigma = \{0,\dots,9\}$ and the following language over $\Sigma \cup \{\#\}$: $$L=\{\#w \ |\ w \in\Sigma^*,\sum_{i\geq1}w_i\ \text{is prime}\}\\$$ This language represents all numbers wich have a prime as digit sum. I now want to show that this language is not context free. I want to ...
It's an exercise question from chapter 0 of Michael Sipser's book Introduction to the Theory of Computation. >e. The set containing the empty string >f. The set containing nothing at all I guess the empty string is still something, which is not nothing. This would be the difference?
What is the difference between the set contatining the empty string and the set contating nothing at all?
|sets|
There are several problems in your proof. The language $L$ indeed is not context-free, and the pumping lemma can be used to prove it. However: - you cannot choose the value of $k$ yourself; - you cannot choose the values of $x, u, y, v$ and $z$ yourself. The pumping lemma states that if $L$ is context-free, t...
Yes, that's it. One important difference could be seen using concatenation: let $L$ be any nonempty language. Then $\{\varepsilon\}L = L$, but $\emptyset L = \emptyset$. Clearly those are different.
Of course it is a possibility that $\mathrm{P} = \mathrm{NP}$, and the best algorithm for SAT takes $O(n^{1000!})$. However, this feels much ***weirder*** than having an $O(n^3)$ algorithm for SAT (with reasonable coefficients). The reason for this feeling weird is the following heuristic: > Naturally occurring natu...
I have a sequence of integer tuples $t_0, t_1,..., t_{N-1}$ of different sizes in lexicographic order, e.g.: $(1, 1), (1, 2), (1, 3, 5), (1, 3, 6), (1, 5), (3), (3, 2, 3), (3, 7), (3, 8, 1), ...$ - sequence length is $N \le 10^9 \space (2^{30})$, - a tuple size bounded by $S, |t| \le S \le 32$, - $i$-th ele...
I have a sequence of integer tuples $t_0, t_1,..., t_{N-1}$ of different sizes in lexicographic order, e.g.: $(1, 1), (1, 2), (1, 3, 5), (1, 3, 6), (1, 5), (3), (3, 2, 3), (3, 7), (3, 8, 1), ...$ - sequence length is $N \le 10^9 \space (2^{30})$, - a tuple size bounded by $S, |t| \le S \le 32$, - $i$-th ele...
I am doing an exercise related to maximizing Independent Set, I have, `G = (V = {v1, . . . , vn}, E)`as an undirected graph. This graph as n! possible orderings for the vertices V. <br> If we pick any such orderings uniformly at random i.e. let `σ = (σ1, . . . , σn).` be such random ordering then consider, <br> Beg...
Prove that algorithm achieves expected value of at least 1/d fraction of the optimal solution
|graphs|sets|set-cover|vertex-cover|
I am doing an exercise related to maximizing Independent Set, I have, `G = (V = {v1, . . . , vn}, E)`as an undirected graph. This graph as n! possible orderings for the vertices V. <br> If we pick any such orderings uniformly at random i.e. let `σ = (σ1, . . . , σn).` be such random ordering then consider, <br> Beg...
I am doing an exercise related to maximizing Independent Set, I have, `G = (V = {v1, . . . , vn}, E)`as an undirected graph. This graph as n! possible orderings for the vertices V. <br> If we pick any such orderings uniformly at random i.e. let `σ = (σ1, . . . , σn).` be such random ordering then consider, <br> Beg...
null
I am doing an exercise related to maximizing Independent Set, I have, `G = (V = {v1, . . . , vn}, E)`as an undirected graph. This graph as n! possible orderings for the vertices V. <br> If we pick any such orderings uniformly at random i.e. let `σ = (σ1, . . . , σn).` be such random ordering then consider, <br> Beg...
Intuitively speaking, it would seem like the graph isomorphism problem (which might be $NP$-intermediate) should be $P$-hard. But maybe it's not? Or maybe it's an open question? If it is indeed $P$-hard, how can that be shown/argued? ----- Doing some searching, I found the following statement in the [Wikipedia...
Is graph isomorphism $P$-hard?
|complexity-theory|graphs|graph-isomorphism|
I am doing an exercise related to maximizing Independent Set, I have, `G = (V = {v1, . . . , vn}, E)`as an undirected graph. This graph as n! possible orderings for the vertices V. <br> If we pick any such orderings uniformly at random i.e. let `σ = (σ1, . . . , σn).` be such random ordering then consider, <br> Beg...
I was wondering, in terms of complexity and "precision", what are the differences, if any, netween the computation of $$2R \sin(\alpha)\cos(\alpha) \qquad \qquad \text{and} \qquad \qquad R\sin(2\alpha)$$ It's the same thing, for it is a goniometric identity. So are there differences in terms of order of complexi...
Complexity time complexity in computing $R\sin(2\alpha)$ VS $2R\sin(\alpha)\cos(\alpha)$
|complexity-theory|time-complexity|computability|asymptotics|
I am doing an exercise related to maximizing Independent Set, I have $G = (V = \{v_1, . . . , v_n\}, E)$ as an undirected graph. This graph as $n!$ possible orderings for the vertices $V$. If we pick any such orderings uniformly at random i.e. let $\sigma = (\sigma_1, . . . , \sigma_n)$ be such random ordering then ...
|graphs|approximation|
|programming-languages|lambda-calculus|types-and-programming-languages|
Order of time complexity in computing $R\sin(2\alpha)$ VS $2R\sin(\alpha)\cos(\alpha)$
null
The problem here is that the reduction used is unclear in your question. Both fact are correct, but the $\mathsf{P}$-hardness claim concern logspace-reduction, so it is not contradictory with the fact that $\texttt{Graph-Iso}\in\mathsf{P}\Rightarrow \mathsf{GI}=\mathsf{P}$. In other terms: - $\texttt{Graph-Iso}...
Donald Knuth's *The Art of Computer Programming, Volume 1 Fascicle 1* contains the following exercise: > If $\alpha$ is any string of 0s and 1s, let $\operatorname{s}(\alpha)$ and $\operatorname{u}(\alpha)$ be the integers that it represents when regarded as a signed or unsinged binary number. Prove that, if $x$ is ...
Donald Knuth's *The Art of Computer Programming, Volume 1 Fascicle 1* contains the following exercise: > If $\alpha$ is any string of 0s and 1s, let $\operatorname{s}(\alpha)$ and $\operatorname{u}(\alpha)$ be the integers that it represents when regarded as a signed or unsinged binary number. Prove that, if $x$ is ...
The difference is essentially structural. In the case of the set containing the empty string, the set has a length of 1. In the case of the set containing nothing, the set has a length of 0. A string is typically conceived as a container of characters (as opposed to say an int, which is not typically conceived...
Let $H=\left( E_0 ,E_1 ,E_2 , \ldots , E_d \right)$ be a $d$-dimensional full-hyper graph/complex. That is to say, if for some $i\in \left[d \right]$ the hyper-edge $e_j \in E_i$ than for any $i-1$-dimensional $e_k \subset e_j$: $e_k \in E_{i-1}$. The vertices are $E_0$, the hyper-edges between $2$ vertices are $E_1$, ...
A general way to check if two sets are equal: **two sets $S_1$ and $S_2$ are equal if (i) all of the elements in $S_1$ are in $S_2$, and (ii) all of the elements in $S_2$ are in $S_1$.** This property is called "extensionality". In your case, let's apply the definition. Our first set, $S_1$ is the set containing the...
I have a sequence of integer tuples $t_0, t_1,..., t_{N-1}$ of different sizes in lexicographic order, e.g.: $(1, 1), (1, 2), (1, 3, 5), (1, 3, 6), (1, 5), (3), (3, 2, 3), (3, 7), (3, 8, 1), ...$ - sequence length is $N \le 10^9 \space (2^{30})$, - a tuple size bounded by $S, |t| \le S \le 32$, - $i$-th ele...
I have a sequence of integer tuples $t_0, t_1,..., t_{N-1}$ of different sizes in lexicographic order, e.g.: $(1, 1), (1, 2), (1, 3, 5), (1, 3, 6), (1, 5), (3), (3, 2, 3), (3, 7), (3, 8, 1), ...$ - sequence length is $N \le 10^9 \space (2^{30})$, - a tuple size bounded by $S, |t| \le S \le 32$, - $i$-th ele...
Let $Y_v$ be the random variable that indicates whether vertex $v$ is added to the independence set. The probability that $v$ appears before all vertices that are incident to $v$ in a random ordering is $\frac1{\deg(v)+1}$, since all orderings are equally likely and all $\deg(v)+1$ vertices involved are symmetric to on...
If $s(\alpha)=-1$, then $s(\alpha)\equiv_{2^n}2^n-1\not\equiv_{2^n}1$ for any $n>1$. Another argument you may find compelling: if $a \equiv_m b$, then $a-b$ is a multiple of $m$. Since $x-s(\alpha)=1-(-1)=2$ is prime, $x$ and $s(\alpha)$ can only be equivalent mod 1 or 2.