Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Mao Zedong Thot
Oct 16, 2008


Internet Janitor posted:

Fun side note: my goofy K projects gained enough recognition to land me an interview with a large consulting firm whose backend systems are written in K.
The interview experience itself was, to put it mildly, surreal in the best way. I'm now in the process of relocating to NYC to start a new job there.

So, uh, I guess the lesson here is occasionally weird side projects can result in unexpected new career paths? :unsmith:

NYC has a J meetup, of all things. Be sure to check it out. I went a few times when I lived there, it was one of the stranger meetup communities, in a totally awesome way.

I have nothing to add, but really appreciate this thread. I was really interested in the APL family a few years ago, particularly J. I don't do anything with my (limited) strange and arcane knowledge, but blowing people's mind with hooks and forks is a great party trick amongst programmers.

Adbot
ADBOT LOVES YOU

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord
I need help from someone more fluent in APL than I am lol

I've been looking up where the mathproglangy convention of treating the dot product as the same as matrix multiplication came from and it seems like APL was a big influence.

http://stackoverflow.com/questions/20424228/how-come-x-in-apl-works-for-both-matrices-and-vectors/20704876#20704876

So there's this answer and I wanted to know what part of the code corresponds to these 2 steps: "cut A into slices along its last axis, do the same with B along its first axis"

Also if anyone could tell me how these particular operations are done in one of the more modern variants like K or Q.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
I'll be sure to check out that J meetup, SFF- thanks for the heads-up.

As for matrix multiplication I think the K formulation is pretty easy to explain. To begin with, dot product is very simple: the sum of multiplying two items. This works equally well for vectors or matrices thanks to K's conforming rules.
code:
dot: {+/x*y}
Given this definition, a matrix multiply is simply the composition of the dot-product with each-left, so you will take the dot product of each row of the left matrix with the entire right matrix.
code:
mmul: {x dot\:y}
Excerpting from an oK trace:
code:
  \x mmul[(1 2 3;4 5 6); (7 8;9 10;11 12)]
First application of dot product:
code:
        (7 8       (7 8
         9 10       18 20
1 2 3 *  11 12) ->  33 36)

   (7 8      
    18 20    
+/  33 36) -> 58 64
Second application of dot product:
code:
        (7 8       (28 32
         9 10       45 50
4 5 6 *  11 12) ->  66 72)

   (28 32    
    45 50    
+/  66 72) -> 139 154
Bringing it all together:
code:
                       (7 8      
(1 2 3                  9 10      (58 64
 4 5 6) {[x;y]+/x*y}\:  11 12) ->  139 154)

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:
Congrats, IJ. I figure you were bound to be approached eventually because you keep releasing 'weird little side projects' that are really polished.

BigBobio
May 1, 2009

Symbolic Butt posted:

I need help from someone more fluent in APL than I am lol

I've been looking up where the mathproglangy convention of treating the dot product as the same as matrix multiplication came from and it seems like APL was a big influence.

http://stackoverflow.com/questions/20424228/how-come-x-in-apl-works-for-both-matrices-and-vectors/20704876#20704876

So there's this answer and I wanted to know what part of the code corresponds to these 2 steps: "cut A into slices along its last axis, do the same with B along its first axis"

It looks like he skipped over how he broke up A and B each into a vector of vectors. It was with the enclose operations (the ⊂ commands on the first line). The [x] direct which axis of the matrix to do the enclose along. Although I'm not sure why he uses a zilde and a 1 for axes, it should be a 1 and a 2 (different flavor of APL maybe?)

Pollyanna
Mar 5, 2005

Milk's on them.


Internet Janitor posted:

Fun side note: my goofy K projects gained enough recognition to land me an interview with a large consulting firm whose backend systems are written in K.
The interview experience itself was, to put it mildly, surreal in the best way. I'm now in the process of relocating to NYC to start a new job there.

So, uh, I guess the lesson here is occasionally weird side projects can result in unexpected new career paths? :unsmith:

niiiiiiiiiiiiice :cool: Gettin dat bux.

Athas
Aug 6, 2007

fuck that joker
Congratulations on the job!

