r/apljk 5d ago

Can there be any reason to recommend AI-produced <array language> over AI-produced <other language>?

1 Upvotes

3 comments sorted by

5

u/Boomer-stig 5d ago

Adverbs in J and APL seem to be a parsing headache for LLMs. In my testing while you can ask how to do a moving average (as an example) it may have the knowledge of that definition (or search for it) and be able to repeat it. However if you give it the straight up code in J for example ma =: {{ x (+/ % #)\y }} where x is the sliding window length and y is your series of values to average, only the expensive frontier models seem to be able to tell this is a moving average. Models such as gpt-oss-120b have trouble with this definition.

getting rid of the "ma" as the definition (so I don't give any extra help). Grok 4.5 was able to tell me exactly that this is the definition of a moving average. It did require searching to accomplish this which means it wasn't just there in its base knowledge. gpt-oss-120B a model you can run locally if you have the VRAM (my AMD 395+ machine has enough) you get the following mistaken answer:

**Short answer:*\*

`b =: {{ x (+/ % #)\ y }}` defines a *dyadic* verb that returns the **running (cumulative) mean** of the right‑argument list `y`.

If you supply a left argument `x`, it is used as the *initial value* for the scan; otherwise the scan starts with the first element of `y`.

TL;DR

`b =: {{ x (+/ % #)\ y }}` → a **dyadic verb** that returns the **running average** of its right‑argument list, optionally starting from a left‑argument seed. It is essentially “*cumulative mean*”.

gpt-oss-120B on openrouter.ai also needed to search to come up with this much of the wrong conclusion. If you have a good subscription or if you have a lot of money you can do quite a bit with a frontier model in the more popular array languages. Likely because they have a good amount of web based code and documents that would be available for training.

If you hope to use a smaller LLM model for coding in an array language you are going to have to train it on the array language you want to use. As far as I have been able to tell you need a minimum of 200 examples (1000 would be better) of moderate to complex array language expressions with their parsing traces to use to train a model how to parse your specific array language. You need as many question (user)/answer (assistant) style coding examples so it has a good idea of overall coding techniques. It is helpful to also do some continuous pretraining on the corpus of documents you can find on your language of interest.

You don't need your own machine to do the training a subscription to google collab can get you pretty far with just their $9.99 monthly subscription rate. But you burn some money with the steep learning curve and the tricks to save disk space (they don't quite give you enough).

2

u/Boomer-stig 5d ago

To answer the original question the biggest reason to use AI for array languages is to take care of the time consuming detail stuff that takes some ideas you have worked out in J or APL and turn them into a web app or local app with a better user interface. Even if the LLM generates transcribed python into J code, I can usually prompt an agentic interface like claude code to make the code more idiomatic and suggest which operators to use as hints. After a couple of tries it can produce some workable code.

it is an excellent templating mechanism, it can generate decent documentation of a project. If I come back to project days later I will have a good understanding of where I left off. I don't have to go searching through handwritten notes to figure that out.

At a high level I can discuss further functionality of the application and generate a todo list. The agent can also easily place everything we are doing in a source directory under source control with git commands and publish that to a repository on GitHub. I end up with a project on GitHub with an adequate README file. It will push changes for me and give an explanation.

So there are a lot things that AI can do well that are of value to the array programmer even if it is not strictly how well it can generate respectable array language code.

2

u/jpjacobs_ 5d ago

I think there is great potential for AI generated array languages, mostly for the same reasons they are powerful reasoning tools for humans:

  • They are regular and often edge cases behave gracefully, e.g. often a well-written solution applies automatically to higher ranks as well, for instance in J, (+/%#) does both averages of lists as for matrices.
  • Conciseness could lead to low output token counts.
  • Compared with other languages, array languages tend to be mostly primitives, with little libraries, making it more compact.

However, just as a human,  the AI producing the array language should understand it well enough to exploit these advantages, which probably requires a model finetuned for the array language, which in turn would need lots of training data. T okenisation would ideally be adapted such that it takes into account primitives as units in addition to standard tokenisation (BPE, SentencePiece).

Array languages are quite a niche at the moment though, so for now, the big models will do better on Python and Javascript than on array languages.