instruction stringlengths 0 29.8k ⌀ |
|---|
|formal-languages|turing-machines|automata| |
Integers modulo a square-free number $r$ can be represented by their value modulo each of $r$'s prime factors, according the Chinese remainder theorem.
Given a number represented like that, is there an efficient way to calculate its representation modulo $r^2$, that is, its remainder modulo each of $r$'s prime facto... |
Efficient algorithm to "lift" a number in CRT representation mod r to mod $r^2$ |
|algorithms|number-theory|integers|modular-arithmetic| |
null |
Integers between 0 and a square-free number $r$ minus one can be represented by their value modulo each of $r$'s prime factors, according the Chinese remainder theorem.
Given a number represented like that, is there an efficient way to calculate its representation fot $r^2$, that is, its remainder modulo each of $r$... |
The constraints on $w, x,y, z$ are not given, I choose everyone $\geq 0.$
The strings could be equal $a$ and equal $d,$ equal $b$ and equal $c,$ equal $b$ and equal $d,$ equal $a$ and equal $c $ etc.(since $w, x,y, z\geq 0.$)
$S\to aSd$
$X\to aXc$
$Y\to bYd$
$Z\to bZc$
Now from start symbol we cou... |
Why is this language regular: $L=\{w~|~\#_a(w) \ge \#_b(w)\}○\{w~|~\#_a(w) \le \#_b(w)\}$?
Where $\#_a(w)$ is defined as the number of $a$ in $w$.
Isn't that a concatenation between 2 CFL?
Thanks! |
Why is $L=\{w~|~\#_a(w) \ge \#_b(w)\}○\{w~|~\#_a(w) \le \#_b(w)\}$ regular? |
|formal-languages|regular-languages|automata|context-free| |
The result of this concatenation is $\Sigma^*$, which is regular.
I will leave it to you to verify this is the case. |
Boolean Satisfiability (CNF-SAT) problem in $n$ variables may contain a CNF formula $O(2^n)$ clauses in the worst case.
My question is: Wouldn't a program reading a CNF formula have to asymptotically run $O(2^n)$ steps? Is the search for a sub-exponential CNF-SAT algorithm moot? |
CNF-SAT time complexity and input processing |
|time-complexity|np-complete|satisfiability| |
$w$ and $x$ are binary strings.
Clearly $|wx|=|xw|$ and $|wx|_0=|xw|_0$. Suppose $wx$ and $xw$ differ only at position $i$, so that $(wx)[i]\ne(xw)[i]$, $(wx)[1..i-1]=(xw)[1..i-1]$, and $(wx)[i+1..n+k]=(xw)[i+1..n+k]$.
Wolog, assume $(wx)[i]$ is $1$, and thus $(xw)[i]$ is $0$. Now,
$$\begin{align}|wx|_0 &= ... |
Let $F=\{x2y\in\{1,2\}^* : |x| = |y|, x\in 1^*, d(x,y) = 1\}$, the language of all strings $1^n2$y where $y$ has length $n$ and exactly one $2$.
Note that $F=\{1^p11^q21^q21^p: p\ge0\land q\ge0\}$. Here is a context-free grammar for it.
$S\to 1S1\mid 1T2$
$T\to 1T1\mid 2$
Since $F$ is context-free, ... |
Boolean Satisfiability (CNF-SAT) problem in $n$ variables may contain a CNF formula with $O(2^n)$ clauses in the worst case.
My question is: Wouldn't a program reading a CNF formula have to asymptotically run $O(2^n)$ steps? Is the search for a sub-exponential CNF-SAT algorithm moot? |
**Lemma:**
The parity of the Hamming distance between two strings is the parity of the total number of $1$s.
**Proof:**
If you toggle a bit in any of the strings, the parity of the distance changes. Start from two "all zeroes" string and toggle all it takes to get to the targeted strings.
----------
Th... |
I know that interface means a point where any two things meet and interact, but I can't seem to wrap my head around the term when they use it in computers.
A chipset performs interface and peripheral functions for the processor. What does it mean?
What do you mean when you say the chipsets are the circuitry that ... |
What does interface and peripheral functions mean? |
|computer-architecture| |
**Lemma:**
The parity of the Hamming distance between two strings is the parity of the total number of $1$s.
**Proof:**
If you toggle any bit in any of the strings, the parity of the distance changes. Start from two "all zeroes" strings and toggle all it takes to get to the targeted strings.
----------
... |
>For two equal-length binary strings $x$ and $y$, let $d(x,y)$ denote the Hamming distance. Prove or disprove: there exists a positive integer $k$ such that the language $\{x2y : |x| = |y|, x\in A, y\in\{0,1\}^*,d(x,y) = k\}$ is context-free for some infinite regular language $A$ over the alphabet $\{0,1\}$.
I t... |
Is $\{x2y : |x| = |y|, x\in A, y\in\{0,1\}^*, d(x,y) = k\}$ context-free for some infinite regular language $A$? |
Let $F=\{x2y : |x| = |y|, x\in \{0\}^*, y\in\{0,1\}^*, d(x,y) = 1\}$, the language of all strings $0^n2$y where $y$ consists of $n-1$ $0$s and one $1$.
Note that $F=\{0^p00^q20^q10^p: p\ge0, q\ge0\}$. Here is a context-free grammar for it.
$S\to 0S0\mid 0T1$
$T\to 0T0\mid 2$
Since $F$ is context-fre... |
I am implementing [A No-Reference Perceptual Blur Metric][1] paper.
Somewhere in the prep steps they mention the use of vertical Sobel filter for finding vertical edges.
> The algorithm is summarized in Fig. 1. First we apply an edge detector
> (e.g. vertical Sobel filter) in order to find vertical edges in the
... |
Interpreting results of Sobel Edge Detection |
|algorithms|computer-vision|image-processing| |
**Lemma:**
The parity of the Hamming distance between two strings is the parity of the total number of $1$s.
**Proof:**
If you toggle any bit in any of the strings, the parity of the distance changes. Start from two "all zeroes" strings and toggle all it takes to get to the targeted strings.
----------
... |
null |
Let $F=\{x2y : |x| = |y|,\ x\in \{0\}^*,\ y\in\{0,1\}^*,\ d(x,y) = 1\}$, the language of all strings $0^n2$y where $y$ consists of $n-1$ $0$s and one $1$.
Note that $F=\{0^p00^q20^q10^p: p\ge0, q\ge0\}$. Here is a context-free grammar for it.
$S\to 0S0\mid 0T1$
$T\to 0T0\mid 2$
Since $F$ is context-... |
No. Note that $A = A1 / \{1\}$, the right quotient of $A1$ over $\{1\}$. Since $\{1\}$ is a regular language, we know that $A$ is context-free when $A1$ is context-free, thanks to [this post](https://cs.stackexchange.com/q/1886/91753) that shows the right quotient of a context-free language over a regular language is ... |
No. The meaning of "polynomial-time" is "polynomial in the length of an input". We can still search for an algorithm that is efficient on short inputs.
For instance, suppose we have CNF formulas with $n$ variables and only $10n$ clauses. No one knows how to solve this in time polynomial in $n$. |
I came here to ask for help with a two-tape Turing machine for the following language.
$L = \{ a^{n^2} | n \ge 0 \}$
I tried following the advice on this site: [Turing machine that accepts L={an2|n≥1}
[duplicate]][1]
[1]: https://cs.stackexchange.com/questions/118739/turing-machine-that-accepts-l-an2-n-%... |
Let $F=\{x2y : |x| = |y|,\ x\in \{0\}^*,\ y\in\{0,1\}^*,\ d(x,y) = 1\}$, the language of all strings $0^n2y$ where $y$ consists of $n-1$ $0$s and one $1$.
Note that $F=\{0^p00^q20^q10^p: p\ge0, q\ge0\}$. Here is a context-free grammar for it.
$S\to 0S0\mid 0T1$
$T\to 0T0\mid 2$
Since $F$ is context-... |
I came here to ask for help with a two-tape Turing machine for the following language.
$L = \{ a^{n^2} | n \ge 0 \}$
I tried following the advice on this site: [Turing machine that accepts L={an2|n≥1}
[duplicate]][1]
[1]: https://cs.stackexchange.com/questions/118739/turing-machine-that-accepts-l-an2-n-%... |
I was studying Turing languages for an exam and I came up with this problem for wich I haven't found a solution online. This is my question:
> Let's say we have $L_1, L_2 \subseteq\{0,1\}^*$. $L_1$ is
> Turing-recognisable and $L_2$ is Turing-decidable.
>
> Is $L_u = L_1 \cup L_2$ decidable?
My guess is that ... |
Is this language Turing decidable? |
|formal-languages|turing-recognizable| |
If you can show an **algorithm** works on a Turing Machine to compute the $4x$, then you can show it is Turing computable. You can also use any TM that can be reduced to a TM as well *[Example: the double tapes, double heads and other variants]*
The really cheap way to do this is if you have a TM-complete programmin... |
null |
The language $\mathrm{half}(L)=\{x\mid xy\in L,|x|=|y|\}$ can be quite complicated, compared to the original language $L$. I am afraid that **there is no simple construction and we have to keep track of the behaviour of the automaton both forward and backward**, which is the product automaton you are referring to.
L... |
Your operation is very general, and in its generality your conjecture is not true.
For instance take for $o$ the identity, then we get the simple example $o(\{a,b\}^*) = \{wcw\mid w\in \{a,b\}^*\}$ which is not context-free.
Your examples show that a better conjecture would be that instead $\{ x c\, o(x^R)\mid x\... |
According to [wikipedia][1], the Frontier supercomputer is the largest supercomputer in the world, at 1 exaFLOPS, and cost 600 million USD.
I am quite surprised that the largest supercomputer only has 1 exaFLOPs, because of the following:
* The AMD Instinct MI250X has about 100 teraFLOPS, i.e. 0.1 petaFLOPS.
... |
Are GPU's only a fraction of the cost of supercomputers? |
|computer-architecture| |
The answer to the question "Is $L_u = L_1 \cup L_2$ decidable?" is "sometimes".
For a positive example, let both $L_1$ and $L_2$ be the empty language. <!-- or both are decidable. -->
For a negative example, let $L_1$ be Turing-recognisable but not Turing-co-recognisable such as the language of halting Turing ma... |
Is the union of a Turing-recognisable language and a Turing-decidable language Turing decidable? |
A few things,
- It's hard to find what your proof attempt is trying to do. I know you're stuck, but you should at least have a strategy of what you want to do. In your proof, a good idea is to use AFSOC and look for a contradiction.
- The online theorem you found makes no sense, if we have $L_x = S \cup L_1$ but we d... |
You have to remember that sticking a bunch of GPUs together does not linearly increase the performance. You can argue that yeah, if all the GPUs are running then instructions are being run, but to actually efficiently run useful operations on a bunch of GPUs is no easy task.
Some factors for scaling up GPUs:
- Com... |
Most CV algorithms deal with 2D images produced by cameras. However, sometimes we need to process 3D “images” (I don’t know how to call them). For example, CT and MRI produce 3D radiographs. Traditionally these radiographs are cut into many slices for doctors to read. Because human eyes can only see 2D images (and most... |
Can computer vision process 3D “images” directly? |
|computer-vision|pattern-recognition| |
I'll let the mods decide if it's a duplicate or not, but I do agree that the explanations could warrant a bit more explicit explaining.
1. You have two tapes, one of them is the one with the input, and the other one is to help us advance by $1, 3, 5, \cdots.$ since as they mentioned, $1 + 3 +5 + \cdots (2n+1) = (n+1... |
I was studying Turing languages for an exam and I came up with this problem for wich I haven't found a solution online. This is my question:
> Let's say we have $L_1, L_2 \subseteq\{0,1\}^*$. $L_1$ is
> Turing-recognisable and $L_2$ is Turing-decidable.
>
> Is $L_u = L_1 \cup L_2$ decidable? Is it recognisable?
... |
Is the union of a Turing-recognisable language and a Turing-decidable language Turing decidable? Is it recognisable? |
I was studying Turing languages for an exam and I came up with this problem for wich I haven't found a solution online. This is my question:
> Let's say we have $L_1, L_2 \subseteq\{0,1\}^*$. $L_1$ is
> Turing-recognisable and $L_2$ is Turing-decidable.
>
> Is $L_u = L_1 \cup L_2$ decidable? Is it recognisable?
... |
I was studying Turing languages for an exam and I came up with this problem for wich I haven't found a solution online. This is my question:
> Let's say we have $L_1, L_2 \subseteq\{0,1\}^*$. $L_1$ is
> Turing-recognisable and $L_2$ is Turing-decidable.
>
> Is $L_u = L_1 \cup L_2$ decidable? Is it recognisable?
... |
This is a _very_ general question, so I'll give some ideas.
The short answer is yes. If you're talking about the "processing" as some function, then yes, we can use some function $f_3: \mathbb{R}^3 \to A$ in our computer algorithm rather than a $f_2: \mathbb{R}^2 \to B$. In fact, there are many computer algorithms t... |
I came here to ask for help with a two-tape Turing machine for the following language.
$L = \{ a^{n^2} | n \ge 0 \}$
I tried following the advice on this site: [Turing machine that accepts L={an2|n≥1}
[duplicate]][1]
[1]: https://cs.stackexchange.com/questions/118739/turing-machine-that-accepts-l-an2-n-%... |
Integers between 0 and a square-free number $r$ minus one can be represented by their value modulo each of $r$'s prime factors, according the Chinese remainder theorem.
Given a number represented like that, is there an efficient way to calculate its representation for $r^2$, that is, its remainder modulo each of $r$... |
I think you have the general idea right. I would add that
- Interfaces are more like APIs and cross-boundary objects that help interactions between two different worlds. So you can imagine a bus is an interface between the CPU and its peripherals, such as hard drives, GPUs, memory, etc. A chipset provides an interf... |
I might be wrong, but I think the red line is actually discrete line segments, and it looks like the green dashed lines are placed two red segments away from a local max or local min. Otherwise, I think the idea is that you take two equidistant lines, some distance away from the local min or max. |
The answer to the question "Is $L_u = L_1 \cup L_2$ decidable?" is "sometimes".
For a positive example, let both $L_1$ and $L_2$ be the empty language. <!-- or both are decidable. -->
For a negative example, let $L_1$ be Turing-recognisable but not Turing-co-recognisable such as the language of halting Turing m... |
The language $\mathrm{half}(L)=\{x\mid xy\in L,|x|=|y|\}$ can be quite complicated, compared to the original language $L$. I am afraid that **there is no simple construction and we have to keep track of the behaviour of the automaton both forward and backward**, which is the product automaton you are referring to.
L... |
I have an array $a$ with $n$ elements, all of which have an associated weight. For example:
$a = \{ (A,2), (B,5), (C,9), ..., (Z,1) \}$, such that element $A$ has weight $w_A=2$, element $B$ has weight $w_B=5$ and so on. The array is not necessarily sorted.
Now, I would like to obtain a sample from this array whe... |
Weighted sample of ~k elements from array in O(n) time? |
|probabilistic-algorithms|sampling| |
Assume I have a euclidean TSP solver that is **optimal**, but it can only solve inputs with exactly $N$ vertices. Let's call it the **N-solver**.
Now, I have an input with $K$ vertices in the 2D plane, where $K < N$. Can I convert this $K$ sized input to an $N$ sized input where I can feed it into my N-solver and ob... |
Reducing euclidean TSP of smaller size to euclidean TSP of bigger size |
|algorithms|complexity-theory|reductions|approximation|traveling-salesman| |
### Definitions
Define the *density* $\rho_L$ of a language $L$ to be a function $\rho_L : \mathbb{N} \rightarrow \mathbb{N}$ where $\rho_L(n)$ is the number of words in $L$ of length $n$.
### Question
Let $L \subseteq \Sigma^*$ be a regular language with density $\rho_L(n) \leq b^n$ for some constant $b \in \... |
Regular language superset with exactly exponential size |
|regular-languages| |
The language $\mathrm{half}(L)=\{x\mid xy\in L,|x|=|y|\}$ can be quite complicated, compared to the original language $L$. I am afraid that **there is no simple construction and we have to keep track of the behaviour of the automaton both forward and backward**, which is the product automaton you are referring to.
L... |
The language $\mathrm{half}(L)=\{x\mid xy\in L,|x|=|y|\}$ can be quite complicated, compared to the original language $L$. I am afraid that **there is no simple construction and we have to keep track of the behaviour of the automaton both forward and backward**, which is the product automaton you are referring to.
L... |
Yes, assuming we can assume that all elements are distinct. Here is one approach. Let $x_1,\dots,x_n$ denote the elements and $w_i$ the weight associated to $x_i$. Consider the following algorithm:
- For $i:=1,2,\dots,n$:
- Let $p_i=w_i/(w_i+w_{i+1}+\dots+w_n)$.
- Draw $m_i$ from a Binomial($k$, $p_i$) di... |
I am tasked to design a turing machine which calculates the function:
$f(n) = 2n \iff 0 \le n \le 2$, or $4n+2 \iff n>2$
Where "n" is given in **binary**.
Now, I'm not in the slightest way sure how to do this. This is what I came up with so far:
I tried checking if a binary number is bigger than two. First,... |
What would be an easy approach for this Turing machine description? |
|formal-languages|turing-machines| |
null |
Let $[x_1,...,x_n]$ be an array of numbers. Let $y > 1$ be fixed.
We want to find two numbers $x_i$ and $x_j$ such that $|x_i - x_j| \leq y$.
I am trying to solve this using hashing similar to the following interview-style problem which also has a hashing solution https://afteracademy.com/blog/check-for-pair-in... |
|algorithms|data-structures| |
null |
Let $[x_1,...,x_n]$ be an array of numbers. Let $y > 1$ be fixed.
We want to find two numbers $x_i$ and $x_j$ such that their absolute difference it at most $y$.
I am trying to solve this using hashing similar to the following interview-style problem which also has a hashing solution https://afteracademy.com/bl... |
|algorithms| |
Let $A$ be an array of numbers. Let $y$ be positive.
We want to find two numbers $A[i]$ and $A[j]$ such that their absolute difference is at most $y$. |
Algorithm for searching two numbers whose absolute difference is small |
I think it's a template match, meaning if you have some list $L = [x_1, x_2, \dots, x_n]$, then $L = x:L'$ where $L' = [x_2, x_3, \dots, x_n]$.
So you can imagine what that definition is saying is that $f(x:L)$ is equivalent to operating on the rest of the list, i.e. $L$ in this case, hence $f(L)$.
Induction foll... |
Instead of using a hash *set*, use a hash *map*. Store each $x_i$ under its hash $h_i = \lfloor \frac{x_i}{y} \rfloor$. But before you store it, check it against the hash entries $h_i-1$, $h_i$ and $h_i+1$ and report a pair if it's close enough.
Python implementation:
```
def pair(xs, y):
seen = {}
for x... |
Instead of using a hash *set* (← that refers to the question text before they vandalized it, just like the names $x_i$ instead of $A[i]$), use a hash *map*. Store each $x_i$ under its hash $h_i = \lfloor \frac{x_i}{y} \rfloor$. But before you store it, check it against the hash entries $h_i-1$, $h_i$ and $h_i... |
I'm just starting to learn about representing numbers in sign-and-magnitude and two's complement, and both as signed binary integers two's complement if representing a negative number I should invert all bits and add one, while sign-and-magnitude represents negative numbers with the first bit as a sign bit, but is it p... |
Difference between two's complement and sign-and-magnitude |
|binary| |
In actual industry use, does bottom-up provide a significant speed-up compared to an equivalent top-down approach to a dynamic programming algorithm?
Assume that the top-down and bottom-up implementations both have the same asymptotic runtime.
Do the constants really make a difference? Or does this all depend on ... |
How much of a difference does bottom-up vs top-down make in actual practice when implementing dynamic programming? |
|algorithms| |
Whether you care about such a thing depends on:
1. The specifics of the code at hand.
2. Whether the application is time-critical.
In other words, there is no general conclusion here.
Luckily, the vast majority of applications are not time-critical so we don't care.
|
As far as I see, the solutions have all used integration. We can easily do without.
Of course $\log n! = \sum_{k=1}^n \log k$.
For the upper bound use $\log k \le \log n$ for $1\le k \le n$, so $\sum_{k=1}^n \log k \le \sum_{k=1}^n \log n =n \log n$.
For the lower bound, observe that $\log \frac n2 \ge \frac 12{... |
Let $A$ be an $n \times k$ matrix of real numbers.
I'm looking for an exact algorithm to find a permutation of the rows of $A$, in such a way that the total number of inversions found in the resulting $k$ row vectors is minimal. That is, if $B$ is a row-wise permutation of $A$, I want to minimize:
$$ L(B) = \sum... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.