instruction
stringlengths
0
29.8k
⌀
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
> Re-posting from [cstheory.SE](http://cstheory.stackexchange.com/q/10676/1546) as suggested I'm a graduate student taking a course in theory of computation and I'm having serious trouble producing content once I'm asked to. I'm able to follow the textbook ( Introduction to the Theory of Computation by Michael Sipse...
My only advice would be that you start from the beginning. In my course we use Sipser's book too, it is a good book in my opinion. But we do have a course before TC, named FLA (Formal Languages an Automaton) that gave be a better intuition and background on TC. So, again, everybody learns at different rates, and yo...
Abstraction is pretty much bread and butter in computer science but unfortunately is hard to teach explicitly. In my opinion, *understanding* concepts it more important than being able to mechanically calculate or proof stuff. Sure, you need to know your way around some elementary methods, but the meat lies elsewher...
I have been working on dynamic programming for some time. The canonical way to evaluate a dynamic programming recursion is by creating a table of all necessary values and filling it row by row. See for example [Cormen, Leiserson et al: "Introduction to Algorithms"](http://mitpress.mit.edu/catalog/item/default.asp?ttype...
When searching graphs, there are two easy algorithms: **breadth-first** and **depth-first** (Usually done by adding all adjactent graph nodes to a queue (breadth-first) or stack (depth-first)). Now, are there any advantages of one over another? The ones I could think of: - If you expect your data to be pretty...
graph searching: Breadth-first vs. depth-first
|algorithms|graphs|searching|
Abstraction is pretty much bread and butter in computer science but unfortunately is hard to teach explicitly. In my opinion, *understanding* concepts it more important than being able to mechanically calculate or proof stuff. Sure, you need to know your way around some elementary methods, but the meat lies elsewher...
Abstraction is pretty much bread and butter in computer science but unfortunately it is hard to teach explicitly. In my opinion, *understanding* concepts is more important than being able to mechanically calculate or prove stuff. Sure, you need to know your way around some elementary methods, but the meat lies elsew...
null
Breadth-first and depth-first certainly have the same worst-case behaviour (the desired node is the last one found). I suspect this is also true for averave-case if you don't have information about your graphs. One nice bonus of breadth-first search is that it finds shortest paths (in the sense of fewest edges) whic...
One scenario (other than finding the shortest path, which has already been mentioned) where you may have to choose one over the other to get a correct program would be infinite graphs: If we consider for example a tree where each node has a finite number of children, but the height of the tree is infinite, DFS might...
$u+1=v$ is indeed a post-condition of the while loop (why do you think it's “clearly” not the case?). This is always the case with a while loop that doesn't contain a `break`: when the loop exits, it can only be because the loop condition (here, $u+1 \neq v$) is false. It's not the only thing that will be true when the...
How is the loop invariant obtained in this square root bound finding algorithm?
|algorithms|invariants|
Our professor asked us to think of a function in OCaml that has the type 'a -> 'b i.e. a function of one argument that could be anything, and that can return a different anything. I thought of `raise`, but the professor said there was a solution that doesn't require any function in the standard library. I'...
ML function of type 'a -> 'b
|typing|
The skeleton is `let f x = BODY`. In BODY you must use x only in generic ways (for example, don't send it to a function that expects integers), and you must return a value of *any* other type. But how can the latter part be true? There are exactly two possibilities: either BODY faults or it doesn't terminate. The funct...
First, some remarks. Using only the core typed lambda calculus it's not possible to obtain `'a -> 'b` because the typing system is in correspondence (via the [Curry Howard isomorphism][1]) to intuitionistic logics, and the corresponding formula `A → B` is not a tautology. Other extensions such as tuples and matching...
$u+1=v$ is indeed a post-condition of the while loop (why do you think it's “clearly” not the case?). This is always the case with a while loop that doesn't contain a `break`: when the loop exits, it can only be because the loop condition (here, $u+1 \neq v$) is false. It's not the only thing that will be true when the...
Our professor asked us to think of a function in OCaml that has the type 'a -> 'b i.e. a function of one argument that could be anything, and that can return a different anything. I thought of using `raise` in a function that ignores its argument: let f x = raise Exit But the professor said there...
Meta-knowledge: you want to find a non-decidable language which nonetheless has some computational property. An arbitrary non-decidable language is probably not going to lead you very far. But a semi-decidable one… ---- Stronger hint: what's a semi-decidable language? It means we can enumerate the words: it's som...
First, some remarks. Using only the core typed lambda calculus it's not possible to obtain `'a -> 'b` because the typing system is in correspondence (via the [Curry Howard isomorphism][1]) to intuitionistic logics, and the corresponding formula `A → B` is not a tautology. Other extensions such as tuples and matching...
I remember coming across the following question about a language that's supposedly is context-free, but I was unable to find a proof of the fact. Have I perhaps misremembered the question. Anyway, here's the question: > Show that the following language is context free $\{xy | |x| = |y| but x\neq y\}$.
Context freeness of certain language
|formal-languages|
I remember coming across the following question about a language that's supposedly is context-free, but I was unable to find a proof of the fact. Have I perhaps misremembered the question? Anyway, here's the question: > Show that the following language is context free $\{xy | |x| = |y| but x\neq y\}$.
Semantics formally describe the meaning of some syntax.
null
First, some remarks. Using only the core typed lambda calculus it's not possible to obtain `'a -> 'b` because the typing system is in correspondence (via the [Curry Howard isomorphism][1]) to intuitionistic logics, and the corresponding formula `A → B` is not a tautology. Other extensions such as tuples and matching...
I remember coming across the following question about a language that supposedly is context-free, but I was unable to find a proof of the fact. Have I perhaps misremembered the question? Anyway, here's the question: > Show that the following language is context free $\{xy \mid |x| = |y|, x\neq y\}$.
|formal-languages|context-free|
The only reason I can imagine is the following scenario: 1. An original implementation of a file system existed with the same directory format but the notions of file paths and subdirectories was not considered at that time (See [The PDP-7 Unix file system][1]). 2. Then people thought that path resolution and s...
|programming-languages|typing|
I'd like to quote [an answer from Stack Overflow][1] which covers the problem nicely: > **That heavily depends on the structure of the search tree and the number and location of solutions**. If you know a solution is not far from the root of the tree, a breadth first search (BFS) might be better. If the tree is ...
To my knowledge the pumping lemma is *by far* the simplest and most-used technique. If you find [it][1] hard, try the [regular version][2] first, it's not that bad. There are some other means for languages that are far from context free. For example undecidable languages are trivially not context free. That said, I ...
I'd like to quote [an answer from Stack Overflow][1] by [hstoerr](http://stackoverflow.com/users/21499/hstoerr) which covers the problem nicely: > **That heavily depends on the structure of the search tree and the number and location of solutions**. If you know a solution is not far from the root of the tree, a ...
In Hromkovič's "[Algorithmics for Hard Problems](http://www.ite.ethz.ch/publications/buch/index_EN)" (2nd edition) there is this theorem (2.3.3.3, page 117): > There is a decision problem $P$ such that for every algorithm $A$ that solves $P$ there is another algorithm $A'$ that also solves $P$ and additionally fulfi...
Wanted: proof for interesting theorem
|complexity-theory|
To my knowledge the pumping lemma is *by far* the simplest and most-used technique. If you find [it][1] hard, try the [regular version][2] first, it's not that bad. There are some other means for languages that are far from context free. For example undecidable languages are trivially not context free. That said, I ...
I'm working on a parser for a C-style language, and for that parser I need the regular expression that matches C-style /**/ comments. Now, I've found this expression on the web: /\*((!\*)*\*+(!*|!/))*((!\*)*\*+|(!\*)*\*/ However, as you can see, this is a rather messy expression, and I have no idea whether it...
Deriving the regular expression for C-stype /**/ comments
|compilers|parsers|regular-languages|
I remember coming across the following question about a language that supposedly is context-free, but I was unable to find a proof of the fact. Have I perhaps misremembered the question? Anyway, here's the question: > Show that the language $L = \{xy \mid |x| = |y|, x\neq y\}$ is context free.
I can think of two ways: 1. Define an automaton for the language you are interested in. Convert the regular expression to an automaton (using Brzozowski's derivatives). Check that both automata accept the same language (determinize and minimize or use a bisimulation argument). 2. Write loads of test cases and app...
I can think of four ways: 1. Define an automaton for the language you are interested in. Convert the regular expression to an automaton (using Brzozowski's derivatives). Check that both automata accept the same language (determinize and minimize or use a bisimulation argument). 2. Write loads of test cases and ap...
**Claim**: $L$ is context-free. **Proof Idea**: There has to be at least one difference between the first and second half; we give a grammar that makes sure to generate one and leaves the rest arbitrary. **Proof**: For sake of simplicity, assume a binary alphabet $\Sigma = \\{a,b\\}$. The proof readily extends to...
You can think of the social graph as a matrix $\mathbf{M}$. One approach to the problem is to first calculate $\mathbf{M}^2$, which will give all of the paths of length two between two actors in the social network. This can be seen as the weight of the connection between these friends of friends. The next step is to se...
**Claim**: $L$ is context-free. **Proof Idea**: There has to be at least one difference between the first and second half; we give a grammar that makes sure to generate one and leaves the rest arbitrary. **Proof**: For sake of simplicity, assume a binary alphabet $\Sigma = \{a,b\}$. The proof readily extends to o...
I came across this figure, expressing that context-free and regular languages are subset of efficient problems. I perfectly understand that efficient problems are subset of undecidable problems because we can solve them but it could take a very long time. Why are **all** context-free and regular languages sufficient? ...
Is this categorizing correct?
|automata|undecidability|regular-languages|context-free|efficiency|
**Claim**: $L$ is context-free. **Proof Idea**: There has to be at least one difference between the first and second half; we give a grammar that makes sure to generate one and leaves the rest arbitrary. **Proof**: For sake of simplicity, assume a binary alphabet $\Sigma = \{a,b\}$. The proof readily extends to o...
null
Yes. Regular language membership can be decided in linear time. Context free language membership can be decided in $O(n^3)$. There are decidable languages that are not in $P$, such as those in ${EXPTIME}$.
Is this categorizing correct: context-free and regular languages are subset of efficient problems?
null
What you're looking for is a heuristic. No algorithm can say, given a graph of friends as the only input, whether two individuals not directly connected are friends or aren't; the friendship/acquaintance relation isn't guaranteed to be transitive (we can assume symmetry, but that might even be a stretch in real life). ...
Show that $L = \{xy \mid |x| = |y|, x\neq y\}$ is context free
null
Show that the language of non-squares is context-free
**Claim**: $L$ is context-free. **Proof Idea**: There has to be at least one difference between the first and second half; we give a grammar that makes sure to generate one and leaves the rest arbitrary. **Proof**: For sake of simplicity, assume a binary alphabet $\Sigma = \{a,b\}$. The proof readily extends to o...
Show that $\{xy \mid |x| = |y|, x\neq y\}$ is context-free
Regular language membership can be decided in linear time. Context free language membership can be decided in $O(n^3)$. There are decidable languages that are not in $P$, such as those in ${EXPTIME}$.
Decision problem such that any solution admits an exponentially faster solution
Regular language membership can be decided in $\cal{O}(n)$ time by simulating the language's (minimal) DEA (which has been precomputed). Context free language membership can be decided in $\cal{O}(n^3)$ by the [CYK Algorithm](https://en.wikipedia.org/wiki/CYK_algorithm). There are decidable languages that are n...
What you're looking for is a heuristic. No algorithm can say, given a graph of friends as the only input, whether two individuals not directly connected are friends or aren't; the friendship/acquaintance relation isn't guaranteed to be transitive (we can assume symmetry, but that might even be a stretch in real life). ...
I was reading an article that described the switch between user-space and kernel-space that happens upon a system call. The article said > An application expects the completion of the system call before resuming user-mode execution. Now, until now I was assuming that some system calls are `blocking`, where as ot...
Are all system calls blocking?
|kernel|
I came across this figure which suggests that context-free and regular languages are (proper) subsets of efficient problems (supposedly $\mathrm{P}$). I perfectly understand that efficient problems are a subset of all decidable problems because there are problems we can solve but it could take a very long time. Why...
Are all context-free and regular languages efficiently decidable?
In Hromkovič's "[Algorithmics for Hard Problems](http://www.ite.ethz.ch/publications/buch/index_EN)" (2nd edition) there is this theorem (2.3.3.3, page 117): > There is a (decidable) decision problem $P$ such that for every algorithm $A$ that solves $P$ there is another algorithm $A'$ that also solves $P$ and additi...
I'm working on a parser for a C-style language, and for that parser I need the regular expression that matches C-style /**/ comments. Now, I've found this expression on the web: /\*([^\*]*\*+[^\*/])*([^\*]*\*+|[^\*]*\*/ However, as you can see, this is a rather messy expression, and I have no idea whether it ...
In Hromkovič's [Algorithmics for Hard Problems](http://www.ite.ethz.ch/publications/buch/index_EN) (2nd edition) there is this theorem (2.3.3.3, page 117): > There is a (decidable) decision problem $P$ such that for every algorithm $A$ that solves $P$ there is another algorithm $A'$ that also solves $P$ and addition...
Decision problem such that any algorithm admits an exponentially faster algorithm
You seem to be overloading the term 'blocking'. Any context switch you make to the kernel, you have to wait for it to switch back to the usermode before your application can continue. This is not what is usually called 'blocking'. Blocking calls are calls where the kernel returns only when the request is complet...
Excellent question. I believe the answer is yes. Evolving a cellular automaton is essentially equivalent to performing a stencil computation. On some 1D, 2D, or 3D grid, successive values of points (or cells) are computed based on the last value of point's neighborhood. In a simple 1D CA, this neighborhood might be ...
|operating-systems|kernel|
Regular language membership can be decided in $\cal{O}(n)$ time by simulating the language's (minimal) DFA (which has been precomputed). Context free language membership can be decided in $\cal{O}(n^3)$ by the [CYK Algorithm](https://en.wikipedia.org/wiki/CYK_algorithm). There are decidable languages that are n...
|algorithms|formal-languages|regular-languages|context-free|
Excellent question. I believe the answer is yes. Evolving a cellular automaton is essentially equivalent to performing a stencil computation. On some 1D, 2D, or 3D grid, successive values of points (or cells) are computed based on the last value of point's neighborhood. In a simple 1D CA, this neighborhood might be ...
It seems to be a simple case of [Blum's Speedup Theorem](http://en.wikipedia.org/wiki/Blum's_speedup_theorem).
I am reading about atomicity and came across the following scenario int x = y = z = 0; Thread 1 Thread 2 --------- -------- x = y + z y = 1 z = 2 Which gives the following sets of output $$\begin{array}{ccc}1&2&3\\ T1 : x = y + z&T2 : y = 1&T2 : y =...
Which instruction yields atomicity in this expression that makes the result 2?
|concurrency|
It seems to be a simple case of [Blum's Speedup Theorem](http://en.wikipedia.org/wiki/Blum's_speedup_theorem): >Given a Blum complexity measure $(\varphi, \Phi)$ and a total computable function $f$ with two parameters, then there exists a total computable predicate $g$ (a Boolean valued computable function) so that ...
|operating-systems|programming-languages|concurrency|
I was reading an article that described the switch between user-space and kernel-space that happens upon a system call. The article said > An application expects the completion of the system call before resuming user-mode execution. Now, until now I was assuming that some system calls are `blocking`, where as ot...
It seems to be a simple case of [Blum's Speedup Theorem](http://en.wikipedia.org/wiki/Blum's_speedup_theorem): >Given a Blum complexity measure $(\varphi, \Phi)$ and a total computable function $f$ with two parameters, then there exists a total computable predicate $g$ (a Boolean valued computable function) so that ...
The point you are missing is that in thread $y$ is loaded into $r1$ and that any subsequent changes to $y$ will not affect the value stored in $r1$. Thus, the value in $r1$ is $0$ even after statement $y=1$. From this it is easy to see that the result is $x=2$.
The skeleton is `let f x = BODY`. In BODY you must use x only in generic ways (for example, don't send it to a function that expects integers), and you must return a value of *any* other type. But how can the latter part be true? The only way to satisfy the statement "for all types `'b`, the returned value is a value o...
Regarding the quantum [Toffoli gate](https://en.wikipedia.org/wiki/Toffoli_gate): 1. is it *classicaly* universal, and if so, why? 1. is it *quantumly* universal, and why?
Gilles is right that the general technique is to go fishing for interesting observations. In this case, you may observe that the program is an instance of binary search, because it has the following shape: while i + 1 != k j := strictly_between(i, k) if f(j) <= X then i := j if f(j) > X t...
I came across this figure which shows that context-free and regular languages are (proper) subsets of efficient problems (supposedly $\mathrm{P}$). I perfectly understand that efficient problems are a subset of all decidable problems because we can solve them but it could take a very long time. Why are *all* contex...
|formal-languages|regular-languages|context-free|efficiency|