It could be possible to speculate that list is a graph, plus is a value of binary relation, and sum is a value of transitive path corresponding to a direct edge from a root node, etc. But lets just say that some Transitive Closuresque methods were used.
--- Roger Hui <[EMAIL PROTECTED]> wrote: > An explanation of closure usually begins with a description of > graphs and then proceeds to closure. From the J dictionary: > > http://www.jsoftware.com/help/dictionary/samp20.htm (Directed Graphs) > http://www.jsoftware.com/help/dictionary/samp21.htm (Closure) > > One particular kind of graph provides a telling example: > the relation ship is "children of". The transitive closure > of this graph is "descendant of". "Transitive" means > if a R b and b R c, then a R c . > > > > ----- Original Message ----- > From: Oleg Kobchenko <[EMAIL PROTECTED]> > Date: Wednesday, April 2, 2008 0:23 > Subject: [Jgeneral] Transitive Closure and Line Wrap > To: General forum <[email protected]> > > > Transitive Closer (TC) is applying the same operation over and > > over until the results stop changing. > > > > As a simple example +/ can be expressed: remove first two items, > > prepend their sum. > > > > In TC it is (typically) necesary to establish a stop condition. > > Here, it is: until there is more than one item. We apply > > operation > > only while stop condition is satisfied. Here's one step: > > > > 2&(+/@{. , }.) ^: (1<#) 1 2 3 4 5 > > 3 3 4 5 > > > > We get the sought +/ after applying the above ad infinum: > > > > 2&(+/@{. , }.) ^: (1<#) ^:_ ] 1 2 3 4 5 > > 15 > > +/ 1 2 3 4 5 > > 15 > > > > Now for convenience, we separate the TC operator from > > the functional arguments: operation and stop condition: > > > > tc=: 2 : 'u ^:v ^:_' > > > > 2&(+/@{. , }.) tc (1<#) 1 2 3 4 5 > > 15 > > > > Now, in line wrap problem we need to break the sequence > > of words into lines. Suppose we calculated each word length > > (plus 1 for space) and have line length. > > > > L=. 1 2 3 4 5 3 2 1 2 3 4 3 2 NB. > > word lengths +1 > > > > Continuing the idea of TCing +/ here we need to > > do the +/ until we reach line end, which gives us > > first line, and then repeat it until we exhaust all > > words, which will give the rest of the lines. That's > > two nested TCs. > > > > Here's inner TC: calculate leading line length > > > > ln=. 1 : '2&(+/@{. , }.) tc ((m>:[:+/2&{.)*.(1<#))' > > 8 ln L > > 6 4 5 3 2 1 2 3 4 3 2 > > > > For outer TC we need "trasitive accumulator" for > > intermediate results > > > > ta=: 2 : 'u&.> ^: (v&>) ^:a:' > > > > We are interested in }.@(8 ln) which are unwrapped > > words after each successive line. Getting their > > lengths and then pairwise differences will yield > > the sought word lengths of each line: > > > > ]s=. 2-/\ #&> }.@(8 ln) ta (0<#) <L > > 3 1 2 4 2 1 > > > > ((# [EMAIL PROTECTED]) s) </. L > > +-----+-+---+-------+---+-+ > > |1 2 3|4|5 3|2 1 2 3|4 3|2| > > +-----+-+---+-------+---+-+ > > > > > > > > --- Mattia Landoni <[EMAIL PROTECTED]> wrote: > > > > > Out of sheer curiosity, and far from intervening in the merit > > of the > > > discussion, what does "transitive closure" have to do with > > "line wrap"? The > > > Wikipedia entry failed to illuminate me. There must be some subtle > > > connection! > > > > > > > > > > From: Devon McCormick <[EMAIL PROTECTED]> > > > > > > > > > Yes - "transitive closure" will become my new > > > > > catchphrase for the way we state things in J-world that > > render them > > > > > opaque to everyone but college math professors and a > > > > > few fellow travelers. As I've mentioned before, when > > I originally > > > > needed to > > > > > do this, > > > > > it was simpler for me to write a crude text folder than to > > find the > > > > > code I knew already existed. > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ____________________________________________________________________________________ You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost. http://tc.deals.yahoo.com/tc/blockbuster/text5.com ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
