« first day (237 days earlier)      last day (2418 days later) » 

8:33 PM
Welcome.
How do you fancy finding primes until N?
 
like all primes in range 1..N?
 
You'll see.
 
range -> filter?
 
is first N ɩntegers.
 
So somewhat like range?
oh and it's prefix function huh
wait is APL in/pre-fix?
 
8:36 PM
Oh right. So APL has monadic and dyadic functions. Monads are always prefix. Dyads are always infix. All functions are right-associative.
 
oo okay
 
Most functions are "overloaded" to mean something both when monadic and when dyadic. There is never any ambiguity due to the strict associativity.
 
ah okay
 
So is ɩndices when dyadic, but we won't use that right now.
 
ah ok
is there a prime built-in?
 
8:38 PM
@HyperNeutrino No, but we'll make a primes finder.
 
ah okay
are we using range -> filter or another approach?
 
Dyadic is drop, it drops the first items: tryapl.org/?a=1%u2193%u237310&run
@HyperNeutrino Kind of filter.
 
Now let's define a tacit function. Tacit functions use a tree (or fork if you want) structure where the left and right parts form the arguments to the middle part (which therefore will be called dyadically).
In other words (f g h) X is the same as (f X) g (h X).
 
ah ok
 
8:42 PM
. is a dyadic operator. f.g is generalized inner product (substituting f for + and g for ×), while ∘.× is outer product as serves as a placeholder (i.e. take no further action). Outer product is the same as a table.
 
> Unable to open session file " /TryAPLServer/MiServer/ServerData/TAS000023.dcf"
 
@HyperNeutrino Uh oh; Try it online!
 
ooo
also I really like how APL formats things so nicely :D
 
@HyperNeutrino Yeah, it is intended to encourage exploring and "playing" with data.
 
Ah I see.
Apparently (⍳10) +.× (⍳10) returns 385
 
8:46 PM
@HyperNeutrino Yes, (1×1)+(2×2)+… or the sum of the squares of the first ten integers.
 
huh I'm slightly confused on this one
 
hence the dot .
 
so how does the first example (outer product) work exactly?
 
@HyperNeutrino That simply omits the combining function, and instead does all the combinations. It is kind of like two nested for loops.
 
oh so the circle is a special case?
 
8:50 PM
@HyperNeutrino Yeah. isn't a function, but rather a "space occupier" for .'s left operand, giving a related functionality. It is a slight oddity in APL syntax.
 
huh that is kind of weird, but okay, I see.
so ∘.+ would be an addition table?
 
@HyperNeutrino Yes, and so on.
 
ah ok :D
also tryapl came back to life
 
@HyperNeutrino Has historical reasons. We may replace it with a more regular syntax in the future. If it bothers you, you can do table←{⍺ ∘.⍺⍺ ⍵} which causes table to be a regular-syntax monadic operator, so +table is addition table.
 
ooh interesting! :D
 
8:52 PM
@HyperNeutrino The server was probably restarted. Development is ongoing…
 
what's with all the alphas
@Adám ah ok
also what is the weird w thing, is it the argument of the function iirc?
 
Tried APL a couple days ago. I'm addicted :p
4
 
@HyperNeutrino is the left argument, as in Alpha, the leftmost letter of the Greek alphabet. is right arg, as in Omega, the rightmost letter. ⍺⍺ is the left (and in this case the only) operand.
 
oh huh that's interesting
so the arguments need to be explicitly specified?
 
@HyperNeutrino Only for operators. Functions can take any of three forms: tacit, dfn, and tradfn. Operators can be only dop and tradop. But that is a bit much to go into now.
 
8:55 PM
ah ok
 
So, you may remember from TNB?
 
is a monadic operator, i.e. it takes a single operand (a function) on its left. APL operators are left-associative, so monadic operators are post-fix. (Dyadic operators are infix left-associative.)
 
huh so operators are l-assoc and functions are r-assoc?
 
@HyperNeutrino Correct. In practice, that works very neatly.
 
8:57 PM
@Adám can't understand why the many s act differently. Do they get passed down to the new function or what?
 
I see.
 
