Ticket #6621: new-inverse.patch

File new-inverse.patch, 785 bytes (added by aclaesson, 14 years ago)
  • sage/combinat/permutation.py

    # HG changeset patch
    # User Anders Claesson <anders@ru.is>
    # Date 1248543177 0
    # Node ID 7ee14d081bde6b08274996ed9251c8746fde4462
    # Parent  78ea5b9e2f85b9befff57c38d28fb2266f8250e9
    Improve running time of inverse method
    
    diff -r 78ea5b9e2f85 -r 7ee14d081bde sage/combinat/permutation.py
    a b  
    890890            sage: Permutation([2, 4, 1, 5, 3]).inverse()
    891891            [3, 1, 5, 2, 4]
    892892        """
    893         return Permutation([self.index(i+1)+1 for i in range(len(self))])
     893        w = range(len(self))
     894        for i,j in enumerate(self):
     895            w[j-1] = i+1
     896        return Permutation(w)
    894897
    895898    def _icondition(self, i):
    896899        """