← Latest papers
💻 computer science

Neural Code Translation of Legacy Code: APL to C#

This paper presents a novel framework for translating legacy APL code into C# using large language models, demonstrating that guided strategies like retrieval augmentation and iterative refinement, combined with an automated evaluation pipeline, significantly improve translation quality despite the challenges of APL's sparse syntax and limited training data.

Original authors: Abdulrahman Ramadan, Hanen Borchani, Iben Lilholm, Mikkel Almind, Allan Peter Engsig-Karup

Published 2026-05-15
📖 5 min read🧠 Deep dive

Original authors: Abdulrahman Ramadan, Hanen Borchani, Iben Lilholm, Mikkel Almind, Allan Peter Engsig-Karup

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a massive, ancient library written in a secret, highly compressed code called APL. This code is like a shorthand language used by a small group of mathematicians and engineers decades ago. It's incredibly powerful but looks like a jumble of strange symbols (like , , and ) that most modern programmers can't read.

Now, imagine you need to move all these books into a modern library written in C#, a language used by today's software giants. The problem? The two languages speak completely different dialects. APL is like a fluid, mathematical dance where one line of code can do the work of a whole paragraph in C#. C# is rigid, structured, and demands you explain every single step in detail.

This paper is a report on a team of researchers who tried to build a robot translator (using Artificial Intelligence) to move these ancient books from the APL library to the C# library automatically.

Here is how they did it, explained simply:

The Problem: The "Lost in Translation" Gap

The researchers found that standard AI translators often fail at this task. Why?

  1. The Alphabet is Weird: APL uses special symbols that most AI models have never seen before. It's like trying to teach a robot to read a language written in emojis it doesn't understand.
  2. The Logic is Different: APL works on whole groups of numbers at once (like a bucket of water), while C# usually works on one number at a time (like a single drop). The AI has to figure out how to break the "bucket" into "drops" without spilling the logic.
  3. No Dictionary: There aren't many examples of APL code paired with C# code for the AI to learn from. It's like trying to learn a new language without a textbook.

The Solution: Three "Helpers" for the Robot

The researchers tested four different ways to help the AI translator. Think of these as different levels of assistance for a student taking a difficult exam:

  1. The "Solo" Attempt (Baseline): The AI is given the APL code and told, "Just write the C# code."

    • Result: The AI gets confused. It often writes code that looks okay but doesn't actually work, or it crashes because it forgot the rules of C#.
  2. The "Translator's Note" (Natural Language): Before writing the code, the AI is asked to first explain what the APL code is doing in plain English (like a human translator writing a summary). Then, it uses that summary to write the C# code.

    • Result: This helped a lot. By forcing the AI to "think" about the meaning in English first, it made fewer mistakes.
  3. The "Cheat Sheet" (Retrieval): The AI is given a stack of reference cards (a database of APL rules and examples) and told to look up the specific rule it needs before writing.

    • Result: This was okay, but sometimes the AI picked the wrong reference card, so it didn't help as much as the "Translator's Note."
  4. The "Practice Run" (Iterative Refinement): This was the winner. The AI writes the code, then the computer tries to run it. If the code crashes or gives the wrong answer, the computer yells, "Error! Try again!" The AI reads the error message, fixes its work, and tries again. It keeps doing this until the code works perfectly.

    • Result: This produced the best results. It's like a student taking a practice test, seeing their mistakes, and re-taking the test until they get an A.

The Secret Sauce: "Method Signatures"

The researchers also discovered a crucial trick. Because C# is so strict about types (it needs to know if a number is an integer or a decimal), they gave the AI a "blueprint" of the function's shape before it started writing. This is like giving the AI a template that says, "This function takes two lists of numbers and returns a list of yes/no answers." With this blueprint, the AI wrote much more accurate code.

What They Found (The Results)

  • AI can do it, but it needs help: A raw AI model isn't good at this yet. But if you give it the "blueprint," ask it to explain the logic in English first, and let it practice fixing its own errors, it becomes very good at the job.
  • More data = Better results: The more examples of APL-to-C# pairs they fed the AI, the better it got. However, they found that even with a relatively small amount of data, the "Practice Run" method worked surprisingly well.
  • The main enemy isn't syntax, it's logic: Most of the time, the AI could write code that compiled (worked without crashing), but it didn't do exactly what the original APL code did. The hardest part was understanding the intent of the math, not just the spelling of the code.

The Bottom Line

The researchers successfully built a pipeline that can automatically translate old, mysterious APL code into modern, usable C# code. They proved that by combining fine-tuning (specialized training), explanations (English summaries), and feedback loops (fixing errors), AI can bridge the gap between these two very different worlds. This means companies with old, critical systems written in APL might finally be able to modernize them without having to hire a rare, expensive expert to rewrite everything by hand.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →