## permutations: can we exchange elements strangely in a list without modifying it?

Thank you for contributing a response to Mathematics Stack Exchange!

But avoid

• Make statements based on opinion; Support them with references or personal experience.

Use MathJax to format equations. MathJax reference.

## Sum of n sums, permutations of the indexes, how to write them in Mathematica?

I was wondering how to write a function $$F (r, q, n, f)$$ in Mathematica, defined in this way:

$$F (r, q, n, f): = sum_ {i_0 = 1} ^ qf (i_0) Biggl ( sum_ {i_1 = i_0 + 1} ^ {q + 1} f (i_1) biggl ( sum_ {i_2 = i_1 + 1} ^ {q + 2} f (i_2) Bigl ( ldots ( sum_ {i_n = i_ {n-1} +1} ^ {q + n} f (i_n) ) ldots Bigl) biggl) Biggl)$$
is.
$$sum_ {i_0 = 1} ^ 2 f (i_0) Biggl ( sum_ {i_1 = i_0 + 1} ^ {3} f (i_1) biggl ( sum_ {i_2 = i_1 + 1} ^ {4 } f (i_2) biggl) Biggl) = f (1) f (2) f (3) + f (1) f (2) f (4) + f (1) f (3) f (4) + + f (2) f (3) f (4)$$

Is there already an operator that can be used in this way?

Trying to write this function in mathematics, I realized that "recursion" is variable and I don't know how to program in this case.

Thank you





another example

$$sum_ {i_0 = 1} ^ 1 f (i_0) Biggl ( sum_ {i_1 = i_0 + 1} ^ {2} f (i_1) biggl ( sum_ {i_2 = i_1 + 1} ^ {3 } f (i_2) ( sum_ {i_3 = i_2 + 1} 4 {f} (i_2)) biggl) Biggl) = f (1) f (2) f (3) f (4)$$

## combinatorial – Go function to generate permutations of a given whole matrix

I am writing a function to generate a permutation of dice ()int:

// Input: (1,2,3)
// Output:
// (
//   (1,2,3),
//   (1,3,2),
//   (2,1,3),
//   (2,3,1),
//   (3,1,2),
//   (3,2,1)
// )

func permute(nums ()int) ()()int {
var tmp ()int
var res ()()int
invalid_pos := make(()bool, len(nums))
res = backtrack(nums, tmp, invalid_pos, res)
return res
}

// backtrack generates all the permutations of the given nums and put them into res.
// invalid_pos keeps track of which number is valid to pick from nums to form a permutation
// tmp
func backtrack(nums ()int, tmp ()int, invalid_pos ()bool, res ()()int) ()()int {
if len(tmp) == len(nums) {
tmp2 := make(()int, len(tmp))
copy(tmp2, tmp)
res = append(res, tmp2)
} else {
for i, num := range nums {
if invalid_pos(i) {
continue
}
invalid_pos(i) = true
tmp = append(tmp, num)
res = backtrack(nums, tmp, invalid_pos, res)
invalid_pos(i) = false
tmp = tmp(:len(tmp)-1)
}
}
return res
}


My question is if I need to make a copy copy(tmp2, tmp)? I read about capturing iteration variables and I was wondering if this will have any side effects. I think I can simplify the code by removing copy

## What is the connection between the number of permutations and the number of subsets?

How many different ways to fill 100 boxes in a line with the back or white balls.
(A box can only contain one ball at a time).

My attempt:

Different ways to fill 1 st box = 2
Different ways to fill the 2nd box = 2
Different ways to fill the third box = 2
& # 39;
& # 39;
& # 39;
& # 39;
& # 39;
Different ways to fill table 99 = 2
Different ways to fill the table number 100 = 2

SO by method of counting the answer is $$2 100$$.

Is this equal to the number of subsets that has a set of 100 elements?

What is the connection of these types of questions and $$2 ^ n$$ has?

## randomness: simple generator of variable length short sequence pseudo-random permutations

The problem in front of me is to write a function (from scratch) to permute n elements, where n is an argument. I decided to divide it into applying Knuth's shuffling algorithm, therefore, I needed to write a pseudorandom number generator.

So now my task is to write a simple function F(seed,n) That will help me generate indexes for the pseudo-random permutations of n elements. However, the function has to be extremely simple: my restriction is that I can only use the following operators: +, -, *, /,%, specifically, without access to the address, binary encoding, bit selection, etc. – only arithmetic in numbers. That's fine, I went for linear congruental generators and implemented a (a*x+c)%m process.

When i started testing F(seed,2) It immediately became clear that the results range from zero to one with a period of two.

My problem is: how can I adjust F to avoid that behavior? Maybe I should generate the n-permutations in a different way?

In practice, I'm only interested in n = <32

## Algorithms – Generating all possible permutations in the problem of fox, goose and beans

I learned the theory of graphics and I am using it to solve the classic puzzle of fox, goose and bean bag. If we consider that there are three locations for each of the foxes (X), geese (G), farmers (F) and beans (B) (near the river, in the boat, on the other side of the river), and there are Four characters, therefore, there are 4 ^ 3 = 81 combinations.
Two of these combinations would be