I've become involved in writing an APL compiler targeting GPU execution. As a result, I figured I should probably get some more experience with APL by itself. Is there a nice way to write stencils? Currently we do it by a mess of concatenations and transposes, for example here, for the core of a 2D stencil:

pre:
  iter ← {
    temp ← ⍵
    m1 ← (⍉1↓⍉temp),row 1⍴0
    m2 ← (row 1⍴0),⍉¯1↓⍉temp
    x ← (m1 + m2) - c1 × temp

    n1 ← ⍉(⍉1↓temp),col⍴0
    n2 ← ⍉(col⍴0),⍉¯1↓temp
    y ← (n1 + n2) - c2 × temp

    delta ← (step ÷ Cap) × (power + (y ÷ Ry) + (x ÷ Rx) + (amb_temp - temp) ÷ Rz)
    temp + delta
  }
Row, step, Cap and the like are constants. Everything interesting happens in the definitions of m1, m1, n1, and n2. What this code basically does is take the 2D-array temp, and for each of the four cardinal directions, split off a row/column, then add a row/column of zeroes on the opposite side. I think this code would be more concise and simpler in Python+Numpy, which is unusual. Maybe stencils just haven't been a priority for the domains where APL is usually applied? We managed to get this to run pretty fast, but I don't much like the way it looks.

BigBobio
May 1, 2009

Athas posted:

Congratulations on the job!

I've become involved in writing an APL compiler targeting GPU execution. As a result, I figured I should probably get some more experience with APL by itself. Is there a nice way to write stencils? Currently we do it by a mess of concatenations and transposes, for example here, for the core of a 2D stencil:

pre:
  iter ← {
    temp ← ⍵
    m1 ← (⍉1↓⍉temp),row 1⍴0
    m2 ← (row 1⍴0),⍉¯1↓⍉temp
    x ← (m1 + m2) - c1 × temp

    n1 ← ⍉(⍉1↓temp),col⍴0
    n2 ← ⍉(col⍴0),⍉¯1↓temp
    y ← (n1 + n2) - c2 × temp

    delta ← (step ÷ Cap) × (power + (y ÷ Ry) + (x ÷ Rx) + (amb_temp - temp) ÷ Rz)
    temp + delta
  }
Row, step, Cap and the like are constants. Everything interesting happens in the definitions of m1, m1, n1, and n2. What this code basically does is take the 2D-array temp, and for each of the four cardinal directions, split off a row/column, then add a row/column of zeroes on the opposite side. I think this code would be more concise and simpler in Python+Numpy, which is unusual. Maybe stencils just haven't been a priority for the domains where APL is usually applied? We managed to get this to run pretty fast, but I don't much like the way it looks.

Two things i noticed:
-You can use the [x] modifier on ↓ (e.g. ↓[1] and ↓[2]) to control whether you drop the first row or column from the matrix, instead of doing all those transpose operations.↓[1] will drop by rows, and ↓[2] by columns
-If you're appending a row or column that is a single value to a matrix, you don't need to add it as a vector. You just need to concatenate the value of interest with the matrix using the , function (and again, you can control whether you append as a row or column by using the [x] modifier on ,). So, matrix,0 will add a whole column of zeros to the right of the matrix, and 0,matrix will add it to the left.

No idea if this will make it faster, but it will be easier to read.

Athas
Aug 6, 2007

fuck that joker
Oh yeah, that'll make it nicer. I wonder if it's supported by our parser. Won't do anything for performance, but we're already close to hand-written code anyway.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:
Stumbled across this on HN:
Dyalog APL v15.0 Free for Non-Commercial Use

Dyalog posted:

To make it easier for students, researchers and others who would like to experiment with Dyalog APL to get started, we are making Educational, Personal and Non-Commercial use of Dyalog APL completely free. Low-cost support contracts will be available for GBP150 per year, as they are today. The non-commercial system is a fully functional 64-bit Unicode interpreter, except on the Raspberry Pi where it remains a 32-bit application.

Athas
Aug 6, 2007

fuck that joker
You still have to fill out a form and wait for someone to approve it if you want to try it out. There is an "unregistered" version, but only for Windows. Why do they make it so hard to try it out?

It's interesting that there's been so relatively many array programming posts on HN recently.

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:
They know anyone willing to learn APL is also willing to jump through some hoops. :/

