« first day (1224 days earlier)      last day (1413 days later) » 

1:19 AM
dzaima/APL solution to https://codegolf.stackexchange.com/questions/205425 by hardcoding equations not answers because why not (based on equations from https://explainxkcd.com/2313#Explanation):
https://dzaima.github.io/paste#0TVC7TsNAEOzvK7ZLIivgO5@dS0GkGCcmZ/A3UOUnEA1IEbLkCAkh99Cko0CIPv6T@xJmNw8RWev1zM7Mbma0DpvXh2Fot/fDvhsnfReaz5H0ejyWJjqDJuq7A2f6zpxo809z7jVGxyc4Cs3HETt9i13fMdD/ipSx0DyHdqej0P6gHeqwedNX4aUJ7fd@h6JjjDztvzCxfZ8DGOR3S3/jfb269cUNl9IvFr6ufFXVvlhVVZGX3pdlfp0XdV1US/zm9WowQs4lYh5nSqkZrY/2pGNFFFN8kRJZItSMaELkiKYgCS8lJCPCakPaSnWkp0TGKJGCZT8MJMwaSwmqJkoSJVLWZgKm8kwpycjA1jolseyZMJXGLL
 
1:34 AM
really obvious golf ಠ_ಠ:
https://dzaima.github.io/paste#0TVC7TsNAEOzvK7ZLosjge9i5FESKcRJyBn8DVX4C0YAUIUuOkBByDw19hOjxn9yXMLt5CMta783szOx5Rpu4fX0YxnZ3P@y7xPZdbD5H0uskkWZ8Bs247w6c6Ttzos0/zbnXGE1O8Dg2H0fsdBa7vmOg/xEpY7F5ju1XbL/RDHXcvumr@NLEdv8LcK9TDDzF3fsch0Fxtww3IdTr21DecFmFxSLUVaiqOpTrqiqLVQirVXFdlHVdVks883o9GCHhEhGPM6XUjDZHa9KpIkopvciIHBFqTjQh8kRTkISPEpIRYbUh7aR60lMiY5RIwbIfBiyzxpFF1UTWKpGyNhcwk3dKNicDW@eVxLKnZSpLWe5SchlXynlJLHXIZa2YO8@TEwOOd/B0zIUzaz05Q5mDGpxTfCHeGULkOkkBi7EJXzxXcl3cCDtjKyfO0ILlCK8PDgZyy6pcBryDFCRp/Mk/#dAPL
 
 
2 hours later…
3:32 AM
@Adám Recently I've been wondering how Dyalog's (floor) and (gcd) exactly work on complex numbers, and the rationale behind that. (A general intro to complex numbers and complex arithmetic would make a good topic for the Cultivation too, I guess.)
 
3:45 AM
^ (and, probably, some application of complex numbers to grid problems too)
 
 
1 hour later…
5:13 AM
@Bubbler Floor and GCD.
 
@Adám So they are how Dyalog APL and J work on complex numbers?
 
Yes, although both have added TAO so complex numbers can be graded.
 
5:28 AM
Are there any other APLs that implement complex floor?
 
@Bubbler NARS2000, and btw, very relevant.
 
 
2 hours later…
RGS
7:20 AM
@Bubbler +← 1
 
 
3 hours later…
10:11 AM
(/me agrees with @Bubbler regarding Complex Numbers as a possible Cultivation topic.)
 
10:44 AM
How would I create a new namespace in the )editor? Or isn't that the way? I get a "Can't fix object without a name" when I try:
:Namespace Test
:EndNamespace
 
@xpqz You have to open the editor, indicating that you want a namespace: )ed ○Test
@xpqz (btw, did you APLcart it? — I'll add "new" as a keyword.)
 
(Use it as SomeNS f 'NewName')
 
@Bubbler Ah, you've done the AoC! I just finished 2015, and now half-way through '16...
 
@xpqz Yes, but falling behind by large margin (just almost finished 2015 with some holes, and not yet into 2016)
 
@Adám I didn't, this time -- didn't strike me as an APL-howto, more a tool-specific. I did trawl through the Legrand book and the Dyalog docs, but my hitrate is lower there I find.
@Bubbler I daren't look at your code...
 
10:51 AM
Oops, btw, it is and not of course.
 
Are these incantations in the docs somewhere I can't see, or age-old APL-lore?
 
@xpqz It is exactly a how-to: "how to create a new namespace in the editor". However, yes, tooling and language are intertwined.
@xpqz Yes, click the (?) in APLcart!
 
:D
 
@Bubbler But that only establishes the namespace, doesn't edit it.
 
So as a casual observation of course the logarithm glyph means new namespace :)
Keeps the new learners on their toes.
 
