Inspired by Fraser, I offer a boxed matrix multiplication table whose 
entries can be retrieved (using Fetch {::) for calculation:

    NB. matrices here are non-empty rank 2 arrays

    mm =: (+/ . *)"2  NB. matrix multiplication

    overm =: 13 : '(<"2 x),<"2 y'  NB. for matrices

    bym =: 13 : '(a:,<"2 x),. y'   NB. for matrices

    ]a =: i. 3 2 2  NB. items are 2 by 2 matrices
  0  1
  2  3

  4  5
  6  7

  8  9
10 11

    ]b =: i. 2 2 1  NB. items are 2 by 1 matrices
0
1

2
3

    ]c =: a bym b overm a mm/ b
+-----+--+--+
|     |0 |2 |
|     |1 |3 |
+-----+--+--+
|0 1  |1 | 3|
|2 3  |3 |13|
+-----+--+--+
|4 5  |5 |23|
|6 7  |7 |33|
+-----+--+--+
| 8  9| 9|43|
|10 11|11|53|
+-----+--+--+

    ((<1 2) {:: c) -: ((<1 0) {:: c) mm (<0 2) {:: c
1


On 11/20/2011 2:18 PM, Fraser Jackson wrote:
> 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

Reply via email to