Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fortran Help, Please. Waiting online. 1

Status
Not open for further replies.

kevek

Programmer
May 1, 2009
5
The "multiplication (*)" in the group is simply performing them after one another.
Take 6 coloured balls. Permute the first and third one. Now permute the third and fifth one (note: by third one I mean the one in the third position, not the third ball which is not in the first position).
You have just composed the permutations (13) and (35). In effect, you have moved the first one to the fifth, the fifth one to the third and the third one to the first, so in cycle notation:
(35) * (13) = (153).
(where the composition o is to be read as: "after").

Then as in any group, a power is simply composing the permutation with itself, e.g.
(13)**2 = (13) * (13) = 1
(153)**2 = (153)(153) = (135)
and working out the order is simply composing until you get the identity, e.g.
(153)**3 = (135)(153) = 1

To print out either do multiplication and take power, they all equal to identity number.

What I can do now is.

first ball
integer x(6)
integer i;
do i = 1,6,1
x(i) =i
end do

finish permutation, if x(i) is 1,2,3,4,5,6 then identity=1
integer flag
flag = 1 ?first ball
do i = 1,6,1
if ( x(i) .NE. i ) then
flag = 0
end if
end do

if flag .EQ. 1 identity=1

But I don't know how to create Do Loops, IF block, and Subroutine to To print out either do multiplication and take power, they all equal to identity number.

Can any one help me please.
 
kevek,

