J ammend adverb } 
Author Message
 J ammend adverb }

Donald McIntyre's article "Mastering J" in APL91 p270 gives following example
which is supposed to change element 3 4 from 22 to 100:

   m=. i. 6 6
   (<3 4){m
22
   x=. 100  
   x (<3 4)} m

However I get "domain error" using J6.2. Is this a bug?

The best sentence I have tried which works is:
   x ((<3 4){i. $m)}m
This seems rather complex. Can anyone suggest anything simpler?
--

Harvey Davies,
CSIRO Division of Atmospheric Research,    Voice: +61 3 586 7574
Private Bag No. 1, Mordialloc,               Fax: +61 3 586 7600



Mon, 08 Jan 1996 12:48:02 GMT  
 J ammend adverb }
I spoke  to Ken  Iverson  this morning about the same problem with amend.
I'm using J6.2 and
I found out last night (independent of Harvie) that
amend

 x u } y

will only  work   if u is  a verb that returns the correct
indices.
Dr. Iverson fired up the OFFICAL 386 version and it ran properly.
I'm using a Linux PC with Raul Miller's Diffs' to the source code,
Have other's seen this problem?
and on what systems..

=======================

also I'd like to use amend to allow me to fill the main and off  diagonals
of  matrices with interesting stuff.
here is a verb that will work on the first off diagonal


NB.                                                indices
NB.                                     rotate the ROWS once (hardwired right now)
NB.                   run the axes of the main diagonal together
NB.  drop the last index

Now ,
maybe my problems stem from a bug in my version of J (no fault of ISI)
but does anyone have any suggests of the format that would most conveniently
allow the offset to be specified on invocation?
ie
x 2&u }y
to amend the 2nd off diagonal of y  with x (of course without modifying y)

Ira Ekhaus



Tue, 09 Jan 1996 00:28:45 GMT  
 J ammend adverb }
|>
|> Donald McIntyre's article "Mastering J" in APL91 p270 gives following example
(old indexing example)
...
|> However I get "domain error" using J6.2. Is this a bug?

amend changed over the course of its existance, so very old stuff
won't work.

|> The best sentence I have tried which works is:
|>    x ((<3 4){i. $m)}m
|> This seems rather complex. Can anyone suggest anything simpler?

This question comes up periodically, due to the absence of the good
old APL indexing and reassignment from J. The short answer is no,
there is no really simple built-in construction that does the trick.
Here are some ideas we've discussed here before that help:

I use

via

or
   x (i&index y) } y
which looks a bit better. There's also (from E. Weg)

Now you can write:
   1  _1(>1 2; 2 4)amind a  
to replace arbitrary cells. Your example then becomes

or
   100 (3 4) amind m

Hope this helps.
--
Sam Sirlin



Tue, 09 Jan 1996 00:24:46 GMT  
 J ammend adverb }

Here is an old post which answers your questions and
answers a few other which new J programmers often have.

You will be interested in question number 4 on selective
reassignment. These verbs are variants on your solution
but dont create a matrix (table) of the same shape as the
right argument for getting the indices.

  As an aside, I see that Sam posted some solutions. There
  have been several threads on this topic on the Internet
  in the past and I recall that Sam's solutions were
  more efficient that the ones I have below. But fundamentally
  all of these solutions are structurally similar.

Regardless of which approach you take, I think you'll
find that it takes more memory to invoke selective
reassignment than it does to invoke, y =. y + 1 .
My understanding is that ISI expects to have a more efficient
amendment verb in the version of J in their October release
(which will include a de{*filter*}). But in the case that they
don't get to it, I may be introducing some C programs which
implement efficient selective reassignment myself.

=======cut here======
NB. 1. How do I read a text file into a character table?

NB. 2. How do I reassign a column in a table ?

NB. 3. How do I reassign a row in a table ?

NB. 4. How do I implement selective reassignment ?

NB. 5. How do I use explicit definition to write a program which
NB.    loops (branches) ?

NB. =================================================================
NB. 1. How do I read a text file into a character table ?
NB. =================================================================

NB. Try :

NB. Usage is :
NB. Read 'filename'

NB. =================================================================
NB. 2. How do I reassign a column in a table ?
NB. =================================================================

NB. Comment. In a language like APL row reassignment into a
NB. table is accomplished using bracket notation. Ken Iverson
NB. felt that this lead to asymmetries in the language.
NB. In J column and row reassignment can be accomplished
NB. in a variety of ways.   The list below is not
NB. comprehensive. It is designed so that one can can study
NB. the examples and experiment with various approaches and
NB. choose a verb best suiting his asthetic sense
NB. or which runs the fastest for his particular application.
NB. Don't expect to understand much of what follows if you
NB. are new to J and/or do not have a copy of the "Dictionary
NB. of J". Use the verb test to experiment with time and
NB. space measures of the following:


