« first day (821 days earlier)      last day (146 days later) » 

9:07 AM
considering super trivial problems; "find the index of the last even number in an array". OK, I can do that, find the remainders of 2, iota-underbar to get the indexes, the neg-1 take.
And it's fast.
but in the back of my head, I'm thinking "in another language, I'd walk the array backwards and stop at the first match", saving a lot of work
assume the vector was a zillion numbers, and the last even one was three from the end, it would only be three comparisons, instead of making and throwing away a zillion item boolean vector.
 
Ven
.oO( clearly you should start by reversing the array :P )
 
reversing the array doesn't seem to make a difference (NARS2000), i imagine it still has to calculate every remainder of 2, before getting every index, before taking the first one
but reversing the array of ten million numbers doesn't slow it down at all, so I guess it isn't moving any data, and is just traversing it differently
which is cool
am I right in thinking a sufficiently smart APL environment could short-circuit that, see that the last one is needed, and work backwards?
am I right in thinking the way to do this manually might be an APL function to take the last N items, test them, and either run or exit, and window it along the big array?
or hmm, sure I've seen some "stop at the first" idioms around
 
Ven
?SufficientlySmartCompiler ..:)
 
SufficientlyPatientHuman ;)
 
Ven
9:23 AM
Oh, I was trying to access it using https...
 
I was wondering if it would be easier to be "sufficiently smart" with APL, since the pattern to recognise is "1 take" and that's a lot simpler than a ton of Java
that page / concept is why I said that
I adore the idea of the boolean matrix as an intermediate step for processing data
it's SO COOL
i just connected that 1 0 1 / 55 66 77 isn't any custom "filter", it's still general "replicate", just replicating some things 0 times.
 
Ven
Yes, APL has quite a few Eurekas like that one, each one feels like a deeper understanding of array programming
 
 
2 hours later…
11:12 AM
@TessellatingHeckler things like that are what APL is pretty bad at. it's why i believe there's still use for allowing impericalish fast code.
(need to get around to adding those some control flow constructs in my apl)
 
 
3 hours later…
ngn
1:50 PM
@TessellatingHeckler in apl you could do the same using recursion or a :for loop
 
 
1 hour later…
2:55 PM
Started playing with @dyalogapl to see where the #APL state of the art stands. Impressive! And the #Windows integration is incredible (APL IME, COM & .NET access, awesome Explorer preview handlers, etc.) Couldn't find a color-coded Dyalog APL US keyboard layout, so here:
 
 
6 hours later…
8:25 PM
I guess.. I should have thought of that! :)

numbers ← ? (1e7⍴100)
{ 0=2|numbers[⍵]: ⍵ ⋄ ∇ (⍵-1) } ≢numbers
stops in 2ms instead of 1.3s
 
@TessellatingHeckler of course, that comes at a huge cost - for 0,1+2×? (1e7⍴100) the simple ⊃⌽⍸0=2|n2 is 500x faster
 
:for I :in (≢numbers)..1 ⋄ :if 0=2|numbers[I] ⋄ I ⋄ :leave ⋄ :endif ⋄ :endfor
4ms (edit: oops, I made numbers larger so that doesn't compare)
@dzaima ok I've just clued in that that intends to make the array all odd, and force a long walk; why do you 0, at the start?
 
8:41 PM
{⍵∘{ 0=2|⍺[⍵]: ⍵ ⋄ ⍺ ∇ (⍵-1) } ≢⍵} 0,1+2×? (1e7⍴100) huh, this is 12x slower with the compiler than without it. i thought the compiler was made mainly for faster scalar operations :|
@TessellatingHeckler so there'd be an even number to find at all
 
oh, fair enough
is APL recursion prone to stack overflows? when I'm hitting LIMIT ERROR in NARS is that trying to recurse too many times?
 
@TessellatingHeckler Dyalog has tail call optimization, but if that's not applicable, it will quickly overflow
 
everything's a bleeping tradeoff :P
 
oh actually it doesn't quickly overflow, but it instead just keeps using more and more memory (probably meaning there isn't a stack size limit)
 
I was trying to read a text file earlier, 5GB, 55M lines, in my everyday PowerShell which does a lot of behind the scenes work for programmer convenience. Come back 14 hours later, 12GB RAM used, programs crashing from memory problems, still not finished. Rewrote in PowerShell to stream it, 45 minutes to complete. Used cat | grep > file in bash shell, 10 seconds to complete.
so it's not that I'm picking for performance problems in APL, it's just that I spend all my time caring about performance in powershell rather than doing substantial actual computation
I was really wondering if there was a kind of "scan-and-stop" primitive
reverse the array, scan some pattern until the first match, then don't do the rest
 
