Python | SymPy Permutation.get_precedence_distance() method

Permutation.get_precedence_distance() : get_precedence_distance() is a sympy Python library function that calculates the precedence distance between two permutations.
p and q represent n jobs. The precedence metric counts the no. of times a job n is preceded by job m in both p and q. This is a commutative matrix.
Syntax :
sympy.combinatorics.permutations.Permutation.get_precedence_distance()Return :
precedence distance between two permutations
Code #1 : get_precedence_distance() Example
# Python code explaining # SymPy.Permutation.get_precedence_distance() # importing SymPy libraries from sympy.combinatorics.partitions import Partition from sympy.combinatorics.permutations import Permutation # Using from # sympy.combinatorics.permutations.Permutation.get_precedence_distance() method # creating Permutation a = Permutation([2, 0, 3, 1, 5, 4]) b = Permutation([3, 1, 2, 5, 4, 0]) c = Permutation([0, 1, 3, 4, 5, 2]) print ("a - get_precedence_distance form b: ", a.get_precedence_distance(b)) print ("b - get_precedence_distance form c: ", b.get_precedence_distance(c)) |
Output :
a – get_precedence_distance form b: 6
b – get_precedence_distance form c: 9
Code #2 : get_precedence_distance() Example – 2D Permutation
# Python code explaining # SymPy.Permutation.get_precedence_distance() # importing SymPy libraries from sympy.combinatorics.partitions import Partition from sympy.combinatorics.permutations import Permutation # Using from # sympy.combinatorics.permutations.Permutation.get_precedence_distance() method # creating Permutation a = Permutation([[2, 4, 0], [7, 1, 3], [8, 5, 6]]) b = Permutation([[8, 4, 0], [2, 7, 0], [1, 6, 7]]) print ("a get_precedence_distance form b : ", a.get_precedence_distance(b)) |
Output :
a get_precedence_distance form b : 22


