Live data from Hacker News

Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

medium.com

121–130 of 154 posts

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#121

Earlier quoted context omitted.

I think long term LLMs should directly generate Abstract Syntax Trees. But this is hard now because all the training data is text code.

It's possible that LLMs build ASTs internally for programming. I have no 1st hand data on this, but it would not surprise me at all.

LLMs don't have memory, so they can't build anything. Insofar as they produce correct results, they have implicit structures corresponding to ASTs built into their networks during training time.

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#122

My curmudgeonly genius Q/Kdb+ programmer of a co-worker, whom claims to be immune to the impact of LLMs, is going to be fucking pissed when he hears about Qython.

:D Well I'm still building Qython, but if your colleague has some example code snippets they think particularly difficult to translate, I'd love to take on the challenge!

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#123

Earlier quoted context omitted.

Once you get used to it, traditional ways look tedious and annoying to me. I think the power is in 'once you get used to it'. That will keep out most people. See python llm implementations vs k ones as a novice and you will see verbose unreadable stuff vs line noise. When you learn the math you see verbose code where the verbose code adds nothing at all vs exactly what you would write if you could.

Tedious and annoying for one-off commands maybe. It's like regex. Pretty compelling if you're writing a one-off pattern, you get immediate feedback and then you throw it away. But it's not a good idea to use regexes in code that you're going to use long term. It's justifiable for simple regexes, and many people go against this advice, but really for anything remotely complex regexes become totally unreadable and extr…

Yeah never had that issue; maybe it's because I have been doing regexes (and apl which people call write only as well) for 30 years: it is not unreadable, nor throw away. I find it far more readable than the alternatives; reading pages of elaborate 'pseudocode' is more bothersome/time consuming than a oneliner to me.

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#124

Cognitive load in LLMs: When LLMs are faced with syntactic complexity (Lisp/J parentheses/RL-NOP), distractors (cat facts), or unfamiliar paradigms (right-to-left evaluation), the model’s performance degrades because its "attention bandwidth" is split or overwhelmed. This mirrors human cognitive overload. My question: is there a way to reduce cognitive load in LLMs?, one solution seems to be process the input and out…

I think a translation layer to a lower-density language might be a good solution; e.g. Iverson's divisible-by-11 check, 0=11|-/d, can be verbosely done in Python with

import numpy as np

def flippedSubtract(a, b): return b - a

flipSubUfunc = np.frompyfunc(flippedSubtract, 2, 1)

def isDivBy11(number): digits = list(map(int, str(number))) discriminant = flipSubUfunc.reduce(digits) return (discriminant % 11) == 0

Though Claude already understands (has already seen?) 0=11|-/d so it's hard to tell for this example

As for the cat attack, my gut feeling is that it has to do with the LLM having been trained/instructed to be kind

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#125

How do they do with lisps?

(en passant, k is arguably more lispy than some lisps. for a lisp guy, the first cultural shock is usually the absence of 99% of superfluous parens)

as for LLM copilots and the quality of their lisp: why you'd expect them to excel in lisp better than they lisp in excel, pardon the pun?

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#126
post #120

curiously enough, this thread made me revisit some past conversations with people like atw, nsl and aab with regard to possible ways to expose humans to the way rivers flow in k/q/apl land. the choices are limited, and decision takes some agony: a) if you don't want your audience to close the tab right away, you'd say "a k expression is written, read and evaluated strictly right to left unless the precedence is expli…

Those github links are so cool, thanks for sharing! :)

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#127

It's not because of the left of right evaluation. If the difference was that simple, most humans, let alone LLMs, wouldn't struggle with picking up q when they come from the common languages. Usually when someone solves problems with q, they don't use the way one would for Python/Java/C/C++/C#/etc. This is probably a poor example, if I asked someone to write a function to create an nxn identity matrix for a given num…

Or, even better, also from the cookbook: {(2#x)#1,x#0} But this really borders on obfuscation :P

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#128

I can write code right-to-left, I simply choose to not do it.

no, it wasn't your choice how you were taught to read and write something like this:

1|2*3>>4+5

in C and k, this expression should hopefully evaluate to 1, but this is just a lucky coincidence: reading and writing these two expressions are wildly different in complexity in those two languages. if you're not sure what i mean, ask your local LLM to explain why that is, but make sure you're sitting down. what you'll discover is that what you think you "simply chose to do" is not what you're actually doing.

while it is true that you can write code anyway you deem fit, i'm afraid you're a bit confused about the actual direction you're forced to think you chose to write it.

but once you're there, it suddenly gets a lot less complicated, and - miraculosly - doesn't cancel out or mess up your previous beliefs and habits.

k/q, of apl heritage, are beautiful - first and foremost because they're simple to write and simple to read.

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#129
post #120

curiously enough, this thread made me revisit some past conversations with people like atw, nsl and aab with regard to possible ways to expose humans to the way rivers flow in k/q/apl land. the choices are limited, and decision takes some agony: a) if you don't want your audience to close the tab right away, you'd say "a k expression is written, read and evaluated strictly right to left unless the precedence is expli…

Those github links are so cool, thanks for sharing! :)

thanks, and you're welcome.

i hope you'll find them useful.

Re: Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left

#130
I fully discount the right to left thing.

There is not enough q/kdb full source code "out there" that would have made it into the LLM training data. It tends to be used in secretive environments and can be very site specific in convention. I bet a purpose built small fine tune with real + synthetic data would be enough to get something generating better Q code.

Post reply on HN