10:57 AM
Yeah, while a couple of them make sense (∇∊) most I have absolutely no idea whence they came.
I'd think /, or at least / would be more mnemonic for matrix/vector.
Hey, maybe I understand // for class/namespace/interface now.
A class doesn't expose its content (no visible star) like a namespace does (exposes its star), and an interface is like a mini-class that can't stand on its own (mini ).
 
So if I make a namespace this way, how do I save it to a text file in RIDE?
/me looks in `cart
 
@xpqz Do you want to maintain synchronisation between the text file and the namespace?
@Adám Should have called it aplcart.it?
 
Well, I have a few utility routines I want to be able to reuse as a convenient code unit. I'd exect it to be largely static once completed, so I'd ]load or ⎕CY it when needed (or however you import a namespace into your session.
I am probably reaching for concepts more familiar to me in my day-to-day languages perhaps.
Python's "from .foo import Foo" imports the class Foo from the ./foo.py file
 
@xpqz No, that's fine. You should probably use Link, but you might also want to look into :require and :import. Anyway, myns{⎕FIX'file://',⍵⊣⍵ ⎕NPUT⍨⊂⎕SRC ⍺}'path/filename.apln' will put your namespace code into a file and keep it synced.
I'll add all three to APLcart.
 
What is Link?
 
11:12 AM
@xpqz A system to maintain source in text files. If you have some source files in mydir, you can do ]link.create myutils /path/mydir
 
11:26 AM
Right. So that ]link statement, what happens? It doesn't seem to actually create something, as far as I can detect.
Linked: #.utils → /Users/stefan/src
I should probably read up on this.
 
@xpqz If your utils namespace has content, it should have created corresponding files in …/src
 
I just typed the link.create, thinking that would create a skeleton file for me, but it's the other way around, I see, reading a bit -- it's the link that's created, not the file to be linked to.
...which is what you said, reading it again.
 
12:01 PM
ಠ_ಠ my second keyboard reader wasn't active
 
 
2 hours later…
1:54 PM
CMP: Did you ever want APL's output to go to a pane separated from the session input? (A little like Code vs Output on TIO.)
 
@Adám - I haven't, because I haven't (yet) been doing any "serious" programming in APL, but I can conceive of wanting the possibility.
 
@Adám That very much defeats the purpose of a REPL (and non-REPL use-cases shouldn't be using a REPL)
 
@dzaima How so? It is still a Read-Evaluate-Print-Loop, it just outputs to a different pane.
 
@Adám the purpose of a REPL (as far as i'm concerned) is to be able to see outputs of expressions, and the two being separated makes multiple outputs confusing to read (and even harder to match)
what I would however like is a mode where there's a tab whose code I can evaluate at any point and see the output of only that, pretty much as in TIO (note specifically clearing the output before re-execution)
 
2:12 PM
I enjoy REPLs for their friendliness as I'm still learning to program.
 
@dzaima Good point. I can do that.
@dzaima Hm, but does that window need access to your general workspace?
 
But I'm stuck using a chromebook so I have to use repl.it and the APL there has only a repl, too bad
 
@dzaima What about a pane that shows input and output like normal, but you type into a session that doesn't show output?
@Wezl I wonder if you can run a Pi interpreter on it.
 
@Adám personally i would maybe even make it do the equivalent of )clear at the start but that'd probably make many many people mad (being able to view the resulting namespace in a separate REPL window would probably be nice too)
 
@dzaima So you'd really like a separate interpreter window, that just has the special behaviour of having a single input-output pair, and no log?
 
2:17 PM
@Adám chromebooks aren't that horrible but this is a restricted chromebook so all I have is Chrome browser basically...
 
@Adám yes, and, optionally, a REPL window separately after execution for debugging/playing around
 
 
@Wezl You could get someone to run APL remotely for you, and then you can RIDE into it.
@Wezl TryAPL might be more friendly.
 
I tried getting Dyalog up on a spare RazzyPi a while back -- the interpreter runs fine, but not RIDE -- some version of some dependency not working. Also couldn't figure out how to connect my laptop RIDE session to it, but got distracted before i could figure it out.
Anyone else got this setup working?
 
@xpqz There's always the option of the interpreter serving RIDE to the browser, which then shouldn't have any dependencies.
 
2:24 PM
@Adám might be worth showing an example here, it took me to go back to the 18.0 intrroduction video to see that I need to put an = sign between load and the filename..
(also still no dyalog --help (nor dyalog --version but that's less important))
 
@dzaima Yeah, I hate that our docs often describe things without any example code, leaving you to guess the syntax.
 
@Adám well, there is the usual right-of-title (where you'd see R←X-Y) that'd imo be perfectly suitable for dyalog load=…
 
@dzaima It should go here though.
 
@Wezl I recommend forking this and running on Gitpod
Then you can run Dyalog in the cloud and access it via RIDE in the browser.
 
Ah yes ^ is very nice. I've tried it. Very easy to use.
 
2:29 PM
and it seems there's still no way to, from the command line, execute a lone file with this as its contents
 
@dzaima 18.0 can do that.
Welcome to APL Cultivation!
 
@Adám how?
 
@dzaima Let's address that afterwards.
 
cool
 
So, first thing is subject.
We've had the request for how to plot simple things from inside APL. For that purpose, I've invited a guest speaker for the next lesson. He's the expert on this.
 
2:33 PM
\o/
 
Then we have a request for complex numbers.
Now, I'm no big expert on that, so we can either wait until RichardPark has time to be a guest speaker, or I can try it now.
The last suggestion was basic GUIs. In my opinion, there's really no such thing as basic GUIs…
So, any other suggestions for today, or shall we do complex numbers?
 
(/me is all for complex numbers...)
 
I guess I can help a little if we go for complex numbers.
 
Complex numbers it is. Let's do this as a team effort.
Let's take the very basics first. The notation.
 
I'll pop in and out but am no expert either
 
2:37 PM
Instead of a+bi or a+b×i, APL uses aJb for scalar atomic complex numbers.
I.e. 3+4i is 3J4 and i is 0J1.
The arithmetic functions support complex mathematics where sensible.
Of special interest are monadic + and | and the circular functions k○Y
Monadic + is the complex conjugate, i.e. a+bi → a-bi
 
Is that an actual capital-letter-J?
 
@xpqz It is. You can use lowercase too for input. There's no ambiguity as there must be one or more digits (or .) before it.
 
Also, the notation supports e-notation on both sides, e.g. 1e2j3e4
 
2J4*0.5

1.79890744J1.111785941
Nice
 
2:41 PM
Yes ^, and of course signs: ¯1E¯2J¯3E¯4
 
nice easter egg coming up in this lesson
 
We can combine a real and imaginary parts with re+0J1×im but since the complex numbers are atomic (simple scalars) we need a way to split them.
For this we have 9○Y and 11○Y which would be Re(Y) and Im(Y) in traditional notation.
You might think it odd that we have numbered functions (like the trigonometric functions; sine and cosine are 1○Y and 2○Y) but it can actually be really neat because is a scalar function.
 
Of course :) 9 for real, 11 for imaginary -- totally natural....
 
@xpqz Reasons…
This means that we can split a scalar complex number with 9 11○Ys
Challenge: Let's say we have a vector of complex numbers Nv←2J3 0j1 10 then how might we get a 2-row matrix with one row for the real parts and one row for the complex part?
 
9 11∘.○Nv
 
2:49 PM
Perfect.
 
Now it makes sense.
 
Challenge: And if we have an array N←2 2⍴2J3 0j1 10 0 and want a two-element vector where each element has the same shape as N but the first has the real parts and the second the imaginary parts?
 
9 11○⊂ right?
 
That's it. Scalar extension is nice.
Does everyone understand how Bubbler's solution works?
 
No.
 
2:53 PM
It can be either a tacit function (9 11○⊂)N or the expression 9 11○⊂N though the outcome is equivalent.
First we enclose N which makes it a scalar.
Then we pair that scalar with a vector (9 11) as arguments to a scalar function ().
 
@Adám It becomes equivalent to (9○N)(11○N) due to scalar extension, right?
 
Yes, this makes APL do a scalar extension: 9 11○(⍴9 11)⍴⊂N or 9 11○N N or (9○N)(11○N).
Now, if you're familiar with the trigonometric functions, you'll know that negating the left argument of gives you the inverse function. E.g. sin is 1○Y and arcsin is ¯1○Y.
So 11○Y extracts the imaginary part into a real number. ¯11○Y will "put back" a real number into its imaginary place:
    ¯11○3
0J3
Of course, it can't restore the real part, as that was discarded. So…
Challenge: Given our 2-element real-and-complex vector from above, how can we reconstitute our original N?
 
I was exactly thinking about it...
 
Just for clarification: You want to convert (2 0)(3 1) back to 2J3 0J1?
 
Yes.
 
3:01 PM
⊃+/¯9 ¯11○m
 
Yes that'll work. ¯9○Y also "puts" back like ¯11○Y does, but it puts back into the real part, which means no change. So ¯9○Y is an identity function.
Any other ideas?
Also, is it clear how Bubbler's code works?
 
Yes
 
Yes.
 
If the input was a matrix, I'd suggest ¯9 ¯11+.○m instead
 
Yes, that'd be the inverse of the 9 11∘.○Y we had originally.
If you deal with complex numbers a lot, you might want to define J←{⍺+0j1×⍵} which will then allow you to write a J b to form aJb, and so ⊃J/vec for this challenge.
 
3:06 PM
Or 0j1⊥⊖↑v for the sake of creativity
 
I was actually thinking of that to allow for combining variables into complexes; you can't write aJb tp make a complex number from the variables a and b.
 
@Bubbler Sure, but that'll only work with simple arguments.
@JeffZeitlin Right. One might even argue that APL could use a "J" primitive…
 
Funnily enough, the language J has that exact primitive
called j. (j dot)
 
@Adám - I wouldn't disagree with such an argument...
 
@Bubbler Anything less would be ironic.
 
3:08 PM
... Although there is the problem that it would "block" having a variable named J
 
@JeffZeitlin Right, it would need to be some sort of symbol, not a valid character. e.g. or or something. Some APLs let you use the name .
Now, complex numbers are not just for hard-core mathematicians. Sometimes they are convenient to use as simple scalar 2D coordinates, where the real part represents offset along one axis, and the imaginary part along the other.
One benefit in doing so is that some formulas become vastly simpler with this representation.
Let's say e.g. we have two points in 2D space (a,b) and (x,y) and we want to compute the distance between them.
Challenge: Do that! ^
 
Can we write aJb and xJy?
 
Eventually, but first try it with the separate numbers.
 
You want the Euclidean distance, not the Manhattan distance, correct?
 
@JeffZeitlin Correct.
For example, with ((a b)(x y))←(4 6)(1 2) we want 5.
 
3:17 PM
4J6{(0.5*⍨+×⊢)⍺-⍵}1J2
 
Hint: monadic | is magnitude, which is the distance from 0.
 
@JamesHeslip That gives you the result, but 1) you used complex numbers, 2) that's way more complicated than needed when using complex numbers.
 
@Adám Sorry, I'm only half paying attention. Supposed to be working :D
 
|¯9 ¯11+.○x y-a b
(I'm really hooked with that +.○)
 
Sure sure, now you're using complex numbers again. My point here was to show how much simpler it is than when not using complex numbers.
 
3:20 PM
Oh.
 
OK, if I assign a←4 6 and b←1 2, it works if I use 0.5*⍨+/2*⍨a-b
That's kinda ugly, though...
 
@JeffZeitlin Yes, that's what I was looking for. You don't need the assignments though:
      0.5*⍨+/2*⍨a b-x y
5
 
@JeffZeitlin Little golf: you can use +.×⍨ for +/2*⍨
 
Stranding FTW.
And now we've already seen it done with complex numbers, but let's rewrite it given (u v)←4j6 1j2
 
|u-v
 
3:23 PM
Yup. That is a bit cleaner, and even lends itself nicely to a 2-train: Dist←|- ⋄ u Dist y
All clear on how and why that works?
 
With no one responding, I'd say yes
 
I guess.
OK, now imagine you need to represent some vectors in 2D space. 3j3 would point north-east.
We can now rotate the pointer 90 degrees counter-clockwise, with 0j1×3j3:
      0J1×3J3
¯3J3
Now it points north-west instead.
Using 0J¯1× will rotate clockwise instead.
 
And monadic - would rotate 180 degrees
 
Yes, of course, but negation is also multiplication by ¯1 (which is 0J1*2) and so rotation by 180 degrees, giving us the oppositely pointed vector, and further multiplication by 0J1 (i.e. to 0J1*3) is 270 degs.
 
Yeah.
 
3:34 PM
This means we can get the four corners with 3j3×0j1*⍳4.
Similarly, we can get the four cardinal directions with 3J0×0J1*⍳4
     3J3×0J1*⍳4
¯3J3 ¯3J¯3 3J¯3 3J3
     3×0J1*⍳4
0J3 ¯3 0J¯3 3
 
Some more cheatsheet about vectors: +v is reflection by x-axis, +-v is by y-axis, |v is length, ×v is unit vector in that direction
 
@Bubbler Oh well, you type faster than me. Well done.
@Bubbler Also k××v is vector of length k in that direction.
 
If you want to scale vector v with scaling factor k, do k×v
And if you want to rotate vector v by the angle of vector w, do v××w
 
Yup. All nice ones.
You can represent a number of "moves" in 2D space as complex vectors, say moves← 1j2 0j3 ¯1j0
This means move 1 right and 2 up, then 3 right, then 1 down.
Challenge: Where do we end up?
 
(Waiting for a minute...)
 
3:41 PM
@Bubbler Yeah, this one is too easy for you, but I have follow-up challenges to it.
 
+/moves (assuming we start at zero)
 
Yup. Now what points did we pass through?
 
+\moves
 
Good, although you might want to say +\0,moves to include the origin.
Now given our path←0 1J2 1J5 0J5 then what steps did we take?
 
2-⍨/path
or +\⍣¯1⊢path, though this one gives the initial 0
 
3:46 PM
Very good.
OK, before we finish, there's one more aspect of complex numbers to address.
Sometimes, it is convenient to deal with the angle (upwards from due east) and magnitude (pointer length) instead of the "coordinates".
We can already get the magnitude (absolute value) with |Y but the angle (or phase) is 12○Y.
Now remember how convenient it was to use the scalar function with a 2-element left argument 9 11.
 
(Side note: the 12○Y is the one called "atan2" in other languages.)
 
@Bubbler (Remind me to add that to the primitive on APLcart)
For that same reason, |Y exists as argument, which is 10 of course. So 10 12○Y gives you the magnitude and phase.
And of course we can use 10 12∘.○Y and 10 12○⊂Y like before.
 
Cute
 
How about the other way, if we have an angle and magnitude and want to combine them into a single complex number?
Remember how we used {⍺+¯11○⍵} before. This is then {⍺ׯ12○⍵}.
Or we can go with Bubbler's style: ¯10 ¯12×.○Y
 
Yeah. Though the definition of ¯10 isn't well justified compared to ¯9 ¯11 one...
 
3:56 PM
True. Still cute.
So, I think that just about covers it. Any questions?
OK, before we finish: APL Cultivation is every other week. Is there interest in short informal video meet-ups on the other weeks?
Thank you so much for participating. Special thanks to Bubbler for assisting. Look forward to a guest speaker on plotting in APL, in two weeks.
 
I'd be interested, but can't guarantee ability; I'm technically working from home right now.
 
Note to later readers: If you're interested in a video meet-up, ping me. If we have enough people, we'll do it for the last 30 mins before the regular session end-time.
 
4:13 PM
@Adám Oh, we already have atan2 entry using 12○.
 
just noticed that it's possible to view some of Dyalog's inverse logic. For some reason i had assumed that wouldn't work. ¯\_(ツ)_/¯
 
(For what it's worth, complex numbers using magnitude (r) and phase (theta) are notated in TMN as either r cis theta or r*e^i*theta (APL for the latter is r×*0J1×theta)
 
@Bubbler - Yes. But ¯12○ is 'opaque' as compared to *0J1×
Just clarifying the "expanded" TMN, which would normally be written with i and theta as superscripts, no caret, and no multiplication signs.
 
4:29 PM
@Adám for reference, my workflow with dzaima/APL is to write "proper code" in a text file and evaluate it in a REPL (with )ex path/to/file), play around, update file, and re-eval the file in the REPL, repeat. When it comes to using code, i can do apl -f file to launch (which exits upon finishing)
 

« first day (1224 days earlier)      last day (1413 days later) »