# Scientists are using artificial intelligence and large language models to rewrite old code in modern languages

**URL:** <https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598>\
**Category:** Uncategorized\
**Created:** [April 20, 2025, 5:35am UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598 "2025-04-20T05:35:46Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [April 20, 2025, 5:35am UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/1 "2025-04-20T05:35:46Z")

</div>

"Specifically, he and his 20-person team have a goal to demonstrate that AI is capable of translating some of the tens of millions of lines of Lab code written in Fortran, an older coding language, into C++, a code language that runs better on modern computers. "

🤦‍♂️

> **[Translate Fortran to C++ with AI and RAG | LANL](https://www.lanl.gov/media/publications/1663/0125-llm-translation)**
>
> Scientists are using AI, machine learning, and LLMs to rewrite old programming code into a modern language.

---

<div class="post-metadata">

**Author:** ![FedericoPerini](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/federicoperini/32/1750_2.png) [@FedericoPerini](https://fortran-lang.discourse.group/u/FedericoPerini)\
**Post date:** [April 20, 2025, 7:39am UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/2 "2025-04-20T07:39:07Z")

</div>

I also use LLMs extensively to refactor Fortran and got to say that they’re great: the accuracy they catch patterns in code e.g. where error handling should be put, what design patterns to use, is insanely impressive (for complex tasks: not so much if phd-level)

The pain point is that we are Fortran enthusiasts, but people generally cares little about this stuff and moves toward the least-friction setup - the fact C++ is perceived as less friction than Fortran at math and science is telling….

What we can do is to keep developing good Fortran packages: math but also all the stuff that makes C and C++ more convenient rn (think Boost library, GUIs, GPU interaction, YAML/structured IO, etc). Maybe we should use LLMs for part of that as well!

Final thought I want to post a [link](https://www.modular.com/blog/democratizing-ai-compute-part-5-what-about-cuda-c-alternatives) to a really interesting article @clattner_llvm posted about why OpenCL has not made it to dominate AI. I found many similarities with where Fortran is at now.

PS happy Easter everyone!

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [April 20, 2025, 11:07am UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/3 "2025-04-20T11:07:03Z")

</div>

Such conversion efforts are occurring not just at Los Alamos. There is also  
  
 [GitHub - akashdhruv/CodeScribe: Command line tool for code translation using generative AI](https://github.com/akashdhruv/CodeScribe) from Argonne  
  
[GitHub - HPC-Fortran2CPP/Fortran2Cpp: Fortran2Cpp: A new model designed for the Code translation between the Fortran and C++](https://github.com/HPC-Fortran2CPP/Fortran2Cpp) from Lawrence Livermore.

---

<div class="post-metadata">

**Author:** ![fxm](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fxm/32/5726_2.png) [@fxm](https://fortran-lang.discourse.group/u/fxm)\
**Post date:** [April 20, 2025, 11:13am UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/4 "2025-04-20T11:13:00Z")

</div>

There’s a lot to unpack here.

> “[…] written in Fortran, an older coding language […]”

I’m always puzzled when people bring up age and seem to think the rest of the argument makes itself. By the logic `old = no good`, we could throw out a lot of great inventions. I can only assume age is brought up, because it is falsely seen as some indicator for being outdated/not updated for decades - a persistent myth we see parroted even by computer science students who never engaged with the language. It continues to baffle me how many are able to ignore the developments since 90 (i.e. the last 35 years) and talk about 77 when criticising Fortran. I sometimes wonder if the “Fortran is old” argument would be as persistent if the `implicit none` had been dropped in the 90s and the language had been continued with the name Fortran++. The whole argument is particularly strange when you consider that 1) C++ is older than modern Fortran, 2) C (of which C++ is an extension) is older than the 77 standard. We can talk about modern tooling options still being more limited for Fortran (something many here are addressing), but this point usually isn’t reached by those making the “Fortran is old” argument.

> “Being dependent on Fortran alone is risky these days”

I have difficulties wrapping my head around this. What is risky? If the argument is about depending too much on just 1-2 languages, surely, the trend of switching everything to Python and C/C++ should be more alarming?

> C++, a code language that runs better on modern computers

Did I miss something? 🙂

I don’t know what kind of code they’re reworking, but if I imagine someone announcing this in my field of research, the whole endeavour would feel rather naive and ill-informed. After all, the existing models are written in a way to leverage Fortran’s strengths and using a style/structure suited to Fortran’s paradigms. Simply translating the code will give you some strange-looking C++ code. If it’s old Fortran code, why not use LLMs to translate it to modern Fortran to leverage new developments? I found LLMs fairly useful for that.

> the fact C++ is perceived as less friction than Fortran at math and science is telling

Just the thought of writing C++ for maths and science feels like a tedious slog to me, haha.

P.S. Happy Easter! ❤

---

<div class="post-metadata">

**Author:** ![R\_cubed](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/r_cubed/32/263_2.png) [@R\_cubed](https://fortran-lang.discourse.group/u/R_cubed)\
**Post date:** [April 20, 2025, 11:46am UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/5 "2025-04-20T11:46:18Z")

</div>

I don’t see why this is so surprising; I see this as a downgrade from what would be possible with source to source translators and stepwise refinement as developed in the formal methods community.

Now, if you train the model yourself, perhaps much of the problems can be avoided. I remember a section in the CS classic [Structure and Interpretation of Computer Programs](https://web.mit.edu/6.001/6.037/sicp.pdf) (AKA SICP p. 161 in footnote) that most old Fortran programs had a pattern of map, filter and accumulate, which I suspect hasn’t changed that much.

But adding randomness via the LLM to this code conversion process can’t be a good thing.

> **[E.W.Dijkstra Archive: On the foolishness of "natural language programming"....](https://www.cs.utexas.edu/~EWD/transcriptions/EWD06xx/EWD667.html)**

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [April 20, 2025, 12:05pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/6 "2025-04-20T12:05:51Z")

</div>

> [@jacobwilliams](#):
>
> [Translate Fortran to C++ with AI and RAG | LANL](https://www.lanl.gov/media/publications/1663/0125-llm-translation)

The link is broken (?)

EDIT: looks like the whole site is down

EDIT2: was because of my VPN, as suggested by @fxm

---

<div class="post-metadata">

**Author:** ![fxm](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fxm/32/5726_2.png) [@fxm](https://fortran-lang.discourse.group/u/fxm)\
**Post date:** [April 20, 2025, 12:15pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/7 "2025-04-20T12:15:37Z")

</div>

You may need to disable VPN. Works for me.

---

<div class="post-metadata">

**Author:** ![rwmsu](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rwmsu](https://fortran-lang.discourse.group/u/rwmsu)\
**Post date:** [April 20, 2025, 12:22pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/8 "2025-04-20T12:22:13Z")

</div>

> [@jacobwilliams](#):
>
> a code language that runs better on modern computers

This is my first clue that the person that wrote this is clueless and just recycleing what some other supposed expert told him. Maybe they should go to any large Gov’t HPC system that’s not DoE and ask what language is burning the most cycles on their hundreds of thousands of cores.

---

<div class="post-metadata">

**Author:** ![fxm](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fxm/32/5726_2.png) [@fxm](https://fortran-lang.discourse.group/u/fxm)\
**Post date:** [April 20, 2025, 12:41pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/9 "2025-04-20T12:41:20Z")

</div>

> [@rwmsu](#):
>
> just recycleing what some other suppossed expert told him

… and that’s the dangers of persistent myths “parroted even by computer science students who never engaged with the language”, as I described it earlier. At some point, it becomes accepted as fact even by people in the field, which are then cited as experts by others. These things are hard to get out of the system, because they become self-perpetuating. It’s even worse when these myths become fun trivia when socialising in certain circles. The “Lol, Fortran is old” line is sadly one that will earn you confirmation and cheers among others who’ve not engaged with the language. If there’s one thing people feel they know about it is that “it’s old/no one uses it/it’s only for legacy stuff”.

---

<div class="post-metadata">

**Author:** ![PierU](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/pieru/32/1848_2.png) [@PierU](https://fortran-lang.discourse.group/u/PierU)\
**Post date:** [April 20, 2025, 12:45pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/10 "2025-04-20T12:45:35Z")

</div>

And BTW, C++ is 40 years old now, which is kinda “old” as well…

---

<div class="post-metadata">

**Author:** ![fxm](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fxm/32/5726_2.png) [@fxm](https://fortran-lang.discourse.group/u/fxm)\
**Post date:** [April 20, 2025, 12:49pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/11 "2025-04-20T12:49:47Z")

</div>

Yep, older than modern Fortran. And if you consider it just an extension to C, you could argue much of it is from the 70s.

---

<div class="post-metadata">

**Author:** ![jacobwilliams](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/jacobwilliams/32/10_2.png) [@jacobwilliams](https://fortran-lang.discourse.group/u/jacobwilliams)\
**Post date:** [April 20, 2025, 1:07pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/12 "2025-04-20T13:07:33Z")

</div>

We have to start writing articles about using AI to convert old C/C++ code into modern, easy to read and maintain Fortran.

---

<div class="post-metadata">

**Author:** ![fxm](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fxm/32/5726_2.png) [@fxm](https://fortran-lang.discourse.group/u/fxm)\
**Post date:** [April 20, 2025, 1:24pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/13 "2025-04-20T13:24:17Z")

</div>

Maybe I would if I could find any C/C++ code relevant to what I do. 🙂

---

<div class="post-metadata">

**Author:** ![R\_cubed](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/r_cubed/32/263_2.png) [@R\_cubed](https://fortran-lang.discourse.group/u/R_cubed)\
**Post date:** [April 20, 2025, 1:34pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/14 "2025-04-20T13:34:12Z")

</div>

At least in this case, I think “AI” is a term that serves the function that “dynamic programming” did for Richard Bellman

> I spent the Fall quarter (of 1950) at [RAND](https://en.wikipedia.org/wiki/RAND_Corporation). My first task was to find a name for multistage decision processes. An interesting question is, “Where did the name, dynamic programming, come from?” The 1950s were not good years for mathematical research. We had a very interesting gentleman in Washington named [Wilson](https://en.wikipedia.org/wiki/Charles_Erwin_Wilson). He was Secretary of Defense, and he actually had a pathological fear and hatred of the word “research”. I’m not using the term lightly; I’m using it precisely. His face would suffuse, he would turn red, and he would get violent if people used the term research in his presence. You can imagine how he felt, then, about the term mathematical. The RAND Corporation was employed by the Air Force, and the Air Force had Wilson as its boss, essentially. **Hence, I felt I had to do something to shield Wilson and the Air Force from the fact that I was really doing mathematics inside the RAND Corporation.** What title, what name, could I choose? In the first place I was interested in planning, in decision making, in thinking. But planning, is not a good word for various reasons. I decided therefore to use the word “programming”. I wanted to get across the idea that this was dynamic, this was multistage, this was time-varying. I thought, let’s kill two birds with one stone. Let’s take a word that has an absolutely precise meaning, namely dynamic, in the classical physical sense. It also has a very interesting property as an adjective, and that is it’s impossible to use the word dynamic in a pejorative sense. Try thinking of some combination that will possibly give it a pejorative meaning. It’s impossible. Thus, I thought dynamic programming was a good name. It was something not even a Congressman could object to. So I used it as an umbrella for my activities.
> 
> — Richard Bellman, _Eye of the Hurricane: An Autobiography_ (1984, page 159)

> **[Dynamic programming | History of the name](https://en.wikipedia.org/wiki/Dynamic_programming#History_of_the_name)**
>
> The term dynamic programming was originally used in the 1940s by Richard Bellman to describe the process of solving problems where one needs to find the best decisions one after another. By 1953, he refined this to the modern meaning, referring specifically to nesting smaller decision problems inside larger decisions, and the field was thereafter recognized by the IEEE as a systems analysis and engineering topic. Bellman's contribution is remembered in the name of the Bellman equation, a c Bel...

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [April 20, 2025, 1:59pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/15 "2025-04-20T13:59:12Z")

</div>

The article quotes Dan O’Malley. A preprint he co-authored about the work is [Enhancing Code Translation in Language Models with Few-Shot Learning via Retrieval-Augmented  
Generation](https://arxiv.org/abs/2407.19619).

---

<div class="post-metadata">

**Author:** ![aledinola](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@aledinola](https://fortran-lang.discourse.group/u/aledinola)\
**Post date:** [April 20, 2025, 2:27pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/16 "2025-04-20T14:27:56Z")

</div>

C and C++ are really not a good choice for numerical methods. I would understand if they said that Julia is better than Fortran…

---

<div class="post-metadata">

**Author:** ![rwmsu](https://avatars.discourse-cdn.com/v4/letter/r/48db29/32.png) [@rwmsu](https://fortran-lang.discourse.group/u/rwmsu)\
**Post date:** [April 20, 2025, 2:51pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/17 "2025-04-20T14:51:22Z")

</div>

Probably have to wait until templates and generic routines finally make it into Fortran. Almost all large scale C++ apps I’ve seen are basically one big collection of templates see openFoam and SU2. Im sure there are others. However, if that day comes and AI can convert either of these to Fortran then I’ll finally become an AI believer.

---

<div class="post-metadata">

**Author:** ![apetros85](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/apetros85/32/5415_2.png) [@apetros85](https://fortran-lang.discourse.group/u/apetros85)\
**Post date:** [April 20, 2025, 3:06pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/18 "2025-04-20T15:06:20Z")

</div>

Do you have any specific prompts or rules that you use when refactoring the code? I have a big project that I wrote during my PhD and have been wanting to refactor the code to fix a lot of my questionable practices over the years, but I never seem to find the time.

---

<div class="post-metadata">

**Author:** ![fxm](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/fxm/32/5726_2.png) [@fxm](https://fortran-lang.discourse.group/u/fxm)\
**Post date:** [April 20, 2025, 3:41pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/19 "2025-04-20T15:41:18Z")

</div>

I think expanding the FPM project setup with templates for different types of libs/apps could help here (see related [github issue](https://github.com/fortran-lang/fpm/issues/833)). The individual .f90 files for specific templates could be expanded from bare bone skeleton scripts to scripts that already include general routines or import relevant fpm packages/fortran libs (for linear algebra, for example). While it may not be particularly clean to include these directly in the FPM project, if the creation of templates is straightforward and well documented, larger Fortran projects could create templates for all involved programmers to use.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [April 20, 2025, 4:20pm UTC](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598/20 "2025-04-20T16:20:15Z")

</div>

We are preaching to the converted here 🙂 . A recent presentation by Vincent Lafage about the evolution of Fortran and evolving legacy Fortran codes is at [https://www.youtube.com/watch?v=iXodpBBvVQY](https://www.youtube.com/watch?v=iXodpBBvVQY) starting at 8:47. The video (in English) has links to two tutorials on Fortran, in French: [Avancé](http://www.idris.fr/media/formations/fortran/idris_fortran_avance_cours.pdf) and [Expert](http://www.idris.fr/media/formations/fortran/idris_fortran_expert_cours.pdf).

[Next page](https://fortran-lang.discourse.group/t/scientists-are-using-artificial-intelligence-and-large-language-models-to-rewrite-old-code-in-modern-languages/9598.md?page=2)
