Thursday, October 9, 2025
HomeLanguagesPython | SymPy Permutation.get_precedence_distance() method

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

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11875 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS