The APL Orchard

apl.chat ― Learn, teach, ask, code, golf, & discuss usage. See ...
Apr 4, 2023 12:07
well, i can work with this. thanks for your help.
Apr 4, 2023 11:36
hold up, this works
f = apl.fn("{⊂⍵}⌺3 3")
print(f(apl.eval("4 4⍴⍳9", raw=True)))
i have to use raw to tell it to not do python conversion weirdness
Apr 4, 2023 11:34
in 3 3⍴⍳9?
Apr 4, 2023 11:32
this works. something weird must happen when you pass a function an evaluated expression.
f = apl.fn("{({⊂⍵}⌺3 3)3 3⍴∊⍵}")
print(f(apl.eval("3 3⍴⍳9")))
Apr 4, 2023 11:29
f = apl.fn("{⍴⍵}")
print(f(apl.eval("3 3⍴⍳9")))

prints 3. something weird happens when the function is passed the evaluation
Apr 4, 2023 11:25
didnt work to wrap the stencil in a dfn either
Apr 4, 2023 11:25
doesnt it? it works fine like this:
f = apl.fn("+⌿÷≢")
print(f(apl.eval("⍳6")))
Apr 4, 2023 11:21
this worked apparently
f = apl.fn("{⊂⍵}⌺3")
print(f(apl.eval("⍳9")))

i shouldve tested that. it seems this:
f = apl.fn("({⊂⍵}⌺3 3)")
print(f(apl.eval("3 3⍴⍳9")))
doesnt work
Apr 4, 2023 11:02
it seems eval statements work, but not the fn
Apr 4, 2023 11:01
works just fine
Apr 4, 2023 10:19
am i misunderstanding how to use this stuff?
Apr 4, 2023 10:19
simpler example with LENGTH ERROR that doesnt use my actual function

f = apl.fn("{⊂⍺↓⍵}⌺3 3")

print(f(apl.eval("3 3⍴⍳9")))
Apr 4, 2023 10:08
@finooiigee my thoughts exactly
Apr 4, 2023 10:08
wait, it only works in eval, not in fn.

f = apl.fn("{⍵-⍨({m←2 2⌷⍵ ⋄ ⊃((-∘m+⌿)÷(-∘1≢)),⍺↓⍵}⌺3 3)⍵}")

print(f(apl.eval("3 3⍴⍳9")))

it gives a LENGTH ERROR
Apr 4, 2023 10:06
im pretty sure i tried that
Apr 4, 2023 10:06
hold up {⊂⍺↓⍵}⌺3 3⊢3 3⍴⍳9 works now
Apr 4, 2023 10:03
@Adám monadically? yes. dyadically? i dont really know how to use them dyadically
Apr 4, 2023 10:01
right, missing ⊂ for 1)
is it just an @ thing to work that way with enclosed arrays? i feel like im missing something very fundamental when it comes to ⊂
yesterday i messed around with it a little and i could use it to kind of map over the left argument instead using something like {⍺ f¨ ⊂⍵}
Apr 4, 2023 09:57
@Adám i can test it
Apr 4, 2023 09:57
is there any way to make (0@2 2)3 3⍴⍳9 change the element in the middle of the 3x3 array to 0, instead of the middle row?
Apr 4, 2023 08:22
or actually, if none of that works, do you have a good algorithm or way to implement stencil, so that i can port the algorithm itself to python?
Apr 4, 2023 08:21
now i have a question. last week i mentioned i was going to make a thermophysics project with an apl backend. i have created the backend in apl, no problem, but it seems stencil of any kind doesnt work in pynapl. im trying to port the apl code directly to python with pynapl.
so i wonder
1) if you have a way to define ({⍺↓⍵}⌺3 3) without the use of stencil or
2) if you know a way to use stencil in pynapl.
Apr 4, 2023 08:17
i randomly found some videos on youtube (probably code_reports leetcode solutions) and was immediately enthralled by the mishmash of greek letters and other wacky symbols.
Mar 30, 2023 11:50
yes, i figured it out. thanks!
Mar 30, 2023 07:24
does it show the index of the elements or what?
Mar 30, 2023 07:12
hey so for a physics project im going to make a thermophysics simulator. my backend is going to be apl. ill use a 2d array of temperatures to represent a grid of temperatures. i want to change the temperature of tiles adjacent to tiles with differing temperatures. the quad diamond comes to mind.
({⊂⍵}⌺3 3) 3 3⍴⍳9
this gives me a nested array of adjacent tiles. im wondering how i can make the border values default to something else than 0, because i want 0 to be a possible temperature in the array. having the border values be something other than 0 which is outside of the domain of temperatu
Mar 18, 2023 07:42
@dzaima thank you for these solutions! i must say, the last one is very very beautiful.
Mar 17, 2023 17:54
ive got two bqn functions:
MedianOfSortedLists ← ({𝕩{2|≠𝕨 ? ⊑𝕩⊏𝕨 ; ÷⟜2+´𝕨⊏˜𝕩-1‿0}⌊2÷˜≠𝕩}∘∧∘∾)
FirstMissingPositiveInteger ← {⌊´1+/¬𝕩∊˜1+↕≠𝕩}
both as solutions to these leetcode challenges respectively:
https://leetcode.com/problems/median-of-two-sorted-arrays/
https://leetcode.com/problems/first-missing-positive/

