## How should be GSA SER projects efficiently arranged to create more links?

Hello Sven,
is it better to create one master project and duplicate it aside (lets says 5 times), or create master project (already having approx. 19900 verified links for a few months) and create 5 Tiers below it? I have recently purchased here on Your board annual DropBox subscription with links refreshed every now and then, but DropBpox fights with GSA SER for system resources. Therefore I perform projects to reset some email cache, unify articles to keep only 1 finespinned and so one. My VpM falls no matter how I did it to @ 0,23VpM in a while.
You helped me some tine ago resolve freezing of GSA SER because of houndreds of e-mail addresses, that were kept in RAM. So now, I use for master project just 1000 of them, and they are shared to its Tiers. Now, highest file size in the folder is master’s file (.statics @ 25MB).

Any hint would be appreciated from You.
Thanks,
Michal

## Efficiently removing elements from list of permutations

I’m looking for an efficient way to remove entries from a list of permutations.

I have a list of variables from which I calculate all possible permutations. I then want to remove those permutations that begin with a sequence of variables that match one from another list. The order of the variables is important.

As an example of the desired behaviour, I begin with the list $$(a,b,b,c,c,c)$$ and then compute all permutations, giving $$((a,b,b,c,c,c),(b,a,b,c,c,c),(c,a,b,b,c,c),\ldots)$$, and so on. I have a second list of the form $$((a), (b, c), (c, b, b))$$. I want to remove from the list of permutations those of the form $$(a,\ldots)$$, $$(b,c,\ldots)$$ or $$(c,b,b,\ldots)$$.

At the moment, I’m using DeleteCases to achieve this. For the above example:

