instruction
stringlengths
0
29.8k
⌀
|time-complexity|matching|
null
This problem is indeed undecidable, assuming that $n$ is not a constant but refers to the length of the machine's input. Consider the problem $P$ of, given a Turing machine $\mathcal{M}$, to decide if it runs in at most $|x|$ steps on every input $x$. Problem $P$ is undecidable. For any constants $c,c' > 0$, let...
null
ERROR: type should be string, got "https://superuser.com/questions/1735122/why-are-most-of-the-common-processors-bit-counts-powers-of-2/1735399#1735399 and other answers discuss some of the engineering problems you'd have with e.g. 24-bit words on a byte-addressable machine. (24-bit DSPs use word-addressable memory) - some 3-byte words will span wider boundaries, differing in higher bits of the address. But CPU caches and memory systems really want to group binary addresses by ignoring some low bits, not by doing a full division.\r\n\r\nIn algorithm terms, this is optimization of `i / sizeof(int)` into a right shift for unsigned `i`, and `i * sizeof(int)` into a left shift.\r\n\r\nAnother algorithm where this is relevant is a bit-array: given an integer bit-index, you need to break that up into a byte index or word index, and a bit number within the byte (to use as a shift count).\r\n\r\n```\r\n#include <limits>\r\nint get_bit(unsigned int *bit_array, size_t n)\r\n{\r\n size_t element_idx = n / std::numeric_limits<unsigned int>::digits;\r\n int bit_idx = n % std::numeric_limits<unsigned int>::digits;\r\n unsigned chunk = bit_array[element_idx];\r\n return (chunk >> bit_idx) & 1;\r\n}\r\n```\r\n\r\nWhen [`numeric_limits<unsigned int>::digits`][1] is a power of 2, like 32 on typical C++ implementations, this unsigned division and remainder become simple right-shift and bitwise AND, like `n >> 5` and `n & 31`.\r\n\r\nThis wouldn't be the case for 24-bit `unsigned int`, for example, unless you choose to only use 16 of the 24 bits per `unsigned int`. Division by a constant `24` or `3` is not *very* expensive if you have a fast multiplier, but it's non-trivial.\r\n\r\nIn hardware it's even more significant: splitting a value into multiple fields is literally just wiring. But for `n%24`, the remainder depends on all 24 bits, not just the low 5 bits, as well as requiring some significant computation.\r\n\r\n----\r\n\r\n### `std::vector`'s `.size()` member function, and indexing\r\n\r\nAnother more widely used data structure that benefits from it being very cheap to convert between element index and addresses is **[C++'s `std::vector<T>`, a dynamic array][2] that knows its size and can reallocate when push_back exceeds the current capacity.** Typical implementations have 3 pointer members, perhaps named `T *m_begin`, `m_end`, and `m_capacity`.\r\n\r\nThe API includes `.begin()` and `.data()` which are trivial, just return the the start pointer. Similarly `.end()` can just return the end pointer. (C++ library functions that loop over a range take a start and end pointer, rather than a pointer + length). `.push_back` can increment `m_end += sizeof(T)` and check `m_end < m_capacity` is still true. (The size in bytes to pass to allocator functions can be obtained by casting to `char*` before subtracting.) None of that benefits from `sizeof(T)` being a power of 2, which is good for use-cases with T = an odd sized struct.\r\n\r\nBut `std::vector` also has a `.size()` API, typically implemented as `return end - begin;`. In C++, subtracting pointers returns the distance in elements, not bytes, so in asm it typically looks like `sub r0, r1` / `sra r0, 2` or something to arithmetic right shift the subtraction result to scale by `sizeof(T)`. If `sizeof(T)` isn't a power of 2, a right shift won't work for this division. (It is at least a compile-time constant [so a multiply and shift can do the trick][3].)\r\n\r\nIt's not rare for code to do `for (size_t i = 0 ; i < vec.size() ; i++) do stuff with vec[i]`, or to use `.size()` for other things. Compilers might transform this loop into a pointer increment, avoiding the division by `sizeof(vec[0])`, but some uses of `.size()` won't optimize away.\r\n\r\nA non-power-of-2 `sizeof(T)` for common primitive types like `int` and `int *` would make some uses of vectors of those types less efficient. (But implementations would probably keep the 3-pointer design, rather than needing to multiply by `sizeof(T)` more often with one pointer and size_t length, capacity.\r\n\r\nIt would also mean `alignof(int)` had to be `1`, unless an implementation padded 3-byte `int` to a larger size. Unless you redefine alignment to mean multiple-of-3 instead of multiple-of-2.\r\n\r\n\r\nAlso, **array indexing** by an integer is normally just a left-shift to multiply by `sizeof(T)` to get a byte offset.\r\n\r\nPerhaps such a machine would include scaled-index addressing modes so asm that could scale by 3 and 6, with a shift+add like `i + (i<<1)` instead of just a shift. For example current x86-64 can do `mov eax, [rdi + rcx*4]`. (The asm syntax is a multiply, but the only valid multipliers are 1, 2, 4, and 8; the machine code uses a 2-bit shift count.) So a 24-bit machine might allow `[rx + ry * 3]` or `*6` or `*12`. Otherwise software would need to do more operations to generate addresses.\r\n\r\nMany RISCs like MIPS and RISC-V only have 1-register addressing modes so scaling needs software, but maybe they'd provide a single instruction scale-by-3 for address-generation. (Maybe also including a shift count to scale by 6 or 12 or whatever.) `3` only has two set bits, so a fixed shift (trivial in hardware) and an adder will do the trick.\r\n\r\nDividing by 3 is expensive, though.\r\n\r\nIf the caches on a byte-addressable machine with odd-sized words was still sized to a power-of-2 number of bytes, it could work a lot like a modern x86 which allows efficient unaligned loads/stores, with fairly efficient handling of cases where a load spans the boundary between two cache lines or even pages. Addresses break into offset-within-cache-line vs. index vs. tag by treating the binary address as separate fields.\r\n\r\nIf cache line sizes were a multiple of 3, like 48 bytes, none of the `int` in an array will span a cache-line boundary. (As long as the start of the array is \"aligned\" to a multiple-of-3 address!) But if addresses are still binary numbers, cache indexing is no longer simple. `index = (address / 48) % num_sets`, and `tag = (address / 48) / num_sets`. (Assuming for simplicity physical index and tagging.) Paging has a similar problem, power of 2 page size vs. multiple of 3.\r\n\r\n(This is the same problem as for a bit-array where the `unsigned int` chunks aren't a power-of-2 size.)\r\n\r\n [1]: https://en.cppreference.com/w/cpp/types/numeric_limits/digits\r\n [2]: https://en.cppreference.com/w/cpp/container/vector\r\n [3]: https://stackoverflow.com/questions/41183935/why-does-gcc-use-multiplication-by-a-strange-number-in-implementing-integer-divi"
Multiplying and dividing binary integers by powers of 2 is *very* cheap, like multiplying and dividing by 10 for decimal numbers. It's qualitatively different from other factors because the other bits don't change, you just move digits left or right (shifting). In hardware for fixed shift counts, it's literally jus...
null
null
I think the original question to be valid and Ciarán Taaffe's answer is useful: Consider a diagonalisation on Turing machines, computing total computable functions from N to N. Then, G would be given a number, select the corresponding TM from the assumed enumeration, calculate the value and so on. But by assuming G ...
I think the original question to be valid and Ciarán Taaffe's answer is useful: Consider a diagonalisation on Turing machines, computing total computable functions from N to N. Then, G would be given a number, select the corresponding TM from the assumed enumeration, calculate the value and so on. But by assuming G ...
I think the original question to be valid and Ciarán Taaffe's answer to be useful: Consider a diagonalisation on Turing machines, computing total computable functions from N to N. Then, G would be given a number, select the corresponding TM from the assumed enumeration, calculate the value and so on. But by assuming...
I think the original question to be valid and Ciarán Taaffe's answer to be useful: Consider a diagonalisation on Turing machines, computing total computable functions from N to N. Then, G would be given a number, select the corresponding TM from the assumed enumeration, calculate the value and so on. But by assuming...
I am currently trying map a grammar to a graph in the context of syntax- and graph-based testing. However, until now I haven't had an enlightenment how **would I map non-terminals and terminals to nodes and edges in relation to the following quote**? > ... [Terminal Symbol Coverage] and [Production Derivation Cover...
Every optimization problem is asking about what's the value of a certain parameter closest to some target that's achievable under certain conditions. For example: > What's the largest clique in the given graph? Here the clique size is the parameter, the target is $\infty$ and the description of the graph is the s...
I am writing a program where I need to have a circle animation that grows from a start value to a end value and back to the starting value. I was able to come up with a semi-solution. double radiusFromProgress(double progress, double maxValue) { // Ensure progress is in the range [0, 1] progres...
Looking for an algorithm f(min, max, progress[from 0.0 to 1.0]) = value between min and max
|algorithms|
Forrest-Tomlin is designed to take advantage of the sparse nature of your problem. Since the extra cost does not scale with the number of variables, but the number of constraints, it is not the cause of the issue. The problem could lie in the design of the implementation.
In a usual priority queue, you insert items, and you delete the top item. To change a key, the obvious way would be to remove the item, change the key, and insert the item back. The problem is: You don’t know where the item is in your heap. And searching would be O(n) for n items in the priority queue. Since you kn...
I am writing a program where I need to have a circle animation that grows from a start value to a end value and back to the starting value. I was able to come up with a semi-solution. double radiusFromProgress(double progress, double maxValue) { // Ensure progress is in the range [0, 1] progres...
In the classical set cover problem, we are given the set $U$ of elements $\{1, \dots, n\}$ and a collection $C$ of some subsets such that their union is the whole set. Now, I will introduce the first small twist: instead of searching for one cover, we have a target number $t$ and we need to find $t$ disjoint covers. F...
Set cover variation: disjoint covers for all but one element
|combinatorics|discrete-mathematics|set-cover|disjoint-sets|
How to create a structure which acts as union of ranges. In that structure new ranges can be inserted beforehand and then some queries are asked to find out if the given point is covered by any of the ranges. What are different approaches and space/time complexity tradeoff?
Create a class or structure like union of ranges
|binary-trees|hash-tables|binary-search-trees|union-find|
null
My wife has a small workshop where she fixes dolls. <br> She works alone without any external help.<br> She has N orders from her clients, she estimates each order and she has deadline for each order.<br> She asks me to make a program which will create a schedule for her.<br> She wants to minimize a number of overd...
Schduling theory with weekends and holidays
|scheduling|
null
null
I agree, this is not how C++ handles thread abortion. I don't think such correctness guarantees can be achieved in C++ without turning to garbage collection (GC) techniques or binary instrumentation (BI) and changing the current semantics. C++ takes advantage of RAII, hence, it is the responsibility of the constructor...
Dan Doel's answer is helpful, but I want to include some more introductory info I've uncovered, about what "classical control operators" refers to. First of all, "classical" doesn't refer here to classical logic. It refers to a range of control operators derived in the 80s and 90s, all of which provide the facility ...
null
I think the story may be more complicated than some other answers suggest, even if they contain a lot of good arguments. I add some observations: * systems with 12,18,24,36 and other bit sizes exist * Nibbles are the minimum needed for BCD arithmetic. it may sound like a distant memory from the past, but doing...
I am looking for some greatest references that could help me understand the theorem $MIP^* = RE$ ([$MIP*=RE$](https://arxiv.org/abs/2001.04383)) step by step. The paper ([The Connes Embedding Problem: A guided tour](https://arxiv.org/abs/2109.12682v1)) covers various topics related to this problem, but it is very brie...
Good book on (Quantum) Complexity and Computability Theories to start learning the theorem $MIP^* = RE$ as an operator algebraist
|complexity-theory|quantum-computing|interactive-proof-systems|recursively-enumerable|
null
null
Try to visualize the solution mentioned in Navjot Singh's Answer. [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/sjM83.jpg
Try to visualize the solution mentioned in Navjot Singh's Answer. [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/BL7uR.jpg
You need a large enough alphabet to have enough degrees of freedom yielding codes with optimum minimum distance. The idea of the RS codes comes from choosing generator polynomials with no conjugacy constraints (unlike the binary cyclic code case where the conjugacy constraints restrict the factorization of $x^n-1$ ...
One answer to your question can be that if all recursively enumerable languages could be recognised by an LBA, Then LBA would be as powerful as Turing machine. Also we know that the set of languages recognisable by a LBA is equal to set of languages produced by context sensitive grammers. Also we know that restricted g...
You can abort a C++ thread in such a way that destructors of automatic ("stack") variables are called: just throw an exception that you don't catch (or that you catch only in a `try` block that wraps the thread's main function). In a comment you said the question is about using [`TerminateThread`](https://learn.micr...
Any $\mathsf{NC}$ circuit could be presented in SAT form via Tseytin transform. This applies in the reverse too: an arbitrary SAT instance could encode any $\mathsf{NC}$ circuit. Now, Frege proof system is said to be limited with $\mathsf{NC_1}$ circuits. In that case, does it mean that $\mathsf{NP=coNP}$ iff there ...
Does $\mathsf{NC_1\subsetneq NC}$ imply $\mathsf{NP\neq coNP}$?
|complexity-theory|time-complexity|satisfiability|circuits|
null
Of course, it isn't possible to construct them directly since we hasn't these type constructors, but only function constructor (arrow). But suppose there are 2 types $A$ and $B$, from which we need to create a product (or tuple) type $A*B$ and also sum type $A+B$. Let's remember the algebra of types: functional type...
I've heard that it isn't possible to encode product types and sum types in a simply typed lambda calculus, but it seems for me that it's false
|lambda-calculus|type-theory|propositional-logic|
As @jschnei has mentioned in the comment, the answer is: The communication matrix has rows indexed by Alice's inputs, columns indexed by Bob's input, and value f(x, y) at the cell in the row corresponding to Alice's input x and Bob's input y. In this case, when x and y are any vertices of a graph G, this should give...
Consider the language $L = \{\langle M_1,\ M_2 \rangle \mid \exists x : x \in L(M_1) \cap L(M_2)\}$. Show that $L$ is not decidable. I'm attempting a proof by contradiction but I'm having trouble with the Turing machine part.
Turing Machine Decidability
null
null
I am trying to understand why the above is not the case. In my understanding, if $P = NP$ I can replace a deterministic machine with a non-deterministic and vice-versa. Hence, I will always have the exact same computational tool ...
If $P = NP$ why is it not the case that for every oracle $A$ $P^{A} = NP^{A})$?
|complexity-theory|
If $P = NP$ why is it not the case that for every oracle $A$, $P^{A} = NP^{A}$?
A phrase like "it is not possible to encode product types in the simply-typed $\lambda$-calculus (without product types)" means: it is not true that for every type $A$ and type $B$, there exists some type $X$ such that $X$ is (isomorphic to) the product of $A$ and $B$. It does *not* mean that there exist no types that ...
The algorithm mentioned in the question has a storage problem (the required storage is not available as of now and I don't think it will be available in future also), otherwise, this algorithm is the fastest - because only a lookup in the prime number file(s) is required to find whether a number (N) is prime or not (...
null
null
For simplicity, let's assume all Turing machines print 0 or 1 on the tape. Consider an algorithm $A$, which, given any Turing machine $T$ as the input, outputs $x\in \{0,1\}$, satisfying the condition that if $T$ halts, then the last symbol printed by $T$ is $x.$ When $T$ does not halt, it does not matter what the ou...
Is the problem of "finding the output given the algorithm halts" not computable?
|turing-machines|computability|
Try to visualize the solution mentioned in Navjot Singh's Answer. [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/2htaw.jpg
Consider an $n \times n$ matrix of integers. Define a boundary in the matrix to be a sequence of cells, one per x-coordinate, where the y-coordinates of the boundary either stay the same or go up/down by one for successive values on the x-axis. I would like to find a boundary that maximizes the sum of the cell values o...
is there an efficient algorithm to find the optimal partition of a matrix?
|algorithms|optimization|
I was taught in my Computer Science Algorithms class at IIT back in 1992 that "easy" problems are solved with a time/resource complexity of at worst X^3. This makes problems with solutions of x^4 or worse "hard" problems, as well as problems that have an exponential resource characteristic. But a "Google" search toda...
Consider an $n \times n$ matrix of integers. Define a boundary in the matrix to be a sequence of cells, one per x-coordinate, where the y-coordinates of the boundary either stay the same or go up/down by one for successive values on the x-axis. I would like to find a boundary that maximizes the sum of the cell values o...
My definition: Its easy if my computer can find a solution within a few days. And it’s hard if my computer cannot solve it within six months. That’s instances, not problems. The travelling salesman problem is easy for 20 nodes. Problems are easy / hard if interesting instances are easy / hard. Matrix multiplication...
Call your matrix $A$ and define $S(r,c) := \sum_{1\leq i\leq c}A_{i,c}$. Now call $D(r,c)$ the optimal value for the submatrix consisting of the first $c$ columns of $A$, for a path which ends at row $r$. For convenience, define $D(r,0):=0$ for all $1\leq r \leq n$ and $D(0,c):=DC(n+1,c)=\infty$ for all $1\leq c \l...
|algorithms|optimization|dynamic-programming|
null
The assumption that the output is one bit does not actually simplify matters - the proof is easier for machines that can output strings. Let $U_M$ be the machine which simulates the machine $M$ and outputs the protocol of computation of $M$ (the sequence of successive configurations of $M$ until it halts). If $M$ do...
null
The fast Fourier transform and its relatives, such as the discrete Fourier transform used in JPEG compression, work best with data sizes that are powers of two. So, if you were to implement the FFT on, say, a DEC PDP-10, with its 9-bit bytes and 36-bit words, you'd have to "waste" 11% of the bits available (and you mig...
null
I think I can clear this up: Because you now have the predecessor prev, removal at the tail becomes faster because the time complexity is now 0(1). The logic behind it? The predecessor can now be renamed as the tail, which only needs to be done once for an individual removal. However, that does not mean removal in b...
null
null
null
I have a set cover problem in the real world, it is an unicost set cover problem, with many subsets(around 10~30 million subsets, yes, no mistake here). Due to the nature of the problem in real world, it is kind of easy to find all the exact covers of the problem. I am trying hard to find a better solution in many ways...
will it help to find the optimal solution to set cover problem if all exact cover of the same problem was found
|set-cover|
null
I solved this problem by fixing units of measurement.<br> Estimates are counted in "work days", but deadlines are "calendar days"<br> So, if we take a count of calendar days before a deadline and subtract a count of holydays and other non working days then we will have a deadline in "working days" and Moore's algorit...
As D.W. says, it is NP-hard, so we don't expect the problem to have a polynomial time algorithm, but it is FPT: You can solve it in time $O(2^{|A|} n^5)$ which is polynomial if you consider $|A|$ _small_, e.g. $|A| = O(\log n)$. The factor $n^5$ can be improved. Check out the (very accessible) paper by [Shortest ...
You're looking for [Church encodings](https://en.wikipedia.org/wiki/Church_encoding), which are encodings of type constructions and datatypes in the [*polymorphic* $\lambda$-calculus](https://en.wikipedia.org/wiki/System_F). That is, apart from having function types $\to$ we also need $\forall$ to quantify over all typ...
Let B and C be two languages on A = {a,b}: **B = {w | w has the same number as a and b} C = {a^n b^m | n,m >= 0}** (i) abba ∈ B ? (ii) Describe B∩C and determine whether B is regular or not using ONLY the closure property of regular languages. **For (i) I answered like this: Yes, it belongs to B becau...
Proving that the intersection of two languages is regular or not?
|regular-languages|finite-automata|
null
I have a set cover problem in the real world, it is a unicost set cover problem, with many subsets(around 10~30 million subsets, yes, no mistake here). Due to the nature of the problem in real world, it is kind of easy to find all the exact covers of the problem. I am trying very hard to find a better set-cover solutio...
will it help to find the optimal solution to set cover problem if all exact-covers of the same problem were found