8:54 PM
@TessellatingHeckler problem is, without a Sufficiently Smart Compiler, it'd probably be worse than naive unoptimized C due to Dyalog APLs overhead for eachy scalar code
@TessellatingHeckler reversing the array would already make the algorithm O(n), making further optimizations less significant
 
hmm; what I said earlier earlier (with Ven) about reversing the array not adding any overhead, so I thought nothing was happening behind the scenes - I can see it now just trying that alone, reversing 10M items takes ~100ms
 
the way I'd probably do the optimized version is {T←⍵ ⋄ -∘1 ⍣ {~2|⍺⊃T} ≢⍵} - about the same speed as the recursive option
 
so NARS at least probably isn't leaving the array alone and walking backwards via some indirection magic (I guess)
 
@dzaima I haven't got enough skills for that version; I reached for the power operator for "looping and repetition" yesterday for a Fibonacci generator, but it's too advanced
APL's "simple" rules and evaluation order turn confusing with operators, it's no longer left to right
 
9:03 PM
@TessellatingHeckler (f⍣g) A applies f to the argument repeatedly until g called with ⍺ as the last result & ⍵ as the one before it gives 1
@TessellatingHeckler first of all in an expression operators bind their operands left-to-right, and then everything continues in the regular right-to-left way
 
T takes omega, which is the vector of numbers(?); subtract curried to 1 as a left argument to power. power does something. a dfn. the quantity of numbers in the array as a right arg to the dfn.
Inside the dfn is the logical inverse of the two-remainder of alpha (the -1 operation?)..
 
@TessellatingHeckler -∘1 is a function that subtracts one - it's the counter
 
@dzaima "A applies" ? intentional A or typo A?
and if intentional, what is it
> (f⍣g) A applies f to the argument repeatedly until g called with ⍺ as the last result & ⍵ as the one before it gives 1
sooo
f is the subtract 1 function, the argument is the length of the list of numbers, so that's how the counter works.
 
@TessellatingHeckler first it does f A, then f f A, then f f f A (of course, just keeping the last result instead of executing the chain again and again). So here it first tries ≢⍵, then (≢⍵)-1, then (≢⍵)-2, etc
 
power applies -1 to the counter repeatedly until .. g, which is the dfn, called with alpha as the last result (result of what?) and omega as the one before it, gives 1 (1 exactly or non-zero truthy, or is that not a thing in APL?)
 
9:08 PM
@TessellatingHeckler "(f⍣g) A" is a code block. also "to the argument A"
 
ah ok, so ⍺⊃T is T[⍺] ?
 
@TessellatingHeckler yep
@TessellatingHeckler result of the application. First it effectively tries (≢⍵) {~2|⍺⊃T} (¯1+≢⍵), then (¯1+≢⍵) {~2|⍺⊃T} (¯2+≢⍵), etc.
 
@dzaima oh font subtlety missed, gotcha
 
@TessellatingHeckler yeah, i use a theme and the contrast of the codeblock is huge for me. i hate the default codeblock contrast
(and really the fact that SE is in a light theme :p )
 
Is there a way to pronounce (f⍣g) ? it doesn't feel right to read it "f to the power g" or "f to the gth power", like I would read exponentiation 2^4
 
9:13 PM
the classical example of the operator is {1 + ÷⍵}⍣≡ 1 - the golden ratio. Repeatedly do X ← 1 + 1÷X until the values converge (i.e. the last two are equal)
@TessellatingHeckler I'd say "f until g"
 
@dzaima oh stag, if only it was called the "do {} until (condition)" operator, maybe it would never have seemed scary at all
OK, so by passing "match" as the primitive function for g, that's how and why power can run until the state stops changing, it's simply comparing the last and last-but-one result until they are the same, using that as the until condition
(as per the Conway's game of life video, where I followed the vocal description, but not really why it was working)
 
@TessellatingHeckler TryAPL has a step-by-step explanation of that in the "learn" tab
 
10:16 PM
@dzaima I have more tutorial tabs open than anything else ;) I need to pick one and stick with it. But also, I have read of it a couple of times before, but you introducing it into a problem I was already thinking about and had rewritten several ways, and being able to compare what it's doing and why, might have been the first time I have enough context to feel like I understand it
 
ngn
10:59 PM
@TessellatingHeckler in apl 1 is the only truthy value, 0 the only falsey. others cause an error if a boolean is expected
 
11:18 PM
@ngn that should simplify things. Kinda feel that "truthy" in powershell is way more nuanced than it should be.
@dzaima bugfix, I think; ≢⍵ needs to be 1+≢⍵ to stop it skipping over the last element if that's the even one
 

« first day (821 days earlier)      last day (146 days later) »