Inspired by Fraser Jackson below

    btable NB. produce boxed op table from lists of boxed arrays
1 : (':'; '(a: , y) , x ,. x u&.>/ y')

    NB. a, b, and c are lists of boxed rank 2 arrays

    a
+---+---+---+
|0 1|0 1|0 1|
|   |2 3|2 3|
|   |   |4 5|
+---+---+---+
    b
+---+-----+-+
|0 1|0 1 2|0|
|2 3|3 4 5|1|
+---+-----+-+
    c
+---+---+-----+
|0 1|4 5| 8  9|
|2 3|6 7|10 11|
+---+---+-----+

    c ,.btable b  NB. op is ,.
+-----+---------+-----------+-------+
|     |0 1      |0 1 2      |0      |
|     |2 3      |3 4 5      |1      |
+-----+---------+-----------+-------+
|0 1  |0 1 0 1  |0 1 0 1 2  |0 1 0  |
|2 3  |2 3 2 3  |2 3 3 4 5  |2 3 1  |
+-----+---------+-----------+-------+
|4 5  |4 5 0 1  |4 5 0 1 2  |4 5 0  |
|6 7  |6 7 2 3  |6 7 3 4 5  |6 7 1  |
+-----+---------+-----------+-------+
| 8  9| 8  9 0 1| 8  9 0 1 2| 8  9 0|
|10 11|10 11 2 3|10 11 3 4 5|10 11 1|
+-----+---------+-----------+-------+

    a (+/ . *)btable b   NB. matrix multiplication
+---+-----+--------+-+
|   |0 1  |0 1 2   |0|
|   |2 3  |3 4 5   |1|
+---+-----+--------+-+
|0 1|2 3  |3 4 5   |1|
+---+-----+--------+-+
|0 1|2  3 |3  4  5 |1|
|2 3|6 11 |9 14 19 |3|
+---+-----+--------+-+
|0 1| 2  3| 3  4  5|1|
|2 3| 6 11| 9 14 19|3|
|4 5|10 19|15 24 33|5|
+---+-----+--------+-+

    NB. Fetch {:: can retrieve arrays from these tables for calculation


> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]] On Behalf Of Fraser Jackson
> Sent: Sunday, November 20, 2011 3:19 PM
> To: Programming forum
> Subject: Re: [Jprogramming] table challenge in simple J
>
> In this thread there has been a focus on the visual appearance
> of the output.  But many of the functions fail what I consider
> a basic requirement in many programming situations.
>
> We can get visual identity, but the displayed objects may
> be of different shape or type.
>
> If the objective is purely to produce a pretty display then
> conversion to literal may be fine.  If it is to create
> a result which is to be used in further calculations it may not.
>
> After my post Dan Lettow suggested off line that I should
> incorporate ": in future solutions.  I looked at it, drafted
> a simple addendum to my post but did not post it.
>
> Now that we have some more solutions it is clear that Linda's
> problem specification is not really adequate in a J environment.
>
> (1) We need to specify the ranks of the function, or some
> very powerful defaults will be applied.
>
> If we want the full power of insert then the default is _ _ _  .
> I think there are strong grounds for wanting to preserve that.
>
> To handle what Kip called extreme cases, it was suggested
> that the arguments should be converted to vectors. That is
> fine for functions defined over a pair of numeric scalars.
>
> We might want to generalise that in many different ways.
> Suppose we had two tables of points with three coordinates,
> and wish to tabulate some function dependent on them -
> perhaps the distance between them.
>
> The function in table need not be of rank 0 0 though that
> is the commonest form used for illustration.
>
> Linda's problem was interpreted by most contributors as
> writing a function for rank 1  arguments on left and right
> and the table function as having rank 0.
>
>
> (2)If we are to preserve fidelity then we need to
> consider the type of the result.  Again several contributors
> have proposed solutions in which some of the boxed displays
> are literal.  That gives a pretty display, but it is not
> true to the original argument.  A sum of a numeric and
> a literal vector does not make sense.
>
> One thing we often find in J is that a structure which is
> based on the algorithmic needs is different from the
> best way of presenting the information.
>
> There is a need for a table function which preserves
> all features of the J objects, but also a need for a
> listtable function which displays the results using forms
> which assist visual interpretation.
>
> They are different needs and we should recognize them.  In
> statistical programs having both table and  listtable which
> operates on the result a table call is a common way of
> dealing with this.
>
> (3)  Sometimes it is easier to build up a set of results
> of interest and then assemble them.  Someone may have
> suggested it, but if they have I did not notice it.
>
>    table4  adopts that approach.
>
> table4 =: 2 2 $ '';];([:,.[);+/
>
>
> It works when the left argument is of rank 0 or 1 but it is not
> totally satisfactory visually and does not work at all
> well otherwise.
>
>
>
> Linda raised a very simple problem.  Her intuition that it
> would raise interesting and important issues has indeed
> been true.
> ----- Original Message -----
> ----------------------------------------------------------------------
> 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

Reply via email to