instruction
stringlengths
0
29.8k
⌀
markov algorithm unary multiplication
|turing-machines|strings|
Selection sort will sort in O(n^2) with O(n) pointer changes. So if for some reason you need to minimise the number of pointer changes, that’s it. On the other hand, you can just put all the pointers into an array, sort the array, and reconstruct the double linked list. (I actually had this in a job interview. ...
A sequence $(a_1,a_2, \dots, a_n) $ and natural numbers $n$ and $k$ are given. We want to calculate the longest increasing subsequence of sequence $(b_1,b_2, \dots, b_n)$ for which there exist an interval of pointers $[l, r]$ and a number $x$, $-k\le x\le k$, such that $b_i = a_i + x$ for $i \in [l, r]$, and $b_i = ...
Longest increasing subsequence when a number can be added to all numbers in a subarray
Take a look at [Huffman coding](https://en.wikipedia.org/wiki/Huffman_coding) - efficient algorithm for finding optimal (as short as possible) binary coding for given string. This algorithm takes alphabet and weights (usually probabilities of each letter in your text) of each symbol in alphabet, as input. Then computes...
|turing-machines|strings|term-rewriting|
Let's say, initially we have an epsilon NFA in which the start state, say state 1, has epsilon transition to state 3 We know when converting from epsilon NFA to NFA, we apply the following formula for each state: E(T(E(state), input)), where E = epsilon closure and T = transition function. In this stage the start st...
When converting a epsilon NFA to NFA to DFA, how to handle the start state?
|automata|finite-automata|nondeterminism|
Let me answer all your questions as stated, keeping to the practical programmer's point of view. *Is it correct to say that requiring the functor laws on a type constructor is equivalent to requiring that its data constructors satisfy the naturality conditions or something along these lines?* No, this is not quit...
For a given **height (h)** in m-ary tree, you can calculate first the max/main number of nodes and then calculate the leaves according to each situation: 1) To calculate the **max/min** number of nodes in m-ary tree use the following equations: **Maximum number of nodes: $\frac{m^{h+1}-1} {m-1}$** **Minim...
I'm looking for a good mathematical symbol to represent the conversion from a double-precision floating value to an unsigned 32-bit integer value. Does anyone have suggestions for a good Greek letter or a math symbol to express this? The best candidate I can think of is to use a symbol for a floor function with a su...
Math symbol to represent an operator to convert from double-precision to 32-bit integer value?
|integers|
There is no need to apply the $\varepsilon$-closure twice when computing transitions. There are two main ways to convert an $\varepsilon$-NFA into a NFA: the forward closure and the backward closure. Consider $(Q, \Delta, I, F)$ an $\varepsilon$-NFA. - In the forward closure, you are trying to apply $\varepsilon$-tr...
You have demonstrated that example on multiplication cannot be correct. Well, there is typo in that example. The substitution rule $p_3$ should have been $$A\to\epsilon$$
I am learning Markov algorithms and came across the paper [*Markov Algorithm*][1] by CHEN Yuanmi. I am trying to understand the following example (well, any of the examples in the paper). >Example 3: Multiplication. MA3 = $\{\Sigma, P, P_0\}$ > >- $\Sigma = \{a, A, B, C, \#\}$ > >- Productions in $P$: >$p_1: ...
A Markov algorithm that does unary multiplication
|turing-machines|strings|multiplication|term-rewriting|
I asked [a chatbot][1], "what is an advantage of dynamic scoping?" and it said this: >One of the main advantages of dynamic scoping is that it is more flexible and convenient than static scoping. Dynamic scoping makes it easier to pass parameters from one subprogram to another and allows for more efficient use of me...
A chatbot's take on dynamic scoping: it is easier to debug - correct?
|programming-languages|compilers|language-design|
I am learning Markov algorithms and came across the paper [*Markov Algorithm*][1] by CHEN Yuanmi. I am trying to understand the following example (well, any of the examples in the paper). >Example 3: Multiplication. MA3 = $\{\Sigma, P, P_0\}$ > >- $\Sigma = \{a, A, B, C, \#\}$ > >- Productions in $P$: >$p_1: ...
Yes, it is certainly do-able. Use a different $y$ for each rule, e.g., $y_1=1$ if the first rule triggers or $y_1=0$ otherwise, $y_2=1$ if the second rule triggers or $y_2=10$ otherwise, etc. Then your goal is to minimize or maximize $3y_1+10y_2+\dots+y_n$. It is easy to express each rule (e.g., $y_1=1$ if $x_3=1$...
As far as I know, there is no common/standard symbology to represent finite types. Neither floating-point nor unsigned integer. And even less for conversions, taking into account that they are not always possible. You can represent the naturals as the set $\mathbb N$, but there is nothing for the floating-point numbers...
You say "as far as I can tell, the parametricity theorem doesn't even allow you to specify the morphism part of the functors ,. It only takes them as type constructors." What you are missing is the fact that the morphism part of the functors is uniquely fixed by their type, at least in System F (and in many other la...
There is no need to apply the $\varepsilon$-closure twice when computing transitions. There are two main ways to convert an $\varepsilon$-NFA into a NFA: the forward closure and the backward closure. Consider $(Q, \Delta, I, F)$ an $\varepsilon$-NFA. - In the forward closure, you are trying to apply $\varepsilon$-tr...
The definition of "Single Connected" is that for every $u,v \in V$ there is at most a single simple path from $u$ to $v$, and at most a single simple path from $v$ to $u$. The objective is to find an efficient algorithm to decide whether the graph is "single connected". I've managed to come up with the following ...
Deciding if a graph is "Single Connected"
|graphs|connected-components|
null
null
A problem is called solvable by Dynamic Programming if its solution can be calculated by solving its sub-problems. Let's see how the current state of the given problem depends on its previous states (aka sub-problems). [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/JJRJR.png Le...
null
Is your graph directed or undirected? If your graph is undirected then the condition you mention is equivalent to your graph being a forest (every connected component is a tree). If your graph is directed then the condition is equivalent to the corresponding undirected graph being a forest (and there being no ant...
There is no need to apply the $\varepsilon$-closure twice when computing transitions. There are two main ways to convert an $\varepsilon$-NFA into a NFA: the forward closure and the backward closure. Consider $(Q, \Delta, I, F)$ an $\varepsilon$-NFA. - In the forward closure, you are trying to apply $\varepsilon$-tr...
I am working through (1) "GLL Parsing" (2) "GLL parse-tree generation" and (3) "Structuring the GLL parsing algorithm for performance" by Elizabeth Scott and Adrian Johnstone. An example grammar given in (3) 2.1 is S ::= b a c | b a a | b A c A ::= a When parsing `bac` the following packed forest is s...
In GLL generated SPPF graph, how does the algorithm produce children with only one parent?
|parsers|
I'm attempting to search through all the integers between 10^15 and 10^16 to check if they are in the oeis sequence [A277274][1], and the entirety of the program can be summarized as mostly equivalent to : <!-- language: lang-python --> for n in range(int(10**15),int(10**16)): if pow(3, n, n) == 11: ...
Are there any mathematical properties of consecutive integer power modulo operations that could be exploited for algorithmic speed gain?
|performance|modular-arithmetic|
**Problem:** we have a sequence of numeric values, e.g. `[102, 25, 77, 17, 2, 13]`. We need to implement 3 operations, each can be at most logarithmic time complexity. 1. `insert(i, v)` - inserts value `v` at index `i`. 2. `remove(i)` - removes value at index `i`. 3. `peek(i)` - returns value at index `i`. **What...
Ordered sequence with logarithmic insert and remove
|algorithms|time-complexity|data-structures|search-algorithms|avl-trees|
null
There are n houses in a city T, some of which are connected by streets in such a way that there is exactly one path between any two houses (i.e. the graph of houses and streets is a tree T). Tanya has already prepared $m$ gift bags but she ran into a problem. After all, she herself also needs to find a house in the ...
Choosing the appropriate starting vertex
|algorithms|graphs|
I think you have already a good idea with AVL trees. To improve the data structure, you should keep track of the size of each subtree (and discard indices, they are not really useful here). In details, a node $x$ of the tree should have the following information: - value; - size; - height; - pointer to th...
There are n houses in a city T, some of which are connected by streets in such a way that there is exactly one path between any two houses (i.e. the graph of houses and streets is a tree T). Tanya has already prepared $m$ gift bags but she ran into a problem. After all, she herself also needs to find a house in the ...
I am not sure if this is a math question or a computer science question, so please direct me to a better suited community if needed. Given a bounded space G,and a set of points P, I want to create two sets of polygons of Q, and R where Q is a set of polygons where a point in P is the center of each polygon in Q, and...
Creating an Influence Map within a bounded Space
|optimization|computational-geometry|
There are n houses in a city T, some of which are connected by streets in such a way that there is exactly one path between any two houses (i.e. the graph of houses and streets is a tree T). Tanya has already prepared $m$ gift bags but she ran into a problem. After all, she herself also needs to find a house in the ...
I asked a chatbot, "what is an advantage of dynamic scoping?" and it said this: >One of the main advantages of dynamic scoping is that it is more flexible and convenient than static scoping. Dynamic scoping makes it easier to pass parameters from one subprogram to another and allows for more efficient use of memory,...
I asked the chatbot at you.com, ["what is an advantage of dynamic scoping?"](https://you.com/search?q=What+is+an+advantage+of+dynamic+scoping) and it said the following on the pane titled YouChat. (If you click the link, you will probably see a different reply by YouChat since, apparently, there is some random/live fac...
Do a sieve. First you can strike out all multiples of 3, 4, and 11. You've already gotten rid of over half. But now the property that you use is that if `p` is a prime then `3^(kp) mod p = 3^k mod p` which has a pattern that repeats with a period of `p-1`. So, for example, for `5` the pattern goes `3, 2, 1, 4...
null
No, it's not correct. Dynamic scoping is hard to reason about, and therefore hard to debug; because it is hard to reason about, it causes problems for code analysis tools, including optimisers and garbage collectors. If you're thinking about writing a language, implement block-level lexical scoping from the start. ...
Is your graph directed or undirected? If your graph is undirected then the condition you mention is equivalent to your graph being a forest (every connected component is a tree).
In an older question I asked about stack, the statement came up that recursive functions cannot be inlined ([link][1]). I am interested in whether this statement is actually true or not. I understand that it is extremely impractical. But, is it impossible, in theory? To my intuition, it seems like it should be possible...
In theory, is it impossible, or possible (although ridiculously impractical), to inline recursive functions?
|recursion|assembly|
null
In an abstract rewriting system $\langle A, \rightarrow\rangle$, confluence may be stated by using set inclusion. Namely, a rewriting system is confluent iff ${\leftarrow^*\rightarrow^*}\ {\subseteq}\ {\rightarrow^*\leftarrow^*}$ (or equivalenty as the Church-Rosser theorem, ${\leftrightarrow^*}\ {\subseteq}\ {\rightar...
Is it possible to state strong normalization through set inclusion?
|lambda-calculus|normal-forms|term-rewriting|
Your inlined factorial function is incorrect. When $n=10$ (for instance), it gives the wrong result. This is not considered a correct way of inlining. The implicit requirement, when inlining is that the code must maintain the same behavior. Of course, if you don't require that the code produce the same result in...
When I want to judge whether two regular forms represent the same language, I have learned the next method: 1. create the (non-deterministic) finite-state automaton which accepts the language the given regular form represents for two regular forms respectively. 2. convert the two NFA into DFAs. 3. **Judge whet...
In an older question I asked about stack, the statement came up that recursive functions cannot be inlined ([link][1]). I am interested in whether this statement is actually true or not. I understand that it is extremely impractical. But, is it impossible, in theory? To my intuition, it seems like it should be possible...
I don't think it's correct to look at the equivalence of **DFA's** as an isomorphism of their graph representation, as two **DFA's** accepting the same language may have **different** numbers of states(nodes), from graph point of view they will not be isomorphic but they happen to be equivalent as they accept the same ...
null
When I want to judge whether two regular forms represent the same language, I have learned the next method: 1. create the (non-deterministic) finite-state automaton which accepts the language the given regular form represents for two regular forms respectively. 2. convert the two NFA into DFAs. 3. **Judge whet...
When I want to judge whether two regular forms represent the same language, I have learned the next method: 1. create the (non-deterministic) finite-state automata which accepts the language the given regular form represents for two regular forms respectively. 2. convert the two NFA into DFAs. 3. **Judge wheth...
Automata: Are there algorithms to judge whether two automata are isomorphic?
It is usually up to the compiler what exactly to do, and an "inline" command is just a hint. Inlining is usually a trade between call overhead and the amount of code, and the compiler is in the best position to decide. In addition, the compiler may be able to optimise the code because it knows the parameters at call ti...
null
There is no need to apply the $\varepsilon$-closure twice when computing transitions. There are two main ways to convert an $\varepsilon$-NFA into a NFA: the forward closure and the backward closure. Consider $(Q, \Delta, I, F)$ an $\varepsilon$-NFA. - In the forward closure, you are trying to apply $\varepsilon$-tr...
I don't think it's correct to look at the equivalence of **DFA's** as an isomorphism of their graph representation, as two **DFA's** accepting the same language may have **different** numbers of states(nodes), from graph point of view they will not be isomorphic but they happen to be equivalent as they accept the same ...
I think you have already a good idea with AVL trees. To improve the data structure, you should keep track of the size of each subtree (and discard indices, they are not really useful here). In details, a node $x$ of the tree should have the following information: - value; - size; - height; - pointer to th...
I think you have already a good idea with AVL trees. To improve the data structure, you should keep track of the size of each subtree (and discard indices, they are not really useful here). In details, a node $x$ of the tree should have the following information: - value; - size; - height; - pointer to th...
You need to augment the AVL tree with weight information on every node (i.e. the number of nodes in the subtree rooted there). Insertion and deletion will require to update all nodes from the root to the insertion/deletion point. Lookup will use the weight information to choose the descent directions. Note th...
null
You need to augment the AVL tree with weight information on every node (i.e. the number of nodes in the subtree rooted there). Insertion and deletion will require to increment/decrement the weights of all nodes from the root to the insertion/deletion point. Lookup will use the weight information to choose the de...
You need to augment the AVL tree with weight information on every node (i.e. the number of nodes in the subtree rooted there). Insertion and deletion will require to increment/decrement the weights of all nodes from the root to the insertion/deletion point. Lookup will use the weight information to choose the de...
I think you're conflating two different problems here. One is "inlining" (the elimination of a method call), the other is "loop unrolling" (the elimination of a jump instruction). Certainly, recursive method calls can always be replaced with a loop and a stack, and therefore a recursive method can be inlined by ...
When I want to judge whether two regular forms represent the same language, I have learned the next method: 1. create the (non-deterministic) finite-state automata which accepts the language the given regular form represents for two regular forms respectively. 2. convert the two NFA into DFAs. 3. **Judge wheth...
null
Rules for agents in interaction nets are defined by what the principal port of that agent is connected to and each agent has exactly one principal port. In the "max" example, for the top left rule to work the principal port of the Max agent must be the one connected to the 0. But then the top right rule can only ...
Lets assume $2n $ gifts such that each gift $i$ has price $a_i$ The goal is to find a partition of the gifts into $n$ pairs such that each pair $P_i=\left(a_{i_{0}},a_{i_{1}}\right)$ has maximal minimum average IE $ \min_{i\le n}\left\{ \frac{a_{i_{0}}+a_{i_{1}}}{2}\right\} $ is maximal. The problem I have is pr...
Greedy algorithm-maximal minimum average of n pairs
|greedy-algorithms|correctness-proof|induction|
I am trying to create the regular expression for the automaton named "full closure" in the following diagram using the arden's theorem: [![enter image description here][1]][1] Since, we have 3 accepting states, we would find 3 different regular expression and then just union them up. I was able to find regular expr...
Can we further minimize this regular expression: a*(ac* + bc* + cc* + b*bc* + b*cc* ) + b*(bc* + cc*) + c*
|automata|regular-expressions|
There are n houses in a city T, some of which are connected by streets in such a way that there is exactly one path between any two houses (i.e. the graph of houses and streets is a tree T). Tanya has already prepared $m$ gift bags but she ran into a problem. After all, she herself also needs to find a house in the ...
I am trying to create the regular expression for the automaton named "full closure" in the following diagram using the arden's theorem: [![enter image description here][1]][1] Since, we have 3 accepting states, we would find 3 different regular expression and then just union them up. I was able to find regular expr...
Lets assume $2n $ gifts such that each gift $i$ has price $a_i$ The goal is to find a partition of the gifts into $n$ pairs such that each pair $P_i=\left(a_{i_{0}},a_{i_{1}}\right)$ has maximal minimum average IE $ \min_{i\le n}\left\{ \frac{a_{i_{0}}+a_{i_{1}}}{2}\right\} $ is maximal. How to get a contradicti...