Hi TongKe, If you have not already read Chapter 6 of Henry Rich's J for C programming , it may be worth going over as it may provide insight into how all of this works. http://www.jsoftware.com/help/jforc/loopless_code_i_verbs_have_r.htm#_Toc191734331
Henry's Dissect tool in the jqt environment is another way to get a look inside the process. It is an addon and has labs that demonstrate its use. Cheers, bob > On Dec 12, 2017, at 6:11 PM, TongKe Xue <[email protected]> wrote: > > This answered a question I didn't even think to ask -- "what if the > cells have different ranks?" > > Thanks! > > On Tue, Dec 12, 2017 at 5:39 PM, bill lam <[email protected]> wrote: >> In J dictionary, verb >> >> The shape of a result is the frame (relative to the cells to which the verb >> applies) catenated with the shape produced by applying the verb to the >> individual cells. Commonly these individual shapes agree, but if not, they >> are first brought to a common rank by introducing leading unit axes to any >> of lower rank, and are then brought to a common shape by *padding* with an >> appropriate *fill* element: space for a character array, 0 for a numeric >> array, and a boxed empty list for a boxed array. For example: >> >> i."0 s=: 2 3 4 >'I';'was';'here' >> 0 1 0 0 I >> 0 1 2 0 was >> 0 1 2 3 here >> >> >> >> On Dec 13, 2017 7:59 AM, "TongKe Xue" <[email protected]> wrote: >> >>> Both explanations are great. Unfortunately, I asked an XY problem. Let >>> me re-ask as follows: >>> >>> I am trying to write a mini interpreter for J. >>> >>> How do we execute "i. (2 2 $ 1 2 3 4)" ? >>> >>> After parsing, and evaluating the (), we are left with: >>> >>> 1. execute monad "i." on tensor of (shape: [2 2], data: [[1 2] [3 4]]) >>> >>> 2. Next, we look up the rank of "i." and see that it is [1 _ _] >>> >>> 3. Therefore, we split [[1 2] [3 4]] into a frame, containing two cells: >>> cell1 = [1 2] >>> cell2 = [3 4] >>> >>> 4. We execute i. on each cell, getting: >>> cell1-output = [0 1] >>> cell2-output = [[0 1 2 3] [4 5 6 7] [8 9 10 11]] >>> >>> 5. At this point, I am expecting: error! tensor shape mismatch >>> >>> 6. Instead, J appears to just 0 pad the cells until they are of the same >>> size. >>> >>> Is there some fundamental principle why the 0 padding is happening, or >>> does J have a hard coded piece of logic that says: >>> when merging the output-cells of a frame, if the output-cells are of >>> different shape, 0-pad them all until they are of the same shape ? >>> >>> Thanks, >>> --TongKe >>> >>> >>> >>> On Tue, Dec 12, 2017 at 4:35 PM, Brian Schott <[email protected]> >>> wrote: >>>> The rank of monadic i. is 1 as determined by the following. >>>> i. b. 0 >>>> 1 _ _ >>>> >>>> Consider the following where the rows and column lengths of i. 1 2 are >>>> made to match those of i. 3 4. >>>> >>>> (i. 1 2),:i. 3 4 >>>> 0 1 0 0 >>>> 0 0 0 0 >>>> 0 0 0 0 >>>> >>>> 0 1 2 3 >>>> 4 5 6 7 >>>> 8 9 10 11 >>>> >>>> But that may not be explanation enough. >>>> >>>> On Tue, Dec 12, 2017 at 5:49 PM, TongKe Xue <[email protected]> wrote: >>>> >>>>> Hi, >>>>> >>>>> >>>>> I understand what (2 2 $ 1 2 3 4) does. >>>>> I understand what i. 1 2 does >>>>> I understand what i. 3 4 does. >>>>> >>>>> I have read http://www.jsoftware.com/help/ >>> jforc/loopless_code_i_verbs_ >>>>> have_r.htm#_Toc191734331 >>>>> >>>>> I understand the concept of verb-rank, of frames + cells, of >>>>> "promoting one frame to another if they share the same prefix." >>>>> >>>>> I don't understand how the 0 padding in >>>>> >>>>> i. (2 2 $ 1 2 3 4) works >>>>> >>>>> >>>>> What is the mechanism by which 0-padding is happening? >>>>> >>>>> >>>>> Thanks, >>>>> --TongKe >>>>> >>>>> >>>>> ==== >>>>> >>>>> 2 2 $ 1 2 3 4 >>>>> >>>>> 1 2 >>>>> >>>>> 3 4 >>>>> >>>>> i. 1 2 >>>>> >>>>> 0 1 >>>>> >>>>> i. 3 4 >>>>> >>>>> 0 1 2 3 >>>>> >>>>> 4 5 6 7 >>>>> >>>>> 8 9 10 11 >>>>> >>>>> i. (2 2 $ 1 2 3 4) >>>>> >>>>> 0 1 0 0 >>>>> >>>>> 0 0 0 0 >>>>> >>>>> 0 0 0 0 >>>>> >>>>> >>>>> 0 1 2 3 >>>>> >>>>> 4 5 6 7 >>>>> >>>>> 8 9 10 11 >>>>> ---------------------------------------------------------------------- >>>>> For information about J forums see http://www.jsoftware.com/forums.htm >>>> >>>> >>>> >>>> >>>> -- >>>> (B=) <-----my sig >>>> Brian Schott >>>> ---------------------------------------------------------------------- >>>> 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
