instruction stringlengths 0 29.8k ⌀ |
|---|
Functional programming employs persistent data structures and immutable objects. The question is why it is crucial to have such data structures here? I want to understand **at low level** if the data structure is not persistent what will happen? Will the program crash more often? |
Why do we use persistent data structures in functional programming? |
You should have a look at Jean-François Raskin's paper [Antichain Algorithms for Finite Automata][1].
In our experiments, the antichain-based inclusion test performed one or two orders of magnitude better than the "traditionally" approaches.
Edit: If I remember correctly, this algorithm is implemented in the [lib... |
Suppose we have a set $S = \{(a_1,b_1),...,(a_n,b_n)\}$ where $a_i < m$, $b_i = m-a_i$, $m \in \mathbb{Z}^{+}$, $m>2$ and $n$ is an even number greater than $3$. What is the most efficient algorithm to partition $S$ into two distinct subsets, $C$ and $D$, of equal size such that the sum of the $a$'s in $C$ is greater t... |
Optimal partition of a set of pairs |
|algorithms| |
It is *easier* to correctly work with persistent data structures than it is to work with mutable data structures. This, I would say, is the main advantage.
Of course, theoretically speaking, anything we do with persistent data structures we can also do with mutable ones, and vice versa. In many cases persitent data ... |
When you work with immutable data objects, functions have the property that every time you call them with the same inputs, they produce the same outputs. This makes it easier to conceptualize computations and get them right. It also makes them easier to test.
That is just a start. Since mathematics has long worke... |
When you work with immutable data objects, functions have the property that every time you call them with the same inputs, they produce the same outputs. This makes it easier to conceptualize computations and get them right. It also makes them easier to test.
That is just a start. Since mathematics has long worke... |
null |
I was looking at the construction proof showing the equivalence of NFA and DFA from Sipser's text. It started by taking number of states of DFA as $\mathcal{P}(Q)$, where $\mathcal{P}(Q)$ is the set of subsets of $Q$.
My doubt is when we construct DFA from NFA, all the subsets may not occur in that DFA. So how coul... |
Equivalence of NFA and DFA - proof by construction |
When you work with immutable data objects, functions have the property that every time you call them with the same inputs, they produce the same outputs. This makes it easier to conceptualize computations and get them right. It also makes them easier to test.
That is just a start. Since mathematics has long worke... |
Functional programming employs persistent data structures and immutable objects. My question is why is it crucial to have such data structures here? I want to understand **at a low level** what would happen if the data structure is not persistent? Would the program crash more often? |
null |
The sum divider game for $n$ starts with the set $M_0 = \{1,\dots,n\}$. Player A chooses a number $m_1$ from $M_0 \setminus \{1\}$ and B has to choose a divider $m_2$ of $m_1$ from $M_1 = M_0 \setminus \{m_1\}$. The players continue to choose a number $m_i$ from $M_{i-1} = M_{i-2} \setminus \{m_{i-1}\}$ alternatingly, ... |
Complexity of deciding whether there is a winning stratagy in the following game |
|time-complexity|number-theory|game-theory| |
null |
Consider this rule:
example : 'a' | thingie 'b' ;
Now consider a left-to-right parser trying to match a non-matching string like `'b'` to this rule. Since `'a'` doesn't match, it'll try to match `example 'b'`. But in order to do so, it has to match `example`...which is what it was trying to do in the first ... |
one of the best/most thorough/state-of-the-art and highly optimized, free FSM libraries available online is the [AT&T FSM library](http://www2.research.att.com/~fsmtools/fsm/). it implements ["fsmdifference"](http://www2.research.att.com/~fsmtools/fsm/man4/fsm.1.html) exactly as you describe, requiring a determinized e... |
Say, L⊆{0}* . Then how to prove that L* is regular?
If L is regular, then of course L* is regular. If L is finite, then it is regular and again L* is regular.
Also I have noticed that, for L = {0^p | p is a prime}, L is not regular, L⊆{0}* and L* is regular.
But how to show this for any subset L of {0}* ? |
If L is a subset of {0}* , then how to show that L* is regular? |
|regular-languages| |
Given the reduction $3SAT\leq_p IndSet$ as follows:
![enter image description here][1]
how can I argue that it's in polynomial time? I understand how the reduction works, but even though it appears rather trivial, I can't explain why it's efficient.
>To place $IndSet$ in NP-Hard, we will show $3SAT\leq_p IndSe... |
How can I argue that $3SAT\leq_p IndSet$ is polynomial in time? |
|reductions| |
Given the reduction $3SAT\leq_p IndSet$ as follows:
![enter image description here][1]
how can I argue that it's in polynomial time? I understand how the reduction works, but even though it appears rather trivial, I can't explain why it's efficient.
>To place $IndSet$ in NP-Hard, we will show $3SAT\leq_p IndSe... |
You are given a formula, and you will construct a graph. You can argue the reduction is polynomial time by analyzing the time you need to construct the graph.
Scan the clauses of the formula in time that is linear in the number of clauses. Scan the 3 literals in every clause. Build 3 vertices, with labels correspond... |
Suppose we have a set $S = \{(a_1,b_1),...,(a_n,b_n)\}$ where $a_i < m$, $b_i = m-a_i$, $m \in \mathbb{Z}^{+}$, $m>2$ and $n$ is an even number greater than $3$. What is the most efficient algorithm to partition $S$ into two distinct subsets, $C$ and $D$, of equal size such that $\sum_{a \in C} a > \sum_{b \in C} b$ an... |
You are given a formula, and you will construct a graph. You can argue the reduction is polynomial time by analyzing the time you need to construct the graph. The transformation is an algorithm: write each step down, and analyze them. If every step takes polynomial time, you have shown the reduction runs in polynomial ... |
Let Undir-Reachability be the following problem:
given an undirected graph G and two specified vertices s and t in G, is there a path from s to t in G?
I need to prove that the 2-Colourability is in L, by knowing that Undir-Reachability belongs to the complexity class L.
I don't know how to start. |
Prove that 2-Colourability is in L from Undir-Reachability is in L |
|complexity-theory|graphs|space-complexity|colorings| |
I need to prove that the following problem 01-Ineq is NL-complete.
Given a finite set of variables V , a finite set of inequalities of the form x ≤ y (where x, y∈V)and a finite set of equalities of the form x=a (where x∈V and a∈{0,1}), is there an assignment of values from {0, 1} to the variables satisfying all the ... |
Prove that 01-Ineq is NL-complete |
|complexity-theory|graphs|space-complexity| |
Fan-in in a circuit tree or a formula (i.e. outdegree $= 1$ as you mention) is limited by the number of input variables. A node or a gate cannot connect to more than the input variables. However, note that often in many constructions, the indegree is limited to 2, and gates are combined using the simple rule $a \wedge ... |
One of the best, most thorough state-of-the-art and highly optimized, free FSM libraries available online is the [AT&T FSM library](http://www2.research.att.com/~fsmtools/fsm/). It implements ["fsmdifference"](http://www2.research.att.com/~fsmtools/fsm/man4/fsm.1.html) exactly as you describe, requiring a determinized ... |
Assume that $L$ contains two words $w_1$ and $w_2$ such that the lengths of these words, $|w_1|$ and $|w_2|$, have no factors in common. Then, we have that the longest word that cannot be formed by concatenating these words has length $(|w_1|-1)(|w_2|-1) - 1$ ([Frobenius number][1]). That is to say, if there are words ... |
Say, $L \subseteq \{0\}^*$. Then how can we prove that $L^*$ is regular?
If $L$ is regular, then of course $L^*$ is also regular. If $L$ is finite, then it is regular and again $L^*$ is regular.
Also I have noticed that, for $L = \{0^p \mid p \text{ is a prime}\}$, $L$ is not regular, $L \subseteq \{0\}^*$ and $L^*... |
If $L$ is a subset of $\{0\}^*$, then how can we show that $L^*$ is regular? |
|formal-languages|regular-languages| |
null |
Pumping Lemmas: How do we determine if set of binary strings with equal 0 and 1 are or aren't regular
I'm trying to figure out if a set of binary strings has an equal number of 0's and 1's if it's regular or not |
Pumping Lemmas: How do we determine if set of binary strings with equal 0 and 1 are or aren't regular |
|pumping-lemma| |
I'm in a course about computing and complexity, and am unable to understand what these terms mean. All I know is that np is a subset of np complete which is a subset of np hard... but I have no idea what they actually mean. Wikipedia isn't much help either as the explanations are still a bit too high level. |
{"OriginalQuestionIds":[1031],"Voters":[{"Id":69,"DisplayName":"Patrick87"}]} |
Consider this rule:
example : 'a' | thingie 'b' ;
Now consider a LL parser trying to match a non-matching string like `'b'` to this rule. Since `'a'` doesn't match, it'll try to match `example 'b'`. But in order to do so, it has to match `example`...which is what it was trying to do in the first place. It ... |
I am building a system and I have a couple of architectures in mind. I want to have an idea of which architecture is likely to be most performant (quickest).
I can make different decisions like
1) Do everything in one thread
2) Separate this part into one thread, that part into another thread since it can run in ... |
Modeling timing characterists of an architecture |
|efficiency| |
My solution, suggested OOB by a friend, is to use a Finite State Machine:
section ::= c ;
a ::= CODE SC ;
b ::= a CODE SC ;
c ::= c HOUR SC | b HOUR SC | e CODE SC ;
d ::= HOUR SC | d HOUR SC ;
e ::= e HOUR SC | a HOUR SC | d CODE SC ... |
Given a relation $R(A, B, C, D, E, F)$, with the following functional dependencies:
$\{A \rightarrow BC, CD \rightarrow E, B \rightarrow D, E \rightarrow A\}$.
The objective is to decompose $R$ into 3NF relations.
So far, I have determined that the following candidate keys are present in the given relation:
$AF... |
The basic idea is that in a language built on a one-letter alphabet, every sufficiently long word is a concatenation of shorter words. So when you take a word $w$ in $L^*$, i.e. a concatenation of words in $L$, there is a core $\mathring{L}$ such that $w$ is a concatenation of words in $\mathring{L}$. Thus $L^* = \math... |
The basic idea is that in a language built on a one-letter alphabet, every sufficiently long word is a concatenation of shorter words. So when you take a word $w$ in $L^*$, i.e. a concatenation of words in $L$, there is a core $\mathring{L}$ such that $w$ is a concatenation of words in $\mathring{L}$. Thus $L^* = \math... |
Hint: Directed reachability is NL-complete. |
Hint: a graph is not bipartite if there is a walk of odd length from a vertex to itself. |
Complexity of deciding whether there is a winning strategy in the following game |
The simple answer is to just build the _simplest_ architecture that gives the results you want. You will have lots of problems anyway, making the system more complex than strictly required is just making more work. And a simple architecture is probably more performant than a more complex one, and easier to work with fo... |
null |
There are some not-very-commonly considered forms of [trinary logic](http://en.wikipedia.org/wiki/Three-valued_logic) using 3 truth values. Even entire (unusual/rare) [ternary computers](http://en.wikipedia.org/wiki/Ternary_computer) have been built from it.
> Is there some knowledge or reference of how to convert s... |
Building functionally complete boolean circuits out of trinary logic |
Hint: This is 2SAT in disguise. |
null |
null |
Suppose we have a set $S = \{(a_1,b_1),...,(a_n,b_n)\}$ where $a_i < m$, $b_i = m-a_i$, $m \in \mathbb{Z}^{+}$, $m>2$ and $n$ is an even number greater than $3$. What is the most efficient algorithm to determine if it is possible to partition $S$ into two distinct subsets, $C$ and $D$, of equal size such that $\sum_{a ... |
I need to prove that the following problem $0$-$1$ $\mathsf{ Ineq}$ is $\mathsf{NL}$-complete.
Given a finite set of variables $V$, a finite set of inequalities of the form $x \le y$ (where $x, y \in V$) and a finite set of equalities of the form $x=a$ (where $x \in V$ and $a \in \{0,1\}$), is there an assignment of... |
Prove that $0$-$1$ $\mathsf{ Ineq}$ is $\mathsf{NL}$-complete |
|complexity-theory|graphs|reductions|space-complexity| |
null |
Suppose we have a set $S = \{(a_1,b_1),...,(a_n,b_n)\}$ where $a_i < m$, $b_i = m-a_i$, $m \in \mathbb{Z}^{+}$, $m>2$ and $n$ is an even number greater than $3$. What is the most efficient algorithm to determine if it is possible to partition $S$ into two distinct subsets, $C$ and $D$, of equal size such that
$\sum... |
I am trying to define a non terminal symbol in a LALR(1) grammar (with CUP parser). It is requested that
the <code> token must appear exactly twice,
while the <hour> token must appear at least once.
In the end I came up with this definition:
section ::= hour_l CODE SC hour_l CODE SC hour... |
My solution, suggested by a friend, is to use a Finite State Machine:
section ::= c ;
a ::= CODE SC ;
b ::= a CODE SC ;
c ::= c HOUR SC | b HOUR SC | e CODE SC ;
d ::= HOUR SC | d HOUR SC ;
e ::= e HOUR SC | a HOUR SC | d CODE SC ;
... |
My solution, suggested by a friend, is to use a Finite State Machine. I drew a Deterministic Finite Automata, and $C$ is the final state accepted by this machine:
![DFA][1]
I then transformed it into a right regular grammar:
section ::= c ;
a ::= CODE SC ;
b ::= a CODE SC ... |
Pumping Lemmas: How do we determine if this language isn't regular
I'm not really sure the how you would go about this
$L= \{0^p 1^q 0^m 1^n | p+q=m+n, p,q,m,n \geq 0 \}$
Does this indicated that $S = 4$, so we start by by using a string $\geq 4$? |
Pumping Lemmas: How do we determine if this language isn't regular $L= \{0^p 1^q 0^m 1^n | p+q=m+n, p,q,m,n \geq0 \}$ |
Pumping Lemmas: How do we determine if this language isn't regular
I'm not really sure the how you would go about this
$L= \{0^m 1^n | 2n \geq m \geq 3n, m,n \geq 0 \}$
Does this indicated that $S = 2$, so we start by by using a string $\geq 2$? |
Pumping Lemmas: How do we determine if this language isn't regular $L= \{0^m 1^n | 2n \geq m \geq 3n, m,n \geq 0 \}$ |
Pumping Lemmas: How do we determine if this language isn't regular
I'm not really sure the how you would go about this
$L= \{0^m 1^n | 2n \leq m \leq 3n, m,n \geq 0 \}$
Does this indicated that $S = 2$, so we start by by using a string $\geq 2$? |
Pumping Lemmas: How do we determine if this language isn't regular $L= \{0^m 1^n | 2n \leq m \leq 3n, m,n \geq 0 \}$ |
null |
If I understood well the problem:
$S = \{ (a_1, m-a_1), (a_2, m-a_2), ..., (a_n, m-a_n),\; m>2 $
$\sum_{a_i \in C} a_i > \sum_{a_i \in C} (m - a_i)$ and $\sum_{a_j \in D} a_j > \sum_{a_j \in D} (m - a_j)$ is equivalent to
$\sum_{a_i \in C} a_i > m * |C| - \sum_{a_i \in C} a_i$ and $\sum_{a_j \in D} a_j > m * |... |
A somewhat late response:
The formula $AX(p U q)$ is equivalent to the CTL formula $AXA(pUq)$: Consider a state that satisfies the former, then in all the paths from it, after one transition it holds that $pUq$. Thus, in all the paths after one transition, we reach a state from which all the paths satisfy $p U q$, s... |
Proof by contradiction is often used to show that a language is not regular: let $P$ a property true for all regular languages, if your specific language does not verify $P$, then it's not regular.
The following properties can be used:
1. The pumping lemma, as exemplified in [Dave's answer][1];
2. [Closure prope... |
null |
Given the reduction $3\mathsf{SAT}\leq_p \mathsf{IndSet}$ as follows:
![enter image description here][1]
How can I argue that it's in polynomial time? I understand how the reduction works, but even though it appears rather trivial, I can't explain why it's efficient.
>To place $\mathsf{IndSet}$ in $\mathsf{NP}... |
How can I argue that $3\mathsf{SAT}\leq_p \mathsf{IndSet}$ is polynomial in time? |
null |
null |
How do we find all equivalence classes of $\operatorname{R}_L$ for a language?
Say I'm trying to look for all equivalent classes in 011(0+1)*011 |
Finding all equivalence classes of '\operatorname(R)_L' for a language |
|regular-languages|finite-automata| |
How do we find all equivalence classes of $\mathsf{R_L}$ for a language?
Say I'm trying to look for all equivalent classes in $011(0+1)^*011$. |
Finding all equivalence classes of $\mathsf{R_L}$ for a language |
How do we find all equivalence classes of $\mathsf{R_L}$ for a language?
Say I'm trying to look for all equivalent classes in $011(0+1)^*011$.
Equivalent Relation
$xRy$ iff $(\forall w)[xw \in \mathsf{L} \Leftrightarrow yw \in \mathsf{L}]$ |
You may want to look at Sipser's "Theory of Computation" for a full explanation.
Technically, you must first define the problem. What do you mean by "find the equivalence classes"? You probably mean that you want to find a representative of each class, or to find an algorithm that given a word, classifies it to a clas... |
How do we find all equivalence classes of $\mathsf{R_L}$ for a language?
Say I'm trying to look for all equivalent classes in language $011(0+1)^*011$.
Equivalent Relation
$xRy$ iff $(\forall w)[xw \in \mathsf{L} \Leftrightarrow yw \in \mathsf{L}]$ |
Finding all equivalence classes of $\mathsf{R_L}$ for language $011(0+1)^*011$ |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.