@dzaima notice the spacing (added for clarity) ⍺⍺ is a single entity which is the (left) operand. refers to the left argument.
@dzaima So X f{⍺ ∘.⍺⍺ ⍵} Y is the same as X ∘.f Y
 
@Adám ah. The same works for I assume?
 
X is left argument. Y is right argument. f is left operand.
@dzaima Yes. is right argument. ⍵⍵ is right operand.
f⍨ derives a new function which (when called dyadically) is identical to f except it takes its arguments in reversed order.
 
how could I convert a nested array to a shaped array? The difference is annoying me a lot
 
9:02 PM
f⍨ may also be applied monadically, even though f is dyadic. In that case, the single argument (which must of course be on the right) is used as both left AND right argument. Monadic f⍨ can therefore be called "selfie".
@dzaima monadic
Of course, the inverse ("shaped" to nested) is
The arrows indicate that the rank goes up vs down. Rank is the number of dimensions (or axes if you want). A (nested) vector (list) has only one dimension (axis). A matrix (table) has two.
@HyperNeutrino So, ∘.×⍨ is multiplication table selfie: tryapl.org/?a=%u2218.%D7%u2368%u237310&run
 
oo cool :D
 
As you can see, even derived functions can be operands to other operators. And now you can see why it is practical the operators are left associative.
(i.e. so you can "stack" operators)
 
ah that makes sense :D
∘.×⍨1 2 5
interesting hmm
 
Here is a simple function: Monadic ~ is logical NOT, i.e. 0→1 and 1→0.
Dyadic ~ is "but NOT", as a set difference. So 1 2 3 4~2 4 gives 1 3
 
ah ok
 
9:11 PM
is the (right) identity function. It points to the right (its result). (If you apply it dyadically, it yields its right argument unmodified, ignoring its left argument)
 
ah ok
 
of course gives the left argument unmodified.
 
mhm
what happens if you apply left identity monadically?
 
@HyperNeutrino What do you think should happen?
Remember that (f g h) X is the same as (f X) g (h X) so (⊢ ~ ∘.×⍨) X is (⊢X) ~ (∘.×⍨X)
E.g. (⊢ ~ ∘.×⍨)2 3 4 gives 2 3 because 4 was removed (but NOT 2×2).
 
I'm guessing that the left pointing one also is just identity when applied monadically?
 
9:15 PM
@HyperNeutrino Exactly. Superfluous as it may seem, it has some neat uses.
Now we are ready to put all the pieces together to get primes. 1↓⍳ is 2…N and the multiplication table of that has all the composite numbers (non-primes).
 
yay I just made a prime generator!
 
@dzaima Link? On TryAPL, you can hover over a previously entered line to reveal a "permalink" button (link actually).
 
@Adám there :p
I have no idea no idea what I was doing but it works :D
 
@dzaima Wow. That's not the solution I had in mind. How about (⊢ ~ ∘.×⍨) 1↓⍳
 
@Adám I don't know APL :p
 
9:21 PM
@dzaima I'm amazed that you managed to write that function. I'm still analyzing it.
 
I probably could've done better but I was too lazy to search for the appropriate functions or whatever they're called
it also says that 1 is prime (oh wait that's an easy fix - =)
 
what's the filter operator in APL
 
@HyperNeutrino /
 
isn't that reduce though
 
@dzaima Ah, Now I get it. That's very clever.
 
9:24 PM
@HyperNeutrino 1 0 1 / ⍳3
 
o ok
anyway gtg now, I'll try to get a solution when I come back. o/!
 
@HyperNeutrino / is reduction when the left operand is a function. It is replicate when the left operand is data (non-negative integers).
@HyperNeutrino Bye! Was fun.
 
I should go sleep, will try to comprehend your solution tomorrow
 
@dzaima OK. All the best!
 
 
2 hours later…
11:10 PM
@Adám Try APL I could probably shorten this and make it more APL-ish but here's Prime List 1 .. N
 
11:49 PM
@Adám yet, that would require complexity of n squared, while filtering each value by modulo against it's square root range is much less (see math.stackexchange.com/questions/422559/…)
I might be wrong about that, as it depends on implementation details (as well as the compiler used to compile the c source)
 

« first day (237 days earlier)      last day (2418 days later) »