Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use pure Python and avoids (see documentation) for a direct implementation:

sage: P = Permutations(5)
sage: pi_1 = [1, 2, 3, 4, 5]
sage: pi_2 = [4, 1, 2, 3, 5]
sage: all(P(x).avoids(pi_1) and P(x).avoids(pi_2) for x in U)
True/False

As of version 9.4, Sage will support sets with given predicates (see Release Tour), which allows you to define the set $\mathrm{Av}(π_1,π_2)$ directly:

sage: P = Permutations(5)
sage: pi_1 = [1, 2, 3, 4, 5]
sage: pi_2 = [4, 1, 2, 3, 5]
sage: Av = ConditionSet(P, lambda x: x.avoids(pi_1) and x.avoids(pi_2))
sage: all(P(x) in Av for x in U)
True/False

Mathematically, the latter version is a bit nicer, but there is basically no difference.