AI Fortran Code

Hello all, does everybody know any AI that create Fortran code starting from a sentence?

Welcome @cla99 to the Discourse,
there were some examples of that in this recent thread:

starting from the 4th message:

write a Fortran code solving the 2D trajectory of a tennis ball exposed to drag force and gravity

I asked ChatGPT to write an INTERCAL program for me, and it did. It can certainly do Fortran. There’s even a mention in the Advent of Code thread where someone gave it one of the day’s problems and it created a decent solution for it in Fortran.

2 Likes

Not about Fortran, but its old brother COBOL:

It does not seem so easy to generate a code that compiles:

Looking at the failure cases, we can see that state-of-the-art LLMs struggle to generate COBOL that even compiles. Only 47.94% of GPT-4 generated solutions compile with GnuCOBOL.

The company then presents its mAInframer-34b model which have a 74% score.

This was discussed a bit on another site yesterday and someone made an interesting comment about getting AI to write Fortran:

“”"
Fortran also has the disadvantage of numerous separate dialects/flavours that plenty of times can’t be mixed. And rarely is the exact style mentioned in random code found somewhere.
It got a lot better with Fortran 95 and newer, but in the old world of e.g. lahey compilers and custom commands only available there, any LLM has failed me consistently to stick to these intricacies. I can’t even blame them, when asking humans questions about these topics, you’ll get all sorts of answers that are equally close to a correct solution, but almost never precisely correct.
“”"

1 Like
fortran program to print the count from 1 to 10 generated by
ChatGPT

Here is a simple Fortran program that prints the numbers from 1 to 10:

fortran

program count_to_ten
    integer :: i

    do i = 1, 10
        print *, i
    end do
end program count_to_ten

In this program:

    program count_to_ten starts the definition of a program named count_to_ten.
    integer :: i declares an integer variable i.
    do i = 1, 10 starts a loop that will iterate with i going from 1 to 10.
    print *, i prints the current value of i.
    end do marks the end of the loop.
    end program count_to_ten marks the end of the program.

ian@ian-Latitude-E7440
ian@ian-Latitude-E7440:~$ gfortran countto10.f -ffree-form -o countto10
ian@ian-Latitude-E7440:~$ ./countto10
           1
           2
           3
           4
           5
           6
           7
           8
           9
          10
ian@ian-Latitude-E7440:~$ cat countto10.f
program count_to_ten
    integer :: i

    do i = 1, 10
        print *, i
    end do
end program count_to_ten