# Fortran Help, Please. Waiting online.

• Fortran
• kevek

#### kevek

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.

1. I only see pseudo-code to initialize the array, and to check for identity.
I do not see any operators/methods, much less what you'd like to achieve.

2. I am not familiar with the operator * and the (123) notation, therefore the properties you mentioned are not obvious to me since they have not been developed/derived.
for example:
how do I know that (135)(135)=(153) without actually working it out?

(a b c), appears to be some type of rotate operator:

() = 1 2 3 4 5 6
(3 5) = 1 2 5 4 3 6
(1 3) = 5 2 1 4 3 6

if(a b c) means to rotate "left" = b->a + c->b + a->c

(3 5) + (1 3) = (1 5 3) => 5->1 + 3->5 + 1-> 3 = 5 2 1 4 3 6 == (1 3 5) + (1 3 5) = (1 3) + (3 5) + (1 3) + (3 5)

(1 3 5) = (3 5 1) = (5 1 3) = left rotate of 1 3 5
(1 5 3) = (5 3 1) = (3 1 5) = right rotate of 1 3 5

It sould be clear that 2 right rotate of 3 things = 1 left rotate of 3 things and vice versa, and that 3 rotates of 3 things = identity.

(a b c d), for example (1 2 4 3) = 2 4 1 3 5 6. Repeating a sequence of a 4 "rotate" 4 times gets you back to the original

1 2 3 4 5 6
2 4 1 3 5 6
4 3 2 1 5 6
3 1 4 2 5 6
1 2 3 4 5 6

I don't understand what you're trying to accomplish though, prove that repeating any sequence of operations enough times and you get back to the original?

Last edited:
Thank you for your reply. I don't have any idear how to create subroutine and Do loops. and the (153)(153)=(135) is defined like that. just need to set it into subroutine.

Thank you Jeff. for your clearly explanation.

your code fragment looks ok to me, except you can just start off with flag = 1. My Fortran is very rusty, but based on your code fragment:

Code:
      integer flag

flag = 1
do i = 1,6,1
if ( x(i) .NE. i ) then
flag = 0
end if
end do

if (flag .EQ. 1) identity=1

Code:
      IMPLICIT REAL(A-H,O-Z), INTEGER(I-L)
INTEGER X(6)
INTEGER I
DO 15 I=1,6
15 X(I)=I
WRITE(6,999)IS_IDENTICAL(X)
999 FORMAT(I5)
STOP
END
INTEGER FUNCTION IS_IDENTICAL(X)
INTEGER X(6)
integer flag
IS_IDENTICAL=0
flag = 1
do i = 1,6,1
if ( x(i) .NE. i ) then
flag = 0
end if
end do

if (flag .EQ. 1) IS_IDENTICAL=1
RETURN
END
This completes what you started according to the given pseudocode, and using Jeff's code. However, as I mentioned earlier, it is not clear what you want to achieve.

Jeff Reid said:
(a b c), appears to be some type of rotate operator:

() = 1 2 3 4 5 6
(3 5) = 1 2 5 4 3 6
(1 3) = 5 2 1 4 3 6

if(a b c) means to rotate "left" = b->a + c->b + a->c

(3 5) + (1 3) = (1 5 3) => 5->1 + 3->5 + 1-> 3 = 5 2 1 4 3 6 == (1 3 5) + (1 3 5) = (1 3) + (3 5) + (1 3) + (3 5)

(1 3 5) = (3 5 1) = (5 1 3) = left rotate of 1 3 5
(1 5 3) = (5 3 1) = (3 1 5) = right rotate of 1 3 5

It sould be clear that 2 right rotate of 3 things = 1 left rotate of 3 things and vice versa, and that 3 rotates of 3 things = identity.

(a b c d), for example (1 2 4 3) = 2 4 1 3 5 6. Repeating a sequence of a 4 "rotate" 4 times gets you back to the original

1 2 3 4 5 6
2 4 1 3 5 6
4 3 2 1 5 6
3 1 4 2 5 6
1 2 3 4 5 6

I don't understand what you're trying to accomplish though, prove that repeating any sequence of operations enough times and you get back to the original?

Thank you again. yes it was what i meant. I just want to create 2 subroutin that one contain group (13)**2 = identity. and another one shows group (135)**3 = identity.
hence whatever the group contains (the number inside), it will get the identity after the finite powers of the group.
Thank you

Hi Jeff and Mathsmate, I wrote some code. don't know does it right ,can you please check for me?
Can you add (mutliplication '*' e.g.(35) * (13) = (153).) and powers of group(**2 or **3 .e.g.(153)**2 = (153)(153) = (135), and (153)**3 = (135)(153) = 1) into this code. I really don't know how to reload * and **. please.

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

Last edited:
You could make this more generic by using a second level of indexing:

Code:
      integer :: s[6]

size = 3
s(1) = 1
s(2) = 3
s(3) = 5

tmp     = P(s(1))
P(s(1)) = P(s(2))
P(s(2)) = P(s(3))
P(s(3)) = tmp

## What is Fortran?

Fortran is a high-level programming language commonly used for scientific and numerical computing. It was first developed in the 1950s and has been updated over the years to support modern computing architectures.

## Why do scientists use Fortran?

Fortran is specifically designed for scientific and numerical computing, making it a powerful tool for solving complex mathematical equations and performing data analysis. It also has a long history of use in the scientific community and a large library of pre-written code for common tasks.

## Is Fortran still relevant today?

Yes, Fortran is still widely used in scientific and high-performance computing applications. It has been continuously updated to support modern programming practices and is particularly well-suited for tasks that require speed and efficiency.

## Where can I find help with Fortran?

There are many online resources available to help with Fortran, including tutorials, forums, and documentation. You can also reach out to your colleagues or university for assistance or consider taking a course on Fortran programming.

## Are there any alternatives to Fortran?

While Fortran is a popular language for scientific computing, there are other programming languages that can also be used, such as Python, MATLAB, and R. Each language has its own strengths and weaknesses, so it is important to consider the specific needs of your project when choosing a language.