In my opinion, “do” and “undo” is not the idea/concept of &.
and doesn’t get across what it actually does.

&. is very helpful in a plethora of use cases
it is like transform, work in transformed space, transform back
(like working with conjugate matrices or in fourier space, e.g.)

From my personal experience (which is not much),
I’ve had most use of &. with v ∈ { >, |., |: }
but being aware of what it does for you will make
you find it’s useful in many more cases.

hope this helps


Am 13.03.20 um 08:55 schrieb ethiejiesa via Programming:
I'll contribute a little prose. Hopefully, it's helpful.

In this particular case, notice that > transforms your list of boxes into a 5x6
table:

         > (6?55);(6?55);(6?55);(6?55);(6?55)
     13 4 19 43 3 52
     10 1 4 46 52 11
     38 12 48 50 54 45
     36 54 39 35 53 50
     44 1 7 54 11 41

So, we should be able to easily "reverse" the above, meaning that dealing with
a 5x6 array is pretty much the same as dealing with 5 boxes of 6-arrays. Let's
just keep this in mind for now, and first try to generate this 6x5 table.

The key point of ? is that it's monadic and dyadic ranks are all 0, meaning
that it transforms an array of integers into a corresponding array of random
numbers:

         ? 50 6 $ 55
     ...

produces a random 50x6 array of integers each in the range i.55. This is not
quite what we want, but we first note that it can be more idiomatically
written:

         50 6 ?@$ 55

The utility of @ (and @:) become a lot more apparent when writing tacit
expressions. In general, x u@v y is equivalent to u (x v y), applying u "atop"
x v y, hence the mnemonic. (NB. The difference between u@v and u@:v is that
they produce verbs of different rank.)

The dyad n?m produces n random numbers without replacement. Your posed problem
is to generate 50 such lists, so conceptually we want to *reshape* the
arguments of ? into 50-lists:

         (50$6) ? (50$55)

but, better yet, as lots of verbs to ? will automatically reshape an atomic
argument to the shape of the other argument, so we can abbreviate the above in
one of two ways:

         6 ? (50$55) NB. or
         (50$6) ? 55

In the first case, the parentheses are not necessary due to J parsing rules, so
its more compact and idomatic to elide them

         6 ? 50$55

These three previous options should produce the desired random tables. Now,
putting things together, we just want to "redo" the boxing we did in the
beginning example:

         <"1 (6 ? 50$55)

Which should give the desired result. We need the
parenthesis to separate the 1 from the 6, otherwise J would interpret this as
<"1 6. Another way to break up the list lexing is like this:

         <"1 [ 6 ? 50 $ 55

Anyway, Hui's use of &. is even nicer. The key ideas is that u&.v first runs v
on u's aguments and then *undoes* v on the result. The really neat thing is
that > is a no-op on non-boxed atoms:

         > 42
     42

So the idea is to let > be a no-op on our input array of integers, then let ?
do it's thing, and finally *undo* > on *each* result. And since undoing > is
simply doing <, we get what we want.

         6 ?&.> 50 $ 55

The "each result" part above is exactly why this form is slick. ?&.> has the
rank of >, i.e. 0 0 0. This means that it will box each list produced by ? as
the integers are fed to it, which is exactly what we want in this case.

Very cool stuff. Rank!


Skip Cave <s...@caveconsulting.com> wrote:
Wow! Two completely different ways to generate multiple sets of random
integers. Roger used &. which I haven't really ever used or understood. I
will definitely need to understand &. for the future. Devon used @, which I
also haven't used very much. I need to find some practice and  training
examples to work on both concepts.

Skip Cave
Cave Consulting LLC


On Fri, Mar 13, 2020 at 12:04 AM Devon McCormick <devon...@gmail.com> wrote:

    6 5?@$55
Will give you a 6x5 table that is 6 independent rows of 5?55.


On Fri, Mar 13, 2020 at 12:52 AM Roger Hui <rogerhui.can...@gmail.com>
wrote:

    6 ?&.> 5 $ 55


┌────────────────┬─────────────────┬───────────────┬─────────────────┬───────────────┐
│47 28 45 25 8 36│22 40 23 20 11 49│15 16 42 38 4 5│50 45 38 37 13 28│42
4
36 7 23 49│


└────────────────┴─────────────────┴───────────────┴─────────────────┴───────────────┘

    6 ?&.> 50 $ 55
...


On Thu, Mar 12, 2020 at 9:49 PM Skip Cave <s...@caveconsulting.com>
wrote:

How can I generate the following result extended 50 times, without
explicit
looping?

(6?55);(6?55);(6?55);(6?55);(6?55)




┌───────────────┬───────────────┬─────────────────┬─────────────────┬───────────────┐

│13 4 19 43 3 52│10 1 4 46 52 11│38 12 48 50 54 45│36 54 39 35 53 50│44
1 7
54 11 41│




└───────────────┴───────────────┴─────────────────┴─────────────────┴───────────────┘



Skip Cave
Cave Consulting LLC
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm



--

Devon McCormick, CFA

Quantitative Consultant
----------------------------------------------------------------------
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


--
----------------------
mail written using NEO
neo-layout.org

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to