Here's my progress so far:

   2 |.@(*"1) a=:i.2 3
 4 2 0
10 8 6
   (|."1) 2(*"1)a
 4 2 0
10 8 6
   2 |.@:(*"1) a
6 8 10
0 2  4
   |. 2*"1 a
6 8 10
0 2  4
   3 4 5<@#"0 i.3 
+-----+-------+---------+
|0 0 0|1 1 1 1|2 2 2 2 2|
+-----+-------+---------+
   3 4 5#"0&.> i.3 
+-----+-------+---------+
|0 0 0|1 1 1 1|2 2 2 2 2|
+-----+-------+---------+

I am trying to remove &. following these rules:

   NB. x u&v y ↔ (v x) u (v y)
   NB. u &.v is equivalent to the composition u & v
   NB. except that the verb obverse to v is applied 
   NB. to the result for each cell
   NB.(subject to the monadic rank of v)
   
   (<"1 3 4 5 )   #"0      (>"0  i.3)
|length error
|   (    <"1 3 4 5)#"0(>"0 i.3)
  
 The is one of my better tries to follow the directions.

Linda

-----Original Message-----
From: [email protected] [mailto:programming-
[email protected]] On Behalf Of Graham Parkhouse
Sent: Thursday, January 03, 2013 3:26 AM
To: [email protected]
Subject: Re: [Jprogramming] Atop continues to puzzle me

Subject: Re: Atop continues to puzzle me


This post was initially titled 'The benefits of function composition'

See my PS.

There are things you can achieve with function composition that cannot be
achieved so elegantly any other way:

   3 4 5<@#"0 i.3
+-----+-------+---------+
|0 0 0|1 1 1 1|2 2 2 2 2|
+-----+-------+---------+

This is what I want - a set of 3 0s, a set of 4 1s and a set of 5 2s.

This doesn't give me what I want:

   3 4 5#"0 i.3
0 0 0 0 0
1 1 1 1 0
2 2 2 2 2

Nor does this:

   3 4 5 ([: <"1 #"0) i.3
+---------+---------+---------+
|0 0 0 0 0|1 1 1 1 0|2 2 2 2 2|
+---------+---------+---------+

But this does:

   each
+--+-+
|&.|>|
+--+-+
   3 4 5#"0 each i.3
+-----+-------+---------+
|0 0 0|1 1 1 1|2 2 2 2 2|
+-----+-------+---------+

... but then &. is function composition.

The unavoidable problem with not using function composition in such
instances is that J turns the result from every execution of a verb into a
rectangular array. When a series of verbs is executed in succession without
composition, J has to produce a succession of 'properly finished' results
along the way. With composition, this finishing process is confined to just
once at the end of the process.

------------------------------------------------------------------------

PS I wrote this before reading Linda's recent post on 'atop continues to
puzzle me' (Wed, 02 Jan 2013 03:02:54 -0500):

> Here's another, hopefully simpler, example of my problem > with   @
> 
>     ]a=:?>:i.6
> 
> 0 1 1 3 1 5
> 
>    ]a=:=a
> 
> 1 0 0 0 0 0
> 
> 0 1 1 0 1 0
> 
> 0 0 0 1 0 0
> 
> 0 0 0 0 0 1
> 
>    ]b=:?>:i.6
> 
> 0 1 0 3 1 3
> 
>    a #@# b
> 
> 1 3 1 1   

Linda, this example is another illustration of the point I have made above.
Not using @, as you rightly suggest, we might expect

   # a # b
4

not to give 4 but  1 3 1 1. But no, for the reasons I have explained above.
a # b has to produce an intermediate rectangular result:

   a # b
0 0 0
1 0 1
3 0 0
3 0 0

But 6 of those zeroes are padding. If J didn't have to mould that
intermediate result it would look like

0
1 0 1
3
3

and the tally of those is 1 3 1 1!

I hope this is helpful.

Regards

Graham


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