Readit News logoReadit News
gabiteodoru commented on Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left   medium.com/@gabiteodoru/w... · Posted by u/gabiteodoru
leprechaun1066 · a month ago
That does require someone to know that the take operator continues to treat the y list as circular when x is a list.

I think this form might be a bit easier: {(x,x)#(x*x)#1,x#0}

gabiteodoru · a month ago
But then you're not flexing your q muscles. Btw this is from the cookbook, these obfuscated patterns are actually recommended! https://code.kx.com/phrases/matrix/#identity-matrix-of-order...
gabiteodoru commented on Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left   medium.com/@gabiteodoru/w... · Posted by u/gabiteodoru
anticensor · 2 months ago
Idea: feed the language model the parse tree instead of the textual sequence.
gabiteodoru · a month ago
Yep, that's exactly what my MCP server is doing -- write in a Python-like language (I called in Qython), parse into AST tree, write the q code.
gabiteodoru commented on Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left   medium.com/@gabiteodoru/w... · Posted by u/gabiteodoru
leprechaun1066 · 2 months ago
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 number the non-q solution would probably involve some kind of nested loop that checks if i==j and assigns 1, otherwise assigns 0.

In q you'd still check equivalence, but instead of looping, you generate a list of numbers as long as the given dimension and then compare each item of the list to itself:

  {x=/:x:til x}3
An LLM that's been so heavily trained on an imperative style will likely struggle to solve similar (and often more complex) problems in a standard q manner.

gabiteodoru · 2 months ago
Or, even better, also from the cookbook: {(2#x)#1,x#0} But this really borders on obfuscation :P
gabiteodoru commented on Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left   medium.com/@gabiteodoru/w... · Posted by u/gabiteodoru
kelas · 2 months ago
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 explicitly overridden by parens, and this works better than you think, no worries, you'll come around. by the way, parens are evil, avoid them if you can".

b) if your intent is to retain a sharper crowd who went to yale or something, you'd say "a k expression is to be understood right of left", and throw them a freebie in form of a prompt for their local LLM in order to get lit. the magic sequence is just "f g h x leibniz".

for my own selfish reasons, i always chose the former, and it seems to perform better than the latter, proof:

https://github.com/kparc/ksimple

https://github.com/kparc/kcc

still, neither approach is anywhere near the chances of successfuly explaining which way to write python code to a 5yo kid, especially its precedence rules, which are much more intuitive (lol).

to explain the same thing to an LLM is not much different, really. all you need to do is to depress your 0yo kid with an obscene amount of _quality_ python code, of which there is no shortage. obviously, the more python code is fed to LLMs, the more humans will paste more LLM-generated python code, to be fed back to LLMs, ad lemniscate.

(and don't mind the future tense, we are already there)

============

so this is why LLMs can't write k/q/apl. first, they haven't seen enough of it. second, they are helpless to understand the meaning of a quote which was once chosen to helm a book known as SICP, not to mention countless human counterparts who came across it earlier, to the same effect:

"I think that it's extraordinarily important that we in computer science keep fun in computing. When it started out it was an awful lot of fun. Of course the paying customers got shafted every now and then and after a while we began to take their complaints seriously. We began to feel as if we really were responsible for the successful error-free perfect use of these machines. I don’t think we are. I think we're responsible for stretching them setting them off in new directions and keeping fun in the house. I hope the field of computer science never loses its sense of fun. Above all I hope we don’t become missionaries. Don't feel as if you're Bible salesmen. The world has too many of those already. What you know about computing other people will learn. Don’t feel as if the key to successful computing is only in your hands. What's in your hands I think and hope is intelligence: the ability to see the machine as more than when you were first led up to it that you can make it more."

― Alan J. Perlis

gabiteodoru · 2 months ago
Those github links are so cool, thanks for sharing! :)
gabiteodoru commented on Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left   medium.com/@gabiteodoru/w... · Posted by u/gabiteodoru
catfacts · 2 months ago
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 output format so that the LLM can use a more common format. I don't know if there is a more general solution.

Edit: Cat attack https://the-decoder.com/cat-attack-on-reasoning-model-shows-...

gabiteodoru · 2 months ago
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

gabiteodoru commented on Why LLMs Can't Write Q/Kdb+: Writing Code Right-to-Left   medium.com/@gabiteodoru/w... · Posted by u/gabiteodoru
helsinki · 2 months ago
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.
gabiteodoru · 2 months ago
: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!
gabiteodoru commented on Ask HN: Who is hiring? (February 2015)    · Posted by u/whoishiring
chillydawg · 11 years ago
Data Manager, London, UK. Longshot Systems is a sports betting syndicate that is looking for a new syndicate member to take control of all data. Sourcing, parsing, scraping, storing, manipulating - everything.

Benefits: cold, hard cash. We have no ping pong table, but we are very profitable, tiny and growing very very quickly. You'll be member #5, working with two coders, one PhD quant and our quant/commercial guru dude.

This is a full time role in our office in Marylebone. If you like sports, perhaps a bit of sports betting and are a dab hand at hacking stuff together, then get in touch at

hiring+david@longshotsystems.co.uk

gabiteodoru · 11 years ago
Delivery to the following recipient failed permanently:

     hiring+david@longshotsystems.co.uk

u/gabiteodoru

KarmaCake day79February 2, 2015
About
AI engineer & quant building tools for q/kdb+. 10+ years experience.
View Original