I hadn't actually tried to get it yet, that is pretty dumb.

Athas posted:

It's interesting that there's been so relatively many array programming posts on HN recently.

HN seems to do everything in spurts. Maybe array languages are finally going to get big because concurrency is becoming so important.

Athas
Aug 6, 2007

fuck that joker

taqueso posted:

HN seems to do everything in spurts. Maybe array languages are finally going to get big because concurrency is becoming so important.

Are any of the array languages particularly parallel in practice? I noticed Dyalog added futures recently, which is something you could find in any old procedural language.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."

Athas posted:

Why do they make it so hard to try it out?

I've had a conversation to this effect with a number of K programmers, as well as discussing the need for more accessible documentation, and the response is basically, "eh, people will find vector languages on their own; they always have." It's a bit frustrating. The main thing I'm learning is that the isolation and obscurity of these language communities is at least partly intentional.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Internet Janitor posted:

I've had a conversation to this effect with a number of K programmers, as well as discussing the need for more accessible documentation, and the response is basically, "eh, people will find vector languages on their own; they always have." It's a bit frustrating. The main thing I'm learning is that the isolation and obscurity of these language communities is at least partly intentional.

Obscurity has some benefits. Knowing an obscure language at all can be used as a signal that you're better than the typical Java[Script] programmer. Using an obscure language would also filter out anyone unwilling to learn it from your hiring process.

You trade that typically for a good standard library and ease in hiring.

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
Ever wanted a pocket calculator that could understand K expressions?

...No?

Well, er... you can have one anyway:



Try it live- I've mainly tested the layout on my iPhone SE, so on larger devices it should still be usable. If the window/browser has a landscape aspect ratio it will instead display a full keyboard. Still tinkering a bit with the layouts. The pl and ps functions are extensions for this oK frontend which plot a line graph or plot a scatterplot, respectively, because it just didn't seem complete if it couldn't function as a graphing calculator.

Internet Janitor fucked around with this message at 18:34 on Oct 16, 2016

taqueso
Mar 8, 2004


:911:
:wookie: :thermidor: :wookie:
:dehumanize:

:pirate::hf::tinfoil:
Is there official K documentation somewhere? Something more like a book than a reference card.

e: Is this it? http://code.kx.com/mkdocs/reference/

taqueso fucked around with this message at 17:03 on Dec 22, 2016

Cybernetic Vermin
Apr 18, 2005

taqueso posted:

Is there official K documentation somewhere? Something more like a book than a reference card.

e: Is this it? http://code.kx.com/mkdocs/reference/

That reference really does cover pretty much everything, the language is not large. This is the read if you want to get more of a sense of KDB+ generally though: http://code.kx.com/wiki/JB:QforMortals2/contents

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
The K2 Reference Manual is a bit out of date (kdb+ ships on top of K4), but largely still relevant, and it's fairly exhaustive and well-written. I used it as my primary reference when writing the initial revision of oK.

edit: Unrelated, but I've done a bit of work on oK Mobile recently- see the docs for details on spiffy new features. I'm pleased to note that several of my coworkers have started using it as a desk calculator.

Internet Janitor fucked around with this message at 00:51 on Dec 23, 2016

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."


Happy holidays, everyone.

Adbot
ADBOT LOVES YOU

Internet Janitor
May 17, 2008

"That isn't the appropriate trash receptacle."
I've been tinkering with parsing techniques lately, culminating in writing a parser combinator library in K. I may try using a similar approach in JS to simplify oK's parser.

Here's a parser for Bencode:
code:
digits:  plus oneof "0123456789"
number:  prod[seq(option lit "-";digits);.,/]
bstr:    nof[prod[seq(digits;lit ":");.*:];anychar]
bint:    prod[seq(lit "i";number                 ;lit "e");{x 1}]
blst:    prod[seq(lit "l";plus`bencode           ;lit "e");{x 1}]
bdict:   prod[seq(lit "d";plus seq(bstr;`bencode);lit "e");{!/+x 1}]
bencode: choose(bdict;bint;blst;bstr)
I'm really happy with how compact and straightforward this comes out.

  • Locked thread