The monad  <./ .+~^:_  is equivalent to the monad
<./ .+^:_~  but can be substantially faster and 
leaner.  For example:

   (<./ .+^:_~ -: <./ .+~^:_) a=: 200 200 [EMAIL PROTECTED] 100
1
   ts=: 6!:2 , 7!:[EMAIL PROTECTED]
   ts '<./ .+^:_~ a'
0.506575 3.41446e6
   ts '<./ .+~^:_ a'
0.173773 2.10323e6

   $ <./ .+^:a:~ a
15 200 200
   $ <./ .+~^:a: a
5 200 200



----- Original Message -----
From: eesuk <[EMAIL PROTECTED]>
Date: Friday, January 19, 2007 5:08 pm
Subject: Re: [Jprogramming] length of the path between two nodes in a tree

> NB. x : (# of nodes);r
> NB. y : travel pairs
> NB. a : adjacency matrix
> NB. d : all pair distance matrix
> 
> length2=: 4 : 0
> 'N r'=.x
> a=.(<.|:)1 (;/r)}_ 0{~ =i.N
> d=.((<./ . +)^:_)~ a
> d{~;/y
> )
> 
> r=:0 2, 0 1, 2 3, 2 5, 2 7, 5 6,: 1 4
> 
>   (8;r) length2 7 6,4 7,4 6,:0 6
> 3 4 5 3
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to