(* original list of permutations *) original = Permutations[{a, b, b, c, c, c}];  (* list of permutations to be removed *) remove = {{a}, {b, c}, {c, b, b}};  (* convert to pattern *) remove = Join[#, {___}] & /@ remove;  (* remove all permutations from original that start with one of the sequences in "remove" *) reduced = DeleteCases[original, Alternatives @@ remove]; 

This seems fine for small numbers of permutations, but rapidly gets out of hand. The following code can be used to generate lists of arbitrary length permutations and the sequences to be removed.

(* function to repeat variable in list *) repeat[m_, 0] := Nothing repeat[m_, n_Integer?Positive] := Sequence @@ ConstantArray[m, n]  (* how many times do a, b, c repeat in original permutations? *) n = 4; (* which starting sequences are we removing? *) m = 2;  (* original list of permutations *) original = Permutations[{repeat[a, n], repeat[b, n], repeat[c, n]}];  (* example list of permutations to be removed - not all of the same length in general *) remove = Join[    Permutations[{repeat[a, m], repeat[b, m], repeat[c, m]}],     Permutations[{repeat[a, m], repeat[b, m], repeat[c, m + 1]}]];  (* convert to pattern *) remove = Join[#, {___}] & /@ remove;  (*remove all permutations from original that start with one of the sequences in "remove"*) reduced = DeleteCases[original, Alternatives @@ remove]; 

For $$n=4$$ and $$m=2$$, this runs in ~0.5s. For $$n=5$$ and $$m=3$$, this balloons to ~200s.

In my real code, original is generated as above, from Permutations. The remove list is not generated from a list of permutations like in the above code – it will contain elements of length 1 to one less than the length of the elements of original.

Is there any way to speed up the removal of the matching permutations? Or is it hopeless, given how the number of permutations blows up?

Thanks!

## Efficiently storing and modifying a reorderable data structure in a database

I’m trying to create a list curation web app. One thing that’s important to me is being able to drag-and-drop reorder items in the list easily. At first I thought I could just store the order of each item, but with the reordering requirements, that would mean renumbering everything with a higher order (down the list) than the place where you removed or where you inserted the moved item. So I started looking at data structures that were friendly to reordering, or to both deletion and insertion. I’m looking at binary trees, probably red-black trees or something like that. I feel like I could with great effort probably implement the algorithms for manipulating those.

So here’s my actual question. All the tree tutorials assume you’re creating these trees in memory, usually through instantiating a simple Node class or whatever. But I’m going to be using a database to persist these structures, right? So one issue is how do I represent this data, which is kind of a broad question, sure. I would like to not have to read the whole tree from the database to update the order of one item in the list. But then again if I have to modify a lot of nodes that are stored as separate documents, that’s going to be expensive too, even if I have an index on the relevant fields, right? Like, every time I need to manipulate a node I need to actually find it in the database first, I think.

Also, I obviously need the content and order of each node on the front end in order to display the list, but do I need the client to know the whole tree structure in order to be able to send updates to the server, or can I just send the item id and its new position in the list or something?

I’m sorry if this veers too practical but I thought someone might want to take a crack at it.

## If I can efficiently uniformly sample both $A$ and $B\subset A$, can I efficiently uniformly sample $A-B$?

As posed in the question; the statement naively seems like it should be self-evident but there are no algorithms that come immediately to mind. Suppose I have some domain $$A$$ (in my case a subset of $$\mathbb{Z}^n$$ for some $$n$$, but I would expect any answer to be independent of that structure), and a domain $$B\subset A$$. If I have an efficient algorithm for uniformly sampling from $$A$$, and an efficient algorithm for uniformly sampling from $$B$$, is there any way of ‘combining’ these to get an efficient algorithm for uniformly sampling $$A-B$$? I can certainly rejection-sample, but if $$|A-B|\ll|A|$$ then there’s no guarantee that that will be efficient.

## Distance to $k$th nearest neighbor efficiently for arbitrary $k$

Problem. Given $$X$$ a finite metric space of cardinality $$n$$, construct a data structure in subquadratic time such that the query distance to the kth nearest neighbor of x can be resolved in sublinear time (independent of $$k$$) for arbitrary $$k \leq n$$ and $$x \in X$$.

What I have tried. I am aware of the existence of kdtrees, ball-trees, and cover trees. Under some assumptions (which I’m willing to make), I know that these structures can resolve the query distance to the nearest neighbor of x in sublinear time (often $$O(\log(n))$$), but I haven’t been able to find similar results for the $$k$$th nearest neighbor for arbitrary $$k$$.

It seems that, often, one is interested in $$k$$ values that are small compared to $$n$$, and that, in those cases, the algorithms mentioned in the previous paragraph can be adapted at the cost of a multiplicative constant of the order of $$k$$. My problem is that I am interested in $$k$$ values that are potentially of the order of $$n$$.

## Are there any enumerations of (machines for) languages in P such that all the machines can be simulated efficiently on any input?

From Computational Complexity A Modern Approach: Efficient Universal Turing Machine Theorem: There exists a TM U such that for every x, α ∈ {0, 1}∗, U(x, α) = Mα(x), where Mα denotes the TM represented by α. Furthermore, if Mα halts on input x within T steps then U(x,α) halts within CT log T steps, where C is a number independent of |x| and depending only on Mα’s alphabet size, number of tapes, and number of states.

From Kozen INDEXINGS OF SUBRECURSIVE CLASSES: "the class of polynomial time computable functions is often indexed by Turing machines with polynomial time counters…. The collection of all (encodings over (0, 1)) of such machines provides an indexing of PTIME…we have Theorem: No universal simulator for this indexing can run in polynomial space."

He then goes on to say: "can it be proved that gr U for any indexing of PTIME requires more than polynomial space to compute? We have proved this for a wide class of indexings, namely counter indexings satisfying the succinct composition property."

• gr U is the graph of the universal function U and (barring details) represents the minimum power necessary to simulate P uniformly.

• And the counter indexing (or polynomial time counters) he is referring to is specified in the answer here: How does an enumerator for machines for languages work?

I’m wondering how theorem for efficient universal Turing machine relates to Kozen’s result, that for certain types of enumerations of P, there is no machine that can efficiently simulate the machines enumerated. What causes simulation to be difficult and can it be circumvented–namely: does there exist an enumeration of P that describes the (machines for) languages in P in such a way that allows them to be efficiently simulated (with no more than poly overhead) on any input–or as Kozen puts it "allow(s) easy construction of programs from specifications"?

My guess is that part of the reason for the difficulty is because the efficient simulation theorem only says that there exists a machine that can efficiently simulate any single TM, but not a whole class of them… and when you start having to simulate more than one TM you loose the ability to optimize your simulator’s design to solve any particular language (run any particular machine) and have to design the simulator with the various machines you need to simulate in mind (and the more different those machines are the larger your overhead gets).

PS. A possible example could be in implicit complexity theory… where they construct languages that are complete for certain complexity classes. A language that is complete for P doesn’t seem to have trouble running its programs (which represent the languages in P)? But, if there are examples here, how do they overcome the difficulty Kozen is referring to, as they are programming systems and thus enumerations / indexings?

Just as a related aside… I think I have a proof that for a language Lp 1. and 2. cannot be true at the same time:

1. An enumeration of P, call it language Lp (whose members are the strings in the enumeration) is decidable in poly time.

2. All the P machines / languages represented by strings in Lp can be efficiently simulated by a universal simulator for P on any input.

It makes sense that there would be a relationship between the way the machines are encoded and the overhead for their simulation and 1. can be made to be true so that leaves 2. and brings us to the question being asked… Is it possible that 2. is always false–meaning for ANY enumeration/ encoding of P (any language Lp) simulation of those machines is not efficient for any universal simulator for P.

Here’s a rough sketch for anyone interested:

Take L:= {w∈L iff w∈Lp and W(w)=0}

So, one way to do this is our diagonal function maps w–>the language in P that w encodes (if w encodes a machine for a language in P (if w is a member of Lp)) and if it does not then it maps to the language containing all words. The existance of a map between a w and a language translates to w∈L iff w ‘is not a member’ of the language it is mapped to.

Since all w’s that aren’t encodings of P machines (members of Lp) are mapped to the language containing all words–they are members of L iff they are not members of this language. This is always false, so all words that are not members of Lp are not members of L.

This leaves only words of Lp as candidates for members of L. But for w to be a member of L not only does it need to be a member of Lp–the machine that w encodes, W, needs to evaluate to 0 on w. W(w)= 0 and w∈Lp <–> w∈L.

L is not in P. If L were in P then for some w, w would encode a machine for L, Wl. and for that w∈L iff Wl(w) = 0, ie. w∈L iff w is not in L.

Now, let’s employ the assumption that 1. Lp is poly decidable. As well as the assumption 2. that any machine specified by Lp can be simulated with no more than poly overhead by a universal simulator.

Then we can devise an algorithm, namely: given w, decide w∈Lp. If w∈Lp then run W(w). If w(w)=0 –> w∈L.

By the above algorithm, under these the assumptions 1. and 2. L would be in P–which is a contradiction to the previous proof by contradiction. I think the previous proof is correct and conclude that neither 1. nor 2. can be true at the same time.

## If anything can be verified efficiently, must it be solvable efficiently on a Non-Deterministic machine?

Suppose, I wanted to verify the solution to $$2$$^$$3$$. Which is $$8$$.

The $$powers~of~2$$ have only one 1-bit at the start of the binary-string.

## Verify Solution Efficently

n = 8 N = 3 IF only ONE 1-bit at start of binary-string:   IF total_0-bits == N:    if n is a power_of_2:      OUTPUT solution verified, 2^3 == 8 

A solution will always be approximately $$2$$^$$N$$ digits. Its not possible for even a non-deterministic machine to arrive to a solution with $$2$$^$$N$$ digits faster than $$2$$^$$N$$ time.

Question

Can this problem be solved efficently in non-deterministic poly-time? Why not if the solutions can be verified efficently?

## Sort the given list efficiently [closed]

Consider you have a permutation of $$1$$ to $$n$$ in an array $$s$$. Now select three distinct indices $$a$$,$$b$$,$$c$$,need not to be sorted. Let $$s_a$$, $$s_b$$ and $$s_c$$ be the values at those indices and now you make a right shift to it ,that is $$new$$ $$s_a$$= $$old$$ $$s_b$$ and $$new$$ $$s_b$$= $$old$$ $$s_c$$ and $$new$$ $$s_c$$=$$old$$ $$s_a$$. Find the minimum number of operations required to sort the array or if is impossible how to determine it.

Example : Consider $$s= [2, 1, 3]$$; consider indices $$(1,3,2)$$ in the given order after applying one opeartion it is $$s =[1,2,3]$$.

I am thinking of applying a graph approach and solve it using graph traversal, am I right? Or you could explain your apporach.

## How do I compare these ranges of numbers efficiently?

I’m looking for an efficient way of testing eights. What happens is I need to check if a value is eights and discard it.

The numbers I need to check for are:

8.8888, 88.888, 888.88, 8888.8, 88888.00                // 5 digits 88.8888, 888.888, 8888.88, 88888.8, 888888.00           // 6 digits 888.8888, 8888.888, 88888.88, 888888.8, 8888888.00      // 7 digits 8888.8888, 88888.888, 888888.88, 8888888.8, 88888888.00 // 8 digits 

However, these are actually represented in integer form. Which is the number multiplied by 10000.

So 8.8888 is represented as an int64 with the value 88888, and 888888.00 is represented as 888880000

There are quite a few values here to check. My simple approach was to just compare each one directly from a table. But then I thought perhaps I should maybe do something more efficient like masking and comparing each digit. But my crude approach did not work. It seems cumbersome and potentially a bit slow to convert to a string and compare eights that way. This code will run on an embedded system which checks these values many times over so I do need it to be reasonably performant. Note that I won’t have less than 5 digits represented or more than 8.

## Proof that uniform circuit families can efficiently simulate a Turing Machine

Can someone explain (or provide a reference for) how to show that uniform circuit families can efficiently simulate Turing machines? I have only seen them discussed in terms of specific complexity classes (e.g., $$\mathbf{P}$$ or $$\mathbf{NC}$$). I would like to see how uniform circuit families is a strong enough model for universal, efficient computation.