J does not have a primitive verb which permutes values of atoms, like C.
permutes indexes. 

 

So, if P would be such a primitive, then (5 0 3; 1 2) P y  would replace in
y each 5 by 0, each 0 by 3 and each 3 by 5 and swap 1's and 2's.

Contrary to the behaviour of C. , preferably P accepts only boxed left hand
argument.

 

One way to realize P with the use of C. is:

P=: [EMAIL PROTECTED] $ (((i.!.0~ ~.)@] { (((i.&.>~<) C. ]) ~.)) ,) 

 

   a ; (5 0 3;1 2) P  a =: 3 4 [EMAIL PROTECTED]

+---------+---------+

|0 5 5 4 2|3 0 0 4 1|

|3 2 1 4 2|5 1 2 4 1|

|0 2 1 4 1|3 1 2 4 2|

|2 4 0 4 0|1 4 3 4 3|

|         |         |

|5 4 0 0 0|0 4 3 3 3|

|5 1 5 0 4|0 2 0 3 4|

|5 5 2 0 0|0 0 1 3 3|

|1 1 5 3 1|2 2 0 5 2|

|         |         |

|3 2 1 1 3|5 1 2 2 5|

|4 4 3 5 5|4 4 5 0 0|

|5 0 1 0 3|0 3 2 3 5|

|1 3 5 0 1|2 5 0 3 2|

+---------+---------+

 

As can be seen, realizing P using C. can be rather complicated 

On the other hand, it would be easy to realize C. with the help of P, as C.
is a special case of P, applying P to the array of indexes.

C. would be (roughly) equal to  (P [EMAIL PROTECTED]) { ] 

   (5 0 3;1 2) ((P [EMAIL PROTECTED]) { ]) 'ABCDEF'

DCBFEA

 

The conclusion seems to be that P is more primitive than C. 

 

What is the opinion of the forum on this?

 

R.E. Boss

 

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

Reply via email to