NB. For reassigning one column try:


NB. (ac1 requires jv6.1 or 6.2)


NB. Usage :
    ] table =. 10 * i. 4 3
    (2    ;    3 3 3 3) ac0  table
    (2    ;    3 3 3 3) ac1  table
    (2    ;    3 3 3 3) ac1s table
    ((,2) ; ,. 3 3 3 3) ac2  table

NB. For reassigning several columns at once try ac2 or ac1s :

NB. Usage :
    (0 2 ; 4 2 $ 3) ac2 table
    (0 2 ; 4 2 $ 3) ac1s table

NB. =================================================================
NB. 3. How do I reassign a row in a table ?
NB. =================================================================

NB. For reassigning one row try :

NB. Usage :
    ( 2 ; 3 # 3 ) ra0 table

NB. For reassigning several rows at once try:
ar1 =. ac2&.|:
NB. Usage :
    (0 2 ; |: 2 3 $ 3) ar1 table

NB. =================================================================
NB. 4. How do I implement selective reassignment ?
NB. =================================================================



NB. If you are using Jv6.0 or earlier try s1
NB. s2 only works on Jv6.1 and higher.
NB. Useage:
    (1 1 ; 100) s1 table
    (1 1 ; 100) s2 table

NB. =================================================================
NB. 5. How do I use explicit definition to write a program which loops?
NB. =================================================================

NB. (BTW,  these examples are meant to provide a starting point for
NB. those familiar with imperative languages.)

   a =. i. 0 0           NB. Create a null character table
   a =. a, 'i =. 1'      NB. Initialize counting index      
   a =. a, 'n =. 100 '   NB. set an upper limit to the number of loops
   a =. a, 'loop) '      NB. earlier post.
   a =. a, 'y. =. y. + 2'
   a =. a, 'i =. >: i'   NB. Increment the counter
   a =. a, '$. =. > (i = 100) { loop ; end '  NB. branch to loop if i neq 100
   NB. Else branch to end
   a =. a, 'end) y.'      
   r =. a : '' "0
   NB. Create an explicit defn verb from the character
   NB. table a and define it so if acts on the atomic
   NB. components of its inputs.
   5!:2 <'r'             NB. Display verb

   NB. One important point, the comparison defining the loop condition
   NB. the result must have rank 0. For example :

   $ (100 = 100)

   NB. In the more general of comparisons, one sometimes has to cast the result
   NB. of the comparison to be a scalar 0 or a scalar 1. For example, suppose
   NB. a loop terminates if two nouns a and c (which are not scalars) match .
   NB. Then the statement in the definition of the character table b would
   NB.  look like :


   NB. - - - - -
   NB.   For those familiar with APL's execute command, here is the
   NB.   corresponding J implementation :
   b =. i. 0 0  
   b =. b, 'i =. 1'      
   b =. b, 'n =. 100'
   b =. b, 'loop) ".(i -: n)#''$.=. end'' '  
   NB. if i matches n then
   NB. then the suite is assign
   NB. to point to end (and what
   NB. follows end which in this
   NB. case is nothing).
   b =. b, 'y. =. y. + 2'
   b =. b, 'i =. >: i'
   b =. b, '$. =. loop'
   b =. b, 'end) y.'
   t =. b : '' "0  

   NB.  - - - - -
   NB. Here is more efficient example

   l =. 0 0 $''
   l=.l,  'n =. 99'
   l=.l,  '$. =., n #,: loop_start -. loop_end '
   l=.l,  'loop_start)'
   l=.l,  'y. =. y. + 2 '
   l=.l,  'loop_end)'
   s=. l : ''  "0

   NB. execute r, s, and t simultaneously with an arugment of 3 :
   r`s`t`:0 (3)



Tue, 09 Jan 1996 09:56:32 GMT  
 J ammend adverb }

Quote:
In Ira Ekhaus writes:
>does anyone have any suggests of the format that would most conveniently
>allow the offset to be specified on invocation?

Format? How about dlr and drl where :

 zeros =. 3 3 $ 0

 (0 2) dlr zeros
2 0 0
0 2 0
0 0 2
 (1 2) dlr zeros
0 2 0
0 0 2
0 0 0
 (2 2) dlr zeros
0 0 2
0 0 0
0 0 0
 (_1 2) dlr zeros
0 0 0
2 0 0
0 2 0
 (_2 2) ldr zeros
0 0 0
0 0 0
0 0 2
 (0 2) drl zeros
0 0 2
0 2 0
2 0 0
 (1 2) drl zeros
0 2 0
2 0 0
0 0 0
 (2 2) drl zeros
2 0 0
0 0 0
0 0 0
 (_1 2) drl zeros
0 0 0
0 0 2
0 2 0
 (_2 2) drl zeros
0 0 0
0 0 0
0 0 2

  Like selective reassignment, this would be more efficiently
  implemented as a foreign conjunction rather than a verb.

  I recommend against not hacking the code to amend
  as in your post, just for the sake of keeping changes
  to the language modular to ISI's implementation. Why?
  Because someday ISI may stop offering the source.
  Then supplemental hacks, say for LAPACK, or 'high
  performance amend' or 'keyed files' would be loaded
  into ISI's J dynamically. So if you keep your modifications
  modular you don't have to worry about losing your new verbs
  (foreign conjunctions).

   Also, now that I've brought it up, I'll add that,
   as far as I know, ISI has every intention of releasing
   the source to version of J due out this october.

   -emmett

  -emmett

  -emmett



Tue, 09 Jan 1996 10:25:05 GMT  
 J ammend adverb }

Quote:
>In Ira Ekhaus writes:

>>does anyone have any suggests of the format that would most conveniently
>>allow the offset to be specified on invocation?

   NB. Is dlr is what you want? Dlr can be made more efficient by
   NB. using suite differently but this should provide the fundamentals.

   a =. i. 0 0
   a =. a, 'w0 =.  > 1&{ x.'


   a =. a, '$.=. > (w0 < 0) { s1;s2'

   a =. a,' $.=.s3'

   a =. a,' s3) y. =. (> 0 &{ x.) w3 } y.'
   dlr =. ('' : a) "(1 2)

   y2 =. |: y1 =. 5 3 $ 0


   (3 4 5 ; 0) dlr y1
3 0 0
0 4 0
0 0 5
0 0 0
0 0 0
   s1 dlr y1
0 0 0
0 0 0
0 0 0
0 0 0
4 0 0

0 0 0
0 0 0
0 0 0
4 0 0
0 4 0

0 0 0
0 0 0
4 0 0
0 4 0
0 0 4

0 0 0
4 0 0
0 4 0
0 0 4
0 0 0

4 0 0
0 4 0
0 0 4
0 0 0
0 0 0

0 4 0
0 0 4
0 0 0
0 0 0
0 0 0

0 0 4
0 0 0
0 0 0
0 0 0
0 0 0
   s2 dlr y2
0 0 0 0 0
0 0 0 0 0
4 0 0 0 0

0 0 0 0 0
4 0 0 0 0
0 4 0 0 0

4 0 0 0 0
0 4 0 0 0
0 0 4 0 0

0 4 0 0 0
0 0 4 0 0
0 0 0 4 0

0 0 4 0 0
0 0 0 4 0
0 0 0 0 4

0 0 0 4 0
0 0 0 0 4
0 0 0 0 0

0 0 0 0 4
0 0 0 0 0
0 0 0 0 0



Wed, 10 Jan 1996 07:08:21 GMT  
 J ammend adverb }

[deleted]
   =======================

   also I'd like to use amend to allow me to fill the main and off  diagonals
   of  matrices with interesting stuff.
   here is a verb that will work on the first off diagonal


   NB.                                             indices
   NB.                                  rotate the ROWS once (hardwired right now)
   NB.                run the axes of the main diagonal together
   NB.  drop the last index

   Now ,
   maybe my problems stem from a bug in my version of J (no fault of ISI)
   but does anyone have any suggests of the format that would most conveniently
   allow the offset to be specified on invocation?
   ie
   x 2&u }y
   to amend the 2nd off diagonal of y  with x (of course without modifying y)

   Ira Ekhaus

Consider


  ] a=.?3 4$10
1 7 4 5
2 0 6 6
9 3 5 8
   100 (0) u a
100 7 4 5
  2 0 6 6
  9 3 5 8

 100 1000 10 (2) u a
 1    7 100 5
 2 1000   6 6
10    3   5 8

and also:
   100&(4 u)&. |. a
1 100   4   5
2   0 100   6
9   3   5 100

   100&(2 u)&. |. a
100   7   4 5
  2 100   6 6
  9   3 100 8

Eythan



Sat, 13 Jan 1996 04:16:51 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. JS-EAI with *JS*-callback

2. js.exception 3279.js

3. J adverb question

4. Need help with adverb

5. Defining adverbs tacitly

6. adverb definition via : in J 3.2

7. User-defined adverbs?

8. Trains of conjunctions and/or adverbs

9. Prefix adverb in J

10. tacit adverb problem [J]

11. A handy explicit adverb in J

12. Can I design a bivalent adverb without using : ?

 

 
Powered by phpBB® Forum Software