(Near)    (Boat)    (Far)
F,G,B,X     -         -

(Near)    (Boat)    (Far)
B,X        F,G        -


… for the initial state and the state in which the farmer and the goose have entered the boat, respectively.

I want to generate all these states programmatically (in C ++, but that's beyond the point), but I just can't understand how to do it. (I know that some of these 81 possible states will not be valid (for example, with all the characters in the boat at the same time), but I can search and delete them later.)

I know the binary well and how I get 81 combinations, and I know that using C ++ I could generate all the combinations of the characters F, G, X, B, but I still can't understand how to add the three "locations" in this.

EDIT:

OK, can the voter explain how "this question does not show any research effort, is it unclear or not useful"? Do you want me to list everything I've tried and every search I've done?

(And yes, I searched for many solutions before posting here).

## Replacement rule with all possible permutations

I have a list with expressions like

{1,3,5,a,c,b,3,d}



I want to generate all outputs with permutations of {a, b, c, d},
so, for example, a rule like

/. {a->a,b->d, c->c, d->b]


In total shere must be k! New lists For the previous example, I also don't know how to make a replacement like b<->d that would save some time.

I found the PermutationReplace function, and something like

PermutationReplace[{1,2,3},SymmetricGroup[3]]


It would give me the 6 permutations of 123. But I don't know how I can apply something like that if the elements I want to permute are arbitrary numbers / characters / variables.

I appreciate any help, and thanks for reading.

## query: are all permutations of a string a good way to index the full text search?

I am writing an application to use as a local disk. Documents store functionality similar to Firebase or MongoDB. The essence of how it works is a column hash table.
For example:

Let's say I have a user document

{
"first": "stack",
"last": "overflow",
"age": 2147
}


Basically, itero each field as a column and save a hash value as a file name for a file, which contains the unique row key (if several objects have the same value for a column, several row keys will be written to the file ). Then, save the record in a directory with the key as the file name. So, for a simple name = "stack" I have a search O (1), hash the value, see if there is a file with the hash value as a name, if it exists, read all the file's row keys. iterate each key and load data from the file. I guess if the number of rows is large, this will be a slower query.

What i'm trying to do
I want to add a partial text search capability. My initial idea is to write all the permutations of the value in the index and then do the same OR (1) – the file exists – verify that I mentioned above. So, if the query is name name contains st I will only search for a file name for that value and read all the row keys.

Is this a good way to offer a partial text search?
What are some common industry techniques?

Draft

## optimization: minimizes the same elements placed in a permutations list (heap)

I am trying to optimize the permutations generated from a set of n elements.

Here is the tone:
Let's say we have a set of 6 elements. $${1,2,3,4,5,6 }$$ and I want to create 10 permutations. I could use the Heap algorithm to keep 10 out of 6! possible combinations

But I would like to add a specific restriction: I want to select the 10 permutations that minimize the number of items in the same index.
(avoid having 10 permutations with 3 in the same index, for example)

For example, I simply create the first 6 permutations by turning my initial set from 1 to 6 to the right to obtain the following combinations: $${1,2,3,4,5,6 }$$, $${2,3,4,5,6,1 }$$, $${3,4,5,6,1,2 }$$, $${4,5,6,1,2,3 }$$, $${5,6,1,2,3,4 }$$, $${6,1,2,3,4,5 }$$

Now, I would like to generate additional combinations following my restriction, do you have any clues or advice?

## Linear algebra – Permutations, asymmetric forms and degeneration

Define a biased form of symmetry. $$( cdot, cdot)$$ in $$mathbb {R} ^ {2k}$$ by $$(e_i, e_j) = begin {cases} 1 & text {if ij }, \ 0 & text {if i = j .} end {cases}$$ Given a permutation $$pi: {1, dotsc, 2 k } a {1, dotsc, 2 k }$$, leave $$V_ pi$$ be the space covered by $$e _ { pi (2i)} – e _ { pi (2i-1)}$$ for $$1 leq i leq k$$.

For what permutations $$pi$$ is the restriction $$( cdot, cdot) | _ {V_ pi times V_ pi}$$ not degenerate?

(It is clear that the restriction will be degenerated to Some $$pi$$: for example, if there are any $$1 leq i leq k$$ such that $$pi (2i-1) = pi (2 i) -1$$ or $$pi (2i – 1) = pi (2 i) + 1$$, or also if there $$1 leq i, j leq k$$ such that $$pi (2 j) = pi (2 i) + 1$$ Y $$pi (2 j -1) = pi (2 i -1) – 1$$. Or one more time if there $$1 leq i_0, i_1, i_2 leq k$$ such that $$pi (2 i_2) = pi (2 i_1) + 1 = pi (2 i_0) + 2$$ Y $$pi (2 i_2-1) = pi (2 i_1 – 1) + 1 = pi (2 i_0 – 1) + 2$$. Perhaps there are simple criteria like these that describe the exact answer and that clarify that $$pi$$ for which $$( cdot, cdot) _ {V_ pi times V_ pi}$$ Is degenerate they are "special"?)