im new to bqn, coming from apl and im wondering about some ways to refactor these expressions.

median-function:
first off, im not proud of the algorithm in and of itself. its quite imperative by nature and requires the ? if-like statement (which i love as bqns response t
Mar 3, 2023 10:29
that is very understandable. thank you for your help!
Mar 3, 2023 10:07
awesome! i can see why this alternative solution is not preferred, although it removes the duplication of the code. what irks me most with that solution is the repetition of the ones again, but so be it.

is this flipover combinator present in any of the other array languages, like J or BQN? does it have a combinatory logic equivalent? i dont know much combinatory logic, but i find it intriguing. do you think apl should maybe implement such a combinator, or would it not be useful as a primitive due to likely under-utilization?
Mar 3, 2023 09:15
today i looked up the vector product in aplcart and was surprised by the repeated code
((1∘⌽⍤⊣ׯ1⌽⊢)-¯1∘⌽⍤⊣×1⌽⊢)
looking at the train-tree in ride, the two sides of the minus-fork were identical, with the exception of the negation of the ones present in the rotate functions. i was wondering: is there really no good way to shorten this in apl? could newer languages like bqn do it? could we make a nice combinator to solve this issue? well, its not really an issue, but it would be neat to have something to make it even more concise. any thoughts?
Nov 20, 2022 08:16
okay, i see, thank you
Nov 19, 2022 23:36
but just not in an easy way i assume
Nov 19, 2022 23:27
yeah, true, i just wanted to see if i could compute it without changing to a dyalog interpreter
Nov 19, 2022 23:19
yes actually, and it threw an error saying it doesnt support dyading inverting of omega. does this mean its not implemented?
Nov 19, 2022 23:14
anyone have experience with dzaima apl? im using the android app as a calculator nowadays, and i started learning about matrices for solving sets of equations, and i was wondering how to find an inverse matrix, seeing as the domino isnt available in this version, as opposed to dyalog. any ideas, programmatic or mathematic?
Nov 17, 2022 15:20
or rather, a friend of mines solution
Nov 17, 2022 15:20
for those curious: its my solution to one of the abel 2022 math competition questions
Nov 17, 2022 15:16
okay, i see. thank you. im just golfing, so the performance isn't a big deal to me
Nov 17, 2022 15:12
is it possible to shorten the fork here even more? i feel like having two outer products is a little too much. (∘.+<∘.×)⍨1-⍨⍳10
Nov 17, 2022 15:11
i have a question:
Oct 25, 2022 19:56
awesome! thank you so much!
i really like where this path of ⍣ is leading, i feel learning to use it will be really useful. im excited!
Oct 25, 2022 19:46
ooooh, thats really clever. was my understanding of the function p correct? if i understand how it works ill likely figure out how to read it
Oct 25, 2022 19:36
i thought of the mathematical function analysis way of solving it, as well as thinking of a possibility of solving the problem by computing twice, but didnt want to do those. cool solutions, thanks!

about your last solution: what do the ⍺←⊢ in the dfns of p do? i havent played much around with combining tacit and dfn forms, as it might look like here.
i assume p works so that it takes a left function and left argument and maybe "binds" it to the function like ⍣ composes its left argument with its left function. p also takes a right function and argument, where the right function is the con
Oct 25, 2022 16:31
i should maybe note that ⎕IO←0 for all code so far
Oct 25, 2022 16:30
i thought about several possible workarounds for it, and this is maybe the best one ive come up with for now: ⊃1↓{⍵,⍨5×⊣/⍵}⍣{1e4<⊃⍺}2
it returns 6250, as i wanted.
i followed an example of a fibonacci generator, {⍵,+/¯2↑⍵}⍣n⊢1 to produce n+1 fibonacci numbers.
using the idea of trailing older ⍵-values i came up with the above solution.
now im just wondering how you could improve upon my solution, maybe using the same core idea.
Oct 25, 2022 16:15
hello, im messing around with recursion and attempting to do things without loops in apl. im currently tackling the power operator, trying to use it to give me the nth element of a sequence, provided the nth element is beneath a certain limit.
i have the mathematical sequence: {2, 10, 50, 250,...}
and i wish to get the last element of it before the elements go over 10000.
in this example, the value i would be looking for is 6250, as the next element after that is 31250, which is more than 10000.
Jan 11, 2022 17:27
@AlexB im learning about using bind, so its been creeping in all over my code
Jan 11, 2022 16:58
thank you @FawnLocke. i see why you like 1-⍨ more, i think i will use that from now on, as it makes reading from right to left a little more pleasant. good to know im getting better at creating quick, tacit functions
Jan 11, 2022 16:42
how would you write P(n) = n(3n - 1)/2 in an apl function, be it tacit or dfn?
i did
P ← .5×(¯1+3∘×)×⊢
could it be written better? im also pretty sure its better to write it out as a dfn, as that could make it a little clearer