« first day (407 days earlier)      last day (1128 days later) » 

4:25 AM
Another where, this time recursive (atom as base case): {,/(!#x)+&'x}
 
4:52 AM
@ngn - what's the purpose of |: in your soln? bounds check so that negative input doesn't throw? chat.stackexchange.com/transcript/message/54095075#54095075
 
5:03 AM
what flags can apply to lists? sorted, unique, grouped, step? thinking it may be worth preserving % for something that results in a flag if there are other properties that are useful to track
 
5:15 AM
ok i think this does where with no nesting:
{|\@[&+/x; +\0,-1_x; :; !#x]}
i admit i like the triadic case of @, sad it was removed from ngn/k
(above again assumes &i is already defined)
doesn't seem to be faster than the simple {,/x#'!#x} but maybe something can improve it
hmm seems to break when input ends with zero
 
6:04 AM
using (+/x)#0 looks to be faster than &+/x - the latter makes a binary-type list so needs to be converted. without the max-scan at the end, it trounces {,/x#'!#x}
 
6:43 AM
Guessing the max-scan is hard to parallelise... wonder if k can operate on array slices in parallel
 
7:27 AM
avoids the max-scan but goes back into each-y code {@[&+/x; (!'x)+0,-1_+\x; :; !#x]}
 
 
1 hour later…
8:51 AM
^ intuition for this one is that we have a single array and multiple threads? processes? are operating on different parts of it, where # things operating in parallel = #x. no idea if that's how it works under the hood; maybe deferred execution of ! would help. i'll try on k7
^ nope, not a lot
 
9:34 AM
can drop the first batch of indices but it doesn't help that much {@[(:/v)#0; (-1_v:+\x)+!'1_x; :; 1_!#x]}
 
10:20 AM
to sum up, still way off the native where:
 \t:1000 {@[(:/v)#0; (-1_v:+\x)+!'1_x; :; 1_!#x]}10000#2
4116
 \t:1000 {|\@[(:/v)#0; -1_0,v:+\x; :; !#x]}10000#2
1143
 \t:1000 {,/x#'!#x}10000#2
1692
 \t:1000 &10000#2
57
 
11:19 AM
what is a fast algorithm for 'where', in pseudocode? what prevents k from doing the same thing?
 
11:47 AM
ngn/k has:
A1(whr,P(xtA||xtX,et(x))P(xta,A y=gkv(&x);idx(x,Nx(whr(y))))
 x=N(gL(enla(x)));L n=0;F(xn,P(xli<0,ed(x))n+=xli)A u=aL(n);mr2(x,n=0;F(xn,Fj(xli,ul[n++]=i))u))
 
i do that: n:0;xn/(n+:I xp;xp+:4);xp:8+x;r:2 mk n;r8;xn/((I xp)/(rp::i;rp+:4);xp+:4);dxr
first count the number of elements with a +/ (i see i forgot to check for negative numbers, as ngn is doing), then set the elements with a double loop. this may be where an array implementation struggles, as the inner loop size depends on the value and is not fixed.
 
@ktye thanks! good to know there's not some super-insight i'm missing
a series of triadic amends should be able to do the same thing
 
12:02 PM
Does K have a rank conjunction (dyadic " in J)? If no, how can it reproduce the behavior?
 
@gnu-nobody do you have an example in mind? generally the adverbs each/eachleft/eachright are used for this kind of thing
 
Let's say I have a 4-D array, and want to add a matrix to all its elements (producing a 6D array) (I admit this is not a very useful thing though)
 
12:29 PM
what about 2x2 and 2x2x2:
try (1 2;3 4) + 2 2 2#1 or (1 2;3 4) +'/ 2 2 2#1
 
12:42 PM
man this is slow
 {{@[x; *y; :; :/y]}/ (,(+/x)#0) , +((0,+\-1_x)+!'x;!#x)}2 1 0 3
0 0 1 3 3 3
although interestingly - and aren't really sure what's going on here - this isn't as bad (still ~2-3x slower as the examples above though)
 
ngn
@chrispsn only to agree with the one you mentioned above it. isn't this (using `step) the one you want?
 
{+/((+/x)#0) {@[x; *y; :; :/y]}/ +((0,+\-1_x)+!'x;!#x)}1000#2
@ngn it's definitely faster than the other examples above - but still a way off native speed
and not sure if step has avoidable overhead
 \t:1000 {|\@[(:/v)#0; -1_0,v:+\x; :; !#x]}10000#1 2
843
 \t:1000 {1+(`step(-1,+\x)!-1,!#x)@!+/x:0|$[x~*x;,;]x}10000#1 2
924
 \t:1000 &10000#1 2
66
 
ngn
i don't believe you can match native where's performance with a k expression
 
just too much overhead for what's a relatively simple copying operation when expressed in c?
 
ngn
@chrispsn yeah. not "copying" though, more like "generating".
 
 
1 hour later…
ngn
2:13 PM
is there a way to get the version of a k9 binary from bash?
 
3:01 PM
@chrispsn the second algorithm seems competitive using ngn/k
 \t:1000 {|\@[(:/v)#0; -1_0,v:+\x; :; !#x]}10000#2
37
 \t:1000 &10000#2
19
 \t:1000 {,/x#'!#x}10000#2
931
 
@Traws good to know! i had tried an earlier version and got similar results but wasn't sure if things had moved on since then
does feel like k could be, as you said, somewhat competitive here - unless there's some SIMD or parallel/shared memory stuff going on that can't be matched
 
it's taken me a while to internalize arthur's latest mapping of / and /: to operations, but i think i get it now: where f is dyadic f/x is reduction and y f/x is each-right. where f is monadic, then f/:x is converge. where g is dyadic then y g/x is over with initial state y, and in general h/[x;y1;...;yn] is n+1-adic over with initial state x.
i had my doubts initially, but i think this is a HUGE improvement over previous k's.
 
y g/x - does that need a colon?
 
yes thanks typo
 
very glad that there's a way to specify initial state
 
3:09 PM
i wish i knew how to edit my posts
 
there's a dropdown menu if you mouse over the top-left of the box
edit is available for a limited time after writing
 
i don't see an edit option
 
huge improvement - for what reason? (i agree btw)
it goes away after a minute or so
 
ugh
correction: where g is dyadic then y g/:x is over with initial state y, and in general h/:[x;y1;...;yn] is n+1-adic over with initial state x.
as i said to arthur, personally i wouldn't mind always having to specify the intial state to over, so +/x would be flip-over and 10+/x would be plus over with initial state 10.
but if you insist on supporting +/ then make / do JUST THAT -- which is what he has done.
it's very clear, easy to teach to newbies, easy to state
/ ALWAYS takes a dyad. it's over without a left argument, each-right with.
 
ah interesting
also - do you know why rotate has returned? it's a new op for me (although am aware it appeared in earlier dialects)
 
3:18 PM
i asked arthur about that a few minutes ago. he said he'd never seen a real-world case of rotate, that it didn't make sense when processing data. i pointed out that i've used it frequently. e.g. 1!")(",... where ... computes the string of an expression. the alternative is ugly: "(",(...),")".
and in general, i've used it where i want to compute the extent and the direction of the rotation, as in f[x]!x:...
 
ah - delimiters
 
yes, not data processing, but general purpose programming (there's a difference there to be drawn, right?)
 
also raised by geocar when discussing XML processing in k4 i believe news.ycombinator.com/item?id=22524751
 
k4 has the lambda 'rotate' defined in terms of mod ..
but in general you want to use it infix
 
btw on !!x - if you're pulling out the domain argument for why rotate shouldn't go there, then that suggests !x should return list indices :P
i understand the argument that the length encodes that info, but numbers are often treated differently to sequences
otherwise we wouldn't need enum at all
if !x becoming 'list keys' and atoms having length are both ruled out by arthur, and there's a push to relegate odometer to a k-string in z.k or similar, then i'm coming around to your way of thinking
but still feel there's a nice symmetry if ! returns keys for both lists and dicts
and although shorter code may not be the goal, !#x comes up so often
still - happy to leave !L as odometer
 
4:23 PM
arthur seems to agree with me that odomoter isn't important enough to live on a primitive, and i think he's divided about whether !list should be !#list or #list, but leaning in the direction of the former. i think it's neater to have the related functions of domain, count, and enumerate all live on !x. (and i've never believed that #atom made any sense.)
 
4:41 PM
having !list return the indices raises the question whether list~(!list)!list. i.e. is (!list)!list a dictionary or a list? if the former, then !list is the domain of list only metaphorically. on the other hand, if it really is the domain, then e.g. 0 1 2!1 2 3 is a list, not a dictionary.
 
I like odometer as an operation but I'll freely admit that it comes up more often in code golf puzzles than real-world code and is easy enough to synthesize provided access to decode
 
 
1 hour later…
6:15 PM
Does K have the concept of conjunctions in J? Or do adverbs simply work all the time?
 
ngn
@gnu-nobody k has only 6 adverbs and no conjunctions
but it has first-class functions, so any function can be higher-order by accepting functions as arguments
 
really it's about 13 adverbs that just happen to reside on six symbols
 
 
2 hours later…
8:02 PM
@StevanApter I have hardly ever used rotate in general purpose programming.
Independent of syntax tweaks, it would be interesting to know there is a set of operations which are most commonly used. Sort of a reduced/regular instruction set for an array computer. RISAC!
 
@StevanApter I think it'd be great if you repurposed that K prettifier/minifier you wrote to gather statistics on the use of mondadic/dyadic/underbar verbs and verb/adverb compositions on a large codebase like the 1010data application. It would be an enormously valuable study to get real empirical measurements on a large codebase.
I think you'd get a very clear picture of which (if any) k3 verbs probably don't need to be primitives, and which underbar verbs might be common enough to warrant a symbol. Best to treat the IO verbs like underbars, too. I imagine that 4: is at least as common in that codebase as _vs
 
 
2 hours later…
10:25 PM
i don't believe that frequency of use is a good principle for sorting functions onto primitives. n: groups the i/o verbs, so even if one of them occurred far more often than some primitive, that wouldn't constitute a reason to displace that primitive and move the i/o verb onto the symbol.
the question which drives me is rather: what's the principle (or principles) which distinguishes primitive functions and ones which can be safely relegated to keywords?
what is it which all primitives have in common?
still, what you suggest IS an interesting little project
 
the k3 monads 5: and 4: have very little to do with IO
 
yes, but the i/o verbs should be grouped together in some distinctive symbol pattern
 
(string-representation and typecode, for anyone reading along who hasn't memorized this particular piece of trivia)
 
k3 gets those wrong
 
well then at any rate my suggestion is simply that for purposes of analysis you pretend 4: and 5: are in the same category as underbar builtins since their overloading on IO verb syntax appears to be entirely a historical accident
5: is probably used primarily for debugging purposes and I doubt it has many legitimate uses in the 1010 codebase. 4: is used all over the place for type dispatch
frequency analysis alone shouldn't drive the selection of verb behaviors- huffman-encoding the semantics of the 1010 codebase isn't the point. It can, however, provide evidence that certain verbs which have been given symbols are wasted. I think demonstrating that a given operation should be "upgraded" is harder to prove, because those are just as likely a short idiom peppered throughout the codebase (like cut string by character) as they are a currently-existing underbar builtin.
 
10:38 PM
i do believe the result would be useful to arthur. he was surprised when i gave him the parenthesis-rotation example.
 
ksi
11:05 PM
2020.04.16 (c) shakti
p1:{,/'@[;y,!y]\:x,,(#*x)#y}/(,0 1#0),!
p:{,/'((,(#*x)#y),x)a^@[&1,y#b;(b:y+2)*!a:y+1;0]}/(,0 1#0),!
\t:100 p 10
2314
\t:100 p 10
2101
\t:100 p 10
2134
\t:100 p1 10
2718
\t:100 p1 10
2614
a slightly faster but much longer permutations inspired by @dzaima, any golf interest on it?
 
ngn
yesterday, by Stevan Apter
avoid the prefix in @dzaima's solution with (0 1#0){,/'@[;y,!y]\:x,,(#*x)#y}/:!
 
ksi
@ngn oh sorry, didn't notice it
 
ngn
11:23 PM
@ksi are you in the google group? arthur golfed it down to (,/'%\:++,)/!
monadic % is 1-rotate in 2020.04.17. ++ will be a recognized idiom in the next version.
 
ksi
11:45 PM
@ngn oh, the mac version hasn't got updated for some reason. I just tried it on a linux box, great for having rotate. but i guess i just value speed more
 

« first day (407 days earlier)      last day (1128 days later) »