Module osl_permutation

module osl_permutation

    ! Uses
    use osl_core, wp => osl_wp
    use osl_special, only: osl_factorial

    ! Subroutines and functions
    public function osl_permutation_valid(pi)
    public subroutine osl_permutation_print(msg, pi)
    public subroutine osl_permutation_unrank(rank, pi)
    public function osl_permutation_rank(pi)
    public subroutine osl_permutation_next(pi, status)
    public subroutine osl_permutation_identity(pi)
    private function osl_permutation_parity(pi)
    public subroutine osl_permutation_invert(pi)
    public subroutine osl_permutation_reverse(pi)

end module osl_permutation

Description of Subroutines and Functions

osl_permutation_valid

public function osl_permutation_valid(pi)
    integer, dimension(:), intent(in) :: pi
    logical :: osl_permutation_valid
end function osl_permutation_valid

Returns .TRUE. if a permutation is valid and .FALSE. otherwise.

osl_permutation_print

public subroutine osl_permutation_print(msg, pi)
    character (len=*), intent(in) :: msg
    integer, dimension(:), intent(in) :: pi
    ! Calls: osl_permutation_identity
end subroutine osl_permutation_print

Print a permutation to the standard output.

osl_permutation_unrank

public subroutine osl_permutation_unrank(rank, pi)
    integer, intent(in) :: rank
    integer, dimension(:), intent(out) :: pi
    ! Calls: osl_error
end subroutine osl_permutation_unrank

Set PI (of length N) equal to the permutation with rank M.

osl_permutation_rank

public function osl_permutation_rank(pi)
    integer, dimension(:), intent(in) :: pi
    integer :: osl_permutation_rank
    ! Calls: osl_error, osl_permutation_invert
end function osl_permutation_rank

Return the rank ordering of a given permutation PI.

osl_permutation_next

public subroutine osl_permutation_next(pi, status)
    integer, dimension(:), intent(inout) :: pi
    integer, optional, intent(out) :: status
    ! Calls: osl_error, osl_permutation_identity, osl_swap
end subroutine osl_permutation_next

Return the next permutation in Johnson-Trotter rank order. When called with the last permutation, STATUS is set to OSL_FAIL and the identity permutation is returned in PI. This is an implementation of Algorithm 2.20 of Kreher and Simpson (1998).

osl_permutation_identity

public subroutine osl_permutation_identity(pi)
    integer, dimension(:), intent(out) :: pi
end subroutine osl_permutation_identity

Set the given permutation PI to the identity permutation.

osl_permutation_parity

private function osl_permutation_parity(pi)
    integer, dimension(:), intent(in) :: pi
    integer :: osl_permutation_parity
    ! Calls: osl_error
end function osl_permutation_parity

Return the sign of a given permutation PI. If PI is "even", the sign is +1 and if PI is "odd", the sign is -1. This is an implementation of Algorithm 2.19 of Kreher and Simpson (1998).

osl_permutation_invert

public subroutine osl_permutation_invert(pi)
    integer, dimension(:), intent(inout) :: pi
    ! Calls: osl_error
end subroutine osl_permutation_invert

Return the inverse permutation of the given permutation PI.

osl_permutation_reverse

public subroutine osl_permutation_reverse(pi)
    integer, dimension(:), intent(inout) :: pi
    ! Calls: osl_error
end subroutine osl_permutation_reverse

Reverse the elements of a permutation.