postgresql 9.6 – Pivoting a two-column table to show if a permutation exists

This gets you everything except the pivot, so you’re left with a pure dynamic pivot problem. As the other commenter says, it doesn’t look like you’ll be able to do so in a single select.

CREATE TEMP TABLE input_table (element INT, grp VARCHAR(10));

INSERT INTO input_table (element, grp)
VALUES (1, 'A'),
       (1, 'B'),
       (2, 'A'),
       (3, 'C');

;WITH grps AS (
 SELECT DISTINCT grp FROM input_table
),
elems AS (
  SELECT DISTINCT element FROM input_table
),
potentialCombos AS (
  SELECT e.element, g.grp
  FROM elems e
  CROSS JOIN grps g
)
SELECT pc.element, pc.grp, CASE WHEN i.element IS NULL THEN 0 ELSE 1 END present
FROM potentialCombos pc
LEFT JOIN input_table i ON i.element = pc.element AND i.grp = pc.grp

permutation – How to get the complete list of subsets the pairwise intersections of which are empty

Given the list Range(6). I want to get the sublists of length 2 where each element has length 2 and the pairwise intersections are empty. So I am looking for:

  {{{1, 2}, {3, 4}}, {{1, 3}, {2, 4}}, {{1, 4}, {2, 3}}}

Switched elements like {{1,2},{4,3}} should not appear. My code works well but when Range and lengths get bigger it consumes a lot of space and time. For sublists of length 3 with two elements the result
would look like:

    {{{1, 2}, {3, 4}, {5, 6}}, {{1, 2}, {3, 5}, {4, 6}}, {{1, 2}, {3, 
   6}, {4, 5}}, {{1, 3}, {2, 4}, {5, 6}}, {{1, 3}, {2, 5}, {4, 
   6}}, {{1, 3}, {2, 6}, {4, 5}}, {{1, 4}, {2, 3}, {5, 6}}, {{1, 
   4}, {2, 5}, {3, 6}}, {{1, 4}, {2, 6}, {3, 5}}, {{1, 5}, {2, 3}, {4,
    6}}, {{1, 5}, {2, 4}, {3, 6}}, {{1, 5}, {2, 6}, {3, 4}}, {{1, 
   6}, {2, 3}, {4, 5}}, {{1, 6}, {2, 4}, {3, 5}}, {{1, 6}, {2, 5}, {3,
    4}}}

Is there a function (maybe in Combinatorica) for this problem or a smarter way to do it? I am sure this is a standard problem and there must be a name for this kind of sublist. I would be grateful for further hints.

Here is my code:

k = 3;
t1 = Partition(#, {2}) & /@ Permutations(Range(2 k))
t2 = Map(Sort, t1, {2})
t3 = Map(Sort, t2, {1})
t4 = DeleteDuplicates(t3)

procedural programming – Permutation cycles

I would like to program function with procedural programming in Mathematica. My hypotethical function gets list of permutations of length n and give me back permutation cycles decomposition. My program must use another list of length n, which is fullfiled with False and during the computation, anytime you include the number in your algorithm, write True on ith place of your list.

Any ideas how to do that? I know that Mathematica has function PermutationCycles :-]

probability – permutation of n objects taken r at a time having p similar objects

What is the permutation of n objects taken r at a time having p similar objects.
Consider the example
What is the no of ways,5 red ball and 2 black ball can be arranged taken 2 at a time.

If you consider the probable combination it will be nothing but
{RB,BR,RR,BB} and nothing other else. So how can we get 4 ways by formula.
As we know P of n DISTINCT object taken r at a time is given by
n P r = n! / (n-r)!
And permutations of n objects having p similar objects and taken r object at a time is given by
n P r = n! / (n-r)! . p!

Here if we put that
It comes out = 7*6 / (5! × 2!)
But it’s a fraction = 42 / 120 × 2
=21/120 and not 4 🙄
How where am I wrong.

Closure of regular languages under permutation

You can consider the regular language $(ab)^*$. We have
$$ mathrm{Perm}((ab)^*) cap a^*b^* = { a^n b^n : n geq 0 }, $$
which isn’t regular. If you take instead $(abc)^*$ and intersect with $a^*b^*c^*$, you get the language ${ a^nb^nc^n : n geq 0 }$, which isn’t even context-free.

In contrast, the class of context-sensitive languages is closed under permutation. To see this, it suffices to observe that you can nondeterministically permute the input without any additional space (for example, by applying an arbitrary number of transpositions).

complexity theory – Iterated multiplication of permutation matrices

It’s not in $AC^0$, by reduction from parity, which is not in $AC^0$.

Let $x$ be a parity input of length $n$.
For each bit $x_i$, we build an $n times n$ matrix $A_i$, s.t. $A_i$ is the identity matrix $I$ if $x_i$ is $0$. Otherwise, it’s a matrix I’ll call $P_{12}$ which permutes first $2$ elements (i.e. it’s almost $I$, but $a_{11}=a_{22}=0$ and $a_{12}=a_{21}=1$).

The result of the multiplication of these matrices is either $I$ or $P_{12}$.
And finding the parity of $x$ is equivalent to checking whether the result is $I$ or $P_{12}$.
These matrices can be built in depth $1$.
If we can multiply the matrices in $O(1)$ depth, then we can check parity in $O(1)$ depth, which is impossible.

nt.number theory – Is there a permutation $tauin S_n$ with $tau(1)^{tau(2)}+cdots+tau(n-1)^{tau(n)}+tau(n)^{tau(1)}$ a square?

Let $n>1$ be an integer, and let $S_n$ be the symmetric group of all the permutatins of ${1,ldots,n}$.
I’m curious whether there is a permutation $tauin S_n$ such that
$$tau(1)^{tau(2)}+cdots+tau(n-1)^{tau(n)}+tau(n)^{tau(1)}$$
is a square. (Without loss of generality we may assume that $tau(n)=n$.) For $n=2,3$ there is no such a permutation $tau$. But my computations for $n=4,5,ldots,11$
lead me to formulate the following conjecture.

Conjecture. For any integer $n>3$, there is a permutation $tauin S_n$ such that
$$tau(1)^{tau(2)}+cdots+tau(n-1)^{tau(n)}+tau(n)^{tau(1)}$$
is a square.

For example,
$$2^1 + 1^3 + 3^4 + 4^2 = 10^2, 1^5 + 5^2 + 2^4 + 4^3 + 3^6 + 6^1 = 29^2,$$
and
$$1^3 + 3^2 + 2^{10} + 10^5 + 5^7 + 7^8 + 8^6 + 6^9 + 9^4 + 4^{11} + 11^1 = 4526^2.$$
For more examples and related data, one may consult http://oeis.org/A342965.

QUESTION. Is the above conjecture true?

Your are welcome to check the conjecture further.

gr.group theory – Is every permutation group on $n$ letters the symmetry group of a set of $n$ points in some euclidean space?

No. If $G$ is $2$-transitive $-$ or even transitive on pairs $-$ then
$X$ must be the set of vertices of a regular simplex,
which has isometry group $S_n$. But there are plenty of
examples of $2$-transitive groups $G$ properly contained in $S_n$
(such as the $ax+b$ group if $n$ is a prime power and $n>3$).