Ah, the classic story. A solution so simple it didn't even cross my mind.
That makes it a lot less of a pain to undo, thank you!
Though it may be stating the obvious, <"0&> works in many respects like
the , and ,: operators when applied to a list of boxed lists, simply also
boxing each element of each list. The > also functions as a no-op when
applied to a single unboxed list. As such, you can compose such "pitted"
lists using the , and ,: operators themselves as normal, which may be
useful for incremental application. The following are all equivalent:
(<"0 a) , (<"0 b) , (<"0 c) ,: (<"0 d)
<"0&> a;b;c;d
(<"0&> a;b) , (<"0&> c;d)
(<"0&> a;b) , (<"0&> c) ,: (<"0 d)
~ Katrina
On 10/15/21 5:29 PM, Elijah Stone wrote:
One solution is: <@;"1
On Fri, 15 Oct 2021, Katrina Scialdone wrote:
On a little further play this morning, I found that while the simple
inverse <"0&>^:_1 doesn't work, there is a way to reverse the process
and regain the original list of boxed lists.
pitted =. <"0&> (];parens;depthOf) input
pitted
┌─┬─┬─┬─┬─┬──┬─┬─┬─┬─┬──┬─┬─┬──┬──┬─┬─┬─┬─┬─┬──┐
│(│(│a│^│2│) │+│(│(│b│) │^│2│) │) │=│(│c│^│2│) │
├─┼─┼─┼─┼─┼──┼─┼─┼─┼─┼──┼─┼─┼──┼──┼─┼─┼─┼─┼─┼──┤
│1│1│0│0│0│_1│0│1│1│0│_1│0│0│_1│_1│0│1│0│0│0│_1│
├─┼─┼─┼─┼─┼──┼─┼─┼─┼─┼──┼─┼─┼──┼──┼─┼─┼─┼─┼─┼──┤
│1│2│2│2│2│1 │1│2│3│3│2 │2│2│1 │0 │0│1│1│1│1│0 │
└─┴─┴─┴─┴─┴──┴─┴─┴─┴─┴──┴─┴─┴──┴──┴─┴─┴─┴─┴─┴──┘
<@:([:|:,&>)"1 pitted
┌─────────────────────┬──────────────────────────────────────────────┬─────────────────────────────────────────┐
│((a^2)+((b)^2))=(c^2)│1 1 0 0 0 _1 0 1 1 0 _1 0 0 _1 _1 0 1 0 0 0 _1│1 2
2 2 2 1 1 2 3 3 2 2 2 1 0 0 1 1 1 1 0│
└─────────────────────┴──────────────────────────────────────────────┴─────────────────────────────────────────┘
I'm not sure what the best use case of this is; reversing the process
doesn't have much point in debugging, but perhaps there's something
beyond simple debug output for which it would be useful. That said, if
anyone can find a way to simplify this "inverse pit droid", I'd be
delighted. As I'm quite new to J still, it's very likely I missed a
simpler way.
~ Katrina
On 10/15/21 9:36 AM, Devon McCormick wrote:
Katrina - this looks like this may be a useful extension of the work done
at the end of this essay: https://code.jsoftware.com/wiki/Array_Thinking .
Please keep us informed if you extend it further.
Elijah - I suspect Ken may be to blame for the axis specification. It
would appear that J's rank ideas reflect his more recent thinking on this.
On Fri, Oct 15, 2021 at 5:51 AM Katrina Scialdone <[email protected]>
wrote:
I'm aware of ,: for homogeneous lists =) The main reason I was searching
for a solution and
eventually found <"0&> was specifically to deal with non-homogeneous lists
(such as a string
and two lists of numbers), as well as to deal with arbitrary numbers of
lists easily. The
manual alternative I found and was seeking to optimize was something along
the lines of this
(potential forks aside):
(<"0 input) , (<"0 parens input) ,: (<"0 depthOf input)
The dictionary example you linked is quite interesting! The 'table'
definition in profile
implements something similar which I've used before. I'm guessing it's a
more recent addition
than that dictionary page?
*/~ table 1+i.5
┌───┬─────────────┐
│*/~│1 2 3 4 5│
├───┼─────────────┤
│1 │1 2 3 4 5│
│2 │2 4 6 8 10│
│3 │3 6 9 12 15│
│4 │4 8 12 16 20│
│5 │5 10 15 20 25│
└───┴─────────────┘
~ Katrina
On 10/15/21 3:32 AM, Elijah Stone wrote:
On Fri, 15 Oct 2021, Katrina Scialdone wrote:
<"0&> input ; (parens input) ; (depthOf input)
NB. you can remove redundancies here using a fork:
<"0&> (] ; parens ; depthOf) input
Its behavior is quite similar to ,[0.5] in Dyalog APL, which was the
inspiration for finding a J equivalent.
If your lists are homogenous, you can use ,: instead:
x=. i.5
y=. -x
z=. *:x
w=. -:x
x , y , z ,: w
0 1 2 3 4
0 _1 _2 _3 _4
0 1 4 9 16
0 0.5 1 1.5 2
(Whoever thought the axis operator was a good idea, I have no idea... :)
Is this a known technique, and is there a common name for this?
I don't know of a specific name for it, but using boxes to format tables
is definitely common.
The dictionary uses something similar to demonstrate the 'table' adverb
(https://www.jsoftware.com/help/dictionary/intro03.htm).
-E
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm