instruction stringlengths 0 29.8k ⌀ |
|---|
$x$ must obviously be a multiple of $10$, so let us focus on $y=2n+5m+10k$. According to the comments, it is enough to consider numbers in $[0,9]$, hence $\dfrac x{10}\bmod10=0,2,4,5,7,9$ are the solutions, and you are done.
|
$x$ must obviously be a multiple of $10$, so let us focus on $y=2n+5m+10k$. Taking the modulo $5$, the equation reduces to $y\bmod5=2n\bmod5$, which works for $0, 2,4$.
$$\begin{cases}x\bmod10\ne0\to\text{false}\\x\bmod10=0\land\dfrac x{10}\bmod5\in\{1,3\}\to\text{false}\\x\bmod10=0\land\dfrac x{10}\bmod5\in\{0,2,4\... |
$$x=20n+50m+100k\iff x\bmod20=10m$$ which is trivial to check. |
null |
The greatest common divisor of 20, 50 and 100 is gcd(20, 50, 100) = 10. All multiples of 10 can be found as the sum of (positive or negative) multiples of 20, 50, or 100, and no other integers can. However, some numbers might require negative multiples, for example 10 = 1 * 50 - 2 * 20.
If x and x+10 are a sum with... |
$$x=20n+50m+100k\implies x\bmod20=10m$$ which is trivial to check. Anyway, the reverse implication
$$ x\bmod20=10m\implies x=20n+50m+100k$$ is no true for $x=10$ and $x=30$ (and only these numbers), due to the positiveness constraint. |
The linear combinations of $2$ and $5$ with non-negative coefficients are
$$0,2,4,5,6,7,8,9,10,11,\cdots$$
Hence all $x$ multiples of $10$ will work, except $10$ and $30$. |
The linear combinations of $20$ and $50$ with non-negative coefficients are
$$0,20,40,50,60,70,80,90,100,110,\cdots$$
Hence all $x$ multiples of $10$ will work, except $10$ and $30$. |
null |
Given some ordered list of $n$ items, I obviously have $n!$ possible arrangements. However, as a heuristic in some larger algorithm that needs to find the optimal order, I want to do some quick local exploration. One option is to walk through all possible removal & insert operations at $O(n(n-1))$. A similar option is ... |
swapping numbers in a list is equivalent to remove & reinsert? |
|optimization|combinatorics|local-search| |
There is a derivation of the modularity difference in this book chapter:
[Multilevel Local Optimization of Modularity][1] by
Thomas Aynaud, Vincent D. Blondel, Jean-Loup Guillaume, and Renaud Lambiotte. It is also [available in French][2].
I provide my own version below, with the notations introduced in the questi... |
null |
You just need to add some additional data in each node, namely:
- the maximum sum of values of previous nodes **in the subtree**;
- the key **in the subtree** that reach this maximum sum.
It is clear that with this data, you can get `maxSumPrevious()` in $\mathcal{O}(1)$ time, but you would need to update the ... |
You just need to add some additional data in each node, namely:
- the maximum sum of values of previous nodes **in the subtree**;
- the key **in the subtree** that reach this maximum sum.
It is clear that with this data, you can get `maxSumPrevious()` in $\mathcal{O}(1)$ time, but you would need to update the ... |
This has been completely rewritten today 2022-09-16 to address all of the objections from thousands of reviews in the last 12 months.
**Are the halting problem proofs refuted by software engineering ?**
void Px(ptr x)
{
int Halt_Status = Hx(x, x);
if (Halt_Status)
HERE: goto HE... |
This [video][1] claims that the Mersenne-Twister is based on the Linear Congruential Generator. The math in the Mersenne-Twister original paper is a bit too much for me. I have not seen that claim explicitly made in the wikipedia article for Mersenne-Twister or in some of the other sources I consulted. Is the Mersenne-... |
What is the connection between the Mersenne-Twister and Linear Congruential Generator? |
|pseudo-random-generators| |
No it is not.
MT is based on a twisted generalized feedback shift register. It defined on vector spaces over finite fields, specifically $GF(2)$.
The LCG is based on integer arithmetic over the integers modulo $n,$ say $\mathbb{Z}_n.$
The two algebraic structures are quite different so this statement is fal... |
No, simply because $[1,2,3]$ can be transformed to $[3,1,2]$ using one insertion but not using one swap. Just check all possible swaps to prove this.
|
The property you speak of is indeed true.
Denote $E = \{e_1, e_2, …, e_{k-1}\}$ and $F = \{f_1, f_2, …, f_k\}$. Note $V'$ the vertices covered by $E_1$: $V' = \{v\in V\mid \exists e\in E\text{ such that } v\in e\}$.
I will prove that there exists $f\in F\setminus E$ such that $(V, E\cup\{f\})$ is acyclic. That w... |
We know that if $T_1 = \{e_1, \dots, e_n\}$ and $T_2=\{f_1, \dots, f_n\}$ are MST then if we order the edges such as
$$w(e_1) \le w(e_2) \le \dots \le w(e_n)$$
$$w(f_1) \le w(f_2) \le \dots \le w(f_n)$$
then $w(e_i)=w(f_i)$ for all $i\in [n]$
This also (trivially) implies that $w(e_1) \le w(f_i)$ for all $i\in ... |
The property you speak of is indeed true.
Denote $E = \{e_1, e_2, …, e_{k-1}\}$ and $F = \{f_1, f_2, …, f_k\}$. Note $V'$ the vertices covered by $E$: $V' = \{v\in V\mid \exists e\in E\text{ such that } v\in e\}$.
I will prove that there exists $f\in F\setminus E$ such that $(V, E\cup\{f\})$ is acyclic. That wou... |
Is this language context free?
$L = \{a^kb^lb^ka^l \ | \ k,l \in \mathbb{N}\}$
Using Pumping Lemma and $z = a^nb^nb^na^n$ I find it contradicting PL.
If $z = uvwxy$ and $|vwx| \leq n$, follows:
1. $vwx$ is in either $a^n$ or $b^n$, second $b^n$, or second $a^n$. After pumping form of the word changes and t... |
Context free language with valid Pumping Lemma use |
|context-free|pumping-lemma| |
The language is indeed context-free. Since it can be defined as $L = \{a^kb^kb^la^l\mid k,l\geqslant 0\}$, the following grammar can generate it:
> $S \rightarrow XY$
>
> $X\rightarrow AXB\mid \varepsilon$
>
> $Y\rightarrow BYA\mid \varepsilon$
In your tentative of proof, the second case is wrongly considered. ... |
The property you speak of is indeed true.
Denote $E = \{e_1, e_2, …, e_{k-1}\}$ and $F = \{f_1, f_2, …, f_k\}$. Note $V'$ the vertices covered by $E$: $V' = \{v\in V\mid \exists e\in E\text{ such that } v\in e\}$.
I will prove that there exists $f\in F\setminus E$ such that $(V, E\cup\{f\})$ is acyclic. That wou... |
I'm trying to optimise (to a certain precision) a monotonic function for many points (100+). I know a-priori that the function is continuous, with some parts zero derivative. I know that all points lie within a range [a, b].
My current approach is to sample the range [a, b] with N points, and then find the closest ... |
Optimising for many points in a monotone function |
|algorithms|optimization|search-algorithms| |
In comparison sort, the fastest possible algorithm is order $n \log(n)$. Also this bound can be achieved by various algorithms such as merge sort. What is the time complexity of sorting a list of natural numbers, each represented as a binary string in base 2, and separated by commas. For example, the list $3,1,2$ would... |
null |
We know that computer programs are either AOT compiled, JIT compiled or interpreted
And we also know that AOT compiled programs usually get compiled from its high level source code into machine code
Now the question is, if machine code is so hard to understand and write, why the idea of compilers wasn't to transl... |
Why executables aren't written in a way that the OS understand instead of machine code? |
|compilers| |
null |
null |
null |
Assuming there are $n$ numbers, and each number can be represented in $O(\log n)$ bits, you can read in the file and each number in $O(n \log n)$ time, then sort with any standard comparison-based sort algorithm, for a total running time of $O(n \log n)$.
If each number is $m$ bits long, and there are $n$ numbers, t... |
The OS doesn't execute programs. The CPU does. The OS helps manage access to resources. Since the CPU executes programs, programs need to be translated (compiled) into a form that the CPU can execute.
I see no obvious benefit or advantage to the scheme you describe (compile the program to an intermediate language... |
null |
null |
I understand that if `f(n) ∈ O(g(n))` and `f(n) ∈ Ω(g(n))`, we can conclude that `f(n) ∈ Θ(g(n))`.
But what if we have an algorithm where the Big-O and Big-Ω are different? For example `f(n) ∈ O(n^2)` and `f(n) ∈ Ω(n)`. Then what would be its Big-Theta notation?
To me, it seems that both `f(n) ∈ Θ(n^2)` and `f(n... |
How do you specify Big-Theta of an algorithm when the Big-O and Big-Omega are different? |
|algorithms|complexity-theory| |
null |
There are two possibilities:
- either the Big-$\Theta$ lies somewhere between the Big-$O$ and Big-$\Omega$ but we can't tell from the given;
- or there is no Big-$\Theta$ expression at all (but we can't tell from the given).
E.g.
$n^2=O(n^2), n^2=\Omega(n)$ and $n^2=\Theta(n^2)$.
But
$n\cos(n)+\sqrt ... |
There are two possibilities:
- either the Big-$\Theta$ lies somewhere between the Big-$O$ and Big-$\Omega$ but we can't tell from the given;
- or there is no Big-$\Theta$ expression at all (but we can't tell from the given).
E.g.
$T_n=O(n^2), T_n=\Omega(n)$ and $T_n=\Theta(n^2)$ are all true,
where $T_n... |
OS-independent layers (more precisely CPU-independent) introduce some overhead to achieve the exact specifications, so in many contexts this is just unacceptable. And computer manufacturers have no interest in making their solution too standardized, as this impairs customer retention.
Anyway, you can consider that t... |
Potential Speed up is how much we could have make it faster.
with 10 processor and total task size 110t (10t sequential and 110t parallelizable)
By Ahmdal's law
$$ Speedup_{curr} = \frac{T_{old}}{T_{new}} $$
And when would be the speedup be maximum. When every part is parallelizable. Then,
$$ T_{new} = \... |
I'm sure you'll find some references by taking a look at how [Giac](http://xcas.sourceforge.net/en/) works. It is quite extensive so I couldn't do it myself now. [Here](http://www-fourier.ujf-grenoble.fr/~parisse/giac.html) you will many useful links. I think you might find something related to your question [in the 11... |
There are many posts here and elsewhere asking for algorithms to simplify simple arithmetic expressions. For example, [this question](https://cs.stackexchange.com/q/133534/125765) asks how to simplify the expression $axc + byc + ayc + bxc$. [Symbolics](https://symbolics.juliasymbolics.org/dev/) and [xcas](http://xcas.s... |
Simplify equations with available knowledge |
|reference-request|computer-algebra| |
Can equations be simplified with available knowledge? |
I am no specialist, but IMO this problem is even harder than symbolic integration, and I have not heard of a general theorem that would parallel that of Liouville. (https://en.wikipedia.org/wiki/Liouville%27s_theorem_(differential_algebra))
Of course, the case of univariate polynomials was settled by Galois, but onl... |
Let's assume I have the following regular language:
L = {1,0}\*{010}{1,0}\*
I would like to convert this to regex for a program. Would the equivalent regular expression for this be:
((0+1)\*(010)(0+1)\*)
or
((0+1)\*(010)(0+1)\*)\*
Or is it something else completely? |
Regular Language to Regular Expression |
|regular-languages|regular-expressions| |
With $p$ processors, you expect the solution to be obtained $p$ times faster, and this is of course the best you could hope.
This is indeed the *potential* speedup, and in practice it is never reached, due to overhead of parallelism and unavoidable parts of the algorithm that cannot be parallelized at all.
Things... |
If your knowledge is in the form of linear equations, as in your example, then you can make a simple substitution. In your example, set $b=2-a$ and $y=-1-x$, as [Yves Daoust suggests](https://cs.stackexchange.com/questions/154304/can-equations-be-simplified-with-available-knowledge#comment324392_154304). This will wo... |
I'm just a beginner, I've started learning programming, CS, math, and Unix. I know how to code in Pascal and also study C.
In the university a professional programmer, who teaches coding, said that literally everything in C is a side effect.
>Accessing a volatile object, modifying an object, modifying a file, or ca... |
null |
> How the $M_t ← \max\{0, M_{t-1} + A[t]\}$ part works at all? Is it creating a lot of $M_t$ variables, one for every t value?
Yes, it is creating variable $M_t$ for every $t$. Together with $M_0$, there are $n+1$ of them.
When $t=1$, the statement is $M_1 ← \max\{0, M_0 + A[1]\}$. Note that $M_0$ is used.
> ... |
I'm reading *Algorithm Design and Application*, by Michael T. Goodrich and Robert Tamassia, and sometimes the pseudo-code in this book doesn't make sense at all.
At chapter one they show us 3 solutions for the famous [maximum subarray problem][1]. I understood completely the first and second solutions, but the thir... |
How can I convert the pseudo-code that solves maximum subarray problem to Python code? |
null |
Consider the reduction $A_{TM} \le_m \overline{E}_{TM}$, where
$$A_{TM} = \{\langle M, w \rangle \mid \text{TM $M$ accepts $w$}\}\text{, and}$$
$$\overline{E}_{TM} = \{\langle M \rangle \mid \text{TM $M$ accepts some string}\}$$
Then define the mapping reduction, $f(\langle M, w \rangle)$ as follows:
Const... |
Infinite loops and the computability of mapping reductions |
|turing-machines|computability|undecidability| |
Consider the reduction $A_{TM} \le_m \overline{E}_{TM}$, where
$$A_{TM} = \{\langle M, w \rangle \mid \text{TM $M$ accepts $w$}\}\text{, and}$$
$$\overline{E}_{TM} = \{\langle M \rangle \mid \text{TM $M$ accepts some string}\}$$
Then define the mapping reduction, $f(\langle M, w \rangle)$ as follows:
Const... |
"fully determined by its inputs" does not imply "computable". The halting function is fully determined by its inputs, but not computable. |
null |
null |
if $p$ is a universal diophantine polynomial then we can represent a non-computable solution to the halting problem as follows
$$
h(m,n) = sgn(\lim_{w \to \infty}\sum_{x_1=1}^{w}...\sum_{x_u=1}^{w}\dfrac{1}{1 + wp^2(m,n,x_1,...,x_u)})
$$
if we define halting function as
$$
\begin{align*}
h(m,n) &=
\begi... |
Are these functions computable? |
|computability|halting-problem| |
null |
consider $g$ and $f$ and $h$ as
$
\begin{align*}
g(m) &=
\begin{cases}
1 & if\;program\;m\;halts\;on\;input\;m \\
0 & otherwise \\
\end{cases}
\end{align*}
$
$
\begin{align*}
f(m,n) &=
\begin{cases}
undefined & if\;m=n \\
1 & if\;program\;m\;halts\;on\;input\;n \\
... |
null |
null |
We want to show that the following function $F$ is primitive recursive (using the primitive recursion scheme) :
For all $x,p,a\in \mathbb N$,
$F(p,a,0)=g(\eta^{p}(a))$
\
$F(p,a,x+1)=h(\eta^{(p-(x+1))}(a),x,F(p,a,x))$
where $\eta, g : \mathbb{N}\to \mathbb{N}$ and $h: \mathbb{N}^3 \to \mathbb{N}$ are primiti... |
How to show that the following function $F$ is primitive recursive? |
|computability|primitive-recursion| |
null |
null |
null |
There are many posts here and elsewhere asking for algorithms to simplify simple arithmetic expressions. For example, [this question](https://cs.stackexchange.com/q/133534/125765) asks how to simplify the expression $axc + byc + ayc + bxc$. [Symbolics](https://symbolics.juliasymbolics.org/dev/) and [xcas](http://xcas.s... |
Can equations be simplified with the help of a given set of equations? |
I designed this FSM graph to demonstrate a DFA that would accept any string that
- is of length 5,
- must contain a *d*,
- can only have *a*s and/or *b*s before the *d*, and
- can only have *b*s and/or *c*s after the *d*.
Here is what I came up with:
[![enter image description here][1]][1]
I was wonder... |
Is my DFA optimal? |
|graphs|formal-languages|regular-languages|automata|finite-automata| |
It's easy to see that $f$ is **not** computable, using the padding lemma: there is a total computable function $t$ such that for all $x$, $t(x)>x$ but program number $x$ and program number $t(x)$ have the same behavior (= yield the same partial computable function).
This means that $f$ computes $g$, since we have $g... |
a formulation on an example:
let's have on a grid:
- a position of a bee queen **Q** (source node),
- a set of positions of free cells to lay an egg **E** (destination nodes),
- and a set of positions with worker bees **W** (moveable obstacles).
the queen and workers can move to 4 orthogonally neighboring ce... |
find shortest path on graph with obstacles which you can move |
|shortest-path|graph-traversal| |
An approach that is fast and seems to work well for me, and does not involve any fancy stuff, is to use the correlation of pixels over time as an indicator of motion:
0. Make your video greyscale (lets call it `video` $\in \mathbb R^{T\times H\times W}$)
1. Spatially Highpass filter video to make `video_shp`
2. ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.