Did I find the right examples for you? yes no

sympy.combinatorics.permutations._af_parity

All Samples(6)  |  Call(4)  |  Derive(0)  |  Import(2)
```Computes the parity of a permutation in array form.

The parity of a permutation reflects the parity of the
number of inversions in the permutation, i.e., the
number of pairs of x and y such that x > y but p[x] < p[y].

Examples
========

>>> from sympy.combinatorics.permutations import _af_parity(more...)
```

```        def _af_parity(pi):
"""
Computes the parity of a permutation in array form.

The parity of a permutation reflects the parity of the
number of inversions in the permutation, i.e., the
number of pairs of x and y such that x > y but p[x] < p[y].

Examples
========

>>> from sympy.combinatorics.permutations import _af_parity
>>> _af_parity([0,1,2,3])
0
>>> _af_parity([3,2,0,1])
1

========

Permutation
"""
n = len(pi)
a = [0] * n
c = 0
for j in range(n):
if a[j] == 0:
c += 1
a[j] = 1
i = j
while pi[i] != j:
i = pi[i]
a[i] = 1
return (n - c) % 2
```

```from itertools import permutations

from sympy.combinatorics.permutations import (Permutation, _af_parity,
_af_rmul, _af_rmuln, Cycle)
from sympy.utilities.pytest import raises
```
```    assert s.is_even
assert Permutation([0, 1, 4, 3, 2]).parity() == 1
assert _af_parity([0, 4, 1, 3, 2]) == 0
assert _af_parity([0, 1, 4, 3, 2]) == 1

```

```from itertools import permutations

from sympy.combinatorics.permutations import (Permutation, _af_parity,
_af_rmul, _af_rmuln, Cycle)
from sympy.utilities.pytest import raises
```
```    assert s.is_even
assert Permutation([0, 1, 4, 3, 2]).parity() == 1
assert _af_parity([0, 4, 1, 3, 2]) == 0
assert _af_parity([0, 1, 4, 3, 2]) == 1

```