instruction
stringlengths
0
29.8k
⌀
Assuming that the input $n$ is given as a decimal number. I was asked to **prove** whether the function $f: \mathbb{N} \rightarrow \mathbb{N}$ where $f(n) = 2^n$ is computable in polynomial time using TM or not. My guess is that the function cannot be computed in polynomial time but I can't figure out how I c...
Is the function $f: \mathbb{N} \rightarrow \mathbb{N}$ where $f(n) = 2^n$ computable in polynomial time using TM?
|turing-machines|computability|polynomial-time|
Look at the size of the required output. How much time would it take you just to _write_ the result? And this has nothing to do whatsoever with P vs NP, or computable or decidable languages.
The way your condition is written, it could be that almost all elements are considered equal. That will be hard to handle efficiently. By comparing $x_i$ and $x_{i+128}$ for example you can find all k that could be in the middle of a sequence with 129 or more elements. With your typical data that might very much re...
There are $n^3$ possible $(x, y, r)$ tuple, each describing a circle centered at $(x, y)$ with radius $r$. It would be nice if we can compute each tuple in $O(1)$, but can we? Notice each circle is its smaller version added with rectangles on four sides. It would be nice if we can compute each rectangle in $O(1)$, but ...
Merging $n$ sorted numbers and $\text{log}\ n$ unsorted numbers asks you to do two things: 1. Sort the $\text{log}\ n$ unsorted numbers in $O(\text{log}\ n\ \text{log}\ \text{log}\ n)$. 2. Merge $n$ sorted numbers and $\text{log}\ n$ sorted numbers in $O(n + \text{log}\ n)$. This yields the total time complexi...
I'm not sure if the algorithm qualifies as "efficient", but at least it works in polynomial time. The idea is that for a given pair pair $(x,y)$ of coordinates, there is at most $n^2$ many radiuses to consider (indeed, two discs that contain exactly the same points will have the same sum). To enumerate these discs, ...
There are $n^4$ possible $(x, y, r^2)$ tuple, each describing a circle centered at $(x, y)$ with radius $r$. It would be nice if we can compute each tuple in $O(1)$, but can we? Notice each circle is its smaller version added with rectangles on four sides. It would be nice if we can compute each rectangle in $O(1)$, bu...
There are $n^4$ possible $(x, y, r^2)$ tuple, each describing a circle centered at $(x, y)$ with radius $r$. Since each circle is its smaller version added with $O(1)$ additional points, this yields a time complexity of $O(n^4)$.
There are $n^4$ possible $(x, y, r^2)$ tuple, each describing a circle centered at $(x, y)$ with radius $r$. Since each circle is its smaller version added with $O(1)$ additional points, this yields a time complexity of $O(n^4)$. We may find the additional points by sorting every $r^2 = a^2 + b^2$ pair.
I'm just getting started with lambda calculus and I see that the fixed-point $Y$ combinator is defined as: $Y = \lambda f . (\lambda x . f(x x))(\lambda x . f(x x))$ (*) I read [here][1] that something like $t s$ (where $t, s$ are both terms) represents an application of a function $t$ to the input $s$, so in (*)...
$xx$ application in lambda calculus
|lambda-calculus|
The following picture is a block diagram of an arithmetic unit dedicated to IEEE 754 floating-point addition from [Computer Organization and Design RISC-V Edition: The Hardware Software Interface 2nd Edition][1] book. My questions are: 1) Why are in the sketch, the sign of the numbers ignored, while the final res...
How does signed floating point adder implement?
|computer-architecture|arithmetic|floating-point|
null
You're right: $xx$ is the application of $x$ to $x$. But this is not a problem as long as you remember that you're only dealing with *syntax* here: $x$ is a term, $x$ is another term, so $xx$ is a term. In particular, to form an application term $MN$, you do *not* suppose that $M$ is an abstraction. Another way to ...
Hidden leading bit: You add a 1 when you extract the mantissa except for renormalised numbers where you add zero. You use both sign bits to determine whether you add the mantissas (same sign) or subtract (different signs). And the result of the sign comes from the sign of the bigger number.
null
If you have these keys, they require `8x4=32` bits of storage 11110001 11110010 11010001 11010010 But you can separate them in buckets bucket: 1111 bucket: 1101 now you only need to store the numbers 0001 and 0010 in each bucket, and reduced your storage to half. You can do it...
Hidden leading bit: You add a 1 when you extract the mantissa except for denormalised numbers where you add zero. You use both sign bits to determine whether you add the mantissas (same sign) or subtract (different signs). And the result of the sign comes from the sign of the bigger number.
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+n*(n+1)/2$ different possible radius. You better work with the radius squared, since is integer arithmetic, which is faster than float. for $0$ to $9$, you get $55$ different radius to try. Addi...
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+(n+1)*(n+2)/2$ different possible radius. You better work with the radius squared, since is integer arithmetic, which is faster than float. for $0$ to $9$, you get $67$ different radius to try. Th...
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+(n+1)*(n+2)/2$ different possible radius. You better work with the radius squared, since is integer arithmetic, which is faster than float. for $0$ to $9$, you get $67$ different radius to try. Th...
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+(n+1)*(n+2)/2$ different possible radius. You better work with the radius squared, since is integer arithmetic, which is faster than float. for $0$ to $9$, you get $67$ different radius to t...
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+(n+1)*(n+2)/2$ different possible radius. You better work with the radius squared, since is integer arithmetic, which is faster than float. for $0$ to $9$, you get $67$ different radius to t...
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+(n+1)*(n+2)/2$ different possible radius. (but only $n=1+(n)*(n+1)/2$ are inside the rectangle). You better work with the radius squared, since is integer arithmetic, which is faster than float...
null
null
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+(n+1)*(n+2)/2$ different possible radius. (but only $n=1+(n)*(n+1)/2$ are inside the rectangle). You better work with the radius squared, since is integer arithmetic, which is faster than float...
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+(n+1)(n+2)/2$ different possible radius. (but only $n=1+n(n+1)/2$ are inside the rectangle). You better work with the radius squared, since is integer arithmetic, which is faster than float. ...
null
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+(n+1)(n+2)/2$ different possible radius. (but only $n=1+n(n+1)/2$ are inside the rectangle). You better work with the radius squared, since is integer arithmetic, which is faster than float. ...
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $n=1+(n+1)(n+2)/2$ different possible radius. (but only $n=1+n(n+1)/2$ are inside the rectangle). You better work with the radius squared, since is integer arithmetic, which is faster than float. ...
The possible radiuses squared are given by OEIS sequence [A001481][1]. For square with nodes $0,...,n$, there are $1+(n+1)(n+2)/2$ different possible radius. (but only $1+n(n+1)/2$ are inside the rectangle). You better work with the radius squared, since is integer arithmetic, which is faster than float. Thi...
null
This is my dynamic programming solution in Python to the problem of finding the cost of the optimal binary search tree: def optBST(freqs): """C(i,j) = min(C(i,k) + C(k+1, j)) + sum(freqs[i:j])""" # i references the rows in the 2D array, representing the starting element. # j references...
How to prove the time complexity of a function without calculating the precise number of steps taken? (Example: cost of optimal binary search tree)
|time-complexity|runtime-analysis|
This is my dynamic programming solution in Python to the problem of finding the cost of the optimal binary search tree: def optBST(freqs): """C(i,j) = min(C(i,k) + C(k+1, j)) + sum(freqs[i:j])""" # i references the rows in the 2D array, representing the starting element. # j references...
This is my dynamic programming solution in Python to the problem of finding the cost of the optimal binary search tree: def optBST(freqs): """C(i,j) = min(C(i,k) + C(k+1, j)) + sum(freqs[i:j])""" # i references the rows in the 2D array, representing the starting element. # j references...
null
A simple method is a resizable array with a bitmap of which entries are used, and an index where to look for the next unused entry. Resize the array when it’s 90% full. Since you can typically check 64 bits for the next unset bit, finding an empty entry is very fast.
The algorithm proposed by [Mirzaian and Arjomandi][1] (A. Mirzaian, E. Arjomandi, Selection in X + Y and matrices with sorted rows and columns, Information Processing Letters, Volume 20, Issue 1, 1985, Pages 13-17, ISSN 0020-0190, https://doi.org/10.1016/0020-0190(85)90123-1) can compute any order statistics, in...
The algorithm proposed by [Mirzaian and Arjomandi][1] (A. Mirzaian, E. Arjomandi, Selection in X + Y and matrices with sorted rows and columns, Information Processing Letters, Volume 20, Issue 1, 1985, Pages 13-17, ISSN 0020-0190, https://doi.org/10.1016/0020-0190(85)90123-1) can compute any order statistics, in...
I find the Russian Elbrus CPU fascinating. It seems that it is fairly decent at performing calculations, and security. This is likely as it is heavily specific for military and financial industries, within Russia. Less focus was put on end user desktop computers. However, I am confused about the decision to use t...
Why does Elbrus use VLIW architecture?
|computer-architecture|cpu|performance|
The algorithm proposed by [Mirzaian and Arjomandi][1] (A. Mirzaian, E. Arjomandi, Selection in X + Y and matrices with sorted rows and columns, Information Processing Letters, Volume 20, Issue 1, 1985, Pages 13-17, ISSN 0020-0190, https://doi.org/10.1016/0020-0190(85)90123-1) can compute any order statistics, in...
As you write, $L$ iterates over $O(n)$ many values, $i$ over $O(n)$ many values, and the minimum and sum in the inner loop also iterate over $O(n)$ many values. In total, we get $O(n) \cdot O(n) \cdot O(n) = O(n^3)$ many operations. This calculation doesn't show that $O(n^3)$ is tight. For this, we notice that if $L...
null
The proof in question is based on Wikipedia [page][1] at the time of posting. However, the reason that the cycle contains edges that does not belong to F is inaccurate, the reason is simply that F does not contain a cycle. It was written in 2009 and lacks a reference. Here is an improved version of the second part: ...
The proof in question is based on a Wikipedia [page][1] at the time of posting. However, the reason that the cycle contains edges that does not belong to F is inaccurate, the reason is simply that F does not contain a cycle. Also note that it lacks a reference. Here is an improved version of the second part, which is i...
The proof in question is based on a Wikipedia [page][1] at the time of posting. However, the reason that the cycle contains edges that does not belong to F is inaccurate, the reason is simply that F does not contain a cycle. Also note that it lacks a reference. Here is an improved version of the second part, which is i...
I work with big integers that I need to convert to and from strings, and to and from different bases. In JavaScript, BigInt allows to convert an integer to a string in a chosen base by doing: ```js 12345n.toString(9) ``` Unfortunately, when parsing a string to convert it to an integer, BigInt only accepts ba...
Fast string-to-integer algorithm
|integers|base-conversion|
null
At some point in time people thought that VLIW computers were a very reasonable approach. And as long as you cannot handle out-of-order execution it is quite useful. You may be able to execute say four instructions in some cycles without doing anything complicated. I’ve actually seen a 6MHz maths-coprocessor (a very lo...
At some point in time people thought that VLIW computers were a very reasonable approach. And as long as you cannot handle out-of-order execution it is quite useful. You may be able to execute say four instructions in some cycles without doing anything complicated. I’ve actually seen a 6MHz maths-coprocessor (a very lo...
The Ackermann function is the textbook example of a function which is total recursive but not primitive recursive. If we want to implement it in some programming language we will need to use a priori unbounded loops (generally using `while` or `goto`). I am looking for an algorithm used in real situations (e.g. ...
Useful algorithm not primitive recursive
|algorithms|computability|recursion|primitive-recursion|
No, in general not. For example the MIX language, consisting of equal numbers of $\{a,b,c\}$ in any order is not context-free but is the permutation of the regular language $(abc)^*$.
null
I was thinking about an efficient binary search for unsorted arrays with $n$ entirely unique elements, and came up with something that probably already exists. Here's how it works: At each level of recursion (starting with $k=1$), you have $2^{k-1}$ pairs of searchers, taking up some $O(1)$ memory each. In each pair...
What is the name of this search algorithm?
|algorithm-analysis|runtime-analysis|search-algorithms|
Section **1.9 Binary Strings** of the textbook *Introduction to Lattices and Order*, second edition, by Davey and Priestley, says the following: > Let $\Sigma^\ast$ be the set of all finite binary strings, that is, all finite sequences of zeros and ones; the empty string is included. Adding the infinite sequences, w...
Does adding all of these sequences actually get us the set of all infinite sequences?
|sets|
L1 and L2 are two languages that have a finite deterministic automat. Σ = {0,1} for the two languages. let L={x∈L1∣∃y∈L2,#0(x)=#0(y)}#0(x) means the number of times zero appears in x. which means every word in l1 if there is a word in l2 where the number of 0 in both words is equal. I need to prove that l has a det...
How to build a deterministic or non deterministic finite automat for a language
|finite-automata|
$L_1$ and $L_2$ are two languages that have a finite deterministic automaton. $Σ = \{0,1\}$ for the two languages. Let $L=\{x∈L_1\mid \text{there exists } y∈L_2,\text{such that } \#_0(x)=\#_0(y)\}$, here $\#_0(x)$ means the number of times $0$ appears in $x$. This means we keep every word in $L_1$ if there is a w...
A possible approach is to change the language $L_2$. We only need to check the number of $0$'s in its strings, not the number of $1$'s nor the positions of the $1$'s. Thus replace all $1$'s in the automaton for $L_2$ by $\lambda$-transitions, and make the resulting automaton over $\{0\}$ deterministic again. Then, ...
You can prove this to yourself formally as follows: Say that $F$ is the set of finite binary strings, and $I$ is the set of infinite binary strings. Both of these sets are infinite. Now, the question is whether $I\cup F$ is the set of all binary strings. This is equivalent to saying that for any binary string $b$, $b\i...
I do not think there is a name for that particular algorithm, but I think it will achieve similar performance to much simpler parallel algorithms for this task. In general when designing parallel algorithms, you assume that you have $k$ cores at your disposal. Then, if a task can be accomplished in time $O(f(n))$ using...
Given a string of length $n$, the provided algorithm will loop $n$ times, and each addition is in the order of $O(n)$, yielding a total of $O(n^2)$. To convert a single digit number from base 36 to base 9, here are some examples: $0 - 0, 8 - 8, 9 - 10, H - 18, I - 20, Q - 28, R - 30, Z - 38$. To convert a multi d...
null
Consider the figure in Exercise 2. If the current machine code that executes is 0x214bfffd and the values of the registers in the processor are as shown below, what is then the value of the input WD3 ? Answer as a 32-bit hexadecimal value. at = 0x00011021 v0 = 0x5234f1a0 v1 = 0x1114f111 a0 = 0xff001231 a1 = 0xf...
How do you tell whether a binary number is positive or negative?
|computer-architecture|computer-networks|c|assembly|mips|
null
Could someone help me understand why in the below proof, if $k > log_{2}n$, then $P(N_i=1)< \frac{1}{n}$? [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/bI7Jz.png
Understanding the last algebra step of this proof
|graphs|probabilistic-algorithms|
null
null
Let's say a Language ***L*** is **NON-semi decidable** and **undecidable**. Let's also take the Halting problem ***H***, which is a **semi decidable** and **undecidable** language. Is it possible to reduce ***L*** to ***H***? I know that both are undecidable languages, and we can reduce an **undecidable** language ...
Can I reduce a non semi decidable and undecidable language to a semi decidable language and undecidable langauge?
|reductions|undecidability|halting-problem|semi-decidability|
Can I reduce a non semi decidable and undecidable language to a semi decidable and undecidable langauge?
Let's say a Language ***L*** is **NON-semi decidable** and **undecidable**. Let's also take the Halting problem ***H***, which is a **semi decidable** and **undecidable** language. Is it possible to reduce ***L*** to ***H***? I know that both are undecidable languages, and we can reduce an **undecidable** language ...
null
> how do we know that they t2 = 0xfffffff5= -11 and not $t2 = 4294967285? We don't. They're the same number (in mod 2<sup>32</sup> arithmetic, which is what your computer uses.) Essentially, signed or unsigned is not a property of the number. It's a property of each individual assembly instruction. Some instructi...
|computability|reductions|undecidability|halting-problem|semi-decidability|
I am trying to implement an algorithm that fairly distributes people into groups, given their ranking of those groups, while also taking into account their preference for partners. I have modeled this as a directed graph with upper and lower bounds and costs on edges representing their ratings. Finding a solution w...