Here is what I have tried, maybe it helps you to start your project
permutations.f90
Code:
[COLOR=#a020f0]module[/color] my_permutations
  [COLOR=#2e8b57][b]type[/b][/color] permutation
    [COLOR=#2e8b57][b]integer[/b][/color] :: element
  [COLOR=#2e8b57][b]end type[/b][/color] permutation

  [COLOR=#a020f0]interface[/color] [COLOR=#a020f0]assignment[/color]([COLOR=#804040][b]=[/b][/color])
    [COLOR=#a020f0]module[/color] [COLOR=#a020f0]procedure[/color] permutation_from_array
  [COLOR=#a020f0]end interface[/color]

  [COLOR=#a020f0]interface[/color] [COLOR=#a020f0]operator[/color]([COLOR=#804040][b]*[/b][/color])
    [COLOR=#a020f0]module[/color] [COLOR=#a020f0]procedure[/color] multiply_permutations
  [COLOR=#a020f0]end interface[/color]  

[COLOR=#a020f0]contains[/color]
  [COLOR=#a020f0]subroutine[/color] permutation_from_array(p, v)
    [COLOR=#0000ff]! construct permutation from an integer array[/color]
    [COLOR=#0000ff]! p = v[/color]
    [COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: v
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color]([COLOR=#008080]size[/color](v)), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]out[/b][/color]) :: p
    p(:)%element [COLOR=#804040][b]=[/b][/color] v(:)
  [COLOR=#a020f0]end subroutine[/color] permutation_from_array

  [COLOR=#a020f0]subroutine[/color] print_permutation(p)
    [COLOR=#0000ff]! Print the permutation[/color]
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color], [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: p
    [COLOR=#2e8b57][b]integer[/b][/color] :: j, n
    n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](p)
    [COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
      [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) j,[COLOR=#ff00ff]' -> '[/color],p(j)%element
    [COLOR=#804040][b]enddo[/b][/color]
  [COLOR=#a020f0]end subroutine[/color] print_permutation

  [COLOR=#a020f0]subroutine[/color] print_permutation_cycles(p)
    [COLOR=#0000ff]! Print the permutation cycles[/color]
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color], [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: p
    [COLOR=#2e8b57][b]integer[/b][/color] :: i, j, n, nr_cycles
[COLOR=#2e8b57][b]    logical[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color]([COLOR=#008080]size[/color](p)) :: is_in_cycle [COLOR=#0000ff]! flags if element in cycle[/color]
    n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](p)
    [COLOR=#0000ff]! initialize flag array at .false.[/color]
    [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
      is_in_cycle(i) [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].false.[/color]
    [COLOR=#804040][b]end do[/b][/color]
    nr_cycles [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]0[/color]
    [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
      [COLOR=#0000ff]! if i not in other cycle[/color]
      [COLOR=#804040][b]if[/b][/color] ([COLOR=#804040][b].not.[/b][/color](is_in_cycle(i))) [COLOR=#804040][b]then[/b][/color]
        [COLOR=#804040][b]if[/b][/color] (i [COLOR=#804040][b].ne.[/b][/color] p(i)%element) [COLOR=#804040][b]then[/b][/color]
          is_in_cycle(i) [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].true.[/color]
          [COLOR=#0000ff]! i is now the new cycle begin[/color]
          nr_cycles [COLOR=#804040][b]=[/b][/color] nr_cycles [COLOR=#804040][b]+[/b][/color] [COLOR=#ff00ff]1[/color]
          [COLOR=#0000ff]!write (*,*) 'Cycle ', nr_cycles,':'[/color]
          [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a2)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]'('[/color]
          [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(i2)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) i
            j[COLOR=#804040][b]=[/b][/color]p(i)%element
          [COLOR=#804040][b]do[/b][/color] 
            [COLOR=#804040][b]if[/b][/color] (j[COLOR=#804040][b].ne.[/b][/color]i) [COLOR=#804040][b]then[/b][/color]
              is_in_cycle(j) [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].true.[/color]
              [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(i2)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) j
            [COLOR=#804040][b]else[/b][/color]
              [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]')'[/color]
              [COLOR=#804040][b]exit[/b][/color] [COLOR=#0000ff]! end loop[/color]
            [COLOR=#804040][b]end if[/b][/color]
            j[COLOR=#804040][b]=[/b][/color]p(j)%element [COLOR=#0000ff]! next cycle element[/color]
          [COLOR=#804040][b]end do[/b][/color]
        [COLOR=#804040][b]end if[/b][/color]
      [COLOR=#804040][b]end if[/b][/color]
    [COLOR=#804040][b]enddo[/b][/color]
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#0000ff]! next line[/color]
  [COLOR=#a020f0]end subroutine[/color] print_permutation_cycles

  [COLOR=#a020f0]function[/color] multiply_permutations(p, q) [COLOR=#a020f0]result[/color](r)
    [COLOR=#0000ff]! Multiply permutations: r = p * q[/color]
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: p, q
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color] :: r
    [COLOR=#2e8b57][b]integer[/b][/color] :: j, n
    [COLOR=#804040][b]if[/b][/color] ([COLOR=#008080]size[/color](p) [COLOR=#804040][b].eq.[/b][/color] [COLOR=#008080]size[/color](q)) [COLOR=#804040][b]then[/b][/color]
      n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](p)
      [COLOR=#804040][b]allocate[/b][/color](r(n))
      [COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
        r(j) [COLOR=#804040][b]=[/b][/color] q(p(j)%element)
      [COLOR=#804040][b]end do[/b][/color]
    [COLOR=#804040][b]else[/b][/color]
      [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Error - the permutations are not compatible !!!'[/color]
    [COLOR=#804040][b]end if[/b][/color]
  [COLOR=#a020f0]end function[/color] multiply_permutations
[COLOR=#a020f0]end module[/color] my_permutations

[COLOR=#a020f0]program[/color] permutations
  [COLOR=#a020f0]use[/color] my_permutations

  [COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]parameter[/b][/color] :: n [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]6[/color]  [COLOR=#0000ff]! size of permutations[/color]
  [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color] :: p, q, r, s
  [COLOR=#2e8b57][b]integer[/b][/color] :: j

  [COLOR=#0000ff]! construct permutation p[/color]
  [COLOR=#804040][b]allocate[/b][/color](p(n))
  [COLOR=#0000ff]!p(:)%element=(/1, 2, 5, 4, 3, 6/)[/color]
  [COLOR=#0000ff]! assigning values using overloaded assignment (=)[/color]
  p[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]5[/color], [COLOR=#ff00ff]4[/color], [COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]6[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation P ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(p) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation P factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(p)   
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  [COLOR=#0000ff]! construct permutation q[/color]
  [COLOR=#804040][b]allocate[/b][/color](q(n))
  [COLOR=#0000ff]!q(:)%element=(/3, 2, 1, 4, 5, 6/)[/color]
  [COLOR=#0000ff]! assigning values using overloaded assignment (=)[/color]
  q[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]4[/color], [COLOR=#ff00ff]5[/color], [COLOR=#ff00ff]6[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation Q ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(q)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation Q factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(q)   
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  [COLOR=#804040][b]allocate[/b][/color](r(n))  
  [COLOR=#0000ff]!r=multiply_permutations(p,q)[/color]
  [COLOR=#0000ff]! compute permutation R = P * Q using overloaded operator (*)[/color]
  r [COLOR=#804040][b]=[/b][/color] p [COLOR=#804040][b]*[/b][/color] q
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R = P * Q'[/color]
  [COLOR=#a020f0]call[/color] print_permutation(r)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(r)  
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  [COLOR=#0000ff]! Proof the factorization into cycles[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'-------------------------------------------------------'[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Proof the factorization procedure:'[/color]
  [COLOR=#804040][b]allocate[/b][/color](s(n))
  s[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]4[/color], [COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]6[/color], [COLOR=#ff00ff]5[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(s)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(s) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  s[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]5[/color], [COLOR=#ff00ff]6[/color], [COLOR=#ff00ff]4[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(s)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(s) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  s[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]6[/color], [COLOR=#ff00ff]5[/color], [COLOR=#ff00ff]4[/color], [COLOR=#ff00ff]1[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(s)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(s) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])
[COLOR=#a020f0]end program[/color] permutations
Output:
Code:
$ g95 permutations.f90 -o permutations

$ permutations
 Permutation P =
 1  ->  1
 2  ->  2
 3  ->  5
 4  ->  4
 5  ->  3
 6  ->  6
 Permutation P factorized into cycles =
 ( 3 5)

 Permutation Q =
 1  ->  3
 2  ->  2
 3  ->  1
 4  ->  4
 5  ->  5
 6  ->  6
 Permutation Q factorized into cycles =
 ( 1 3)

 Permutation R = P * Q
 1  ->  3
 2  ->  2
 3  ->  5
 4  ->  4
 5  ->  1
 6  ->  6
 Permutation R factorized into cycles =
 ( 1 3 5)

 -------------------------------------------------------
 Proof the factorization procedure:
 Permutation S =
 1  ->  2
 2  ->  1
 3  ->  4
 4  ->  3
 5  ->  6
 6  ->  5
 Permutation S factorized into cycles =
 ( 1 2) ( 3 4) ( 5 6)

 Permutation S =
 1  ->  2
 2  ->  3
 3  ->  1
 4  ->  5
 5  ->  6
 6  ->  4
 Permutation S factorized into cycles =
 ( 1 2 3) ( 4 5 6)

 Permutation S =
 1  ->  2
 2  ->  3
 3  ->  6
 4  ->  5
 5  ->  4
 6  ->  1
 Permutation S factorized into cycles =
 ( 1 2 3 6) ( 4 5)

1. I use integer arrays to represent the permutations. E.g. if we have this permutation as an 2 rows matrix
Code:
1 2 3 4 5 6
2 1 4 3 6 5
it can be represented simply as an array using only the second row
Code:
2 1 4 3 6 5

2. In the module I defined the new type named permutation as an integer.
I could use native integer datatype too, however then I couldn't do overloading of the intrinsic multiplication operator.

3. So you see I overloaded the assignment (=) and the multipplication operator (*)

4. From the factorization in cycles I have only done a procedure which prints the cycles. I done it with do-loops so it seems horrible ! /I don't know if the new fortran standard will support while-loop/
But for cycle-arithmetic, you need to do a function which returns the cycles from the permutation. You don't know how many cycles it could be. So you should consider for a data structure you will take for representing the cycles. I would suggest a linked list of arrays, but I don't know if it's possible., because as I'm only a recreational fortranner I have not done a linked list til now in fortran.
The other eventuality would be to use an N*N matrix (for permutation of N elements) and represent the cycles as row of the matrix (only the no-zero elements).
But you should consider, what you want to use.

5. So I would suggest you to do following things:
a) Do a function which factorize a permutation into cycles.
b) Do a function which creates from the cycles a permutation
c) Create a function for n-th power (**). You can use for it the function multiply_permutations(p,q) from the above program:
For 2-nd power you only need to apply it once
p**2 = multiply_permutations(p, p)
For 3-rd power twice
p**3 = p * (p**2)
and so on
...

Ok, that was my suggestions, but the decision is yours, because it's your project not mine
:)
 
Thank you very much. mikrom. your fortran level is ultimate.

This was my simple idea.


Subroutine trans(temp, size)
implicit none
integer :: size
integer :: temp(size)
integer :: m, t, i !temp
t = temp(1)
do i=1,size-1
m = temp(i+1)
temp(i+1) = t
t = m
END do
temp(1) = t
END Subroutine trans

Program main
implicit none
integer :: P(6) = (/ 1, 2, 3, 4, 5, 6 /)
integer :: temp(3)
integer :: i
! (153)
write(*, *) 'original numbers is = '
write(*, *) P(1), P(5), P(3)
temp(1) = P(1)
temp(2) = P(5)
temp(3) = P(3)
do i=1, 3
call trans(temp, 3)
write(*, *) "trans ", i, "time(s) is"
write(*, *) temp
END do
write(*, *) 'final numbers is ='
write(*, *) temp
if (temp(1) == P(1) .AND. temp(2) == P(5).AND. temp(3) == P(3)) then
write(*, *) 'they are same again'
END if
stop
END


However, after i read your idea. I don't know what can i say. I would like to be you to help people like me after I finish my crouse.

Anyway, I really have no idea how to use reload to do powers of group. can you just show me how can I overload **2 of group. then I will try the following.

Thank you very much again.

Kevek
 
Hi kevek,

Thanks for praising me, but I wonder, why you didn't give me a star, if my post was helpful for you?

If you want to overload an intrinsic operator you need first to write a function which does the work and then you have to use the interface operator clause in your module.
See the code I posted, how I overloaded the intrinsic multiplication operator *.
But as I wrote you need to define your own datatype - therefore I defined the datatype permutation.
Now in my code, when I use the operator * on datatypes integer, then the intrinsic integer multiplication will be executed.
But when I apply the operator * on datatypes permutation then the permutation composition (multiplication) will be executed, i.e. the program calls the function multiply_permutations(), which have 2 arguments of datatype permutation and returns a result of a datatype permutation.
Here are some sources about overloading the operators in Fortran I found:

But I wonder, what is your university course about? It's about general programming, or about Fortran, or about algebra?

So as I wrote the function multiply_permutations(), you should first write the function power_permuttion(). When the function works, then you can overload the intrinsic operator **.
If you then have some problems with it, then post them here.
 
Thank for again. I am new here. I didn't know about 'star' thing. However, I gave you after your mention.
I will try the powers of permutation.
This is a part of my computional method course, and the lecturer only teach us Fortran and some other algorithem.
Anyway,do you have any idea that how other algebraic structures could be represented and calculated.
Thank you again. mikrom.
 
kevek said:
Anyway,do you have any idea that how other algebraic structures could be represented and calculated
What do you mean under algebraic structures? Group,etc,..?
IMHO Forran is not well suited for symbolic computation. It's strength was numerical computation only.
 
Hi kevek,

I imlemented the function permutation_power_n() which computes the n-th power. I used in it the function multiply_permutations() which I posted before.
Then I overloaded the operator ** for the datatype permutation with the function.

Here is the improved program
permutations.f90
Code:
[COLOR=#a020f0]module[/color] my_permutations
  [COLOR=#2e8b57][b]type[/b][/color] permutation
    [COLOR=#2e8b57][b]integer[/b][/color] :: element
  [COLOR=#2e8b57][b]end type[/b][/color] permutation

  [COLOR=#a020f0]interface[/color] [COLOR=#a020f0]assignment[/color]([COLOR=#804040][b]=[/b][/color])
    [COLOR=#a020f0]module[/color] [COLOR=#a020f0]procedure[/color] permutation_from_array
  [COLOR=#a020f0]end interface[/color]

  [COLOR=#a020f0]interface[/color] [COLOR=#a020f0]operator[/color]([COLOR=#804040][b]*[/b][/color])
    [COLOR=#a020f0]module[/color] [COLOR=#a020f0]procedure[/color] multiply_permutations
  [COLOR=#a020f0]end interface[/color]  

  [COLOR=#a020f0]interface[/color] [COLOR=#a020f0]operator[/color]([COLOR=#804040][b]**[/b][/color])
    [COLOR=#a020f0]module[/color] [COLOR=#a020f0]procedure[/color] permutation_power_n
  [COLOR=#a020f0]end interface[/color]

[COLOR=#a020f0]contains[/color]
  [COLOR=#a020f0]subroutine[/color] permutation_from_array(p, v)
    [COLOR=#0000ff]! construct permutation from an integer array[/color]
    [COLOR=#0000ff]! p = v[/color]
    [COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: v
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color]([COLOR=#008080]size[/color](v)), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]out[/b][/color]) :: p
    p(:)%element [COLOR=#804040][b]=[/b][/color] v(:)
  [COLOR=#a020f0]end subroutine[/color] permutation_from_array

  [COLOR=#a020f0]subroutine[/color] print_permutation(p)
    [COLOR=#0000ff]! Print the permutation[/color]
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color], [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: p
    [COLOR=#2e8b57][b]integer[/b][/color] :: j, n
    n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](p)
    [COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
      [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) j,[COLOR=#ff00ff]' -> '[/color],p(j)%element
    [COLOR=#804040][b]enddo[/b][/color]
  [COLOR=#a020f0]end subroutine[/color] print_permutation

  [COLOR=#a020f0]subroutine[/color] print_permutation_cycles(p)
    [COLOR=#0000ff]! Print the permutation cycles[/color]
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color], [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: p
    [COLOR=#2e8b57][b]integer[/b][/color] :: i, j, n, nr_cycles
[COLOR=#2e8b57][b]    logical[/b][/color], [COLOR=#2e8b57][b]dimension[/b][/color]([COLOR=#008080]size[/color](p)) :: is_in_cycle [COLOR=#0000ff]! flags if element in cycle[/color]
    n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](p)
    [COLOR=#0000ff]! initialize flag array at .false.[/color]
    [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
      is_in_cycle(i) [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].false.[/color]
    [COLOR=#804040][b]end do[/b][/color]
    nr_cycles [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]0[/color]
    [COLOR=#804040][b]do[/b][/color] i[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
      [COLOR=#0000ff]! if i not in other cycle[/color]
      [COLOR=#804040][b]if[/b][/color] ([COLOR=#804040][b].not.[/b][/color](is_in_cycle(i))) [COLOR=#804040][b]then[/b][/color]
        [COLOR=#804040][b]if[/b][/color] (i [COLOR=#804040][b].ne.[/b][/color] p(i)%element) [COLOR=#804040][b]then[/b][/color]
          is_in_cycle(i) [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].true.[/color]
          [COLOR=#0000ff]! i is now the new cycle begin[/color]
          nr_cycles [COLOR=#804040][b]=[/b][/color] nr_cycles [COLOR=#804040][b]+[/b][/color] [COLOR=#ff00ff]1[/color]
          [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a2)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]'('[/color]
          [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(i2)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) i
            j[COLOR=#804040][b]=[/b][/color]p(i)%element
          [COLOR=#804040][b]do[/b][/color] 
            [COLOR=#804040][b]if[/b][/color] (j[COLOR=#804040][b].ne.[/b][/color]i) [COLOR=#804040][b]then[/b][/color]
              is_in_cycle(j) [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff].true.[/color]
              [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(i2)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) j
            [COLOR=#804040][b]else[/b][/color]
              [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#ff00ff]'(a)'[/color],[COLOR=#804040][b]advance[/b][/color][COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]'no'[/color]) [COLOR=#ff00ff]')'[/color]
              [COLOR=#804040][b]exit[/b][/color] [COLOR=#0000ff]! end loop[/color]
            [COLOR=#804040][b]end if[/b][/color]
            j[COLOR=#804040][b]=[/b][/color]p(j)%element [COLOR=#0000ff]! next cycle element[/color]
          [COLOR=#804040][b]end do[/b][/color]
        [COLOR=#804040][b]end if[/b][/color]
      [COLOR=#804040][b]end if[/b][/color]
    [COLOR=#804040][b]enddo[/b][/color]
    [COLOR=#804040][b]if[/b][/color] (nr_cycles [COLOR=#804040][b].eq.[/b][/color] [COLOR=#ff00ff]0[/color]) [COLOR=#804040][b]then[/b][/color]
      [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'No cycles found.'[/color]
    [COLOR=#804040][b]else[/b][/color]
      [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#0000ff]! next line[/color]
    [COLOR=#804040][b]end if[/b][/color]
  [COLOR=#a020f0]end subroutine[/color] print_permutation_cycles

  [COLOR=#a020f0]function[/color] multiply_permutations(p, q) [COLOR=#a020f0]result[/color](r)
    [COLOR=#0000ff]! Multiply permutations: r = p * q[/color]
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: p, q
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color] :: r
    [COLOR=#2e8b57][b]integer[/b][/color] :: j, n
    [COLOR=#804040][b]if[/b][/color] ([COLOR=#008080]size[/color](p) [COLOR=#804040][b].eq.[/b][/color] [COLOR=#008080]size[/color](q)) [COLOR=#804040][b]then[/b][/color]
      n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](p)
      [COLOR=#804040][b]allocate[/b][/color](r(n))
      [COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n
        r(j) [COLOR=#804040][b]=[/b][/color] q(p(j)%element)
      [COLOR=#804040][b]end do[/b][/color]
    [COLOR=#804040][b]else[/b][/color]
      [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Error - the permutations are not compatible !!!'[/color]
      [COLOR=#804040][b]stop[/b][/color] [COLOR=#0000ff]! abort processing[/color]
    [COLOR=#804040][b]end if[/b][/color]
  [COLOR=#a020f0]end function[/color] multiply_permutations

  [COLOR=#a020f0]function[/color] permutation_power_2(p) [COLOR=#a020f0]result[/color](r)
    [COLOR=#0000ff]! 2nd-power of permutation: r = p**2[/color]
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: p
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color] :: r
    [COLOR=#2e8b57][b]integer[/b][/color] :: n
    n [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]size[/color](p)
    [COLOR=#804040][b]allocate[/b][/color](r(n))
    r [COLOR=#804040][b]=[/b][/color] multiply_permutations(p, p)
  [COLOR=#a020f0]end function[/color] permutation_power_2

  [COLOR=#a020f0]function[/color] permutation_power_n(p, n) [COLOR=#a020f0]result[/color](r)
    [COLOR=#0000ff]! nth-power of permutation: r = p**n[/color]
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: p
    [COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]intent[/b][/color]([COLOR=#2e8b57][b]in[/b][/color]) :: n
    [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color] :: r
    [COLOR=#2e8b57][b]integer[/b][/color] :: j
    [COLOR=#804040][b]allocate[/b][/color](r([COLOR=#008080]size[/color](p)))
    r [COLOR=#804040][b]=[/b][/color] p
    [COLOR=#804040][b]if[/b][/color] (n [COLOR=#804040][b].gt.[/b][/color] [COLOR=#ff00ff]0[/color]) [COLOR=#804040][b]then[/b][/color]
      [COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], n[COLOR=#804040][b]-[/b][/color][COLOR=#ff00ff]1[/color]
        r [COLOR=#804040][b]=[/b][/color] multiply_permutations(r, p)
      [COLOR=#804040][b]end do[/b][/color]
    [COLOR=#804040][b]else[/b][/color]
      [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Error - n ='[/color], n,[COLOR=#ff00ff]' not allowed !!!'[/color]
      [COLOR=#804040][b]stop[/b][/color] [COLOR=#0000ff]! abort processing[/color]
    [COLOR=#804040][b]end if[/b][/color]
  [COLOR=#a020f0]end function[/color] permutation_power_n

[COLOR=#a020f0]end module[/color] my_permutations

[COLOR=#a020f0]program[/color] permutations
  [COLOR=#a020f0]use[/color] my_permutations

  [COLOR=#2e8b57][b]integer[/b][/color], [COLOR=#2e8b57][b]parameter[/b][/color] :: n [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]6[/color]  [COLOR=#0000ff]! size of permutations[/color]
  [COLOR=#2e8b57][b]type[/b][/color](permutation), [COLOR=#2e8b57][b]dimension[/b][/color](:), [COLOR=#2e8b57][b]allocatable[/b][/color] :: p, q, r, s
  [COLOR=#2e8b57][b]integer[/b][/color] :: j

  [COLOR=#0000ff]! construct permutation p[/color]
  [COLOR=#804040][b]allocate[/b][/color](p(n))
  [COLOR=#0000ff]!p(:)%element=(/1, 2, 5, 4, 3, 6/)[/color]
  [COLOR=#0000ff]! assigning values using overloaded assignment (=)[/color]
  p[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]5[/color], [COLOR=#ff00ff]4[/color], [COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]6[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation P ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(p) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation P factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(p)   
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  [COLOR=#0000ff]! construct permutation q[/color]
  [COLOR=#804040][b]allocate[/b][/color](q(n))
  [COLOR=#0000ff]!q(:)%element=(/3, 2, 1, 4, 5, 6/)[/color]
  [COLOR=#0000ff]! assigning values using overloaded assignment (=)[/color]
  q[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]4[/color], [COLOR=#ff00ff]5[/color], [COLOR=#ff00ff]6[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation Q ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(q)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation Q factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(q)   
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  [COLOR=#804040][b]allocate[/b][/color](r(n))  
  [COLOR=#0000ff]!r=multiply_permutations(p,q)[/color]
  [COLOR=#0000ff]! compute permutation R = P * Q using overloaded operator (*)[/color]
  r [COLOR=#804040][b]=[/b][/color] p [COLOR=#804040][b]*[/b][/color] q
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R = P * Q'[/color]
  [COLOR=#a020f0]call[/color] print_permutation(r)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(r)  
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  [COLOR=#0000ff]! Proof the factorization into cycles[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'-------------------------------------------------------'[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Proof the factorization procedure:'[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'-------------------------------------------------------'[/color]  
  [COLOR=#804040][b]allocate[/b][/color](s(n))
  s[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]4[/color], [COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]6[/color], [COLOR=#ff00ff]5[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(s)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(s) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  s[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]5[/color], [COLOR=#ff00ff]6[/color], [COLOR=#ff00ff]4[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(s)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(s) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  s[COLOR=#804040][b]=[/b][/color]([COLOR=#804040][b]/[/b][/color][COLOR=#ff00ff]2[/color], [COLOR=#ff00ff]3[/color], [COLOR=#ff00ff]6[/color], [COLOR=#ff00ff]5[/color], [COLOR=#ff00ff]4[/color], [COLOR=#ff00ff]1[/color][COLOR=#804040][b]/[/b][/color])
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S ='[/color]
  [COLOR=#a020f0]call[/color] print_permutation(s)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation S factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(s) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'-------------------------------------------------------'[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Proof the 2-th power procedure:'[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'-------------------------------------------------------'[/color]
  r [COLOR=#804040][b]=[/b][/color] permutation_power_2(p)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R = P**2'[/color]
  [COLOR=#a020f0]call[/color] print_permutation(r)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(r) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  r [COLOR=#804040][b]=[/b][/color] permutation_power_2(s)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R = S**2'[/color]
  [COLOR=#a020f0]call[/color] print_permutation(r)
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R factorized into cycles ='[/color]  
  [COLOR=#a020f0]call[/color] print_permutation_cycles(r) 
  [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])

  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'-------------------------------------------------------'[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Proof the n-th power procedure:'[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'-------------------------------------------------------'[/color]
  [COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]5[/color]
    r [COLOR=#804040][b]=[/b][/color] permutation_power_n(s, j)
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R = S **'[/color],j
    [COLOR=#a020f0]call[/color] print_permutation(r)
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R factorized into cycles ='[/color]  
    [COLOR=#a020f0]call[/color] print_permutation_cycles(r) 
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])
  [COLOR=#804040][b]end do[/b][/color] 

  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'-------------------------------------------------------'[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Proof the n-th power with overloaded operator **:'[/color]
  [COLOR=#804040][b]write[/b][/color]([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'-------------------------------------------------------'[/color]
  [COLOR=#804040][b]do[/b][/color] j[COLOR=#804040][b]=[/b][/color][COLOR=#ff00ff]1[/color], [COLOR=#ff00ff]5[/color]
    [COLOR=#0000ff]! compute permutation R = S ** j using overloaded operator (**)[/color]
    r [COLOR=#804040][b]=[/b][/color] s [COLOR=#804040][b]**[/b][/color] j
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R = S **'[/color],j
    [COLOR=#a020f0]call[/color] print_permutation(r)
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color]) [COLOR=#ff00ff]'Permutation R factorized into cycles ='[/color]  
    [COLOR=#a020f0]call[/color] print_permutation_cycles(r) 
    [COLOR=#804040][b]write[/b][/color] ([COLOR=#804040][b]*[/b][/color],[COLOR=#804040][b]*[/b][/color])
  [COLOR=#804040][b]end do[/b][/color]    
[COLOR=#a020f0]end program[/color] permutations
Output:
Code:
$ g95 permutations.f90 -o permutations

$ permutations
 Permutation P =
 1  ->  1
 2  ->  2
 3  ->  5
 4  ->  4
 5  ->  3
 6  ->  6
 Permutation P factorized into cycles =
 ( 3 5)

 Permutation Q =
 1  ->  3
 2  ->  2
 3  ->  1
 4  ->  4
 5  ->  5
 6  ->  6
 Permutation Q factorized into cycles =
 ( 1 3)

 Permutation R = P * Q
 1  ->  3
 2  ->  2
 3  ->  5
 4  ->  4
 5  ->  1
 6  ->  6
 Permutation R factorized into cycles =
 ( 1 3 5)

 -------------------------------------------------------
 Proof the factorization procedure:
 -------------------------------------------------------
 Permutation S =
 1  ->  2
 2  ->  1
 3  ->  4
 4  ->  3
 5  ->  6
 6  ->  5
 Permutation S factorized into cycles =
 ( 1 2) ( 3 4) ( 5 6)

 Permutation S =
 1  ->  2
 2  ->  3
 3  ->  1
 4  ->  5
 5  ->  6
 6  ->  4
 Permutation S factorized into cycles =
 ( 1 2 3) ( 4 5 6)

 Permutation S =
 1  ->  2
 2  ->  3
 3  ->  6
 4  ->  5
 5  ->  4
 6  ->  1
 Permutation S factorized into cycles =
 ( 1 2 3 6) ( 4 5)

 -------------------------------------------------------
 Proof the 2-th power procedure:
 -------------------------------------------------------
 Permutation R = P**2
 1  ->  1
 2  ->  2
 3  ->  3
 4  ->  4
 5  ->  5
 6  ->  6
 Permutation R factorized into cycles =
 No cycles found.

 Permutation R = S**2
 1  ->  3
 2  ->  6
 3  ->  1
 4  ->  4
 5  ->  5
 6  ->  2
 Permutation R factorized into cycles =
 ( 1 3) ( 2 6)

 -------------------------------------------------------
 Proof the n-th power procedure:
 -------------------------------------------------------
 Permutation R = S ** 1
 1  ->  2
 2  ->  3
 3  ->  6
 4  ->  5
 5  ->  4
 6  ->  1
 Permutation R factorized into cycles =
 ( 1 2 3 6) ( 4 5)

 Permutation R = S ** 2
 1  ->  3
 2  ->  6
 3  ->  1
 4  ->  4
 5  ->  5
 6  ->  2
 Permutation R factorized into cycles =
 ( 1 3) ( 2 6)

 Permutation R = S ** 3
 1  ->  6
 2  ->  1
 3  ->  2
 4  ->  5
 5  ->  4
 6  ->  3
 Permutation R factorized into cycles =
 ( 1 6 3 2) ( 4 5)

 Permutation R = S ** 4
 1  ->  1
 2  ->  2
 3  ->  3
 4  ->  4
 5  ->  5
 6  ->  6
 Permutation R factorized into cycles =
 No cycles found.

 Permutation R = S ** 5
 1  ->  2
 2  ->  3
 3  ->  6
 4  ->  5
 5  ->  4
 6  ->  1
 Permutation R factorized into cycles =
 ( 1 2 3 6) ( 4 5)

 -------------------------------------------------------
 Proof the n-th power with overloaded operator **:
 -------------------------------------------------------
 Permutation R = S ** 1
 1  ->  2
 2  ->  3
 3  ->  6
 4  ->  5
 5  ->  4
 6  ->  1
 Permutation R factorized into cycles =
 ( 1 2 3 6) ( 4 5)

 Permutation R = S ** 2
 1  ->  3
 2  ->  6
 3  ->  1
 4  ->  4
 5  ->  5
 6  ->  2
 Permutation R factorized into cycles =
 ( 1 3) ( 2 6)

 Permutation R = S ** 3
 1  ->  6
 2  ->  1
 3  ->  2
 4  ->  5
 5  ->  4
 6  ->  3
 Permutation R factorized into cycles =
 ( 1 6 3 2) ( 4 5)

 Permutation R = S ** 4
 1  ->  1
 2  ->  2
 3  ->  3
 4  ->  4
 5  ->  5
 6  ->  6
 Permutation R factorized into cycles =
 No cycles found.

 Permutation R = S ** 5
 1  ->  2
 2  ->  3
 3  ->  6
 4  ->  5
 5  ->  4
 6  ->  1
 Permutation R factorized into cycles =
 ( 1 2 3 6) ( 4 5)
 
oh. My god. prof. mikrom. I can't say a word.
are you the person design Fortran program. ill never get your level.

what I meant by other algebraic structures is that eg. inverts a permutation or whether a permutation is even or odd.
 
oh. My god. prof. mikrom. I can't say a word.
are you the person design Fortran program. ill never get your level.
[lol]
Kevek, if you believe or not, I never programmed at professional level in Fortran. I used it a little bit during my study of mathematics and then later I teached mathematics (calculus and numerical mathematics) about 6 years at the technical university. But it was a fortran standard called Fortran 77 and it was in that time already obsolete language. We used in that time rather more progressive languages like Pascal and C.
But I never reached a professor level, I was only an assistent [lol]
If you believe or not I never used the Fortran 90 feature of operator overloading before your assignment. I only have read the 2 links I posted above and tried out if it works or not.
Now I 'm working in banking and I code in Fortran only for fun on this forum. At the professional level I code in other languages, like COBOL, REXX, CL (Control Language on iSeries), Java, Python, .., etc.

Keevek never say never. You can reach my level or higher if you want. What are you studying?

kevek said:
what I meant by other algebraic structures is that eg. inverts a permutation or whether a permutation is even or odd.
Ok, I know what's a permutation and what's a cycle, but I forgot, when the permutation is even or odd and how to construct the inverse of it. As I said, now I'm working at banking (it's about 8 years now) and I forgot many basics things from mathematics. I have no more time to study something from the basics of algebra :)
 
mikrom, thank you for your kind words, thank you for your encouragement. never say never!!!I will!!!
As what i say, you got talent to learn things to do things. Just like you never used f90, but you could do it after you read 2 web pages!
I am currently study Mathematic with Economics on final year. I am still considering whether I should go on study or start to look for a job.
Anyway, I am living in London, if I do have a chance, please let me buy your a drink.
I wish you well in your endeavors.
take care.
kev
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top