# AI Fortran Code

**URL:** <https://fortran-lang.discourse.group/t/ai-fortran-code/4978>\
**Category:** Help\
**Created:** [January 4, 2023, 5:09pm UTC](https://fortran-lang.discourse.group/t/ai-fortran-code/4978 "2023-01-04T17:09:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cla99](https://avatars.discourse-cdn.com/v4/letter/c/f07891/32.png) [@cla99](https://fortran-lang.discourse.group/u/cla99)\
**Post date:** [January 4, 2023, 5:09pm UTC](https://fortran-lang.discourse.group/t/ai-fortran-code/4978/1 "2023-01-04T17:09:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [January 4, 2023, 5:19pm UTC](https://fortran-lang.discourse.group/t/ai-fortran-code/4978/2 "2023-01-04T17:19:46Z")

</div>

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

> [@What ChatGPT says about Fortran](https://fortran-lang.discourse.group/t/what-chatgpt-says-about-fortran/4926):
>
> I asked ChatGPT about Fortran. The answers may reflect what is believed about Fortran on the Internet. I think the answers are pretty good, although Fortran now has decent support for OOP. What are the strengths of the Fortran programming language? Fortran (short for “Formula Translation”) is a general-purpose, compiled programming language that is especially suited to numerical and scientific computing. Some of the strengths of Fortran include: High performance: Fortran is known for its fast…

starting from the 4th message:

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

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [January 4, 2023, 8:29pm UTC](https://fortran-lang.discourse.group/t/ai-fortran-code/4978/3 "2023-01-04T20:29:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vmagnin](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/vmagnin/32/28_2.png) [@vmagnin](https://fortran-lang.discourse.group/u/vmagnin)\
**Post date:** [April 1, 2024, 7:32pm UTC](https://fortran-lang.discourse.group/t/ai-fortran-code/4978/4 "2024-04-01T19:32:57Z")

</div>

Not about Fortran, but its old brother COBOL:

> **[bloop | Evaluating LLMs on COBOL](https://bloop.ai/blog/evaluating-llms-on-cobol)**
>
> Modernising legacy code with AI

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.

---

<div class="post-metadata">

**Author:** ![rbitr](https://avatars.discourse-cdn.com/v4/letter/r/f1d935/32.png) [@rbitr](https://fortran-lang.discourse.group/u/rbitr)\
**Post date:** [April 1, 2024, 9:39pm UTC](https://fortran-lang.discourse.group/t/ai-fortran-code/4978/5 "2024-04-01T21:39:03Z")

</div>

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.  
“”"

> <https://news.ycombinator.com/item?id=39887462>
>
> 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.\<p\>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...

---

<div class="post-metadata">

**Author:** ![IanMartinAjzenszmidt](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ianmartinajzenszmidt/32/1992_2.png) [@IanMartinAjzenszmidt](https://fortran-lang.discourse.group/u/IanMartinAjzenszmidt)\
**Post date:** [April 1, 2024, 11:47pm UTC](https://fortran-lang.discourse.group/t/ai-fortran-code/4978/6 "2024-04-01T23:47:44Z")

</div>

```auto
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

```
